void ServerVoteMgr::CheckVoteStatus( ) { //check to see if this requires a unanimous vote bool bUnanimous = m_CurrentVote.m_nVotesNeeded >= m_lstEligibleVoter.size(); if (m_CurrentVote.m_nYesVotes >= m_CurrentVote.m_nVotesNeeded) { HandleVotePass(); } else if (m_CurrentVote.m_nNoVotes >= m_CurrentVote.m_nVotesNeeded ) { HandleVoteFail(); } else if (bUnanimous && m_CurrentVote.m_nNoVotes > 0) { HandleVoteFail(); } else { //Update clients CAutoMessage cMsg; cMsg.Writeuint8( MID_VOTE ); cMsg.WriteBits( eVote_Cast, FNumBitsExclusive<kNumVoteActions>::k_nValue ); cMsg.Writeuint8( m_CurrentVote.m_nVoteID ); cMsg.Writeuint8( m_CurrentVote.m_nYesVotes ); cMsg.Writeuint8( m_CurrentVote.m_nNoVotes ); cMsg.Writeuint8( m_CurrentVote.m_nVotesNeeded ); // Send the vote status info to the eligible voters. SendToEligibleVoters( *cMsg.Read( )); } }
static void SendCancelNotEnoughPlayers( HCLIENT hTarget ) { // Tell the player why their vote didn't start CAutoMessage cMsg; cMsg.Writeuint8( MID_VOTE ); cMsg.WriteBits( eVote_Cancel_Players, FNumBitsExclusive<kNumVoteActions>::k_nValue ); g_pLTServer->SendToClient( cMsg.Read(), hTarget, MESSAGE_GUARANTEED ); }
void CAISensorDamageFX::CreateDamageFX( EnumAIDamageFXState eDamageFXState ) { CAutoMessage cMsg; cMsg.Writeuint8( MID_SFX_MESSAGE ); cMsg.Writeuint8( SFX_CHARACTER_ID ); cMsg.WriteObject( m_pAI->m_hObject ); // Kill looping FX, or create looping FX corresponding to level of health. const char* pszFX; std::string strFX = m_pAI->GetAIAttributes()->strName; switch( eDamageFXState ) { case kDamageFX_None: cMsg.WriteBits(CFX_KILL_LOOP_FX_MSG, FNumBitsExclusive<CFX_COUNT>::k_nValue ); break; case kDamageFX_75: strFX += DAMAGE_FX_75; pszFX = g_pAIDB->GetMiscString( strFX.c_str() ); cMsg.WriteBits(CFX_CREATE_LOOP_FX_MSG, FNumBitsExclusive<CFX_COUNT>::k_nValue ); cMsg.WriteString( pszFX ); break; case kDamageFX_50: strFX += DAMAGE_FX_50; pszFX = g_pAIDB->GetMiscString( strFX.c_str() ); cMsg.WriteBits(CFX_CREATE_LOOP_FX_MSG, FNumBitsExclusive<CFX_COUNT>::k_nValue ); cMsg.WriteString( pszFX ); break; case kDamageFX_25: strFX += DAMAGE_FX_25; pszFX = g_pAIDB->GetMiscString( strFX.c_str() ); cMsg.WriteBits(CFX_CREATE_LOOP_FX_MSG, FNumBitsExclusive<CFX_COUNT>::k_nValue ); cMsg.WriteString( pszFX ); break; } g_pLTServer->SendToClient(cMsg.Read(), NULL, MESSAGE_GUARANTEED); }
void ServerVoteMgr::HandleVoteFail( ) { // Tell everyone the vote failed. CAutoMessage cMsg; cMsg.Writeuint8( MID_VOTE ); cMsg.WriteBits( eVote_Fail, FNumBitsExclusive<kNumVoteActions>::k_nValue ); // Send the vote status info to the eligible voters. SendToEligibleVoters( *cMsg.Read( )); // Clear the current vote. ClearVote( ); }
void ClientVoteMgr::CallVoteNext(VoteType eVoteType) { if (IsVoteInProgress()) { g_pTransmission->Show("ScreenVote_VoteInProgress"); return; } if (IsVoteDelayed()) { wchar_t szMsg[256]; szMsg[0] = '\0'; FormatString("ScreenVote_VoteDelayed",szMsg,LTARRAYSIZE(szMsg),(uint32)m_VoteDelayTimer.GetTimeLeft()); g_pTransmission->Show(szMsg); return; } CAutoMessage cMsg; cMsg.Writeuint8( MID_VOTE ); cMsg.WriteBits( eVote_Start, FNumBitsExclusive<kNumVoteActions>::k_nValue ); cMsg.WriteBits( eVoteType, FNumBitsExclusive<kNumVoteTypes>::k_nValue ); g_pLTClient->SendToServer( cMsg.Read(), MESSAGE_GUARANTEED ); }
void ServerVoteMgr::Update() { if (m_VoteTimer.IsStarted() && m_VoteTimer.IsTimedOut()) { m_VoteTimer.Stop(); m_CurrentVote.m_eVoteType = eVote_None; // Inform clients that vote timed out CAutoMessage cMsg; cMsg.Writeuint8( MID_VOTE ); cMsg.WriteBits( eVote_Expire, FNumBitsExclusive<kNumVoteActions>::k_nValue ); SendToEligibleVoters( *cMsg.Read( )); } }
void Water::HandleAllowSwimmingMsg( HOBJECT hSender, const CParsedMsg &crParsedMsg ) { static CParsedMsg::CToken s_cTok_0( "0" ); m_bAllowSwimming = !(crParsedMsg.GetArg( 1 ) == s_cTok_0); CAutoMessage cMsg; cMsg.Writeuint8( MID_SFX_MESSAGE ); cMsg.Writeuint8( m_nSfxMsgId ); cMsg.WriteObject( m_hObject ); cMsg.WriteBits( kVolumeBrush_AllowSwimming, FNumBitsExclusive<kVolumeBrush_NumMsgs>::k_nValue ); cMsg.Writebool( m_bAllowSwimming ); g_pLTServer->SendToClient( cMsg.Read( ), NULL, MESSAGE_GUARANTEED ); CreateSpecialFXMsg( ); }
void ClientVoteMgr::CastVote(bool bVote) { if (!IsVoteInProgress() || m_bHasVoted) { return; } CAutoMessage cMsg; cMsg.Writeuint8( MID_VOTE ); cMsg.WriteBits( eVote_Cast, FNumBitsExclusive<kNumVoteActions>::k_nValue ); cMsg.Writeuint8( m_CurrentVote.m_nVoteID ); cMsg.Writebool( bVote ); g_pLTClient->SendToServer( cMsg.Read(), MESSAGE_GUARANTEED ); m_bHasVoted = true; g_pHUDMgr->QueueUpdate(kHUDVote); }
void ServerVoteMgr::HandleVotePass( ) { // Tell everyone the vote passed. CAutoMessage cMsg; cMsg.Writeuint8( MID_VOTE ); cMsg.WriteBits( eVote_Pass, FNumBitsExclusive<kNumVoteActions>::k_nValue ); // Send the vote status info to the eligible voters. SendToEligibleVoters( *cMsg.Read( )); switch( m_CurrentVote.m_eVoteType ) { case eVote_Kick: case eVote_TeamKick: { // Get the client. HCLIENT hClient = g_pLTServer->GetClientHandle( m_CurrentVote.m_nTargetID ); if( hClient ) { // Kick the client. g_pLTServer->KickClient( hClient ); } } break; case eVote_Ban: { // get the user's unique CD Key hash const char* pszUserCDKeyHash = NULL; g_pGameServerShell->GetGameSpyServer()->GetUserCDKeyHash(m_CurrentVote.m_nTargetID, pszUserCDKeyHash); // get the user's player name const wchar_t* pwszPlayerName; HCLIENT hClient = g_pLTServer->GetClientHandle( m_CurrentVote.m_nTargetID ); GameClientData* pGameClientData = ServerConnectionMgr::Instance().GetGameClientData( hClient ); if (!pGameClientData) { pwszPlayerName = L""; } else { pwszPlayerName = pGameClientData->GetUniqueName( ); } // add them to the temp ban list float fDuration = GameModeMgr::Instance( ).m_ServerSettings.m_nVoteBanDuration * 60.0f; BanUserMgr::Instance().AddTempBan( pszUserCDKeyHash, MPW2A(pwszPlayerName).c_str(), fDuration ); } break; case eVote_NextRound: { g_pServerMissionMgr->NextRound( ); } break; case eVote_NextMap: { g_pServerMissionMgr->NextMission( ); } break; case eVote_SelectMap: { // Check to make sure the mission index is within range. Campaign& campaign = g_pServerMissionMgr->GetCampaign( ); if( m_CurrentVote.m_nTargetID < campaign.size( )) { // Do the switch. g_pServerMissionMgr->SwitchToCampaignIndex( m_CurrentVote.m_nTargetID ); } } break; } // Clear the current vote. ClearVote( ); }
void ServerVoteMgr::HandleVoteStart(HCLIENT hSender, ILTMessage_Read* pMsg) { if (!hSender) { return; } if (IsVoteInProgress()) { // Tell the player why their vote didn't start SendCancelVoteInProgress( hSender ); return; } VoteType eVoteType = (VoteType)pMsg->ReadBits( FNumBitsExclusive<kNumVoteTypes>::k_nValue ); //check to see if we have a real client uint32 nCallerID = g_pLTServer->GetClientID( hSender ); HCLIENT hCallerClient = g_pLTServer->GetClientHandle( nCallerID ); if( !hCallerClient ) return; GameClientData* pCallerGameClientData = ServerConnectionMgr::Instance().GetGameClientData( hCallerClient ); if( !pCallerGameClientData ) return; //check to see if the client has a live player... if (!GameModeMgr::Instance( ).m_grbAllowDeadVoting) { CPlayerObj* pPlayerObj = ( CPlayerObj* )g_pLTServer->HandleToObject( pCallerGameClientData->GetPlayer( )); if( !pPlayerObj || !pPlayerObj->IsAlive( )) { return; } }; // Make sure we start fresh. ClearVote( ); switch(eVoteType) { case eVote_Kick: case eVote_TeamKick: case eVote_Ban: { uint32 nTargetID = pMsg->Readuint32(); HCLIENT hTargetClient = g_pLTServer->GetClientHandle( nTargetID ); if( !hTargetClient ) return; GameClientData* pTargetGameClientData = ServerConnectionMgr::Instance().GetGameClientData( hTargetClient ); if( !pTargetGameClientData ) return; // Iterate through all the clients and see if anyone is ready to vote. ServerConnectionMgr::GameClientDataList& gameClientDataList = ServerConnectionMgr::Instance( ).GetGameClientDataList( ); ServerConnectionMgr::GameClientDataList::iterator iter = gameClientDataList.begin( ); for( ; iter != gameClientDataList.end( ); iter++ ) { GameClientData* pGameClientData = *iter; if( !pGameClientData->GetClient( )) continue; // Skip clients that aren't ready to play yet. if( pGameClientData->GetClientConnectionState() != eClientConnectionState_InWorld ) continue; // Client must have reached the inworld state. if( !pGameClientData->IsClientInWorld( )) continue; // Restrict elibible voters if it's a team kick. if( eVoteType == eVote_TeamKick ) { if( pCallerGameClientData->GetLastTeamId() != pGameClientData->GetLastTeamId( )) continue; } // Add to the eligible voter list. m_lstEligibleVoter.push_back( pGameClientData->GetClient( )); } // Check if we have a quorum of voters. uint32 nQuorum = ( eVoteType == eVote_TeamKick ) ? GameModeMgr::Instance().m_ServerSettings.m_nMinPlayersForTeamVote : GameModeMgr::Instance().m_ServerSettings.m_nMinPlayersForVote; //figure out how many votes are needed to pass uint8 nVotesNeeded = ((m_lstEligibleVoter.size() + 2) / 2); //the "+ 2" is here to ensure a majority not just half //if we have less than the "minimum" number of players, the vote must pass unanimously if( m_lstEligibleVoter.size( ) < nQuorum ) { nVotesNeeded = m_lstEligibleVoter.size( ); } // Put the caller on the list of voters already cast. m_lstVoterCastYes.push_back( pCallerGameClientData->GetClient( )); float fDuration = GameModeMgr::Instance().m_ServerSettings.m_nVoteLifetime; m_VoteTimer.Start(fDuration); m_CurrentVote.m_eVoteType = eVoteType; m_CurrentVote.m_nVoteID = m_CurrentVote.m_nVoteID++; //increment vote ID so that each vote is more or less unique... will wrap after 256 votes m_CurrentVote.m_nTargetID = nTargetID; m_CurrentVote.m_nCallerID = nCallerID; m_CurrentVote.m_nNoVotes = 0; m_CurrentVote.m_nYesVotes = 1; m_CurrentVote.m_nVotesNeeded = nVotesNeeded; CAutoMessage cMsg; cMsg.Writeuint8( MID_VOTE ); cMsg.WriteBits( eVote_Start, FNumBitsExclusive<kNumVoteActions>::k_nValue ); cMsg.Writeuint8( m_CurrentVote.m_nVoteID ); cMsg.WriteBits( eVoteType, FNumBitsExclusive<kNumVoteTypes>::k_nValue ); cMsg.Writeuint32( nCallerID ); cMsg.Writeuint32( nTargetID ); cMsg.Writeuint8( m_CurrentVote.m_nVotesNeeded ); cMsg.Writedouble( m_VoteTimer.GetTimeLeft( )); // Send the vote start info to the eligible voters. SendToEligibleVoters( *cMsg.Read( )); // Check if we've already achieved necessary votes. CheckVoteStatus(); } break; case eVote_NextRound: case eVote_NextMap: { // Iterate through all the clients and see if anyone is ready to vote. ServerConnectionMgr::GameClientDataList& gameClientDataList = ServerConnectionMgr::Instance( ).GetGameClientDataList( ); ServerConnectionMgr::GameClientDataList::iterator iter = gameClientDataList.begin( ); for( ; iter != gameClientDataList.end( ); iter++ ) { GameClientData* pGameClientData = *iter; if( !pGameClientData->GetClient( )) continue; // Skip clients that aren't ready to play yet. if( pGameClientData->GetClientConnectionState() != eClientConnectionState_InWorld ) continue; // Client must have reached the inworld state. if( !pGameClientData->IsClientInWorld( )) continue; // Add to the eligible voter list. m_lstEligibleVoter.push_back( pGameClientData->GetClient( )); } // Check if we have a quorum of voters. uint32 nQuorum = GameModeMgr::Instance().m_ServerSettings.m_nMinPlayersForVote; //figure out how many votes are needed to pass uint8 nVotesNeeded = ((m_lstEligibleVoter.size() + 2) / 2); //the "+ 2" is here to ensure a majority not just half //if we have less than the "minimum" number of players, the vote must pass unanimously if( m_lstEligibleVoter.size( ) < nQuorum ) { nVotesNeeded = m_lstEligibleVoter.size( ); } // Put the caller on the list of voters already cast. m_lstVoterCastYes.push_back( pCallerGameClientData->GetClient( )); float fDuration = GameModeMgr::Instance().m_ServerSettings.m_nVoteLifetime; m_VoteTimer.Start(fDuration); m_CurrentVote.m_eVoteType = eVoteType; m_CurrentVote.m_nVoteID = m_CurrentVote.m_nVoteID++; //increment vote ID so that each vote is more or less unique... will wrap after 256 votes m_CurrentVote.m_nTargetID = 0; m_CurrentVote.m_nCallerID = nCallerID; m_CurrentVote.m_nNoVotes = 0; m_CurrentVote.m_nYesVotes = 1; m_CurrentVote.m_nVotesNeeded = nVotesNeeded; CAutoMessage cMsg; cMsg.Writeuint8( MID_VOTE ); cMsg.WriteBits( eVote_Start, FNumBitsExclusive<kNumVoteActions>::k_nValue ); cMsg.Writeuint8( m_CurrentVote.m_nVoteID ); cMsg.WriteBits( eVoteType, FNumBitsExclusive<kNumVoteTypes>::k_nValue ); cMsg.Writeuint32( nCallerID ); cMsg.Writeuint32( 0 ); cMsg.Writeuint8( m_CurrentVote.m_nVotesNeeded ); cMsg.Writedouble( m_VoteTimer.GetTimeLeft( )); // Send the vote start info to the eligible voters. SendToEligibleVoters( *cMsg.Read( )); // Check if we've already achieved necessary votes. CheckVoteStatus(); } break; case eVote_SelectMap: { uint32 nMapIndex = pMsg->Readuint32(); uint32 nCallerID = g_pLTServer->GetClientID( hSender ); HCLIENT hCallerClient = g_pLTServer->GetClientHandle( nCallerID ); if( !hCallerClient ) return; GameClientData* pCallerGameClientData = ServerConnectionMgr::Instance().GetGameClientData( hCallerClient ); if( !pCallerGameClientData ) return; // Iterate through all the clients and see if anyone is ready to vote. ServerConnectionMgr::GameClientDataList& gameClientDataList = ServerConnectionMgr::Instance( ).GetGameClientDataList( ); ServerConnectionMgr::GameClientDataList::iterator iter = gameClientDataList.begin( ); for( ; iter != gameClientDataList.end( ); iter++ ) { GameClientData* pGameClientData = *iter; if( !pGameClientData->GetClient( )) continue; // Skip clients that aren't ready to play yet. if( pGameClientData->GetClientConnectionState() != eClientConnectionState_InWorld ) continue; // Client must have reached the inworld state. if( !pGameClientData->IsClientInWorld( )) continue; // Add to the eligible voter list. m_lstEligibleVoter.push_back( pGameClientData->GetClient( )); } // Check if we have a quorum of voters. uint32 nQuorum = GameModeMgr::Instance().m_ServerSettings.m_nMinPlayersForVote; //figure out how many votes are needed to pass uint8 nVotesNeeded = ((m_lstEligibleVoter.size() + 2) / 2); //the "+ 2" is here to ensure a majority not just half //if we have less than the "minimum" number of players, the vote must pass unanimously if( m_lstEligibleVoter.size( ) < nQuorum ) { nVotesNeeded = m_lstEligibleVoter.size( ); } // Put the caller on the list of voters already cast. m_lstVoterCastYes.push_back( pCallerGameClientData->GetClient( )); float fDuration = GameModeMgr::Instance().m_ServerSettings.m_nVoteLifetime; m_VoteTimer.Start(fDuration); m_CurrentVote.m_eVoteType = eVoteType; m_CurrentVote.m_nVoteID = m_CurrentVote.m_nVoteID++; //increment vote ID so that each vote is more or less unique... will wrap after 256 votes m_CurrentVote.m_nTargetID = nMapIndex; m_CurrentVote.m_nCallerID = nCallerID; m_CurrentVote.m_nNoVotes = 0; m_CurrentVote.m_nYesVotes = 1; m_CurrentVote.m_nVotesNeeded = nVotesNeeded; CAutoMessage cMsg; cMsg.Writeuint8( MID_VOTE ); cMsg.WriteBits( eVote_Start, FNumBitsExclusive<kNumVoteActions>::k_nValue ); cMsg.Writeuint8( m_CurrentVote.m_nVoteID ); cMsg.WriteBits( eVoteType, FNumBitsExclusive<kNumVoteTypes>::k_nValue ); cMsg.Writeuint32( nCallerID ); cMsg.Writeuint32( nMapIndex ); cMsg.Writeuint8( m_CurrentVote.m_nVotesNeeded ); cMsg.Writedouble( m_VoteTimer.GetTimeLeft( )); // Send the vote start info to the eligible voters. SendToEligibleVoters( *cMsg.Read( )); // Check if we've already achieved necessary votes. CheckVoteStatus(); } break; } }