MenuChat Added (#25)

* Update CNShardServer.hpp

* Update ChatManager.cpp

* Update ChatManager.hpp

Co-authored-by: CPunch <sethtstubbs@gmail.com>
This commit is contained in:
Zenpock 2020-08-22 13:11:47 -05:00 committed by GitHub
parent cd9fb6ec25
commit 4f10ee0505
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View File

@ -6,12 +6,12 @@
void ChatManager::init() { void ChatManager::init() {
REGISTER_SHARD_PACKET(P_CL2FE_REQ_SEND_FREECHAT_MESSAGE, chatHandler); 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_PC_AVATAR_EMOTES_CHAT, emoteHandler);
REGISTER_SHARD_PACKET(P_CL2FE_REQ_SEND_MENUCHAT_MESSAGE, menuChatHandler);
} }
void ChatManager::chatHandler(CNSocket* sock, CNPacketData* data) { void ChatManager::chatHandler(CNSocket* sock, CNPacketData* data) {
if (data->size != sizeof(sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE)) if (data->size != sizeof(sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE))
return; // malformed packet return; // malformed packet
sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE* chat = (sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE*)data->buf; sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE* chat = (sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE*)data->buf;
PlayerView plr = PlayerManager::players[sock]; 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())); 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) { void ChatManager::emoteHandler(CNSocket* sock, CNPacketData* data) {
if (data->size != sizeof(sP_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT)) if (data->size != sizeof(sP_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT))
return; // ignore the malformed packet return; // ignore the malformed packet

View File

@ -8,6 +8,7 @@ namespace ChatManager {
void chatHandler(CNSocket* sock, CNPacketData* data); void chatHandler(CNSocket* sock, CNPacketData* data);
void emoteHandler(CNSocket* sock, CNPacketData* data); void emoteHandler(CNSocket* sock, CNPacketData* data);
void menuChatHandler(CNSocket* sock, CNPacketData* data);
} }
#endif #endif