major refactoring

This commit is contained in:
CPunch 2020-08-22 18:31:09 -05:00
parent 0ff1f74cd3
commit 94b0dc724e
11 changed files with 466 additions and 457 deletions

View File

@ -26,8 +26,8 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
return; // ignore the malformed packet
sP_CL2LS_REQ_LOGIN* login = (sP_CL2LS_REQ_LOGIN*)data->buf;
sP_LS2CL_REP_LOGIN_SUCC* response = (sP_LS2CL_REP_LOGIN_SUCC*)xmalloc(sizeof(sP_LS2CL_REP_LOGIN_SUCC));
uint64_t cachedKey = sock->getEKey(); // so we can still send the response packet with the correct key
sP_LS2CL_REP_LOGIN_SUCC resp;
uint64_t cachedKey = sock->getEKey(); // so we can still send the resp packet with the correct key
int charCount = 2; // send 4 randomly generated characters for now
DEBUGLOG(
@ -37,71 +37,71 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
std::cout << "\tID: " << U16toU8(login->szID) << " Password: " << U16toU8(login->szPassword) << std::endl;
)
response->iCharCount = charCount;
response->iSlotNum = 1;
response->iPaymentFlag = 1;
response->iOpenBetaFlag = 0;
response->uiSvrTime = getTime();
resp.iCharCount = charCount;
resp.iSlotNum = 1;
resp.iPaymentFlag = 1;
resp.iOpenBetaFlag = 0;
resp.uiSvrTime = getTime();
// set username in response packet
memcpy(response->szID, login->szID, sizeof(char16_t) * 33);
// set username in resp packet
memcpy(resp.szID, login->szID, sizeof(char16_t) * 33);
// send the resp in with original key
sock->sendPacket((void*)&resp, P_LS2CL_REP_LOGIN_SUCC, sizeof(sP_LS2CL_REP_LOGIN_SUCC));
// update keys
sock->setEKey(CNSocketEncryption::createNewKey(response->uiSvrTime, response->iCharCount + 1, response->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));
// send the response in with original key
sock->sendPacket(new CNPacketData((void*)response, P_LS2CL_REP_LOGIN_SUCC, sizeof(sP_LS2CL_REP_LOGIN_SUCC), cachedKey));
loginSessions[sock] = CNLoginData();
if (settings::LOGINRANDCHARACTERS) {
// now send the characters :)
for (int i = 0; i < charCount; i++) {
sP_LS2CL_REP_CHAR_INFO* charInfo = (sP_LS2CL_REP_CHAR_INFO*)xmalloc(sizeof(sP_LS2CL_REP_CHAR_INFO));
charInfo->iSlot = (int8_t)i + 1;
charInfo->iLevel = (int16_t)1;
charInfo->sPC_Style.iPC_UID = rand(); // unique identifier for the character
charInfo->sPC_Style.iNameCheck = 1;
charInfo->sPC_Style.iGender = (i%2)+1; // can be 1(boy) or 2(girl)
charInfo->sPC_Style.iFaceStyle = 1;
charInfo->sPC_Style.iHairStyle = 1;
charInfo->sPC_Style.iHairColor = (rand()%19) + 1; // 1 - 19
charInfo->sPC_Style.iSkinColor = (rand()%13) + 1; // 1 - 13
charInfo->sPC_Style.iEyeColor = (rand()%6) + 1; // 1 - 6
charInfo->sPC_Style.iHeight = (rand()%6); // 0 -5
charInfo->sPC_Style.iBody = (rand()%4); // 0 - 3
charInfo->sPC_Style.iClass = 0;
charInfo->sPC_Style2.iAppearanceFlag = 1;
charInfo->sPC_Style2.iPayzoneFlag = 1;
charInfo->sPC_Style2.iTutorialFlag = 1;
sP_LS2CL_REP_CHAR_INFO charInfo = sP_LS2CL_REP_CHAR_INFO();
charInfo.iSlot = (int8_t)i + 1;
charInfo.iLevel = (int16_t)1;
charInfo.sPC_Style.iPC_UID = rand(); // unique identifier for the character
charInfo.sPC_Style.iNameCheck = 1;
charInfo.sPC_Style.iGender = (i%2)+1; // can be 1(boy) or 2(girl)
charInfo.sPC_Style.iFaceStyle = 1;
charInfo.sPC_Style.iHairStyle = 1;
charInfo.sPC_Style.iHairColor = (rand()%19) + 1; // 1 - 19
charInfo.sPC_Style.iSkinColor = (rand()%13) + 1; // 1 - 13
charInfo.sPC_Style.iEyeColor = (rand()%6) + 1; // 1 - 6
charInfo.sPC_Style.iHeight = (rand()%6); // 0 -5
charInfo.sPC_Style.iBody = (rand()%4); // 0 - 3
charInfo.sPC_Style.iClass = 0;
charInfo.sPC_Style2.iAppearanceFlag = 1;
charInfo.sPC_Style2.iPayzoneFlag = 1;
charInfo.sPC_Style2.iTutorialFlag = 1;
// past's town hall
charInfo->iX = settings::SPAWN_X;
charInfo->iY = settings::SPAWN_Y;
charInfo->iZ = settings::SPAWN_Z;
charInfo.iX = settings::SPAWN_X;
charInfo.iY = settings::SPAWN_Y;
charInfo.iZ = settings::SPAWN_Z;
U8toU16(std::string("Player"), charInfo->sPC_Style.szFirstName);
U8toU16(std::to_string(i + 1), charInfo->sPC_Style.szLastName);
U8toU16(std::string("Player"), charInfo.sPC_Style.szFirstName);
U8toU16(std::to_string(i + 1), charInfo.sPC_Style.szLastName);
int64_t UID = charInfo->sPC_Style.iPC_UID;
int64_t UID = charInfo.sPC_Style.iPC_UID;
loginSessions[sock].characters[UID] = Player();
loginSessions[sock].characters[UID].level = charInfo->iLevel;
loginSessions[sock].characters[UID].slot = charInfo->iSlot;
loginSessions[sock].characters[UID].level = charInfo.iLevel;
loginSessions[sock].characters[UID].slot = charInfo.iSlot;
loginSessions[sock].characters[UID].FEKey = sock->getFEKey();
loginSessions[sock].characters[UID].x = charInfo->iX;
loginSessions[sock].characters[UID].y = charInfo->iY;
loginSessions[sock].characters[UID].z = charInfo->iZ;
loginSessions[sock].characters[UID].PCStyle = charInfo->sPC_Style;
loginSessions[sock].characters[UID].PCStyle2 = charInfo->sPC_Style2;
loginSessions[sock].characters[UID].x = charInfo.iX;
loginSessions[sock].characters[UID].y = charInfo.iY;
loginSessions[sock].characters[UID].z = charInfo.iZ;
loginSessions[sock].characters[UID].PCStyle = charInfo.sPC_Style;
loginSessions[sock].characters[UID].PCStyle2 = charInfo.sPC_Style2;
loginSessions[sock].characters[UID].IsGM = false;
for (int i = 0; i < AEQUIP_COUNT; i++) {
// setup equips
charInfo->aEquip[i].iID = 0;
charInfo->aEquip[i].iType = i;
charInfo->aEquip[i].iOpt = 0;
loginSessions[sock].characters[UID].Equip[i] = charInfo->aEquip[i];
charInfo.aEquip[i].iID = 0;
charInfo.aEquip[i].iType = i;
charInfo.aEquip[i].iOpt = 0;
loginSessions[sock].characters[UID].Equip[i] = charInfo.aEquip[i];
}
for (int i = 0; i < AINVEN_COUNT; i++) {
@ -115,7 +115,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
if (i == 0)
loginSessions[sock].selectedChar = UID;
sock->sendPacket(new CNPacketData((void*)charInfo, P_LS2CL_REP_CHAR_INFO, sizeof(sP_LS2CL_REP_CHAR_INFO), sock->getEKey()));
sock->sendPacket((void*)&charInfo, P_LS2CL_REP_CHAR_INFO, sizeof(sP_LS2CL_REP_CHAR_INFO));
}
}
@ -131,18 +131,18 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
// naughty words allowed!!!!!!!! (also for some reason, the client will always show 'Player 0' if you manually type a name. It will show up for other connected players though)
sP_CL2LS_REQ_CHECK_CHAR_NAME* nameCheck = (sP_CL2LS_REQ_CHECK_CHAR_NAME*)data->buf;
sP_LS2CL_REP_CHECK_CHAR_NAME_SUCC* response = (sP_LS2CL_REP_CHECK_CHAR_NAME_SUCC*)xmalloc(sizeof(sP_LS2CL_REP_CHECK_CHAR_NAME_SUCC));
sP_LS2CL_REP_CHECK_CHAR_NAME_SUCC resp;
DEBUGLOG(
std::cout << "P_CL2LS_REQ_CHECK_CHAR_NAME:" << std::endl;
std::cout << "\tFirstName: " << U16toU8(nameCheck->szFirstName) << " LastName: " << U16toU8(nameCheck->szLastName) << std::endl;
)
memcpy(response->szFirstName, nameCheck->szFirstName, sizeof(char16_t) * 9);
memcpy(response->szLastName, nameCheck->szLastName, sizeof(char16_t) * 17);
memcpy(resp.szFirstName, nameCheck->szFirstName, sizeof(char16_t) * 9);
memcpy(resp.szLastName, nameCheck->szLastName, sizeof(char16_t) * 17);
// fr*ck allowed!!!
sock->sendPacket(new CNPacketData((void*)response, P_LS2CL_REP_CHECK_CHAR_NAME_SUCC, sizeof(sP_LS2CL_REP_CHECK_CHAR_NAME_SUCC), sock->getEKey()));
sock->sendPacket((void*)&resp, P_LS2CL_REP_CHECK_CHAR_NAME_SUCC, sizeof(sP_LS2CL_REP_CHECK_CHAR_NAME_SUCC));
break;
}
case P_CL2LS_REQ_SAVE_CHAR_NAME: {
@ -150,7 +150,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
return;
sP_CL2LS_REQ_SAVE_CHAR_NAME* save = (sP_CL2LS_REQ_SAVE_CHAR_NAME*)data->buf;
sP_LS2CL_REP_SAVE_CHAR_NAME_SUCC* response = (sP_LS2CL_REP_SAVE_CHAR_NAME_SUCC*)xmalloc(sizeof(sP_LS2CL_REP_SAVE_CHAR_NAME_SUCC));
sP_LS2CL_REP_SAVE_CHAR_NAME_SUCC resp;
DEBUGLOG(
std::cout << "P_CL2LS_REQ_SAVE_CHAR_NAME:" << std::endl;
@ -159,12 +159,12 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
std::cout << "\tName: " << U16toU8(save->szFirstName) << " " << U16toU8(save->szLastName) << std::endl;
)
response->iSlotNum = save->iSlotNum;
response->iGender = save->iGender;
memcpy(response->szFirstName, save->szFirstName, sizeof(char16_t) * 9);
memcpy(response->szLastName, save->szLastName, sizeof(char16_t) * 17);
resp.iSlotNum = save->iSlotNum;
resp.iGender = save->iGender;
memcpy(resp.szFirstName, save->szFirstName, sizeof(char16_t) * 9);
memcpy(resp.szLastName, save->szLastName, sizeof(char16_t) * 17);
sock->sendPacket(new CNPacketData((void*)response, P_LS2CL_REP_SAVE_CHAR_NAME_SUCC, sizeof(sP_LS2CL_REP_SAVE_CHAR_NAME_SUCC), sock->getEKey()));
sock->sendPacket((void*)&resp, P_LS2CL_REP_SAVE_CHAR_NAME_SUCC, sizeof(sP_LS2CL_REP_SAVE_CHAR_NAME_SUCC));
break;
}
case P_CL2LS_REQ_CHAR_CREATE: {
@ -172,7 +172,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
return;
sP_CL2LS_REQ_CHAR_CREATE* character = (sP_CL2LS_REQ_CHAR_CREATE*)data->buf;
sP_LS2CL_REP_CHAR_CREATE_SUCC* response = (sP_LS2CL_REP_CHAR_CREATE_SUCC*)xmalloc(sizeof(sP_LS2CL_REP_CHAR_CREATE_SUCC));
sP_LS2CL_REP_CHAR_CREATE_SUCC resp;
DEBUGLOG(
std::cout << "P_CL2LS_REQ_CHAR_CREATE:" << std::endl;
@ -206,12 +206,12 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
//}
character->PCStyle.iNameCheck = 1;
response->sPC_Style = character->PCStyle;
response->sPC_Style2.iAppearanceFlag = 1;
response->sPC_Style2.iTutorialFlag = 1;
response->sPC_Style2.iPayzoneFlag = 1;
response->iLevel = 1;
response->sOn_Item = character->sOn_Item;
resp.sPC_Style = character->PCStyle;
resp.sPC_Style2.iAppearanceFlag = 1;
resp.sPC_Style2.iTutorialFlag = 1;
resp.sPC_Style2.iPayzoneFlag = 1;
resp.iLevel = 1;
resp.sOn_Item = character->sOn_Item;
loginSessions[sock].characters[UID] = Player();
loginSessions[sock].characters[UID].level = 1;
@ -231,7 +231,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
loginSessions[sock].characters[UID].Equip[3].iType = 3;
loginSessions[sock].characters[UID].IsGM = false;
sock->sendPacket(new CNPacketData((void*)response, P_LS2CL_REP_CHAR_CREATE_SUCC, sizeof(sP_LS2CL_REP_CHAR_CREATE_SUCC), sock->getEKey()));
sock->sendPacket((void*)&resp, P_LS2CL_REP_CHAR_CREATE_SUCC, sizeof(sP_LS2CL_REP_CHAR_CREATE_SUCC));
break;
}
case P_CL2LS_REQ_CHAR_SELECT: {
@ -240,7 +240,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
// character selected
sP_CL2LS_REQ_CHAR_SELECT* chararacter = (sP_CL2LS_REQ_CHAR_SELECT*)data->buf;
sP_LS2CL_REP_CHAR_SELECT_SUCC* response = (sP_LS2CL_REP_CHAR_SELECT_SUCC*)xmalloc(sizeof(sP_LS2CL_REP_CHAR_SELECT_SUCC));
sP_LS2CL_REP_CHAR_SELECT_SUCC resp;
DEBUGLOG(
std::cout << "P_CL2LS_REQ_CHAR_SELECT:" << std::endl;
@ -249,7 +249,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
loginSessions[sock].selectedChar = chararacter->iPC_UID;
sock->sendPacket(new CNPacketData((void*)response, P_LS2CL_REP_CHAR_SELECT_SUCC, sizeof(sP_LS2CL_REP_CHAR_SELECT_SUCC), sock->getEKey()));
sock->sendPacket((void*)&resp, P_LS2CL_REP_CHAR_SELECT_SUCC, sizeof(sP_LS2CL_REP_CHAR_SELECT_SUCC));
break;
}
case P_CL2LS_REQ_SHARD_SELECT: {
@ -258,7 +258,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
// tell client to connect to the shard server
sP_CL2LS_REQ_SHARD_SELECT* shard = (sP_CL2LS_REQ_SHARD_SELECT*)data->buf;
sP_LS2CL_REP_SHARD_SELECT_SUCC* response = (sP_LS2CL_REP_SHARD_SELECT_SUCC*)xmalloc(sizeof(sP_LS2CL_REP_SHARD_SELECT_SUCC));
sP_LS2CL_REP_SHARD_SELECT_SUCC resp;
DEBUGLOG(
std::cout << "P_CL2LS_REQ_SHARD_SELECT:" << std::endl;
@ -266,17 +266,17 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
)
const char* SHARD_IP = settings::SHARDSERVERIP.c_str();
response->iEnterSerialKey = rand();
response->g_FE_ServerPort = settings::SHARDPORT;
resp.iEnterSerialKey = rand();
resp.g_FE_ServerPort = settings::SHARDPORT;
// copy IP to response (this struct uses ASCII encoding so we don't have to goof around converting encodings)
memcpy(response->g_FE_ServerIP, SHARD_IP, strlen(SHARD_IP));
response->g_FE_ServerIP[strlen(SHARD_IP)] = '\0';
// copy IP to resp (this struct uses ASCII encoding so we don't have to goof around converting encodings)
memcpy(resp.g_FE_ServerIP, SHARD_IP, strlen(SHARD_IP));
resp.g_FE_ServerIP[strlen(SHARD_IP)] = '\0';
// pass player to CNSharedData
CNSharedData::setPlayer(response->iEnterSerialKey, loginSessions[sock].characters[loginSessions[sock].selectedChar]);
CNSharedData::setPlayer(resp.iEnterSerialKey, loginSessions[sock].characters[loginSessions[sock].selectedChar]);
sock->sendPacket(new CNPacketData((void*)response, P_LS2CL_REP_SHARD_SELECT_SUCC, sizeof(sP_LS2CL_REP_SHARD_SELECT_SUCC), sock->getEKey()));
sock->sendPacket((void*)&resp, P_LS2CL_REP_SHARD_SELECT_SUCC, sizeof(sP_LS2CL_REP_SHARD_SELECT_SUCC));
sock->kill(); // client should connect to the Shard server now
break;
}
@ -286,6 +286,10 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
}
}
void CNLoginServer::newConnection(CNSocket* cns) {
cns->setActiveKey(SOCKETKEY_E); // by default they accept keys encrypted with the default key
}
void CNLoginServer::killConnection(CNSocket* cns) {
loginSessions.erase(cns);
}

