Menu

[r1]: / utils.cpp  Maximize  Restore  History

Download this file

150 lines (131 with data), 3.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "legend.h"
#ifdef USECRYPT
#ifndef BSD
#include <crypt.h>
#else
#include <pwd.h>
#endif
#endif
//Utility functions for Legend written by Todd Allen(Barghest), toddmallen@gmail.com,
//unless otherwise noted.
/*******************************************************************************
* Legend is free software licensed under the GNU General Public License (GPL),*
* available in the attached COPYING and/or license.txt file in the docs *
* directory, or at www.fsf.org. *
* This program is provided with NO WARRANTY of any kind and is used or run *
* entirely at the user's own risk. *
******************************************************************************/
namespace UTILS
{
string strip_whitespace(string in_str)
{
register unsigned int i;
char ch;
string ret_str;
char tempbuf[MAX_STRING_INPUT];
for(i = 0; i < in_str.size(); i++)
{
ch = in_str[i];
if(!isgraph(ch) && (ch != ' '))
{
tempbuf[i] = '\0';
break;
}
else
{
tempbuf[i] = ch;
}
}
ret_str = tempbuf;
return ret_str;
}
bool file_exists(const string &filename)
{
fstream fin;
fin.open(filename.c_str(), fstream::in);
if(fin.is_open())
{
fin.close();
return true;
}
return false;
}
// template<class type_out, class type_in>
// type_out convert(const type_in in)
// {
// //using std::stringstream;
// stringstream ss;
// ss << in;
// type_out buf;
// ss >> buf;
// return buf;
// }
} //end namespace UTILS
namespace UPDATE
{
Mud_Handler::Mud_Handler()
{
if((gettimeofday(&started_time, NULL)) == -1)
{
log_console("FATAL ERROR: failed to establish baseline time!");
exit(1);
}
gettimeofday(&current_time, NULL);
set_tick_timer();
}
string Mud_Handler::get_time(void) const
{
string strbuf;
time_t currtime = current_time.tv_sec;
strbuf = ctime(&currtime);
return strbuf;
}
int Mud_Handler::get_time_secs(void) const
{
return current_time.tv_sec;
}
string Mud_Handler::get_boot_time(void) const
{
string strbuf;
time_t boottime = started_time.tv_sec;
strbuf = ctime(&boottime);
return strbuf;
}
int Mud_Handler::get_boot_time_secs(void) const
{
return started_time.tv_sec;
}
void Mud_Handler::set_tick_timer(void)
{
//TODO: Define this!
}
#ifdef USECRYPT
bool Mud_Handler::check_pass(string pass, string name, string hash)
{
string test;
test = crypt(pass.c_str(), name.c_str());
if(test == hash)
return true;
else
return false;
}
//Checks a hashed string against a password hash. For encrypted passwords. Recommended for
//any country where the use of encryption is legal.
string crypt_pass(string pass, string name)
{
string hash_str;
hash_str = crypt(pass.c_str(), name.c_str());
return hash_str;
}
#else
//Unencrypted password checking. Not recommended except for countries where the use of encryption
//is illegal.
bool Mud_Handler::check_pass(string pass, string test)
{
if(pass == test)
return true;
else
return false;
}
#endif
} //end namespace UPDATE