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] 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);