2005-09-25 04:49:02 +00:00
|
|
|
/*
|
|
|
|
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
|
2005-09-25 20:50:57 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
2005-09-25 04:49:02 +00:00
|
|
|
|
|
|
|
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 the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2005-09-24 04:45:24 +00:00
|
|
|
#include "qtv.h"
|
|
|
|
|
|
|
|
#define MAX_INFO_KEY 64
|
|
|
|
|
|
|
|
char *Info_ValueForKey (char *s, const char *key, char *buffer, int buffersize)
|
|
|
|
{
|
|
|
|
char pkey[1024];
|
|
|
|
char *o;
|
2005-09-25 20:50:57 +00:00
|
|
|
|
2005-09-24 04:45:24 +00:00
|
|
|
if (*s == '\\')
|
|
|
|
s++;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
o = pkey;
|
|
|
|
while (*s != '\\')
|
|
|
|
{
|
|
|
|
if (!*s)
|
|
|
|
{
|
|
|
|
*buffer='\0';
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
*o++ = *s++;
|
|
|
|
if (o+2 >= pkey+sizeof(pkey)) //hrm. hackers at work..
|
|
|
|
{
|
|
|
|
*buffer='\0';
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*o = 0;
|
|
|
|
s++;
|
|
|
|
|
|
|
|
o = buffer;
|
|
|
|
|
|
|
|
while (*s != '\\' && *s)
|
|
|
|
{
|
|
|
|
if (!*s)
|
|
|
|
{
|
|
|
|
*buffer='\0';
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
*o++ = *s++;
|
2005-09-25 20:50:57 +00:00
|
|
|
|
2005-09-24 04:45:24 +00:00
|
|
|
if (o+2 >= buffer+buffersize) //hrm. hackers at work..
|
|
|
|
{
|
|
|
|
*buffer='\0';
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*o = 0;
|
|
|
|
|
|
|
|
if (!strcmp (key, pkey) )
|
|
|
|
return buffer;
|
|
|
|
|
|
|
|
if (!*s)
|
|
|
|
{
|
|
|
|
*buffer='\0';
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Info_RemoveKey (char *s, const char *key)
|
|
|
|
{
|
|
|
|
char *start;
|
|
|
|
char pkey[1024];
|
|
|
|
char value[1024];
|
|
|
|
char *o;
|
|
|
|
|
|
|
|
if (strstr (key, "\\"))
|
|
|
|
{
|
2005-10-07 02:02:15 +00:00
|
|
|
// printf ("Key has a slash\n");
|
2005-09-24 04:45:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
start = s;
|
|
|
|
if (*s == '\\')
|
|
|
|
s++;
|
|
|
|
o = pkey;
|
|
|
|
while (*s != '\\')
|
|
|
|
{
|
|
|
|
if (!*s)
|
|
|
|
return;
|
|
|
|
*o++ = *s++;
|
|
|
|
}
|
|
|
|
*o = 0;
|
|
|
|
s++;
|
|
|
|
|
|
|
|
o = value;
|
|
|
|
while (*s != '\\' && *s)
|
|
|
|
{
|
|
|
|
if (!*s)
|
|
|
|
return;
|
|
|
|
*o++ = *s++;
|
|
|
|
}
|
|
|
|
*o = 0;
|
|
|
|
|
|
|
|
if (!strcmp (key, pkey) )
|
|
|
|
{
|
|
|
|
strcpy (start, s); // remove this part
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!*s)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Info_SetValueForStarKey (char *s, const char *key, const char *value, int maxsize)
|
|
|
|
{
|
|
|
|
char newv[1024], *v;
|
|
|
|
int c;
|
|
|
|
#ifdef SERVERONLY
|
|
|
|
extern cvar_t sv_highchars;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (strstr (key, "\\") || strstr (value, "\\") )
|
|
|
|
{
|
2005-10-07 02:02:15 +00:00
|
|
|
// printf ("Key has a slash\n");
|
2005-09-24 04:45:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strstr (key, "\"") || strstr (value, "\"") )
|
|
|
|
{
|
2005-10-07 02:02:15 +00:00
|
|
|
// printf ("Key has a quote\n");
|
2005-09-24 04:45:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(key) >= MAX_INFO_KEY || strlen(value) >= MAX_INFO_KEY)
|
|
|
|
{
|
2005-10-07 02:02:15 +00:00
|
|
|
// printf ("Key or value is too long\n");
|
2005-09-24 04:45:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// this next line is kinda trippy
|
|
|
|
/* if (*(v = Info_ValueForKey(s, key)))
|
|
|
|
{
|
|
|
|
// key exists, make sure we have enough room for new value, if we don't,
|
|
|
|
// don't change it!
|
|
|
|
if (strlen(value) - strlen(v) + strlen(s) + 1 > maxsize)
|
|
|
|
{
|
|
|
|
Con_TPrintf (TL_INFOSTRINGTOOLONG);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
Info_RemoveKey (s, key);
|
|
|
|
if (!value || !strlen(value))
|
|
|
|
return;
|
|
|
|
|
2005-09-25 20:50:57 +00:00
|
|
|
snprintf (newv, sizeof(newv)-1, "\\%s\\%s", key, value);
|
2005-09-24 04:45:24 +00:00
|
|
|
|
|
|
|
if ((int)(strlen(newv) + strlen(s) + 1) > maxsize)
|
|
|
|
{
|
2005-10-07 02:02:15 +00:00
|
|
|
// printf ("info buffer is too small\n");
|
2005-09-24 04:45:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// only copy ascii values
|
|
|
|
s += strlen(s);
|
|
|
|
v = newv;
|
|
|
|
while (*v)
|
|
|
|
{
|
|
|
|
c = (unsigned char)*v++;
|
|
|
|
|
|
|
|
// c &= 127; // strip high bits
|
|
|
|
if (c > 13) // && c < 127)
|
|
|
|
*s++ = c;
|
|
|
|
}
|
|
|
|
*s = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define DEFAULT_PUNCTUATION "(,{})(\':;=!><&|+"
|
|
|
|
|
|
|
|
char *COM_ParseToken (char *data, char *out, int outsize, const char *punctuation)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (!punctuation)
|
|
|
|
punctuation = DEFAULT_PUNCTUATION;
|
2005-09-25 20:50:57 +00:00
|
|
|
|
2005-09-24 04:45:24 +00:00
|
|
|
len = 0;
|
|
|
|
out[0] = 0;
|
2005-09-25 20:50:57 +00:00
|
|
|
|
2005-09-24 04:45:24 +00:00
|
|
|
if (!data)
|
|
|
|
return NULL;
|
2005-09-25 20:50:57 +00:00
|
|
|
|
2005-09-24 04:45:24 +00:00
|
|
|
// skip whitespace
|
|
|
|
skipwhite:
|
|
|
|
while ( (c = *data) <= ' ')
|
|
|
|
{
|
|
|
|
if (c == 0)
|
|
|
|
return NULL; // end of file;
|
|
|
|
data++;
|
|
|
|
}
|
2005-09-25 20:50:57 +00:00
|
|
|
|
2005-09-24 04:45:24 +00:00
|
|
|
// skip // comments
|
|
|
|
if (c=='/')
|
|
|
|
{
|
|
|
|
if (data[1] == '/')
|
|
|
|
{
|
|
|
|
while (*data && *data != '\n')
|
|
|
|
data++;
|
|
|
|
goto skipwhite;
|
|
|
|
}
|
|
|
|
else if (data[1] == '*')
|
|
|
|
{
|
|
|
|
data+=2;
|
|
|
|
while (*data && (*data != '*' || data[1] != '/'))
|
|
|
|
data++;
|
|
|
|
data+=2;
|
|
|
|
goto skipwhite;
|
|
|
|
}
|
|
|
|
}
|
2005-09-25 20:50:57 +00:00
|
|
|
|
2005-09-24 04:45:24 +00:00
|
|
|
|
|
|
|
// handle quoted strings specially
|
|
|
|
if (c == '\"')
|
|
|
|
{
|
|
|
|
data++;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if (len >= outsize-1)
|
|
|
|
{
|
|
|
|
out[len] = '\0';
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
c = *data++;
|
|
|
|
if (c=='\"' || !c)
|
|
|
|
{
|
|
|
|
out[len] = 0;
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
out[len] = c;
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse single characters
|
|
|
|
if (strchr(punctuation, c))
|
|
|
|
{
|
|
|
|
out[len] = c;
|
|
|
|
len++;
|
|
|
|
out[len] = 0;
|
|
|
|
return data+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse a regular word
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (len >= outsize-1)
|
|
|
|
break;
|
|
|
|
out[len] = c;
|
|
|
|
data++;
|
|
|
|
len++;
|
|
|
|
c = *data;
|
|
|
|
if (strchr(punctuation, c))
|
|
|
|
break;
|
|
|
|
} while (c>32);
|
2005-09-25 20:50:57 +00:00
|
|
|
|
2005-09-24 04:45:24 +00:00
|
|
|
out[len] = 0;
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_ARGS 8
|
|
|
|
#define ARG_LEN 512
|
2005-10-07 02:02:15 +00:00
|
|
|
char *Cluster_Rcon_Dispatch(cluster_t *cluster, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
|
|
|
if (!strcmp(arg[0], "hostname"))
|
|
|
|
{
|
|
|
|
strncpy(cluster->hostname, arg[1], sizeof(cluster->hostname)-1);
|
|
|
|
return "hostname will change at start of next map\n"; //I'm too lazy to alter the serverinfo here.
|
|
|
|
}
|
|
|
|
else if (!strcmp(arg[0], "master"))
|
|
|
|
{
|
|
|
|
netadr_t addr;
|
|
|
|
|
|
|
|
strncpy(cluster->master, arg[1], sizeof(cluster->master)-1);
|
|
|
|
cluster->mastersendtime = cluster->curtime;
|
|
|
|
|
|
|
|
if (NET_StringToAddr(arg[1], &addr)) //send a ping like a qw server does. this is kinda pointless of course.
|
|
|
|
NET_SendPacket (cluster, cluster->qwdsocket, 1, "k", addr);
|
|
|
|
|
|
|
|
return "Master server set.\n";
|
|
|
|
}
|
|
|
|
else if (!strcmp(arg[0], "port"))
|
|
|
|
{
|
|
|
|
int news;
|
|
|
|
int newp = atoi(arg[1]);
|
|
|
|
news = QW_InitUDPSocket(newp);
|
|
|
|
|
|
|
|
if (news != INVALID_SOCKET)
|
|
|
|
{
|
|
|
|
cluster->mastersendtime = cluster->curtime;
|
|
|
|
closesocket(cluster->qwdsocket);
|
|
|
|
cluster->qwdsocket = news;
|
|
|
|
cluster->qwlistenportnum = newp;
|
|
|
|
return "Opened udp port (all connected qw clients will time out)\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return "Failed to open udp port\n";
|
|
|
|
}
|
|
|
|
else if (!strcmp(arg[0], "password"))
|
|
|
|
{
|
|
|
|
if (!localcommand)
|
|
|
|
return "Rejecting rcon password change.\n";
|
|
|
|
|
|
|
|
strncpy(cluster->password, arg[1], sizeof(cluster->password)-1);
|
|
|
|
return "Password changed.\n";
|
|
|
|
}
|
2006-02-21 23:25:54 +00:00
|
|
|
else if (!strcmp(arg[0], "qtv") || !strcmp(arg[0], "connect") || !strcmp(arg[0], "addserver"))
|
2005-10-07 02:02:15 +00:00
|
|
|
{
|
|
|
|
if (!*arg[1])
|
|
|
|
return "connect requires an ip:port parameter\n";
|
|
|
|
|
|
|
|
memmove(arg[1]+4, arg[1], ARG_LEN-5);
|
|
|
|
strncpy(arg[1], "tcp:", 4);
|
|
|
|
|
2006-02-21 19:55:12 +00:00
|
|
|
if (!QTV_NewServerConnection(cluster, arg[1], false, !strcmp(arg[0], "connect")))
|
|
|
|
return "Failed to connect to server, connection aborted\n";
|
|
|
|
return "Connection registered\n";
|
|
|
|
}
|
|
|
|
else if (!strcmp(arg[0], "qw"))
|
|
|
|
{
|
|
|
|
if (!*arg[1])
|
|
|
|
return "connect requires an ip:port parameter\n";
|
|
|
|
|
|
|
|
memmove(arg[1]+4, arg[1], ARG_LEN-5);
|
|
|
|
strncpy(arg[1], "udp:", 4);
|
|
|
|
|
|
|
|
if (!QTV_NewServerConnection(cluster, arg[1], false, false))
|
2005-10-07 02:02:15 +00:00
|
|
|
return "Failed to connect to server, connection aborted\n";
|
|
|
|
return "Connection registered\n";
|
|
|
|
}
|
|
|
|
else if (!strcmp(arg[0], "demo") || !strcmp(arg[0], "adddemo") || !strcmp(arg[0], "addfile"))
|
|
|
|
{
|
|
|
|
if (!*arg[1])
|
|
|
|
return "adddemo requires an filename parameter\n";
|
|
|
|
|
|
|
|
if (!localcommand)
|
|
|
|
if (*arg[1] == '\\' || *arg[1] == '/' || strstr(arg[1], "..") || arg[1][1] == ':')
|
|
|
|
return "Absolute paths are prohibited.\n";
|
|
|
|
|
|
|
|
memmove(arg[1]+5, arg[1], ARG_LEN-6);
|
|
|
|
strncpy(arg[1], "file:", 5);
|
|
|
|
|
2006-02-21 19:55:12 +00:00
|
|
|
if (!QTV_NewServerConnection(cluster, arg[1], false, false))
|
2005-10-07 02:02:15 +00:00
|
|
|
return "Failed to connect to server, connection aborted\n";
|
|
|
|
return "Connection registered\n";
|
|
|
|
}
|
|
|
|
else if (!strcmp(arg[0], "exec"))
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
char line[512], *res;
|
|
|
|
|
|
|
|
if (!localcommand)
|
|
|
|
if (*arg[1] == '\\' || *arg[1] == '/' || strstr(arg[1], "..") || arg[1][1] == ':')
|
|
|
|
return "Absolute paths are prohibited.\n";
|
|
|
|
|
|
|
|
f = fopen(arg[1], "rt");
|
|
|
|
if (!f)
|
|
|
|
{
|
|
|
|
snprintf(buffer, sizeofbuffer, "Couldn't exec \"%s\"\n", arg[1]);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while(fgets(line, sizeof(line)-1, f))
|
|
|
|
{
|
|
|
|
res = Rcon_Command(cluster, NULL, line, buffer, sizeofbuffer, localcommand);
|
|
|
|
Sys_Printf(cluster, "%s", res);
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
return "Execed\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!strcmp(arg[0], "status"))
|
|
|
|
{
|
|
|
|
buffer[0] = '\0';
|
|
|
|
|
|
|
|
sprintf(buffer, "%i connections\n", cluster->numservers);
|
|
|
|
|
|
|
|
strcat(buffer, "Options:\n");
|
|
|
|
if (cluster->chokeonnotupdated)
|
|
|
|
strcat(buffer, " Choke\n");
|
|
|
|
if (cluster->lateforward)
|
|
|
|
strcat(buffer, " Late forwarding\n");
|
|
|
|
if (!cluster->notalking)
|
|
|
|
strcat(buffer, " Talking allowed\n");
|
|
|
|
if (cluster->nobsp)
|
|
|
|
strcat(buffer, " No BSP loading\n");
|
|
|
|
strcat(buffer, "\n");
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
else if (!strcmp(arg[0], "choke"))
|
|
|
|
{
|
|
|
|
cluster->chokeonnotupdated = !!atoi(arg[1]);
|
|
|
|
return "choke-until-update set\n";
|
|
|
|
}
|
|
|
|
else if (!strcmp(arg[0], "late"))
|
|
|
|
{
|
|
|
|
cluster->lateforward = !!atoi(arg[1]);
|
|
|
|
return "late forwarding set\n";
|
|
|
|
}
|
|
|
|
else if (!strcmp(arg[0], "talking"))
|
|
|
|
{
|
|
|
|
cluster->notalking = !atoi(arg[1]);
|
|
|
|
return "talking permissions set\n";
|
|
|
|
}
|
|
|
|
else if (!strcmp(arg[0], "nobsp"))
|
|
|
|
{
|
|
|
|
cluster->nobsp = !!atoi(arg[1]);
|
|
|
|
return "nobsp will change at start of next map\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (!strcmp(arg[1], "maxviewers"))
|
|
|
|
{
|
|
|
|
cluster->maxviewers = atoi(arg[2]);
|
|
|
|
return "maxviewers set\n";
|
|
|
|
}
|
|
|
|
else if (!strcmp(arg[1], "maxproxies"))
|
|
|
|
{
|
|
|
|
cluster->maxproxies = atoi(arg[2]);
|
|
|
|
return "maxproxies set\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
else if (!strcmp(arg[0], "ping"))
|
|
|
|
{
|
|
|
|
netadr_t addr;
|
|
|
|
if (NET_StringToAddr(arg[1], &addr))
|
|
|
|
{
|
|
|
|
NET_SendPacket (cluster, cluster->qwdsocket, 1, "k", addr);
|
|
|
|
return "pinged\n";
|
|
|
|
}
|
|
|
|
return "couldn't resolve\n";
|
|
|
|
}
|
|
|
|
else if (!strcmp(arg[0], "help"))
|
|
|
|
{
|
|
|
|
return "FTEQTV proxy\nValid commands: connect, addserver, adddemo, status, choke, late, talking, nobsp, exec, password, master, hostname, port, maxviewers, maxproxies\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (!strcmp(arg[0], "mvdport"))
|
|
|
|
{
|
|
|
|
return "mvdport requires a targeted server. Connect first.\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (!strcmp(arg[0], "record"))
|
|
|
|
{
|
|
|
|
return "record requires a targeted server\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (!strcmp(arg[0], "reconnect"))
|
|
|
|
{
|
|
|
|
return "reconnect requires a targeted server\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (!strcmp(arg[0], "stop"))
|
|
|
|
{ //fixme
|
|
|
|
return "stop requires a targeted server\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (!strcmp(arg[0], "echo"))
|
|
|
|
{
|
|
|
|
return "Poly wants a cracker.\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (!strcmp(arg[0], "quit"))
|
|
|
|
{
|
|
|
|
cluster->wanttoexit = true;
|
|
|
|
return "Shutting down.\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *Server_Rcon_Dispatch(sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
|
|
|
#define TOKENIZE_PUNCTUATION ""
|
2005-09-24 04:45:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
buffer[0] = '\0';
|
|
|
|
if (!strcmp(arg[0], "status"))
|
|
|
|
{
|
2005-10-07 02:02:15 +00:00
|
|
|
sprintf(buffer, "%i connections\n", qtv->cluster->numservers);
|
|
|
|
|
2005-09-24 04:45:24 +00:00
|
|
|
strcat(buffer, "\n");
|
2005-10-07 02:02:15 +00:00
|
|
|
strcat(buffer, "Selected server: ");
|
2005-09-24 04:45:24 +00:00
|
|
|
strcat(buffer, qtv->server);
|
|
|
|
strcat(buffer, "\n");
|
|
|
|
if (qtv->file)
|
|
|
|
strcat(buffer, "Playing from file\n");
|
|
|
|
if (qtv->sourcesock != INVALID_SOCKET)
|
|
|
|
strcat(buffer, "Connected\n");
|
|
|
|
if (qtv->parsingconnectiondata)
|
|
|
|
strcat(buffer, "Waiting for gamestate\n");
|
|
|
|
|
|
|
|
if (qtv->listenmvd != INVALID_SOCKET)
|
2005-09-24 21:36:06 +00:00
|
|
|
{
|
|
|
|
strcat(buffer, "Listening for proxies (");
|
|
|
|
sprintf(arg[0], "%i", qtv->tcplistenportnum);
|
|
|
|
strcat(buffer, arg[0]);
|
|
|
|
strcat(buffer, ")\n");
|
|
|
|
}
|
2005-09-24 04:45:24 +00:00
|
|
|
|
|
|
|
if (qtv->bsp)
|
|
|
|
{
|
|
|
|
strcat(buffer, "BSP (");
|
|
|
|
strcat(buffer, qtv->mapname);
|
|
|
|
strcat(buffer, ") is loaded\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
strcat(buffer, "Options:\n");
|
2005-10-07 02:02:15 +00:00
|
|
|
if (qtv->cluster->chokeonnotupdated)
|
2005-09-24 04:45:24 +00:00
|
|
|
strcat(buffer, " Choke\n");
|
2005-10-07 02:02:15 +00:00
|
|
|
if (qtv->cluster->lateforward)
|
2005-09-24 04:45:24 +00:00
|
|
|
strcat(buffer, " Late forwarding\n");
|
2005-10-07 02:02:15 +00:00
|
|
|
if (!qtv->cluster->notalking)
|
2005-09-24 04:45:24 +00:00
|
|
|
strcat(buffer, " Talking allowed\n");
|
2005-10-07 02:02:15 +00:00
|
|
|
if (qtv->cluster->nobsp)
|
|
|
|
strcat(buffer, " No BSP loading\n");
|
2005-09-24 04:45:24 +00:00
|
|
|
strcat(buffer, "\n");
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
2005-09-24 14:50:48 +00:00
|
|
|
|
2005-09-24 04:45:24 +00:00
|
|
|
else if (!strcmp(arg[0], "connect"))
|
|
|
|
{
|
|
|
|
if (!*arg[1])
|
|
|
|
return "connect requires an ip:port parameter\n";
|
|
|
|
|
|
|
|
if (QTV_Connect(qtv, arg[1]))
|
|
|
|
return "Connected, waiting for data\n";
|
|
|
|
else
|
|
|
|
return "Failed (will keep trying)\n";
|
|
|
|
}
|
2006-02-20 01:33:13 +00:00
|
|
|
|
|
|
|
else if (!strcmp(arg[0], "disconnect"))
|
|
|
|
{
|
|
|
|
QTV_Shutdown(qtv);
|
2006-02-21 19:55:12 +00:00
|
|
|
return "Disconnected\n";
|
2006-02-20 01:33:13 +00:00
|
|
|
}
|
|
|
|
|
2005-09-24 21:36:06 +00:00
|
|
|
else if (!strcmp(arg[0], "file") || !strcmp(arg[0], "play") || !strcmp(arg[0], "playdemo"))
|
2005-09-24 04:45:24 +00:00
|
|
|
{
|
|
|
|
if (!*arg[1])
|
|
|
|
return "file requires a filename on the proxy's machine\n";
|
|
|
|
|
|
|
|
if (!localcommand)
|
|
|
|
if (*arg[1] == '\\' || *arg[1] == '/' || strstr(arg[1], "..") || arg[1][1] == ':')
|
|
|
|
return "Absolute paths are prohibited.\n";
|
|
|
|
|
2005-10-07 02:02:15 +00:00
|
|
|
memmove(arg[1]+5, arg[1], ARG_LEN-6);
|
2005-09-24 04:45:24 +00:00
|
|
|
strncpy(arg[1], "file:", 5);
|
|
|
|
if (QTV_Connect(qtv, arg[1]))
|
|
|
|
return "File opened successfully\n";
|
|
|
|
else
|
|
|
|
return "Failed (will keep trying)\n";
|
|
|
|
}
|
2005-09-24 21:36:06 +00:00
|
|
|
else if (!strcmp(arg[0], "record"))
|
|
|
|
{
|
|
|
|
if (!*arg[1])
|
|
|
|
return "record requires a filename on the proxy's machine\n";
|
|
|
|
|
|
|
|
if (!localcommand)
|
|
|
|
if (*arg[1] == '\\' || *arg[1] == '/' || strstr(arg[1], "..") || arg[1][1] == ':')
|
|
|
|
return "Absolute paths are prohibited.\n";
|
|
|
|
|
|
|
|
if (Net_FileProxy(qtv, arg[1]))
|
|
|
|
return "Recording to disk\n";
|
|
|
|
else
|
|
|
|
return "Failed to open file\n";
|
|
|
|
}
|
|
|
|
else if (!strcmp(arg[0], "stop"))
|
|
|
|
{
|
|
|
|
if (Net_StopFileProxy(qtv))
|
|
|
|
return "stopped\n";
|
|
|
|
else
|
|
|
|
return "not recording to disk\n";
|
|
|
|
}
|
2005-10-07 02:02:15 +00:00
|
|
|
|
2005-09-24 04:45:24 +00:00
|
|
|
else if (!strcmp(arg[0], "reconnect"))
|
|
|
|
{
|
|
|
|
if (QTV_Connect(qtv, qtv->server))
|
|
|
|
return "Reconnected\n";
|
|
|
|
else
|
|
|
|
return "Failed to reconnect (will keep trying)\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (!strcmp(arg[0], "mvdport"))
|
|
|
|
{
|
|
|
|
int news;
|
|
|
|
int newp = atoi(arg[1]);
|
|
|
|
|
2005-09-25 20:50:57 +00:00
|
|
|
if (!newp)
|
2005-09-24 04:45:24 +00:00
|
|
|
{
|
2005-09-25 20:50:57 +00:00
|
|
|
if (qtv->listenmvd != INVALID_SOCKET)
|
|
|
|
{
|
|
|
|
closesocket(qtv->listenmvd);
|
|
|
|
qtv->listenmvd = INVALID_SOCKET;
|
|
|
|
qtv->tcplistenportnum = 0;
|
|
|
|
|
|
|
|
return "mvd port is now closed\n";
|
|
|
|
}
|
|
|
|
return "Already closed\n";
|
2005-09-24 04:45:24 +00:00
|
|
|
}
|
|
|
|
else
|
2005-09-25 20:50:57 +00:00
|
|
|
{
|
|
|
|
news = Net_MVDListen(newp);
|
|
|
|
|
|
|
|
if (news != INVALID_SOCKET)
|
|
|
|
{
|
2006-02-21 19:55:12 +00:00
|
|
|
if (qtv->listenmvd != INVALID_SOCKET)
|
|
|
|
closesocket(qtv->listenmvd);
|
2005-09-25 20:50:57 +00:00
|
|
|
qtv->listenmvd = news;
|
2006-02-21 19:55:12 +00:00
|
|
|
qtv->disconnectwhennooneiswatching = false;
|
2005-09-25 20:50:57 +00:00
|
|
|
qtv->tcplistenportnum = newp;
|
|
|
|
return "Opened tcp port\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return "Failed to open tcp port\n";
|
|
|
|
}
|
2005-09-24 04:45:24 +00:00
|
|
|
}
|
|
|
|
|
2005-10-07 02:02:15 +00:00
|
|
|
else if (!strcmp(arg[0], "exec"))
|
2005-09-24 04:45:24 +00:00
|
|
|
{
|
2005-10-07 02:02:15 +00:00
|
|
|
FILE *f;
|
|
|
|
char line[512], *res;
|
2005-09-24 04:45:24 +00:00
|
|
|
|
2005-09-25 20:50:57 +00:00
|
|
|
if (!localcommand)
|
2005-10-07 02:02:15 +00:00
|
|
|
if (*arg[1] == '\\' || *arg[1] == '/' || strstr(arg[1], "..") || arg[1][1] == ':')
|
|
|
|
return "Absolute paths are prohibited.\n";
|
2005-09-25 20:50:57 +00:00
|
|
|
|
2005-10-07 02:02:15 +00:00
|
|
|
f = fopen(arg[1], "rt");
|
|
|
|
if (!f)
|
2005-09-24 04:45:24 +00:00
|
|
|
{
|
2005-10-07 02:02:15 +00:00
|
|
|
snprintf(buffer, sizeofbuffer, "Couldn't exec \"%s\"\n", arg[1]);
|
|
|
|
return buffer;
|
2005-09-24 04:45:24 +00:00
|
|
|
}
|
|
|
|
else
|
2005-09-25 20:50:57 +00:00
|
|
|
{
|
2005-10-07 02:02:15 +00:00
|
|
|
while(fgets(line, sizeof(line)-1, f))
|
2005-09-25 20:50:57 +00:00
|
|
|
{
|
2005-10-07 02:02:15 +00:00
|
|
|
res = Rcon_Command(qtv->cluster, qtv, line, buffer, sizeofbuffer, localcommand);
|
|
|
|
Sys_Printf(qtv->cluster, "%s", res);
|
2005-09-25 20:50:57 +00:00
|
|
|
}
|
2005-10-07 02:02:15 +00:00
|
|
|
fclose(f);
|
|
|
|
return "Execed\n";
|
2005-09-25 20:50:57 +00:00
|
|
|
}
|
2005-09-24 04:45:24 +00:00
|
|
|
}
|
|
|
|
|
2005-10-07 02:02:15 +00:00
|
|
|
else
|
2005-09-24 04:45:24 +00:00
|
|
|
{
|
2005-10-07 02:02:15 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2005-09-24 04:45:24 +00:00
|
|
|
|
2005-10-07 02:02:15 +00:00
|
|
|
char *Rcon_Command(cluster_t *cluster, sv_t *qtv, char *command, char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
|
|
|
#define TOKENIZE_PUNCTUATION ""
|
|
|
|
|
|
|
|
int i;
|
|
|
|
char arg[MAX_ARGS][ARG_LEN];
|
|
|
|
char *argptrs[MAX_ARGS];
|
|
|
|
char *result;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_ARGS; i++)
|
|
|
|
{
|
|
|
|
command = COM_ParseToken(command, arg[i], ARG_LEN, TOKENIZE_PUNCTUATION);
|
|
|
|
argptrs[i] = arg[i];
|
2005-09-24 04:45:24 +00:00
|
|
|
}
|
|
|
|
|
2005-10-07 02:02:15 +00:00
|
|
|
if (qtv)
|
|
|
|
{ //if there is a specific connection targetted
|
|
|
|
result = Server_Rcon_Dispatch(qtv, argptrs, buffer, sizeofbuffer, localcommand);
|
|
|
|
if (result)
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
else if (cluster->numservers == 1)
|
|
|
|
{ //if it's a single-connection proxy
|
|
|
|
result = Server_Rcon_Dispatch(cluster->servers, argptrs, buffer, sizeofbuffer, localcommand);
|
|
|
|
if (result)
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = Cluster_Rcon_Dispatch(cluster, argptrs, buffer, sizeofbuffer, localcommand);
|
|
|
|
if (result)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
snprintf(buffer, sizeofbuffer, "Command \"%s\" not recognised.\n", arg[0]);
|
|
|
|
return buffer;
|
2005-09-24 04:45:24 +00:00
|
|
|
}
|
|
|
|
|