From 7f295d61ee446b4cd30d6f616540dca9e2d7c223 Mon Sep 17 00:00:00 2001 From: Brian Koropoff Date: Tue, 23 Apr 2002 07:47:24 +0000 Subject: [PATCH] Added the getserverinfo command to return the value of a server info key to GIB. Fixed a bug in dstring_replace that was causing too much data to be copied when the incoming string was larger than what was being replaced. Very minor reorganization in cmd.c (1 function moved around I think). cmd.c should probably get broken up into separate files soon. --- include/QF/cmd.h | 2 ++ libs/util/cmd.c | 33 +++++++++++++++++++-------------- libs/util/dstring.c | 5 +++-- qw/source/cl_main.c | 12 ++++++++++++ 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/include/QF/cmd.h b/include/QF/cmd.h index bba1143ea..a37b785e6 100644 --- a/include/QF/cmd.h +++ b/include/QF/cmd.h @@ -209,6 +209,8 @@ const char *COM_Parse (const char *data); // Returns a value to GIB so that it can be picked up for embedded commands void Cmd_Return (const char *value); +// Generates a GIB error +void Cmd_Error (const char *message); extern struct cvar_s *cmd_warncmd; diff --git a/libs/util/cmd.c b/libs/util/cmd.c index 2a68bb426..9eeaa3ef2 100644 --- a/libs/util/cmd.c +++ b/libs/util/cmd.c @@ -52,6 +52,7 @@ static const char rcsid[] = #include "QF/dstring.h" #include "QF/exp.h" #include "QF/va.h" +#include "QF/info.h" typedef struct cmdalias_s { struct cmdalias_s *next; @@ -215,14 +216,6 @@ Cmd_FreeStack (cmd_buffer_t *stack) { } } -void -Cmd_Return (const char *value) { - if (cmd_activebuffer->prev && cmd_activebuffer->prev->returned == cmd_waiting) { - dstring_clearstr (cmd_activebuffer->prev->retval); - dstring_appendstr (cmd_activebuffer->prev->retval, value); - cmd_activebuffer->prev->returned = cmd_returned; - } -} /*void Cmd_FreeBuffer (cmd_buffer_t *del) @@ -320,6 +313,16 @@ Cmd_Error (const char *message) } } +void +Cmd_Return (const char *value) { + if (cmd_activebuffer->prev && cmd_activebuffer->prev->returned == cmd_waiting) { + dstring_clearstr (cmd_activebuffer->prev->retval); + dstring_appendstr (cmd_activebuffer->prev->retval, value); + cmd_activebuffer->prev->returned = cmd_returned; + } +} + + /* COMMAND BUFFER @@ -1017,9 +1020,9 @@ Cmd_ProcessTags (dstring_t * dstr) if (dstr->str[i] == '<' && !escaped (dstr->str, i)) { close = 0; for (n = 1; - dstr->str[i + n] != '>' || escaped (dstr->str, i + n); + dstr->str[i+n] != '>' || escaped (dstr->str, i + n); n++) - if (dstr->str[n] == 0) + if (dstr->str[i+n] == 0) return; if (dstr->str[i + 1] == '/') close = 1; @@ -1312,8 +1315,7 @@ int Cmd_ProcessToken (cmd_token_t *token) { int res; - - Cmd_ProcessTags (token->processed); + res = Cmd_ProcessEmbedded (token, token->processed); if (res < 0) return res; @@ -1323,6 +1325,7 @@ Cmd_ProcessToken (cmd_token_t *token) res = Cmd_ProcessMath (token->processed); if (res < 0) return res; + Cmd_ProcessTags (token->processed); Cmd_ProcessEscapes (token->processed); return 0; } @@ -2025,7 +2028,8 @@ Cmd_Randint_f (void) { } void -Cmd_Streq_f (void) { +Cmd_Streq_f (void) +{ if (Cmd_Argc () != 3) { Cmd_Error ("streq: invalid number of arguments.\n"); return; @@ -2034,7 +2038,8 @@ Cmd_Streq_f (void) { } void -Cmd_Strlen_f (void) { +Cmd_Strlen_f (void) +{ if (Cmd_Argc () != 2) { Cmd_Error ("strlen: invalid number of arguments.\n"); return; diff --git a/libs/util/dstring.c b/libs/util/dstring.c index 6d30d498b..ee0262574 100644 --- a/libs/util/dstring.c +++ b/libs/util/dstring.c @@ -107,14 +107,15 @@ void dstring_replace (dstring_t *dstr, const char *data, unsigned int len, unsigned int pos, unsigned int rlen) { + unsigned int oldsize = dstr->size; if (rlen < len) { dstr->size += len - rlen; dstring_adjust (dstr); memmove (dstr->str + pos + len, dstr->str + pos + rlen, - dstr->size - (pos + rlen)); + oldsize - (pos + rlen)); } else if (rlen > len) { memmove (dstr->str + pos + len, dstr->str + pos + rlen, - dstr->size - (pos + rlen)); + oldsize - (pos + rlen)); dstr->size -= rlen - len; dstring_adjust (dstr); } diff --git a/qw/source/cl_main.c b/qw/source/cl_main.c index 8579f3cd1..a7bf9b8a4 100644 --- a/qw/source/cl_main.c +++ b/qw/source/cl_main.c @@ -615,6 +615,16 @@ CL_FullServerinfo_f (void) } } +void +CL_Getserverinfo_f (void) +{ + if (Cmd_Argc () != 2) { + Cmd_Error ("getserverinfo: invalid number of arguments.\n"); + return; + } + Cmd_Return (Info_ValueForKey (cl.serverinfo, Cmd_Argv(1))); +} + void CL_AddQFInfoKeys (void) { @@ -1192,6 +1202,8 @@ CL_Init (void) "set setinfo variables"); Cmd_AddCommand ("fullserverinfo", CL_FullServerinfo_f, "Used by GameSpy " "and Qlist to obtain server variables"); + Cmd_AddCommand ("getserverinfo", CL_Getserverinfo_f, "Returns the value corresponding to key" + " $1 in the server info."); Cmd_AddCommand ("download", CL_Download_f, "Manually download a quake " "file from the server"); Cmd_AddCommand ("nextul", CL_NextUpload, "Tells the client to send the "