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.

This commit is contained in:
lotodore
2008-12-26 13:50:09 +00:00
parent 5623e0865d
commit 4f48fdbe2a
4 changed files with 50 additions and 6 deletions
+13 -3
View File
@@ -691,9 +691,19 @@ AbstractClientStateReceiving::Process(ClientThread &client)
NetPacketChatText::Data chatData; NetPacketChatText::Data chatData;
tmpPacket->ToNetPacketChatText()->GetData(chatData); tmpPacket->ToNetPacketChatText()->GetData(chatData);
boost::shared_ptr<PlayerData> tmpPlayer = client.GetPlayerDataByUniqueId(chatData.playerId); string playerName;
if (tmpPlayer.get()) if (chatData.playerId == 0)
client.GetCallback().SignalNetClientChatMsg(tmpPlayer->GetName(), chatData.text); {
playerName = "(global notice)";
}
else
{
boost::shared_ptr<PlayerData> tmpPlayer = client.GetPlayerDataByUniqueId(chatData.playerId);
if (tmpPlayer.get())
playerName = tmpPlayer->GetName();
}
if (!playerName.empty())
client.GetCallback().SignalNetClientChatMsg(playerName, chatData.text);
} }
else if (tmpPacket->ToNetPacketPlayerLeft()) else if (tmpPacket->ToNetPacketPlayerLeft())
{ {
+22 -3
View File
@@ -77,7 +77,7 @@ private:
ServerLobbyThread::ServerLobbyThread(GuiInterface &gui, ConfigFile *playerConfig, AvatarManager &avatarManager) ServerLobbyThread::ServerLobbyThread(GuiInterface &gui, ConfigFile *playerConfig, AvatarManager &avatarManager)
: m_gui(gui), m_avatarManager(avatarManager), m_playerConfig(playerConfig), : 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_statDataChanged(false), m_startTime(boost::posix_time::second_clock::local_time())
{ {
m_senderCallback.reset(new ServerSenderCallback(*this)); 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)); m_removePlayerList.push_back(RemovePlayerList::value_type(playerId, errorCode));
} }
void
ServerLobbyThread::SendGlobalNotice(const std::string &message)
{
boost::shared_ptr<NetPacket> outChat(new NetPacketChatText);
NetPacketChatText::Data outChatData;
outChatData.playerId = 0;
outChatData.text = message;
static_cast<NetPacketChatText *>(outChat.get())->SetData(outChatData);
m_gameSessionManager.SendToAllSessions(GetSender(), outChat, SessionData::Game);
}
void void
ServerLobbyThread::AddComputerPlayer(boost::shared_ptr<PlayerData> player) ServerLobbyThread::AddComputerPlayer(boost::shared_ptr<PlayerData> player)
{ {
@@ -303,13 +314,21 @@ u_int32_t
ServerLobbyThread::GetNextUniquePlayerId() ServerLobbyThread::GetNextUniquePlayerId()
{ {
boost::mutex::scoped_lock lock(m_curUniquePlayerIdMutex); 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 u_int32_t
ServerLobbyThread::GetNextGameId() ServerLobbyThread::GetNextGameId()
{ {
return m_curGameId++; m_curGameId++;
if (m_curGameId == 0) // 0 is an invalid id.
m_curGameId++;
return m_curGameId;
} }
void void
+13
View File
@@ -147,6 +147,19 @@ ServerManager::SignalIrcChatMsg(const std::string &nickName, const std::string &
m_ircThread->SendChatMessage(statStream.str()); 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 else
m_ircThread->SendChatMessage(nickName + ": Invalid command \"" + command + "\"."); m_ircThread->SendChatMessage(nickName + ": Invalid command \"" + command + "\".");
} }
+2
View File
@@ -70,6 +70,8 @@ public:
bool KickPlayerByName(const std::string &playerName); bool KickPlayerByName(const std::string &playerName);
void RemovePlayer(unsigned playerId, unsigned errorCode); void RemovePlayer(unsigned playerId, unsigned errorCode);
void SendGlobalNotice(const std::string &message);
void AddComputerPlayer(boost::shared_ptr<PlayerData> player); void AddComputerPlayer(boost::shared_ptr<PlayerData> player);
void RemoveComputerPlayer(boost::shared_ptr<PlayerData> player); void RemoveComputerPlayer(boost::shared_ptr<PlayerData> player);