2003-02-10 21:06:30 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-02-12 17:15:03 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
2003-02-10 21:06:30 +00:00
|
|
|
|
|
|
|
#include "QF/cbuf.h"
|
|
|
|
#include "QF/cmd.h"
|
|
|
|
#include "QF/console.h"
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/idparse.h"
|
2011-12-24 01:04:33 +00:00
|
|
|
#include "QF/mathlib.h"
|
2003-02-10 21:06:30 +00:00
|
|
|
#include "QF/msg.h"
|
|
|
|
#include "QF/qargs.h"
|
2003-02-12 17:15:03 +00:00
|
|
|
#include "QF/qendian.h"
|
2003-02-10 21:06:30 +00:00
|
|
|
#include "QF/sizebuf.h"
|
|
|
|
#include "QF/sys.h"
|
2003-02-12 17:15:03 +00:00
|
|
|
|
2012-02-13 12:58:34 +00:00
|
|
|
#include "QF/plugin/console.h"
|
|
|
|
|
2003-02-12 17:46:48 +00:00
|
|
|
#include "compat.h"
|
2003-02-11 22:48:57 +00:00
|
|
|
#include "netchan.h"
|
2003-02-10 21:06:30 +00:00
|
|
|
|
2003-02-12 17:46:48 +00:00
|
|
|
#define SV_TIMEOUT 450
|
|
|
|
|
2003-02-12 17:15:03 +00:00
|
|
|
#define PORT_MASTER 26900
|
|
|
|
#define PORT_SERVER 26950
|
2003-02-12 02:39:24 +00:00
|
|
|
|
2003-02-12 17:15:03 +00:00
|
|
|
// M = master, S = server, C = client, A = any
|
|
|
|
// the second character will allways be \n if the message isn't a single
|
|
|
|
// byte long (?? not true anymore?)
|
2003-02-12 02:39:24 +00:00
|
|
|
|
2003-02-12 17:15:03 +00:00
|
|
|
#define S2C_CHALLENGE 'c'
|
|
|
|
#define A2A_PING 'k'
|
2003-02-10 21:06:30 +00:00
|
|
|
|
2003-02-12 17:15:03 +00:00
|
|
|
#define S2M_HEARTBEAT 'a' // + serverinfo + userlist + fraglist
|
|
|
|
#define S2M_SHUTDOWN 'C'
|
2003-02-10 21:06:30 +00:00
|
|
|
|
|
|
|
typedef struct filter_s {
|
|
|
|
netadr_t from;
|
|
|
|
netadr_t to;
|
|
|
|
struct filter_s *next;
|
|
|
|
struct filter_s *previous;
|
|
|
|
} filter_t;
|
|
|
|
|
2003-02-12 17:15:03 +00:00
|
|
|
typedef struct server_s {
|
|
|
|
netadr_t ip;
|
|
|
|
struct server_s *next;
|
|
|
|
struct server_s *previous;
|
|
|
|
double timeout;
|
|
|
|
} server_t;
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
static char *sv_console_plugin;
|
|
|
|
static cvar_t sv_console_plugin_cvar = {
|
|
|
|
.name = "sv_console_plugin",
|
|
|
|
.description =
|
|
|
|
"Plugin used for the console",
|
|
|
|
.default_value = "server",
|
|
|
|
.flags = CVAR_ROM,
|
|
|
|
.value = { .type = 0, .value = &sv_console_plugin },
|
|
|
|
};
|
2003-02-12 17:15:03 +00:00
|
|
|
SERVER_PLUGIN_PROTOS
|
|
|
|
static plugin_list_t server_plugin_list[] = {
|
|
|
|
SERVER_PLUGIN_LIST
|
|
|
|
};
|
|
|
|
|
|
|
|
qboolean is_server = true;
|
|
|
|
|
|
|
|
static cbuf_t *mst_cbuf;
|
|
|
|
|
2003-02-12 18:36:14 +00:00
|
|
|
static server_t *sv_list = NULL;
|
|
|
|
static filter_t *filter_list = NULL;
|
2003-02-10 21:06:30 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
FL_Remove (filter_t * filter)
|
|
|
|
{
|
|
|
|
if (filter->previous)
|
|
|
|
filter->previous->next = filter->next;
|
|
|
|
if (filter->next)
|
|
|
|
filter->next->previous = filter->previous;
|
|
|
|
filter->next = NULL;
|
|
|
|
filter->previous = NULL;
|
|
|
|
if (filter_list == filter)
|
|
|
|
filter_list = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
FL_Clear (void)
|
|
|
|
{
|
|
|
|
filter_t *filter;
|
|
|
|
|
|
|
|
for (filter = filter_list; filter;) {
|
|
|
|
if (filter) {
|
|
|
|
filter_t *next = filter->next;
|
|
|
|
|
|
|
|
FL_Remove (filter);
|
|
|
|
free (filter);
|
|
|
|
filter = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
filter_list = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static filter_t *
|
|
|
|
FL_New (netadr_t *adr1, netadr_t *adr2)
|
|
|
|
{
|
|
|
|
filter_t *filter;
|
|
|
|
|
|
|
|
filter = (filter_t *) calloc (1, sizeof (filter_t));
|
|
|
|
if (adr1)
|
2003-02-12 17:15:03 +00:00
|
|
|
filter->from = *adr1;
|
2003-02-10 21:06:30 +00:00
|
|
|
if (adr2)
|
2003-02-12 17:15:03 +00:00
|
|
|
filter->to = *adr2;
|
2003-02-10 21:06:30 +00:00
|
|
|
return filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
FL_Add (filter_t * filter)
|
|
|
|
{
|
|
|
|
filter->next = filter_list;
|
|
|
|
filter->previous = NULL;
|
|
|
|
if (filter_list)
|
|
|
|
filter_list->previous = filter;
|
|
|
|
filter_list = filter;
|
|
|
|
}
|
|
|
|
|
2018-10-09 03:35:01 +00:00
|
|
|
static __attribute__((pure)) filter_t *
|
2003-02-10 21:06:30 +00:00
|
|
|
FL_Find (netadr_t adr)
|
|
|
|
{
|
|
|
|
filter_t *filter;
|
|
|
|
|
|
|
|
for (filter = filter_list; filter; filter = filter->next) {
|
|
|
|
if (NET_CompareBaseAdr (filter->from, adr))
|
|
|
|
return filter;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-02-12 17:15:03 +00:00
|
|
|
static void
|
2003-02-12 18:36:14 +00:00
|
|
|
Filter (void)
|
2003-02-12 17:15:03 +00:00
|
|
|
{
|
|
|
|
int hold_port;
|
|
|
|
netadr_t filter_adr;
|
|
|
|
filter_t *filter;
|
|
|
|
|
|
|
|
hold_port = net_from.port;
|
|
|
|
NET_StringToAdr ("127.0.0.1:26950", &filter_adr);
|
|
|
|
if (NET_CompareBaseAdr (net_from, filter_adr)) {
|
|
|
|
NET_StringToAdr ("0.0.0.0:26950", &filter_adr);
|
|
|
|
if (!NET_CompareBaseAdr (net_local_adr, filter_adr)) {
|
|
|
|
net_from = net_local_adr;
|
|
|
|
net_from.port = hold_port;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if no compare with filter list
|
|
|
|
if ((filter = FL_Find (net_from))) {
|
|
|
|
net_from = filter->to;
|
|
|
|
net_from.port = hold_port;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SVL_Remove (server_t *sv)
|
|
|
|
{
|
|
|
|
if (sv_list == sv)
|
|
|
|
sv_list = sv->next;
|
|
|
|
if (sv->previous)
|
|
|
|
sv->previous->next = sv->next;
|
|
|
|
if (sv->next)
|
|
|
|
sv->next->previous = sv->previous;
|
|
|
|
sv->next = NULL;
|
|
|
|
sv->previous = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-02-10 21:06:30 +00:00
|
|
|
SVL_Clear (void)
|
|
|
|
{
|
|
|
|
server_t *sv;
|
|
|
|
|
|
|
|
for (sv = sv_list; sv;) {
|
|
|
|
if (sv) {
|
|
|
|
server_t *next = sv->next;
|
|
|
|
|
|
|
|
SVL_Remove (sv);
|
|
|
|
free (sv);
|
|
|
|
sv = next;
|
|
|
|
}
|
2003-02-12 17:15:03 +00:00
|
|
|
}
|
|
|
|
sv_list = NULL;
|
2003-02-10 21:06:30 +00:00
|
|
|
}
|
|
|
|
|
2003-02-12 17:15:03 +00:00
|
|
|
static server_t *
|
2003-02-10 21:06:30 +00:00
|
|
|
SVL_New (netadr_t *adr)
|
|
|
|
{
|
|
|
|
server_t *sv;
|
2003-02-12 06:24:30 +00:00
|
|
|
|
2003-02-10 21:06:30 +00:00
|
|
|
sv = (server_t *) calloc (1, sizeof (server_t));
|
|
|
|
if (adr)
|
2003-02-12 17:15:03 +00:00
|
|
|
sv->ip = *adr;
|
2003-02-10 21:06:30 +00:00
|
|
|
return sv;
|
|
|
|
}
|
|
|
|
|
2003-02-12 17:15:03 +00:00
|
|
|
static void
|
2003-02-10 21:06:30 +00:00
|
|
|
SVL_Add (server_t *sv)
|
|
|
|
{
|
|
|
|
sv->next = sv_list;
|
|
|
|
sv->previous = NULL;
|
|
|
|
if (sv_list)
|
|
|
|
sv_list->previous = sv;
|
|
|
|
sv_list = sv;
|
|
|
|
}
|
|
|
|
|
2018-10-09 03:35:01 +00:00
|
|
|
static __attribute__((pure)) server_t *
|
2003-02-10 21:06:30 +00:00
|
|
|
SVL_Find (netadr_t adr)
|
|
|
|
{
|
|
|
|
server_t *sv;
|
|
|
|
|
|
|
|
for (sv = sv_list; sv; sv = sv->next) {
|
|
|
|
if (NET_CompareAdr (sv->ip, adr))
|
|
|
|
return sv;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SV_InitNet (void)
|
|
|
|
{
|
2003-02-12 17:15:03 +00:00
|
|
|
const char *str;
|
2003-02-12 06:24:30 +00:00
|
|
|
int port, p;
|
2003-02-12 17:15:03 +00:00
|
|
|
QFile *filters;
|
2003-02-10 21:06:30 +00:00
|
|
|
|
|
|
|
port = PORT_MASTER;
|
|
|
|
p = COM_CheckParm ("-port");
|
|
|
|
if (p && p < com_argc) {
|
|
|
|
port = atoi (com_argv[p + 1]);
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("Port: %i\n", port);
|
2003-02-10 21:06:30 +00:00
|
|
|
}
|
|
|
|
NET_Init (port);
|
|
|
|
|
|
|
|
// Add filters
|
2003-02-12 17:15:03 +00:00
|
|
|
if ((filters = Qopen ("filters.ini", "rt"))) {
|
|
|
|
while ((str = Qgetline (filters))) {
|
2003-02-10 21:06:30 +00:00
|
|
|
Cbuf_AddText (mst_cbuf, "filter add ");
|
|
|
|
Cbuf_AddText (mst_cbuf, str);
|
|
|
|
Cbuf_AddText (mst_cbuf, "\n");
|
|
|
|
}
|
2003-02-12 17:15:03 +00:00
|
|
|
Qclose (filters);
|
2003-02-10 21:06:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
AnalysePacket (void)
|
|
|
|
{
|
2003-02-12 17:46:48 +00:00
|
|
|
byte buf[16];
|
|
|
|
byte *p, *data;
|
|
|
|
int i, size, rsize;
|
|
|
|
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("%s >> unknown packet:\n", NET_AdrToString (net_from));
|
2003-02-12 17:46:48 +00:00
|
|
|
|
|
|
|
data = net_message->message->data;
|
|
|
|
size = net_message->message->cursize;
|
|
|
|
|
|
|
|
for (p = data; (rsize = min (size - (p - data), 16)); p += rsize) {
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("%04X:", (unsigned) (p - data));
|
2003-02-12 17:46:48 +00:00
|
|
|
memcpy (buf, p, rsize);
|
|
|
|
for (i = 0; i < rsize; i++) {
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf (" %02X", buf[i]);
|
2003-02-12 17:46:48 +00:00
|
|
|
if (buf[i] < ' ' || buf [i] > '~')
|
|
|
|
buf[i] = '.';
|
|
|
|
}
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("%*.*s\n", 1 + (16 - rsize) * 3 + rsize, rsize, buf);
|
2003-02-10 21:06:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
Mst_SendList (void)
|
|
|
|
{
|
|
|
|
byte buf[MAX_DATAGRAM];
|
|
|
|
sizebuf_t msg;
|
2003-02-12 06:53:38 +00:00
|
|
|
server_t *sv;
|
|
|
|
short int sv_num = 0;
|
2003-02-10 21:06:30 +00:00
|
|
|
|
|
|
|
msg.data = buf;
|
|
|
|
msg.maxsize = sizeof (buf);
|
|
|
|
msg.cursize = 0;
|
|
|
|
msg.allowoverflow = true;
|
|
|
|
msg.overflowed = false;
|
|
|
|
|
|
|
|
// number of servers:
|
|
|
|
for (sv = sv_list; sv; sv = sv->next)
|
|
|
|
sv_num++;
|
|
|
|
MSG_WriteByte (&msg, 255);
|
|
|
|
MSG_WriteByte (&msg, 255);
|
|
|
|
MSG_WriteByte (&msg, 255);
|
|
|
|
MSG_WriteByte (&msg, 255);
|
|
|
|
MSG_WriteByte (&msg, 255);
|
|
|
|
MSG_WriteByte (&msg, 'd');
|
|
|
|
MSG_WriteByte (&msg, '\n');
|
|
|
|
if (sv_num > 0)
|
|
|
|
for (sv = sv_list; sv; sv = sv->next) {
|
|
|
|
MSG_WriteByte (&msg, sv->ip.ip[0]);
|
|
|
|
MSG_WriteByte (&msg, sv->ip.ip[1]);
|
|
|
|
MSG_WriteByte (&msg, sv->ip.ip[2]);
|
|
|
|
MSG_WriteByte (&msg, sv->ip.ip[3]);
|
|
|
|
MSG_WriteShort (&msg, sv->ip.port);
|
|
|
|
}
|
|
|
|
NET_SendPacket (msg.cursize, msg.data, net_from);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
Mst_Packet (void)
|
|
|
|
{
|
|
|
|
char msg;
|
|
|
|
server_t *sv;
|
|
|
|
|
2003-02-13 00:06:24 +00:00
|
|
|
// Filter ();
|
2003-02-10 21:06:30 +00:00
|
|
|
msg = net_message->message->data[1];
|
|
|
|
if (msg == A2A_PING) {
|
2003-02-12 18:36:14 +00:00
|
|
|
Filter ();
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("%s >> A2A_PING\n", NET_AdrToString (net_from));
|
2003-02-10 21:06:30 +00:00
|
|
|
if (!(sv = SVL_Find (net_from))) {
|
|
|
|
sv = SVL_New (&net_from);
|
|
|
|
SVL_Add (sv);
|
|
|
|
}
|
|
|
|
sv->timeout = Sys_DoubleTime ();
|
2003-02-12 06:24:30 +00:00
|
|
|
} else if (msg == S2M_HEARTBEAT) {
|
2003-02-12 18:36:14 +00:00
|
|
|
Filter ();
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("%s >> S2M_HEARTBEAT\n", NET_AdrToString (net_from));
|
2003-02-10 21:06:30 +00:00
|
|
|
if (!(sv = SVL_Find (net_from))) {
|
|
|
|
sv = SVL_New (&net_from);
|
|
|
|
SVL_Add (sv);
|
|
|
|
}
|
|
|
|
sv->timeout = Sys_DoubleTime ();
|
2003-02-12 06:24:30 +00:00
|
|
|
} else if (msg == S2M_SHUTDOWN) {
|
2003-02-12 18:36:14 +00:00
|
|
|
Filter ();
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("%s >> S2M_SHUTDOWN\n", NET_AdrToString (net_from));
|
2003-02-10 21:06:30 +00:00
|
|
|
if ((sv = SVL_Find (net_from))) {
|
|
|
|
SVL_Remove (sv);
|
|
|
|
free (sv);
|
|
|
|
}
|
2003-02-12 17:15:03 +00:00
|
|
|
} else if (msg == S2C_CHALLENGE) {
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("%s >> ", NET_AdrToString (net_from));
|
|
|
|
Sys_Printf ("Gamespy server list request\n");
|
2003-02-10 21:06:30 +00:00
|
|
|
Mst_SendList ();
|
2003-02-12 06:24:30 +00:00
|
|
|
} else {
|
2003-02-10 21:06:30 +00:00
|
|
|
byte *p;
|
|
|
|
|
|
|
|
p = net_message->message->data;
|
|
|
|
if (p[0] == 0 && p[1] == 'y') {
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("%s >> ", NET_AdrToString (net_from));
|
|
|
|
Sys_Printf ("Pingtool server list request\n");
|
2003-02-10 21:06:30 +00:00
|
|
|
Mst_SendList ();
|
2003-02-12 06:24:30 +00:00
|
|
|
} else {
|
2003-02-10 21:06:30 +00:00
|
|
|
AnalysePacket ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-12 17:15:03 +00:00
|
|
|
static void
|
2003-02-10 21:06:30 +00:00
|
|
|
SV_ReadPackets (void)
|
|
|
|
{
|
|
|
|
while (NET_GetPacket ()) {
|
|
|
|
Mst_Packet ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-02-12 18:36:14 +00:00
|
|
|
FilterAdd (int arg)
|
2003-02-10 21:06:30 +00:00
|
|
|
{
|
|
|
|
filter_t *filter;
|
|
|
|
netadr_t to, from;
|
|
|
|
|
2003-02-12 17:15:03 +00:00
|
|
|
if (Cmd_Argc () - arg != 2) {
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("Invalid command parameters. "
|
2003-02-12 06:24:30 +00:00
|
|
|
"Usage:\nfilter add x.x.x.x:port x.x.x.x:port\n\n");
|
2003-02-10 21:06:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-02-12 17:15:03 +00:00
|
|
|
NET_StringToAdr (Cmd_Argv (arg), &from);
|
|
|
|
NET_StringToAdr (Cmd_Argv (arg + 1), &to);
|
2003-02-10 21:06:30 +00:00
|
|
|
if (to.port == 0)
|
|
|
|
from.port = BigShort (PORT_SERVER);
|
|
|
|
if (from.port == 0)
|
|
|
|
from.port = BigShort (PORT_SERVER);
|
|
|
|
if (!(filter = FL_Find (from))) {
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("Added filter %s\t\t%s\n", Cmd_Argv (arg),
|
2003-02-12 17:15:03 +00:00
|
|
|
Cmd_Argv (arg + 1));
|
2003-02-10 21:06:30 +00:00
|
|
|
filter = FL_New (&from, &to);
|
|
|
|
FL_Add (filter);
|
2003-02-12 06:24:30 +00:00
|
|
|
} else
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("%s already defined\n\n", Cmd_Argv (arg));
|
2003-02-10 21:06:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-02-12 18:36:14 +00:00
|
|
|
FilterRemove (int arg)
|
2003-02-10 21:06:30 +00:00
|
|
|
{
|
|
|
|
filter_t *filter;
|
|
|
|
netadr_t from;
|
|
|
|
|
2003-02-12 17:15:03 +00:00
|
|
|
if (Cmd_Argc () - arg != 1) {
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("Invalid command parameters. Usage:\n"
|
2003-02-12 06:24:30 +00:00
|
|
|
"filter remove x.x.x.x:port\n\n");
|
2003-02-10 21:06:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-02-12 17:15:03 +00:00
|
|
|
NET_StringToAdr (Cmd_Argv (arg), &from);
|
2003-02-10 21:06:30 +00:00
|
|
|
if ((filter = FL_Find (from))) {
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("Removed %s\n\n", Cmd_Argv (arg));
|
2003-02-10 21:06:30 +00:00
|
|
|
FL_Remove (filter);
|
|
|
|
free (filter);
|
2003-02-12 06:24:30 +00:00
|
|
|
} else
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("Cannot find %s\n\n", Cmd_Argv (arg));
|
2003-02-10 21:06:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-02-12 18:36:14 +00:00
|
|
|
FilterList (void)
|
2003-02-10 21:06:30 +00:00
|
|
|
{
|
|
|
|
filter_t *filter;
|
|
|
|
|
|
|
|
for (filter = filter_list; filter; filter = filter->next) {
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("%s", NET_AdrToString (filter->from));
|
|
|
|
Sys_Printf ("\t\t%s\n", NET_AdrToString (filter->to));
|
2003-02-10 21:06:30 +00:00
|
|
|
}
|
|
|
|
if (filter_list == NULL)
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("No filter\n");
|
|
|
|
Sys_Printf ("\n");
|
2003-02-10 21:06:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-02-12 18:36:14 +00:00
|
|
|
FilterClear (void)
|
2003-02-10 21:06:30 +00:00
|
|
|
{
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("Removed all filters\n\n");
|
2003-02-10 21:06:30 +00:00
|
|
|
FL_Clear ();
|
|
|
|
}
|
|
|
|
|
2003-02-12 17:15:03 +00:00
|
|
|
static void
|
2003-02-12 18:36:14 +00:00
|
|
|
Filter_f (void)
|
2003-02-10 21:06:30 +00:00
|
|
|
{
|
|
|
|
if (!strcmp (Cmd_Argv (1), "add"))
|
2003-02-12 18:36:14 +00:00
|
|
|
FilterAdd (2);
|
2003-02-10 21:06:30 +00:00
|
|
|
else if (!strcmp (Cmd_Argv (1), "remove"))
|
2003-02-12 18:36:14 +00:00
|
|
|
FilterRemove (2);
|
2003-02-10 21:06:30 +00:00
|
|
|
else if (!strcmp (Cmd_Argv (1), "clear"))
|
2003-02-12 18:36:14 +00:00
|
|
|
FilterClear ();
|
2003-02-10 21:06:30 +00:00
|
|
|
else if (Cmd_Argc () == 3) {
|
2003-02-12 18:36:14 +00:00
|
|
|
FilterAdd (1);
|
2003-02-12 06:24:30 +00:00
|
|
|
} else if (Cmd_Argc () == 2) {
|
2003-02-12 18:36:14 +00:00
|
|
|
FilterRemove (1);
|
2003-02-12 06:24:30 +00:00
|
|
|
} else
|
2003-02-12 18:36:14 +00:00
|
|
|
FilterList ();
|
2003-02-10 21:06:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SV_WriteFilterList (void)
|
|
|
|
{
|
2003-02-12 17:15:03 +00:00
|
|
|
QFile *filters;
|
2003-02-10 21:06:30 +00:00
|
|
|
|
2003-02-12 17:15:03 +00:00
|
|
|
if ((filters = Qopen ("filters.ini", "wt"))) {
|
2003-02-12 06:24:30 +00:00
|
|
|
filter_t *filter;
|
|
|
|
|
2003-02-10 21:06:30 +00:00
|
|
|
if (filter_list == NULL) {
|
2003-02-12 17:15:03 +00:00
|
|
|
Qclose (filters);
|
2003-02-10 21:06:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (filter = filter_list; filter; filter = filter->next) {
|
2003-02-12 17:15:03 +00:00
|
|
|
Qprintf (filters, "%s", NET_AdrToString (filter->from));
|
|
|
|
Qprintf (filters, " %s\n", NET_AdrToString (filter->to));
|
2003-02-10 21:06:30 +00:00
|
|
|
}
|
2003-02-12 17:15:03 +00:00
|
|
|
Qclose (filters);
|
2003-02-10 21:06:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-12 17:15:03 +00:00
|
|
|
static void
|
2020-03-21 13:24:11 +00:00
|
|
|
SV_Shutdown (void *data)
|
2003-02-10 21:06:30 +00:00
|
|
|
{
|
|
|
|
// write filter list
|
|
|
|
SV_WriteFilterList ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SV_TimeOut (void)
|
|
|
|
{
|
|
|
|
// Remove listed severs that havnt sent a heartbeat for some time
|
|
|
|
double time = Sys_DoubleTime ();
|
|
|
|
server_t *sv;
|
|
|
|
server_t *next;
|
|
|
|
|
|
|
|
if (sv_list == NULL)
|
|
|
|
return;
|
2003-02-12 06:24:30 +00:00
|
|
|
|
2003-02-10 21:06:30 +00:00
|
|
|
for (sv = sv_list; sv;) {
|
|
|
|
if (sv->timeout + SV_TIMEOUT < time) {
|
|
|
|
next = sv->next;
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("%s timed out\n", NET_AdrToString (sv->ip));
|
2003-02-10 21:06:30 +00:00
|
|
|
SVL_Remove (sv);
|
|
|
|
free (sv);
|
|
|
|
sv = next;
|
2003-02-12 06:24:30 +00:00
|
|
|
} else
|
2003-02-10 21:06:30 +00:00
|
|
|
sv = sv->next;
|
|
|
|
}
|
|
|
|
}
|
2003-02-12 02:39:24 +00:00
|
|
|
|
2003-02-12 17:15:03 +00:00
|
|
|
static void
|
|
|
|
SV_Frame (void)
|
2003-02-10 21:06:30 +00:00
|
|
|
{
|
2003-02-12 02:39:24 +00:00
|
|
|
Sys_CheckInput (1, net_socket);
|
|
|
|
Con_ProcessInput ();
|
2003-02-10 21:06:30 +00:00
|
|
|
Cbuf_Execute_Stack (mst_cbuf);
|
|
|
|
SV_TimeOut ();
|
|
|
|
SV_ReadPackets ();
|
|
|
|
}
|
|
|
|
|
2003-02-12 02:39:24 +00:00
|
|
|
static void
|
|
|
|
MST_Quit_f (void)
|
|
|
|
{
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("HW master shutdown\n");
|
2003-02-12 02:39:24 +00:00
|
|
|
Sys_Quit ();
|
|
|
|
}
|
|
|
|
|
2003-02-10 21:06:30 +00:00
|
|
|
int
|
|
|
|
main (int argc, const char **argv)
|
|
|
|
{
|
2003-02-12 02:39:24 +00:00
|
|
|
COM_InitArgv (argc, argv);
|
|
|
|
|
|
|
|
mst_cbuf = Cbuf_New (&id_interp);
|
|
|
|
|
2020-03-21 13:24:11 +00:00
|
|
|
Sys_RegisterShutdown (SV_Shutdown, 0);
|
2003-02-12 02:39:24 +00:00
|
|
|
|
|
|
|
Sys_Init ();
|
|
|
|
|
|
|
|
Cmd_AddCommand ("quit", MST_Quit_f, "Shut down the master server");
|
2003-02-12 17:15:03 +00:00
|
|
|
Cmd_AddCommand ("clear", SVL_Clear, "Clear the server list");
|
2003-02-12 18:36:14 +00:00
|
|
|
Cmd_AddCommand ("filter", Filter_f, "Manipulate filtering");
|
2003-02-12 02:39:24 +00:00
|
|
|
|
|
|
|
Cmd_StuffCmds (mst_cbuf);
|
|
|
|
Cbuf_Execute_Sets (mst_cbuf);
|
|
|
|
|
2003-02-10 21:06:30 +00:00
|
|
|
PI_Init ();
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Cvar_Register (&sv_console_plugin_cvar, 0, 0);
|
2003-02-10 21:06:30 +00:00
|
|
|
PI_RegisterPlugins (server_plugin_list);
|
2023-01-20 04:27:17 +00:00
|
|
|
Con_Load (sv_console_plugin);
|
2003-02-10 21:06:30 +00:00
|
|
|
if (con_module)
|
|
|
|
con_module->data->console->cbuf = mst_cbuf;
|
2023-01-20 04:27:17 +00:00
|
|
|
Con_Init ();
|
2003-02-10 21:06:30 +00:00
|
|
|
con_list_print = Sys_Printf;
|
|
|
|
|
|
|
|
SV_InitNet ();
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("Exe: " __TIME__ " " __DATE__ "\n");
|
|
|
|
Sys_Printf ("======== HW master initialized ========\n\n");
|
2003-02-10 21:06:30 +00:00
|
|
|
while (1) {
|
|
|
|
SV_Frame ();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|