コード例 #1
0
ファイル: Log.cpp プロジェクト: roseon/life-marvelous
void InitLog()
{
	FILE* pFile;
	pFile = fopen( "patchlog.txt", "w");
	if ( pFile == NULL)
		return;


	__time64_t ltime;
	_time64( &ltime);
	fprintf( pFile, "Log start : %s\n", _ctime64( &ltime));


	char szDir[ 512];
	GetCurrentDirectory( sizeof( szDir), szDir);
	fprintf( pFile, "Current Directory : %s\n", szDir);

	fclose( pFile);
}
コード例 #2
0
void CHTMLContainerDlg::_OnBeforeNavigate2(LPDISPATCH pDisp, VARIANT FAR* URL, VARIANT FAR* Flags, VARIANT FAR* TargetFrameName, VARIANT FAR* PostData, VARIANT FAR* Headers, BOOL FAR* Cancel)
{
	CString targetURL(V_BSTR(URL));

	__time64_t now;
	_time64(&now);
	if (max(now, m_backspaceTime) - min(now, m_backspaceTime) <= 1) *Cancel = TRUE;
// 	if (m_lastURL.CompareNoCase(targetURL) == 0)
// 	{
// 		*Cancel = TRUE;
// 	}
// 	else
// 	{
// 		m_lastURL = m_curURL;
// 		m_curURL = targetURL;
// 	}
	
	OnBeforeNavigate(pDisp, targetURL);
}
コード例 #3
0
ファイル: file_logger.hpp プロジェクト: Vilse1202/nscp
		void log(const std::wstring category, const wchar_t* file, const int line, const wchar_t* message) {
			TCHAR buffer[65];
			__time64_t ltime;
			_time64( &ltime );
			struct tm *today = _localtime64( &ltime );
			if (today) {
				size_t len = wcsftime(buffer, 63, datemask_.c_str(), today);
				if ((len < 1)||(len > 64))
					wcsncpy(buffer, 64, _T("???"));
				else
					buffer[len] = 0;
			} else {
				wcsncpy(buffer, 64, _T("<unknown time>"));
			}
			std::wstring logline = std::wstring(buffer) + _T(": ") + category + _T(":") + std::wstring(file) + _T(":") + strEx::itos(line) +_T(": ") + message + _T("\r\n");
			if (!writeEntry(logline)) {
				std::wcerr << _T("Failed to write: ") << logline;
			}
		}
コード例 #4
0
int64_t getDateTime(tm *date)
{
#ifdef _WIN32
	__time64_t t;
	_time64(&t);
	if(date != 0)
		_localtime64_s(date, &t);
	return (int64_t)t;
#else
	time_t t;
	time(&t);
	if(date != 0)
	{
		tm *result = localtime(&t);
		memcpy(date, result, sizeof(tm));
	}
	return (int64_t)t;
#endif
}
コード例 #5
0
ファイル: DessertSystem.cpp プロジェクト: luw630/Server
void CDessertSystem::InitLuaData()
{
	__time64_t now = _time64(nullptr);
	__time64_t tCurTime = m_BaseDataManager.GetLogoutTime();
	__time64_t nextRfreshTime = tCurTime;

	tm curTime;
	_localtime64_s(&curTime, &now);
	curTime.tm_hour = 5;
	curTime.tm_min = 0;
	curTime.tm_sec = 0;
	nextRfreshTime = _mktime64(&curTime);

	///判断登出时间到登陆时间的这段时间中是否已经刷新了相关的领取数据
	if (RefreshJudgement::JudgeCrossed(tCurTime, nextRfreshTime))
	{
		ResetData();
	}
}
コード例 #6
0
ファイル: xstime.c プロジェクト: GYengera/mrpt
/*! \brief Retrieves the date and time (platform-independent)
	\param date : if non-zero the local (!) date and time is stored in the tm struct this parameter points to
	\returns The UTC date and time as seconds since 1970
*/
int64_t XsTime_getDateTime(struct tm *date)
{
#ifdef _WIN32
	__time64_t t;
	_time64(&t);	//lint !e534 return value is stored in t
	if (date != 0)
		_localtime64_s(date, &t);	//lint !e534
	return (int64_t)t;
#else
	time_t t;
	time(&t);
	if(date != 0)
	{
		struct tm *result = localtime(&t);
		memcpy(date, result, sizeof(struct tm));
	}
	return (int64_t)t;
#endif
}
コード例 #7
0
ファイル: common.c プロジェクト: raohl/MySSTable
void* create_data(const char* key, int key_len, const char* value, int value_len, char type)
{
	data_t* data = (data_t*)xmalloc(sizeof(data_t) + key_len + value_len + 2);
	memset(data,0,sizeof(*data));
	data->type = type;
	data->key_len = key_len;
	data->value_len = value_len;

	data->key = data->addr + 1;
	data->value = data->addr + 2 + data->key_len;
	memcpy(data->key,key,data->key_len);
	memcpy(data->value,value,data->value_len);
	data->addr[data->key_len + 1] = 0;
	data->addr[data->key_len + data->value_len + 2] = 0;
	data->version = _time64(NULL);

	data->hash_value = PMurHash32(0,data->key,data->key_len);

	return data;   
}
コード例 #8
0
ファイル: SEdDesktop.cpp プロジェクト: HonzaMD/Krkal2
CSEdDesktop::CSEdDesktop()
	: CGUIDesktop()
{
	try{
		assert(!SEdDesktop);
		SEdDesktop=this;

		RemoveFromTrash();
		MsgAcceptConsume(MsgMouseL|MsgMouseM|MsgMouseR);
		// MsgSetProduce(MsgAll);

		CGUIWindowPanel* panel = new CGUIWindowPanel(0,sy-STD_PANEL_HEIGHT-STD_PANEL_SHIFT,styleSet->Get("Panel"),this,true,false,0,0);
													//0,-STD_PANEL_SHIFT (pridani nahoru)
		push=false;

		iconDefaultHandler = new CSEdDesktopIconHandler();
		iconDefaultHandler->icons = new typeID[4];		// zadat velikost pole dle poctu icon (polozek typeID)

		SEdOpenedFiles = new CSEdOpenedFiles();

		AddStartMenu();

		InitDefaultIcons();

		iconDefaultHandler->ShowFileBrowser();

		AddToTrash();
	}
	catch(CExc c)
	{
		mainGUI->LogError(c);

		// vypis informace o chybe na obrazovce jako DebugMessage (prozatimni reseni)
		__time64_t ltime;
		_time64( &ltime );
		DebugMessage(0,"%s : %2d:%2d - %s",_ctime64( &ltime ), c.errnum, c.param, c.errstr);

		desktop=0;
		throw CExc(eGUI, E_INTERNAL,"CSEdDesktop::CSEdDesktop> Fatal error - cannot creat DESKTOP");
	}
}
コード例 #9
0
CDemoRecorder::CDemoRecorder()
{
	// We want this folder to exist
	if (!filesystem.CreateDirectory("demos"))
		return;

	wantedName = demoName = "demos/unnamed.sdf";

	std::string filename = filesystem.LocateFile(demoName, FileSystem::WRITE);
	recordDemo = SAFE_NEW std::ofstream(filename.c_str(), std::ios::out | std::ios::binary);

	memset(&fileHeader, 0, sizeof(DemoFileHeader));
	strcpy(fileHeader.magic, DEMOFILE_MAGIC);
	fileHeader.version = DEMOFILE_VERSION;
	fileHeader.headerSize = sizeof(DemoFileHeader);
	strcpy(fileHeader.versionString, VERSION_STRING);

	__time64_t currtime;
	_time64(&currtime);
	fileHeader.unixTime = currtime;

	recordDemo->write((char*)&fileHeader, sizeof(fileHeader));

	if (gameSetup) {
		// strip trailing null termination characters
		int length = gameSetup->gameSetupTextLength;
		while (gameSetup->gameSetupText[length - 1] == '\0')
			--length;

		fileHeader.scriptSize = length;
		recordDemo->write(gameSetup->gameSetupText, length);
	}

	fileHeader.playerStatElemSize = sizeof(CPlayer::Statistics);
	fileHeader.teamStatElemSize = sizeof(CTeam::Statistics);
	fileHeader.teamStatPeriod = CTeam::statsPeriod;
	fileHeader.winningAllyTeam = -1;

	WriteFileHeader();
}
コード例 #10
0
ファイル: logging.cpp プロジェクト: jonac/concprog_project
	static void add_destination(Severity severity, FILE* dst, bool autoclose){
		Destination* o = new Destination(severity, dst, false);
		output.push_back(o);

		if ( dst == stdout || dst == stderr ){
			return;
		}

#ifdef HAVE_GETTIMEOFDAY
		struct timeval tv;
		gettimeofday(&tv, nullptr);
		struct tm* local = localtime(&tv.tv_sec);
#else
		__time64_t tv;
		struct tm tm, *local = &tm;
        _time64(&tv);
        _localtime64_s(local, &tv);
#endif

		char buf[64] = {0,};
		strftime(buf, sizeof(buf), "\nLogging started at %Y-%m-%d %H.%M.%S\n", local);
		o->write(INFO, buf);
	}
