Cleaned up all whitespace issues.

The incantation was: sed -i 's/[ \t]*$//g' src/*.[ch]pp
This commit is contained in:
dongresource 2020-09-14 15:53:48 +02:00
parent ed86bc9160
commit 131997f34f
18 changed files with 232 additions and 232 deletions

View File

@ -24,7 +24,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
if (data->size != sizeof(sP_CL2LS_REQ_LOGIN)) if (data->size != sizeof(sP_CL2LS_REQ_LOGIN))
return; // ignore the malformed packet 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 //TODO: implement better way of sending credentials
std::string userLogin((char*)login->szCookie_TEGid); std::string userLogin((char*)login->szCookie_TEGid);
std::string userPassword((char*)login->szCookie_authid); std::string userPassword((char*)login->szCookie_authid);
@ -49,8 +49,8 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
if (!CNLoginServer::isLoginDataGood(userLogin, userPassword)) if (!CNLoginServer::isLoginDataGood(userLogin, userPassword))
{ {
errorCode = (int)LoginError::LOGIN_ERROR; errorCode = (int)LoginError::LOGIN_ERROR;
} }
else else
{ {
std::unique_ptr<Database::Account> findUser = Database::findAccount(userLogin); std::unique_ptr<Database::Account> findUser = Database::findAccount(userLogin);
//if account not found, create it //if account not found, create it
@ -59,7 +59,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
loginSessions[sock] = CNLoginData(); loginSessions[sock] = CNLoginData();
loginSessions[sock].userID = Database::addAccount(userLogin, userPassword); loginSessions[sock].userID = Database::addAccount(userLogin, userPassword);
loginSessions[sock].slot = 1; loginSessions[sock].slot = 1;
success = true; success = true;
} }
//if user exists, check if password is correct //if user exists, check if password is correct
else if (CNLoginServer::isPasswordCorrect(findUser->Password, userPassword)) 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; errorCode = (int)LoginError::ID_ALREADY_IN_USE;
} }
//if not, login success //if not, login success
else else
{ {
loginSessions[sock] = CNLoginData(); loginSessions[sock] = CNLoginData();
loginSessions[sock].userID = findUser->AccountID; loginSessions[sock].userID = findUser->AccountID;
loginSessions[sock].slot = findUser->Selected; loginSessions[sock].slot = findUser->Selected;
success = true; success = true;
} }
} }
else else
{ {
errorCode = (int)LoginError::ID_AND_PASSWORD_DO_NOT_MATCH; errorCode = (int)LoginError::ID_AND_PASSWORD_DO_NOT_MATCH;
@ -107,8 +107,8 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
// update keys // update keys
sock->setEKey(CNSocketEncryption::createNewKey(resp.uiSvrTime, resp.iCharCount + 1, resp.iSlotNum + 1)); 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)); sock->setFEKey(CNSocketEncryption::createNewKey((uint64_t)(*(uint64_t*)&CNSocketEncryption::defaultKey[0]), login->iClientVerC, 1));
// now send the characters :) // now send the characters :)
std::vector<Player>::iterator it; std::vector<Player>::iterator it;
for (it = characters.begin(); it != characters.end(); 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) //save character in session (for char select)
int UID = it->iID; int UID = it->iID;
loginSessions[sock].characters[UID] = Player(*it); loginSessions[sock].characters[UID] = Player(*it);
loginSessions[sock].characters[UID].FEKey = sock->getFEKey(); loginSessions[sock].characters[UID].FEKey = sock->getFEKey();
//Equip info //Equip info
for (int i = 0; i < AEQUIP_COUNT; i++) { for (int i = 0; i < AEQUIP_COUNT; i++) {
charInfo.aEquip[i] = it->Equip[i]; charInfo.aEquip[i] = it->Equip[i];
} }
@ -138,16 +138,16 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
if (it == characters.begin()) if (it == characters.begin())
loginSessions[sock].selectedChar = UID; 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 //Failure
else { else {
INITSTRUCT(sP_LS2CL_REP_LOGIN_FAIL, resp); INITSTRUCT(sP_LS2CL_REP_LOGIN_FAIL, resp);
memcpy(resp.szID, login->szID, sizeof(char16_t) * 33); memcpy(resp.szID, login->szID, sizeof(char16_t) * 33);
resp.iErrorCode = errorCode; resp.iErrorCode = errorCode;
sock->sendPacket((void*)&resp, P_LS2CL_REP_LOGIN_FAIL, sizeof(sP_LS2CL_REP_LOGIN_FAIL)); 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: { case P_CL2LS_REQ_CHECK_CHAR_NAME: {
if (data->size != sizeof(sP_CL2LS_REQ_CHECK_CHAR_NAME)) if (data->size != sizeof(sP_CL2LS_REQ_CHECK_CHAR_NAME))
return; return;
sP_CL2LS_REQ_CHECK_CHAR_NAME* nameCheck = (sP_CL2LS_REQ_CHECK_CHAR_NAME*)data->buf; sP_CL2LS_REQ_CHECK_CHAR_NAME* nameCheck = (sP_CL2LS_REQ_CHECK_CHAR_NAME*)data->buf;
bool success = true; bool success = true;
int errorcode = 0; int errorcode = 0;
@ -196,10 +196,10 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
case P_CL2LS_REQ_SAVE_CHAR_NAME: { case P_CL2LS_REQ_SAVE_CHAR_NAME: {
if (data->size != sizeof(sP_CL2LS_REQ_SAVE_CHAR_NAME)) if (data->size != sizeof(sP_CL2LS_REQ_SAVE_CHAR_NAME))
return; return;
sP_CL2LS_REQ_SAVE_CHAR_NAME* save = (sP_CL2LS_REQ_SAVE_CHAR_NAME*)data->buf; sP_CL2LS_REQ_SAVE_CHAR_NAME* save = (sP_CL2LS_REQ_SAVE_CHAR_NAME*)data->buf;
INITSTRUCT(sP_LS2CL_REP_SAVE_CHAR_NAME_SUCC, resp); INITSTRUCT(sP_LS2CL_REP_SAVE_CHAR_NAME_SUCC, resp);
DEBUGLOG( DEBUGLOG(
std::cout << "P_CL2LS_REQ_SAVE_CHAR_NAME:" << std::endl; std::cout << "P_CL2LS_REQ_SAVE_CHAR_NAME:" << std::endl;
std::cout << "\tSlot: " << (int)save->iSlotNum << 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: { case P_CL2LS_REQ_CHAR_CREATE: {
if (data->size != sizeof(sP_CL2LS_REQ_CHAR_CREATE)) if (data->size != sizeof(sP_CL2LS_REQ_CHAR_CREATE))
return; return;
sP_CL2LS_REQ_CHAR_CREATE* character = (sP_CL2LS_REQ_CHAR_CREATE*)data->buf; sP_CL2LS_REQ_CHAR_CREATE* character = (sP_CL2LS_REQ_CHAR_CREATE*)data->buf;
Database::finishCharacter(character); Database::finishCharacter(character);
@ -255,7 +255,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
//save player in session //save player in session
loginSessions[sock].characters[UID] = Player(player); loginSessions[sock].characters[UID] = Player(player);
loginSessions[sock].characters[UID].FEKey = sock->getFEKey(); loginSessions[sock].characters[UID].FEKey = sock->getFEKey();
sock->sendPacket((void*)&resp, P_LS2CL_REP_CHAR_CREATE_SUCC, sizeof(sP_LS2CL_REP_CHAR_CREATE_SUCC)); sock->sendPacket((void*)&resp, P_LS2CL_REP_CHAR_CREATE_SUCC, sizeof(sP_LS2CL_REP_CHAR_CREATE_SUCC));
Database::updateSelected(loginSessions[sock].userID, player.slot); Database::updateSelected(loginSessions[sock].userID, player.slot);
break; 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; sP_CL2LS_REQ_CHAR_DELETE* del = (sP_CL2LS_REQ_CHAR_DELETE*)data->buf;
int operationResult = Database::deleteCharacter(del->iPC_UID, loginSessions[sock].userID); int operationResult = Database::deleteCharacter(del->iPC_UID, loginSessions[sock].userID);
INITSTRUCT(sP_LS2CL_REP_CHAR_DELETE_SUCC, resp); INITSTRUCT(sP_LS2CL_REP_CHAR_DELETE_SUCC, resp);
resp.iSlotNum = operationResult; resp.iSlotNum = operationResult;
sock->sendPacket((void*)&resp, P_LS2CL_REP_CHAR_DELETE_SUCC, sizeof(sP_LS2CL_REP_CHAR_DELETE_SUCC)); 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: { case P_CL2LS_REQ_CHAR_SELECT: {
if (data->size != sizeof(sP_CL2LS_REQ_CHAR_SELECT)) if (data->size != sizeof(sP_CL2LS_REQ_CHAR_SELECT))
return; return;
// character selected // character selected
sP_CL2LS_REQ_CHAR_SELECT* chararacter = (sP_CL2LS_REQ_CHAR_SELECT*)data->buf; sP_CL2LS_REQ_CHAR_SELECT* chararacter = (sP_CL2LS_REQ_CHAR_SELECT*)data->buf;
INITSTRUCT(sP_LS2CL_REP_CHAR_SELECT_SUCC, resp); INITSTRUCT(sP_LS2CL_REP_CHAR_SELECT_SUCC, resp);
@ -284,7 +284,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
DEBUGLOG( DEBUGLOG(
std::cout << "P_CL2LS_REQ_CHAR_SELECT:" << std::endl; std::cout << "P_CL2LS_REQ_CHAR_SELECT:" << std::endl;
std::cout << "\tPC_UID: " << chararacter->iPC_UID << std::endl; std::cout << "\tPC_UID: " << chararacter->iPC_UID << std::endl;
) )
loginSessions[sock].selectedChar = chararacter->iPC_UID; loginSessions[sock].selectedChar = chararacter->iPC_UID;
Database::updateSelected(loginSessions[sock].userID, loginSessions[sock].characters[chararacter->iPC_UID].slot); 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)); 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: { case P_CL2LS_REQ_SHARD_SELECT: {
if (data->size != sizeof(sP_CL2LS_REQ_SHARD_SELECT)) if (data->size != sizeof(sP_CL2LS_REQ_SHARD_SELECT))
return; return;
// tell client to connect to the shard server // tell client to connect to the shard server
sP_CL2LS_REQ_SHARD_SELECT* shard = (sP_CL2LS_REQ_SHARD_SELECT*)data->buf; sP_CL2LS_REQ_SHARD_SELECT* shard = (sP_CL2LS_REQ_SHARD_SELECT*)data->buf;
INITSTRUCT(sP_LS2CL_REP_SHARD_SELECT_SUCC, resp); INITSTRUCT(sP_LS2CL_REP_SHARD_SELECT_SUCC, resp);
@ -353,8 +353,8 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
int accountId = account->AccountID; int accountId = account->AccountID;
if (!exitDuplicate(accountId)) if (!exitDuplicate(accountId))
PlayerManager::exitDuplicate(accountId); PlayerManager::exitDuplicate(accountId);
break; break;
} }
default: default:

View File

@ -29,7 +29,7 @@ class CNLoginServer : public CNServer {
private: private:
static void handlePacket(CNSocket* sock, CNPacketData* data); static void handlePacket(CNSocket* sock, CNPacketData* data);
static std::map<CNSocket*, CNLoginData> loginSessions; static std::map<CNSocket*, CNLoginData> loginSessions;
static bool isLoginDataGood(std::string login, std::string password); static bool isLoginDataGood(std::string login, std::string password);
static bool isPasswordCorrect(std::string actualPassword, std::string tryPassword); static bool isPasswordCorrect(std::string actualPassword, std::string tryPassword);
static bool isAccountInUse(int accountId); static bool isAccountInUse(int accountId);
@ -40,5 +40,5 @@ public:
CNLoginServer(uint16_t p); CNLoginServer(uint16_t p);
void newConnection(CNSocket* cns); void newConnection(CNSocket* cns);
void killConnection(CNSocket* cns); void killConnection(CNSocket* cns);
}; };

View File

@ -83,7 +83,7 @@ bool CNSocket::sendData(uint8_t* data, int size) {
} }
sentBytes += sent; sentBytes += sent;
} }
return true; // it worked! return true; // it worked!
} }
@ -122,7 +122,7 @@ void CNSocket::kill() {
void CNSocket::sendPacket(void* buf, uint32_t type, size_t size) { void CNSocket::sendPacket(void* buf, uint32_t type, size_t size) {
if (!alive) if (!alive)
return; return;
size_t bodysize = size + sizeof(uint32_t); size_t bodysize = size + sizeof(uint32_t);
uint8_t* fullpkt = (uint8_t*)xmalloc(bodysize+4); uint8_t* fullpkt = (uint8_t*)xmalloc(bodysize+4);
uint8_t* body = fullpkt+4; uint8_t* body = fullpkt+4;
@ -150,7 +150,7 @@ void CNSocket::sendPacket(void* buf, uint32_t type, size_t size) {
} }
// send packet data! // send packet data!
if (alive && !sendData(fullpkt, bodysize+4)) if (alive && !sendData(fullpkt, bodysize+4))
kill(); kill();
free(fullpkt); free(fullpkt);
@ -183,7 +183,7 @@ void CNSocket::step() {
return; return;
} }
} }
if (readSize > 0 && readBufferIndex < readSize) { if (readSize > 0 && readBufferIndex < readSize) {
// read until the end of the packet! (or at least try too) // read until the end of the packet! (or at least try too)
int recved = recv(sock, (buffer_t*)(readBuffer + readBufferIndex), readSize - readBufferIndex, 0); 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 // decrypt readBuffer and copy to CNPacketData
CNSocketEncryption::decryptData((uint8_t*)&readBuffer, (uint8_t*)(&EKey), readSize); CNSocketEncryption::decryptData((uint8_t*)&readBuffer, (uint8_t*)(&EKey), readSize);
@ -216,38 +216,38 @@ void CNSocket::step() {
// ========================================================[[ CNServer ]]======================================================== // ========================================================[[ CNServer ]]========================================================
void CNServer::init() { void CNServer::init() {
// create socket file descriptor // create socket file descriptor
sock = socket(AF_INET, SOCK_STREAM, 0); sock = socket(AF_INET, SOCK_STREAM, 0);
if (SOCKETINVALID(sock)) { if (SOCKETINVALID(sock)) {
std::cerr << "[FATAL] OpenFusion: socket failed" << std::endl; std::cerr << "[FATAL] OpenFusion: socket failed" << std::endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
// attach socket to the port // attach socket to the port
int opt = 1; int opt = 1;
#ifdef _WIN32 #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 #else
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) != 0) { if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) != 0) {
#endif #endif
std::cerr << "[FATAL] OpenFusion: setsockopt failed" << std::endl; std::cerr << "[FATAL] OpenFusion: setsockopt failed" << std::endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
address.sin_family = AF_INET; address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY; address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons(port); address.sin_port = htons(port);
addressSize = sizeof(address); addressSize = sizeof(address);
// Bind to the port // Bind to the port
if (SOCKETERROR(bind(sock, (struct sockaddr *)&address, addressSize))) { if (SOCKETERROR(bind(sock, (struct sockaddr *)&address, addressSize))) {
std::cerr << "[FATAL] OpenFusion: bind failed" << std::endl; std::cerr << "[FATAL] OpenFusion: bind failed" << std::endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (SOCKETERROR(listen(sock, SOMAXCONN))) { if (SOCKETERROR(listen(sock, SOMAXCONN))) {
std::cerr << "[FATAL] OpenFusion: listen failed" << std::endl; std::cerr << "[FATAL] OpenFusion: listen failed" << std::endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
// set server listener to non-blocking // set server listener to non-blocking
@ -257,8 +257,8 @@ void CNServer::init() {
#else #else
if (fcntl(sock, F_SETFL, (fcntl(sock, F_GETFL, 0) | O_NONBLOCK)) != 0) { if (fcntl(sock, F_SETFL, (fcntl(sock, F_GETFL, 0) | O_NONBLOCK)) != 0) {
#endif #endif
std::cerr << "[FATAL] OpenFusion: fcntl failed" << std::endl; std::cerr << "[FATAL] OpenFusion: fcntl failed" << std::endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
@ -281,7 +281,7 @@ void CNServer::start() {
#else #else
if (fcntl(newConnectionSocket, F_SETFL, (fcntl(sock, F_GETFL, 0) | O_NONBLOCK)) != 0) { if (fcntl(newConnectionSocket, F_SETFL, (fcntl(sock, F_GETFL, 0) | O_NONBLOCK)) != 0) {
#endif #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 #ifdef _WIN32
shutdown(newConnectionSocket, SD_BOTH); shutdown(newConnectionSocket, SD_BOTH);
closesocket(newConnectionSocket); closesocket(newConnectionSocket);
@ -295,7 +295,7 @@ void CNServer::start() {
std::cout << "New connection! " << inet_ntoa(address.sin_addr) << std::endl; std::cout << "New connection! " << inet_ntoa(address.sin_addr) << std::endl;
// add connection to list! // add connection to list!
CNSocket* tmp = new CNSocket(newConnectionSocket, pHandler); CNSocket* tmp = new CNSocket(newConnectionSocket, pHandler);
connections.push_back(tmp); connections.push_back(tmp);
newConnection(tmp); newConnection(tmp);
} }

View File

@ -5,7 +5,7 @@
#include <iostream> #include <iostream>
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#ifdef _WIN32 #ifdef _WIN32
// windows // windows
#define _WINSOCK_DEPRECATED_NO_WARNINGS #define _WINSOCK_DEPRECATED_NO_WARNINGS
#include <winsock2.h> #include <winsock2.h>
@ -46,7 +46,7 @@
#if defined(__MINGW32__) && !defined(_GLIBCXX_HAS_GTHREADS) #if defined(__MINGW32__) && !defined(_GLIBCXX_HAS_GTHREADS)
#include "mingw/mingw.mutex.h" #include "mingw/mingw.mutex.h"
#else #else
#include <mutex> #include <mutex>
#endif #endif

View File

@ -2,7 +2,7 @@
#if defined(__MINGW32__) && !defined(_GLIBCXX_HAS_GTHREADS) #if defined(__MINGW32__) && !defined(_GLIBCXX_HAS_GTHREADS)
#include "mingw/mingw.mutex.h" #include "mingw/mingw.mutex.h"
#else #else
#include <mutex> #include <mutex>
#endif #endif
std::map<int64_t, Player> CNSharedData::players; std::map<int64_t, Player> CNSharedData::players;

View File

@ -24,7 +24,7 @@
#include <locale> #include <locale>
#include <codecvt> #include <codecvt>
// 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; \ #define INITSTRUCT(T, x) T x; \
memset(&x, 0, sizeof(T)); memset(&x, 0, sizeof(T));

View File

@ -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; sP_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT* emote = (sP_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT*)data->buf;
PlayerView plr = PlayerManager::players[sock]; PlayerView plr = PlayerManager::players[sock];
// send to client // send to client
INITSTRUCT(sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT, resp); INITSTRUCT(sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT, resp);
resp.iEmoteCode = emote->iEmoteCode; resp.iEmoteCode = emote->iEmoteCode;

View File

@ -73,7 +73,7 @@ auto db = make_storage("database.db",
#pragma region LoginServer #pragma region LoginServer
void Database::open() void Database::open()
{ {
//this parameter means it will try to preserve data during migration //this parameter means it will try to preserve data during migration
bool preserve = true; 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); password = BCrypt::generateHash(password);
Account x = {}; Account x = {};
@ -100,7 +100,7 @@ void Database::updateSelected(int accountId, int slot)
db.update(acc); db.update(acc);
} }
std::unique_ptr<Database::Account> Database::findAccount(std::string login) std::unique_ptr<Database::Account> Database::findAccount(std::string login)
{ {
//this is awful, I've tried everything to improve it //this is awful, I've tried everything to improve it
auto find = db.get_all<Account>( auto find = db.get_all<Account>(
@ -108,7 +108,7 @@ std::unique_ptr<Database::Account> Database::findAccount(std::string login)
if (find.empty()) if (find.empty())
return nullptr; return nullptr;
return return
std::unique_ptr<Account>(new Account(find.front())); std::unique_ptr<Account>(new Account(find.front()));
} }
bool Database::isNameFree(sP_CL2LS_REQ_CHECK_CHAR_NAME* nameCheck) 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()); .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 // fail if the player already has 4 or more characters
if (db.count<DbPlayer>(where(c(&DbPlayer::AccountID) == AccountID)) >= 4) if (db.count<DbPlayer>(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); 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); DbPlayer finish = getDbPlayerById(character->PCStyle.iPC_UID);
finish.AppearanceFlag = 1; finish.AppearanceFlag = 1;
@ -188,7 +188,7 @@ void Database::finishCharacter(sP_CL2LS_REQ_CHAR_CREATE* character)
Inventory Foot, LB, UB; Inventory Foot, LB, UB;
Foot.playerId = character->PCStyle.iPC_UID; Foot.playerId = character->PCStyle.iPC_UID;
Foot.id = character->sOn_Item.iEquipFootID; Foot.id = character->sOn_Item.iEquipFootID;
Foot.Type = 3; Foot.Type = 3;
Foot.slot = 3; Foot.slot = 3;
Foot.Opt = 1; Foot.Opt = 1;
Foot.TimeLimit = 0; Foot.TimeLimit = 0;
@ -209,11 +209,11 @@ void Database::finishCharacter(sP_CL2LS_REQ_CHAR_CREATE* character)
db.insert(UB); db.insert(UB);
} }
void Database::finishTutorial(int PlayerID) void Database::finishTutorial(int PlayerID)
{ {
Player finish = getPlayer(PlayerID); Player finish = getPlayer(PlayerID);
//set flag //set flag
finish.PCStyle2.iTutorialFlag= 1; finish.PCStyle2.iTutorialFlag= 1;
//add Gun //add Gun
Inventory LightningGun = {}; Inventory LightningGun = {};
LightningGun.playerId = PlayerID; LightningGun.playerId = PlayerID;
@ -237,7 +237,7 @@ void Database::finishTutorial(int PlayerID)
db.update(playerToDb(&finish)); db.update(playerToDb(&finish));
} }
int Database::deleteCharacter(int characterID, int userID) int Database::deleteCharacter(int characterID, int userID)
{ {
auto find = auto find =
db.get_all<DbPlayer>(where(c(&DbPlayer::PlayerID) == characterID and c(&DbPlayer::AccountID)==userID)); db.get_all<DbPlayer>(where(c(&DbPlayer::PlayerID) == characterID and c(&DbPlayer::AccountID)==userID));
@ -249,7 +249,7 @@ int Database::deleteCharacter(int characterID, int userID)
return slot; return slot;
} }
std::vector <Player> Database::getCharacters(int UserID) std::vector <Player> Database::getCharacters(int UserID)
{ {
std::vector<DbPlayer>characters = std::vector<DbPlayer>characters =
db.get_all<DbPlayer>(where db.get_all<DbPlayer>(where
@ -257,7 +257,7 @@ std::vector <Player> Database::getCharacters(int UserID)
//parsing DbPlayer to Player //parsing DbPlayer to Player
std::vector<Player> result = std::vector<Player>(); std::vector<Player> result = std::vector<Player>();
for (auto &character : characters) { for (auto &character : characters) {
Player toadd = DbToPlayer(character); Player toadd = DbToPlayer(character);
result.push_back( result.push_back(
toadd toadd
); );
@ -340,7 +340,7 @@ Database::DbPlayer Database::playerToDb(Player *player)
Player Database::DbToPlayer(DbPlayer player) { Player Database::DbToPlayer(DbPlayer player) {
Player result = {}; // fixes some weird memory errors, this zeros out the members (not the padding inbetween though) Player result = {}; // fixes some weird memory errors, this zeros out the members (not the padding inbetween though)
result.iID = player.PlayerID; result.iID = player.PlayerID;
result.accountId = player.AccountID; result.accountId = player.AccountID;
result.PCStyle2.iAppearanceFlag = player.AppearanceFlag; result.PCStyle2.iAppearanceFlag = player.AppearanceFlag;
@ -374,7 +374,7 @@ Player Database::DbToPlayer(DbPlayer player) {
result.equippedNanos[0] = player.Nano1; result.equippedNanos[0] = player.Nano1;
result.equippedNanos[1] = player.Nano2; result.equippedNanos[1] = player.Nano2;
result.equippedNanos[2] = player.Nano3; result.equippedNanos[2] = player.Nano3;
Database::getInventory(&result); Database::getInventory(&result);
Database::getNanos(&result); Database::getNanos(&result);
@ -479,7 +479,7 @@ void Database::updateNanos(Player *player) {
); );
//insert //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) if ((player->Nanos[i]).iID == 0)
continue; continue;
Nano toAdd = {}; Nano toAdd = {};
@ -506,7 +506,7 @@ void Database::getInventory(Player* player) {
toSet.iTimeLimit = current.TimeLimit; toSet.iTimeLimit = current.TimeLimit;
//assign to proper arrays //assign to proper arrays
if (current.slot <= AEQUIP_COUNT) if (current.slot <= AEQUIP_COUNT)
player->Equip[current.slot] = toSet; player->Equip[current.slot] = toSet;
else if (current.slot <= (AEQUIP_COUNT + AINVEN_COUNT)) else if (current.slot <= (AEQUIP_COUNT + AINVEN_COUNT))
player->Inven[current.slot - AEQUIP_COUNT] = toSet; player->Inven[current.slot - AEQUIP_COUNT] = toSet;
else else

View File

@ -5,7 +5,7 @@
#include <vector> #include <vector>
namespace Database { namespace Database {
#pragma region DatabaseStructs #pragma region DatabaseStructs
struct Account struct Account
{ {
@ -49,7 +49,7 @@ namespace Database {
int HP; int HP;
short int HairColor; short int HairColor;
short int HairStyle; short int HairStyle;
short int Height; short int Height;
short int NameCheck; short int NameCheck;
short int PayZoneFlag; short int PayZoneFlag;
short int SkinColor; short int SkinColor;
@ -65,7 +65,7 @@ namespace Database {
std::vector<char> QuestFlag; std::vector<char> QuestFlag;
}; };
#pragma endregion DatabaseStructs #pragma endregion DatabaseStructs

View File

@ -32,9 +32,9 @@ void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) {
sP_CL2FE_REQ_ITEM_MOVE* itemmove = (sP_CL2FE_REQ_ITEM_MOVE*)data->buf; sP_CL2FE_REQ_ITEM_MOVE* itemmove = (sP_CL2FE_REQ_ITEM_MOVE*)data->buf;
INITSTRUCT(sP_FE2CL_PC_ITEM_MOVE_SUCC, resp); INITSTRUCT(sP_FE2CL_PC_ITEM_MOVE_SUCC, resp);
PlayerView& plr = PlayerManager::players[sock]; PlayerView& plr = PlayerManager::players[sock];
//sanity check //sanity check
if (plr.plr->Equip[itemmove->iFromSlotNum].iType != 0 && itemmove->eFrom == 0 && itemmove->eTo == 0) { 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 // 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.eFrom = itemmove->eTo;
resp.iFromSlotNum = itemmove->iToSlotNum; resp.iFromSlotNum = itemmove->iToSlotNum;
resp.FromSlotItem = plr.plr->Equip[itemmove->iFromSlotNum]; resp.FromSlotItem = plr.plr->Equip[itemmove->iFromSlotNum];
sock->sendPacket((void*)&resp, P_FE2CL_PC_ITEM_MOVE_SUCC, sizeof(sP_FE2CL_PC_ITEM_MOVE_SUCC)); sock->sendPacket((void*)&resp, P_FE2CL_PC_ITEM_MOVE_SUCC, sizeof(sP_FE2CL_PC_ITEM_MOVE_SUCC));
return; return;
} }
// sanity check // sanity check
if (itemmove->iToSlotNum > ABANK_COUNT || itemmove->iToSlotNum < 0) if (itemmove->iToSlotNum > ABANK_COUNT || itemmove->iToSlotNum < 0)
return; return;
//get the fromItem //get the fromItem
sItemBase *fromItem; sItemBase *fromItem;
switch ((SlotType)itemmove->eFrom) { switch ((SlotType)itemmove->eFrom) {
@ -103,7 +103,7 @@ void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) {
equipChange.iEquipSlotNum = itemmove->iToSlotNum; equipChange.iEquipSlotNum = itemmove->iToSlotNum;
equipChange.EquipSlotItem = resp.FromSlotItem; equipChange.EquipSlotItem = resp.FromSlotItem;
} }
// unequip vehicle if equip slot 8 is 0 // unequip vehicle if equip slot 8 is 0
if (plr.plr->Equip[8].iID == 0) if (plr.plr->Equip[8].iID == 0)
plr.plr->iPCState = 0; plr.plr->iPCState = 0;
@ -116,10 +116,10 @@ void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) {
//send response //send response
resp.eTo = itemmove->eFrom; resp.eTo = itemmove->eFrom;
resp.iToSlotNum = itemmove->iFromSlotNum; resp.iToSlotNum = itemmove->iFromSlotNum;
resp.eFrom = itemmove->eTo; resp.eFrom = itemmove->eTo;
resp.iFromSlotNum = itemmove->iToSlotNum; resp.iFromSlotNum = itemmove->iToSlotNum;
sock->sendPacket((void*)&resp, P_FE2CL_PC_ITEM_MOVE_SUCC, sizeof(sP_FE2CL_PC_ITEM_MOVE_SUCC)); 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 // 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())); // 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) { } else if (itemreq->eIL == 1 && itemreq->Item.iType >= 0 && itemreq->Item.iType <= 10) {
INITSTRUCT(sP_FE2CL_REP_PC_GIVE_ITEM_SUCC, resp); INITSTRUCT(sP_FE2CL_REP_PC_GIVE_ITEM_SUCC, resp);
resp.eIL = itemreq->eIL; resp.eIL = itemreq->eIL;
@ -191,44 +191,44 @@ void ItemManager::itemTradeOfferHandler(CNSocket* sock, CNPacketData* data) {
return; // ignore the malformed packet return; // ignore the malformed packet
sP_CL2FE_REQ_PC_TRADE_OFFER* pacdat = (sP_CL2FE_REQ_PC_TRADE_OFFER*)data->buf; sP_CL2FE_REQ_PC_TRADE_OFFER* pacdat = (sP_CL2FE_REQ_PC_TRADE_OFFER*)data->buf;
int iID_Check; int iID_Check;
if (pacdat->iID_Request == pacdat->iID_From) { if (pacdat->iID_Request == pacdat->iID_From) {
iID_Check = pacdat->iID_To; iID_Check = pacdat->iID_To;
} else { } else {
iID_Check = pacdat->iID_From; iID_Check = pacdat->iID_From;
} }
CNSocket* otherSock = sock; CNSocket* otherSock = sock;
for (auto& pair : PlayerManager::players) { for (auto& pair : PlayerManager::players) {
if (pair.second.plr->iID == iID_Check) { if (pair.second.plr->iID == iID_Check) {
otherSock = pair.first; otherSock = pair.first;
break; break;
} }
} }
PlayerView& plr = PlayerManager::players[otherSock]; PlayerView& plr = PlayerManager::players[otherSock];
if (plr.plr->isTrading) { if (plr.plr->isTrading) {
INITSTRUCT(sP_FE2CL_REP_PC_TRADE_OFFER_REFUSAL, resp); INITSTRUCT(sP_FE2CL_REP_PC_TRADE_OFFER_REFUSAL, resp);
resp.iID_Request = pacdat->iID_To; resp.iID_Request = pacdat->iID_To;
resp.iID_From = pacdat->iID_From; resp.iID_From = pacdat->iID_From;
resp.iID_To = pacdat->iID_To; 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)); 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 return; //prevent trading with a player already trading
} }
INITSTRUCT(sP_FE2CL_REP_PC_TRADE_OFFER, resp); INITSTRUCT(sP_FE2CL_REP_PC_TRADE_OFFER, resp);
resp.iID_Request = pacdat->iID_Request; resp.iID_Request = pacdat->iID_Request;
resp.iID_From = pacdat->iID_From; resp.iID_From = pacdat->iID_From;
resp.iID_To = pacdat->iID_To; resp.iID_To = pacdat->iID_To;
otherSock->sendPacket((void*)&resp, P_FE2CL_REP_PC_TRADE_OFFER, sizeof(sP_FE2CL_REP_PC_TRADE_OFFER)); 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 return; // ignore the malformed packet
sP_CL2FE_REQ_PC_TRADE_OFFER_ACCEPT* pacdat = (sP_CL2FE_REQ_PC_TRADE_OFFER_ACCEPT*)data->buf; sP_CL2FE_REQ_PC_TRADE_OFFER_ACCEPT* pacdat = (sP_CL2FE_REQ_PC_TRADE_OFFER_ACCEPT*)data->buf;
int iID_Check; int iID_Check;
if (pacdat->iID_Request == pacdat->iID_From) { if (pacdat->iID_Request == pacdat->iID_From) {
iID_Check = pacdat->iID_To; iID_Check = pacdat->iID_To;
} else { } else {
iID_Check = pacdat->iID_From; iID_Check = pacdat->iID_From;
} }
CNSocket* otherSock = sock; CNSocket* otherSock = sock;
for (auto& pair : PlayerManager::players) { for (auto& pair : PlayerManager::players) {
if (pair.second.plr->iID == iID_Check) { if (pair.second.plr->iID == iID_Check) {
otherSock = pair.first; otherSock = pair.first;
break; break;
} }
} }
INITSTRUCT(sP_FE2CL_REP_PC_TRADE_OFFER, resp); INITSTRUCT(sP_FE2CL_REP_PC_TRADE_OFFER, resp);
resp.iID_Request = pacdat->iID_Request; resp.iID_Request = pacdat->iID_Request;
resp.iID_From = pacdat->iID_From; resp.iID_From = pacdat->iID_From;
resp.iID_To = pacdat->iID_To; resp.iID_To = pacdat->iID_To;
// Clearing up trade slots // Clearing up trade slots
PlayerView& plr = PlayerManager::players[sock]; PlayerView& plr = PlayerManager::players[sock];
PlayerView& plr2 = PlayerManager::players[otherSock]; PlayerView& plr2 = PlayerManager::players[otherSock];
if (plr2.plr->isTrading) { if (plr2.plr->isTrading) {
INITSTRUCT(sP_FE2CL_REP_PC_TRADE_OFFER_REFUSAL, resp); INITSTRUCT(sP_FE2CL_REP_PC_TRADE_OFFER_REFUSAL, resp);
resp.iID_Request = pacdat->iID_To; resp.iID_Request = pacdat->iID_To;
resp.iID_From = pacdat->iID_From; resp.iID_From = pacdat->iID_From;
resp.iID_To = pacdat->iID_To; 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)); 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 return; //prevent trading with a player already trading
} }
plr.plr->isTrading = true; plr.plr->isTrading = true;
plr2.plr->isTrading = true; plr2.plr->isTrading = true;
plr.plr->isTradeConfirm = false; plr.plr->isTradeConfirm = false;
plr2.plr->isTradeConfirm = false; plr2.plr->isTradeConfirm = false;
memset(&plr.plr->Trade, 0, sizeof(plr.plr->Trade)); memset(&plr.plr->Trade, 0, sizeof(plr.plr->Trade));
memset(&plr2.plr->Trade, 0, sizeof(plr2.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_Request = pacdat->iID_Request;
resp.iID_From = pacdat->iID_From; resp.iID_From = pacdat->iID_From;
resp.iID_To = pacdat->iID_To; resp.iID_To = pacdat->iID_To;
int iID_Check; int iID_Check;
if (pacdat->iID_Request == pacdat->iID_From) { if (pacdat->iID_Request == pacdat->iID_From) {
iID_Check = pacdat->iID_To; iID_Check = pacdat->iID_To;
} else { } else {
iID_Check = pacdat->iID_From; iID_Check = pacdat->iID_From;
} }
CNSocket* otherSock = sock; CNSocket* otherSock = sock;
for (auto& pair : PlayerManager::players) { for (auto& pair : PlayerManager::players) {
if (pair.second.plr->iID == iID_Check) { if (pair.second.plr->iID == iID_Check) {
otherSock = pair.first; otherSock = pair.first;
break; break;
} }
@ -325,111 +325,111 @@ void ItemManager::itemTradeConfirmHandler(CNSocket* sock, CNPacketData* data) {
return; // ignore the malformed packet return; // ignore the malformed packet
sP_CL2FE_REQ_PC_TRADE_CONFIRM* pacdat = (sP_CL2FE_REQ_PC_TRADE_CONFIRM*)data->buf; sP_CL2FE_REQ_PC_TRADE_CONFIRM* pacdat = (sP_CL2FE_REQ_PC_TRADE_CONFIRM*)data->buf;
int iID_Check; int iID_Check;
if (pacdat->iID_Request == pacdat->iID_From) { if (pacdat->iID_Request == pacdat->iID_From) {
iID_Check = pacdat->iID_To; iID_Check = pacdat->iID_To;
} else { } else {
iID_Check = pacdat->iID_From; iID_Check = pacdat->iID_From;
} }
CNSocket* otherSock = sock; CNSocket* otherSock = sock;
for (auto& pair : PlayerManager::players) { for (auto& pair : PlayerManager::players) {
if (pair.second.plr->iID == iID_Check) { if (pair.second.plr->iID == iID_Check) {
otherSock = pair.first; otherSock = pair.first;
break; break;
} }
} }
PlayerView& plr = PlayerManager::players[sock]; PlayerView& plr = PlayerManager::players[sock];
PlayerView& plr2 = PlayerManager::players[otherSock]; PlayerView& plr2 = PlayerManager::players[otherSock];
if (plr2.plr->isTradeConfirm) { if (plr2.plr->isTradeConfirm) {
plr.plr->isTrading = false; plr.plr->isTrading = false;
plr2.plr->isTrading = false; plr2.plr->isTrading = false;
plr.plr->isTradeConfirm = false; plr.plr->isTradeConfirm = false;
plr2.plr->isTradeConfirm = false; plr2.plr->isTradeConfirm = false;
// Check if we have enough free slots // Check if we have enough free slots
int freeSlots = 0; int freeSlots = 0;
int freeSlotsNeeded = 0; int freeSlotsNeeded = 0;
int freeSlots2 = 0; int freeSlots2 = 0;
int freeSlotsNeeded2 = 0; int freeSlotsNeeded2 = 0;
for (int i = 0; i < AINVEN_COUNT; i++) { for (int i = 0; i < AINVEN_COUNT; i++) {
if (plr.plr->Inven[i].iID == 0) if (plr.plr->Inven[i].iID == 0)
freeSlots++; freeSlots++;
} }
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
if (plr.plr->Trade[i].iID != 0) if (plr.plr->Trade[i].iID != 0)
freeSlotsNeeded++; freeSlotsNeeded++;
} }
for (int i = 0; i < AINVEN_COUNT; i++) { for (int i = 0; i < AINVEN_COUNT; i++) {
if (plr2.plr->Inven[i].iID == 0) if (plr2.plr->Inven[i].iID == 0)
freeSlots2++; freeSlots2++;
} }
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
if (plr2.plr->Trade[i].iID != 0) if (plr2.plr->Trade[i].iID != 0)
freeSlotsNeeded2++; freeSlotsNeeded2++;
} }
if (freeSlotsNeeded2 - freeSlotsNeeded > freeSlots) { if (freeSlotsNeeded2 - freeSlotsNeeded > freeSlots) {
INITSTRUCT(sP_FE2CL_REP_PC_TRADE_CONFIRM_ABORT, resp); INITSTRUCT(sP_FE2CL_REP_PC_TRADE_CONFIRM_ABORT, resp);
resp.iID_Request = pacdat->iID_Request; resp.iID_Request = pacdat->iID_Request;
resp.iID_From = pacdat->iID_From; resp.iID_From = pacdat->iID_From;
resp.iID_To = pacdat->iID_To; 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)); 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)); 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 return; // Fail trade because of the lack of slots
} }
if (freeSlotsNeeded - freeSlotsNeeded2 > freeSlots2) { if (freeSlotsNeeded - freeSlotsNeeded2 > freeSlots2) {
INITSTRUCT(sP_FE2CL_REP_PC_TRADE_CONFIRM_CANCEL, resp); INITSTRUCT(sP_FE2CL_REP_PC_TRADE_CONFIRM_CANCEL, resp);
resp.iID_Request = pacdat->iID_Request; resp.iID_Request = pacdat->iID_Request;
resp.iID_From = pacdat->iID_From; resp.iID_From = pacdat->iID_From;
resp.iID_To = pacdat->iID_To; 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)); 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)); 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 return; // Fail trade because of the lack of slots
} }
INITSTRUCT(sP_FE2CL_REP_PC_TRADE_CONFIRM, resp); INITSTRUCT(sP_FE2CL_REP_PC_TRADE_CONFIRM, resp);
resp.iID_Request = pacdat->iID_Request; resp.iID_Request = pacdat->iID_Request;
resp.iID_From = pacdat->iID_From; resp.iID_From = pacdat->iID_From;
resp.iID_To = pacdat->iID_To; resp.iID_To = pacdat->iID_To;
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_TRADE_CONFIRM, sizeof(sP_FE2CL_REP_PC_TRADE_CONFIRM)); 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 // ^^ 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++) { 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].iID = 0;
plr.plr->Inven[plr.plr->Trade[i].iInvenNum].iType = 0; plr.plr->Inven[plr.plr->Trade[i].iInvenNum].iType = 0;
plr.plr->Inven[plr.plr->Trade[i].iInvenNum].iOpt = 0; plr.plr->Inven[plr.plr->Trade[i].iInvenNum].iOpt = 0;
} }
for (int i = 0; i < freeSlotsNeeded2; i++) { 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].iID = 0;
plr2.plr->Inven[plr2.plr->Trade[i].iInvenNum].iType = 0; plr2.plr->Inven[plr2.plr->Trade[i].iInvenNum].iType = 0;
plr2.plr->Inven[plr2.plr->Trade[i].iInvenNum].iOpt = 0; plr2.plr->Inven[plr2.plr->Trade[i].iInvenNum].iOpt = 0;
} }
for (int i = 0; i < AINVEN_COUNT; i++) { for (int i = 0; i < AINVEN_COUNT; i++) {
if (freeSlotsNeeded <= 0) if (freeSlotsNeeded <= 0)
break; break;
if (plr2.plr->Inven[i].iID == 0) { if (plr2.plr->Inven[i].iID == 0) {
plr2.plr->Inven[i].iID = plr.plr->Trade[freeSlotsNeeded - 1].iID; 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].iType = plr.plr->Trade[freeSlotsNeeded - 1].iType;
plr2.plr->Inven[i].iOpt = plr.plr->Trade[freeSlotsNeeded - 1].iOpt; plr2.plr->Inven[i].iOpt = plr.plr->Trade[freeSlotsNeeded - 1].iOpt;
@ -437,13 +437,13 @@ void ItemManager::itemTradeConfirmHandler(CNSocket* sock, CNPacketData* data) {
freeSlotsNeeded--; freeSlotsNeeded--;
} }
} }
for (int i = 0; i < AINVEN_COUNT; i++) { for (int i = 0; i < AINVEN_COUNT; i++) {
if (freeSlotsNeeded2 <= 0) if (freeSlotsNeeded2 <= 0)
break; break;
if (plr.plr->Inven[i].iID == 0) { if (plr.plr->Inven[i].iID == 0) {
plr.plr->Inven[i].iID = plr2.plr->Trade[freeSlotsNeeded2 - 1].iID; 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].iType = plr2.plr->Trade[freeSlotsNeeded2 - 1].iType;
plr.plr->Inven[i].iOpt = plr2.plr->Trade[freeSlotsNeeded2 - 1].iOpt; plr.plr->Inven[i].iOpt = plr2.plr->Trade[freeSlotsNeeded2 - 1].iOpt;
@ -451,38 +451,38 @@ void ItemManager::itemTradeConfirmHandler(CNSocket* sock, CNPacketData* data) {
freeSlotsNeeded2--; freeSlotsNeeded2--;
} }
} }
INITSTRUCT(sP_FE2CL_REP_PC_TRADE_CONFIRM_SUCC, resp2); INITSTRUCT(sP_FE2CL_REP_PC_TRADE_CONFIRM_SUCC, resp2);
resp2.iID_Request = pacdat->iID_Request; resp2.iID_Request = pacdat->iID_Request;
resp2.iID_From = pacdat->iID_From; resp2.iID_From = pacdat->iID_From;
resp2.iID_To = pacdat->iID_To; resp2.iID_To = pacdat->iID_To;
plr.plr->money = plr.plr->money + plr2.plr->moneyInTrade - plr.plr->moneyInTrade; plr.plr->money = plr.plr->money + plr2.plr->moneyInTrade - plr.plr->moneyInTrade;
resp2.iCandy = plr.plr->money; resp2.iCandy = plr.plr->money;
memcpy(resp2.Item, plr2.plr->Trade, sizeof(plr2.plr->Trade)); memcpy(resp2.Item, plr2.plr->Trade, sizeof(plr2.plr->Trade));
memcpy(resp2.ItemStay, plr.plr->Trade, sizeof(plr.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)); 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; plr2.plr->money = plr2.plr->money + plr.plr->moneyInTrade - plr2.plr->moneyInTrade;
resp2.iCandy = plr2.plr->money; resp2.iCandy = plr2.plr->money;
memcpy(resp2.Item, plr.plr->Trade, sizeof(plr.plr->Trade)); memcpy(resp2.Item, plr.plr->Trade, sizeof(plr.plr->Trade));
memcpy(resp2.ItemStay, plr2.plr->Trade, sizeof(plr2.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)); otherSock->sendPacket((void*)&resp2, P_FE2CL_REP_PC_TRADE_CONFIRM_SUCC, sizeof(sP_FE2CL_REP_PC_TRADE_CONFIRM_SUCC));
} else { } else {
INITSTRUCT(sP_FE2CL_REP_PC_TRADE_CONFIRM, resp); INITSTRUCT(sP_FE2CL_REP_PC_TRADE_CONFIRM, resp);
resp.iID_Request = pacdat->iID_Request; resp.iID_Request = pacdat->iID_Request;
resp.iID_From = pacdat->iID_From; resp.iID_From = pacdat->iID_From;
resp.iID_To = pacdat->iID_To; resp.iID_To = pacdat->iID_To;
plr.plr->isTradeConfirm = true; plr.plr->isTradeConfirm = true;
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_TRADE_CONFIRM, sizeof(sP_FE2CL_REP_PC_TRADE_CONFIRM)); 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)); 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_Request = pacdat->iID_Request;
resp.iID_From = pacdat->iID_From; resp.iID_From = pacdat->iID_From;
resp.iID_To = pacdat->iID_To; resp.iID_To = pacdat->iID_To;
int iID_Check; int iID_Check;
if (pacdat->iID_Request == pacdat->iID_From) { if (pacdat->iID_Request == pacdat->iID_From) {
iID_Check = pacdat->iID_To; iID_Check = pacdat->iID_To;
} else { } else {
iID_Check = pacdat->iID_From; iID_Check = pacdat->iID_From;
} }
CNSocket* otherSock = sock; CNSocket* otherSock = sock;
for (auto pair : PlayerManager::players) { for (auto pair : PlayerManager::players) {
if (pair.second.plr->iID == iID_Check) { if (pair.second.plr->iID == iID_Check) {
otherSock = pair.first; otherSock = pair.first;
} }
} }
PlayerView& plr = PlayerManager::players[sock]; PlayerView& plr = PlayerManager::players[sock];
PlayerView& plr2 = PlayerManager::players[otherSock]; PlayerView& plr2 = PlayerManager::players[otherSock];
plr.plr->isTrading = false; plr.plr->isTrading = false;
plr.plr->isTradeConfirm = false; plr.plr->isTradeConfirm = false;
plr2.plr->isTrading = false; plr2.plr->isTrading = false;
@ -531,10 +531,10 @@ void ItemManager::itemTradeRegisterItemHandler(CNSocket* sock, CNPacketData* dat
return; // ignore the malformed packet return; // ignore the malformed packet
sP_CL2FE_REQ_PC_TRADE_ITEM_REGISTER* pacdat = (sP_CL2FE_REQ_PC_TRADE_ITEM_REGISTER*)data->buf; 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) if (pacdat->Item.iSlotNum < 0 || pacdat->Item.iSlotNum > 4)
return; // sanity check return; // sanity check
INITSTRUCT(sP_FE2CL_REP_PC_TRADE_ITEM_REGISTER_SUCC, resp); INITSTRUCT(sP_FE2CL_REP_PC_TRADE_ITEM_REGISTER_SUCC, resp);
resp.iID_Request = pacdat->iID_Request; resp.iID_Request = pacdat->iID_Request;
@ -542,27 +542,27 @@ void ItemManager::itemTradeRegisterItemHandler(CNSocket* sock, CNPacketData* dat
resp.iID_To = pacdat->iID_To; resp.iID_To = pacdat->iID_To;
resp.TradeItem = pacdat->Item; resp.TradeItem = pacdat->Item;
resp.InvenItem = pacdat->Item; resp.InvenItem = pacdat->Item;
int iID_Check; int iID_Check;
if (pacdat->iID_Request == pacdat->iID_From) { if (pacdat->iID_Request == pacdat->iID_From) {
iID_Check = pacdat->iID_To; iID_Check = pacdat->iID_To;
} else { } else {
iID_Check = pacdat->iID_From; iID_Check = pacdat->iID_From;
} }
CNSocket* otherSock = sock; CNSocket* otherSock = sock;
for (auto pair : PlayerManager::players) { for (auto pair : PlayerManager::players) {
if (pair.second.plr->iID == iID_Check) { if (pair.second.plr->iID == iID_Check) {
otherSock = pair.first; otherSock = pair.first;
} }
} }
PlayerView& plr = PlayerManager::players[sock]; PlayerView& plr = PlayerManager::players[sock];
plr.plr->Trade[pacdat->Item.iSlotNum] = pacdat->Item; plr.plr->Trade[pacdat->Item.iSlotNum] = pacdat->Item;
plr.plr->isTradeConfirm = false; 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)); 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)); 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_From = pacdat->iID_From;
resp.iID_To = pacdat->iID_To; resp.iID_To = pacdat->iID_To;
resp.TradeItem = pacdat->Item; resp.TradeItem = pacdat->Item;
PlayerView& plr = PlayerManager::players[sock]; PlayerView& plr = PlayerManager::players[sock];
resp.InvenItem = plr.plr->Trade[pacdat->Item.iSlotNum]; resp.InvenItem = plr.plr->Trade[pacdat->Item.iSlotNum];
plr.plr->isTradeConfirm = false; plr.plr->isTradeConfirm = false;
int iID_Check; int iID_Check;
if (pacdat->iID_Request == pacdat->iID_From) { if (pacdat->iID_Request == pacdat->iID_From) {
iID_Check = pacdat->iID_To; iID_Check = pacdat->iID_To;
} else { } else {
iID_Check = pacdat->iID_From; iID_Check = pacdat->iID_From;
} }
CNSocket* otherSock = sock; CNSocket* otherSock = sock;
for (auto pair : PlayerManager::players) { for (auto pair : PlayerManager::players) {
if (pair.second.plr->iID == iID_Check) { if (pair.second.plr->iID == iID_Check) {
otherSock = pair.first; otherSock = pair.first;
} }
} }
int temp_num = pacdat->Item.iSlotNum; int temp_num = pacdat->Item.iSlotNum;
if (temp_num >= 0 && temp_num <= 4) { if (temp_num >= 0 && temp_num <= 4) {
plr.plr->Trade[temp_num].iID = 0; plr.plr->Trade[temp_num].iID = 0;
plr.plr->Trade[temp_num].iType = 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].iInvenNum = 0;
plr.plr->Trade[temp_num].iSlotNum = 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)); 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)); 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 return; // ignore the malformed packet
sP_CL2FE_REQ_PC_TRADE_CASH_REGISTER* pacdat = (sP_CL2FE_REQ_PC_TRADE_CASH_REGISTER*)data->buf; sP_CL2FE_REQ_PC_TRADE_CASH_REGISTER* pacdat = (sP_CL2FE_REQ_PC_TRADE_CASH_REGISTER*)data->buf;
PlayerView& plr = PlayerManager::players[sock]; PlayerView& plr = PlayerManager::players[sock];
if (pacdat->iCandy < 0 || pacdat->iCandy > plr.plr->money) if (pacdat->iCandy < 0 || pacdat->iCandy > plr.plr->money)
return; // famous glitch, begone return; // famous glitch, begone
INITSTRUCT(sP_FE2CL_REP_PC_TRADE_CASH_REGISTER_SUCC, resp); INITSTRUCT(sP_FE2CL_REP_PC_TRADE_CASH_REGISTER_SUCC, resp);
resp.iID_Request = pacdat->iID_Request; resp.iID_Request = pacdat->iID_Request;
resp.iID_From = pacdat->iID_From; resp.iID_From = pacdat->iID_From;
resp.iID_To = pacdat->iID_To; resp.iID_To = pacdat->iID_To;
resp.iCandy = pacdat->iCandy; resp.iCandy = pacdat->iCandy;
int iID_Check; int iID_Check;
if (pacdat->iID_Request == pacdat->iID_From) { if (pacdat->iID_Request == pacdat->iID_From) {
iID_Check = pacdat->iID_To; iID_Check = pacdat->iID_To;
} else { } else {
iID_Check = pacdat->iID_From; iID_Check = pacdat->iID_From;
} }
CNSocket* otherSock = sock; CNSocket* otherSock = sock;
for (auto pair : PlayerManager::players) { for (auto pair : PlayerManager::players) {
if (pair.second.plr->iID == iID_Check) { if (pair.second.plr->iID == iID_Check) {
otherSock = pair.first; otherSock = pair.first;
} }
} }
plr.plr->moneyInTrade = pacdat->iCandy; plr.plr->moneyInTrade = pacdat->iCandy;
plr.plr->isTradeConfirm = false; 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)); 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)); 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)) if (data->size != sizeof(sP_CL2FE_REQ_PC_TRADE_EMOTES_CHAT))
return; // malformed packet return; // malformed packet
sP_CL2FE_REQ_PC_TRADE_EMOTES_CHAT* pacdat = (sP_CL2FE_REQ_PC_TRADE_EMOTES_CHAT*)data->buf; 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); INITSTRUCT(sP_FE2CL_REP_PC_TRADE_EMOTES_CHAT, resp);
resp.iID_Request = pacdat->iID_Request; resp.iID_Request = pacdat->iID_Request;
resp.iID_From = pacdat->iID_From; resp.iID_From = pacdat->iID_From;
resp.iID_To = pacdat->iID_To; resp.iID_To = pacdat->iID_To;
memcpy(resp.szFreeChat, pacdat->szFreeChat, sizeof(pacdat->szFreeChat)); memcpy(resp.szFreeChat, pacdat->szFreeChat, sizeof(pacdat->szFreeChat));
resp.iEmoteCode = pacdat->iEmoteCode; resp.iEmoteCode = pacdat->iEmoteCode;
int iID_Check; int iID_Check;
if (pacdat->iID_Request == pacdat->iID_From) { if (pacdat->iID_Request == pacdat->iID_From) {
iID_Check = pacdat->iID_To; iID_Check = pacdat->iID_To;
} else { } else {
iID_Check = pacdat->iID_From; iID_Check = pacdat->iID_From;
} }
CNSocket* otherSock = sock; CNSocket* otherSock = sock;
for (auto pair : PlayerManager::players) { for (auto pair : PlayerManager::players) {
if (pair.second.plr->iID == iID_Check) { if (pair.second.plr->iID == iID_Check) {
otherSock = pair.first; otherSock = pair.first;
} }
} }
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_TRADE_EMOTES_CHAT, sizeof(sP_FE2CL_REP_PC_TRADE_EMOTES_CHAT)); 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)); otherSock->sendPacket((void*)&resp, P_FE2CL_REP_PC_TRADE_EMOTES_CHAT, sizeof(sP_FE2CL_REP_PC_TRADE_EMOTES_CHAT));
} }

View File

@ -9,10 +9,10 @@ namespace ItemManager {
INVENTORY = 1, INVENTORY = 1,
BANK = 3 BANK = 3
}; };
void init(); void init();
void itemMoveHandler(CNSocket* sock, CNPacketData* data); void itemMoveHandler(CNSocket* sock, CNPacketData* data);
void itemDeleteHandler(CNSocket* sock, CNPacketData* data); void itemDeleteHandler(CNSocket* sock, CNPacketData* data);
void itemGMGiveHandler(CNSocket* sock, CNPacketData* data); void itemGMGiveHandler(CNSocket* sock, CNPacketData* data);
//Bank //Bank
void itemBankOpenHandler(CNSocket* sock, CNPacketData* data); void itemBankOpenHandler(CNSocket* sock, CNPacketData* data);

View File

@ -78,7 +78,7 @@ void NPCManager::npcVendorSell(CNSocket* sock, CNPacketData* data) {
sItemBase* item = &plr->Inven[req->iInvenSlotNum]; sItemBase* item = &plr->Inven[req->iInvenSlotNum];
INITSTRUCT(sP_FE2CL_REP_PC_VENDOR_ITEM_SELL_SUCC, resp); INITSTRUCT(sP_FE2CL_REP_PC_VENDOR_ITEM_SELL_SUCC, resp);
int sellValue = 100 * req->iItemCnt; // TODO: lookup item price int sellValue = 100 * req->iItemCnt; // TODO: lookup item price
// increment taros // increment taros

View File

@ -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 * P_FE2CL_REP_PC_CHANGE_LEVEL appear to play the same animation, but only the latter affects
* the other player's displayed level. * the other player's displayed level.
*/ */
INITSTRUCT(sP_FE2CL_REP_PC_CHANGE_LEVEL, resp2); INITSTRUCT(sP_FE2CL_REP_PC_CHANGE_LEVEL, resp2);
resp2.iPC_ID = plr->iID; resp2.iPC_ID = plr->iID;

