2020-08-18 20:42:30 +00:00
|
|
|
#include "CNShardServer.hpp"
|
|
|
|
#include "CNStructs.hpp"
|
|
|
|
#include "ChatManager.hpp"
|
|
|
|
#include "PlayerManager.hpp"
|
|
|
|
|
|
|
|
void ChatManager::init() {
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_SEND_FREECHAT_MESSAGE, chatHandler);
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT, emoteHandler);
|
2020-08-22 18:11:47 +00:00
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_SEND_MENUCHAT_MESSAGE, menuChatHandler);
|
2020-08-18 20:42:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChatManager::chatHandler(CNSocket* sock, CNPacketData* data) {
|
2020-08-20 23:50:30 +00:00
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE))
|
|
|
|
return; // malformed packet
|
2020-08-18 20:42:30 +00:00
|
|
|
sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE* chat = (sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE*)data->buf;
|
2020-09-16 19:46:15 +00:00
|
|
|
PlayerView& plr = PlayerManager::players[sock];
|
2020-08-19 18:22:51 +00:00
|
|
|
|
2020-08-19 18:25:54 +00:00
|
|
|
// send to client
|
2020-08-23 00:26:18 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, resp);
|
2020-08-22 23:31:09 +00:00
|
|
|
memcpy(resp.szFreeChat, chat->szFreeChat, sizeof(chat->szFreeChat));
|
2020-08-24 22:02:07 +00:00
|
|
|
resp.iPC_ID = plr.plr->iID;
|
2020-08-22 23:31:09 +00:00
|
|
|
resp.iEmoteCode = chat->iEmoteCode;
|
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC));
|
2020-08-19 18:22:51 +00:00
|
|
|
|
2020-08-19 18:25:54 +00:00
|
|
|
// send to visible players
|
2020-09-17 22:45:43 +00:00
|
|
|
PlayerManager::sendToViewable(sock, (void*)&resp, P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC));
|
2020-08-18 20:42:30 +00:00
|
|
|
}
|
2020-09-16 19:46:15 +00:00
|
|
|
|
2020-08-22 18:11:47 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
// send to client
|
2020-08-23 00:26:18 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, resp);
|
2020-08-22 23:31:09 +00:00
|
|
|
memcpy(resp.szFreeChat, chat->szFreeChat, sizeof(chat->szFreeChat));
|
2020-08-24 22:02:07 +00:00
|
|
|
resp.iPC_ID = PlayerManager::players[sock].plr->iID;
|
2020-08-22 23:31:09 +00:00
|
|
|
resp.iEmoteCode = chat->iEmoteCode;
|
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC));
|
2020-08-18 20:42:30 +00:00
|
|
|
|
2020-08-22 18:11:47 +00:00
|
|
|
// send to visible players
|
2020-09-17 22:45:43 +00:00
|
|
|
PlayerManager::sendToViewable(sock, (void*)&resp, P_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC));
|
2020-08-22 18:11:47 +00:00
|
|
|
}
|
2020-09-16 19:46:15 +00:00
|
|
|
|
2020-08-18 20:42:30 +00:00
|
|
|
void ChatManager::emoteHandler(CNSocket* sock, CNPacketData* data) {
|
2020-08-19 00:11:31 +00:00
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT))
|
|
|
|
return; // ignore the malformed packet
|
|
|
|
|
2020-08-18 20:42:30 +00:00
|
|
|
// you can dance with friends!!!!!!!!
|
|
|
|
|
|
|
|
sP_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT* emote = (sP_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT*)data->buf;
|
2020-09-16 19:46:15 +00:00
|
|
|
PlayerView& plr = PlayerManager::players[sock];
|
2020-09-14 13:53:48 +00:00
|
|
|
|
2020-08-18 20:42:30 +00:00
|
|
|
// send to client
|
2020-08-23 00:26:18 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT, resp);
|
2020-08-22 23:31:09 +00:00
|
|
|
resp.iEmoteCode = emote->iEmoteCode;
|
2020-08-24 22:02:07 +00:00
|
|
|
resp.iID_From = plr.plr->iID;
|
2020-08-22 23:31:09 +00:00
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_AVATAR_EMOTES_CHAT, sizeof(sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT));
|
2020-08-18 20:42:30 +00:00
|
|
|
|
|
|
|
// send to visible players (players within render distance)
|
2020-09-17 22:45:43 +00:00
|
|
|
PlayerManager::sendToViewable(sock, (void*)&resp, P_FE2CL_REP_PC_AVATAR_EMOTES_CHAT, sizeof(sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT));
|
2020-08-18 20:42:30 +00:00
|
|
|
}
|