コード例 #11
0
ファイル: CommManager.cpp プロジェクト: redblack168/trochilus
void CommManager::UpdateHeartbeat( LPCTSTR clientid, SOCKADDR_IN addr )
{
	__time64_t now;
	_time64(&now);

	m_mapSection.Enter();
	{
		HeartbeatMap::iterator finditer = m_heartbeatMap.find(clientid);
		if (finditer != m_heartbeatMap.end())
		{
			finditer->second.time = now;
			finditer->second.lastAddr = addr;
		}
		else
		{
			HEARTBEAT_INFO info;
			info.time = now;
			info.lastAddr = addr;
			m_heartbeatMap[clientid] = info;
		}
	}
	m_mapSection.Leave();
}
コード例 #12
0
ファイル: Logger.cpp プロジェクト: c-base/libavg
void Logger::trace(const UTF8String& sMsg, const category_t& category,
        severity_t severity) const
{
    lock_guard lock(s_traceMutex);
    struct tm* pTime;
    #ifdef _WIN32
    __int64 now;
    _time64(&now);
    pTime = _localtime64(&now);
    DWORD tms = timeGetTime();
    unsigned millis = unsigned(tms % 1000);
    #else
    struct timeval time;
    gettimeofday(&time, NULL);
    pTime = localtime(&time.tv_sec);
    unsigned millis = time.tv_usec/1000;
    #endif
    lock_guard lockHandler(s_sinkMutex);
    std::vector<LogSinkPtr>::const_iterator it;
    for(it=m_pSinks.begin(); it!=m_pSinks.end(); ++it){
        (*it)->logMessage(pTime, millis, category, severity, sMsg);
    }
}
コード例 #13
0
ファイル: Log.cpp プロジェクト: shadowcomer/CatLing
void Log::writeToFile(LOG_LEVEL level, char* text)
{
    if (!m_logFile.is_open()){
        return;
    }

    if (level < m_capLevel){
        return;
    }

    struct tm timeInfo;
    __time64_t long_time;
    char timeStr[64];
    std::string levelText(textifyLogLevel(level));

    errno_t err;

    _time64(&long_time);
    err = localtime_s(&timeInfo, &long_time);
    assert(err == 0);

    err = sprintf_s(timeStr, "%d:%d:%d", timeInfo.tm_hour, timeInfo.tm_min, timeInfo.tm_sec);
    assert(err == 0);

    {
        tbb::mutex::scoped_lock lock(SYNC_operation);
        // We have to check again because the rest of the
        // function isn't within the lock.
        if (!m_logFile.is_open()){
            return;
        }

        m_logFile << timeStr << " " << levelText << ": "
            << text << std::endl;
        m_logFile.flush();
    }
}
コード例 #14
0
void LCD_UpdateThread(void* Control)
{
	CMPC_Lcd* ctrl = static_cast<CMPC_Lcd*>(Control);
	wchar_t str[40];
	__time64_t ltime;
	__time64_t otime = 0;
	struct tm thetime;
	_locale_t locale = _create_locale(LC_TIME, "");

	while (ctrl->Thread_Loop) {
		EnterCriticalSection(&ctrl->cs);
		if (_time64(&ltime) != otime) { // Retrieve the time
			otime = ltime;
			_localtime64_s(&thetime, &ltime);

			// Format the current time structure into a string
			// using %#x is the long date representation,
			// appropriate to the current locale
			if (_wcsftime_l(str, _countof(str), _T("%#x"), (const struct tm*)&thetime, locale) &&
			(ltime > ctrl->nThread_tTimeout || ltime < otime)) { // message displayed, no update until timeout
				ctrl->m_MonoPage.m_Text[0].SetText(str);
				ctrl->m_ColorPage.m_Text[0].SetText(str);
			}

			if (_wcsftime_l(str, _countof(str), _T("%X"), (const struct tm*)&thetime, locale)) {
				ctrl->m_MonoPage.m_Text[1].SetText(str);
				ctrl->m_ColorPage.m_Text[1].SetText(str);
			}
		}
		ctrl->m_Connection.Update();
		LeaveCriticalSection(&ctrl->cs);
		Sleep(LCD_UPD_TIMER);
	}

	_free_locale(locale);
	_endthread();
}
コード例 #15
0
ファイル: LcdSupport.cpp プロジェクト: Samangan/mpc-hc
void LCD_UpdateThread(void * Control)
{
	CMPC_Lcd * ctrl = static_cast<CMPC_Lcd *> (Control);
	wchar_t str[40];
	__time64_t ltime;
	__time64_t otime = 0;
	struct tm  thetime;
	_tsetlocale(LC_ALL, _T(""));			// set current system locale

	while (ctrl->Thread_Loop) {
		EnterCriticalSection(&ctrl->cs);
		if (_time64(&ltime) != otime) {	// Retrieve the time
			otime = ltime;
			_localtime64_s(&thetime, &ltime);

			// Format the current time structure into a string
			// using %#x is the long date representation,
			// appropriate to the current locale
			if (wcsftime(str, sizeof(str)/sizeof(wchar_t), _T("%#x"), (const struct tm *)&thetime) &&
					(ltime > ctrl->nThread_tTimeout || ltime < otime)) {	// message displayed, no update until timeout
				ctrl->m_Manager.m_Text[0].SetText(str);
			}

			if (wcsftime(str, sizeof(str)/sizeof(wchar_t), _T("%X"), (const struct tm *)&thetime)) {
				ctrl->m_Manager.m_Text[1].SetText(str);
			}
		}

		ctrl->m_Output.Update(GetTickCount());	// This invokes OnUpdate for the active screen
		ctrl->m_Output.Draw();			// This invokes OnDraw for the active screen
		LeaveCriticalSection(&ctrl->cs);
		Sleep(LCD_UPD_TIMER);
	}

	_endthread();
}
コード例 #16
0
ファイル: Log.cpp プロジェクト: ItsClemi/DerpCraft
void LogEx( _In_ WORD lColor, bool bShowTime, _In_ char* szStr, _In_ ... )
{
	char szBuff[256] = {0,};

	va_list arg;
	va_start(arg, szStr);
	_vsnprintf_s(szBuff, 256, szStr, arg);
	va_end(arg);

	HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);

	if(bShowTime)
	{
		__time64_t time = _time64( nullptr ); 
		struct tm t;
		_localtime64_s(&t, &time);

		printf("[%02d:%02d:%02d] ", t.tm_hour, t.tm_min, t.tm_sec );
	}

	SetConsoleTextAttribute( hStdout, lColor );
	printf( "%s\n", szBuff );		
	SetConsoleTextAttribute( hStdout, Silver );
}
コード例 #17
0
void CDuplicateBaseManager::OnRecvMsg(const SMessage *pMsg)
{
	const SDuplicateMsg * prtMsg = static_cast<const SDuplicateMsg*>(pMsg);
	if (prtMsg == nullptr)
	{
		rfalse("副本消息转换失败");
		return;
	}

	const SQDuplicateEarningClear* clearMsg = nullptr;

	switch (prtMsg->_protocol)
	{
	case SDuplicateMsg::REQUEST_ENTER_SPECIFY_TOLLGATE:
		///请求挑战指定的副本关卡
		AskToEnterTollgate(prtMsg);
		break;
	case SDuplicateMsg::REQUEST_EARNING_CLEAR:
		clearMsg = static_cast<const SQDuplicateEarningClear*>(pMsg);
		if (clearMsg != nullptr)
			EarningClearProcess(clearMsg->duplicateID, clearMsg->tollgateID, clearMsg->combatGrade);
		break;
	case SDuplicateMsg::REQUEST_START_CHALLENGE:
		OnStartToChallenge();
		/// 记录战斗开始时间(由于子类有重载OnStartToChanllenge 故在此处记录 不管此次是否通过战斗申请 在结算前都应由此函数通知切换场景)
		_time64(&m_tBattleStartTime);
		break;
	case SDuplicateMsg::REREQUEST_TOLLGATE_DROPED_ITEM:
		ReRequestTollgateDropedItem(prtMsg);
		break;
	default:
		///子类的差异化的消息处理模块
		DispatchMsg(prtMsg);
		break;
	}
}
コード例 #18
0
ファイル: MissionActiveness.cpp プロジェクト: luw630/Server
bool CMissionActiveness::InitDataMgr(void * pData)
{
	if (pData != nullptr)
		m_dwMissionActiveness = static_cast<DWORD*>(pData);

	///初始判断是否可以重置任务数据
	__time64_t tCurTime = m_pBaseDataMgr.GetLogoutTime();
	__time64_t nextRefreshTime = tCurTime;

	__time64_t now = _time64(nullptr);
	tm curTime;
	_localtime64_s(&curTime, &now);
	curTime.tm_hour = 5;
	curTime.tm_min = 0;
	curTime.tm_sec = 0;
	nextRefreshTime = _mktime64(&curTime);

	if (RefreshJudgement::JudgeCrossed(tCurTime, nextRefreshTime))
	{
		m_bInitResetMissionActiveness = true;
	}

	return true;
}
コード例 #19
0
std::string FormatHTTPDate(__int64* ltime)
{
	struct tm t;
	if(ltime != NULL)
	{
		_gmtime64_s(&t, ltime);
	}
	else
	{
		//  传入空指针,则取当前时间.
		__int64 ltime_cur;
		_time64( &ltime_cur );
		_gmtime64_s(&t, &ltime_cur);
	}

	char szTime[100] = {0};

	// 格式化邮件时间 - Sun, 24 Aug 2008 22:43:45 GMT
	sprintf(szTime, "%s, %d %s %d %d:%d:%d GMT", 
		week[t.tm_wday], t.tm_mday, month[t.tm_mon], 
		t.tm_year + 1900, t.tm_hour, t.tm_min, t.tm_sec);

	return szTime;
}
コード例 #20
0
ファイル: Demo.cpp プロジェクト: genxinzou/svn-spring-archive
void CDemoRecorder::SetName(const std::string& mapname)
{
	struct tm *newtime;
	__time64_t long_time;
	_time64(&long_time);                /* Get time as long integer. */
	newtime = _localtime64(&long_time); /* Convert to local time. */

	char buf[500];
	sprintf(buf,"%02i%02i%02i",newtime->tm_year%100,newtime->tm_mon+1,newtime->tm_mday);
	std::string name=std::string(buf)+"-"+mapname.substr(0,mapname.find_first_of("."));
	name+=std::string("-")+VERSION_STRING;
	
	sprintf(buf,"demos/%s.sdf",name.c_str());
	CFileHandler ifs(buf);
	if(ifs.FileExists()){
		for(int a=0;a<9999;++a){
			sprintf(buf,"demos/%s-%i.sdf",name.c_str(),a);
			CFileHandler ifs(buf);
			if(!ifs.FileExists())
				break;
		}
	}
	wantedName = buf;
}
コード例 #21
0
ファイル: LeakReport.cpp プロジェクト: liminzhu/ChakraCore
LeakReport::UrlRecord *
LeakReport::LogUrl(char16 const * url, void * globalObject)
{
    UrlRecord * record = NoCheckHeapNewStruct(UrlRecord);

    size_t length = wcslen(url) + 1; // Add 1 for the NULL.
    char16* urlCopy = NoCheckHeapNewArray(char16, length);
    js_memcpy_s(urlCopy, (length - 1) * sizeof(char16), url, (length - 1) * sizeof(char16));
    urlCopy[length - 1] = _u('\0');

    record->url = urlCopy;
#if _MSC_VER
    record->time = _time64(NULL);
#else
    record->time = time(NULL);
#endif
    record->tid = ::GetCurrentThreadId();
    record->next = nullptr;
    record->scriptEngine = nullptr;
    record->globalObject = globalObject;

    AutoCriticalSection autocs(&s_cs);
    if (LeakReport::urlRecordHead == nullptr)
    {
        Assert(LeakReport::urlRecordTail == nullptr);
        LeakReport::urlRecordHead = record;
        LeakReport::urlRecordTail = record;
    }
    else
    {
        LeakReport::urlRecordTail->next = record;
        LeakReport::urlRecordTail = record;
    }

    return record;
}
コード例 #22
0
ファイル: ch.cpp プロジェクト: alphaonex86/Copy-handler
LONG WINAPI MyUnhandledExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo)
{
	// Step1 - should not fail - prepare some more unique crash name, create under the path where ch data exists
	TCHAR szPath[_MAX_PATH];
	HRESULT hResult = SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, szPath);
	if(FAILED(hResult))
		_tcscpy(szPath, _T("c:\\"));

	CString strPath(szPath);
	// make sure to create the required directories if they does not exist
	strPath += _T("\\Copy Handler");
	CreateDirectory(strPath, NULL);
	strPath += _T("\\Dumps");
	CreateDirectory(strPath, NULL);

	// current date
	SYSTEMTIME st;
	GetLocalTime(&st);
	
	TCHAR szName[_MAX_PATH];
	_sntprintf(szName, _MAX_PATH, _T("%s\\ch_crashdump-%s-%I64u-%s.dmp"), (PCTSTR)strPath, _T(PRODUCT_VERSION), (ull_t)_time64(NULL),
#ifdef _WIN64
		_T("64")
#else
		_T("32")
#endif
		);
	szPath[_MAX_PATH - 1] = _T('\0');

	// Step 2 - create the crash dump in case anything happens later
	bool bResult = false;
	HANDLE hFile = CreateFile(szName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
	if(hFile != INVALID_HANDLE_VALUE)
	{
		MINIDUMP_EXCEPTION_INFORMATION mei;
		mei.ThreadId = GetCurrentThreadId();
		mei.ExceptionPointers = ExceptionInfo;
		mei.ClientPointers = TRUE;

		if(MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpWithProcessThreadData, &mei, NULL, NULL))
			bResult = true;
	}

	CloseHandle(hFile);

	CCrashDlg dlgCrash(bResult, szName);
	dlgCrash.DoModal();

	return EXCEPTION_EXECUTE_HANDLER;
}
コード例 #23
0
ファイル: HttpCookie.cpp プロジェクト: ldcsaa/HP-Socket
BOOL CCookieMgr::LoadFromFile(LPCSTR lpszFile, BOOL bKeepExists)
{
	BOOL isOK	= FALSE;
	FILE* pFile = nullptr;

	if((pFile = fopen(lpszFile, "r")) == nullptr)
		goto _ERROR_END;

	{
		CStringA strDomain;
		CStringA strPath;
		CCookie cookie;

		char szBuffer[8192];
		int iBufferSize			= _countof(szBuffer);
		__time64_t tmCurrent	= _time64(nullptr);
		CCookieSet* pCookieSet	= nullptr;

		CWriteLock locallock(m_cs);

		if(!bKeepExists)
			ClearDomainCookiesNoLock();

		while(fgets(szBuffer, iBufferSize, pFile) != nullptr)
		{
			char c = szBuffer[0];

			if(c == '\n' || c == '\r')
				continue;
			else if(c != '\t')
			{
				if(!LoadDomainAndPath(szBuffer, strDomain, strPath))
					goto _ERROR_END;

				pCookieSet	= GetCookieSetNoLock(strDomain, strPath);
			}
			else
			{
				if(!LoadCookie(szBuffer, strDomain, strPath, cookie))
					goto _ERROR_END;

				if(cookie.expires <= tmCurrent)
					continue;

				if(pCookieSet)
				{
					if(bKeepExists)
					{
						CCookieSetCI it = pCookieSet->find(cookie);
						if(it != pCookieSet->end())
							continue;
					}

					pCookieSet->emplace(move(cookie));
				}
				else
				{
					SetCookieNoLock(cookie, FALSE);
					pCookieSet = GetCookieSetNoLock(strDomain, strPath);
				}
			}
		}

		if(!feof(pFile))
			goto _ERROR_END;
	}

	isOK = TRUE;

_ERROR_END:

	if(pFile) fclose(pFile);

	return isOK;
}
コード例 #24
0
ファイル: GeneralizedTime.c プロジェクト: dmbaggett/asn1c
static inline time_t time(time_t *_dtime) {
        return _time64(_dtime);
}
コード例 #25
0
void CMasterServerConfig::AddRentGame(int customerid , const char* name , const char* pwd , int mapid , int slot , int RentalTime, int Region, int SesionID, bool EnableCrosshair,bool enableSnipers)
{
	static std::vector<const CServerS*> supers;
	supers.clear();
	for(CMasterGameServer::TSupersList::const_iterator it = gMasterGameServer.supers_.begin(); it != gMasterGameServer.supers_.end(); ++it)
		supers.push_back(it->second);

	const CServerS* super = supers[0];

	__int64 secs1 = _time64(&secs1);
	GBGameInfo ginfo;
	ginfo.mapId = mapid;
	ginfo.region = GBNET_REGION_US_West;
	//Mateuus Rent Server
	/*switch(Region)
	{
	case 1 : 
			ginfo.region = GBNET_REGION_US_West;
			break;
	case 10:
			ginfo.region = GBNET_REGION_Europe;
			break;
	case 2:
			ginfo.region = GBNET_REGION_US_East;
			break;
	}*/
	ginfo.enableCrosshair=EnableCrosshair;
	ginfo.enableSnipers=enableSnipers;
	ginfo.maxPlayers = slot;
	strcpy(ginfo.MapSettings,"6");
	
	
	ginfo.gameServerId = (int)u_GetRandom(300,999);

	if(gMasterGameServer.IsGameServerIdStarted(ginfo.gameServerId))
	{
		r3dOutToLog("RentServer id %d already started, reseting..\n");
		AddRentGame(customerid,name,pwd,mapid,slot,RentalTime,Region,SesionID,EnableCrosshair,enableSnipers);
		return;
	}
	ginfo.ownercustomerid = customerid; // !!!!!!! MUST SET CUSTOMERID FOR MY SERVER SCREEN !!!!!!!!!!
	r3dscpy(ginfo.name,name);
	r3dscpy(ginfo.PasswordGame,pwd);
	switch(RentalTime)
	{
	case 3: // 3 DAY
		    ginfo.expirein = 259200;
			break;
	case 7: /// 7 DAY
		    ginfo.expirein = 604800;
			break;
	case 15: // 15 DAY
		    ginfo.expirein = 1296000;
			break;
	case 30: /// 30 DAY
		    ginfo.expirein = 2592000;
			break;
	case 60: // 60 DAY
		    ginfo.expirein = 5184000;
			break;
	}
	ginfo.expirein = (int)secs1 + ginfo.expirein+120;

	char* g_ServerApiKey = "a5gfd4u8df1jhjs47ws86F";
	CWOBackendReq req("api_SrvRentGame.aspx");
	req.AddSessionInfo(customerid, SesionID);
	req.AddParam("skey1",  g_ServerApiKey);
	req.AddParam("StateSesion",1);
	req.AddParam("gameServerId",ginfo.gameServerId);
	req.AddParam("MapSettings",6);
	req.AddParam("Region",ginfo.region);
	req.AddParam("Name", name);
	req.AddParam("MapID",ginfo.mapId);
	req.AddParam("Password", pwd);
	req.AddParam("MaxPlayers", slot);
	req.AddParam("Owner",customerid);
	req.AddParam("ExpireTime",ginfo.expirein);
	req.AddParam("RentalTime", RentalTime);
	int Cross = (ginfo.enableCrosshair)?true:false;
	req.AddParam("Crosshair", Cross);
	int SNP = (enableSnipers)?true:false;
	req.AddParam("SNP", SNP);
	
	// issue
	if(!req.Issue())
	{
		r3dOutToLog("!!!! RentServer failed, code: %d\n", req.resultCode_);
		//return req.resultCode_;
		return;
	}

	CMSNewGameData ngd(ginfo, "", 0);
	DWORD ip;
	DWORD port;
	__int64 sessionId;
	r3dOutToLog("RentServer : Starting..\n");
	gMasterGameServer.CreateNewGame(ngd, &ip, &port, &sessionId);
}
コード例 #26
0
ファイル: log_agent.c プロジェクト: mf0324/Code_Learn
/**  
 * @brief output to buf
 * @param [in] p_agent, agent
 * @param [in] level, log level
 * @param [in] p_src_file, src file that call this func
 * @param [in] src_line, src line that call this func
 * @param [in] p_buf, output buf
 * @param [in/out] buf_size, output buf size/actual use size
 * @param [in] p_format, format string
 * @param [in] var_str, var string
 * @return
 * 0: success
 * other: fail
 */
