added INITSTRUCT to zero-out data

This commit is contained in:
CPunch 2020-08-22 19:26:18 -05:00
parent 94b0dc724e
commit 88953541ef
9 changed files with 44 additions and 41 deletions

View File

@ -1,5 +1,5 @@
# should the server print every packet it receives?
verbose=false
verbose=true
# Login Server configuration
[login]
@ -13,7 +13,7 @@ randomcharacters=true
[shard]
port=8002
# you'll want to change this one
ip=127.0.0.1
ip=192.168.1.183
# distance at which other players and NPCs become visible
view=20000
# little message players see when they enter the game

View File

@ -26,7 +26,7 @@ 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 resp;
INITSTRUCT(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
@ -131,7 +131,7 @@ 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 resp;
INITSTRUCT(sP_LS2CL_REP_CHECK_CHAR_NAME_SUCC, resp);
DEBUGLOG(
std::cout << "P_CL2LS_REQ_CHECK_CHAR_NAME:" << std::endl;
@ -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 resp;
INITSTRUCT(sP_LS2CL_REP_SAVE_CHAR_NAME_SUCC, resp);
DEBUGLOG(
std::cout << "P_CL2LS_REQ_SAVE_CHAR_NAME:" << std::endl;
@ -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 resp;
INITSTRUCT(sP_LS2CL_REP_CHAR_CREATE_SUCC, resp);
DEBUGLOG(
std::cout << "P_CL2LS_REQ_CHAR_CREATE:" << std::endl;
@ -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 resp;
INITSTRUCT(sP_LS2CL_REP_CHAR_SELECT_SUCC, resp);
DEBUGLOG(
std::cout << "P_CL2LS_REQ_CHAR_SELECT:" << std::endl;
@ -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 resp;
INITSTRUCT(sP_LS2CL_REP_SHARD_SELECT_SUCC, resp);
DEBUGLOG(
std::cout << "P_CL2LS_REQ_SHARD_SELECT:" << std::endl;

View File

@ -52,7 +52,7 @@ void CNShardServer::onTimer() {
}
// passed the heartbeat, send another
sP_FE2CL_REQ_LIVE_CHECK data;
INITSTRUCT(sP_FE2CL_REQ_LIVE_CHECK, data);
pair.first->sendPacket((void*)&data, P_FE2CL_REQ_LIVE_CHECK, sizeof(sP_FE2CL_REQ_LIVE_CHECK));
}
}

View File

@ -25,6 +25,10 @@
#include <locale>
#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.
#define INITSTRUCT(T, x) T x; \
memset(&x, 0, sizeof(T));
// TODO: rewrite U16toU8 & U8toU16 to not use codecvt
std::string U16toU8(char16_t* src);

View File

@ -16,7 +16,7 @@ void ChatManager::chatHandler(CNSocket* sock, CNPacketData* data) {
PlayerView plr = PlayerManager::players[sock];
// send to client
sP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC resp;
INITSTRUCT(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;
@ -35,7 +35,7 @@ void ChatManager::menuChatHandler(CNSocket* sock, CNPacketData* data) {
PlayerView plr = PlayerManager::players[sock];
// send to client
sP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC resp;
INITSTRUCT(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;
@ -56,7 +56,7 @@ void ChatManager::emoteHandler(CNSocket* sock, CNPacketData* data) {
PlayerView plr = PlayerManager::players[sock];
// send to client
sP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT resp;
INITSTRUCT(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));

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;
INITSTRUCT(sP_FE2CL_PC_ITEM_MOVE_SUCC, resp);
PlayerView& plr = PlayerManager::players[sock];
sItemBase fromItem;
@ -46,7 +46,7 @@ void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) {
}
if (itemmove->eFrom == 0 || itemmove->eTo == 0) {
sP_FE2CL_PC_EQUIP_CHANGE equipChange;
INITSTRUCT(sP_FE2CL_PC_EQUIP_CHANGE, equipChange);
equipChange.iPC_ID = plr.plr.iID;
if (itemmove->eFrom == 0) {
@ -78,7 +78,7 @@ 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;
INITSTRUCT(sP_FE2CL_REP_PC_ITEM_DELETE_SUCC, resp);
PlayerView& plr = PlayerManager::players[sock];
@ -110,7 +110,7 @@ void ItemManager::itemGMGiveHandler(CNSocket* sock, CNPacketData* data) {
// Quest item, not a real item, handle this later, stubbed for now
// sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_PC_GIVE_ITEM_FAIL, sizeof(sP_FE2CL_REP_PC_GIVE_ITEM_FAIL), sock->getFEKey()));
} else if (itemreq->eIL == 1) {
sP_FE2CL_REP_PC_GIVE_ITEM_SUCC resp;
INITSTRUCT(sP_FE2CL_REP_PC_GIVE_ITEM_SUCC, resp);
resp.eIL = itemreq->eIL;
resp.iSlotNum = itemreq->iSlotNum;

View File

@ -49,7 +49,7 @@ void NPCManager::updatePlayerNPCS(CNSocket* sock, PlayerView& view) {
}
}
sP_FE2CL_NPC_EXIT exitData;
INITSTRUCT(sP_FE2CL_NPC_EXIT, exitData);
std::list<int32_t>::iterator i = view.viewableNPCs.begin();
while (i != view.viewableNPCs.end()) {
int32_t id = *i;
@ -67,7 +67,7 @@ void NPCManager::updatePlayerNPCS(CNSocket* sock, PlayerView& view) {
++i;
}
sP_FE2CL_NPC_ENTER enterData;
INITSTRUCT(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

View File

@ -17,7 +17,7 @@ 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;
INITSTRUCT(sP_FE2CL_REP_NANO_EQUIP_SUCC, resp);
resp.iNanoID = nano->iNanoID;
resp.iNanoSlotNum = nano->iNanoSlotNum;
@ -30,7 +30,7 @@ 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;
INITSTRUCT(sP_FE2CL_REP_NANO_UNEQUIP_SUCC, resp);
resp.iNanoSlotNum = nano->iNanoSlotNum;
@ -61,7 +61,7 @@ void NanoManager::nanoSummonHandler(CNSocket* sock, CNPacketData* data) {
PlayerView plr = PlayerManager::players[sock];
// Send to client
sP_FE2CL_REP_NANO_ACTIVE_SUCC resp;
INITSTRUCT(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));
@ -78,7 +78,7 @@ void NanoManager::nanoSkillUseHandler(CNSocket* sock, CNPacketData* data) {
PlayerView plr = PlayerManager::players[sock];
// Send to client
sP_FE2CL_NANO_SKILL_USE_SUCC resp;
INITSTRUCT(sP_FE2CL_NANO_SKILL_USE_SUCC, resp);
resp.iArg1 = skill->iArg1;
resp.iArg2 = skill->iArg2;
resp.iArg3 = skill->iArg3;
@ -107,7 +107,7 @@ 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;
INITSTRUCT(sP_FE2CL_REP_PC_NANO_CREATE_SUCC, resp);
resp.Nano.iID = nanoId;
resp.Nano.iStamina = 150;
resp.iQuestItemSlotNum = slot;
@ -127,7 +127,7 @@ 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;
INITSTRUCT(sP_FE2CL_REP_NANO_TUNE_SUCC, resp);
resp.iNanoID = nanoId;
resp.iSkillID = skillId;

View File

@ -88,8 +88,7 @@ void PlayerManager::updatePlayerPosition(CNSocket* sock, int X, int Y, int Z) {
}
}
sP_FE2CL_PC_EXIT exitPacket;
INITSTRUCT(sP_FE2CL_PC_EXIT, exitPacket);
std::list<CNSocket*>::iterator i = players[sock].viewable.begin();
while (i != players[sock].viewable.end()) {
CNSocket* otherSock = *i;
@ -110,7 +109,7 @@ void PlayerManager::updatePlayerPosition(CNSocket* sock, int X, int Y, int Z) {
++i;
}
sP_FE2CL_PC_NEW newPlayer;
INITSTRUCT(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
@ -155,8 +154,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_PC_MOTD_LOGIN motd;
INITSTRUCT(sP_FE2CL_REP_PC_ENTER_SUCC, response);
INITSTRUCT(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);
@ -229,7 +228,7 @@ 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;
INITSTRUCT(sP_FE2CL_REP_PC_LOADING_COMPLETE_SUCC, response);
DEBUGLOG(
std::cout << "P_CL2FE_REQ_PC_LOADING_COMPLETE:" << std::endl;
@ -251,7 +250,7 @@ void PlayerManager::movePlayer(CNSocket* sock, CNPacketData* data) {
players[sock].plr.angle = moveData->iAngle;
uint64_t tm = getTime();
sP_FE2CL_PC_MOVE moveResponse;
INITSTRUCT(sP_FE2CL_PC_MOVE, moveResponse);
moveResponse.iID = players[sock].plr.iID;
moveResponse.cKeyValue = moveData->cKeyValue;
@ -282,7 +281,7 @@ void PlayerManager::stopPlayer(CNSocket* sock, CNPacketData* data) {
uint64_t tm = getTime();
sP_FE2CL_PC_STOP stopResponse;
INITSTRUCT(sP_FE2CL_PC_STOP, stopResponse);
stopResponse.iID = players[sock].plr.iID;
@ -307,7 +306,7 @@ void PlayerManager::jumpPlayer(CNSocket* sock, CNPacketData* data) {
uint64_t tm = getTime();
sP_FE2CL_PC_JUMP jumpResponse;
INITSTRUCT(sP_FE2CL_PC_JUMP, jumpResponse);
jumpResponse.iID = players[sock].plr.iID;
jumpResponse.cKeyValue = jumpData->cKeyValue;
@ -338,7 +337,7 @@ void PlayerManager::jumppadPlayer(CNSocket* sock, CNPacketData* data) {
uint64_t tm = getTime();
sP_FE2CL_PC_JUMPPAD jumppadResponse;
INITSTRUCT(sP_FE2CL_PC_JUMPPAD, jumppadResponse);
jumppadResponse.iPC_ID = players[sock].plr.iID;
jumppadResponse.cKeyValue = jumppadData->cKeyValue;
@ -367,7 +366,7 @@ void PlayerManager::launchPlayer(CNSocket* sock, CNPacketData* data) {
uint64_t tm = getTime();
sP_FE2CL_PC_LAUNCHER launchResponse;
INITSTRUCT(sP_FE2CL_PC_LAUNCHER, launchResponse);
launchResponse.iPC_ID = players[sock].plr.iID;
@ -397,7 +396,7 @@ void PlayerManager::ziplinePlayer(CNSocket* sock, CNPacketData* data) {
uint64_t tm = getTime();
sP_FE2CL_PC_ZIPLINE ziplineResponse;
INITSTRUCT(sP_FE2CL_PC_ZIPLINE, ziplineResponse);
ziplineResponse.iPC_ID = players[sock].plr.iID;
ziplineResponse.iCliTime = ziplineData->iCliTime;
@ -434,7 +433,7 @@ void PlayerManager::movePlatformPlayer(CNSocket* sock, CNPacketData* data) {
uint64_t tm = getTime();
sP_FE2CL_PC_MOVEPLATFORM platResponse;
INITSTRUCT(sP_FE2CL_PC_MOVEPLATFORM, platResponse);
platResponse.iPC_ID = players[sock].plr.iID;
platResponse.iCliTime = platformData->iCliTime;
@ -468,7 +467,7 @@ void PlayerManager::moveSlopePlayer(CNSocket* sock, CNPacketData* data) {
uint64_t tm = getTime();
sP_FE2CL_PC_SLOPE slopeResponse;
INITSTRUCT(sP_FE2CL_PC_SLOPE, slopeResponse);
slopeResponse.iPC_ID = players[sock].plr.iID;
slopeResponse.iCliTime = slopeData->iCliTime;
@ -494,7 +493,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;
INITSTRUCT(sP_FE2CL_REP_PC_GOTO_SUCC, response);
DEBUGLOG(
std::cout << "P_CL2FE_REQ_PC_GOTO:" << std::endl;
@ -515,7 +514,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;
INITSTRUCT(sP_FE2CL_GM_REP_PC_SET_VALUE, response);
DEBUGLOG(
std::cout << "P_CL2FE_GM_REQ_PC_SET_VALUE:" << std::endl;
@ -540,7 +539,7 @@ 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;
INITSTRUCT(sP_FE2CL_REP_PC_EXIT_SUCC, response);
response.iID = exitData->iID;
response.iExitCode = 1;