/*
* Ascent MMORPG Server
* Copyright (C) 2005-2007 Ascent Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
*/
#include "Common.h"
using namespace std;
vector StrSplit(const string &src, const string &sep)
{
vector r;
string s;
for (string::const_iterator i = src.begin(); i != src.end(); i++) {
if (sep.find(*i) != string::npos) {
if (s.length()) r.push_back(s);
s = "";
} else {
s += *i;
}
}
if (s.length()) r.push_back(s);
return r;
}
void SetThreadName(const char* format, ...)
{
// This isn't supported on nix?
va_list ap;
va_start(ap, format);
#ifdef WIN32
char thread_name[200];
vsnprintf(thread_name, 200, format, ap);
THREADNAME_INFO info;
info.dwType = 0x1000;
info.dwThreadID = GetCurrentThreadId();
info.dwFlags = 0;
info.szName = thread_name;
__try
{
RaiseException(0x406D1388, 0, sizeof(info)/sizeof(DWORD), (DWORD*)&info);
}
__except(EXCEPTION_CONTINUE_EXECUTION)
{
}
#endif
va_end(ap);
}
time_t convTimePeriod ( uint32 dLength, char dType )
{
time_t rawtime = 0;
if (dLength == 0)
return rawtime;
struct tm * ti = localtime( &rawtime );
switch(dType)
{
case 'h': // hours
ti->tm_hour += dLength;
break;
case 'd': // days
ti->tm_mday += dLength;
break;
case 'w': // weeks
ti->tm_mday += 7 * dLength;
break;
case 'm': // months
ti->tm_mon += dLength;
break;
case 'y': // years
// are leap years considered ? do we care ?
ti->tm_year += dLength;
break;
default: // minutes
ti->tm_min += dLength;
break;
}
return mktime(ti);
}