CAntiCheatManager::~CAntiCheatManager() { CloseLogFile(); CDownloadableResourcePtr res = GetDownloadableResource(); if (res) { res->RemoveDataListener(this); } }
//------------------------------------------------------------------------ bool CPlaylistActivityTracker::UploadData( const char* pUrlPath, const char* pUrlParams, int receiveSize, ERequestTaskType taskType ) { CDownloadableResourcePtr newResource = new CDownloadableResource; newResource->SetDownloadInfo( pUrlParams, pUrlPath, m_serverNameCVar->GetString(), m_serverPortCVar->GetIVal(), receiveSize, "PlaylistRequest" ); newResource->AddDataListener( this ); m_downloadableResources[ taskType ] = newResource; return true; }
void CAntiCheatManager::DataDownloaded(CDownloadableResourcePtr inResource) { const int bufferSize = 1024*1024; char* pBuffer = new char[bufferSize]; int dataLength = bufferSize; inResource->GetDecryptedData(pBuffer,&dataLength,DECRYPTION_KEY,int(sizeof(DECRYPTION_KEY)-1),SIGNING_SALT,int(sizeof(SIGNING_SALT)-1)); if (dataLength > 0) { XmlNodeRef xmlData = gEnv->pSystem->LoadXmlFromBuffer(pBuffer, dataLength); if (xmlData) { CryLog("Parsing downloaded Anti-Cheat Configuration..."); ParseAntiCheatConfig(xmlData); } else { CryLog("Unable to parse downloaded Anti-Cheat Configuration"); } } else { CryLog("Error decrypting Anti-Cheat Configuration"); } }
CAntiCheatManager::CAntiCheatManager() : m_pLogFile(NULL) , m_decayRate(100.f) , m_hashMethod(0) , m_totalAssetWeighting(0) , m_enableLogUploads(true) , m_uChatMsgsSent(0) , m_uIncidents(0) { ResetAntiCheatVars(); int instance = gEnv->pSystem->GetApplicationInstance(); if(instance != 0) { m_logFileName.Format("./%sAntiCheatLog(%d).xml", gEnv->pSystem->GetRootFolder(), instance); } else { m_logFileName.Format("./%sAntiCheatLog.xml", gEnv->pSystem->GetRootFolder()); } ParseAntiCheatConfig("Scripts/DedicatedConfigs/AntiCheatConfig.xml"); #if defined(_RELEASE) CDownloadableResourcePtr res = GetDownloadableResource(); if (res) { res->AddDataListener(this); } #endif m_lastDownloadTime = gEnv->pTimer->GetAsyncTime(); //Examples of usage /*FlagActivity(eCT_WeaponDamage, 5641, 4, 300); FlagActivity(eCT_WeaponDamage, 5641, 2, 300); FlagActivity(eCT_WeaponDamage, 5641, 4, 100); FlagActivity(eCT_PlayerSpeed, 6465, 40); FlagActivity(eCT_PlayerSpeed, 6465, 100); FlagActivity(eCT_AmmoUsed, 8489);*/ }
void CDataPatchDownloader::DataDownloaded( CDownloadableResourcePtr inResource) { const int bufferSize = 1024*1024; char* pBuffer = new char[bufferSize]; if (pBuffer) { int dataLength = bufferSize; inResource->GetDecryptedData(pBuffer,&dataLength,DECRYPTION_KEY,int(sizeof(DECRYPTION_KEY)-1),SIGNING_SALT,int(sizeof(SIGNING_SALT)-1)); if (dataLength > 0) { IXmlParser *pParser=GetISystem()->GetXmlUtils()->CreateXmlParser(); m_patchCRC=CCrc32::Compute(pBuffer,dataLength); m_patchXML=pParser->ParseBuffer(pBuffer,dataLength,false); if (!m_patchXML) { m_patchCRC = 0; CryLog("Failed to parse game data patch xml"); } else { m_patchXML->getAttr("patchid",m_patchId); int matchmakingVersion = 0; if (m_patchXML->getAttr("matchmakingversion",matchmakingVersion)) { if (matchmakingVersion != g_pGameCVars->g_MatchmakingVersion) { // Unload the patch XML, because it doesn't match the matchmaking version CryLog("Game data patch matchmaking version (%d) does not match this build's matchmaking version (%d)", matchmakingVersion, g_pGameCVars->g_MatchmakingVersion); m_patchCRC = 0; m_patchId = 0; m_patchXML = NULL; } } } pParser->Release(); } delete [] pBuffer; } // if it downloads the patch is marked as available, regardless of whether it parsed / passed checks // if it fails parsing or checks, it will end up with a CRC of 0 and so cause the game to follow paths // of not having a patch if (m_pListener) { m_pListener->DataPatchAvailable(); } }
void CDownloadMgr::WaitForDownloadsToFinish(const char** resources, int numResources, float timeout) { CDownloadableResourcePtr* pResources=new CDownloadableResourcePtr[numResources]; for (int i=0; i<numResources; ++i) { CDownloadableResourcePtr pRes = FindResourceByName(resources[i]); if (pRes) { pRes->StartDownloading(); } pResources[i] = pRes; } CTimeValue startTime = gEnv->pTimer->GetAsyncTime(); while (true) { bool allFinished = true; for (int i=0; i<numResources; ++i) { CDownloadableResourcePtr pRes = pResources[i]; if (pRes) { CDownloadableResource::TState state = pRes->GetState(); if (state & CDownloadableResource::k_callbackInProgressMask) { allFinished = false; break; } } } CTimeValue currentTime = gEnv->pTimer->GetAsyncTime(); if (allFinished || currentTime.GetDifferenceInSeconds(startTime) > timeout) { break; } CrySleep(100); }; delete [] pResources; DispatchCallbacks(); }
void CAntiCheatManager::OnSessionEnd() { DumpPlayerRecords(); DumpCheatRecords(); DecayCheatRecords(); CloseLogFile(); BackupLogFileAndSubmit(); CTimeValue currentTime = gEnv->pTimer->GetAsyncTime(); float deltaSeconds = currentTime.GetDifferenceInSeconds(m_lastDownloadTime); if (deltaSeconds > g_pGameCVars->g_dataRefreshFrequency * 3600) { CDownloadableResourcePtr res = GetDownloadableResource(); if (res) { // Clear the downloaded data and start download again res->Purge(); res->StartDownloading(); } m_lastDownloadTime = currentTime; } }
//------------------------------------------------------------------------ void CPlaylistActivityTracker::DataDownloaded( CDownloadableResourcePtr inResource ) { //get the task type of the resource by finding it in our vector ERequestTaskType taskType = eRTT_MaxCount; for( int i = 0; i < eRTT_MaxCount; i++ ) { if( m_downloadableResources[ i ] == inResource ) { taskType = (ERequestTaskType)i; break; } } if( taskType == eRTT_RequestActivity ) { bool dataRead = false; //parse xml int bufferSize = -1; char* buffer; inResource->GetRawData( &buffer, &bufferSize ); //debug output data stream to log CryLog( "PlaylistActivity: Full processed Data %s", buffer ); IXmlParser* parser = GetISystem()->GetXmlUtils()->CreateXmlParser(); XmlNodeRef topNode = parser->ParseBuffer(buffer, bufferSize, false); if( topNode && stricmp( topNode->getTag(), "playlists" ) == 0 ) { //Iterate over playlists const int numberOfPlaylistElements = topNode->getChildCount(); int destPlaylistIdx = 0; //separate index to write to in case there are non-playlist node for(int playlistIdx = 0; playlistIdx < numberOfPlaylistElements && destPlaylistIdx < MAX_PLAYLISTS; ++playlistIdx ) { //get and check playlist node const XmlNodeRef playlistNode = topNode->getChild( playlistIdx ); if( playlistNode && stricmp( playlistNode->getTag(), "playlist" ) == 0 ) { PlaylistActivity& currentPlaylist = m_activityData[ destPlaylistIdx ]; //copy name and Id into structure const char* playlistName = NULL; if( playlistNode->getAttr( "name", &playlistName ) ) { cry_strcpy( currentPlaylist.name, playlistName ); } int id = 0; if( playlistNode->getAttr( "index", id ) ) { currentPlaylist.id = id; } //clear totals currentPlaylist.nPlayers = 0; currentPlaylist.nGames = 0; //Iterate over variants const int numberOfVariantElements = playlistNode->getChildCount(); currentPlaylist.nVariants = 0; //use count as index to write to in case there are non-variant nodes for(int variantIdx = 0; variantIdx < numberOfVariantElements && currentPlaylist.nVariants < MAX_VARIANTS; ++variantIdx ) { //get and check variant node const XmlNodeRef variantNode = playlistNode->getChild( variantIdx ); if( variantNode && stricmp( variantNode->getTag(), "variant" ) == 0 ) { VariantActivity& currentVariant = currentPlaylist.variants[ currentPlaylist.nVariants ]; //copy data into structure const char* variantName = NULL; if( variantNode->getAttr( "name", &variantName ) ) { cry_strcpy( currentVariant.name, variantName ); } int variantId = 0; if( variantNode->getAttr( "index", variantId ) ) { currentVariant.id = variantId; } int count = 0; if( variantNode->getAttr( "players", count ) ) { currentVariant.nPlayers = count; //increase total currentPlaylist.nPlayers += count; } if( variantNode->getAttr( "games", count ) ) { currentVariant.nGames = count; //increase total currentPlaylist.nGames += count; } currentPlaylist.nVariants++; dataRead = true; } } destPlaylistIdx++; } }//end loop m_nKnownPlaylists = destPlaylistIdx; } if( m_currentActivityCallback ) { m_currentActivityCallback( dataRead, m_activityData, m_nKnownPlaylists ); } } else { //other requests don't have a payload to deliver to us } ReleaseResourceReference( inResource ); }