short LobbyGame::HandleJoinGameReply(ReadBuffer &theMsg) { short aStatus = LobbyGameStatus_None; try { aStatus = theMsg.ReadShort(); if(aStatus!=LobbyGameStatus_Success) return aStatus; unsigned short aNumPlayers = theMsg.ReadShort(); for(int i=0; i<aNumPlayers; i++) { unsigned short aClientId = theMsg.ReadShort(); LobbyClient *aClient = GetClient(aClientId); if(aClient!=NULL) { LobbyPlayerPtr aPlayer = LobbyPlayer::CreatePlayer(); if(aPlayer->ReadData(theMsg)) aClient->SetPlayer(aPlayer); } } HandleJoinGameReplyHook(theMsg); } catch(ReadBufferException&) { aStatus = LobbyGameStatus_UnpackFailure; } return aStatus; }
LobbyPlayer* LobbyStaging::GetMyPlayer() { LobbyClient *aClient = GetMyClient(); if(aClient!=NULL) return aClient->GetPlayer(); else return NULL; }
bool LobbyGame::IsEveryoneReady() { const LobbyClientMap &aMap = mClientList->GetClientMap(); for(LobbyClientMap::const_iterator anItr = aMap.begin(); anItr!=aMap.end(); ++anItr) { LobbyClient *aClient = anItr->second; if(aClient->IsPlayer() && !aClient->IsCaptain(true) && !aClient->IsPlayerReady()) return false; } return true; }
LobbyClient* ChatCommandParser::GetClientByName(const GUIString &theName, MatchResult *theResult) { MatchResult aResult = MatchResult_NotFound; LobbyClient *aMatchClient = NULL; if(mClientList!=NULL) { const LobbyClientMap &aMap = mClientList->GetClientMap(); LobbyClientMap::const_iterator anItr = aMap.begin(); for(; anItr!=aMap.end(); ++anItr) { LobbyClient *aClient = anItr->second; bool partialMatch = false; bool exactMatch = false; exactMatch = Compare(theName,aClient->GetName(),partialMatch); if(exactMatch) { if(aResult==MatchResult_Exact) { aResult = MatchResult_Ambiguous; break; } aResult = MatchResult_Exact; aMatchClient = aClient; } else if(partialMatch) { if(aResult==MatchResult_NotFound) { aResult = MatchResult_Partial; aMatchClient = anItr->second; } else if(aResult==MatchResult_Partial) { aResult = MatchResult_Ambiguous; break; } } } } if(aResult==MatchResult_NotFound || aResult==MatchResult_Ambiguous) aMatchClient = NULL; if(theResult!=NULL) *theResult = aResult; return aMatchClient; }
void StagingLogic::HandlePingChanged(ReadBuffer &theMsg, LobbyClient *theSender) { if(!theSender->IsCaptain(true)) return; unsigned short aClientId = theMsg.ReadShort(); unsigned short aPing = theMsg.ReadShort(); LobbyClient *aClient = mGame->GetClient(aClientId); if(aClient==NULL) return; LobbyPlayer *aPlayer = aClient->GetPlayer(); if(aPlayer==NULL) return; aPlayer->SetPing(aPing); LobbyEvent::BroadcastEvent(new PlayerChangedEvent(aClient,LobbyChangeType_Modify)); }
void StagingLogic::HandlePlayerJoined(ReadBuffer &theMsg, LobbyClient *theSender) { if(!theSender->IsCaptain(true)) return; unsigned short aClientId = theMsg.ReadShort(); LobbyClient *aClient = mGame->GetClient(aClientId); if(aClient==NULL) return; if(!aClient->IsPlayer()) { LobbyPlayerPtr aPlayer = LobbyPlayer::CreatePlayer(); if(!aPlayer->ReadData(theMsg)) return; aClient->SetPlayer(aPlayer); } else { // already know about him (can happen if we're the captain or it's our client right after we joined) if(!IAmCaptain()) // already got ourselves in the join game reply return; } LobbyEvent::BroadcastEvent(new PlayerChangedEvent(aClient,LobbyChangeType_Add)); if(aClient->SameTeam(mMyClient)) LobbyEvent::BroadcastEvent(new PlayerTeamChangedEvent(aClient,LobbyChangeType_Add)); mGame->HandlePlayerJoined(aClient); if(LobbyPersistentData::GetStagingSoundEffects()) LobbyMisc::PlaySound(LobbyGlobal_PlayerJoined_Sound); if(mEveryoneReadySoundState && !aClient->IsPlayerReady()) mEveryoneReadySoundState = false; UpdateStartButton(); }
void StagingLogic::HandlePlayerReady(ReadBuffer &theMsg, LobbyClient *theSender) { if(!theSender->IsCaptain(true)) return; unsigned short aClientId = theMsg.ReadShort(); bool isReady = theMsg.ReadBool(); LobbyClient *aClient = mGame->GetClient(aClientId); if(aClient==NULL) return; LobbyPlayer *aPlayer = aClient->GetPlayer(); if(aPlayer==NULL) return; aPlayer->SetReady(isReady); CheckPlayReadySound(); LobbyEvent::BroadcastEvent(new PlayerChangedEvent(aClient,LobbyChangeType_Modify)); }
/////////////////////////////////////////////////////////////////////////////// // GetHelpText: Return a block of text that sums up the chat commands. /////////////////////////////////////////////////////////////////////////////// GUIString ChatCommandParser::GetHelpText(unsigned short myClientId) { bool isAdmin = false; bool isModerator = false; bool isCaptain = false; bool isGameCaptain = false; bool isLan = mRoomSpecFlags&LobbyRoomSpecFlag_Lan?true:false; if(mClientList.get()!=NULL) { LobbyClient *aClient = mClientList->GetClient(myClientId); if(aClient!=NULL) { isModerator = aClient->IsModerator(); isCaptain = aClient->IsCaptain(mRoomSpecFlags&LobbyRoomSpecFlag_Game?true:false); isGameCaptain = aClient->IsCaptain(true); isAdmin = aClient->IsAdmin(); } } GUIString aHelp = ChatCommandLogic_HelpHeader_String; aHelp.append("<n>"); AddCommandToHelpText(LobbyChatCommand_Help, ChatCommandLogic_HelpHelp_String, aHelp); AddCommandToHelpText(LobbyChatCommand_Whisper, ChatCommandLogic_WhisperHelp_String, aHelp); AddCommandToHelpText(LobbyChatCommand_Reply, ChatCommandLogic_ReplyHelp_String, aHelp); AddCommandToHelpText(LobbyChatCommand_Emote, ChatCommandLogic_EmoteHelp_String, aHelp); AddCommandToHelpText(LobbyChatCommand_Ignore, ChatCommandLogic_IgnoreHelp_String, aHelp); AddCommandToHelpText(LobbyChatCommand_Clear, ChatCommandLogic_ClearHelp_String, aHelp); if(mRoomSpecFlags&LobbyRoomSpecFlag_Game) AddCommandToHelpText(LobbyChatCommand_ShowTeam, ChatCommandLogic_ShowTeamHelp_String, aHelp); if(!isLan) { AddCommandToHelpText(LobbyChatCommand_Block, ChatCommandLogic_BlockHelp_String, aHelp); AddCommandToHelpText(LobbyChatCommand_Away, ChatCommandLogic_AwayHelp_String, aHelp); if(isGameCaptain) { AddCommandToHelpText(LobbyChatCommand_Invite, ChatCommandLogic_InviteHelp_String, aHelp); AddCommandToHelpText(LobbyChatCommand_Uninvite, ChatCommandLogic_UninviteHelp_String, aHelp); } if(isCaptain || isModerator) { AddCommandToHelpText(LobbyChatCommand_Mute, ChatCommandLogic_MuteHelp_String, aHelp); AddCommandToHelpText(LobbyChatCommand_Unmute, ChatCommandLogic_UnmuteHelp_String, aHelp); AddCommandToHelpText(LobbyChatCommand_Ban, ChatCommandLogic_BanHelp_String, aHelp); AddCommandToHelpText(LobbyChatCommand_Unban, ChatCommandLogic_UnbanHelp_String, aHelp); } if(isModerator) { AddCommandToHelpText(LobbyChatCommand_BecomeModerator, ChatCommandLogic_ModeratorHelp_String, aHelp); AddCommandToHelpText(LobbyChatCommand_ServerMute, ChatCommandLogic_ServerMuteHelp_String, aHelp); AddCommandToHelpText(LobbyChatCommand_ServerUnmute, ChatCommandLogic_ServerUnmuteHelp_String, aHelp); AddCommandToHelpText(LobbyChatCommand_ServerBan, ChatCommandLogic_ServerBanHelp_String, aHelp); AddCommandToHelpText(LobbyChatCommand_ServerUnban, ChatCommandLogic_ServerUnbanHelp_String, aHelp); AddCommandToHelpText(LobbyChatCommand_Warn, ChatCommandLogic_WarnHelp_String, aHelp); } if(isAdmin) AddCommandToHelpText(LobbyChatCommand_Alert, ChatCommandLogic_AlertHelp_String, aHelp); } return aHelp; }
short LobbyGame::HandleJoinGameRequest(ReadBuffer &theMsg, LobbyClient *theClient, WriteBuffer &theReply) { LobbyPlayerPtr aPlayer; if(IsGameFull()) return LobbyGameStatus_GameFull; else if(mInProgress) return LobbyGameStatus_GameInProgress; LobbyConfig *aConfig = LobbyConfig::GetLobbyConfig(); if(aConfig!=NULL && !aConfig->mAllowDuplicateNames) { // check if the name is already used LobbyClientMap::const_iterator aClientItr = mClientList->GetClientMap().begin(); for(; aClientItr != mClientList->GetClientMap().end(); ++aClientItr) { if (aClientItr->second->GetName() == theClient->GetName() && aClientItr->second.get() != theClient) return LobbyGameStatus_DuplicateName; } } aPlayer = LobbyPlayer::CreatePlayer(); theClient->SetPlayer(aPlayer); try { unsigned short aPing = theMsg.ReadShort(); aPlayer->SetPing(aPing); short aStatus = HandleJoinGameRequestHook(theMsg, theClient); if(aStatus!=LobbyGameStatus_Success) { theClient->SetPlayer(NULL); return aStatus; } } catch(ReadBufferException&) { theClient->SetPlayer(NULL); return LobbyGameStatus_UnpackFailure; } // Send PlayerList back mNumPlayers++; theReply.AppendShort(mNumPlayers); LobbyPlayerList aList(mClientList); while(aList.HasMorePlayers()) { LobbyClient *aClient; LobbyPlayer *aPlayer = aList.GetNextPlayer(&aClient); if(aPlayer!=NULL) { theReply.AppendShort(aClient->GetClientId()); aPlayer->WriteData(theReply); } } GetJoinGameReplyHook(theClient,theReply); return LobbyGameStatus_Success; }