diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2012-01-21 05:10:39 +0800 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2012-01-21 05:56:26 +0800 |
commit | 80397d3f1c93d79a4151647e4a412bb003a0f9bc (patch) | |
tree | a25ae4fed6c45bac348e905a51f83e0d64ffddf4 | |
parent | 07da1b321cde4787aa51741079fa2e41fbf08a8b (diff) | |
download | manaserv-80397d3f1c93d79a4151647e4a412bb003a0f9bc.tar.gz manaserv-80397d3f1c93d79a4151647e4a412bb003a0f9bc.tar.xz manaserv-80397d3f1c93d79a4151647e4a412bb003a0f9bc.zip |
Made @announce fully functional
- Added announcements having senders now.
- Removed /announcement support.
Reviewed-by: Bjorn.
-rw-r--r-- | src/account-server/serverhandler.cpp | 8 | ||||
-rw-r--r-- | src/chat-server/chathandler.cpp | 53 | ||||
-rw-r--r-- | src/chat-server/chathandler.h | 7 | ||||
-rw-r--r-- | src/common/manaserv_protocol.h | 4 | ||||
-rw-r--r-- | src/game-server/commandhandler.cpp | 15 |
5 files changed, 40 insertions, 47 deletions
diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp index 6a41d71..041e8e6 100644 --- a/src/account-server/serverhandler.cpp +++ b/src/account-server/serverhandler.cpp @@ -601,6 +601,14 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) storage->removeFloorItem(mapId, itemId, amount, posX, posY); } break; + case GAMSG_ANNOUNCE: + { + const std::string message = msg.readString(); + const int senderId = msg.readInt16(); + const std::string senderName = msg.readString(); + chatHandler->handleAnnounce(message, senderId, senderName); + } break; + default: LOG_WARN("ServerHandler::processMessage, Invalid message type: " << msg.getId()); diff --git a/src/chat-server/chathandler.cpp b/src/chat-server/chathandler.cpp index e7ef11d..2e0bd60 100644 --- a/src/chat-server/chathandler.cpp +++ b/src/chat-server/chathandler.cpp @@ -157,10 +157,6 @@ void ChatHandler::processMessage(NetComputer *comp, MessageIn &message) handleChatMessage(computer, message); break; - case PCMSG_ANNOUNCE: - handleAnnounceMessage(computer, message); - break; - case PCMSG_PRIVMSG: handlePrivMsgMessage(computer, message); break; @@ -298,42 +294,25 @@ void ChatHandler::handleChatMessage(ChatClient &client, MessageIn &msg) storage->addTransaction(trans); } -void ChatHandler::handleAnnounceMessage(ChatClient &client, MessageIn &msg) +void ChatHandler::handleAnnounce(const std::string &message, int senderId, + const std::string &senderName) { - std::string text = msg.readString(); - - if (!stringFilter->filterContent(text)) - { - warnPlayerAboutBadWords(client); - return; - } - - if (client.accountLevel == AL_ADMIN || client.accountLevel == AL_GM) - { - // TODO: b_lindeijer: Shouldn't announcements also have a sender? - LOG_INFO("ANNOUNCE: " << text); - MessageOut result(CPMSG_ANNOUNCEMENT); - result.writeString(text); + // We do not need to check for right permissions since the game server does + // this. + MessageOut result(CPMSG_ANNOUNCEMENT); + result.writeString(message); + result.writeString(senderName); + sendToEveryone(result); - // We send the message to all players in the default channel as it is - // an announcement. - sendToEveryone(result); + if (!senderId) + return; // Do not log scripted announcements - // log transaction - Transaction trans; - trans.mCharacterId = client.characterId; - trans.mAction = TRANS_MSG_ANNOUNCE; - trans.mMessage = "User announced " + text; - storage->addTransaction(trans); - } - else - { - MessageOut result(CPMSG_ERROR); - result.writeInt8(ERRMSG_INSUFFICIENT_RIGHTS); - client.send(result); - LOG_INFO(client.characterName << - " couldn't make an announcement due to insufficient rights."); - } + // log transaction + Transaction trans; + trans.mCharacterId = senderId; + trans.mAction = TRANS_MSG_ANNOUNCE; + trans.mMessage = senderName + " announced: " + message; + storage->addTransaction(trans); } diff --git a/src/chat-server/chathandler.h b/src/chat-server/chathandler.h index 9796bf7..af22e45 100644 --- a/src/chat-server/chathandler.h +++ b/src/chat-server/chathandler.h @@ -113,6 +113,12 @@ class ChatHandler : public ConnectionHandler void handlePartyInvite(MessageIn &msg); /** + * Sends an announce to all connected clients. + */ + void handleAnnounce(const std::string &message, int senderId, + const std::string &senderName); + + /** * Returns ChatClient from the Player Map * @param The name of the character * @return The Chat Client @@ -156,7 +162,6 @@ class ChatHandler : public ConnectionHandler void handleCommand(ChatClient &client, const std::string &command); void handleChatMessage(ChatClient &client, MessageIn &msg); - void handleAnnounceMessage(ChatClient &client, MessageIn &msg); void handlePrivMsgMessage(ChatClient &client, MessageIn &msg); void handleWhoMessage(ChatClient &client); diff --git a/src/common/manaserv_protocol.h b/src/common/manaserv_protocol.h index 7ad2bc1..6c34276 100644 --- a/src/common/manaserv_protocol.h +++ b/src/common/manaserv_protocol.h @@ -209,11 +209,10 @@ enum { // Chat CPMSG_ERROR = 0x0401, // B error - CPMSG_ANNOUNCEMENT = 0x0402, // S text + CPMSG_ANNOUNCEMENT = 0x0402, // S text, S sender CPMSG_PRIVMSG = 0x0403, // S user, S text CPMSG_PUBMSG = 0x0404, // W channel, S user, S text PCMSG_CHAT = 0x0410, // S text, W channel - PCMSG_ANNOUNCE = 0x0411, // S text PCMSG_PRIVMSG = 0x0412, // S user, S text PCMSG_WHO = 0x0415, // - CPMSG_WHO_RESPONSE = 0x0416, // { S user } @@ -264,6 +263,7 @@ enum { GAMSG_TRANSACTION = 0x0600, // D character id, D action, S message GAMSG_CREATE_ITEM_ON_MAP = 0x0601, // D map id, D item id, W amount, W pos x, W pos y GAMSG_REMOVE_ITEM_ON_MAP = 0x0602, // D map id, D item id, W amount, W pos x, W pos y + GAMSG_ANNOUNCE = 0x0603, // S text, W senderid, S sendername XXMSG_INVALID = 0x7FFF }; diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index 687457b..6904e0f 100644 --- a/src/game-server/commandhandler.cpp +++ b/src/game-server/commandhandler.cpp @@ -1107,19 +1107,20 @@ static void handleReport(Character *player, std::string &args) // TODO: Send the report to a developer or something } -static void handleAnnounce(Character *player, std::string &msg) +static void handleAnnounce(Character *player, std::string &args) { - if (msg.empty()) + if (args.empty()) { say("Invalid number of arguments given.", player); say("Usage: @announce <message>", player); return; } - GameState::sayToAll(msg); - - // log transaction - accountHandler->sendTransaction(player->getDatabaseID(), TRANS_CMD_ANNOUNCE, msg); + MessageOut msg(GAMSG_ANNOUNCE); + msg.writeString(args); + msg.writeInt16(player->getDatabaseID()); + msg.writeString(player->getName()); + accountHandler->send(msg); } static void handleWhere(Character *player, std::string &) @@ -1463,7 +1464,7 @@ static void handleSkills(Character *player, std::string &args) say("List of skills of player '" + other->getName() + "':", player); std::map<int, int>::const_iterator it = other->getSkillBegin(); - std::map<int, int>::const_iterator it_end = other->getSkillEnd(); + std::map<int, int>::const_iterator it_end = other->getSkillEnd(); if (it == it_end) { |