/// ---------------- ClientOnlineRecord operation ---------------- bool DBHandler::InsertClientOnlineRecord(const TOnlineRecordItem &item) { bool bResult = false; if (NULL != m_pDBSpool){ char cStart[32]; GetLocalTimeString(cStart, sizeof(cStart), item.start); char cEnd[32]; GetLocalTimeString(cEnd, sizeof(cEnd), item.end); char cSQLBuffer[BUFFER_SIZE_2K]; snprintf(cSQLBuffer, sizeof(cSQLBuffer), "INSERT INTO %s(%s,%s,%s,%s,%s,%s,%s) VALUES('%s','%s',%d,'%s','%s',%d,%d)" , CLIENT_ONLINE_RECORD_TABLE , CORT_TOKENID_FIELD, CORT_IP_FIELD, CORT_PORT_FIELD, CORT_START_FIELD, CORT_END_FIELD, CORT_OFFLINEMSG_FIELD, CORT_ONLINEMSG_FIELD , item.tokenid.c_str(), item.ip.c_str(), item.port, cStart, cEnd, item.offlineMsg, item.onlineMsg); MYSQL_RES* pSQLRes = NULL; short shIdt = 0; int iRows = 0; bResult = (SQL_TYPE_INSERT == m_pDBSpool->ExecuteSQL(cSQLBuffer, &pSQLRes, shIdt, iRows)); m_pDBSpool->ReleaseConnection(shIdt); } if (!bResult){ gvLog(LOG_ERR_USER, "(DBHandler::InsertClientOnlineRecord) ERR: m_pDBSpool is NULL"); } return bResult; }
// // CFunctionUseLogger::MaybeFlush // void CFunctionUseLogger::MaybeFlush( bool bForce ) { CTickCount timeNow = CTickCount::Now(); for( std::map < SString, SFuncCallRecord >::iterator iter = m_FuncCallRecordMap.begin() ; iter != m_FuncCallRecordMap.end() ; ) { const SFuncCallRecord& callRecord = iter->second; // Time to flush this line? if ( bForce || ( timeNow - callRecord.timeFirstUsed ).ToInt() > 1500 ) { // Add log line SString strMessage( "%s - %s - %s x %d [%s]\n" , *GetLocalTimeString( true, true ) , *callRecord.strResourceName , *callRecord.strFunctionName , callRecord.uiCallCount , *callRecord.strExampleArgs ); if ( !m_strLogFilename.empty() ) FileAppend( m_strLogFilename, strMessage ); m_FuncCallRecordMap.erase( iter++ ); } else ++iter; } }
/////////////////////////////////////////////////////////////// // // CDatabaseJobQueueImpl::LogResult // // Log last job if connection has logging enabled // /////////////////////////////////////////////////////////////// void CDatabaseJobQueueImpl::LogResult ( CDbJobData* pJobData ) { // Early out if logging switched off globally if ( m_LogLevel == EJobLogLevel::NONE ) return; // Check logging status of connection CDatabaseConnection* pConnection = GetConnectionFromHandle ( pJobData->command.connectionHandle ); if ( !pConnection || !pConnection->m_bLoggingEnabled ) return; if ( pJobData->result.status == EJobResult::SUCCESS ) { if ( m_LogLevel >= EJobLogLevel::ALL ) { SString strLine ( "%s: [%s] SUCCESS: Affected rows:%d [Query:%s]\n" , *GetLocalTimeString ( true, true ) , *pConnection->m_strLogTag , pJobData->result.registryResult->uiNumAffectedRows , *pJobData->GetCommandStringForLog() ); LogString ( strLine ); } } else { if ( m_LogLevel >= EJobLogLevel::ERRORS ) { // Suppress requested errors unless logging is set to ALL if ( pJobData->result.bErrorSuppressed && m_LogLevel != EJobLogLevel::ALL ) return; SString strLine ( "%s: [%s] FAIL: (%d) %s [Query:%s]\n" , *GetLocalTimeString ( true, true ) , *pConnection->m_strLogTag , pJobData->result.uiErrorCode , *pJobData->result.strReason , *pJobData->GetCommandStringForLog() ); LogString ( strLine ); } } }
// // Output timestamped line into the debugger // void SharedUtil::OutputReleaseLine ( const char* szMessage ) { SString strMessage = GetLocalTimeString ( false, true ) + " - " + szMessage; if ( strMessage.length () > 0 && strMessage[ strMessage.length () - 1 ] != '\n' ) strMessage += "\n"; #ifdef _WIN32 OutputDebugString ( strMessage ); #else // Other platforms here #endif }
/////////////////////////////////////////////////////////////// // // CPerfStatDebugInfoImpl::AddLine // // // /////////////////////////////////////////////////////////////// void CPerfStatDebugInfoImpl::AddLine ( const SString& strSection, const SString& strData ) { if ( !IsActive ( strSection ) ) return; SLineInfo info; info.strSection = strSection; info.strHead = SString ( "%s - %s" , *GetLocalTimeString ( true, true ) , *strSection ); info.strData = strData; m_LineList.push_back ( info ); while ( m_LineList.size () > 50 ) m_LineList.pop_front (); }
// // Output timestamped line into the debugger // void SharedUtil::OutputDebugLine ( const char* szMessage ) { if ( szMessage[0] == '[' ) { // Filter test const char* szEnd = strchr ( szMessage, ']' ); if ( szEnd && IsDebugTagHidden ( std::string ( szMessage + 1, szEnd - szMessage - 1 ) ) ) return; } SString strMessage = GetLocalTimeString ( false, true ) + " - " + szMessage; if ( strMessage.length () > 0 && strMessage[ strMessage.length () - 1 ] != '\n' ) strMessage += "\n"; #ifdef _WIN32 OutputDebugString ( strMessage ); #else // Other platforms here #endif }
/////////////////////////////////////////////////////////////// // // CResource::HandleAclRequestChange // // Update an existing valid acl request // Returns true if the acl request was changed // /////////////////////////////////////////////////////////////// bool CResource::HandleAclRequestChange ( const CAclRightName& rightName, bool bAccess, const SString& strWho ) { // Get current request SAclRequest currentRequest ( rightName ); if ( !FindAclRequest ( currentRequest ) ) return false; // Check access is changing if ( !currentRequest.bPending && currentRequest.bAccess == bAccess ) return false; // Update currentRequest.bAccess = bAccess; currentRequest.bPending = false; currentRequest.strWho = strWho; currentRequest.strDate = GetLocalTimeString ( true ); CommitAclRequest ( currentRequest ); SString strOutput; strOutput += SString( "aclrequest: %s", GetName ().c_str () ); strOutput += SString( " %s changed to %s (%s)", *rightName.GetFullName (), bAccess ? "allow" : "deny", *strWho ); CLogger::LogPrintf ( strOutput + "\n" ); return true; }
/////////////////////////////////////////////////////////////// // // CPerfStatServerInfoImpl::GetStats // // // /////////////////////////////////////////////////////////////// void CPerfStatServerInfoImpl::GetStats ( CPerfStatResult* pResult, const std::map < SString, int >& strOptionMap, const SString& strFilter ) { // // Set option flags // bool bHelp = MapContains ( strOptionMap, "h" ); bool bIncludeDebugInfo = MapContains ( strOptionMap, "d" ); // // Process help // if ( bHelp ) { pResult->AddColumn ( "Server info help" ); pResult->AddRow ()[0] ="Option h - This help"; pResult->AddRow ()[0] ="Option d - Include debug info"; return; } // Calculate current rates long long llIncomingBytesPS = CPerfStatManager::GetPerSecond ( m_llDeltaGameBytesRecv, m_DeltaTickCount.ToLongLong () ); long long llIncomingBytesPSBlocked = CPerfStatManager::GetPerSecond ( m_llDeltaGameBytesRecvBlocked, m_DeltaTickCount.ToLongLong () ); long long llOutgoingBytesPS = CPerfStatManager::GetPerSecond ( m_llDeltaGameBytesSent, m_DeltaTickCount.ToLongLong () ); long long llOutgoingBytesResentPS = CPerfStatManager::GetPerSecond ( m_llDeltaGameBytesResent, m_DeltaTickCount.ToLongLong () ); SString strIncomingPacketsPS = CPerfStatManager::GetPerSecondString ( m_llDeltaGamePacketsRecv, m_DeltaTickCount.ToDouble () ); SString strIncomingPacketsPSBlocked = CPerfStatManager::GetPerSecondString ( m_llDeltaGamePacketsRecvBlocked, m_DeltaTickCount.ToDouble () ); SString strOutgoingPacketsPS = CPerfStatManager::GetPerSecondString ( m_llDeltaGamePacketsSent, m_DeltaTickCount.ToDouble () ); SString strOutgoingMessagesResentPS = CPerfStatManager::GetPerSecondString ( m_llDeltaGameMessagesResent, m_DeltaTickCount.ToDouble () ); // Estimate total network usage long long llIncomingPacketsPS = CPerfStatManager::GetPerSecond ( m_llDeltaGamePacketsRecv, m_DeltaTickCount.ToLongLong () ); long long llIncomingPacketsPSBlocked = CPerfStatManager::GetPerSecond ( m_llDeltaGamePacketsRecvBlocked, m_DeltaTickCount.ToLongLong () ); long long llOutgoingPacketsPS = CPerfStatManager::GetPerSecond ( m_llDeltaGamePacketsSent, m_DeltaTickCount.ToLongLong () ); long long llNetworkUsageBytesPS = ( llIncomingPacketsPS + llOutgoingPacketsPS ) * UDP_PACKET_OVERHEAD + llIncomingBytesPS + llOutgoingBytesPS; long long llNetworkUsageBytesPSInclBlocked = ( llIncomingPacketsPS + llIncomingPacketsPSBlocked + llOutgoingPacketsPS ) * UDP_PACKET_OVERHEAD + llIncomingBytesPS + llIncomingBytesPSBlocked + llOutgoingBytesPS; // Calculate uptime time_t tUptime = time ( NULL ) - m_tStartTime; time_t tDays = tUptime / ( 60 * 60 * 24 ); tUptime = tUptime % ( 60 * 60 * 24 ); time_t tHours = tUptime / ( 60 * 60 ); tUptime = tUptime % ( 60 * 60 ); time_t tMinutes = tUptime / ( 60 ); SString strNone; CMainConfig* pConfig = g_pGame->GetConfig (); m_InfoList.clear (); m_StatusList.clear (); m_OptionsList.clear (); // Fill info lists m_InfoList.push_back ( StringPair ( "Platform", CStaticFunctionDefinitions::GetOperatingSystemName () ) ); m_InfoList.push_back ( StringPair ( "Version", CStaticFunctionDefinitions::GetVersionSortable () ) ); m_InfoList.push_back ( StringPair ( "Date", GetLocalTimeString ( true ) ) ); m_InfoList.push_back ( StringPair ( "Uptime", SString ( "%d Days %d Hours %02d Mins", (int)tDays, (int)tHours, (int)tMinutes ) ) ); m_InfoList.push_back ( StringPair ( "Memory", GetProcessMemoryUsage() ) ); if ( !pConfig->GetThreadNetEnabled () ) m_StatusList.push_back ( StringPair ( "Server FPS", SString ( "%d", g_pGame->GetServerFPS () ) ) ); else m_StatusList.push_back ( StringPair ( "Server FPS sync (logic)", SString ( "%3d (%d)", g_pGame->GetSyncFPS (), g_pGame->GetServerFPS () ) ) ); m_StatusList.push_back ( StringPair ( "Players", SString ( "%d / %d", g_pGame->GetPlayerManager ()->Count (), pConfig->GetMaxPlayers () ) ) ); m_StatusList.push_back ( StringPair ( "Bytes/sec incoming", CPerfStatManager::GetScaledByteString ( llIncomingBytesPS ) ) ); m_StatusList.push_back ( StringPair ( "Bytes/sec outgoing", CPerfStatManager::GetScaledByteString ( llOutgoingBytesPS ) ) ); m_StatusList.push_back ( StringPair ( "Packets/sec incoming", strIncomingPacketsPS ) ); m_StatusList.push_back ( StringPair ( "Packets/sec outgoing", strOutgoingPacketsPS ) ); m_StatusList.push_back ( StringPair ( "Packet loss outgoing", CPerfStatManager::GetPercentString ( llOutgoingBytesResentPS, llOutgoingBytesPS ) ) ); m_StatusList.push_back ( StringPair ( "Approx network usage", CPerfStatManager::GetScaledBitString ( llNetworkUsageBytesPS * 8LL ) + "/s" ) ); if ( pConfig->GetThreadNetEnabled () ) { m_StatusList.push_back ( StringPair ( "Msg queue incoming", SString ( "%d", CNetBufferWatchDog::ms_uiInResultQueueSize ) ) ); if ( bIncludeDebugInfo ) m_StatusList.push_back ( StringPair ( " finished incoming", SString ( "%d", CNetBufferWatchDog::ms_uiFinishedListSize ) ) ); m_StatusList.push_back ( StringPair ( "Msg queue outgoing", SString ( "%d", CNetBufferWatchDog::ms_uiOutCommandQueueSize ) ) ); if ( bIncludeDebugInfo ) m_StatusList.push_back ( StringPair ( " finished outgoing", SString ( "%d", CNetBufferWatchDog::ms_uiOutResultQueueSize ) ) ); } if ( ASE* pAse = ASE::GetInstance() ) m_StatusList.push_back ( StringPair ( "ASE queries", SString ( "%d (%d/min)", pAse->GetTotalQueryCount (), pAse->GetQueriesPerMinute () ) ) ); m_OptionsList.push_back ( StringPair ( "MinClientVersion", g_pGame->CalculateMinClientRequirement () ) ); m_OptionsList.push_back ( StringPair ( "RecommendedClientVersion", pConfig->GetRecommendedClientVersion () ) ); m_OptionsList.push_back ( StringPair ( "NetworkEncryptionEnabled", SString ( "%d", pConfig->GetNetworkEncryptionEnabled () ) ) ); m_OptionsList.push_back ( StringPair ( "VoiceEnabled", SString ( "%d", pConfig->IsVoiceEnabled () ) ) ); m_OptionsList.push_back ( StringPair ( "Busy sleep time", SString ( "%d ms", pConfig->GetPendingWorkToDoSleepTime () ) ) ); m_OptionsList.push_back ( StringPair ( "Idle sleep time", SString ( "%d ms", pConfig->GetNoWorkToDoSleepTime () ) ) ); m_OptionsList.push_back ( StringPair ( "BandwidthReductionMode", pConfig->GetSetting ( "bandwidth_reduction" ) ) ); m_OptionsList.push_back ( StringPair ( "LightSyncEnabled", SString ( "%d", g_pBandwidthSettings->bLightSyncEnabled ) ) ); m_OptionsList.push_back ( StringPair ( "ThreadNetEnabled", SString ( "%d", pConfig->GetThreadNetEnabled () ) ) ); const static CTickRateSettings defaultRates; if ( defaultRates.iPureSync != g_TickRateSettings.iPureSync ) m_OptionsList.push_back ( StringPair ( "Player sync interval", SString ( "%d", g_TickRateSettings.iPureSync ) ) ); if ( defaultRates.iLightSync != g_TickRateSettings.iLightSync ) m_OptionsList.push_back ( StringPair ( "Lightweight sync interval", SString ( "%d", g_TickRateSettings.iLightSync ) ) ); if ( defaultRates.iCamSync != g_TickRateSettings.iCamSync ) m_OptionsList.push_back ( StringPair ( "Camera sync interval", SString ( "%d", g_TickRateSettings.iCamSync ) ) ); if ( defaultRates.iPedSync != g_TickRateSettings.iPedSync ) m_OptionsList.push_back ( StringPair ( "Ped sync interval", SString ( "%d", g_TickRateSettings.iPedSync ) ) ); if ( defaultRates.iUnoccupiedVehicle != g_TickRateSettings.iUnoccupiedVehicle ) m_OptionsList.push_back ( StringPair ( "Unocc. veh. sync interval", SString ( "%d", g_TickRateSettings.iUnoccupiedVehicle ) ) ); if ( defaultRates.iKeySyncRotation != g_TickRateSettings.iKeySyncRotation ) m_OptionsList.push_back ( StringPair ( "Keysync mouse sync interval", SString ( "%d", g_TickRateSettings.iKeySyncRotation ) ) ); if ( defaultRates.iKeySyncAnalogMove != g_TickRateSettings.iKeySyncAnalogMove ) m_OptionsList.push_back ( StringPair ( "Keysync analog sync interval", SString ( "%d", g_TickRateSettings.iKeySyncAnalogMove ) ) ); if ( defaultRates.iKeySyncAnalogMove != g_TickRateSettings.iNearListUpdate ) m_OptionsList.push_back ( StringPair ( "Update near interval", SString ( "%d", g_TickRateSettings.iNearListUpdate ) ) ); if ( bIncludeDebugInfo ) { m_StatusList.push_back ( StringPair ( "Bytes/sec outgoing resent", CPerfStatManager::GetScaledByteString ( llOutgoingBytesResentPS ) ) ); m_StatusList.push_back ( StringPair ( "Msgs/sec outgoing resent", strOutgoingMessagesResentPS ) ); m_StatusList.push_back ( StringPair ( "Bytes/sec blocked", CPerfStatManager::GetScaledByteString ( llIncomingBytesPSBlocked ) ) ); m_StatusList.push_back ( StringPair ( "Packets/sec blocked", strIncomingPacketsPSBlocked ) ); m_StatusList.push_back ( StringPair ( "Usage incl. blocked", CPerfStatManager::GetScaledBitString ( llNetworkUsageBytesPSInclBlocked * 8LL ) + "/s" ) ); m_OptionsList.push_back ( StringPair ( "Main (Logic) core #", SString ( "%d", _GetCurrentProcessorNumber () ) ) ); m_OptionsList.push_back ( StringPair ( "Threadnet (Sync) core #", SString ( "%d", g_uiThreadnetProcessorNumber ) ) ); m_OptionsList.push_back ( StringPair ( "Raknet thread core #", SString ( "%d", m_PrevLiveStats.uiNetworkUpdateLoopProcessorNumber ) ) ); m_OptionsList.push_back ( StringPair ( "DB thread core #", SString ( "%d", g_uiDatabaseThreadProcessorNumber ) ) ); // Get net performance stats if ( m_NetPerformanceStatsUpdateTimer.Get() > 2000 ) { m_NetPerformanceStatsUpdateTimer.Reset(); g_pNetServer->GetNetPerformanceStatistics ( &m_NetPerformanceStats, true ); } m_OptionsList.push_back ( StringPair ( "Update cycle prep time max", SString ( "%s ms (Avg %s ms)", *CPerfStatManager::GetScaledFloatString( m_NetPerformanceStats.uiUpdateCyclePrepTimeMaxUs / 1000.f ), *CPerfStatManager::GetScaledFloatString( m_NetPerformanceStats.uiUpdateCyclePrepTimeAvgUs / 1000.f ) ) ) ); m_OptionsList.push_back ( StringPair ( "Update cycle process time max", SString ( "%s ms (Avg %s ms)", *CPerfStatManager::GetScaledFloatString( m_NetPerformanceStats.uiUpdateCycleProcessTimeMaxUs / 1000.f ), *CPerfStatManager::GetScaledFloatString( m_NetPerformanceStats.uiUpdateCycleProcessTimeAvgUs / 1000.f ) ) ) ); m_OptionsList.push_back ( StringPair ( "Update cycle datagrams max", SString ( "%d (Avg %s)", m_NetPerformanceStats.uiUpdateCycleDatagramsMax, *CPerfStatManager::GetScaledFloatString( m_NetPerformanceStats.fUpdateCycleDatagramsAvg ) ) ) ); m_OptionsList.push_back ( StringPair ( "Update cycle datagrams limit", SString ( "%d", m_NetPerformanceStats.uiUpdateCycleDatagramsLimit ) ) ); m_OptionsList.push_back ( StringPair ( "Update cycle sends limited", SString ( "%d (%s %%)", m_NetPerformanceStats.uiUpdateCycleSendsLimitedTotal, *CPerfStatManager::GetScaledFloatString( m_NetPerformanceStats.fUpdateCycleSendsLimitedPercent ) ) ) ); } // Add columns pResult->AddColumn ( "Info.Name" ); pResult->AddColumn ( "Info.Value" ); pResult->AddColumn ( "Status.Name" ); pResult->AddColumn ( "Status.Value" ); pResult->AddColumn ( "Settings.Name" ); pResult->AddColumn ( "Settings.Value" ); // Output rows std::vector < StringPair >* columnList[] = { &m_InfoList, &m_StatusList, &m_OptionsList }; uint uiMaxRows = Max ( Max ( m_InfoList.size (), m_StatusList.size () ), m_OptionsList.size () ); for ( uint i = 0 ; i < uiMaxRows ; i++ ) { SString* row = pResult->AddRow (); int c = 0; for ( uint a = 0 ; a < NUMELMS( columnList ) ; a++ ) { const std::vector < StringPair >& column = *columnList[a]; if ( i < column.size () ) { row[c++] = column[i].strName; row[c++] = column[i].strValue; } else { row[c++] = ""; row[c++] = ""; } } } }
void CloseProc(int id, int idx, const char *ident) { char ltstr[64]; GetLocalTimeString(ltstr); printf("%s {%d} %s: CLOSE\n", ltstr, id, ident); }
void ReadProc(int id, int idx, const char *ident, const char *buf) { char ltstr[64]; GetLocalTimeString(ltstr); printf("%s {%d} %s: %s\n", ltstr, id, ident, buf); }
void OpenProc(int id, int idx, const char *ident) { char ltstr[64]; GetLocalTimeString(ltstr); printf("%s {%d} %s: OPEN\n", ltstr, id, ident); }