From b08fb52272c8f4c1e031a77d9478bde394dbf4ff Mon Sep 17 00:00:00 2001 From: Titan <70135297+darkredtitan@users.noreply.github.com> Date: Thu, 19 Nov 2020 18:19:22 +0200 Subject: [PATCH] Implement /announce --- src/ChatManager.cpp | 33 +++++++++++++++++++++++++++++++++ src/ChatManager.hpp | 1 + 2 files changed, 34 insertions(+) diff --git a/src/ChatManager.cpp b/src/ChatManager.cpp index 8e9f48e..4809999 100644 --- a/src/ChatManager.cpp +++ b/src/ChatManager.cpp @@ -528,6 +528,7 @@ void ChatManager::init() { REGISTER_SHARD_PACKET(P_CL2FE_REQ_SEND_FREECHAT_MESSAGE, chatHandler); REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT, emoteHandler); REGISTER_SHARD_PACKET(P_CL2FE_REQ_SEND_MENUCHAT_MESSAGE, menuChatHandler); + REGISTER_SHARD_PACKET(P_CL2FE_GM_REQ_PC_ANNOUNCE, announcementHandler); registerCommand("help", 100, helpCommand, "list all unlocked server-side commands"); registerCommand("access", 100, accessCommand, "print your access level"); @@ -637,6 +638,38 @@ void ChatManager::sendServerMessage(CNSocket* sock, std::string msg) { sock->sendPacket((void*)&motd, P_FE2CL_PC_MOTD_LOGIN, sizeof(sP_FE2CL_PC_MOTD_LOGIN)); } +void ChatManager::announcementHandler(CNSocket* sock, CNPacketData* data) { + if (data->size != sizeof(sP_CL2FE_GM_REQ_PC_ANNOUNCE)) + return; // ignore malformed packet + if (PlayerManager::getPlayer(sock)->accountLevel > 30) + return; // only players with account level less than 30 (GM) are allowed to use this command + sP_CL2FE_GM_REQ_PC_ANNOUNCE* announcement = (sP_CL2FE_GM_REQ_PC_ANNOUNCE*)data->buf; + + INITSTRUCT(sP_FE2CL_GM_REP_PC_ANNOUNCE, msg); + msg.iAnnounceType = announcement->iAnnounceType; + msg.iDuringTime = announcement->iDuringTime; + memcpy(msg.szAnnounceMsg, announcement->szAnnounceMsg, sizeof(msg.szAnnounceMsg)); + std::map::iterator it; + + switch (announcement->iAreaType) { + case 0: // area + break; // stubbed for now + case 1: // shard + break; //stubbed for now + case 2: // world + break; // stubbed for now + case 3: // global + + // send announced messqage to ALL players + for (it = PlayerManager::players.begin(); it != PlayerManager::players.end(); it++) { + CNSocket* allSock = it->first; + allSock->sendPacket((void*)&msg, P_FE2CL_GM_REP_PC_ANNOUNCE, sizeof(sP_FE2CL_GM_REP_PC_ANNOUNCE)); + } + default: + break; + } +} + // we only allow plain ascii, at least for now std::string ChatManager::sanitizeText(std::string text) { int i; diff --git a/src/ChatManager.hpp b/src/ChatManager.hpp index 1a7d536..59a8125 100644 --- a/src/ChatManager.hpp +++ b/src/ChatManager.hpp @@ -27,6 +27,7 @@ namespace ChatManager { void emoteHandler(CNSocket* sock, CNPacketData* data); void menuChatHandler(CNSocket* sock, CNPacketData* data); void sendServerMessage(CNSocket* sock, std::string msg); // uses MOTD + void announcementHandler(CNSocket* sock, CNPacketData* data); std::string sanitizeText(std::string text); }