mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-05 06:50:04 +00:00
Merge pull request #35 from dongresource/work1
Avoid excessive copying of large Player struct
This commit is contained in:
commit
d025b611a1
9
.vimrc
Normal file
9
.vimrc
Normal file
@ -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
|
@ -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:
|
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 `/speed` of around 2400 or 3000 is nice.
|
||||||
* A `/jump` of about 50 will send you soaring
|
* 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.
|
* [This map](res/dong_number_map.png) (credit to Danny O) is useful for `/warp` coordinates.
|
||||||
|
@ -16,7 +16,6 @@ randomcharacters=true
|
|||||||
# Shard Server configuration
|
# Shard Server configuration
|
||||||
[shard]
|
[shard]
|
||||||
port=8002
|
port=8002
|
||||||
# you'll want to change this one
|
|
||||||
ip=127.0.0.1
|
ip=127.0.0.1
|
||||||
# distance at which other players and NPCs become visible
|
# distance at which other players and NPCs become visible
|
||||||
view=20000
|
view=20000
|
||||||
|
@ -275,7 +275,6 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
|
|||||||
CNSharedData::setPlayer(resp.iEnterSerialKey, loginSessions[sock].characters[loginSessions[sock].selectedChar]);
|
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->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;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -48,11 +48,15 @@ void CNShardServer::newConnection(CNSocket* cns) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CNShardServer::killConnection(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
|
// remove from CNSharedData
|
||||||
Player cachedPlr = PlayerManager::getPlayer(cns);
|
int64_t key = PlayerManager::getPlayer(cns)->SerialKey;
|
||||||
PlayerManager::removePlayer(cns);
|
PlayerManager::removePlayer(cns);
|
||||||
|
|
||||||
CNSharedData::erasePlayer(cachedPlr.SerialKey);
|
CNSharedData::erasePlayer(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CNShardServer::onStep() {
|
void CNShardServer::onStep() {
|
||||||
|
@ -18,7 +18,7 @@ void ChatManager::chatHandler(CNSocket* sock, CNPacketData* data) {
|
|||||||
// send to client
|
// send to client
|
||||||
INITSTRUCT(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, resp);
|
INITSTRUCT(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, resp);
|
||||||
memcpy(resp.szFreeChat, chat->szFreeChat, sizeof(chat->szFreeChat));
|
memcpy(resp.szFreeChat, chat->szFreeChat, sizeof(chat->szFreeChat));
|
||||||
resp.iPC_ID = plr.plr.iID;
|
resp.iPC_ID = plr.plr->iID;
|
||||||
resp.iEmoteCode = chat->iEmoteCode;
|
resp.iEmoteCode = chat->iEmoteCode;
|
||||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC));
|
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
|
// send to client
|
||||||
INITSTRUCT(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, resp);
|
INITSTRUCT(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, resp);
|
||||||
memcpy(resp.szFreeChat, chat->szFreeChat, sizeof(chat->szFreeChat));
|
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;
|
resp.iEmoteCode = chat->iEmoteCode;
|
||||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC));
|
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
|
// send to client
|
||||||
INITSTRUCT(sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT, resp);
|
INITSTRUCT(sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT, resp);
|
||||||
resp.iEmoteCode = emote->iEmoteCode;
|
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));
|
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)
|
// 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
|
// this packet should never happen, tell the client to do nothing and do nothing ourself
|
||||||
resp.eTo = itemmove->eFrom;
|
resp.eTo = itemmove->eFrom;
|
||||||
resp.iToSlotNum = itemmove->iFromSlotNum;
|
resp.iToSlotNum = itemmove->iFromSlotNum;
|
||||||
resp.ToSlotItem = plr.plr.Equip[itemmove->iToSlotNum];
|
resp.ToSlotItem = plr.plr->Equip[itemmove->iToSlotNum];
|
||||||
resp.eFrom = itemmove->eTo;
|
resp.eFrom = itemmove->eTo;
|
||||||
resp.iFromSlotNum = itemmove->iToSlotNum;
|
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));
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_ITEM_DELETE_SUCC, sizeof(sP_FE2CL_REP_PC_ITEM_DELETE_SUCC));
|
||||||
return;
|
return;
|
||||||
@ -41,31 +41,31 @@ void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) {
|
|||||||
// eFrom 0 means from equip
|
// eFrom 0 means from equip
|
||||||
if (itemmove->eFrom == 0) {
|
if (itemmove->eFrom == 0) {
|
||||||
// unequiping an item
|
// unequiping an item
|
||||||
fromItem = plr.plr.Equip[itemmove->iFromSlotNum];
|
fromItem = plr.plr->Equip[itemmove->iFromSlotNum];
|
||||||
} else {
|
} else {
|
||||||
fromItem = plr.plr.Inven[itemmove->iFromSlotNum];
|
fromItem = plr.plr->Inven[itemmove->iFromSlotNum];
|
||||||
}
|
}
|
||||||
|
|
||||||
// eTo 0 means to equip
|
// eTo 0 means to equip
|
||||||
if (itemmove->eTo == 0) {
|
if (itemmove->eTo == 0) {
|
||||||
// equiping an item
|
// equiping an item
|
||||||
toItem = plr.plr.Equip[itemmove->iToSlotNum];
|
toItem = plr.plr->Equip[itemmove->iToSlotNum];
|
||||||
plr.plr.Equip[itemmove->iToSlotNum] = fromItem;
|
plr.plr->Equip[itemmove->iToSlotNum] = fromItem;
|
||||||
} else {
|
} else {
|
||||||
toItem = plr.plr.Inven[itemmove->iToSlotNum];
|
toItem = plr.plr->Inven[itemmove->iToSlotNum];
|
||||||
plr.plr.Inven[itemmove->iToSlotNum] = fromItem;
|
plr.plr->Inven[itemmove->iToSlotNum] = fromItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (itemmove->eFrom == 0) {
|
if (itemmove->eFrom == 0) {
|
||||||
plr.plr.Equip[itemmove->iFromSlotNum] = toItem;
|
plr.plr->Equip[itemmove->iFromSlotNum] = toItem;
|
||||||
} else {
|
} else {
|
||||||
plr.plr.Inven[itemmove->iFromSlotNum] = toItem;
|
plr.plr->Inven[itemmove->iFromSlotNum] = toItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (itemmove->eFrom == 0 || itemmove->eTo == 0) {
|
if (itemmove->eFrom == 0 || itemmove->eTo == 0) {
|
||||||
INITSTRUCT(sP_FE2CL_PC_EQUIP_CHANGE, equipChange);
|
INITSTRUCT(sP_FE2CL_PC_EQUIP_CHANGE, equipChange);
|
||||||
|
|
||||||
equipChange.iPC_ID = plr.plr.iID;
|
equipChange.iPC_ID = plr.plr->iID;
|
||||||
if (itemmove->eFrom == 0) {
|
if (itemmove->eFrom == 0) {
|
||||||
equipChange.iEquipSlotNum = itemmove->iFromSlotNum;
|
equipChange.iEquipSlotNum = itemmove->iFromSlotNum;
|
||||||
equipChange.EquipSlotItem = toItem;
|
equipChange.EquipSlotItem = toItem;
|
||||||
@ -103,9 +103,9 @@ void ItemManager::itemDeleteHandler(CNSocket* sock, CNPacketData* data) {
|
|||||||
resp.iSlotNum = itemdel->iSlotNum;
|
resp.iSlotNum = itemdel->iSlotNum;
|
||||||
|
|
||||||
// so, im not sure what this eIL thing does since you always delete items in inventory and not equips
|
// 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].iID = 0;
|
||||||
plr.plr.Inven[itemdel->iSlotNum].iType = 0;
|
plr.plr->Inven[itemdel->iSlotNum].iType = 0;
|
||||||
plr.plr.Inven[itemdel->iSlotNum].iOpt = 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));
|
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];
|
PlayerView& plr = PlayerManager::players[sock];
|
||||||
|
|
||||||
// Commented and disabled for future use
|
// Commented and disabled for future use
|
||||||
//if (!plr.plr.IsGM) {
|
//if (!plr.plr->IsGM) {
|
||||||
// TODO: send fail packet
|
// TODO: send fail packet
|
||||||
// return;
|
// return;
|
||||||
//}
|
//}
|
||||||
@ -134,16 +134,16 @@ void ItemManager::itemGMGiveHandler(CNSocket* sock, CNPacketData* data) {
|
|||||||
resp.iSlotNum = itemreq->iSlotNum;
|
resp.iSlotNum = itemreq->iSlotNum;
|
||||||
resp.Item = itemreq->Item;
|
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));
|
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
|
// 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;
|
//sP_FE2CL_REP_PC_CHANGE_LEVEL resp2;
|
||||||
|
|
||||||
//resp2.iPC_ID = plr.plr.iID;
|
//resp2.iPC_ID = plr.plr->iID;
|
||||||
//resp2.iPC_Level = 36;
|
//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));
|
||||||
|
@ -58,8 +58,8 @@ void NPCManager::updatePlayerNPCS(CNSocket* sock, PlayerView& view) {
|
|||||||
std::list<int32_t> noView;
|
std::list<int32_t> noView;
|
||||||
|
|
||||||
for (auto& pair : NPCs) {
|
for (auto& pair : NPCs) {
|
||||||
int diffX = abs(view.plr.x - pair.second.appearanceData.iX);
|
int diffX = abs(view.plr->x - pair.second.appearanceData.iX);
|
||||||
int diffY = abs(view.plr.y - pair.second.appearanceData.iY);
|
int diffY = abs(view.plr->y - pair.second.appearanceData.iY);
|
||||||
|
|
||||||
if (diffX < settings::VIEWDISTANCE && diffY < settings::VIEWDISTANCE) {
|
if (diffX < settings::VIEWDISTANCE && diffY < settings::VIEWDISTANCE) {
|
||||||
yesView.push_back(pair.first);
|
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;
|
sP_CL2FE_REQ_NANO_EQUIP* nano = (sP_CL2FE_REQ_NANO_EQUIP*)data->buf;
|
||||||
INITSTRUCT(sP_FE2CL_REP_NANO_EQUIP_SUCC, resp);
|
INITSTRUCT(sP_FE2CL_REP_NANO_EQUIP_SUCC, resp);
|
||||||
Player plr = PlayerManager::getPlayer(sock);
|
Player *plr = PlayerManager::getPlayer(sock);
|
||||||
|
|
||||||
if (nano->iNanoSlotNum > 2)
|
if (nano->iNanoSlotNum > 2)
|
||||||
return;
|
return;
|
||||||
@ -28,8 +28,7 @@ void NanoManager::nanoEquipHandler(CNSocket* sock, CNPacketData* data) {
|
|||||||
|
|
||||||
|
|
||||||
// Update player
|
// Update player
|
||||||
plr.equippedNanos[nano->iNanoSlotNum] = nano->iNanoID;
|
plr->equippedNanos[nano->iNanoSlotNum] = nano->iNanoID;
|
||||||
PlayerManager::updatePlayer(sock, plr);
|
|
||||||
|
|
||||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_NANO_EQUIP_SUCC, sizeof(sP_FE2CL_REP_NANO_EQUIP_SUCC));
|
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;
|
sP_CL2FE_REQ_NANO_UNEQUIP* nano = (sP_CL2FE_REQ_NANO_UNEQUIP*)data->buf;
|
||||||
INITSTRUCT(sP_FE2CL_REP_NANO_UNEQUIP_SUCC, resp);
|
INITSTRUCT(sP_FE2CL_REP_NANO_UNEQUIP_SUCC, resp);
|
||||||
Player plr = PlayerManager::getPlayer(sock);
|
Player *plr = PlayerManager::getPlayer(sock);
|
||||||
|
|
||||||
if (nano->iNanoSlotNum > 2)
|
if (nano->iNanoSlotNum > 2)
|
||||||
return;
|
return;
|
||||||
@ -48,8 +47,7 @@ void NanoManager::nanoUnEquipHandler(CNSocket* sock, CNPacketData* data) {
|
|||||||
resp.iNanoSlotNum = nano->iNanoSlotNum;
|
resp.iNanoSlotNum = nano->iNanoSlotNum;
|
||||||
|
|
||||||
// update player
|
// update player
|
||||||
plr.equippedNanos[nano->iNanoSlotNum] = 0;
|
plr->equippedNanos[nano->iNanoSlotNum] = 0;
|
||||||
PlayerManager::updatePlayer(sock, plr);
|
|
||||||
|
|
||||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_NANO_UNEQUIP_SUCC, sizeof(sP_FE2CL_REP_NANO_UNEQUIP_SUCC));
|
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>
|
// Cmd: /nano <nanoId>
|
||||||
sP_CL2FE_REQ_PC_GIVE_NANO* nano = (sP_CL2FE_REQ_PC_GIVE_NANO*)data->buf;
|
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
|
// Add nano to player
|
||||||
addNano(sock, nano->iNanoID, 0);
|
addNano(sock, nano->iNanoID, 0);
|
||||||
|
|
||||||
DEBUGLOG(
|
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
|
return; // malformed packet
|
||||||
|
|
||||||
sP_CL2FE_REQ_NANO_ACTIVE* pkt = (sP_CL2FE_REQ_NANO_ACTIVE*)data->buf;
|
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
|
// Send to client
|
||||||
INITSTRUCT(sP_FE2CL_REP_NANO_ACTIVE_SUCC, resp);
|
INITSTRUCT(sP_FE2CL_REP_NANO_ACTIVE_SUCC, resp);
|
||||||
@ -85,28 +83,27 @@ void NanoManager::nanoSummonHandler(CNSocket* sock, CNPacketData* data) {
|
|||||||
if (pkt->iNanoSlotNum > 2)
|
if (pkt->iNanoSlotNum > 2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int nanoId = plr.equippedNanos[pkt->iNanoSlotNum];
|
int nanoId = plr->equippedNanos[pkt->iNanoSlotNum];
|
||||||
|
|
||||||
if (nanoId > 36)
|
if (nanoId > 36)
|
||||||
return; // sanity check
|
return; // sanity check
|
||||||
|
|
||||||
sNano nano = plr.Nanos[nanoId];
|
sNano nano = plr->Nanos[nanoId];
|
||||||
|
|
||||||
// Send to other players
|
// Send to other players
|
||||||
INITSTRUCT(sP_FE2CL_NANO_ACTIVE, pkt1);
|
INITSTRUCT(sP_FE2CL_NANO_ACTIVE, pkt1);
|
||||||
|
|
||||||
pkt1.iPC_ID = plr.iID;
|
pkt1.iPC_ID = plr->iID;
|
||||||
pkt1.Nano = nano;
|
pkt1.Nano = nano;
|
||||||
|
|
||||||
for (CNSocket* s : PlayerManager::players[sock].viewable)
|
for (CNSocket* s : PlayerManager::players[sock].viewable)
|
||||||
s->sendPacket((void*)&pkt1, P_FE2CL_NANO_ACTIVE, sizeof(sP_FE2CL_NANO_ACTIVE));
|
s->sendPacket((void*)&pkt1, P_FE2CL_NANO_ACTIVE, sizeof(sP_FE2CL_NANO_ACTIVE));
|
||||||
|
|
||||||
// update player
|
// update player
|
||||||
plr.activeNano = nanoId;
|
plr->activeNano = nanoId;
|
||||||
PlayerManager::updatePlayer(sock, plr);
|
|
||||||
|
|
||||||
DEBUGLOG(
|
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
|
return; // malformed packet
|
||||||
|
|
||||||
sP_CL2FE_REQ_NANO_SKILL_USE* skill = (sP_CL2FE_REQ_NANO_SKILL_USE*)data->buf;
|
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
|
// Send to client
|
||||||
INITSTRUCT(sP_FE2CL_NANO_SKILL_USE_SUCC, resp);
|
INITSTRUCT(sP_FE2CL_NANO_SKILL_USE_SUCC, resp);
|
||||||
@ -124,10 +121,14 @@ void NanoManager::nanoSkillUseHandler(CNSocket* sock, CNPacketData* data) {
|
|||||||
resp.iArg3 = skill->iArg3;
|
resp.iArg3 = skill->iArg3;
|
||||||
resp.iBulletID = skill->iBulletID;
|
resp.iBulletID = skill->iBulletID;
|
||||||
resp.iTargetCnt = skill->iTargetCnt;
|
resp.iTargetCnt = skill->iTargetCnt;
|
||||||
resp.iPC_ID = plr.iID;
|
resp.iPC_ID = plr->iID;
|
||||||
resp.iNanoStamina = 150; // Hardcoded for now
|
resp.iNanoStamina = 150; // Hardcoded for now
|
||||||
|
|
||||||
sock->sendPacket((void*)&resp, P_FE2CL_NANO_SKILL_USE_SUCC, sizeof(sP_FE2CL_NANO_SKILL_USE_SUCC));
|
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) {
|
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)
|
if (nanoId > 36)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Player plr = PlayerManager::getPlayer(sock);
|
Player *plr = PlayerManager::getPlayer(sock);
|
||||||
|
|
||||||
// Send to client
|
// Send to client
|
||||||
INITSTRUCT(sP_FE2CL_REP_PC_NANO_CREATE_SUCC, resp);
|
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));
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_NANO_CREATE_SUCC, sizeof(sP_FE2CL_REP_PC_NANO_CREATE_SUCC));
|
||||||
|
|
||||||
// Update player
|
// Update player
|
||||||
plr.Nanos[nanoId] = resp.Nano;
|
plr->Nanos[nanoId] = resp.Nano;
|
||||||
PlayerManager::updatePlayer(sock, plr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NanoManager::setNanoSkill(CNSocket* sock, int16_t nanoId, int16_t skillId) {
|
void NanoManager::setNanoSkill(CNSocket* sock, int16_t nanoId, int16_t skillId) {
|
||||||
if (nanoId > 36)
|
if (nanoId > 36)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Player plr = PlayerManager::getPlayer(sock);
|
Player *plr = PlayerManager::getPlayer(sock);
|
||||||
sNano nano = plr.Nanos[nanoId];
|
sNano nano = plr->Nanos[nanoId];
|
||||||
|
|
||||||
nano.iSkillID = skillId;
|
nano.iSkillID = skillId;
|
||||||
plr.Nanos[nanoId] = nano;
|
plr->Nanos[nanoId] = nano;
|
||||||
|
|
||||||
// Send to client
|
// Send to client
|
||||||
INITSTRUCT(sP_FE2CL_REP_NANO_TUNE_SUCC, resp);
|
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));
|
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(
|
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) {
|
void NanoManager::resetNanoSkill(CNSocket* sock, int16_t nanoId) {
|
||||||
if (nanoId > 36)
|
if (nanoId > 36)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Player plr = PlayerManager::getPlayer(sock);
|
Player *plr = PlayerManager::getPlayer(sock);
|
||||||
sNano nano = plr.Nanos[nanoId];
|
sNano nano = plr->Nanos[nanoId];
|
||||||
|
|
||||||
// 0 is reset
|
// 0 is reset
|
||||||
nano.iSkillID = 0;
|
nano.iSkillID = 0;
|
||||||
plr.Nanos[nanoId] = nano;
|
plr->Nanos[nanoId] = nano;
|
||||||
|
|
||||||
// Update the player
|
|
||||||
PlayerManager::updatePlayer(sock, plr);
|
|
||||||
}
|
}
|
||||||
#pragma endregion
|
#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_REGEN, PlayerManager::revivePlayer);
|
||||||
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_EXIT, PlayerManager::exitGame);
|
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_SPECIAL_STATE_SWITCH, PlayerManager::setSpecialSwitchPlayer);
|
||||||
|
|
||||||
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_VEHICLE_ON, PlayerManager::enterPlayerVehicle);
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_VEHICLE_ON, PlayerManager::enterPlayerVehicle);
|
||||||
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_VEHICLE_OFF, PlayerManager::exitPlayerVehicle);
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_VEHICLE_OFF, PlayerManager::exitPlayerVehicle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerManager::addPlayer(CNSocket* key, Player plr) {
|
void PlayerManager::addPlayer(CNSocket* key, Player plr) {
|
||||||
|
Player *p = new Player();
|
||||||
|
|
||||||
|
memcpy(p, &plr, sizeof(Player));
|
||||||
|
|
||||||
players[key] = PlayerView();
|
players[key] = PlayerView();
|
||||||
players[key].viewable = std::list<CNSocket*>();
|
players[key].viewable = std::list<CNSocket*>();
|
||||||
players[key].plr = plr;
|
players[key].plr = p;
|
||||||
players[key].lastHeartbeat = 0;
|
players[key].lastHeartbeat = 0;
|
||||||
|
|
||||||
std::cout << U16toU8(plr.PCStyle.szFirstName) << " " << U16toU8(plr.PCStyle.szLastName) << " has joined!" << std::endl;
|
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
|
// now sent PC_EXIT packet
|
||||||
sP_FE2CL_PC_EXIT exitPacket;
|
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));
|
otherSock->sendPacket((void*)&exitPacket, P_FE2CL_PC_EXIT, sizeof(sP_FE2CL_PC_EXIT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete cachedView.plr;
|
||||||
players.erase(key);
|
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;
|
std::cout << players.size() << " players" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerManager::updatePlayerPosition(CNSocket* sock, int X, int Y, int Z) {
|
void PlayerManager::updatePlayerPosition(CNSocket* sock, int X, int Y, int Z) {
|
||||||
players[sock].plr.x = X;
|
players[sock].plr->x = X;
|
||||||
players[sock].plr.y = Y;
|
players[sock].plr->y = Y;
|
||||||
players[sock].plr.z = Z;
|
players[sock].plr->z = Z;
|
||||||
|
|
||||||
std::vector<CNSocket*> noView;
|
std::vector<CNSocket*> noView;
|
||||||
std::vector<CNSocket*> yesView;
|
std::vector<CNSocket*> yesView;
|
||||||
@ -78,8 +82,8 @@ void PlayerManager::updatePlayerPosition(CNSocket* sock, int X, int Y, int Z) {
|
|||||||
if (pair.first == sock)
|
if (pair.first == sock)
|
||||||
continue; // ignore our own connection
|
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 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 diffY = abs(pair.second.plr->y - Y);
|
||||||
|
|
||||||
if (diffX < settings::VIEWDISTANCE && diffY < settings::VIEWDISTANCE) {
|
if (diffX < settings::VIEWDISTANCE && diffY < settings::VIEWDISTANCE) {
|
||||||
yesView.push_back(pair.first);
|
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()) {
|
if (std::find(noView.begin(), noView.end(), otherSock) != noView.end()) {
|
||||||
|
|
||||||
// sock shouldn't be visible, send PC_EXIT packet
|
// 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));
|
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));
|
sock->sendPacket((void*)&exitPacket, P_FE2CL_PC_EXIT, sizeof(sP_FE2CL_PC_EXIT));
|
||||||
|
|
||||||
// remove them from the viewable list
|
// 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()) {
|
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
|
// this needs to be added to the viewable players, send PC_ENTER
|
||||||
|
|
||||||
Player otherPlr = players[otherSock].plr;
|
Player *otherPlr = players[otherSock].plr;
|
||||||
Player plr = players[sock].plr;
|
Player *plr = players[sock].plr;
|
||||||
|
|
||||||
newPlayer.PCAppearanceData.iID = plr.iID;
|
newPlayer.PCAppearanceData.iID = plr->iID;
|
||||||
newPlayer.PCAppearanceData.iHP = plr.HP;
|
newPlayer.PCAppearanceData.iHP = plr->HP;
|
||||||
newPlayer.PCAppearanceData.iLv = plr.level;
|
newPlayer.PCAppearanceData.iLv = plr->level;
|
||||||
newPlayer.PCAppearanceData.iX = plr.x;
|
newPlayer.PCAppearanceData.iX = plr->x;
|
||||||
newPlayer.PCAppearanceData.iY = plr.y;
|
newPlayer.PCAppearanceData.iY = plr->y;
|
||||||
newPlayer.PCAppearanceData.iZ = plr.z;
|
newPlayer.PCAppearanceData.iZ = plr->z;
|
||||||
newPlayer.PCAppearanceData.iAngle = plr.angle;
|
newPlayer.PCAppearanceData.iAngle = plr->angle;
|
||||||
newPlayer.PCAppearanceData.PCStyle = plr.PCStyle;
|
newPlayer.PCAppearanceData.PCStyle = plr->PCStyle;
|
||||||
newPlayer.PCAppearanceData.Nano = plr.Nanos[plr.activeNano];
|
newPlayer.PCAppearanceData.Nano = plr->Nanos[plr->activeNano];
|
||||||
newPlayer.PCAppearanceData.iPCState = plr.iPCState;
|
newPlayer.PCAppearanceData.iPCState = plr->iPCState;
|
||||||
memcpy(newPlayer.PCAppearanceData.ItemEquip, plr.Equip, sizeof(sItemBase) * AEQUIP_COUNT);
|
memcpy(newPlayer.PCAppearanceData.ItemEquip, plr->Equip, sizeof(sItemBase) * AEQUIP_COUNT);
|
||||||
|
|
||||||
otherSock->sendPacket((void*)&newPlayer, P_FE2CL_PC_NEW, sizeof(sP_FE2CL_PC_NEW));
|
otherSock->sendPacket((void*)&newPlayer, P_FE2CL_PC_NEW, sizeof(sP_FE2CL_PC_NEW));
|
||||||
|
|
||||||
newPlayer.PCAppearanceData.iID = otherPlr.iID;
|
newPlayer.PCAppearanceData.iID = otherPlr->iID;
|
||||||
newPlayer.PCAppearanceData.iHP = otherPlr.HP;
|
newPlayer.PCAppearanceData.iHP = otherPlr->HP;
|
||||||
newPlayer.PCAppearanceData.iLv = otherPlr.level;
|
newPlayer.PCAppearanceData.iLv = otherPlr->level;
|
||||||
newPlayer.PCAppearanceData.iX = otherPlr.x;
|
newPlayer.PCAppearanceData.iX = otherPlr->x;
|
||||||
newPlayer.PCAppearanceData.iY = otherPlr.y;
|
newPlayer.PCAppearanceData.iY = otherPlr->y;
|
||||||
newPlayer.PCAppearanceData.iZ = otherPlr.z;
|
newPlayer.PCAppearanceData.iZ = otherPlr->z;
|
||||||
newPlayer.PCAppearanceData.iAngle = otherPlr.angle;
|
newPlayer.PCAppearanceData.iAngle = otherPlr->angle;
|
||||||
newPlayer.PCAppearanceData.PCStyle = otherPlr.PCStyle;
|
newPlayer.PCAppearanceData.PCStyle = otherPlr->PCStyle;
|
||||||
newPlayer.PCAppearanceData.Nano = otherPlr.Nanos[otherPlr.activeNano];
|
newPlayer.PCAppearanceData.Nano = otherPlr->Nanos[otherPlr->activeNano];
|
||||||
newPlayer.PCAppearanceData.iPCState = otherPlr.iPCState;
|
newPlayer.PCAppearanceData.iPCState = otherPlr->iPCState;
|
||||||
memcpy(newPlayer.PCAppearanceData.ItemEquip, otherPlr.Equip, sizeof(sItemBase) * AEQUIP_COUNT);
|
memcpy(newPlayer.PCAppearanceData.ItemEquip, otherPlr->Equip, sizeof(sItemBase) * AEQUIP_COUNT);
|
||||||
|
|
||||||
sock->sendPacket((void*)&newPlayer, P_FE2CL_PC_NEW, sizeof(sP_FE2CL_PC_NEW));
|
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;
|
std::list<CNSocket*> plrs;
|
||||||
|
|
||||||
for (auto pair : players) {
|
for (auto pair : players) {
|
||||||
int diffX = abs(pair.second.plr.x - x);
|
int diffX = abs(pair.second.plr->x - x);
|
||||||
int diffY = abs(pair.second.plr.x - x);
|
int diffY = abs(pair.second.plr->x - x);
|
||||||
|
|
||||||
if (diffX < dist && diffY < dist)
|
if (diffX < dist && diffY < dist)
|
||||||
plrs.push_back(pair.first);
|
plrs.push_back(pair.first);
|
||||||
@ -181,13 +185,13 @@ void PlayerManager::enterPlayer(CNSocket* sock, CNPacketData* data) {
|
|||||||
|
|
||||||
DEBUGLOG(
|
DEBUGLOG(
|
||||||
std::cout << "P_CL2FE_REQ_PC_ENTER:" << std::endl;
|
std::cout << "P_CL2FE_REQ_PC_ENTER:" << std::endl;
|
||||||
std::cout << "\tID: " << U16toU8(enter->szID) << std::endl;
|
std::cout << "\tID: " << U16toU8(enter->szID) << std::endl;
|
||||||
std::cout << "\tSerial: " << enter->iEnterSerialKey << std::endl;
|
std::cout << "\tSerial: " << enter->iEnterSerialKey << std::endl;
|
||||||
std::cout << "\tTemp: " << enter->iTempValue << std::endl;
|
std::cout << "\tTemp: " << enter->iTempValue << std::endl;
|
||||||
std::cout << "\tPC_UID: " << plr.PCStyle.iPC_UID << std::endl;
|
std::cout << "\tPC_UID: " << plr.PCStyle.iPC_UID << std::endl;
|
||||||
)
|
)
|
||||||
|
|
||||||
response.iID = rand();
|
response.iID = rand();
|
||||||
response.uiSvrTime = getTime();
|
response.uiSvrTime = getTime();
|
||||||
response.PCLoadData2CL.iUserLevel = 1;
|
response.PCLoadData2CL.iUserLevel = 1;
|
||||||
response.PCLoadData2CL.iHP = 3625; //TODO: Check player levelupdata and get this right
|
response.PCLoadData2CL.iHP = 3625; //TODO: Check player levelupdata and get this right
|
||||||
@ -251,10 +255,10 @@ void PlayerManager::loadPlayer(CNSocket* sock, CNPacketData* data) {
|
|||||||
|
|
||||||
DEBUGLOG(
|
DEBUGLOG(
|
||||||
std::cout << "P_CL2FE_REQ_PC_LOADING_COMPLETE:" << std::endl;
|
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));
|
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;
|
sP_CL2FE_REQ_PC_MOVE* moveData = (sP_CL2FE_REQ_PC_MOVE*)data->buf;
|
||||||
updatePlayerPosition(sock, moveData->iX, moveData->iY, moveData->iZ);
|
updatePlayerPosition(sock, moveData->iX, moveData->iY, moveData->iZ);
|
||||||
|
|
||||||
players[sock].plr.angle = moveData->iAngle;
|
players[sock].plr->angle = moveData->iAngle;
|
||||||
uint64_t tm = getTime();
|
uint64_t tm = getTime();
|
||||||
|
|
||||||
INITSTRUCT(sP_FE2CL_PC_MOVE, moveResponse);
|
INITSTRUCT(sP_FE2CL_PC_MOVE, moveResponse);
|
||||||
|
|
||||||
moveResponse.iID = players[sock].plr.iID;
|
moveResponse.iID = players[sock].plr->iID;
|
||||||
moveResponse.cKeyValue = moveData->cKeyValue;
|
moveResponse.cKeyValue = moveData->cKeyValue;
|
||||||
|
|
||||||
moveResponse.iX = moveData->iX;
|
moveResponse.iX = moveData->iX;
|
||||||
@ -302,7 +306,7 @@ void PlayerManager::stopPlayer(CNSocket* sock, CNPacketData* data) {
|
|||||||
|
|
||||||
INITSTRUCT(sP_FE2CL_PC_STOP, stopResponse);
|
INITSTRUCT(sP_FE2CL_PC_STOP, stopResponse);
|
||||||
|
|
||||||
stopResponse.iID = players[sock].plr.iID;
|
stopResponse.iID = players[sock].plr->iID;
|
||||||
|
|
||||||
stopResponse.iX = stopData->iX;
|
stopResponse.iX = stopData->iX;
|
||||||
stopResponse.iY = stopData->iY;
|
stopResponse.iY = stopData->iY;
|
||||||
@ -327,7 +331,7 @@ void PlayerManager::jumpPlayer(CNSocket* sock, CNPacketData* data) {
|
|||||||
|
|
||||||
INITSTRUCT(sP_FE2CL_PC_JUMP, jumpResponse);
|
INITSTRUCT(sP_FE2CL_PC_JUMP, jumpResponse);
|
||||||
|
|
||||||
jumpResponse.iID = players[sock].plr.iID;
|
jumpResponse.iID = players[sock].plr->iID;
|
||||||
jumpResponse.cKeyValue = jumpData->cKeyValue;
|
jumpResponse.cKeyValue = jumpData->cKeyValue;
|
||||||
|
|
||||||
jumpResponse.iX = jumpData->iX;
|
jumpResponse.iX = jumpData->iX;
|
||||||
@ -358,7 +362,7 @@ void PlayerManager::jumppadPlayer(CNSocket* sock, CNPacketData* data) {
|
|||||||
|
|
||||||
INITSTRUCT(sP_FE2CL_PC_JUMPPAD, jumppadResponse);
|
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.cKeyValue = jumppadData->cKeyValue;
|
||||||
|
|
||||||
jumppadResponse.iX = jumppadData->iX;
|
jumppadResponse.iX = jumppadData->iX;
|
||||||
@ -387,7 +391,7 @@ void PlayerManager::launchPlayer(CNSocket* sock, CNPacketData* data) {
|
|||||||
|
|
||||||
INITSTRUCT(sP_FE2CL_PC_LAUNCHER, launchResponse);
|
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.iX = launchData->iX;
|
||||||
launchResponse.iY = launchData->iY;
|
launchResponse.iY = launchData->iY;
|
||||||
@ -417,7 +421,7 @@ void PlayerManager::ziplinePlayer(CNSocket* sock, CNPacketData* data) {
|
|||||||
|
|
||||||
INITSTRUCT(sP_FE2CL_PC_ZIPLINE, ziplineResponse);
|
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.iCliTime = ziplineData->iCliTime;
|
||||||
ziplineResponse.iSvrTime = tm;
|
ziplineResponse.iSvrTime = tm;
|
||||||
ziplineResponse.iX = ziplineData->iX;
|
ziplineResponse.iX = ziplineData->iX;
|
||||||
@ -454,7 +458,7 @@ void PlayerManager::movePlatformPlayer(CNSocket* sock, CNPacketData* data) {
|
|||||||
|
|
||||||
INITSTRUCT(sP_FE2CL_PC_MOVEPLATFORM, platResponse);
|
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.iCliTime = platformData->iCliTime;
|
||||||
platResponse.iSvrTime = tm;
|
platResponse.iSvrTime = tm;
|
||||||
platResponse.iX = platformData->iX;
|
platResponse.iX = platformData->iX;
|
||||||
@ -488,7 +492,7 @@ void PlayerManager::moveSlopePlayer(CNSocket* sock, CNPacketData* data) {
|
|||||||
|
|
||||||
INITSTRUCT(sP_FE2CL_PC_SLOPE, slopeResponse);
|
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.iCliTime = slopeData->iCliTime;
|
||||||
slopeResponse.iSvrTime = tm;
|
slopeResponse.iSvrTime = tm;
|
||||||
slopeResponse.iX = slopeData->iX;
|
slopeResponse.iX = slopeData->iX;
|
||||||
@ -516,12 +520,12 @@ void PlayerManager::gotoPlayer(CNSocket* sock, CNPacketData* data) {
|
|||||||
|
|
||||||
DEBUGLOG(
|
DEBUGLOG(
|
||||||
std::cout << "P_CL2FE_REQ_PC_GOTO:" << std::endl;
|
std::cout << "P_CL2FE_REQ_PC_GOTO:" << std::endl;
|
||||||
std::cout << "\tX: " << gotoData->iToX << std::endl;
|
std::cout << "\tX: " << gotoData->iToX << std::endl;
|
||||||
std::cout << "\tY: " << gotoData->iToY << std::endl;
|
std::cout << "\tY: " << gotoData->iToY << std::endl;
|
||||||
std::cout << "\tZ: " << gotoData->iToZ << std::endl;
|
std::cout << "\tZ: " << gotoData->iToZ << std::endl;
|
||||||
)
|
)
|
||||||
|
|
||||||
response.iX = gotoData->iToX;
|
response.iX = gotoData->iToX;
|
||||||
response.iY = gotoData->iToY;
|
response.iY = gotoData->iToY;
|
||||||
response.iZ = gotoData->iToZ;
|
response.iZ = gotoData->iToZ;
|
||||||
|
|
||||||
@ -537,12 +541,12 @@ void PlayerManager::setSpecialPlayer(CNSocket* sock, CNPacketData* data) {
|
|||||||
|
|
||||||
DEBUGLOG(
|
DEBUGLOG(
|
||||||
std::cout << "P_CL2FE_GM_REQ_PC_SET_VALUE:" << std::endl;
|
std::cout << "P_CL2FE_GM_REQ_PC_SET_VALUE:" << std::endl;
|
||||||
std::cout << "\tPC_ID: " << setData->iPC_ID << std::endl;
|
std::cout << "\tPC_ID: " << setData->iPC_ID << std::endl;
|
||||||
std::cout << "\tSetValueType: " << setData->iSetValueType << std::endl;
|
std::cout << "\tSetValueType: " << setData->iSetValueType << std::endl;
|
||||||
std::cout << "\tSetValue: " << setData->iSetValue << 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.iSetValue = setData->iSetValue;
|
||||||
response.iSetValueType = setData->iSetValueType;
|
response.iSetValueType = setData->iSetValueType;
|
||||||
|
|
||||||
@ -570,23 +574,22 @@ void PlayerManager::revivePlayer(CNSocket* sock, CNPacketData* data) {
|
|||||||
if (data->size != sizeof(sP_CL2FE_REQ_PC_REGEN))
|
if (data->size != sizeof(sP_CL2FE_REQ_PC_REGEN))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Player plr = PlayerManager::getPlayer(sock);
|
Player *plr = PlayerManager::getPlayer(sock);
|
||||||
|
|
||||||
// players respawn at same spot they died at for now...
|
// players respawn at same spot they died at for now...
|
||||||
sP_CL2FE_REQ_PC_REGEN* reviveData = (sP_CL2FE_REQ_PC_REGEN*)data->buf;
|
sP_CL2FE_REQ_PC_REGEN* reviveData = (sP_CL2FE_REQ_PC_REGEN*)data->buf;
|
||||||
INITSTRUCT(sP_FE2CL_REP_PC_REGEN_SUCC, response);
|
INITSTRUCT(sP_FE2CL_REP_PC_REGEN_SUCC, response);
|
||||||
response.bMoveLocation = reviveData->eIL;
|
response.bMoveLocation = reviveData->eIL;
|
||||||
response.PCRegenData.iMapNum = reviveData->iIndex;
|
response.PCRegenData.iMapNum = reviveData->iIndex;
|
||||||
response.PCRegenData.iHP = 1000 * plr.level;
|
response.PCRegenData.iHP = 1000 * plr->level;
|
||||||
response.PCRegenData.iX = plr.x;
|
response.PCRegenData.iX = plr->x;
|
||||||
response.PCRegenData.iY = plr.y;
|
response.PCRegenData.iY = plr->y;
|
||||||
response.PCRegenData.iZ = plr.z;
|
response.PCRegenData.iZ = plr->z;
|
||||||
|
|
||||||
sock->sendPacket((void*)&response, P_FE2CL_REP_PC_REGEN_SUCC, sizeof(sP_FE2CL_REP_PC_REGEN_SUCC));
|
sock->sendPacket((void*)&response, P_FE2CL_REP_PC_REGEN_SUCC, sizeof(sP_FE2CL_REP_PC_REGEN_SUCC));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerManager::enterPlayerVehicle(CNSocket* sock, CNPacketData* data) {
|
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);
|
INITSTRUCT(sP_FE2CL_PC_VEHICLE_ON_SUCC, response);
|
||||||
PlayerView plrv = PlayerManager::players[sock];
|
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));
|
otherSock->sendPacket((void*)&pkt, P_FE2CL_PC_EQUIP_CHANGE, sizeof(sP_FE2CL_PC_EQUIP_CHANGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
plrv.plr.iPCState = 8;
|
plrv.plr->iPCState = 8;
|
||||||
updatePlayer(sock, plrv.plr);
|
|
||||||
|
|
||||||
sock->sendPacket((void*)&response, P_FE2CL_PC_VEHICLE_ON_SUCC, sizeof(sP_FE2CL_PC_VEHICLE_ON_SUCC));
|
sock->sendPacket((void*)&response, P_FE2CL_PC_VEHICLE_ON_SUCC, sizeof(sP_FE2CL_PC_VEHICLE_ON_SUCC));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerManager::exitPlayerVehicle(CNSocket* sock, CNPacketData* data) {
|
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);
|
INITSTRUCT(sP_FE2CL_PC_VEHICLE_OFF_SUCC, response);
|
||||||
PlayerView plrv = PlayerManager::players[sock];
|
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));
|
otherSock->sendPacket((void*)&pkt, P_FE2CL_PC_EQUIP_CHANGE, sizeof(sP_FE2CL_PC_EQUIP_CHANGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
plrv.plr.iPCState = 0;
|
plrv.plr->iPCState = 0;
|
||||||
updatePlayer(sock, plrv.plr);
|
|
||||||
|
|
||||||
sock->sendPacket((void*)&response, P_FE2CL_PC_VEHICLE_OFF_SUCC, sizeof(sP_FE2CL_PC_VEHICLE_OFF_SUCC));
|
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
|
#pragma region Helper methods
|
||||||
Player PlayerManager::getPlayer(CNSocket* key) {
|
Player *PlayerManager::getPlayer(CNSocket* key) {
|
||||||
return players[key].plr;
|
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 {
|
struct PlayerView {
|
||||||
std::list<CNSocket*> viewable;
|
std::list<CNSocket*> viewable;
|
||||||
std::list<int32_t> viewableNPCs;
|
std::list<int32_t> viewableNPCs;
|
||||||
Player plr;
|
Player *plr;
|
||||||
uint64_t lastHeartbeat;
|
uint64_t lastHeartbeat;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -22,9 +22,8 @@ namespace PlayerManager {
|
|||||||
|
|
||||||
void addPlayer(CNSocket* key, Player plr);
|
void addPlayer(CNSocket* key, Player plr);
|
||||||
void removePlayer(CNSocket* key);
|
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);
|
void updatePlayerPosition(CNSocket* sock, int X, int Y, int Z);
|
||||||
std::list<CNSocket*> getNearbyPlayers(int X, int Y, int dist);
|
std::list<CNSocket*> getNearbyPlayers(int X, int Y, int dist);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user