static inline int32 log_agent_output2bufA(LOG_AGENT* p_agent, uint32 level, int8* p_src_file, int32 src_line, int8* p_buf, int32* p_buf_size, int8* p_format, va_list var_str)
{
	int8*  p_int8 = NULL;
	int32  buf_left_size;
	int32  total_str_size;

#if RUN_OS_WINDOWS

	SYSTEMTIME sys_time;
	struct tm  now_time;
	uint32 proc_id;
	uint32 thread_id;

	LARGE_INTEGER seek_pos;
	int64  file_pos;

#else

	struct timeval sys_time;
	struct tm  now_time;
	pid_t  thread_id;

#endif

	int64  now;
	int32  left_value;
	int32  b_need_open;
	uint32 write_size;

	int32  ret;

#if RUN_OS_WINDOWS

	_time64(&now);
	ret = _localtime64_s(&now_time, &now);
	GetLocalTime(&sys_time);
	proc_id = GetCurrentProcessId();
	thread_id = GetCurrentThreadId();

	EnterCriticalSection(&p_agent->cs);

	p_agent->now_time_year = sys_time.wYear;
	p_agent->now_time_month = sys_time.wMonth;
	p_agent->now_time_day = sys_time.wDay;
	p_agent->now_time_hour = sys_time.wHour;

#else

	now = time(NULL);
	ret = gettimeofday(&sys_time, NULL);
	localtime_r(&sys_time.tv_sec, &now_time);
	//thread_id = gettid();
	thread_id = syscall(SYS_gettid);

	pthread_mutex_lock(&p_agent->mutex);

	p_agent->now_time_year = now_time.tm_year + 1900;
	p_agent->now_time_month = now_time.tm_mon + 1;
	p_agent->now_time_day = now_time.tm_mday;
	p_agent->now_time_hour = now_time.tm_hour;

#endif

	p_int8 = p_buf;
	buf_left_size = *p_buf_size;
	total_str_size = 0;


	switch( level )
	{
	case LA_LOG_LEVEL_FATAL:
		{
			if( p_agent->level & LA_LOG_LEVEL_FATAL )
			{
#if RUN_OS_WINDOWS

				ret = sprintf_s(p_int8, buf_left_size, "[Fatal]");

#else

				ret = snprintf(p_int8, buf_left_size, "[Fatal]");

#endif

				p_int8 += ret;
				buf_left_size -= ret;
				total_str_size += ret;

			}else
			{
				goto FIN;
			}
		}
		break;

	case LA_LOG_LEVEL_ERROR:
		{
			if( p_agent->level & LA_LOG_LEVEL_ERROR )
			{
#if RUN_OS_WINDOWS

				ret = sprintf_s(p_int8, buf_left_size, "[Error]");

#else

				ret = snprintf(p_int8, buf_left_size, "[Error]");

#endif

				p_int8 += ret;
				buf_left_size -= ret;
				total_str_size += ret;

			}else
			{
				goto FIN;
			}
		}
		break;

	case LA_LOG_LEVEL_WARN:
		{
			if( p_agent->level & LA_LOG_LEVEL_WARN )
			{
#if RUN_OS_WINDOWS

				ret = sprintf_s(p_int8, buf_left_size, "[Warn]");

#else

				ret = snprintf(p_int8, buf_left_size, "[Warn]");

#endif

				p_int8 += ret;
				buf_left_size -= ret;
				total_str_size += ret;

			}else
			{
				goto FIN;
			}
		}
		break;

	case LA_LOG_LEVEL_INFO:
		{
			if( p_agent->level & LA_LOG_LEVEL_INFO )
			{
#if RUN_OS_WINDOWS

				ret = sprintf_s(p_int8, buf_left_size, "[Info]");

#else

				ret = snprintf(p_int8, buf_left_size, "[Info]");

#endif

				p_int8 += ret;
				buf_left_size -= ret;
				total_str_size += ret;

			}else
			{
				goto FIN;
			}
		}
		break;

	case LA_LOG_LEVEL_DEBUG:
		{
			if( p_agent->level & LA_LOG_LEVEL_DEBUG )
			{
#if RUN_OS_WINDOWS

				ret = sprintf_s(p_int8, buf_left_size, "[Debug]");

#else

				ret = snprintf(p_int8, buf_left_size, "[Debug]");

#endif

				p_int8 += ret;
				buf_left_size -= ret;
				total_str_size += ret;

			}else
			{
				goto FIN;
			}
		}
		break;

	case LA_LOG_LEVEL_ACCESS:
		{
			if( p_agent->level & LA_LOG_LEVEL_ACCESS )
			{
#if RUN_OS_WINDOWS

				ret = sprintf_s(p_int8, buf_left_size, "[Access]");

#else

				ret = snprintf(p_int8, buf_left_size, "[Access]");

#endif

				p_int8 += ret;
				buf_left_size -= ret;
				total_str_size += ret;

			}else
			{
				goto FIN;
			}
		}
		break;

	default:
		{
			goto FIN;
		}
	}

#if RUN_OS_WINDOWS

	ret = sprintf_s(p_int8, buf_left_size, "[%04d-%02d-%02d %02d:%02d:%02d %03d][%s:%d][%u:%u] ",
		sys_time.wYear, sys_time.wMonth, sys_time.wDay, sys_time.wHour, sys_time.wMinute, sys_time.wSecond, sys_time.wMilliseconds,
		p_src_file, src_line, proc_id, thread_id);

#else

	ret = snprintf(p_int8, buf_left_size, "[%04d-%02d-%02d %02d:%02d:%02d %03d][%s:%d][%u] ",
		now_time.tm_year + 1900, now_time.tm_mon + 1, now_time.tm_mday, now_time.tm_hour, now_time.tm_min, now_time.tm_sec, (int)sys_time.tv_usec / 1000,
		p_src_file, src_line, thread_id);

#endif

	p_int8 += ret;
	buf_left_size -= ret;
	total_str_size += ret;

#if RUN_OS_WINDOWS

	ret = vsprintf_s(p_int8, buf_left_size, p_format, var_str);

#else

	ret = vsnprintf(p_int8, buf_left_size, p_format, var_str);

#endif

	if( ret < 0 )
	{
		goto FIN;
	}

	p_int8 += ret;
	buf_left_size -= ret;
	total_str_size += ret;

FIN:

#if RUN_OS_WINDOWS

	LeaveCriticalSection(&p_agent->cs);

#else

	pthread_mutex_unlock(&p_agent->mutex);

#endif

	*p_buf_size = total_str_size;
	p_buf[total_str_size] = 0x00;

	return GEN_S_OK;
}
コード例 #27
0
ファイル: log_agent.c プロジェクト: mf0324/Code_Learn
/**  
 * @brief output
 * @param [in] p_agent, agent
 * @param [in] level, log level
 * @param [in] p_src_file, src file that call this func
 * @param [in] src_line, src line that call this func
 * @param [in] p_format, format string
 * @param [in] var_str, var string
 * @return
 * 0: success
 * other: fail
 */
