mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-17 22:50:51 +00:00
move the ucmd message code into a common qw lib (more will likely follow)
This commit is contained in:
parent
551c7ee89a
commit
6e6df349e4
19 changed files with 643 additions and 115 deletions
|
@ -2183,6 +2183,7 @@ AC_OUTPUT(
|
|||
libs/net/nc/Makefile
|
||||
libs/net/nm/Makefile
|
||||
libs/object/Makefile
|
||||
libs/qw/Makefile
|
||||
libs/ruamoko/Makefile
|
||||
libs/util/Makefile
|
||||
libs/video/Makefile
|
||||
|
|
|
@ -3,4 +3,5 @@ AUTOMAKE_OPTIONS= foreign
|
|||
# everything depends on util
|
||||
# gamecode depends on gib (only for builtins, not the engine)
|
||||
# ruamoko depends on gamecode (engine only, not builtins)
|
||||
SUBDIRS=util audio console gib gamecode image models net object ruamoko video
|
||||
SUBDIRS=util audio console gib gamecode image models net object qw ruamoko \
|
||||
video
|
||||
|
|
9
libs/qw/.gitignore
vendored
Normal file
9
libs/qw/.gitignore
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
*.a
|
||||
*.la
|
||||
*.lo
|
||||
.deps
|
||||
.libs
|
||||
.vimrc
|
||||
Makefile
|
||||
Makefile.in
|
||||
|
8
libs/qw/Makefile.am
Normal file
8
libs/qw/Makefile.am
Normal file
|
@ -0,0 +1,8 @@
|
|||
AUTOMAKE_OPTIONS= foreign
|
||||
|
||||
INCLUDES= -I$(top_srcdir)/include
|
||||
|
||||
noinst_LIBRARIES= libqw.a
|
||||
|
||||
libqw_a_SOURCES= \
|
||||
msg_ucmd.c
|
133
libs/qw/msg_ucmd.c
Normal file
133
libs/qw/msg_ucmd.c
Normal file
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
msg.c
|
||||
|
||||
(description)
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
static __attribute__ ((unused)) const char rcsid[] =
|
||||
"$Id$";
|
||||
|
||||
#ifdef HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
#endif
|
||||
|
||||
#include "QF/msg.h"
|
||||
#include "QF/qendian.h"
|
||||
#include "QF/sys.h"
|
||||
|
||||
#include "qw/msg_ucmd.h"
|
||||
#include "qw/protocol.h"
|
||||
|
||||
#include "netchan.h"
|
||||
|
||||
struct usercmd_s nullcmd;
|
||||
|
||||
|
||||
void
|
||||
MSG_WriteDeltaUsercmd (sizebuf_t *buf, usercmd_t *from, usercmd_t *cmd)
|
||||
{
|
||||
int bits;
|
||||
|
||||
// send the movement message
|
||||
bits = 0;
|
||||
if (cmd->angles[0] != from->angles[0])
|
||||
bits |= CM_ANGLE1;
|
||||
if (cmd->angles[1] != from->angles[1])
|
||||
bits |= CM_ANGLE2;
|
||||
if (cmd->angles[2] != from->angles[2])
|
||||
bits |= CM_ANGLE3;
|
||||
if (cmd->forwardmove != from->forwardmove)
|
||||
bits |= CM_FORWARD;
|
||||
if (cmd->sidemove != from->sidemove)
|
||||
bits |= CM_SIDE;
|
||||
if (cmd->upmove != from->upmove)
|
||||
bits |= CM_UP;
|
||||
if (cmd->buttons != from->buttons)
|
||||
bits |= CM_BUTTONS;
|
||||
if (cmd->impulse != from->impulse)
|
||||
bits |= CM_IMPULSE;
|
||||
MSG_WriteByte (buf, bits);
|
||||
|
||||
if (bits & CM_ANGLE1)
|
||||
MSG_WriteAngle16 (buf, cmd->angles[0]);
|
||||
if (bits & CM_ANGLE2)
|
||||
MSG_WriteAngle16 (buf, cmd->angles[1]);
|
||||
if (bits & CM_ANGLE3)
|
||||
MSG_WriteAngle16 (buf, cmd->angles[2]);
|
||||
|
||||
if (bits & CM_FORWARD)
|
||||
MSG_WriteShort (buf, cmd->forwardmove);
|
||||
if (bits & CM_SIDE)
|
||||
MSG_WriteShort (buf, cmd->sidemove);
|
||||
if (bits & CM_UP)
|
||||
MSG_WriteShort (buf, cmd->upmove);
|
||||
|
||||
if (bits & CM_BUTTONS)
|
||||
MSG_WriteByte (buf, cmd->buttons);
|
||||
if (bits & CM_IMPULSE)
|
||||
MSG_WriteByte (buf, cmd->impulse);
|
||||
MSG_WriteByte (buf, cmd->msec);
|
||||
}
|
||||
|
||||
void
|
||||
MSG_ReadDeltaUsercmd (usercmd_t *from, usercmd_t *move)
|
||||
{
|
||||
int bits;
|
||||
|
||||
memcpy (move, from, sizeof (*move));
|
||||
|
||||
bits = MSG_ReadByte (net_message);
|
||||
|
||||
// read current angles
|
||||
if (bits & CM_ANGLE1)
|
||||
move->angles[0] = MSG_ReadAngle16 (net_message);
|
||||
if (bits & CM_ANGLE2)
|
||||
move->angles[1] = MSG_ReadAngle16 (net_message);
|
||||
if (bits & CM_ANGLE3)
|
||||
move->angles[2] = MSG_ReadAngle16 (net_message);
|
||||
|
||||
// read movement
|
||||
if (bits & CM_FORWARD)
|
||||
move->forwardmove = MSG_ReadShort (net_message);
|
||||
if (bits & CM_SIDE)
|
||||
move->sidemove = MSG_ReadShort (net_message);
|
||||
if (bits & CM_UP)
|
||||
move->upmove = MSG_ReadShort (net_message);
|
||||
|
||||
// read buttons
|
||||
if (bits & CM_BUTTONS)
|
||||
move->buttons = MSG_ReadByte (net_message);
|
||||
|
||||
if (bits & CM_IMPULSE)
|
||||
move->impulse = MSG_ReadByte (net_message);
|
||||
|
||||
// read time to run command
|
||||
move->msec = MSG_ReadByte (net_message);
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
## Process this file with automake to produce Makefile.in
|
||||
AUTOMAKE_OPTIONS= foreign
|
||||
|
||||
EXTRA_DIST = client.h connection.h server.h
|
||||
EXTRA_DIST = client.h connection.h qtv.h server.h
|
||||
|
|
|
@ -36,12 +36,17 @@
|
|||
|
||||
typedef struct client_s {
|
||||
struct info_s *userinfo;
|
||||
struct connection_s *con;
|
||||
int drop;
|
||||
netchan_t netchan;
|
||||
} client_t;
|
||||
|
||||
struct connection_s;
|
||||
typedef struct challenge_s {
|
||||
int challenge;
|
||||
double time;
|
||||
} challenge_t;
|
||||
|
||||
void Client_Init (void);
|
||||
void Client_Connect (struct connection_s *con, int qport, struct info_s *info);
|
||||
void Client_NewConnection (void);
|
||||
|
||||
#endif//__client_h
|
||||
|
|
53
qtv/include/qtv.h
Normal file
53
qtv/include/qtv.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
#FILENAME#
|
||||
|
||||
#DESCRIPTION#
|
||||
|
||||
Copyright (C) 2004 #AUTHOR#
|
||||
|
||||
Author: #AUTHOR#
|
||||
Date: #DATE#
|
||||
|
||||
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
|
||||
|
||||
$Id$
|
||||
*/
|
||||
|
||||
#ifndef __qtv_h
|
||||
#define __qtv_h
|
||||
|
||||
#define PORT_QTV 27501
|
||||
|
||||
typedef enum {
|
||||
RD_NONE,
|
||||
RD_CLIENT,
|
||||
RD_PACKET,
|
||||
} redirect_t;
|
||||
|
||||
extern double realtime;
|
||||
|
||||
extern cbuf_t *qtv_cbuf;
|
||||
extern cbuf_args_t *qtv_args;
|
||||
|
||||
void qtv_printf (const char *fmt, ...) __attribute__((format(printf,1,2)));
|
||||
void qtv_begin_redirect (redirect_t rd);
|
||||
void qtv_end_redirect (void);
|
||||
void qtv_flush_redirect (void);
|
||||
|
||||
#endif//__qtv_h
|
|
@ -39,6 +39,7 @@ common_ldflags= -export-dynamic
|
|||
|
||||
qtv_LIBS= \
|
||||
$(SERVER_PLUGIN_STATIC_LIBS) \
|
||||
$(top_builddir)/libs/qw/libqw.a \
|
||||
$(top_builddir)/libs/net/libnet_chan.la \
|
||||
$(top_builddir)/libs/console/libQFconsole.la \
|
||||
$(top_builddir)/libs/util/libQFutil.la
|
||||
|
|
|
@ -44,39 +44,401 @@ static __attribute__ ((unused)) const char rcsid[] =
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "QF/cbuf.h"
|
||||
#include "QF/cmd.h"
|
||||
#include "QF/console.h"
|
||||
#include "QF/dstring.h"
|
||||
#include "QF/hash.h"
|
||||
#include "QF/idparse.h"
|
||||
#include "QF/info.h"
|
||||
|
||||
#include "qw/msg_ucmd.h"
|
||||
#include "qw/protocol.h"
|
||||
|
||||
#include "client.h"
|
||||
#include "connection.h"
|
||||
#include "qtv.h"
|
||||
|
||||
void
|
||||
Client_Init (void)
|
||||
typedef struct ucmd_s {
|
||||
const char *name;
|
||||
void (*func) (client_t *cl, void *userdata);
|
||||
unsigned no_redirect:1;
|
||||
unsigned overridable:1;
|
||||
unsigned freeable:1;
|
||||
void *userdata;
|
||||
void (*on_free) (void *userdata);
|
||||
} ucmd_t;
|
||||
|
||||
static void
|
||||
client_drop (client_t *cl)
|
||||
{
|
||||
MSG_WriteByte (&cl->netchan.message, svc_disconnect);
|
||||
Con_Printf ("Client %s removed\n", Info_ValueForKey (cl->userinfo, "name"));
|
||||
cl->drop = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
cl_new_f (client_t *cl, void *unused)
|
||||
{
|
||||
qtv_printf ("\"qtv list\" for a list of servers\n");
|
||||
qtv_printf ("\"qtv connect <servername>\" to connect to a server\n");
|
||||
}
|
||||
|
||||
static void
|
||||
cl_modellist_f (client_t *cl, void *unused)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
cl_soundlist_f (client_t *cl, void *unused)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
cl_prespawn_f (client_t *cl, void *unused)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
cl_spawn_f (client_t *cl, void *unused)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
cl_begin_f (client_t *cl, void *unused)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
cl_drop_f (client_t *cl, void *unused)
|
||||
{
|
||||
client_drop (cl);
|
||||
}
|
||||
|
||||
static void
|
||||
cl_pings_f (client_t *cl, void *unused)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
cl_rate_f (client_t *cl, void *unused)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
cl_say_f (client_t *cl, void *unused)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
cl_setinfo_f (client_t *cl, void *unused)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
cl_serverinfo_f (client_t *cl, void *unused)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
cl_download_f (client_t *cl, void *unused)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
cl_nextdl_f (client_t *cl, void *unused)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
cl_ptrack_f (client_t *cl, void *unused)
|
||||
{
|
||||
}
|
||||
|
||||
static ucmd_t ucmds[] = {
|
||||
{"new", cl_new_f, 0, 0},
|
||||
{"modellist", cl_modellist_f, 0, 0},
|
||||
{"soundlist", cl_soundlist_f, 0, 0},
|
||||
{"prespawn", cl_prespawn_f, 0, 0},
|
||||
{"spawn", cl_spawn_f, 0, 0},
|
||||
{"begin", cl_begin_f, 1, 0},
|
||||
|
||||
{"drop", cl_drop_f, 0, 0},
|
||||
{"pings", cl_pings_f, 0, 0},
|
||||
|
||||
// issued by hand at client consoles
|
||||
{"rate", cl_rate_f, 0, 0},
|
||||
{"kill", 0, 1, 1},
|
||||
{"pause", 0, 1, 0},
|
||||
{"msg", 0, 0, 0},
|
||||
|
||||
{"say", cl_say_f, 1, 1},
|
||||
{"say_team", cl_say_f, 1, 1},
|
||||
|
||||
{"setinfo", cl_setinfo_f, 1, 0},
|
||||
|
||||
{"serverinfo", cl_serverinfo_f, 0, 0},
|
||||
|
||||
{"download", cl_download_f, 1, 0},
|
||||
{"nextdl", cl_nextdl_f, 0, 0},
|
||||
|
||||
{"ptrack", cl_ptrack_f, 0, 1}, // ZOID - used with autocam
|
||||
|
||||
{"snap", 0, 0, 0},
|
||||
};
|
||||
|
||||
static hashtab_t *ucmd_table;
|
||||
int (*ucmd_unknown)(void);
|
||||
|
||||
static void
|
||||
client_exec_command (client_t *cl, const char *s)
|
||||
{
|
||||
ucmd_t *u;
|
||||
|
||||
COM_TokenizeString (s, qtv_args);
|
||||
cmd_args = qtv_args;
|
||||
|
||||
u = (ucmd_t*) Hash_Find (ucmd_table, qtv_args->argv[0]->str);
|
||||
|
||||
if (!u) {
|
||||
if (ucmd_unknown && !ucmd_unknown ()) {
|
||||
qtv_begin_redirect (RD_CLIENT);
|
||||
qtv_printf ("Bad user command: %s\n", qtv_args->argv[0]->str);
|
||||
qtv_end_redirect ();
|
||||
}
|
||||
} else {
|
||||
if (!u->no_redirect)
|
||||
qtv_begin_redirect (RD_CLIENT);
|
||||
u->func (cl, u->userdata);
|
||||
if (!u->no_redirect)
|
||||
qtv_end_redirect ();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
client_parse_message (client_t *cl)
|
||||
{
|
||||
int c, size;
|
||||
vec3_t o;
|
||||
const char *s;
|
||||
usercmd_t oldest, oldcmd, newcmd;
|
||||
|
||||
while (1) {
|
||||
if (net_message->badread) {
|
||||
Con_Printf ("SV_ReadClientMessage: badread\n");
|
||||
client_drop (cl);
|
||||
return;
|
||||
}
|
||||
|
||||
c = MSG_ReadByte (net_message);
|
||||
if (c == -1)
|
||||
return;
|
||||
|
||||
switch (c) {
|
||||
default:
|
||||
Con_Printf ("SV_ReadClientMessage: unknown command char\n");
|
||||
client_drop (cl);
|
||||
return;
|
||||
case clc_nop:
|
||||
break;
|
||||
case clc_delta:
|
||||
/*cl->delta_sequence = */MSG_ReadByte (net_message);
|
||||
break;
|
||||
case clc_move:
|
||||
/*if (move_issued)
|
||||
return; // someone is trying to cheat...
|
||||
move_issued = true;*/
|
||||
/*checksumIndex = */MSG_GetReadCount (net_message);
|
||||
/*checksum = (byte) */MSG_ReadByte (net_message);
|
||||
// read loss percentage
|
||||
/*cl->lossage = */MSG_ReadByte (net_message);
|
||||
MSG_ReadDeltaUsercmd (&nullcmd, &oldest);
|
||||
MSG_ReadDeltaUsercmd (&oldest, &oldcmd);
|
||||
MSG_ReadDeltaUsercmd (&oldcmd, &newcmd);
|
||||
#if 0
|
||||
if (cl->state != cs_spawned)
|
||||
break;
|
||||
// if the checksum fails, ignore the rest of the packet
|
||||
calculatedChecksum =
|
||||
COM_BlockSequenceCRCByte (net_message->message->data +
|
||||
checksumIndex + 1,
|
||||
MSG_GetReadCount (net_message) -
|
||||
checksumIndex - 1, seq_hash);
|
||||
if (calculatedChecksum != checksum) {
|
||||
Con_DPrintf
|
||||
("Failed command checksum for %s(%d) (%d != %d)\n",
|
||||
cl->name, cl->netchan.incoming_sequence, checksum,
|
||||
calculatedChecksum);
|
||||
return;
|
||||
}
|
||||
if (!sv.paused) {
|
||||
SV_PreRunCmd ();
|
||||
if (net_drop < 20) {
|
||||
while (net_drop > 2) {
|
||||
SV_RunCmd (&cl->lastcmd, 0);
|
||||
net_drop--;
|
||||
}
|
||||
if (net_drop > 1)
|
||||
SV_RunCmd (&oldest, 0);
|
||||
if (net_drop > 0)
|
||||
SV_RunCmd (&oldcmd, 0);
|
||||
}
|
||||
SV_RunCmd (&newcmd, 0);
|
||||
SV_PostRunCmd ();
|
||||
}
|
||||
cl->lastcmd = newcmd;
|
||||
cl->lastcmd.buttons = 0; // avoid multiple fires on lag
|
||||
#endif
|
||||
break;
|
||||
case clc_stringcmd:
|
||||
s = MSG_ReadString (net_message);
|
||||
client_exec_command (cl, s);
|
||||
break;
|
||||
case clc_tmove:
|
||||
MSG_ReadCoordV (net_message, o);
|
||||
#if 0
|
||||
// only allowed by spectators
|
||||
if (host_client->spectator) {
|
||||
VectorCopy (o, SVvector (sv_player, origin));
|
||||
SV_LinkEdict (sv_player, false);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case clc_upload:
|
||||
size = MSG_ReadShort (net_message);
|
||||
MSG_ReadByte (net_message);
|
||||
net_message->readcount += size;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
client_handler (connection_t *con, void *object)
|
||||
{
|
||||
client_t *cl = (client_t *) object;
|
||||
byte d[1];
|
||||
|
||||
Con_Printf ("hi\n");
|
||||
Netchan_Transmit (&cl->netchan, 0, d);
|
||||
if (net_message->message->cursize < 11) {
|
||||
Con_Printf ("%s: Runt packet\n", NET_AdrToString (net_from));
|
||||
return;
|
||||
}
|
||||
#if 0
|
||||
// read the qport out of the message so we can fix up
|
||||
// stupid address translating routers
|
||||
MSG_ReadLong (net_message); // sequence number
|
||||
MSG_ReadLong (net_message); // sequence number
|
||||
qport = MSG_ReadShort (net_message) & 0xffff;
|
||||
if (cl->netchan.qport != qport)
|
||||
return;
|
||||
#endif
|
||||
if (Netchan_Process (&cl->netchan)) {
|
||||
// this is a valid, sequenced packet, so process it
|
||||
//svs.stats.packets++;
|
||||
//cl->send_message = true;
|
||||
//if (cl->state != cs_zombie)
|
||||
client_parse_message (cl);
|
||||
Netchan_Transmit (&cl->netchan, 0, NULL);
|
||||
if (cl->drop) {
|
||||
Connection_Del (cl->con);
|
||||
Info_Destroy (cl->userinfo);
|
||||
free (cl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Client_Connect (connection_t *con, int qport, info_t *info)
|
||||
static void
|
||||
client_connect (connection_t *con, void *object)
|
||||
{
|
||||
challenge_t *ch = (challenge_t *) object;
|
||||
client_t *cl;
|
||||
const char *str;
|
||||
info_t *userinfo;
|
||||
int version, qport, challenge, seq;
|
||||
|
||||
MSG_BeginReading (net_message);
|
||||
seq = MSG_ReadLong (net_message);
|
||||
if (seq != -1) {
|
||||
Con_Printf ("unexpected connected packet\n");
|
||||
return;
|
||||
}
|
||||
str = MSG_ReadString (net_message);
|
||||
COM_TokenizeString (str, qtv_args);
|
||||
cmd_args = qtv_args;
|
||||
if (strcmp (Cmd_Argv (0), "connect")) {
|
||||
Con_Printf ("unexpected connected packet\n");
|
||||
return;
|
||||
}
|
||||
version = atoi (Cmd_Argv (1));
|
||||
if (version != PROTOCOL_VERSION) {
|
||||
Netchan_OutOfBandPrint (net_from, "%c\nServer is version %s.\n",
|
||||
A2C_PRINT, QW_VERSION);
|
||||
Con_Printf ("* rejected connect from version %i\n", version);
|
||||
return;
|
||||
}
|
||||
qport = atoi (Cmd_Argv (2));
|
||||
challenge = atoi (Cmd_Argv (3));
|
||||
if (!(con = Connection_Find (&net_from))
|
||||
|| (ch = con->object)->challenge != challenge) {
|
||||
Netchan_OutOfBandPrint (net_from, "%c\nBad challenge.\n",
|
||||
A2C_PRINT);
|
||||
return;
|
||||
}
|
||||
free (con->object);
|
||||
userinfo = Info_ParseString (Cmd_Argv (4), 0, 0);
|
||||
if (!userinfo) {
|
||||
Netchan_OutOfBandPrint (net_from, "%c\nInvalid userinfo string.\n",
|
||||
A2C_PRINT);
|
||||
return;
|
||||
}
|
||||
|
||||
cl = calloc (1, sizeof (client_t));
|
||||
Netchan_Setup (&cl->netchan, con->address, qport, NC_READ_QPORT);
|
||||
cl->userinfo = info;
|
||||
cl->userinfo = userinfo;
|
||||
cl->con = con;
|
||||
con->object = cl;
|
||||
con->handler = client_handler;
|
||||
Con_Printf ("client %s (%s) connected\n", Info_ValueForKey (info, "name"),
|
||||
|
||||
Con_Printf ("client %s (%s) connected\n",
|
||||
Info_ValueForKey (userinfo, "name"),
|
||||
NET_AdrToString (con->address));
|
||||
|
||||
Netchan_OutOfBandPrint (net_from, "%c", S2C_CONNECTION);
|
||||
}
|
||||
|
||||
void
|
||||
Client_NewConnection (void)
|
||||
{
|
||||
challenge_t *ch;
|
||||
connection_t *con;
|
||||
|
||||
if ((con = Connection_Find (&net_from))) {
|
||||
if (con->handler == client_handler)
|
||||
return;
|
||||
ch = con->object;
|
||||
} else {
|
||||
ch = malloc (sizeof (challenge_t));
|
||||
}
|
||||
ch->challenge = (rand () << 16) ^ rand ();
|
||||
ch->time = realtime;
|
||||
if (!con)
|
||||
con = Connection_Add (&net_from, ch, 0);
|
||||
Netchan_OutOfBandPrint (net_from, "%c%i QF", S2C_CHALLENGE, ch->challenge);
|
||||
con->handler = client_connect;
|
||||
}
|
||||
|
||||
static const char *
|
||||
ucmds_getkey (void *_a, void *unused)
|
||||
{
|
||||
ucmd_t *a = (ucmd_t*)_a;
|
||||
return a->name;
|
||||
}
|
||||
|
||||
void
|
||||
Client_Init (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
ucmd_table = Hash_NewTable (251, ucmds_getkey, 0, 0);
|
||||
for (i = 0; i < sizeof (ucmds) / sizeof (ucmds[0]); i++)
|
||||
Hash_Add (ucmd_table, &ucmds[i]);
|
||||
}
|
||||
|
|
136
qtv/source/qtv.c
136
qtv/source/qtv.c
|
@ -64,16 +64,9 @@ static __attribute__ ((unused)) const char rcsid[] =
|
|||
#include "compat.h"
|
||||
#include "connection.h"
|
||||
#include "netchan.h"
|
||||
#include "qtv.h"
|
||||
#include "server.h"
|
||||
|
||||
#define PORT_QTV 27501
|
||||
|
||||
typedef enum {
|
||||
RD_NONE,
|
||||
RD_CLIENT,
|
||||
RD_PACKET,
|
||||
} redirect_t;
|
||||
|
||||
SERVER_PLUGIN_PROTOS
|
||||
static plugin_list_t server_plugin_list[] = {
|
||||
SERVER_PLUGIN_LIST
|
||||
|
@ -84,11 +77,11 @@ double realtime;
|
|||
cbuf_t *qtv_cbuf;
|
||||
cbuf_args_t *qtv_args;
|
||||
|
||||
cvar_t *qtv_console_plugin;
|
||||
cvar_t *qtv_port;
|
||||
cvar_t *qtv_mem_size;
|
||||
cvar_t *fs_globalcfg;
|
||||
cvar_t *fs_usercfg;
|
||||
static cvar_t *qtv_console_plugin;
|
||||
static cvar_t *qtv_port;
|
||||
static cvar_t *qtv_mem_size;
|
||||
static cvar_t *fs_globalcfg;
|
||||
static cvar_t *fs_usercfg;
|
||||
|
||||
redirect_t qtv_redirected;
|
||||
dstring_t outputbuf = {&dstring_default_mem};
|
||||
|
@ -126,7 +119,17 @@ qtv_print (const char *fmt, va_list args)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
qtv_printf (const char *fmt, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
|
||||
va_start (argptr, fmt);
|
||||
qtv_print (fmt, argptr);
|
||||
va_end (argptr);
|
||||
}
|
||||
|
||||
void
|
||||
qtv_flush_redirect (void)
|
||||
{
|
||||
char send[8000 + 6];
|
||||
|
@ -153,18 +156,39 @@ qtv_flush_redirect (void)
|
|||
p += bytes;
|
||||
count -= bytes;
|
||||
}
|
||||
} else if (qtv_redirected == RD_CLIENT) {
|
||||
#if 0
|
||||
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
|
||||
bytes = ClientReliableCheckSize (cl, count + 3, 4) - 3;
|
||||
// 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;
|
||||
ClientReliableWrite_Begin (cl, svc_print, bytes + 3);
|
||||
ClientReliableWrite_Byte (cl, PRINT_HIGH);
|
||||
ClientReliableWrite_SZ (cl, p, bytes);
|
||||
ClientReliableWrite_Byte (cl, 0);
|
||||
p += bytes;
|
||||
count -= bytes;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
dstring_clear (&outputbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
qtv_begin_redirect (redirect_t rd)
|
||||
{
|
||||
qtv_redirected = rd;
|
||||
dstring_clear (&outputbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
qtv_end_redirect (void)
|
||||
{
|
||||
qtv_flush_redirect ();
|
||||
|
@ -270,6 +294,7 @@ qtv_init (void)
|
|||
|
||||
qtv_net_init ();
|
||||
Server_Init ();
|
||||
Client_Init ();
|
||||
|
||||
Cmd_AddCommand ("quit", qtv_quit_f, "Shut down qtv");
|
||||
|
||||
|
@ -292,77 +317,6 @@ qtv_status (void)
|
|||
qtv_end_redirect ();
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
int challenge;
|
||||
double time;
|
||||
} challenge_t;
|
||||
|
||||
static void
|
||||
qtv_getchallenge (void)
|
||||
{
|
||||
challenge_t *ch;
|
||||
connection_t *con;
|
||||
|
||||
if ((con = Connection_Find (&net_from))) {
|
||||
if (con->handler)
|
||||
return;
|
||||
ch = con->object;
|
||||
} else {
|
||||
ch = malloc (sizeof (challenge_t));
|
||||
}
|
||||
ch->challenge = (rand () << 16) ^ rand ();
|
||||
ch->time = Sys_DoubleTime ();
|
||||
if (!con)
|
||||
Connection_Add (&net_from, ch, 0);
|
||||
Netchan_OutOfBandPrint (net_from, "%c%i QF", S2C_CHALLENGE, ch->challenge);
|
||||
}
|
||||
|
||||
static void
|
||||
qtv_client_connect (void)
|
||||
{
|
||||
info_t *userinfo;
|
||||
int version, qport, challenge;
|
||||
connection_t *con;
|
||||
challenge_t *ch;
|
||||
|
||||
version = atoi (Cmd_Argv (1));
|
||||
if (version != PROTOCOL_VERSION) {
|
||||
Netchan_OutOfBandPrint (net_from, "%c\nServer is version %s.\n",
|
||||
A2C_PRINT, QW_VERSION);
|
||||
Con_Printf ("* rejected connect from version %i\n", version);
|
||||
return;
|
||||
}
|
||||
qport = atoi (Cmd_Argv (2));
|
||||
challenge = atoi (Cmd_Argv (3));
|
||||
if (!(con = Connection_Find (&net_from)) || con->handler
|
||||
|| (ch = con->object)->challenge != challenge) {
|
||||
Netchan_OutOfBandPrint (net_from, "%c\nBad challenge.\n",
|
||||
A2C_PRINT);
|
||||
return;
|
||||
}
|
||||
free (con->object);
|
||||
userinfo = Info_ParseString (Cmd_Argv (4), 0, 0);
|
||||
if (!userinfo) {
|
||||
Netchan_OutOfBandPrint (net_from, "%c\nInvalid userinfo string.\n",
|
||||
A2C_PRINT);
|
||||
return;
|
||||
}
|
||||
|
||||
Client_Connect (con, qport, userinfo);
|
||||
Netchan_OutOfBandPrint (net_from, "%c", S2C_CONNECTION);
|
||||
}
|
||||
|
||||
static void
|
||||
qtv_server_packet (void)
|
||||
{
|
||||
connection_t *con;
|
||||
|
||||
if (!(con = Connection_Find (&net_from)))
|
||||
return;
|
||||
if (con->handler)
|
||||
con->handler (con, con->object);
|
||||
}
|
||||
|
||||
static void
|
||||
qtv_connectionless_packet (void)
|
||||
{
|
||||
|
@ -381,9 +335,7 @@ qtv_connectionless_packet (void)
|
|||
} else if (!strcmp (cmd, "status")) {
|
||||
qtv_status ();
|
||||
} else if (!strcmp (cmd, "getchallenge")) {
|
||||
qtv_getchallenge ();
|
||||
} else if (!strcmp (cmd, "connect")) {
|
||||
qtv_client_connect ();
|
||||
Client_NewConnection ();
|
||||
} else if (cmd[0]) {
|
||||
switch (cmd[0]) {
|
||||
default:
|
||||
|
@ -394,10 +346,6 @@ qtv_connectionless_packet (void)
|
|||
case A2A_PING:
|
||||
qtv_ping ();
|
||||
break;
|
||||
case S2C_CHALLENGE:
|
||||
case S2C_CONNECTION:
|
||||
qtv_server_packet ();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
bad_packet:
|
||||
|
|
|
@ -4,5 +4,5 @@ AUTOMAKE_OPTIONS= foreign
|
|||
EXTRA_DIST = \
|
||||
bothdefs.h cl_cam.h cl_chat.h cl_demo.h cl_ents.h cl_input.h \
|
||||
cl_main.h cl_parse.h cl_pred.h cl_skin.h cl_slist.h cl_tent.h \
|
||||
client.h crudefile.h game.h host.h msg_ucmd.h pmove.h \
|
||||
client.h crudefile.h game.h host.h pmove.h \
|
||||
server.h sv_gib.h sv_demo.h sv_pr_cmds.h sv_pr_qwe.h sv_progs.h
|
||||
|
|
|
@ -51,7 +51,7 @@ EXTRA_LIBRARIES=libasm.a libqw_client.a libqw_common.a libqw_sdl.a libqw_server.
|
|||
|
||||
libasm_a_SOURCES= worlda.S
|
||||
libasm_la_CCASFLAGS=@PREFER_NON_PIC@
|
||||
libqw_common_a_SOURCES= com.c game.c msg_ucmd.c pmove.c pmovetst.c net_packetlog.c
|
||||
libqw_common_a_SOURCES= com.c game.c pmove.c pmovetst.c net_packetlog.c
|
||||
libqw_sdl_a_SOURCES=cl_sys_sdl.c
|
||||
libqw_sdl_a_CFLAGS=$(SDL_CFLAGS)
|
||||
|
||||
|
@ -75,6 +75,7 @@ libqw_server_a_SOURCES= \
|
|||
|
||||
qw_server_LIBS= \
|
||||
$(SERVER_PLUGIN_STATIC_LIBS) \
|
||||
$(top_builddir)/libs/qw/libqw.a \
|
||||
$(top_builddir)/libs/net/libnet_chan.la \
|
||||
$(top_builddir)/libs/ruamoko/libQFruamoko.la \
|
||||
$(top_builddir)/libs/models/libQFmodels.la \
|
||||
|
@ -99,6 +100,7 @@ cl_plugin_LIBS= \
|
|||
$(top_builddir)/libs/ruamoko/libQFruamoko.la
|
||||
|
||||
qw_client_LIBS= \
|
||||
$(top_builddir)/libs/qw/libqw.a \
|
||||
$(top_builddir)/libs/net/libnet_chan.la \
|
||||
$(top_builddir)/libs/console/libQFconsole.la \
|
||||
$(top_builddir)/libs/video/targets/libQFjs.la \
|
||||
|
|
|
@ -44,6 +44,8 @@ static __attribute__ ((unused)) const char rcsid[] =
|
|||
#include "QF/render.h"
|
||||
#include "QF/skin.h"
|
||||
|
||||
#include "qw/msg_ucmd.h"
|
||||
|
||||
#include "cl_cam.h"
|
||||
#include "cl_ents.h"
|
||||
#include "cl_main.h"
|
||||
|
@ -53,7 +55,6 @@ static __attribute__ ((unused)) const char rcsid[] =
|
|||
#include "compat.h"
|
||||
#include "d_iface.h"
|
||||
#include "host.h"
|
||||
#include "msg_ucmd.h"
|
||||
#include "pmove.h"
|
||||
#include "r_cvar.h"
|
||||
#include "r_dynamic.h"
|
||||
|
|
|
@ -48,6 +48,8 @@ static __attribute__ ((unused)) const char rcsid[] =
|
|||
#include "QF/teamplay.h"
|
||||
#include "QF/va.h"
|
||||
|
||||
#include "qw/msg_ucmd.h"
|
||||
|
||||
#include "cl_cam.h"
|
||||
#include "cl_demo.h"
|
||||
#include "cl_input.h"
|
||||
|
@ -55,7 +57,6 @@ static __attribute__ ((unused)) const char rcsid[] =
|
|||
#include "client.h"
|
||||
#include "compat.h"
|
||||
#include "host.h"
|
||||
#include "msg_ucmd.h"
|
||||
#include "view.h"
|
||||
|
||||
cvar_t *cl_nodelta;
|
||||
|
|
|
@ -42,10 +42,11 @@ static __attribute__ ((unused)) const char rcsid[] =
|
|||
#include "QF/qendian.h"
|
||||
#include "QF/sys.h"
|
||||
|
||||
#include "msg_ucmd.h"
|
||||
#include "netchan.h"
|
||||
#include "qw/msg_ucmd.h"
|
||||
#include "qw/protocol.h"
|
||||
|
||||
#include "netchan.h"
|
||||
|
||||
struct usercmd_s nullcmd;
|
||||
|
||||
|
||||
|
|
|
@ -42,8 +42,9 @@ static __attribute__ ((unused)) const char rcsid[] =
|
|||
#include "QF/msg.h"
|
||||
#include "QF/sys.h"
|
||||
|
||||
#include "qw/msg_ucmd.h"
|
||||
|
||||
#include "compat.h"
|
||||
#include "msg_ucmd.h"
|
||||
#include "server.h"
|
||||
#include "sv_demo.h"
|
||||
#include "sv_progs.h"
|
||||
|
|
|
@ -56,9 +56,10 @@ static __attribute__ ((unused)) const char rcsid[] =
|
|||
#include "QF/sys.h"
|
||||
#include "QF/va.h"
|
||||
|
||||
#include "qw/msg_ucmd.h"
|
||||
|
||||
#include "bothdefs.h"
|
||||
#include "compat.h"
|
||||
#include "msg_ucmd.h"
|
||||
#include "pmove.h"
|
||||
#include "server.h"
|
||||
#include "sv_demo.h"
|
||||
|
|
Loading…
Reference in a new issue