Removed redundant checks for a nullptr from PlayerManager::getPlayer()

These were written in desparation and never should have been there in
the first place.
This commit is contained in:
dongresource 2020-12-01 20:18:01 +01:00
parent c43a3d64fb
commit 1e822f7a6c
10 changed files with 21 additions and 161 deletions

View File

@ -74,13 +74,6 @@ void CNShardServer::_killConnection(CNSocket* cns) {
Player* plr = PlayerManager::getPlayer(cns); Player* plr = PlayerManager::getPlayer(cns);
if (plr == nullptr) { // this shouldn't happen if everything works correctly...
PlayerManager::removePlayer(cns);
// also, hopefully the player's progress was already saved since the last db save interval, but rip those 2 mins of progress lol
return;
}
int64_t key = plr->SerialKey; int64_t key = plr->SerialKey;
PlayerManager::removePlayer(cns); // removes the player from the list and saves it to DB PlayerManager::removePlayer(cns); // removes the player from the list and saves it to DB

View File

@ -69,8 +69,6 @@ void levelCommand(std::string full, std::vector<std::string>& args, CNSocket* so
} }
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
char *tmp; char *tmp;
int level = std::strtol(args[1].c_str(), &tmp, 10); int level = std::strtol(args[1].c_str(), &tmp, 10);
@ -210,7 +208,7 @@ void summonWCommand(std::string full, std::vector<std::string>& args, CNSocket*
} }
// permission & sanity check // permission & sanity check
if (plr == nullptr || type >= 3314) if (type >= 3314)
return; return;
int team = NPCManager::NPCData[type]["m_iTeam"]; int team = NPCManager::NPCData[type]["m_iTeam"];
@ -514,9 +512,6 @@ void eggCommand(std::string full, std::vector<std::string>& args, CNSocket* sock
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
// some math to place egg nicely in front of the player // some math to place egg nicely in front of the player
// temporarly disabled for sake of gruntwork // temporarly disabled for sake of gruntwork
int addX = 0; //-500.0f * sin(plr->angle / 180.0f * M_PI); int addX = 0; //-500.0f * sin(plr->angle / 180.0f * M_PI);

View File

@ -28,7 +28,7 @@ void GroupManager::requestGroup(CNSocket* sock, CNPacketData* data) {
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
Player* otherPlr = PlayerManager::getPlayerFromID(recv->iID_To); Player* otherPlr = PlayerManager::getPlayerFromID(recv->iID_To);
if (plr == nullptr || otherPlr == nullptr) if (otherPlr == nullptr)
return; return;
otherPlr = PlayerManager::getPlayerFromID(otherPlr->iIDGroup); otherPlr = PlayerManager::getPlayerFromID(otherPlr->iIDGroup);
@ -68,9 +68,6 @@ void GroupManager::refuseGroup(CNSocket* sock, CNPacketData* data) {
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
INITSTRUCT(sP_FE2CL_PC_GROUP_INVITE_REFUSE, resp); INITSTRUCT(sP_FE2CL_PC_GROUP_INVITE_REFUSE, resp);
resp.iID_To = plr->iID; resp.iID_To = plr->iID;
@ -86,7 +83,7 @@ void GroupManager::joinGroup(CNSocket* sock, CNPacketData* data) {
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
Player* otherPlr = PlayerManager::getPlayerFromID(recv->iID_From); Player* otherPlr = PlayerManager::getPlayerFromID(recv->iID_From);
if (plr == nullptr || otherPlr == nullptr) if (otherPlr == nullptr)
return; return;
otherPlr = PlayerManager::getPlayerFromID(otherPlr->iIDGroup); otherPlr = PlayerManager::getPlayerFromID(otherPlr->iIDGroup);
@ -159,10 +156,6 @@ void GroupManager::joinGroup(CNSocket* sock, CNPacketData* data) {
void GroupManager::leaveGroup(CNSocket* sock, CNPacketData* data) { void GroupManager::leaveGroup(CNSocket* sock, CNPacketData* data) {
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
groupKickPlayer(plr); groupKickPlayer(plr);
} }
@ -174,11 +167,11 @@ void GroupManager::chatGroup(CNSocket* sock, CNPacketData* data) {
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
Player* otherPlr = PlayerManager::getPlayerFromID(plr->iIDGroup); Player* otherPlr = PlayerManager::getPlayerFromID(plr->iIDGroup);
std::string fullChat = ChatManager::sanitizeText(U16toU8(chat->szFreeChat)); if (otherPlr == nullptr)
if (plr == nullptr || otherPlr == nullptr)
return; return;
std::string fullChat = ChatManager::sanitizeText(U16toU8(chat->szFreeChat));
// send to client // send to client
INITSTRUCT(sP_FE2CL_REP_SEND_ALL_GROUP_FREECHAT_MESSAGE_SUCC, resp); INITSTRUCT(sP_FE2CL_REP_SEND_ALL_GROUP_FREECHAT_MESSAGE_SUCC, resp);
@ -197,11 +190,11 @@ void GroupManager::menuChatGroup(CNSocket* sock, CNPacketData* data) {
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
Player* otherPlr = PlayerManager::getPlayerFromID(plr->iIDGroup); Player* otherPlr = PlayerManager::getPlayerFromID(plr->iIDGroup);
std::string fullChat = ChatManager::sanitizeText(U16toU8(chat->szFreeChat)); if (otherPlr == nullptr)
if (plr == nullptr || otherPlr == nullptr)
return; return;
std::string fullChat = ChatManager::sanitizeText(U16toU8(chat->szFreeChat));
// send to client // send to client
INITSTRUCT(sP_FE2CL_REP_SEND_ALL_GROUP_MENUCHAT_MESSAGE_SUCC, resp); INITSTRUCT(sP_FE2CL_REP_SEND_ALL_GROUP_MENUCHAT_MESSAGE_SUCC, resp);

View File

@ -234,7 +234,7 @@ void ItemManager::itemUseHandler(CNSocket* sock, CNPacketData* data) {
sP_CL2FE_REQ_ITEM_USE* request = (sP_CL2FE_REQ_ITEM_USE*)data->buf; sP_CL2FE_REQ_ITEM_USE* request = (sP_CL2FE_REQ_ITEM_USE*)data->buf;
Player* player = PlayerManager::getPlayer(sock); Player* player = PlayerManager::getPlayer(sock);
if (player == nullptr || request->iSlotNum < 0 || request->iSlotNum >= AINVEN_COUNT) if (request->iSlotNum < 0 || request->iSlotNum >= AINVEN_COUNT)
return; // sanity check return; // sanity check
// gumball can only be used from inventory, so we ignore eIL // gumball can only be used from inventory, so we ignore eIL
@ -840,9 +840,6 @@ void ItemManager::chestOpenHandler(CNSocket *sock, CNPacketData *data) {
INITSTRUCT(sP_FE2CL_REP_ITEM_CHEST_OPEN_SUCC, resp); INITSTRUCT(sP_FE2CL_REP_ITEM_CHEST_OPEN_SUCC, resp);
resp.iSlotNum = chest->iSlotNum; resp.iSlotNum = chest->iSlotNum;
if (plr == nullptr)
return;
// item giving packet // item giving packet
const size_t resplen = sizeof(sP_FE2CL_REP_REWARD_ITEM) + sizeof(sItemReward); const size_t resplen = sizeof(sP_FE2CL_REP_REWARD_ITEM) + sizeof(sItemReward);
assert(resplen < CN_PACKET_BUFFER_SIZE - 8); assert(resplen < CN_PACKET_BUFFER_SIZE - 8);

View File

@ -67,9 +67,6 @@ void MissionManager::taskStart(CNSocket* sock, CNPacketData* data) {
INITSTRUCT(sP_FE2CL_REP_PC_TASK_START_SUCC, response); INITSTRUCT(sP_FE2CL_REP_PC_TASK_START_SUCC, response);
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
if (!startTask(plr, missionData->iTaskNum, false)) { if (!startTask(plr, missionData->iTaskNum, false)) {
// TODO: TASK_FAIL? // TODO: TASK_FAIL?
response.iTaskNum = missionData->iTaskNum; response.iTaskNum = missionData->iTaskNum;
@ -138,9 +135,6 @@ void MissionManager::taskEnd(CNSocket* sock, CNPacketData* data) {
bool MissionManager::endTask(CNSocket *sock, int32_t taskNum) { bool MissionManager::endTask(CNSocket *sock, int32_t taskNum) {
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return false;
if (Tasks.find(taskNum) == Tasks.end()) if (Tasks.find(taskNum) == Tasks.end())
return false; return false;
@ -207,9 +201,6 @@ void MissionManager::setMission(CNSocket* sock, CNPacketData* data) {
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
sP_CL2FE_REQ_PC_SET_CURRENT_MISSION_ID* missionData = (sP_CL2FE_REQ_PC_SET_CURRENT_MISSION_ID*)data->buf; sP_CL2FE_REQ_PC_SET_CURRENT_MISSION_ID* missionData = (sP_CL2FE_REQ_PC_SET_CURRENT_MISSION_ID*)data->buf;
INITSTRUCT(sP_FE2CL_REP_PC_SET_CURRENT_MISSION_ID, response); INITSTRUCT(sP_FE2CL_REP_PC_SET_CURRENT_MISSION_ID, response);
response.iCurrentMissionID = missionData->iCurrentMissionID; response.iCurrentMissionID = missionData->iCurrentMissionID;
@ -229,7 +220,7 @@ void MissionManager::quitMission(CNSocket* sock, CNPacketData* data) {
void MissionManager::quitTask(CNSocket* sock, int32_t taskNum, bool manual) { void MissionManager::quitTask(CNSocket* sock, int32_t taskNum, bool manual) {
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
if (plr == nullptr || Tasks.find(taskNum) == Tasks.end()) if (Tasks.find(taskNum) == Tasks.end())
return; // sanity check return; // sanity check
// update player // update player
@ -300,9 +291,6 @@ void MissionManager::dropQuestItem(CNSocket *sock, int task, int count, int id,
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
uint8_t respbuf[resplen]; // not a variable length array, don't worry uint8_t respbuf[resplen]; // not a variable length array, don't worry
sP_FE2CL_REP_REWARD_ITEM *reward = (sP_FE2CL_REP_REWARD_ITEM *)respbuf; sP_FE2CL_REP_REWARD_ITEM *reward = (sP_FE2CL_REP_REWARD_ITEM *)respbuf;
sItemReward *item = (sItemReward *)(respbuf + sizeof(sP_FE2CL_REP_REWARD_ITEM)); sItemReward *item = (sItemReward *)(respbuf + sizeof(sP_FE2CL_REP_REWARD_ITEM));
@ -354,9 +342,6 @@ int MissionManager::giveMissionReward(CNSocket *sock, int task) {
Reward *reward = Rewards[task]; Reward *reward = Rewards[task];
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return -1;
int nrewards = 0; int nrewards = 0;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (reward->itemIds[i] != 0) if (reward->itemIds[i] != 0)
@ -438,9 +423,6 @@ int MissionManager::giveMissionReward(CNSocket *sock, int task) {
void MissionManager::updateFusionMatter(CNSocket* sock, int fusion) { void MissionManager::updateFusionMatter(CNSocket* sock, int fusion) {
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
plr->fusionmatter += fusion; plr->fusionmatter += fusion;
// there's a much lower FM cap in the Future // there's a much lower FM cap in the Future
@ -481,9 +463,6 @@ void MissionManager::updateFusionMatter(CNSocket* sock, int fusion) {
void MissionManager::mobKilled(CNSocket *sock, int mobid) { void MissionManager::mobKilled(CNSocket *sock, int mobid) {
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
bool missionmob = false; bool missionmob = false;
for (int i = 0; i < ACTIVE_MISSION_COUNT; i++) { for (int i = 0; i < ACTIVE_MISSION_COUNT; i++) {
@ -545,9 +524,6 @@ void MissionManager::saveMission(Player* player, int missionId) {
bool MissionManager::isQuestItemFull(CNSocket* sock, int itemId, int itemCount) { bool MissionManager::isQuestItemFull(CNSocket* sock, int itemId, int itemCount) {
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return true;
int slot = findQSlot(plr, itemId); int slot = findQSlot(plr, itemId);
if (slot == -1) { if (slot == -1) {
// this should never happen // this should never happen

View File

@ -43,9 +43,6 @@ void MobManager::pcAttackNpcs(CNSocket *sock, CNPacketData *data) {
sP_CL2FE_REQ_PC_ATTACK_NPCs* pkt = (sP_CL2FE_REQ_PC_ATTACK_NPCs*)data->buf; sP_CL2FE_REQ_PC_ATTACK_NPCs* pkt = (sP_CL2FE_REQ_PC_ATTACK_NPCs*)data->buf;
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
// sanity check // sanity check
if (!validInVarPacket(sizeof(sP_CL2FE_REQ_PC_ATTACK_NPCs), pkt->iNPCCnt, sizeof(int32_t), data->size)) { 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"; std::cout << "[WARN] bad sP_CL2FE_REQ_PC_ATTACK_NPCs packet size\n";
@ -122,9 +119,6 @@ void MobManager::pcAttackNpcs(CNSocket *sock, CNPacketData *data) {
void MobManager::npcAttackPc(Mob *mob, time_t currTime) { void MobManager::npcAttackPc(Mob *mob, time_t currTime) {
Player *plr = PlayerManager::getPlayer(mob->target); Player *plr = PlayerManager::getPlayer(mob->target);
if (plr == nullptr)
return;
const size_t resplen = sizeof(sP_FE2CL_PC_ATTACK_NPCs_SUCC) + sizeof(sAttackResult); const size_t resplen = sizeof(sP_FE2CL_PC_ATTACK_NPCs_SUCC) + sizeof(sAttackResult);
assert(resplen < CN_PACKET_BUFFER_SIZE - 8); assert(resplen < CN_PACKET_BUFFER_SIZE - 8);
uint8_t respbuf[CN_PACKET_BUFFER_SIZE]; uint8_t respbuf[CN_PACKET_BUFFER_SIZE];
@ -158,9 +152,6 @@ void MobManager::npcAttackPc(Mob *mob, time_t currTime) {
void MobManager::giveReward(CNSocket *sock, Mob* mob) { void MobManager::giveReward(CNSocket *sock, Mob* mob) {
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
const size_t resplen = sizeof(sP_FE2CL_REP_REWARD_ITEM) + sizeof(sItemReward); const size_t resplen = sizeof(sP_FE2CL_REP_REWARD_ITEM) + sizeof(sItemReward);
assert(resplen < CN_PACKET_BUFFER_SIZE - 8); assert(resplen < CN_PACKET_BUFFER_SIZE - 8);
// we know it's only one trailing struct, so we can skip full validation // we know it's only one trailing struct, so we can skip full validation
@ -391,20 +382,17 @@ void MobManager::killMob(CNSocket *sock, Mob *mob) {
if (sock != nullptr) { if (sock != nullptr) {
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
if (plr->groupCnt == 1 && plr->iIDGroup == plr->iID) { if (plr->groupCnt == 1 && plr->iIDGroup == plr->iID) {
giveReward(sock, mob); giveReward(sock, mob);
MissionManager::mobKilled(sock, mob->appearanceData.iNPCType); MissionManager::mobKilled(sock, mob->appearanceData.iNPCType);
} else { } else {
plr = PlayerManager::getPlayerFromID(plr->iIDGroup); Player* otherPlayer = PlayerManager::getPlayerFromID(plr->iIDGroup);
if (plr == nullptr) if (otherPlayer == nullptr)
return; return;
for (int i = 0; i < plr->groupCnt; i++) { for (int i = 0; i < otherPlayer->groupCnt; i++) {
CNSocket* sockTo = PlayerManager::getSockFromID(plr->groupIDs[i]); CNSocket* sockTo = PlayerManager::getSockFromID(otherPlayer->groupIDs[i]);
giveReward(sockTo, mob); giveReward(sockTo, mob);
MissionManager::mobKilled(sockTo, mob->appearanceData.iNPCType); MissionManager::mobKilled(sockTo, mob->appearanceData.iNPCType);
} }
@ -509,9 +497,6 @@ void MobManager::combatStep(Mob *mob, time_t currTime) {
Player *plr = PlayerManager::getPlayer(mob->target); Player *plr = PlayerManager::getPlayer(mob->target);
if (plr == nullptr)
return;
// did something else kill the player in the mean time? // did something else kill the player in the mean time?
if (plr->HP <= 0) { if (plr->HP <= 0) {
mob->target = nullptr; mob->target = nullptr;
@ -834,11 +819,6 @@ std::pair<int,int> MobManager::lerp(int x1, int y1, int x2, int y2, int speed) {
void MobManager::combatBegin(CNSocket *sock, CNPacketData *data) { void MobManager::combatBegin(CNSocket *sock, CNPacketData *data) {
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr) {
std::cout << "[WARN] combatBegin: null player!" << std::endl;
return;
}
plr->inCombat = true; plr->inCombat = true;
// HACK: make sure the player has the right weapon out for combat // HACK: make sure the player has the right weapon out for combat
@ -864,11 +844,6 @@ void MobManager::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;
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr) {
std::cout << "[WARN] dotDamageOnOff: null player!" << std::endl;
return;
}
if ((plr->iConditionBitFlag & CSB_BIT_INFECTION) != (bool)pkt->iFlag) if ((plr->iConditionBitFlag & CSB_BIT_INFECTION) != (bool)pkt->iFlag)
plr->iConditionBitFlag ^= CSB_BIT_INFECTION; plr->iConditionBitFlag ^= CSB_BIT_INFECTION;
@ -888,9 +863,6 @@ void MobManager::dealGooDamage(CNSocket *sock, int amount) {
uint8_t respbuf[CN_PACKET_BUFFER_SIZE]; uint8_t respbuf[CN_PACKET_BUFFER_SIZE];
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
memset(respbuf, 0, resplen); memset(respbuf, 0, resplen);
sP_FE2CL_CHAR_TIME_BUFF_TIME_TICK *pkt = (sP_FE2CL_CHAR_TIME_BUFF_TIME_TICK*)respbuf; sP_FE2CL_CHAR_TIME_BUFF_TIME_TICK *pkt = (sP_FE2CL_CHAR_TIME_BUFF_TIME_TICK*)respbuf;
@ -1043,9 +1015,6 @@ void MobManager::pcAttackChars(CNSocket *sock, CNPacketData *data) {
sP_CL2FE_REQ_PC_ATTACK_CHARs* pkt = (sP_CL2FE_REQ_PC_ATTACK_CHARs*)data->buf; sP_CL2FE_REQ_PC_ATTACK_CHARs* pkt = (sP_CL2FE_REQ_PC_ATTACK_CHARs*)data->buf;
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
// Unlike the attack mob packet, attacking players packet has an 8-byte trail (Instead of 4 bytes). // Unlike the attack mob packet, attacking players packet has an 8-byte trail (Instead of 4 bytes).
if (!validInVarPacket(sizeof(sP_CL2FE_REQ_PC_ATTACK_CHARs), pkt->iTargetCnt, sizeof(int32_t) * 2, data->size)) { if (!validInVarPacket(sizeof(sP_CL2FE_REQ_PC_ATTACK_CHARs), pkt->iTargetCnt, sizeof(int32_t) * 2, data->size)) {
std::cout << "[WARN] bad sP_CL2FE_REQ_PC_ATTACK_CHARs packet size\n"; std::cout << "[WARN] bad sP_CL2FE_REQ_PC_ATTACK_CHARs packet size\n";
@ -1345,9 +1314,6 @@ void MobManager::projectileHit(CNSocket* sock, CNPacketData* data) {
sP_CL2FE_REQ_PC_ROCKET_STYLE_HIT* pkt = (sP_CL2FE_REQ_PC_ROCKET_STYLE_HIT*)data->buf; sP_CL2FE_REQ_PC_ROCKET_STYLE_HIT* pkt = (sP_CL2FE_REQ_PC_ROCKET_STYLE_HIT*)data->buf;
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
if (pkt->iTargetCnt == 0) { if (pkt->iTargetCnt == 0) {
Bullets[plr->iID].erase(pkt->iBulletID); Bullets[plr->iID].erase(pkt->iBulletID);
// no targets hit, don't send response // no targets hit, don't send response

View File

@ -120,9 +120,6 @@ void NPCManager::npcVendorBuy(CNSocket* sock, CNPacketData* data) {
sP_CL2FE_REQ_PC_VENDOR_ITEM_BUY* req = (sP_CL2FE_REQ_PC_VENDOR_ITEM_BUY*)data->buf; sP_CL2FE_REQ_PC_VENDOR_ITEM_BUY* req = (sP_CL2FE_REQ_PC_VENDOR_ITEM_BUY*)data->buf;
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
Item* item = ItemManager::getItemData(req->Item.iID, req->Item.iType); Item* item = ItemManager::getItemData(req->Item.iID, req->Item.iType);
if (item == nullptr) { if (item == nullptr) {
@ -172,9 +169,6 @@ void NPCManager::npcVendorSell(CNSocket* sock, CNPacketData* data) {
sP_CL2FE_REQ_PC_VENDOR_ITEM_SELL* req = (sP_CL2FE_REQ_PC_VENDOR_ITEM_SELL*)data->buf; sP_CL2FE_REQ_PC_VENDOR_ITEM_SELL* req = (sP_CL2FE_REQ_PC_VENDOR_ITEM_SELL*)data->buf;
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
if (req->iInvenSlotNum < 0 || req->iInvenSlotNum >= AINVEN_COUNT || req->iItemCnt < 0) { if (req->iInvenSlotNum < 0 || req->iInvenSlotNum >= AINVEN_COUNT || req->iItemCnt < 0) {
std::cout << "[WARN] Client failed to sell item in slot " << req->iInvenSlotNum << std::endl; std::cout << "[WARN] Client failed to sell item in slot " << req->iInvenSlotNum << std::endl;
INITSTRUCT(sP_FE2CL_REP_PC_VENDOR_ITEM_SELL_FAIL, failResp); INITSTRUCT(sP_FE2CL_REP_PC_VENDOR_ITEM_SELL_FAIL, failResp);
@ -231,9 +225,6 @@ void NPCManager::npcVendorBuyback(CNSocket* sock, CNPacketData* data) {
sP_CL2FE_REQ_PC_VENDOR_ITEM_RESTORE_BUY* req = (sP_CL2FE_REQ_PC_VENDOR_ITEM_RESTORE_BUY*)data->buf; sP_CL2FE_REQ_PC_VENDOR_ITEM_RESTORE_BUY* req = (sP_CL2FE_REQ_PC_VENDOR_ITEM_RESTORE_BUY*)data->buf;
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
Item* item = ItemManager::getItemData(req->Item.iID, req->Item.iType); Item* item = ItemManager::getItemData(req->Item.iID, req->Item.iType);
if (item == nullptr) { if (item == nullptr) {
@ -325,9 +316,6 @@ void NPCManager::npcVendorBuyBattery(CNSocket* sock, CNPacketData* data) {
sP_CL2FE_REQ_PC_VENDOR_BATTERY_BUY* req = (sP_CL2FE_REQ_PC_VENDOR_BATTERY_BUY*)data->buf; sP_CL2FE_REQ_PC_VENDOR_BATTERY_BUY* req = (sP_CL2FE_REQ_PC_VENDOR_BATTERY_BUY*)data->buf;
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
int cost = req->Item.iOpt * 100; int cost = req->Item.iOpt * 100;
if ((req->Item.iID == 3 ? (plr->batteryW >= 9999) : (plr->batteryN >= 9999)) || plr->money < cost) { // sanity check if ((req->Item.iID == 3 ? (plr->batteryW >= 9999) : (plr->batteryN >= 9999)) || plr->money < cost) { // sanity check
INITSTRUCT(sP_FE2CL_REP_PC_VENDOR_BATTERY_BUY_FAIL, failResp); INITSTRUCT(sP_FE2CL_REP_PC_VENDOR_BATTERY_BUY_FAIL, failResp);
@ -364,9 +352,6 @@ void NPCManager::npcCombineItems(CNSocket* sock, CNPacketData* data) {
sP_CL2FE_REQ_PC_ITEM_COMBINATION* req = (sP_CL2FE_REQ_PC_ITEM_COMBINATION*)data->buf; sP_CL2FE_REQ_PC_ITEM_COMBINATION* req = (sP_CL2FE_REQ_PC_ITEM_COMBINATION*)data->buf;
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
if (req->iCostumeItemSlot < 0 || req->iCostumeItemSlot >= AINVEN_COUNT || req->iStatItemSlot < 0 || req->iStatItemSlot >= AINVEN_COUNT) { // sanity check 1 if (req->iCostumeItemSlot < 0 || req->iCostumeItemSlot >= AINVEN_COUNT || req->iStatItemSlot < 0 || req->iStatItemSlot >= AINVEN_COUNT) { // sanity check 1
INITSTRUCT(sP_FE2CL_REP_PC_ITEM_COMBINATION_FAIL, failResp); INITSTRUCT(sP_FE2CL_REP_PC_ITEM_COMBINATION_FAIL, failResp);
failResp.iCostumeItemSlot = req->iCostumeItemSlot; failResp.iCostumeItemSlot = req->iCostumeItemSlot;
@ -454,7 +439,7 @@ void NPCManager::npcUnsummonHandler(CNSocket* sock, CNPacketData* data) {
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
if (plr == nullptr || plr->accountLevel > 30) if (plr->accountLevel > 30)
return; return;
sP_CL2FE_REQ_NPC_UNSUMMON* req = (sP_CL2FE_REQ_NPC_UNSUMMON*)data->buf; sP_CL2FE_REQ_NPC_UNSUMMON* req = (sP_CL2FE_REQ_NPC_UNSUMMON*)data->buf;
@ -469,7 +454,7 @@ void NPCManager::npcSummonHandler(CNSocket* sock, CNPacketData* data) {
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
// permission & sanity check // permission & sanity check
if (plr == nullptr || plr->accountLevel > 30 || req->iNPCType >= 3314 || req->iNPCCnt > 100) if (plr->accountLevel > 30 || req->iNPCType >= 3314 || req->iNPCCnt > 100)
return; return;
int team = NPCData[req->iNPCType]["m_iTeam"]; int team = NPCData[req->iNPCType]["m_iTeam"];

View File

@ -33,7 +33,7 @@ void NanoManager::nanoEquipHandler(CNSocket* sock, CNPacketData* data) {
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
// sanity checks // sanity checks
if (plr == nullptr || nano->iNanoSlotNum > 2 || nano->iNanoSlotNum < 0) if (nano->iNanoSlotNum > 2 || nano->iNanoSlotNum < 0)
return; return;
resp.iNanoID = nano->iNanoID; resp.iNanoID = nano->iNanoID;
@ -70,7 +70,7 @@ void NanoManager::nanoUnEquipHandler(CNSocket* sock, CNPacketData* data) {
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
// sanity check // sanity check
if (plr == nullptr || nano->iNanoSlotNum > 2 || nano->iNanoSlotNum < 0) if (nano->iNanoSlotNum > 2 || nano->iNanoSlotNum < 0)
return; return;
resp.iNanoSlotNum = nano->iNanoSlotNum; resp.iNanoSlotNum = nano->iNanoSlotNum;
@ -93,9 +93,6 @@ void NanoManager::nanoGMGiveHandler(CNSocket* sock, CNPacketData* data) {
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);
if (plr == nullptr)
return;
// Add nano to player // Add nano to player
addNano(sock, nano->iNanoID, 0); addNano(sock, nano->iNanoID, 0);
@ -111,9 +108,6 @@ void NanoManager::nanoSummonHandler(CNSocket* sock, CNPacketData* data) {
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);
if (plr == nullptr)
return;
summonNano(sock, pkt->iNanoSlotNum); summonNano(sock, pkt->iNanoSlotNum);
// Send to client // Send to client
@ -125,9 +119,6 @@ void NanoManager::nanoSummonHandler(CNSocket* sock, CNPacketData* data) {
void NanoManager::nanoSkillUseHandler(CNSocket* sock, CNPacketData* data) { void NanoManager::nanoSkillUseHandler(CNSocket* sock, CNPacketData* data) {
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
int16_t nanoID = plr->activeNano; int16_t nanoID = plr->activeNano;
int16_t skillID = plr->Nanos[nanoID].iSkillID; int16_t skillID = plr->Nanos[nanoID].iSkillID;
@ -214,7 +205,7 @@ void NanoManager::nanoPotionHandler(CNSocket* sock, CNPacketData* data) {
Player* player = PlayerManager::getPlayer(sock); Player* player = PlayerManager::getPlayer(sock);
// sanity checks // sanity checks
if (player == nullptr || player->activeNano == -1 || player->batteryN == 0) if (player->activeNano == -1 || player->batteryN == 0)
return; return;
sNano nano = player->Nanos[player->activeNano]; sNano nano = player->Nanos[player->activeNano];
@ -244,9 +235,6 @@ void NanoManager::addNano(CNSocket* sock, int16_t nanoID, int16_t slot, bool spe
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
int level = nanoID < plr->level ? plr->level : nanoID; int level = nanoID < plr->level ? plr->level : nanoID;
/* /*
@ -296,7 +284,7 @@ void NanoManager::summonNano(CNSocket *sock, int slot, bool silent) {
resp.iActiveNanoSlotNum = slot; resp.iActiveNanoSlotNum = slot;
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr || slot > 2 || slot < -1) if (slot > 2 || slot < -1)
return; // sanity check return; // sanity check
plr->nanoDrainRate = 0; plr->nanoDrainRate = 0;
@ -354,9 +342,6 @@ void NanoManager::setNanoSkill(CNSocket* sock, sP_CL2FE_REQ_NANO_TUNE* skill) {
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
if (plr->activeNano > 0 && plr->activeNano == skill->iNanoID) if (plr->activeNano > 0 && plr->activeNano == skill->iNanoID)
summonNano(sock, -1); // just unsummon the nano to prevent infinite buffs summonNano(sock, -1); // just unsummon the nano to prevent infinite buffs
@ -428,9 +413,6 @@ void NanoManager::resetNanoSkill(CNSocket* sock, int16_t nanoID) {
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
sNano nano = plr->Nanos[nanoID]; sNano nano = plr->Nanos[nanoID];
// 0 is reset // 0 is reset
@ -441,9 +423,6 @@ void NanoManager::resetNanoSkill(CNSocket* sock, int16_t nanoID) {
void NanoManager::nanoUnbuff(CNSocket* sock, std::vector<int> targetData, int32_t bitFlag, int16_t timeBuffID, int16_t amount, bool groupPower) { void NanoManager::nanoUnbuff(CNSocket* sock, std::vector<int> targetData, int32_t bitFlag, int16_t timeBuffID, int16_t amount, bool groupPower) {
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
plr->iSelfConditionBitFlag &= ~bitFlag; plr->iSelfConditionBitFlag &= ~bitFlag;
int groupFlags = 0; int groupFlags = 0;
@ -692,9 +671,6 @@ bool doDamage(CNSocket *sock, sSkillResult_Damage *respdata, int i, int32_t targ
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return false;
int damage = MobManager::hitMob(sock, mob, PC_MAXHEALTH(plr->level) * amount / 2000 + mob->appearanceData.iHP * amount / 2000); int damage = MobManager::hitMob(sock, mob, PC_MAXHEALTH(plr->level) * amount / 2000 + mob->appearanceData.iHP * amount / 2000);
respdata[i].eCT = 4; respdata[i].eCT = 4;
@ -726,9 +702,6 @@ bool doLeech(CNSocket *sock, sSkillResult_Heal_HP *healdata, int i, int32_t targ
sSkillResult_Damage *damagedata = (sSkillResult_Damage*)(((uint8_t*)healdata) + sizeof(sSkillResult_Heal_HP)); sSkillResult_Damage *damagedata = (sSkillResult_Damage*)(((uint8_t*)healdata) + sizeof(sSkillResult_Heal_HP));
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return false;
int healedAmount = amount; int healedAmount = amount;
plr->HP += healedAmount; plr->HP += healedAmount;
@ -818,9 +791,6 @@ void nanoPower(CNSocket *sock, std::vector<int> targetData,
int16_t skillType, int32_t bitFlag, int16_t timeBuffID) { int16_t skillType, int32_t bitFlag, int16_t timeBuffID) {
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
if (skillType == EST_RETROROCKET_SELF || skillType == EST_RECALL) // rocket and self recall does not need any trailing structs if (skillType == EST_RETROROCKET_SELF || skillType == EST_RECALL) // rocket and self recall does not need any trailing structs
targetData[0] = 0; targetData[0] = 0;

View File

@ -627,9 +627,6 @@ void PlayerManager::setSpecialPlayer(CNSocket* sock, CNPacketData* data) {
sP_CL2FE_GM_REQ_PC_SET_VALUE* setData = (sP_CL2FE_GM_REQ_PC_SET_VALUE*)data->buf; sP_CL2FE_GM_REQ_PC_SET_VALUE* setData = (sP_CL2FE_GM_REQ_PC_SET_VALUE*)data->buf;
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
INITSTRUCT(sP_FE2CL_GM_REP_PC_SET_VALUE, response); INITSTRUCT(sP_FE2CL_GM_REP_PC_SET_VALUE, response);
DEBUGLOG( DEBUGLOG(
@ -696,9 +693,6 @@ void PlayerManager::revivePlayer(CNSocket* sock, CNPacketData* data) {
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
WarpLocation* target = PlayerManager::getRespawnPoint(plr); WarpLocation* target = PlayerManager::getRespawnPoint(plr);
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;
@ -934,9 +928,6 @@ void PlayerManager::setSpecialState(CNSocket* sock, CNPacketData* data) {
Player *plr = getPlayer(sock); Player *plr = getPlayer(sock);
if (plr == nullptr)
return;
sP_CL2FE_GM_REQ_PC_SPECIAL_STATE_SWITCH* setData = (sP_CL2FE_GM_REQ_PC_SPECIAL_STATE_SWITCH*)data->buf; sP_CL2FE_GM_REQ_PC_SPECIAL_STATE_SWITCH* setData = (sP_CL2FE_GM_REQ_PC_SPECIAL_STATE_SWITCH*)data->buf;
// HACK: work around the invisible weapon bug // HACK: work around the invisible weapon bug

View File

@ -29,9 +29,6 @@ void TransportManager::transportRegisterLocationHandler(CNSocket* sock, CNPacket
sP_CL2FE_REQ_REGIST_TRANSPORTATION_LOCATION* transport = (sP_CL2FE_REQ_REGIST_TRANSPORTATION_LOCATION*)data->buf; sP_CL2FE_REQ_REGIST_TRANSPORTATION_LOCATION* transport = (sP_CL2FE_REQ_REGIST_TRANSPORTATION_LOCATION*)data->buf;
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
bool newReg = false; // this is a new registration bool newReg = false; // this is a new registration
//std::cout << "request to register transport, eTT " << transport->eTT << ", locID " << transport->iLocationID << ", npc " << transport->iNPC_ID << std::endl; //std::cout << "request to register transport, eTT " << transport->eTT << ", locID " << transport->iLocationID << ", npc " << transport->iNPC_ID << std::endl;
if (transport->eTT == 1) { // S.C.A.M.P.E.R. if (transport->eTT == 1) { // S.C.A.M.P.E.R.
@ -114,9 +111,6 @@ void TransportManager::transportWarpHandler(CNSocket* sock, CNPacketData* data)
sP_CL2FE_REQ_PC_WARP_USE_TRANSPORTATION* req = (sP_CL2FE_REQ_PC_WARP_USE_TRANSPORTATION*)data->buf; sP_CL2FE_REQ_PC_WARP_USE_TRANSPORTATION* req = (sP_CL2FE_REQ_PC_WARP_USE_TRANSPORTATION*)data->buf;
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return;
/* /*
* req: * req:
* eIL -- inventory type * eIL -- inventory type