View File

@ -21,6 +21,7 @@ private:
public:
CNLoginServer(uint16_t p);
void newConnection(CNSocket* cns);
void killConnection(CNSocket* cns);
};

View File

@ -63,11 +63,7 @@ int CNSocketEncryption::decryptData(uint8_t* buffer, uint8_t* key, int size) {
// ========================================================[[ CNPacketData ]]========================================================
CNPacketData::CNPacketData(void* b, uint32_t t, int l, uint64_t k): buf(b), type(t), size(l), key(k) {}
CNPacketData::~CNPacketData() {
free(buf); // we own the buffer
}
CNPacketData::CNPacketData(void* b, uint32_t t, int l): buf(b), type(t), size(l) {}
// ========================================================[[ CNSocket ]]========================================================
@ -126,21 +122,34 @@ void CNSocket::kill() {
#endif
}
void CNSocket::sendPacket(CNPacketData* pak) {
if (!alive) {
delete pak;
// we don't own buf
void CNSocket::sendPacket(void* buf, uint32_t type, size_t size) {
if (!alive)
return;
}
int tmpSize = pak->size + sizeof(uint32_t);
int tmpSize = size + sizeof(uint32_t);
uint8_t* tmpBuf = (uint8_t*)xmalloc(tmpSize);
// copy packet type to the front of the buffer & then the actual buffer
memcpy(tmpBuf, (void*)&pak->type, sizeof(uint32_t));
memcpy(tmpBuf+sizeof(uint32_t), pak->buf, pak->size);
memcpy(tmpBuf, (void*)&type, sizeof(uint32_t));
memcpy(tmpBuf+sizeof(uint32_t), buf, size);
// encrypt the packet
CNSocketEncryption::encryptData((uint8_t*)tmpBuf, (uint8_t*)(&pak->key), tmpSize);
switch (activeKey) {
case SOCKETKEY_E:
CNSocketEncryption::encryptData((uint8_t*)tmpBuf, (uint8_t*)(&EKey), tmpSize);
break;
case SOCKETKEY_FE:
CNSocketEncryption::encryptData((uint8_t*)tmpBuf, (uint8_t*)(&FEKey), tmpSize);
break;
default: {
free(tmpBuf);
DEBUGLOG(
std::cout << "[WARN]: UNSET KEYTYPE FOR SOCKET!! ABORTING SEND" << std::endl;
)
return;
}
}
// send packet size
if (!sendData((uint8_t*)&tmpSize, sizeof(uint32_t)))
@ -150,10 +159,13 @@ void CNSocket::sendPacket(CNPacketData* pak) {
if (alive && !sendData(tmpBuf, tmpSize))
kill();
delete pak;
free(tmpBuf); // free tmp buffer
}
void CNSocket::setActiveKey(ACTIVEKEY key) {
activeKey = key;
}
void CNSocket::step() {
if (readSize <= 0) {
// we aren't reading a packet yet, try to start looking for one
@ -183,13 +195,15 @@ void CNSocket::step() {
// decrypt readBuffer and copy to CNPacketData
CNSocketEncryption::decryptData(readBuffer, (uint8_t*)(&EKey), readSize);
// this doesn't leak memory because we free it in CNPacketData's deconstructor LOL
void* tmpBuf = xmalloc(readSize-sizeof(int32_t));
memcpy(tmpBuf, readBuffer+sizeof(uint32_t), readSize-sizeof(int32_t));
CNPacketData tmp(tmpBuf, *((uint32_t*)readBuffer), readSize-sizeof(int32_t), EKey);
CNPacketData tmp(tmpBuf, *((uint32_t*)readBuffer), readSize-sizeof(int32_t));
// CALL PACKET HANDLER!!
pHandler(this, &tmp); // tmp's deconstructor will be called when readStep returns so that tmpBuffer we made will be cleaned up :)
// call packet handler!!
pHandler(this, &tmp);
// clean up the buffer :)
free(tmpBuf);
// reset vars :)
readSize = 0;
@ -261,22 +275,22 @@ void CNServer::start() {
std::lock_guard<std::mutex> lock(activeCrit);
// listen for a new connection
SOCKET newConnection = accept(sock, (struct sockaddr *)&(address), (socklen_t*)&(addressSize));
if (!SOCKETINVALID(newConnection)) {
SOCKET newConnectionSocket = accept(sock, (struct sockaddr *)&(address), (socklen_t*)&(addressSize));
if (!SOCKETINVALID(newConnectionSocket)) {
// new connection! make sure to set non-blocking!
#ifdef _WIN32
unsigned long mode = 1;
if (ioctlsocket(newConnection, FIONBIO, &mode) != 0) {
if (ioctlsocket(newConnectionSocket, FIONBIO, &mode) != 0) {
#else
if (fcntl(newConnection, F_SETFL, (fcntl(sock, F_GETFL, 0) | O_NONBLOCK)) != 0) {
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;
#ifdef _WIN32
shutdown(newConnection, SD_BOTH);
closesocket(newConnection);
shutdown(newConnectionSocket, SD_BOTH);
closesocket(newConnectionSocket);
#else
shutdown(newConnection, SHUT_RDWR);
close(newConnection);
shutdown(newConnectionSocket, SHUT_RDWR);
close(newConnectionSocket);
#endif
continue;
}
@ -284,8 +298,9 @@ void CNServer::start() {
std::cout << "New connection! " << inet_ntoa(address.sin_addr) << std::endl;
// add connection to list!
CNSocket* tmp = new CNSocket(newConnection, pHandler);
CNSocket* tmp = new CNSocket(newConnectionSocket, pHandler);
connections.push_back(tmp);
newConnection(tmp);
}
// for each connection, check if it's alive, if not kill it!
@ -337,5 +352,6 @@ void CNServer::kill() {
connections.clear();
}
void CNServer::killConnection(CNSocket* cns) {} // stubbed lol
void CNServer::onTimer() {} // stubbed lol
void CNServer::newConnection(CNSocket* cns) {} // stubbed
void CNServer::killConnection(CNSocket* cns) {} // stubbed
void CNServer::onTimer() {} // stubbed

View File

@ -77,15 +77,17 @@ namespace CNSocketEncryption {
int decryptData(uint8_t* buffer, uint8_t* key, int size);
}
class CNPacketData {
public:
struct CNPacketData {
void* buf;
int size;
uint32_t type;
uint64_t key;
CNPacketData(void* b, uint32_t t, int l, uint64_t k);
~CNPacketData();
CNPacketData(void* b, uint32_t t, int l);
};
enum ACTIVEKEY {
SOCKETKEY_E,
SOCKETKEY_FE
};
class CNSocket;
@ -101,6 +103,8 @@ private:
bool activelyReading = false;
bool alive = true;
ACTIVEKEY activeKey;
bool sendData(uint8_t* data, int size);
public:
@ -113,9 +117,10 @@ public:
void setFEKey(uint64_t k);
uint64_t getEKey();
uint64_t getFEKey();
void setActiveKey(ACTIVEKEY t);
void kill();
void sendPacket(CNPacketData* pak);
void sendPacket(void* buf, uint32_t packetType, size_t size);
void step();
bool isAlive();
};
@ -143,6 +148,7 @@ public:
void start();
void kill();
virtual void newConnection(CNSocket* cns);
virtual void killConnection(CNSocket* cns);
virtual void onTimer(); // called every 2 seconds
};

View File

@ -28,6 +28,10 @@ void CNShardServer::handlePacket(CNSocket* sock, CNPacketData* data) {
std::cerr << "OpenFusion: SHARD UNIMPLM ERR. PacketType: " << Defines::p2str(CL2FE, data->type) << " (" << data->type << ")" << std::endl;
}
void CNShardServer::newConnection(CNSocket* cns) {
cns->setActiveKey(SOCKETKEY_E); // by default they accept keys encrypted with the default key
}
void CNShardServer::killConnection(CNSocket* cns) {
// remove from CNSharedData
Player cachedPlr = PlayerManager::getPlayer(cns);
@ -48,7 +52,7 @@ void CNShardServer::onTimer() {
}
// passed the heartbeat, send another
sP_FE2CL_REQ_LIVE_CHECK* data = (sP_FE2CL_REQ_LIVE_CHECK*)xmalloc(sizeof(sP_FE2CL_REQ_LIVE_CHECK));
pair.first->sendPacket(new CNPacketData((void*)data, P_FE2CL_REQ_LIVE_CHECK, sizeof(sP_FE2CL_REQ_LIVE_CHECK), pair.first->getFEKey()));
sP_FE2CL_REQ_LIVE_CHECK data;
pair.first->sendPacket((void*)&data, P_FE2CL_REQ_LIVE_CHECK, sizeof(sP_FE2CL_REQ_LIVE_CHECK));
}
}

View File

@ -17,6 +17,7 @@ public:
CNShardServer(uint16_t p);
void newConnection(CNSocket* cns);
void killConnection(CNSocket* cns);
void onTimer();
};

View File

@ -16,21 +16,18 @@ void ChatManager::chatHandler(CNSocket* sock, CNPacketData* data) {
PlayerView plr = PlayerManager::players[sock];
// send to client
sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC* resp = (sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC));
memcpy(resp->szFreeChat, chat->szFreeChat, sizeof(chat->szFreeChat));
resp->iPC_ID = PlayerManager::players[sock].plr.iID;
resp->iEmoteCode = chat->iEmoteCode;
sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC), sock->getFEKey()));
sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC resp;
memcpy(resp.szFreeChat, chat->szFreeChat, sizeof(chat->szFreeChat));
resp.iPC_ID = plr.plr.iID;
resp.iEmoteCode = chat->iEmoteCode;
sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC));
// send to visible players
for (CNSocket* otherSock : plr.viewable) {
sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC* resp = (sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC));
memcpy(resp->szFreeChat, chat->szFreeChat, sizeof(chat->szFreeChat));
resp->iPC_ID = PlayerManager::players[sock].plr.iID;
resp->iEmoteCode = chat->iEmoteCode;
otherSock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC), otherSock->getFEKey()));
otherSock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC));
}
}
void ChatManager::menuChatHandler(CNSocket* sock, CNPacketData* data) {
if (data->size != sizeof(sP_CL2FE_REQ_SEND_MENUCHAT_MESSAGE))
return; // malformed packet
@ -38,19 +35,15 @@ void ChatManager::menuChatHandler(CNSocket* sock, CNPacketData* data) {
PlayerView plr = PlayerManager::players[sock];
// send to client
sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC* resp = (sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC));
memcpy(resp->szFreeChat, chat->szFreeChat, sizeof(chat->szFreeChat));
resp->iPC_ID = PlayerManager::players[sock].plr.iID;
resp->iEmoteCode = chat->iEmoteCode;
sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC), sock->getFEKey()));
sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC resp;
memcpy(resp.szFreeChat, chat->szFreeChat, sizeof(chat->szFreeChat));
resp.iPC_ID = plr.plr.iID;
resp.iEmoteCode = chat->iEmoteCode;
sock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC));
// send to visible players
for (CNSocket* otherSock : plr.viewable) {
sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC* resp = (sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC));
memcpy(resp->szFreeChat, chat->szFreeChat, sizeof(chat->szFreeChat));
resp->iPC_ID = PlayerManager::players[sock].plr.iID;
resp->iEmoteCode = chat->iEmoteCode;
otherSock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC), otherSock->getFEKey()));
otherSock->sendPacket((void*)&resp, P_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, sizeof(sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC));
}
}
void ChatManager::emoteHandler(CNSocket* sock, CNPacketData* data) {
@ -63,16 +56,13 @@ void ChatManager::emoteHandler(CNSocket* sock, CNPacketData* data) {
PlayerView plr = PlayerManager::players[sock];
// send to client
sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT* resp = (sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT*)xmalloc(sizeof(sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT));
resp->iEmoteCode = emote->iEmoteCode;
resp->iID_From = plr.plr.iID;
sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_PC_AVATAR_EMOTES_CHAT, sizeof(sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT), sock->getFEKey()));
sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT resp;
resp.iEmoteCode = emote->iEmoteCode;
resp.iID_From = plr.plr.iID;
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_AVATAR_EMOTES_CHAT, sizeof(sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT));
// send to visible players (players within render distance)
for (CNSocket* otherSock : plr.viewable) {
resp = (sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT*)xmalloc(sizeof(sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT));
resp->iEmoteCode = emote->iEmoteCode;
resp->iID_From = plr.plr.iID;
otherSock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_PC_AVATAR_EMOTES_CHAT, sizeof(sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT), otherSock->getFEKey()));
otherSock->sendPacket((void*)&resp, P_FE2CL_REP_PC_AVATAR_EMOTES_CHAT, sizeof(sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT));
}
}

