From 4cf42d2113f340e26b276ef40c526c2f86687083 Mon Sep 17 00:00:00 2001 From: lotodore Date: Sat, 15 Aug 2009 14:51:21 +0000 Subject: [PATCH] Lobby chat works now, but player list ist not yet shown. --- .../gamelobbydialog/lobbychat/lobbychat.cpp | 16 ++++------ src/net/common/clientstate.cpp | 8 ++--- src/net/common/servergamestate.cpp | 32 ++++++++++++------- src/net/common/serverlobbythread.cpp | 10 +++++- src/net/serverlobbythread.h | 1 + 5 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/gui/qt/gamelobbydialog/lobbychat/lobbychat.cpp b/src/gui/qt/gamelobbydialog/lobbychat/lobbychat.cpp index 08ae729d..c74cb9d8 100644 --- a/src/gui/qt/gamelobbydialog/lobbychat/lobbychat.cpp +++ b/src/gui/qt/gamelobbydialog/lobbychat/lobbychat.cpp @@ -42,20 +42,16 @@ LobbyChat::~LobbyChat() void LobbyChat::sendMessage() { + // TODO nick needs to be set earlier. if (myNick.isEmpty()) myNick = QString::fromUtf8(myConfig->readConfigString("MyName").c_str()); - if (!myNick.isEmpty()) + fillChatLinesHistory(myLobby->lineEdit_ChatInput->text()); + QString tmpMsg(myLobby->lineEdit_ChatInput->text()); + if (tmpMsg.size()) { - fillChatLinesHistory(myLobby->lineEdit_ChatInput->text()); - QString tmpMsg(myLobby->lineEdit_ChatInput->text()); - if (tmpMsg.size()) - { - myLobby->getSession()->sendLobbyChatMessage(tmpMsg.toUtf8().constData()); - myLobby->lineEdit_ChatInput->setText(""); - - displayMessage(myNick, tmpMsg); - } + myLobby->getSession()->sendLobbyChatMessage(tmpMsg.toUtf8().constData()); + myLobby->lineEdit_ChatInput->setText(""); } } diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index 639952a3..d8d94e42 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -826,11 +826,9 @@ AbstractClientStateReceiving::HandlePacket(boost::shared_ptr clien else if (netMessage->chatType.present == chatType_PR_chatTypeLobby) { unsigned playerId = netMessage->chatType.choice.chatTypeLobby.playerId; - boost::shared_ptr tmpPlayer = client->GetPlayerDataByUniqueId(playerId); - if (tmpPlayer.get()) - playerName = tmpPlayer->GetName(); - if (!playerName.empty()) - client->GetCallback().SignalNetClientLobbyChatMsg(playerName, STL_STRING_FROM_OCTET_STRING(netMessage->chatText)); + PlayerInfo info; + if (client->GetCachedPlayerInfo(playerId, info)) + client->GetCallback().SignalNetClientLobbyChatMsg(info.playerName, STL_STRING_FROM_OCTET_STRING(netMessage->chatText)); } } else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_dialogMessage) diff --git a/src/net/common/servergamestate.cpp b/src/net/common/servergamestate.cpp index 8fb66476..17541b7b 100644 --- a/src/net/common/servergamestate.cpp +++ b/src/net/common/servergamestate.cpp @@ -237,18 +237,26 @@ AbstractServerGameStateReceiving::ProcessPacket(boost::shared_ptr se // Forward chat text to all players. // TODO: Some limitation needed. ChatRequestMessage_t *netChatRequest = &packet->GetMsg()->choice.chatRequestMessage; - boost::shared_ptr packet(new NetPacket(NetPacket::Alloc)); - packet->GetMsg()->present = PokerTHMessage_PR_chatMessage; - ChatMessage_t *netChat = &packet->GetMsg()->choice.chatMessage; - netChat->chatType.present = chatType_PR_chatTypeGame; - ChatTypeGame_t *netGameChat = &netChat->chatType.choice.chatTypeGame; - netGameChat->gameId = server->GetId(); - netGameChat->playerId = session.playerData->GetUniqueId(); - OCTET_STRING_fromBuf( - &netChat->chatText, - (char *)netChatRequest->chatText.buf, - netChatRequest->chatText.size); - server->SendToAllPlayers(packet, SessionData::Game); + if (netChatRequest->chatRequestType.present == chatRequestType_PR_chatRequestTypeLobby) + { + if (!server->IsRunning()) + server->GetLobbyThread().HandleChatRequest(session, *netChatRequest); + } + else if (netChatRequest->chatRequestType.present == chatRequestType_PR_chatRequestTypeGame) + { + boost::shared_ptr packet(new NetPacket(NetPacket::Alloc)); + packet->GetMsg()->present = PokerTHMessage_PR_chatMessage; + ChatMessage_t *netChat = &packet->GetMsg()->choice.chatMessage; + netChat->chatType.present = chatType_PR_chatTypeGame; + ChatTypeGame_t *netGameChat = &netChat->chatType.choice.chatTypeGame; + netGameChat->gameId = server->GetId(); + netGameChat->playerId = session.playerData->GetUniqueId(); + OCTET_STRING_fromBuf( + &netChat->chatText, + (char *)netChatRequest->chatText.buf, + netChatRequest->chatText.size); + server->SendToAllPlayers(packet, SessionData::Game); + } } } else if (packet->GetMsg()->present == PokerTHMessage_PR_subscriptionRequestMessage) diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index 9fcf3c46..2a599042 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -355,6 +355,13 @@ ServerLobbyThread::HandleGameRetrieveAvatar(SessionWrapper session, const Avatar HandleNetPacketRetrieveAvatar(session, retrieveAvatar); } +void +ServerLobbyThread::HandleChatRequest(SessionWrapper session, const ChatRequestMessage_t &chatRequest) +{ + // Someone within a game sent a lobby message. + HandleNetPacketChatRequest(session, chatRequest); +} + bool ServerLobbyThread::KickPlayerByName(const std::string &playerName) { @@ -1087,7 +1094,8 @@ ServerLobbyThread::HandleNetPacketChatRequest(SessionWrapper session, const Chat (char *)chatRequest.chatText.buf, chatRequest.chatText.size); - m_sessionManager.SendToAllSessions(GetSender(), packet, SessionData::Established); + m_sessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Established); + m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Game); } } diff --git a/src/net/serverlobbythread.h b/src/net/serverlobbythread.h index e4a0f007..e7bb4f41 100644 --- a/src/net/serverlobbythread.h +++ b/src/net/serverlobbythread.h @@ -70,6 +70,7 @@ public: void HandleGameRetrievePlayerInfo(SessionWrapper session, const PlayerInfoRequestMessage_t &playerInfoRequest); void HandleGameRetrieveAvatar(SessionWrapper session, const AvatarRequestMessage_t &retrieveAvatar); + void HandleChatRequest(SessionWrapper session, const ChatRequestMessage_t &chatRequest); bool KickPlayerByName(const std::string &playerName); std::string GetPlayerIPAddress(const std::string &playerName) const;