2004-02-19 00:49:34 +00:00
|
|
|
/*
|
2005-06-09 03:07:13 +00:00
|
|
|
qtv.c
|
2004-02-19 00:49:34 +00:00
|
|
|
|
2005-06-09 03:07:13 +00:00
|
|
|
QTV main file
|
2004-02-19 00:49:34 +00:00
|
|
|
|
2005-06-09 03:07:13 +00:00
|
|
|
Copyright (C) 2004 Bill Currie <bill@taniwha.org>
|
2004-02-19 00:49:34 +00:00
|
|
|
|
2005-06-09 03:07:13 +00:00
|
|
|
Author: Bill Currie
|
|
|
|
Date: 2004/02/18
|
2004-02-19 00:49:34 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2004-02-20 04:29:03 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
2004-02-18 23:21:11 +00:00
|
|
|
#include <stdio.h>
|
2004-02-19 00:49:34 +00:00
|
|
|
#include <stdlib.h>
|
2004-02-20 04:29:03 +00:00
|
|
|
#include <time.h>
|
2004-02-19 00:49:34 +00:00
|
|
|
|
|
|
|
#include "QF/cbuf.h"
|
|
|
|
#include "QF/cmd.h"
|
|
|
|
#include "QF/console.h"
|
|
|
|
#include "QF/cvar.h"
|
2004-02-20 04:29:03 +00:00
|
|
|
#include "QF/dstring.h"
|
2004-02-19 00:49:34 +00:00
|
|
|
#include "QF/idparse.h"
|
2004-02-20 05:37:47 +00:00
|
|
|
#include "QF/info.h"
|
2004-02-19 00:49:34 +00:00
|
|
|
#include "QF/qargs.h"
|
|
|
|
#include "QF/quakefs.h"
|
|
|
|
#include "QF/sys.h"
|
2004-02-20 04:29:03 +00:00
|
|
|
#include "QF/va.h"
|
2004-02-19 00:49:34 +00:00
|
|
|
#include "QF/zone.h"
|
|
|
|
|
2012-02-13 12:58:34 +00:00
|
|
|
#include "QF/plugin/console.h"
|
|
|
|
|
2004-02-20 04:29:03 +00:00
|
|
|
#include "compat.h"
|
2004-02-19 00:49:34 +00:00
|
|
|
#include "netchan.h"
|
2020-06-21 14:15:17 +00:00
|
|
|
|
|
|
|
#include "qw/protocol.h"
|
|
|
|
|
|
|
|
#include "qtv/include/client.h"
|
|
|
|
#include "qtv/include/connection.h"
|
|
|
|
#include "qtv/include/qtv.h"
|
|
|
|
#include "qtv/include/server.h"
|
2004-02-19 00:49:34 +00:00
|
|
|
|
2005-05-05 07:31:31 +00:00
|
|
|
#undef qtv_print
|
|
|
|
|
2004-02-19 00:49:34 +00:00
|
|
|
SERVER_PLUGIN_PROTOS
|
|
|
|
static plugin_list_t server_plugin_list[] = {
|
|
|
|
SERVER_PLUGIN_LIST
|
|
|
|
};
|
|
|
|
|
2004-02-20 05:37:47 +00:00
|
|
|
double realtime;
|
|
|
|
|
[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
|
|
|
float sv_timeout;
|
|
|
|
static cvar_t sv_timeout_cvar = {
|
|
|
|
.name = "timeout",
|
|
|
|
.description =
|
|
|
|
"Sets the amount of time in seconds before a client is considered "
|
|
|
|
"disconnected if the server does not receive a packet",
|
|
|
|
.default_value = "60",
|
|
|
|
.flags = CVAR_NONE,
|
|
|
|
.value = { .type = &cexpr_float, .value = &sv_timeout },
|
|
|
|
};
|
2010-01-13 06:46:26 +00:00
|
|
|
|
2004-02-19 00:49:34 +00:00
|
|
|
cbuf_t *qtv_cbuf;
|
2004-02-20 04:29:03 +00:00
|
|
|
cbuf_args_t *qtv_args;
|
2004-02-19 00:49:34 +00:00
|
|
|
|
[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 *qtv_console_plugin;
|
|
|
|
static cvar_t qtv_console_plugin_cvar = {
|
|
|
|
.name = "qtv_console_plugin",
|
|
|
|
.description =
|
|
|
|
"Plugin used for the console",
|
|
|
|
.default_value = "server",
|
|
|
|
.flags = CVAR_ROM,
|
|
|
|
.value = { .type = 0, .value = &qtv_console_plugin },
|
|
|
|
};
|
|
|
|
static int qtv_port;
|
|
|
|
static cvar_t qtv_port_cvar = {
|
|
|
|
.name = "qtv_port",
|
|
|
|
.description =
|
|
|
|
"udp port to use",
|
|
|
|
.default_value = 0,
|
|
|
|
.flags = CVAR_ROM,
|
|
|
|
.value = { .type = &cexpr_int, .value = &qtv_port },
|
|
|
|
};
|
|
|
|
static float qtv_mem_size;
|
|
|
|
static cvar_t qtv_mem_size_cvar = {
|
|
|
|
.name = "qtv_mem_size",
|
|
|
|
.description =
|
|
|
|
"Amount of memory (in MB) to allocate for the "
|
|
|
|
PACKAGE_NAME
|
|
|
|
" heap",
|
|
|
|
.default_value = "8",
|
|
|
|
.flags = CVAR_ROM,
|
|
|
|
.value = { .type = &cexpr_float, .value = &qtv_mem_size },
|
|
|
|
};
|
2004-02-19 00:49:34 +00:00
|
|
|
|
2004-02-20 04:29:03 +00:00
|
|
|
redirect_t qtv_redirected;
|
2004-02-22 06:19:38 +00:00
|
|
|
client_t *qtv_redirect_client;
|
2004-02-20 04:29:03 +00:00
|
|
|
dstring_t outputbuf = {&dstring_default_mem};
|
|
|
|
|
2021-03-27 10:52:59 +00:00
|
|
|
static __attribute__((format(PRINTF, 1, 0))) void
|
2004-02-20 04:29:03 +00:00
|
|
|
qtv_print (const char *fmt, va_list args)
|
|
|
|
{
|
|
|
|
static int pending;
|
|
|
|
static dstring_t *msg;
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2004-02-20 04:29:03 +00:00
|
|
|
if (!msg)
|
|
|
|
msg = dstring_new ();
|
|
|
|
|
|
|
|
dvsprintf (msg, fmt, args);
|
|
|
|
if (qtv_redirected)
|
|
|
|
dstring_appendstr (&outputbuf, msg->str);
|
|
|
|
else {
|
|
|
|
time_t mytime;
|
|
|
|
struct tm *local;
|
|
|
|
char stamp[123];
|
|
|
|
|
|
|
|
if (pending) {
|
2010-01-13 06:43:27 +00:00
|
|
|
Con_Printf ("%s", msg->str);
|
2004-02-20 04:29:03 +00:00
|
|
|
} else {
|
|
|
|
mytime = time (NULL);
|
|
|
|
local = localtime (&mytime);
|
2010-12-23 02:40:16 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
strftime (stamp, sizeof (stamp), "[%b %d %X] ", local);
|
|
|
|
#else
|
2004-02-20 04:29:03 +00:00
|
|
|
strftime (stamp, sizeof (stamp), "[%b %e %X] ", local);
|
2010-12-23 02:40:16 +00:00
|
|
|
#endif
|
2010-01-13 06:43:27 +00:00
|
|
|
Con_Printf ("%s%s", stamp, msg->str);
|
2004-02-20 04:29:03 +00:00
|
|
|
}
|
|
|
|
if (msg->str[0] && msg->str[strlen (msg->str) - 1] != '\n') {
|
|
|
|
pending = 1;
|
|
|
|
} else {
|
|
|
|
pending = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-21 05:09:02 +00:00
|
|
|
void
|
|
|
|
qtv_printf (const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
|
|
|
|
va_start (argptr, fmt);
|
|
|
|
qtv_print (fmt, argptr);
|
|
|
|
va_end (argptr);
|
|
|
|
}
|
|
|
|
|
2010-12-21 00:23:59 +00:00
|
|
|
static void
|
2004-02-20 04:29:03 +00:00
|
|
|
qtv_flush_redirect (void)
|
|
|
|
{
|
|
|
|
char send[8000 + 6];
|
2004-07-13 19:14:01 +00:00
|
|
|
size_t count;
|
2004-02-20 04:29:03 +00:00
|
|
|
int bytes;
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
if (!outputbuf.size)
|
|
|
|
return;
|
|
|
|
|
|
|
|
count = strlen (outputbuf.str);
|
|
|
|
if (qtv_redirected == RD_PACKET) {
|
|
|
|
send[0] = 0xff;
|
|
|
|
send[1] = 0xff;
|
|
|
|
send[2] = 0xff;
|
|
|
|
send[3] = 0xff;
|
|
|
|
send[4] = A2C_PRINT;
|
|
|
|
|
|
|
|
p = outputbuf.str;
|
|
|
|
while (count) {
|
|
|
|
bytes = min (count, sizeof (send) - 5);
|
|
|
|
memcpy (send + 5, p, bytes);
|
|
|
|
Netchan_SendPacket (bytes + 5, send, net_from);
|
|
|
|
p += bytes;
|
|
|
|
count -= bytes;
|
|
|
|
}
|
2004-02-21 05:09:02 +00:00
|
|
|
} else if (qtv_redirected == RD_CLIENT) {
|
2004-02-22 06:19:38 +00:00
|
|
|
client_t *cl = qtv_redirect_client;
|
2004-02-21 05:09:02 +00:00
|
|
|
p = outputbuf.str;
|
|
|
|
while (count) {
|
|
|
|
// +/- 3 for svc_print, PRINT_HIGH and nul byte
|
|
|
|
// min of 4 because we don't want to send an effectively empty
|
|
|
|
// message
|
2004-02-22 06:19:38 +00:00
|
|
|
bytes = MSG_ReliableCheckSize (&cl->backbuf, count + 3, 4) - 3;
|
2004-02-21 05:09:02 +00:00
|
|
|
// if writing another packet would overflow the client, just drop
|
|
|
|
// the rest of the data. getting rudely disconnected would be much
|
|
|
|
// more annoying than losing the tail end of the output
|
|
|
|
if (bytes <= 0)
|
|
|
|
break;
|
2004-02-22 06:19:38 +00:00
|
|
|
MSG_ReliableWrite_Begin (&cl->backbuf, svc_print, bytes + 3);
|
|
|
|
MSG_ReliableWrite_Byte (&cl->backbuf, PRINT_HIGH);
|
|
|
|
MSG_ReliableWrite_SZ (&cl->backbuf, p, bytes);
|
|
|
|
MSG_ReliableWrite_Byte (&cl->backbuf, 0);
|
2004-02-21 05:09:02 +00:00
|
|
|
p += bytes;
|
|
|
|
count -= bytes;
|
|
|
|
}
|
2004-02-20 04:29:03 +00:00
|
|
|
}
|
|
|
|
dstring_clear (&outputbuf);
|
|
|
|
}
|
|
|
|
|
2004-02-21 05:09:02 +00:00
|
|
|
void
|
2004-02-22 06:19:38 +00:00
|
|
|
qtv_begin_redirect (redirect_t rd, client_t *cl)
|
2004-02-20 04:29:03 +00:00
|
|
|
{
|
|
|
|
qtv_redirected = rd;
|
2004-02-22 06:19:38 +00:00
|
|
|
qtv_redirect_client = cl;
|
2004-02-20 04:29:03 +00:00
|
|
|
dstring_clear (&outputbuf);
|
|
|
|
}
|
|
|
|
|
2004-02-21 05:09:02 +00:00
|
|
|
void
|
2004-02-20 04:29:03 +00:00
|
|
|
qtv_end_redirect (void)
|
|
|
|
{
|
|
|
|
qtv_flush_redirect ();
|
|
|
|
qtv_redirected = RD_NONE;
|
2004-02-22 06:19:38 +00:00
|
|
|
qtv_redirect_client = 0;
|
2004-02-20 04:29:03 +00:00
|
|
|
}
|
|
|
|
|
2021-12-13 00:13:39 +00:00
|
|
|
static memhunk_t *
|
2004-02-19 00:49:34 +00:00
|
|
|
qtv_memory_init (void)
|
|
|
|
{
|
|
|
|
int mem_size;
|
|
|
|
void *mem_base;
|
|
|
|
|
[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 (&qtv_mem_size_cvar, 0, 0);
|
2004-02-19 00:49:34 +00:00
|
|
|
|
[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
|
|
|
mem_size = (int) (qtv_mem_size * 1024 * 1024);
|
2021-02-03 04:19:19 +00:00
|
|
|
mem_base = Sys_Alloc (mem_size);
|
2004-02-19 00:49:34 +00:00
|
|
|
if (!mem_base)
|
|
|
|
Sys_Error ("Can't allocate %d", mem_size);
|
2021-12-13 00:13:39 +00:00
|
|
|
return Memory_Init (mem_base, mem_size);
|
2004-02-19 00:49:34 +00:00
|
|
|
}
|
|
|
|
|
2004-02-20 02:39:34 +00:00
|
|
|
static void
|
2020-03-21 13:24:11 +00:00
|
|
|
qtv_shutdown (void *data)
|
2004-02-20 02:39:34 +00:00
|
|
|
{
|
2005-05-05 22:50:09 +00:00
|
|
|
Cbuf_Delete (qtv_cbuf);
|
|
|
|
Cbuf_ArgsDelete (qtv_args);
|
2004-02-20 02:39:34 +00:00
|
|
|
}
|
|
|
|
|
2004-02-19 00:49:34 +00:00
|
|
|
static void
|
|
|
|
qtv_quit_f (void)
|
|
|
|
{
|
|
|
|
Sys_Printf ("Shutting down.\n");
|
|
|
|
Sys_Quit ();
|
|
|
|
}
|
|
|
|
|
2004-02-20 04:29:03 +00:00
|
|
|
static void
|
|
|
|
qtv_net_init (void)
|
|
|
|
{
|
[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
|
|
|
qtv_port_cvar.default_value = nva ("%d", PORT_QTV);
|
|
|
|
Cvar_Register (&qtv_port_cvar, 0, 0);
|
|
|
|
Cvar_Register (&sv_timeout_cvar, 0, 0);
|
|
|
|
NET_Init (qtv_port);
|
2004-02-20 04:29:03 +00:00
|
|
|
Connection_Init ();
|
2004-02-20 05:37:47 +00:00
|
|
|
net_realtime = &realtime;
|
2004-02-20 04:29:03 +00:00
|
|
|
Netchan_Init ();
|
|
|
|
}
|
|
|
|
|
2004-02-19 00:49:34 +00:00
|
|
|
static void
|
|
|
|
qtv_init (void)
|
|
|
|
{
|
|
|
|
qtv_cbuf = Cbuf_New (&id_interp);
|
2004-02-20 04:29:03 +00:00
|
|
|
qtv_args = Cbuf_ArgsNew ();
|
2004-02-19 00:49:34 +00:00
|
|
|
|
2020-03-21 13:24:11 +00:00
|
|
|
Sys_RegisterShutdown (qtv_shutdown, 0);
|
2004-02-20 02:39:34 +00:00
|
|
|
|
2004-02-19 00:49:34 +00:00
|
|
|
Sys_Init ();
|
2021-04-12 13:09:09 +00:00
|
|
|
COM_ParseConfig (qtv_cbuf);
|
[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
|
|
|
cmd_warncmd = 1;
|
2004-02-19 00:49:34 +00:00
|
|
|
|
2021-12-13 00:13:39 +00:00
|
|
|
memhunk_t *hunk = qtv_memory_init ();
|
2004-02-19 00:49:34 +00:00
|
|
|
|
2021-12-13 00:13:39 +00:00
|
|
|
QFS_Init (hunk, "qw");
|
2004-02-19 00:49:34 +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 (&qtv_console_plugin_cvar, 0, 0);
|
2004-02-19 00:49:34 +00:00
|
|
|
PI_RegisterPlugins (server_plugin_list);
|
2023-01-20 04:27:17 +00:00
|
|
|
Con_Load (qtv_console_plugin);
|
2012-05-21 23:23:22 +00:00
|
|
|
if (con_module)
|
2004-02-19 00:49:34 +00:00
|
|
|
con_module->data->console->cbuf = qtv_cbuf;
|
2023-01-20 04:27:17 +00:00
|
|
|
Con_Init ();
|
2004-02-20 04:29:03 +00:00
|
|
|
Sys_SetStdPrintf (qtv_print);
|
2004-02-19 00:49:34 +00:00
|
|
|
|
2010-12-21 09:15:31 +00:00
|
|
|
qtv_sbar_init ();
|
|
|
|
|
2004-02-19 00:49:34 +00:00
|
|
|
Netchan_Init_Cvars ();
|
|
|
|
|
|
|
|
Cmd_StuffCmds (qtv_cbuf);
|
|
|
|
Cbuf_Execute_Sets (qtv_cbuf);
|
|
|
|
|
2004-02-20 04:29:03 +00:00
|
|
|
qtv_net_init ();
|
2004-02-20 02:39:34 +00:00
|
|
|
Server_Init ();
|
2004-02-21 05:09:02 +00:00
|
|
|
Client_Init ();
|
2004-02-20 02:39:34 +00:00
|
|
|
|
2004-02-19 00:49:34 +00:00
|
|
|
Cmd_AddCommand ("quit", qtv_quit_f, "Shut down qtv");
|
|
|
|
|
|
|
|
Cmd_StuffCmds (qtv_cbuf);
|
|
|
|
}
|
2004-02-18 23:21:11 +00:00
|
|
|
|
2004-02-20 04:29:03 +00:00
|
|
|
static void
|
|
|
|
qtv_ping (void)
|
|
|
|
{
|
|
|
|
char data = A2A_ACK;
|
|
|
|
|
|
|
|
Netchan_SendPacket (1, &data, net_from);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
qtv_status (void)
|
|
|
|
{
|
2004-02-22 06:19:38 +00:00
|
|
|
qtv_begin_redirect (RD_PACKET, 0);
|
2010-08-19 06:01:43 +00:00
|
|
|
Sys_Printf ("\\*version\\%s qtv %s", QW_VERSION, PACKAGE_VERSION);
|
2004-02-20 04:29:03 +00:00
|
|
|
qtv_end_redirect ();
|
|
|
|
}
|
|
|
|
|
2010-12-21 00:23:59 +00:00
|
|
|
static void
|
2004-02-20 04:29:03 +00:00
|
|
|
qtv_connectionless_packet (void)
|
|
|
|
{
|
|
|
|
const char *cmd, *str;
|
|
|
|
|
|
|
|
MSG_BeginReading (net_message);
|
|
|
|
MSG_ReadLong (net_message); // skip the -1 marker
|
|
|
|
|
|
|
|
str = MSG_ReadString (net_message);
|
|
|
|
COM_TokenizeString (str, qtv_args);
|
|
|
|
cmd_args = qtv_args;
|
|
|
|
|
|
|
|
cmd = qtv_args->argv[0]->str;
|
2004-02-21 02:31:22 +00:00
|
|
|
if (!strcmp (cmd, "ping")) {
|
2004-02-20 04:29:03 +00:00
|
|
|
qtv_ping ();
|
|
|
|
} else if (!strcmp (cmd, "status")) {
|
|
|
|
qtv_status ();
|
2004-02-20 05:37:47 +00:00
|
|
|
} else if (!strcmp (cmd, "getchallenge")) {
|
2004-02-21 05:09:02 +00:00
|
|
|
Client_NewConnection ();
|
2004-02-21 02:31:22 +00:00
|
|
|
} else if (cmd[0]) {
|
|
|
|
switch (cmd[0]) {
|
|
|
|
default:
|
|
|
|
goto bad_packet;
|
|
|
|
case A2C_PRINT:
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("%s", str + 1);
|
2004-02-21 02:31:22 +00:00
|
|
|
break;
|
|
|
|
case A2A_PING:
|
|
|
|
qtv_ping ();
|
|
|
|
break;
|
|
|
|
}
|
2004-02-20 04:29:03 +00:00
|
|
|
} else {
|
2004-02-21 02:31:22 +00:00
|
|
|
bad_packet:
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("bad connectionless packet from %s:\n%s\n",
|
2004-02-20 04:29:03 +00:00
|
|
|
NET_AdrToString (net_from), str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
qtv_read_packets (void)
|
|
|
|
{
|
|
|
|
connection_t *con;
|
|
|
|
|
|
|
|
while (NET_GetPacket ()) {
|
2004-02-21 02:31:22 +00:00
|
|
|
if ((con = Connection_Find (&net_from))) {
|
|
|
|
con->handler (con, con->object);
|
|
|
|
} else if (*(int *) net_message->message->data == -1) {
|
2004-02-20 04:29:03 +00:00
|
|
|
qtv_connectionless_packet ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-18 23:21:11 +00:00
|
|
|
int
|
2004-02-19 00:49:34 +00:00
|
|
|
main (int argc, const char *argv[])
|
2004-02-18 23:21:11 +00:00
|
|
|
{
|
2010-12-21 09:15:31 +00:00
|
|
|
int frame = 0;
|
|
|
|
|
2004-02-19 00:49:34 +00:00
|
|
|
COM_InitArgv (argc, argv);
|
|
|
|
|
|
|
|
qtv_init ();
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("Ohayou gozaimasu\n");
|
2004-02-19 00:49:34 +00:00
|
|
|
|
|
|
|
while (1) {
|
2021-12-27 08:00:43 +00:00
|
|
|
realtime = Sys_DoubleTime () + 1;
|
2004-02-19 00:49:34 +00:00
|
|
|
Cbuf_Execute_Stack (qtv_cbuf);
|
|
|
|
|
|
|
|
Sys_CheckInput (1, net_socket);
|
2004-02-20 04:29:03 +00:00
|
|
|
|
|
|
|
qtv_read_packets ();
|
|
|
|
|
2004-02-19 00:49:34 +00:00
|
|
|
Con_ProcessInput ();
|
2005-05-02 04:09:15 +00:00
|
|
|
|
|
|
|
Server_Frame ();
|
2005-05-08 00:48:21 +00:00
|
|
|
Client_Frame ();
|
2010-12-21 09:15:31 +00:00
|
|
|
|
|
|
|
if (++frame == 100) {
|
|
|
|
frame = 0;
|
|
|
|
Con_DrawConsole ();
|
|
|
|
}
|
2004-02-19 00:49:34 +00:00
|
|
|
}
|
2004-02-18 23:21:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|