View File

@ -15,7 +15,7 @@ void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) {
return; // ignore the malformed packet
sP_CL2FE_REQ_ITEM_MOVE* itemmove = (sP_CL2FE_REQ_ITEM_MOVE*)data->buf;
sP_FE2CL_PC_ITEM_MOVE_SUCC* resp = (sP_FE2CL_PC_ITEM_MOVE_SUCC*)xmalloc(sizeof(sP_FE2CL_PC_ITEM_MOVE_SUCC));
sP_FE2CL_PC_ITEM_MOVE_SUCC resp;
PlayerView& plr = PlayerManager::players[sock];
sItemBase fromItem;
@ -46,29 +46,31 @@ void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) {
}
if (itemmove->eFrom == 0 || itemmove->eTo == 0) {
for (CNSocket* otherSock : plr.viewable) {
sP_FE2CL_PC_EQUIP_CHANGE* resp2 = (sP_FE2CL_PC_EQUIP_CHANGE*)xmalloc(sizeof(sP_FE2CL_PC_EQUIP_CHANGE));
sP_FE2CL_PC_EQUIP_CHANGE equipChange;
resp2->iPC_ID = plr.plr.iID;
if (itemmove->eFrom == 0) {
resp2->iEquipSlotNum = itemmove->iFromSlotNum;
resp2->EquipSlotItem = toItem;
} else {
resp2->iEquipSlotNum = itemmove->iToSlotNum;
resp2->EquipSlotItem = fromItem;
}
otherSock->sendPacket(new CNPacketData((void*)resp2, P_FE2CL_PC_EQUIP_CHANGE, sizeof(sP_FE2CL_PC_EQUIP_CHANGE), otherSock->getFEKey()));
equipChange.iPC_ID = plr.plr.iID;
if (itemmove->eFrom == 0) {
equipChange.iEquipSlotNum = itemmove->iFromSlotNum;
equipChange.EquipSlotItem = toItem;
} else {
equipChange.iEquipSlotNum = itemmove->iToSlotNum;
equipChange.EquipSlotItem = fromItem;
}
// send equip event to other players
for (CNSocket* otherSock : plr.viewable) {
otherSock->sendPacket((void*)&equipChange, P_FE2CL_PC_EQUIP_CHANGE, sizeof(sP_FE2CL_PC_EQUIP_CHANGE));
}
}
resp->eTo = itemmove->eFrom;
resp->iToSlotNum = itemmove->iFromSlotNum;
resp->ToSlotItem = toItem;
resp->eFrom = itemmove->eTo;
resp->iFromSlotNum = itemmove->iToSlotNum;
resp->FromSlotItem = fromItem;
resp.eTo = itemmove->eFrom;
resp.iToSlotNum = itemmove->iFromSlotNum;
resp.ToSlotItem = toItem;
resp.eFrom = itemmove->eTo;
resp.iFromSlotNum = itemmove->iToSlotNum;
resp.FromSlotItem = fromItem;
sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_PC_ITEM_MOVE_SUCC, sizeof(sP_FE2CL_PC_ITEM_MOVE_SUCC), sock->getFEKey()));
sock->sendPacket((void*)&resp, P_FE2CL_PC_ITEM_MOVE_SUCC, sizeof(sP_FE2CL_PC_ITEM_MOVE_SUCC));
}
void ItemManager::itemDeleteHandler(CNSocket* sock, CNPacketData* data) {
@ -76,19 +78,19 @@ void ItemManager::itemDeleteHandler(CNSocket* sock, CNPacketData* data) {
return; // ignore the malformed packet
sP_CL2FE_REQ_PC_ITEM_DELETE* itemdel = (sP_CL2FE_REQ_PC_ITEM_DELETE*)data->buf;
sP_FE2CL_REP_PC_ITEM_DELETE_SUCC* resp = (sP_FE2CL_REP_PC_ITEM_DELETE_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_PC_ITEM_DELETE_SUCC));
sP_FE2CL_REP_PC_ITEM_DELETE_SUCC resp;
PlayerView& plr = PlayerManager::players[sock];
resp->eIL = itemdel->eIL;
resp->iSlotNum = itemdel->iSlotNum;
resp.eIL = itemdel->eIL;
resp.iSlotNum = itemdel->iSlotNum;
// so, im not sure what this eIL thing does since you always delete items in inventory and not equips
plr.plr.Inven[itemdel->iSlotNum].iID = 0;
plr.plr.Inven[itemdel->iSlotNum].iType = 0;
plr.plr.Inven[itemdel->iSlotNum].iOpt = 0;
sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_PC_ITEM_DELETE_SUCC, sizeof(sP_FE2CL_REP_PC_ITEM_DELETE_SUCC), sock->getFEKey()));
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_ITEM_DELETE_SUCC, sizeof(sP_FE2CL_REP_PC_ITEM_DELETE_SUCC));
}
void ItemManager::itemGMGiveHandler(CNSocket* sock, CNPacketData* data) {
@ -108,22 +110,24 @@ 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) {
sP_FE2CL_REP_PC_GIVE_ITEM_SUCC* resp = (sP_FE2CL_REP_PC_GIVE_ITEM_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_PC_GIVE_ITEM_SUCC));
sP_FE2CL_REP_PC_GIVE_ITEM_SUCC resp;
resp->eIL = itemreq->eIL;
resp->iSlotNum = itemreq->iSlotNum;
resp->Item = itemreq->Item;
resp.eIL = itemreq->eIL;
resp.iSlotNum = itemreq->iSlotNum;
resp.Item = itemreq->Item;
plr.plr.Inven[itemreq->iSlotNum] = itemreq->Item;
plr.plr.level = 36;
sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_PC_GIVE_ITEM_SUCC, sizeof(sP_FE2CL_REP_PC_GIVE_ITEM_SUCC), sock->getFEKey()));
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_GIVE_ITEM_SUCC, sizeof(sP_FE2CL_REP_PC_GIVE_ITEM_SUCC));
sP_FE2CL_REP_PC_CHANGE_LEVEL* resp2 = (sP_FE2CL_REP_PC_CHANGE_LEVEL*)xmalloc(sizeof(sP_FE2CL_REP_PC_CHANGE_LEVEL));
// some items require a level, for now we're just going to bypass this by setting your level to 36
resp2->iPC_ID = plr.plr.iID;
resp2->iPC_Level = 36;
sP_FE2CL_REP_PC_CHANGE_LEVEL resp2;
sock->sendPacket(new CNPacketData((void*)resp2, P_FE2CL_REP_PC_CHANGE_LEVEL, sizeof(sP_FE2CL_REP_PC_CHANGE_LEVEL), sock->getFEKey()));
resp2.iPC_ID = plr.plr.iID;
resp2.iPC_Level = 36;
sock->sendPacket((void*)&resp2, P_FE2CL_REP_PC_CHANGE_LEVEL, sizeof(sP_FE2CL_REP_PC_CHANGE_LEVEL));
}
}

