From 7757238a4704ab9f46f13c475549e886e19b3545 Mon Sep 17 00:00:00 2001 From: SengokuNadeko <70702835+SengokuNadeko@users.noreply.github.com> Date: Sat, 19 Sep 2020 15:07:09 -0400 Subject: [PATCH 1/6] Buddy System draft (W.I.P) The w.i.p buddy system --- src/BuddyManager.cpp | 417 +++++++++++++++++++++++++++++++++++++++++++ src/BuddyManager.hpp | 31 ++++ 2 files changed, 448 insertions(+) create mode 100644 src/BuddyManager.cpp create mode 100644 src/BuddyManager.hpp diff --git a/src/BuddyManager.cpp b/src/BuddyManager.cpp new file mode 100644 index 0000000..7dc226e --- /dev/null +++ b/src/BuddyManager.cpp @@ -0,0 +1,417 @@ +#include "CNShardServer.hpp" +#include "CNStructs.hpp" +#include "ChatManager.hpp" +#include "PlayerManager.hpp" +#include "BuddyManager.hpp" + +#include + +void BuddyManager::init() { + REGISTER_SHARD_PACKET(P_CL2FE_REQ_REQUEST_MAKE_BUDDY, requestBuddy); + REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_FIND_NAME_MAKE_BUDDY, reqBuddyByName); + REGISTER_SHARD_PACKET(P_CL2FE_REQ_ACCEPT_MAKE_BUDDY, reqAcceptBuddy); + REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_FIND_NAME_ACCEPT_BUDDY, reqFindNameBuddyAccept); + REGISTER_SHARD_PACKET(P_CL2FE_REQ_SEND_BUDDY_FREECHAT_MESSAGE, reqBuddyFreechat); + REGISTER_SHARD_PACKET(P_CL2FE_REQ_SEND_BUDDY_MENUCHAT_MESSAGE, reqBuddyMenuchat); + REGISTER_SHARD_PACKET(P_CL2FE_REQ_GET_BUDDY_STATE, reqPktGetBuddyState); +} + +//Buddy request +void BuddyManager::requestBuddy(CNSocket* sock, CNPacketData* data) { + if (data->size != sizeof(sP_CL2FE_REQ_REQUEST_MAKE_BUDDY)) + return; // malformed packet + + Player* plrReq = PlayerManager::getPlayer(sock); + + sP_CL2FE_REQ_REQUEST_MAKE_BUDDY* pkt = (sP_CL2FE_REQ_REQUEST_MAKE_BUDDY*)data->buf; + + INITSTRUCT(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC, resp); + + CNSocket* otherSock = sock; + + for (auto pair : PlayerManager::players) { + if (pair.second.plr->PCStyle.iPC_UID == pkt->iBuddyPCUID) { + otherSock = pair.first; + } + } + + PlayerView& plr = PlayerManager::players[otherSock]; + + resp.iRequestID = plr.plr->iID; + resp.iBuddyID = plr.plr->iID; + resp.iBuddyPCUID = plr.plr->PCStyle.iPC_UID; + + sock->sendPacket((void*)&resp, P_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC)); + requestedBuddy(otherSock, plrReq, plr); + +} + +//Sending buddy request by player name +void BuddyManager::reqBuddyByName(CNSocket* sock, CNPacketData* data) { + if (data->size != sizeof(sP_CL2FE_REQ_PC_FIND_NAME_MAKE_BUDDY)) { + return; // malformed packet + } + + sP_CL2FE_REQ_PC_FIND_NAME_MAKE_BUDDY* pkt = (sP_CL2FE_REQ_PC_FIND_NAME_MAKE_BUDDY*)data->buf; + Player* plrReq = PlayerManager::getPlayer(sock); + + INITSTRUCT(sP_FE2CL_REP_PC_FIND_NAME_MAKE_BUDDY_SUCC, resp); + + CNSocket* otherSock = sock; + + int sizeOfRes = sizeof(pkt->szFirstName) / 9; + int sizeOfLNRes = sizeof(pkt->szLastName) / 17; + + for (auto pair : PlayerManager::players) { + int sizeOfReq = sizeof(pair.second.plr->PCStyle.szFirstName) / 9; + int sizeOfLNReq = sizeof(pair.second.plr->PCStyle.szLastName) / 17; + if (BuddyManager::firstNameCheck(pair.second.plr->PCStyle.szFirstName, pkt->szFirstName, sizeOfReq, sizeOfRes) == true && BuddyManager::lastNameCheck(pair.second.plr->PCStyle.szLastName, pkt->szLastName, sizeOfLNReq, sizeOfLNRes) == true) { + otherSock = pair.first; + } + } + + PlayerView& plr = PlayerManager::players[otherSock]; + + resp.iPCUID = plrReq->PCStyle.iPC_UID; + resp.iNameCheckFlag = plrReq->PCStyle.iNameCheck; + + for (int fName = 0; fName < 9; fName++) { + resp.szFirstName[fName] = plrReq->PCStyle.szFirstName[fName]; + } + + for (int lName = 0; lName < 17; lName++) { + resp.szLastName[lName] = plrReq->PCStyle.szLastName[lName]; + } + + otherSock->sendPacket((void*)&resp, P_FE2CL_REP_PC_FIND_NAME_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_PC_FIND_NAME_MAKE_BUDDY_SUCC)); + +} + +//Accepting buddy request +void BuddyManager::reqAcceptBuddy(CNSocket* sock, CNPacketData* data) { + if (data->size != sizeof(sP_CL2FE_REQ_ACCEPT_MAKE_BUDDY)) + return; // malformed packet + + sP_CL2FE_REQ_ACCEPT_MAKE_BUDDY* pkt = (sP_CL2FE_REQ_ACCEPT_MAKE_BUDDY*)data->buf; + Player* plrReq = PlayerManager::getPlayer(sock); + + INITSTRUCT(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, resp); + + CNSocket* otherSock = sock; + + for (auto pair : PlayerManager::players) { + if (pair.second.plr->PCStyle.iPC_UID == pkt->iBuddyPCUID) { + otherSock = pair.first; + } + } + + PlayerView& plr = PlayerManager::players[otherSock]; + + if (pkt->iAcceptFlag == 1) { + //resp.iBuddySlot = 0; //hard-coding this for now + resp.BuddyInfo.iID = pkt->iBuddyID; + resp.BuddyInfo.iPCUID = pkt->iBuddyPCUID; + resp.BuddyInfo.iNameCheckFlag = plr.plr->PCStyle.iNameCheck; + resp.BuddyInfo.iPCState = plr.plr->iPCState; + resp.BuddyInfo.iGender = plr.plr->PCStyle.iGender; + resp.BuddyInfo.bBlocked = 0; + resp.BuddyInfo.bFreeChat = 1; + + for (int i = 0; i < 9; i++) { + resp.BuddyInfo.szFirstName[i] = plr.plr->PCStyle.szFirstName[i]; + } + + for (int i = 0; i < 17; i++) { + resp.BuddyInfo.szLastName[i] = plr.plr->PCStyle.szLastName[i]; + } + + sock->sendPacket((void*)&resp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC)); + buddyList(sock, resp.BuddyInfo); + otherAcceptBuddy(otherSock, pkt->iBuddyID, pkt->iBuddyPCUID, resp, plrReq); + } + else { + INITSTRUCT(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL, declineResp); + + declineResp.iErrorCode = 6; //Buddy declined notification + declineResp.iBuddyID = pkt->iBuddyID; + declineResp.iBuddyPCUID = pkt->iBuddyPCUID; + + otherSock->sendPacket((void*)&declineResp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL)); + } + + +} + +//Accepting buddy request from the find name request +void BuddyManager::reqFindNameBuddyAccept(CNSocket* sock, CNPacketData* data) { + if (data->size != sizeof(sP_CL2FE_REQ_PC_FIND_NAME_ACCEPT_BUDDY)) { + return; // malformed packet + } + + sP_CL2FE_REQ_PC_FIND_NAME_ACCEPT_BUDDY* pkt = (sP_CL2FE_REQ_PC_FIND_NAME_ACCEPT_BUDDY*)data->buf; + Player* plrReq = PlayerManager::getPlayer(sock); + + INITSTRUCT(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, resp); + + CNSocket* otherSock = sock; + + int sizeOfRes = sizeof(pkt->szFirstName) / 9; + int sizeOfLNRes = sizeof(pkt->szLastName) / 17; + + for (auto pair : PlayerManager::players) { + int sizeOfReq = sizeof(pair.second.plr->PCStyle.szFirstName) / 9; + int sizeOfLNReq = sizeof(pair.second.plr->PCStyle.szLastName) / 17; + if (BuddyManager::firstNameCheck(pair.second.plr->PCStyle.szFirstName, pkt->szFirstName, sizeOfReq, sizeOfRes) == true && BuddyManager::lastNameCheck(pair.second.plr->PCStyle.szLastName, pkt->szLastName, sizeOfLNReq, sizeOfLNRes) == true) { + otherSock = pair.first; + } + } + + PlayerView& plr = PlayerManager::players[otherSock]; + + if (pkt->iAcceptFlag == 1) { + //resp.iBuddySlot = 0; //hard-coding this for now + resp.BuddyInfo.iID = plr.plr->iID; + resp.BuddyInfo.iPCUID = pkt->iBuddyPCUID; + resp.BuddyInfo.iNameCheckFlag = plr.plr->PCStyle.iNameCheck; + resp.BuddyInfo.iPCState = plr.plr->iPCState; + resp.BuddyInfo.iGender = plr.plr->PCStyle.iGender; + resp.BuddyInfo.bBlocked = 0; + resp.BuddyInfo.bFreeChat = 1; + + for (int i = 0; i < 9; i++) { + resp.BuddyInfo.szFirstName[i] = plr.plr->PCStyle.szFirstName[i]; + } + + for (int i = 0; i < 17; i++) { + resp.BuddyInfo.szLastName[i] = plr.plr->PCStyle.szLastName[i]; + } + + sock->sendPacket((void*)&resp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC)); + buddyList(sock, resp.BuddyInfo); + otherAcceptBuddy(otherSock, plr.plr->iID, pkt->iBuddyPCUID, resp, plrReq); + } + else { + INITSTRUCT(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL, declineResp); + + declineResp.iErrorCode = 6; //Buddy declined notification + declineResp.iBuddyID = plr.plr->iID; + declineResp.iBuddyPCUID = pkt->iBuddyPCUID; + + otherSock->sendPacket((void*)&declineResp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL)); + } + +} + +//Buddy freechatting +void BuddyManager::reqBuddyFreechat(CNSocket* sock, CNPacketData* data) { + if (data->size != sizeof(sP_CL2FE_REQ_SEND_BUDDY_FREECHAT_MESSAGE)) + return; // malformed packet + + sP_CL2FE_REQ_SEND_BUDDY_FREECHAT_MESSAGE* pkt = (sP_CL2FE_REQ_SEND_BUDDY_FREECHAT_MESSAGE*)data->buf; + Player* plr = PlayerManager::getPlayer(sock); + + INITSTRUCT(sP_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC, resp); + + CNSocket* otherSock = sock; + + resp.iFromPCUID = plr->PCStyle.iPC_UID; + resp.iToPCUID = pkt->iBuddyPCUID; + resp.iEmoteCode = pkt->iEmoteCode; + std::cout << "Player UID: "; + std::cout << plr->PCStyle.iPC_UID << std::endl; + memcpy(resp.szFreeChat, pkt->szFreeChat, sizeof(pkt->szFreeChat)); + sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC)); + + for (auto pair : PlayerManager::players) { + if (pair.second.plr->PCStyle.iPC_UID != plr->PCStyle.iPC_UID) { + otherSock = pair.first; + recvBuddyFreechat(otherSock, pair.second.plr->PCStyle.iPC_UID, pkt); + } + } + + //recvBuddyFreechat(otherSock, plr->PCStyle.iPC_UID, pkt); + +} + +//Buddy menuchat +void BuddyManager::reqBuddyMenuchat(CNSocket* sock, CNPacketData* data) { + if (data->size != sizeof(sP_CL2FE_REQ_SEND_BUDDY_MENUCHAT_MESSAGE)) + return; // malformed packet + + sP_CL2FE_REQ_SEND_BUDDY_MENUCHAT_MESSAGE* pkt = (sP_CL2FE_REQ_SEND_BUDDY_MENUCHAT_MESSAGE*)data->buf; + Player* plr = PlayerManager::getPlayer(sock); + + INITSTRUCT(sP_FE2CL_REP_SEND_BUDDY_MENUCHAT_MESSAGE_SUCC, resp); + + resp.iFromPCUID = plr->PCStyle.iPC_UID; + resp.iToPCUID = pkt->iBuddyPCUID; + resp.iEmoteCode = pkt->iEmoteCode; + memcpy(resp.szFreeChat, pkt->szFreeChat, sizeof(pkt->szFreeChat)); + + sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC)); + + CNSocket* otherSock = sock; + + for (auto pair : PlayerManager::players) { + if (pair.second.plr->PCStyle.iPC_UID == pkt->iBuddyPCUID) { + otherSock = pair.first; + } + } + + otherSock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC)); +} + +//Getting buddy state +void BuddyManager::reqPktGetBuddyState(CNSocket* sock, CNPacketData* data) { + INITSTRUCT(sP_FE2CL_REP_GET_BUDDY_STATE_SUCC, resp); + INITSTRUCT(sBuddyBaseInfo, buddyInfo); + + for (int BuddySlot = 0; BuddySlot < 50; BuddySlot++) { + resp.aBuddyState[BuddySlot] = buddyInfo.iPCState; + resp.aBuddyID[BuddySlot] = buddyInfo.iID; + sock->sendPacket((void*)&resp, P_FE2CL_REP_GET_BUDDY_STATE_SUCC, sizeof(sP_FE2CL_REP_GET_BUDDY_STATE_SUCC)); + } +} + +#pragma region Helper methods + +void BuddyManager::requestedBuddy(CNSocket* sock, Player* plrReq, PlayerView& plr) { + INITSTRUCT(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC_TO_ACCEPTER, resp); + + resp.iRequestID = plrReq->iID; + resp.iBuddyID = plr.plr->iID; + + for (int i = 0; i < 9; i++) { + resp.szFirstName[i] = plrReq->PCStyle.szFirstName[i]; + } + for (int i = 0; i < 17; i++) { + resp.szLastName[i] = plrReq->PCStyle.szLastName[i]; + } + + sock->sendPacket((void*)&resp, P_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC_TO_ACCEPTER, sizeof(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC_TO_ACCEPTER)); + +} + +//Buddy list load +void BuddyManager::buddyList(CNSocket* sock, sBuddyBaseInfo BuddyInfo) { + + size_t resplen = sizeof(sP_FE2CL_REP_PC_BUDDYLIST_INFO_SUCC) + sizeof(sBuddyBaseInfo); + uint8_t respbuf[4096]; + + memset(respbuf, 0, resplen); + + sP_FE2CL_REP_PC_BUDDYLIST_INFO_SUCC* resp = (sP_FE2CL_REP_PC_BUDDYLIST_INFO_SUCC*)respbuf; + sBuddyBaseInfo* respdata = (sBuddyBaseInfo*)(respbuf + sizeof(sP_FE2CL_REP_PC_BUDDYLIST_INFO_SUCC)); + + resp->iID = BuddyInfo.iID; + resp->iPCUID = BuddyInfo.iPCUID; + + for (int i = 0; i < resp->iBuddyCnt && i < resp->iListNum; i++) { + respdata->iID = BuddyInfo.iID; + respdata->iPCUID = BuddyInfo.iPCUID; + respdata->iGender = BuddyInfo.iGender; + respdata->iPCState = BuddyInfo.iPCState; + respdata->iNameCheckFlag = BuddyInfo.iNameCheckFlag; + respdata->bBlocked = 0; + respdata->bFreeChat = 1; + for (int fName = 0; fName < 9; fName++) { + respdata->szFirstName[fName] = BuddyInfo.szFirstName[fName]; + } + for (int lName = 0; lName < 17; lName++) { + respdata->szLastName[lName] = BuddyInfo.szLastName[lName]; + } + //reqGetBuddyState(sock, BuddyInfo, resp->iBuddyCnt); + } + + sock->sendPacket((void*)respbuf, P_FE2CL_REP_PC_BUDDYLIST_INFO_SUCC, resplen); + +} + +//If the requested player accepts the buddy request, the requester's buddylist will get loaded up. +void BuddyManager::otherAcceptBuddy(CNSocket* sock, int32_t BuddyID, int64_t BuddyPCUID, sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC resp, Player* plr) { + + //resp.iBuddySlot = 0; //hard-coding this for now + resp.BuddyInfo.iID = BuddyID; + resp.BuddyInfo.iPCUID = BuddyPCUID; + resp.BuddyInfo.iNameCheckFlag = plr->PCStyle.iNameCheck; + resp.BuddyInfo.iPCState = plr->iPCState; + resp.BuddyInfo.iGender = plr->PCStyle.iGender; + resp.BuddyInfo.bBlocked = 0; + resp.BuddyInfo.bFreeChat = 1; + + for (int i = 0; i < 9; i++) { + resp.BuddyInfo.szFirstName[i] = plr->PCStyle.szFirstName[i]; + } + + for (int i = 0; i < 17; i++) { + resp.BuddyInfo.szLastName[i] = plr->PCStyle.szLastName[i]; + } + + sock->sendPacket((void*)&resp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC)); + buddyList(sock, resp.BuddyInfo); +} + +//Getting buddy states +/*void BuddyManager::reqGetBuddyState(CNSocket* sock, sBuddyBaseInfo BuddyInfo, int8_t BuddySlot) { + + INITSTRUCT(sP_FE2CL_REP_GET_BUDDY_STATE_SUCC, resp); + + for (BuddySlot = 0; BuddySlot < 50; BuddySlot++) { + resp.aBuddyState[BuddySlot] = BuddyInfo.iPCState; + resp.aBuddyID[BuddySlot] = BuddyInfo.iID; + sock->sendPacket((void*)&resp, P_FE2CL_REP_GET_BUDDY_STATE_SUCC, sizeof(sP_FE2CL_REP_GET_BUDDY_STATE_SUCC)); + } + +}*/ + +//Check if the requested name matches the requested player's name +bool BuddyManager::firstNameCheck(char16_t reqFirstName[], char16_t resFirstName[], int sizeOfReq, int sizeOfRes) { + // If lengths of array are not equal means + // array are not equal + if (sizeOfReq != sizeOfRes) + return false; + + // Sort both arrays + std::sort(reqFirstName, reqFirstName + sizeOfReq); + std::sort(resFirstName, resFirstName + sizeOfRes); + + // Linearly compare elements + for (int i = 0; i < sizeOfReq; i++) + if (reqFirstName[i] != resFirstName[i]) + return false; + + // If all elements were same. + return true; +} + +bool BuddyManager::lastNameCheck(char16_t reqLastName[], char16_t resLastName[], int sizeOfLNReq, int sizeOfLNRes) { + // If lengths of array are not equal means + // array are not equal + if (sizeOfLNReq != sizeOfLNRes) + return false; + + // Sort both arrays + std::sort(reqLastName, reqLastName + sizeOfLNReq); + std::sort(resLastName, resLastName + sizeOfLNRes); + + // Linearly compare elements + for (int i = 0; i < sizeOfLNReq; i++) + if (reqLastName[i] != resLastName[i]) + return false; + + // If all elements were same. + return true; +} + +void BuddyManager::recvBuddyFreechat(CNSocket* sock, int64_t senderPCUID, sP_CL2FE_REQ_SEND_BUDDY_FREECHAT_MESSAGE* pkt) { + INITSTRUCT(sP_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC, resp); + resp.iFromPCUID = pkt->iBuddyPCUID; + resp.iToPCUID = senderPCUID; + resp.iEmoteCode = pkt->iEmoteCode; + memcpy(resp.szFreeChat, pkt->szFreeChat, sizeof(pkt->szFreeChat)); + std::cout << "Buddy UiD "; + std::cout << resp.iToPCUID << std::endl; + sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC)); +} + +#pragma endregion diff --git a/src/BuddyManager.hpp b/src/BuddyManager.hpp new file mode 100644 index 0000000..8a53f0b --- /dev/null +++ b/src/BuddyManager.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include "Player.hpp" +#include "CNProtocol.hpp" +#include "CNStructs.hpp" +#include "CNShardServer.hpp" + +#include +#include + +namespace BuddyManager { + void init(); + + void requestBuddy(CNSocket* sock, CNPacketData* data); + void reqBuddyByName(CNSocket* sock, CNPacketData* data); + void reqAcceptBuddy(CNSocket* sock, CNPacketData* data); + void reqFindNameBuddyAccept(CNSocket* sock, CNPacketData* data); + void reqBuddyFreechat(CNSocket* sock, CNPacketData* data); + void reqBuddyMenuchat(CNSocket* sock, CNPacketData* data); + void reqPktGetBuddyState(CNSocket* sock, CNPacketData* data); + + //helper methods + void requestedBuddy(CNSocket* sock, Player* plrReq, PlayerView& plr); + void buddyList(CNSocket* sock, sBuddyBaseInfo BuddyInfo); + void otherAcceptBuddy(CNSocket* sock, int32_t BuddyID, int64_t BuddyPCUID, sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC resp, Player* plr); + void reqGetBuddyState(CNSocket* sock, sBuddyBaseInfo BuddyInfo, int8_t BuddySlot); + void recvBuddyFreechat(CNSocket* sock, int64_t senderPCUID, sP_CL2FE_REQ_SEND_BUDDY_FREECHAT_MESSAGE* pkt); + + bool firstNameCheck(char16_t reqFirstName[], char16_t resFirstName[], int sizeOfReq, int sizeOfRes); + bool lastNameCheck(char16_t reqLastName[], char16_t resLastName[], int sizeOfLNReq, int sizeOfLNRes); +} From 9bb19efc99638cf37bb3327d610c2e60ed094b34 Mon Sep 17 00:00:00 2001 From: SengokuNadeko <70702835+SengokuNadeko@users.noreply.github.com> Date: Sat, 19 Sep 2020 15:08:03 -0400 Subject: [PATCH 2/6] Updated main.cpp for buddy manager init function --- src/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index de22839..a27a074 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,7 @@ #include "NanoManager.hpp" #include "NPCManager.hpp" #include "TransportManager.hpp" +#include "BuddyManager.hpp" #include "Database.hpp" #include "TableData.hpp" #include "ChunkManager.hpp" @@ -99,6 +100,7 @@ int main() { NanoManager::init(); NPCManager::init(); TransportManager::init(); + BuddyManager::init(); Database::open(); From 6a05ce45044892df7296b679a2f62417938f75c4 Mon Sep 17 00:00:00 2001 From: Raymonf Date: Sat, 19 Sep 2020 17:16:47 -0400 Subject: [PATCH 3/6] Add BuddyManager to Makefile --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 51a17f3..868f027 100644 --- a/Makefile +++ b/Makefile @@ -47,6 +47,7 @@ CXXSRC=\ src/TransportManager.cpp\ src/TableData.cpp\ src/ChunkManager.cpp\ + src/BuddyManager.cpp\ # headers (for timestamp purposes) CHDR=\ @@ -83,6 +84,7 @@ CXXHDR=\ src/TransportManager.hpp\ src/TableData.hpp\ src/ChunkManager.hpp\ + src/BuddyManager.hpp\ COBJ=$(CSRC:.c=.o) CXXOBJ=$(CXXSRC:.cpp=.o) From 90134cd1fa7b9bf6cee7ee99f59660d6a491cc06 Mon Sep 17 00:00:00 2001 From: SengokuNadeko <70702835+SengokuNadeko@users.noreply.github.com> Date: Mon, 21 Sep 2020 14:28:04 -0400 Subject: [PATCH 4/6] Buddy deleting/blocking works and code clean up Added in buddy deleting and buddy blocking. I also cleaned up some of the code and added some comments to the code. --- src/BuddyManager.cpp | 185 +++++++++++++++++++++---------------------- src/BuddyManager.hpp | 24 ++++-- 2 files changed, 109 insertions(+), 100 deletions(-) diff --git a/src/BuddyManager.cpp b/src/BuddyManager.cpp index 7dc226e..eea21bf 100644 --- a/src/BuddyManager.cpp +++ b/src/BuddyManager.cpp @@ -14,6 +14,8 @@ void BuddyManager::init() { REGISTER_SHARD_PACKET(P_CL2FE_REQ_SEND_BUDDY_FREECHAT_MESSAGE, reqBuddyFreechat); REGISTER_SHARD_PACKET(P_CL2FE_REQ_SEND_BUDDY_MENUCHAT_MESSAGE, reqBuddyMenuchat); REGISTER_SHARD_PACKET(P_CL2FE_REQ_GET_BUDDY_STATE, reqPktGetBuddyState); + REGISTER_SHARD_PACKET(P_CL2FE_REQ_SET_BUDDY_BLOCK, reqBuddyBlock); + REGISTER_SHARD_PACKET(P_CL2FE_REQ_REMOVE_BUDDY, reqBuddyDelete); } //Buddy request @@ -41,8 +43,8 @@ void BuddyManager::requestBuddy(CNSocket* sock, CNPacketData* data) { resp.iBuddyID = plr.plr->iID; resp.iBuddyPCUID = plr.plr->PCStyle.iPC_UID; - sock->sendPacket((void*)&resp, P_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC)); - requestedBuddy(otherSock, plrReq, plr); + sock->sendPacket((void*)&resp, P_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC)); //informs the player that the request was sent + requestedBuddy(otherSock, plrReq, plr); //The other player will see the request } @@ -59,13 +61,13 @@ void BuddyManager::reqBuddyByName(CNSocket* sock, CNPacketData* data) { CNSocket* otherSock = sock; - int sizeOfRes = sizeof(pkt->szFirstName) / 9; - int sizeOfLNRes = sizeof(pkt->szLastName) / 17; + int sizeOfRes = sizeof(pkt->szFirstName) / 9; //Maximum size of a player's first name + int sizeOfLNRes = sizeof(pkt->szLastName) / 17; //Maximum size of a player's last name for (auto pair : PlayerManager::players) { int sizeOfReq = sizeof(pair.second.plr->PCStyle.szFirstName) / 9; int sizeOfLNReq = sizeof(pair.second.plr->PCStyle.szLastName) / 17; - if (BuddyManager::firstNameCheck(pair.second.plr->PCStyle.szFirstName, pkt->szFirstName, sizeOfReq, sizeOfRes) == true && BuddyManager::lastNameCheck(pair.second.plr->PCStyle.szLastName, pkt->szLastName, sizeOfLNReq, sizeOfLNRes) == true) { + if (BuddyManager::firstNameCheck(pair.second.plr->PCStyle.szFirstName, pkt->szFirstName, sizeOfReq, sizeOfRes) == true && BuddyManager::lastNameCheck(pair.second.plr->PCStyle.szLastName, pkt->szLastName, sizeOfLNReq, sizeOfLNRes) == true) { //This long line of gorgeous parameters is to check if the player's name matches :eyes: otherSock = pair.first; } } @@ -75,14 +77,8 @@ void BuddyManager::reqBuddyByName(CNSocket* sock, CNPacketData* data) { resp.iPCUID = plrReq->PCStyle.iPC_UID; resp.iNameCheckFlag = plrReq->PCStyle.iNameCheck; - for (int fName = 0; fName < 9; fName++) { - resp.szFirstName[fName] = plrReq->PCStyle.szFirstName[fName]; - } - - for (int lName = 0; lName < 17; lName++) { - resp.szLastName[lName] = plrReq->PCStyle.szLastName[lName]; - } - + memcpy(resp.szFirstName, plrReq->PCStyle.szFirstName, sizeof(plrReq->PCStyle.szFirstName)); + memcpy(resp.szLastName, plrReq->PCStyle.szLastName, sizeof(plrReq->PCStyle.szLastName)); otherSock->sendPacket((void*)&resp, P_FE2CL_REP_PC_FIND_NAME_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_PC_FIND_NAME_MAKE_BUDDY_SUCC)); } @@ -117,17 +113,24 @@ void BuddyManager::reqAcceptBuddy(CNSocket* sock, CNPacketData* data) { resp.BuddyInfo.bBlocked = 0; resp.BuddyInfo.bFreeChat = 1; - for (int i = 0; i < 9; i++) { - resp.BuddyInfo.szFirstName[i] = plr.plr->PCStyle.szFirstName[i]; - } - - for (int i = 0; i < 17; i++) { - resp.BuddyInfo.szLastName[i] = plr.plr->PCStyle.szLastName[i]; - } + memcpy(resp.BuddyInfo.szFirstName, plr.plr->PCStyle.szFirstName, sizeof(plr.plr->PCStyle.szFirstName)); + memcpy(resp.BuddyInfo.szLastName, plr.plr->PCStyle.szLastName, sizeof(plr.plr->PCStyle.szLastName)); sock->sendPacket((void*)&resp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC)); - buddyList(sock, resp.BuddyInfo); - otherAcceptBuddy(otherSock, pkt->iBuddyID, pkt->iBuddyPCUID, resp, plrReq); + buddyList(sock, resp.BuddyInfo); //saves buddy data to player's buddylist + if (plr.plr->PCStyle.iPC_UID == pkt->iBuddyPCUID) { + resp.BuddyInfo.iID = plrReq->iID; + resp.BuddyInfo.iPCUID = plrReq->PCStyle.iPC_UID; + resp.BuddyInfo.iNameCheckFlag = plrReq->PCStyle.iNameCheck; + resp.BuddyInfo.iPCState = plrReq->iPCState; + resp.BuddyInfo.iGender = plrReq->PCStyle.iGender; + resp.BuddyInfo.bBlocked = 0; + resp.BuddyInfo.bFreeChat = 1; + memcpy(resp.BuddyInfo.szFirstName, plrReq->PCStyle.szFirstName, sizeof(plrReq->PCStyle.szFirstName)); + memcpy(resp.BuddyInfo.szLastName, plrReq->PCStyle.szLastName, sizeof(plrReq->PCStyle.szLastName)); + otherSock->sendPacket((void*)&resp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC)); + buddyList(otherSock, resp.BuddyInfo); //saves requester's data to this player's buddylist + } } else { INITSTRUCT(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL, declineResp); @@ -136,10 +139,8 @@ void BuddyManager::reqAcceptBuddy(CNSocket* sock, CNPacketData* data) { declineResp.iBuddyID = pkt->iBuddyID; declineResp.iBuddyPCUID = pkt->iBuddyPCUID; - otherSock->sendPacket((void*)&declineResp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL)); + otherSock->sendPacket((void*)&declineResp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL)); //tells the requester that the player declined } - - } //Accepting buddy request from the find name request @@ -170,7 +171,7 @@ void BuddyManager::reqFindNameBuddyAccept(CNSocket* sock, CNPacketData* data) { if (pkt->iAcceptFlag == 1) { //resp.iBuddySlot = 0; //hard-coding this for now - resp.BuddyInfo.iID = plr.plr->iID; + //resp.BuddyInfo.iID = plrReq->iID; resp.BuddyInfo.iPCUID = pkt->iBuddyPCUID; resp.BuddyInfo.iNameCheckFlag = plr.plr->PCStyle.iNameCheck; resp.BuddyInfo.iPCState = plr.plr->iPCState; @@ -178,17 +179,27 @@ void BuddyManager::reqFindNameBuddyAccept(CNSocket* sock, CNPacketData* data) { resp.BuddyInfo.bBlocked = 0; resp.BuddyInfo.bFreeChat = 1; - for (int i = 0; i < 9; i++) { - resp.BuddyInfo.szFirstName[i] = plr.plr->PCStyle.szFirstName[i]; - } - - for (int i = 0; i < 17; i++) { - resp.BuddyInfo.szLastName[i] = plr.plr->PCStyle.szLastName[i]; - } + memcpy(resp.BuddyInfo.szFirstName, plr.plr->PCStyle.szFirstName, sizeof(plr.plr->PCStyle.szFirstName)); + memcpy(resp.BuddyInfo.szLastName, plr.plr->PCStyle.szLastName, sizeof(plr.plr->PCStyle.szLastName)); sock->sendPacket((void*)&resp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC)); buddyList(sock, resp.BuddyInfo); - otherAcceptBuddy(otherSock, plr.plr->iID, pkt->iBuddyPCUID, resp, plrReq); + + if (plr.plr->PCStyle.iPC_UID == pkt->iBuddyPCUID) { + resp.BuddyInfo.iID = plrReq->iID; + resp.BuddyInfo.iPCUID = plrReq->PCStyle.iPC_UID; + resp.BuddyInfo.iNameCheckFlag = plrReq->PCStyle.iNameCheck; + resp.BuddyInfo.iPCState = plrReq->iPCState; + resp.BuddyInfo.iGender = plrReq->PCStyle.iGender; + resp.BuddyInfo.bBlocked = 0; + resp.BuddyInfo.bFreeChat = 1; + + memcpy(resp.BuddyInfo.szFirstName, plrReq->PCStyle.szFirstName, sizeof(plrReq->PCStyle.szFirstName)); + memcpy(resp.BuddyInfo.szLastName, plrReq->PCStyle.szLastName, sizeof(plrReq->PCStyle.szLastName)); + + otherSock->sendPacket((void*)&resp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC)); + buddyList(otherSock, resp.BuddyInfo); + } } else { INITSTRUCT(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL, declineResp); @@ -217,19 +228,16 @@ void BuddyManager::reqBuddyFreechat(CNSocket* sock, CNPacketData* data) { resp.iFromPCUID = plr->PCStyle.iPC_UID; resp.iToPCUID = pkt->iBuddyPCUID; resp.iEmoteCode = pkt->iEmoteCode; - std::cout << "Player UID: "; - std::cout << plr->PCStyle.iPC_UID << std::endl; memcpy(resp.szFreeChat, pkt->szFreeChat, sizeof(pkt->szFreeChat)); - sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC)); + sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC)); //shows the player that they sent the message to their buddy for (auto pair : PlayerManager::players) { if (pair.second.plr->PCStyle.iPC_UID != plr->PCStyle.iPC_UID) { otherSock = pair.first; - recvBuddyFreechat(otherSock, pair.second.plr->PCStyle.iPC_UID, pkt); + otherSock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC)); //sends the message to the buddy. } } - //recvBuddyFreechat(otherSock, plr->PCStyle.iPC_UID, pkt); } @@ -243,22 +251,20 @@ void BuddyManager::reqBuddyMenuchat(CNSocket* sock, CNPacketData* data) { INITSTRUCT(sP_FE2CL_REP_SEND_BUDDY_MENUCHAT_MESSAGE_SUCC, resp); + CNSocket* otherSock = sock; + resp.iFromPCUID = plr->PCStyle.iPC_UID; resp.iToPCUID = pkt->iBuddyPCUID; resp.iEmoteCode = pkt->iEmoteCode; memcpy(resp.szFreeChat, pkt->szFreeChat, sizeof(pkt->szFreeChat)); - - sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC)); - - CNSocket* otherSock = sock; + sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_BUDDY_MENUCHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_BUDDY_MENUCHAT_MESSAGE_SUCC)); //shows the player that they sent the message to their buddy for (auto pair : PlayerManager::players) { - if (pair.second.plr->PCStyle.iPC_UID == pkt->iBuddyPCUID) { + if (pair.second.plr->PCStyle.iPC_UID != plr->PCStyle.iPC_UID) { otherSock = pair.first; + otherSock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_BUDDY_MENUCHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_BUDDY_MENUCHAT_MESSAGE_SUCC)); //sends the message to the buddy. } } - - otherSock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC)); } //Getting buddy state @@ -267,12 +273,43 @@ void BuddyManager::reqPktGetBuddyState(CNSocket* sock, CNPacketData* data) { INITSTRUCT(sBuddyBaseInfo, buddyInfo); for (int BuddySlot = 0; BuddySlot < 50; BuddySlot++) { - resp.aBuddyState[BuddySlot] = buddyInfo.iPCState; + resp.aBuddyState[BuddySlot] = 1; //this sets every buddy to online. Will get the pcstate right directly from the DB. resp.aBuddyID[BuddySlot] = buddyInfo.iID; sock->sendPacket((void*)&resp, P_FE2CL_REP_GET_BUDDY_STATE_SUCC, sizeof(sP_FE2CL_REP_GET_BUDDY_STATE_SUCC)); } } +//Blocking the buddy +void BuddyManager::reqBuddyBlock(CNSocket* sock, CNPacketData* data) { + if (data->size != sizeof(sP_CL2FE_REQ_SET_BUDDY_BLOCK)) + return; // malformed packet + + sP_CL2FE_REQ_SET_BUDDY_BLOCK* pkt = (sP_CL2FE_REQ_SET_BUDDY_BLOCK*)data->buf; + + INITSTRUCT(sP_FE2CL_REP_SET_BUDDY_BLOCK_SUCC, resp); + + resp.iBuddyPCUID = pkt->iBuddyPCUID; + resp.iBuddySlot = pkt->iBuddySlot; + + sock->sendPacket((void*)&resp, P_FE2CL_REP_SET_BUDDY_BLOCK_SUCC, sizeof(sP_FE2CL_REP_SET_BUDDY_BLOCK_SUCC)); + +} + +//Deleting the buddy +void BuddyManager::reqBuddyDelete(CNSocket* sock, CNPacketData* data) { + if (data->size != sizeof(sP_CL2FE_REQ_REMOVE_BUDDY)) + return; //malformed packet + + sP_CL2FE_REQ_REMOVE_BUDDY* pkt = (sP_CL2FE_REQ_REMOVE_BUDDY*)data->buf; + + INITSTRUCT(sP_FE2CL_REP_REMOVE_BUDDY_SUCC, resp); + + resp.iBuddyPCUID = pkt->iBuddyPCUID; + resp.iBuddySlot = pkt->iBuddySlot; + + sock->sendPacket((void*)&resp, P_FE2CL_REP_REMOVE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_REMOVE_BUDDY_SUCC)); +} + #pragma region Helper methods void BuddyManager::requestedBuddy(CNSocket* sock, Player* plrReq, PlayerView& plr) { @@ -281,14 +318,10 @@ void BuddyManager::requestedBuddy(CNSocket* sock, Player* plrReq, PlayerView& pl resp.iRequestID = plrReq->iID; resp.iBuddyID = plr.plr->iID; - for (int i = 0; i < 9; i++) { - resp.szFirstName[i] = plrReq->PCStyle.szFirstName[i]; - } - for (int i = 0; i < 17; i++) { - resp.szLastName[i] = plrReq->PCStyle.szLastName[i]; - } + memcpy(resp.szFirstName, plrReq->PCStyle.szFirstName, sizeof(plrReq->PCStyle.szFirstName)); + memcpy(resp.szLastName, plrReq->PCStyle.szLastName, sizeof(plrReq->PCStyle.szLastName)); - sock->sendPacket((void*)&resp, P_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC_TO_ACCEPTER, sizeof(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC_TO_ACCEPTER)); + sock->sendPacket((void*)&resp, P_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC_TO_ACCEPTER, sizeof(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC_TO_ACCEPTER)); //player get the buddy request. } @@ -314,16 +347,11 @@ void BuddyManager::buddyList(CNSocket* sock, sBuddyBaseInfo BuddyInfo) { respdata->iNameCheckFlag = BuddyInfo.iNameCheckFlag; respdata->bBlocked = 0; respdata->bFreeChat = 1; - for (int fName = 0; fName < 9; fName++) { - respdata->szFirstName[fName] = BuddyInfo.szFirstName[fName]; - } - for (int lName = 0; lName < 17; lName++) { - respdata->szLastName[lName] = BuddyInfo.szLastName[lName]; - } - //reqGetBuddyState(sock, BuddyInfo, resp->iBuddyCnt); + memcpy(respdata->szFirstName, BuddyInfo.szFirstName, sizeof(BuddyInfo.szFirstName)); + memcpy(respdata->szLastName, BuddyInfo.szLastName, sizeof(BuddyInfo.szLastName)); } - sock->sendPacket((void*)respbuf, P_FE2CL_REP_PC_BUDDYLIST_INFO_SUCC, resplen); + sock->sendPacket((void*)respbuf, P_FE2CL_REP_PC_BUDDYLIST_INFO_SUCC, resplen); //updates/loads player's buddy list } @@ -339,31 +367,13 @@ void BuddyManager::otherAcceptBuddy(CNSocket* sock, int32_t BuddyID, int64_t Bud resp.BuddyInfo.bBlocked = 0; resp.BuddyInfo.bFreeChat = 1; - for (int i = 0; i < 9; i++) { - resp.BuddyInfo.szFirstName[i] = plr->PCStyle.szFirstName[i]; - } - - for (int i = 0; i < 17; i++) { - resp.BuddyInfo.szLastName[i] = plr->PCStyle.szLastName[i]; - } + memcpy(resp.BuddyInfo.szFirstName, plr->PCStyle.szFirstName, sizeof(plr->PCStyle.szFirstName)); + memcpy(resp.BuddyInfo.szLastName, plr->PCStyle.szLastName, sizeof(plr->PCStyle.szLastName)); sock->sendPacket((void*)&resp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC)); buddyList(sock, resp.BuddyInfo); } -//Getting buddy states -/*void BuddyManager::reqGetBuddyState(CNSocket* sock, sBuddyBaseInfo BuddyInfo, int8_t BuddySlot) { - - INITSTRUCT(sP_FE2CL_REP_GET_BUDDY_STATE_SUCC, resp); - - for (BuddySlot = 0; BuddySlot < 50; BuddySlot++) { - resp.aBuddyState[BuddySlot] = BuddyInfo.iPCState; - resp.aBuddyID[BuddySlot] = BuddyInfo.iID; - sock->sendPacket((void*)&resp, P_FE2CL_REP_GET_BUDDY_STATE_SUCC, sizeof(sP_FE2CL_REP_GET_BUDDY_STATE_SUCC)); - } - -}*/ - //Check if the requested name matches the requested player's name bool BuddyManager::firstNameCheck(char16_t reqFirstName[], char16_t resFirstName[], int sizeOfReq, int sizeOfRes) { // If lengths of array are not equal means @@ -403,15 +413,4 @@ bool BuddyManager::lastNameCheck(char16_t reqLastName[], char16_t resLastName[], return true; } -void BuddyManager::recvBuddyFreechat(CNSocket* sock, int64_t senderPCUID, sP_CL2FE_REQ_SEND_BUDDY_FREECHAT_MESSAGE* pkt) { - INITSTRUCT(sP_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC, resp); - resp.iFromPCUID = pkt->iBuddyPCUID; - resp.iToPCUID = senderPCUID; - resp.iEmoteCode = pkt->iEmoteCode; - memcpy(resp.szFreeChat, pkt->szFreeChat, sizeof(pkt->szFreeChat)); - std::cout << "Buddy UiD "; - std::cout << resp.iToPCUID << std::endl; - sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC)); -} - #pragma endregion diff --git a/src/BuddyManager.hpp b/src/BuddyManager.hpp index 8a53f0b..6ad663a 100644 --- a/src/BuddyManager.hpp +++ b/src/BuddyManager.hpp @@ -10,22 +10,32 @@ namespace BuddyManager { void init(); - + + //Buddy requests void requestBuddy(CNSocket* sock, CNPacketData* data); void reqBuddyByName(CNSocket* sock, CNPacketData* data); + + //Buddy accepting void reqAcceptBuddy(CNSocket* sock, CNPacketData* data); void reqFindNameBuddyAccept(CNSocket* sock, CNPacketData* data); + + //Buddy Messaging void reqBuddyFreechat(CNSocket* sock, CNPacketData* data); void reqBuddyMenuchat(CNSocket* sock, CNPacketData* data); + + //Getting buddy state void reqPktGetBuddyState(CNSocket* sock, CNPacketData* data); + + //Blocking/removing buddies + void reqBuddyBlock(CNSocket* sock, CNPacketData* data); + void reqBuddyDelete(CNSocket* sock, CNPacketData* data); //helper methods void requestedBuddy(CNSocket* sock, Player* plrReq, PlayerView& plr); - void buddyList(CNSocket* sock, sBuddyBaseInfo BuddyInfo); - void otherAcceptBuddy(CNSocket* sock, int32_t BuddyID, int64_t BuddyPCUID, sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC resp, Player* plr); - void reqGetBuddyState(CNSocket* sock, sBuddyBaseInfo BuddyInfo, int8_t BuddySlot); - void recvBuddyFreechat(CNSocket* sock, int64_t senderPCUID, sP_CL2FE_REQ_SEND_BUDDY_FREECHAT_MESSAGE* pkt); + void buddyList(CNSocket* sock, sBuddyBaseInfo BuddyInfo); //updates the buddylist + void otherAcceptBuddy(CNSocket* sock, int32_t BuddyID, int64_t BuddyPCUID, sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC resp, Player* plr); //tells the other player that they are now buddies with the requester. - bool firstNameCheck(char16_t reqFirstName[], char16_t resFirstName[], int sizeOfReq, int sizeOfRes); - bool lastNameCheck(char16_t reqLastName[], char16_t resLastName[], int sizeOfLNReq, int sizeOfLNRes); + //Name checks + bool firstNameCheck(char16_t reqFirstName[], char16_t resFirstName[], int sizeOfReq, int sizeOfRes); //checks if the request and requested player's first names match + bool lastNameCheck(char16_t reqLastName[], char16_t resLastName[], int sizeOfLNReq, int sizeOfLNRes); //checks if the request and requested player's last names match } From e0e474924d8f355f97edd74566d374f68f97f53c Mon Sep 17 00:00:00 2001 From: SengokuNadeko <70702835+SengokuNadeko@users.noreply.github.com> Date: Tue, 22 Sep 2020 13:02:00 -0400 Subject: [PATCH 5/6] Implemented buddy warping Buddy warping now works, if anything else needs to be added/redone in regards to this feel free to let me know ^ --- src/BuddyManager.cpp | 27 +++++++++++++++++++++++++++ src/BuddyManager.hpp | 3 +++ 2 files changed, 30 insertions(+) diff --git a/src/BuddyManager.cpp b/src/BuddyManager.cpp index eea21bf..40939c2 100644 --- a/src/BuddyManager.cpp +++ b/src/BuddyManager.cpp @@ -16,6 +16,7 @@ void BuddyManager::init() { REGISTER_SHARD_PACKET(P_CL2FE_REQ_GET_BUDDY_STATE, reqPktGetBuddyState); REGISTER_SHARD_PACKET(P_CL2FE_REQ_SET_BUDDY_BLOCK, reqBuddyBlock); REGISTER_SHARD_PACKET(P_CL2FE_REQ_REMOVE_BUDDY, reqBuddyDelete); + REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_BUDDY_WARP, reqBuddyWarp); } //Buddy request @@ -310,6 +311,32 @@ void BuddyManager::reqBuddyDelete(CNSocket* sock, CNPacketData* data) { sock->sendPacket((void*)&resp, P_FE2CL_REP_REMOVE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_REMOVE_BUDDY_SUCC)); } +//Warping to buddy +void BuddyManager::reqBuddyWarp(CNSocket* sock, CNPacketData* data) { + if (data->size != sizeof(sP_CL2FE_REQ_PC_BUDDY_WARP)) + return; //malformed packet + + sP_CL2FE_REQ_PC_BUDDY_WARP* pkt = (sP_CL2FE_REQ_PC_BUDDY_WARP*)data->buf; + + INITSTRUCT(sP_FE2CL_REP_PC_BUDDY_WARP_OTHER_SHARD_SUCC, resp); + resp.iBuddyPCUID = pkt->iBuddyPCUID; + + CNSocket* otherSock = sock; + + for (auto pair : PlayerManager::players) { + if (pair.second.plr->PCStyle.iPC_UID == pkt->iBuddyPCUID) { + otherSock = pair.first; + } + } + + Player* buddy = PlayerManager::getPlayer(otherSock); + + PlayerManager::updatePlayerPosition(sock, buddy->x, buddy->y, buddy->z); + + sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_BUDDY_WARP_OTHER_SHARD_SUCC, sizeof(sP_FE2CL_REP_PC_BUDDY_WARP_OTHER_SHARD_SUCC)); + +} + #pragma region Helper methods void BuddyManager::requestedBuddy(CNSocket* sock, Player* plrReq, PlayerView& plr) { diff --git a/src/BuddyManager.hpp b/src/BuddyManager.hpp index 6ad663a..856d94b 100644 --- a/src/BuddyManager.hpp +++ b/src/BuddyManager.hpp @@ -29,6 +29,9 @@ namespace BuddyManager { //Blocking/removing buddies void reqBuddyBlock(CNSocket* sock, CNPacketData* data); void reqBuddyDelete(CNSocket* sock, CNPacketData* data); + + //Buddy warping + void reqBuddyWarp(CNSocket* sock, CNPacketData* data); //helper methods void requestedBuddy(CNSocket* sock, Player* plrReq, PlayerView& plr); From 9cfced88c94f7960d7b45252870a5955ad306692 Mon Sep 17 00:00:00 2001 From: SengokuNadeko <70702835+SengokuNadeko@users.noreply.github.com> Date: Wed, 23 Sep 2020 13:52:21 -0400 Subject: [PATCH 6/6] Stubbed buddy warping After testing warping a lot I saw how buggy it is. I decided to stub it for this PR and work on it in a later PR. --- src/BuddyManager.cpp | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/src/BuddyManager.cpp b/src/BuddyManager.cpp index 40939c2..198c614 100644 --- a/src/BuddyManager.cpp +++ b/src/BuddyManager.cpp @@ -4,7 +4,10 @@ #include "PlayerManager.hpp" #include "BuddyManager.hpp" +#include +#include #include +#include void BuddyManager::init() { REGISTER_SHARD_PACKET(P_CL2FE_REQ_REQUEST_MAKE_BUDDY, requestBuddy); @@ -73,8 +76,6 @@ void BuddyManager::reqBuddyByName(CNSocket* sock, CNPacketData* data) { } } - PlayerView& plr = PlayerManager::players[otherSock]; - resp.iPCUID = plrReq->PCStyle.iPC_UID; resp.iNameCheckFlag = plrReq->PCStyle.iNameCheck; @@ -312,30 +313,7 @@ void BuddyManager::reqBuddyDelete(CNSocket* sock, CNPacketData* data) { } //Warping to buddy -void BuddyManager::reqBuddyWarp(CNSocket* sock, CNPacketData* data) { - if (data->size != sizeof(sP_CL2FE_REQ_PC_BUDDY_WARP)) - return; //malformed packet - - sP_CL2FE_REQ_PC_BUDDY_WARP* pkt = (sP_CL2FE_REQ_PC_BUDDY_WARP*)data->buf; - - INITSTRUCT(sP_FE2CL_REP_PC_BUDDY_WARP_OTHER_SHARD_SUCC, resp); - resp.iBuddyPCUID = pkt->iBuddyPCUID; - - CNSocket* otherSock = sock; - - for (auto pair : PlayerManager::players) { - if (pair.second.plr->PCStyle.iPC_UID == pkt->iBuddyPCUID) { - otherSock = pair.first; - } - } - - Player* buddy = PlayerManager::getPlayer(otherSock); - - PlayerManager::updatePlayerPosition(sock, buddy->x, buddy->y, buddy->z); - - sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_BUDDY_WARP_OTHER_SHARD_SUCC, sizeof(sP_FE2CL_REP_PC_BUDDY_WARP_OTHER_SHARD_SUCC)); - -} +void BuddyManager::reqBuddyWarp(CNSocket* sock, CNPacketData* data) {} //stub #pragma region Helper methods