From 4f48fdbe2a79806e65bf20fcfde6f6fe1849cafc Mon Sep 17 00:00:00 2001 From: lotodore Date: Fri, 26 Dec 2008 13:50:09 +0000 Subject: [PATCH] Allow the server to send a global notice to all players (for example if a server reboot is going to happen). Does not work with current client version 0.6.3. --- src/net/common/clientstate.cpp | 16 +++++++++++++--- src/net/common/serverlobbythread.cpp | 25 ++++++++++++++++++++++--- src/net/common/servermanager.cpp | 13 +++++++++++++ src/net/serverlobbythread.h | 2 ++ 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index a5d635b5..c46e2a5c 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -691,9 +691,19 @@ AbstractClientStateReceiving::Process(ClientThread &client) NetPacketChatText::Data chatData; tmpPacket->ToNetPacketChatText()->GetData(chatData); - boost::shared_ptr tmpPlayer = client.GetPlayerDataByUniqueId(chatData.playerId); - if (tmpPlayer.get()) - client.GetCallback().SignalNetClientChatMsg(tmpPlayer->GetName(), chatData.text); + string playerName; + if (chatData.playerId == 0) + { + playerName = "(global notice)"; + } + else + { + boost::shared_ptr tmpPlayer = client.GetPlayerDataByUniqueId(chatData.playerId); + if (tmpPlayer.get()) + playerName = tmpPlayer->GetName(); + } + if (!playerName.empty()) + client.GetCallback().SignalNetClientChatMsg(playerName, chatData.text); } else if (tmpPacket->ToNetPacketPlayerLeft()) { diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index eeca6e90..8b8dd285 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -77,7 +77,7 @@ private: ServerLobbyThread::ServerLobbyThread(GuiInterface &gui, ConfigFile *playerConfig, AvatarManager &avatarManager) : m_gui(gui), m_avatarManager(avatarManager), m_playerConfig(playerConfig), - m_curGameId(0), m_curUniquePlayerId(0), m_curSessionId(INVALID_SESSION + 1), + m_curGameId(1), m_curUniquePlayerId(1), m_curSessionId(INVALID_SESSION + 1), m_statDataChanged(false), m_startTime(boost::posix_time::second_clock::local_time()) { m_senderCallback.reset(new ServerSenderCallback(*this)); @@ -259,6 +259,17 @@ ServerLobbyThread::RemovePlayer(unsigned playerId, unsigned errorCode) m_removePlayerList.push_back(RemovePlayerList::value_type(playerId, errorCode)); } +void +ServerLobbyThread::SendGlobalNotice(const std::string &message) +{ + boost::shared_ptr outChat(new NetPacketChatText); + NetPacketChatText::Data outChatData; + outChatData.playerId = 0; + outChatData.text = message; + static_cast(outChat.get())->SetData(outChatData); + m_gameSessionManager.SendToAllSessions(GetSender(), outChat, SessionData::Game); +} + void ServerLobbyThread::AddComputerPlayer(boost::shared_ptr player) { @@ -303,13 +314,21 @@ u_int32_t ServerLobbyThread::GetNextUniquePlayerId() { boost::mutex::scoped_lock lock(m_curUniquePlayerIdMutex); - return m_curUniquePlayerId++; + m_curUniquePlayerId++; + if (m_curUniquePlayerId == 0) // 0 is an invalid id. + m_curUniquePlayerId++; + + return m_curUniquePlayerId; } u_int32_t ServerLobbyThread::GetNextGameId() { - return m_curGameId++; + m_curGameId++; + if (m_curGameId == 0) // 0 is an invalid id. + m_curGameId++; + + return m_curGameId; } void diff --git a/src/net/common/servermanager.cpp b/src/net/common/servermanager.cpp index 47146c91..598bc5d2 100644 --- a/src/net/common/servermanager.cpp +++ b/src/net/common/servermanager.cpp @@ -147,6 +147,19 @@ ServerManager::SignalIrcChatMsg(const std::string &nickName, const std::string & m_ircThread->SendChatMessage(statStream.str()); } } + else if (command == "msg") + { + while (msgStream.peek() == ' ') + msgStream.get(); + string message(msgStream.str().substr(msgStream.tellg())); + if (!message.empty()) + { + GetLobbyThread().SendGlobalNotice(message); + m_ircThread->SendChatMessage(nickName + ": Global notice sent."); + } + else + m_ircThread->SendChatMessage(nickName + ": Invalid message."); + } else m_ircThread->SendChatMessage(nickName + ": Invalid command \"" + command + "\"."); } diff --git a/src/net/serverlobbythread.h b/src/net/serverlobbythread.h index 0d626b22..8f21bc1e 100644 --- a/src/net/serverlobbythread.h +++ b/src/net/serverlobbythread.h @@ -70,6 +70,8 @@ public: bool KickPlayerByName(const std::string &playerName); void RemovePlayer(unsigned playerId, unsigned errorCode); + void SendGlobalNotice(const std::string &message); + void AddComputerPlayer(boost::shared_ptr player); void RemoveComputerPlayer(boost::shared_ptr player);