mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-17 22:50:51 +00:00
move ClientReliable* from sv_nchan to MSG_Reliabe* in msg_backbuf so the
backbuffer code can be shared between qw-server and qtv
This commit is contained in:
parent
a520c715ef
commit
b502cfc3ce
16 changed files with 503 additions and 441 deletions
|
@ -12,7 +12,7 @@ EXTRA_DIST = asm_i386.h alsa_funcs_list.h adivtab.h anorm_dots.h anorms.h \
|
|||
r_local.h r_screen.h r_shared.h rua_internal.h sbar.h skin_stencil.h \
|
||||
snd_render.h varrays.h vgamodes.h view.h vregset.h winquake.h world.h \
|
||||
\
|
||||
qw/protocol.h \
|
||||
qw/msg_backbuf.h msg_ucmd.h qw/protocol.h \
|
||||
\
|
||||
win32/fnmatch.h \
|
||||
\
|
||||
|
|
|
@ -34,7 +34,8 @@
|
|||
#include "QF/qdefs.h"
|
||||
#include "QF/sizebuf.h"
|
||||
|
||||
#include "../qw/include/bothdefs.h"
|
||||
#define MAX_MSGLEN 1450 // max length of a reliable message
|
||||
#define MAX_DATAGRAM 1450 // max length of unreliable message
|
||||
|
||||
#define PORT_ANY -1
|
||||
|
||||
|
@ -90,8 +91,7 @@ qboolean ServerPaused (void);
|
|||
|
||||
#define MAX_LATENT 32
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct netchan_s {
|
||||
qboolean fatal_error;
|
||||
|
||||
float last_received; // for timeouts
|
||||
|
|
65
include/qw/msg_backbuf.h
Normal file
65
include/qw/msg_backbuf.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
#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 __qw_msg_backbuf_h
|
||||
#define __qw_msg_backbuf_h
|
||||
|
||||
#define MAX_BACK_BUFFERS 8
|
||||
|
||||
typedef struct backbuf_s {
|
||||
sizebuf_t backbuf;
|
||||
int num_backbuf;
|
||||
int head_backbuf;
|
||||
int backbuf_size[MAX_BACK_BUFFERS];
|
||||
byte backbuf_data[MAX_BACK_BUFFERS][MAX_MSGLEN];
|
||||
struct netchan_s *netchan;
|
||||
const char *name;
|
||||
} backbuf_t;
|
||||
|
||||
int MSG_ReliableCheckSize (backbuf_t *rel, int maxsize, int minsize);
|
||||
void MSG_ReliableCheckBlock(backbuf_t *rel, int maxsize);
|
||||
void MSG_Reliable_FinishWrite(backbuf_t *rel);
|
||||
void MSG_ReliableWrite_Begin(backbuf_t *rel, int c, int maxsize);
|
||||
void MSG_ReliableWrite_Angle(backbuf_t *rel, float f);
|
||||
void MSG_ReliableWrite_Angle16(backbuf_t *rel, float f);
|
||||
void MSG_ReliableWrite_Byte(backbuf_t *rel, int c);
|
||||
void MSG_ReliableWrite_Char(backbuf_t *rel, int c);
|
||||
void MSG_ReliableWrite_Float(backbuf_t *rel, float f);
|
||||
void MSG_ReliableWrite_Coord(backbuf_t *rel, float f);
|
||||
void MSG_ReliableWrite_Long(backbuf_t *rel, int c);
|
||||
void MSG_ReliableWrite_Short(backbuf_t *rel, int c);
|
||||
void MSG_ReliableWrite_String(backbuf_t *rel, const char *s);
|
||||
void MSG_ReliableWrite_SZ(backbuf_t *rel, const void *data, int len);
|
||||
void MSG_ReliableWrite_AngleV(backbuf_t *rel, const vec3_t v);
|
||||
void MSG_ReliableWrite_CoordV(backbuf_t *rel, const vec3_t v);
|
||||
void MSG_Reliable_Send (backbuf_t *rel);
|
||||
|
||||
#endif//__qw_msg_backbuf_h
|
|
@ -27,8 +27,8 @@
|
|||
*/
|
||||
// protocol.h -- communications protocols
|
||||
|
||||
#ifndef _PROTOCOL_H
|
||||
#define _PROTOCOL_H
|
||||
#ifndef __qw_protocol_h
|
||||
#define __qw_protocol_h
|
||||
|
||||
#include "QF/mathlib.h"
|
||||
|
||||
|
@ -319,4 +319,4 @@ typedef struct usercmd_s
|
|||
byte impulse;
|
||||
} usercmd_t;
|
||||
|
||||
#endif // _PROTOCOL_H
|
||||
#endif//__qw_protocol_h
|
||||
|
|
|
@ -5,4 +5,4 @@ INCLUDES= -I$(top_srcdir)/include
|
|||
noinst_LIBRARIES= libqw.a
|
||||
|
||||
libqw_a_SOURCES= \
|
||||
msg_ucmd.c
|
||||
msg_backbuf.c msg_ucmd.c
|
||||
|
|
274
libs/qw/msg_backbuf.c
Normal file
274
libs/qw/msg_backbuf.c
Normal file
|
@ -0,0 +1,274 @@
|
|||
/*
|
||||
msg_backbuf.c
|
||||
|
||||
user reliable data stream writes
|
||||
|
||||
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/console.h"
|
||||
#include "QF/msg.h"
|
||||
|
||||
#include "netchan.h"
|
||||
#include "qw/msg_backbuf.h"
|
||||
|
||||
|
||||
static void
|
||||
PushBackbuf (backbuf_t *rel)
|
||||
{
|
||||
int tail_backbuf;
|
||||
|
||||
Con_DPrintf ("backbuffering %d %s\n", rel->num_backbuf, rel->name);
|
||||
tail_backbuf = (rel->head_backbuf + rel->num_backbuf) % MAX_BACK_BUFFERS;
|
||||
memset (&rel->backbuf, 0, sizeof (rel->backbuf));
|
||||
rel->backbuf.allowoverflow = true;
|
||||
rel->backbuf.data = rel->backbuf_data[tail_backbuf];
|
||||
rel->backbuf.maxsize = sizeof (rel->backbuf_data[tail_backbuf]);
|
||||
rel->backbuf_size[tail_backbuf] = 0;
|
||||
rel->num_backbuf++;
|
||||
}
|
||||
|
||||
int
|
||||
MSG_ReliableCheckSize (backbuf_t *rel, int maxsize, int minsize)
|
||||
{
|
||||
sizebuf_t *msg = &rel->netchan->message;
|
||||
|
||||
if (rel->num_backbuf)
|
||||
msg = &rel->backbuf;
|
||||
|
||||
if (maxsize <= msg->maxsize - msg->cursize - 1)
|
||||
return maxsize;
|
||||
|
||||
if (minsize <= msg->maxsize - msg->cursize - 1)
|
||||
return msg->maxsize - msg->cursize - 1;
|
||||
|
||||
if (rel->num_backbuf == MAX_BACK_BUFFERS)
|
||||
return 0;
|
||||
|
||||
return rel->backbuf.maxsize;
|
||||
}
|
||||
|
||||
// check to see if client block will fit, if not, rotate buffers
|
||||
void
|
||||
MSG_ReliableCheckBlock (backbuf_t *rel, int maxsize)
|
||||
{
|
||||
sizebuf_t *msg = &rel->netchan->message;
|
||||
|
||||
if (rel->num_backbuf || msg->cursize > msg->maxsize - maxsize - 1) {
|
||||
// we would probably overflow the buffer, save it for next
|
||||
if (!rel->num_backbuf) {
|
||||
PushBackbuf (rel);
|
||||
}
|
||||
|
||||
if (rel->backbuf.cursize > rel->backbuf.maxsize - maxsize - 1) {
|
||||
if (rel->num_backbuf == MAX_BACK_BUFFERS) {
|
||||
Con_Printf ("WARNING: MAX_BACK_BUFFERS for %s\n", rel->name);
|
||||
rel->backbuf.cursize = 0; // don't overflow without
|
||||
// allowoverflow set
|
||||
msg->overflowed = true; // this will drop the client
|
||||
return;
|
||||
}
|
||||
PushBackbuf (rel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// begin a client block, estimated maximum size
|
||||
void
|
||||
MSG_ReliableWrite_Begin (backbuf_t *rel, int c, int maxsize)
|
||||
{
|
||||
MSG_ReliableCheckBlock (rel, maxsize);
|
||||
MSG_ReliableWrite_Byte (rel, c);
|
||||
}
|
||||
|
||||
void
|
||||
MSG_Reliable_FinishWrite (backbuf_t *rel)
|
||||
{
|
||||
int tail_backbuf;
|
||||
|
||||
if (rel->num_backbuf) {
|
||||
tail_backbuf = (rel->head_backbuf + rel->num_backbuf - 1)
|
||||
% MAX_BACK_BUFFERS;
|
||||
rel->backbuf_size[tail_backbuf] = rel->backbuf.cursize;
|
||||
|
||||
if (rel->backbuf.overflowed) {
|
||||
Con_Printf ("WARNING: backbuf [%d] overflow for %s\n",
|
||||
rel->num_backbuf, rel->name);
|
||||
rel->netchan->message.overflowed = true; // this will drop the
|
||||
// client
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MSG_ReliableWrite_Angle (backbuf_t *rel, float f)
|
||||
{
|
||||
if (rel->num_backbuf) {
|
||||
MSG_WriteAngle (&rel->backbuf, f);
|
||||
MSG_Reliable_FinishWrite (rel);
|
||||
} else
|
||||
MSG_WriteAngle (&rel->netchan->message, f);
|
||||
}
|
||||
|
||||
void
|
||||
MSG_ReliableWrite_Angle16 (backbuf_t *rel, float f)
|
||||
{
|
||||
if (rel->num_backbuf) {
|
||||
MSG_WriteAngle16 (&rel->backbuf, f);
|
||||
MSG_Reliable_FinishWrite (rel);
|
||||
} else
|
||||
MSG_WriteAngle16 (&rel->netchan->message, f);
|
||||
}
|
||||
|
||||
void
|
||||
MSG_ReliableWrite_Byte (backbuf_t *rel, int c)
|
||||
{
|
||||
if (rel->num_backbuf) {
|
||||
MSG_WriteByte (&rel->backbuf, c);
|
||||
MSG_Reliable_FinishWrite (rel);
|
||||
} else
|
||||
MSG_WriteByte (&rel->netchan->message, c);
|
||||
}
|
||||
|
||||
void
|
||||
MSG_ReliableWrite_Char (backbuf_t *rel, int c)
|
||||
{
|
||||
if (rel->num_backbuf) {
|
||||
MSG_WriteByte (&rel->backbuf, c);
|
||||
MSG_Reliable_FinishWrite (rel);
|
||||
} else
|
||||
MSG_WriteByte (&rel->netchan->message, c);
|
||||
}
|
||||
|
||||
void
|
||||
MSG_ReliableWrite_Float (backbuf_t *rel, float f)
|
||||
{
|
||||
if (rel->num_backbuf) {
|
||||
MSG_WriteFloat (&rel->backbuf, f);
|
||||
MSG_Reliable_FinishWrite (rel);
|
||||
} else
|
||||
MSG_WriteFloat (&rel->netchan->message, f);
|
||||
}
|
||||
|
||||
void
|
||||
MSG_ReliableWrite_Coord (backbuf_t *rel, float f)
|
||||
{
|
||||
if (rel->num_backbuf) {
|
||||
MSG_WriteCoord (&rel->backbuf, f);
|
||||
MSG_Reliable_FinishWrite (rel);
|
||||
} else
|
||||
MSG_WriteCoord (&rel->netchan->message, f);
|
||||
}
|
||||
|
||||
void
|
||||
MSG_ReliableWrite_Long (backbuf_t *rel, int c)
|
||||
{
|
||||
if (rel->num_backbuf) {
|
||||
MSG_WriteLong (&rel->backbuf, c);
|
||||
MSG_Reliable_FinishWrite (rel);
|
||||
} else
|
||||
MSG_WriteLong (&rel->netchan->message, c);
|
||||
}
|
||||
|
||||
void
|
||||
MSG_ReliableWrite_Short (backbuf_t *rel, int c)
|
||||
{
|
||||
if (rel->num_backbuf) {
|
||||
MSG_WriteShort (&rel->backbuf, c);
|
||||
MSG_Reliable_FinishWrite (rel);
|
||||
} else
|
||||
MSG_WriteShort (&rel->netchan->message, c);
|
||||
}
|
||||
|
||||
void
|
||||
MSG_ReliableWrite_String (backbuf_t *rel, const char *s)
|
||||
{
|
||||
if (rel->num_backbuf) {
|
||||
MSG_WriteString (&rel->backbuf, s);
|
||||
MSG_Reliable_FinishWrite (rel);
|
||||
} else
|
||||
MSG_WriteString (&rel->netchan->message, s);
|
||||
}
|
||||
|
||||
void
|
||||
MSG_ReliableWrite_SZ (backbuf_t *rel, const void *data, int len)
|
||||
{
|
||||
if (rel->num_backbuf) {
|
||||
SZ_Write (&rel->backbuf, data, len);
|
||||
MSG_Reliable_FinishWrite (rel);
|
||||
} else
|
||||
SZ_Write (&rel->netchan->message, data, len);
|
||||
}
|
||||
|
||||
void
|
||||
MSG_ReliableWrite_AngleV (backbuf_t *rel, const vec3_t v)
|
||||
{
|
||||
if (rel->num_backbuf) {
|
||||
MSG_WriteAngleV (&rel->backbuf, v);
|
||||
MSG_Reliable_FinishWrite (rel);
|
||||
} else
|
||||
MSG_WriteAngleV (&rel->netchan->message, v);
|
||||
}
|
||||
|
||||
void
|
||||
MSG_ReliableWrite_CoordV (backbuf_t *rel, const vec3_t v)
|
||||
{
|
||||
if (rel->num_backbuf) {
|
||||
MSG_WriteCoordV (&rel->backbuf, v);
|
||||
MSG_Reliable_FinishWrite (rel);
|
||||
} else
|
||||
MSG_WriteCoordV (&rel->netchan->message, v);
|
||||
}
|
||||
|
||||
void
|
||||
MSG_Reliable_Send (backbuf_t *rel)
|
||||
{
|
||||
sizebuf_t *msg = &rel->netchan->message;
|
||||
int *size = &rel->backbuf_size[rel->head_backbuf];
|
||||
byte *data = rel->backbuf_data[rel->head_backbuf];
|
||||
|
||||
if (!rel->num_backbuf)
|
||||
return;
|
||||
// will it fit?
|
||||
if (msg->cursize + *size < msg->maxsize) {
|
||||
Con_DPrintf ("%s: backbuf %d bytes\n", rel->name, *size);
|
||||
// it'll fit
|
||||
SZ_Write (msg, data, *size);
|
||||
|
||||
// move along, move along
|
||||
if (--rel->num_backbuf)
|
||||
rel->head_backbuf = (rel->head_backbuf + 1) % MAX_BACK_BUFFERS;
|
||||
}
|
||||
}
|
|
@ -52,9 +52,6 @@
|
|||
|
||||
#define ON_EPSILON 0.1 // point on plane side epsilon
|
||||
|
||||
#define MAX_MSGLEN 1450 // max length of a reliable message
|
||||
#define MAX_DATAGRAM 1450 // max length of unreliable message
|
||||
|
||||
//
|
||||
// per-level limits
|
||||
//
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
|
||||
#include "host.h"
|
||||
#include "netchan.h"
|
||||
#include "qw/msg_backbuf.h"
|
||||
#include "qw/protocol.h"
|
||||
|
||||
#define QW_SERVER
|
||||
|
@ -186,10 +187,7 @@ typedef struct client_s
|
|||
byte datagram_buf[MAX_DATAGRAM];
|
||||
|
||||
// back buffers for client reliable data
|
||||
sizebuf_t backbuf;
|
||||
int num_backbuf;
|
||||
int backbuf_size[MAX_BACK_BUFFERS];
|
||||
byte backbuf_data[MAX_BACK_BUFFERS][MAX_MSGLEN];
|
||||
backbuf_t backbuf;
|
||||
|
||||
byte stufftext_buf[MAX_STUFFTEXT];
|
||||
|
||||
|
@ -581,22 +579,6 @@ void SV_WriteEntitiesToClient (client_t *client, sizebuf_t *msg,
|
|||
//
|
||||
// sv_nchan.c
|
||||
//
|
||||
int ClientReliableCheckSize (client_t *cl, int maxsize, int minsize);
|
||||
void ClientReliableCheckBlock(client_t *cl, int maxsize);
|
||||
void ClientReliable_FinishWrite(client_t *cl);
|
||||
void ClientReliableWrite_Begin(client_t *cl, int c, int maxsize);
|
||||
void ClientReliableWrite_Angle(client_t *cl, float f);
|
||||
void ClientReliableWrite_Angle16(client_t *cl, float f);
|
||||
void ClientReliableWrite_Byte(client_t *cl, int c);
|
||||
void ClientReliableWrite_Char(client_t *cl, int c);
|
||||
void ClientReliableWrite_Float(client_t *cl, float f);
|
||||
void ClientReliableWrite_Coord(client_t *cl, float f);
|
||||
void ClientReliableWrite_Long(client_t *cl, int c);
|
||||
void ClientReliableWrite_Short(client_t *cl, int c);
|
||||
void ClientReliableWrite_String(client_t *cl, const char *s);
|
||||
void ClientReliableWrite_SZ(client_t *cl, const void *data, int len);
|
||||
void ClientReliableWrite_AngleV(client_t *cl, const vec3_t v);
|
||||
void ClientReliableWrite_CoordV(client_t *cl, const vec3_t v);
|
||||
|
||||
void Cvar_Info (struct cvar_s *var);
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ EXTRA_DIST=sv_sys_win.c sv_sys_unix.c
|
|||
|
||||
libqw_server_a_SOURCES= \
|
||||
crudefile.c sv_ccmds.c sv_demo.c sv_ents.c sv_gib.c sv_init.c sv_main.c \
|
||||
sv_move.c sv_nchan.c sv_phys.c sv_pr_cmds.c sv_pr_qwe.c sv_progs.c \
|
||||
sv_move.c sv_phys.c sv_pr_cmds.c sv_pr_qwe.c sv_progs.c \
|
||||
sv_send.c sv_user.c world.c $(syssv_SRC)
|
||||
|
||||
qw_server_LIBS= \
|
||||
|
|
|
@ -46,6 +46,7 @@ static __attribute__ ((unused)) const char rcsid[] =
|
|||
|
||||
#include "qw/msg_ucmd.h"
|
||||
|
||||
#include "bothdefs.h"
|
||||
#include "cl_cam.h"
|
||||
#include "cl_ents.h"
|
||||
#include "cl_main.h"
|
||||
|
|
|
@ -615,9 +615,9 @@ SV_Punish (int mode)
|
|||
if (mins) {
|
||||
dsprintf (text, "You are %s for %.1f minutes\n\n"
|
||||
"reconnecting won't help...\n", cmd_do, mins);
|
||||
ClientReliableWrite_Begin (cl, svc_centerprint,
|
||||
2 + strlen (text->str));
|
||||
ClientReliableWrite_String (cl, text->str);
|
||||
MSG_ReliableWrite_Begin (&cl->backbuf, svc_centerprint,
|
||||
2 + strlen (text->str));
|
||||
MSG_ReliableWrite_String (&cl->backbuf, text->str);
|
||||
}
|
||||
}
|
||||
if (all) {
|
||||
|
@ -629,9 +629,9 @@ SV_Punish (int mode)
|
|||
if (mins) {
|
||||
dsprintf (text, "You are %s for %.1f minutes\n\n"
|
||||
"reconnecting won't help...\n", cmd_do, mins);
|
||||
ClientReliableWrite_Begin (cl, svc_centerprint,
|
||||
2 + strlen (text->str));
|
||||
ClientReliableWrite_String (cl, text->str);
|
||||
MSG_ReliableWrite_Begin (&cl->backbuf, svc_centerprint,
|
||||
2 + strlen (text->str));
|
||||
MSG_ReliableWrite_String (&cl->backbuf, text->str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1047,8 +1047,8 @@ SV_Snap (int uid)
|
|||
else
|
||||
cl->remote_snap = false;
|
||||
|
||||
ClientReliableWrite_Begin (cl, svc_stufftext, 24);
|
||||
ClientReliableWrite_String (cl, "cmd snap\n");
|
||||
MSG_ReliableWrite_Begin (&cl->backbuf, svc_stufftext, 24);
|
||||
MSG_ReliableWrite_String (&cl->backbuf, "cmd snap\n");
|
||||
SV_Printf ("Requesting snap from user %d...\n", uid);
|
||||
}
|
||||
|
||||
|
|
|
@ -460,10 +460,10 @@ SV_FullClientUpdateToClient (client_t *client, client_t *cl)
|
|||
{
|
||||
if (client->state < cs_connected && client->state != cs_server)
|
||||
return;
|
||||
ClientReliableCheckBlock (cl, 24 + client->userinfo->cursize);
|
||||
if (cl->num_backbuf) {
|
||||
SV_FullClientUpdate (client, &cl->backbuf);
|
||||
ClientReliable_FinishWrite (cl);
|
||||
MSG_ReliableCheckBlock (&cl->backbuf, 24 + client->userinfo->cursize);
|
||||
if (cl->backbuf.num_backbuf) {
|
||||
SV_FullClientUpdate (client, &cl->backbuf.backbuf);
|
||||
MSG_Reliable_FinishWrite (&cl->backbuf);
|
||||
} else
|
||||
SV_FullClientUpdate (client, &cl->netchan.message);
|
||||
}
|
||||
|
@ -897,6 +897,8 @@ SVC_DirectConnect (void)
|
|||
Netchan_OutOfBandPrint (adr, "%c", S2C_CONNECTION);
|
||||
|
||||
Netchan_Setup (&newcl->netchan, adr, qport, NC_READ_QPORT);
|
||||
newcl->backbuf.netchan = &newcl->netchan;
|
||||
newcl->backbuf.name = newcl->name;
|
||||
|
||||
newcl->state = cs_connected;
|
||||
newcl->prespawned = false;
|
||||
|
@ -1450,8 +1452,9 @@ SV_AddIP_f (void)
|
|||
snprintf (text, sizeof (text), "You are %s %s\n%s",
|
||||
typestr, timestr, type == ft_ban ? "" :
|
||||
"\nReconnecting won't help...");
|
||||
ClientReliableWrite_Begin (cl, svc_centerprint, strlen (text) + 2);
|
||||
ClientReliableWrite_String (cl, text);
|
||||
MSG_ReliableWrite_Begin (&cl->backbuf, svc_centerprint,
|
||||
strlen (text) + 2);
|
||||
MSG_ReliableWrite_String (&cl->backbuf, text);
|
||||
// FIXME: print on the console too
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,243 +0,0 @@
|
|||
/*
|
||||
sv_nchan.c
|
||||
|
||||
user reliable data stream writes
|
||||
|
||||
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 "server.h"
|
||||
|
||||
|
||||
static void
|
||||
PushBackbuf (client_t *cl)
|
||||
{
|
||||
memset (&cl->backbuf, 0, sizeof (cl->backbuf));
|
||||
cl->backbuf.allowoverflow = true;
|
||||
cl->backbuf.data = cl->backbuf_data[cl->num_backbuf];
|
||||
cl->backbuf.maxsize = sizeof (cl->backbuf_data[cl->num_backbuf]);
|
||||
cl->backbuf_size[cl->num_backbuf] = 0;
|
||||
cl->num_backbuf++;
|
||||
}
|
||||
|
||||
int
|
||||
ClientReliableCheckSize (client_t *cl, int maxsize, int minsize)
|
||||
{
|
||||
sizebuf_t *msg = &cl->netchan.message;
|
||||
|
||||
if (cl->num_backbuf)
|
||||
msg = &cl->backbuf;
|
||||
|
||||
if (maxsize <= msg->maxsize - msg->cursize - 1)
|
||||
return maxsize;
|
||||
|
||||
if (minsize <= msg->maxsize - msg->cursize - 1)
|
||||
return msg->maxsize - msg->cursize - 1;
|
||||
|
||||
if (cl->num_backbuf == MAX_BACK_BUFFERS)
|
||||
return 0;
|
||||
|
||||
return cl->backbuf.maxsize;
|
||||
}
|
||||
|
||||
// check to see if client block will fit, if not, rotate buffers
|
||||
void
|
||||
ClientReliableCheckBlock (client_t *cl, int maxsize)
|
||||
{
|
||||
sizebuf_t *msg = &cl->netchan.message;
|
||||
|
||||
if (cl->num_backbuf || msg->cursize > msg->maxsize - maxsize - 1) {
|
||||
// we would probably overflow the buffer, save it for next
|
||||
if (!cl->num_backbuf) {
|
||||
PushBackbuf (cl);
|
||||
}
|
||||
|
||||
if (cl->backbuf.cursize > cl->backbuf.maxsize - maxsize - 1) {
|
||||
if (cl->num_backbuf == MAX_BACK_BUFFERS) {
|
||||
SV_Printf ("WARNING: MAX_BACK_BUFFERS for %s\n", cl->name);
|
||||
cl->backbuf.cursize = 0; // don't overflow without
|
||||
// allowoverflow set
|
||||
msg->overflowed = true; // this will drop the client
|
||||
return;
|
||||
}
|
||||
PushBackbuf (cl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// begin a client block, estimated maximum size
|
||||
void
|
||||
ClientReliableWrite_Begin (client_t *cl, int c, int maxsize)
|
||||
{
|
||||
ClientReliableCheckBlock (cl, maxsize);
|
||||
ClientReliableWrite_Byte (cl, c);
|
||||
}
|
||||
|
||||
void
|
||||
ClientReliable_FinishWrite (client_t *cl)
|
||||
{
|
||||
if (cl->num_backbuf) {
|
||||
cl->backbuf_size[cl->num_backbuf - 1] = cl->backbuf.cursize;
|
||||
|
||||
if (cl->backbuf.overflowed) {
|
||||
SV_Printf ("WARNING: backbuf [%d] reliable overflow for %s\n",
|
||||
cl->num_backbuf, cl->name);
|
||||
cl->netchan.message.overflowed = true; // this will drop the
|
||||
// client
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ClientReliableWrite_Angle (client_t *cl, float f)
|
||||
{
|
||||
if (cl->num_backbuf) {
|
||||
MSG_WriteAngle (&cl->backbuf, f);
|
||||
ClientReliable_FinishWrite (cl);
|
||||
} else
|
||||
MSG_WriteAngle (&cl->netchan.message, f);
|
||||
}
|
||||
|
||||
void
|
||||
ClientReliableWrite_Angle16 (client_t *cl, float f)
|
||||
{
|
||||
if (cl->num_backbuf) {
|
||||
MSG_WriteAngle16 (&cl->backbuf, f);
|
||||
ClientReliable_FinishWrite (cl);
|
||||
} else
|
||||
MSG_WriteAngle16 (&cl->netchan.message, f);
|
||||
}
|
||||
|
||||
void
|
||||
ClientReliableWrite_Byte (client_t *cl, int c)
|
||||
{
|
||||
if (cl->num_backbuf) {
|
||||
MSG_WriteByte (&cl->backbuf, c);
|
||||
ClientReliable_FinishWrite (cl);
|
||||
} else
|
||||
MSG_WriteByte (&cl->netchan.message, c);
|
||||
}
|
||||
|
||||
void
|
||||
ClientReliableWrite_Char (client_t *cl, int c)
|
||||
{
|
||||
if (cl->num_backbuf) {
|
||||
MSG_WriteByte (&cl->backbuf, c);
|
||||
ClientReliable_FinishWrite (cl);
|
||||
} else
|
||||
MSG_WriteByte (&cl->netchan.message, c);
|
||||
}
|
||||
|
||||
void
|
||||
ClientReliableWrite_Float (client_t *cl, float f)
|
||||
{
|
||||
if (cl->num_backbuf) {
|
||||
MSG_WriteFloat (&cl->backbuf, f);
|
||||
ClientReliable_FinishWrite (cl);
|
||||
} else
|
||||
MSG_WriteFloat (&cl->netchan.message, f);
|
||||
}
|
||||
|
||||
void
|
||||
ClientReliableWrite_Coord (client_t *cl, float f)
|
||||
{
|
||||
if (cl->num_backbuf) {
|
||||
MSG_WriteCoord (&cl->backbuf, f);
|
||||
ClientReliable_FinishWrite (cl);
|
||||
} else
|
||||
MSG_WriteCoord (&cl->netchan.message, f);
|
||||
}
|
||||
|
||||
void
|
||||
ClientReliableWrite_Long (client_t *cl, int c)
|
||||
{
|
||||
if (cl->num_backbuf) {
|
||||
MSG_WriteLong (&cl->backbuf, c);
|
||||
ClientReliable_FinishWrite (cl);
|
||||
} else
|
||||
MSG_WriteLong (&cl->netchan.message, c);
|
||||
}
|
||||
|
||||
void
|
||||
ClientReliableWrite_Short (client_t *cl, int c)
|
||||
{
|
||||
if (cl->num_backbuf) {
|
||||
MSG_WriteShort (&cl->backbuf, c);
|
||||
ClientReliable_FinishWrite (cl);
|
||||
} else
|
||||
MSG_WriteShort (&cl->netchan.message, c);
|
||||
}
|
||||
|
||||
void
|
||||
ClientReliableWrite_String (client_t *cl, const char *s)
|
||||
{
|
||||
if (cl->num_backbuf) {
|
||||
MSG_WriteString (&cl->backbuf, s);
|
||||
ClientReliable_FinishWrite (cl);
|
||||
} else
|
||||
MSG_WriteString (&cl->netchan.message, s);
|
||||
}
|
||||
|
||||
void
|
||||
ClientReliableWrite_SZ (client_t *cl, const void *data, int len)
|
||||
{
|
||||
if (cl->num_backbuf) {
|
||||
SZ_Write (&cl->backbuf, data, len);
|
||||
ClientReliable_FinishWrite (cl);
|
||||
} else
|
||||
SZ_Write (&cl->netchan.message, data, len);
|
||||
}
|
||||
|
||||
void
|
||||
ClientReliableWrite_AngleV (client_t *cl, const vec3_t v)
|
||||
{
|
||||
if (cl->num_backbuf) {
|
||||
MSG_WriteAngleV (&cl->backbuf, v);
|
||||
ClientReliable_FinishWrite (cl);
|
||||
} else
|
||||
MSG_WriteAngleV (&cl->netchan.message, v);
|
||||
}
|
||||
|
||||
void
|
||||
ClientReliableWrite_CoordV (client_t *cl, const vec3_t v)
|
||||
{
|
||||
if (cl->num_backbuf) {
|
||||
MSG_WriteCoordV (&cl->backbuf, v);
|
||||
ClientReliable_FinishWrite (cl);
|
||||
} else
|
||||
MSG_WriteCoordV (&cl->netchan.message, v);
|
||||
}
|
|
@ -291,8 +291,8 @@ PF_centerprint (progs_t *pr)
|
|||
|
||||
s = PF_VarString (pr, 1);
|
||||
|
||||
ClientReliableWrite_Begin (cl, svc_centerprint, 2 + strlen (s));
|
||||
ClientReliableWrite_String (cl, s);
|
||||
MSG_ReliableWrite_Begin (&cl->backbuf, svc_centerprint, 2 + strlen (s));
|
||||
MSG_ReliableWrite_String (&cl->backbuf, s);
|
||||
|
||||
if (sv.demorecording) {
|
||||
DemoWrite_Begin (dem_single, entnum - 1, 2 + strlen (s));
|
||||
|
@ -601,8 +601,8 @@ PF_stuffcmd (progs_t *pr)
|
|||
if (p) {
|
||||
char t = p[1];
|
||||
p[1] = 0;
|
||||
ClientReliableWrite_Begin (cl, svc_stufftext, 2 + p - buf);
|
||||
ClientReliableWrite_String (cl, buf);
|
||||
MSG_ReliableWrite_Begin (&cl->backbuf, svc_stufftext, 2 + p - buf);
|
||||
MSG_ReliableWrite_String (&cl->backbuf, buf);
|
||||
if (sv.demorecording) {
|
||||
DemoWrite_Begin (dem_single, cl - svs.clients, 2 + strlen (buf));
|
||||
MSG_WriteByte (&demo.dbuf->sz, svc_stufftext);
|
||||
|
@ -862,7 +862,7 @@ void
|
|||
PF_lightstyle (progs_t *pr)
|
||||
{
|
||||
const char *val;
|
||||
client_t *client;
|
||||
client_t *cl;
|
||||
int style, j;
|
||||
|
||||
style = P_FLOAT (pr, 0);
|
||||
|
@ -875,12 +875,12 @@ PF_lightstyle (progs_t *pr)
|
|||
if (sv.state != ss_active)
|
||||
return;
|
||||
|
||||
for (j = 0, client = svs.clients; j < MAX_CLIENTS; j++, client++)
|
||||
if (client->state == cs_spawned) {
|
||||
ClientReliableWrite_Begin (client, svc_lightstyle,
|
||||
for (j = 0, cl = svs.clients; j < MAX_CLIENTS; j++, cl++)
|
||||
if (cl->state == cs_spawned) {
|
||||
MSG_ReliableWrite_Begin (&cl->backbuf, svc_lightstyle,
|
||||
strlen (val) + 3);
|
||||
ClientReliableWrite_Char (client, style);
|
||||
ClientReliableWrite_String (client, val);
|
||||
MSG_ReliableWrite_Char (&cl->backbuf, style);
|
||||
MSG_ReliableWrite_String (&cl->backbuf, val);
|
||||
}
|
||||
if (sv.demorecording) {
|
||||
DemoWrite_Begin (dem_all, 0, strlen (val) + 3);
|
||||
|
@ -1111,13 +1111,13 @@ PF_WriteBytes (progs_t *pr)
|
|||
client_t *cl = Write_GetClient (pr);
|
||||
|
||||
if (cl->state != cs_server)
|
||||
ClientReliableCheckBlock (cl, pr->pr_argc);
|
||||
MSG_ReliableCheckBlock (&cl->backbuf, pr->pr_argc);
|
||||
if (sv.demorecording)
|
||||
DemoWrite_Begin (dem_single, cl - svs.clients, pr->pr_argc);
|
||||
for (i = 1; i < pr->pr_argc; i++) {
|
||||
p = P_FLOAT (pr, i);
|
||||
if (cl->state != cs_server)
|
||||
ClientReliableWrite_Byte (cl, p);
|
||||
MSG_ReliableWrite_Byte (&cl->backbuf, p);
|
||||
if (sv.demorecording)
|
||||
MSG_WriteByte (&demo.dbuf->sz, p);
|
||||
}
|
||||
|
@ -1138,8 +1138,8 @@ PF_WriteByte (progs_t *pr)
|
|||
client_t *cl = Write_GetClient (pr);
|
||||
|
||||
if (cl->state != cs_server) {
|
||||
ClientReliableCheckBlock (cl, 1);
|
||||
ClientReliableWrite_Byte (cl, P_FLOAT (pr, 1));
|
||||
MSG_ReliableCheckBlock (&cl->backbuf, 1);
|
||||
MSG_ReliableWrite_Byte (&cl->backbuf, P_FLOAT (pr, 1));
|
||||
}
|
||||
if (sv.demorecording) {
|
||||
DemoWrite_Begin (dem_single, cl - svs.clients, 1);
|
||||
|
@ -1157,8 +1157,8 @@ PF_WriteChar (progs_t *pr)
|
|||
client_t *cl = Write_GetClient (pr);
|
||||
|
||||
if (cl->state != cs_server) {
|
||||
ClientReliableCheckBlock (cl, 1);
|
||||
ClientReliableWrite_Char (cl, P_FLOAT (pr, 1));
|
||||
MSG_ReliableCheckBlock (&cl->backbuf, 1);
|
||||
MSG_ReliableWrite_Char (&cl->backbuf, P_FLOAT (pr, 1));
|
||||
}
|
||||
if (sv.demorecording) {
|
||||
DemoWrite_Begin (dem_single, cl - svs.clients, 1);
|
||||
|
@ -1176,8 +1176,8 @@ PF_WriteShort (progs_t *pr)
|
|||
client_t *cl = Write_GetClient (pr);
|
||||
|
||||
if (cl->state != cs_server) {
|
||||
ClientReliableCheckBlock (cl, 2);
|
||||
ClientReliableWrite_Short (cl, P_FLOAT (pr, 1));
|
||||
MSG_ReliableCheckBlock (&cl->backbuf, 2);
|
||||
MSG_ReliableWrite_Short (&cl->backbuf, P_FLOAT (pr, 1));
|
||||
}
|
||||
if (sv.demorecording) {
|
||||
DemoWrite_Begin (dem_single, cl - svs.clients, 2);
|
||||
|
@ -1195,8 +1195,8 @@ PF_WriteLong (progs_t *pr)
|
|||
client_t *cl = Write_GetClient (pr);
|
||||
|
||||
if (cl->state != cs_server) {
|
||||
ClientReliableCheckBlock (cl, 4);
|
||||
ClientReliableWrite_Long (cl, P_FLOAT (pr, 1));
|
||||
MSG_ReliableCheckBlock (&cl->backbuf, 4);
|
||||
MSG_ReliableWrite_Long (&cl->backbuf, P_FLOAT (pr, 1));
|
||||
}
|
||||
if (sv.demorecording) {
|
||||
DemoWrite_Begin (dem_single, cl - svs.clients, 4);
|
||||
|
@ -1214,8 +1214,8 @@ PF_WriteAngle (progs_t *pr)
|
|||
client_t *cl = Write_GetClient (pr);
|
||||
|
||||
if (cl->state != cs_server) {
|
||||
ClientReliableCheckBlock (cl, 1);
|
||||
ClientReliableWrite_Angle (cl, P_FLOAT (pr, 1));
|
||||
MSG_ReliableCheckBlock (&cl->backbuf, 1);
|
||||
MSG_ReliableWrite_Angle (&cl->backbuf, P_FLOAT (pr, 1));
|
||||
}
|
||||
if (sv.demorecording) {
|
||||
DemoWrite_Begin (dem_single, cl - svs.clients, 1);
|
||||
|
@ -1233,8 +1233,8 @@ PF_WriteCoord (progs_t *pr)
|
|||
client_t *cl = Write_GetClient (pr);
|
||||
|
||||
if (cl->state != cs_server) {
|
||||
ClientReliableCheckBlock (cl, 2);
|
||||
ClientReliableWrite_Coord (cl, P_FLOAT (pr, 1));
|
||||
MSG_ReliableCheckBlock (&cl->backbuf, 2);
|
||||
MSG_ReliableWrite_Coord (&cl->backbuf, P_FLOAT (pr, 1));
|
||||
}
|
||||
if (sv.demorecording) {
|
||||
DemoWrite_Begin (dem_single, cl - svs.clients, 2);
|
||||
|
@ -1254,8 +1254,8 @@ PF_WriteAngleV (progs_t *pr)
|
|||
client_t *cl = Write_GetClient (pr);
|
||||
|
||||
if (cl->state != cs_server) {
|
||||
ClientReliableCheckBlock (cl, 1);
|
||||
ClientReliableWrite_AngleV (cl, ang);
|
||||
MSG_ReliableCheckBlock (&cl->backbuf, 1);
|
||||
MSG_ReliableWrite_AngleV (&cl->backbuf, ang);
|
||||
}
|
||||
if (sv.demorecording) {
|
||||
DemoWrite_Begin (dem_single, cl - svs.clients, 1);
|
||||
|
@ -1275,8 +1275,8 @@ PF_WriteCoordV (progs_t *pr)
|
|||
client_t *cl = Write_GetClient (pr);
|
||||
|
||||
if (cl->state != cs_server) {
|
||||
ClientReliableCheckBlock (cl, 2);
|
||||
ClientReliableWrite_CoordV (cl, coord);
|
||||
MSG_ReliableCheckBlock (&cl->backbuf, 2);
|
||||
MSG_ReliableWrite_CoordV (&cl->backbuf, coord);
|
||||
}
|
||||
if (sv.demorecording) {
|
||||
DemoWrite_Begin (dem_single, cl - svs.clients, 2);
|
||||
|
@ -1294,8 +1294,9 @@ PF_WriteString (progs_t *pr)
|
|||
client_t *cl = Write_GetClient (pr);
|
||||
|
||||
if (cl->state != cs_server) {
|
||||
ClientReliableCheckBlock (cl, 1 + strlen (P_GSTRING (pr, 1)));
|
||||
ClientReliableWrite_String (cl, P_GSTRING (pr, 1));
|
||||
MSG_ReliableCheckBlock (&cl->backbuf,
|
||||
1 + strlen (P_GSTRING (pr, 1)));
|
||||
MSG_ReliableWrite_String (&cl->backbuf, P_GSTRING (pr, 1));
|
||||
}
|
||||
if (sv.demorecording) {
|
||||
DemoWrite_Begin (dem_single, cl - svs.clients,
|
||||
|
@ -1314,8 +1315,8 @@ PF_WriteEntity (progs_t *pr)
|
|||
client_t *cl = Write_GetClient (pr);
|
||||
|
||||
if (cl->state != cs_server) {
|
||||
ClientReliableCheckBlock (cl, 2);
|
||||
ClientReliableWrite_Short (cl, P_EDICTNUM (pr, 1));
|
||||
MSG_ReliableCheckBlock (&cl->backbuf, 2);
|
||||
MSG_ReliableWrite_Short (&cl->backbuf, P_EDICTNUM (pr, 1));
|
||||
}
|
||||
if (sv.demorecording) {
|
||||
DemoWrite_Begin (dem_single, cl - svs.clients, 2);
|
||||
|
|
|
@ -111,16 +111,16 @@ SV_FlushRedirect (void)
|
|||
// +/- 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;
|
||||
bytes = MSG_ReliableCheckSize (&cl->backbuf, 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);
|
||||
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);
|
||||
p += bytes;
|
||||
count -= bytes;
|
||||
}
|
||||
|
@ -266,9 +266,9 @@ SV_PrintToClient (client_t *cl, int level, const char *string)
|
|||
if (*b != 0xFF)
|
||||
b++;
|
||||
|
||||
ClientReliableWrite_Begin (cl, svc_print, strlen (buffer) + 3);
|
||||
ClientReliableWrite_Byte (cl, level);
|
||||
ClientReliableWrite_String (cl, buffer);
|
||||
MSG_ReliableWrite_Begin (&cl->backbuf, svc_print, strlen (buffer) + 3);
|
||||
MSG_ReliableWrite_Byte (&cl->backbuf, level);
|
||||
MSG_ReliableWrite_String (&cl->backbuf, buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -348,9 +348,9 @@ SV_Multicast (const vec3_t origin, int to)
|
|||
|
||||
inrange:
|
||||
if (reliable) {
|
||||
ClientReliableCheckBlock (client, sv.multicast.cursize);
|
||||
ClientReliableWrite_SZ (client, sv.multicast.data,
|
||||
sv.multicast.cursize);
|
||||
MSG_ReliableCheckBlock (&client->backbuf, sv.multicast.cursize);
|
||||
MSG_ReliableWrite_SZ (&client->backbuf, sv.multicast.data,
|
||||
sv.multicast.cursize);
|
||||
} else
|
||||
SZ_Write (&client->datagram, sv.multicast.data,
|
||||
sv.multicast.cursize);
|
||||
|
@ -590,13 +590,14 @@ SV_UpdateClientStats (client_t *client)
|
|||
if (stats[i] != client->stats[i]) {
|
||||
client->stats[i] = stats[i];
|
||||
if (stats[i] >= 0 && stats[i] <= 255) {
|
||||
ClientReliableWrite_Begin (client, svc_updatestat, 3);
|
||||
ClientReliableWrite_Byte (client, i);
|
||||
ClientReliableWrite_Byte (client, stats[i]);
|
||||
MSG_ReliableWrite_Begin (&client->backbuf, svc_updatestat, 3);
|
||||
MSG_ReliableWrite_Byte (&client->backbuf, i);
|
||||
MSG_ReliableWrite_Byte (&client->backbuf, stats[i]);
|
||||
} else {
|
||||
ClientReliableWrite_Begin (client, svc_updatestatlong, 6);
|
||||
ClientReliableWrite_Byte (client, i);
|
||||
ClientReliableWrite_Long (client, stats[i]);
|
||||
MSG_ReliableWrite_Begin (&client->backbuf,
|
||||
svc_updatestatlong, 6);
|
||||
MSG_ReliableWrite_Byte (&client->backbuf, i);
|
||||
MSG_ReliableWrite_Long (&client->backbuf, stats[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -665,10 +666,10 @@ SV_UpdateToReliableMessages (void)
|
|||
for (j = 0, client = svs.clients; j < MAX_CLIENTS; j++, client++) {
|
||||
if (client->state < cs_connected)
|
||||
continue;
|
||||
ClientReliableWrite_Begin (client, svc_updatefrags, 4);
|
||||
ClientReliableWrite_Byte (client, i);
|
||||
ClientReliableWrite_Short (client, SVfloat (host_client->edict,
|
||||
frags));
|
||||
MSG_ReliableWrite_Begin (&client->backbuf, svc_updatefrags, 4);
|
||||
MSG_ReliableWrite_Byte (&client->backbuf, i);
|
||||
MSG_ReliableWrite_Short (&client->backbuf,
|
||||
SVfloat (host_client->edict, frags));
|
||||
}
|
||||
|
||||
if (sv.demorecording) {
|
||||
|
@ -687,8 +688,9 @@ SV_UpdateToReliableMessages (void)
|
|||
if (sv_fields.gravity != -1
|
||||
&& host_client->entgravity != SVfloat (ent, gravity)) {
|
||||
host_client->entgravity = SVfloat (ent, gravity);
|
||||
ClientReliableWrite_Begin (host_client, svc_entgravity, 5);
|
||||
ClientReliableWrite_Float (host_client, host_client->entgravity);
|
||||
MSG_ReliableWrite_Begin (&host_client->backbuf, svc_entgravity, 5);
|
||||
MSG_ReliableWrite_Float (&host_client->backbuf,
|
||||
host_client->entgravity);
|
||||
if (sv.demorecording) {
|
||||
DemoWrite_Begin (dem_single, i, 5);
|
||||
MSG_WriteByte (&demo.dbuf->sz, svc_entgravity);
|
||||
|
@ -698,8 +700,9 @@ SV_UpdateToReliableMessages (void)
|
|||
if (sv_fields.maxspeed != -1
|
||||
&& host_client->maxspeed != SVfloat (ent, maxspeed)) {
|
||||
host_client->maxspeed = SVfloat (ent, maxspeed);
|
||||
ClientReliableWrite_Begin (host_client, svc_maxspeed, 5);
|
||||
ClientReliableWrite_Float (host_client, host_client->maxspeed);
|
||||
MSG_ReliableWrite_Begin (&host_client->backbuf, svc_maxspeed, 5);
|
||||
MSG_ReliableWrite_Float (&host_client->backbuf,
|
||||
host_client->maxspeed);
|
||||
if (sv.demorecording) {
|
||||
DemoWrite_Begin (dem_single, i, 5);
|
||||
MSG_WriteByte (&demo.dbuf->sz, svc_maxspeed);
|
||||
|
@ -716,8 +719,9 @@ SV_UpdateToReliableMessages (void)
|
|||
if (client->state < cs_connected)
|
||||
continue; // reliables go to all connected or spawned
|
||||
|
||||
ClientReliableCheckBlock (client, sv.reliable_datagram.cursize);
|
||||
ClientReliableWrite_SZ (client, sv.reliable_datagram.data,
|
||||
MSG_ReliableCheckBlock (&client->backbuf,
|
||||
sv.reliable_datagram.cursize);
|
||||
MSG_ReliableWrite_SZ (&client->backbuf, sv.reliable_datagram.data,
|
||||
sv.reliable_datagram.cursize);
|
||||
|
||||
if (client->state != cs_spawned)
|
||||
|
@ -745,7 +749,7 @@ void
|
|||
SV_SendClientMessages (void)
|
||||
{
|
||||
client_t *c;
|
||||
int i, j;
|
||||
int i;
|
||||
|
||||
// update frags, names, etc
|
||||
SV_UpdateToReliableMessages ();
|
||||
|
@ -761,38 +765,14 @@ SV_SendClientMessages (void)
|
|||
c->drop = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
// check to see if we have a backbuf to stick in the reliable
|
||||
if (c->num_backbuf) {
|
||||
// will it fit?
|
||||
if (c->netchan.message.cursize + c->backbuf_size[0] <
|
||||
c->netchan.message.maxsize) {
|
||||
if (c->backbuf.num_backbuf)
|
||||
MSG_Reliable_Send (&c->backbuf);
|
||||
|
||||
Con_DPrintf ("%s: backbuf %d bytes\n",
|
||||
c->name, c->backbuf_size[0]);
|
||||
|
||||
// it'll fit
|
||||
SZ_Write (&c->netchan.message, c->backbuf_data[0],
|
||||
c->backbuf_size[0]);
|
||||
|
||||
// move along, move along
|
||||
for (j = 1; j < c->num_backbuf; j++) {
|
||||
memcpy (c->backbuf_data[j - 1], c->backbuf_data[j],
|
||||
c->backbuf_size[j]);
|
||||
c->backbuf_size[j - 1] = c->backbuf_size[j];
|
||||
}
|
||||
|
||||
c->num_backbuf--;
|
||||
if (c->num_backbuf) {
|
||||
memset (&c->backbuf, 0, sizeof (c->backbuf));
|
||||
c->backbuf.data = c->backbuf_data[c->num_backbuf - 1];
|
||||
c->backbuf.cursize = c->backbuf_size[c->num_backbuf - 1];
|
||||
c->backbuf.maxsize =
|
||||
sizeof (c->backbuf_data[c->num_backbuf - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if the reliable message overflowed, drop the client
|
||||
if (c->netchan.message.overflowed) {
|
||||
#if 0
|
||||
int i;
|
||||
|
||||
Analyze_Server_Packet (c->netchan.message.data,
|
||||
|
@ -802,7 +782,7 @@ SV_SendClientMessages (void)
|
|||
Analyze_Server_Packet (c->backbuf_data[i],
|
||||
c->backbuf_size[i], 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
SZ_Clear (&c->netchan.message);
|
||||
SZ_Clear (&c->datagram);
|
||||
SV_BroadcastPrintf (PRINT_HIGH, "%s overflowed\n", c->name);
|
||||
|
|
|
@ -126,12 +126,12 @@ SV_New_f (void *unused)
|
|||
if (!gamedir[0])
|
||||
gamedir = "qw";
|
||||
|
||||
// NOTE: This doesn't go through ClientReliableWrite since it's before the
|
||||
// NOTE: This doesn't go through MSG_ReliableWrite since it's before the
|
||||
// user spawns. These functions are written to not overflow
|
||||
if (host_client->num_backbuf) {
|
||||
if (host_client->backbuf.num_backbuf) {
|
||||
SV_Printf ("WARNING %s: [SV_New] Back buffered (%d0, clearing\n",
|
||||
host_client->name, host_client->netchan.message.cursize);
|
||||
host_client->num_backbuf = 0;
|
||||
host_client->backbuf.num_backbuf = 0;
|
||||
SZ_Clear (&host_client->netchan.message);
|
||||
}
|
||||
// send the serverdata
|
||||
|
@ -201,12 +201,12 @@ SV_Soundlist_f (void *unused)
|
|||
SV_New_f (0);
|
||||
return;
|
||||
}
|
||||
// NOTE: This doesn't go through ClientReliableWrite since it's before the
|
||||
// NOTE: This doesn't go through MSG_ReliableWrite since it's before the
|
||||
// user spawns. These functions are written to not overflow
|
||||
if (host_client->num_backbuf) {
|
||||
if (host_client->backbuf.num_backbuf) {
|
||||
SV_Printf ("WARNING %s: [SV_Soundlist] Back buffered (%d0, clearing",
|
||||
host_client->name, host_client->netchan.message.cursize);
|
||||
host_client->num_backbuf = 0;
|
||||
host_client->backbuf.num_backbuf = 0;
|
||||
SZ_Clear (&host_client->netchan.message);
|
||||
}
|
||||
|
||||
|
@ -248,12 +248,12 @@ SV_Modellist_f (void *unused)
|
|||
SV_New_f (0);
|
||||
return;
|
||||
}
|
||||
// NOTE: This doesn't go through ClientReliableWrite since it's before the
|
||||
// NOTE: This doesn't go through MSG_ReliableWrite since it's before the
|
||||
// user spawns. These functions are written to not overflow
|
||||
if (host_client->num_backbuf) {
|
||||
if (host_client->backbuf.num_backbuf) {
|
||||
SV_Printf ("WARNING %s: [SV_Modellist] Back buffered (%d0, clearing",
|
||||
host_client->name, host_client->netchan.message.cursize);
|
||||
host_client->num_backbuf = 0;
|
||||
host_client->backbuf.num_backbuf = 0;
|
||||
SZ_Clear (&host_client->netchan.message);
|
||||
}
|
||||
|
||||
|
@ -323,9 +323,9 @@ SV_PreSpawn_f (void *unused)
|
|||
|
||||
size = sv.signon_buffer_size[buf] + 1 + strlen (command) + 1;
|
||||
|
||||
ClientReliableCheckBlock (host_client, size);
|
||||
if (host_client->num_backbuf)
|
||||
msg = &host_client->backbuf;
|
||||
MSG_ReliableCheckBlock (&host_client->backbuf, size);
|
||||
if (host_client->backbuf.num_backbuf)
|
||||
msg = &host_client->backbuf.backbuf;
|
||||
else
|
||||
msg = &host_client->netchan.message;
|
||||
|
||||
|
@ -403,11 +403,11 @@ SV_Spawn_f (void *unused)
|
|||
|
||||
// send all current light styles
|
||||
for (i = 0; i < MAX_LIGHTSTYLES; i++) {
|
||||
ClientReliableWrite_Begin (host_client, svc_lightstyle,
|
||||
3 + (sv.lightstyles[i] ?
|
||||
strlen (sv.lightstyles[i]) : 1));
|
||||
ClientReliableWrite_Byte (host_client, (char) i);
|
||||
ClientReliableWrite_String (host_client, sv.lightstyles[i]);
|
||||
MSG_ReliableWrite_Begin (&host_client->backbuf, svc_lightstyle,
|
||||
3 + (sv.lightstyles[i] ?
|
||||
strlen (sv.lightstyles[i]) : 1));
|
||||
MSG_ReliableWrite_Byte (&host_client->backbuf, (char) i);
|
||||
MSG_ReliableWrite_String (&host_client->backbuf, sv.lightstyles[i]);
|
||||
}
|
||||
|
||||
SV_Spawn (host_client);
|
||||
|
@ -417,26 +417,28 @@ SV_Spawn_f (void *unused)
|
|||
//
|
||||
memset (host_client->stats, 0, sizeof (host_client->stats));
|
||||
|
||||
ClientReliableWrite_Begin (host_client, svc_updatestatlong, 6);
|
||||
ClientReliableWrite_Byte (host_client, STAT_TOTALSECRETS);
|
||||
ClientReliableWrite_Long (host_client, *sv_globals.total_secrets);
|
||||
MSG_ReliableWrite_Begin (&host_client->backbuf, svc_updatestatlong, 6);
|
||||
MSG_ReliableWrite_Byte (&host_client->backbuf, STAT_TOTALSECRETS);
|
||||
MSG_ReliableWrite_Long (&host_client->backbuf, *sv_globals.total_secrets);
|
||||
|
||||
ClientReliableWrite_Begin (host_client, svc_updatestatlong, 6);
|
||||
ClientReliableWrite_Byte (host_client, STAT_TOTALMONSTERS);
|
||||
ClientReliableWrite_Long (host_client, *sv_globals.total_monsters);
|
||||
MSG_ReliableWrite_Begin (&host_client->backbuf, svc_updatestatlong, 6);
|
||||
MSG_ReliableWrite_Byte (&host_client->backbuf, STAT_TOTALMONSTERS);
|
||||
MSG_ReliableWrite_Long (&host_client->backbuf,
|
||||
*sv_globals.total_monsters);
|
||||
|
||||
ClientReliableWrite_Begin (host_client, svc_updatestatlong, 6);
|
||||
ClientReliableWrite_Byte (host_client, STAT_SECRETS);
|
||||
ClientReliableWrite_Long (host_client, *sv_globals.found_secrets);
|
||||
MSG_ReliableWrite_Begin (&host_client->backbuf, svc_updatestatlong, 6);
|
||||
MSG_ReliableWrite_Byte (&host_client->backbuf, STAT_SECRETS);
|
||||
MSG_ReliableWrite_Long (&host_client->backbuf, *sv_globals.found_secrets);
|
||||
|
||||
ClientReliableWrite_Begin (host_client, svc_updatestatlong, 6);
|
||||
ClientReliableWrite_Byte (host_client, STAT_MONSTERS);
|
||||
ClientReliableWrite_Long (host_client, *sv_globals.killed_monsters);
|
||||
MSG_ReliableWrite_Begin (&host_client->backbuf, svc_updatestatlong, 6);
|
||||
MSG_ReliableWrite_Byte (&host_client->backbuf, STAT_MONSTERS);
|
||||
MSG_ReliableWrite_Long (&host_client->backbuf,
|
||||
*sv_globals.killed_monsters);
|
||||
|
||||
// get the client to check and download skins
|
||||
// when that is completed, a begin command will be issued
|
||||
ClientReliableWrite_Begin (host_client, svc_stufftext, 8);
|
||||
ClientReliableWrite_String (host_client, "skins\n");
|
||||
MSG_ReliableWrite_Begin (&host_client->backbuf, svc_stufftext, 8);
|
||||
MSG_ReliableWrite_String (&host_client->backbuf, "skins\n");
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -537,8 +539,8 @@ SV_Begin_f (void *unused)
|
|||
|
||||
// if we are paused, tell the client
|
||||
if (sv.paused) {
|
||||
ClientReliableWrite_Begin (host_client, svc_setpause, 2);
|
||||
ClientReliableWrite_Byte (host_client, sv.paused);
|
||||
MSG_ReliableWrite_Begin (&host_client->backbuf, svc_setpause, 2);
|
||||
MSG_ReliableWrite_Byte (&host_client->backbuf, sv.paused);
|
||||
SV_ClientPrintf (1, host_client, PRINT_HIGH, "Server is paused.\n");
|
||||
}
|
||||
#if 0
|
||||
|
@ -576,16 +578,16 @@ SV_NextDownload_f (void *unused)
|
|||
if (r > sizeof (buffer))
|
||||
r = sizeof (buffer);
|
||||
r = Qread (host_client->download, buffer, r);
|
||||
ClientReliableWrite_Begin (host_client, svc_download, 6 + r);
|
||||
ClientReliableWrite_Short (host_client, r);
|
||||
MSG_ReliableWrite_Begin (&host_client->backbuf, svc_download, 6 + r);
|
||||
MSG_ReliableWrite_Short (&host_client->backbuf, r);
|
||||
|
||||
host_client->downloadcount += r;
|
||||
size = host_client->downloadsize;
|
||||
if (!size)
|
||||
size = 1;
|
||||
percent = host_client->downloadcount * 100 / size;
|
||||
ClientReliableWrite_Byte (host_client, percent);
|
||||
ClientReliableWrite_SZ (host_client, buffer, r);
|
||||
MSG_ReliableWrite_Byte (&host_client->backbuf, percent);
|
||||
MSG_ReliableWrite_SZ (&host_client->backbuf, buffer, r);
|
||||
|
||||
if (host_client->downloadcount != host_client->downloadsize)
|
||||
return;
|
||||
|
@ -602,8 +604,8 @@ SV_NextUpload (void)
|
|||
|
||||
if (!host_client->uploadfn) {
|
||||
SV_ClientPrintf (1, host_client, PRINT_HIGH, "Upload denied\n");
|
||||
ClientReliableWrite_Begin (host_client, svc_stufftext, 8);
|
||||
ClientReliableWrite_String (host_client, "stopul");
|
||||
MSG_ReliableWrite_Begin (&host_client->backbuf, svc_stufftext, 8);
|
||||
MSG_ReliableWrite_String (&host_client->backbuf, "stopul");
|
||||
|
||||
// suck out rest of packet
|
||||
size = MSG_ReadShort (net_message);
|
||||
|
@ -619,8 +621,8 @@ SV_NextUpload (void)
|
|||
host_client->upload = QFS_Open (host_client->uploadfn->str, "wb");
|
||||
if (!host_client->upload) {
|
||||
SV_Printf ("Can't create %s\n", host_client->uploadfn->str);
|
||||
ClientReliableWrite_Begin (host_client, svc_stufftext, 8);
|
||||
ClientReliableWrite_String (host_client, "stopul");
|
||||
MSG_ReliableWrite_Begin (&host_client->backbuf, svc_stufftext, 8);
|
||||
MSG_ReliableWrite_String (&host_client->backbuf, "stopul");
|
||||
dstring_delete (host_client->uploadfn);
|
||||
host_client->uploadfn = 0;
|
||||
return;
|
||||
|
@ -640,8 +642,8 @@ SV_NextUpload (void)
|
|||
Con_DPrintf ("UPLOAD: %d received\n", size);
|
||||
|
||||
if (percent != 100) {
|
||||
ClientReliableWrite_Begin (host_client, svc_stufftext, 8);
|
||||
ClientReliableWrite_String (host_client, "nextul\n");
|
||||
MSG_ReliableWrite_Begin (&host_client->backbuf, svc_stufftext, 8);
|
||||
MSG_ReliableWrite_String (&host_client->backbuf, "nextul\n");
|
||||
} else {
|
||||
Qclose (host_client->upload);
|
||||
host_client->upload = NULL;
|
||||
|
@ -691,9 +693,9 @@ SV_BeginDownload_f (void *unused)
|
|||
|| (strncmp (name, "maps/", 5) == 0 && !allow_download_maps->int_val)
|
||||
// MUST be in a subdirectory
|
||||
|| !strstr (name, "/")) { // don't allow anything with .. path
|
||||
ClientReliableWrite_Begin (host_client, svc_download, 4);
|
||||
ClientReliableWrite_Short (host_client, -1);
|
||||
ClientReliableWrite_Byte (host_client, 0);
|
||||
MSG_ReliableWrite_Begin (&host_client->backbuf, svc_download, 4);
|
||||
MSG_ReliableWrite_Short (&host_client->backbuf, -1);
|
||||
MSG_ReliableWrite_Byte (&host_client->backbuf, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -721,21 +723,21 @@ SV_BeginDownload_f (void *unused)
|
|||
}
|
||||
|
||||
SV_Printf ("Couldn't download %s to %s\n", name, host_client->name);
|
||||
ClientReliableWrite_Begin (host_client, svc_download, 4);
|
||||
ClientReliableWrite_Short (host_client, -1);
|
||||
ClientReliableWrite_Byte (host_client, 0);
|
||||
MSG_ReliableWrite_Begin (&host_client->backbuf, svc_download, 4);
|
||||
MSG_ReliableWrite_Short (&host_client->backbuf, -1);
|
||||
MSG_ReliableWrite_Byte (&host_client->backbuf, 0);
|
||||
dstring_delete (realname);
|
||||
return;
|
||||
}
|
||||
|
||||
if (zip && strcmp (realname->str, name)) {
|
||||
SV_Printf ("download renamed to %s\n", realname->str);
|
||||
ClientReliableWrite_Begin (host_client, svc_download,
|
||||
strlen (realname->str) + 5);
|
||||
ClientReliableWrite_Short (host_client, -2);
|
||||
ClientReliableWrite_Byte (host_client, 0);
|
||||
ClientReliableWrite_String (host_client, realname->str);
|
||||
ClientReliable_FinishWrite (host_client);
|
||||
MSG_ReliableWrite_Begin (&host_client->backbuf, svc_download,
|
||||
strlen (realname->str) + 5);
|
||||
MSG_ReliableWrite_Short (&host_client->backbuf, -2);
|
||||
MSG_ReliableWrite_Byte (&host_client->backbuf, 0);
|
||||
MSG_ReliableWrite_String (&host_client->backbuf, realname->str);
|
||||
MSG_Reliable_FinishWrite (&host_client->backbuf);
|
||||
}
|
||||
dstring_delete (realname);
|
||||
|
||||
|
@ -913,12 +915,12 @@ SV_Pings_f (void *unused)
|
|||
if (client->state != cs_spawned && client->state != cs_server)
|
||||
continue;
|
||||
|
||||
ClientReliableWrite_Begin (host_client, svc_updateping, 4);
|
||||
ClientReliableWrite_Byte (host_client, j);
|
||||
ClientReliableWrite_Short (host_client, SV_CalcPing (client));
|
||||
ClientReliableWrite_Begin (host_client, svc_updatepl, 4);
|
||||
ClientReliableWrite_Byte (host_client, j);
|
||||
ClientReliableWrite_Byte (host_client, client->lossage);
|
||||
MSG_ReliableWrite_Begin (&host_client->backbuf, svc_updateping, 4);
|
||||
MSG_ReliableWrite_Byte (&host_client->backbuf, j);
|
||||
MSG_ReliableWrite_Short (&host_client->backbuf, SV_CalcPing (client));
|
||||
MSG_ReliableWrite_Begin (&host_client->backbuf, svc_updatepl, 4);
|
||||
MSG_ReliableWrite_Byte (&host_client->backbuf, j);
|
||||
MSG_ReliableWrite_Byte (&host_client->backbuf, client->lossage);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -954,8 +956,8 @@ SV_TogglePause (const char *msg)
|
|||
for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) {
|
||||
if (cl->state < cs_zombie)
|
||||
continue;
|
||||
ClientReliableWrite_Begin (cl, svc_setpause, 2);
|
||||
ClientReliableWrite_Byte (cl, sv.paused);
|
||||
MSG_ReliableWrite_Begin (&cl->backbuf, svc_setpause, 2);
|
||||
MSG_ReliableWrite_Byte (&cl->backbuf, sv.paused);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue