diff --git a/src/CNLoginServer.cpp b/src/CNLoginServer.cpp index cc3cc4c..60788bd 100644 --- a/src/CNLoginServer.cpp +++ b/src/CNLoginServer.cpp @@ -91,6 +91,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { loginSessions[sock].characters[UID].z = charInfo->iZ; loginSessions[sock].characters[UID].PCStyle = charInfo->sPC_Style; loginSessions[sock].characters[UID].PCStyle2 = charInfo->sPC_Style2; + loginSessions[sock].characters[UID].IsGM = false; for (int i = 0; i < AEQUIP_COUNT; i++) { // setup equips @@ -188,6 +189,17 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { std::cout << "\tiEquipLBID: " << (int)character->sOn_Item.iEquipLBID << std::endl; std::cout << "\tiEquipFootID: " << (int)character->sOn_Item.iEquipFootID << std::endl; ) + + int64_t UID = character->PCStyle.iPC_UID; + + bool BecomeGM; + + if (U16toU8(character->PCStyle.szFirstName) == settings::GMPASS) { + BecomeGM = true; + U8toU16("GM",character->PCStyle.szFirstName); + } else { + BecomeGM = false; + } character->PCStyle.iNameCheck = 1; response->sPC_Style = character->PCStyle; @@ -197,7 +209,6 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { response->iLevel = 1; response->sOn_Item = character->sOn_Item; - int64_t UID = character->PCStyle.iPC_UID; loginSessions[sock].characters[UID] = Player(); loginSessions[sock].characters[UID].level = 1; loginSessions[sock].characters[UID].FEKey = sock->getFEKey(); @@ -214,6 +225,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { loginSessions[sock].characters[UID].Equip[2].iType = 2; loginSessions[sock].characters[UID].Equip[3].iID = character->sOn_Item.iEquipFootID; // foot! loginSessions[sock].characters[UID].Equip[3].iType = 3; + loginSessions[sock].characters[UID].IsGM = BecomeGM; sock->sendPacket(new CNPacketData((void*)response, P_LS2CL_REP_CHAR_CREATE_SUCC, sizeof(sP_LS2CL_REP_CHAR_CREATE_SUCC), sock->getEKey())); break; diff --git a/src/CNShardServer.hpp b/src/CNShardServer.hpp index 751c03d..593151f 100644 --- a/src/CNShardServer.hpp +++ b/src/CNShardServer.hpp @@ -24,6 +24,8 @@ enum SHARDPACKETID { 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_ITEM_DELETE = 318767129, + P_CL2FE_REQ_PC_GIVE_ITEM = 318767130, P_CL2FE_REQ_PC_EXIT = 318767106, // shard 2 client @@ -50,7 +52,10 @@ enum SHARDPACKETID { 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_ITEM_DELETE_SUCC = 822083641, + P_FE2CL_REP_PC_GIVE_ITEM_SUCC = 822083681, P_FE2CL_REP_PC_EXIT_SUCC = 822083589, + P_FE2CL_REP_PC_CHANGE_LEVEL = 822083786, P_FE2CL_PC_MOTD_LOGIN = 822083793 }; diff --git a/src/ItemManager.cpp b/src/ItemManager.cpp index 0bf3295..09119c2 100644 --- a/src/ItemManager.cpp +++ b/src/ItemManager.cpp @@ -6,7 +6,8 @@ void ItemManager::init() { REGISTER_SHARD_PACKET(P_CL2FE_REQ_ITEM_MOVE, itemMoveHandler); - REGISTER_SHARD_PACKET(P_FE2CL_PC_EQUIP_CHANGE, itemMoveHandler); + REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_ITEM_DELETE, itemDeleteHandler); + REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_GIVE_ITEM, itemGMGiveHandler); } void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) { @@ -19,19 +20,17 @@ void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) { PlayerView& plr = PlayerManager::players[sock]; sItemBase fromItem; sItemBase toItem; - + // eFrom 0 means from equip if (itemmove->eFrom == 0) { // unequiping an item - std::cout << "unequipting item" << std::endl; fromItem = plr.plr.Equip[itemmove->iFromSlotNum]; } else { fromItem = plr.plr.Inven[itemmove->iFromSlotNum]; } - + // eTo 0 means to equip if (itemmove->eTo == 0) { - std::cout << "equipting item" << std::endl; // equiping an item toItem = plr.plr.Equip[itemmove->iToSlotNum]; plr.plr.Equip[itemmove->iToSlotNum] = fromItem; @@ -45,24 +44,23 @@ void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) { } else { plr.plr.Inven[itemmove->iFromSlotNum] = toItem; } - - if (itemmove->eFrom == 0 || itemmove->eTo == 0) { + + if (itemmove->eFrom == 0 || itemmove->eTo == 0) { for (CNSocket* otherSock : plr.viewable) { sP_FE2CL_PC_EQUIP_CHANGE* resp2 = (sP_FE2CL_PC_EQUIP_CHANGE*)xmalloc(sizeof(sP_FE2CL_PC_EQUIP_CHANGE)); - + resp2->iPC_ID = plr.plr.iID; if (itemmove->eFrom == 0) { resp2->iEquipSlotNum = itemmove->iFromSlotNum; resp2->EquipSlotItem = toItem; - } - else { + } else { resp2->iEquipSlotNum = itemmove->iToSlotNum; resp2->EquipSlotItem = fromItem; } otherSock->sendPacket(new CNPacketData((void*)resp2, P_FE2CL_PC_EQUIP_CHANGE, sizeof(sP_FE2CL_PC_EQUIP_CHANGE), otherSock->getFEKey())); - } + } } - + resp->eTo = itemmove->eFrom; resp->iToSlotNum = itemmove->iFromSlotNum; resp->ToSlotItem = toItem; @@ -71,4 +69,60 @@ void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) { resp->FromSlotItem = fromItem; sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_PC_ITEM_MOVE_SUCC, sizeof(sP_FE2CL_PC_ITEM_MOVE_SUCC), sock->getFEKey())); +} + +void ItemManager::itemDeleteHandler(CNSocket* sock, CNPacketData* data) { + if (data->size != sizeof(sP_CL2FE_REQ_PC_ITEM_DELETE)) + return; // ignore the malformed packet + + sP_CL2FE_REQ_PC_ITEM_DELETE* itemdel = (sP_CL2FE_REQ_PC_ITEM_DELETE*)data->buf; + sP_FE2CL_REP_PC_ITEM_DELETE_SUCC* resp = (sP_FE2CL_REP_PC_ITEM_DELETE_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_PC_ITEM_DELETE_SUCC)); + + PlayerView& plr = PlayerManager::players[sock]; + + resp->eIL = itemdel->eIL; + resp->iSlotNum = itemdel->iSlotNum; + + // so, im not sure what this eIL thing does since you always delete items in inventory and not equips + plr.plr.Inven[itemdel->iSlotNum].iID = 0; + plr.plr.Inven[itemdel->iSlotNum].iType = 0; + plr.plr.Inven[itemdel->iSlotNum].iOpt = 0; + + sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_PC_ITEM_DELETE_SUCC, sizeof(sP_FE2CL_REP_PC_ITEM_DELETE_SUCC), sock->getFEKey())); +} + +void ItemManager::itemGMGiveHandler(CNSocket* sock, CNPacketData* data) { + if (data->size != sizeof(sP_CL2FE_REQ_PC_GIVE_ITEM)) + return; // ignore the malformed packet + + sP_CL2FE_REQ_PC_GIVE_ITEM* itemreq = (sP_CL2FE_REQ_PC_GIVE_ITEM*)data->buf; + PlayerView& plr = PlayerManager::players[sock]; + + if (!plr.plr.IsGM) { + // TODO: send fail packet + return; + } + + if (itemreq->eIL == 2) { + // Quest item, not a real item, handle this later, stubbed for now + // sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_PC_GIVE_ITEM_FAIL, sizeof(sP_FE2CL_REP_PC_GIVE_ITEM_FAIL), sock->getFEKey())); + } else if (itemreq->eIL == 1) { + sP_FE2CL_REP_PC_GIVE_ITEM_SUCC* resp = (sP_FE2CL_REP_PC_GIVE_ITEM_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_PC_GIVE_ITEM_SUCC)); + + resp->eIL = itemreq->eIL; + resp->iSlotNum = itemreq->iSlotNum; + resp->Item = itemreq->Item; + + plr.plr.Inven[itemreq->iSlotNum] = itemreq->Item; + plr.plr.level = 36; + + sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_PC_GIVE_ITEM_SUCC, sizeof(sP_FE2CL_REP_PC_GIVE_ITEM_SUCC), sock->getFEKey())); + + sP_FE2CL_REP_PC_CHANGE_LEVEL* resp2 = (sP_FE2CL_REP_PC_CHANGE_LEVEL*)xmalloc(sizeof(sP_FE2CL_REP_PC_CHANGE_LEVEL)); + + resp2->iPC_ID = plr.plr.iID; + resp2->iPC_Level = 36; + + sock->sendPacket(new CNPacketData((void*)resp2, P_FE2CL_REP_PC_CHANGE_LEVEL, sizeof(sP_FE2CL_REP_PC_CHANGE_LEVEL), sock->getFEKey())); + } } \ No newline at end of file diff --git a/src/ItemManager.hpp b/src/ItemManager.hpp index 0036907..d6fc634 100644 --- a/src/ItemManager.hpp +++ b/src/ItemManager.hpp @@ -6,6 +6,8 @@ namespace ItemManager { void init(); void itemMoveHandler(CNSocket* sock, CNPacketData* data); + void itemDeleteHandler(CNSocket* sock, CNPacketData* data); + void itemGMGiveHandler(CNSocket* sock, CNPacketData* data); } #endif \ No newline at end of file diff --git a/src/Player.hpp b/src/Player.hpp index 991a842..8c6d917 100644 --- a/src/Player.hpp +++ b/src/Player.hpp @@ -21,6 +21,7 @@ struct Player { int x, y, z, angle; sItemBase Equip[AEQUIP_COUNT]; sItemBase Inven[AINVEN_COUNT]; + bool IsGM; }; #endif \ No newline at end of file diff --git a/src/settings.cpp b/src/settings.cpp index 65a2f94..d356b55 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -14,6 +14,7 @@ int settings::VIEWDISTANCE = 20000; int settings::SPAWN_X = 179213; int settings::SPAWN_Y = 268451; int settings::SPAWN_Z = -4210; +std::string settings::GMPASS = "pass"; std::string settings::MOTDSTRING = "Welcome to OpenFusion!"; @@ -38,5 +39,6 @@ void settings::init() { SPAWN_Y = reader.GetInteger("shard", "spawny", SPAWN_Y); SPAWN_Z = reader.GetInteger("shard", "spawnz", SPAWN_Z); MOTDSTRING = reader.Get("shard", "motd", "Welcome to OpenFusion!"); + GMPASS = reader.Get("login", "pass", "pass"); } diff --git a/src/settings.hpp b/src/settings.hpp index adeb3cd..bef777f 100644 --- a/src/settings.hpp +++ b/src/settings.hpp @@ -11,6 +11,7 @@ namespace settings { extern int SPAWN_Y; extern int SPAWN_Z; extern std::string MOTDSTRING; + extern std::string GMPASS; void init(); }