View File

@ -49,17 +49,16 @@ void NPCManager::updatePlayerNPCS(CNSocket* sock, PlayerView& view) {
}
}
sP_FE2CL_NPC_EXIT exitData;
std::list<int32_t>::iterator i = view.viewableNPCs.begin();
while (i != view.viewableNPCs.end()) {
int32_t id = *i;
if (std::find(noView.begin(), noView.end(), id) != noView.end()) {
// it shouldn't be visible, send NPC_EXIT
sP_FE2CL_NPC_EXIT* exitData = (sP_FE2CL_NPC_EXIT*)xmalloc(sizeof(sP_FE2CL_NPC_EXIT));
exitData->iNPC_ID = id;
sock->sendPacket(new CNPacketData((void*)exitData, P_FE2CL_NPC_EXIT, sizeof(sP_FE2CL_NPC_EXIT), sock->getFEKey()));
exitData.iNPC_ID = id;
sock->sendPacket((void*)&exitData, P_FE2CL_NPC_EXIT, sizeof(sP_FE2CL_NPC_EXIT));
// remove from view
view.viewableNPCs.erase(i++);
@ -68,16 +67,15 @@ void NPCManager::updatePlayerNPCS(CNSocket* sock, PlayerView& view) {
++i;
}
sP_FE2CL_NPC_ENTER enterData;
for (int32_t id : yesView) {
if (std::find(view.viewableNPCs.begin(), view.viewableNPCs.end(), id) == view.viewableNPCs.end()) {
// needs to be added to viewableNPCs! send NPC_ENTER
sP_FE2CL_NPC_ENTER* enterData = (sP_FE2CL_NPC_ENTER*)xmalloc(sizeof(sP_FE2CL_NPC_ENTER));
enterData->NPCAppearanceData = NPCs[id].appearanceData;
sock->sendPacket(new CNPacketData((void*)enterData, P_FE2CL_NPC_ENTER, sizeof(sP_FE2CL_NPC_ENTER), sock->getFEKey()));
enterData.NPCAppearanceData = NPCs[id].appearanceData;
sock->sendPacket((void*)&enterData, P_FE2CL_NPC_ENTER, sizeof(sP_FE2CL_NPC_ENTER));
// add to viewable
view.viewableNPCs.push_back(id);
}
}

View File

@ -17,11 +17,12 @@ void NanoManager::nanoEquipHandler(CNSocket* sock, CNPacketData* data) {
return; // malformed packet
sP_CL2FE_REQ_NANO_EQUIP* nano = (sP_CL2FE_REQ_NANO_EQUIP*)data->buf;
sP_FE2CL_REP_NANO_EQUIP_SUCC* resp = (sP_FE2CL_REP_NANO_EQUIP_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_NANO_EQUIP_SUCC));
resp->iNanoID = nano->iNanoID;
resp->iNanoSlotNum = nano->iNanoSlotNum;
sP_FE2CL_REP_NANO_EQUIP_SUCC resp;
sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_NANO_EQUIP_SUCC, sizeof(sP_FE2CL_REP_NANO_EQUIP_SUCC), sock->getFEKey()));
resp.iNanoID = nano->iNanoID;
resp.iNanoSlotNum = nano->iNanoSlotNum;
sock->sendPacket((void*)&resp, P_FE2CL_REP_NANO_EQUIP_SUCC, sizeof(sP_FE2CL_REP_NANO_EQUIP_SUCC));
}
void NanoManager::nanoUnEquipHandler(CNSocket* sock, CNPacketData* data) {
@ -29,10 +30,11 @@ void NanoManager::nanoUnEquipHandler(CNSocket* sock, CNPacketData* data) {
return; // malformed packet
sP_CL2FE_REQ_NANO_UNEQUIP* nano = (sP_CL2FE_REQ_NANO_UNEQUIP*)data->buf;
sP_FE2CL_REP_NANO_UNEQUIP_SUCC* resp = (sP_FE2CL_REP_NANO_UNEQUIP_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_NANO_UNEQUIP_SUCC));
resp->iNanoSlotNum = nano->iNanoSlotNum;
sP_FE2CL_REP_NANO_UNEQUIP_SUCC resp;
sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_NANO_UNEQUIP_SUCC, sizeof(sP_FE2CL_REP_NANO_UNEQUIP_SUCC), sock->getFEKey()));
resp.iNanoSlotNum = nano->iNanoSlotNum;
sock->sendPacket((void*)&resp, P_FE2CL_REP_NANO_UNEQUIP_SUCC, sizeof(sP_FE2CL_REP_NANO_UNEQUIP_SUCC));
}
void NanoManager::nanoGMGiveHandler(CNSocket* sock, CNPacketData* data) {
@ -59,9 +61,9 @@ void NanoManager::nanoSummonHandler(CNSocket* sock, CNPacketData* data) {
PlayerView plr = PlayerManager::players[sock];
// Send to client
sP_FE2CL_REP_NANO_ACTIVE_SUCC* resp = (sP_FE2CL_REP_NANO_ACTIVE_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_NANO_ACTIVE_SUCC));
resp->iActiveNanoSlotNum = nano->iNanoSlotNum;
sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_NANO_ACTIVE_SUCC, sizeof(sP_FE2CL_REP_NANO_ACTIVE_SUCC), sock->getFEKey()));
sP_FE2CL_REP_NANO_ACTIVE_SUCC resp;
resp.iActiveNanoSlotNum = nano->iNanoSlotNum;
sock->sendPacket((void*)&resp, P_FE2CL_REP_NANO_ACTIVE_SUCC, sizeof(sP_FE2CL_REP_NANO_ACTIVE_SUCC));
DEBUGLOG(
std::cout << U16toU8(plr.plr.PCStyle.szFirstName) << U16toU8(plr.plr.PCStyle.szLastName) << " requested to summon nano slot: " << nano->iNanoSlotNum << std::endl;
@ -76,16 +78,16 @@ void NanoManager::nanoSkillUseHandler(CNSocket* sock, CNPacketData* data) {
PlayerView plr = PlayerManager::players[sock];
// Send to client
sP_FE2CL_NANO_SKILL_USE_SUCC* resp = (sP_FE2CL_NANO_SKILL_USE_SUCC*)xmalloc(sizeof(sP_FE2CL_NANO_SKILL_USE_SUCC));
resp->iArg1 = skill->iArg1;
resp->iArg2 = skill->iArg2;
resp->iArg3 = skill->iArg3;
resp->iBulletID = skill->iBulletID;
resp->iTargetCnt = skill->iTargetCnt;
resp->iPC_ID = plr.plr.iID;
resp->iNanoStamina = 150; // Hardcoded for now
sP_FE2CL_NANO_SKILL_USE_SUCC resp;
resp.iArg1 = skill->iArg1;
resp.iArg2 = skill->iArg2;
resp.iArg3 = skill->iArg3;
resp.iBulletID = skill->iBulletID;
resp.iTargetCnt = skill->iTargetCnt;
resp.iPC_ID = plr.plr.iID;
resp.iNanoStamina = 150; // Hardcoded for now
sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_NANO_SKILL_USE_SUCC, sizeof(sP_FE2CL_NANO_SKILL_USE_SUCC), sock->getFEKey()));
sock->sendPacket((void*)&resp, P_FE2CL_NANO_SKILL_USE_SUCC, sizeof(sP_FE2CL_NANO_SKILL_USE_SUCC));
DEBUGLOG(
std::cout << U16toU8(plr.plr.PCStyle.szFirstName) << U16toU8(plr.plr.PCStyle.szLastName) << " requested to summon nano skill " << std::endl;
@ -105,15 +107,15 @@ void NanoManager::addNano(CNSocket* sock, int16_t nanoId, int16_t slot) {
Player plr = PlayerManager::getPlayer(sock);
// Send to client
sP_FE2CL_REP_PC_NANO_CREATE_SUCC* resp = new sP_FE2CL_REP_PC_NANO_CREATE_SUCC();
resp->Nano.iID = nanoId;
resp->Nano.iStamina = 150;
resp->iQuestItemSlotNum = slot;
sP_FE2CL_REP_PC_NANO_CREATE_SUCC resp;
resp.Nano.iID = nanoId;
resp.Nano.iStamina = 150;
resp.iQuestItemSlotNum = slot;
sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_PC_NANO_CREATE_SUCC, sizeof(sP_FE2CL_REP_PC_NANO_CREATE_SUCC), sock->getFEKey()));
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_NANO_CREATE_SUCC, sizeof(sP_FE2CL_REP_PC_NANO_CREATE_SUCC));
// Update player
plr.Nanos[nanoId] = resp->Nano;
plr.Nanos[nanoId] = resp.Nano;
PlayerManager::updatePlayer(sock, plr);
}
@ -125,11 +127,11 @@ void NanoManager::setNanoSkill(CNSocket* sock, int16_t nanoId, int16_t skillId)
plr.Nanos[nanoId] = nano;
// Send to client
sP_FE2CL_REP_NANO_TUNE_SUCC* resp = (sP_FE2CL_REP_NANO_TUNE_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_NANO_TUNE_SUCC));
resp->iNanoID = nanoId;
resp->iSkillID = skillId;
sP_FE2CL_REP_NANO_TUNE_SUCC resp;
resp.iNanoID = nanoId;
resp.iSkillID = skillId;
sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_NANO_TUNE_SUCC, sizeof(sP_FE2CL_REP_NANO_TUNE_SUCC), sock->getFEKey()));
sock->sendPacket((void*)&resp, P_FE2CL_REP_NANO_TUNE_SUCC, sizeof(sP_FE2CL_REP_NANO_TUNE_SUCC));
DEBUGLOG(
std::cout << U16toU8(plr.PCStyle.szFirstName) << U16toU8(plr.PCStyle.szLastName) << " set skill id " << skillId << " for nano: " << nanoId << std::endl;

View File

@ -48,10 +48,10 @@ void PlayerManager::removePlayer(CNSocket* key) {
players[otherSock].viewable.remove(key); // gone
// now sent PC_EXIT packet
sP_FE2CL_PC_EXIT* exitPacket = (sP_FE2CL_PC_EXIT*)xmalloc(sizeof(sP_FE2CL_PC_EXIT));
exitPacket->iID = players[key].plr.iID;
sP_FE2CL_PC_EXIT exitPacket;
exitPacket.iID = players[key].plr.iID;
otherSock->sendPacket(new CNPacketData((void*)exitPacket, P_FE2CL_PC_EXIT, sizeof(sP_FE2CL_PC_EXIT), otherSock->getFEKey()));
otherSock->sendPacket((void*)&exitPacket, P_FE2CL_PC_EXIT, sizeof(sP_FE2CL_PC_EXIT));
}
players.erase(key);
@ -88,21 +88,20 @@ void PlayerManager::updatePlayerPosition(CNSocket* sock, int X, int Y, int Z) {
}
}
sP_FE2CL_PC_EXIT exitPacket;
std::list<CNSocket*>::iterator i = players[sock].viewable.begin();
while (i != players[sock].viewable.end()) {
CNSocket* otherSock = *i;
if (std::find(noView.begin(), noView.end(), otherSock) != noView.end()) {
// sock shouldn't be visible, send PC_EXIT packet & remove them
sP_FE2CL_PC_EXIT* exitPacket = (sP_FE2CL_PC_EXIT*)xmalloc(sizeof(sP_FE2CL_PC_EXIT));
sP_FE2CL_PC_EXIT* exitPacketOther = (sP_FE2CL_PC_EXIT*)xmalloc(sizeof(sP_FE2CL_PC_EXIT));
exitPacket->iID = players[sock].plr.iID;
exitPacketOther->iID = players[otherSock].plr.iID;
otherSock->sendPacket(new CNPacketData((void*)exitPacket, P_FE2CL_PC_EXIT, sizeof(sP_FE2CL_PC_EXIT), otherSock->getFEKey()));
sock->sendPacket(new CNPacketData((void*)exitPacketOther, P_FE2CL_PC_EXIT, sizeof(sP_FE2CL_PC_EXIT), sock->getFEKey()));
// sock shouldn't be visible, send PC_EXIT packet
exitPacket.iID = players[sock].plr.iID;
otherSock->sendPacket((void*)&exitPacket, P_FE2CL_PC_EXIT, sizeof(sP_FE2CL_PC_EXIT));
exitPacket.iID = players[otherSock].plr.iID;
sock->sendPacket((void*)&exitPacket, P_FE2CL_PC_EXIT, sizeof(sP_FE2CL_PC_EXIT));
// remove them from the viewable list
players[sock].viewable.erase(i++);
players[otherSock].viewable.remove(sock);
continue;
@ -111,38 +110,37 @@ void PlayerManager::updatePlayerPosition(CNSocket* sock, int X, int Y, int Z) {
++i;
}
sP_FE2CL_PC_NEW newPlayer;
for (CNSocket* otherSock : yesView) {
if (std::find(players[sock].viewable.begin(), players[sock].viewable.end(), otherSock) == players[sock].viewable.end()) {
// this needs to be added to the viewable players, send PC_ENTER
sP_FE2CL_PC_NEW* newPlayer = (sP_FE2CL_PC_NEW*)xmalloc(sizeof(sP_FE2CL_PC_NEW)); // current connection to other player
sP_FE2CL_PC_NEW* newOtherPlayer = (sP_FE2CL_PC_NEW*)xmalloc(sizeof(sP_FE2CL_PC_NEW)); // other player to current connection
Player otherPlr = players[otherSock].plr;
Player plr = players[sock].plr;
newPlayer->PCAppearanceData.iID = plr.iID;
newPlayer->PCAppearanceData.iHP = plr.HP;
newPlayer->PCAppearanceData.iLv = plr.level;
newPlayer->PCAppearanceData.iX = plr.x;
newPlayer->PCAppearanceData.iY = plr.y;
newPlayer->PCAppearanceData.iZ = plr.z;
newPlayer->PCAppearanceData.iAngle = plr.angle;
newPlayer->PCAppearanceData.PCStyle = plr.PCStyle;
memcpy(newPlayer->PCAppearanceData.ItemEquip, plr.Equip, sizeof(sItemBase) * AEQUIP_COUNT);
newPlayer.PCAppearanceData.iID = plr.iID;
newPlayer.PCAppearanceData.iHP = plr.HP;
newPlayer.PCAppearanceData.iLv = plr.level;
newPlayer.PCAppearanceData.iX = plr.x;
newPlayer.PCAppearanceData.iY = plr.y;
newPlayer.PCAppearanceData.iZ = plr.z;
newPlayer.PCAppearanceData.iAngle = plr.angle;
newPlayer.PCAppearanceData.PCStyle = plr.PCStyle;
memcpy(newPlayer.PCAppearanceData.ItemEquip, plr.Equip, sizeof(sItemBase) * AEQUIP_COUNT);
newOtherPlayer->PCAppearanceData.iID = otherPlr.iID;
newOtherPlayer->PCAppearanceData.iHP = otherPlr.HP;
newOtherPlayer->PCAppearanceData.iLv = otherPlr.level;
newOtherPlayer->PCAppearanceData.iX = otherPlr.x;
newOtherPlayer->PCAppearanceData.iY = otherPlr.y;
newOtherPlayer->PCAppearanceData.iZ = otherPlr.z;
newOtherPlayer->PCAppearanceData.iAngle = otherPlr.angle;
newOtherPlayer->PCAppearanceData.PCStyle = otherPlr.PCStyle;
memcpy(newOtherPlayer->PCAppearanceData.ItemEquip, otherPlr.Equip, sizeof(sItemBase) * AEQUIP_COUNT);
otherSock->sendPacket((void*)&newPlayer, P_FE2CL_PC_NEW, sizeof(sP_FE2CL_PC_NEW));
sock->sendPacket(new CNPacketData((void*)newOtherPlayer, P_FE2CL_PC_NEW, sizeof(sP_FE2CL_PC_NEW), sock->getFEKey()));
otherSock->sendPacket(new CNPacketData((void*)newPlayer, P_FE2CL_PC_NEW, sizeof(sP_FE2CL_PC_NEW), otherSock->getFEKey()));
newPlayer.PCAppearanceData.iID = otherPlr.iID;
newPlayer.PCAppearanceData.iHP = otherPlr.HP;
newPlayer.PCAppearanceData.iLv = otherPlr.level;
newPlayer.PCAppearanceData.iX = otherPlr.x;
newPlayer.PCAppearanceData.iY = otherPlr.y;
newPlayer.PCAppearanceData.iZ = otherPlr.z;
newPlayer.PCAppearanceData.iAngle = otherPlr.angle;
newPlayer.PCAppearanceData.PCStyle = otherPlr.PCStyle;
memcpy(newPlayer.PCAppearanceData.ItemEquip, otherPlr.Equip, sizeof(sItemBase) * AEQUIP_COUNT);
sock->sendPacket((void*)&newPlayer, P_FE2CL_PC_NEW, sizeof(sP_FE2CL_PC_NEW));
players[sock].viewable.push_back(otherSock);
players[otherSock].viewable.push_back(sock);
@ -157,8 +155,8 @@ void PlayerManager::enterPlayer(CNSocket* sock, CNPacketData* data) {
return; // ignore the malformed packet
sP_CL2FE_REQ_PC_ENTER* enter = (sP_CL2FE_REQ_PC_ENTER*)data->buf;
sP_FE2CL_REP_PC_ENTER_SUCC* response = (sP_FE2CL_REP_PC_ENTER_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_PC_ENTER_SUCC));
sP_FE2CL_PC_MOTD_LOGIN* motd = (sP_FE2CL_PC_MOTD_LOGIN*)xmalloc(sizeof(sP_FE2CL_PC_MOTD_LOGIN));
sP_FE2CL_REP_PC_ENTER_SUCC response;
sP_FE2CL_PC_MOTD_LOGIN motd;
// TODO: check if serialkey exists, if it doesn't send sP_FE2CL_REP_PC_ENTER_FAIL
Player plr = CNSharedData::getPlayer(enter->iEnterSerialKey);
@ -171,69 +169,57 @@ void PlayerManager::enterPlayer(CNSocket* sock, CNPacketData* data) {
std::cout << "\tPC_UID: " << plr.PCStyle.iPC_UID << std::endl;
)
response->iID = rand();
response->uiSvrTime = getTime();
response->PCLoadData2CL.iUserLevel = 1;
response->PCLoadData2CL.iHP = 1000 * plr.level;
response->PCLoadData2CL.iLevel = plr.level;
response->PCLoadData2CL.iMentor = 1;
response->PCLoadData2CL.iMentorCount = 4;
response->PCLoadData2CL.iMapNum = 0;
response->PCLoadData2CL.iX = plr.x;
response->PCLoadData2CL.iY = plr.y;
response->PCLoadData2CL.iZ = plr.z;
response->PCLoadData2CL.iActiveNanoSlotNum = -1;
response->PCLoadData2CL.iFatigue = 50;
response->PCLoadData2CL.PCStyle = plr.PCStyle;
response->PCLoadData2CL.PCStyle2 = plr.PCStyle2;
response.iID = rand();
response.uiSvrTime = getTime();
response.PCLoadData2CL.iUserLevel = 1;
response.PCLoadData2CL.iHP = 1000 * plr.level;
response.PCLoadData2CL.iLevel = plr.level;
response.PCLoadData2CL.iMentor = 1;
response.PCLoadData2CL.iMentorCount = 4;
response.PCLoadData2CL.iMapNum = 0;
response.PCLoadData2CL.iX = plr.x;
response.PCLoadData2CL.iY = plr.y;
response.PCLoadData2CL.iZ = plr.z;
response.PCLoadData2CL.iActiveNanoSlotNum = -1;
response.PCLoadData2CL.iFatigue = 50;
response.PCLoadData2CL.PCStyle = plr.PCStyle;
response.PCLoadData2CL.PCStyle2 = plr.PCStyle2;
for (int i = 0; i < AEQUIP_COUNT; i++)
response->PCLoadData2CL.aEquip[i] = plr.Equip[i];
response.PCLoadData2CL.aEquip[i] = plr.Equip[i];
// protocol-agnostic sItemBase usage
sItemBase item;
memset(&item, 0, sizeof(sItemBase));
item.iID = 495;
for (int i = 0; i < AINVEN_COUNT; i++) {
switch (i) {
case 6: case 8: case 11: case 13: case 20:
case 24: case 26: case 27: case 28:
plr.Inven[i] = item;
break;
default:
memset(&plr.Inven[i], 0, sizeof(sItemBase));
}
response->PCLoadData2CL.aInven[i] = plr.Inven[i];
}
for (int i = 0; i < AINVEN_COUNT; i++)
response.PCLoadData2CL.aInven[i] = plr.Inven[i];
// don't ask..
for (int i = 1; i < 37; i++) {
response->PCLoadData2CL.aNanoBank[i].iID = i;
response->PCLoadData2CL.aNanoBank[i].iSkillID = 1;
response->PCLoadData2CL.aNanoBank[i].iStamina = 150;
response.PCLoadData2CL.aNanoBank[i].iID = i;
response.PCLoadData2CL.aNanoBank[i].iSkillID = 1;
response.PCLoadData2CL.aNanoBank[i].iStamina = 150;
}
// temporarily not add nanos for nano add test through commands
//response->PCLoadData2CL.aNanoSlots[0] = 1;
//response->PCLoadData2CL.aNanoSlots[1] = 2;
//response->PCLoadData2CL.aNanoSlots[2] = 3;
//response.PCLoadData2CL.aNanoSlots[0] = 1;
//response.PCLoadData2CL.aNanoSlots[1] = 2;
//response.PCLoadData2CL.aNanoSlots[2] = 3;
response->PCLoadData2CL.aQuestFlag[0] = -1;
response.PCLoadData2CL.aQuestFlag[0] = -1;
plr.iID = response->iID;
plr.iID = response.iID;
plr.SerialKey = enter->iEnterSerialKey;
plr.HP = response->PCLoadData2CL.iHP;
plr.HP = response.PCLoadData2CL.iHP;
motd->iType = 1;
U8toU16(settings::MOTDSTRING, (char16_t*)motd->szSystemMsg);
motd.iType = 1;
U8toU16(settings::MOTDSTRING, (char16_t*)motd.szSystemMsg);
sock->setEKey(CNSocketEncryption::createNewKey(response->uiSvrTime, response->iID + 1, response->PCLoadData2CL.iFusionMatter + 1));
sock->setEKey(CNSocketEncryption::createNewKey(response.uiSvrTime, response.iID + 1, response.PCLoadData2CL.iFusionMatter + 1));
sock->setFEKey(plr.FEKey);
sock->setActiveKey(SOCKETKEY_FE); // send all packets using the FE key from now on
sock->sendPacket((void*)&response, P_FE2CL_REP_PC_ENTER_SUCC, sizeof(sP_FE2CL_REP_PC_ENTER_SUCC));
sock->sendPacket(new CNPacketData((void*)response, P_FE2CL_REP_PC_ENTER_SUCC, sizeof(sP_FE2CL_REP_PC_ENTER_SUCC), sock->getFEKey()));
// transmit MOTD after entering the game, so the client hopefully changes modes on time
sock->sendPacket(new CNPacketData((void*)motd, P_FE2CL_PC_MOTD_LOGIN, sizeof(sP_FE2CL_PC_MOTD_LOGIN), sock->getFEKey()));
sock->sendPacket((void*)&motd, P_FE2CL_PC_MOTD_LOGIN, sizeof(sP_FE2CL_PC_MOTD_LOGIN));
addPlayer(sock, plr);
}
@ -243,16 +229,16 @@ void PlayerManager::loadPlayer(CNSocket* sock, CNPacketData* data) {
return; // ignore the malformed packet
sP_CL2FE_REQ_PC_LOADING_COMPLETE* complete = (sP_CL2FE_REQ_PC_LOADING_COMPLETE*)data->buf;
sP_FE2CL_REP_PC_LOADING_COMPLETE_SUCC* response = (sP_FE2CL_REP_PC_LOADING_COMPLETE_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_PC_LOADING_COMPLETE_SUCC));
sP_FE2CL_REP_PC_LOADING_COMPLETE_SUCC response;
DEBUGLOG(
std::cout << "P_CL2FE_REQ_PC_LOADING_COMPLETE:" << std::endl;
std::cout << "\tPC_ID: " << complete->iPC_ID << std::endl;
)
response->iPC_ID = complete->iPC_ID;
response.iPC_ID = complete->iPC_ID;
sock->sendPacket(new CNPacketData((void*)response, P_FE2CL_REP_PC_LOADING_COMPLETE_SUCC, sizeof(sP_FE2CL_REP_PC_LOADING_COMPLETE_SUCC), sock->getFEKey()));
sock->sendPacket((void*)&response, P_FE2CL_REP_PC_LOADING_COMPLETE_SUCC, sizeof(sP_FE2CL_REP_PC_LOADING_COMPLETE_SUCC));
}
void PlayerManager::movePlayer(CNSocket* sock, CNPacketData* data) {
@ -265,25 +251,25 @@ void PlayerManager::movePlayer(CNSocket* sock, CNPacketData* data) {
players[sock].plr.angle = moveData->iAngle;
uint64_t tm = getTime();
sP_FE2CL_PC_MOVE moveResponse;
moveResponse.iID = players[sock].plr.iID;
moveResponse.cKeyValue = moveData->cKeyValue;
moveResponse.iX = moveData->iX;
moveResponse.iY = moveData->iY;
moveResponse.iZ = moveData->iZ;
moveResponse.iAngle = moveData->iAngle;
moveResponse.fVX = moveData->fVX;
moveResponse.fVY = moveData->fVY;
moveResponse.fVZ = moveData->fVZ;
moveResponse.iSpeed = moveData->iSpeed;
moveResponse.iCliTime = moveData->iCliTime; // maybe don't send this??? seems unneeded...
moveResponse.iSvrTime = tm;
for (CNSocket* otherSock : players[sock].viewable) {
sP_FE2CL_PC_MOVE* moveResponse = (sP_FE2CL_PC_MOVE*)xmalloc(sizeof(sP_FE2CL_PC_MOVE));
moveResponse->iID = players[sock].plr.iID;
moveResponse->cKeyValue = moveData->cKeyValue;
moveResponse->iX = moveData->iX;
moveResponse->iY = moveData->iY;
moveResponse->iZ = moveData->iZ;
moveResponse->iAngle = moveData->iAngle;
moveResponse->fVX = moveData->fVX;
moveResponse->fVY = moveData->fVY;
moveResponse->fVZ = moveData->fVZ;
moveResponse->iSpeed = moveData->iSpeed;
moveResponse->iCliTime = moveData->iCliTime; // maybe don't send this??? seems unneeded...
moveResponse->iSvrTime = tm;
otherSock->sendPacket(new CNPacketData((void*)moveResponse, P_FE2CL_PC_MOVE, sizeof(sP_FE2CL_PC_MOVE), otherSock->getFEKey()));
otherSock->sendPacket((void*)&moveResponse, P_FE2CL_PC_MOVE, sizeof(sP_FE2CL_PC_MOVE));
}
}
@ -296,19 +282,19 @@ void PlayerManager::stopPlayer(CNSocket* sock, CNPacketData* data) {
uint64_t tm = getTime();
sP_FE2CL_PC_STOP stopResponse;
stopResponse.iID = players[sock].plr.iID;
stopResponse.iX = stopData->iX;
stopResponse.iY = stopData->iY;
stopResponse.iZ = stopData->iZ;
stopResponse.iCliTime = stopData->iCliTime; // maybe don't send this??? seems unneeded...
stopResponse.iSvrTime = tm;
for (CNSocket* otherSock : players[sock].viewable) {
sP_FE2CL_PC_STOP* stopResponse = (sP_FE2CL_PC_STOP*)xmalloc(sizeof(sP_FE2CL_PC_STOP));
stopResponse->iID = players[sock].plr.iID;
stopResponse->iX = stopData->iX;
stopResponse->iY = stopData->iY;
stopResponse->iZ = stopData->iZ;
stopResponse->iCliTime = stopData->iCliTime; // maybe don't send this??? seems unneeded...
stopResponse->iSvrTime = tm;
otherSock->sendPacket(new CNPacketData((void*)stopResponse, P_FE2CL_PC_STOP, sizeof(sP_FE2CL_PC_STOP), otherSock->getFEKey()));
otherSock->sendPacket((void*)&stopResponse, P_FE2CL_PC_STOP, sizeof(sP_FE2CL_PC_STOP));
}
}
@ -321,25 +307,25 @@ void PlayerManager::jumpPlayer(CNSocket* sock, CNPacketData* data) {
uint64_t tm = getTime();
sP_FE2CL_PC_JUMP jumpResponse;
jumpResponse.iID = players[sock].plr.iID;
jumpResponse.cKeyValue = jumpData->cKeyValue;
jumpResponse.iX = jumpData->iX;
jumpResponse.iY = jumpData->iY;
jumpResponse.iZ = jumpData->iZ;
jumpResponse.iAngle = jumpData->iAngle;
jumpResponse.iVX = jumpData->iVX;
jumpResponse.iVY = jumpData->iVY;
jumpResponse.iVZ = jumpData->iVZ;
jumpResponse.iSpeed = jumpData->iSpeed;
jumpResponse.iCliTime = jumpData->iCliTime; // maybe don't send this??? seems unneeded...
jumpResponse.iSvrTime = tm;
for (CNSocket* otherSock : players[sock].viewable) {
sP_FE2CL_PC_JUMP* jumpResponse = (sP_FE2CL_PC_JUMP*)xmalloc(sizeof(sP_FE2CL_PC_JUMP));
jumpResponse->iID = players[sock].plr.iID;
jumpResponse->cKeyValue = jumpData->cKeyValue;
jumpResponse->iX = jumpData->iX;
jumpResponse->iY = jumpData->iY;
jumpResponse->iZ = jumpData->iZ;
jumpResponse->iAngle = jumpData->iAngle;
jumpResponse->iVX = jumpData->iVX;
jumpResponse->iVY = jumpData->iVY;
jumpResponse->iVZ = jumpData->iVZ;
jumpResponse->iSpeed = jumpData->iSpeed;
jumpResponse->iCliTime = jumpData->iCliTime; // maybe don't send this??? seems unneeded...
jumpResponse->iSvrTime = tm;
otherSock->sendPacket(new CNPacketData((void*)jumpResponse, P_FE2CL_PC_JUMP, sizeof(sP_FE2CL_PC_JUMP), otherSock->getFEKey()));
otherSock->sendPacket((void*)&jumpResponse, P_FE2CL_PC_JUMP, sizeof(sP_FE2CL_PC_JUMP));
}
}
@ -352,23 +338,23 @@ void PlayerManager::jumppadPlayer(CNSocket* sock, CNPacketData* data) {
uint64_t tm = getTime();
sP_FE2CL_PC_JUMPPAD jumppadResponse;
jumppadResponse.iPC_ID = players[sock].plr.iID;
jumppadResponse.cKeyValue = jumppadData->cKeyValue;
jumppadResponse.iX = jumppadData->iX;
jumppadResponse.iY = jumppadData->iY;
jumppadResponse.iZ = jumppadData->iZ;
jumppadResponse.iVX = jumppadData->iVX;
jumppadResponse.iVY = jumppadData->iVY;
jumppadResponse.iVZ = jumppadData->iVZ;
jumppadResponse.iCliTime = jumppadData->iCliTime;
jumppadResponse.iSvrTime = tm;
for (CNSocket* otherSock : players[sock].viewable) {
sP_FE2CL_PC_JUMPPAD* jumppadResponse = (sP_FE2CL_PC_JUMPPAD*)xmalloc(sizeof(sP_FE2CL_PC_JUMPPAD));
jumppadResponse->iPC_ID = players[sock].plr.iID;
jumppadResponse->cKeyValue = jumppadData->cKeyValue;
jumppadResponse->iX = jumppadData->iX;
jumppadResponse->iY = jumppadData->iY;
jumppadResponse->iZ = jumppadData->iZ;
jumppadResponse->iVX = jumppadData->iVX;
jumppadResponse->iVY = jumppadData->iVY;
jumppadResponse->iVZ = jumppadData->iVZ;
jumppadResponse->iCliTime = jumppadData->iCliTime;
jumppadResponse->iSvrTime = tm;
otherSock->sendPacket(new CNPacketData((void*)jumppadResponse, P_FE2CL_PC_JUMPPAD, sizeof(sP_FE2CL_PC_JUMPPAD), otherSock->getFEKey()));
otherSock->sendPacket((void*)&jumppadResponse, P_FE2CL_PC_JUMPPAD, sizeof(sP_FE2CL_PC_JUMPPAD));
}
}
@ -381,24 +367,24 @@ void PlayerManager::launchPlayer(CNSocket* sock, CNPacketData* data) {
uint64_t tm = getTime();
sP_FE2CL_PC_LAUNCHER launchResponse;
launchResponse.iPC_ID = players[sock].plr.iID;
launchResponse.iX = launchData->iX;
launchResponse.iY = launchData->iY;
launchResponse.iZ = launchData->iZ;
launchResponse.iVX = launchData->iVX;
launchResponse.iVY = launchData->iVY;
launchResponse.iVZ = launchData->iVZ;
launchResponse.iSpeed = launchData->iSpeed;
launchResponse.iAngle = launchData->iAngle;
launchResponse.iCliTime = launchData->iCliTime;
launchResponse.iSvrTime = tm;
for (CNSocket* otherSock : players[sock].viewable) {
sP_FE2CL_PC_LAUNCHER* launchResponse = (sP_FE2CL_PC_LAUNCHER*)xmalloc(sizeof(sP_FE2CL_PC_LAUNCHER));
launchResponse->iPC_ID = players[sock].plr.iID;
launchResponse->iX = launchData->iX;
launchResponse->iY = launchData->iY;
launchResponse->iZ = launchData->iZ;
launchResponse->iVX = launchData->iVX;
launchResponse->iVY = launchData->iVY;
launchResponse->iVZ = launchData->iVZ;
launchResponse->iSpeed = launchData->iSpeed;
launchResponse->iAngle = launchData->iAngle;
launchResponse->iCliTime = launchData->iCliTime;
launchResponse->iSvrTime = tm;
otherSock->sendPacket(new CNPacketData((void*)launchResponse, P_FE2CL_PC_LAUNCHER, sizeof(sP_FE2CL_PC_LAUNCHER), otherSock->getFEKey()));
otherSock->sendPacket((void*)&launchResponse, P_FE2CL_PC_LAUNCHER, sizeof(sP_FE2CL_PC_LAUNCHER));
}
}
@ -411,32 +397,31 @@ void PlayerManager::ziplinePlayer(CNSocket* sock, CNPacketData* data) {
uint64_t tm = getTime();
sP_FE2CL_PC_ZIPLINE ziplineResponse;
ziplineResponse.iPC_ID = players[sock].plr.iID;
ziplineResponse.iCliTime = ziplineData->iCliTime;
ziplineResponse.iSvrTime = tm;
ziplineResponse.iX = ziplineData->iX;
ziplineResponse.iY = ziplineData->iY;
ziplineResponse.iZ = ziplineData->iZ;
ziplineResponse.fVX = ziplineData->fVX;
ziplineResponse.fVY = ziplineData->fVY;
ziplineResponse.fVZ = ziplineData->fVZ;
ziplineResponse.fMovDistance = ziplineData->fMovDistance;
ziplineResponse.fMaxDistance = ziplineData->fMaxDistance;
ziplineResponse.fDummy = ziplineData->fDummy; //wtf is this for?
ziplineResponse.iStX = ziplineData->iStX;
ziplineResponse.iStY = ziplineData->iStY;
ziplineResponse.iStZ = ziplineData->iStZ;
ziplineResponse.bDown = ziplineData->bDown;
ziplineResponse.iSpeed = ziplineData->iSpeed;
ziplineResponse.iAngle = ziplineData->iAngle;
ziplineResponse.iRollMax = ziplineData->iRollMax;
ziplineResponse.iRoll = ziplineData->iRoll;
for (CNSocket* otherSock : players[sock].viewable) {
sP_FE2CL_PC_ZIPLINE* ziplineResponse = (sP_FE2CL_PC_ZIPLINE*)xmalloc(sizeof(sP_FE2CL_PC_ZIPLINE));
ziplineResponse->iPC_ID = players[sock].plr.iID;
ziplineResponse->iCliTime = ziplineData->iCliTime;
ziplineResponse->iSvrTime = tm;
ziplineResponse->iX = ziplineData->iX;
ziplineResponse->iY = ziplineData->iY;
ziplineResponse->iZ = ziplineData->iZ;
ziplineResponse->fVX = ziplineData->fVX;
ziplineResponse->fVY = ziplineData->fVY;
ziplineResponse->fVZ = ziplineData->fVZ;
ziplineResponse->fMovDistance = ziplineData->fMovDistance;
ziplineResponse->fMaxDistance = ziplineData->fMaxDistance;
ziplineResponse->fDummy = ziplineData->fDummy; //wtf is this for?
ziplineResponse->iStX = ziplineData->iStX;
ziplineResponse->iStY = ziplineData->iStY;
ziplineResponse->iStZ = ziplineData->iStZ;
ziplineResponse->bDown = ziplineData->bDown;
ziplineResponse->iSpeed = ziplineData->iSpeed;
ziplineResponse->iAngle = ziplineData->iAngle;
ziplineResponse->iRollMax = ziplineData->iRollMax;
ziplineResponse->iRoll = ziplineData->iRoll;
otherSock->sendPacket(new CNPacketData((void*)ziplineResponse, P_FE2CL_PC_ZIPLINE, sizeof(sP_FE2CL_PC_ZIPLINE), otherSock->getFEKey()));
otherSock->sendPacket((void*)&ziplineResponse, P_FE2CL_PC_ZIPLINE, sizeof(sP_FE2CL_PC_ZIPLINE));
}
}
@ -449,29 +434,28 @@ void PlayerManager::movePlatformPlayer(CNSocket* sock, CNPacketData* data) {
uint64_t tm = getTime();
sP_FE2CL_PC_MOVEPLATFORM platResponse;
platResponse.iPC_ID = players[sock].plr.iID;
platResponse.iCliTime = platformData->iCliTime;
platResponse.iSvrTime = tm;
platResponse.iX = platformData->iX;
platResponse.iY = platformData->iY;
platResponse.iZ = platformData->iZ;
platResponse.iAngle = platformData->iAngle;
platResponse.fVX = platformData->fVX;
platResponse.fVY = platformData->fVY;
platResponse.fVZ = platformData->fVZ;
platResponse.iLcX = platformData->iLcX;
platResponse.iLcY = platformData->iLcY;
platResponse.iLcZ = platformData->iLcZ;
platResponse.iSpeed = platformData->iSpeed;
platResponse.bDown = platformData->bDown;
platResponse.cKeyValue = platformData->cKeyValue;
platResponse.iPlatformID = platformData->iPlatformID;
for (CNSocket* otherSock : players[sock].viewable) {
sP_FE2CL_PC_MOVEPLATFORM* platResponse = (sP_FE2CL_PC_MOVEPLATFORM*)xmalloc(sizeof(sP_FE2CL_PC_MOVEPLATFORM));
platResponse->iPC_ID = players[sock].plr.iID;
platResponse->iCliTime = platformData->iCliTime;
platResponse->iSvrTime = tm;
platResponse->iX = platformData->iX;
platResponse->iY = platformData->iY;
platResponse->iZ = platformData->iZ;
platResponse->iAngle = platformData->iAngle;
platResponse->fVX = platformData->fVX;
platResponse->fVY = platformData->fVY;
platResponse->fVZ = platformData->fVZ;
platResponse->iLcX = platformData->iLcX;
platResponse->iLcY = platformData->iLcY;
platResponse->iLcZ = platformData->iLcZ;
platResponse->iSpeed = platformData->iSpeed;
platResponse->bDown = platformData->bDown;
platResponse->cKeyValue = platformData->cKeyValue;
platResponse->iPlatformID = platformData->iPlatformID;
otherSock->sendPacket(new CNPacketData((void*)platResponse, P_FE2CL_PC_MOVEPLATFORM, sizeof(sP_FE2CL_PC_MOVEPLATFORM), otherSock->getFEKey()));
otherSock->sendPacket((void*)&platResponse, P_FE2CL_PC_MOVEPLATFORM, sizeof(sP_FE2CL_PC_MOVEPLATFORM));
}
}
@ -484,25 +468,24 @@ void PlayerManager::moveSlopePlayer(CNSocket* sock, CNPacketData* data) {
uint64_t tm = getTime();
sP_FE2CL_PC_SLOPE slopeResponse;
slopeResponse.iPC_ID = players[sock].plr.iID;
slopeResponse.iCliTime = slopeData->iCliTime;
slopeResponse.iSvrTime = tm;
slopeResponse.iX = slopeData->iX;
slopeResponse.iY = slopeData->iY;
slopeResponse.iZ = slopeData->iZ;
slopeResponse.iAngle = slopeData->iAngle;
slopeResponse.fVX = slopeData->fVX;
slopeResponse.fVY = slopeData->fVY;
slopeResponse.fVZ = slopeData->fVZ;
slopeResponse.iSpeed = slopeData->iSpeed;
slopeResponse.cKeyValue = slopeData->cKeyValue;
slopeResponse.iSlopeID = slopeData->iSlopeID;
for (CNSocket* otherSock : players[sock].viewable) {
sP_FE2CL_PC_SLOPE* slopeResponse = (sP_FE2CL_PC_SLOPE*)xmalloc(sizeof(sP_FE2CL_PC_SLOPE));
slopeResponse->iPC_ID = players[sock].plr.iID;
slopeResponse->iCliTime = slopeData->iCliTime;
slopeResponse->iSvrTime = tm;
slopeResponse->iX = slopeData->iX;
slopeResponse->iY = slopeData->iY;
slopeResponse->iZ = slopeData->iZ;
slopeResponse->iAngle = slopeData->iAngle;
slopeResponse->fVX = slopeData->fVX;
slopeResponse->fVY = slopeData->fVY;
slopeResponse->fVZ = slopeData->fVZ;
slopeResponse->iSpeed = slopeData->iSpeed;
slopeResponse->cKeyValue = slopeData->cKeyValue;
slopeResponse->iSlopeID = slopeData->iSlopeID;
otherSock->sendPacket(new CNPacketData((void*)slopeResponse, P_FE2CL_PC_SLOPE, sizeof(sP_FE2CL_PC_SLOPE), otherSock->getFEKey()));
otherSock->sendPacket((void*)&slopeResponse, P_FE2CL_PC_SLOPE, sizeof(sP_FE2CL_PC_SLOPE));
}
}
@ -511,7 +494,7 @@ void PlayerManager::gotoPlayer(CNSocket* sock, CNPacketData* data) {
return; // ignore the malformed packet
sP_CL2FE_REQ_PC_GOTO* gotoData = (sP_CL2FE_REQ_PC_GOTO*)data->buf;
sP_FE2CL_REP_PC_GOTO_SUCC* response = (sP_FE2CL_REP_PC_GOTO_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_PC_GOTO_SUCC));
sP_FE2CL_REP_PC_GOTO_SUCC response;
DEBUGLOG(
std::cout << "P_CL2FE_REQ_PC_GOTO:" << std::endl;
@ -520,11 +503,11 @@ void PlayerManager::gotoPlayer(CNSocket* sock, CNPacketData* data) {
std::cout << "\tZ: " << gotoData->iToZ << std::endl;
)
response->iX = gotoData->iToX;
response->iY = gotoData->iToY;
response->iZ = gotoData->iToZ;
response.iX = gotoData->iToX;
response.iY = gotoData->iToY;
response.iZ = gotoData->iToZ;
sock->sendPacket(new CNPacketData((void*)response, P_FE2CL_REP_PC_GOTO_SUCC, sizeof(sP_FE2CL_REP_PC_GOTO_SUCC), sock->getFEKey()));
sock->sendPacket((void*)&response, P_FE2CL_REP_PC_GOTO_SUCC, sizeof(sP_FE2CL_REP_PC_GOTO_SUCC));
}
void PlayerManager::setSpecialPlayer(CNSocket* sock, CNPacketData* data) {
@ -532,7 +515,7 @@ void PlayerManager::setSpecialPlayer(CNSocket* sock, CNPacketData* data) {
return; // ignore the malformed packet
sP_CL2FE_GM_REQ_PC_SET_VALUE* setData = (sP_CL2FE_GM_REQ_PC_SET_VALUE*)data->buf;
sP_FE2CL_GM_REP_PC_SET_VALUE* response = (sP_FE2CL_GM_REP_PC_SET_VALUE*)xmalloc(sizeof(sP_FE2CL_GM_REP_PC_SET_VALUE));
sP_FE2CL_GM_REP_PC_SET_VALUE response;
DEBUGLOG(
std::cout << "P_CL2FE_GM_REQ_PC_SET_VALUE:" << std::endl;
@ -541,11 +524,11 @@ void PlayerManager::setSpecialPlayer(CNSocket* sock, CNPacketData* data) {
std::cout << "\tSetValue: " << setData->iSetValue << std::endl;
)
response->iPC_ID = setData->iPC_ID;
response->iSetValue = setData->iSetValue;
response->iSetValueType = setData->iSetValueType;
response.iPC_ID = setData->iPC_ID;
response.iSetValue = setData->iSetValue;
response.iSetValueType = setData->iSetValueType;
sock->sendPacket(new CNPacketData((void*)response, P_FE2CL_GM_REP_PC_SET_VALUE, sizeof(sP_FE2CL_GM_REP_PC_SET_VALUE), sock->getFEKey()));
sock->sendPacket((void*)&response, P_FE2CL_GM_REP_PC_SET_VALUE, sizeof(sP_FE2CL_GM_REP_PC_SET_VALUE));
}
void PlayerManager::heartbeatPlayer(CNSocket* sock, CNPacketData* data) {
@ -557,12 +540,12 @@ void PlayerManager::exitGame(CNSocket* sock, CNPacketData* data) {
return;
sP_CL2FE_REQ_PC_EXIT* exitData = (sP_CL2FE_REQ_PC_EXIT*)data->buf;
sP_FE2CL_REP_PC_EXIT_SUCC* response = (sP_FE2CL_REP_PC_EXIT_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_PC_EXIT_SUCC));
sP_FE2CL_REP_PC_EXIT_SUCC response;
response->iID = exitData->iID;
response->iExitCode = 1;
response.iID = exitData->iID;
response.iExitCode = 1;
sock->sendPacket(new CNPacketData((void*)response, P_FE2CL_REP_PC_EXIT_SUCC, sizeof(sP_FE2CL_REP_PC_EXIT_SUCC), sock->getFEKey()));
sock->sendPacket((void*)&response, P_FE2CL_REP_PC_EXIT_SUCC, sizeof(sP_FE2CL_REP_PC_EXIT_SUCC));
}
void PlayerManager::updatePlayer(CNSocket* key, Player plr) {