Browse Source

Added /findspawn searchstring/regex

Fix #159 allows us to more easily locate spawns by partial name and identify location / database ids
Image 3 years ago
parent
commit
c34cf38c7d

+ 1 - 0
DB/updates/findspawn_command.sql

@@ -0,0 +1 @@
+insert into commands set handler=521,command='findspawn',required_status=200,subcommand='';

+ 5 - 0
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]);
+}

+ 4 - 0
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				

+ 42 - 0
EQ2/source/WorldServer/zoneserver.cpp

@@ -25,6 +25,7 @@ using namespace std;
 #include <stdio.h>
 #include <time.h>
 #include <stdlib.h>
+#include <regex>
 #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<int32, Spawn*>::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) {

+ 2 - 1
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;