From ff5f3966e31af2812cce5ba2371ce8ac00a3d8fb Mon Sep 17 00:00:00 2001 From: JadeShrineMaiden <69916714+JadeShrineMaiden@users.noreply.github.com> Date: Mon, 24 Aug 2020 09:07:51 +0100 Subject: [PATCH] Sanity checks + Starting level changes (#31) * Sanity checks + Starting level changes - Item movement handler checks to make sure items aren't moved from equipment slot to equipment slot. - Item give command checks to make sure an out of bounds item is not spawned (Below iType 0 or above iType 8) - Players now begin at level 36, consequently the item give command does not level you up now. * Sanity Check - Prevents out of bounds item movement by comparing it to AINVEN_COUNT. --- src/CNLoginServer.cpp | 4 ++-- src/ItemManager.cpp | 33 ++++++++++++++++++++++++++------- src/PlayerManager.cpp | 2 +- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/CNLoginServer.cpp b/src/CNLoginServer.cpp index 5e62ea4..63a7824 100644 --- a/src/CNLoginServer.cpp +++ b/src/CNLoginServer.cpp @@ -208,11 +208,11 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { resp.sPC_Style2.iAppearanceFlag = 1; resp.sPC_Style2.iTutorialFlag = 1; resp.sPC_Style2.iPayzoneFlag = 1; - resp.iLevel = 1; + resp.iLevel = 36; resp.sOn_Item = character->sOn_Item; loginSessions[sock].characters[UID] = Player(); - loginSessions[sock].characters[UID].level = 1; + loginSessions[sock].characters[UID].level = 36; loginSessions[sock].characters[UID].FEKey = sock->getFEKey(); loginSessions[sock].characters[UID].PCStyle = character->PCStyle; loginSessions[sock].characters[UID].PCStyle2.iAppearanceFlag = 1; diff --git a/src/ItemManager.cpp b/src/ItemManager.cpp index a293aa6..62d1639 100644 --- a/src/ItemManager.cpp +++ b/src/ItemManager.cpp @@ -16,8 +16,25 @@ void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) { sP_CL2FE_REQ_ITEM_MOVE* itemmove = (sP_CL2FE_REQ_ITEM_MOVE*)data->buf; INITSTRUCT(sP_FE2CL_PC_ITEM_MOVE_SUCC, resp); - + PlayerView& plr = PlayerManager::players[sock]; + + if (itemmove->eFrom == 0 && itemmove->eTo == 0) { + // this packet should never happen, tell the client to do nothing and do nothing ourself + resp.eTo = itemmove->eFrom; + resp.iToSlotNum = itemmove->iFromSlotNum; + resp.ToSlotItem = plr.plr.Equip[itemmove->iToSlotNum]; + resp.eFrom = itemmove->eTo; + resp.iFromSlotNum = itemmove->iToSlotNum; + resp.FromSlotItem = plr.plr.Equip[itemmove->iFromSlotNum]; + + sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_ITEM_DELETE_SUCC, sizeof(sP_FE2CL_REP_PC_ITEM_DELETE_SUCC)); + return; + } + + if (itemmove->iToSlotNum > AINVEN_COUNT) + return; // sanity checks + sItemBase fromItem; sItemBase toItem; @@ -109,7 +126,8 @@ void ItemManager::itemGMGiveHandler(CNSocket* sock, CNPacketData* data) { 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) { + } else if (itemreq->eIL == 1 && itemreq->Item.iType >= 0 && itemreq->Item.iType <= 8) { + INITSTRUCT(sP_FE2CL_REP_PC_GIVE_ITEM_SUCC, resp); resp.eIL = itemreq->eIL; @@ -117,17 +135,18 @@ void ItemManager::itemGMGiveHandler(CNSocket* sock, CNPacketData* data) { resp.Item = itemreq->Item; plr.plr.Inven[itemreq->iSlotNum] = itemreq->Item; - plr.plr.level = 36; sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_GIVE_ITEM_SUCC, sizeof(sP_FE2CL_REP_PC_GIVE_ITEM_SUCC)); // some items require a level, for now we're just going to bypass this by setting your level to 36 + //plr.plr.level = 36; - sP_FE2CL_REP_PC_CHANGE_LEVEL resp2; + //sP_FE2CL_REP_PC_CHANGE_LEVEL resp2; - resp2.iPC_ID = plr.plr.iID; - resp2.iPC_Level = 36; + //resp2.iPC_ID = plr.plr.iID; + //resp2.iPC_Level = 36; - sock->sendPacket((void*)&resp2, P_FE2CL_REP_PC_CHANGE_LEVEL, sizeof(sP_FE2CL_REP_PC_CHANGE_LEVEL)); + //sock->sendPacket((void*)&resp2, P_FE2CL_REP_PC_CHANGE_LEVEL, sizeof(sP_FE2CL_REP_PC_CHANGE_LEVEL)); + // saving this for later use on a /level command } } \ No newline at end of file diff --git a/src/PlayerManager.cpp b/src/PlayerManager.cpp index ab17c51..16b097f 100644 --- a/src/PlayerManager.cpp +++ b/src/PlayerManager.cpp @@ -187,7 +187,7 @@ void PlayerManager::enterPlayer(CNSocket* sock, CNPacketData* data) { response.iID = rand(); response.uiSvrTime = getTime(); response.PCLoadData2CL.iUserLevel = 1; - response.PCLoadData2CL.iHP = 1000 * plr.level; + response.PCLoadData2CL.iHP = 3625; //TODO: Check player levelupdata and get this right response.PCLoadData2CL.iLevel = plr.level; response.PCLoadData2CL.iMentor = 1; response.PCLoadData2CL.iMentorCount = 4;