From 10534886b8f013b84017fdae4ccb28f7caa3b8c4 Mon Sep 17 00:00:00 2001 From: dongresource Date: Mon, 19 Oct 2020 19:26:14 +0200 Subject: [PATCH] Cleanup for 1.2. Cleaned up whitespace, comments, brace style, etc. Updated tdata reference. --- src/BuddyManager.cpp | 76 ++++++++++++++++++++---------------------- src/BuddyManager.hpp | 54 +++++++++++++++--------------- src/CNLoginServer.cpp | 23 ++++++------- src/CNProtocol.cpp | 6 ++-- src/CNProtocol.hpp | 14 ++++---- src/CNShared.hpp | 6 ++-- src/CNStructs.hpp | 4 +-- src/ChatManager.cpp | 2 +- src/ChunkManager.cpp | 5 ++- src/ChunkManager.hpp | 6 ++-- src/Database.cpp | 53 +++++++++++------------------ src/Database.hpp | 11 +++--- src/GroupManager.cpp | 42 +++++++++++------------ src/ItemManager.cpp | 20 +++++------ src/ItemManager.hpp | 1 - src/MissionManager.cpp | 19 ++++------- src/MissionManager.hpp | 2 +- src/MobManager.cpp | 58 ++++++++++++++++---------------- src/MobManager.hpp | 4 --- src/NPCManager.cpp | 27 ++++++--------- src/NanoManager.cpp | 52 ++++++++++++++--------------- src/PlayerManager.cpp | 19 +++++------ src/TableData.cpp | 14 +++----- tdata | 2 +- 24 files changed, 234 insertions(+), 286 deletions(-) diff --git a/src/BuddyManager.cpp b/src/BuddyManager.cpp index 1f79f73..bc83dee 100644 --- a/src/BuddyManager.cpp +++ b/src/BuddyManager.cpp @@ -22,7 +22,7 @@ void BuddyManager::init() { REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_BUDDY_WARP, reqBuddyWarp); } -//Buddy request +// Buddy request void BuddyManager::requestBuddy(CNSocket* sock, CNPacketData* data) { if (data->size != sizeof(sP_CL2FE_REQ_REQUEST_MAKE_BUDDY)) return; // malformed packet @@ -51,12 +51,12 @@ void BuddyManager::requestBuddy(CNSocket* sock, CNPacketData* data) { resp.iBuddyID = plr.plr->iID; resp.iBuddyPCUID = plr.plr->PCStyle.iPC_UID; - sock->sendPacket((void*)&resp, P_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC)); //informs the player that the request was sent - requestedBuddy(otherSock, plrReq, plr); //The other player will see the request + sock->sendPacket((void*)&resp, P_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC)); // informs the player that the request was sent + requestedBuddy(otherSock, plrReq, plr); // The other player will see the request } -//Sending buddy request by player name +// Sending buddy request by player name void BuddyManager::reqBuddyByName(CNSocket* sock, CNPacketData* data) { if (data->size != sizeof(sP_CL2FE_REQ_PC_FIND_NAME_MAKE_BUDDY)) { return; // malformed packet @@ -72,13 +72,13 @@ void BuddyManager::reqBuddyByName(CNSocket* sock, CNPacketData* data) { CNSocket* otherSock = sock; - int sizeOfRes = sizeof(pkt->szFirstName) / 9; //Maximum size of a player's first name - int sizeOfLNRes = sizeof(pkt->szLastName) / 17; //Maximum size of a player's last name + int sizeOfRes = sizeof(pkt->szFirstName) / 9; // Maximum size of a player's first name + int sizeOfLNRes = sizeof(pkt->szLastName) / 17; // Maximum size of a player's last name for (auto pair : PlayerManager::players) { int sizeOfReq = sizeof(pair.second.plr->PCStyle.szFirstName) / 9; int sizeOfLNReq = sizeof(pair.second.plr->PCStyle.szLastName) / 17; - if (BuddyManager::firstNameCheck(pair.second.plr->PCStyle.szFirstName, pkt->szFirstName, sizeOfReq, sizeOfRes) == true && BuddyManager::lastNameCheck(pair.second.plr->PCStyle.szLastName, pkt->szLastName, sizeOfLNReq, sizeOfLNRes) == true) { //This long line of gorgeous parameters is to check if the player's name matches :eyes: + if (BuddyManager::firstNameCheck(pair.second.plr->PCStyle.szFirstName, pkt->szFirstName, sizeOfReq, sizeOfRes) == true && BuddyManager::lastNameCheck(pair.second.plr->PCStyle.szLastName, pkt->szLastName, sizeOfLNReq, sizeOfLNRes) == true) { // This long line of gorgeous parameters is to check if the player's name matches :eyes: otherSock = pair.first; break; } @@ -93,7 +93,7 @@ void BuddyManager::reqBuddyByName(CNSocket* sock, CNPacketData* data) { } -//Accepting buddy request +// Accepting buddy request void BuddyManager::reqAcceptBuddy(CNSocket* sock, CNPacketData* data) { if (data->size != sizeof(sP_CL2FE_REQ_ACCEPT_MAKE_BUDDY)) return; // malformed packet @@ -118,7 +118,7 @@ void BuddyManager::reqAcceptBuddy(CNSocket* sock, CNPacketData* data) { PlayerView& plr = PlayerManager::players[otherSock]; if (pkt->iAcceptFlag == 1) { - //resp.iBuddySlot = 0; //hard-coding this for now + //resp.iBuddySlot = 0; // hard-coding this for now resp.BuddyInfo.iID = pkt->iBuddyID; resp.BuddyInfo.iPCUID = pkt->iBuddyPCUID; resp.BuddyInfo.iNameCheckFlag = plr.plr->PCStyle.iNameCheck; @@ -131,7 +131,7 @@ void BuddyManager::reqAcceptBuddy(CNSocket* sock, CNPacketData* data) { memcpy(resp.BuddyInfo.szLastName, plr.plr->PCStyle.szLastName, sizeof(plr.plr->PCStyle.szLastName)); sock->sendPacket((void*)&resp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC)); - buddyList(sock, resp.BuddyInfo); //saves buddy data to player's buddylist + buddyList(sock, resp.BuddyInfo); // saves buddy data to player's buddylist if (plr.plr->PCStyle.iPC_UID == pkt->iBuddyPCUID) { resp.BuddyInfo.iID = plrReq->iID; resp.BuddyInfo.iPCUID = plrReq->PCStyle.iPC_UID; @@ -143,21 +143,20 @@ void BuddyManager::reqAcceptBuddy(CNSocket* sock, CNPacketData* data) { memcpy(resp.BuddyInfo.szFirstName, plrReq->PCStyle.szFirstName, sizeof(plrReq->PCStyle.szFirstName)); memcpy(resp.BuddyInfo.szLastName, plrReq->PCStyle.szLastName, sizeof(plrReq->PCStyle.szLastName)); otherSock->sendPacket((void*)&resp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC)); - buddyList(otherSock, resp.BuddyInfo); //saves requester's data to this player's buddylist + buddyList(otherSock, resp.BuddyInfo); // saves requester's data to this player's buddylist } - } - else { + } else { INITSTRUCT(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL, declineResp); - declineResp.iErrorCode = 6; //Buddy declined notification + declineResp.iErrorCode = 6; // Buddy declined notification declineResp.iBuddyID = pkt->iBuddyID; declineResp.iBuddyPCUID = pkt->iBuddyPCUID; - otherSock->sendPacket((void*)&declineResp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL)); //tells the requester that the player declined + otherSock->sendPacket((void*)&declineResp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL)); // tells the requester that the player declined } } -//Accepting buddy request from the find name request +// Accepting buddy request from the find name request void BuddyManager::reqFindNameBuddyAccept(CNSocket* sock, CNPacketData* data) { if (data->size != sizeof(sP_CL2FE_REQ_PC_FIND_NAME_ACCEPT_BUDDY)) { return; // malformed packet @@ -188,7 +187,7 @@ void BuddyManager::reqFindNameBuddyAccept(CNSocket* sock, CNPacketData* data) { PlayerView& plr = PlayerManager::players[otherSock]; if (pkt->iAcceptFlag == 1) { - //resp.iBuddySlot = 0; //hard-coding this for now + //resp.iBuddySlot = 0; // hard-coding this for now //resp.BuddyInfo.iID = plrReq->iID; resp.BuddyInfo.iPCUID = pkt->iBuddyPCUID; resp.BuddyInfo.iNameCheckFlag = plr.plr->PCStyle.iNameCheck; @@ -218,11 +217,10 @@ void BuddyManager::reqFindNameBuddyAccept(CNSocket* sock, CNPacketData* data) { otherSock->sendPacket((void*)&resp, P_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC)); buddyList(otherSock, resp.BuddyInfo); } - } - else { + } else { INITSTRUCT(sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_FAIL, declineResp); - declineResp.iErrorCode = 6; //Buddy declined notification + declineResp.iErrorCode = 6; // Buddy declined notification declineResp.iBuddyID = plr.plr->iID; declineResp.iBuddyPCUID = pkt->iBuddyPCUID; @@ -231,7 +229,7 @@ void BuddyManager::reqFindNameBuddyAccept(CNSocket* sock, CNPacketData* data) { } -//Buddy freechatting +// Buddy freechatting void BuddyManager::reqBuddyFreechat(CNSocket* sock, CNPacketData* data) { if (data->size != sizeof(sP_CL2FE_REQ_SEND_BUDDY_FREECHAT_MESSAGE)) return; // malformed packet @@ -250,19 +248,19 @@ void BuddyManager::reqBuddyFreechat(CNSocket* sock, CNPacketData* data) { resp.iToPCUID = pkt->iBuddyPCUID; resp.iEmoteCode = pkt->iEmoteCode; memcpy(resp.szFreeChat, pkt->szFreeChat, sizeof(pkt->szFreeChat)); - sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC)); //shows the player that they sent the message to their buddy + sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC)); // shows the player that they sent the message to their buddy for (auto pair : PlayerManager::players) { if (pair.second.plr->PCStyle.iPC_UID != plr->PCStyle.iPC_UID) { otherSock = pair.first; - otherSock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC)); //sends the message to the buddy. + otherSock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_BUDDY_FREECHAT_MESSAGE_SUCC)); // sends the message to the buddy. } } } -//Buddy menuchat +// Buddy menuchat void BuddyManager::reqBuddyMenuchat(CNSocket* sock, CNPacketData* data) { if (data->size != sizeof(sP_CL2FE_REQ_SEND_BUDDY_MENUCHAT_MESSAGE)) return; // malformed packet @@ -281,29 +279,29 @@ void BuddyManager::reqBuddyMenuchat(CNSocket* sock, CNPacketData* data) { resp.iToPCUID = pkt->iBuddyPCUID; resp.iEmoteCode = pkt->iEmoteCode; memcpy(resp.szFreeChat, pkt->szFreeChat, sizeof(pkt->szFreeChat)); - sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_BUDDY_MENUCHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_BUDDY_MENUCHAT_MESSAGE_SUCC)); //shows the player that they sent the message to their buddy + sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_BUDDY_MENUCHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_BUDDY_MENUCHAT_MESSAGE_SUCC)); // shows the player that they sent the message to their buddy for (auto pair : PlayerManager::players) { if (pair.second.plr->PCStyle.iPC_UID != plr->PCStyle.iPC_UID) { otherSock = pair.first; - otherSock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_BUDDY_MENUCHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_BUDDY_MENUCHAT_MESSAGE_SUCC)); //sends the message to the buddy. + otherSock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_BUDDY_MENUCHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_BUDDY_MENUCHAT_MESSAGE_SUCC)); // sends the message to the buddy. } } } -//Getting buddy state +// Getting buddy state void BuddyManager::reqPktGetBuddyState(CNSocket* sock, CNPacketData* data) { INITSTRUCT(sP_FE2CL_REP_GET_BUDDY_STATE_SUCC, resp); INITSTRUCT(sBuddyBaseInfo, buddyInfo); for (int BuddySlot = 0; BuddySlot < 50; BuddySlot++) { - resp.aBuddyState[BuddySlot] = 1; //this sets every buddy to online. Will get the pcstate right directly from the DB. + resp.aBuddyState[BuddySlot] = 1; // this sets every buddy to online. Will get the pcstate right directly from the DB. resp.aBuddyID[BuddySlot] = buddyInfo.iID; sock->sendPacket((void*)&resp, P_FE2CL_REP_GET_BUDDY_STATE_SUCC, sizeof(sP_FE2CL_REP_GET_BUDDY_STATE_SUCC)); } } -//Blocking the buddy +// Blocking the buddy void BuddyManager::reqBuddyBlock(CNSocket* sock, CNPacketData* data) { if (data->size != sizeof(sP_CL2FE_REQ_SET_BUDDY_BLOCK)) return; // malformed packet @@ -319,10 +317,10 @@ void BuddyManager::reqBuddyBlock(CNSocket* sock, CNPacketData* data) { } -//Deleting the buddy +// Deleting the buddy void BuddyManager::reqBuddyDelete(CNSocket* sock, CNPacketData* data) { if (data->size != sizeof(sP_CL2FE_REQ_REMOVE_BUDDY)) - return; //malformed packet + return; // malformed packet sP_CL2FE_REQ_REMOVE_BUDDY* pkt = (sP_CL2FE_REQ_REMOVE_BUDDY*)data->buf; @@ -334,8 +332,8 @@ void BuddyManager::reqBuddyDelete(CNSocket* sock, CNPacketData* data) { sock->sendPacket((void*)&resp, P_FE2CL_REP_REMOVE_BUDDY_SUCC, sizeof(sP_FE2CL_REP_REMOVE_BUDDY_SUCC)); } -//Warping to buddy -void BuddyManager::reqBuddyWarp(CNSocket* sock, CNPacketData* data) {} //stub +// Warping to buddy +void BuddyManager::reqBuddyWarp(CNSocket* sock, CNPacketData* data) {} // stub #pragma region Helper methods @@ -348,11 +346,11 @@ void BuddyManager::requestedBuddy(CNSocket* sock, Player* plrReq, PlayerView& pl memcpy(resp.szFirstName, plrReq->PCStyle.szFirstName, sizeof(plrReq->PCStyle.szFirstName)); memcpy(resp.szLastName, plrReq->PCStyle.szLastName, sizeof(plrReq->PCStyle.szLastName)); - sock->sendPacket((void*)&resp, P_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC_TO_ACCEPTER, sizeof(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC_TO_ACCEPTER)); //player get the buddy request. + sock->sendPacket((void*)&resp, P_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC_TO_ACCEPTER, sizeof(sP_FE2CL_REP_REQUEST_MAKE_BUDDY_SUCC_TO_ACCEPTER)); // player get the buddy request. } -//Buddy list load +// Buddy list load void BuddyManager::buddyList(CNSocket* sock, sBuddyBaseInfo BuddyInfo) { size_t resplen = sizeof(sP_FE2CL_REP_PC_BUDDYLIST_INFO_SUCC) + sizeof(sBuddyBaseInfo); @@ -378,14 +376,14 @@ void BuddyManager::buddyList(CNSocket* sock, sBuddyBaseInfo BuddyInfo) { memcpy(respdata->szLastName, BuddyInfo.szLastName, sizeof(BuddyInfo.szLastName)); } - sock->sendPacket((void*)respbuf, P_FE2CL_REP_PC_BUDDYLIST_INFO_SUCC, resplen); //updates/loads player's buddy list + sock->sendPacket((void*)respbuf, P_FE2CL_REP_PC_BUDDYLIST_INFO_SUCC, resplen); // updates/loads player's buddy list } -//If the requested player accepts the buddy request, the requester's buddylist will get loaded up. +// If the requested player accepts the buddy request, the requester's buddylist will get loaded up. void BuddyManager::otherAcceptBuddy(CNSocket* sock, int32_t BuddyID, int64_t BuddyPCUID, sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC resp, Player* plr) { - //resp.iBuddySlot = 0; //hard-coding this for now + // resp.iBuddySlot = 0; //hard-coding this for now resp.BuddyInfo.iID = BuddyID; resp.BuddyInfo.iPCUID = BuddyPCUID; resp.BuddyInfo.iNameCheckFlag = plr->PCStyle.iNameCheck; @@ -401,7 +399,7 @@ void BuddyManager::otherAcceptBuddy(CNSocket* sock, int32_t BuddyID, int64_t Bud buddyList(sock, resp.BuddyInfo); } -//Check if the requested name matches the requested player's name +// Check if the requested name matches the requested player's name bool BuddyManager::firstNameCheck(char16_t reqFirstName[], char16_t resFirstName[], int sizeOfReq, int sizeOfRes) { // If lengths of array are not equal means // array are not equal diff --git a/src/BuddyManager.hpp b/src/BuddyManager.hpp index 320d46a..69dd7e5 100644 --- a/src/BuddyManager.hpp +++ b/src/BuddyManager.hpp @@ -1,44 +1,44 @@ -#pragma once - -#include "Player.hpp" -#include "CNProtocol.hpp" -#include "CNStructs.hpp" -#include "CNShardServer.hpp" - -#include -#include - -namespace BuddyManager { - void init(); +#pragma once - //Buddy requests - void requestBuddy(CNSocket* sock, CNPacketData* data); +#include "Player.hpp" +#include "CNProtocol.hpp" +#include "CNStructs.hpp" +#include "CNShardServer.hpp" + +#include +#include + +namespace BuddyManager { + void init(); + + // Buddy requests + void requestBuddy(CNSocket* sock, CNPacketData* data); void reqBuddyByName(CNSocket* sock, CNPacketData* data); - //Buddy accepting + // Buddy accepting void reqAcceptBuddy(CNSocket* sock, CNPacketData* data); void reqFindNameBuddyAccept(CNSocket* sock, CNPacketData* data); - //Buddy Messaging + // Buddy Messaging void reqBuddyFreechat(CNSocket* sock, CNPacketData* data); void reqBuddyMenuchat(CNSocket* sock, CNPacketData* data); - //Getting buddy state + // Getting buddy state void reqPktGetBuddyState(CNSocket* sock, CNPacketData* data); - //Blocking/removing buddies + // Blocking/removing buddies void reqBuddyBlock(CNSocket* sock, CNPacketData* data); void reqBuddyDelete(CNSocket* sock, CNPacketData* data); - //Buddy warping + // Buddy warping void reqBuddyWarp(CNSocket* sock, CNPacketData* data); - - //helper methods - void requestedBuddy(CNSocket* sock, Player* plrReq, PlayerView& plr); - void buddyList(CNSocket* sock, sBuddyBaseInfo BuddyInfo); //updates the buddylist - void otherAcceptBuddy(CNSocket* sock, int32_t BuddyID, int64_t BuddyPCUID, sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC resp, Player* plr); //tells the other player that they are now buddies with the requester. - //Name checks - bool firstNameCheck(char16_t reqFirstName[], char16_t resFirstName[], int sizeOfReq, int sizeOfRes); //checks if the request and requested player's first names match - bool lastNameCheck(char16_t reqLastName[], char16_t resLastName[], int sizeOfLNReq, int sizeOfLNRes); //checks if the request and requested player's last names match + // helper methods + void requestedBuddy(CNSocket* sock, Player* plrReq, PlayerView& plr); + void buddyList(CNSocket* sock, sBuddyBaseInfo BuddyInfo); // updates the buddylist + void otherAcceptBuddy(CNSocket* sock, int32_t BuddyID, int64_t BuddyPCUID, sP_FE2CL_REP_ACCEPT_MAKE_BUDDY_SUCC resp, Player* plr); // tells the other player that they are now buddies with the requester. + + // Name checks + bool firstNameCheck(char16_t reqFirstName[], char16_t resFirstName[], int sizeOfReq, int sizeOfRes); // checks if the request and requested player's first names match + bool lastNameCheck(char16_t reqLastName[], char16_t resLastName[], int sizeOfLNReq, int sizeOfLNRes); // checks if the request and requested player's last names match } diff --git a/src/CNLoginServer.cpp b/src/CNLoginServer.cpp index 91c75e2..d3a8362 100644 --- a/src/CNLoginServer.cpp +++ b/src/CNLoginServer.cpp @@ -57,27 +57,23 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { loginSessions[sock].slot = 1; loginSessions[sock].lastHeartbeat = getTime(); success = true; - } + // if user exists, check if password is correct - else if (CNLoginServer::isPasswordCorrect(findUser->Password, userPassword)) { + } else if (CNLoginServer::isPasswordCorrect(findUser->Password, userPassword)) { /*calling this here to timestamp login attempt, * in order to make duplicate exit sanity check work*/ Database::updateSelected(findUser->AccountID, findUser->Selected); // check if account isn't currently in use if (CNLoginServer::isAccountInUse(findUser->AccountID)) { errorCode = (int)LoginError::ID_ALREADY_IN_USE; - } - // if not, login success - else - { + } else { // if not, login success loginSessions[sock] = CNLoginData(); loginSessions[sock].userID = findUser->AccountID; loginSessions[sock].slot = findUser->Selected; loginSessions[sock].lastHeartbeat = getTime(); success = true; } - } - else { + } else { errorCode = (int)LoginError::ID_AND_PASSWORD_DO_NOT_MATCH; } } @@ -369,11 +365,12 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { if (settings::VERBOSITY) std::cerr << "OpenFusion: LOGIN UNIMPLM ERR. PacketType: " << Defines::p2str(CL2LS, data->type) << " (" << data->type << ")" << std::endl; break; - /* Unimplemented CL2LS packets: - P_CL2LS_CHECK_NAME_LIST - unused by the client - P_CL2LS_REQ_SERVER_SELECT - P_CL2LS_REQ_SHARD_LIST_INFO - dev commands, useless as we only run 1 server - */ + /* + * Unimplemented CL2LS packets: + * P_CL2LS_CHECK_NAME_LIST - unused by the client + * P_CL2LS_REQ_SERVER_SELECT + * P_CL2LS_REQ_SHARD_LIST_INFO - dev commands, useless as we only run 1 server + */ } } diff --git a/src/CNProtocol.cpp b/src/CNProtocol.cpp index 7fbb3ed..5e062d3 100644 --- a/src/CNProtocol.cpp +++ b/src/CNProtocol.cpp @@ -9,8 +9,7 @@ int CNSocketEncryption::Encrypt_byte_change_A(int ERSize, uint8_t* data, int siz int num2 = 0; int num3 = 0; - while (num + ERSize <= size) - { + while (num + ERSize <= size) { int num4 = num + num3; int num5 = num + (ERSize - 1 - num3); @@ -19,8 +18,7 @@ int CNSocketEncryption::Encrypt_byte_change_A(int ERSize, uint8_t* data, int siz data[num5] = b; num += ERSize; num3++; - if (num3 > ERSize / 2) - { + if (num3 > ERSize / 2) { num3 = 0; } } diff --git a/src/CNProtocol.hpp b/src/CNProtocol.hpp index 2d72ec8..5bc3d9e 100644 --- a/src/CNProtocol.hpp +++ b/src/CNProtocol.hpp @@ -54,13 +54,13 @@ #endif /* - Packets format (sent from the client): - [4 bytes] - size of packet including the 4 byte packet type - [size bytes] - Encrypted packet (byte swapped && xor'd with 8 byte key; see CNSocketEncryption) - [4 bytes] - packet type (which is a combination of the first 4 bytes of the packet and a checksum in some versions) - [structure] - one member contains length of trailing data (expressed in packet-dependant structures) - [trailing data] - optional variable-length data that only some packets make use of -*/ + * Packets format (sent from the client): + * [4 bytes] - size of packet including the 4 byte packet type + * [size bytes] - Encrypted packet (byte swapped && xor'd with 8 byte key; see CNSocketEncryption) + * [4 bytes] - packet type (which is a combination of the first 4 bytes of the packet and a checksum in some versions) + * [structure] - one member contains length of trailing data (expressed in packet-dependant structures) + * [trailing data] - optional variable-length data that only some packets make use of + */ // error checking calloc wrapper inline void* xmalloc(size_t sz) { diff --git a/src/CNShared.hpp b/src/CNShared.hpp index f852191..572661a 100644 --- a/src/CNShared.hpp +++ b/src/CNShared.hpp @@ -1,7 +1,7 @@ /* - CNShared.hpp - There's some data shared between the Login Server and the Shard Server. Of course all of this needs to be thread-safe. No mucking about on this one! -*/ + * CNShared.hpp + * There's some data shared between the Login Server and the Shard Server. Of course all of this needs to be thread-safe. No mucking about on this one! + */ #pragma once diff --git a/src/CNStructs.hpp b/src/CNStructs.hpp index d65fedf..10ecd1a 100644 --- a/src/CNStructs.hpp +++ b/src/CNStructs.hpp @@ -1,6 +1,6 @@ /* - CNStructs.hpp - defines some basic structs & useful methods for packets used by FusionFall based on the version defined -*/ + * CNStructs.hpp - defines some basic structs & useful methods for packets used by FusionFall based on the version defined + */ #pragma once diff --git a/src/ChatManager.cpp b/src/ChatManager.cpp index 4c7bb2f..fc41df3 100644 --- a/src/ChatManager.cpp +++ b/src/ChatManager.cpp @@ -311,7 +311,7 @@ void toggleAiCommand(std::string full, std::vector& args, CNSocket* void npcRotateCommand(std::string full, std::vector& args, CNSocket* sock) { PlayerView& plrv = PlayerManager::players[sock]; Player* plr = plrv.plr; - + BaseNPC* npc = NPCManager::getNearestNPC(plrv.currentChunks, plr->x, plr->y, plr->z); if (npc == nullptr) { diff --git a/src/ChunkManager.cpp b/src/ChunkManager.cpp index 45e5f24..4424dc9 100644 --- a/src/ChunkManager.cpp +++ b/src/ChunkManager.cpp @@ -94,7 +94,7 @@ void ChunkManager::destroyChunk(std::tuple chunkPos) { for (Chunk* otherChunk : grabChunks(chunkPos)) { if (otherChunk == chunk) continue; - + // remove from NPCs for (uint32_t id : otherChunk->NPCs) { if (std::find(NPCManager::NPCs[id]->currentChunks.begin(), NPCManager::NPCs[id]->currentChunks.end(), chunk) != NPCManager::NPCs[id]->currentChunks.end()) { @@ -223,8 +223,7 @@ void ChunkManager::createInstance(uint64_t instanceID) { NPCManager::updateNPCInstance(newID, instanceID); // make sure the npc state gets updated } } - } - else { + } else { std::cout << "Instance " << instanceID << " already exists" << std::endl; } } diff --git a/src/ChunkManager.hpp b/src/ChunkManager.hpp index 22c3328..67e59d6 100644 --- a/src/ChunkManager.hpp +++ b/src/ChunkManager.hpp @@ -15,9 +15,9 @@ public: }; enum { - INSTANCE_OVERWORLD // default instance every player starts in - //INSTANCE_IZ, // these aren't actually used - //INSTANCE_UNIQUE + INSTANCE_OVERWORLD, // default instance every player starts in + INSTANCE_IZ, // these aren't actually used + INSTANCE_UNIQUE // these aren't actually used }; namespace ChunkManager { diff --git a/src/Database.cpp b/src/Database.cpp index ab1698b..9fc1dbf 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -100,8 +100,7 @@ auto db = make_storage("database.db", #pragma region LoginServer -void Database::open() -{ +void Database::open() { // this parameter means it will try to preserve data during migration bool preserve = true; db.sync_schema(preserve); @@ -130,8 +129,7 @@ int Database::getPlayersCount() { return db.count(); } -int Database::addAccount(std::string login, std::string password) -{ +int Database::addAccount(std::string login, std::string password) { std::lock_guard lock(dbCrit); password = BCrypt::generateHash(password); @@ -143,19 +141,17 @@ int Database::addAccount(std::string login, std::string password) return db.insert(account); } -void Database::updateSelected(int accountId, int slot) -{ +void Database::updateSelected(int accountId, int slot) { std::lock_guard lock(dbCrit); Account acc = db.get(accountId); acc.Selected = slot; - //timestamp + // timestamp acc.LastLogin = getTimestamp(); db.update(acc); } -std::unique_ptr Database::findAccount(std::string login) -{ +std::unique_ptr Database::findAccount(std::string login) { std::lock_guard lock(dbCrit); // this is awful, I've tried everything to improve it @@ -167,8 +163,7 @@ std::unique_ptr Database::findAccount(std::string login) std::unique_ptr(new Account(find.front())); } -bool Database::isNameFree(sP_CL2LS_REQ_CHECK_CHAR_NAME* nameCheck) -{ +bool Database::isNameFree(sP_CL2LS_REQ_CHECK_CHAR_NAME* nameCheck) { std::lock_guard lock(dbCrit); std::string First = U16toU8(nameCheck->szFirstName); @@ -180,8 +175,7 @@ bool Database::isNameFree(sP_CL2LS_REQ_CHECK_CHAR_NAME* nameCheck) .empty()); } -int Database::createCharacter(sP_CL2LS_REQ_SAVE_CHAR_NAME* save, int AccountID) -{ +int Database::createCharacter(sP_CL2LS_REQ_SAVE_CHAR_NAME* save, int AccountID) { std::lock_guard lock(dbCrit); // fail if the player already has 4 or more characters @@ -190,7 +184,7 @@ int Database::createCharacter(sP_CL2LS_REQ_SAVE_CHAR_NAME* save, int AccountID) DbPlayer create = {}; - //set timestamp + // set timestamp create.Created = getTimestamp(); // save packet data create.FirstName = U16toU8(save->szFirstName); @@ -226,7 +220,7 @@ int Database::createCharacter(sP_CL2LS_REQ_SAVE_CHAR_NAME* save, int AccountID) create.y_coordinates = settings::SPAWN_Y; create.z_coordinates = settings::SPAWN_Z; create.angle = settings::SPAWN_ANGLE; - //set mentor to computress + // set mentor to computress create.Mentor = 5; // initialize the quest blob to 128 0-bytes @@ -235,8 +229,7 @@ int Database::createCharacter(sP_CL2LS_REQ_SAVE_CHAR_NAME* save, int AccountID) return db.insert(create); } -void Database::finishCharacter(sP_CL2LS_REQ_CHAR_CREATE* character) -{ +void Database::finishCharacter(sP_CL2LS_REQ_CHAR_CREATE* character) { std::lock_guard lock(dbCrit); DbPlayer finish = getDbPlayerById(character->PCStyle.iPC_UID); @@ -277,8 +270,7 @@ void Database::finishCharacter(sP_CL2LS_REQ_CHAR_CREATE* character) db.insert(UB); } -void Database::finishTutorial(int PlayerID) -{ +void Database::finishTutorial(int PlayerID) { std::lock_guard lock(dbCrit); Player finish = getPlayer(PlayerID); @@ -307,8 +299,7 @@ void Database::finishTutorial(int PlayerID) db.update(playerToDb(&finish)); } -int Database::deleteCharacter(int characterID, int userID) -{ +int Database::deleteCharacter(int characterID, int userID) { std::lock_guard lock(dbCrit); auto find = @@ -321,8 +312,7 @@ int Database::deleteCharacter(int characterID, int userID) return slot; } -std::vector Database::getCharacters(int UserID) -{ +std::vector Database::getCharacters(int UserID) { std::lock_guard lock(dbCrit); std::vectorcharacters = @@ -361,9 +351,8 @@ void Database::changeName(sP_CL2LS_REQ_CHANGE_CHAR_NAME* save) { db.update(Player); } -Database::DbPlayer Database::playerToDb(Player *player) -{ - //TODO: move stuff that is never updated to separate table so it doesn't try to update it every time +Database::DbPlayer Database::playerToDb(Player *player) { + // TODO: move stuff that is never updated to separate table so it doesn't try to update it every time DbPlayer result = {}; result.PlayerID = player->iID; @@ -395,8 +384,7 @@ Database::DbPlayer Database::playerToDb(Player *player) result.y_coordinates = player->y; result.z_coordinates = player->z; result.angle = player->angle; - } - else { + } else { result.x_coordinates = player->lastX; result.y_coordinates = player->lastY; result.z_coordinates = player->lastZ; @@ -580,8 +568,7 @@ void Database::updateNanos(Player *player) { where(c(&Nano::playerId) == player->iID) ); // insert - for (int i=1; i < SIZEOF_NANO_BANK_SLOT; i++) - { + for (int i=1; i < SIZEOF_NANO_BANK_SLOT; i++) { if ((player->Nanos[i]).iID == 0) continue; Nano toAdd = {}; @@ -603,8 +590,7 @@ void Database::updateQuests(Player* player) { where(c(&DbQuest::PlayerId) == player->iID) ); // insert - for (int i = 0; i < ACTIVE_MISSION_COUNT; i++) - { + for (int i = 0; i < ACTIVE_MISSION_COUNT; i++) { if (player->tasks[i] == 0) continue; DbQuest toAdd = {}; @@ -655,8 +641,7 @@ void Database::removeExpiredVehicles(Player* player) { std::vector toRemove; // equiped vehicle - if (player->Equip[8].iOpt > 0 && player->Equip[8].iTimeLimit < currentTime) - { + if (player->Equip[8].iOpt > 0 && player->Equip[8].iTimeLimit < currentTime) { toRemove.push_back(&player->Equip[8]); player->toRemoveVehicle.eIL = 0; player->toRemoveVehicle.iSlotNum = 8; diff --git a/src/Database.hpp b/src/Database.hpp index 9c90f09..380b287 100644 --- a/src/Database.hpp +++ b/src/Database.hpp @@ -7,8 +7,7 @@ namespace Database { #pragma region DatabaseStructs - struct Account - { + struct Account { int AccountID; std::string Login; std::string Password; @@ -16,8 +15,7 @@ namespace Database { uint64_t Created; uint64_t LastLogin; }; - struct Inventory - { + struct Inventory { int playerId; int slot; int16_t Type; @@ -31,8 +29,7 @@ namespace Database { int16_t iSkillID; int16_t iStamina; }; - struct DbPlayer - { + struct DbPlayer { int PlayerID; int AccountID; short int slot; @@ -130,7 +127,7 @@ namespace Database { void getNanos(Player* player); void getQuests(Player* player); - //parsing blobs + // parsing blobs void appendBlob(std::vector*blob, int64_t input); int64_t blobToInt64(std::vector::iterator it); } diff --git a/src/GroupManager.cpp b/src/GroupManager.cpp index 4f8a1a5..1df9571 100644 --- a/src/GroupManager.cpp +++ b/src/GroupManager.cpp @@ -105,7 +105,7 @@ void GroupManager::joinGroup(CNSocket* sock, CNPacketData* data) { std::cout << "[WARN] bad sP_FE2CL_PC_GROUP_JOIN packet size\n"; return; } - + int bitFlagBefore = getGroupFlags(otherPlr); plr->iIDGroup = otherPlr->iID; @@ -122,7 +122,7 @@ void GroupManager::joinGroup(CNSocket* sock, CNPacketData* data) { resp->iID_NewMember = plr->iID; resp->iMemberPCCnt = otherPlr->groupCnt; - + int bitFlag = getGroupFlags(otherPlr); for (int i = 0; i < otherPlr->groupCnt; i++) { @@ -147,10 +147,10 @@ void GroupManager::joinGroup(CNSocket* sock, CNPacketData* data) { respdata[i].iY = varPlr->y; respdata[i].iZ = varPlr->z; // client doesnt read nano data here - + NanoManager::nanoChangeBuff(sockTo, varPlr, bitFlagBefore | varPlr->iConditionBitFlag, bitFlag | varPlr->iConditionBitFlag); } - + sendToGroup(otherPlr, (void*)&respbuf, P_FE2CL_PC_GROUP_JOIN, resplen); } @@ -236,10 +236,10 @@ void GroupManager::groupTickInfo(Player* plr) { for (int i = 0; i < plr->groupCnt; i++) { Player* varPlr = PlayerManager::getPlayerFromID(plr->groupIDs[i]); - + if (varPlr == nullptr) continue; - + respdata[i].iPC_ID = varPlr->iID; respdata[i].iPCUID = varPlr->PCStyle.iPC_UID; respdata[i].iNameCheck = varPlr->PCStyle.iNameCheck; @@ -263,7 +263,7 @@ void GroupManager::groupTickInfo(Player* plr) { sendToGroup(plr, (void*)&respbuf, P_FE2CL_PC_GROUP_MEMBER_INFO, resplen); } -void GroupManager::groupKickPlayer(Player* plr) { +void GroupManager::groupKickPlayer(Player* plr) { // if you are the group leader, destroy your own group and kick everybody if (plr->iID == plr->iIDGroup) { groupUnbuff(plr); @@ -282,7 +282,7 @@ void GroupManager::groupKickPlayer(Player* plr) { std::cout << "[WARN] bad sP_FE2CL_PC_GROUP_LEAVE packet size\n"; return; } - + size_t resplen = sizeof(sP_FE2CL_PC_GROUP_LEAVE) + (otherPlr->groupCnt - 1) * sizeof(sPCGroupMemberInfo); uint8_t respbuf[CN_PACKET_BUFFER_SIZE]; @@ -317,8 +317,8 @@ void GroupManager::groupKickPlayer(Player* plr) { respdata[i-moveDown].iLv = varPlr->level; respdata[i-moveDown].iHP = varPlr->HP; respdata[i-moveDown].iMaxHP = PC_MAXHEALTH(varPlr->level); - //respdata[i-moveDown]].iMapType = 0; - //respdata[i-moveDown]].iMapNum = 0; + // respdata[i-moveDown]].iMapType = 0; + // respdata[i-moveDown]].iMapNum = 0; respdata[i-moveDown].iX = varPlr->x; respdata[i-moveDown].iY = varPlr->y; respdata[i-moveDown].iZ = varPlr->z; @@ -334,9 +334,9 @@ void GroupManager::groupKickPlayer(Player* plr) { plr->iIDGroup = plr->iID; otherPlr->groupCnt -= 1; - + sendToGroup(otherPlr, (void*)&respbuf, P_FE2CL_PC_GROUP_LEAVE, resplen); - + CNSocket* sock = PlayerManager::getSockFromID(plr->iID); if (sock == nullptr) @@ -348,13 +348,13 @@ void GroupManager::groupKickPlayer(Player* plr) { void GroupManager::groupUnbuff(Player* plr) { int bitFlag = getGroupFlags(plr); - + for (int i = 0; i < plr->groupCnt; i++) { CNSocket* sock = PlayerManager::getSockFromID(plr->groupIDs[i]); - + if (sock == nullptr) continue; - + Player* otherPlr = PlayerManager::getPlayer(sock); NanoManager::nanoChangeBuff(sock, otherPlr, bitFlag | otherPlr->iConditionBitFlag, otherPlr->iConditionBitFlag); } @@ -362,15 +362,15 @@ void GroupManager::groupUnbuff(Player* plr) { int GroupManager::getGroupFlags(Player* plr) { int bitFlag = 0; - + for (int i = 0; i < plr->groupCnt; i++) { Player* otherPlr = PlayerManager::getPlayerFromID(plr->groupIDs[i]); - + if (otherPlr == nullptr) continue; - - bitFlag |= otherPlr->iGroupConditionBitFlag; + + bitFlag |= otherPlr->iGroupConditionBitFlag; } - + return bitFlag; -} \ No newline at end of file +} diff --git a/src/ItemManager.cpp b/src/ItemManager.cpp index d005f79..4a22745 100644 --- a/src/ItemManager.cpp +++ b/src/ItemManager.cpp @@ -13,7 +13,7 @@ std::map> ItemManager::VendorTables; std::map ItemManager::CrocPotTable; std::map> ItemManager::RarityRatios; std::map ItemManager::Crates; -/// pair Itemset, Rarity -> vector of pointers (map iterators) to records in ItemData +// pair Itemset, Rarity -> vector of pointers (map iterators) to records in ItemData std::map, std::vector, Item>::iterator>> ItemManager::CrateItems; void ItemManager::init() { @@ -143,8 +143,7 @@ void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) { if (itemmove->eFrom == (int)SlotType::EQUIP) { equipChange.iEquipSlotNum = itemmove->iFromSlotNum; equipChange.EquipSlotItem = resp.ToSlotItem; - } - else { + } else { equipChange.iEquipSlotNum = itemmove->iToSlotNum; equipChange.EquipSlotItem = resp.FromSlotItem; } @@ -237,11 +236,11 @@ void ItemManager::itemUseHandler(CNSocket* sock, CNPacketData* data) { if (player == nullptr) return; - //gumball can only be used from inventory, so we ignore eIL + // gumball can only be used from inventory, so we ignore eIL sItemBase gumball = player->Inven[request->iSlotNum]; sNano nano = player->Nanos[player->equippedNanos[request->iNanoSlot]]; - //sanity check, check if gumball exists + // sanity check, check if gumball exists if (!(gumball.iOpt > 0 && gumball.iType == 7 && gumball.iID>=119 && gumball.iID<=121)) { std::cout << "[WARN] Gumball not found" << std::endl; INITSTRUCT(sP_FE2CL_REP_PC_ITEM_USE_FAIL, response); @@ -249,7 +248,7 @@ void ItemManager::itemUseHandler(CNSocket* sock, CNPacketData* data) { return; } - //sanity check, check if gumball type matches nano style + // sanity check, check if gumball type matches nano style int nanoStyle = NanoManager::nanoStyle(nano.iID); if (!((gumball.iID == 119 && nanoStyle == 0) || ( gumball.iID == 120 && nanoStyle == 1) || @@ -274,11 +273,11 @@ void ItemManager::itemUseHandler(CNSocket* sock, CNPacketData* data) { // response.iSkillID = ? sock->sendPacket((void*)&response, P_FE2CL_REP_PC_ITEM_USE_SUCC, sizeof(sP_FE2CL_REP_PC_ITEM_USE_SUCC)); - //update inventory serverside + // update inventory serverside player->Inven[response.iSlotNum] = response.RemainItem; - //this is a temporary way of calling buff efect - //TODO: send buff data via response packet + // this is a temporary way of calling buff efect + // TODO: send buff data via response packet int value1 = CSB_BIT_STIMPAKSLOT1 << request->iNanoSlot; int value2 = ECSB_STIMPAKSLOT1 + request->iNanoSlot; @@ -950,8 +949,7 @@ int ItemManager::getCrateItem(sItemBase& result, int itemSetId, int rarity, int // only take into account items that have correct gender std::vector, Item>::iterator> items; - for (auto crateitem : CrateItems[key]) - { + for (auto crateitem : CrateItems[key]) { int gender = crateitem->second.gender; // if gender is incorrect, exclude item if (gender != 0 && gender != playerGender) diff --git a/src/ItemManager.hpp b/src/ItemManager.hpp index 678a060..3708f01 100644 --- a/src/ItemManager.hpp +++ b/src/ItemManager.hpp @@ -44,7 +44,6 @@ namespace ItemManager { // Bank void itemBankOpenHandler(CNSocket* sock, CNPacketData* data); void itemTradeOfferHandler(CNSocket* sock, CNPacketData* data); - //void itemTradeOfferCancel(CNSocket* sock, CNPacketData* data); void itemTradeOfferAcceptHandler(CNSocket* sock, CNPacketData* data); void itemTradeOfferRefusalHandler(CNSocket* sock, CNPacketData* data); void itemTradeConfirmHandler(CNSocket* sock, CNPacketData* data); diff --git a/src/MissionManager.cpp b/src/MissionManager.cpp index 9951d36..fadbccb 100644 --- a/src/MissionManager.cpp +++ b/src/MissionManager.cpp @@ -148,8 +148,7 @@ bool MissionManager::endTask(CNSocket *sock, int32_t taskNum) { // update player int i; for (i = 0; i < ACTIVE_MISSION_COUNT; i++) { - if (plr->tasks[i] == taskNum) - { + if (plr->tasks[i] == taskNum) { plr->tasks[i] = 0; for (int j = 0; j < 3; j++) { plr->RemainingNPCCount[i][j] = 0; @@ -161,8 +160,7 @@ bool MissionManager::endTask(CNSocket *sock, int32_t taskNum) { } // if it's the last task - if (task["m_iSUOutgoingTask"] == 0) - { + if (task["m_iSUOutgoingTask"] == 0) { // save completed mission on player saveMission(plr, (int)(task["m_iHMissionID"])-1); @@ -211,8 +209,7 @@ void MissionManager::quitTask(CNSocket* sock, int32_t taskNum, bool manual) { // update player int i; for (i = 0; i < ACTIVE_MISSION_COUNT; i++) { - if (plr->tasks[i] == taskNum) - { + if (plr->tasks[i] == taskNum) { plr->tasks[i] = 0; for (int j = 0; j < 3; j++) { plr->RemainingNPCCount[i][j] = 0; @@ -247,7 +244,7 @@ void MissionManager::quitTask(CNSocket* sock, int32_t taskNum, bool manual) { failResp.iTaskNum = taskNum; sock->sendPacket((void*)&failResp, P_FE2CL_REP_PC_TASK_END_FAIL, sizeof(sP_FE2CL_REP_PC_TASK_END_FAIL)); } - + INITSTRUCT(sP_FE2CL_REP_PC_TASK_STOP_SUCC, response); response.iTaskNum = taskNum; sock->sendPacket((void*)&response, P_FE2CL_REP_PC_TASK_STOP_SUCC, sizeof(sP_FE2CL_REP_PC_TASK_STOP_SUCC)); @@ -449,14 +446,12 @@ void MissionManager::mobKilled(CNSocket *sock, int mobid) { continue; // acknowledge killing of mission mob... - if (task["m_iCSUNumToKill"][j] != 0) - { + if (task["m_iCSUNumToKill"][j] != 0) { missionmob = true; // sanity check if (plr->RemainingNPCCount[i][j] == 0) { std::cout << "[WARN] RemainingNPCCount tries to go below 0?!" << std::endl; - } - else { + } else { plr->RemainingNPCCount[i][j]--; } } @@ -486,7 +481,7 @@ void MissionManager::mobKilled(CNSocket *sock, int mobid) { } void MissionManager::saveMission(Player* player, int missionId) { - //sanity check missionID so we don't get exceptions + // sanity check missionID so we don't get exceptions if (missionId < 0 || missionId>1023) { std::cout << "[WARN] Client submitted invalid missionId: " <groupDamage; else damage.first = plr->pointDamage; - + int difficulty = (int)mob->data["m_iNpcLevel"]; - + damage = getDamage(damage.first, (int)mob->data["m_iProtection"], true, (plr->batteryW >= 11 + difficulty), NanoManager::nanoStyle(plr->activeNano), (int)mob->data["m_iNpcStyle"], difficulty); - + if (plr->batteryW >= 11 + difficulty) plr->batteryW -= 11 + difficulty; @@ -258,6 +258,7 @@ void MobManager::giveEventReward(CNSocket* sock, Player* player) { // random drop chance if (rand() % 100 > settings::EVENTCRATECHANCE) return; + // no slot = no reward int slot = ItemManager::findFreeSlot(player); if (slot == -1) @@ -284,18 +285,17 @@ void MobManager::giveEventReward(CNSocket* sock, Player* player) { // which crate to drop int crateId; - switch (settings::EVENTMODE) - { - // knishmas - case 1: crateId = 1187; break; - // halloween - case 2: crateId = 1181; break; - // spring - case 3: crateId = 1126; break; - // what - default: - std::cout << "[WARN] Unknown event Id " << settings::EVENTMODE << std::endl; - return; + switch (settings::EVENTMODE) { + // knishmas + case 1: crateId = 1187; break; + // halloween + case 2: crateId = 1181; break; + // spring + case 3: crateId = 1126; break; + // what + default: + std::cout << "[WARN] Unknown event Id " << settings::EVENTMODE << std::endl; + return; } item->sItem.iType = 9; @@ -352,7 +352,7 @@ void MobManager::killMob(CNSocket *sock, Mob *mob) { if (plr == nullptr) return; - if (plr->groupCnt == 1 && plr->iIDGroup == plr->iID) { + if (plr->groupCnt == 1 && plr->iIDGroup == plr->iID) { giveReward(sock, mob); MissionManager::mobKilled(sock, mob->appearanceData.iNPCType); } else { @@ -360,7 +360,7 @@ void MobManager::killMob(CNSocket *sock, Mob *mob) { if (plr == nullptr) return; - + for (int i = 0; i < plr->groupCnt; i++) { CNSocket* sockTo = PlayerManager::getSockFromID(plr->groupIDs[i]); giveReward(sockTo, mob); @@ -732,9 +732,9 @@ void MobManager::dotDamageOnOff(CNSocket *sock, CNPacketData *data) { INITSTRUCT(sP_FE2CL_PC_BUFF_UPDATE, pkt1); - pkt1.eCSTB = ECSB_INFECTION; //eCharStatusTimeBuffID - pkt1.eTBU = 1; //eTimeBuffUpdate - pkt1.eTBT = 0; //eTimeBuffType 1 means nano + pkt1.eCSTB = ECSB_INFECTION; // eCharStatusTimeBuffID + pkt1.eTBU = 1; // eTimeBuffUpdate + pkt1.eTBT = 0; // eTimeBuffType 1 means nano pkt1.iConditionBitFlag = plr->iConditionBitFlag; sock->sendPacket((void*)&pkt1, P_FE2CL_PC_BUFF_UPDATE, sizeof(sP_FE2CL_PC_BUFF_UPDATE)); @@ -871,19 +871,19 @@ std::pair MobManager::getDamage(int attackPower, int defensePower, bool int damage = attackPower * attackPower / (attackPower + defensePower); damage = std::max(std::max(29, attackPower / 7), damage - defensePower * (12 + difficulty) / 65); damage = damage * (rand() % 40 + 80) / 100; - + // Adaptium/Blastons/Cosmix if (attackerStyle != -1 && defenderStyle != -1 && attackerStyle != defenderStyle) { - if (attackerStyle < defenderStyle || attackerStyle - defenderStyle == 2) + if (attackerStyle < defenderStyle || attackerStyle - defenderStyle == 2) damage = damage * 5 / 4; else damage = damage * 4 / 5; } - + // weapon boosts if (batteryBoost) damage = damage * 5 / 4; - + ret.first = damage; ret.second = 1; @@ -949,9 +949,9 @@ void MobManager::pcAttackChars(CNSocket *sock, CNPacketData *data) { damage.first = plr->groupDamage; else damage.first = plr->pointDamage; - + damage = getDamage(damage.first, target->defense, true, (plr->batteryW >= 12), -1, -1, 1); - + if (plr->batteryW >= 12) plr->batteryW -= 12; @@ -976,12 +976,12 @@ void MobManager::pcAttackChars(CNSocket *sock, CNPacketData *data) { damage.first = plr->groupDamage; else damage.first = plr->pointDamage; - + int difficulty = (int)mob->data["m_iNpcLevel"]; - + damage = getDamage(damage.first, (int)mob->data["m_iProtection"], true, (plr->batteryW >= 11 + difficulty), NanoManager::nanoStyle(plr->activeNano), (int)mob->data["m_iNpcStyle"], difficulty); - + if (plr->batteryW >= 11 + difficulty) plr->batteryW -= 11 + difficulty; diff --git a/src/MobManager.hpp b/src/MobManager.hpp index 3049484..136d52b 100644 --- a/src/MobManager.hpp +++ b/src/MobManager.hpp @@ -60,10 +60,6 @@ struct Mob : public BaseNPC { dropType = data["m_iDropType"]; level = data["m_iNpcLevel"]; - // XXX: temporarily force respawns for Fusions until we implement instancing - //if (regenTime >= 300000000) - // regenTime = 1500; - roamX = spawnX = appearanceData.iX; roamY = spawnY = appearanceData.iY; roamZ = spawnZ = appearanceData.iZ; diff --git a/src/NPCManager.cpp b/src/NPCManager.cpp index ffd7234..d8645c3 100644 --- a/src/NPCManager.cpp +++ b/src/NPCManager.cpp @@ -288,8 +288,7 @@ void NPCManager::npcVendorSell(CNSocket* sock, CNPacketData* data) { if (plr->Inven[req->iInvenSlotNum].iOpt - req->iItemCnt > 0) { // selling part of a stack item->iOpt -= req->iItemCnt; original.iOpt = req->iItemCnt; - } - else { // selling entire slot + } else { // selling entire slot item->iID = 0; item->iOpt = 0; item->iType = 0; @@ -378,7 +377,7 @@ void NPCManager::npcVendorTable(CNSocket* sock, CNPacketData* data) { vItem.item = base; vItem.iSortNum = listings[i].sort; vItem.iVendorID = req->iVendorID; - //vItem.fBuyCost = listings[i].price; this value is not actually the one that is used + //vItem.fBuyCost = listings[i].price; // this value is not actually the one that is used resp.item[i] = vItem; } @@ -461,8 +460,7 @@ void NPCManager::npcCombineItems(CNSocket* sock, CNPacketData* data) { Item* itemLooksDat = ItemManager::getItemData(itemLooks->iID, itemLooks->iType); if (itemStatsDat == nullptr || itemLooksDat == nullptr - || ItemManager::CrocPotTable.find(abs(itemStatsDat->level - itemLooksDat->level)) == ItemManager::CrocPotTable.end()) // sanity check 2 - { + || ItemManager::CrocPotTable.find(abs(itemStatsDat->level - itemLooksDat->level)) == ItemManager::CrocPotTable.end()) { // sanity check 2 INITSTRUCT(sP_FE2CL_REP_PC_ITEM_COMBINATION_FAIL, failResp); failResp.iCostumeItemSlot = req->iCostumeItemSlot; failResp.iStatItemSlot = req->iStatItemSlot; @@ -477,8 +475,7 @@ void NPCManager::npcCombineItems(CNSocket* sock, CNPacketData* data) { float successChance = recipe->base / 100.0f; // base success chance // rarity gap multiplier - switch(abs(itemStatsDat->rarity - itemLooksDat->rarity)) - { + switch(abs(itemStatsDat->rarity - itemLooksDat->rarity)) { case 0: successChance *= recipe->rd0; break; @@ -514,8 +511,7 @@ void NPCManager::npcCombineItems(CNSocket* sock, CNPacketData* data) { itemStats->iOpt = 0; itemStats->iTimeLimit = 0; itemStats->iType = 0; - } - else { + } else { // failure; don't do anything? resp.iSuccessFlag = 0; } @@ -591,7 +587,7 @@ void NPCManager::handleWarp(CNSocket* sock, int32_t warpId) { return; MissionManager::failInstancedMissions(sock); // fail any missions that require the player's current instance - + uint64_t fromInstance = plrv.plr->instanceID; // saved for post-warp if (plrv.plr->instanceID == 0) { @@ -603,19 +599,16 @@ void NPCManager::handleWarp(CNSocket* sock, int32_t warpId) { } // std::cerr << "Warped to Map Num:" << Warps[warpId].instanceID << " NPC ID " << Warps[warpId].npcID << std::endl; - if (Warps[warpId].isInstance) - { + if (Warps[warpId].isInstance) { uint64_t instanceID = Warps[warpId].instanceID; if (Warps[warpId].limitTaskID != 0) { // if warp requires you to be on a mission, it's gotta be a unique instance instanceID += ((uint64_t)plrv.plr->iIDGroup << 32); // upper 32 bits are leader ID ChunkManager::createInstance(instanceID); } - + PlayerManager::sendPlayerTo(sock, Warps[warpId].x, Warps[warpId].y, Warps[warpId].z, instanceID); - } - else - { - INITSTRUCT(sP_FE2CL_REP_PC_WARP_USE_NPC_SUCC, resp); //Can only be used for exiting instances because it sets the instance flag to false + } else { + INITSTRUCT(sP_FE2CL_REP_PC_WARP_USE_NPC_SUCC, resp); // Can only be used for exiting instances because it sets the instance flag to false resp.iX = Warps[warpId].x; resp.iY = Warps[warpId].y; resp.iZ = Warps[warpId].z; diff --git a/src/NanoManager.cpp b/src/NanoManager.cpp index 99954c2..52179fa 100644 --- a/src/NanoManager.cpp +++ b/src/NanoManager.cpp @@ -232,7 +232,7 @@ void NanoManager::nanoPotionHandler(CNSocket* sock, CNPacketData* data) { response.iBatteryN = player->batteryN - difference; sock->sendPacket((void*)&response, P_FE2CL_REP_CHARGE_NANO_STAMINA, sizeof(sP_FE2CL_REP_CHARGE_NANO_STAMINA)); - //now update serverside + // now update serverside player->batteryN -= difference; player->Nanos[nano.iID].iStamina += difference; @@ -689,26 +689,26 @@ void NanoManager::nanoBuff(CNSocket* sock, int16_t nanoId, int skillId, int16_t if (plr == nullptr) return; - + int pktCnt = 1; Player *leader = plr; plr->iConditionBitFlag |= iCBFlag; - + if (groupPower) { plr->iGroupConditionBitFlag |= iCBFlag; - + if (plr->iID != plr->iIDGroup) leader = PlayerManager::getPlayerFromID(plr->iIDGroup); - + if (leader == nullptr) return; - + pktCnt = leader->groupCnt; } if (leader == nullptr) return; - + if (!validOutVarPacket(sizeof(sP_FE2CL_NANO_SKILL_USE), pktCnt, sizeof(sSkillResult_Buff))) { std::cout << "[WARN] bad sP_FE2CL_NANO_SKILL_USE packet size\n"; return; @@ -728,7 +728,7 @@ void NanoManager::nanoBuff(CNSocket* sock, int16_t nanoId, int skillId, int16_t resp->iNanoStamina = plr->Nanos[plr->activeNano].iStamina; resp->eST = eSkillType; resp->iTargetCnt = pktCnt; - + int bitFlag = GroupManager::getGroupFlags(leader); for (int i = 0; i < pktCnt; i++) { @@ -745,15 +745,15 @@ void NanoManager::nanoBuff(CNSocket* sock, int16_t nanoId, int skillId, int16_t if (varPlr == nullptr || sockTo == nullptr) continue; - + respdata[i].eCT = 1; respdata[i].iID = varPlr->iID; respdata[i].iConditionBitFlag = iCBFlag; INITSTRUCT(sP_FE2CL_PC_BUFF_UPDATE, pkt1); - pkt1.eCSTB = eCharStatusTimeBuffID; //eCharStatusTimeBuffID - pkt1.eTBU = 1; //eTimeBuffUpdate - pkt1.eTBT = 1; //eTimeBuffType 1 means nano + pkt1.eCSTB = eCharStatusTimeBuffID; // eCharStatusTimeBuffID + pkt1.eTBU = 1; // eTimeBuffUpdate + pkt1.eTBT = 1; // eTimeBuffType 1 means nano pkt1.iConditionBitFlag = bitFlag | varPlr->iConditionBitFlag; if (iValue > 0) @@ -771,23 +771,23 @@ void NanoManager::nanoUnbuff(CNSocket* sock, int32_t iCBFlag, int16_t eCharStatu if (plr == nullptr) return; - + int pktCnt = 1; Player *leader = plr; plr->iConditionBitFlag &= ~iCBFlag; - + if (groupPower) { plr->iGroupConditionBitFlag &= ~iCBFlag; - + if (plr->iID != plr->iIDGroup) leader = PlayerManager::getPlayerFromID(plr->iIDGroup); - + if (leader == nullptr) return; - + pktCnt = leader->groupCnt; } - + int bitFlag = GroupManager::getGroupFlags(leader); for (int i = 0; i < pktCnt; i++) { @@ -801,11 +801,11 @@ void NanoManager::nanoUnbuff(CNSocket* sock, int32_t iCBFlag, int16_t eCharStatu varPlr = PlayerManager::getPlayerFromID(leader->groupIDs[i]); sockTo = PlayerManager::getSockFromID(leader->groupIDs[i]); } - + INITSTRUCT(sP_FE2CL_PC_BUFF_UPDATE, resp1); - resp1.eCSTB = eCharStatusTimeBuffID; //eCharStatusTimeBuffID - resp1.eTBU = 2; //eTimeBuffUpdate - resp1.eTBT = 1; //eTimeBuffType 1 means nano + resp1.eCSTB = eCharStatusTimeBuffID; // eCharStatusTimeBuffID + resp1.eTBU = 2; // eTimeBuffUpdate + resp1.eTBT = 1; // eTimeBuffType 1 means nano resp1.iConditionBitFlag = bitFlag | varPlr->iConditionBitFlag; if (iValue > 0) @@ -892,8 +892,8 @@ void NanoManager::nanoChangeBuff(CNSocket* sock, Player* plr, int32_t cbFrom, in resp.eTBU = 3; resp.eTBT = 1; resp.iConditionBitFlag = cbTo; - - if (!(cbFrom & CSB_BIT_UP_MOVE_SPEED) && (cbTo & CSB_BIT_UP_MOVE_SPEED)) { + + if (!(cbFrom & CSB_BIT_UP_MOVE_SPEED) && (cbTo & CSB_BIT_UP_MOVE_SPEED)) { resp.eCSTB = ECSB_UP_MOVE_SPEED; resp.eTBU = 1; resp.TimeBuff.iValue = 200; @@ -906,7 +906,7 @@ void NanoManager::nanoChangeBuff(CNSocket* sock, Player* plr, int32_t cbFrom, in sock->sendPacket((void*)&resp, P_FE2CL_PC_BUFF_UPDATE, sizeof(sP_FE2CL_PC_BUFF_UPDATE)); sentPacket = true; } - + if (!(cbFrom & CSB_BIT_UP_JUMP_HEIGHT) && (cbTo & CSB_BIT_UP_JUMP_HEIGHT)) { resp.eCSTB = ECSB_UP_JUMP_HEIGHT; resp.eTBU = 1; @@ -920,7 +920,7 @@ void NanoManager::nanoChangeBuff(CNSocket* sock, Player* plr, int32_t cbFrom, in sock->sendPacket((void*)&resp, P_FE2CL_PC_BUFF_UPDATE, sizeof(sP_FE2CL_PC_BUFF_UPDATE)); sentPacket = true; } - + if (!sentPacket) sock->sendPacket((void*)&resp, P_FE2CL_PC_BUFF_UPDATE, sizeof(sP_FE2CL_PC_BUFF_UPDATE)); } diff --git a/src/PlayerManager.cpp b/src/PlayerManager.cpp index 97cdb1e..c3a441e 100644 --- a/src/PlayerManager.cpp +++ b/src/PlayerManager.cpp @@ -66,7 +66,6 @@ void PlayerManager::removePlayer(CNSocket* key) { PlayerView& view = players[key]; uint64_t fromInstance = view.plr->instanceID; - //MissionManager::failInstancedMissions(key); moved to enter GroupManager::groupKickPlayer(view.plr); // save player to DB @@ -315,7 +314,7 @@ void PlayerManager::enterPlayer(CNSocket* sock, CNPacketData* data) { response.PCLoadData2CL.iAngle = plr.angle; response.PCLoadData2CL.iBatteryN = plr.batteryN; response.PCLoadData2CL.iBatteryW = plr.batteryW; - response.PCLoadData2CL.iBuddyWarpTime = 60; //sets 60s warp cooldown on login + response.PCLoadData2CL.iBuddyWarpTime = 60; // sets 60s warp cooldown on login response.PCLoadData2CL.iWarpLocationFlag = plr.iWarpLocationFlag; response.PCLoadData2CL.aWyvernLocationFlag[0] = plr.aSkywayLocationFlag[0]; @@ -325,8 +324,8 @@ void PlayerManager::enterPlayer(CNSocket* sock, CNPacketData* data) { response.PCLoadData2CL.iFatigue = 50; response.PCLoadData2CL.PCStyle = plr.PCStyle; - //client doesnt read this, it gets it from charinfo - //response.PCLoadData2CL.PCStyle2 = plr.PCStyle2; + // client doesnt read this, it gets it from charinfo + // response.PCLoadData2CL.PCStyle2 = plr.PCStyle2; // inventory for (int i = 0; i < AEQUIP_COUNT; i++) response.PCLoadData2CL.aEquip[i] = plr.Equip[i]; @@ -342,7 +341,7 @@ void PlayerManager::enterPlayer(CNSocket* sock, CNPacketData* data) { for (int i = 0; i < 3; i++) { response.PCLoadData2CL.aNanoSlots[i] = plr.equippedNanos[i]; } - //missions in progress + // missions in progress for (int i = 0; i < ACTIVE_MISSION_COUNT; i++) { if (plr.tasks[i] == 0) break; @@ -385,10 +384,10 @@ void PlayerManager::enterPlayer(CNSocket* sock, CNPacketData* data) { ChatManager::sendServerMessage(sock, settings::MOTDSTRING); addPlayer(sock, plr); - //check if there is an expiring vehicle + // check if there is an expiring vehicle ItemManager::checkItemExpire(sock, getPlayer(sock)); - //set player equip stats + // set player equip stats ItemManager::setItemStats(getPlayer(sock)); MissionManager::failInstancedMissions(sock); @@ -863,8 +862,7 @@ void PlayerManager::enterPlayerVehicle(CNSocket* sock, CNPacketData* data) { sock->sendPacket((void*)&response, P_FE2CL_PC_VEHICLE_ON_FAIL, sizeof(sP_FE2CL_PC_VEHICLE_ON_FAIL)); // check if vehicle didn't expire - if (plr.plr->Equip[8].iTimeLimit < getTimestamp()) - { + if (plr.plr->Equip[8].iTimeLimit < getTimestamp()) { plr.plr->toRemoveVehicle.eIL = 0; plr.plr->toRemoveVehicle.iSlotNum = 8; ItemManager::checkItemExpire(sock, plr.plr); @@ -955,8 +953,7 @@ WarpLocation PlayerManager::getRespawnPoint(Player *plr) { bool PlayerManager::isAccountInUse(int accountId) { std::map::iterator it; - for (it = PlayerManager::players.begin(); it != PlayerManager::players.end(); it++) - { + for (it = PlayerManager::players.begin(); it != PlayerManager::players.end(); it++) { if (it->second.plr->accountId == accountId) return true; } diff --git a/src/TableData.cpp b/src/TableData.cpp index 5f37198..e2a9ce9 100644 --- a/src/TableData.cpp +++ b/src/TableData.cpp @@ -165,7 +165,7 @@ void TableData::init() { std::cout << "[INFO] Loaded " << ItemManager::CrocPotTable.size() << " croc pot value sets" << std::endl; - //load nano info + // load nano info nlohmann::json nanoInfo = xdtData["m_pNanoTable"]["m_pNanoData"]; for (nlohmann::json::iterator _nano = nanoInfo.begin(); _nano != nanoInfo.end(); _nano++) { auto nano = _nano.value(); @@ -223,8 +223,7 @@ void TableData::init() { */ int TableData::getItemType(int itemSet) { int overriden; - switch (itemSet) - { + switch (itemSet) { case 11: // Chest items don't have iEquipLoc and are type 9. overriden = 9; break; @@ -343,13 +342,11 @@ void TableData::loadDrops() { toAdd.dropChanceType = (int)drop["DropChance"]; // Check if DropChance exists - if (MobManager::MobDropChances.find(toAdd.dropChanceType) == MobManager::MobDropChances.end()) - { + if (MobManager::MobDropChances.find(toAdd.dropChanceType) == MobManager::MobDropChances.end()) { throw TableException(" MobDropChance not found: " + std::to_string((toAdd.dropChanceType))); } // Check if number of crates is correct - if (!(MobManager::MobDropChances[(int)drop["DropChance"]].cratesRatio.size() == toAdd.crateIDs.size())) - { + if (!(MobManager::MobDropChances[(int)drop["DropChance"]].cratesRatio.size() == toAdd.crateIDs.size())) { throw TableException(" DropType " + std::to_string((int)drop["DropType"]) + " contains invalid number of crates"); } @@ -392,8 +389,7 @@ void TableData::loadDrops() { std::pair itemSetkey = std::make_pair((int)item["ItemSet"], (int)item["Rarity"]); std::pair itemDataKey = std::make_pair((int)item["Id"], (int)item["Type"]); - if (ItemManager::ItemData.find(itemDataKey) == ItemManager::ItemData.end()) - { + if (ItemManager::ItemData.find(itemDataKey) == ItemManager::ItemData.end()) { char buff[255]; sprintf(buff, "Unknown item with Id %d and Type %d", (int)item["Id"], (int)item["Type"]); throw TableException(std::string(buff)); diff --git a/tdata b/tdata index ffbb1af..aa43382 160000 --- a/tdata +++ b/tdata @@ -1 +1 @@ -Subproject commit ffbb1afb36381e99e2ec7de3006bcbe09b3d4e18 +Subproject commit aa4338202eb02d913bdfd8cf6d008795ded0f026