Browse Source

More robust update check

No need to have SteamTools for automatic updates anymore; we'll also
check the version on startup.
nosoop 6 years ago
parent
commit
4c644986a8
1 changed files with 24 additions and 6 deletions
  1. 24 6
      scripting/csrd_data_dump.sp

+ 24 - 6
scripting/csrd_data_dump.sp

@@ -13,7 +13,7 @@
 #include <stocksoup/files>
 #include <stocksoup/version>
 
-#define PLUGIN_VERSION "1.3.0"
+#define PLUGIN_VERSION "1.4.0"
 public Plugin myinfo = {
 	name = "[CSRD] SRCDS Automatic Data Dumper",
 	author = "nosoop",
@@ -87,7 +87,7 @@ public void OnMapStart() {
 		 * This is performed on first map load.
 		 */
 		case DumpAction_UpdateCheck: {
-			if (FileExists(path, false)) {
+			if (FileExists(path) || IsNewServerVersion()) {
 				g_DumpAction = DumpAction_PendingDump;
 				ForceChangeLevel(LOW_ENTITY_MAP, "Starting server data dump");
 			} else {
@@ -106,7 +106,8 @@ public void OnMapStart() {
 			char currentMap[PLATFORM_MAX_PATH];
 			GetCurrentMap(currentMap, sizeof(currentMap));
 			
-			if (StrEqual(LOW_ENTITY_MAP, currentMap) && FileExists(path, false)) {
+			if (StrEqual(LOW_ENTITY_MAP, currentMap)
+					&& (FileExists(path) || IsNewServerVersion())) {
 				DataPack pack = new DataPack();
 				pack.WriteString(path);
 				
@@ -118,6 +119,23 @@ public void OnMapStart() {
 	}
 }
 
+bool IsNewServerVersion() {
+	char updatePath[PLATFORM_MAX_PATH];
+	BuildPath(Path_SM, updatePath, sizeof(updatePath), "%s/%s", REDUMP_OUTPUT_DIRECTORY,
+			".server-version");
+	
+	if (FileExists(updatePath)) {
+		char versionString[64];
+		
+		File versionFile = OpenFile(updatePath, "r");
+		versionFile.ReadLine(versionString, sizeof(versionString));
+		delete versionFile;
+		
+		return GetNetworkPatchVersion() > StringToInt(versionString);
+	}
+	return true;
+}
+
 void PerformDataDump(RequestFrameCallback postDumpCallback = INVALID_FUNCTION, any data = 0) {
 	char outputDirectory[PLATFORM_MAX_PATH];
 	BuildPath(Path_SM, outputDirectory, sizeof(outputDirectory), REDUMP_OUTPUT_DIRECTORY);
@@ -184,7 +202,9 @@ public void OnDataDumpFinished(DataPack pack) {
 	pack.ReadString(path, sizeof(path));
 	delete pack;
 	
-	DeleteFile(path);
+	if (FileExists(path)) {
+		DeleteFile(path);
+	}
 	
 	LogMessage("Dumped server data for network patchversion %d", GetNetworkPatchVersion());
 	
@@ -204,9 +224,7 @@ public Action Steam_RestartRequested() {
 
 public Action ForceDataDump(int client, int argc) {
 	PrepareRedump();
-	
 	ReplyToCommand(client, "[SM] Prepared dump process.  Restart server.");
-	
 	return Plugin_Continue;
 }