From c5efbceca3404024cd9a7157d179937140d27ce4 Mon Sep 17 00:00:00 2001 From: CPunch Date: Fri, 21 Aug 2020 19:33:42 -0500 Subject: [PATCH 1/3] added sanity checks for sendPacket() --- src/CNProtocol.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/CNProtocol.cpp b/src/CNProtocol.cpp index d41e007..ad724d6 100644 --- a/src/CNProtocol.cpp +++ b/src/CNProtocol.cpp @@ -76,8 +76,12 @@ bool CNSocket::sendData(uint8_t* data, int size) { while (sentBytes < size) { int sent = send(sock, (buffer_t*)(data + sentBytes), size - sentBytes, 0); // no flags defined - if (SOCKETERROR(sent)) + if (SOCKETERROR(sent)) { + if (errno == 11) + continue; // try again + std::cout << "[FATAL] SOCKET ERROR: " << errno << std::endl; return false; // error occured while sending bytes + } sentBytes += sent; } @@ -116,6 +120,11 @@ void CNSocket::kill() { } void CNSocket::sendPacket(CNPacketData* pak) { + if (!alive) { + delete pak; + return; + } + int tmpSize = pak->size + sizeof(uint32_t); uint8_t* tmpBuf = (uint8_t*)xmalloc(tmpSize); @@ -127,10 +136,12 @@ void CNSocket::sendPacket(CNPacketData* pak) { CNSocketEncryption::encryptData((uint8_t*)tmpBuf, (uint8_t*)(&pak->key), tmpSize); // send packet size - sendData((uint8_t*)&tmpSize, sizeof(uint32_t)); + if (!sendData((uint8_t*)&tmpSize, sizeof(uint32_t))) + kill(); // send packet data! - sendData(tmpBuf, tmpSize); + if (alive && !sendData(tmpBuf, tmpSize)) + kill(); delete pak; free(tmpBuf); // free tmp buffer From 786ee5f4f49f80058b745acd98d6cb42f328e0a9 Mon Sep 17 00:00:00 2001 From: FinnHornhoover <30576665+FinnHornhoover@users.noreply.github.com> Date: Sat, 22 Aug 2020 03:37:59 +0300 Subject: [PATCH 2/3] fixed PROTOCOL_VERSION not being defined (#23) --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9614d43..be6ed7a 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ PROTOCOL_VERSION?=104 # Windows-specific WIN_CXX=x86_64-w64-mingw32-g++ -WIN_CXXFLAGS=-std=c++17 -O3 #-g3 -fsanitize=address +WIN_CXXFLAGS=-std=c++17 -O3 -DPROTOCOL_VERSION=$(PROTOCOL_VERSION) #-g3 -fsanitize=address WIN_LDFLAGS=-static -lws2_32 -lwsock32 WIN_SERVER=bin/winfusion.exe From ab6df26f9212f4d05613e388217efc9148787979 Mon Sep 17 00:00:00 2001 From: JadeShrineMaiden <69916714+JadeShrineMaiden@users.noreply.github.com> Date: Sat, 22 Aug 2020 01:38:10 +0100 Subject: [PATCH 3/3] Disabled GM mode (#22) Temporarily disabled, players can now use item commands without GM mode. --- src/CNLoginServer.cpp | 17 +++++++++-------- src/ItemManager.cpp | 7 ++++--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/CNLoginServer.cpp b/src/CNLoginServer.cpp index 60788bd..0def10e 100644 --- a/src/CNLoginServer.cpp +++ b/src/CNLoginServer.cpp @@ -192,14 +192,15 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { int64_t UID = character->PCStyle.iPC_UID; - bool BecomeGM; + // commented and disabled for now + //bool BecomeGM; - if (U16toU8(character->PCStyle.szFirstName) == settings::GMPASS) { - BecomeGM = true; - U8toU16("GM",character->PCStyle.szFirstName); - } else { - BecomeGM = false; - } + //if (U16toU8(character->PCStyle.szFirstName) == settings::GMPASS) { + // BecomeGM = true; + // U8toU16("GM",character->PCStyle.szFirstName); + //} else { + // BecomeGM = false; + //} character->PCStyle.iNameCheck = 1; response->sPC_Style = character->PCStyle; @@ -225,7 +226,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { loginSessions[sock].characters[UID].Equip[2].iType = 2; loginSessions[sock].characters[UID].Equip[3].iID = character->sOn_Item.iEquipFootID; // foot! loginSessions[sock].characters[UID].Equip[3].iType = 3; - loginSessions[sock].characters[UID].IsGM = BecomeGM; + 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())); break; diff --git a/src/ItemManager.cpp b/src/ItemManager.cpp index 09119c2..0525e1f 100644 --- a/src/ItemManager.cpp +++ b/src/ItemManager.cpp @@ -98,10 +98,11 @@ void ItemManager::itemGMGiveHandler(CNSocket* sock, CNPacketData* data) { sP_CL2FE_REQ_PC_GIVE_ITEM* itemreq = (sP_CL2FE_REQ_PC_GIVE_ITEM*)data->buf; PlayerView& plr = PlayerManager::players[sock]; - if (!plr.plr.IsGM) { + // Commented and disabled for future use + //if (!plr.plr.IsGM) { // TODO: send fail packet - return; - } + // return; + //} if (itemreq->eIL == 2) { // Quest item, not a real item, handle this later, stubbed for now