2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
sv_send.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
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
2001-08-28 02:43:24 +00:00
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2001-05-31 03:41:35 +00:00
|
|
|
#include "QF/cvar.h"
|
2007-11-07 08:19:17 +00:00
|
|
|
#include "QF/console.h"
|
2003-11-21 06:09:21 +00:00
|
|
|
#include "QF/dstring.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/msg.h"
|
2021-07-26 02:15:51 +00:00
|
|
|
#include "QF/set.h"
|
2001-08-28 02:43:24 +00:00
|
|
|
#include "QF/sys.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-28 02:43:24 +00:00
|
|
|
#include "compat.h"
|
2020-06-21 14:15:17 +00:00
|
|
|
|
|
|
|
#include "qw/bothdefs.h"
|
|
|
|
#include "qw/include/server.h"
|
|
|
|
#include "qw/include/sv_progs.h"
|
|
|
|
#include "qw/include/sv_recorder.h"
|
2001-05-31 03:41:35 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#define CHAN_AUTO 0
|
|
|
|
#define CHAN_WEAPON 1
|
|
|
|
#define CHAN_VOICE 2
|
|
|
|
#define CHAN_ITEM 3
|
|
|
|
#define CHAN_BODY 4
|
|
|
|
|
2001-08-28 02:43:24 +00:00
|
|
|
/* SV_Printf redirection */
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2003-12-22 23:40:20 +00:00
|
|
|
dstring_t outputbuf = {&dstring_default_mem};
|
2001-02-19 21:15:25 +00:00
|
|
|
int con_printf_no_log;
|
2001-08-28 02:43:24 +00:00
|
|
|
redirect_t sv_redirected;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_FlushRedirect (void)
|
|
|
|
{
|
|
|
|
char send[8000 + 6];
|
2004-07-13 19:14:01 +00:00
|
|
|
size_t count;
|
2003-11-21 06:09:21 +00:00
|
|
|
int bytes;
|
|
|
|
const char *p;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2003-11-21 06:09:21 +00:00
|
|
|
if (!outputbuf.size)
|
|
|
|
return;
|
|
|
|
|
|
|
|
count = strlen (outputbuf.str);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (sv_redirected == RD_PACKET) {
|
2003-11-21 06:09:21 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
send[0] = 0xff;
|
|
|
|
send[1] = 0xff;
|
|
|
|
send[2] = 0xff;
|
|
|
|
send[3] = 0xff;
|
|
|
|
send[4] = A2C_PRINT;
|
2003-11-21 06:09:21 +00:00
|
|
|
|
|
|
|
p = outputbuf.str;
|
|
|
|
while (count) {
|
|
|
|
bytes = min (count, sizeof (send) - 5);
|
|
|
|
memcpy (send + 5, p, bytes);
|
2003-11-25 03:22:51 +00:00
|
|
|
Netchan_SendPacket (bytes + 5, send, net_from);
|
2003-11-21 06:09:21 +00:00
|
|
|
p += bytes;
|
|
|
|
count -= bytes;
|
|
|
|
}
|
|
|
|
} else if (sv_redirected == RD_CLIENT || sv_redirected > RD_MOD) {
|
|
|
|
client_t *cl;
|
|
|
|
|
|
|
|
if (sv_redirected > RD_MOD) {
|
|
|
|
cl = svs.clients + sv_redirected - RD_MOD - 1;
|
2004-04-06 22:02:45 +00:00
|
|
|
if (cl->state != cs_spawned) //FIXME record to mvd?
|
2003-11-21 06:09:21 +00:00
|
|
|
count = 0;
|
|
|
|
} else {
|
|
|
|
cl = host_client;
|
|
|
|
}
|
|
|
|
p = outputbuf.str;
|
|
|
|
while (count) {
|
|
|
|
// +/- 3 for svc_print, PRINT_HIGH and nul byte
|
|
|
|
// min of 4 because we don't want to send an effectively empty
|
|
|
|
// message
|
2004-02-22 05:40:08 +00:00
|
|
|
bytes = MSG_ReliableCheckSize (&cl->backbuf, count + 3, 4) - 3;
|
2003-11-21 06:09:21 +00:00
|
|
|
// if writing another packet would overflow the client, just drop
|
|
|
|
// the rest of the data. getting rudely disconnected would be much
|
|
|
|
// more annoying than losing the tail end of the output
|
|
|
|
if (bytes <= 0)
|
|
|
|
break;
|
2004-02-22 05:40:08 +00:00
|
|
|
MSG_ReliableWrite_Begin (&cl->backbuf, svc_print, bytes + 3);
|
|
|
|
MSG_ReliableWrite_Byte (&cl->backbuf, PRINT_HIGH);
|
|
|
|
MSG_ReliableWrite_SZ (&cl->backbuf, p, bytes);
|
|
|
|
MSG_ReliableWrite_Byte (&cl->backbuf, 0);
|
2003-11-21 06:09:21 +00:00
|
|
|
p += bytes;
|
|
|
|
count -= bytes;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2003-11-21 06:09:21 +00:00
|
|
|
// RD_MOD doesn't do anything :)
|
2001-02-19 21:15:25 +00:00
|
|
|
// clear it
|
2003-11-21 06:09:21 +00:00
|
|
|
dstring_clear (&outputbuf);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
SV_BeginRedirect
|
|
|
|
|
2001-07-11 23:11:29 +00:00
|
|
|
Send SV_Printf data to the remote client
|
2001-02-19 21:15:25 +00:00
|
|
|
instead of the console
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
SV_BeginRedirect (redirect_t rd)
|
|
|
|
{
|
|
|
|
sv_redirected = rd;
|
2003-11-21 06:09:21 +00:00
|
|
|
dstring_clear (&outputbuf);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SV_EndRedirect (void)
|
|
|
|
{
|
|
|
|
SV_FlushRedirect ();
|
|
|
|
sv_redirected = RD_NONE;
|
|
|
|
}
|
|
|
|
|
2001-08-28 02:43:24 +00:00
|
|
|
#define MAXPRINTMSG 4096
|
2018-08-19 15:05:00 +00:00
|
|
|
static int
|
|
|
|
find_userid (const char *name)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_CLIENTS; i++) {
|
|
|
|
if (!svs.clients[i].state)
|
|
|
|
continue;
|
|
|
|
if (!strcmp (svs.clients[i].name, name)) {
|
|
|
|
return svs.clients[i].userid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-03-29 08:27:06 +00:00
|
|
|
#define hstrftime ((size_t (*)(char *s, size_t, const char *, \
|
|
|
|
const struct tm*))strftime)
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
/*
|
2001-07-11 23:11:29 +00:00
|
|
|
SV_Printf
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Handles cursor positioning, line wrapping, etc
|
|
|
|
*/
|
2001-09-26 22:26:31 +00:00
|
|
|
// FIXME: the msg variables need to be renamed/cleaned up
|
2001-02-19 21:15:25 +00:00
|
|
|
void
|
2001-09-21 04:22:46 +00:00
|
|
|
SV_Print (const char *fmt, va_list args)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2018-08-19 15:05:00 +00:00
|
|
|
static dstring_t *premsg;
|
|
|
|
static dstring_t *msg;
|
|
|
|
static dstring_t *msg2;
|
2001-02-19 21:15:25 +00:00
|
|
|
static int pending = 0; // partial line being printed
|
2018-08-19 15:05:00 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
char msg3[MAXPRINTMSG];
|
|
|
|
|
|
|
|
time_t mytime = 0;
|
|
|
|
struct tm *local = NULL;
|
2023-06-13 09:06:11 +00:00
|
|
|
bool timestamps = false;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2005-06-08 06:35:48 +00:00
|
|
|
char *in;
|
2001-09-26 22:26:31 +00:00
|
|
|
|
2018-08-19 15:05:00 +00:00
|
|
|
if (!premsg) {
|
|
|
|
premsg = dstring_newstr ();
|
|
|
|
msg = dstring_new ();
|
|
|
|
msg2 = dstring_new ();
|
|
|
|
}
|
|
|
|
dstring_clearstr (msg);
|
|
|
|
|
|
|
|
dvsprintf (premsg, fmt, args);
|
|
|
|
in = premsg->str;
|
2001-09-26 22:26:31 +00:00
|
|
|
|
2018-08-19 15:05:00 +00:00
|
|
|
if (!*premsg->str)
|
2011-09-05 11:51:10 +00:00
|
|
|
return;
|
2001-09-26 22:26:31 +00:00
|
|
|
// expand FFnickFF to nick <userid>
|
|
|
|
do {
|
2018-08-19 15:05:00 +00:00
|
|
|
char *beg = strchr (in, 0xFF);
|
|
|
|
if (beg) {
|
|
|
|
char *name = beg + 1;
|
|
|
|
char *end = strchr (name, 0xFF);
|
|
|
|
if (!end) {
|
|
|
|
end = beg + strlen (name);
|
2001-09-26 22:26:31 +00:00
|
|
|
}
|
2018-08-19 15:05:00 +00:00
|
|
|
*end = 0;
|
|
|
|
dstring_appendsubstr (msg, in, beg - in);
|
|
|
|
dasprintf (msg, "%s <%d>", name, find_userid (name));
|
|
|
|
in = end + 1;
|
|
|
|
} else {
|
|
|
|
dstring_appendstr (msg, in);
|
|
|
|
break;
|
2001-09-26 22:26:31 +00:00
|
|
|
}
|
2018-08-19 15:05:00 +00:00
|
|
|
} while (*in);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (sv_redirected) { // Add to redirected message
|
2018-08-19 15:05:00 +00:00
|
|
|
dstring_appendstr (&outputbuf, msg->str);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2018-08-19 15:05:00 +00:00
|
|
|
if (*msg->str && !con_printf_no_log) {
|
2001-02-19 21:15:25 +00:00
|
|
|
// We want to output to console and maybe logfile
|
[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
|
|
|
if (sv_timefmt && sv_timestamps && !pending)
|
2001-02-19 21:15:25 +00:00
|
|
|
timestamps = true;
|
|
|
|
|
|
|
|
if (timestamps) {
|
|
|
|
mytime = time (NULL);
|
|
|
|
local = localtime (&mytime);
|
[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
|
|
|
hstrftime (msg3, sizeof (msg3), sv_timefmt, local);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2018-08-19 15:05:00 +00:00
|
|
|
dsprintf (msg2, "%s%s", msg3, msg->str);
|
2001-02-19 21:15:25 +00:00
|
|
|
} else {
|
2018-08-19 15:05:00 +00:00
|
|
|
dsprintf (msg2, "%s", msg->str);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2018-08-19 15:05:00 +00:00
|
|
|
if (msg2->str[strlen (msg2->str) - 1] != '\n') {
|
2001-02-19 21:15:25 +00:00
|
|
|
pending = 1;
|
|
|
|
} else {
|
|
|
|
pending = 0;
|
|
|
|
}
|
|
|
|
|
2018-08-19 15:05:00 +00:00
|
|
|
Con_Printf ("%s", msg2->str); // also echo to debugging console
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-28 02:43:24 +00:00
|
|
|
/* EVENT MESSAGES */
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
static void
|
2001-07-15 07:04:17 +00:00
|
|
|
SV_PrintToClient (client_t *cl, int level, const char *string)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2005-06-08 06:35:48 +00:00
|
|
|
static char *buffer;
|
|
|
|
const char *a;
|
2001-09-26 22:26:31 +00:00
|
|
|
unsigned char *b;
|
|
|
|
int size;
|
|
|
|
static int buffer_size;
|
|
|
|
|
|
|
|
size = strlen (string) + 1;
|
- fix a little mistake in SV_PrintToClient that'd cause it to
segfault if your first call was with "". Probably could cause
crashes too
- add a string.c file to libQFutil, with a Q_strcasestr function,
which strcasestr is defined to if it's not already defined. (we'd
get that with glibc if we defined __USE_GNU, but we don't)
- make client_t and SV_ExtractFromUserinfo both use NAME_MAX for
their name arrays, instead of 32 for one and 80 for the other
- rewrite almost all of SV_ExtractFromUserinfo's name handling.
- \r, \n, and \t are all converted to spaces
- leading/trailing spaces are stripped
- consecutive spaces are reduced to a single space
- empty names are considered bad
- user-* nicks are considered bad (unless forced to them)
- a name containing console or admin is considered bad
- a name that already exists is considered bad
- if they have a bad name it gets forced to user-%d, where %d is
their userid
- netname in the progs is now updated properly
- name changes are always reported unless it's the initial setting,
rather than only if they're full connected and not a spectator
- finally, if the name change fails (info string exceeded), give
them the boot. (before this was only done for duplicate names)
That's about it :)
2001-10-04 19:11:39 +00:00
|
|
|
if (size > buffer_size) {
|
2001-09-26 22:26:31 +00:00
|
|
|
buffer_size = (size + 1023) & ~1023; // 1k multiples
|
|
|
|
if (buffer)
|
|
|
|
free (buffer);
|
|
|
|
buffer = malloc (buffer_size);
|
|
|
|
if (!buffer)
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("SV_PrintToClient: could not allocate %d bytes",
|
2001-09-26 22:26:31 +00:00
|
|
|
buffer_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
a = string;
|
2005-06-08 06:35:48 +00:00
|
|
|
b = (byte *) buffer;
|
2001-09-26 22:26:31 +00:00
|
|
|
// strip 0xFFs
|
|
|
|
while ((*b = *a++))
|
|
|
|
if (*b != 0xFF)
|
|
|
|
b++;
|
|
|
|
|
2004-02-22 05:40:08 +00:00
|
|
|
MSG_ReliableWrite_Begin (&cl->backbuf, svc_print, strlen (buffer) + 3);
|
|
|
|
MSG_ReliableWrite_Byte (&cl->backbuf, level);
|
|
|
|
MSG_ReliableWrite_String (&cl->backbuf, buffer);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
SV_Multicast
|
|
|
|
|
|
|
|
Sends the contents of sv.multicast to a subset of the clients,
|
|
|
|
then clears sv.multicast.
|
|
|
|
|
|
|
|
MULTICAST_ALL same as broadcast
|
|
|
|
MULTICAST_PVS send to clients potentially visible from org
|
|
|
|
MULTICAST_PHS send to clients potentially hearable from org
|
|
|
|
*/
|
|
|
|
void
|
2002-01-03 05:29:38 +00:00
|
|
|
SV_Multicast (const vec3_t origin, int to)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2021-07-26 02:15:51 +00:00
|
|
|
set_t *mask;
|
2001-08-28 02:43:24 +00:00
|
|
|
client_t *client;
|
|
|
|
int leafnum, j;
|
2001-02-19 21:15:25 +00:00
|
|
|
mleaf_t *leaf;
|
2023-06-13 09:06:11 +00:00
|
|
|
bool reliable;
|
2021-02-01 10:31:11 +00:00
|
|
|
mod_brush_t *brush = &sv.worldmodel->brush;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2022-05-22 02:18:32 +00:00
|
|
|
vec4f_t org = { VectorExpand (origin), 1 };
|
2023-06-28 12:45:41 +00:00
|
|
|
leaf = Mod_PointInLeaf (org, &sv.worldmodel->brush);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!leaf)
|
|
|
|
leafnum = 0;
|
|
|
|
else
|
2021-02-01 10:31:11 +00:00
|
|
|
leafnum = leaf - sv.worldmodel->brush.leafs;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
reliable = false;
|
|
|
|
|
|
|
|
switch (to) {
|
2001-08-28 02:43:24 +00:00
|
|
|
case MULTICAST_ALL_R:
|
|
|
|
reliable = true; // intentional fallthrough
|
|
|
|
case MULTICAST_ALL:
|
2021-07-26 02:15:51 +00:00
|
|
|
mask = &sv.pvs[0]; // leaf 0 is everything;
|
2001-08-28 02:43:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MULTICAST_PHS_R:
|
|
|
|
reliable = true; // intentional fallthrough
|
|
|
|
case MULTICAST_PHS:
|
2021-07-26 02:15:51 +00:00
|
|
|
mask = &sv.phs[leafnum];
|
2001-08-28 02:43:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MULTICAST_PVS_R:
|
|
|
|
reliable = true; // intentional fallthrough
|
|
|
|
case MULTICAST_PVS:
|
2021-07-26 02:15:51 +00:00
|
|
|
mask = &sv.pvs[leafnum];
|
2001-08-28 02:43:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2002-02-20 19:22:52 +00:00
|
|
|
Sys_Error ("SV_Multicast: bad to:%i", to);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// send the data to all relevent clients
|
|
|
|
for (j = 0, client = svs.clients; j < MAX_CLIENTS; j++, client++) {
|
|
|
|
if (client->state != cs_spawned)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (to == MULTICAST_PHS_R || to == MULTICAST_PHS) {
|
|
|
|
vec3_t delta;
|
|
|
|
|
2001-08-08 20:28:53 +00:00
|
|
|
VectorSubtract (origin, SVvector (client->edict, origin), delta);
|
2002-08-20 02:22:40 +00:00
|
|
|
if (VectorLength (delta) <= 1024)
|
2001-02-19 21:15:25 +00:00
|
|
|
goto inrange;
|
|
|
|
}
|
|
|
|
|
2022-05-22 02:18:32 +00:00
|
|
|
org = (vec4f_t) {VectorExpand (SVvector (client->edict, origin)), 1};
|
2023-06-28 12:45:41 +00:00
|
|
|
leaf = Mod_PointInLeaf (org, &sv.worldmodel->brush);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (leaf) {
|
|
|
|
// -1 is because pvs rows are 1 based, not 0 based like leafs
|
2021-02-01 10:31:11 +00:00
|
|
|
leafnum = leaf - brush->leafs - 1;
|
2021-07-26 02:15:51 +00:00
|
|
|
if (!set_is_member (mask, leafnum)) {
|
2001-08-28 02:43:24 +00:00
|
|
|
// SV_Printf ("supressed multicast\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inrange:
|
|
|
|
if (reliable) {
|
2004-02-22 05:40:08 +00:00
|
|
|
MSG_ReliableCheckBlock (&client->backbuf, sv.multicast.cursize);
|
|
|
|
MSG_ReliableWrite_SZ (&client->backbuf, sv.multicast.data,
|
|
|
|
sv.multicast.cursize);
|
2001-02-19 21:15:25 +00:00
|
|
|
} else
|
|
|
|
SZ_Write (&client->datagram, sv.multicast.data,
|
|
|
|
sv.multicast.cursize);
|
|
|
|
}
|
|
|
|
|
2005-05-01 09:07:20 +00:00
|
|
|
if (sv.recorders) {
|
2002-10-04 02:29:03 +00:00
|
|
|
if (reliable) {
|
2005-05-01 09:07:20 +00:00
|
|
|
sizebuf_t *dbuf = SVR_WriteBegin (dem_all, 0,
|
|
|
|
sv.multicast.cursize);
|
|
|
|
SZ_Write (dbuf, sv.multicast.data, sv.multicast.cursize);
|
2002-10-04 02:29:03 +00:00
|
|
|
} else
|
2005-05-01 09:07:20 +00:00
|
|
|
SZ_Write (SVR_Datagram (), sv.multicast.data, sv.multicast.cursize);
|
2002-10-04 02:29:03 +00:00
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
SZ_Clear (&sv.multicast);
|
|
|
|
}
|
|
|
|
|
2012-05-21 23:23:22 +00:00
|
|
|
/*
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_StartSound
|
|
|
|
|
|
|
|
Each entity can have eight independant sound sources, like voice,
|
|
|
|
weapon, feet, etc.
|
|
|
|
|
|
|
|
Channel 0 is an auto-allocate channel, the others override anything
|
2001-02-21 23:45:49 +00:00
|
|
|
already running on that entity/channel pair.
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
An attenuation of 0 will play full volume everywhere in the level.
|
|
|
|
Larger attenuations will drop off. (max 4 attenuation)
|
|
|
|
*/
|
|
|
|
void
|
2001-11-07 08:24:56 +00:00
|
|
|
SV_StartSound (edict_t *entity, int channel, const char *sample, int volume,
|
|
|
|
float attenuation)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2011-06-19 01:48:02 +00:00
|
|
|
int ent, sound_num, i;
|
2023-06-13 09:06:11 +00:00
|
|
|
bool use_phs;
|
|
|
|
bool reliable = false;
|
2001-11-07 08:24:56 +00:00
|
|
|
vec3_t origin;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-11-07 08:24:56 +00:00
|
|
|
if (volume < 0 || volume > 255)
|
2002-02-20 19:22:52 +00:00
|
|
|
Sys_Error ("SV_StartSound: volume = %i", volume);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (attenuation < 0 || attenuation > 4)
|
2002-02-20 19:22:52 +00:00
|
|
|
Sys_Error ("SV_StartSound: attenuation = %f", attenuation);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (channel < 0 || channel > 15)
|
2002-02-20 19:22:52 +00:00
|
|
|
Sys_Error ("SV_StartSound: channel = %i", channel);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-28 02:43:24 +00:00
|
|
|
// find precache number for sound
|
2001-02-19 21:15:25 +00:00
|
|
|
for (sound_num = 1; sound_num < MAX_SOUNDS
|
|
|
|
&& sv.sound_precache[sound_num]; sound_num++)
|
|
|
|
if (!strcmp (sample, sv.sound_precache[sound_num]))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (sound_num == MAX_SOUNDS || !sv.sound_precache[sound_num]) {
|
2001-07-11 23:11:29 +00:00
|
|
|
SV_Printf ("SV_StartSound: %s not precacheed\n", sample);
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-11-07 08:24:56 +00:00
|
|
|
ent = NUM_FOR_EDICT (&sv_pr_state, entity);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if ((channel & 8) || !sv_phs) // no PHS flag
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
if (channel & 8)
|
|
|
|
reliable = true; // sounds that break the phs are
|
|
|
|
// reliable
|
|
|
|
use_phs = false;
|
|
|
|
channel &= 7;
|
|
|
|
} else
|
|
|
|
use_phs = true;
|
|
|
|
|
2001-08-28 02:43:24 +00:00
|
|
|
// if (channel == CHAN_BODY || channel == CHAN_VOICE)
|
|
|
|
// reliable = true;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-11-07 08:24:56 +00:00
|
|
|
channel = (ent << 3) | channel;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-11-07 08:24:56 +00:00
|
|
|
if (volume != DEFAULT_SOUND_PACKET_VOLUME)
|
|
|
|
channel |= SND_VOLUME;
|
|
|
|
if (attenuation != DEFAULT_SOUND_PACKET_ATTENUATION)
|
|
|
|
channel |= SND_ATTENUATION;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// use the entity origin unless it is a bmodel
|
2001-08-08 20:28:53 +00:00
|
|
|
if (SVfloat (entity, solid) == SOLID_BSP) {
|
2001-02-19 21:15:25 +00:00
|
|
|
for (i = 0; i < 3; i++)
|
2001-11-07 08:24:56 +00:00
|
|
|
origin[i] = SVvector (entity, origin)[i] + 0.5 *
|
2001-08-28 02:43:24 +00:00
|
|
|
(SVvector (entity, mins)[i] + SVvector (entity, maxs)[i]);
|
2001-02-19 21:15:25 +00:00
|
|
|
} else {
|
2001-11-07 08:24:56 +00:00
|
|
|
VectorCopy (SVvector (entity, origin), origin);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MSG_WriteByte (&sv.multicast, svc_sound);
|
2001-11-07 08:24:56 +00:00
|
|
|
MSG_WriteShort (&sv.multicast, channel);
|
|
|
|
if (channel & SND_VOLUME)
|
|
|
|
MSG_WriteByte (&sv.multicast, volume);
|
|
|
|
if (channel & SND_ATTENUATION)
|
|
|
|
MSG_WriteByte (&sv.multicast, attenuation * 64);
|
|
|
|
MSG_WriteByte (&sv.multicast, sound_num);
|
2001-12-12 21:56:09 +00:00
|
|
|
MSG_WriteCoordV (&sv.multicast, origin);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (use_phs)
|
2001-11-07 08:24:56 +00:00
|
|
|
SV_Multicast (origin, reliable ? MULTICAST_PHS_R : MULTICAST_PHS);
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2001-11-07 08:24:56 +00:00
|
|
|
SV_Multicast (origin, reliable ? MULTICAST_ALL_R : MULTICAST_ALL);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-08-28 02:43:24 +00:00
|
|
|
/* FRAME UPDATES */
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
int sv_nailmodel, sv_supernailmodel, sv_playermodel;
|
|
|
|
|
|
|
|
void
|
|
|
|
SV_FindModelNumbers (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
sv_nailmodel = -1;
|
|
|
|
sv_supernailmodel = -1;
|
|
|
|
sv_playermodel = -1;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_MODELS; i++) {
|
|
|
|
if (!sv.model_precache[i])
|
|
|
|
break;
|
|
|
|
if (!strcmp (sv.model_precache[i], "progs/spike.mdl"))
|
|
|
|
sv_nailmodel = i;
|
|
|
|
if (!strcmp (sv.model_precache[i], "progs/s_spike.mdl"))
|
|
|
|
sv_supernailmodel = i;
|
|
|
|
if (!strcmp (sv.model_precache[i], "progs/player.mdl"))
|
|
|
|
sv_playermodel = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SV_WriteClientdataToMessage (client_t *client, sizebuf_t *msg)
|
|
|
|
{
|
2001-08-28 02:43:24 +00:00
|
|
|
edict_t *ent, *other;
|
2002-10-04 02:29:03 +00:00
|
|
|
int i, clnum;
|
2005-05-01 09:07:20 +00:00
|
|
|
sizebuf_t *dbuf;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
ent = client->edict;
|
|
|
|
|
2002-10-04 02:29:03 +00:00
|
|
|
clnum = NUM_FOR_EDICT (&sv_pr_state, ent) - 1;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// send the chokecount for r_netgraph
|
|
|
|
if (client->chokecount) {
|
|
|
|
MSG_WriteByte (msg, svc_chokecount);
|
|
|
|
MSG_WriteByte (msg, client->chokecount);
|
|
|
|
client->chokecount = 0;
|
|
|
|
}
|
|
|
|
// send a damage message if the player got hit this frame
|
2001-08-08 20:28:53 +00:00
|
|
|
if (SVfloat (ent, dmg_take) || SVfloat (ent, dmg_save)) {
|
|
|
|
other = PROG_TO_EDICT (&sv_pr_state, SVentity (ent, dmg_inflictor));
|
2001-11-07 08:24:56 +00:00
|
|
|
MSG_WriteByte (msg, svc_damage);
|
|
|
|
MSG_WriteByte (msg, SVfloat (ent, dmg_save));
|
|
|
|
MSG_WriteByte (msg, SVfloat (ent, dmg_take));
|
2001-02-19 21:15:25 +00:00
|
|
|
for (i = 0; i < 3; i++)
|
2001-11-07 08:24:56 +00:00
|
|
|
MSG_WriteCoord (msg, SVvector (other, origin)[i] + 0.5 *
|
2001-08-28 02:43:24 +00:00
|
|
|
(SVvector (other, mins)[i] +
|
2001-11-07 08:24:56 +00:00
|
|
|
SVvector (other, maxs)[i]));
|
2001-08-08 20:28:53 +00:00
|
|
|
SVfloat (ent, dmg_take) = 0;
|
|
|
|
SVfloat (ent, dmg_save) = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2002-10-04 02:29:03 +00:00
|
|
|
|
|
|
|
// add this to server demo
|
2005-05-01 09:07:20 +00:00
|
|
|
if (sv.recorders && msg->cursize) {
|
|
|
|
dbuf = SVR_WriteBegin (dem_single, clnum, msg->cursize);
|
|
|
|
SZ_Write (dbuf, msg->data, msg->cursize);
|
2002-10-04 02:29:03 +00:00
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// a fixangle might get lost in a dropped packet. Oh well.
|
2001-08-08 20:28:53 +00:00
|
|
|
if (SVfloat (ent, fixangle)) {
|
2004-03-31 19:14:55 +00:00
|
|
|
vec_t *angles = SVvector (ent, angles);
|
2001-02-19 21:15:25 +00:00
|
|
|
MSG_WriteByte (msg, svc_setangle);
|
2004-03-31 19:14:55 +00:00
|
|
|
MSG_WriteAngleV (msg, angles);
|
2001-08-08 20:28:53 +00:00
|
|
|
SVfloat (ent, fixangle) = 0;
|
2002-10-04 02:29:03 +00:00
|
|
|
|
2005-05-01 09:07:20 +00:00
|
|
|
if (sv.recorders) {
|
|
|
|
dbuf = SVR_Datagram ();
|
|
|
|
MSG_WriteByte (dbuf, svc_setangle);
|
|
|
|
MSG_WriteByte (dbuf, clnum);
|
|
|
|
MSG_WriteAngleV (dbuf, angles);
|
2002-10-04 02:29:03 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-01 09:07:20 +00:00
|
|
|
void
|
|
|
|
SV_GetStats (edict_t *ent, int spectator, int stats[])
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-10-07 22:15:19 +00:00
|
|
|
memset (stats, 0, sizeof (int) * MAX_CL_STATS);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-08 20:28:53 +00:00
|
|
|
stats[STAT_HEALTH] = SVfloat (ent, health);
|
2002-10-07 22:15:19 +00:00
|
|
|
stats[STAT_WEAPON] = SV_ModelIndex (PR_GetString (&sv_pr_state,
|
|
|
|
SVstring (ent, weaponmodel)));
|
2001-08-08 20:28:53 +00:00
|
|
|
stats[STAT_AMMO] = SVfloat (ent, currentammo);
|
|
|
|
stats[STAT_ARMOR] = SVfloat (ent, armorvalue);
|
|
|
|
stats[STAT_SHELLS] = SVfloat (ent, ammo_shells);
|
|
|
|
stats[STAT_NAILS] = SVfloat (ent, ammo_nails);
|
|
|
|
stats[STAT_ROCKETS] = SVfloat (ent, ammo_rockets);
|
|
|
|
stats[STAT_CELLS] = SVfloat (ent, ammo_cells);
|
2002-10-07 22:15:19 +00:00
|
|
|
if (!spectator)
|
2001-08-08 20:28:53 +00:00
|
|
|
stats[STAT_ACTIVEWEAPON] = SVfloat (ent, weapon);
|
2001-02-19 21:15:25 +00:00
|
|
|
// stuff the sigil bits into the high bits of items for sbar
|
2002-10-07 22:15:19 +00:00
|
|
|
stats[STAT_ITEMS] = ((int) SVfloat (ent, items)
|
|
|
|
| ((int) *sv_globals.serverflags << 28));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// Extensions to the QW 2.40 protocol for Mega2k --KB
|
2001-08-08 20:28:53 +00:00
|
|
|
stats[STAT_VIEWHEIGHT] = (int) SVvector (ent, view_ofs)[2];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// FIXME: this should become a * key! --KB
|
2002-10-07 18:58:54 +00:00
|
|
|
if (SVfloat (ent, movetype) == MOVETYPE_FLY
|
|
|
|
&& !atoi (Info_ValueForKey (svs.info, "playerfly")))
|
2001-08-08 20:28:53 +00:00
|
|
|
SVfloat (ent, movetype) = MOVETYPE_WALK;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-08 20:28:53 +00:00
|
|
|
stats[STAT_FLYMODE] = (SVfloat (ent, movetype) == MOVETYPE_FLY);
|
2002-10-07 22:15:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
SV_UpdateClientStats
|
|
|
|
|
2010-01-13 06:42:26 +00:00
|
|
|
Performs a delta update of the stats array. This should be performed only
|
2002-10-07 22:15:19 +00:00
|
|
|
when a reliable message can be delivered this frame.
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-10-07 22:15:19 +00:00
|
|
|
SV_UpdateClientStats (client_t *client)
|
|
|
|
{
|
|
|
|
edict_t *ent;
|
|
|
|
int i;
|
|
|
|
int stats[MAX_CL_STATS];
|
|
|
|
|
|
|
|
ent = client->edict;
|
|
|
|
|
|
|
|
// if we are a spectator and we are tracking a player, we get his stats
|
|
|
|
// so our status bar reflects his
|
|
|
|
if (client->spectator && client->spec_track > 0)
|
|
|
|
ent = svs.clients[client->spec_track - 1].edict;
|
|
|
|
|
2005-05-01 09:07:20 +00:00
|
|
|
SV_GetStats (ent, client->spectator, stats);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_CL_STATS; i++)
|
|
|
|
if (stats[i] != client->stats[i]) {
|
|
|
|
client->stats[i] = stats[i];
|
|
|
|
if (stats[i] >= 0 && stats[i] <= 255) {
|
2004-02-22 05:40:08 +00:00
|
|
|
MSG_ReliableWrite_Begin (&client->backbuf, svc_updatestat, 3);
|
|
|
|
MSG_ReliableWrite_Byte (&client->backbuf, i);
|
|
|
|
MSG_ReliableWrite_Byte (&client->backbuf, stats[i]);
|
2001-02-19 21:15:25 +00:00
|
|
|
} else {
|
2004-02-22 05:40:08 +00:00
|
|
|
MSG_ReliableWrite_Begin (&client->backbuf,
|
|
|
|
svc_updatestatlong, 6);
|
|
|
|
MSG_ReliableWrite_Byte (&client->backbuf, i);
|
|
|
|
MSG_ReliableWrite_Long (&client->backbuf, stats[i]);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-13 09:06:11 +00:00
|
|
|
static bool
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_SendClientDatagram (client_t *client)
|
|
|
|
{
|
|
|
|
byte buf[MAX_DATAGRAM];
|
|
|
|
sizebuf_t msg;
|
|
|
|
|
|
|
|
msg.data = buf;
|
|
|
|
msg.maxsize = sizeof (buf);
|
|
|
|
msg.cursize = 0;
|
|
|
|
msg.allowoverflow = true;
|
|
|
|
msg.overflowed = false;
|
|
|
|
|
|
|
|
// add the client specific data to the datagram
|
|
|
|
SV_WriteClientdataToMessage (client, &msg);
|
|
|
|
|
2003-08-21 20:35:36 +00:00
|
|
|
if (client->state == cs_server)
|
|
|
|
return true;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// send over all the objects that are in the PVS
|
|
|
|
// this will include clients, a packetentities, and
|
|
|
|
// possibly a nails update
|
2005-04-30 08:45:17 +00:00
|
|
|
SV_WriteEntitiesToClient (&client->delta, &msg);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// copy the accumulated multicast datagram
|
|
|
|
// for this client out to the message
|
|
|
|
if (client->datagram.overflowed)
|
2001-07-11 23:11:29 +00:00
|
|
|
SV_Printf ("WARNING: datagram overflowed for %s\n", client->name);
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
|
|
|
SZ_Write (&msg, client->datagram.data, client->datagram.cursize);
|
|
|
|
SZ_Clear (&client->datagram);
|
|
|
|
|
|
|
|
// send deltas over reliable stream
|
|
|
|
if (Netchan_CanReliable (&client->netchan))
|
|
|
|
SV_UpdateClientStats (client);
|
|
|
|
|
|
|
|
if (msg.overflowed) {
|
2001-07-11 23:11:29 +00:00
|
|
|
SV_Printf ("WARNING: msg overflowed for %s\n", client->name);
|
2001-02-19 21:15:25 +00:00
|
|
|
SZ_Clear (&msg);
|
|
|
|
}
|
|
|
|
// send the datagram
|
2005-04-25 07:55:56 +00:00
|
|
|
Netchan_Transmit (&client->netchan, msg.cursize, msg.data);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_UpdateToReliableMessages (void)
|
|
|
|
{
|
|
|
|
client_t *client;
|
|
|
|
edict_t *ent;
|
2001-08-28 02:43:24 +00:00
|
|
|
int i, j;
|
2005-05-01 09:07:20 +00:00
|
|
|
sizebuf_t *dbuf;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-28 02:43:24 +00:00
|
|
|
// check for changes to be sent over the reliable streams to all clients
|
2001-02-19 21:15:25 +00:00
|
|
|
for (i = 0, host_client = svs.clients; i < MAX_CLIENTS; i++, host_client++) {
|
2003-03-05 03:56:50 +00:00
|
|
|
if (host_client->state != cs_spawned && host_client->state != cs_server)
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
|
|
|
if (host_client->sendinfo) {
|
|
|
|
host_client->sendinfo = false;
|
|
|
|
SV_FullClientUpdate (host_client, &sv.reliable_datagram);
|
|
|
|
}
|
2001-09-24 18:26:23 +00:00
|
|
|
if (host_client->old_frags != (int) SVfloat (host_client->edict, frags)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
for (j = 0, client = svs.clients; j < MAX_CLIENTS; j++, client++) {
|
|
|
|
if (client->state < cs_connected)
|
|
|
|
continue;
|
2004-02-22 05:40:08 +00:00
|
|
|
MSG_ReliableWrite_Begin (&client->backbuf, svc_updatefrags, 4);
|
|
|
|
MSG_ReliableWrite_Byte (&client->backbuf, i);
|
|
|
|
MSG_ReliableWrite_Short (&client->backbuf,
|
|
|
|
SVfloat (host_client->edict, frags));
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2005-05-01 09:07:20 +00:00
|
|
|
if (sv.recorders) {
|
|
|
|
dbuf = SVR_WriteBegin (dem_all, 0, 4);
|
|
|
|
MSG_WriteByte (dbuf, svc_updatefrags);
|
|
|
|
MSG_WriteByte (dbuf, i);
|
|
|
|
MSG_WriteShort (dbuf, SVfloat (host_client->edict, frags));
|
2002-10-04 02:29:03 +00:00
|
|
|
}
|
|
|
|
|
2001-08-08 20:28:53 +00:00
|
|
|
host_client->old_frags = SVfloat (host_client->edict, frags);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
// maxspeed/entgravity changes
|
|
|
|
ent = host_client->edict;
|
|
|
|
|
2002-02-25 07:44:17 +00:00
|
|
|
if (sv_fields.gravity != -1
|
|
|
|
&& host_client->entgravity != SVfloat (ent, gravity)) {
|
|
|
|
host_client->entgravity = SVfloat (ent, gravity);
|
2004-02-26 23:15:58 +00:00
|
|
|
if (host_client->state != cs_server) {
|
|
|
|
MSG_ReliableWrite_Begin (&host_client->backbuf,
|
|
|
|
svc_entgravity, 5);
|
|
|
|
MSG_ReliableWrite_Float (&host_client->backbuf,
|
|
|
|
host_client->entgravity);
|
|
|
|
}
|
2005-05-01 09:07:20 +00:00
|
|
|
if (sv.recorders) {
|
|
|
|
dbuf = SVR_WriteBegin (dem_single, i, 5);
|
|
|
|
MSG_WriteByte (dbuf, svc_entgravity);
|
|
|
|
MSG_WriteFloat (dbuf, host_client->entgravity);
|
2002-10-04 02:29:03 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2002-02-25 07:44:17 +00:00
|
|
|
if (sv_fields.maxspeed != -1
|
|
|
|
&& host_client->maxspeed != SVfloat (ent, maxspeed)) {
|
|
|
|
host_client->maxspeed = SVfloat (ent, maxspeed);
|
2004-02-26 23:15:58 +00:00
|
|
|
if (host_client->state != cs_server) {
|
|
|
|
MSG_ReliableWrite_Begin (&host_client->backbuf,
|
|
|
|
svc_maxspeed, 5);
|
|
|
|
MSG_ReliableWrite_Float (&host_client->backbuf,
|
|
|
|
host_client->maxspeed);
|
|
|
|
}
|
2005-05-01 09:07:20 +00:00
|
|
|
if (sv.recorders) {
|
|
|
|
dbuf = SVR_WriteBegin (dem_single, i, 5);
|
|
|
|
MSG_WriteByte (dbuf, svc_maxspeed);
|
|
|
|
MSG_WriteFloat (dbuf, host_client->maxspeed);
|
2002-10-04 02:29:03 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sv.datagram.overflowed)
|
|
|
|
SZ_Clear (&sv.datagram);
|
|
|
|
|
|
|
|
// append the broadcast messages to each client messages
|
|
|
|
for (j = 0, client = svs.clients; j < MAX_CLIENTS; j++, client++) {
|
|
|
|
if (client->state < cs_connected)
|
2002-10-04 02:29:03 +00:00
|
|
|
continue; // reliables go to all connected or spawned
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-02-22 05:40:08 +00:00
|
|
|
MSG_ReliableCheckBlock (&client->backbuf,
|
|
|
|
sv.reliable_datagram.cursize);
|
|
|
|
MSG_ReliableWrite_SZ (&client->backbuf, sv.reliable_datagram.data,
|
2001-02-19 21:15:25 +00:00
|
|
|
sv.reliable_datagram.cursize);
|
|
|
|
|
|
|
|
if (client->state != cs_spawned)
|
2010-01-13 06:42:26 +00:00
|
|
|
continue; // datagrams go to only spawned
|
2001-02-19 21:15:25 +00:00
|
|
|
SZ_Write (&client->datagram, sv.datagram.data, sv.datagram.cursize);
|
|
|
|
}
|
|
|
|
|
2005-05-01 09:07:20 +00:00
|
|
|
if (sv.recorders && sv.reliable_datagram.cursize) {
|
|
|
|
dbuf = SVR_WriteBegin (dem_all, 0, sv.reliable_datagram.cursize);
|
|
|
|
SZ_Write (dbuf, sv.reliable_datagram.data,
|
2002-10-04 02:29:03 +00:00
|
|
|
sv.reliable_datagram.cursize);
|
|
|
|
}
|
2005-05-01 09:07:20 +00:00
|
|
|
if (sv.recorders)
|
|
|
|
SZ_Write (SVR_Datagram (), sv.datagram.data, sv.datagram.cursize);
|
2002-10-04 02:29:03 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
SZ_Clear (&sv.reliable_datagram);
|
|
|
|
SZ_Clear (&sv.datagram);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(_WIN32) && !defined(__GNUC__)
|
2001-08-28 02:43:24 +00:00
|
|
|
# pragma optimize( "", off )
|
2001-02-19 21:15:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
SV_SendClientMessages (void)
|
|
|
|
{
|
|
|
|
client_t *c;
|
2004-02-22 05:40:08 +00:00
|
|
|
int i;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-28 02:43:24 +00:00
|
|
|
// update frags, names, etc
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_UpdateToReliableMessages ();
|
|
|
|
|
2001-08-28 02:43:24 +00:00
|
|
|
// build individual updates
|
2001-02-19 21:15:25 +00:00
|
|
|
for (i = 0, c = svs.clients; i < MAX_CLIENTS; i++, c++) {
|
2003-08-21 20:35:36 +00:00
|
|
|
if (c->state != cs_server) {
|
|
|
|
if (c->state < cs_zombie)
|
|
|
|
continue;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2003-08-21 20:35:36 +00:00
|
|
|
if (c->drop) {
|
|
|
|
SV_DropClient (c);
|
|
|
|
c->drop = false;
|
|
|
|
continue;
|
|
|
|
}
|
2004-02-22 05:40:08 +00:00
|
|
|
|
2003-08-21 20:35:36 +00:00
|
|
|
// check to see if we have a backbuf to stick in the reliable
|
2004-02-22 05:40:08 +00:00
|
|
|
if (c->backbuf.num_backbuf)
|
|
|
|
MSG_Reliable_Send (&c->backbuf);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2003-08-21 20:35:36 +00:00
|
|
|
// if the reliable message overflowed, drop the client
|
|
|
|
if (c->netchan.message.overflowed) {
|
|
|
|
SZ_Clear (&c->netchan.message);
|
|
|
|
SZ_Clear (&c->datagram);
|
|
|
|
SV_BroadcastPrintf (PRINT_HIGH, "%s overflowed\n", c->name);
|
|
|
|
SV_Printf ("WARNING: reliable overflow for %s\n", c->name);
|
|
|
|
SV_DropClient (c);
|
|
|
|
c->send_message = true;
|
|
|
|
c->netchan.cleartime = 0; // don't choke this message
|
|
|
|
}
|
2010-01-13 06:42:26 +00:00
|
|
|
// send messages only if the client has sent one
|
2003-08-21 20:35:36 +00:00
|
|
|
// and the bandwidth is not choked
|
|
|
|
if (!c->send_message)
|
|
|
|
continue;
|
|
|
|
c->send_message = false; // try putting this after choke?
|
|
|
|
if (!sv.paused && !Netchan_CanPacket (&c->netchan)) {
|
|
|
|
c->chokecount++;
|
|
|
|
continue; // bandwidth choke
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2003-08-21 20:35:36 +00:00
|
|
|
if (c->state == cs_spawned || c->state == cs_server)
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_SendClientDatagram (c);
|
|
|
|
else
|
|
|
|
Netchan_Transmit (&c->netchan, 0, NULL); // just update
|
|
|
|
// reliable
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(_WIN32) && !defined(__GNUC__)
|
2001-08-28 02:43:24 +00:00
|
|
|
# pragma optimize( "", on )
|
2001-02-19 21:15:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
SV_SendMessagesToAll
|
|
|
|
|
|
|
|
FIXME: does this sequence right?
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
SV_SendMessagesToAll (void)
|
|
|
|
{
|
|
|
|
client_t *c;
|
2001-08-28 02:43:24 +00:00
|
|
|
int i;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
for (i = 0, c = svs.clients; i < MAX_CLIENTS; i++, c++)
|
2010-01-13 06:42:26 +00:00
|
|
|
if (c->state < cs_zombie) // FIXME: should this send to only active?
|
2001-02-19 21:15:25 +00:00
|
|
|
c->send_message = true;
|
|
|
|
|
|
|
|
SV_SendClientMessages ();
|
|
|
|
}
|
2003-05-07 04:24:50 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
SV_Printf (const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
|
|
|
|
va_start (argptr, fmt);
|
|
|
|
SV_Print (fmt, argptr);
|
|
|
|
va_end (argptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
SV_ClientPrintf
|
|
|
|
|
|
|
|
Sends text across to be displayed if the level passes
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
SV_ClientPrintf (int recorder, client_t *cl, int level, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char string[1024];
|
|
|
|
va_list argptr;
|
|
|
|
|
|
|
|
if (level < cl->messagelevel)
|
|
|
|
return;
|
|
|
|
|
|
|
|
va_start (argptr, fmt);
|
|
|
|
vsnprintf (string, sizeof (string), fmt, argptr);
|
|
|
|
va_end (argptr);
|
|
|
|
|
2005-05-01 09:07:20 +00:00
|
|
|
if (recorder && sv.recorders) {
|
|
|
|
sizebuf_t *dbuf = SVR_WriteBegin (dem_single, cl - svs.clients,
|
|
|
|
strlen (string) + 3);
|
|
|
|
MSG_WriteByte (dbuf, svc_print);
|
|
|
|
MSG_WriteByte (dbuf, level);
|
|
|
|
MSG_WriteString (dbuf, string);
|
2003-05-07 04:24:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SV_PrintToClient (cl, level, string);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
SV_BroadcastPrintf
|
|
|
|
|
|
|
|
Sends text to all active clients
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
SV_BroadcastPrintf (int level, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char string[1024];
|
|
|
|
client_t *cl;
|
|
|
|
int i;
|
|
|
|
va_list argptr;
|
|
|
|
|
|
|
|
va_start (argptr, fmt);
|
|
|
|
vsnprintf (string, sizeof (string), fmt, argptr);
|
|
|
|
va_end (argptr);
|
|
|
|
|
|
|
|
SV_Printf ("%s", string); // print to the console
|
|
|
|
|
|
|
|
for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) {
|
|
|
|
if (level < cl->messagelevel)
|
|
|
|
continue;
|
2004-04-06 22:02:45 +00:00
|
|
|
if (cl->state < cs_zombie) //FIXME record to mvd
|
2003-05-07 04:24:50 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
SV_PrintToClient (cl, level, string);
|
|
|
|
}
|
|
|
|
|
2005-05-01 09:07:20 +00:00
|
|
|
if (sv.recorders) {
|
|
|
|
sizebuf_t *dbuf = SVR_WriteBegin (dem_all, cl - svs.clients,
|
|
|
|
strlen (string) + 3);
|
|
|
|
MSG_WriteByte (dbuf, svc_print);
|
|
|
|
MSG_WriteByte (dbuf, level);
|
|
|
|
MSG_WriteString (dbuf, string);
|
2003-05-07 04:24:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
SV_BroadcastCommand
|
|
|
|
|
|
|
|
Sends text to all active clients
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
SV_BroadcastCommand (const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char string[1024];
|
|
|
|
va_list argptr;
|
|
|
|
|
|
|
|
if (!sv.state)
|
|
|
|
return;
|
|
|
|
va_start (argptr, fmt);
|
|
|
|
vsnprintf (string, sizeof (string), fmt, argptr);
|
|
|
|
va_end (argptr);
|
|
|
|
|
|
|
|
MSG_WriteByte (&sv.reliable_datagram, svc_stufftext);
|
|
|
|
MSG_WriteString (&sv.reliable_datagram, string);
|
|
|
|
}
|