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
|
|
|
|
|
2006-09-17 01:27:32 +00:00
|
|
|
//I apologise for this if it breaks your formatting or anything
|
2006-06-11 12:09:29 +00:00
|
|
|
#define HELPSTRING "\
|
|
|
|
FTEQTV proxy commands: (build "__DATE__")\n\
|
|
|
|
----------------------\n\
|
|
|
|
connect, qtv, addserver\n\
|
|
|
|
- connect to a MVD stream (TCP)\n\
|
|
|
|
qw\n\
|
|
|
|
- connect to a server as a player (UDP)\n\
|
|
|
|
adddemo\n\
|
|
|
|
- play a demo from a MVD file\n\
|
|
|
|
port\n\
|
|
|
|
- UDP port for QuakeWorld client connections\n\
|
|
|
|
mvdport\n\
|
|
|
|
- specify TCP port for MVD broadcasting\n\
|
|
|
|
maxviewers, maxproxies\n\
|
|
|
|
- limit number of connections\n\
|
|
|
|
status, choke, late, talking, nobsp, reconnect, exec, password, master, hostname, record, stop, quit\n\n"
|
|
|
|
|
2006-09-17 01:27:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-09-24 04:45:24 +00:00
|
|
|
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
|
2006-10-20 14:17:56 +00:00
|
|
|
if (*(v = Info_ValueForKey(s, key, newv, sizeof(newv))))
|
2005-09-24 04:45:24 +00:00
|
|
|
{
|
|
|
|
// 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)
|
|
|
|
{
|
2006-10-20 14:17:56 +00:00
|
|
|
// Con_TPrintf (TL_INFOSTRINGTOOLONG);
|
2005-09-24 04:45:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2006-10-20 14:17:56 +00:00
|
|
|
|
2005-09-24 04:45:24 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2006-09-17 01:27:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-09-24 04:45:24 +00:00
|
|
|
#define MAX_ARGS 8
|
|
|
|
#define ARG_LEN 512
|
2006-09-17 01:27:32 +00:00
|
|
|
typedef char *(*dispatchrconcommand_t)(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand);
|
|
|
|
|
|
|
|
char *Cmd_Hostname(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
2006-10-20 14:17:56 +00:00
|
|
|
if (!*arg[1])
|
|
|
|
{
|
|
|
|
buffer[0] = 0;
|
|
|
|
if (*cluster->hostname)
|
|
|
|
snprintf(buffer, sizeofbuffer, "Current hostname is %s\n", cluster->hostname);
|
|
|
|
else
|
|
|
|
return "No master server is currently set.\n";
|
|
|
|
return buffer;
|
|
|
|
}
|
2006-09-17 01:27:32 +00:00
|
|
|
strncpy(cluster->hostname, arg[1], sizeof(cluster->hostname)-1);
|
2006-10-20 14:17:56 +00:00
|
|
|
return "hostname set (might have a slight delay)\n"; //I'm too lazy to alter the serverinfo here.
|
2006-09-17 01:27:32 +00:00
|
|
|
}
|
|
|
|
char *Cmd_Master(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
|
|
|
netadr_t addr;
|
|
|
|
|
2006-10-20 14:17:56 +00:00
|
|
|
if (!*arg[1])
|
|
|
|
{
|
|
|
|
if (*cluster->master)
|
|
|
|
return "Subscribed to a master server (use '-' to clear)\n";
|
|
|
|
else
|
|
|
|
return "No master server is currently set.\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(arg[1], "-"))
|
|
|
|
{
|
|
|
|
strncpy(cluster->master, "", sizeof(cluster->master)-1);
|
|
|
|
return "Master server cleared\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!NET_StringToAddr(arg[1], &addr, 27000)) //send a ping like a qw server does. this is kinda pointless of course.
|
|
|
|
{
|
|
|
|
return "Couldn't resolve address\n";
|
|
|
|
}
|
|
|
|
|
2006-09-17 01:27:32 +00:00
|
|
|
strncpy(cluster->master, arg[1], sizeof(cluster->master)-1);
|
|
|
|
cluster->mastersendtime = cluster->curtime;
|
|
|
|
|
2006-10-20 14:17:56 +00:00
|
|
|
NET_SendPacket (cluster, cluster->qwdsocket, 1, "k", addr);
|
2006-09-17 01:27:32 +00:00
|
|
|
return "Master server set.\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char *Cmd_UDPPort(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
char *Cmd_AdminPassword(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
|
|
|
if (!localcommand)
|
|
|
|
return "Rejecting remote password change.\n";
|
|
|
|
|
2006-10-20 14:17:56 +00:00
|
|
|
if (!*arg[1])
|
|
|
|
{
|
|
|
|
if (*cluster->adminpassword)
|
|
|
|
return "An admin password is currently set\n";
|
|
|
|
else
|
|
|
|
return "No admin passsword is currently set\n";
|
|
|
|
}
|
|
|
|
|
2006-09-17 01:27:32 +00:00
|
|
|
strncpy(cluster->adminpassword, arg[1], sizeof(cluster->adminpassword)-1);
|
|
|
|
return "Password changed.\n";
|
|
|
|
}
|
|
|
|
char *Cmd_QTVConnect(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (!QTV_NewServerConnection(cluster, arg[1], arg[2], false, false, false))
|
|
|
|
return "Failed to connect to server, connection aborted\n";
|
|
|
|
return "Source registered\n";
|
|
|
|
}
|
|
|
|
char *Cmd_QWConnect(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
|
|
|
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], arg[2], false, false, false))
|
|
|
|
return "Failed to connect to server, connection aborted\n";
|
|
|
|
return "Source registered\n";
|
|
|
|
}
|
|
|
|
char *Cmd_MVDConnect(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (!QTV_NewServerConnection(cluster, arg[1], arg[2], false, false, false))
|
|
|
|
return "Failed to connect to server, connection aborted\n";
|
|
|
|
return "Source registered\n";
|
|
|
|
}
|
|
|
|
char *Cmd_Exec(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
char line[512], *res;
|
|
|
|
|
|
|
|
if (!localcommand)
|
2006-10-20 14:17:56 +00:00
|
|
|
{
|
2006-09-17 01:27:32 +00:00
|
|
|
if (*arg[1] == '\\' || *arg[1] == '/' || strstr(arg[1], "..") || arg[1][1] == ':')
|
|
|
|
return "Absolute paths are prohibited.\n";
|
2006-10-20 14:17:56 +00:00
|
|
|
if (!strncmp(arg[1], "usercfg/", 8)) //this is how we stop users from execing a 50gb pk3..
|
|
|
|
return "Remote-execed configs must be in the usercfg directory\n";
|
|
|
|
}
|
2006-09-17 01:27:32 +00:00
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
2006-10-27 10:57:06 +00:00
|
|
|
if (*line)
|
|
|
|
{
|
|
|
|
res = Rcon_Command(cluster, qtv, line, buffer, sizeofbuffer, localcommand);
|
|
|
|
Sys_Printf(cluster, "%s", res); //this is perhaps wrong.
|
|
|
|
}
|
2006-09-17 01:27:32 +00:00
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
return "Execed\n";
|
|
|
|
}
|
|
|
|
}
|
2006-10-07 22:29:31 +00:00
|
|
|
|
|
|
|
void catbuffer(char *buffer, int bufsize, char *format, ...)
|
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
char string[1024];
|
|
|
|
|
|
|
|
va_start (argptr, format);
|
|
|
|
vsnprintf (string,sizeof(string)-1, format,argptr);
|
|
|
|
va_end (argptr);
|
|
|
|
|
|
|
|
Q_strncatz(buffer, string, bufsize);
|
|
|
|
}
|
2006-09-17 01:27:32 +00:00
|
|
|
char *Cmd_Status(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
2006-10-07 22:29:31 +00:00
|
|
|
|
2006-09-17 01:27:32 +00:00
|
|
|
buffer[0] = '\0';
|
|
|
|
|
2006-10-07 22:29:31 +00:00
|
|
|
catbuffer(buffer, sizeofbuffer, "%i sources\n", cluster->numservers);
|
|
|
|
catbuffer(buffer, sizeofbuffer, "%i viewers\n", cluster->numviewers);
|
|
|
|
catbuffer(buffer, sizeofbuffer, "%i proxies\n", cluster->numproxies);
|
2006-09-17 01:27:32 +00:00
|
|
|
|
2006-10-07 22:29:31 +00:00
|
|
|
catbuffer(buffer, sizeofbuffer, "Options:\n");
|
|
|
|
catbuffer(buffer, sizeofbuffer, " Hostname %s\n", cluster->hostname);
|
|
|
|
|
2006-09-17 01:27:32 +00:00
|
|
|
if (cluster->chokeonnotupdated)
|
2006-10-07 22:29:31 +00:00
|
|
|
catbuffer(buffer, sizeofbuffer, " Choke\n");
|
2006-09-17 01:27:32 +00:00
|
|
|
if (cluster->lateforward)
|
2006-10-07 22:29:31 +00:00
|
|
|
catbuffer(buffer, sizeofbuffer, " Late forwarding\n");
|
2006-09-17 01:27:32 +00:00
|
|
|
if (!cluster->notalking)
|
2006-10-07 22:29:31 +00:00
|
|
|
catbuffer(buffer, sizeofbuffer, " Talking allowed\n");
|
2006-09-17 01:27:32 +00:00
|
|
|
if (cluster->nobsp)
|
2006-10-07 22:29:31 +00:00
|
|
|
catbuffer(buffer, sizeofbuffer, " No BSP loading\n");
|
|
|
|
catbuffer(buffer, sizeofbuffer, "\n");
|
2006-09-17 01:27:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (qtv)
|
|
|
|
{
|
2006-10-07 22:29:31 +00:00
|
|
|
catbuffer(buffer, sizeofbuffer, "Selected server: %s\n", qtv->server);
|
2006-10-22 19:18:15 +00:00
|
|
|
if (qtv->sourcefile)
|
2006-10-07 22:29:31 +00:00
|
|
|
catbuffer(buffer, sizeofbuffer, "Playing from file\n");
|
2006-09-17 01:27:32 +00:00
|
|
|
if (qtv->sourcesock != INVALID_SOCKET)
|
2006-10-07 22:29:31 +00:00
|
|
|
catbuffer(buffer, sizeofbuffer, "Connected\n");
|
2006-09-17 01:27:32 +00:00
|
|
|
if (qtv->parsingqtvheader || qtv->parsingconnectiondata)
|
2006-10-07 22:29:31 +00:00
|
|
|
catbuffer(buffer, sizeofbuffer, "Waiting for gamestate\n");
|
2006-11-03 15:53:04 +00:00
|
|
|
if (qtv->usequkeworldprotocols)
|
2006-09-17 01:27:32 +00:00
|
|
|
{
|
2006-11-03 15:53:04 +00:00
|
|
|
catbuffer(buffer, sizeofbuffer, "QuakeWorld protocols\n");
|
|
|
|
if (qtv->controller)
|
|
|
|
{
|
|
|
|
catbuffer(buffer, sizeofbuffer, "Controlled by %s\n", qtv->controller->name);
|
|
|
|
}
|
2006-09-17 01:27:32 +00:00
|
|
|
}
|
2006-11-03 15:53:04 +00:00
|
|
|
else if (qtv->sourcesock == INVALID_SOCKET && !qtv->sourcefile)
|
|
|
|
catbuffer(buffer, sizeofbuffer, "Connection not established\n");
|
|
|
|
|
2006-09-17 01:27:32 +00:00
|
|
|
if (*qtv->modellist[1].name)
|
|
|
|
{
|
2006-10-07 22:29:31 +00:00
|
|
|
catbuffer(buffer, sizeofbuffer, "Map name %s\n", qtv->modellist[1].name);
|
2006-09-17 01:27:32 +00:00
|
|
|
}
|
2006-10-07 22:29:31 +00:00
|
|
|
if (*qtv->connectpassword)
|
|
|
|
catbuffer(buffer, sizeofbuffer, "Using a password\n");
|
2006-09-17 01:27:32 +00:00
|
|
|
|
|
|
|
if (qtv->tcpsocket != INVALID_SOCKET)
|
|
|
|
{
|
2006-10-07 22:29:31 +00:00
|
|
|
catbuffer(buffer, sizeofbuffer, "Listening for proxies (%i)\n", qtv->tcplistenportnum);
|
2006-09-17 01:27:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (qtv->bsp)
|
|
|
|
{
|
2006-10-07 22:29:31 +00:00
|
|
|
catbuffer(buffer, sizeofbuffer, "BSP (%s) is loaded\n", qtv->mapname);
|
2006-09-17 01:27:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
char *Cmd_Choke(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
2006-10-20 14:17:56 +00:00
|
|
|
if (!*arg[1])
|
|
|
|
{
|
|
|
|
if (cluster->chokeonnotupdated)
|
|
|
|
return "proxy will not interpolate packets\n";
|
|
|
|
else
|
|
|
|
return "proxy will smooth action at the expense of extra packets\n";
|
|
|
|
}
|
2006-09-17 01:27:32 +00:00
|
|
|
cluster->chokeonnotupdated = !!atoi(arg[1]);
|
|
|
|
return "choke-until-update set\n";
|
|
|
|
}
|
|
|
|
char *Cmd_Late(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
2006-10-20 14:17:56 +00:00
|
|
|
if (!*arg[1])
|
|
|
|
{
|
|
|
|
if (cluster->lateforward)
|
|
|
|
return "forwarded streams will be artificially delayed\n";
|
|
|
|
else
|
|
|
|
return "forwarded streams are forwarded immediatly\n";
|
|
|
|
}
|
2006-09-17 01:27:32 +00:00
|
|
|
cluster->lateforward = !!atoi(arg[1]);
|
|
|
|
return "late forwarding set\n";
|
|
|
|
}
|
|
|
|
char *Cmd_Talking(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
2006-10-20 14:17:56 +00:00
|
|
|
if (!*arg[1])
|
|
|
|
{
|
|
|
|
if (cluster->notalking)
|
|
|
|
return "viewers may not talk\n";
|
|
|
|
else
|
|
|
|
return "viewers may talk freely\n";
|
|
|
|
}
|
2006-09-17 01:27:32 +00:00
|
|
|
cluster->notalking = !atoi(arg[1]);
|
|
|
|
return "talking permissions set\n";
|
|
|
|
}
|
|
|
|
char *Cmd_NoBSP(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
2006-10-20 14:17:56 +00:00
|
|
|
if (!*arg[1])
|
|
|
|
{
|
|
|
|
if (cluster->nobsp)
|
|
|
|
return "no bsps will be loaded\n";
|
|
|
|
else
|
|
|
|
return "attempting to load bsp files\n";
|
|
|
|
}
|
2006-09-17 01:27:32 +00:00
|
|
|
cluster->nobsp = !!atoi(arg[1]);
|
|
|
|
return "nobsp will change at start of next map\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
char *Cmd_MaxViewers(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
2006-10-20 14:17:56 +00:00
|
|
|
if (!*arg[1])
|
|
|
|
{
|
|
|
|
buffer[0] = '\0';
|
|
|
|
if (cluster->maxviewers)
|
|
|
|
snprintf(buffer, sizeofbuffer, "maxviewers is currently %i\n", cluster->maxviewers);
|
|
|
|
else
|
|
|
|
return "maxviewers is currently unlimited\n";
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
cluster->maxviewers = atoi(arg[1]);
|
2006-09-17 01:27:32 +00:00
|
|
|
return "maxviewers set\n";
|
|
|
|
}
|
2006-10-22 20:31:10 +00:00
|
|
|
char *Cmd_AllowNQ(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
|
|
|
if (!*arg[1])
|
|
|
|
{
|
|
|
|
buffer[0] = '\0';
|
|
|
|
snprintf(buffer, sizeofbuffer, "allownq is currently %i\n", cluster->allownqclients);
|
|
|
|
return buffer;
|
|
|
|
}
|
2006-10-27 10:57:06 +00:00
|
|
|
cluster->allownqclients = !!atoi(arg[1]);
|
2006-10-22 20:31:10 +00:00
|
|
|
return "allownq set\n";
|
|
|
|
}
|
2006-09-17 01:27:32 +00:00
|
|
|
char *Cmd_MaxProxies(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
2006-10-20 14:17:56 +00:00
|
|
|
if (!*arg[1])
|
|
|
|
{
|
|
|
|
buffer[0] = '\0';
|
|
|
|
if (cluster->maxproxies)
|
|
|
|
snprintf(buffer, sizeofbuffer, "maxproxies is currently %i\n", cluster->maxproxies);
|
|
|
|
else
|
|
|
|
return "maxproxies is currently unlimited\n";
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
cluster->maxproxies = atoi(arg[1]);
|
2006-09-17 01:27:32 +00:00
|
|
|
return "maxproxies set\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *Cmd_Ping(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
|
|
|
netadr_t addr;
|
|
|
|
if (NET_StringToAddr(arg[1], &addr, 27500))
|
|
|
|
{
|
|
|
|
NET_SendPacket (cluster, cluster->qwdsocket, 1, "k", addr);
|
|
|
|
return "pinged\n";
|
|
|
|
}
|
|
|
|
return "couldn't resolve\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
char *Cmd_Help(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
|
|
|
return HELPSTRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *Cmd_Echo(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
|
|
|
return "Poly wants a cracker.\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
char *Cmd_Quit(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
|
|
|
if (!localcommand)
|
|
|
|
return "Remote shutdown refused.\n";
|
|
|
|
cluster->wanttoexit = true;
|
|
|
|
return "Shutting down.\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-10-07 22:29:31 +00:00
|
|
|
char *Cmd_Streams(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
|
|
|
catbuffer(buffer, sizeofbuffer, "Streams:\n");
|
|
|
|
|
|
|
|
for (qtv = cluster->servers; qtv; qtv = qtv->next)
|
|
|
|
{
|
|
|
|
catbuffer(buffer, sizeofbuffer, "%i: %s\n", qtv->streamid, qtv->server);
|
|
|
|
}
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2006-09-17 01:27:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char *Cmd_Disconnect(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
|
|
|
QTV_Shutdown(qtv);
|
|
|
|
return "Disconnected\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
char *Cmd_Record(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
char *Cmd_Stop(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
|
|
|
if (Net_StopFileProxy(qtv))
|
|
|
|
return "stopped\n";
|
|
|
|
else
|
|
|
|
return "not recording to disk\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
char *Cmd_Reconnect(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
|
|
|
if (QTV_Connect(qtv, qtv->server))
|
|
|
|
return "Reconnected\n";
|
|
|
|
else
|
|
|
|
return "Failed to reconnect (will keep trying)\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
char *Cmd_MVDPort(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
|
|
|
int news;
|
|
|
|
int newp = atoi(arg[1]);
|
|
|
|
|
|
|
|
if (!newp)
|
|
|
|
{
|
|
|
|
if (qtv->tcpsocket != INVALID_SOCKET)
|
|
|
|
{
|
|
|
|
closesocket(qtv->tcpsocket);
|
|
|
|
qtv->tcpsocket = INVALID_SOCKET;
|
|
|
|
qtv->tcplistenportnum = 0;
|
|
|
|
|
|
|
|
return "mvd port is now closed\n";
|
|
|
|
}
|
|
|
|
return "Already closed\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
news = Net_MVDListen(newp);
|
|
|
|
|
|
|
|
if (news != INVALID_SOCKET)
|
|
|
|
{
|
|
|
|
if (qtv->tcpsocket != INVALID_SOCKET)
|
|
|
|
closesocket(qtv->tcpsocket);
|
|
|
|
qtv->tcpsocket = news;
|
|
|
|
qtv->disconnectwhennooneiswatching = false;
|
|
|
|
qtv->tcplistenportnum = newp;
|
|
|
|
return "Opened tcp port\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return "Failed to open tcp port\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char *Cmd_Commands(cluster_t *cluster, sv_t *qtv, char *arg[MAX_ARGS], char *buffer, int sizeofbuffer, qboolean localcommand)
|
|
|
|
{
|
2006-10-27 10:57:06 +00:00
|
|
|
return "fixme\n";
|
2006-09-17 01:27:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct rconcommands_s {
|
|
|
|
char *name;
|
|
|
|
qboolean serverspecific; //works within a qtv context
|
|
|
|
qboolean clusterspecific; //works without a qtv context (ignores context)
|
|
|
|
dispatchrconcommand_t func;
|
|
|
|
} rconcommands_t;
|
|
|
|
|
|
|
|
const rconcommands_t rconcommands[] =
|
|
|
|
{
|
|
|
|
{"exec", 1, 1, Cmd_Exec},
|
|
|
|
{"status", 1, 1, Cmd_Status},
|
|
|
|
|
|
|
|
{"help", 0, 1, Cmd_Help},
|
|
|
|
{"commands", 0, 1, Cmd_Commands},
|
|
|
|
{"hostname", 0, 1, Cmd_Hostname},
|
|
|
|
{"master", 0, 1, Cmd_Master},
|
|
|
|
{"udpport", 0, 1, Cmd_UDPPort},
|
|
|
|
{"port", 0, 1, Cmd_UDPPort},
|
|
|
|
{"adminpassword",0, 1, Cmd_AdminPassword},
|
|
|
|
{"rconpassword",0, 1, Cmd_AdminPassword},
|
|
|
|
{"qtv", 0, 1, Cmd_QTVConnect},
|
|
|
|
{"addserver", 0, 1, Cmd_QTVConnect},
|
|
|
|
{"connect", 0, 1, Cmd_QTVConnect},
|
|
|
|
{"qw", 0, 1, Cmd_QWConnect},
|
2006-10-07 22:29:31 +00:00
|
|
|
{"observe", 0, 1, Cmd_QWConnect},
|
2006-09-17 01:27:32 +00:00
|
|
|
{"demo", 0, 1, Cmd_MVDConnect},
|
|
|
|
{"playdemo", 0, 1, Cmd_MVDConnect},
|
|
|
|
{"choke", 0, 1, Cmd_Choke},
|
|
|
|
{"late", 0, 1, Cmd_Late},
|
|
|
|
{"talking", 0, 1, Cmd_Talking},
|
|
|
|
{"nobsp", 0, 1, Cmd_NoBSP},
|
|
|
|
{"maxviewers", 0, 1, Cmd_MaxViewers},
|
|
|
|
{"maxproxies", 0, 1, Cmd_MaxProxies},
|
|
|
|
{"ping", 0, 1, Cmd_Ping},
|
|
|
|
{"reconnect", 0, 1, Cmd_Reconnect},
|
|
|
|
{"echo", 0, 1, Cmd_Echo},
|
|
|
|
{"quit", 0, 1, Cmd_Quit},
|
2006-10-07 22:29:31 +00:00
|
|
|
{"streams", 0, 1, Cmd_Streams},
|
2006-10-22 20:31:10 +00:00
|
|
|
{"allownq", 0, 1, Cmd_AllowNQ},
|
2006-09-17 01:27:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{"disconnect", 1, 0, Cmd_Disconnect},
|
|
|
|
{"record", 1, 0, Cmd_Record},
|
|
|
|
{"stop", 1, 0, Cmd_Stop},
|
|
|
|
{"tcpport", 1, 0, Cmd_MVDPort},
|
|
|
|
{"mvdport", 1, 0, Cmd_MVDPort},
|
|
|
|
|
|
|
|
{NULL}
|
|
|
|
};
|
|
|
|
|
2006-10-07 22:29:31 +00:00
|
|
|
char *Rcon_Command(cluster_t *cluster, sv_t *qtv, char *command, char *buffer, int sizeofbuffer, qboolean localcommand)
|
2005-10-07 02:02:15 +00:00
|
|
|
{
|
|
|
|
#define TOKENIZE_PUNCTUATION ""
|
2005-09-24 04:45:24 +00:00
|
|
|
|
2006-10-07 22:29:31 +00:00
|
|
|
int i;
|
|
|
|
char arg[MAX_ARGS][ARG_LEN];
|
|
|
|
char *argptrs[MAX_ARGS];
|
|
|
|
char *sid;
|
2005-09-24 04:45:24 +00:00
|
|
|
|
2006-10-07 22:29:31 +00:00
|
|
|
for (sid = command; *sid; sid = sid++)
|
2005-09-24 04:45:24 +00:00
|
|
|
{
|
2006-10-07 22:29:31 +00:00
|
|
|
if (*sid == ':')
|
|
|
|
break;
|
|
|
|
if (*sid < '0' || *sid > '9')
|
|
|
|
break;
|
2005-09-24 04:45:24 +00:00
|
|
|
}
|
2006-10-07 22:29:31 +00:00
|
|
|
if (*sid == ':')
|
2005-09-24 04:45:24 +00:00
|
|
|
{
|
2006-10-07 22:29:31 +00:00
|
|
|
i = atoi(command);
|
|
|
|
command = sid+1;
|
2005-09-24 04:45:24 +00:00
|
|
|
|
2006-10-07 22:29:31 +00:00
|
|
|
for (qtv = cluster->servers; qtv; qtv = qtv->next)
|
|
|
|
if (qtv->streamid == i)
|
|
|
|
break;
|
2005-09-24 04:45:24 +00:00
|
|
|
}
|
|
|
|
|
2005-10-07 02:02:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2006-09-17 01:27:32 +00:00
|
|
|
if (!qtv && cluster->numservers==1)
|
|
|
|
qtv = cluster->servers;
|
|
|
|
|
|
|
|
buffer[0] = 0;
|
|
|
|
|
2005-10-07 02:02:15 +00:00
|
|
|
if (qtv)
|
|
|
|
{ //if there is a specific connection targetted
|
2006-09-17 01:27:32 +00:00
|
|
|
|
|
|
|
for (i = 0; rconcommands[i].name; i++)
|
|
|
|
{
|
|
|
|
if (rconcommands[i].serverspecific)
|
|
|
|
if (!strcmp(rconcommands[i].name, argptrs[0]))
|
|
|
|
return rconcommands[i].func(cluster, qtv, argptrs, buffer, sizeofbuffer, localcommand);
|
|
|
|
}
|
2005-10-07 02:02:15 +00:00
|
|
|
}
|
2006-09-17 01:27:32 +00:00
|
|
|
|
|
|
|
for (i = 0; rconcommands[i].name; i++)
|
|
|
|
{
|
|
|
|
if (!strcmp(rconcommands[i].name, argptrs[0]))
|
|
|
|
{
|
|
|
|
if (rconcommands[i].clusterspecific)
|
|
|
|
return rconcommands[i].func(cluster, NULL, argptrs, buffer, sizeofbuffer, localcommand);
|
|
|
|
else if (rconcommands[i].serverspecific)
|
|
|
|
{
|
|
|
|
snprintf(buffer, sizeofbuffer, "Command \"%s\" requires a targeted server.\n", arg[0]);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
}
|
2005-10-07 02:02:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
snprintf(buffer, sizeofbuffer, "Command \"%s\" not recognised.\n", arg[0]);
|
|
|
|
return buffer;
|
2005-09-24 04:45:24 +00:00
|
|
|
}
|
|
|
|
|