diff --git a/Makefile b/Makefile index 725581d..c37561d 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,11 @@ +GIT_VERSION!=git describe --tags + CC=clang CXX=clang++ # -w suppresses all warnings (the part that's commented out helps me find memory leaks, it ruins performance though!) # If compiling with ASAN, invoke like this: $ LSAN_OPTIONS=suppressions=suppr.txt bin/fusion CFLAGS=-O3 #-g3 -fsanitize=address -CXXFLAGS=-Wall -Wno-unknown-pragmas -std=c++17 -O2 -DPROTOCOL_VERSION=$(PROTOCOL_VERSION) -DGIT_VERSION=\"$(shell git describe --tags)\" #-g3 -fsanitize=address +CXXFLAGS=-Wall -Wno-unknown-pragmas -std=c++17 -O2 -DPROTOCOL_VERSION=$(PROTOCOL_VERSION) -DGIT_VERSION=\"$(GIT_VERSION)\" #-g3 -fsanitize=address LDFLAGS=-lpthread -ldl #-g3 -fsanitize=address # specifies the name of our exectuable SERVER=bin/fusion @@ -18,7 +20,7 @@ WIN_CXX=x86_64-w64-mingw32-g++ WIN_CFLAGS=-O3 #-g3 -fsanitize=address WIN_CXX_VANILLA_MINGW_OPT_DISABLES=-fno-tree-dce -fno-inline-small-functions WIN_CXX_MSYS2_MINGW_OPT_DISABLES=-fno-tree-dce -fno-tree-fre -fno-tree-vrp -fno-ipa-sra -WIN_CXXFLAGS=-D_WIN32_WINNT=0x0601 -Wall -Wno-unknown-pragmas -std=c++17 -O3 $(WIN_CXX_OPT_DISABLES) -DPROTOCOL_VERSION=$(PROTOCOL_VERSION) -DGIT_VERSION=\"$(shell git describe --tags)\" #-g3 -fsanitize=address +WIN_CXXFLAGS=-D_WIN32_WINNT=0x0601 -Wall -Wno-unknown-pragmas -std=c++17 -O3 $(WIN_CXX_OPT_DISABLES) -DPROTOCOL_VERSION=$(PROTOCOL_VERSION) -DGIT_VERSION=\"$(GIT_VERSION)\" #-g3 -fsanitize=address WIN_LDFLAGS=-static -lws2_32 -lwsock32 #-g3 -fsanitize=address WIN_SERVER=bin/winfusion.exe diff --git a/src/CNProtocol.cpp b/src/CNProtocol.cpp index eb97818..69047bb 100644 --- a/src/CNProtocol.cpp +++ b/src/CNProtocol.cpp @@ -313,7 +313,7 @@ void CNServer::start() { int n = poll(fds.data(), fds.size(), 50); if (SOCKETERROR(n)) { std::cout << "[FATAL] poll() returned error" << std::endl; - terminate(); + terminate(0); } oldnfds = fds.size(); @@ -329,7 +329,7 @@ void CNServer::start() { // any sort of error on the listener if (fds[i].revents & ~POLLIN) { std::cout << "[FATAL] Error on listener socket" << std::endl; - terminate(); + terminate(0); } SOCKET newConnectionSocket = accept(sock, (struct sockaddr *)&address, (socklen_t*)&addressSize); diff --git a/src/CNStructs.hpp b/src/CNStructs.hpp index c3eb1fc..7f8eb85 100644 --- a/src/CNStructs.hpp +++ b/src/CNStructs.hpp @@ -41,7 +41,7 @@ std::string U16toU8(char16_t* src); size_t U8toU16(std::string src, char16_t* des, size_t max); // returns number of char16_t that was written at des time_t getTime(); time_t getTimestamp(); -void terminate(int unused=0); +void terminate(int); // The PROTOCOL_VERSION definition is defined by the build system. #if !defined(PROTOCOL_VERSION) diff --git a/src/Monitor.cpp b/src/Monitor.cpp index f9e4e52..941fc7a 100644 --- a/src/Monitor.cpp +++ b/src/Monitor.cpp @@ -123,7 +123,7 @@ bool Monitor::acceptConnection(SOCKET fd, uint16_t revents) { if (revents & ~POLLIN) { std::cout << "[FATAL] Error on monitor listener?" << std::endl; - terminate(); + terminate(0); } int sock = accept(listener, (struct sockaddr*)&address, &len); diff --git a/src/PlayerManager.cpp b/src/PlayerManager.cpp index 92a23b2..deece88 100644 --- a/src/PlayerManager.cpp +++ b/src/PlayerManager.cpp @@ -720,7 +720,7 @@ void PlayerManager::revivePlayer(CNSocket* sock, CNPacketData* data) { int nanoID = plr->equippedNanos[i]; // halve nano health if respawning // all revives not 3-5 are normal respawns. - if (reviveData->iRegenType < 3 && reviveData->iRegenType > 5) + if (reviveData->iRegenType < 3 || reviveData->iRegenType > 5) plr->Nanos[nanoID].iStamina = 75; // max is 150, so 75 is half response.PCRegenData.Nanos[i] = plr->Nanos[nanoID]; if (plr->activeNano == nanoID) diff --git a/src/TableData.cpp b/src/TableData.cpp index f58c0cf..41af05c 100644 --- a/src/TableData.cpp +++ b/src/TableData.cpp @@ -54,7 +54,7 @@ void TableData::init() { } catch (const std::exception& err) { std::cerr << "[FATAL] Malformed NPCs.json file! Reason:" << err.what() << std::endl; - terminate(); + exit(1); } // load everything else from xdttable @@ -230,7 +230,7 @@ void TableData::init() { } catch (const std::exception& err) { std::cerr << "[FATAL] Malformed xdt.json file! Reason:" << err.what() << std::endl; - terminate(); + exit(1); } // load temporary mob dump @@ -303,7 +303,7 @@ void TableData::init() { } catch (const std::exception& err) { std::cerr << "[FATAL] Malformed mobs.json file! Reason:" << err.what() << std::endl; - terminate(); + exit(1); } loadDrops(); @@ -373,7 +373,7 @@ void TableData::loadPaths(int* nextId) { if (firstPoint["iX"] != pair.second->spawnX || firstPoint["iY"] != pair.second->spawnY) { std::cout << "[FATAL] The first point of the route for mob " << pair.first << " (type " << pair.second->appearanceData.iNPCType << ") does not correspond with its spawn point." << std::endl; - terminate(); + exit(1); } constructPathNPC(npcPath, pair.first); @@ -386,7 +386,7 @@ void TableData::loadPaths(int* nextId) { } catch (const std::exception& err) { std::cerr << "[FATAL] Malformed paths.json file! Reason:" << err.what() << std::endl; - terminate(); + exit(1); } } @@ -497,7 +497,7 @@ void TableData::loadDrops() { } catch (const std::exception& err) { std::cerr << "[FATAL] Malformed drops.json file! Reason:" << err.what() << std::endl; - terminate(); + exit(1); } } @@ -539,7 +539,7 @@ void TableData::loadEggs(int32_t* nextId) { } catch (const std::exception& err) { std::cerr << "[FATAL] Malformed eggs.json file! Reason:" << err.what() << std::endl; - terminate(); + exit(1); } } @@ -763,7 +763,7 @@ void TableData::loadGruntwork(int32_t *nextId) { } catch (const std::exception& err) { std::cerr << "[FATAL] Malformed gruntwork.json file! Reason:" << err.what() << std::endl; - terminate(); + exit(1); } } diff --git a/src/main.cpp b/src/main.cpp index 35bc13b..aabfee3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,10 +46,8 @@ void startShard(CNShardServer* server) { void terminate(int arg) { std::cout << "OpenFusion: terminating." << std::endl; - if (shardServer != nullptr && shardThread != nullptr) { + if (shardServer != nullptr && shardThread != nullptr) shardServer->kill(); - shardThread->join(); - } exit(0); } @@ -111,7 +109,7 @@ int main() { case 3: std::cout << "[INFO] Event active. Have a very hoppy Easter!" << std::endl; break; default: std::cout << "[FATAL] Unknown event set in config file." << std::endl; - terminate(); + exit(1); /* not reached */ }