2000-05-20 09:42:02 +00:00
|
|
|
/*
|
|
|
|
info.c
|
|
|
|
|
|
|
|
(description)
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2000-12-08 06:51:37 +00:00
|
|
|
# include "config.h"
|
2000-05-20 09:42:02 +00:00
|
|
|
#endif
|
2000-12-30 02:16:36 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
2001-02-07 05:45:59 +00:00
|
|
|
# include <string.h>
|
2000-12-30 02:16:36 +00:00
|
|
|
#endif
|
2000-05-26 03:55:27 +00:00
|
|
|
#ifdef HAVE_STRINGS_H
|
2001-02-07 05:45:59 +00:00
|
|
|
# include <strings.h>
|
2000-05-26 03:55:27 +00:00
|
|
|
#endif
|
2000-05-20 09:42:02 +00:00
|
|
|
|
2001-02-07 05:45:59 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
2001-03-09 08:25:39 +00:00
|
|
|
#include "compat.h"
|
2000-12-30 02:16:36 +00:00
|
|
|
#include "console.h"
|
|
|
|
#include "info.h"
|
|
|
|
|
2000-05-20 09:42:02 +00:00
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
INFO STRINGS
|
2000-05-20 09:42:02 +00:00
|
|
|
*/
|
|
|
|
|
2001-03-09 08:25:39 +00:00
|
|
|
const static char *client_info_filters[] = { // Info keys needed by client
|
|
|
|
"name",
|
|
|
|
"topcolor",
|
|
|
|
"bottomcolor",
|
|
|
|
"rate",
|
|
|
|
"msg",
|
|
|
|
"skin",
|
|
|
|
"team",
|
|
|
|
"noaim",
|
|
|
|
"pmodel",
|
|
|
|
"emodel",
|
|
|
|
"spectator",
|
|
|
|
"*spectator",
|
|
|
|
"*ver",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Info_FilterForKey
|
|
|
|
|
|
|
|
Searches for key in the "client-needed" info string list
|
|
|
|
*/
|
|
|
|
qboolean
|
|
|
|
Info_FilterForKey (const char *key)
|
|
|
|
{
|
|
|
|
const char **s;
|
|
|
|
|
|
|
|
for (s = client_info_filters; *s; s++) {
|
|
|
|
if (strequal (*s, key)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2000-05-20 09:42:02 +00:00
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Info_ValueForKey
|
2000-05-20 09:42:02 +00:00
|
|
|
|
2001-02-09 02:53:09 +00:00
|
|
|
Searches the string for the given
|
|
|
|
key and returns the associated value, or an empty string.
|
2000-05-20 09:42:02 +00:00
|
|
|
*/
|
2001-03-09 08:25:39 +00:00
|
|
|
char *
|
2000-12-08 06:51:37 +00:00
|
|
|
Info_ValueForKey (char *s, char *key)
|
2000-05-20 09:42:02 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
char pkey[512];
|
|
|
|
static char value[4][512]; // use two buffers so compares
|
|
|
|
|
|
|
|
// work without stomping on each other
|
|
|
|
static int valueindex;
|
|
|
|
char *o;
|
|
|
|
|
2000-05-20 09:42:02 +00:00
|
|
|
valueindex = (valueindex + 1) % 4;
|
|
|
|
if (*s == '\\')
|
|
|
|
s++;
|
2000-12-08 06:51:37 +00:00
|
|
|
while (1) {
|
2000-05-20 09:42:02 +00:00
|
|
|
o = pkey;
|
2000-12-08 06:51:37 +00:00
|
|
|
while (*s != '\\') {
|
2000-05-20 09:42:02 +00:00
|
|
|
if (!*s)
|
|
|
|
return "";
|
|
|
|
*o++ = *s++;
|
|
|
|
}
|
|
|
|
*o = 0;
|
|
|
|
s++;
|
|
|
|
|
|
|
|
o = value[valueindex];
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
while (*s != '\\' && *s) {
|
2000-05-20 09:42:02 +00:00
|
|
|
if (!*s)
|
|
|
|
return "";
|
|
|
|
*o++ = *s++;
|
|
|
|
}
|
|
|
|
*o = 0;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!strcmp (key, pkey))
|
2000-05-20 09:42:02 +00:00
|
|
|
return value[valueindex];
|
|
|
|
|
|
|
|
if (!*s)
|
|
|
|
return "";
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Info_RemoveKey (char *s, char *key)
|
2000-05-20 09:42:02 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
char *start;
|
|
|
|
char pkey[512];
|
|
|
|
char value[512];
|
|
|
|
char *o;
|
2000-05-20 09:42:02 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (strstr (key, "\\")) {
|
2000-05-20 09:42:02 +00:00
|
|
|
Con_Printf ("Can't use a key with a \\\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
while (1) {
|
2000-05-20 09:42:02 +00:00
|
|
|
start = s;
|
|
|
|
if (*s == '\\')
|
|
|
|
s++;
|
|
|
|
o = pkey;
|
2000-12-08 06:51:37 +00:00
|
|
|
while (*s != '\\') {
|
2000-05-20 09:42:02 +00:00
|
|
|
if (!*s)
|
|
|
|
return;
|
|
|
|
*o++ = *s++;
|
|
|
|
}
|
|
|
|
*o = 0;
|
|
|
|
s++;
|
|
|
|
|
|
|
|
o = value;
|
2000-12-08 06:51:37 +00:00
|
|
|
while (*s != '\\' && *s) {
|
2000-05-20 09:42:02 +00:00
|
|
|
if (!*s)
|
|
|
|
return;
|
|
|
|
*o++ = *s++;
|
|
|
|
}
|
|
|
|
*o = 0;
|
|
|
|
|
2001-03-09 08:25:39 +00:00
|
|
|
if (strequal (key, pkey)) {
|
2000-12-08 06:51:37 +00:00
|
|
|
strcpy (start, s); // remove this part
|
2000-05-20 09:42:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!*s)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Info_RemovePrefixedKeys (char *start, char prefix)
|
2000-05-20 09:42:02 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
char *s;
|
|
|
|
char pkey[512];
|
|
|
|
char value[512];
|
|
|
|
char *o;
|
2000-05-20 09:42:02 +00:00
|
|
|
|
|
|
|
s = start;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
while (1) {
|
2000-05-20 09:42:02 +00:00
|
|
|
if (*s == '\\')
|
|
|
|
s++;
|
|
|
|
o = pkey;
|
2000-12-08 06:51:37 +00:00
|
|
|
while (*s != '\\') {
|
2000-05-20 09:42:02 +00:00
|
|
|
if (!*s)
|
|
|
|
return;
|
|
|
|
*o++ = *s++;
|
|
|
|
}
|
|
|
|
*o = 0;
|
|
|
|
s++;
|
|
|
|
|
|
|
|
o = value;
|
2000-12-08 06:51:37 +00:00
|
|
|
while (*s != '\\' && *s) {
|
2000-05-20 09:42:02 +00:00
|
|
|
if (!*s)
|
|
|
|
return;
|
|
|
|
*o++ = *s++;
|
|
|
|
}
|
|
|
|
*o = 0;
|
|
|
|
|
2001-03-09 08:25:39 +00:00
|
|
|
if ((pkey[0] == prefix) || (!(Info_FilterForKey (pkey)))) {
|
2000-05-20 09:42:02 +00:00
|
|
|
Info_RemoveKey (start, pkey);
|
|
|
|
s = start;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!*s)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Info_SetValueForStarKey (char *s, char *key, char *value, size_t maxsize)
|
2000-05-20 09:42:02 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
char newstr[1024], *v;
|
|
|
|
int c, is_name, is_team;
|
2000-05-20 09:42:02 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (strstr (key, "\\") || strstr (value, "\\")) {
|
2000-05-20 09:42:02 +00:00
|
|
|
Con_Printf ("Can't use keys or values with a \\\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (strstr (key, "\"") || strstr (value, "\"")) {
|
2000-05-20 09:42:02 +00:00
|
|
|
Con_Printf ("Can't use keys or values with a \"\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (strlen (key) > 63 || strlen (value) > 63) {
|
2000-05-20 09:42:02 +00:00
|
|
|
Con_Printf ("Keys and values must be < 64 characters.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// this next line is kinda trippy
|
2000-12-08 06:51:37 +00:00
|
|
|
if (*(v = Info_ValueForKey (s, key))) {
|
|
|
|
// key exists, make sure we have enough room for new value, if we
|
|
|
|
// don't,
|
2000-05-20 09:42:02 +00:00
|
|
|
// don't change it!
|
2000-12-08 06:51:37 +00:00
|
|
|
if (strlen (value) - strlen (v) + strlen (s) > maxsize) {
|
2000-05-20 09:42:02 +00:00
|
|
|
Con_Printf ("Info string length exceeded\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Info_RemoveKey (s, key);
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!value || !strlen (value))
|
2000-05-20 09:42:02 +00:00
|
|
|
return;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
snprintf (newstr, sizeof (newstr), "\\%s\\%s", key, value);
|
2000-05-20 09:42:02 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if ((int) (strlen (newstr) + strlen (s)) > maxsize) {
|
2000-05-20 09:42:02 +00:00
|
|
|
Con_Printf ("Info string length exceeded\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// only copy ascii values
|
2000-12-08 06:51:37 +00:00
|
|
|
s += strlen (s);
|
2000-05-20 09:42:02 +00:00
|
|
|
v = newstr;
|
2001-05-23 08:08:49 +00:00
|
|
|
is_name = strcaseequal (key, "name");
|
|
|
|
is_team = strcaseequal (key, "team");
|
2000-12-08 06:51:37 +00:00
|
|
|
while (*v) {
|
|
|
|
c = (unsigned char) *v++;
|
2000-05-20 09:42:02 +00:00
|
|
|
// client only allows highbits on name
|
|
|
|
if (!is_name) {
|
|
|
|
c &= 127;
|
|
|
|
if (c < 32 || c > 127)
|
|
|
|
continue;
|
|
|
|
// auto lowercase team
|
|
|
|
if (is_team)
|
2000-12-08 06:51:37 +00:00
|
|
|
c = tolower (c);
|
2000-05-20 09:42:02 +00:00
|
|
|
}
|
|
|
|
if (c > 13)
|
|
|
|
*s++ = c;
|
|
|
|
}
|
|
|
|
*s = 0;
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Info_SetValueForKey (char *s, char *key, char *value, size_t maxsize)
|
2000-05-20 09:42:02 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
if (key[0] == '*') {
|
2000-05-20 09:42:02 +00:00
|
|
|
Con_Printf ("Can't set * keys\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Info_SetValueForStarKey (s, key, value, maxsize);
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Info_Print (char *s)
|
2000-05-20 09:42:02 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
char key[512];
|
|
|
|
char value[512];
|
|
|
|
char *o;
|
|
|
|
int l;
|
2000-05-20 09:42:02 +00:00
|
|
|
|
|
|
|
if (*s == '\\')
|
|
|
|
s++;
|
2000-12-08 06:51:37 +00:00
|
|
|
while (*s) {
|
2000-05-20 09:42:02 +00:00
|
|
|
o = key;
|
|
|
|
while (*s && *s != '\\')
|
|
|
|
*o++ = *s++;
|
|
|
|
|
|
|
|
l = o - key;
|
2000-12-08 06:51:37 +00:00
|
|
|
if (l < 20) {
|
|
|
|
memset (o, ' ', 20 - l);
|
2000-05-20 09:42:02 +00:00
|
|
|
key[20] = 0;
|
2000-12-08 06:51:37 +00:00
|
|
|
} else
|
2000-05-20 09:42:02 +00:00
|
|
|
*o = 0;
|
|
|
|
Con_Printf ("%s", key);
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!*s) {
|
2000-05-20 09:42:02 +00:00
|
|
|
Con_Printf ("MISSING VALUE\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
o = value;
|
|
|
|
s++;
|
|
|
|
while (*s && *s != '\\')
|
|
|
|
*o++ = *s++;
|
|
|
|
*o = 0;
|
|
|
|
|
|
|
|
if (*s)
|
|
|
|
s++;
|
|
|
|
Con_Printf ("%s\n", value);
|
|
|
|
}
|
|
|
|
}
|
2001-05-22 14:23:19 +00:00
|
|
|
|
|
|
|
qboolean
|
|
|
|
Info_Validate (char *s)
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
if (!s || *s == '\0')
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (p = s, count = 0; *p != '\0'; p++)
|
|
|
|
if (*p == '\\')
|
|
|
|
count++;
|
|
|
|
|
|
|
|
return (!(count % 2));
|
|
|
|
}
|
|
|
|
|