diff --git a/Makefile b/Makefile index ee6e209..8f455c9 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,7 @@ SRC=\ src/CNStructs.cpp\ src/main.cpp\ src/NanoManager.cpp\ + src/ItemManager.cpp\ src/NPCManager.cpp\ src/Player.cpp\ src/PlayerManager.cpp\ @@ -36,6 +37,7 @@ HDR=\ src/CNStructs.hpp\ src/INIReader.hpp\ src/NanoManager.hpp\ + src/ItemManager.hpp\ src/NPCManager.hpp\ src/Player.hpp\ src/PlayerManager.hpp\ diff --git a/src/CNLoginServer.cpp b/src/CNLoginServer.cpp index 6017a0f..cc3cc4c 100644 --- a/src/CNLoginServer.cpp +++ b/src/CNLoginServer.cpp @@ -93,13 +93,20 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { loginSessions[sock].characters[UID].PCStyle2 = charInfo->sPC_Style2; for (int i = 0; i < AEQUIP_COUNT; i++) { - // setup item + // setup equips charInfo->aEquip[i].iID = 0; charInfo->aEquip[i].iType = i; charInfo->aEquip[i].iOpt = 0; loginSessions[sock].characters[UID].Equip[i] = charInfo->aEquip[i]; } + for (int i = 0; i < AINVEN_COUNT; i++) { + // setup inventories + loginSessions[sock].characters[UID].Inven[i].iID = 0; + loginSessions[sock].characters[UID].Inven[i].iType = 0; + loginSessions[sock].characters[UID].Inven[i].iOpt = 0; + } + // set default to the first character if (i == 0) loginSessions[sock].selectedChar = UID; diff --git a/src/CNShardServer.hpp b/src/CNShardServer.hpp index 139f71e..751c03d 100644 --- a/src/CNShardServer.hpp +++ b/src/CNShardServer.hpp @@ -23,6 +23,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_ITEM_MOVE = 318767114, P_CL2FE_REQ_PC_EXIT = 318767106, // shard 2 client @@ -47,6 +48,8 @@ enum SHARDPACKETID { 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_PC_ITEM_MOVE_SUCC = 822083610, + P_FE2CL_PC_EQUIP_CHANGE = 822083611, P_FE2CL_REP_PC_EXIT_SUCC = 822083589, P_FE2CL_PC_MOTD_LOGIN = 822083793 }; diff --git a/src/ItemManager.cpp b/src/ItemManager.cpp new file mode 100644 index 0000000..7937e69 --- /dev/null +++ b/src/ItemManager.cpp @@ -0,0 +1,63 @@ +#include "CNShardServer.hpp" +#include "CNStructs.hpp" +#include "ItemManager.hpp" +#include "PlayerManager.hpp" +#include "Player.hpp" + +void ItemManager::init() { + REGISTER_SHARD_PACKET(P_CL2FE_REQ_ITEM_MOVE, itemMoveHandler); + REGISTER_SHARD_PACKET(P_FE2CL_PC_EQUIP_CHANGE, itemMoveHandler); +} + +void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) { + if (data->size != sizeof(sP_CL2FE_REQ_ITEM_MOVE)) + return; // ignore the malformed packet + + sP_CL2FE_REQ_ITEM_MOVE* itemmove = (sP_CL2FE_REQ_ITEM_MOVE*)data->buf; + sP_FE2CL_PC_ITEM_MOVE_SUCC* resp = (sP_FE2CL_PC_ITEM_MOVE_SUCC*)xmalloc(sizeof(sP_FE2CL_PC_ITEM_MOVE_SUCC)); + + PlayerView plr = PlayerManager::players[sock]; + + //weird flip flop but it makes things happen + resp->eFrom = itemmove->eTo; + resp->iFromSlotNum = itemmove->iToSlotNum; + resp->eTo = itemmove->eFrom; + resp->iToSlotNum = itemmove->iFromSlotNum; + + //eFrom 0 means from equip, 1 means from inventory + if (itemmove->eFrom == 0) { + resp->FromSlotItem = plr.plr.Equip[itemmove->iFromSlotNum]; + } else { + resp->FromSlotItem = plr.plr.Inven[itemmove->iFromSlotNum]; + } + + //eTo 0 means to equip, 1 means to inventory + if (itemmove->eTo == 0) { + resp->ToSlotItem = plr.plr.Equip[itemmove->iToSlotNum]; + plr.plr.Equip[itemmove->iToSlotNum] = resp->FromSlotItem; + } else { + resp->ToSlotItem = plr.plr.Inven[itemmove->iToSlotNum]; + plr.plr.Inven[itemmove->iToSlotNum] = resp->FromSlotItem; + } + + if (itemmove->eFrom == 0) { + plr.plr.Equip[itemmove->iFromSlotNum] = resp->ToSlotItem; + + sP_FE2CL_PC_EQUIP_CHANGE* resp2 = (sP_FE2CL_PC_EQUIP_CHANGE*)xmalloc(sizeof(sP_FE2CL_PC_EQUIP_CHANGE)); + + resp2->iPC_ID = plr.plr.iID; + resp2->iEquipSlotNum = resp->iToSlotNum; + resp2->EquipSlotItem = resp->ToSlotItem; + + for (CNSocket* otherSock : plr.viewable) { + otherSock->sendPacket(new CNPacketData((void*)resp2, P_FE2CL_PC_EQUIP_CHANGE, sizeof(sP_FE2CL_PC_EQUIP_CHANGE), otherSock->getFEKey())); + } + + } else { + plr.plr.Inven[itemmove->iFromSlotNum] = resp->ToSlotItem; + } + + PlayerManager::players[sock] = plr; + + sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_PC_ITEM_MOVE_SUCC, sizeof(sP_FE2CL_PC_ITEM_MOVE_SUCC), sock->getFEKey())); +} \ No newline at end of file diff --git a/src/ItemManager.hpp b/src/ItemManager.hpp new file mode 100644 index 0000000..0036907 --- /dev/null +++ b/src/ItemManager.hpp @@ -0,0 +1,11 @@ +#ifndef _IM_HPP +#define _IM_HPP + +#include "CNShardServer.hpp" + +namespace ItemManager { + void init(); + void itemMoveHandler(CNSocket* sock, CNPacketData* data); +} + +#endif \ No newline at end of file diff --git a/src/Player.hpp b/src/Player.hpp index 2f2d8d2..991a842 100644 --- a/src/Player.hpp +++ b/src/Player.hpp @@ -20,6 +20,7 @@ struct Player { int x, y, z, angle; sItemBase Equip[AEQUIP_COUNT]; + sItemBase Inven[AINVEN_COUNT]; }; #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 4cf48d5..56e9055 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,7 @@ #include "CNShardServer.hpp" #include "PlayerManager.hpp" #include "ChatManager.hpp" +#include "ItemManager.hpp" #include "NanoManager.hpp" #include "NPCManager.hpp" @@ -30,6 +31,7 @@ int main() { std::cout << "[INFO] Intializing Packet Managers..." << std::endl; PlayerManager::init(); ChatManager::init(); + ItemManager::init(); NanoManager::init(); NPCManager::init(); diff --git a/src/structs/0104.hpp b/src/structs/0104.hpp index e238410..bd70161 100644 --- a/src/structs/0104.hpp +++ b/src/structs/0104.hpp @@ -1,6 +1,7 @@ /* genstructs.py */ #define AEQUIP_COUNT 9 +#define AINVEN_COUNT 50 #pragma pack(push)