diff --git a/src/gui/generic/serverguiwrapper.cpp b/src/gui/generic/serverguiwrapper.cpp index a0191f6d..657cc349 100644 --- a/src/gui/generic/serverguiwrapper.cpp +++ b/src/gui/generic/serverguiwrapper.cpp @@ -158,3 +158,7 @@ void ServerGuiWrapper::SignalIrcPlayerLeft(const string &nickName) { if (myIrccb void ServerGuiWrapper::SignalIrcChatMsg(const string &nickName, const string &msg) { if (myIrccb) myIrccb->SignalIrcChatMsg(nickName, msg); } void ServerGuiWrapper::SignalIrcError(int errorCode) { if (myIrccb) myIrccb->SignalIrcError(errorCode); } void ServerGuiWrapper::SignalIrcServerError(int errorCode) {if (myIrccb) myIrccb->SignalIrcServerError(errorCode); } + +void ServerGuiWrapper::SignalLobbyPlayerJoined(unsigned playerId, const std::string &nickName) { if (myClientcb) myClientcb->SignalLobbyPlayerJoined(playerId, nickName); } +void ServerGuiWrapper::SignalLobbyPlayerKicked(const std::string &nickName, const std::string &byWhom, const std::string &reason) { if (myClientcb) myClientcb->SignalLobbyPlayerKicked(nickName, byWhom, reason); } +void ServerGuiWrapper::SignalLobbyPlayerLeft(unsigned playerId) { if (myClientcb) myClientcb->SignalLobbyPlayerLeft(playerId); } diff --git a/src/gui/generic/serverguiwrapper.h b/src/gui/generic/serverguiwrapper.h index e6262ca8..2edc0513 100644 --- a/src/gui/generic/serverguiwrapper.h +++ b/src/gui/generic/serverguiwrapper.h @@ -145,6 +145,9 @@ public: void SignalNetClientMsgBox(const std::string &msg); void SignalIrcError(int errorCode); void SignalIrcServerError(int errorCode); + void SignalLobbyPlayerJoined(unsigned playerId, const std::string &nickName); + void SignalLobbyPlayerKicked(const std::string &nickName, const std::string &byWhom, const std::string &reason); + void SignalLobbyPlayerLeft(unsigned playerId); private: diff --git a/src/net/clientcallback.h b/src/net/clientcallback.h index 4f5485a8..8408b915 100644 --- a/src/net/clientcallback.h +++ b/src/net/clientcallback.h @@ -66,6 +66,10 @@ public: virtual void SignalNetClientServerListClear() =0; virtual void SignalNetClientServerListShow() =0; + virtual void SignalLobbyPlayerJoined(unsigned playerId, const std::string &nickName) = 0; + virtual void SignalLobbyPlayerKicked(const std::string &nickName, const std::string &byWhom, const std::string &reason) = 0; + virtual void SignalLobbyPlayerLeft(unsigned playerId) = 0; + }; #endif diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index d8d94e42..254c86b8 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -730,7 +730,6 @@ AbstractClientStateReceiving::HandlePacket(boost::shared_ptr clien if (netInfo->avatarData != NULL) { tmpInfo.hasAvatar = true; - // TODO: use sha1. memcpy(tmpInfo.avatar.data, netInfo->avatarData->avatar.buf, MD5_DATA_SIZE); tmpInfo.avatarType = (AvatarFileType)netInfo->avatarData->avatarType; } @@ -840,11 +839,23 @@ AbstractClientStateReceiving::HandlePacket(boost::shared_ptr clien else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_playerListMessage) { PlayerListMessage_t *netPlayerList = &tmpPacket->GetMsg()->choice.playerListMessage; - PlayerInfo info; - if (!client->GetCachedPlayerInfo(netPlayerList->playerId, info)) + + if (netPlayerList->playerListNotification == playerListNotification_playerListNew) { - // Request player info. - client->RequestPlayerInfo(netPlayerList->playerId); + PlayerInfo info; + if (!client->GetCachedPlayerInfo(netPlayerList->playerId, info)) + { + // Request player info. + ostringstream name; + name << "#" << netPlayerList->playerId; + info.playerName = name.str(); + client->RequestPlayerInfo(netPlayerList->playerId); + } + client->GetCallback().SignalLobbyPlayerJoined(netPlayerList->playerId, info.playerName); + } + else if (netPlayerList->playerListNotification == playerListNotification_playerListLeft) + { + client->GetCallback().SignalLobbyPlayerLeft(netPlayerList->playerId); } } else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_gameListMessage) diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index 2a599042..a1570b2a 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -263,6 +263,8 @@ ServerLobbyThread::CloseSession(SessionWrapper session) m_sessionManager.RemoveSession(session.sessionData->GetId()); m_gameSessionManager.RemoveSession(session.sessionData->GetId()); + if (session.playerData) + NotifyPlayerLeftLobby(session.playerData->GetUniqueId()); // Update stats (if needed). UpdateStatisticsNumberOfPlayers(); } @@ -274,6 +276,22 @@ ServerLobbyThread::ResubscribeLobbyMsg(SessionWrapper session) InternalResubscribeMsg(session); } +void +ServerLobbyThread::NotifyPlayerJoinedLobby(unsigned playerId) +{ + boost::shared_ptr notify = CreateNetPacketPlayerListNew(playerId); + m_sessionManager.SendLobbyMsgToAllSessions(GetSender(), notify, SessionData::Established); + m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), notify, SessionData::Game); +} + +void +ServerLobbyThread::NotifyPlayerLeftLobby(unsigned playerId) +{ + boost::shared_ptr notify = CreateNetPacketPlayerListLeft(playerId); + m_sessionManager.SendLobbyMsgToAllSessions(GetSender(), notify, SessionData::Established); + m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), notify, SessionData::Game); +} + void ServerLobbyThread::NotifyPlayerJoinedGame(unsigned gameId, unsigned playerId) { @@ -1129,9 +1147,7 @@ ServerLobbyThread::EstablishSession(SessionWrapper session) m_statDataChanged = true; } // Notify all players. - boost::shared_ptr notify = CreateNetPacketPlayerListNew(session.playerData->GetUniqueId()); - m_sessionManager.SendLobbyMsgToAllSessions(GetSender(), notify, SessionData::Established); - m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), notify, SessionData::Game); + NotifyPlayerJoinedLobby(session.playerData->GetUniqueId()); UpdateStatisticsNumberOfPlayers(); } diff --git a/src/net/serverlobbythread.h b/src/net/serverlobbythread.h index e7bb4f41..29143561 100644 --- a/src/net/serverlobbythread.h +++ b/src/net/serverlobbythread.h @@ -62,6 +62,8 @@ public: void RemoveSessionFromGame(SessionWrapper session); void SessionError(SessionWrapper session, int errorCode); void ResubscribeLobbyMsg(SessionWrapper session); + void NotifyPlayerJoinedLobby(unsigned playerId); + void NotifyPlayerLeftLobby(unsigned playerId); void NotifyPlayerJoinedGame(unsigned gameId, unsigned playerId); void NotifyPlayerLeftGame(unsigned gameId, unsigned playerId); void NotifyGameAdminChanged(unsigned gameId, unsigned newAdminPlayerId);