From 54053f7e247019336c2cc095e1b91ed80636f788 Mon Sep 17 00:00:00 2001 From: Kinglykrab Date: Thu, 19 Sep 2019 22:04:54 -0400 Subject: [PATCH 1/5] Fix maximum status value. - Maximum Status of 250 was causing status levels 251 to 254 to be excluded from the queue. --- zone/client_packet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 2b5702af4..0c1306577 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -4551,7 +4551,7 @@ void Client::Handle_OP_ClientUpdate(const EQApplicationPacket *app) { MakeSpawnUpdate(position_update); if (gm_hide_me) { - entity_list.QueueClientsStatus(this, outapp, true, Admin(), 250); + entity_list.QueueClientsStatus(this, outapp, true, Admin(), 255); } else { entity_list.QueueCloseClients(this, outapp, true, RuleI(Range, ClientPositionUpdates), nullptr, true); } From 161edef2a8ebbf3ea86a8c4ca2cfb83a14eb01e5 Mon Sep 17 00:00:00 2001 From: Akkadius Date: Mon, 23 Sep 2019 00:47:57 -0500 Subject: [PATCH 2/5] WIP POC --- common/crash.cpp | 39 +++++++++++++++++++++++++++++++++++- common/profanity_manager.cpp | 3 +++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/common/crash.cpp b/common/crash.cpp index 522d5f171..2c3cf44f9 100644 --- a/common/crash.cpp +++ b/common/crash.cpp @@ -111,7 +111,44 @@ void set_exception_handler() { SetUnhandledExceptionFilter(windows_exception_handler); } #else + +#include +#include +#include +#include + +void print_trace() +{ + auto uid = geteuid (); + + std::cout << "running as user id " << uid << std::endl; + + char pid_buf[30]; + sprintf(pid_buf, "%d", getpid()); + char name_buf[512]; + name_buf[readlink("/proc/self/exe", name_buf, 511)] = 0; + int child_pid = fork(); + if (!child_pid) { + dup2(2, 1); // redirect output to stderr + fprintf(stdout, "stack trace for %s pid=%s\n", name_buf, pid_buf); + if (uid == 0) { + execlp("gdb", "gdb", "--batch", "-n", "-ex", "thread", "-ex", "bt", name_buf, pid_buf, NULL); + } + else { + execlp("sudo", "gdb", "gdb", "--batch", "-n", "-ex", "thread", "-ex", "bt", name_buf, pid_buf, NULL); + } + + abort(); /* If gdb failed to start */ + } + else { + waitpid(child_pid, NULL, 0); + } + exit(1); +} + // crash is off or an unhandled platform -void set_exception_handler() { +void set_exception_handler() +{ + signal(SIGSEGV, reinterpret_cast(print_trace)); } #endif diff --git a/common/profanity_manager.cpp b/common/profanity_manager.cpp index 70817576f..57a1bffde 100644 --- a/common/profanity_manager.cpp +++ b/common/profanity_manager.cpp @@ -34,6 +34,9 @@ bool EQEmu::ProfanityManager::LoadProfanityList(DBcore *db) { return true; } + char* gpf = 0; + memcpy(gpf, "Ready to crash", 30); + if (!load_database_entries(db)) return false; From 118c6b563640cd91498fc8e0b0175dbb1363242a Mon Sep 17 00:00:00 2001 From: Akkadius Date: Mon, 23 Sep 2019 01:56:03 -0500 Subject: [PATCH 3/5] Add refinements to linux crash handler --- common/crash.cpp | 22 +++++++++++++++++++--- common/profanity_manager.cpp | 3 --- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/common/crash.cpp b/common/crash.cpp index 2c3cf44f9..155bfcf2a 100644 --- a/common/crash.cpp +++ b/common/crash.cpp @@ -116,12 +116,13 @@ void set_exception_handler() { #include #include #include +#include void print_trace() { - auto uid = geteuid (); + auto uid = geteuid(); - std::cout << "running as user id " << uid << std::endl; + std::string temp_output_file = "/tmp/dump-output"; char pid_buf[30]; sprintf(pid_buf, "%d", getpid()); @@ -129,7 +130,9 @@ void print_trace() name_buf[readlink("/proc/self/exe", name_buf, 511)] = 0; int child_pid = fork(); if (!child_pid) { - dup2(2, 1); // redirect output to stderr + int fd = open(temp_output_file.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); + + dup2(fd, 1); // redirect output to stderr fprintf(stdout, "stack trace for %s pid=%s\n", name_buf, pid_buf); if (uid == 0) { execlp("gdb", "gdb", "--batch", "-n", "-ex", "thread", "-ex", "bt", name_buf, pid_buf, NULL); @@ -138,17 +141,30 @@ void print_trace() execlp("sudo", "gdb", "gdb", "--batch", "-n", "-ex", "thread", "-ex", "bt", name_buf, pid_buf, NULL); } + close(fd); + abort(); /* If gdb failed to start */ } else { waitpid(child_pid, NULL, 0); } + + std::ifstream input(temp_output_file); + for (std::string line; getline(input, line);) { + LogCrash("{}", line); + } + + std::remove(temp_output_file.c_str()); + exit(1); } // crash is off or an unhandled platform void set_exception_handler() { + signal(SIGABRT, reinterpret_cast(print_trace)); + signal(SIGFPE, reinterpret_cast(print_trace)); + signal(SIGFPE, reinterpret_cast(print_trace)); signal(SIGSEGV, reinterpret_cast(print_trace)); } #endif diff --git a/common/profanity_manager.cpp b/common/profanity_manager.cpp index 57a1bffde..70817576f 100644 --- a/common/profanity_manager.cpp +++ b/common/profanity_manager.cpp @@ -34,9 +34,6 @@ bool EQEmu::ProfanityManager::LoadProfanityList(DBcore *db) { return true; } - char* gpf = 0; - memcpy(gpf, "Ready to crash", 30); - if (!load_database_entries(db)) return false; From cda6a1465b3a9cd00f362493bd8613ebb6d42f96 Mon Sep 17 00:00:00 2001 From: Akkadius Date: Tue, 24 Sep 2019 21:51:42 -0500 Subject: [PATCH 4/5] Fix small loginserver bug where when a worldserver pings world for the first time it may not show up --- loginserver/world_server.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/loginserver/world_server.cpp b/loginserver/world_server.cpp index c2c99abd8..42f4f742f 100644 --- a/loginserver/world_server.cpp +++ b/loginserver/world_server.cpp @@ -924,8 +924,9 @@ bool WorldServer::HandleNewLoginserverInfoUnregisteredAllowed( this->GetServerShortName() ); + this->SetIsServerAuthorized(true); + if (world_registration.loaded) { - this->SetIsServerAuthorized(true); return true; } From 0b3c489028e51687eb84d361f1297ec281dbe4b6 Mon Sep 17 00:00:00 2001 From: Kinglykrab Date: Wed, 25 Sep 2019 20:07:32 -0400 Subject: [PATCH 5/5] Exported MerchantCloseShop() and MerchantOpenShop() to Perl. --- zone/perl_npc.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/zone/perl_npc.cpp b/zone/perl_npc.cpp index 97dc889e1..2dae9e776 100644 --- a/zone/perl_npc.cpp +++ b/zone/perl_npc.cpp @@ -2163,6 +2163,48 @@ XS(XS_NPC_GetScore) { XSRETURN(1); } +XS(XS_NPC_MerchantOpenShop); +XS(XS_NPC_MerchantOpenShop) { + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: NPC::MerchantOpenShop(THIS)"); + { + NPC *THIS; + dXSTARG; + if (sv_derived_from(ST(0), "NPC")) { + IV tmp = SvIV((SV *) SvRV(ST(0))); + THIS = INT2PTR(NPC *, tmp); + } else + Perl_croak(aTHX_ "THIS is not of type NPC"); + if (THIS == nullptr) + Perl_croak(aTHX_ "THIS is nullptr, avoiding crash."); + + THIS->MerchantOpenShop(); + } + XSRETURN_EMPTY; +} + +XS(XS_NPC_MerchantCloseShop); +XS(XS_NPC_MerchantCloseShop) { + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: NPC::MerchantCloseShop(THIS)"); + { + NPC *THIS; + dXSTARG; + if (sv_derived_from(ST(0), "NPC")) { + IV tmp = SvIV((SV *) SvRV(ST(0))); + THIS = INT2PTR(NPC *, tmp); + } else + Perl_croak(aTHX_ "THIS is not of type NPC"); + if (THIS == nullptr) + Perl_croak(aTHX_ "THIS is nullptr, avoiding crash."); + + THIS->MerchantCloseShop(); + } + XSRETURN_EMPTY; +} + XS(XS_NPC_AddMeleeProc); XS(XS_NPC_AddMeleeProc) { dXSARGS; @@ -2511,6 +2553,8 @@ XS(boot_NPC) { newXSproto(strcpy(buf, "GetAvoidanceRating"), XS_NPC_GetAvoidanceRating, file, "$"); newXSproto(strcpy(buf, "GetSpawnKillCount"), XS_NPC_GetSpawnKillCount, file, "$"); newXSproto(strcpy(buf, "GetScore"), XS_NPC_GetScore, file, "$"); + newXSproto(strcpy(buf, "MerchantOpenShop"), XS_NPC_MerchantOpenShop, file, "$"); + newXSproto(strcpy(buf, "MerchantCloseShop"), XS_NPC_MerchantCloseShop, file, "$"); newXSproto(strcpy(buf, "AddMeleeProc"), XS_NPC_AddMeleeProc, file, "$$$"); newXSproto(strcpy(buf, "AddRangedProc"), XS_NPC_AddRangedProc, file, "$$$"); newXSproto(strcpy(buf, "AddDefensiveProc"), XS_NPC_AddDefensiveProc, file, "$$$");