static inline int32 log_agent_outputA(LOG_AGENT* p_agent, uint32 level, int8* p_src_file, int32 src_line, int8* p_format, va_list var_str)
{
	int8*  p_int8 = NULL;
	int32  buf_left_size;
	int32  total_str_size;

#if RUN_OS_WINDOWS

	SYSTEMTIME sys_time;
	struct tm  now_time;
	uint32 proc_id;
	uint32 thread_id;

	LARGE_INTEGER seek_pos;
	int64  file_pos;

#else

	struct timeval sys_time;
	struct tm  now_time;
	pid_t  thread_id;

#endif

	int64  now;
	int32  left_value;
	int32  b_need_open;
	uint32 write_size;

	int32  ret;

#if RUN_OS_WINDOWS

	_time64(&now);
	ret = _localtime64_s(&now_time, &now);
	GetLocalTime(&sys_time);
	proc_id = GetCurrentProcessId();
	thread_id = GetCurrentThreadId();

	EnterCriticalSection(&p_agent->cs);

	p_agent->now_time_year = sys_time.wYear;
	p_agent->now_time_month = sys_time.wMonth;
	p_agent->now_time_day = sys_time.wDay;
	p_agent->now_time_hour = sys_time.wHour;

#else

	now = time(NULL);
	ret = gettimeofday(&sys_time, NULL);
	localtime_r(&sys_time.tv_sec, &now_time);
	//thread_id = gettid();
	thread_id = syscall(SYS_gettid);

	pthread_mutex_lock(&p_agent->mutex);

	p_agent->now_time_year = now_time.tm_year + 1900;
	p_agent->now_time_month = now_time.tm_mon + 1;
	p_agent->now_time_day = now_time.tm_mday;
	p_agent->now_time_hour = now_time.tm_hour;

#endif

	p_int8 = p_agent->str_buf;
	buf_left_size = LA_MAX_LOG_STRING_SIZE;
	total_str_size = 0;


	switch( level )
	{
	case LA_LOG_LEVEL_FATAL:
		{
			if( p_agent->level & LA_LOG_LEVEL_FATAL )
			{
#if RUN_OS_WINDOWS

				ret = sprintf_s(p_int8, buf_left_size, "[Fatal]");

#else

				ret = snprintf(p_int8, buf_left_size, "[Fatal]");

#endif

				p_int8 += ret;
				buf_left_size -= ret;
				total_str_size += ret;

			}else
			{
				goto FIN;
			}
		}
		break;

	case LA_LOG_LEVEL_ERROR:
		{
			if( p_agent->level & LA_LOG_LEVEL_ERROR )
			{
#if RUN_OS_WINDOWS

				ret = sprintf_s(p_int8, buf_left_size, "[Error]");

#else

				ret = snprintf(p_int8, buf_left_size, "[Error]");

#endif

				p_int8 += ret;
				buf_left_size -= ret;
				total_str_size += ret;

			}else
			{
				goto FIN;
			}
		}
		break;

	case LA_LOG_LEVEL_WARN:
		{
			if( p_agent->level & LA_LOG_LEVEL_WARN )
			{
#if RUN_OS_WINDOWS

				ret = sprintf_s(p_int8, buf_left_size, "[Warn]");

#else

				ret = snprintf(p_int8, buf_left_size, "[Warn]");

#endif

				p_int8 += ret;
				buf_left_size -= ret;
				total_str_size += ret;

			}else
			{
				goto FIN;
			}
		}
		break;

	case LA_LOG_LEVEL_INFO:
		{
			if( p_agent->level & LA_LOG_LEVEL_INFO )
			{
#if RUN_OS_WINDOWS

				ret = sprintf_s(p_int8, buf_left_size, "[Info]");

#else

				ret = snprintf(p_int8, buf_left_size, "[Info]");

#endif

				p_int8 += ret;
				buf_left_size -= ret;
				total_str_size += ret;

			}else
			{
				goto FIN;
			}
		}
		break;

	case LA_LOG_LEVEL_DEBUG:
		{
			if( p_agent->level & LA_LOG_LEVEL_DEBUG )
			{
#if RUN_OS_WINDOWS

				ret = sprintf_s(p_int8, buf_left_size, "[Debug]");

#else

				ret = snprintf(p_int8, buf_left_size, "[Debug]");

#endif

				p_int8 += ret;
				buf_left_size -= ret;
				total_str_size += ret;

			}else
			{
				goto FIN;
			}
		}
		break;

	case LA_LOG_LEVEL_ACCESS:
		{
			if( p_agent->level & LA_LOG_LEVEL_ACCESS )
			{
#if RUN_OS_WINDOWS

				ret = sprintf_s(p_int8, buf_left_size, "[Access]");

#else

				ret = snprintf(p_int8, buf_left_size, "[Access]");

#endif

				p_int8 += ret;
				buf_left_size -= ret;
				total_str_size += ret;

			}else
			{
				goto FIN;
			}
		}
		break;

	default:
		{
			goto FIN;
		}
	}

#if RUN_OS_WINDOWS

	ret = sprintf_s(p_int8, buf_left_size, "[%04d-%02d-%02d %02d:%02d:%02d %03d][%s:%d][%u:%u] ",
		sys_time.wYear, sys_time.wMonth, sys_time.wDay, sys_time.wHour, sys_time.wMinute, sys_time.wSecond, sys_time.wMilliseconds,
		p_src_file, src_line, proc_id, thread_id);

#else

	ret = snprintf(p_int8, buf_left_size, "[%04d-%02d-%02d %02d:%02d:%02d %03d][%s:%d][%u] ",
		now_time.tm_year + 1900, now_time.tm_mon + 1, now_time.tm_mday, now_time.tm_hour, now_time.tm_min, now_time.tm_sec, (int)sys_time.tv_usec / 1000,
		p_src_file, src_line, thread_id);

#endif

	p_int8 += ret;
	buf_left_size -= ret;
	total_str_size += ret;

#if RUN_OS_WINDOWS

	ret = vsprintf_s(p_int8, buf_left_size, p_format, var_str);

#else

	ret = vsnprintf(p_int8, buf_left_size, p_format, var_str);

#endif

	if( ret < 0 )
	{
		goto FIN;
	}

	p_int8 += ret;
	buf_left_size -= ret;
	total_str_size += ret;

	p_agent->str_buf_size = total_str_size;
	p_agent->str_buf[total_str_size] = 0x00;

	/** output to stdout */
	if( p_agent->type & LA_LOG_TYPE_STDOUT )
	{
#if RUN_OS_WINDOWS
		//OutputDebugStringA(p_agent->str_buf);
#else
		printf(p_agent->str_buf);
#endif
	}

	/** output to file */
	if( p_agent->type & LA_LOG_TYPE_FILE )
	{
		b_need_open = 0;

#if RUN_OS_WINDOWS

		if( p_agent->h != INVALID_HANDLE_VALUE )
		{
			/** already open */
			if( p_agent->split_file_rule == LA_SPLIT_FILE_BY_TIME )
			{
				/** split by time */
				if( now >= p_agent->next_split_time )
				{
					CloseHandle(p_agent->h);
					p_agent->h = INVALID_HANDLE_VALUE;

					p_agent->split_file_seq++;
					p_agent->next_split_time += p_agent->split_time;
					b_need_open = 1;
				}

			}else
			{
				/** split by size */
			}

		}else
		{
			/** not open */
			if( p_agent->split_time < 60 )
			{
				/** split < 1 minute */
				p_agent->split_file_seq = sys_time.wSecond / p_agent->split_time;
				left_value = sys_time.wSecond % p_agent->split_time;
				p_agent->next_split_time = now - left_value + p_agent->split_time;

			}else if( p_agent->split_time < (60 * 60) )
			{
				/** split < 1 hour */
				p_agent->split_file_seq = (sys_time.wMinute * 60 + sys_time.wSecond) / p_agent->split_time;
				left_value = (sys_time.wMinute * 60 + sys_time.wSecond) % p_agent->split_time;
				p_agent->next_split_time = now - left_value + p_agent->split_time;

			}else
			{
				/** split >= 1 hour */
				p_agent->split_file_seq = (sys_time.wHour * 60 * 60 + sys_time.wMinute * 60 + sys_time.wSecond) / p_agent->split_time;
				left_value = (sys_time.wHour * 60 * 60 + sys_time.wMinute * 60 + sys_time.wSecond) % p_agent->split_time;
				p_agent->next_split_time = now - left_value + p_agent->split_time;
			}

			b_need_open = 1;
		}

		if( b_need_open )
		{
			/** open file */
			ret = log_agent_open_fileA(p_agent);
			if( ret )
			{
				goto FIN;
			}

			seek_pos.QuadPart = 0;
			ret = SetFilePointerEx(p_agent->h, seek_pos, (LARGE_INTEGER*)&file_pos, FILE_END);
		}

		ret = WriteFile(p_agent->h, p_agent->str_buf, p_agent->str_buf_size, (DWORD*)&write_size, NULL);

#else

		if( p_agent->fd > 0 )
		{
			/** already open */
			if( p_agent->split_file_rule == LA_SPLIT_FILE_BY_TIME )
			{
				if( now >= p_agent->next_split_time )
				{
					close(p_agent->fd);
					p_agent->fd = -1;

					p_agent->split_file_seq++;
					p_agent->next_split_time += p_agent->split_time;
					b_need_open = 1;
				}
			}

		}else
		{
			if( p_agent->split_time < 60 )
			{
				/** split < 1 minute */
				p_agent->split_file_seq = now_time.tm_sec / p_agent->split_time;
				left_value = now_time.tm_sec % p_agent->split_time;
				p_agent->next_split_time = now - left_value + p_agent->split_time;

			}else if( p_agent->split_time < (60 * 60) )
			{
				/** split < 1 hour */
				p_agent->split_file_seq = (now_time.tm_min * 60 + now_time.tm_sec) / p_agent->split_time;
				left_value = (now_time.tm_min * 60 + now_time.tm_sec) % p_agent->split_time;
				p_agent->next_split_time = now - left_value + p_agent->split_time;

			}else
			{
				/** split >= 1 hour */
				p_agent->split_file_seq = (now_time.tm_hour * 60 * 60 + now_time.tm_min * 60 + now_time.tm_sec) / p_agent->split_time;
				left_value = (now_time.tm_hour * 60 * 60 + now_time.tm_min * 60 + now_time.tm_sec) % p_agent->split_time;
				p_agent->next_split_time = now - left_value + p_agent->split_time;
			}

			b_need_open = 1;
		}

		if( b_need_open )
		{
			/** open file */
			ret = log_agent_open_fileA(p_agent);
			if( ret )
			{
				goto FIN;
			}

			ret = lseek(p_agent->fd, 0, SEEK_END);
		}

		ret = write(p_agent->fd, p_agent->str_buf, p_agent->str_buf_size);
		//printf("fd = %d, write ret = %d\n", p_agent->fd, ret);

#endif
	}

	/** output to sock */
	if( p_agent->type & LA_LOG_TYPE_SOCK )
	{
#if LA_ENABLE_NETWORK

		if( p_agent->sock == -1 )
		{
			ret = log_agent_open_sock(p_agent);
			if( ret )
			{
				goto FIN;
			}
		}

		ret = log_agent_sendto_sock(p_agent, p_agent->str_buf, p_agent->str_buf_size);

#endif
	}

FIN:

#if RUN_OS_WINDOWS

	LeaveCriticalSection(&p_agent->cs);

#else

	pthread_mutex_unlock(&p_agent->mutex);

#endif

	return GEN_S_OK;
}
コード例 #28
0
ファイル: log_agent.c プロジェクト: mf0324/Code_Learn
/**  
 * @brief output to buf(unicode)
 * @param [in] p_agent, agent
 * @param [in] level, log level
 * @param [in] p_src_file, src file that call this func
 * @param [in] src_line, src line that call this func
 * @param [in] p_buf, output buf
 * @param [in/out] p_buf_size, output buf size/actual use size
 * @param [in] p_format, format string
 * @param [in] var_str, var string
 * @return
 * 0: success
 * other: fail
 * @remark
 * 1. buf size count in bytes!
 */
