From 95e454232ab459b5e0bf5dea144fd962d52d923a Mon Sep 17 00:00:00 2001 From: JadeShrineMaiden Date: Wed, 19 Aug 2020 18:37:15 +0100 Subject: [PATCH 1/3] Chat Feature It just works --- src/CNShardServer.hpp | 6 ++---- src/CNStructs.hpp | 5 ++++- src/ChatManager.cpp | 21 +++++++++++++++++++-- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/CNShardServer.hpp b/src/CNShardServer.hpp index e3c213f..6ca39e6 100644 --- a/src/CNShardServer.hpp +++ b/src/CNShardServer.hpp @@ -18,7 +18,6 @@ enum SHARDPACKETID { P_CL2FE_GM_REQ_PC_SET_VALUE = 318767211, P_CL2FE_REQ_SEND_FREECHAT_MESSAGE = 318767111, P_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT = 318767184, - P_CL2FE_REQ_PC_EXIT = 318767106, // shard 2 client P_FE2CL_REP_PC_ENTER_SUCC = 822083586, @@ -33,8 +32,7 @@ enum SHARDPACKETID { P_FE2CL_REP_PC_GOTO_SUCC = 822083633, P_FE2CL_GM_REP_PC_SET_VALUE = 822083781, P_FE2CL_REP_PC_AVATAR_EMOTES_CHAT = 822083730, - P_FE2CL_REP_PC_EXIT_SUCC = 822083589, - P_FE2CL_PC_MOTD_LOGIN = 822083793 + P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC = 822083602 }; #define REGISTER_SHARD_PACKET(pactype, handlr) CNShardServer::ShardPackets[pactype] = handlr; @@ -52,4 +50,4 @@ public: void onTimer(); }; -#endif +#endif \ No newline at end of file diff --git a/src/CNStructs.hpp b/src/CNStructs.hpp index 94bfea1..4b76647 100644 --- a/src/CNStructs.hpp +++ b/src/CNStructs.hpp @@ -547,9 +547,12 @@ struct sP_FE2CL_REP_PC_EXIT_SUCC { struct sP_FE2CL_PC_MOTD_LOGIN { int8_t iType; uint16_t szSystemMsg[512]; +struct sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC { + int32_t iPC_ID; + char16_t szFreeChat[128]; + int32_t iEmoteCode; }; #pragma pack(pop) -#endif diff --git a/src/ChatManager.cpp b/src/ChatManager.cpp index 82dbf63..dc3d8a1 100644 --- a/src/ChatManager.cpp +++ b/src/ChatManager.cpp @@ -10,8 +10,25 @@ void ChatManager::init() { void ChatManager::chatHandler(CNSocket* sock, CNPacketData* data) { sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE* chat = (sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE*)data->buf; - - // stubbed for now + PlayerView plr = PlayerManager::players[sock]; + + DEBUGLOG( + std::cout << "\tChat Message: " << U16toU8(chat->szFreeChat) << std::endl; + ) + + sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC* resp = (sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC)); + resp->iPC_ID = PlayerManager::players[sock].plr.iID; + memcpy(resp->szFreeChat, chat->szFreeChat, sizeof(chat->szFreeChat)); + resp->iEmoteCode = chat->iEmoteCode; + sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC), sock->getFEKey())); + + for (CNSocket* otherSock : plr.viewable) { + sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC* resp = (sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC)); + resp->iPC_ID = PlayerManager::players[sock].plr.iID; + memcpy(resp->szFreeChat, chat->szFreeChat, sizeof(chat->szFreeChat)); + resp->iEmoteCode = chat->iEmoteCode; + 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::emoteHandler(CNSocket* sock, CNPacketData* data) { From a17b72b0b3075e82d30d7e29cd6c483cbd659eef Mon Sep 17 00:00:00 2001 From: JadeShrineMaiden Date: Wed, 19 Aug 2020 18:43:24 +0100 Subject: [PATCH 2/3] Revert "Chat Feature" This reverts commit 95e454232ab459b5e0bf5dea144fd962d52d923a. --- src/CNShardServer.hpp | 6 ++++-- src/CNStructs.hpp | 5 +---- src/ChatManager.cpp | 21 ++------------------- 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/src/CNShardServer.hpp b/src/CNShardServer.hpp index 6ca39e6..e3c213f 100644 --- a/src/CNShardServer.hpp +++ b/src/CNShardServer.hpp @@ -18,6 +18,7 @@ enum SHARDPACKETID { P_CL2FE_GM_REQ_PC_SET_VALUE = 318767211, P_CL2FE_REQ_SEND_FREECHAT_MESSAGE = 318767111, P_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT = 318767184, + P_CL2FE_REQ_PC_EXIT = 318767106, // shard 2 client P_FE2CL_REP_PC_ENTER_SUCC = 822083586, @@ -32,7 +33,8 @@ enum SHARDPACKETID { P_FE2CL_REP_PC_GOTO_SUCC = 822083633, P_FE2CL_GM_REP_PC_SET_VALUE = 822083781, P_FE2CL_REP_PC_AVATAR_EMOTES_CHAT = 822083730, - P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC = 822083602 + P_FE2CL_REP_PC_EXIT_SUCC = 822083589, + P_FE2CL_PC_MOTD_LOGIN = 822083793 }; #define REGISTER_SHARD_PACKET(pactype, handlr) CNShardServer::ShardPackets[pactype] = handlr; @@ -50,4 +52,4 @@ public: void onTimer(); }; -#endif \ No newline at end of file +#endif diff --git a/src/CNStructs.hpp b/src/CNStructs.hpp index 4b76647..94bfea1 100644 --- a/src/CNStructs.hpp +++ b/src/CNStructs.hpp @@ -547,12 +547,9 @@ struct sP_FE2CL_REP_PC_EXIT_SUCC { struct sP_FE2CL_PC_MOTD_LOGIN { int8_t iType; uint16_t szSystemMsg[512]; -struct sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC { - int32_t iPC_ID; - char16_t szFreeChat[128]; - int32_t iEmoteCode; }; #pragma pack(pop) +#endif diff --git a/src/ChatManager.cpp b/src/ChatManager.cpp index dc3d8a1..82dbf63 100644 --- a/src/ChatManager.cpp +++ b/src/ChatManager.cpp @@ -10,25 +10,8 @@ void ChatManager::init() { void ChatManager::chatHandler(CNSocket* sock, CNPacketData* data) { sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE* chat = (sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE*)data->buf; - PlayerView plr = PlayerManager::players[sock]; - - DEBUGLOG( - std::cout << "\tChat Message: " << U16toU8(chat->szFreeChat) << std::endl; - ) - - sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC* resp = (sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC)); - resp->iPC_ID = PlayerManager::players[sock].plr.iID; - memcpy(resp->szFreeChat, chat->szFreeChat, sizeof(chat->szFreeChat)); - resp->iEmoteCode = chat->iEmoteCode; - sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC), sock->getFEKey())); - - for (CNSocket* otherSock : plr.viewable) { - sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC* resp = (sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC)); - resp->iPC_ID = PlayerManager::players[sock].plr.iID; - memcpy(resp->szFreeChat, chat->szFreeChat, sizeof(chat->szFreeChat)); - resp->iEmoteCode = chat->iEmoteCode; - otherSock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC), otherSock->getFEKey())); - } + + // stubbed for now } void ChatManager::emoteHandler(CNSocket* sock, CNPacketData* data) { From 8328ebf4f3731791b1ea07eb9218dc5853acd42e Mon Sep 17 00:00:00 2001 From: JadeShrineMaiden Date: Wed, 19 Aug 2020 18:47:25 +0100 Subject: [PATCH 3/3] Chat Feature Chat with other players, no swearing!!! --- src/CNShardServer.hpp | 1 + src/CNStructs.hpp | 6 ++++++ src/ChatManager.cpp | 17 +++++++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/CNShardServer.hpp b/src/CNShardServer.hpp index e3c213f..894d76b 100644 --- a/src/CNShardServer.hpp +++ b/src/CNShardServer.hpp @@ -32,6 +32,7 @@ enum SHARDPACKETID { P_FE2CL_PC_MOVEPLATFORM = 822083704, P_FE2CL_REP_PC_GOTO_SUCC = 822083633, P_FE2CL_GM_REP_PC_SET_VALUE = 822083781, + P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC = 822083602, P_FE2CL_REP_PC_AVATAR_EMOTES_CHAT = 822083730, P_FE2CL_REP_PC_EXIT_SUCC = 822083589, P_FE2CL_PC_MOTD_LOGIN = 822083793 diff --git a/src/CNStructs.hpp b/src/CNStructs.hpp index 94bfea1..ae1cfc4 100644 --- a/src/CNStructs.hpp +++ b/src/CNStructs.hpp @@ -533,6 +533,12 @@ struct sP_FE2CL_REP_PC_GOTO_SUCC { int32_t iZ; }; +struct sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC { + int32_t iPC_ID; + char16_t szFreeChat[128]; + int32_t iEmoteCode; +}; + struct sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT { int32_t iID_From; int32_t iEmoteCode; diff --git a/src/ChatManager.cpp b/src/ChatManager.cpp index 82dbf63..0bf0726 100644 --- a/src/ChatManager.cpp +++ b/src/ChatManager.cpp @@ -10,8 +10,21 @@ void ChatManager::init() { void ChatManager::chatHandler(CNSocket* sock, CNPacketData* data) { sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE* chat = (sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE*)data->buf; - - // stubbed for now + PlayerView plr = PlayerManager::players[sock]; + + sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC* resp = (sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC)); + resp->iPC_ID = PlayerManager::players[sock].plr.iID; + memcpy(resp->szFreeChat, chat->szFreeChat, sizeof(chat->szFreeChat)); + resp->iEmoteCode = chat->iEmoteCode; + sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC), sock->getFEKey())); + + for (CNSocket* otherSock : plr.viewable) { + sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC* resp = (sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC)); + resp->iPC_ID = PlayerManager::players[sock].plr.iID; + memcpy(resp->szFreeChat, chat->szFreeChat, sizeof(chat->szFreeChat)); + resp->iEmoteCode = chat->iEmoteCode; + 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::emoteHandler(CNSocket* sock, CNPacketData* data) {