2004-03-04 00:13:20 +00:00
|
|
|
/*
|
|
|
|
#FILENAME#
|
|
|
|
|
|
|
|
#DESCRIPTION#
|
|
|
|
|
2010-01-13 06:50:44 +00:00
|
|
|
Copyright (C) 2004 Bill Currie <bill@taniwha.org>
|
2004-03-04 00:13:20 +00:00
|
|
|
|
2010-01-13 06:50:44 +00:00
|
|
|
Author: Bill Currie
|
|
|
|
Date: 2004/3/4
|
2004-03-04 00:13:20 +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
|
|
|
|
|
2005-05-02 04:09:15 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2004-03-04 00:13:20 +00:00
|
|
|
#include "QF/cmd.h"
|
2005-05-02 04:09:15 +00:00
|
|
|
#include "QF/cbuf.h"
|
|
|
|
#include "QF/dstring.h"
|
2004-03-05 23:42:15 +00:00
|
|
|
#include "QF/hash.h"
|
2005-05-02 04:09:15 +00:00
|
|
|
#include "QF/idparse.h"
|
2004-03-05 23:42:15 +00:00
|
|
|
#include "QF/info.h"
|
2007-11-06 10:17:14 +00:00
|
|
|
#include "QF/sys.h"
|
2005-05-02 09:00:17 +00:00
|
|
|
#include "QF/va.h"
|
2004-03-04 00:13:20 +00:00
|
|
|
|
2005-05-02 04:09:15 +00:00
|
|
|
#include "compat.h"
|
2020-06-21 14:15:17 +00:00
|
|
|
|
|
|
|
#include "qw/include/server.h"
|
|
|
|
#include "qw/include/sv_qtv.h"
|
|
|
|
#include "qw/include/sv_recorder.h"
|
2004-03-04 00:13:20 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2004-03-05 23:42:15 +00:00
|
|
|
netchan_t netchan;
|
|
|
|
backbuf_t backbuf;
|
|
|
|
info_t *info;
|
|
|
|
info_key_t *name_key;
|
2005-05-05 11:46:29 +00:00
|
|
|
qboolean packet;
|
2005-05-05 07:31:31 +00:00
|
|
|
recorder_t *recorder;
|
|
|
|
sizebuf_t datagram;
|
|
|
|
byte datagram_buf[MAX_DATAGRAM];
|
2005-05-05 11:46:29 +00:00
|
|
|
int begun;
|
2004-03-04 00:13:20 +00:00
|
|
|
} sv_qtv_t;
|
|
|
|
|
2004-03-05 23:42:15 +00:00
|
|
|
#define MAX_PROXIES 2
|
|
|
|
|
|
|
|
static sv_qtv_t proxies[MAX_PROXIES];
|
|
|
|
|
|
|
|
static sv_qtv_t *
|
|
|
|
alloc_proxy (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_PROXIES; i++) {
|
|
|
|
if (!proxies[i].info)
|
|
|
|
return proxies;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-05-02 04:09:15 +00:00
|
|
|
static void
|
|
|
|
drop_proxy (sv_qtv_t *proxy)
|
|
|
|
{
|
|
|
|
SV_Printf ("dropped %s\n", proxy->name_key->value);
|
2005-05-05 07:31:31 +00:00
|
|
|
if (proxy->recorder) {
|
|
|
|
SVR_RemoveUser (proxy->recorder);
|
|
|
|
proxy->recorder = 0;
|
|
|
|
}
|
2005-05-02 04:09:15 +00:00
|
|
|
MSG_WriteByte (&proxy->netchan.message, qtv_disconnect);
|
|
|
|
Netchan_Transmit (&proxy->netchan, 0, 0);
|
2005-05-05 11:46:29 +00:00
|
|
|
proxy->packet = false;
|
2005-05-02 04:09:15 +00:00
|
|
|
Info_Destroy (proxy->info);
|
|
|
|
proxy->info = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
qtv_new_f (sv_qtv_t *proxy)
|
|
|
|
{
|
|
|
|
const char *gamedir;
|
2005-05-05 07:31:31 +00:00
|
|
|
int pos, len;
|
|
|
|
byte *buf;
|
2005-05-02 04:09:15 +00:00
|
|
|
|
|
|
|
gamedir = Info_ValueForKey (svs.info, "*gamedir");
|
|
|
|
if (!gamedir[0])
|
|
|
|
gamedir = "qw";
|
|
|
|
|
2005-05-05 07:31:31 +00:00
|
|
|
MSG_WriteByte (&proxy->netchan.message, qtv_packet);
|
|
|
|
pos = proxy->netchan.message.cursize;
|
|
|
|
MSG_WriteShort (&proxy->netchan.message, qtv_p_signon);
|
|
|
|
MSG_WriteByte (&proxy->netchan.message, svc_serverdata);
|
2005-05-02 04:09:15 +00:00
|
|
|
MSG_WriteLong (&proxy->netchan.message, PROTOCOL_VERSION);
|
|
|
|
MSG_WriteLong (&proxy->netchan.message, svs.spawncount);
|
|
|
|
MSG_WriteString (&proxy->netchan.message, gamedir);
|
|
|
|
SV_WriteWorldVars (&proxy->netchan);
|
2005-05-05 07:31:31 +00:00
|
|
|
len = proxy->netchan.message.cursize - pos - 2;
|
|
|
|
buf = proxy->netchan.message.data + pos;
|
|
|
|
buf[0] = len & 0xff;
|
|
|
|
buf[1] |= (len >> 8) & 0x0f;
|
2010-01-13 06:46:26 +00:00
|
|
|
proxy->begun = 0;
|
2005-05-02 04:09:15 +00:00
|
|
|
}
|
|
|
|
|
2005-05-02 09:00:17 +00:00
|
|
|
static void
|
|
|
|
qtv_soundlist_f (sv_qtv_t *proxy)
|
|
|
|
{
|
|
|
|
int n;
|
2005-05-05 07:31:31 +00:00
|
|
|
int pos, len;
|
|
|
|
byte *buf;
|
2005-05-02 09:00:17 +00:00
|
|
|
|
|
|
|
if (atoi (Cmd_Argv (1)) != svs.spawncount) {
|
|
|
|
qtv_new_f (proxy);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = atoi (Cmd_Argv (2));
|
|
|
|
if (n >= MAX_SOUNDS) {
|
|
|
|
qtv_new_f (proxy);
|
|
|
|
return;
|
|
|
|
}
|
2005-05-05 07:31:31 +00:00
|
|
|
MSG_WriteByte (&proxy->netchan.message, qtv_packet);
|
|
|
|
pos = proxy->netchan.message.cursize;
|
|
|
|
MSG_WriteShort (&proxy->netchan.message, qtv_p_signon);
|
2005-05-02 09:00:17 +00:00
|
|
|
SV_WriteSoundlist (&proxy->netchan, n);
|
2005-05-05 07:31:31 +00:00
|
|
|
len = proxy->netchan.message.cursize - pos - 2;
|
|
|
|
buf = proxy->netchan.message.data + pos;
|
|
|
|
buf[0] = len & 0xff;
|
|
|
|
buf[1] |= (len >> 8) & 0x0f;
|
2005-05-02 09:00:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
qtv_modellist_f (sv_qtv_t *proxy)
|
|
|
|
{
|
|
|
|
int n;
|
2005-05-05 07:31:31 +00:00
|
|
|
int pos, len;
|
|
|
|
byte *buf;
|
2005-05-02 09:00:17 +00:00
|
|
|
|
|
|
|
if (atoi (Cmd_Argv (1)) != svs.spawncount) {
|
|
|
|
qtv_new_f (proxy);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = atoi (Cmd_Argv (2));
|
2010-01-13 06:46:26 +00:00
|
|
|
if (n >= MAX_MODELS) {
|
2005-05-02 09:00:17 +00:00
|
|
|
qtv_new_f (proxy);
|
|
|
|
return;
|
|
|
|
}
|
2005-05-05 07:31:31 +00:00
|
|
|
MSG_WriteByte (&proxy->netchan.message, qtv_packet);
|
|
|
|
pos = proxy->netchan.message.cursize;
|
|
|
|
MSG_WriteShort (&proxy->netchan.message, qtv_p_signon);
|
2005-05-02 09:00:17 +00:00
|
|
|
SV_WriteModellist (&proxy->netchan, n);
|
2005-05-05 07:31:31 +00:00
|
|
|
len = proxy->netchan.message.cursize - pos - 2;
|
|
|
|
buf = proxy->netchan.message.data + pos;
|
|
|
|
buf[0] = len & 0xff;
|
|
|
|
buf[1] |= (len >> 8) & 0x0f;
|
2005-05-02 09:00:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
qtv_prespawn_f (sv_qtv_t *proxy)
|
|
|
|
{
|
|
|
|
int buf;
|
|
|
|
int size;
|
|
|
|
const char *command;
|
|
|
|
sizebuf_t *msg;
|
|
|
|
|
|
|
|
if (atoi (Cmd_Argv (1)) != svs.spawncount) {
|
|
|
|
qtv_new_f (proxy);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = atoi (Cmd_Argv (2));
|
|
|
|
if (buf >= sv.num_signon_buffers)
|
|
|
|
buf = 0;
|
|
|
|
|
|
|
|
if (buf == sv.num_signon_buffers - 1)
|
2021-01-31 07:01:20 +00:00
|
|
|
command = va (0, "cmd spawn %i 0\n", svs.spawncount);
|
2005-05-02 09:00:17 +00:00
|
|
|
else
|
2021-01-31 07:01:20 +00:00
|
|
|
command = va (0, "cmd prespawn %i %i\n", svs.spawncount, buf + 1);
|
2010-01-13 06:46:26 +00:00
|
|
|
size = (3 + sv.signon_buffer_size[buf]) + (1 + strlen (command) + 1);
|
2005-05-02 09:00:17 +00:00
|
|
|
|
|
|
|
msg = MSG_ReliableCheckBlock (&proxy->backbuf, size);
|
|
|
|
|
2005-05-05 07:31:31 +00:00
|
|
|
MSG_WriteByte (msg, qtv_packet);
|
|
|
|
MSG_WriteShort (msg, qtv_p_signon | sv.signon_buffer_size[buf]);
|
2005-05-02 09:00:17 +00:00
|
|
|
SZ_Write (msg, sv.signon_buffers[buf], sv.signon_buffer_size[buf]);
|
|
|
|
|
|
|
|
MSG_WriteByte (msg, qtv_stringcmd);
|
|
|
|
MSG_WriteString (msg, command);
|
|
|
|
}
|
|
|
|
|
2005-05-05 07:31:31 +00:00
|
|
|
static void
|
|
|
|
qtv_spawn_f (sv_qtv_t *proxy)
|
|
|
|
{
|
2005-05-05 11:46:29 +00:00
|
|
|
int pos = -1, len = 0;
|
|
|
|
byte *buf = 0;
|
2005-05-05 07:31:31 +00:00
|
|
|
|
|
|
|
if (atoi (Cmd_Argv (1)) != svs.spawncount) {
|
|
|
|
qtv_new_f (proxy);
|
|
|
|
return;
|
|
|
|
}
|
2005-05-05 11:46:29 +00:00
|
|
|
if (!proxy->backbuf.num_backbuf) {
|
|
|
|
MSG_WriteByte (&proxy->netchan.message, qtv_packet);
|
|
|
|
pos = proxy->netchan.message.cursize;
|
|
|
|
MSG_WriteShort (&proxy->netchan.message, qtv_p_signon);
|
|
|
|
}
|
2005-05-05 07:31:31 +00:00
|
|
|
SV_WriteSpawn1 (&proxy->backbuf, 0);
|
|
|
|
SV_WriteSpawn2 (&proxy->backbuf);
|
2005-05-05 11:46:29 +00:00
|
|
|
MSG_ReliableWrite_Begin (&proxy->backbuf, svc_stufftext, 8);
|
2005-05-05 07:31:31 +00:00
|
|
|
MSG_ReliableWrite_String (&proxy->backbuf, "skins\n");
|
2005-05-05 11:46:29 +00:00
|
|
|
if (pos != -1) {
|
|
|
|
len = proxy->netchan.message.cursize - pos - 2;
|
|
|
|
buf = proxy->netchan.message.data + pos;
|
|
|
|
buf[0] = len & 0xff;
|
|
|
|
buf[1] |= (len >> 8) & 0x0f;
|
|
|
|
}
|
2005-05-05 07:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
qtv_write (void *r, sizebuf_t *msg, int reliable)
|
|
|
|
{
|
|
|
|
sv_qtv_t *proxy = (sv_qtv_t *) r;
|
|
|
|
sizebuf_t *buf;
|
2005-05-05 11:46:29 +00:00
|
|
|
int type;
|
2005-05-05 07:31:31 +00:00
|
|
|
|
2005-05-05 11:46:29 +00:00
|
|
|
if (!msg->cursize)
|
|
|
|
return;
|
2005-05-05 07:31:31 +00:00
|
|
|
if (reliable) {
|
2010-01-13 06:46:26 +00:00
|
|
|
buf = MSG_ReliableCheckBlock (&proxy->backbuf, msg->cursize + 3);
|
2005-05-05 11:46:29 +00:00
|
|
|
type = qtv_p_reliable;
|
2005-05-05 07:31:31 +00:00
|
|
|
} else {
|
2005-05-05 11:46:29 +00:00
|
|
|
buf = &proxy->datagram;
|
|
|
|
type = qtv_p_unreliable;
|
2005-05-05 07:31:31 +00:00
|
|
|
}
|
2005-05-05 11:46:29 +00:00
|
|
|
MSG_WriteByte (buf, qtv_packet);
|
|
|
|
MSG_WriteShort (buf, type | msg->cursize);
|
|
|
|
SZ_Write (buf, msg->data, msg->cursize);
|
2005-05-05 07:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
qtv_frame (void *r)
|
|
|
|
{
|
|
|
|
sv_qtv_t *proxy = (sv_qtv_t *) r;
|
|
|
|
return proxy->packet;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
qtv_finish (void *r, sizebuf_t *msg)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
qtv_begin_f (sv_qtv_t *proxy)
|
|
|
|
{
|
|
|
|
if (atoi (Cmd_Argv (1)) != svs.spawncount) {
|
|
|
|
qtv_new_f (proxy);
|
|
|
|
return;
|
|
|
|
}
|
2010-01-13 06:49:28 +00:00
|
|
|
if (!proxy->recorder)
|
|
|
|
proxy->recorder = SVR_AddUser (qtv_write, qtv_frame, 0, qtv_finish, 0,
|
|
|
|
proxy);
|
2010-01-13 06:50:44 +00:00
|
|
|
else
|
|
|
|
SVR_Continue (proxy->recorder);
|
2005-05-05 11:46:29 +00:00
|
|
|
proxy->begun = 1;
|
2005-05-05 07:31:31 +00:00
|
|
|
}
|
|
|
|
|
2005-05-02 04:09:15 +00:00
|
|
|
typedef struct {
|
|
|
|
const char *name;
|
|
|
|
void (*func) (sv_qtv_t *proxy);
|
|
|
|
unsigned no_redirect:1;
|
|
|
|
} qcmd_t;
|
|
|
|
|
|
|
|
qcmd_t qcmds[] = {
|
2005-05-02 09:00:17 +00:00
|
|
|
{"drop", drop_proxy},
|
|
|
|
{"new", qtv_new_f},
|
|
|
|
{"soundlist", qtv_soundlist_f},
|
|
|
|
{"modellist", qtv_modellist_f},
|
|
|
|
{"prespawn", qtv_prespawn_f},
|
2005-05-05 07:31:31 +00:00
|
|
|
{"spawn", qtv_spawn_f},
|
|
|
|
{"begin", qtv_begin_f},
|
2005-05-02 04:09:15 +00:00
|
|
|
|
2005-05-02 09:00:17 +00:00
|
|
|
{0, 0},
|
2005-05-02 04:09:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
qtv_command (sv_qtv_t *proxy, const char *s)
|
|
|
|
{
|
|
|
|
qcmd_t *c;
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
COM_TokenizeString (s, sv_args);
|
|
|
|
cmd_args = sv_args;
|
|
|
|
name = Cmd_Argv (0);
|
|
|
|
|
|
|
|
for (c = qcmds; c->name; c++)
|
|
|
|
if (strcmp (c->name, name) == 0)
|
|
|
|
break;
|
|
|
|
if (!c->name) {
|
|
|
|
SV_Printf ("Bad QTV command: %s\n", sv_args->argv[0]->str);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
c->func (proxy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
qtv_parse (sv_qtv_t *proxy)
|
|
|
|
{
|
2005-05-05 11:46:29 +00:00
|
|
|
int c, delta;
|
2005-05-02 04:09:15 +00:00
|
|
|
|
2005-05-05 11:46:29 +00:00
|
|
|
// make sure the reply sequence number matches the incoming
|
2012-05-21 23:23:22 +00:00
|
|
|
// sequence number
|
2005-05-05 11:46:29 +00:00
|
|
|
if (proxy->netchan.incoming_sequence >= proxy->netchan.outgoing_sequence) {
|
|
|
|
proxy->netchan.outgoing_sequence = proxy->netchan.incoming_sequence;
|
|
|
|
proxy->packet = true;
|
|
|
|
} else {
|
2010-01-13 06:45:43 +00:00
|
|
|
SV_Printf ("qtv_parse: slipped sequence: %d %d\n",
|
|
|
|
proxy->netchan.incoming_sequence,
|
|
|
|
proxy->netchan.outgoing_sequence);
|
2005-05-05 11:46:29 +00:00
|
|
|
proxy->packet = false; // don't reply, sequences have slipped
|
|
|
|
return; // FIXME right thing?
|
|
|
|
}
|
|
|
|
if (proxy->recorder)
|
|
|
|
SVR_SetDelta (proxy->recorder, -1, proxy->netchan.incoming_sequence);
|
2005-05-02 04:09:15 +00:00
|
|
|
while (1) {
|
|
|
|
if (net_message->badread) {
|
2010-01-13 06:45:43 +00:00
|
|
|
SV_Printf ("qtv_parse: badread\n");
|
2005-05-02 04:09:15 +00:00
|
|
|
drop_proxy (proxy);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
c = MSG_ReadByte (net_message);
|
|
|
|
if (c == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
default:
|
2010-01-13 06:45:43 +00:00
|
|
|
SV_Printf ("qtv_parse: unknown command char\n");
|
2005-05-02 04:09:15 +00:00
|
|
|
drop_proxy (proxy);
|
|
|
|
return;
|
|
|
|
case qtv_nop:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case qtv_stringcmd:
|
|
|
|
qtv_command (proxy, MSG_ReadString (net_message));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case qtv_delta:
|
2005-05-05 11:46:29 +00:00
|
|
|
delta = MSG_ReadByte (net_message);
|
|
|
|
if (proxy->recorder)
|
|
|
|
SVR_SetDelta (proxy->recorder, delta,
|
|
|
|
proxy->netchan.incoming_sequence);
|
2005-05-02 04:09:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-05 07:31:31 +00:00
|
|
|
static void
|
|
|
|
qtv_reliable_send (sv_qtv_t *proxy)
|
|
|
|
{
|
2005-05-05 11:46:29 +00:00
|
|
|
int pos = 0, len = 0;
|
|
|
|
byte *buf = 0;
|
|
|
|
|
|
|
|
SV_Printf ("proxy->begun: %d\n", proxy->begun);
|
2021-12-27 13:55:29 +00:00
|
|
|
SZ_Clear (&proxy->netchan.message);
|
2005-05-05 11:46:29 +00:00
|
|
|
if (!proxy->begun) {
|
|
|
|
MSG_WriteByte (&proxy->netchan.message, qtv_packet);
|
|
|
|
pos = proxy->netchan.message.cursize;
|
|
|
|
MSG_WriteShort (&proxy->netchan.message, qtv_p_signon);
|
|
|
|
}
|
2005-05-05 07:31:31 +00:00
|
|
|
MSG_Reliable_Send (&proxy->backbuf);
|
2005-05-05 11:46:29 +00:00
|
|
|
if (!proxy->begun) {
|
|
|
|
len = proxy->netchan.message.cursize - pos - 2;
|
|
|
|
buf = proxy->netchan.message.data + pos;
|
|
|
|
buf[0] = len & 0xff;
|
|
|
|
buf[1] |= (len >> 8) & 0x0f;
|
|
|
|
}
|
2005-05-05 07:31:31 +00:00
|
|
|
}
|
|
|
|
|
2004-03-04 00:13:20 +00:00
|
|
|
void
|
2011-07-23 12:39:13 +00:00
|
|
|
SV_qtvConnect (int qport, info_t *info)
|
2004-03-04 00:13:20 +00:00
|
|
|
{
|
2004-03-05 23:42:15 +00:00
|
|
|
sv_qtv_t *proxy;
|
|
|
|
|
2005-05-05 11:46:29 +00:00
|
|
|
SV_Printf ("QTV proxy connection: %s\n", NET_AdrToString (net_from));
|
2004-03-05 23:42:15 +00:00
|
|
|
|
|
|
|
if (!(proxy = alloc_proxy ())) {
|
|
|
|
SV_Printf ("%s:full proxy connect\n", NET_AdrToString (net_from));
|
2021-12-27 08:54:58 +00:00
|
|
|
SV_OutOfBandPrint (net_from, "%c\nserver is full\n\n", A2C_PRINT);
|
2004-03-05 23:42:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
proxy->info = info;
|
2012-05-21 13:50:59 +00:00
|
|
|
while (!(proxy->name_key = Info_Key (proxy->info, "name")))
|
2004-03-05 23:42:15 +00:00
|
|
|
Info_SetValueForKey (proxy->info, "name", "\"unnamed proxy\"", 1);
|
|
|
|
|
2011-07-23 08:51:07 +00:00
|
|
|
Netchan_Setup (&proxy->netchan, net_from, qport, NC_QPORT_READ);
|
2004-03-05 23:42:15 +00:00
|
|
|
proxy->backbuf.netchan = &proxy->netchan;
|
|
|
|
proxy->backbuf.name = proxy->name_key->value;
|
2005-05-05 07:31:31 +00:00
|
|
|
proxy->datagram.data = proxy->datagram_buf;
|
|
|
|
proxy->datagram.maxsize = sizeof (proxy->datagram_buf);
|
2005-05-05 11:46:29 +00:00
|
|
|
proxy->begun = 0;
|
2004-03-05 23:42:15 +00:00
|
|
|
|
2021-12-27 08:54:58 +00:00
|
|
|
SV_OutOfBandPrint (net_from, "%c", S2C_CONNECTION);
|
2004-03-05 23:42:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-07-23 12:39:13 +00:00
|
|
|
SV_qtvPacket (int qport)
|
2004-03-05 23:42:15 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_PROXIES; i++) {
|
|
|
|
if (!proxies[i].info)
|
|
|
|
continue;
|
|
|
|
if (!NET_CompareBaseAdr (net_from, proxies[i].netchan.remote_address))
|
|
|
|
continue;
|
|
|
|
if (proxies[i].netchan.qport != qport)
|
|
|
|
continue;
|
|
|
|
if (proxies[i].netchan.remote_address.port != net_from.port) {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_dev,
|
2010-11-23 05:09:30 +00:00
|
|
|
"SV_ReadPackets: fixing up a translated port\n");
|
2004-03-05 23:42:15 +00:00
|
|
|
proxies[i].netchan.remote_address.port = net_from.port;
|
|
|
|
}
|
|
|
|
if (Netchan_Process (&proxies[i].netchan)) {
|
|
|
|
// this is a valid, sequenced packet, so process it
|
|
|
|
svs.stats.packets++;
|
2005-05-05 11:46:29 +00:00
|
|
|
qtv_parse (&proxies[i]);
|
2004-03-05 23:42:15 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SV_qtvCheckTimeouts (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
float droptime;
|
|
|
|
sv_qtv_t *proxy;
|
|
|
|
|
[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
|
|
|
droptime = realtime - sv_timeout;
|
2004-03-05 23:42:15 +00:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_PROXIES; i++) {
|
|
|
|
proxy = proxies + i;
|
|
|
|
if (proxy->info) {
|
|
|
|
if (proxy->netchan.last_received < droptime) {
|
|
|
|
SV_Printf ("%s timed out\n", proxy->name_key->value);
|
2005-05-02 04:09:15 +00:00
|
|
|
drop_proxy (proxy);
|
2004-03-05 23:42:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-03-04 00:13:20 +00:00
|
|
|
}
|
2005-05-02 04:09:15 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
SV_qtvSendMessages (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
sv_qtv_t *proxy;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_PROXIES; i++) {
|
|
|
|
proxy = proxies + i;
|
|
|
|
if (!proxy->info)
|
|
|
|
continue;
|
|
|
|
if (!proxy->packet)
|
|
|
|
continue;
|
2005-05-05 07:31:31 +00:00
|
|
|
if (proxy->backbuf.num_backbuf)
|
|
|
|
qtv_reliable_send (proxy);
|
|
|
|
if (proxy->netchan.message.overflowed) {
|
|
|
|
SZ_Clear (&proxy->netchan.message);
|
|
|
|
drop_proxy (proxy);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (proxy->datagram.cursize) {
|
|
|
|
Netchan_Transmit (&proxy->netchan, proxy->datagram.cursize,
|
|
|
|
proxy->datagram.data);
|
|
|
|
SZ_Clear (&proxy->datagram);
|
|
|
|
} else {
|
|
|
|
Netchan_Transmit (&proxy->netchan, 0, 0);
|
|
|
|
}
|
2005-05-02 04:09:15 +00:00
|
|
|
proxy->packet = 0;
|
2005-05-05 07:31:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SV_qtvFinalMessage (const char *message)
|
|
|
|
{
|
|
|
|
sv_qtv_t *proxy;
|
|
|
|
int i;
|
|
|
|
int pos, len;
|
|
|
|
byte *buf;
|
|
|
|
|
|
|
|
SZ_Clear (net_message->message);
|
|
|
|
MSG_WriteByte (net_message->message, qtv_packet);
|
|
|
|
pos = net_message->message->cursize;
|
|
|
|
MSG_WriteShort (net_message->message, qtv_p_print);
|
|
|
|
MSG_WriteByte (net_message->message, PRINT_HIGH);
|
|
|
|
MSG_WriteString (net_message->message, message);
|
|
|
|
len = net_message->message->cursize - pos - 2;
|
|
|
|
buf = net_message->message->data + pos;
|
|
|
|
buf[0] = len & 0xff;
|
|
|
|
buf[1] |= (len >> 8) & 0x0f;
|
|
|
|
MSG_WriteByte (net_message->message, qtv_disconnect);
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_PROXIES; i++) {
|
|
|
|
proxy = proxies + i;
|
|
|
|
if (!proxy->info)
|
|
|
|
continue;
|
|
|
|
Netchan_Transmit (&proxy->netchan, net_message->message->cursize,
|
|
|
|
net_message->message->data);
|
2005-05-02 04:09:15 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-13 06:50:44 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
SV_qtvChanging (void)
|
|
|
|
{
|
|
|
|
sv_qtv_t *proxy;
|
|
|
|
int i, len;
|
|
|
|
const char *msg;
|
|
|
|
|
2021-01-31 07:01:20 +00:00
|
|
|
msg = va (0, "%cchanging", qtv_stringcmd);
|
2010-01-13 06:50:44 +00:00
|
|
|
len = strlen (msg) + 1;
|
|
|
|
for (i = 0; i < MAX_PROXIES; i++) {
|
|
|
|
proxy = proxies + i;
|
|
|
|
if (!proxy->info)
|
|
|
|
continue;
|
|
|
|
SVR_Pause (proxy->recorder);
|
|
|
|
|
2011-06-19 01:48:02 +00:00
|
|
|
MSG_ReliableCheckBlock (&proxy->backbuf, len);
|
2010-01-13 06:50:44 +00:00
|
|
|
MSG_ReliableWrite_SZ (&proxy->backbuf, msg, len);
|
|
|
|
}
|
|
|
|
SV_qtvSendMessages ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SV_qtvReconnect (void)
|
|
|
|
{
|
|
|
|
sv_qtv_t *proxy;
|
|
|
|
int i, len;
|
|
|
|
const char *msg;
|
|
|
|
|
2021-01-31 07:01:20 +00:00
|
|
|
msg = va (0, "%creconnect", qtv_stringcmd);
|
2010-01-13 06:50:44 +00:00
|
|
|
len = strlen (msg) + 1;
|
|
|
|
for (i = 0; i < MAX_PROXIES; i++) {
|
|
|
|
proxy = proxies + i;
|
|
|
|
if (!proxy->info)
|
|
|
|
continue;
|
|
|
|
|
2011-06-19 01:48:02 +00:00
|
|
|
MSG_ReliableCheckBlock (&proxy->backbuf, len);
|
2010-01-13 06:50:44 +00:00
|
|
|
MSG_ReliableWrite_SZ (&proxy->backbuf, msg, len);
|
|
|
|
}
|
|
|
|
}
|