[refactor] Initial conversion to new packet handler interfaces

Manually converted PlayerManager, PlayerMovement and a few parts of
Combat to the new system.
This commit is contained in:
dongresource 2021-03-19 22:29:14 +01:00
parent 688f13e649
commit 55b140f673
3 changed files with 62 additions and 124 deletions

View File

@ -56,18 +56,12 @@ static std::pair<int,int> getDamage(int attackPower, int defensePower, bool shou
} }
static void pcAttackNpcs(CNSocket *sock, CNPacketData *data) { static void pcAttackNpcs(CNSocket *sock, CNPacketData *data) {
sP_CL2FE_REQ_PC_ATTACK_NPCs* pkt = (sP_CL2FE_REQ_PC_ATTACK_NPCs*)data->buf; auto pkt = (sP_CL2FE_REQ_PC_ATTACK_NPCs*)data->buf;
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
auto targets = (int32_t*)data->trailers;
// sanity check
if (!validInVarPacket(sizeof(sP_CL2FE_REQ_PC_ATTACK_NPCs), pkt->iNPCCnt, sizeof(int32_t), data->size)) {
std::cout << "[WARN] bad sP_CL2FE_REQ_PC_ATTACK_NPCs packet size\n";
return;
}
int32_t *pktdata = (int32_t*)((uint8_t*)data->buf + sizeof(sP_CL2FE_REQ_PC_ATTACK_NPCs));
// rapid fire anti-cheat // rapid fire anti-cheat
// TODO: move this out of here, when generalizing packet frequency validation
time_t currTime = getTime(); time_t currTime = getTime();
if (currTime - plr->lastShot < plr->fireRate * 80) if (currTime - plr->lastShot < plr->fireRate * 80)
plr->suspicionRating += plr->fireRate * 100 + plr->lastShot - currTime; // gain suspicion for rapid firing plr->suspicionRating += plr->fireRate * 100 + plr->lastShot - currTime; // gain suspicion for rapid firing
@ -83,33 +77,27 @@ static void pcAttackNpcs(CNSocket *sock, CNPacketData *data) {
sock->kill(); sock->kill();
/* /*
* Due to the possibility of multiplication overflow (and regular buffer overflow), * IMPORTANT: This validates memory safety in addition to preventing
* both incoming and outgoing variable-length packets must be validated, at least if * ordinary cheating. If the client sends a very large number of trailing
* the number of trailing structs isn't well known (ie. it's from the client). * values, it could overflow the *response* buffer, which isn't otherwise
* being validated anymore.
*/ */
if (!validOutVarPacket(sizeof(sP_FE2CL_PC_ATTACK_NPCs_SUCC), pkt->iNPCCnt, sizeof(sAttackResult))) { if (pkt->iNPCCnt > 3) {
std::cout << "[WARN] bad sP_FE2CL_PC_ATTACK_NPCs_SUCC packet size\n"; std::cout << "[WARN] Player tried to attack more than 3 NPCs at once" << std::endl;
return; return;
} }
// initialize response struct INITVARPACKET(respbuf, sP_FE2CL_PC_ATTACK_NPCs_SUCC, resp, sAttackResult, respdata);
size_t resplen = sizeof(sP_FE2CL_PC_ATTACK_NPCs_SUCC) + pkt->iNPCCnt * sizeof(sAttackResult);
uint8_t respbuf[CN_PACKET_BUFFER_SIZE];
memset(respbuf, 0, resplen);
sP_FE2CL_PC_ATTACK_NPCs_SUCC *resp = (sP_FE2CL_PC_ATTACK_NPCs_SUCC*)respbuf;
sAttackResult *respdata = (sAttackResult*)(respbuf+sizeof(sP_FE2CL_PC_ATTACK_NPCs_SUCC));
resp->iNPCCnt = pkt->iNPCCnt; resp->iNPCCnt = pkt->iNPCCnt;
for (int i = 0; i < pkt->iNPCCnt; i++) { for (int i = 0; i < data->trCnt; i++) {
if (MobAI::Mobs.find(pktdata[i]) == MobAI::Mobs.end()) { if (MobAI::Mobs.find(targets[i]) == MobAI::Mobs.end()) {
// not sure how to best handle this // not sure how to best handle this
std::cout << "[WARN] pcAttackNpcs: mob ID not found" << std::endl; std::cout << "[WARN] pcAttackNpcs: mob ID not found" << std::endl;
return; return;
} }
Mob *mob = MobAI::Mobs[pktdata[i]]; Mob *mob = MobAI::Mobs[targets[i]];
std::pair<int,int> damage; std::pair<int,int> damage;
@ -119,7 +107,8 @@ static void pcAttackNpcs(CNSocket *sock, CNPacketData *data) {
damage.first = plr->pointDamage; damage.first = plr->pointDamage;
int difficulty = (int)mob->data["m_iNpcLevel"]; int difficulty = (int)mob->data["m_iNpcLevel"];
damage = getDamage(damage.first, (int)mob->data["m_iProtection"], true, (plr->batteryW > 6 + difficulty), Nanos::nanoStyle(plr->activeNano), (int)mob->data["m_iNpcStyle"], difficulty); damage = getDamage(damage.first, (int)mob->data["m_iProtection"], true, (plr->batteryW > 6 + difficulty),
Nanos::nanoStyle(plr->activeNano), (int)mob->data["m_iNpcStyle"], difficulty);
if (plr->batteryW >= 6 + difficulty) if (plr->batteryW >= 6 + difficulty)
plr->batteryW -= 6 + difficulty; plr->batteryW -= 6 + difficulty;
@ -135,28 +124,22 @@ static void pcAttackNpcs(CNSocket *sock, CNPacketData *data) {
} }
resp->iBatteryW = plr->batteryW; resp->iBatteryW = plr->batteryW;
sock->sendPacket((void*)respbuf, P_FE2CL_PC_ATTACK_NPCs_SUCC, resplen); sock->sendPacket(respbuf, P_FE2CL_PC_ATTACK_NPCs_SUCC);
// a bit of a hack: these are the same size, so we can reuse the response packet // a bit of a hack: these are the same size, so we can reuse the response packet
assert(sizeof(sP_FE2CL_PC_ATTACK_NPCs_SUCC) == sizeof(sP_FE2CL_PC_ATTACK_NPCs)); assert(sizeof(sP_FE2CL_PC_ATTACK_NPCs_SUCC) == sizeof(sP_FE2CL_PC_ATTACK_NPCs));
sP_FE2CL_PC_ATTACK_NPCs *resp1 = (sP_FE2CL_PC_ATTACK_NPCs*)respbuf; auto *resp1 = (sP_FE2CL_PC_ATTACK_NPCs*)respbuf;
resp1->iPC_ID = plr->iID; resp1->iPC_ID = plr->iID;
// send to other players // send to other players
PlayerManager::sendToViewable(sock, (void*)respbuf, P_FE2CL_PC_ATTACK_NPCs, resplen); PlayerManager::sendToViewable(sock, respbuf, P_FE2CL_PC_ATTACK_NPCs);
} }
void Combat::npcAttackPc(Mob *mob, time_t currTime) { void Combat::npcAttackPc(Mob *mob, time_t currTime) {
Player *plr = PlayerManager::getPlayer(mob->target); Player *plr = PlayerManager::getPlayer(mob->target);
const size_t resplen = sizeof(sP_FE2CL_PC_ATTACK_NPCs_SUCC) + sizeof(sAttackResult); INITVARPACKET(respbuf, sP_FE2CL_NPC_ATTACK_PCs, pkt, sAttackResult, atk);
assert(resplen < CN_PACKET_BUFFER_SIZE - 8);
uint8_t respbuf[CN_PACKET_BUFFER_SIZE];
memset(respbuf, 0, resplen);
sP_FE2CL_NPC_ATTACK_PCs *pkt = (sP_FE2CL_NPC_ATTACK_PCs*)respbuf;
sAttackResult *atk = (sAttackResult*)(respbuf + sizeof(sP_FE2CL_NPC_ATTACK_PCs));
auto damage = getDamage(450 + (int)mob->data["m_iPower"], plr->defense, false, false, -1, -1, 0); auto damage = getDamage(450 + (int)mob->data["m_iPower"], plr->defense, false, false, -1, -1, 0);
@ -171,8 +154,8 @@ void Combat::npcAttackPc(Mob *mob, time_t currTime) {
atk->iHP = plr->HP; atk->iHP = plr->HP;
atk->iHitFlag = damage.second; atk->iHitFlag = damage.second;
mob->target->sendPacket((void*)respbuf, P_FE2CL_NPC_ATTACK_PCs, resplen); mob->target->sendPacket(respbuf, P_FE2CL_NPC_ATTACK_PCs);
PlayerManager::sendToViewable(mob->target, (void*)respbuf, P_FE2CL_NPC_ATTACK_PCs, resplen); PlayerManager::sendToViewable(mob->target, respbuf, P_FE2CL_NPC_ATTACK_PCs);
if (plr->HP <= 0) { if (plr->HP <= 0) {
mob->target = nullptr; mob->target = nullptr;
@ -315,11 +298,9 @@ static void combatBegin(CNSocket *sock, CNPacketData *data) {
static void combatEnd(CNSocket *sock, CNPacketData *data) { static void combatEnd(CNSocket *sock, CNPacketData *data) {
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr != nullptr) {
plr->inCombat = false; plr->inCombat = false;
plr->healCooldown = 4000; plr->healCooldown = 4000;
} }
}
static void dotDamageOnOff(CNSocket *sock, CNPacketData *data) { static void dotDamageOnOff(CNSocket *sock, CNPacketData *data) {
sP_CL2FE_DOT_DAMAGE_ONOFF *pkt = (sP_CL2FE_DOT_DAMAGE_ONOFF*)data->buf; sP_CL2FE_DOT_DAMAGE_ONOFF *pkt = (sP_CL2FE_DOT_DAMAGE_ONOFF*)data->buf;
@ -608,7 +589,7 @@ static void projectileHit(CNSocket* sock, CNPacketData* data) {
return; return;
} }
// client sends us 8 byters, where last 4 bytes are mob ID, // client sends us 8 bytes, where last 4 bytes are mob ID,
// we use int64 pointer to move around but have to remember to cast it to int32 // we use int64 pointer to move around but have to remember to cast it to int32
int64_t* pktdata = (int64_t*)((uint8_t*)data->buf + sizeof(sP_CL2FE_REQ_PC_ROCKET_STYLE_HIT)); int64_t* pktdata = (int64_t*)((uint8_t*)data->buf + sizeof(sP_CL2FE_REQ_PC_ROCKET_STYLE_HIT));

View File

@ -123,7 +123,7 @@ void PlayerManager::sendPlayerTo(CNSocket* sock, int X, int Y, int Z, uint64_t I
resp.iZ = Z; resp.iZ = Z;
resp.iCandy = plr->money; resp.iCandy = plr->money;
resp.eIL = 4; // do not take away any items resp.eIL = 4; // do not take away any items
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_WARP_USE_NPC_SUCC, sizeof(sP_FE2CL_REP_PC_WARP_USE_NPC_SUCC)); sock->sendPacket(resp, P_FE2CL_REP_PC_WARP_USE_NPC_SUCC);
} }
if (I != INSTANCE_OVERWORLD) { if (I != INSTANCE_OVERWORLD) {
@ -141,14 +141,15 @@ void PlayerManager::sendPlayerTo(CNSocket* sock, int X, int Y, int Z, uint64_t I
pkt.iMapCoordZ_Max = INT32_MAX; pkt.iMapCoordZ_Max = INT32_MAX;
} }
sock->sendPacket((void*)&pkt, P_FE2CL_INSTANCE_MAP_INFO, sizeof(sP_FE2CL_INSTANCE_MAP_INFO)); sock->sendPacket(pkt, P_FE2CL_INSTANCE_MAP_INFO);
} }
INITSTRUCT(sP_FE2CL_REP_PC_GOTO_SUCC, pkt2); INITSTRUCT(sP_FE2CL_REP_PC_GOTO_SUCC, pkt2);
pkt2.iX = X; pkt2.iX = X;
pkt2.iY = Y; pkt2.iY = Y;
pkt2.iZ = Z; pkt2.iZ = Z;
sock->sendPacket((void*)&pkt2, P_FE2CL_REP_PC_GOTO_SUCC, sizeof(sP_FE2CL_REP_PC_GOTO_SUCC)); sock->sendPacket(pkt2, P_FE2CL_REP_PC_GOTO_SUCC);
Chunking::updatePlayerChunk(sock, plr->chunkPos, std::make_tuple(0, 0, 0)); // force player to reload chunks Chunking::updatePlayerChunk(sock, plr->chunkPos, std::make_tuple(0, 0, 0)); // force player to reload chunks
updatePlayerPosition(sock, X, Y, Z, I, plr->angle); updatePlayerPosition(sock, X, Y, Z, I, plr->angle);
@ -189,16 +190,14 @@ static void sendNanoBookSubset(CNSocket *sock) {
for (int i = id - pkt.elementOffset; id < NANO_COUNT && i < 10; id++, i = id - pkt.elementOffset) for (int i = id - pkt.elementOffset; id < NANO_COUNT && i < 10; id++, i = id - pkt.elementOffset)
pkt.element[i] = plr->Nanos[id]; pkt.element[i] = plr->Nanos[id];
// TODO: add NANO_BOOK_SUBSET to Defines.c, so we can switch this to the new system later
sock->sendPacket((void*)&pkt, P_FE2CL_REP_NANO_BOOK_SUBSET, sizeof(sP_FE2CL_REP_NANO_BOOK_SUBSET)); sock->sendPacket((void*)&pkt, P_FE2CL_REP_NANO_BOOK_SUBSET, sizeof(sP_FE2CL_REP_NANO_BOOK_SUBSET));
} }
#endif #endif
} }
static void enterPlayer(CNSocket* sock, CNPacketData* data) { static void enterPlayer(CNSocket* sock, CNPacketData* data) {
if (data->size != sizeof(sP_CL2FE_REQ_PC_ENTER)) auto* enter = (sP_CL2FE_REQ_PC_ENTER*)data->buf;
return; // ignore the malformed packet
sP_CL2FE_REQ_PC_ENTER* enter = (sP_CL2FE_REQ_PC_ENTER*)data->buf;
INITSTRUCT(sP_FE2CL_REP_PC_ENTER_SUCC, response); INITSTRUCT(sP_FE2CL_REP_PC_ENTER_SUCC, response);
// TODO: check if serialkey exists, if it doesn't send sP_FE2CL_REP_PC_ENTER_FAIL // TODO: check if serialkey exists, if it doesn't send sP_FE2CL_REP_PC_ENTER_FAIL
@ -307,7 +306,7 @@ static void enterPlayer(CNSocket* sock, CNPacketData* data) {
sock->setFEKey(plr.FEKey); sock->setFEKey(plr.FEKey);
sock->setActiveKey(SOCKETKEY_FE); // send all packets using the FE key from now on sock->setActiveKey(SOCKETKEY_FE); // send all packets using the FE key from now on
sock->sendPacket((void*)&response, P_FE2CL_REP_PC_ENTER_SUCC, sizeof(sP_FE2CL_REP_PC_ENTER_SUCC)); sock->sendPacket(response, P_FE2CL_REP_PC_ENTER_SUCC);
// transmit MOTD after entering the game, so the client hopefully changes modes on time // transmit MOTD after entering the game, so the client hopefully changes modes on time
Chat::sendServerMessage(sock, settings::MOTDSTRING); Chat::sendServerMessage(sock, settings::MOTDSTRING);
@ -345,9 +344,6 @@ void PlayerManager::sendToViewable(CNSocket* sock, void* buf, uint32_t type, siz
} }
static void loadPlayer(CNSocket* sock, CNPacketData* data) { static void loadPlayer(CNSocket* sock, CNPacketData* data) {
if (data->size != sizeof(sP_CL2FE_REQ_PC_LOADING_COMPLETE))
return; // ignore the malformed packet
sP_CL2FE_REQ_PC_LOADING_COMPLETE* complete = (sP_CL2FE_REQ_PC_LOADING_COMPLETE*)data->buf; sP_CL2FE_REQ_PC_LOADING_COMPLETE* complete = (sP_CL2FE_REQ_PC_LOADING_COMPLETE*)data->buf;
INITSTRUCT(sP_FE2CL_REP_PC_LOADING_COMPLETE_SUCC, response); INITSTRUCT(sP_FE2CL_REP_PC_LOADING_COMPLETE_SUCC, response);
Player *plr = getPlayer(sock); Player *plr = getPlayer(sock);
@ -361,7 +357,7 @@ static void loadPlayer(CNSocket* sock, CNPacketData* data) {
updatePlayerPosition(sock, plr->x, plr->y, plr->z, plr->instanceID, plr->angle); updatePlayerPosition(sock, plr->x, plr->y, plr->z, plr->instanceID, plr->angle);
sock->sendPacket((void*)&response, P_FE2CL_REP_PC_LOADING_COMPLETE_SUCC, sizeof(sP_FE2CL_REP_PC_LOADING_COMPLETE_SUCC)); sock->sendPacket(response, P_FE2CL_REP_PC_LOADING_COMPLETE_SUCC);
} }
static void heartbeatPlayer(CNSocket* sock, CNPacketData* data) { static void heartbeatPlayer(CNSocket* sock, CNPacketData* data) {
@ -369,16 +365,13 @@ static void heartbeatPlayer(CNSocket* sock, CNPacketData* data) {
} }
static void exitGame(CNSocket* sock, CNPacketData* data) { static void exitGame(CNSocket* sock, CNPacketData* data) {
if (data->size != sizeof(sP_CL2FE_REQ_PC_EXIT)) auto exitData = (sP_CL2FE_REQ_PC_EXIT*)data->buf;
return;
sP_CL2FE_REQ_PC_EXIT* exitData = (sP_CL2FE_REQ_PC_EXIT*)data->buf;
INITSTRUCT(sP_FE2CL_REP_PC_EXIT_SUCC, response); INITSTRUCT(sP_FE2CL_REP_PC_EXIT_SUCC, response);
response.iID = exitData->iID; response.iID = exitData->iID;
response.iExitCode = 1; response.iExitCode = 1;
sock->sendPacket((void*)&response, P_FE2CL_REP_PC_EXIT_SUCC, sizeof(sP_FE2CL_REP_PC_EXIT_SUCC)); sock->sendPacket(response, P_FE2CL_REP_PC_EXIT_SUCC);
} }
static WarpLocation* getRespawnPoint(Player *plr) { static WarpLocation* getRespawnPoint(Player *plr) {
@ -397,13 +390,10 @@ static WarpLocation* getRespawnPoint(Player *plr) {
} }
static void revivePlayer(CNSocket* sock, CNPacketData* data) { static void revivePlayer(CNSocket* sock, CNPacketData* data) {
if (data->size != sizeof(sP_CL2FE_REQ_PC_REGEN))
return;
Player *plr = getPlayer(sock); Player *plr = getPlayer(sock);
WarpLocation* target = getRespawnPoint(plr); WarpLocation* target = getRespawnPoint(plr);
sP_CL2FE_REQ_PC_REGEN* reviveData = (sP_CL2FE_REQ_PC_REGEN*)data->buf; auto reviveData = (sP_CL2FE_REQ_PC_REGEN*)data->buf;
INITSTRUCT(sP_FE2CL_REP_PC_REGEN_SUCC, response); INITSTRUCT(sP_FE2CL_REP_PC_REGEN_SUCC, response);
INITSTRUCT(sP_FE2CL_PC_REGEN, resp2); INITSTRUCT(sP_FE2CL_PC_REGEN, resp2);
@ -462,7 +452,7 @@ static void revivePlayer(CNSocket* sock, CNPacketData* data) {
response.bMoveLocation = 0; response.bMoveLocation = 0;
response.PCRegenData.iMapNum = MAPNUM(plr->instanceID); response.PCRegenData.iMapNum = MAPNUM(plr->instanceID);
sock->sendPacket((void*)&response, P_FE2CL_REP_PC_REGEN_SUCC, sizeof(sP_FE2CL_REP_PC_REGEN_SUCC)); sock->sendPacket(response, P_FE2CL_REP_PC_REGEN_SUCC);
// Update other players // Update other players
resp2.PCRegenDataForOtherPC.iPC_ID = plr->iID; resp2.PCRegenDataForOtherPC.iPC_ID = plr->iID;
@ -481,7 +471,7 @@ static void revivePlayer(CNSocket* sock, CNPacketData* data) {
resp2.PCRegenDataForOtherPC.iSpecialState = plr->iSpecialState; resp2.PCRegenDataForOtherPC.iSpecialState = plr->iSpecialState;
resp2.PCRegenDataForOtherPC.Nano = plr->Nanos[plr->activeNano]; resp2.PCRegenDataForOtherPC.Nano = plr->Nanos[plr->activeNano];
sendToViewable(sock, (void*)&resp2, P_FE2CL_PC_REGEN, sizeof(sP_FE2CL_PC_REGEN)); sendToViewable(sock, resp2, P_FE2CL_PC_REGEN);
} }
if (!move) if (!move)
@ -502,18 +492,18 @@ static void enterPlayerVehicle(CNSocket* sock, CNPacketData* data) {
if (plr->Equip[8].iID > 0 && !expired) { if (plr->Equip[8].iID > 0 && !expired) {
INITSTRUCT(sP_FE2CL_PC_VEHICLE_ON_SUCC, response); INITSTRUCT(sP_FE2CL_PC_VEHICLE_ON_SUCC, response);
sock->sendPacket((void*)&response, P_FE2CL_PC_VEHICLE_ON_SUCC, sizeof(sP_FE2CL_PC_VEHICLE_ON_SUCC)); sock->sendPacket(response, P_FE2CL_PC_VEHICLE_ON_SUCC);
// send to other players // send to other players
plr->iPCState |= 8; plr->iPCState |= 8;
INITSTRUCT(sP_FE2CL_PC_STATE_CHANGE, response2); INITSTRUCT(sP_FE2CL_PC_STATE_CHANGE, response2);
response2.iPC_ID = plr->iID; response2.iPC_ID = plr->iID;
response2.iState = plr->iPCState; response2.iState = plr->iPCState;
sendToViewable(sock, (void*)&response2, P_FE2CL_PC_STATE_CHANGE, sizeof(sP_FE2CL_PC_STATE_CHANGE)); sendToViewable(sock, response2, P_FE2CL_PC_STATE_CHANGE);
} else { } else {
INITSTRUCT(sP_FE2CL_PC_VEHICLE_ON_FAIL, response); INITSTRUCT(sP_FE2CL_PC_VEHICLE_ON_FAIL, response);
sock->sendPacket((void*)&response, P_FE2CL_PC_VEHICLE_ON_FAIL, sizeof(sP_FE2CL_PC_VEHICLE_ON_FAIL)); sock->sendPacket(response, P_FE2CL_PC_VEHICLE_ON_FAIL);
// check if vehicle didn't expire // check if vehicle didn't expire
if (expired) { if (expired) {
@ -529,7 +519,7 @@ static void exitPlayerVehicle(CNSocket* sock, CNPacketData* data) {
if (plr->iPCState & 8) { if (plr->iPCState & 8) {
INITSTRUCT(sP_FE2CL_PC_VEHICLE_OFF_SUCC, response); INITSTRUCT(sP_FE2CL_PC_VEHICLE_OFF_SUCC, response);
sock->sendPacket((void*)&response, P_FE2CL_PC_VEHICLE_OFF_SUCC, sizeof(sP_FE2CL_PC_VEHICLE_OFF_SUCC)); sock->sendPacket(response, P_FE2CL_PC_VEHICLE_OFF_SUCC);
// send to other players // send to other players
plr->iPCState &= ~8; plr->iPCState &= ~8;
@ -537,7 +527,7 @@ static void exitPlayerVehicle(CNSocket* sock, CNPacketData* data) {
response2.iPC_ID = plr->iID; response2.iPC_ID = plr->iID;
response2.iState = plr->iPCState; response2.iState = plr->iPCState;
sendToViewable(sock, (void*)&response2, P_FE2CL_PC_STATE_CHANGE, sizeof(sP_FE2CL_PC_STATE_CHANGE)); sendToViewable(sock, response2, P_FE2CL_PC_STATE_CHANGE);
} }
} }
@ -546,10 +536,7 @@ static void setSpecialSwitchPlayer(CNSocket* sock, CNPacketData* data) {
} }
static void changePlayerGuide(CNSocket *sock, CNPacketData *data) { static void changePlayerGuide(CNSocket *sock, CNPacketData *data) {
if (data->size != sizeof(sP_CL2FE_REQ_PC_CHANGE_MENTOR)) auto pkt = (sP_CL2FE_REQ_PC_CHANGE_MENTOR*)data->buf;
return;
sP_CL2FE_REQ_PC_CHANGE_MENTOR *pkt = (sP_CL2FE_REQ_PC_CHANGE_MENTOR*)data->buf;
INITSTRUCT(sP_FE2CL_REP_PC_CHANGE_MENTOR_SUCC, resp); INITSTRUCT(sP_FE2CL_REP_PC_CHANGE_MENTOR_SUCC, resp);
Player *plr = getPlayer(sock); Player *plr = getPlayer(sock);
@ -557,7 +544,7 @@ static void changePlayerGuide(CNSocket *sock, CNPacketData *data) {
resp.iMentorCnt = 1; resp.iMentorCnt = 1;
resp.iFusionMatter = plr->fusionmatter; // no cost resp.iFusionMatter = plr->fusionmatter; // no cost
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_CHANGE_MENTOR_SUCC, sizeof(sP_FE2CL_REP_PC_CHANGE_MENTOR_SUCC)); sock->sendPacket(resp, P_FE2CL_REP_PC_CHANGE_MENTOR_SUCC);
// if it's changed from computress // if it's changed from computress
if (plr->mentor == 5) { if (plr->mentor == 5) {
// we're warping to the past // we're warping to the past
@ -576,10 +563,7 @@ static void changePlayerGuide(CNSocket *sock, CNPacketData *data) {
} }
static void setFirstUseFlag(CNSocket* sock, CNPacketData* data) { static void setFirstUseFlag(CNSocket* sock, CNPacketData* data) {
if (data->size != sizeof(sP_CL2FE_REQ_PC_FIRST_USE_FLAG_SET)) auto flag = (sP_CL2FE_REQ_PC_FIRST_USE_FLAG_SET*)data->buf;
return;
sP_CL2FE_REQ_PC_FIRST_USE_FLAG_SET* flag = (sP_CL2FE_REQ_PC_FIRST_USE_FLAG_SET*)data->buf;
Player* plr = getPlayer(sock); Player* plr = getPlayer(sock);
if (flag->iFlagCode < 1 || flag->iFlagCode > 128) { if (flag->iFlagCode < 1 || flag->iFlagCode > 128) {
@ -638,7 +622,7 @@ void PlayerManager::exitDuplicate(int accountId) {
INITSTRUCT(sP_FE2CL_REP_PC_EXIT_DUPLICATE, resp); INITSTRUCT(sP_FE2CL_REP_PC_EXIT_DUPLICATE, resp);
resp.iErrorCode = 0; resp.iErrorCode = 0;
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_EXIT_DUPLICATE, sizeof(sP_FE2CL_REP_PC_EXIT_DUPLICATE)); sock->sendPacket(resp, P_FE2CL_REP_PC_EXIT_DUPLICATE);
sock->kill(); sock->kill();
CNShardServer::_killConnection(sock); CNShardServer::_killConnection(sock);

View File

@ -3,12 +3,9 @@
#include "core/Core.hpp" #include "core/Core.hpp"
static void movePlayer(CNSocket* sock, CNPacketData* data) { static void movePlayer(CNSocket* sock, CNPacketData* data) {
if (data->size != sizeof(sP_CL2FE_REQ_PC_MOVE))
return; // ignore the malformed packet
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
sP_CL2FE_REQ_PC_MOVE* moveData = (sP_CL2FE_REQ_PC_MOVE*)data->buf; auto* moveData = (sP_CL2FE_REQ_PC_MOVE*)data->buf;
PlayerManager::updatePlayerPosition(sock, moveData->iX, moveData->iY, moveData->iZ, plr->instanceID, moveData->iAngle); PlayerManager::updatePlayerPosition(sock, moveData->iX, moveData->iY, moveData->iZ, plr->instanceID, moveData->iAngle);
uint64_t tm = getTime(); uint64_t tm = getTime();
@ -30,16 +27,13 @@ static void movePlayer(CNSocket* sock, CNPacketData* data) {
moveResponse.iCliTime = moveData->iCliTime; // maybe don't send this??? seems unneeded... moveResponse.iCliTime = moveData->iCliTime; // maybe don't send this??? seems unneeded...
moveResponse.iSvrTime = tm; moveResponse.iSvrTime = tm;
PlayerManager::sendToViewable(sock, (void*)&moveResponse, P_FE2CL_PC_MOVE, sizeof(sP_FE2CL_PC_MOVE)); PlayerManager::sendToViewable(sock, moveResponse, P_FE2CL_PC_MOVE);
} }
static void stopPlayer(CNSocket* sock, CNPacketData* data) { static void stopPlayer(CNSocket* sock, CNPacketData* data) {
if (data->size != sizeof(sP_CL2FE_REQ_PC_STOP))
return; // ignore the malformed packet
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
sP_CL2FE_REQ_PC_STOP* stopData = (sP_CL2FE_REQ_PC_STOP*)data->buf; auto stopData = (sP_CL2FE_REQ_PC_STOP*)data->buf;
PlayerManager::updatePlayerPosition(sock, stopData->iX, stopData->iY, stopData->iZ, plr->instanceID, plr->angle); PlayerManager::updatePlayerPosition(sock, stopData->iX, stopData->iY, stopData->iZ, plr->instanceID, plr->angle);
uint64_t tm = getTime(); uint64_t tm = getTime();
@ -55,16 +49,13 @@ static void stopPlayer(CNSocket* sock, CNPacketData* data) {
stopResponse.iCliTime = stopData->iCliTime; // maybe don't send this??? seems unneeded... stopResponse.iCliTime = stopData->iCliTime; // maybe don't send this??? seems unneeded...
stopResponse.iSvrTime = tm; stopResponse.iSvrTime = tm;
PlayerManager::sendToViewable(sock, (void*)&stopResponse, P_FE2CL_PC_STOP, sizeof(sP_FE2CL_PC_STOP)); PlayerManager::sendToViewable(sock, stopResponse, P_FE2CL_PC_STOP);
} }
static void jumpPlayer(CNSocket* sock, CNPacketData* data) { static void jumpPlayer(CNSocket* sock, CNPacketData* data) {
if (data->size != sizeof(sP_CL2FE_REQ_PC_JUMP))
return; // ignore the malformed packet
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
sP_CL2FE_REQ_PC_JUMP* jumpData = (sP_CL2FE_REQ_PC_JUMP*)data->buf; auto jumpData = (sP_CL2FE_REQ_PC_JUMP*)data->buf;
PlayerManager::updatePlayerPosition(sock, jumpData->iX, jumpData->iY, jumpData->iZ, plr->instanceID, jumpData->iAngle); PlayerManager::updatePlayerPosition(sock, jumpData->iX, jumpData->iY, jumpData->iZ, plr->instanceID, jumpData->iAngle);
uint64_t tm = getTime(); uint64_t tm = getTime();
@ -86,16 +77,13 @@ static void jumpPlayer(CNSocket* sock, CNPacketData* data) {
jumpResponse.iCliTime = jumpData->iCliTime; // maybe don't send this??? seems unneeded... jumpResponse.iCliTime = jumpData->iCliTime; // maybe don't send this??? seems unneeded...
jumpResponse.iSvrTime = tm; jumpResponse.iSvrTime = tm;
PlayerManager::sendToViewable(sock, (void*)&jumpResponse, P_FE2CL_PC_JUMP, sizeof(sP_FE2CL_PC_JUMP)); PlayerManager::sendToViewable(sock, jumpResponse, P_FE2CL_PC_JUMP);
} }
static void jumppadPlayer(CNSocket* sock, CNPacketData* data) { static void jumppadPlayer(CNSocket* sock, CNPacketData* data) {
if (data->size != sizeof(sP_CL2FE_REQ_PC_JUMPPAD))
return; // ignore the malformed packet
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
sP_CL2FE_REQ_PC_JUMPPAD* jumppadData = (sP_CL2FE_REQ_PC_JUMPPAD*)data->buf; auto jumppadData = (sP_CL2FE_REQ_PC_JUMPPAD*)data->buf;
PlayerManager::updatePlayerPosition(sock, jumppadData->iX, jumppadData->iY, jumppadData->iZ, plr->instanceID, jumppadData->iAngle); PlayerManager::updatePlayerPosition(sock, jumppadData->iX, jumppadData->iY, jumppadData->iZ, plr->instanceID, jumppadData->iAngle);
uint64_t tm = getTime(); uint64_t tm = getTime();
@ -115,16 +103,13 @@ static void jumppadPlayer(CNSocket* sock, CNPacketData* data) {
jumppadResponse.iCliTime = jumppadData->iCliTime; jumppadResponse.iCliTime = jumppadData->iCliTime;
jumppadResponse.iSvrTime = tm; jumppadResponse.iSvrTime = tm;
PlayerManager::sendToViewable(sock, (void*)&jumppadResponse, P_FE2CL_PC_JUMPPAD, sizeof(sP_FE2CL_PC_JUMPPAD)); PlayerManager::sendToViewable(sock, jumppadResponse, P_FE2CL_PC_JUMPPAD);
} }
static void launchPlayer(CNSocket* sock, CNPacketData* data) { static void launchPlayer(CNSocket* sock, CNPacketData* data) {
if (data->size != sizeof(sP_CL2FE_REQ_PC_LAUNCHER))
return; // ignore the malformed packet
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
sP_CL2FE_REQ_PC_LAUNCHER* launchData = (sP_CL2FE_REQ_PC_LAUNCHER*)data->buf; auto launchData = (sP_CL2FE_REQ_PC_LAUNCHER*)data->buf;
PlayerManager::updatePlayerPosition(sock, launchData->iX, launchData->iY, launchData->iZ, plr->instanceID, launchData->iAngle); PlayerManager::updatePlayerPosition(sock, launchData->iX, launchData->iY, launchData->iZ, plr->instanceID, launchData->iAngle);
uint64_t tm = getTime(); uint64_t tm = getTime();
@ -145,13 +130,10 @@ static void launchPlayer(CNSocket* sock, CNPacketData* data) {
launchResponse.iCliTime = launchData->iCliTime; launchResponse.iCliTime = launchData->iCliTime;
launchResponse.iSvrTime = tm; launchResponse.iSvrTime = tm;
PlayerManager::sendToViewable(sock, (void*)&launchResponse, P_FE2CL_PC_LAUNCHER, sizeof(sP_FE2CL_PC_LAUNCHER)); PlayerManager::sendToViewable(sock, launchResponse, P_FE2CL_PC_LAUNCHER);
} }
static void ziplinePlayer(CNSocket* sock, CNPacketData* data) { static void ziplinePlayer(CNSocket* sock, CNPacketData* data) {
if (data->size != sizeof(sP_CL2FE_REQ_PC_ZIPLINE))
return; // ignore the malformed packet
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
sP_CL2FE_REQ_PC_ZIPLINE* ziplineData = (sP_CL2FE_REQ_PC_ZIPLINE*)data->buf; sP_CL2FE_REQ_PC_ZIPLINE* ziplineData = (sP_CL2FE_REQ_PC_ZIPLINE*)data->buf;
@ -182,16 +164,13 @@ static void ziplinePlayer(CNSocket* sock, CNPacketData* data) {
ziplineResponse.iRollMax = ziplineData->iRollMax; ziplineResponse.iRollMax = ziplineData->iRollMax;
ziplineResponse.iRoll = ziplineData->iRoll; ziplineResponse.iRoll = ziplineData->iRoll;
PlayerManager::sendToViewable(sock, (void*)&ziplineResponse, P_FE2CL_PC_ZIPLINE, sizeof(sP_FE2CL_PC_ZIPLINE)); PlayerManager::sendToViewable(sock, ziplineResponse, P_FE2CL_PC_ZIPLINE);
} }
static void movePlatformPlayer(CNSocket* sock, CNPacketData* data) { static void movePlatformPlayer(CNSocket* sock, CNPacketData* data) {
if (data->size != sizeof(sP_CL2FE_REQ_PC_MOVEPLATFORM))
return; // ignore the malformed packet
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
sP_CL2FE_REQ_PC_MOVEPLATFORM* platformData = (sP_CL2FE_REQ_PC_MOVEPLATFORM*)data->buf; auto platformData = (sP_CL2FE_REQ_PC_MOVEPLATFORM*)data->buf;
PlayerManager::updatePlayerPosition(sock, platformData->iX, platformData->iY, platformData->iZ, plr->instanceID, platformData->iAngle); PlayerManager::updatePlayerPosition(sock, platformData->iX, platformData->iY, platformData->iZ, plr->instanceID, platformData->iAngle);
uint64_t tm = getTime(); uint64_t tm = getTime();
@ -216,16 +195,13 @@ static void movePlatformPlayer(CNSocket* sock, CNPacketData* data) {
platResponse.cKeyValue = platformData->cKeyValue; platResponse.cKeyValue = platformData->cKeyValue;
platResponse.iPlatformID = platformData->iPlatformID; platResponse.iPlatformID = platformData->iPlatformID;
PlayerManager::sendToViewable(sock, (void*)&platResponse, P_FE2CL_PC_MOVEPLATFORM, sizeof(sP_FE2CL_PC_MOVEPLATFORM)); PlayerManager::sendToViewable(sock, platResponse, P_FE2CL_PC_MOVEPLATFORM);
} }
static void moveSliderPlayer(CNSocket* sock, CNPacketData* data) { static void moveSliderPlayer(CNSocket* sock, CNPacketData* data) {
if (data->size != sizeof(sP_CL2FE_REQ_PC_MOVETRANSPORTATION))
return; // ignore the malformed packet
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
sP_CL2FE_REQ_PC_MOVETRANSPORTATION* sliderData = (sP_CL2FE_REQ_PC_MOVETRANSPORTATION*)data->buf; auto sliderData = (sP_CL2FE_REQ_PC_MOVETRANSPORTATION*)data->buf;
PlayerManager::updatePlayerPosition(sock, sliderData->iX, sliderData->iY, sliderData->iZ, plr->instanceID, sliderData->iAngle); PlayerManager::updatePlayerPosition(sock, sliderData->iX, sliderData->iY, sliderData->iZ, plr->instanceID, sliderData->iAngle);
uint64_t tm = getTime(); uint64_t tm = getTime();
@ -249,13 +225,10 @@ static void moveSliderPlayer(CNSocket* sock, CNPacketData* data) {
sliderResponse.cKeyValue = sliderData->cKeyValue; sliderResponse.cKeyValue = sliderData->cKeyValue;
sliderResponse.iT_ID = sliderData->iT_ID; sliderResponse.iT_ID = sliderData->iT_ID;
PlayerManager::sendToViewable(sock, (void*)&sliderResponse, P_FE2CL_PC_MOVETRANSPORTATION, sizeof(sP_FE2CL_PC_MOVETRANSPORTATION)); PlayerManager::sendToViewable(sock, sliderResponse, P_FE2CL_PC_MOVETRANSPORTATION);
} }
static void moveSlopePlayer(CNSocket* sock, CNPacketData* data) { static void moveSlopePlayer(CNSocket* sock, CNPacketData* data) {
if (data->size != sizeof(sP_CL2FE_REQ_PC_SLOPE))
return; // ignore the malformed packet
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
sP_CL2FE_REQ_PC_SLOPE* slopeData = (sP_CL2FE_REQ_PC_SLOPE*)data->buf; sP_CL2FE_REQ_PC_SLOPE* slopeData = (sP_CL2FE_REQ_PC_SLOPE*)data->buf;
@ -279,7 +252,7 @@ static void moveSlopePlayer(CNSocket* sock, CNPacketData* data) {
slopeResponse.cKeyValue = slopeData->cKeyValue; slopeResponse.cKeyValue = slopeData->cKeyValue;
slopeResponse.iSlopeID = slopeData->iSlopeID; slopeResponse.iSlopeID = slopeData->iSlopeID;
PlayerManager::sendToViewable(sock, (void*)&slopeResponse, P_FE2CL_PC_SLOPE, sizeof(sP_FE2CL_PC_SLOPE)); PlayerManager::sendToViewable(sock, slopeResponse, P_FE2CL_PC_SLOPE);
} }
void PlayerMovement::init() { void PlayerMovement::init() {