Various bugfixes

* Fixed Nano stamina not being halved on respawn
* Reverted the default argument to terminate() change because MSVC is
undable to disambiguate the function pointer passed to sigaction()
* Fatal errors during init (like in TableData) can just call exit(1)
directly anyway (missing "OpenFusion: terminated." be damned)
* Switched to a slightly more portable syntax for getting the version
in the Makefile
* We shouldn't join the shard thread in the signal handler because the
thread the signal handler ends up running in is undefined behaviour and
we don't strictly need to join it anyway

Many of these issues were discovered on OpenBSD.
This commit is contained in:
dongresource 2020-12-06 05:25:23 +01:00
parent 02c5df5c1b
commit 8ebabac7c0
7 changed files with 19 additions and 19 deletions

View File

@ -1,9 +1,11 @@
GIT_VERSION!=git describe --tags
CC=clang CC=clang
CXX=clang++ CXX=clang++
# -w suppresses all warnings (the part that's commented out helps me find memory leaks, it ruins performance though!) # -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 # If compiling with ASAN, invoke like this: $ LSAN_OPTIONS=suppressions=suppr.txt bin/fusion
CFLAGS=-O3 #-g3 -fsanitize=address 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 LDFLAGS=-lpthread -ldl #-g3 -fsanitize=address
# specifies the name of our exectuable # specifies the name of our exectuable
SERVER=bin/fusion SERVER=bin/fusion
@ -18,7 +20,7 @@ WIN_CXX=x86_64-w64-mingw32-g++
WIN_CFLAGS=-O3 #-g3 -fsanitize=address WIN_CFLAGS=-O3 #-g3 -fsanitize=address
WIN_CXX_VANILLA_MINGW_OPT_DISABLES=-fno-tree-dce -fno-inline-small-functions 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_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_LDFLAGS=-static -lws2_32 -lwsock32 #-g3 -fsanitize=address
WIN_SERVER=bin/winfusion.exe WIN_SERVER=bin/winfusion.exe

View File