static inline int32 log_agent_output2bufW(LOG_AGENT* p_agent, uint32 level, wchar_t* p_src_file, int32 src_line, int8* p_buf, int32* p_buf_size, wchar_t* p_format, va_list var_str)
{
	wchar_t*  p_char = NULL;
	int32  buf_left_size;
	int32  char_buf_left_size;
	int32  total_str_size;


	SYSTEMTIME sys_time;
	struct tm  now_time;
	uint32 proc_id;
	uint32 thread_id;

	LARGE_INTEGER seek_pos;
	int64  file_pos;

	int64  now;
	int32  left_value;
	int32  b_need_open;
	uint32 write_size;
	int32  ret;

	_time64(&now);
	ret = _localtime64_s(&now_time, &now);
	GetLocalTime(&sys_time);
	proc_id = GetCurrentProcessId();
	thread_id = GetCurrentThreadId();

	EnterCriticalSection(&p_agent->cs);

	p_agent->now_time_year = sys_time.wYear;
	p_agent->now_time_month = sys_time.wMonth;
	p_agent->now_time_day = sys_time.wDay;
	p_agent->now_time_hour = sys_time.wHour;

	p_char = (wchar_t*)p_buf;
	buf_left_size = *p_buf_size;
	char_buf_left_size = buf_left_size / sizeof(wchar_t);
	total_str_size = 0;

	switch( level )
	{
	case LA_LOG_LEVEL_FATAL:
		{
			if( p_agent->level & LA_LOG_LEVEL_FATAL )
			{
				ret = swprintf_s(p_char, char_buf_left_size, L"[Fatal]");

				p_char += ret;
				char_buf_left_size -= ret;
				buf_left_size -= (ret * sizeof(wchar_t));
				total_str_size += ret;

			}else
			{
				goto FIN;
			}
		}
		break;

	case LA_LOG_LEVEL_ERROR:
		{
			if( p_agent->level & LA_LOG_LEVEL_ERROR )
			{
				ret = swprintf_s(p_char, char_buf_left_size, L"[Error]");

				p_char += ret;
				char_buf_left_size -= ret;
				buf_left_size -= (ret * sizeof(wchar_t));
				total_str_size += ret;

			}else
			{
				goto FIN;
			}
		}
		break;

	case LA_LOG_LEVEL_WARN:
		{
			if( p_agent->level & LA_LOG_LEVEL_WARN )
			{
				ret = swprintf_s(p_char, char_buf_left_size, L"[Warn]");

				p_char += ret;
				char_buf_left_size -= ret;
				buf_left_size -= (ret * sizeof(wchar_t));
				total_str_size += ret;

			}else
			{
				goto FIN;
			}
		}
		break;

	case LA_LOG_LEVEL_INFO:
		{
			if( p_agent->level & LA_LOG_LEVEL_INFO )
			{
				ret = swprintf_s(p_char, char_buf_left_size, L"[Info]");

				p_char += ret;
				char_buf_left_size -= ret;
				buf_left_size -= (ret * sizeof(wchar_t));
				total_str_size += ret;

			}else
			{
				goto FIN;
			}
		}
		break;

	case LA_LOG_LEVEL_DEBUG:
		{
			if( p_agent->level & LA_LOG_LEVEL_DEBUG )
			{
				ret = swprintf_s(p_char, char_buf_left_size, L"[Debug]");

				p_char += ret;
				char_buf_left_size -= ret;
				buf_left_size -= (ret * sizeof(wchar_t));
				total_str_size += ret;

			}else
			{
				goto FIN;
			}
		}
		break;

	case LA_LOG_LEVEL_ACCESS:
		{
			if( p_agent->level & LA_LOG_LEVEL_ACCESS )
			{
				ret = swprintf_s(p_char, char_buf_left_size, L"[Access]");

				p_char += ret;
				char_buf_left_size -= ret;
				buf_left_size -= (ret * sizeof(wchar_t));
				total_str_size += ret;

			}else
			{
				goto FIN;
			}
		}
		break;

	default:
		{
			goto FIN;
		}
	}

	ret = swprintf_s(p_char, char_buf_left_size, L"[%04d-%02d-%02d %02d:%02d:%02d %03d][%s:%d][%u:%u] ",
		sys_time.wYear, sys_time.wMonth, sys_time.wDay, sys_time.wHour, sys_time.wMinute, sys_time.wSecond, sys_time.wMilliseconds,
		p_src_file, src_line, proc_id, thread_id);

	p_char += ret;
	char_buf_left_size -= ret;
	buf_left_size -= (ret * sizeof(wchar_t));
	total_str_size += ret;

	ret = vswprintf_s(p_char, char_buf_left_size, p_format, var_str);

	if( ret < 0 )
	{
		goto FIN;
	}

	p_char += ret;
	char_buf_left_size -= ret;
	buf_left_size -= (ret * sizeof(wchar_t));
	total_str_size += ret;

FIN:

	LeaveCriticalSection(&p_agent->cs);

	*p_buf_size = total_str_size * sizeof(wchar_t);
	p_char = (wchar_t*)p_buf;
	p_char[total_str_size] = 0x00;

	return GEN_S_OK;
}
コード例 #29
0
ファイル: log_agent.c プロジェクト: mf0324/Code_Learn
/**  
 * @brief output(unicode)
 * @param [in] p_agent, agent
 * @param [in] level, log level
 * @param [in] p_src_file, src file that call this func
 * @param [in] src_line, src line that call this func
 * @param [in] p_format, format string
 * @param [in] var_str, var string
 * @return
 * 0: success
 * other: fail
 */
