mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2025-11-15 22:50:11 +00:00
Chat strings are now sanitized.
* Only plain, printable ASCII is allowed for now. * Local chat is now printed to the server console, but group chat is still private * Added a helper function to print character names and IDs
This commit is contained in:
@@ -474,7 +474,9 @@ void ChatManager::chatHandler(CNSocket* sock, CNPacketData* data) {
|
||||
sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE* chat = (sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE*)data->buf;
|
||||
Player* plr = PlayerManager::getPlayer(sock);
|
||||
|
||||
std::string fullChat = U16toU8(chat->szFreeChat);
|
||||
std::string fullChat = sanitizeText(U16toU8(chat->szFreeChat));
|
||||
|
||||
std::cout << "[FreeChat] " << PlayerManager::getPlayerName(plr, false) << ": " << fullChat << std::endl;
|
||||
|
||||
if (fullChat.length() > 1 && fullChat[0] == CMD_PREFIX) { // PREFIX
|
||||
runCmd(fullChat, sock);
|
||||
@@ -483,9 +485,11 @@ void ChatManager::chatHandler(CNSocket* sock, CNPacketData* data) {
|
||||
|
||||
// send to client
|
||||
INITSTRUCT(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, resp);
|
||||
memcpy(resp.szFreeChat, chat->szFreeChat, sizeof(chat->szFreeChat));
|
||||
|
||||
U8toU16(fullChat, (char16_t*)&resp.szFreeChat, sizeof(resp.szFreeChat));
|
||||
resp.iPC_ID = plr->iID;
|
||||
resp.iEmoteCode = chat->iEmoteCode;
|
||||
|
||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC));
|
||||
|
||||
// send to visible players
|
||||
@@ -495,13 +499,21 @@ void ChatManager::chatHandler(CNSocket* sock, CNPacketData* data) {
|
||||
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;
|
||||
Player *plr = PlayerManager::getPlayer(sock);
|
||||
|
||||
std::string fullChat = sanitizeText(U16toU8(chat->szFreeChat));
|
||||
|
||||
std::cout << "[MenuChat] " << PlayerManager::getPlayerName(plr, false) << ": " << fullChat << std::endl;
|
||||
|
||||
// send to client
|
||||
INITSTRUCT(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, resp);
|
||||
memcpy(resp.szFreeChat, chat->szFreeChat, sizeof(chat->szFreeChat));
|
||||
|
||||
U8toU16(fullChat, (char16_t*)&resp.szFreeChat, sizeof(resp.szFreeChat));
|
||||
resp.iPC_ID = PlayerManager::players[sock].plr->iID;
|
||||
resp.iEmoteCode = chat->iEmoteCode;
|
||||
|
||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC));
|
||||
|
||||
// send to visible players
|
||||
@@ -537,3 +549,20 @@ void ChatManager::sendServerMessage(CNSocket* sock, std::string msg) {
|
||||
// send the packet :)
|
||||
sock->sendPacket((void*)&motd, P_FE2CL_PC_MOTD_LOGIN, sizeof(sP_FE2CL_PC_MOTD_LOGIN));
|
||||
}
|
||||
|
||||
// we only allow plain ascii, at least for now
|
||||
std::string ChatManager::sanitizeText(std::string text) {
|
||||
int i;
|
||||
char buf[128];
|
||||
|
||||
i = 0;
|
||||
for (char c : text) {
|
||||
if (i >= 127)
|
||||
break;
|
||||
if (c >= ' ' && c <= '~')
|
||||
buf[i++] = c;
|
||||
}
|
||||
buf[i] = 0;
|
||||
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user