From: TimePath Date: Fri, 8 Jan 2016 05:50:31 +0000 (+1100) Subject: csprogs: more pk3 support X-Git-Tag: xonotic-v0.8.2~1261 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=cafdc69255ce3a4bb5fa7f9d341689e33c814e1c;p=xonotic%2Fxonotic-data.pk3dir.git csprogs: more pk3 support --- diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index 768219833..18eebc4cb 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -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); diff --git a/qcsrc/lib/string.qh b/qcsrc/lib/string.qh index 8a984d67e..bd0c8d30f 100644 --- a/qcsrc/lib/string.qh +++ b/qcsrc/lib/string.qh @@ -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) { diff --git a/qcsrc/server/g_world.qc b/qcsrc/server/g_world.qc index 64799df46..eac04a629 100644 --- a/qcsrc/server/g_world.qc +++ b/qcsrc/server/g_world.qc @@ -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