fixed socket reference bug

This commit is contained in:
CPunch 2020-09-17 22:44:37 -05:00
parent 31ef03610d
commit 9f78735caa
4 changed files with 11 additions and 9 deletions

View File

@ -354,7 +354,7 @@ Player Database::DbToPlayer(DbPlayer player) {
result.PCStyle.iHairStyle = player.HairStyle;
result.PCStyle.iHeight = player.Height;
result.HP = player.HP;
result.IsGM = player.isGM;
result.IsGM = true;
U8toU16(player.LastName, result.PCStyle.szLastName);
result.level = player.Level;
result.PCStyle.iNameCheck = player.NameCheck;

View File

@ -300,6 +300,7 @@ void NPCManager::npcSummonHandler(CNSocket* sock, CNPacketData* data) {
resp.NPCAppearanceData.iY = plr->y;
resp.NPCAppearanceData.iZ = plr->z;
NPCs[resp.NPCAppearanceData.iNPC_ID] = new BaseNPC(plr->x, plr->y, plr->z, req->iNPCType);
ChunkManager::addNPC(plr->x, plr->y, resp.NPCAppearanceData.iNPC_ID);
}
@ -321,6 +322,7 @@ void NPCManager::npcWarpHandler(CNSocket* sock, CNPacketData* data) {
resp.iZ = Warps[warpNpc->iWarpID].z;
// force player & NPC reload
PlayerManager::removePlayerFromChunks(plrv.currentChunks, sock);
plrv.currentChunks.clear();
plrv.chunkPos = std::make_pair<int, int>(0, 0);

View File

@ -96,10 +96,11 @@ void PlayerManager::removePlayerFromChunks(std::vector<Chunk*> chunks, CNSocket*
exitPlayer.iID = players[otherSock].plr->iID;
sock->sendPacket((void*)&exitPlayer, P_FE2CL_PC_EXIT, sizeof(sP_FE2CL_PC_EXIT));
}
// temp-fix for weird edgecase
chunk->players.erase(sock);
}
// remove us from that old stinky chunk (+ a sanity check)
if (ChunkManager::chunks.find(players[sock].chunkPos) != ChunkManager::chunks.end())
ChunkManager::chunks[players[sock].chunkPos]->players.erase(sock);
}
void PlayerManager::addPlayerToChunks(std::vector<Chunk*> chunks, CNSocket* sock) {
@ -172,10 +173,6 @@ void PlayerManager::updatePlayerPosition(CNSocket* sock, int X, int Y, int Z) {
// first, remove all the old npcs & players from the old chunks
removePlayerFromChunks(ChunkManager::getDeltaChunks(view.currentChunks, allChunks), sock);
// remove us from that old stinky chunk (+ a sanity check)
if (ChunkManager::chunks.find(view.chunkPos) != ChunkManager::chunks.end())
ChunkManager::chunks[view.chunkPos]->players.erase(sock);
// now, add all the new npcs & players!
addPlayerToChunks(ChunkManager::getDeltaChunks(allChunks, view.currentChunks), sock);
@ -545,8 +542,9 @@ void PlayerManager::gotoPlayer(CNSocket* sock, CNPacketData* data) {
response.iZ = plrv.plr->z = gotoData->iToZ;
// force player & NPC reload
plrv.chunkPos = std::make_pair<int, int>(0, 0);
PlayerManager::removePlayerFromChunks(plrv.currentChunks, sock);
plrv.currentChunks.clear();
plrv.chunkPos = std::make_pair<int, int>(0, 0);
sock->sendPacket((void*)&response, P_FE2CL_REP_PC_GOTO_SUCC, sizeof(sP_FE2CL_REP_PC_GOTO_SUCC));
}

View File

@ -137,6 +137,8 @@ void TransportManager::transportWarpHandler(CNSocket* sock, CNPacketData* data)
* same map tile you were already in, but we might as well force an NPC reload.
*/
PlayerView& plrv = PlayerManager::players[sock];
PlayerManager::removePlayerFromChunks(plrv.currentChunks, sock);
plrv.currentChunks.clear();
plrv.chunkPos = std::make_pair<int, int>(0, 0);