bool ScmdServer_Impl::HandleSetMission( HCLIENT hClient, ILTMessage_Read& msg ) { // Read the mission index desired. uint8 nMissionIndex = msg.Readuint8( ); // Check to make sure the mission index is within range. Campaign& campaign = g_pServerMissionMgr->GetCampaign( ); if( nMissionIndex >= campaign.size( )) { // Tell the client it failed. if( !SendStatusMessage( hClient, kScmdCommandSetMission, kScmdCommandStatusFailed )) return false; return true; } // Tell the client it worked. if( !SendStatusMessage( hClient, kScmdCommandSetMission, kScmdCommandStatusOk )) return false; // Do the switch. g_pServerMissionMgr->SwitchToCampaignIndex( nMissionIndex ); return true; }
bool CServerMissionMgr::Load( ILTMessage_Read& msg, uint32 dwSaveFlags ) { msg.ReadString( m_sCampaignFile.GetBuffer( MAX_PATH ), MAX_PATH ); m_sCampaignFile.ReleaseBuffer( ); m_Campaign.clear( ); int nNumCampaignEntries = msg.Readuint8( ); for( int nCampaignIndex = 0; nCampaignIndex < nNumCampaignEntries; ++nCampaignIndex ) { m_Campaign.push_back( msg.Readuint8( )); } m_nCurCampaignIndex = msg.Readuint8( ); ServerMissionSettings ss = m_ServerSettings; ss.m_bUseSkills = msg.Readbool(); ss.m_bFriendlyFire = msg.Readbool(); ss.m_nMPDifficulty = msg.Readuint8(); ss.m_fPlayerDiffFactor = msg.Readfloat(); SetServerSettings(ss); return true; }
bool CServerMissionMgr::OnMessage( HCLIENT hSender, ILTMessage_Read& msg ) { msg.SeekTo(0); uint8 messageID = msg.Readuint8(); switch (messageID) { case MID_START_GAME: HandleStartGame ( hSender, msg ); return true; case MID_START_LEVEL: HandleStartLevel ( hSender, msg ); return true; case MID_EXIT_LEVEL: HandleExitLevel ( hSender, msg ); return true; case MID_MULTIPLAYER_OPTIONS: HandleMultiplayerOptions( hSender, msg ); return true; default: break; } return false; }
bool ScmdServer_Impl::OnMessage( HCLIENT hClient, ILTMessage_Read& msg ) { // Make sure we're initialized. if( !m_bInitialized ) return false; msg.SeekTo( 0 ); uint8 messageID = msg.Readuint8( ); switch( messageID ) { case MID_SCMD: HandleScmdMessage( hClient, msg ); return true; default: break; } return false; }
bool ScmdServer_Impl::HandleRemoveBan( HCLIENT hClient, ILTMessage_Read& msg ) { // Read the banid. uint8 nBanId = msg.Readuint8( ); bool bOk = true; // Index into the ban list. BanIPMgr::BanList const& banList = BanIPMgr::Instance( ).GetBanList( ); // Make sure the id is in range. if( nBanId >= banList.size( )) { bOk = false; } if( bOk ) { // Index into ban list and remove the ban. BanIPMgr::BanList::const_iterator iter = banList.begin( ); for( uint8 nId = 0; iter != banList.end( ); iter++, nId++ ) { if( nId == nBanId ) { BanIPMgr::ClientIP const& clientIP = *iter; bOk = BanIPMgr::Instance( ).RemoveBan( clientIP ); break; } } } // Tell the client if it worked or not. if( !SendStatusMessage( hClient, kScmdCommandRemoveBan, ( bOk ) ? kScmdCommandStatusOk : kScmdCommandStatusFailed )) return false; return true; }
bool ScmdServer_Impl::HandleScmdMessage( HCLIENT hClient, ILTMessage_Read& msg ) { // Check if SCMD commands are not allowed. if( !m_bAllowScmdCommands ) { return true; } // Read the scmd command. ScmdCommand eScmdCommand = ( ScmdCommand )msg.Readuint8( ); // Check if we're not controlled by an admin. Since Login is the only // command you can send without being logged in, it has special handling. if( eScmdCommand != kScmdCommandLogin && ( m_eAdminControl == kAdminControlNone ) || ( m_eAdminControl == kAdminControlClient && hClient != m_hAdminClient ) || ( m_eAdminControl == kAdminControlServerapp && hClient != NULL )) { // Doesn't have privileges. SendStatusMessage( hClient, eScmdCommand, kScmdCommandStatusNotLoggedIn ); return false; } switch( eScmdCommand ) { case kScmdCommandLogin: return HandleLogin( hClient, msg ); break; case kScmdCommandLogout: return HandleLogout( hClient, msg ); break; case kScmdCommandListClients: return HandleListClients( hClient, msg ); break; case kScmdCommandListMissions: return HandleListMissions( hClient, msg ); break; case kScmdCommandNextMission: return HandleNextMission( hClient, msg ); break; case kScmdCommandNextRound: return HandleNextRound( hClient, msg ); break; case kScmdCommandSetMission: return HandleSetMission( hClient, msg ); break; case kScmdCommandBootName: return HandleBootName( hClient, msg ); break; case kScmdCommandBootId: return HandleBootId( hClient, msg ); break; case kScmdCommandAddBan: return HandleAddBan( hClient, msg ); break; case kScmdCommandRemoveBan: return HandleRemoveBan( hClient, msg ); break; case kScmdCommandListBans: return HandleListBans( hClient, msg ); break; case kScmdCommandBanClient: return HandleBanClient( hClient, msg ); break; case kScmdCommandListGameOptions: return HandleListGameOptions( hClient, msg ); break; case kScmdCommandSetGameOption: return HandleSetGameOption( hClient, msg ); break; } return false; }
bool ScmdServer_Impl::HandleSetGameOption( HCLIENT hClient, ILTMessage_Read& msg ) { bool bOk = true; // Get the game option they are setting. uint8 nGameOption = msg.Readuint8( ); // Read in the value. char szVal[256]; msg.ReadString( szVal, ARRAY_LEN( szVal )); ServerMissionSettings sms = g_pServerMissionMgr->GetServerSettings(); switch( g_pGameServerShell->GetGameType( )) { case eGameTypeDeathmatch: { switch( nGameOption ) { // Runspeed. case 0: { SetGameOption( sms.m_nRunSpeed, atoi( szVal ), 100, 150 ); } break; // Score limit. case 1: { SetGameOption( sms.m_nScoreLimit, atoi( szVal ), 0, 255 ); } break; // Time limit. case 2: { SetGameOption( sms.m_nTimeLimit, atoi( szVal ), 0, 255 ); } break; // Rounds. case 3: { SetGameOption( sms.m_nRounds, atoi( szVal ), 1, 255 ); } break; default: { bOk = false; } break; } } break; case eGameTypeTeamDeathmatch: { switch( nGameOption ) { // Runspeed. case 0: { SetGameOption( sms.m_nRunSpeed, atoi( szVal ), 100, 150 ); } break; // Score limit. case 1: { SetGameOption( sms.m_nScoreLimit, atoi( szVal ), 0, 255 ); } break; // Time limit. case 2: { SetGameOption( sms.m_nTimeLimit, atoi( szVal ), 0, 255 ); } break; // Rounds. case 3: { SetGameOption( sms.m_nRounds, atoi( szVal ), 1, 255 ); } break; // Friendly fire. case 4: { SetGameOption( sms.m_bFriendlyFire, ( bool )( !!atoi( szVal )), false, true ); } break; default: { bOk = false; } break; } } break; case eGameTypeDoomsDay: { switch( nGameOption ) { // Runspeed. case 0: { SetGameOption( sms.m_nRunSpeed, atoi( szVal ), 100, 150 ); } break; // Time limit. case 1: { SetGameOption( sms.m_nTimeLimit, atoi( szVal ), 0, 255 ); } break; // Rounds. case 2: { SetGameOption( sms.m_nRounds, atoi( szVal ), 1, 255 ); } break; // Friendly fire. case 3: { SetGameOption( sms.m_bFriendlyFire, ( bool )( !!atoi( szVal )), false, true ); } break; default: { bOk = false; } break; } } break; case eGameTypeCooperative: { switch( nGameOption ) { // Friendly fire. case 0: { SetGameOption( sms.m_bFriendlyFire, ( bool )( !!atoi( szVal )), false, true ); } break; // mp difficulty. case 1: { SetGameOption( sms.m_nMPDifficulty, atoi( szVal ), 0, 255 ); } break; // player diff factor. case 2: { SetGameOption( sms.m_fPlayerDiffFactor, ( float )atof( szVal ), 0.0f, 20.0f ); } break; default: { bOk = false; } break; } } break; default: { bOk = false; } break; } // We need to tell the host client about the new settings. if( bOk ) { // Record any changes. g_pServerMissionMgr->SetServerSettings(sms); // Try to find a local host if one exists. HCLIENT hHost = g_pLTServer->GetNextClient( NULL ); while( hHost ) { uint32 nClientInfoFlags = g_pLTServer->GetClientInfoFlags( hHost ); if( nClientInfoFlags & CIF_LOCAL ) { break; } hHost = g_pLTServer->GetNextClient( hHost ); } // If we have a host, tell them about the new settings. if( hHost ) { CAutoMessage cMsg; cMsg.Writeuint8( MID_MULTIPLAYER_OPTIONS ); cMsg.Writeuint8( sms.m_nRunSpeed); cMsg.Writeuint8( sms.m_nScoreLimit); cMsg.Writeuint8( sms.m_nTimeLimit); cMsg.Writeuint8( sms.m_nRounds); cMsg.Writebool( sms.m_bFriendlyFire); cMsg.Writeuint8( sms.m_nMPDifficulty); cMsg.Writefloat( sms.m_fPlayerDiffFactor); g_pLTServer->SendToClient( cMsg.Read( ), hHost, MESSAGE_GUARANTEED ); } } SendStatusMessage( hClient, kScmdCommandSetGameOption, ( bOk ) ? kScmdCommandStatusOk : kScmdCommandStatusFailed ); return true; }