diff --git a/src/CNLoginServer.cpp b/src/CNLoginServer.cpp index d61d561..cd668f0 100644 --- a/src/CNLoginServer.cpp +++ b/src/CNLoginServer.cpp @@ -24,7 +24,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { if (data->size != sizeof(sP_CL2LS_REQ_LOGIN)) return; // ignore the malformed packet - sP_CL2LS_REQ_LOGIN* login = (sP_CL2LS_REQ_LOGIN*)data->buf; + sP_CL2LS_REQ_LOGIN* login = (sP_CL2LS_REQ_LOGIN*)data->buf; //TODO: implement better way of sending credentials std::string userLogin((char*)login->szCookie_TEGid); std::string userPassword((char*)login->szCookie_authid); @@ -49,8 +49,8 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { if (!CNLoginServer::isLoginDataGood(userLogin, userPassword)) { errorCode = (int)LoginError::LOGIN_ERROR; - } - else + } + else { std::unique_ptr findUser = Database::findAccount(userLogin); //if account not found, create it @@ -59,7 +59,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { loginSessions[sock] = CNLoginData(); loginSessions[sock].userID = Database::addAccount(userLogin, userPassword); loginSessions[sock].slot = 1; - success = true; + success = true; } //if user exists, check if password is correct else if (CNLoginServer::isPasswordCorrect(findUser->Password, userPassword)) @@ -71,14 +71,14 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { errorCode = (int)LoginError::ID_ALREADY_IN_USE; } //if not, login success - else + else { loginSessions[sock] = CNLoginData(); loginSessions[sock].userID = findUser->AccountID; loginSessions[sock].slot = findUser->Selected; success = true; } - } + } else { errorCode = (int)LoginError::ID_AND_PASSWORD_DO_NOT_MATCH; @@ -107,8 +107,8 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { // update keys sock->setEKey(CNSocketEncryption::createNewKey(resp.uiSvrTime, resp.iCharCount + 1, resp.iSlotNum + 1)); sock->setFEKey(CNSocketEncryption::createNewKey((uint64_t)(*(uint64_t*)&CNSocketEncryption::defaultKey[0]), login->iClientVerC, 1)); - - // now send the characters :) + + // now send the characters :) std::vector::iterator it; for (it = characters.begin(); it != characters.end(); it++) { @@ -126,10 +126,10 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { //save character in session (for char select) int UID = it->iID; - loginSessions[sock].characters[UID] = Player(*it); + loginSessions[sock].characters[UID] = Player(*it); loginSessions[sock].characters[UID].FEKey = sock->getFEKey(); - //Equip info + //Equip info for (int i = 0; i < AEQUIP_COUNT; i++) { charInfo.aEquip[i] = it->Equip[i]; } @@ -138,16 +138,16 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { if (it == characters.begin()) loginSessions[sock].selectedChar = UID; - sock->sendPacket((void*)&charInfo, P_LS2CL_REP_CHAR_INFO, sizeof(sP_LS2CL_REP_CHAR_INFO)); + sock->sendPacket((void*)&charInfo, P_LS2CL_REP_CHAR_INFO, sizeof(sP_LS2CL_REP_CHAR_INFO)); } - } + } //Failure else { INITSTRUCT(sP_LS2CL_REP_LOGIN_FAIL, resp); memcpy(resp.szID, login->szID, sizeof(char16_t) * 33); resp.iErrorCode = errorCode; - + sock->sendPacket((void*)&resp, P_LS2CL_REP_LOGIN_FAIL, sizeof(sP_LS2CL_REP_LOGIN_FAIL)); } @@ -160,7 +160,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { case P_CL2LS_REQ_CHECK_CHAR_NAME: { if (data->size != sizeof(sP_CL2LS_REQ_CHECK_CHAR_NAME)) return; - + sP_CL2LS_REQ_CHECK_CHAR_NAME* nameCheck = (sP_CL2LS_REQ_CHECK_CHAR_NAME*)data->buf; bool success = true; int errorcode = 0; @@ -196,10 +196,10 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { case P_CL2LS_REQ_SAVE_CHAR_NAME: { if (data->size != sizeof(sP_CL2LS_REQ_SAVE_CHAR_NAME)) return; - + sP_CL2LS_REQ_SAVE_CHAR_NAME* save = (sP_CL2LS_REQ_SAVE_CHAR_NAME*)data->buf; INITSTRUCT(sP_LS2CL_REP_SAVE_CHAR_NAME_SUCC, resp); - + DEBUGLOG( std::cout << "P_CL2LS_REQ_SAVE_CHAR_NAME:" << std::endl; std::cout << "\tSlot: " << (int)save->iSlotNum << std::endl; @@ -220,7 +220,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { case P_CL2LS_REQ_CHAR_CREATE: { if (data->size != sizeof(sP_CL2LS_REQ_CHAR_CREATE)) return; - + sP_CL2LS_REQ_CHAR_CREATE* character = (sP_CL2LS_REQ_CHAR_CREATE*)data->buf; Database::finishCharacter(character); @@ -255,7 +255,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { //save player in session loginSessions[sock].characters[UID] = Player(player); loginSessions[sock].characters[UID].FEKey = sock->getFEKey(); - + sock->sendPacket((void*)&resp, P_LS2CL_REP_CHAR_CREATE_SUCC, sizeof(sP_LS2CL_REP_CHAR_CREATE_SUCC)); Database::updateSelected(loginSessions[sock].userID, player.slot); break; @@ -266,7 +266,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { sP_CL2LS_REQ_CHAR_DELETE* del = (sP_CL2LS_REQ_CHAR_DELETE*)data->buf; int operationResult = Database::deleteCharacter(del->iPC_UID, loginSessions[sock].userID); - + INITSTRUCT(sP_LS2CL_REP_CHAR_DELETE_SUCC, resp); resp.iSlotNum = operationResult; sock->sendPacket((void*)&resp, P_LS2CL_REP_CHAR_DELETE_SUCC, sizeof(sP_LS2CL_REP_CHAR_DELETE_SUCC)); @@ -276,7 +276,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { case P_CL2LS_REQ_CHAR_SELECT: { if (data->size != sizeof(sP_CL2LS_REQ_CHAR_SELECT)) return; - + // character selected sP_CL2LS_REQ_CHAR_SELECT* chararacter = (sP_CL2LS_REQ_CHAR_SELECT*)data->buf; INITSTRUCT(sP_LS2CL_REP_CHAR_SELECT_SUCC, resp); @@ -284,7 +284,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { DEBUGLOG( std::cout << "P_CL2LS_REQ_CHAR_SELECT:" << std::endl; std::cout << "\tPC_UID: " << chararacter->iPC_UID << std::endl; - ) + ) loginSessions[sock].selectedChar = chararacter->iPC_UID; Database::updateSelected(loginSessions[sock].userID, loginSessions[sock].characters[chararacter->iPC_UID].slot); sock->sendPacket((void*)&resp, P_LS2CL_REP_CHAR_SELECT_SUCC, sizeof(sP_LS2CL_REP_CHAR_SELECT_SUCC)); @@ -293,7 +293,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { case P_CL2LS_REQ_SHARD_SELECT: { if (data->size != sizeof(sP_CL2LS_REQ_SHARD_SELECT)) return; - + // tell client to connect to the shard server sP_CL2LS_REQ_SHARD_SELECT* shard = (sP_CL2LS_REQ_SHARD_SELECT*)data->buf; INITSTRUCT(sP_LS2CL_REP_SHARD_SELECT_SUCC, resp); @@ -353,8 +353,8 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { int accountId = account->AccountID; if (!exitDuplicate(accountId)) - PlayerManager::exitDuplicate(accountId); - + PlayerManager::exitDuplicate(accountId); + break; } default: diff --git a/src/CNLoginServer.hpp b/src/CNLoginServer.hpp index eea7f59..e1a8961 100644 --- a/src/CNLoginServer.hpp +++ b/src/CNLoginServer.hpp @@ -29,7 +29,7 @@ class CNLoginServer : public CNServer { private: static void handlePacket(CNSocket* sock, CNPacketData* data); static std::map loginSessions; - + static bool isLoginDataGood(std::string login, std::string password); static bool isPasswordCorrect(std::string actualPassword, std::string tryPassword); static bool isAccountInUse(int accountId); @@ -40,5 +40,5 @@ public: CNLoginServer(uint16_t p); void newConnection(CNSocket* cns); - void killConnection(CNSocket* cns); + void killConnection(CNSocket* cns); }; diff --git a/src/CNProtocol.cpp b/src/CNProtocol.cpp index fd568b8..baf5bdb 100644 --- a/src/CNProtocol.cpp +++ b/src/CNProtocol.cpp @@ -83,7 +83,7 @@ bool CNSocket::sendData(uint8_t* data, int size) { } sentBytes += sent; } - + return true; // it worked! } @@ -122,7 +122,7 @@ void CNSocket::kill() { void CNSocket::sendPacket(void* buf, uint32_t type, size_t size) { if (!alive) return; - + size_t bodysize = size + sizeof(uint32_t); uint8_t* fullpkt = (uint8_t*)xmalloc(bodysize+4); uint8_t* body = fullpkt+4; @@ -150,7 +150,7 @@ void CNSocket::sendPacket(void* buf, uint32_t type, size_t size) { } // send packet data! - if (alive && !sendData(fullpkt, bodysize+4)) + if (alive && !sendData(fullpkt, bodysize+4)) kill(); free(fullpkt); @@ -183,7 +183,7 @@ void CNSocket::step() { return; } } - + if (readSize > 0 && readBufferIndex < readSize) { // read until the end of the packet! (or at least try too) int recved = recv(sock, (buffer_t*)(readBuffer + readBufferIndex), readSize - readBufferIndex, 0); @@ -196,7 +196,7 @@ void CNSocket::step() { } } - if (activelyReading && readBufferIndex - readSize <= 0) { + if (activelyReading && readBufferIndex - readSize <= 0) { // decrypt readBuffer and copy to CNPacketData CNSocketEncryption::decryptData((uint8_t*)&readBuffer, (uint8_t*)(&EKey), readSize); @@ -216,38 +216,38 @@ void CNSocket::step() { // ========================================================[[ CNServer ]]======================================================== void CNServer::init() { - // create socket file descriptor + // create socket file descriptor sock = socket(AF_INET, SOCK_STREAM, 0); - if (SOCKETINVALID(sock)) { - std::cerr << "[FATAL] OpenFusion: socket failed" << std::endl; - exit(EXIT_FAILURE); + if (SOCKETINVALID(sock)) { + std::cerr << "[FATAL] OpenFusion: socket failed" << std::endl; + exit(EXIT_FAILURE); } // attach socket to the port int opt = 1; #ifdef _WIN32 - if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&opt, sizeof(opt)) != 0) { + if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&opt, sizeof(opt)) != 0) { #else - if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) != 0) { + if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) != 0) { #endif - std::cerr << "[FATAL] OpenFusion: setsockopt failed" << std::endl; - exit(EXIT_FAILURE); - } - address.sin_family = AF_INET; - address.sin_addr.s_addr = INADDR_ANY; - address.sin_port = htons(port); + std::cerr << "[FATAL] OpenFusion: setsockopt failed" << std::endl; + exit(EXIT_FAILURE); + } + address.sin_family = AF_INET; + address.sin_addr.s_addr = INADDR_ANY; + address.sin_port = htons(port); addressSize = sizeof(address); // Bind to the port - if (SOCKETERROR(bind(sock, (struct sockaddr *)&address, addressSize))) { - std::cerr << "[FATAL] OpenFusion: bind failed" << std::endl; - exit(EXIT_FAILURE); + if (SOCKETERROR(bind(sock, (struct sockaddr *)&address, addressSize))) { + std::cerr << "[FATAL] OpenFusion: bind failed" << std::endl; + exit(EXIT_FAILURE); } if (SOCKETERROR(listen(sock, SOMAXCONN))) { - std::cerr << "[FATAL] OpenFusion: listen failed" << std::endl; - exit(EXIT_FAILURE); + std::cerr << "[FATAL] OpenFusion: listen failed" << std::endl; + exit(EXIT_FAILURE); } // set server listener to non-blocking @@ -257,8 +257,8 @@ void CNServer::init() { #else if (fcntl(sock, F_SETFL, (fcntl(sock, F_GETFL, 0) | O_NONBLOCK)) != 0) { #endif - std::cerr << "[FATAL] OpenFusion: fcntl failed" << std::endl; - exit(EXIT_FAILURE); + std::cerr << "[FATAL] OpenFusion: fcntl failed" << std::endl; + exit(EXIT_FAILURE); } } @@ -281,7 +281,7 @@ void CNServer::start() { #else if (fcntl(newConnectionSocket, F_SETFL, (fcntl(sock, F_GETFL, 0) | O_NONBLOCK)) != 0) { #endif - std::cerr << "[WARN] OpenFusion: fcntl failed on new connection" << std::endl; + std::cerr << "[WARN] OpenFusion: fcntl failed on new connection" << std::endl; #ifdef _WIN32 shutdown(newConnectionSocket, SD_BOTH); closesocket(newConnectionSocket); @@ -295,7 +295,7 @@ void CNServer::start() { std::cout << "New connection! " << inet_ntoa(address.sin_addr) << std::endl; // add connection to list! - CNSocket* tmp = new CNSocket(newConnectionSocket, pHandler); + CNSocket* tmp = new CNSocket(newConnectionSocket, pHandler); connections.push_back(tmp); newConnection(tmp); } diff --git a/src/CNProtocol.hpp b/src/CNProtocol.hpp index a23de27..36f024e 100644 --- a/src/CNProtocol.hpp +++ b/src/CNProtocol.hpp @@ -5,7 +5,7 @@ #include #include #include -#ifdef _WIN32 +#ifdef _WIN32 // windows #define _WINSOCK_DEPRECATED_NO_WARNINGS #include @@ -46,7 +46,7 @@ #if defined(__MINGW32__) && !defined(_GLIBCXX_HAS_GTHREADS) #include "mingw/mingw.mutex.h" -#else +#else #include #endif diff --git a/src/CNShared.cpp b/src/CNShared.cpp index 1682ade..7054fd3 100644 --- a/src/CNShared.cpp +++ b/src/CNShared.cpp @@ -2,7 +2,7 @@ #if defined(__MINGW32__) && !defined(_GLIBCXX_HAS_GTHREADS) #include "mingw/mingw.mutex.h" -#else +#else #include #endif std::map CNSharedData::players; diff --git a/src/CNStructs.hpp b/src/CNStructs.hpp index 584463a..30309ce 100644 --- a/src/CNStructs.hpp +++ b/src/CNStructs.hpp @@ -24,7 +24,7 @@ #include #include -// yes this is ugly, but this is needed to zero out the memory so we don't have random stackdata in our structs. +// yes this is ugly, but this is needed to zero out the memory so we don't have random stackdata in our structs. #define INITSTRUCT(T, x) T x; \ memset(&x, 0, sizeof(T)); diff --git a/src/ChatManager.cpp b/src/ChatManager.cpp index 2be5c3e..ac6fe8a 100644 --- a/src/ChatManager.cpp +++ b/src/ChatManager.cpp @@ -53,7 +53,7 @@ void ChatManager::emoteHandler(CNSocket* sock, CNPacketData* data) { sP_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT* emote = (sP_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT*)data->buf; PlayerView plr = PlayerManager::players[sock]; - + // send to client INITSTRUCT(sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT, resp); resp.iEmoteCode = emote->iEmoteCode; diff --git a/src/Database.cpp b/src/Database.cpp index 5b8472f..7489480 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -73,7 +73,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; @@ -83,7 +83,7 @@ void Database::open() ) } -int Database::addAccount(std::string login, std::string password) +int Database::addAccount(std::string login, std::string password) { password = BCrypt::generateHash(password); Account x = {}; @@ -100,7 +100,7 @@ void Database::updateSelected(int accountId, int slot) db.update(acc); } -std::unique_ptr Database::findAccount(std::string login) +std::unique_ptr Database::findAccount(std::string login) { //this is awful, I've tried everything to improve it auto find = db.get_all( @@ -108,7 +108,7 @@ std::unique_ptr Database::findAccount(std::string login) if (find.empty()) return nullptr; return - std::unique_ptr(new Account(find.front())); + std::unique_ptr(new Account(find.front())); } bool Database::isNameFree(sP_CL2LS_REQ_CHECK_CHAR_NAME* nameCheck) @@ -122,7 +122,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) { // fail if the player already has 4 or more characters if (db.count(where(c(&DbPlayer::AccountID) == AccountID)) >= 4) @@ -169,7 +169,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) { DbPlayer finish = getDbPlayerById(character->PCStyle.iPC_UID); finish.AppearanceFlag = 1; @@ -188,7 +188,7 @@ void Database::finishCharacter(sP_CL2LS_REQ_CHAR_CREATE* character) Inventory Foot, LB, UB; Foot.playerId = character->PCStyle.iPC_UID; Foot.id = character->sOn_Item.iEquipFootID; - Foot.Type = 3; + Foot.Type = 3; Foot.slot = 3; Foot.Opt = 1; Foot.TimeLimit = 0; @@ -209,11 +209,11 @@ void Database::finishCharacter(sP_CL2LS_REQ_CHAR_CREATE* character) db.insert(UB); } -void Database::finishTutorial(int PlayerID) +void Database::finishTutorial(int PlayerID) { Player finish = getPlayer(PlayerID); - //set flag - finish.PCStyle2.iTutorialFlag= 1; + //set flag + finish.PCStyle2.iTutorialFlag= 1; //add Gun Inventory LightningGun = {}; LightningGun.playerId = PlayerID; @@ -237,7 +237,7 @@ void Database::finishTutorial(int PlayerID) db.update(playerToDb(&finish)); } -int Database::deleteCharacter(int characterID, int userID) +int Database::deleteCharacter(int characterID, int userID) { auto find = db.get_all(where(c(&DbPlayer::PlayerID) == characterID and c(&DbPlayer::AccountID)==userID)); @@ -249,7 +249,7 @@ int Database::deleteCharacter(int characterID, int userID) return slot; } -std::vector Database::getCharacters(int UserID) +std::vector Database::getCharacters(int UserID) { std::vectorcharacters = db.get_all(where @@ -257,7 +257,7 @@ std::vector Database::getCharacters(int UserID) //parsing DbPlayer to Player std::vector result = std::vector(); for (auto &character : characters) { - Player toadd = DbToPlayer(character); + Player toadd = DbToPlayer(character); result.push_back( toadd ); @@ -340,7 +340,7 @@ Database::DbPlayer Database::playerToDb(Player *player) Player Database::DbToPlayer(DbPlayer player) { Player result = {}; // fixes some weird memory errors, this zeros out the members (not the padding inbetween though) - + result.iID = player.PlayerID; result.accountId = player.AccountID; result.PCStyle2.iAppearanceFlag = player.AppearanceFlag; @@ -374,7 +374,7 @@ Player Database::DbToPlayer(DbPlayer player) { result.equippedNanos[0] = player.Nano1; result.equippedNanos[1] = player.Nano2; result.equippedNanos[2] = player.Nano3; - + Database::getInventory(&result); Database::getNanos(&result); @@ -479,7 +479,7 @@ void Database::updateNanos(Player *player) { ); //insert for (int i=1; i < SIZEOF_NANO_BANK_SLOT; i++) - { + { if ((player->Nanos[i]).iID == 0) continue; Nano toAdd = {}; @@ -506,7 +506,7 @@ void Database::getInventory(Player* player) { toSet.iTimeLimit = current.TimeLimit; //assign to proper arrays if (current.slot <= AEQUIP_COUNT) - player->Equip[current.slot] = toSet; + player->Equip[current.slot] = toSet; else if (current.slot <= (AEQUIP_COUNT + AINVEN_COUNT)) player->Inven[current.slot - AEQUIP_COUNT] = toSet; else diff --git a/src/Database.hpp b/src/Database.hpp index 68c604e..819796f 100644 --- a/src/Database.hpp +++ b/src/Database.hpp @@ -5,7 +5,7 @@ #include namespace Database { -#pragma region DatabaseStructs +#pragma region DatabaseStructs struct Account { @@ -49,7 +49,7 @@ namespace Database { int HP; short int HairColor; short int HairStyle; - short int Height; + short int Height; short int NameCheck; short int PayZoneFlag; short int SkinColor; @@ -65,7 +65,7 @@ namespace Database { std::vector QuestFlag; }; - + #pragma endregion DatabaseStructs diff --git a/src/ItemManager.cpp b/src/ItemManager.cpp index 70f813b..25d3d0d 100644 --- a/src/ItemManager.cpp +++ b/src/ItemManager.cpp @@ -32,9 +32,9 @@ void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) { sP_CL2FE_REQ_ITEM_MOVE* itemmove = (sP_CL2FE_REQ_ITEM_MOVE*)data->buf; INITSTRUCT(sP_FE2CL_PC_ITEM_MOVE_SUCC, resp); - + PlayerView& plr = PlayerManager::players[sock]; - + //sanity check if (plr.plr->Equip[itemmove->iFromSlotNum].iType != 0 && itemmove->eFrom == 0 && itemmove->eTo == 0) { // this packet should never happen unless it is a weapon, tell the client to do nothing and do nothing ourself @@ -44,15 +44,15 @@ void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) { resp.eFrom = itemmove->eTo; resp.iFromSlotNum = itemmove->iToSlotNum; resp.FromSlotItem = plr.plr->Equip[itemmove->iFromSlotNum]; - + sock->sendPacket((void*)&resp, P_FE2CL_PC_ITEM_MOVE_SUCC, sizeof(sP_FE2CL_PC_ITEM_MOVE_SUCC)); return; } - + // sanity check - if (itemmove->iToSlotNum > ABANK_COUNT || itemmove->iToSlotNum < 0) - return; - + if (itemmove->iToSlotNum > ABANK_COUNT || itemmove->iToSlotNum < 0) + return; + //get the fromItem sItemBase *fromItem; switch ((SlotType)itemmove->eFrom) { @@ -103,7 +103,7 @@ void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) { equipChange.iEquipSlotNum = itemmove->iToSlotNum; equipChange.EquipSlotItem = resp.FromSlotItem; } - + // unequip vehicle if equip slot 8 is 0 if (plr.plr->Equip[8].iID == 0) plr.plr->iPCState = 0; @@ -116,10 +116,10 @@ void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) { //send response resp.eTo = itemmove->eFrom; - resp.iToSlotNum = itemmove->iFromSlotNum; + resp.iToSlotNum = itemmove->iFromSlotNum; resp.eFrom = itemmove->eTo; resp.iFromSlotNum = itemmove->iToSlotNum; - + sock->sendPacket((void*)&resp, P_FE2CL_PC_ITEM_MOVE_SUCC, sizeof(sP_FE2CL_PC_ITEM_MOVE_SUCC)); } @@ -160,7 +160,7 @@ void ItemManager::itemGMGiveHandler(CNSocket* sock, CNPacketData* data) { // Quest item, not a real item, handle this later, stubbed for now // sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_PC_GIVE_ITEM_FAIL, sizeof(sP_FE2CL_REP_PC_GIVE_ITEM_FAIL), sock->getFEKey())); } else if (itemreq->eIL == 1 && itemreq->Item.iType >= 0 && itemreq->Item.iType <= 10) { - + INITSTRUCT(sP_FE2CL_REP_PC_GIVE_ITEM_SUCC, resp); resp.eIL = itemreq->eIL; @@ -191,44 +191,44 @@ void ItemManager::itemTradeOfferHandler(CNSocket* sock, CNPacketData* data) { return; // ignore the malformed packet sP_CL2FE_REQ_PC_TRADE_OFFER* pacdat = (sP_CL2FE_REQ_PC_TRADE_OFFER*)data->buf; - + int iID_Check; - + if (pacdat->iID_Request == pacdat->iID_From) { iID_Check = pacdat->iID_To; } else { iID_Check = pacdat->iID_From; } - + CNSocket* otherSock = sock; - + for (auto& pair : PlayerManager::players) { - if (pair.second.plr->iID == iID_Check) { + if (pair.second.plr->iID == iID_Check) { otherSock = pair.first; break; } } - + PlayerView& plr = PlayerManager::players[otherSock]; - + if (plr.plr->isTrading) { INITSTRUCT(sP_FE2CL_REP_PC_TRADE_OFFER_REFUSAL, resp); - + resp.iID_Request = pacdat->iID_To; resp.iID_From = pacdat->iID_From; resp.iID_To = pacdat->iID_To; - + sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_TRADE_OFFER_REFUSAL, sizeof(sP_FE2CL_REP_PC_TRADE_OFFER_REFUSAL)); - + return; //prevent trading with a player already trading } - + INITSTRUCT(sP_FE2CL_REP_PC_TRADE_OFFER, resp); resp.iID_Request = pacdat->iID_Request; resp.iID_From = pacdat->iID_From; resp.iID_To = pacdat->iID_To; - + otherSock->sendPacket((void*)&resp, P_FE2CL_REP_PC_TRADE_OFFER, sizeof(sP_FE2CL_REP_PC_TRADE_OFFER)); } @@ -237,52 +237,52 @@ void ItemManager::itemTradeOfferAcceptHandler(CNSocket* sock, CNPacketData* data return; // ignore the malformed packet sP_CL2FE_REQ_PC_TRADE_OFFER_ACCEPT* pacdat = (sP_CL2FE_REQ_PC_TRADE_OFFER_ACCEPT*)data->buf; - + int iID_Check; - + if (pacdat->iID_Request == pacdat->iID_From) { iID_Check = pacdat->iID_To; } else { iID_Check = pacdat->iID_From; } - + CNSocket* otherSock = sock; - + for (auto& pair : PlayerManager::players) { - if (pair.second.plr->iID == iID_Check) { + if (pair.second.plr->iID == iID_Check) { otherSock = pair.first; break; } } - + INITSTRUCT(sP_FE2CL_REP_PC_TRADE_OFFER, resp); resp.iID_Request = pacdat->iID_Request; resp.iID_From = pacdat->iID_From; resp.iID_To = pacdat->iID_To; - + // Clearing up trade slots - + PlayerView& plr = PlayerManager::players[sock]; PlayerView& plr2 = PlayerManager::players[otherSock]; - + if (plr2.plr->isTrading) { INITSTRUCT(sP_FE2CL_REP_PC_TRADE_OFFER_REFUSAL, resp); - + resp.iID_Request = pacdat->iID_To; resp.iID_From = pacdat->iID_From; resp.iID_To = pacdat->iID_To; - + sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_TRADE_OFFER_REFUSAL, sizeof(sP_FE2CL_REP_PC_TRADE_OFFER_REFUSAL)); - + return; //prevent trading with a player already trading } - + plr.plr->isTrading = true; plr2.plr->isTrading = true; plr.plr->isTradeConfirm = false; plr2.plr->isTradeConfirm = false; - + memset(&plr.plr->Trade, 0, sizeof(plr.plr->Trade)); memset(&plr2.plr->Trade, 0, sizeof(plr2.plr->Trade)); @@ -299,19 +299,19 @@ void ItemManager::itemTradeOfferRefusalHandler(CNSocket* sock, CNPacketData* dat resp.iID_Request = pacdat->iID_Request; resp.iID_From = pacdat->iID_From; resp.iID_To = pacdat->iID_To; - + int iID_Check; - + if (pacdat->iID_Request == pacdat->iID_From) { iID_Check = pacdat->iID_To; } else { iID_Check = pacdat->iID_From; } - + CNSocket* otherSock = sock; - + for (auto& pair : PlayerManager::players) { - if (pair.second.plr->iID == iID_Check) { + if (pair.second.plr->iID == iID_Check) { otherSock = pair.first; break; } @@ -325,111 +325,111 @@ void ItemManager::itemTradeConfirmHandler(CNSocket* sock, CNPacketData* data) { return; // ignore the malformed packet sP_CL2FE_REQ_PC_TRADE_CONFIRM* pacdat = (sP_CL2FE_REQ_PC_TRADE_CONFIRM*)data->buf; - + int iID_Check; - + if (pacdat->iID_Request == pacdat->iID_From) { iID_Check = pacdat->iID_To; } else { iID_Check = pacdat->iID_From; } - + CNSocket* otherSock = sock; - + for (auto& pair : PlayerManager::players) { - if (pair.second.plr->iID == iID_Check) { + if (pair.second.plr->iID == iID_Check) { otherSock = pair.first; break; } } - + PlayerView& plr = PlayerManager::players[sock]; PlayerView& plr2 = PlayerManager::players[otherSock]; - + if (plr2.plr->isTradeConfirm) { - + plr.plr->isTrading = false; plr2.plr->isTrading = false; plr.plr->isTradeConfirm = false; plr2.plr->isTradeConfirm = false; - + // Check if we have enough free slots int freeSlots = 0; int freeSlotsNeeded = 0; int freeSlots2 = 0; int freeSlotsNeeded2 = 0; - + for (int i = 0; i < AINVEN_COUNT; i++) { if (plr.plr->Inven[i].iID == 0) freeSlots++; } - + for (int i = 0; i < 5; i++) { if (plr.plr->Trade[i].iID != 0) freeSlotsNeeded++; } - + for (int i = 0; i < AINVEN_COUNT; i++) { if (plr2.plr->Inven[i].iID == 0) freeSlots2++; } - + for (int i = 0; i < 5; i++) { if (plr2.plr->Trade[i].iID != 0) freeSlotsNeeded2++; } - + if (freeSlotsNeeded2 - freeSlotsNeeded > freeSlots) { INITSTRUCT(sP_FE2CL_REP_PC_TRADE_CONFIRM_ABORT, resp); - + resp.iID_Request = pacdat->iID_Request; resp.iID_From = pacdat->iID_From; resp.iID_To = pacdat->iID_To; - + sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_TRADE_CONFIRM_ABORT, sizeof(sP_FE2CL_REP_PC_TRADE_CONFIRM_ABORT)); otherSock->sendPacket((void*)&resp, P_FE2CL_REP_PC_TRADE_CONFIRM_ABORT, sizeof(sP_FE2CL_REP_PC_TRADE_CONFIRM_ABORT)); return; // Fail trade because of the lack of slots } - + if (freeSlotsNeeded - freeSlotsNeeded2 > freeSlots2) { INITSTRUCT(sP_FE2CL_REP_PC_TRADE_CONFIRM_CANCEL, resp); - + resp.iID_Request = pacdat->iID_Request; resp.iID_From = pacdat->iID_From; resp.iID_To = pacdat->iID_To; - + sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_TRADE_CONFIRM_CANCEL, sizeof(sP_FE2CL_REP_PC_TRADE_CONFIRM_CANCEL)); otherSock->sendPacket((void*)&resp, P_FE2CL_REP_PC_TRADE_CONFIRM_CANCEL, sizeof(sP_FE2CL_REP_PC_TRADE_CONFIRM_CANCEL)); return; // Fail trade because of the lack of slots } - + INITSTRUCT(sP_FE2CL_REP_PC_TRADE_CONFIRM, resp); - + resp.iID_Request = pacdat->iID_Request; resp.iID_From = pacdat->iID_From; resp.iID_To = pacdat->iID_To; - + sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_TRADE_CONFIRM, sizeof(sP_FE2CL_REP_PC_TRADE_CONFIRM)); // ^^ this is a must have or else the player won't accept a succ packet for some reason - + for (int i = 0; i < freeSlotsNeeded; i++) { plr.plr->Inven[plr.plr->Trade[i].iInvenNum].iID = 0; plr.plr->Inven[plr.plr->Trade[i].iInvenNum].iType = 0; plr.plr->Inven[plr.plr->Trade[i].iInvenNum].iOpt = 0; } - + for (int i = 0; i < freeSlotsNeeded2; i++) { plr2.plr->Inven[plr2.plr->Trade[i].iInvenNum].iID = 0; plr2.plr->Inven[plr2.plr->Trade[i].iInvenNum].iType = 0; plr2.plr->Inven[plr2.plr->Trade[i].iInvenNum].iOpt = 0; } - + for (int i = 0; i < AINVEN_COUNT; i++) { if (freeSlotsNeeded <= 0) break; - + if (plr2.plr->Inven[i].iID == 0) { - + plr2.plr->Inven[i].iID = plr.plr->Trade[freeSlotsNeeded - 1].iID; plr2.plr->Inven[i].iType = plr.plr->Trade[freeSlotsNeeded - 1].iType; plr2.plr->Inven[i].iOpt = plr.plr->Trade[freeSlotsNeeded - 1].iOpt; @@ -437,13 +437,13 @@ void ItemManager::itemTradeConfirmHandler(CNSocket* sock, CNPacketData* data) { freeSlotsNeeded--; } } - - for (int i = 0; i < AINVEN_COUNT; i++) { + + for (int i = 0; i < AINVEN_COUNT; i++) { if (freeSlotsNeeded2 <= 0) break; - + if (plr.plr->Inven[i].iID == 0) { - + plr.plr->Inven[i].iID = plr2.plr->Trade[freeSlotsNeeded2 - 1].iID; plr.plr->Inven[i].iType = plr2.plr->Trade[freeSlotsNeeded2 - 1].iType; plr.plr->Inven[i].iOpt = plr2.plr->Trade[freeSlotsNeeded2 - 1].iOpt; @@ -451,38 +451,38 @@ void ItemManager::itemTradeConfirmHandler(CNSocket* sock, CNPacketData* data) { freeSlotsNeeded2--; } } - + INITSTRUCT(sP_FE2CL_REP_PC_TRADE_CONFIRM_SUCC, resp2); - + resp2.iID_Request = pacdat->iID_Request; resp2.iID_From = pacdat->iID_From; resp2.iID_To = pacdat->iID_To; - + plr.plr->money = plr.plr->money + plr2.plr->moneyInTrade - plr.plr->moneyInTrade; resp2.iCandy = plr.plr->money; - + memcpy(resp2.Item, plr2.plr->Trade, sizeof(plr2.plr->Trade)); memcpy(resp2.ItemStay, plr.plr->Trade, sizeof(plr.plr->Trade)); - + sock->sendPacket((void*)&resp2, P_FE2CL_REP_PC_TRADE_CONFIRM_SUCC, sizeof(sP_FE2CL_REP_PC_TRADE_CONFIRM_SUCC)); - + plr2.plr->money = plr2.plr->money + plr.plr->moneyInTrade - plr2.plr->moneyInTrade; resp2.iCandy = plr2.plr->money; - + memcpy(resp2.Item, plr.plr->Trade, sizeof(plr.plr->Trade)); memcpy(resp2.ItemStay, plr2.plr->Trade, sizeof(plr2.plr->Trade)); - + otherSock->sendPacket((void*)&resp2, P_FE2CL_REP_PC_TRADE_CONFIRM_SUCC, sizeof(sP_FE2CL_REP_PC_TRADE_CONFIRM_SUCC)); } else { - + INITSTRUCT(sP_FE2CL_REP_PC_TRADE_CONFIRM, resp); resp.iID_Request = pacdat->iID_Request; resp.iID_From = pacdat->iID_From; resp.iID_To = pacdat->iID_To; - + plr.plr->isTradeConfirm = true; - + sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_TRADE_CONFIRM, sizeof(sP_FE2CL_REP_PC_TRADE_CONFIRM)); otherSock->sendPacket((void*)&resp, P_FE2CL_REP_PC_TRADE_CONFIRM, sizeof(sP_FE2CL_REP_PC_TRADE_CONFIRM)); } @@ -498,26 +498,26 @@ void ItemManager::itemTradeConfirmCancelHandler(CNSocket* sock, CNPacketData* da resp.iID_Request = pacdat->iID_Request; resp.iID_From = pacdat->iID_From; resp.iID_To = pacdat->iID_To; - + int iID_Check; - + if (pacdat->iID_Request == pacdat->iID_From) { iID_Check = pacdat->iID_To; } else { iID_Check = pacdat->iID_From; } - + CNSocket* otherSock = sock; - + for (auto pair : PlayerManager::players) { - if (pair.second.plr->iID == iID_Check) { + if (pair.second.plr->iID == iID_Check) { otherSock = pair.first; } } - + PlayerView& plr = PlayerManager::players[sock]; PlayerView& plr2 = PlayerManager::players[otherSock]; - + plr.plr->isTrading = false; plr.plr->isTradeConfirm = false; plr2.plr->isTrading = false; @@ -531,10 +531,10 @@ void ItemManager::itemTradeRegisterItemHandler(CNSocket* sock, CNPacketData* dat return; // ignore the malformed packet sP_CL2FE_REQ_PC_TRADE_ITEM_REGISTER* pacdat = (sP_CL2FE_REQ_PC_TRADE_ITEM_REGISTER*)data->buf; - + if (pacdat->Item.iSlotNum < 0 || pacdat->Item.iSlotNum > 4) return; // sanity check - + INITSTRUCT(sP_FE2CL_REP_PC_TRADE_ITEM_REGISTER_SUCC, resp); resp.iID_Request = pacdat->iID_Request; @@ -542,27 +542,27 @@ void ItemManager::itemTradeRegisterItemHandler(CNSocket* sock, CNPacketData* dat resp.iID_To = pacdat->iID_To; resp.TradeItem = pacdat->Item; resp.InvenItem = pacdat->Item; - + int iID_Check; - + if (pacdat->iID_Request == pacdat->iID_From) { iID_Check = pacdat->iID_To; } else { iID_Check = pacdat->iID_From; } - + CNSocket* otherSock = sock; - + for (auto pair : PlayerManager::players) { - if (pair.second.plr->iID == iID_Check) { + if (pair.second.plr->iID == iID_Check) { otherSock = pair.first; } } - + PlayerView& plr = PlayerManager::players[sock]; plr.plr->Trade[pacdat->Item.iSlotNum] = pacdat->Item; plr.plr->isTradeConfirm = false; - + sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_TRADE_ITEM_REGISTER_SUCC, sizeof(sP_FE2CL_REP_PC_TRADE_ITEM_REGISTER_SUCC)); otherSock->sendPacket((void*)&resp, P_FE2CL_REP_PC_TRADE_ITEM_REGISTER_SUCC, sizeof(sP_FE2CL_REP_PC_TRADE_ITEM_REGISTER_SUCC)); } @@ -578,29 +578,29 @@ void ItemManager::itemTradeUnregisterItemHandler(CNSocket* sock, CNPacketData* d resp.iID_From = pacdat->iID_From; resp.iID_To = pacdat->iID_To; resp.TradeItem = pacdat->Item; - + PlayerView& plr = PlayerManager::players[sock]; resp.InvenItem = plr.plr->Trade[pacdat->Item.iSlotNum]; plr.plr->isTradeConfirm = false; - + int iID_Check; - + if (pacdat->iID_Request == pacdat->iID_From) { iID_Check = pacdat->iID_To; } else { iID_Check = pacdat->iID_From; } - + CNSocket* otherSock = sock; - + for (auto pair : PlayerManager::players) { - if (pair.second.plr->iID == iID_Check) { + if (pair.second.plr->iID == iID_Check) { otherSock = pair.first; } } - + int temp_num = pacdat->Item.iSlotNum; - + if (temp_num >= 0 && temp_num <= 4) { plr.plr->Trade[temp_num].iID = 0; plr.plr->Trade[temp_num].iType = 0; @@ -608,7 +608,7 @@ void ItemManager::itemTradeUnregisterItemHandler(CNSocket* sock, CNPacketData* d plr.plr->Trade[temp_num].iInvenNum = 0; plr.plr->Trade[temp_num].iSlotNum = 0; } - + sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_TRADE_ITEM_UNREGISTER_SUCC, sizeof(sP_FE2CL_REP_PC_TRADE_ITEM_UNREGISTER_SUCC)); otherSock->sendPacket((void*)&resp, P_FE2CL_REP_PC_TRADE_ITEM_UNREGISTER_SUCC, sizeof(sP_FE2CL_REP_PC_TRADE_ITEM_UNREGISTER_SUCC)); } @@ -618,38 +618,38 @@ void ItemManager::itemTradeRegisterCashHandler(CNSocket* sock, CNPacketData* dat return; // ignore the malformed packet sP_CL2FE_REQ_PC_TRADE_CASH_REGISTER* pacdat = (sP_CL2FE_REQ_PC_TRADE_CASH_REGISTER*)data->buf; - + PlayerView& plr = PlayerManager::players[sock]; - + if (pacdat->iCandy < 0 || pacdat->iCandy > plr.plr->money) return; // famous glitch, begone - + INITSTRUCT(sP_FE2CL_REP_PC_TRADE_CASH_REGISTER_SUCC, resp); resp.iID_Request = pacdat->iID_Request; resp.iID_From = pacdat->iID_From; resp.iID_To = pacdat->iID_To; resp.iCandy = pacdat->iCandy; - + int iID_Check; - + if (pacdat->iID_Request == pacdat->iID_From) { iID_Check = pacdat->iID_To; } else { iID_Check = pacdat->iID_From; } - + CNSocket* otherSock = sock; - + for (auto pair : PlayerManager::players) { - if (pair.second.plr->iID == iID_Check) { + if (pair.second.plr->iID == iID_Check) { otherSock = pair.first; } } - + plr.plr->moneyInTrade = pacdat->iCandy; plr.plr->isTradeConfirm = false; - + sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_TRADE_CASH_REGISTER_SUCC, sizeof(sP_FE2CL_REP_PC_TRADE_CASH_REGISTER_SUCC)); otherSock->sendPacket((void*)&resp, P_FE2CL_REP_PC_TRADE_CASH_REGISTER_SUCC, sizeof(sP_FE2CL_REP_PC_TRADE_CASH_REGISTER_SUCC)); } @@ -658,33 +658,33 @@ void ItemManager::itemTradeChatHandler(CNSocket* sock, CNPacketData* data) { if (data->size != sizeof(sP_CL2FE_REQ_PC_TRADE_EMOTES_CHAT)) return; // malformed packet sP_CL2FE_REQ_PC_TRADE_EMOTES_CHAT* pacdat = (sP_CL2FE_REQ_PC_TRADE_EMOTES_CHAT*)data->buf; - + INITSTRUCT(sP_FE2CL_REP_PC_TRADE_EMOTES_CHAT, resp); - + resp.iID_Request = pacdat->iID_Request; resp.iID_From = pacdat->iID_From; resp.iID_To = pacdat->iID_To; - + memcpy(resp.szFreeChat, pacdat->szFreeChat, sizeof(pacdat->szFreeChat)); - + resp.iEmoteCode = pacdat->iEmoteCode; - + int iID_Check; - + if (pacdat->iID_Request == pacdat->iID_From) { iID_Check = pacdat->iID_To; } else { iID_Check = pacdat->iID_From; } - + CNSocket* otherSock = sock; - + for (auto pair : PlayerManager::players) { - if (pair.second.plr->iID == iID_Check) { + if (pair.second.plr->iID == iID_Check) { otherSock = pair.first; } } - + sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_TRADE_EMOTES_CHAT, sizeof(sP_FE2CL_REP_PC_TRADE_EMOTES_CHAT)); otherSock->sendPacket((void*)&resp, P_FE2CL_REP_PC_TRADE_EMOTES_CHAT, sizeof(sP_FE2CL_REP_PC_TRADE_EMOTES_CHAT)); } diff --git a/src/ItemManager.hpp b/src/ItemManager.hpp index 3f4103b..18cae7d 100644 --- a/src/ItemManager.hpp +++ b/src/ItemManager.hpp @@ -9,10 +9,10 @@ namespace ItemManager { INVENTORY = 1, BANK = 3 }; - void init(); + void init(); - void itemMoveHandler(CNSocket* sock, CNPacketData* data); - void itemDeleteHandler(CNSocket* sock, CNPacketData* data); + void itemMoveHandler(CNSocket* sock, CNPacketData* data); + void itemDeleteHandler(CNSocket* sock, CNPacketData* data); void itemGMGiveHandler(CNSocket* sock, CNPacketData* data); //Bank void itemBankOpenHandler(CNSocket* sock, CNPacketData* data); diff --git a/src/NPCManager.cpp b/src/NPCManager.cpp index f2afc12..d1e7f76 100644 --- a/src/NPCManager.cpp +++ b/src/NPCManager.cpp @@ -78,7 +78,7 @@ void NPCManager::npcVendorSell(CNSocket* sock, CNPacketData* data) { sItemBase* item = &plr->Inven[req->iInvenSlotNum]; INITSTRUCT(sP_FE2CL_REP_PC_VENDOR_ITEM_SELL_SUCC, resp); - + int sellValue = 100 * req->iItemCnt; // TODO: lookup item price // increment taros diff --git a/src/NanoManager.cpp b/src/NanoManager.cpp index d48ed5d..3881da0 100644 --- a/src/NanoManager.cpp +++ b/src/NanoManager.cpp @@ -162,7 +162,7 @@ void NanoManager::addNano(CNSocket* sock, int16_t nanoId, int16_t slot) { * P_FE2CL_REP_PC_CHANGE_LEVEL appear to play the same animation, but only the latter affects * the other player's displayed level. */ - + INITSTRUCT(sP_FE2CL_REP_PC_CHANGE_LEVEL, resp2); resp2.iPC_ID = plr->iID; diff --git a/src/PlayerManager.cpp b/src/PlayerManager.cpp index 05867c9..3d92b1e 100644 --- a/src/PlayerManager.cpp +++ b/src/PlayerManager.cpp @@ -226,7 +226,7 @@ void PlayerManager::enterPlayer(CNSocket* sock, CNPacketData* data) { for (int i = 0; i < AINVEN_COUNT; i++) response.PCLoadData2CL.aInven[i] = plr.Inven[i]; - //nanos + //nanos for (int i = 1; i < SIZEOF_NANO_BANK_SLOT; i++) { response.PCLoadData2CL.aNanoBank[i] = plr.Nanos[i]; } @@ -666,23 +666,23 @@ void PlayerManager::revivePlayer(CNSocket* sock, CNPacketData* data) { } void PlayerManager::enterPlayerVehicle(CNSocket* sock, CNPacketData* data) { - + PlayerView& plr = PlayerManager::players[sock]; - + if (plr.plr->Equip[8].iID > 0) { 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)); - + //send to other players plr.plr->iPCState = 8; INITSTRUCT(sP_FE2CL_PC_STATE_CHANGE, response2); response2.iPC_ID = plr.plr->iID; response2.iState = 8; - + for (CNSocket* otherSock : plr.viewable) { otherSock->sendPacket((void*)&response2, P_FE2CL_PC_STATE_CHANGE, sizeof(sP_FE2CL_PC_STATE_CHANGE)); } - + } else { 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)); @@ -690,10 +690,10 @@ void PlayerManager::enterPlayerVehicle(CNSocket* sock, CNPacketData* data) { } void PlayerManager::exitPlayerVehicle(CNSocket* sock, CNPacketData* data) { - + 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)); - + PlayerView plr = PlayerManager::players[sock]; //send to other players @@ -701,10 +701,10 @@ void PlayerManager::exitPlayerVehicle(CNSocket* sock, CNPacketData* data) { INITSTRUCT(sP_FE2CL_PC_STATE_CHANGE, response2); response2.iPC_ID = plr.plr->iID; response2.iState = 0; - + for (CNSocket* otherSock : plr.viewable) { otherSock->sendPacket((void*)&response2, P_FE2CL_PC_STATE_CHANGE, sizeof(sP_FE2CL_PC_STATE_CHANGE)); - } + } } void PlayerManager::setSpecialSwitchPlayer(CNSocket* sock, CNPacketData* data) { diff --git a/src/TableData.cpp b/src/TableData.cpp index 8486dee..df367b1 100644 --- a/src/TableData.cpp +++ b/src/TableData.cpp @@ -21,11 +21,11 @@ void TableData::init() { for (nlohmann::json::iterator npc = npcData.begin(); npc != npcData.end(); npc++) { BaseNPC tmp(npc.value()["x"], npc.value()["y"], npc.value()["z"], npc.value()["id"]); - + // Temporary fix, IDs will be pulled from json later tmp.appearanceData.iNPC_ID = i; i++; - + NPCManager::NPCs[tmp.appearanceData.iNPC_ID] = tmp; if (npc.value()["id"] == 641 || npc.value()["id"] == 642) @@ -48,11 +48,11 @@ void TableData::init() { for (nlohmann::json::iterator npc = npcData.begin(); npc != npcData.end(); npc++) { BaseNPC tmp(npc.value()["iX"], npc.value()["iY"], npc.value()["iZ"], npc.value()["iNPCType"], npc.value()["iHP"], npc.value()["iConditionBitFlag"], npc.value()["iAngle"], npc.value()["iBarkerType"]); - + // Temporary fix, IDs will be pulled from json later tmp.appearanceData.iNPC_ID = i; i++; - + NPCManager::NPCs[tmp.appearanceData.iNPC_ID] = tmp; } diff --git a/src/TransportManager.cpp b/src/TransportManager.cpp index f93f616..4db7acc 100644 --- a/src/TransportManager.cpp +++ b/src/TransportManager.cpp @@ -15,7 +15,7 @@ void TransportManager::init() { void TransportManager::transportRegisterLocationHandler(CNSocket* sock, CNPacketData* data) { if (data->size != sizeof(sP_CL2FE_REQ_REGIST_TRANSPORTATION_LOCATION)) return; // malformed packet - + sP_CL2FE_REQ_REGIST_TRANSPORTATION_LOCATION* transport = (sP_CL2FE_REQ_REGIST_TRANSPORTATION_LOCATION*)data->buf; Player* plr = PlayerManager::getPlayer(sock); @@ -48,7 +48,7 @@ void TransportManager::transportRegisterLocationHandler(CNSocket* sock, CNPacket return; } - /* + /* * assuming the two bitfields are just stuck together to make a longer one... do a similar operation, but on the respective integer * this approach seems to work with initial testing, but we have yet to see a monkey ID greater than 63. */ @@ -106,7 +106,7 @@ void TransportManager::transportWarpHandler(CNSocket* sock, CNPacketData* data) TransportRoute route = Routes[req->iTransporationID]; plr->money -= route.cost; - + TransportLocation target = Locations[route.end]; switch (route.type) { @@ -133,7 +133,7 @@ void TransportManager::transportWarpHandler(CNSocket* sock, CNPacketData* data) resp.iZ = plr->z; /* - * Not strictly necessary since there isn't a valid SCAMPER that puts you in the + * Not strictly necessary since there isn't a valid SCAMPER that puts you in the * same map tile you were already in, but we might as well force an NPC reload. */ PlayerView& plrv = PlayerManager::players[sock]; diff --git a/src/main.cpp b/src/main.cpp index 110acbb..0d7d97b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,7 +15,7 @@ #if defined(__MINGW32__) && !defined(_GLIBCXX_HAS_GTHREADS) #include "mingw/mingw.thread.h" -#else +#else #include #endif #include diff --git a/src/settings.cpp b/src/settings.cpp index 6da8989..9fb3b22 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -31,14 +31,14 @@ void settings::init() { if (reader.ParseError() != 0) { if (reader.ParseError() == -1) std::cerr << "[WARN] Settings: missing config.ini file!" << std::endl; - else + else std::cerr << "[WARN] Settings: invalid config.ini syntax at line " << reader.ParseError() << std::endl; return; } APPROVEALLNAMES = reader.GetBoolean("", "acceptallcustomnames", APPROVEALLNAMES); - VERBOSITY = reader.GetInteger("", "verbosity", VERBOSITY); + VERBOSITY = reader.GetInteger("", "verbosity", VERBOSITY); LOGINPORT = reader.GetInteger("login", "port", LOGINPORT); SHARDPORT = reader.GetInteger("shard", "port", SHARDPORT); SHARDSERVERIP = reader.Get("shard", "ip", "127.0.0.1");