From e840b3c04ca5a05a91b1d74fa4598789fdba9907 Mon Sep 17 00:00:00 2001 From: Carlos Fernandez Date: Fri, 22 Oct 2010 23:54:59 -0400 Subject: [PATCH] Implemented important message --HG-- extra : rebase_source : f2ab2cb7df6d22f6e754ecf932f30ddf14822e04 --- src/network/network.cpp | 52 +++++++++++++++++++++++++++++++++++++++-- src/network/network.h | 3 ++- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/network/network.cpp b/src/network/network.cpp index 3546eac..e2f12b9 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -176,7 +176,8 @@ class InMessage { CLIENT_ACTIVITY = 18, CANCEL_QUEUE = 19, CANCEL_BATTLE_ACTION = 20, - PRIVATE_MESSAGE = 21 + PRIVATE_MESSAGE = 21, + IMPORTANT_MESSAGE = 22 }; InMessage() { @@ -583,6 +584,17 @@ class PrivateMessage : public OutMessage { } }; +class ImportantMessage : public OutMessage { +public: + ImportantMessage(const int channel, const string &sender, + const string &message): OutMessage(IMPORTANT_MESSAGE) { + *this << channel; + *this << sender; + *this << message; + finalise(); + } +}; + class MetagameQueue { public: typedef pair QUEUE_ENTRY; @@ -1499,6 +1511,41 @@ class ClientImpl : public Client, public enable_shared_from_this { client->sendMessage(PrivateMessage(m_name, m_name, content)); } + /** + * int32 : channel (-1 for global) + * string : the message to display + */ + void handleImportantMessage(InMessage &msg) { + int channelId; + string message; + msg >> channelId >> message; + + ChannelPtr channel = (channelId == -1) ? + m_server->getMainChannel() : getChannel(channelId); + if (!channel) { + return; + } + + Channel::Type::TYPE type = channel->getChannelType(); + Channel::FLAGS auth = channel->getStatusFlags(shared_from_this()); + if ((type == Channel::Type::BATTLE) && !auth[Channel::PROTECTED]) { + return; + } + if (!auth[Channel::OP]) { + return; + } + + m_server->broadcast(ImportantMessage(channelId, m_name, message)); + + string logMessage; + if (channelId == -1) { + logMessage = "[important-global] " + m_name + ": " + message; + } else { + logMessage = "[important] " + m_name + ": " + message; + } + channel->writeLog(logMessage); + } + string m_name; int m_id; // user id bool m_authenticated; @@ -1550,7 +1597,8 @@ const ClientImpl::MESSAGE_HANDLER ClientImpl::m_handlers[] = { &ClientImpl::handleActivityMessage, &ClientImpl::handleCancelQueue, &ClientImpl::handleCancelBattleAction, - &ClientImpl::handlePrivateMessage + &ClientImpl::handlePrivateMessage, + &ClientImpl::handleImportantMessage }; const int ClientImpl::MESSAGE_COUNT = diff --git a/src/network/network.h b/src/network/network.h index e39c9e0..4ebd0d8 100644 --- a/src/network/network.h +++ b/src/network/network.h @@ -139,7 +139,8 @@ class OutMessage { CLAUSE_LIST = 31, INVALID_TEAM = 32, ERROR_MESSAGE = 33, - PRIVATE_MESSAGE = 34 + PRIVATE_MESSAGE = 34, + IMPORTANT_MESSAGE = 35 }; // variable size message