Merge pull request #40 from dongresource/bugfix

Bugfixes
This commit is contained in:
CPunch 2020-08-25 13:52:51 -05:00 committed by GitHub
commit 260331715f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 35 deletions

View File

@ -126,7 +126,7 @@ 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 && itemreq->Item.iType >= 0 && itemreq->Item.iType <= 8) {
} else if (itemreq->eIL == 1 && itemreq->Item.iType >= 0 && itemreq->Item.iType <= 10) {
INITSTRUCT(sP_FE2CL_REP_PC_GIVE_ITEM_SUCC, resp);

View File

@ -113,6 +113,7 @@ void NPCManager::npcWarpHandler(CNSocket* sock, CNPacketData* data) {
return; // malformed packet
sP_CL2FE_REQ_PC_WARP_USE_NPC* warpNpc = (sP_CL2FE_REQ_PC_WARP_USE_NPC*)data->buf;
PlayerView& plrv = PlayerManager::players[sock];
// sanity check
if (Warps.find(warpNpc->iWarpID) == Warps.end())
@ -124,6 +125,10 @@ void NPCManager::npcWarpHandler(CNSocket* sock, CNPacketData* data) {
resp.iY = Warps[warpNpc->iWarpID].y;
resp.iZ = Warps[warpNpc->iWarpID].z;
// force player & NPC reload
plrv.viewable.clear();
plrv.viewableNPCs.clear();
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_WARP_USE_NPC_SUCC, sizeof(sP_FE2CL_REP_PC_WARP_USE_NPC_SUCC));
}

View File

@ -20,16 +20,20 @@ void NanoManager::nanoEquipHandler(CNSocket* sock, CNPacketData* data) {
INITSTRUCT(sP_FE2CL_REP_NANO_EQUIP_SUCC, resp);
Player *plr = PlayerManager::getPlayer(sock);
if (nano->iNanoSlotNum > 2)
// sanity check
if (nano->iNanoSlotNum > 2 || nano->iNanoSlotNum < 0)
return;
resp.iNanoID = nano->iNanoID;
resp.iNanoSlotNum = nano->iNanoSlotNum;
// Update player
plr->equippedNanos[nano->iNanoSlotNum] = nano->iNanoID;
// unsummon nano if replaced
if (plr->activeNano == plr->equippedNanos[nano->iNanoSlotNum])
summonNano(sock, -1);
sock->sendPacket((void*)&resp, P_FE2CL_REP_NANO_EQUIP_SUCC, sizeof(sP_FE2CL_REP_NANO_EQUIP_SUCC));
}
@ -41,11 +45,16 @@ void NanoManager::nanoUnEquipHandler(CNSocket* sock, CNPacketData* data) {
INITSTRUCT(sP_FE2CL_REP_NANO_UNEQUIP_SUCC, resp);
Player *plr = PlayerManager::getPlayer(sock);
if (nano->iNanoSlotNum > 2)
// sanity check
if (nano->iNanoSlotNum > 2 || nano->iNanoSlotNum < 0)
return;
resp.iNanoSlotNum = nano->iNanoSlotNum;
// unsummon nano if removed
if (plr->equippedNanos[nano->iNanoSlotNum] == plr->activeNano)
summonNano(sock, -1);
// update player
plr->equippedNanos[nano->iNanoSlotNum] = 0;
@ -75,33 +84,9 @@ void NanoManager::nanoSummonHandler(CNSocket* sock, CNPacketData* data) {
sP_CL2FE_REQ_NANO_ACTIVE* pkt = (sP_CL2FE_REQ_NANO_ACTIVE*)data->buf;
Player *plr = PlayerManager::getPlayer(sock);
summonNano(sock, pkt->iNanoSlotNum);
// Send to client
INITSTRUCT(sP_FE2CL_REP_NANO_ACTIVE_SUCC, resp);
resp.iActiveNanoSlotNum = pkt->iNanoSlotNum;
sock->sendPacket((void*)&resp, P_FE2CL_REP_NANO_ACTIVE_SUCC, sizeof(sP_FE2CL_REP_NANO_ACTIVE_SUCC));
if (pkt->iNanoSlotNum > 2)
return;
int nanoId = plr->equippedNanos[pkt->iNanoSlotNum];
if (nanoId > 36)
return; // sanity check
sNano nano = plr->Nanos[nanoId];
// Send to other players
INITSTRUCT(sP_FE2CL_NANO_ACTIVE, pkt1);
pkt1.iPC_ID = plr->iID;
pkt1.Nano = nano;
for (CNSocket* s : PlayerManager::players[sock].viewable)
s->sendPacket((void*)&pkt1, P_FE2CL_NANO_ACTIVE, sizeof(sP_FE2CL_NANO_ACTIVE));
// update player
plr->activeNano = nanoId;
DEBUGLOG(
std::cout << U16toU8(plr->PCStyle.szFirstName) << U16toU8(plr->PCStyle.szLastName) << " requested to summon nano slot: " << pkt->iNanoSlotNum << std::endl;
)
@ -158,6 +143,37 @@ void NanoManager::addNano(CNSocket* sock, int16_t nanoId, int16_t slot) {
plr->Nanos[nanoId] = resp.Nano;
}
void NanoManager::summonNano(CNSocket *sock, int slot) {
INITSTRUCT(sP_FE2CL_REP_NANO_ACTIVE_SUCC, resp);
resp.iActiveNanoSlotNum = slot;
sock->sendPacket((void*)&resp, P_FE2CL_REP_NANO_ACTIVE_SUCC, sizeof(sP_FE2CL_REP_NANO_ACTIVE_SUCC));
Player *plr = PlayerManager::getPlayer(sock);
std::cout << "summon nano\n";
if (slot > 2 || slot < 0)
return; //sanity check
int nanoId = plr->equippedNanos[slot];
if (nanoId > 36 || nanoId < 0)
return; // sanity check
sNano nano = plr->Nanos[nanoId];
// Send to other players
INITSTRUCT(sP_FE2CL_NANO_ACTIVE, pkt1);
pkt1.iPC_ID = plr->iID;
pkt1.Nano = nano;
for (CNSocket* s : PlayerManager::players[sock].viewable)
s->sendPacket((void*)&pkt1, P_FE2CL_NANO_ACTIVE, sizeof(sP_FE2CL_NANO_ACTIVE));
// update player
plr->activeNano = nanoId;
}
void NanoManager::setNanoSkill(CNSocket* sock, int16_t nanoId, int16_t skillId) {
if (nanoId > 36)
return;

View File

@ -13,6 +13,7 @@ namespace NanoManager {
// Helper methods
void addNano(CNSocket* sock, int16_t nanoId, int16_t slot);
void summonNano(CNSocket* sock, int slot);
void setNanoSkill(CNSocket* sock, int16_t nanoId, int16_t skillId);
void resetNanoSkill(CNSocket* sock, int16_t nanoId);
}

View File

@ -1,9 +1,8 @@
#pragma once
#include <string>
#include <cstring>
#ifndef _PLR_HPP
#define _PLR_HPP
#include "CNProtocol.hpp"
#include "CNStructs.hpp"
@ -27,5 +26,3 @@ struct Player {
sItemBase Inven[AINVEN_COUNT];
bool IsGM;
};
#endif

View File

@ -256,6 +256,7 @@ void PlayerManager::loadPlayer(CNSocket* sock, CNPacketData* data) {
sP_CL2FE_REQ_PC_LOADING_COMPLETE* complete = (sP_CL2FE_REQ_PC_LOADING_COMPLETE*)data->buf;
INITSTRUCT(sP_FE2CL_REP_PC_LOADING_COMPLETE_SUCC, response);
Player *plr = getPlayer(sock);
DEBUGLOG(
std::cout << "P_CL2FE_REQ_PC_LOADING_COMPLETE:" << std::endl;
@ -264,6 +265,9 @@ void PlayerManager::loadPlayer(CNSocket* sock, CNPacketData* data) {
response.iPC_ID = complete->iPC_ID;
// reload players & NPCs
updatePlayerPosition(sock, plr->x, plr->y, plr->z);
sock->sendPacket((void*)&response, P_FE2CL_REP_PC_LOADING_COMPLETE_SUCC, sizeof(sP_FE2CL_REP_PC_LOADING_COMPLETE_SUCC));
}