]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Autocvar: use MakeConsoleSafe
authorTimePath <andrew.hardaker1995@gmail.com>
Thu, 8 Oct 2015 00:42:58 +0000 (11:42 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Thu, 8 Oct 2015 00:42:58 +0000 (11:42 +1100)
qcsrc/common/util.qc
qcsrc/lib/cvar.qh

index 4b6a346ff34af56b9766b9088d1b98c9818c01bd..e93fd6a399875c19719fc7d534760ac03c9d3b25 100644 (file)
@@ -2215,16 +2215,6 @@ string strlimitedlen(string input, string truncation, float strip_colors, float
                return strcat(substring(input, 0, (strlen(input) - strlen(truncation))), truncation);
 }*/
 
-// escape the string to make it safe for consoles
-string MakeConsoleSafe(string input)
-{
-       input = strreplace("\n", "", input);
-       input = strreplace("\\", "\\\\", input);
-       input = strreplace("$", "$$", input);
-       input = strreplace("\"", "\\\"", input);
-       return input;
-}
-
 #ifdef CSQC
 entity ReadCSQCEntity()
 {
index a02ec0f00e56288b312e4312b2d3316e0933e1d8..e30de507ba2cdbea6148ed9d5093ed2d287c7129 100644 (file)
@@ -6,6 +6,16 @@
 
 void RegisterCvars(void(string name, string def, string desc, bool archive, string file) f) { }
 
+/** escape the string to make it safe for consoles */
+string MakeConsoleSafe(string input)
+{
+       input = strreplace("\n", "", input);
+       input = strreplace("\\", "\\\\", input);
+       input = strreplace("$", "$$", input);
+       input = strreplace("\"", "\\\"", input);
+       return input;
+}
+
 void RegisterCvars_Set(string name, string def, string desc, bool archive, string file)
 {
     string val = string_null;
@@ -14,9 +24,9 @@ void RegisterCvars_Set(string name, string def, string desc, bool archive, strin
         // Need to unset first to change the default
         localcmd(sprintf("\nunset %s\n", name));
     }
-    localcmd(sprintf("\n%s %s \"%s\" \"%s\"\n", (archive ? "seta" : "set"), name, def, desc));
+    localcmd(sprintf("\n%s %s \"%s\" \"%s\"\n", (archive ? "seta" : "set"), name, MakeConsoleSafe(def), MakeConsoleSafe(desc)));
     if (val) {
-        localcmd(sprintf("\n%s \"%s\"\n", name, val));
+        localcmd(sprintf("\n%s \"%s\"\n", name, MakeConsoleSafe(val)));
     }
 }