2021-03-16 22:29:13 +00:00
|
|
|
#include "Chat.hpp"
|
2022-07-16 23:19:40 +00:00
|
|
|
|
|
|
|
#include "servers/CNShardServer.hpp"
|
|
|
|
|
|
|
|
#include "Player.hpp"
|
2020-08-18 20:42:30 +00:00
|
|
|
#include "PlayerManager.hpp"
|
2021-03-12 19:07:26 +00:00
|
|
|
#include "CustomCommands.hpp"
|
2020-10-07 18:38:32 +00:00
|
|
|
|
2021-03-12 19:07:26 +00:00
|
|
|
#include <assert.h>
|
2020-10-18 21:02:51 +00:00
|
|
|
|
2021-03-16 22:29:13 +00:00
|
|
|
std::vector<std::string> Chat::dump;
|
2021-03-06 21:29:52 +00:00
|
|
|
|
2021-03-16 22:29:13 +00:00
|
|
|
using namespace Chat;
|
2021-03-12 19:07:26 +00:00
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
static void chatHandler(CNSocket* sock, CNPacketData* data) {
|
2021-03-20 20:19:48 +00:00
|
|
|
auto chat = (sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE*)data->buf;
|
2020-10-02 23:50:47 +00:00
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
|
|
|
|
2021-03-18 04:41:47 +00:00
|
|
|
std::string fullChat = sanitizeText(AUTOU16TOU8(chat->szFreeChat));
|
2020-10-03 00:20:59 +00:00
|
|
|
if (fullChat.length() > 1 && fullChat[0] == CMD_PREFIX) { // PREFIX
|
2021-03-12 19:07:26 +00:00
|
|
|
CustomCommands::runCmd(fullChat, sock);
|
2020-10-02 23:50:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-08-19 18:22:51 +00:00
|
|
|
|
2020-12-31 01:13:43 +00:00
|
|
|
if (plr->iSpecialState & CN_SPECIAL_STATE_FLAG__MUTE_FREECHAT)
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::string logLine = "[FreeChat] " + PlayerManager::getPlayerName(plr, true) + ": " + fullChat;
|
|
|
|
|
|
|
|
std::cout << logLine << std::endl;
|
|
|
|
dump.push_back(logLine);
|
|
|
|
|
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-10-31 20:31:25 +00:00
|
|
|
|
|
|
|
U8toU16(fullChat, (char16_t*)&resp.szFreeChat, sizeof(resp.szFreeChat));
|
2020-10-02 23:50:47 +00:00
|
|
|
resp.iPC_ID = plr->iID;
|
2020-08-22 23:31:09 +00:00
|
|
|
resp.iEmoteCode = chat->iEmoteCode;
|
2020-10-31 20:31:25 +00:00
|
|
|
|
2021-03-20 20:19:48 +00:00
|
|
|
sock->sendPacket(resp, P_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
|
2021-03-20 20:19:48 +00:00
|
|
|
PlayerManager::sendToViewable(sock, resp, P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC);
|
2020-08-18 20:42:30 +00:00
|
|
|
}
|
2020-09-16 19:46:15 +00:00
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
static void menuChatHandler(CNSocket* sock, CNPacketData* data) {
|
2021-03-20 20:19:48 +00:00
|
|
|
auto chat = (sP_CL2FE_REQ_SEND_MENUCHAT_MESSAGE*)data->buf;
|
2020-10-31 20:31:25 +00:00
|
|
|
Player *plr = PlayerManager::getPlayer(sock);
|
|
|
|
|
2021-03-18 04:41:47 +00:00
|
|
|
std::string fullChat = sanitizeText(AUTOU16TOU8(chat->szFreeChat));
|
2020-12-31 01:13:43 +00:00
|
|
|
std::string logLine = "[MenuChat] " + PlayerManager::getPlayerName(plr, true) + ": " + fullChat;
|
2020-10-31 20:31:25 +00:00
|
|
|
|
2020-12-31 01:13:43 +00:00
|
|
|
std::cout << logLine << std::endl;
|
|
|
|
dump.push_back(logLine);
|
2020-08-22 18:11:47 +00:00
|
|
|
|
|
|
|
// send to client
|
2020-08-23 00:26:18 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, resp);
|
2020-10-31 20:31:25 +00:00
|
|
|
|
|
|
|
U8toU16(fullChat, (char16_t*)&resp.szFreeChat, sizeof(resp.szFreeChat));
|
2020-11-17 23:16:16 +00:00
|
|
|
resp.iPC_ID = PlayerManager::getPlayer(sock)->iID;
|
2020-08-22 23:31:09 +00:00
|
|
|
resp.iEmoteCode = chat->iEmoteCode;
|
2020-10-31 20:31:25 +00:00
|
|
|
|
2021-03-20 20:19:48 +00:00
|
|
|
sock->sendPacket(resp, P_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
|
2021-03-20 20:19:48 +00:00
|
|
|
PlayerManager::sendToViewable(sock, resp, P_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC);
|
2020-08-22 18:11:47 +00:00
|
|
|
}
|
2020-09-16 19:46:15 +00:00
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
static void emoteHandler(CNSocket* sock, CNPacketData* data) {
|
2021-03-20 20:19:48 +00:00
|
|
|
auto emote = (sP_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT*)data->buf;
|
2020-10-02 23:50:47 +00:00
|
|
|
Player* plr = PlayerManager::getPlayer(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-10-02 23:50:47 +00:00
|
|
|
resp.iID_From = plr->iID;
|
2021-03-20 20:19:48 +00:00
|
|
|
sock->sendPacket(resp, P_FE2CL_REP_PC_AVATAR_EMOTES_CHAT);
|
2020-08-18 20:42:30 +00:00
|
|
|
|
|
|
|
// send to visible players (players within render distance)
|
2021-03-20 20:19:48 +00:00
|
|
|
PlayerManager::sendToViewable(sock, resp, P_FE2CL_REP_PC_AVATAR_EMOTES_CHAT);
|
2020-08-18 20:42:30 +00:00
|
|
|
}
|
2020-10-02 23:50:47 +00:00
|
|
|
|
2021-03-16 22:29:13 +00:00
|
|
|
void Chat::sendServerMessage(CNSocket* sock, std::string msg) {
|
2020-10-02 23:50:47 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_PC_MOTD_LOGIN, motd);
|
|
|
|
|
|
|
|
motd.iType = 1;
|
2020-10-04 17:52:16 +00:00
|
|
|
// convert string to u16 and write it to the buffer
|
2020-10-04 17:50:58 +00:00
|
|
|
U8toU16(msg, (char16_t*)motd.szSystemMsg, sizeof(motd.szSystemMsg));
|
2020-10-02 23:50:47 +00:00
|
|
|
|
|
|
|
// send the packet :)
|
2021-03-20 20:19:48 +00:00
|
|
|
sock->sendPacket(motd, P_FE2CL_PC_MOTD_LOGIN);
|
2020-10-02 23:50:47 +00:00
|
|
|
}
|
2020-10-31 20:31:25 +00:00
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
static void announcementHandler(CNSocket* sock, CNPacketData* data) {
|
2020-11-17 23:16:16 +00:00
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
|
|
|
if (plr->accountLevel > 30)
|
2020-11-19 16:19:22 +00:00
|
|
|
return; // only players with account level less than 30 (GM) are allowed to use this command
|
2021-03-20 20:19:48 +00:00
|
|
|
auto announcement = (sP_CL2FE_GM_REQ_PC_ANNOUNCE*)data->buf;
|
2020-11-19 16:19:22 +00:00
|
|
|
|
|
|
|
INITSTRUCT(sP_FE2CL_GM_REP_PC_ANNOUNCE, msg);
|
|
|
|
msg.iAnnounceType = announcement->iAnnounceType;
|
|
|
|
msg.iDuringTime = announcement->iDuringTime;
|
|
|
|
memcpy(msg.szAnnounceMsg, announcement->szAnnounceMsg, sizeof(msg.szAnnounceMsg));
|
2020-11-17 23:16:16 +00:00
|
|
|
std::map<CNSocket*, Player*>::iterator it;
|
2020-11-19 16:19:22 +00:00
|
|
|
|
|
|
|
switch (announcement->iAreaType) {
|
2020-11-17 23:16:16 +00:00
|
|
|
case 0: // area (all players in viewable chunks)
|
2021-03-20 20:19:48 +00:00
|
|
|
sock->sendPacket(msg, P_FE2CL_GM_REP_PC_ANNOUNCE);
|
|
|
|
PlayerManager::sendToViewable(sock, msg, P_FE2CL_GM_REP_PC_ANNOUNCE);
|
2020-11-17 23:16:16 +00:00
|
|
|
break;
|
2020-11-19 16:19:22 +00:00
|
|
|
case 1: // shard
|
|
|
|
case 2: // world
|
2020-12-01 22:32:45 +00:00
|
|
|
break; // not applicable to OpenFusion
|
2020-11-17 23:16:16 +00:00
|
|
|
case 3: // global (all players)
|
2020-11-19 16:19:22 +00:00
|
|
|
for (it = PlayerManager::players.begin(); it != PlayerManager::players.end(); it++) {
|
|
|
|
CNSocket* allSock = it->first;
|
2021-03-20 20:19:48 +00:00
|
|
|
allSock->sendPacket(msg, P_FE2CL_GM_REP_PC_ANNOUNCE);
|
2020-11-19 16:19:22 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2020-12-31 01:13:43 +00:00
|
|
|
|
2021-03-18 04:41:47 +00:00
|
|
|
std::string logLine = "[Bcast " + std::to_string(announcement->iAreaType) + "] " + PlayerManager::getPlayerName(plr, false) + ": " + AUTOU16TOU8(msg.szAnnounceMsg);
|
2020-12-31 01:13:43 +00:00
|
|
|
std::cout << logLine << std::endl;
|
|
|
|
dump.push_back("**" + logLine + "**");
|
2020-11-19 16:19:22 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 19:07:26 +00:00
|
|
|
// Buddy freechatting
|
2021-03-16 21:06:10 +00:00
|
|
|
static void buddyChatHandler(CNSocket* sock, CNPacketData* data) {
|
2021-03-20 20:19:48 +00:00
|
|
|
auto pkt = (sP_CL2FE_REQ_SEND_BUDDY_FREECHAT_MESSAGE*)data->buf;
|
2021-03-12 19:07:26 +00:00
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
|
|
|
|
|
|
|
INITSTRUCT(sP_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC, resp);
|
|
|
|
|
|
|
|
CNSocket* otherSock = PlayerManager::getSockFromID(pkt->iBuddyPCUID);
|
|
|
|
|
|
|
|
if (otherSock == nullptr)
|
|
|
|
return; // buddy offline
|
|
|
|
|
|
|
|
Player *otherPlr = PlayerManager::getPlayer(otherSock);
|
|
|
|
|
|
|
|
resp.iFromPCUID = plr->PCStyle.iPC_UID;
|
|
|
|
resp.iToPCUID = pkt->iBuddyPCUID;
|
|
|
|
resp.iEmoteCode = pkt->iEmoteCode;
|
|
|
|
|
2021-03-18 04:41:47 +00:00
|
|
|
std::string fullChat = sanitizeText(AUTOU16TOU8(pkt->szFreeChat));
|
2021-03-12 19:07:26 +00:00
|
|
|
|
|
|
|
if (fullChat.length() > 1 && fullChat[0] == CMD_PREFIX) { // PREFIX
|
|
|
|
CustomCommands::runCmd(fullChat, sock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (plr->iSpecialState & CN_SPECIAL_STATE_FLAG__MUTE_FREECHAT)
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::string logLine = "[BuddyChat] " + PlayerManager::getPlayerName(plr) + " (to " + PlayerManager::getPlayerName(otherPlr) + "): " + fullChat;
|
|
|
|
std::cout << logLine << std::endl;
|
2021-03-16 21:06:10 +00:00
|
|
|
dump.push_back(logLine);
|
2021-03-12 19:07:26 +00:00
|
|
|
|
|
|
|
U8toU16(fullChat, (char16_t*)&resp.szFreeChat, sizeof(resp.szFreeChat));
|
|
|
|
|
2021-03-20 20:19:48 +00:00
|
|
|
sock->sendPacket(resp, P_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC); // confirm send to sender
|
|
|
|
otherSock->sendPacket(resp, P_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC); // broadcast send to receiver
|
2021-03-12 19:07:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Buddy menuchat
|
2021-03-16 21:06:10 +00:00
|
|
|
static void buddyMenuChatHandler(CNSocket* sock, CNPacketData* data) {
|
2021-03-20 20:19:48 +00:00
|
|
|
auto pkt = (sP_CL2FE_REQ_SEND_BUDDY_MENUCHAT_MESSAGE*)data->buf;
|
2021-03-12 19:07:26 +00:00
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
|
|
|
|
|
|
|
INITSTRUCT(sP_FE2CL_REP_SEND_BUDDY_MENUCHAT_MESSAGE_SUCC, resp);
|
|
|
|
|
|
|
|
CNSocket* otherSock = PlayerManager::getSockFromID(pkt->iBuddyPCUID);
|
|
|
|
|
|
|
|
if (otherSock == nullptr)
|
|
|
|
return; // buddy offline
|
|
|
|
|
|
|
|
Player *otherPlr = PlayerManager::getPlayer(otherSock);
|
|
|
|
|
|
|
|
resp.iFromPCUID = plr->PCStyle.iPC_UID;
|
|
|
|
resp.iToPCUID = pkt->iBuddyPCUID;
|
|
|
|
resp.iEmoteCode = pkt->iEmoteCode;
|
|
|
|
|
2021-03-18 04:41:47 +00:00
|
|
|
std::string fullChat = sanitizeText(AUTOU16TOU8(pkt->szFreeChat));
|
2021-03-12 19:07:26 +00:00
|
|
|
std::string logLine = "[BuddyMenuChat] " + PlayerManager::getPlayerName(plr) + " (to " + PlayerManager::getPlayerName(otherPlr) + "): " + fullChat;
|
|
|
|
|
|
|
|
std::cout << logLine << std::endl;
|
2021-03-16 21:06:10 +00:00
|
|
|
dump.push_back(logLine);
|
2021-03-12 19:07:26 +00:00
|
|
|
|
|
|
|
U8toU16(fullChat, (char16_t*)&resp.szFreeChat, sizeof(resp.szFreeChat));
|
|
|
|
|
2021-03-20 20:19:48 +00:00
|
|
|
sock->sendPacket(resp, P_FE2CL_REP_SEND_BUDDY_MENUCHAT_MESSAGE_SUCC); // confirm send to sender
|
|
|
|
otherSock->sendPacket(resp, P_FE2CL_REP_SEND_BUDDY_MENUCHAT_MESSAGE_SUCC); // broadcast send to receiver
|
2021-03-12 19:07:26 +00:00
|
|
|
}
|
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
static void tradeChatHandler(CNSocket* sock, CNPacketData* data) {
|
2021-03-20 20:19:48 +00:00
|
|
|
auto pacdat = (sP_CL2FE_REQ_PC_TRADE_EMOTES_CHAT*)data->buf;
|
2021-03-12 19:07:26 +00:00
|
|
|
|
|
|
|
CNSocket* otherSock; // weird flip flop because we need to know who the other player is
|
|
|
|
if (pacdat->iID_Request == pacdat->iID_From)
|
|
|
|
otherSock = PlayerManager::getSockFromID(pacdat->iID_To);
|
|
|
|
else
|
|
|
|
otherSock = PlayerManager::getSockFromID(pacdat->iID_From);
|
|
|
|
|
|
|
|
if (otherSock == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Player *otherPlr = PlayerManager::getPlayer(otherSock);
|
|
|
|
|
|
|
|
INITSTRUCT(sP_FE2CL_REP_PC_TRADE_EMOTES_CHAT, resp);
|
|
|
|
Player *plr = PlayerManager::getPlayer(sock);
|
|
|
|
resp.iID_Request = pacdat->iID_Request;
|
|
|
|
resp.iID_From = pacdat->iID_From;
|
|
|
|
resp.iID_To = pacdat->iID_To;
|
2021-03-18 04:41:47 +00:00
|
|
|
std::string fullChat = sanitizeText(AUTOU16TOU8(pacdat->szFreeChat));
|
2021-03-12 19:07:26 +00:00
|
|
|
U8toU16(fullChat, resp.szFreeChat, sizeof(resp.szFreeChat));
|
|
|
|
|
|
|
|
std::string logLine = "[TradeChat] " + PlayerManager::getPlayerName(plr) + " (to " + PlayerManager::getPlayerName(otherPlr) + "): " + fullChat;
|
|
|
|
|
|
|
|
std::cout << logLine << std::endl;
|
2021-03-16 21:06:10 +00:00
|
|
|
dump.push_back(logLine);
|
2021-03-12 19:07:26 +00:00
|
|
|
|
|
|
|
resp.iEmoteCode = pacdat->iEmoteCode;
|
2021-03-20 20:19:48 +00:00
|
|
|
sock->sendPacket(resp, P_FE2CL_REP_PC_TRADE_EMOTES_CHAT);
|
|
|
|
otherSock->sendPacket(resp, P_FE2CL_REP_PC_TRADE_EMOTES_CHAT);
|
2021-03-12 19:07:26 +00:00
|
|
|
}
|
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
static void groupChatHandler(CNSocket* sock, CNPacketData* data) {
|
2021-03-12 19:07:26 +00:00
|
|
|
sP_CL2FE_REQ_SEND_ALL_GROUP_FREECHAT_MESSAGE* chat = (sP_CL2FE_REQ_SEND_ALL_GROUP_FREECHAT_MESSAGE*)data->buf;
|
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
|
|
|
|
2021-03-18 04:41:47 +00:00
|
|
|
std::string fullChat = sanitizeText(AUTOU16TOU8(chat->szFreeChat));
|
2021-03-12 19:07:26 +00:00
|
|
|
|
|
|
|
if (fullChat.length() > 1 && fullChat[0] == CMD_PREFIX) { // PREFIX
|
|
|
|
CustomCommands::runCmd(fullChat, sock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (plr->iSpecialState & CN_SPECIAL_STATE_FLAG__MUTE_FREECHAT)
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::string logLine = "[GroupChat] " + PlayerManager::getPlayerName(plr, true) + ": " + fullChat;
|
|
|
|
std::cout << logLine << std::endl;
|
2021-03-16 21:06:10 +00:00
|
|
|
dump.push_back(logLine);
|
2021-03-12 19:07:26 +00:00
|
|
|
|
|
|
|
// send to client
|
|
|
|
INITSTRUCT(sP_FE2CL_REP_SEND_ALL_GROUP_FREECHAT_MESSAGE_SUCC, resp);
|
|
|
|
|
|
|
|
U8toU16(fullChat, (char16_t*)&resp.szFreeChat, sizeof(resp.szFreeChat));
|
|
|
|
resp.iSendPCID = plr->iID;
|
|
|
|
resp.iEmoteCode = chat->iEmoteCode;
|
|
|
|
|
2022-04-23 01:13:00 +00:00
|
|
|
if (plr->group == nullptr)
|
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_ALL_GROUP_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_ALL_GROUP_FREECHAT_MESSAGE_SUCC));
|
|
|
|
else
|
|
|
|
Groups::sendToGroup(plr->group, (void*)&resp, P_FE2CL_REP_SEND_ALL_GROUP_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_ALL_GROUP_FREECHAT_MESSAGE_SUCC));
|
2021-03-12 19:07:26 +00:00
|
|
|
}
|
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
static void groupMenuChatHandler(CNSocket* sock, CNPacketData* data) {
|
2021-03-12 19:07:26 +00:00
|
|
|
sP_CL2FE_REQ_SEND_ALL_GROUP_MENUCHAT_MESSAGE* chat = (sP_CL2FE_REQ_SEND_ALL_GROUP_MENUCHAT_MESSAGE*)data->buf;
|
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
|
|
|
|
2021-03-18 04:41:47 +00:00
|
|
|
std::string fullChat = sanitizeText(AUTOU16TOU8(chat->szFreeChat));
|
2021-03-12 19:07:26 +00:00
|
|
|
std::string logLine = "[GroupMenuChat] " + PlayerManager::getPlayerName(plr, true) + ": " + fullChat;
|
|
|
|
|
|
|
|
std::cout << logLine << std::endl;
|
2021-03-16 21:06:10 +00:00
|
|
|
dump.push_back(logLine);
|
2021-03-12 19:07:26 +00:00
|
|
|
|
|
|
|
// send to client
|
|
|
|
INITSTRUCT(sP_FE2CL_REP_SEND_ALL_GROUP_MENUCHAT_MESSAGE_SUCC, resp);
|
|
|
|
|
|
|
|
U8toU16(fullChat, (char16_t*)&resp.szFreeChat, sizeof(resp.szFreeChat));
|
|
|
|
resp.iSendPCID = plr->iID;
|
|
|
|
resp.iEmoteCode = chat->iEmoteCode;
|
|
|
|
|
2022-04-23 01:13:00 +00:00
|
|
|
if (plr->group == nullptr)
|
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_ALL_GROUP_MENUCHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_ALL_GROUP_MENUCHAT_MESSAGE_SUCC));
|
|
|
|
Groups::sendToGroup(plr->group, (void*)&resp, P_FE2CL_REP_SEND_ALL_GROUP_MENUCHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_ALL_GROUP_MENUCHAT_MESSAGE_SUCC));
|
2021-03-12 19:07:26 +00:00
|
|
|
}
|
|
|
|
|
2020-10-31 20:31:25 +00:00
|
|
|
// we only allow plain ascii, at least for now
|
2021-03-16 22:29:13 +00:00
|
|
|
std::string Chat::sanitizeText(std::string text, bool allowNewlines) {
|
2020-10-31 20:31:25 +00:00
|
|
|
int i;
|
2020-12-19 04:46:38 +00:00
|
|
|
const int BUFSIZE = 512;
|
|
|
|
char buf[BUFSIZE];
|
|
|
|
|
|
|
|
assert(text.size() < BUFSIZE);
|
2020-10-31 20:31:25 +00:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
for (char c : text) {
|
2020-12-19 04:46:38 +00:00
|
|
|
if (i >= BUFSIZE-1)
|
2020-10-31 20:31:25 +00:00
|
|
|
break;
|
2020-11-29 20:31:54 +00:00
|
|
|
|
|
|
|
if (!allowNewlines && c == '\n')
|
|
|
|
continue;
|
|
|
|
|
2020-12-14 01:52:59 +00:00
|
|
|
if ((c >= ' ' && c <= '~') || c == '\n')
|
2020-10-31 20:31:25 +00:00
|
|
|
buf[i++] = c;
|
|
|
|
}
|
|
|
|
buf[i] = 0;
|
|
|
|
|
|
|
|
return std::string(buf);
|
|
|
|
}
|
2021-03-16 21:06:10 +00:00
|
|
|
|
2021-03-16 22:29:13 +00:00
|
|
|
void Chat::init() {
|
2021-03-16 21:06:10 +00:00
|
|
|
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_REQ_SEND_BUDDY_FREECHAT_MESSAGE, buddyChatHandler);
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_SEND_BUDDY_MENUCHAT_MESSAGE, buddyMenuChatHandler);
|
|
|
|
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_TRADE_EMOTES_CHAT, tradeChatHandler);
|
|
|
|
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_SEND_ALL_GROUP_FREECHAT_MESSAGE, groupChatHandler);
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_SEND_ALL_GROUP_MENUCHAT_MESSAGE, groupMenuChatHandler);
|
|
|
|
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_GM_REQ_PC_ANNOUNCE, announcementHandler);
|
|
|
|
}
|