From c34cf38c7d75d81428062aea7d317573f38a78fe Mon Sep 17 00:00:00 2001 From: Image <> Date: Sat, 25 Jul 2020 14:18:01 -0400 Subject: [PATCH] Added /findspawn searchstring/regex Fix #159 allows us to more easily locate spawns by partial name and identify location / database ids --- DB/updates/findspawn_command.sql | 1 + EQ2/source/WorldServer/Commands/Commands.cpp | 5 +++ EQ2/source/WorldServer/Commands/Commands.h | 4 ++ EQ2/source/WorldServer/zoneserver.cpp | 42 ++++++++++++++++++++ EQ2/source/WorldServer/zoneserver.h | 3 +- 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 DB/updates/findspawn_command.sql diff --git a/DB/updates/findspawn_command.sql b/DB/updates/findspawn_command.sql new file mode 100644 index 000000000..397030f66 --- /dev/null +++ b/DB/updates/findspawn_command.sql @@ -0,0 +1 @@ +insert into commands set handler=521,command='findspawn',required_status=200,subcommand=''; \ No newline at end of file diff --git a/EQ2/source/WorldServer/Commands/Commands.cpp b/EQ2/source/WorldServer/Commands/Commands.cpp index 6928e6f96..2dfd67fd2 100644 --- a/EQ2/source/WorldServer/Commands/Commands.cpp +++ b/EQ2/source/WorldServer/Commands/Commands.cpp @@ -4376,6 +4376,7 @@ void Commands::Process(int32 index, EQ2_16BitString* command_parms, Client* clie case SAVE_AA_PROFILE : { Save_AA_Profile(client, sep); break; } case COMMAND_TARGETITEM : { Command_TargetItem(client, sep); break; } + case COMMAND_FINDSPAWN: { Command_FindSpawn(client, sep); break; } default: @@ -10115,3 +10116,7 @@ void Commands::Command_TargetItem(Client* client, Seperator* sep) { } } } + +void Commands::Command_FindSpawn(Client* client, Seperator* sep) { + client->GetCurrentZone()->FindSpawn(client, (char*)sep->argplus[0]); +} diff --git a/EQ2/source/WorldServer/Commands/Commands.h b/EQ2/source/WorldServer/Commands/Commands.h index 2ff828ede..8263b2b04 100644 --- a/EQ2/source/WorldServer/Commands/Commands.h +++ b/EQ2/source/WorldServer/Commands/Commands.h @@ -468,6 +468,8 @@ public: void Command_DeclineResurrection(Client* client, Seperator* set); void Command_TargetItem(Client* client, Seperator* set); + void Command_FindSpawn(Client* client, Seperator* set); + // Bot Commands void Command_Bot(Client* client, Seperator* sep); void Command_Bot_Create(Client* client, Seperator* sep); @@ -899,6 +901,8 @@ private: #define COMMAND_RELOAD_RULES 519 #define COMMAND_RELOAD_TRANSPORTERS 520 +#define COMMAND_FINDSPAWN 521 + #define GET_AA_XML 751 #define ADD_AA 752 #define COMMIT_AA_PROFILE 753 diff --git a/EQ2/source/WorldServer/zoneserver.cpp b/EQ2/source/WorldServer/zoneserver.cpp index 3a4db408b..8d9e24d69 100644 --- a/EQ2/source/WorldServer/zoneserver.cpp +++ b/EQ2/source/WorldServer/zoneserver.cpp @@ -25,6 +25,7 @@ using namespace std; #include #include #include +#include #include "Commands/Commands.h" #include "Zone/pathfinder_interface.h" @@ -5840,6 +5841,47 @@ bool ZoneServer::SendRadiusSpawnInfo(Client* client, float radius) { return ret; } +void ZoneServer::FindSpawn(Client* client, char* regSearchStr) +{ + if (!regSearchStr || strlen(regSearchStr) < 1) + { + client->SimpleMessage(CHANNEL_COLOR_RED, "Bad ZoneServer::FindSpawn(Client*, char* regSearchStr) attempt, regSearchStr is NULL or empty."); + return; + } + + string resString = string(regSearchStr); + std::regex pre_re_check("^[a-zA-Z0-9_\s]+$"); + bool output = std::regex_match(resString, pre_re_check); + if (output) + { + string newStr(".*"); + newStr.append(regSearchStr); + newStr.append(".*"); + resString = newStr; + } + client->Message(CHANNEL_COLOR_WHITE, "RegEx Search Spawn List: %s", regSearchStr); + client->Message(CHANNEL_COLOR_WHITE, "Database ID | Spawn Name | X , Y , Z"); + client->Message(CHANNEL_COLOR_WHITE, "========================"); + map::iterator itr; + MSpawnList.readlock(__FUNCTION__, __LINE__); + int32 spawnsFound = 0; + std::regex re(resString); + for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) { + Spawn* spawn = itr->second; + if (!spawn) + continue; + bool output = std::regex_match(string(spawn->GetName()), re); + if (output) + { + client->Message(CHANNEL_COLOR_WHITE, "%i | %s | %f , %f , %f", spawn->GetDatabaseID(), spawn->GetName(), spawn->GetX(), spawn->GetY(), spawn->GetZ()); + spawnsFound++; + } + } + client->Message(CHANNEL_COLOR_WHITE, "========================", spawnsFound); + client->Message(CHANNEL_COLOR_WHITE, "%u Results Found.", spawnsFound); + MSpawnList.releasereadlock(__FUNCTION__, __LINE__); +} + void ZoneServer::AddPlayerTracking(Player* player) { if (player && !player->GetIsTracking() && players_tracking.count(player->GetDatabaseID()) == 0) { diff --git a/EQ2/source/WorldServer/zoneserver.h b/EQ2/source/WorldServer/zoneserver.h index 4d6d64d02..82156ec1c 100644 --- a/EQ2/source/WorldServer/zoneserver.h +++ b/EQ2/source/WorldServer/zoneserver.h @@ -345,8 +345,9 @@ public: void CheckTransporters(Client* client); void WritePlayerStatistics(); - + bool SendRadiusSpawnInfo(Client* client, float radius); + void FindSpawn(Client* client, char* regSearchStr); volatile bool spawnthread_active; volatile bool combatthread_active;