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.
This commit is contained in:
Brian Koropoff 2002-04-23 07:47:24 +00:00
parent 349fbf7150
commit 7f295d61ee
4 changed files with 36 additions and 16 deletions

View file

@ -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 // Returns a value to GIB so that it can be picked up for embedded commands
void Cmd_Return (const char *value); void Cmd_Return (const char *value);
// Generates a GIB error
void Cmd_Error (const char *message);
extern struct cvar_s *cmd_warncmd; extern struct cvar_s *cmd_warncmd;

View file

@ -52,6 +52,7 @@ static const char rcsid[] =
#include "QF/dstring.h" #include "QF/dstring.h"
#include "QF/exp.h" #include "QF/exp.h"
#include "QF/va.h" #include "QF/va.h"
#include "QF/info.h"
typedef struct cmdalias_s { typedef struct cmdalias_s {
struct cmdalias_s *next; 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 /*void
Cmd_FreeBuffer (cmd_buffer_t *del) 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 COMMAND BUFFER
@ -1017,9 +1020,9 @@ Cmd_ProcessTags (dstring_t * dstr)
if (dstr->str[i] == '<' && !escaped (dstr->str, i)) { if (dstr->str[i] == '<' && !escaped (dstr->str, i)) {
close = 0; close = 0;
for (n = 1; for (n = 1;
dstr->str[i + n] != '>' || escaped (dstr->str, i + n); dstr->str[i+n] != '>' || escaped (dstr->str, i + n);
n++) n++)
if (dstr->str[n] == 0) if (dstr->str[i+n] == 0)
return; return;
if (dstr->str[i + 1] == '/') if (dstr->str[i + 1] == '/')
close = 1; close = 1;
@ -1313,7 +1316,6 @@ Cmd_ProcessToken (cmd_token_t *token)
{ {
int res; int res;
Cmd_ProcessTags (token->processed);
res = Cmd_ProcessEmbedded (token, token->processed); res = Cmd_ProcessEmbedded (token, token->processed);
if (res < 0) if (res < 0)
return res; return res;
@ -1323,6 +1325,7 @@ Cmd_ProcessToken (cmd_token_t *token)
res = Cmd_ProcessMath (token->processed); res = Cmd_ProcessMath (token->processed);
if (res < 0) if (res < 0)
return res; return res;
Cmd_ProcessTags (token->processed);
Cmd_ProcessEscapes (token->processed); Cmd_ProcessEscapes (token->processed);
return 0; return 0;
} }
@ -2025,7 +2028,8 @@ Cmd_Randint_f (void) {
} }
void void
Cmd_Streq_f (void) { Cmd_Streq_f (void)
{
if (Cmd_Argc () != 3) { if (Cmd_Argc () != 3) {
Cmd_Error ("streq: invalid number of arguments.\n"); Cmd_Error ("streq: invalid number of arguments.\n");
return; return;
@ -2034,7 +2038,8 @@ Cmd_Streq_f (void) {
} }
void void
Cmd_Strlen_f (void) { Cmd_Strlen_f (void)
{
if (Cmd_Argc () != 2) { if (Cmd_Argc () != 2) {
Cmd_Error ("strlen: invalid number of arguments.\n"); Cmd_Error ("strlen: invalid number of arguments.\n");
return; return;

View file

@ -107,14 +107,15 @@ void
dstring_replace (dstring_t *dstr, const char *data, unsigned int len, dstring_replace (dstring_t *dstr, const char *data, unsigned int len,
unsigned int pos, unsigned int rlen) unsigned int pos, unsigned int rlen)
{ {
unsigned int oldsize = dstr->size;
if (rlen < len) { if (rlen < len) {
dstr->size += len - rlen; dstr->size += len - rlen;
dstring_adjust (dstr); dstring_adjust (dstr);
memmove (dstr->str + pos + len, dstr->str + pos + rlen, memmove (dstr->str + pos + len, dstr->str + pos + rlen,
dstr->size - (pos + rlen)); oldsize - (pos + rlen));
} else if (rlen > len) { } else if (rlen > len) {
memmove (dstr->str + pos + len, dstr->str + pos + rlen, memmove (dstr->str + pos + len, dstr->str + pos + rlen,
dstr->size - (pos + rlen)); oldsize - (pos + rlen));
dstr->size -= rlen - len; dstr->size -= rlen - len;
dstring_adjust (dstr); dstring_adjust (dstr);
} }

View file

@ -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 void
CL_AddQFInfoKeys (void) CL_AddQFInfoKeys (void)
{ {
@ -1192,6 +1202,8 @@ CL_Init (void)
"set setinfo variables"); "set setinfo variables");
Cmd_AddCommand ("fullserverinfo", CL_FullServerinfo_f, "Used by GameSpy " Cmd_AddCommand ("fullserverinfo", CL_FullServerinfo_f, "Used by GameSpy "
"and Qlist to obtain server variables"); "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 " Cmd_AddCommand ("download", CL_Download_f, "Manually download a quake "
"file from the server"); "file from the server");
Cmd_AddCommand ("nextul", CL_NextUpload, "Tells the client to send the " Cmd_AddCommand ("nextul", CL_NextUpload, "Tells the client to send the "