View File

@ -226,7 +226,7 @@ void PlayerManager::enterPlayer(CNSocket* sock, CNPacketData* data) {
for (int i = 0; i < AINVEN_COUNT; i++) for (int i = 0; i < AINVEN_COUNT; i++)
response.PCLoadData2CL.aInven[i] = plr.Inven[i]; response.PCLoadData2CL.aInven[i] = plr.Inven[i];
//nanos //nanos
for (int i = 1; i < SIZEOF_NANO_BANK_SLOT; i++) { for (int i = 1; i < SIZEOF_NANO_BANK_SLOT; i++) {
response.PCLoadData2CL.aNanoBank[i] = plr.Nanos[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) { void PlayerManager::enterPlayerVehicle(CNSocket* sock, CNPacketData* data) {
PlayerView& plr = PlayerManager::players[sock]; PlayerView& plr = PlayerManager::players[sock];
if (plr.plr->Equip[8].iID > 0) { if (plr.plr->Equip[8].iID > 0) {
INITSTRUCT(sP_FE2CL_PC_VEHICLE_ON_SUCC, response); INITSTRUCT(sP_FE2CL_PC_VEHICLE_ON_SUCC, response);
sock->sendPacket((void*)&response, P_FE2CL_PC_VEHICLE_ON_SUCC, sizeof(sP_FE2CL_PC_VEHICLE_ON_SUCC)); sock->sendPacket((void*)&response, P_FE2CL_PC_VEHICLE_ON_SUCC, sizeof(sP_FE2CL_PC_VEHICLE_ON_SUCC));
//send to other players //send to other players
plr.plr->iPCState = 8; plr.plr->iPCState = 8;
INITSTRUCT(sP_FE2CL_PC_STATE_CHANGE, response2); INITSTRUCT(sP_FE2CL_PC_STATE_CHANGE, response2);
response2.iPC_ID = plr.plr->iID; response2.iPC_ID = plr.plr->iID;
response2.iState = 8; response2.iState = 8;
for (CNSocket* otherSock : plr.viewable) { for (CNSocket* otherSock : plr.viewable) {
otherSock->sendPacket((void*)&response2, P_FE2CL_PC_STATE_CHANGE, sizeof(sP_FE2CL_PC_STATE_CHANGE)); otherSock->sendPacket((void*)&response2, P_FE2CL_PC_STATE_CHANGE, sizeof(sP_FE2CL_PC_STATE_CHANGE));
} }
} else { } else {
INITSTRUCT(sP_FE2CL_PC_VEHICLE_ON_FAIL, response); INITSTRUCT(sP_FE2CL_PC_VEHICLE_ON_FAIL, response);
sock->sendPacket((void*)&response, P_FE2CL_PC_VEHICLE_ON_FAIL, sizeof(sP_FE2CL_PC_VEHICLE_ON_FAIL)); sock->sendPacket((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) { void PlayerManager::exitPlayerVehicle(CNSocket* sock, CNPacketData* data) {
INITSTRUCT(sP_FE2CL_PC_VEHICLE_OFF_SUCC, response); INITSTRUCT(sP_FE2CL_PC_VEHICLE_OFF_SUCC, response);
sock->sendPacket((void*)&response, P_FE2CL_PC_VEHICLE_OFF_SUCC, sizeof(sP_FE2CL_PC_VEHICLE_OFF_SUCC)); sock->sendPacket((void*)&response, P_FE2CL_PC_VEHICLE_OFF_SUCC, sizeof(sP_FE2CL_PC_VEHICLE_OFF_SUCC));
PlayerView plr = PlayerManager::players[sock]; PlayerView plr = PlayerManager::players[sock];
//send to other players //send to other players
@ -701,10 +701,10 @@ void PlayerManager::exitPlayerVehicle(CNSocket* sock, CNPacketData* data) {
INITSTRUCT(sP_FE2CL_PC_STATE_CHANGE, response2); INITSTRUCT(sP_FE2CL_PC_STATE_CHANGE, response2);
response2.iPC_ID = plr.plr->iID; response2.iPC_ID = plr.plr->iID;
response2.iState = 0; response2.iState = 0;
for (CNSocket* otherSock : plr.viewable) { for (CNSocket* otherSock : plr.viewable) {
otherSock->sendPacket((void*)&response2, P_FE2CL_PC_STATE_CHANGE, sizeof(sP_FE2CL_PC_STATE_CHANGE)); otherSock->sendPacket((void*)&response2, P_FE2CL_PC_STATE_CHANGE, sizeof(sP_FE2CL_PC_STATE_CHANGE));
} }
} }
void PlayerManager::setSpecialSwitchPlayer(CNSocket* sock, CNPacketData* data) { void PlayerManager::setSpecialSwitchPlayer(CNSocket* sock, CNPacketData* data) {

View File

@ -21,11 +21,11 @@ void TableData::init() {
for (nlohmann::json::iterator npc = npcData.begin(); npc != npcData.end(); npc++) { 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"]); BaseNPC tmp(npc.value()["x"], npc.value()["y"], npc.value()["z"], npc.value()["id"]);
// Temporary fix, IDs will be pulled from json later // Temporary fix, IDs will be pulled from json later
tmp.appearanceData.iNPC_ID = i; tmp.appearanceData.iNPC_ID = i;
i++; i++;
NPCManager::NPCs[tmp.appearanceData.iNPC_ID] = tmp; NPCManager::NPCs[tmp.appearanceData.iNPC_ID] = tmp;
if (npc.value()["id"] == 641 || npc.value()["id"] == 642) 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++) { 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"], 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"]); npc.value()["iHP"], npc.value()["iConditionBitFlag"], npc.value()["iAngle"], npc.value()["iBarkerType"]);
// Temporary fix, IDs will be pulled from json later // Temporary fix, IDs will be pulled from json later
tmp.appearanceData.iNPC_ID = i; tmp.appearanceData.iNPC_ID = i;
i++; i++;
NPCManager::NPCs[tmp.appearanceData.iNPC_ID] = tmp; NPCManager::NPCs[tmp.appearanceData.iNPC_ID] = tmp;
} }

View File

@ -15,7 +15,7 @@ void TransportManager::init() {
void TransportManager::transportRegisterLocationHandler(CNSocket* sock, CNPacketData* data) { void TransportManager::transportRegisterLocationHandler(CNSocket* sock, CNPacketData* data) {
if (data->size != sizeof(sP_CL2FE_REQ_REGIST_TRANSPORTATION_LOCATION)) if (data->size != sizeof(sP_CL2FE_REQ_REGIST_TRANSPORTATION_LOCATION))
return; // malformed packet return; // malformed packet
sP_CL2FE_REQ_REGIST_TRANSPORTATION_LOCATION* transport = (sP_CL2FE_REQ_REGIST_TRANSPORTATION_LOCATION*)data->buf; sP_CL2FE_REQ_REGIST_TRANSPORTATION_LOCATION* transport = (sP_CL2FE_REQ_REGIST_TRANSPORTATION_LOCATION*)data->buf;
Player* plr = PlayerManager::getPlayer(sock); Player* plr = PlayerManager::getPlayer(sock);
@ -48,7 +48,7 @@ void TransportManager::transportRegisterLocationHandler(CNSocket* sock, CNPacket
return; return;
} }
/* /*
* assuming the two bitfields are just stuck together to make a longer one... do a similar operation, but on the respective integer * 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. * 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]; TransportRoute route = Routes[req->iTransporationID];
plr->money -= route.cost; plr->money -= route.cost;
TransportLocation target = Locations[route.end]; TransportLocation target = Locations[route.end];
switch (route.type) switch (route.type)
{ {
@ -133,7 +133,7 @@ void TransportManager::transportWarpHandler(CNSocket* sock, CNPacketData* data)
resp.iZ = plr->z; 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. * same map tile you were already in, but we might as well force an NPC reload.
*/ */
PlayerView& plrv = PlayerManager::players[sock]; PlayerView& plrv = PlayerManager::players[sock];

View File

@ -15,7 +15,7 @@
#if defined(__MINGW32__) && !defined(_GLIBCXX_HAS_GTHREADS) #if defined(__MINGW32__) && !defined(_GLIBCXX_HAS_GTHREADS)
#include "mingw/mingw.thread.h" #include "mingw/mingw.thread.h"
#else #else
#include <thread> #include <thread>
#endif #endif
#include <string> #include <string>

View File

@ -31,14 +31,14 @@ void settings::init() {
if (reader.ParseError() != 0) { if (reader.ParseError() != 0) {
if (reader.ParseError() == -1) if (reader.ParseError() == -1)
std::cerr << "[WARN] Settings: missing config.ini file!" << std::endl; 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; std::cerr << "[WARN] Settings: invalid config.ini syntax at line " << reader.ParseError() << std::endl;
return; return;
} }
APPROVEALLNAMES = reader.GetBoolean("", "acceptallcustomnames", APPROVEALLNAMES); APPROVEALLNAMES = reader.GetBoolean("", "acceptallcustomnames", APPROVEALLNAMES);
VERBOSITY = reader.GetInteger("", "verbosity", VERBOSITY); VERBOSITY = reader.GetInteger("", "verbosity", VERBOSITY);
LOGINPORT = reader.GetInteger("login", "port", LOGINPORT); LOGINPORT = reader.GetInteger("login", "port", LOGINPORT);
SHARDPORT = reader.GetInteger("shard", "port", SHARDPORT); SHARDPORT = reader.GetInteger("shard", "port", SHARDPORT);
SHARDSERVERIP = reader.Get("shard", "ip", "127.0.0.1"); SHARDSERVERIP = reader.Get("shard", "ip", "127.0.0.1");