diff --git a/.gitignore b/.gitignore index 2d294b1..882e3b1 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,5 @@ tags CMakeFiles/ CMakeCache.txt build/ -.vs/ -.idea/ +.vs/ +.idea/ diff --git a/.vimrc b/.vimrc new file mode 100644 index 0000000..c5c65b2 --- /dev/null +++ b/.vimrc @@ -0,0 +1,9 @@ +" vim configuration file + +" you will need to put 'set exrc' and 'set secure' into your main .vimrc file, +" in which case this file will be loaded automatically, but *only* if you +" start vim in this dir, or you can just load it directly with ':so .vimrc' +" every time. +set tabstop=4 +set shiftwidth=4 +set expandtab diff --git a/README.md b/README.md index e93b288..69000c3 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,7 @@ It's what's called a landwalker; enough of the server has been implemented to al To make your landwalking experience more pleasant, you can make use of a few admin commands to get around easier: +### Movement commands * A `/speed` of around 2400 or 3000 is nice. * A `/jump` of about 50 will send you soaring * [This map](res/dong_number_map.png) (credit to Danny O) is useful for `/warp` coordinates. diff --git a/config.ini b/config.ini index c63fe78..7ab905e 100644 --- a/config.ini +++ b/config.ini @@ -16,7 +16,6 @@ randomcharacters=true # Shard Server configuration [shard] port=8002 -# you'll want to change this one ip=127.0.0.1 # distance at which other players and NPCs become visible view=20000 diff --git a/src/CNLoginServer.cpp b/src/CNLoginServer.cpp index 63a7824..724468c 100644 --- a/src/CNLoginServer.cpp +++ b/src/CNLoginServer.cpp @@ -275,7 +275,6 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { CNSharedData::setPlayer(resp.iEnterSerialKey, loginSessions[sock].characters[loginSessions[sock].selectedChar]); sock->sendPacket((void*)&resp, P_LS2CL_REP_SHARD_SELECT_SUCC, sizeof(sP_LS2CL_REP_SHARD_SELECT_SUCC)); - sock->kill(); // client should connect to the Shard server now break; } default: diff --git a/src/CNShardServer.cpp b/src/CNShardServer.cpp index c38664f..9c3f49c 100644 --- a/src/CNShardServer.cpp +++ b/src/CNShardServer.cpp @@ -48,11 +48,15 @@ void CNShardServer::newConnection(CNSocket* cns) { } void CNShardServer::killConnection(CNSocket* cns) { + // check if the player ever sent a REQ_PC_ENTER + if (PlayerManager::players.find(cns) == PlayerManager::players.end()) + return; + // remove from CNSharedData - Player cachedPlr = PlayerManager::getPlayer(cns); + int64_t key = PlayerManager::getPlayer(cns)->SerialKey; PlayerManager::removePlayer(cns); - CNSharedData::erasePlayer(cachedPlr.SerialKey); + CNSharedData::erasePlayer(key); } void CNShardServer::onStep() { diff --git a/src/ChatManager.cpp b/src/ChatManager.cpp index f9e0d16..2be5c3e 100644 --- a/src/ChatManager.cpp +++ b/src/ChatManager.cpp @@ -18,7 +18,7 @@ void ChatManager::chatHandler(CNSocket* sock, CNPacketData* data) { // send to client INITSTRUCT(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, resp); memcpy(resp.szFreeChat, chat->szFreeChat, sizeof(chat->szFreeChat)); - resp.iPC_ID = plr.plr.iID; + resp.iPC_ID = plr.plr->iID; resp.iEmoteCode = chat->iEmoteCode; sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC)); @@ -36,7 +36,7 @@ void ChatManager::menuChatHandler(CNSocket* sock, CNPacketData* data) { // send to client INITSTRUCT(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, resp); memcpy(resp.szFreeChat, chat->szFreeChat, sizeof(chat->szFreeChat)); - resp.iPC_ID = PlayerManager::players[sock].plr.iID; + resp.iPC_ID = PlayerManager::players[sock].plr->iID; resp.iEmoteCode = chat->iEmoteCode; sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC)); @@ -57,7 +57,7 @@ void ChatManager::emoteHandler(CNSocket* sock, CNPacketData* data) { // send to client INITSTRUCT(sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT, resp); resp.iEmoteCode = emote->iEmoteCode; - resp.iID_From = plr.plr.iID; + resp.iID_From = plr.plr->iID; sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_AVATAR_EMOTES_CHAT, sizeof(sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT)); // send to visible players (players within render distance) diff --git a/src/ItemManager.cpp b/src/ItemManager.cpp index 62d1639..b3c7424 100644 --- a/src/ItemManager.cpp +++ b/src/ItemManager.cpp @@ -23,10 +23,10 @@ void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) { // 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.ToSlotItem = plr.plr->Equip[itemmove->iToSlotNum]; resp.eFrom = itemmove->eTo; resp.iFromSlotNum = itemmove->iToSlotNum; - resp.FromSlotItem = plr.plr.Equip[itemmove->iFromSlotNum]; + 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; @@ -41,31 +41,31 @@ void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) { // eFrom 0 means from equip if (itemmove->eFrom == 0) { // unequiping an item - fromItem = plr.plr.Equip[itemmove->iFromSlotNum]; + fromItem = plr.plr->Equip[itemmove->iFromSlotNum]; } else { - fromItem = plr.plr.Inven[itemmove->iFromSlotNum]; + fromItem = plr.plr->Inven[itemmove->iFromSlotNum]; } // eTo 0 means to equip if (itemmove->eTo == 0) { // equiping an item - toItem = plr.plr.Equip[itemmove->iToSlotNum]; - plr.plr.Equip[itemmove->iToSlotNum] = fromItem; + toItem = plr.plr->Equip[itemmove->iToSlotNum]; + plr.plr->Equip[itemmove->iToSlotNum] = fromItem; } else { - toItem = plr.plr.Inven[itemmove->iToSlotNum]; - plr.plr.Inven[itemmove->iToSlotNum] = fromItem; + toItem = plr.plr->Inven[itemmove->iToSlotNum]; + plr.plr->Inven[itemmove->iToSlotNum] = fromItem; } if (itemmove->eFrom == 0) { - plr.plr.Equip[itemmove->iFromSlotNum] = toItem; + plr.plr->Equip[itemmove->iFromSlotNum] = toItem; } else { - plr.plr.Inven[itemmove->iFromSlotNum] = toItem; + plr.plr->Inven[itemmove->iFromSlotNum] = toItem; } if (itemmove->eFrom == 0 || itemmove->eTo == 0) { INITSTRUCT(sP_FE2CL_PC_EQUIP_CHANGE, equipChange); - equipChange.iPC_ID = plr.plr.iID; + equipChange.iPC_ID = plr.plr->iID; if (itemmove->eFrom == 0) { equipChange.iEquipSlotNum = itemmove->iFromSlotNum; equipChange.EquipSlotItem = toItem; @@ -103,9 +103,9 @@ void ItemManager::itemDeleteHandler(CNSocket* sock, CNPacketData* data) { 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; + plr.plr->Inven[itemdel->iSlotNum].iID = 0; + plr.plr->Inven[itemdel->iSlotNum].iType = 0; + plr.plr->Inven[itemdel->iSlotNum].iOpt = 0; sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_ITEM_DELETE_SUCC, sizeof(sP_FE2CL_REP_PC_ITEM_DELETE_SUCC)); } @@ -118,7 +118,7 @@ void ItemManager::itemGMGiveHandler(CNSocket* sock, CNPacketData* data) { PlayerView& plr = PlayerManager::players[sock]; // Commented and disabled for future use - //if (!plr.plr.IsGM) { + //if (!plr.plr->IsGM) { // TODO: send fail packet // return; //} @@ -134,19 +134,19 @@ void ItemManager::itemGMGiveHandler(CNSocket* sock, CNPacketData* data) { resp.iSlotNum = itemreq->iSlotNum; resp.Item = itemreq->Item; - plr.plr.Inven[itemreq->iSlotNum] = itemreq->Item; + plr.plr->Inven[itemreq->iSlotNum] = itemreq->Item; 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; + //plr.plr->level = 36; //sP_FE2CL_REP_PC_CHANGE_LEVEL resp2; - //resp2.iPC_ID = plr.plr.iID; + //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)); // saving this for later use on a /level command } -} \ No newline at end of file +} diff --git a/src/NPCManager.cpp b/src/NPCManager.cpp index 35afcf9..98d999e 100644 --- a/src/NPCManager.cpp +++ b/src/NPCManager.cpp @@ -58,8 +58,8 @@ void NPCManager::updatePlayerNPCS(CNSocket* sock, PlayerView& view) { std::list noView; for (auto& pair : NPCs) { - int diffX = abs(view.plr.x - pair.second.appearanceData.iX); - int diffY = abs(view.plr.y - pair.second.appearanceData.iY); + int diffX = abs(view.plr->x - pair.second.appearanceData.iX); + int diffY = abs(view.plr->y - pair.second.appearanceData.iY); if (diffX < settings::VIEWDISTANCE && diffY < settings::VIEWDISTANCE) { yesView.push_back(pair.first); diff --git a/src/NanoManager.cpp b/src/NanoManager.cpp index a36bdee..c737b2a 100644 --- a/src/NanoManager.cpp +++ b/src/NanoManager.cpp @@ -18,7 +18,7 @@ void NanoManager::nanoEquipHandler(CNSocket* sock, CNPacketData* data) { sP_CL2FE_REQ_NANO_EQUIP* nano = (sP_CL2FE_REQ_NANO_EQUIP*)data->buf; INITSTRUCT(sP_FE2CL_REP_NANO_EQUIP_SUCC, resp); - Player plr = PlayerManager::getPlayer(sock); + Player *plr = PlayerManager::getPlayer(sock); if (nano->iNanoSlotNum > 2) return; @@ -28,8 +28,7 @@ void NanoManager::nanoEquipHandler(CNSocket* sock, CNPacketData* data) { // Update player - plr.equippedNanos[nano->iNanoSlotNum] = nano->iNanoID; - PlayerManager::updatePlayer(sock, plr); + plr->equippedNanos[nano->iNanoSlotNum] = nano->iNanoID; sock->sendPacket((void*)&resp, P_FE2CL_REP_NANO_EQUIP_SUCC, sizeof(sP_FE2CL_REP_NANO_EQUIP_SUCC)); } @@ -40,7 +39,7 @@ void NanoManager::nanoUnEquipHandler(CNSocket* sock, CNPacketData* data) { sP_CL2FE_REQ_NANO_UNEQUIP* nano = (sP_CL2FE_REQ_NANO_UNEQUIP*)data->buf; INITSTRUCT(sP_FE2CL_REP_NANO_UNEQUIP_SUCC, resp); - Player plr = PlayerManager::getPlayer(sock); + Player *plr = PlayerManager::getPlayer(sock); if (nano->iNanoSlotNum > 2) return; @@ -48,8 +47,7 @@ void NanoManager::nanoUnEquipHandler(CNSocket* sock, CNPacketData* data) { resp.iNanoSlotNum = nano->iNanoSlotNum; // update player - plr.equippedNanos[nano->iNanoSlotNum] = 0; - PlayerManager::updatePlayer(sock, plr); + plr->equippedNanos[nano->iNanoSlotNum] = 0; sock->sendPacket((void*)&resp, P_FE2CL_REP_NANO_UNEQUIP_SUCC, sizeof(sP_FE2CL_REP_NANO_UNEQUIP_SUCC)); } @@ -60,13 +58,13 @@ void NanoManager::nanoGMGiveHandler(CNSocket* sock, CNPacketData* data) { // Cmd: /nano sP_CL2FE_REQ_PC_GIVE_NANO* nano = (sP_CL2FE_REQ_PC_GIVE_NANO*)data->buf; - Player plr = PlayerManager::getPlayer(sock); + Player *plr = PlayerManager::getPlayer(sock); // Add nano to player addNano(sock, nano->iNanoID, 0); DEBUGLOG( - std::cout << U16toU8(plr.PCStyle.szFirstName) << U16toU8(plr.PCStyle.szLastName) << " requested to add nano id: " << nano->iNanoID << std::endl; + std::cout << U16toU8(plr->PCStyle.szFirstName) << U16toU8(plr->PCStyle.szLastName) << " requested to add nano id: " << nano->iNanoID << std::endl; ) } @@ -75,7 +73,7 @@ void NanoManager::nanoSummonHandler(CNSocket* sock, CNPacketData* data) { return; // malformed packet sP_CL2FE_REQ_NANO_ACTIVE* pkt = (sP_CL2FE_REQ_NANO_ACTIVE*)data->buf; - Player plr = PlayerManager::getPlayer(sock); + Player *plr = PlayerManager::getPlayer(sock); // Send to client INITSTRUCT(sP_FE2CL_REP_NANO_ACTIVE_SUCC, resp); @@ -85,28 +83,27 @@ void NanoManager::nanoSummonHandler(CNSocket* sock, CNPacketData* data) { if (pkt->iNanoSlotNum > 2) return; - int nanoId = plr.equippedNanos[pkt->iNanoSlotNum]; + int nanoId = plr->equippedNanos[pkt->iNanoSlotNum]; if (nanoId > 36) return; // sanity check - sNano nano = plr.Nanos[nanoId]; + sNano nano = plr->Nanos[nanoId]; // Send to other players INITSTRUCT(sP_FE2CL_NANO_ACTIVE, pkt1); - pkt1.iPC_ID = plr.iID; + 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; - PlayerManager::updatePlayer(sock, plr); + plr->activeNano = nanoId; DEBUGLOG( - std::cout << U16toU8(plr.PCStyle.szFirstName) << U16toU8(plr.PCStyle.szLastName) << " requested to summon nano slot: " << pkt->iNanoSlotNum << std::endl; + std::cout << U16toU8(plr->PCStyle.szFirstName) << U16toU8(plr->PCStyle.szLastName) << " requested to summon nano slot: " << pkt->iNanoSlotNum << std::endl; ) } @@ -115,7 +112,7 @@ void NanoManager::nanoSkillUseHandler(CNSocket* sock, CNPacketData* data) { return; // malformed packet sP_CL2FE_REQ_NANO_SKILL_USE* skill = (sP_CL2FE_REQ_NANO_SKILL_USE*)data->buf; - Player plr = PlayerManager::getPlayer(sock); + Player *plr = PlayerManager::getPlayer(sock); // Send to client INITSTRUCT(sP_FE2CL_NANO_SKILL_USE_SUCC, resp); @@ -124,10 +121,14 @@ void NanoManager::nanoSkillUseHandler(CNSocket* sock, CNPacketData* data) { resp.iArg3 = skill->iArg3; resp.iBulletID = skill->iBulletID; resp.iTargetCnt = skill->iTargetCnt; - resp.iPC_ID = plr.iID; + resp.iPC_ID = plr->iID; resp.iNanoStamina = 150; // Hardcoded for now sock->sendPacket((void*)&resp, P_FE2CL_NANO_SKILL_USE_SUCC, sizeof(sP_FE2CL_NANO_SKILL_USE_SUCC)); + + DEBUGLOG( + std::cout << U16toU8(plr->PCStyle.szFirstName) << U16toU8(plr->PCStyle.szLastName) << " requested to summon nano skill " << std::endl; + ) } void NanoManager::nanoSkillSetHandler(CNSocket* sock, CNPacketData* data) { @@ -143,7 +144,7 @@ void NanoManager::addNano(CNSocket* sock, int16_t nanoId, int16_t slot) { if (nanoId > 36) return; - Player plr = PlayerManager::getPlayer(sock); + Player *plr = PlayerManager::getPlayer(sock); // Send to client INITSTRUCT(sP_FE2CL_REP_PC_NANO_CREATE_SUCC, resp); @@ -154,19 +155,18 @@ void NanoManager::addNano(CNSocket* sock, int16_t nanoId, int16_t slot) { sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_NANO_CREATE_SUCC, sizeof(sP_FE2CL_REP_PC_NANO_CREATE_SUCC)); // Update player - plr.Nanos[nanoId] = resp.Nano; - PlayerManager::updatePlayer(sock, plr); + plr->Nanos[nanoId] = resp.Nano; } void NanoManager::setNanoSkill(CNSocket* sock, int16_t nanoId, int16_t skillId) { if (nanoId > 36) return; - Player plr = PlayerManager::getPlayer(sock); - sNano nano = plr.Nanos[nanoId]; + Player *plr = PlayerManager::getPlayer(sock); + sNano nano = plr->Nanos[nanoId]; nano.iSkillID = skillId; - plr.Nanos[nanoId] = nano; + plr->Nanos[nanoId] = nano; // Send to client INITSTRUCT(sP_FE2CL_REP_NANO_TUNE_SUCC, resp); @@ -175,27 +175,20 @@ void NanoManager::setNanoSkill(CNSocket* sock, int16_t nanoId, int16_t skillId) sock->sendPacket((void*)&resp, P_FE2CL_REP_NANO_TUNE_SUCC, sizeof(sP_FE2CL_REP_NANO_TUNE_SUCC)); - // Update the player - PlayerManager::updatePlayer(sock, plr); - DEBUGLOG( - std::cout << U16toU8(plr.PCStyle.szFirstName) << U16toU8(plr.PCStyle.szLastName) << " set skill id " << skillId << " for nano: " << nanoId << std::endl; + std::cout << U16toU8(plr->PCStyle.szFirstName) << U16toU8(plr->PCStyle.szLastName) << " set skill id " << skillId << " for nano: " << nanoId << std::endl; ) - } void NanoManager::resetNanoSkill(CNSocket* sock, int16_t nanoId) { if (nanoId > 36) return; - Player plr = PlayerManager::getPlayer(sock); - sNano nano = plr.Nanos[nanoId]; + Player *plr = PlayerManager::getPlayer(sock); + sNano nano = plr->Nanos[nanoId]; // 0 is reset nano.iSkillID = 0; - plr.Nanos[nanoId] = nano; - - // Update the player - PlayerManager::updatePlayer(sock, plr); + plr->Nanos[nanoId] = nano; } #pragma endregion diff --git a/src/PlayerManager.cpp b/src/PlayerManager.cpp index 196fed3..293b3b4 100644 --- a/src/PlayerManager.cpp +++ b/src/PlayerManager.cpp @@ -30,15 +30,18 @@ void PlayerManager::init() { REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_REGEN, PlayerManager::revivePlayer); REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_EXIT, PlayerManager::exitGame); REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_SPECIAL_STATE_SWITCH, PlayerManager::setSpecialSwitchPlayer); - REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_VEHICLE_ON, PlayerManager::enterPlayerVehicle); REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_VEHICLE_OFF, PlayerManager::exitPlayerVehicle); } void PlayerManager::addPlayer(CNSocket* key, Player plr) { + Player *p = new Player(); + + memcpy(p, &plr, sizeof(Player)); + players[key] = PlayerView(); players[key].viewable = std::list(); - players[key].plr = plr; + players[key].plr = p; players[key].lastHeartbeat = 0; std::cout << U16toU8(plr.PCStyle.szFirstName) << " " << U16toU8(plr.PCStyle.szLastName) << " has joined!" << std::endl; @@ -54,21 +57,22 @@ void PlayerManager::removePlayer(CNSocket* key) { // now sent PC_EXIT packet sP_FE2CL_PC_EXIT exitPacket; - exitPacket.iID = players[key].plr.iID; + exitPacket.iID = players[key].plr->iID; otherSock->sendPacket((void*)&exitPacket, P_FE2CL_PC_EXIT, sizeof(sP_FE2CL_PC_EXIT)); } + delete cachedView.plr; players.erase(key); - std::cout << U16toU8(cachedView.plr.PCStyle.szFirstName) << U16toU8(cachedView.plr.PCStyle.szLastName) << " has left!" << std::endl; + std::cout << U16toU8(cachedView.plr->PCStyle.szFirstName) << U16toU8(cachedView.plr->PCStyle.szLastName) << " has left!" << std::endl; std::cout << players.size() << " players" << std::endl; } void PlayerManager::updatePlayerPosition(CNSocket* sock, int X, int Y, int Z) { - players[sock].plr.x = X; - players[sock].plr.y = Y; - players[sock].plr.z = Z; + players[sock].plr->x = X; + players[sock].plr->y = Y; + players[sock].plr->z = Z; std::vector noView; std::vector yesView; @@ -78,8 +82,8 @@ void PlayerManager::updatePlayerPosition(CNSocket* sock, int X, int Y, int Z) { if (pair.first == sock) continue; // ignore our own connection - int diffX = abs(pair.second.plr.x - X); // the map is like a grid, X and Y are your position on the map, Z is the height. very different from other games... - int diffY = abs(pair.second.plr.y - Y); + int diffX = abs(pair.second.plr->x - X); // the map is like a grid, X and Y are your position on the map, Z is the height. very different from other games... + int diffY = abs(pair.second.plr->y - Y); if (diffX < settings::VIEWDISTANCE && diffY < settings::VIEWDISTANCE) { yesView.push_back(pair.first); @@ -96,9 +100,9 @@ void PlayerManager::updatePlayerPosition(CNSocket* sock, int X, int Y, int Z) { if (std::find(noView.begin(), noView.end(), otherSock) != noView.end()) { // sock shouldn't be visible, send PC_EXIT packet - exitPacket.iID = players[sock].plr.iID; + exitPacket.iID = players[sock].plr->iID; otherSock->sendPacket((void*)&exitPacket, P_FE2CL_PC_EXIT, sizeof(sP_FE2CL_PC_EXIT)); - exitPacket.iID = players[otherSock].plr.iID; + exitPacket.iID = players[otherSock].plr->iID; sock->sendPacket((void*)&exitPacket, P_FE2CL_PC_EXIT, sizeof(sP_FE2CL_PC_EXIT)); // remove them from the viewable list @@ -115,34 +119,34 @@ void PlayerManager::updatePlayerPosition(CNSocket* sock, int X, int Y, int Z) { if (std::find(players[sock].viewable.begin(), players[sock].viewable.end(), otherSock) == players[sock].viewable.end()) { // this needs to be added to the viewable players, send PC_ENTER - Player otherPlr = players[otherSock].plr; - Player plr = players[sock].plr; + Player *otherPlr = players[otherSock].plr; + Player *plr = players[sock].plr; - newPlayer.PCAppearanceData.iID = plr.iID; - newPlayer.PCAppearanceData.iHP = plr.HP; - newPlayer.PCAppearanceData.iLv = plr.level; - newPlayer.PCAppearanceData.iX = plr.x; - newPlayer.PCAppearanceData.iY = plr.y; - newPlayer.PCAppearanceData.iZ = plr.z; - newPlayer.PCAppearanceData.iAngle = plr.angle; - newPlayer.PCAppearanceData.PCStyle = plr.PCStyle; - newPlayer.PCAppearanceData.Nano = plr.Nanos[plr.activeNano]; - newPlayer.PCAppearanceData.iPCState = plr.iPCState; - memcpy(newPlayer.PCAppearanceData.ItemEquip, plr.Equip, sizeof(sItemBase) * AEQUIP_COUNT); + newPlayer.PCAppearanceData.iID = plr->iID; + newPlayer.PCAppearanceData.iHP = plr->HP; + newPlayer.PCAppearanceData.iLv = plr->level; + newPlayer.PCAppearanceData.iX = plr->x; + newPlayer.PCAppearanceData.iY = plr->y; + newPlayer.PCAppearanceData.iZ = plr->z; + newPlayer.PCAppearanceData.iAngle = plr->angle; + newPlayer.PCAppearanceData.PCStyle = plr->PCStyle; + newPlayer.PCAppearanceData.Nano = plr->Nanos[plr->activeNano]; + newPlayer.PCAppearanceData.iPCState = plr->iPCState; + memcpy(newPlayer.PCAppearanceData.ItemEquip, plr->Equip, sizeof(sItemBase) * AEQUIP_COUNT); otherSock->sendPacket((void*)&newPlayer, P_FE2CL_PC_NEW, sizeof(sP_FE2CL_PC_NEW)); - newPlayer.PCAppearanceData.iID = otherPlr.iID; - newPlayer.PCAppearanceData.iHP = otherPlr.HP; - newPlayer.PCAppearanceData.iLv = otherPlr.level; - newPlayer.PCAppearanceData.iX = otherPlr.x; - newPlayer.PCAppearanceData.iY = otherPlr.y; - newPlayer.PCAppearanceData.iZ = otherPlr.z; - newPlayer.PCAppearanceData.iAngle = otherPlr.angle; - newPlayer.PCAppearanceData.PCStyle = otherPlr.PCStyle; - newPlayer.PCAppearanceData.Nano = otherPlr.Nanos[otherPlr.activeNano]; - newPlayer.PCAppearanceData.iPCState = otherPlr.iPCState; - memcpy(newPlayer.PCAppearanceData.ItemEquip, otherPlr.Equip, sizeof(sItemBase) * AEQUIP_COUNT); + newPlayer.PCAppearanceData.iID = otherPlr->iID; + newPlayer.PCAppearanceData.iHP = otherPlr->HP; + newPlayer.PCAppearanceData.iLv = otherPlr->level; + newPlayer.PCAppearanceData.iX = otherPlr->x; + newPlayer.PCAppearanceData.iY = otherPlr->y; + newPlayer.PCAppearanceData.iZ = otherPlr->z; + newPlayer.PCAppearanceData.iAngle = otherPlr->angle; + newPlayer.PCAppearanceData.PCStyle = otherPlr->PCStyle; + newPlayer.PCAppearanceData.Nano = otherPlr->Nanos[otherPlr->activeNano]; + newPlayer.PCAppearanceData.iPCState = otherPlr->iPCState; + memcpy(newPlayer.PCAppearanceData.ItemEquip, otherPlr->Equip, sizeof(sItemBase) * AEQUIP_COUNT); sock->sendPacket((void*)&newPlayer, P_FE2CL_PC_NEW, sizeof(sP_FE2CL_PC_NEW)); @@ -158,8 +162,8 @@ std::list PlayerManager::getNearbyPlayers(int x, int y, int dist) { std::list plrs; for (auto pair : players) { - int diffX = abs(pair.second.plr.x - x); - int diffY = abs(pair.second.plr.x - x); + int diffX = abs(pair.second.plr->x - x); + int diffY = abs(pair.second.plr->x - x); if (diffX < dist && diffY < dist) plrs.push_back(pair.first); @@ -181,13 +185,13 @@ void PlayerManager::enterPlayer(CNSocket* sock, CNPacketData* data) { DEBUGLOG( std::cout << "P_CL2FE_REQ_PC_ENTER:" << std::endl; - std::cout << "\tID: " << U16toU8(enter->szID) << std::endl; - std::cout << "\tSerial: " << enter->iEnterSerialKey << std::endl; - std::cout << "\tTemp: " << enter->iTempValue << std::endl; - std::cout << "\tPC_UID: " << plr.PCStyle.iPC_UID << std::endl; + std::cout << "\tID: " << U16toU8(enter->szID) << std::endl; + std::cout << "\tSerial: " << enter->iEnterSerialKey << std::endl; + std::cout << "\tTemp: " << enter->iTempValue << std::endl; + std::cout << "\tPC_UID: " << plr.PCStyle.iPC_UID << std::endl; ) - response.iID = rand(); + response.iID = rand(); response.uiSvrTime = getTime(); response.PCLoadData2CL.iUserLevel = 1; response.PCLoadData2CL.iHP = 3625; //TODO: Check player levelupdata and get this right @@ -251,10 +255,10 @@ void PlayerManager::loadPlayer(CNSocket* sock, CNPacketData* data) { DEBUGLOG( std::cout << "P_CL2FE_REQ_PC_LOADING_COMPLETE:" << std::endl; - std::cout << "\tPC_ID: " << complete->iPC_ID << std::endl; + std::cout << "\tPC_ID: " << complete->iPC_ID << std::endl; ) - response.iPC_ID = complete->iPC_ID; + response.iPC_ID = complete->iPC_ID; sock->sendPacket((void*)&response, P_FE2CL_REP_PC_LOADING_COMPLETE_SUCC, sizeof(sP_FE2CL_REP_PC_LOADING_COMPLETE_SUCC)); } @@ -266,12 +270,12 @@ void PlayerManager::movePlayer(CNSocket* sock, CNPacketData* data) { sP_CL2FE_REQ_PC_MOVE* moveData = (sP_CL2FE_REQ_PC_MOVE*)data->buf; updatePlayerPosition(sock, moveData->iX, moveData->iY, moveData->iZ); - players[sock].plr.angle = moveData->iAngle; + players[sock].plr->angle = moveData->iAngle; uint64_t tm = getTime(); INITSTRUCT(sP_FE2CL_PC_MOVE, moveResponse); - moveResponse.iID = players[sock].plr.iID; + moveResponse.iID = players[sock].plr->iID; moveResponse.cKeyValue = moveData->cKeyValue; moveResponse.iX = moveData->iX; @@ -302,7 +306,7 @@ void PlayerManager::stopPlayer(CNSocket* sock, CNPacketData* data) { INITSTRUCT(sP_FE2CL_PC_STOP, stopResponse); - stopResponse.iID = players[sock].plr.iID; + stopResponse.iID = players[sock].plr->iID; stopResponse.iX = stopData->iX; stopResponse.iY = stopData->iY; @@ -327,7 +331,7 @@ void PlayerManager::jumpPlayer(CNSocket* sock, CNPacketData* data) { INITSTRUCT(sP_FE2CL_PC_JUMP, jumpResponse); - jumpResponse.iID = players[sock].plr.iID; + jumpResponse.iID = players[sock].plr->iID; jumpResponse.cKeyValue = jumpData->cKeyValue; jumpResponse.iX = jumpData->iX; @@ -358,7 +362,7 @@ void PlayerManager::jumppadPlayer(CNSocket* sock, CNPacketData* data) { INITSTRUCT(sP_FE2CL_PC_JUMPPAD, jumppadResponse); - jumppadResponse.iPC_ID = players[sock].plr.iID; + jumppadResponse.iPC_ID = players[sock].plr->iID; jumppadResponse.cKeyValue = jumppadData->cKeyValue; jumppadResponse.iX = jumppadData->iX; @@ -387,7 +391,7 @@ void PlayerManager::launchPlayer(CNSocket* sock, CNPacketData* data) { INITSTRUCT(sP_FE2CL_PC_LAUNCHER, launchResponse); - launchResponse.iPC_ID = players[sock].plr.iID; + launchResponse.iPC_ID = players[sock].plr->iID; launchResponse.iX = launchData->iX; launchResponse.iY = launchData->iY; @@ -417,7 +421,7 @@ void PlayerManager::ziplinePlayer(CNSocket* sock, CNPacketData* data) { INITSTRUCT(sP_FE2CL_PC_ZIPLINE, ziplineResponse); - ziplineResponse.iPC_ID = players[sock].plr.iID; + ziplineResponse.iPC_ID = players[sock].plr->iID; ziplineResponse.iCliTime = ziplineData->iCliTime; ziplineResponse.iSvrTime = tm; ziplineResponse.iX = ziplineData->iX; @@ -454,7 +458,7 @@ void PlayerManager::movePlatformPlayer(CNSocket* sock, CNPacketData* data) { INITSTRUCT(sP_FE2CL_PC_MOVEPLATFORM, platResponse); - platResponse.iPC_ID = players[sock].plr.iID; + platResponse.iPC_ID = players[sock].plr->iID; platResponse.iCliTime = platformData->iCliTime; platResponse.iSvrTime = tm; platResponse.iX = platformData->iX; @@ -488,7 +492,7 @@ void PlayerManager::moveSlopePlayer(CNSocket* sock, CNPacketData* data) { INITSTRUCT(sP_FE2CL_PC_SLOPE, slopeResponse); - slopeResponse.iPC_ID = players[sock].plr.iID; + slopeResponse.iPC_ID = players[sock].plr->iID; slopeResponse.iCliTime = slopeData->iCliTime; slopeResponse.iSvrTime = tm; slopeResponse.iX = slopeData->iX; @@ -516,12 +520,12 @@ void PlayerManager::gotoPlayer(CNSocket* sock, CNPacketData* data) { DEBUGLOG( std::cout << "P_CL2FE_REQ_PC_GOTO:" << std::endl; - std::cout << "\tX: " << gotoData->iToX << std::endl; - std::cout << "\tY: " << gotoData->iToY << std::endl; - std::cout << "\tZ: " << gotoData->iToZ << std::endl; + std::cout << "\tX: " << gotoData->iToX << std::endl; + std::cout << "\tY: " << gotoData->iToY << std::endl; + std::cout << "\tZ: " << gotoData->iToZ << std::endl; ) - response.iX = gotoData->iToX; + response.iX = gotoData->iToX; response.iY = gotoData->iToY; response.iZ = gotoData->iToZ; @@ -537,12 +541,12 @@ void PlayerManager::setSpecialPlayer(CNSocket* sock, CNPacketData* data) { DEBUGLOG( std::cout << "P_CL2FE_GM_REQ_PC_SET_VALUE:" << std::endl; - std::cout << "\tPC_ID: " << setData->iPC_ID << std::endl; - std::cout << "\tSetValueType: " << setData->iSetValueType << std::endl; - std::cout << "\tSetValue: " << setData->iSetValue << std::endl; + std::cout << "\tPC_ID: " << setData->iPC_ID << std::endl; + std::cout << "\tSetValueType: " << setData->iSetValueType << std::endl; + std::cout << "\tSetValue: " << setData->iSetValue << std::endl; ) - response.iPC_ID = setData->iPC_ID; + response.iPC_ID = setData->iPC_ID; response.iSetValue = setData->iSetValue; response.iSetValueType = setData->iSetValueType; @@ -570,23 +574,22 @@ void PlayerManager::revivePlayer(CNSocket* sock, CNPacketData* data) { if (data->size != sizeof(sP_CL2FE_REQ_PC_REGEN)) return; - Player plr = PlayerManager::getPlayer(sock); + Player *plr = PlayerManager::getPlayer(sock); // players respawn at same spot they died at for now... sP_CL2FE_REQ_PC_REGEN* reviveData = (sP_CL2FE_REQ_PC_REGEN*)data->buf; INITSTRUCT(sP_FE2CL_REP_PC_REGEN_SUCC, response); response.bMoveLocation = reviveData->eIL; response.PCRegenData.iMapNum = reviveData->iIndex; - response.PCRegenData.iHP = 1000 * plr.level; - response.PCRegenData.iX = plr.x; - response.PCRegenData.iY = plr.y; - response.PCRegenData.iZ = plr.z; + response.PCRegenData.iHP = 1000 * plr->level; + response.PCRegenData.iX = plr->x; + response.PCRegenData.iY = plr->y; + response.PCRegenData.iZ = plr->z; sock->sendPacket((void*)&response, P_FE2CL_REP_PC_REGEN_SUCC, sizeof(sP_FE2CL_REP_PC_REGEN_SUCC)); } void PlayerManager::enterPlayerVehicle(CNSocket* sock, CNPacketData* data) { - sP_CL2FE_REQ_PC_VEHICLE_ON* vehicleData = (sP_CL2FE_REQ_PC_VEHICLE_ON*)data->buf; INITSTRUCT(sP_FE2CL_PC_VEHICLE_ON_SUCC, response); PlayerView plrv = PlayerManager::players[sock]; @@ -598,14 +601,12 @@ void PlayerManager::enterPlayerVehicle(CNSocket* sock, CNPacketData* data) { otherSock->sendPacket((void*)&pkt, P_FE2CL_PC_EQUIP_CHANGE, sizeof(sP_FE2CL_PC_EQUIP_CHANGE)); } - plrv.plr.iPCState = 8; - updatePlayer(sock, plrv.plr); + plrv.plr->iPCState = 8; sock->sendPacket((void*)&response, P_FE2CL_PC_VEHICLE_ON_SUCC, sizeof(sP_FE2CL_PC_VEHICLE_ON_SUCC)); } void PlayerManager::exitPlayerVehicle(CNSocket* sock, CNPacketData* data) { - sP_CL2FE_REQ_PC_VEHICLE_OFF* vehicleData = (sP_CL2FE_REQ_PC_VEHICLE_OFF*)data->buf; INITSTRUCT(sP_FE2CL_PC_VEHICLE_OFF_SUCC, response); PlayerView plrv = PlayerManager::players[sock]; @@ -617,8 +618,7 @@ void PlayerManager::exitPlayerVehicle(CNSocket* sock, CNPacketData* data) { otherSock->sendPacket((void*)&pkt, P_FE2CL_PC_EQUIP_CHANGE, sizeof(sP_FE2CL_PC_EQUIP_CHANGE)); } - plrv.plr.iPCState = 0; - updatePlayer(sock, plrv.plr); + plrv.plr->iPCState = 0; sock->sendPacket((void*)&response, P_FE2CL_PC_VEHICLE_OFF_SUCC, sizeof(sP_FE2CL_PC_VEHICLE_OFF_SUCC)); } @@ -633,14 +633,7 @@ void PlayerManager::setSpecialSwitchPlayer(CNSocket* sock, CNPacketData* data) { } #pragma region Helper methods -Player PlayerManager::getPlayer(CNSocket* key) { +Player *PlayerManager::getPlayer(CNSocket* key) { return players[key].plr; } - -void PlayerManager::updatePlayer(CNSocket* key, Player plr) { - PlayerView plrv = players[key]; - plrv.plr = plr; - - players[key] = plrv; -} -#pragma endregion \ No newline at end of file +#pragma endregion diff --git a/src/PlayerManager.hpp b/src/PlayerManager.hpp index 5a90ed8..f719b6a 100644 --- a/src/PlayerManager.hpp +++ b/src/PlayerManager.hpp @@ -11,7 +11,7 @@ struct PlayerView { std::list viewable; std::list viewableNPCs; - Player plr; + Player *plr; uint64_t lastHeartbeat; }; @@ -22,9 +22,8 @@ namespace PlayerManager { void addPlayer(CNSocket* key, Player plr); void removePlayer(CNSocket* key); - Player getPlayer(CNSocket* key); + Player *getPlayer(CNSocket* key); - void updatePlayer(CNSocket* key, Player plr); void updatePlayerPosition(CNSocket* sock, int X, int Y, int Z); std::list getNearbyPlayers(int X, int Y, int dist);