소스 검색

Temporarily cache ConCommand flags

Cache flags as early as possible in case another plugin changes the
flags before we dump the data.

Also free handles as necessary.  It doesn't really matter when we're
quitting the server anyways, but who knows?
nosoop 7 년 전
부모
커밋
16fdcf5fb6
1개의 변경된 파일40개의 추가작업 그리고 6개의 파일을 삭제
  1. 40 6
      scripting/csrd_data_dump.sp

+ 40 - 6
scripting/csrd_data_dump.sp

@@ -13,7 +13,7 @@
 #include <stocksoup/files>
 #include <stocksoup/version>
 
-#define PLUGIN_VERSION "1.1.1"
+#define PLUGIN_VERSION "1.1.2"
 public Plugin myinfo = {
 	name = "[CSRD] SRCDS Automatic Data Dumper",
 	author = "nosoop",
@@ -41,12 +41,32 @@ enum DumpAction {
 };
 
 DumpAction g_DumpAction;
+StringMap g_ConCommandFlagCache;
 
 public APLRes AskPluginLoad2(Handle hPluginSelf, bool bLateLoaded, char[] error, int err_max) {
 	if (bLateLoaded) {
 		g_DumpAction = DumpAction_None;
 	} else {
 		g_DumpAction = DumpAction_FileCheck;
+		
+		/**
+		 * cache flags early in case a plugin overrides flags
+		 * https://github.com/nosoop/SM-ConVarConfigs does this when all plugins are loaded
+		 */
+		g_ConCommandFlagCache = new StringMap();
+		
+		char commandName[128];
+		bool bIsCommand;
+		int flags;
+		
+		Handle hConCommandIter = FindFirstConCommand(commandName, sizeof(commandName),
+				bIsCommand, flags);
+		
+		do {
+			g_ConCommandFlagCache.SetValue(commandName, flags);
+		} while ( FindNextConCommand(hConCommandIter, commandName, sizeof(commandName),
+				bIsCommand, flags) );
+		delete hConCommandIter;
 	}
 	
 	return APLRes_Success;
@@ -70,6 +90,10 @@ public void OnMapStart() {
 				ForceChangeLevel(LOW_ENTITY_MAP, "Starting server data dump");
 			} else {
 				g_DumpAction = DumpAction_None;
+				
+				// we're not dumping, so there's no point in keeping the cache
+				delete g_ConCommandFlagCache;
+				g_ConCommandFlagCache = null;
 			}
 		}
 		
@@ -167,20 +191,26 @@ void DumpServerCommands(const char[] format, any ...) {
 	
 	outputFile.WriteLine("\"%s\",\"%s\",\"%s\"", "Names", "Flags", "Help Text");
 	
-	Handle hConCommand = FindFirstConCommand(commandName, sizeof(commandName), bIsCommand,
+	Handle hConCommandIter = FindFirstConCommand(commandName, sizeof(commandName), bIsCommand,
 			flags, commandDescription, sizeof(commandDescription));
 	
 	do {
 		if (bIsCommand) {
+			if (g_ConCommandFlagCache) {
+				g_ConCommandFlagCache.GetValue(commandName, flags);
+			}
+			
 			ReplaceString(commandDescription, sizeof(commandDescription), "\"", "'");
 			ReplaceString(commandDescription, sizeof(commandDescription), "\n", " / ");
 			
 			outputFile.WriteLine("\"%s\",\"%s\",\"%s\"", commandName,
 					GetCommandFlagString(flags), commandDescription);
 		}
-	} while ( FindNextConCommand(hConCommand, commandName, sizeof(commandName),
+	} while ( FindNextConCommand(hConCommandIter, commandName, sizeof(commandName),
 			bIsCommand, flags, commandDescription, sizeof(commandDescription)) );
 	
+	delete hConCommandIter;
+	
 	delete outputFile;
 }
 
@@ -197,11 +227,15 @@ void DumpServerConVars(const char[] format, any ...) {
 	outputFile.WriteLine("\"%s\",\"%s\",\"%s\",\"%s\"", "Names", "Defaults", "Flags",
 			"Help Text");
 	
-	Handle hConCommand = FindFirstConCommand(commandName, sizeof(commandName), bIsCommand,
+	Handle hConCommandIter = FindFirstConCommand(commandName, sizeof(commandName), bIsCommand,
 			flags, commandDescription, sizeof(commandDescription));
 	
 	do {
 		if (!bIsCommand) {
+			if (g_ConCommandFlagCache) {
+				g_ConCommandFlagCache.GetValue(commandName, flags);
+			}
+			
 			char defaultValue[128];
 			FindConVar(commandName).GetDefault(defaultValue, sizeof(defaultValue));
 			
@@ -211,9 +245,9 @@ void DumpServerConVars(const char[] format, any ...) {
 			outputFile.WriteLine("\"%s\",\"%s\",\"%s\",\"%s\"", commandName,
 					defaultValue, GetCommandFlagString(flags), commandDescription);
 		}
-	} while ( FindNextConCommand(hConCommand, commandName, sizeof(commandName),
+	} while ( FindNextConCommand(hConCommandIter, commandName, sizeof(commandName),
 			bIsCommand, flags, commandDescription, sizeof(commandDescription)) );
-	
+	delete hConCommandIter;
 	delete outputFile;
 }