From ac44ca9fa5ab8d1ecb3de306a322fbfb7ce556c4 Mon Sep 17 00:00:00 2001 From: div0 Date: Tue, 2 Jan 2007 14:14:20 +0000 Subject: [PATCH] cmd info (something) prints the content of sv_info_(something), for server admins to put text there git-svn-id: svn://svn.icculus.org/nexuiz/trunk@2086 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/qcsrc/common/util.qc | 169 +++++++--------------------- data/qcsrc/common/util.qh | 4 + data/qcsrc/menu/msys.qc | 1 + data/qcsrc/server/clientcommands.qc | 8 +- 4 files changed, 52 insertions(+), 130 deletions(-) diff --git a/data/qcsrc/common/util.qc b/data/qcsrc/common/util.qc index cddb3f38f..7faa28678 100644 --- a/data/qcsrc/common/util.qc +++ b/data/qcsrc/common/util.qc @@ -1,17 +1,50 @@ +string wordwrap_buffer; + +void wordwrap_buffer_put(string s) +{ + wordwrap_buffer = strcat(wordwrap_buffer, s); +} string wordwrap(string s, float l) { - local string t, c; + wordwrap_buffer = ""; + wordwrap_cb(s, l, wordwrap_buffer_put); + return wordwrap_buffer; +} + +#ifndef MENUQC +void wordwrap_buffer_sprint(string s) +{ + wordwrap_buffer = strcat(wordwrap_buffer, s); + if(s == "\n") + { + sprint(self, wordwrap_buffer); + wordwrap_buffer = ""; + } +} + +void wordwrap_sprint(string s, float l) +{ + wordwrap_buffer = ""; + wordwrap_cb(s, l, wordwrap_buffer_sprint); + if(wordwrap_buffer != "") + sprint(self, strcat(wordwrap_buffer, "\n")); + return; +} +#endif + +void wordwrap_cb(string s, float l, void(string) callback) +{ + local string c; local float lleft, i, j, wlen; s = strzone(s); - t = ""; lleft = l; for (i = 0;i < strlen(s);i++) { if (substring(s, i, 2) == "\\n") { - t = strcat(t, "\n"); + callback("\n"); lleft = l; i++; } @@ -19,7 +52,7 @@ string wordwrap(string s, float l) { if (lleft > 0) { - t = strcat(t, " "); + callback(" "); lleft = lleft - 1; } } @@ -42,142 +75,20 @@ string wordwrap(string s, float l) // we need to keep this tempstring alive even if substring is // called repeatedly, so call strcat even though we're not // doing anything - t = strcat(t); + callback(""); } wlen = j - i; if (lleft < wlen) { - t = strcat(t, "\n"); + callback("\n"); lleft = l; } - t = strcat(t, substring(s, i, wlen)); + callback(substring(s, i, wlen)); lleft = lleft - wlen; i = j - 1; } } strunzone(s); - return t; - -/* - string t; - string word; - - float lleft; - float i; - - float startidx; - - startidx = 0; - - t = ""; - word = ""; - for (i = 0;i < strlen(s);i++) - { - c = substring(s, i, 1); - forceflush = false; - if (c == " ") - dowhat = 0; - else if (c == "\\" && substring(s, i + 1, 1) == "n") - dowhat = 1; - else - { - dowhat = 2; - word = strcat(word, c); - } - - if (dowhat < 2) - { - // a space may add some whitespace to the output, and flushes the word buffer - if (word != "") - { - if (lleft < strlen(word) + 1) - { - // add a newline - t = strcat(t, "\n"); - lleft = l; - } - else - { - // otherwise just add a space if there's already text in - // this line - if (lleft != l) - t = strcat(t, " "); - } - t = strcat(t, word); - word = ""; - } - if (dowhat == 0) - { - // if this is a double space, add the space - if (lleft) - t = strcat(t, " "); - } - else if (dowhat == 1) - { - t = strcat(t, "\n"); - lleft = l; - } - } - // we need to keep these tempstrings alive even if substring is - // called repeatedly, so call strcat even though we're not doing - // anything - t = strcat(t); - word = strcat(word); - } - return t; -*/ - -/* - string t; - string word; - - float lleft; - float i; - - float startidx; - - startidx = 0; - - t = ""; - - lleft = l; - for(i = 0; i <= strlen(s); ++i) - { - if(i != strlen(s) && substring(s, i, 1) != " ") - { - // we need to keep this tempstring alive even if substring is - // called repeatedly, so call strcat even though we're not doing - // anything - t = strcat(t); - continue; - } - - word = substring(s, startidx, i - startidx); - startidx = i + 1; - - if(word == "+++") - { - t = strcat(t, "\n\n"); - lleft = l; - } - else if(!l || (strlen(word) < lleft)) - { - if(lleft != l) - { - t = strcat(t, " "); - lleft = lleft - 1; - } - t = strcat(t, word); - lleft = lleft - strlen(word); - } - else - { - t = strcat(t, "\n", word); - lleft = l - strlen(word); - } - } - return t; -*/ } float dist_point_line(vector p, vector l0, vector ldir) diff --git a/data/qcsrc/common/util.qh b/data/qcsrc/common/util.qh index eabf21da5..14c237ded 100644 --- a/data/qcsrc/common/util.qh +++ b/data/qcsrc/common/util.qh @@ -2,3 +2,7 @@ // this returns a tempstring containing a copy of s with additional \n newlines added, it also replaces \n in the text with a real newline // NOTE: s IS allowed to be a tempstring string wordwrap(string s, float l); +#ifndef MENUQC +void wordwrap_sprint(string s, float l); +#endif +void wordwrap_cb(string s, float l, void(string) callback) diff --git a/data/qcsrc/menu/msys.qc b/data/qcsrc/menu/msys.qc index 4e00cdd7a..92c706307 100644 --- a/data/qcsrc/menu/msys.qc +++ b/data/qcsrc/menu/msys.qc @@ -1,4 +1,5 @@ #pragma flag off fastarrays // make dp behave with new fteqcc versions. remove when dp bug with fteqcc fastarrays is fixed +#define MENUQC // so common/*.qc can check for menu QC or game QC ////////////////////////////////////////////////////////// // sys globals diff --git a/data/qcsrc/server/clientcommands.qc b/data/qcsrc/server/clientcommands.qc index 0f4f1e1c9..52eedf867 100644 --- a/data/qcsrc/server/clientcommands.qc +++ b/data/qcsrc/server/clientcommands.qc @@ -80,6 +80,7 @@ void Say(entity source, float teamsay, string msgin) void SV_ParseClientCommand(string s) { local float index; + local string cmd; tokenize(s); @@ -357,8 +358,13 @@ void SV_ParseClientCommand(string s) { } else if(argv(0) == "say_team") { Say(self, TRUE, substring(s, 9, strlen(s) - 9)); //clientcommand(self, formatmessage(s)); + } else if(argv(0) == "info") { + cmd = cvar_string(strcat("sv_info_", argv(1))); + if(cmd == "") + sprint(self, "ERROR: unsupported info command\n"); + else + wordwrap_sprint(cmd, 1111); } else { - string cmd; cmd = argv(0); if(cmd != "status") if(cmd != "name") -- 2.39.2