From 4f10ee050507f9295297065a3d46abe70963e6f2 Mon Sep 17 00:00:00 2001 From: Zenpock <70054140+Zenpock@users.noreply.github.com> Date: Sat, 22 Aug 2020 13:11:47 -0500 Subject: [PATCH] MenuChat Added (#25) * Update CNShardServer.hpp * Update ChatManager.cpp * Update ChatManager.hpp Co-authored-by: CPunch --- src/ChatManager.cpp | 23 ++++++++++++++++++++++- src/ChatManager.hpp | 3 ++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/ChatManager.cpp b/src/ChatManager.cpp index efbc77f..f786c95 100644 --- a/src/ChatManager.cpp +++ b/src/ChatManager.cpp @@ -6,12 +6,12 @@ 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); } void ChatManager::chatHandler(CNSocket* sock, CNPacketData* data) { if (data->size != sizeof(sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE)) return; // malformed packet - sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE* chat = (sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE*)data->buf; PlayerView plr = PlayerManager::players[sock]; @@ -31,7 +31,28 @@ void ChatManager::chatHandler(CNSocket* sock, CNPacketData* data) { otherSock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC), otherSock->getFEKey())); } } +void ChatManager::menuChatHandler(CNSocket* sock, CNPacketData* data) { + if (data->size != sizeof(sP_CL2FE_REQ_SEND_MENUCHAT_MESSAGE)) + return; // malformed packet + sP_CL2FE_REQ_SEND_MENUCHAT_MESSAGE* chat = (sP_CL2FE_REQ_SEND_MENUCHAT_MESSAGE*)data->buf; + PlayerView plr = PlayerManager::players[sock]; + // send to client + sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC* resp = (sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC)); + memcpy(resp->szFreeChat, chat->szFreeChat, sizeof(chat->szFreeChat)); + resp->iPC_ID = PlayerManager::players[sock].plr.iID; + resp->iEmoteCode = chat->iEmoteCode; + sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC), sock->getFEKey())); + + // send to visible players + for (CNSocket* otherSock : plr.viewable) { + sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC* resp = (sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC)); + memcpy(resp->szFreeChat, chat->szFreeChat, sizeof(chat->szFreeChat)); + resp->iPC_ID = PlayerManager::players[sock].plr.iID; + resp->iEmoteCode = chat->iEmoteCode; + otherSock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC), otherSock->getFEKey())); + } +} void ChatManager::emoteHandler(CNSocket* sock, CNPacketData* data) { if (data->size != sizeof(sP_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT)) return; // ignore the malformed packet diff --git a/src/ChatManager.hpp b/src/ChatManager.hpp index 3f669d7..241d47b 100644 --- a/src/ChatManager.hpp +++ b/src/ChatManager.hpp @@ -8,6 +8,7 @@ namespace ChatManager { void chatHandler(CNSocket* sock, CNPacketData* data); void emoteHandler(CNSocket* sock, CNPacketData* data); + void menuChatHandler(CNSocket* sock, CNPacketData* data); } -#endif \ No newline at end of file +#endif