#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(¤t_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