static inline int32 log_agent_outputW(LOG_AGENT* p_agent, uint32 level, wchar_t* p_src_file, int32 src_line, wchar_t* p_format, va_list var_str)
{
	//int8*  p_int8 = NULL;
	wchar_t*  p_char = NULL;
	int32  buf_left_size;
	int32  char_buf_left_size;
	int32  total_str_size;


	SYSTEMTIME sys_time;
	struct tm  now_time;
	uint32 proc_id;
	uint32 thread_id;

	LARGE_INTEGER seek_pos;
	int64  file_pos;

	int64  now;
	int32  left_value;
	int32  b_need_open;
	uint32 write_size;
	int32  ret;

	_time64(&now);
	ret = _localtime64_s(&now_time, &now);
	GetLocalTime(&sys_time);
	proc_id = GetCurrentProcessId();
	thread_id = GetCurrentThreadId();

	EnterCriticalSection(&p_agent->cs);

	p_agent->now_time_year = sys_time.wYear;
	p_agent->now_time_month = sys_time.wMonth;
	p_agent->now_time_day = sys_time.wDay;
	p_agent->now_time_hour = sys_time.wHour;

	p_char = (wchar_t*)p_agent->str_buf;
	buf_left_size = LA_MAX_LOG_STRING_SIZE;
	char_buf_left_size = buf_left_size / sizeof(wchar_t);
	total_str_size = 0;

	switch( level )
	{
	case LA_LOG_LEVEL_FATAL:
		{
			if( p_agent->level & LA_LOG_LEVEL_FATAL )
			{
				ret = swprintf_s(p_char, char_buf_left_size, L"[Fatal]");

				p_char += ret;
				char_buf_left_size -= ret;
				buf_left_size -= (ret * sizeof(wchar_t));
				total_str_size += ret;

			}else
			{
				goto FIN;
			}
		}
		break;

	case LA_LOG_LEVEL_ERROR:
		{
			if( p_agent->level & LA_LOG_LEVEL_ERROR )
			{
				ret = swprintf_s(p_char, char_buf_left_size, L"[Error]");

				p_char += ret;
				char_buf_left_size -= ret;
				buf_left_size -= (ret * sizeof(wchar_t));
				total_str_size += ret;

			}else
			{
				goto FIN;
			}
		}
		break;

	case LA_LOG_LEVEL_WARN:
		{
			if( p_agent->level & LA_LOG_LEVEL_WARN )
			{
				ret = swprintf_s(p_char, char_buf_left_size, L"[Warn]");

				p_char += ret;
				char_buf_left_size -= ret;
				buf_left_size -= (ret * sizeof(wchar_t));
				total_str_size += ret;

			}else
			{
				goto FIN;
			}
		}
		break;

	case LA_LOG_LEVEL_INFO:
		{
			if( p_agent->level & LA_LOG_LEVEL_INFO )
			{
				ret = swprintf_s(p_char, char_buf_left_size, L"[Info]");

				p_char += ret;
				char_buf_left_size -= ret;
				buf_left_size -= (ret * sizeof(wchar_t));
				total_str_size += ret;

			}else
			{
				goto FIN;
			}
		}
		break;

	case LA_LOG_LEVEL_DEBUG:
		{
			if( p_agent->level & LA_LOG_LEVEL_DEBUG )
			{
				ret = swprintf_s(p_char, char_buf_left_size, L"[Debug]");

				p_char += ret;
				char_buf_left_size -= ret;
				buf_left_size -= (ret * sizeof(wchar_t));
				total_str_size += ret;

			}else
			{
				goto FIN;
			}
		}
		break;

	case LA_LOG_LEVEL_ACCESS:
		{
			if( p_agent->level & LA_LOG_LEVEL_ACCESS )
			{
				ret = swprintf_s(p_char, char_buf_left_size, L"[Access]");

				p_char += ret;
				char_buf_left_size -= ret;
				buf_left_size -= (ret * sizeof(wchar_t));
				total_str_size += ret;

			}else
			{
				goto FIN;
			}
		}
		break;

	default:
		{
			goto FIN;
		}
	}

	ret = swprintf_s(p_char, char_buf_left_size, L"[%04d-%02d-%02d %02d:%02d:%02d %03d][%s:%d][%u:%u] ",
		sys_time.wYear, sys_time.wMonth, sys_time.wDay, sys_time.wHour, sys_time.wMinute, sys_time.wSecond, sys_time.wMilliseconds,
		p_src_file, src_line, proc_id, thread_id);

	p_char += ret;
	char_buf_left_size -= ret;
	buf_left_size -= (ret * sizeof(wchar_t));
	total_str_size += ret;

	ret = vswprintf_s(p_char, char_buf_left_size, p_format, var_str);

	if( ret < 0 )
	{
		goto FIN;
	}

	p_char += ret;
	char_buf_left_size -= ret;
	buf_left_size -= (ret * sizeof(wchar_t));
	total_str_size += ret;

	p_agent->str_buf_size = total_str_size * sizeof(wchar_t);
	p_char = (wchar_t*)p_agent->str_buf;
	p_char[total_str_size] = 0x0;

	/** output to stdout */
	if( p_agent->type & LA_LOG_TYPE_STDOUT )
	{
		//OutputDebugStringW((wchar_t*)p_agent->str_buf);
	}

	/** output to file */
	if( p_agent->type & LA_LOG_TYPE_FILE )
	{
		b_need_open = 0;

		if( p_agent->h != INVALID_HANDLE_VALUE )
		{
			/** already open */
			if( p_agent->split_file_rule == LA_SPLIT_FILE_BY_TIME )
			{
				if( now >= p_agent->next_split_time )
				{
					CloseHandle(p_agent->h);
					p_agent->h = INVALID_HANDLE_VALUE;

					p_agent->split_file_seq++;
					p_agent->next_split_time += p_agent->split_time;
					b_need_open = 1;
				}

			}else
			{
			}

		}else
		{
			/** not open */
			if( p_agent->split_time < 60 )
			{
				/** split < 1 minute */
				p_agent->split_file_seq = sys_time.wSecond / p_agent->split_time;
				left_value = sys_time.wSecond % p_agent->split_time;
				p_agent->next_split_time = now - left_value + p_agent->split_time;

			}else if( p_agent->split_time < (60 * 60) )
			{
				/** split < 1 hour */
				p_agent->split_file_seq = (sys_time.wMinute * 60 + sys_time.wSecond) / p_agent->split_time;
				left_value = (sys_time.wMinute * 60 + sys_time.wSecond) % p_agent->split_time;
				p_agent->next_split_time = now - left_value + p_agent->split_time;

			}else
			{
				/** split >= 1 hour */
				p_agent->split_file_seq = (sys_time.wHour * 60 * 60 + sys_time.wMinute * 60 + sys_time.wSecond) / p_agent->split_time;
				left_value = (sys_time.wHour * 60 * 60 + sys_time.wMinute * 60 + sys_time.wSecond) % p_agent->split_time;
				p_agent->next_split_time = now - left_value + p_agent->split_time;
			}

			b_need_open = 1;
		}

		if( b_need_open )
		{
			/** open file */
			ret = log_agent_open_fileW(p_agent);
			if( ret )
			{
				goto FIN;
			}

			seek_pos.QuadPart = 0;
			ret = SetFilePointerEx(p_agent->h, seek_pos, (LARGE_INTEGER*)&file_pos, FILE_END);
		}

		ret = WriteFile(p_agent->h, p_agent->str_buf, p_agent->str_buf_size, (DWORD*)&write_size, NULL);
	}

	/** output to sock */
	if( p_agent->type & LA_LOG_TYPE_SOCK )
	{
#if LA_ENABLE_NETWORK

		if( p_agent->sock == -1 )
		{
			ret = log_agent_open_sock(p_agent);
			if( ret )
			{
				goto FIN;
			}
		}

		ret = log_agent_sendto_sock(p_agent, p_agent->str_buf, p_agent->str_buf_size);

#endif
	}

FIN:

	LeaveCriticalSection(&p_agent->cs);

	return GEN_S_OK;
}
コード例 #30
0
void CMasterServerConfig::LoadRentConfig()
{

	CWOBackendReq req("api_GetRentServers.aspx");
	req.AddParam("411", "1");

	if(!req.Issue())
	{
		r3dOutToLog("Read RentServers FAILED, code: %d\n", req.resultCode_);
		return;
	}

	pugi::xml_document xmlFile;
	req.ParseXML(xmlFile);
	pugi::xml_node xmlSafelock = xmlFile.child("Rent_Servers");
	
	while(!xmlSafelock.empty())
	{
		r3dPoint3D Position;
		char Password[512];
		char Name[512];
		char MapSettings[512];
		
        uint32_t gameServerId = xmlSafelock.attribute("gameServerId").as_uint();
	    r3dscpy(MapSettings,xmlSafelock.attribute("MapSettings").value());
	    uint32_t Region = xmlSafelock.attribute("Region").as_uint();
	    r3dscpy(Name, xmlSafelock.attribute("Name").value());
	    uint32_t MapID = xmlSafelock.attribute("MapID").as_uint();
	    r3dscpy(Password, xmlSafelock.attribute("Password").value());
	    uint32_t MaxPlayers = xmlSafelock.attribute("MaxPlayers").as_uint();
	    uint32_t Owner = xmlSafelock.attribute("Owner").as_uint();
	    uint32_t ExpireTime = xmlSafelock.attribute("ExpireTime").as_uint();
	    uint32_t RentalTime = xmlSafelock.attribute("RentalTime").as_uint();
		uint32_t Crosshair = xmlSafelock.attribute("Crosshair").as_uint();
		uint32_t SNP = xmlSafelock.attribute("SNP").as_uint();

		if(!gMasterGameServer.IsGameServerIdStarted((int)gameServerId))
		{
			r3dOutToLog("Loading Rent Server %i.......\n",gameServerId);
			__int64 secs1 = _time64(&secs1);
			if (secs1<ExpireTime)
			{
				GBGameInfo ginfo;
				ginfo.expirein = ExpireTime;
				strcpy(ginfo.name,Name);
				strcpy(ginfo.PasswordGame,Password);
				ginfo.mapId = MapID;
				ginfo.region = Region;
				ginfo.maxPlayers = MaxPlayers;
				ginfo.ownercustomerid = Owner;
				strcpy(ginfo.MapSettings,MapSettings);
				ginfo.gameServerId = gameServerId;
				ginfo.enableCrosshair = ((int)Crosshair == 1)?true:false;
				ginfo.enableSnipers = ((int)SNP == 1)?true:false;

				CMSNewGameData ngd(ginfo, "", 0);
				DWORD ip;
				DWORD port;
				__int64 sessionId;
				gMasterGameServer.CreateNewGame(ngd, &ip, &port, &sessionId);
				r3dOutToLog("Rent Server ID %i is loaded\n",gameServerId);
			}
			/*else {
				DeleteRentServer(gameServerId);
			}*/
		}
		xmlSafelock = xmlSafelock.next_sibling();
	}
}