@ -313,7 +313,7 @@ void CNServer::start() {
int n = poll(fds.data(), fds.size(), 50); int n = poll(fds.data(), fds.size(), 50);
if (SOCKETERROR(n)) { if (SOCKETERROR(n)) {
std::cout << "[FATAL] poll() returned error" << std::endl; std::cout << "[FATAL] poll() returned error" << std::endl;
terminate(); terminate(0);
} }
oldnfds = fds.size(); oldnfds = fds.size();
@ -329,7 +329,7 @@ void CNServer::start() {
// any sort of error on the listener // any sort of error on the listener
if (fds[i].revents & ~POLLIN) { if (fds[i].revents & ~POLLIN) {
std::cout << "[FATAL] Error on listener socket" << std::endl; std::cout << "[FATAL] Error on listener socket" << std::endl;
terminate(); terminate(0);
} }
SOCKET newConnectionSocket = accept(sock, (struct sockaddr *)&address, (socklen_t*)&addressSize); SOCKET newConnectionSocket = accept(sock, (struct sockaddr *)&address, (socklen_t*)&addressSize);

View File

@ -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 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 getTime();
time_t getTimestamp(); time_t getTimestamp();
void terminate(int unused=0); void terminate(int);
// The PROTOCOL_VERSION definition is defined by the build system. // The PROTOCOL_VERSION definition is defined by the build system.
#if !defined(PROTOCOL_VERSION) #if !defined(PROTOCOL_VERSION)

View File

@ -123,7 +123,7 @@ bool Monitor::acceptConnection(SOCKET fd, uint16_t revents) {
if (revents & ~POLLIN) { if (revents & ~POLLIN) {
std::cout << "[FATAL] Error on monitor listener?" << std::endl; std::cout << "[FATAL] Error on monitor listener?" << std::endl;
terminate(); terminate(0);
} }
int sock = accept(listener, (struct sockaddr*)&address, &len); int sock = accept(listener, (struct sockaddr*)&address, &len);

View File

@ -720,7 +720,7 @@ void PlayerManager::revivePlayer(CNSocket* sock, CNPacketData* data) {
int nanoID = plr->equippedNanos[i]; int nanoID = plr->equippedNanos[i];
// halve nano health if respawning // halve nano health if respawning
// all revives not 3-5 are normal respawns. // 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 plr->Nanos[nanoID].iStamina = 75; // max is 150, so 75 is half
response.PCRegenData.Nanos[i] = plr->Nanos[nanoID]; response.PCRegenData.Nanos[i] = plr->Nanos[nanoID];
if (plr->activeNano == nanoID) if (plr->activeNano == nanoID)

View File

@ -54,7 +54,7 @@ void TableData::init() {
} }
catch (const std::exception& err) { catch (const std::exception& err) {
std::cerr << "[FATAL] Malformed NPCs.json file! Reason:" << err.what() << std::endl; std::cerr << "[FATAL] Malformed NPCs.json file! Reason:" << err.what() << std::endl;
terminate(); exit(1);
} }
// load everything else from xdttable // load everything else from xdttable
@ -230,7 +230,7 @@ void TableData::init() {
} }
catch (const std::exception& err) { catch (const std::exception& err) {
std::cerr << "[FATAL] Malformed xdt.json file! Reason:" << err.what() << std::endl; std::cerr << "[FATAL] Malformed xdt.json file! Reason:" << err.what() << std::endl;
terminate(); exit(1);
} }
// load temporary mob dump // load temporary mob dump
@ -303,7 +303,7 @@ void TableData::init() {
} }
catch (const std::exception& err) { catch (const std::exception& err) {
std::cerr << "[FATAL] Malformed mobs.json file! Reason:" << err.what() << std::endl; std::cerr << "[FATAL] Malformed mobs.json file! Reason:" << err.what() << std::endl;
terminate(); exit(1);
} }
loadDrops(); loadDrops();
@ -373,7 +373,7 @@ void TableData::loadPaths(int* nextId) {
if (firstPoint["iX"] != pair.second->spawnX || firstPoint["iY"] != pair.second->spawnY) { if (firstPoint["iX"] != pair.second->spawnX || firstPoint["iY"] != pair.second->spawnY) {
std::cout << "[FATAL] The first point of the route for mob " << pair.first << 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; " (type " << pair.second->appearanceData.iNPCType << ") does not correspond with its spawn point." << std::endl;
terminate(); exit(1);
} }
constructPathNPC(npcPath, pair.first); constructPathNPC(npcPath, pair.first);
@ -386,7 +386,7 @@ void TableData::loadPaths(int* nextId) {
} }
catch (const std::exception& err) { catch (const std::exception& err) {
std::cerr << "[FATAL] Malformed paths.json file! Reason:" << err.what() << std::endl; 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) { catch (const std::exception& err) {
std::cerr << "[FATAL] Malformed drops.json file! Reason:" << err.what() << std::endl; 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) { catch (const std::exception& err) {
std::cerr << "[FATAL] Malformed eggs.json file! Reason:" << err.what() << std::endl; 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) { catch (const std::exception& err) {
std::cerr << "[FATAL] Malformed gruntwork.json file! Reason:" << err.what() << std::endl; std::cerr << "[FATAL] Malformed gruntwork.json file! Reason:" << err.what() << std::endl;
terminate(); exit(1);
} }
} }

View File

@ -46,10 +46,8 @@ void startShard(CNShardServer* server) {
void terminate(int arg) { void terminate(int arg) {
std::cout << "OpenFusion: terminating." << std::endl; std::cout << "OpenFusion: terminating." << std::endl;
if (shardServer != nullptr && shardThread != nullptr) { if (shardServer != nullptr && shardThread != nullptr)
shardServer->kill(); shardServer->kill();
shardThread->join();
}
exit(0); exit(0);
} }
@ -111,7 +109,7 @@ int main() {
case 3: std::cout << "[INFO] Event active. Have a very hoppy Easter!" << std::endl; break; case 3: std::cout << "[INFO] Event active. Have a very hoppy Easter!" << std::endl; break;
default: default:
std::cout << "[FATAL] Unknown event set in config file." << std::endl; std::cout << "[FATAL] Unknown event set in config file." << std::endl;
terminate(); exit(1);
/* not reached */ /* not reached */
} }