mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-12-23 03:40:05 +00:00
Dynamically allocate the Player struct in PlayerView.
This way we're not always passing it around by value. Note that the Player structs in CNSharedData are still pass-by-reference. Will probably change this later.
This commit is contained in:
parent
c5dacb4958
commit
14bc368073
@ -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() {
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,8 +58,8 @@ void NPCManager::updatePlayerNPCS(CNSocket* sock, PlayerView& view) {
|
||||
std::list<int32_t> 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);
|
||||
|
@ -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 <nanoId>
|
||||
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
|
||||
|
@ -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<CNSocket*>();
|
||||
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<CNSocket*> noView;
|
||||
std::vector<CNSocket*> 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<CNSocket*> PlayerManager::getNearbyPlayers(int x, int y, int dist) {
|
||||
std::list<CNSocket*> 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);
|
||||
@ -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;
|
||||
@ -570,17 +574,17 @@ 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));
|
||||
}
|
||||
@ -598,8 +602,7 @@ 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));
|
||||
}
|
||||
@ -617,8 +620,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 +635,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
|
||||
#pragma endregion
|
||||
|
@ -11,7 +11,7 @@
|
||||
struct PlayerView {
|
||||
std::list<CNSocket*> viewable;
|
||||
std::list<int32_t> 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<CNSocket*> getNearbyPlayers(int X, int Y, int dist);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user