]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
csprogs: more pk3 support
authorTimePath <andrew.hardaker1995@gmail.com>
Fri, 8 Jan 2016 05:50:31 +0000 (16:50 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Fri, 8 Jan 2016 05:50:31 +0000 (16:50 +1100)
qcsrc/client/main.qc
qcsrc/lib/string.qh
qcsrc/server/g_world.qc

index 7682198338308463520b72a815e03e4b8cd91b0d..18eebc4cb22c78e97c255119ddc9285e87bda375 100644 (file)
@@ -131,6 +131,13 @@ void CSQC_Init()
 // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc)
 void Shutdown()
 {
+       // Reset csqc_progname changes here to keep listen servers working
+       // The engine should do this, but doesn't
+       string csqc_progname_prev = "csprogs.dat";
+       if (fexists(csqc_progname_prev))
+               cvar_set("csqc_progname", csqc_progname_prev);
+       else
+               LOG_WARNING("Don't know what to reset csqc_progname to");
        WarpZone_Shutdown();
 
        remove(teams);
index 8a984d67e4c7a54af18c69a2ddeb5028ee5119c9..bd0c8d30f8a97bef964e41990628003627390dda 100644 (file)
@@ -104,6 +104,9 @@ bool startsWithNocase(string haystack, string needle)
        return strcasecmp(substring(haystack, 0, strlen(needle)), needle) == 0;
 }
 
+noref string _endsWith_suffix;
+#define endsWith(this, suffix) (_endsWith_suffix = suffix, substring(this, -strlen(_endsWith_suffix), -1) == _endsWith_suffix)
+
 /** unzone the string, and return it as tempstring. Safe to be called on string_null */
 string fstrunzone(string s)
 {
index 64799df4691b337aab5d9668442312a7d2877e5a..eac04a62900191da17087d541fad05a0d6d8fea5 100644 (file)
@@ -563,6 +563,48 @@ void WeaponStats_Init();
 void WeaponStats_Shutdown();
 spawnfunc(worldspawn)
 {
+       {
+               bool wantrestart = false;
+               // Try to use versioned csprogs from pk3
+               // Only ever use versioned csprogs.dat files on dedicated servers;
+               // we need to reset csqc_progname on clients ourselves, and it's easier if the client's release name is constant
+               string pk3csprogs = "csprogs-" WATERMARK ".dat";
+               if (cvar_string_normal("csqc_progname") != pk3csprogs && fexists(pk3csprogs))
+               {
+                       cvar_set_normal("csqc_progname", pk3csprogs);
+                       wantrestart = true;
+               }
+               // Check for updates on startup
+               // We do it this way for atomicity so that connecting clients still match the server progs and don't disconnect
+               int sentinel = fopen("progs.txt", FILE_READ);
+               if (sentinel >= 0)
+               {
+                       string switchversion = fgets(sentinel);
+                       fclose(sentinel);
+                       if (switchversion != "" && switchversion != WATERMARK)
+                       {
+                               LOG_INFOF("Switching progs: " WATERMARK " -> %s\n", switchversion);
+                               // if it doesn't exist, assume either:
+                               //   a) the current program was overwritten
+                               //   b) this is a client only update
+                               string newprogs = sprintf("progs-%s.dat", switchversion);
+                               if (fexists(newprogs))
+                               {
+                                       cvar_set_normal("sv_progs", newprogs);
+                                       wantrestart = true;
+                               }
+                               string newcsprogs = sprintf("csprogs-%s.dat", switchversion);
+                               if (fexists(newcsprogs))
+                               {
+                                       cvar_set_normal("csqc_progname", newcsprogs);
+                                       wantrestart = true;
+                               }
+                       }
+               }
+               if (wantrestart) changelevel(mapname);
+               // let initialization continue, shutdown depends on it
+       }
+
        float fd, l;
        string s;
 
@@ -793,8 +835,9 @@ spawnfunc(worldspawn)
                for (int i = 0, n = tokenize_console(cvar_string("sv_curl_serverpackages")); i < n; ++i)
                {
                        string pkg = argv(i);
-                       if (substring(pkg, -18, -1) == "-serverpackage.txt") continue;
-                       if (substring(pkg, -14, -1) == ".serverpackage") continue;  // OLD legacy
+                       if (startsWith(pkg, "csprogs-")) continue;
+                       if (endsWith(pkg, "-serverpackage.txt")) continue;
+                       if (endsWith(pkg, ".serverpackage")) continue;  // OLD legacy
                        s = cons(s, pkg);
                }
                // add automatically managed files to the list