UFO: Alien Invasion
Toggle main menu visibility
Loading...
Searching...
No Matches
sv_send.cpp
Go to the documentation of this file.
1
5
6
/*
7
All original material Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9
Original file from Quake 2 v3.21: quake2-2.31/server/sv_send.c
10
Copyright (C) 1997-2001 Id Software, Inc.
11
12
This program is free software; you can redistribute it and/or
13
modify it under the terms of the GNU General Public License
14
as published by the Free Software Foundation; either version 2
15
of the License, or (at your option) any later version.
16
17
This program is distributed in the hope that it will be useful,
18
but WITHOUT ANY WARRANTY; without even the implied warranty of
19
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
21
See the GNU General Public License for more details.
22
23
You should have received a copy of the GNU General Public License
24
along with this program; if not, write to the Free Software
25
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27
*/
28
29
#include "
server.h
"
30
31
/*
32
=============================================================================
33
EVENT MESSAGES
34
=============================================================================
35
*/
36
40
void
SV_ClientCommand
(
client_t
* client,
const
char
* fmt, ...)
41
{
42
va_list ap;
43
char
str[
MAX_SVC_STUFFTEXT
];
44
dbuffer
msg;
45
46
NET_WriteByte
(&msg,
svc_stufftext
);
47
48
va_start(ap, fmt);
49
NET_VPrintf
(&msg, fmt, ap, str,
sizeof
(str));
50
va_end(ap);
51
52
NET_WriteMsg
(client->
stream
, msg);
53
}
54
58
void
SV_ClientPrintf
(
client_t
*
cl
,
int
level
,
const
char
* fmt, ...)
59
{
60
if
(
level
>
cl
->messagelevel)
61
return
;
62
63
dbuffer
msg;
64
NET_WriteByte
(&msg,
svc_print
);
65
NET_WriteByte
(&msg,
level
);
66
67
va_list argptr;
68
va_start(argptr, fmt);
69
char
str[
MAX_SVC_PRINT
];
70
NET_VPrintf
(&msg, fmt, argptr, str,
sizeof
(str));
71
va_end(argptr);
72
73
NET_WriteMsg
(
cl
->stream, msg);
74
}
75
79
void
SV_BroadcastPrintf
(
int
level
,
const
char
* fmt, ...)
80
{
81
dbuffer
msg;
82
NET_WriteByte
(&msg,
svc_print
);
83
NET_WriteByte
(&msg,
level
);
84
85
va_list argptr;
86
va_start(argptr, fmt);
87
char
str[
MAX_SVC_PRINT
];
88
NET_VPrintf
(&msg, fmt, argptr, str,
sizeof
(str));
89
va_end(argptr);
90
91
/* echo to console */
92
if
(
sv_dedicated
->integer) {
93
char
copy[1024];
94
int
i
;
95
const
int
length
=
sizeof
(copy) - 1;
96
97
va_start(argptr, fmt);
98
Q_vsnprintf
(copy,
sizeof
(copy), fmt, argptr);
99
va_end(argptr);
100
101
/* mask off high bits */
102
for
(
i
= 0;
i
<
length
&& copy[
i
];
i
++)
103
copy[
i
] = copy[
i
] & 127;
104
copy[
i
] =
'\0'
;
105
if
(
level
==
PRINT_HUD
)
106
Com_Printf
(
"%s\n"
, copy);
107
else
108
Com_Printf
(
"%s"
, copy);
109
}
110
111
client_t
*
cl
=
nullptr
;
112
while
((
cl
=
SV_GetNextClient
(
cl
)) !=
nullptr
) {
113
if
(
level
>
cl
->messagelevel)
114
continue
;
115
if
(
cl
->state <
cs_connected
)
116
continue
;
117
NET_WriteConstMsg
(
cl
->stream, msg);
118
}
119
}
120
126
void
SV_Multicast
(
int
mask,
const
dbuffer
& msg)
127
{
128
/* send the data to all relevant clients */
129
client_t
*
cl
=
nullptr
;
130
int
j = -1;
131
while
((
cl
=
SV_GetNextClient
(
cl
)) !=
nullptr
) {
132
j++;
133
if
(
cl
->state <
cs_connected
)
134
continue
;
135
if
(!(mask & (1 << j)))
136
continue
;
137
138
/* write the message */
139
NET_WriteConstMsg
(
cl
->stream, msg);
140
}
141
}
cl
clientBattleScape_t cl
Definition
cl_battlescape.cpp:29
dbuffer
Definition
dbuffer.h:20
sv_dedicated
cvar_t * sv_dedicated
Definition
common.cpp:51
Com_Printf
void Com_Printf(const char *const fmt,...)
Definition
common.cpp:428
MAX_SVC_PRINT
#define MAX_SVC_PRINT
Definition
common.h:160
MAX_SVC_STUFFTEXT
#define MAX_SVC_STUFFTEXT
Definition
common.h:159
svc_stufftext
@ svc_stufftext
Definition
common.h:152
svc_print
@ svc_print
Definition
common.h:151
PRINT_HUD
#define PRINT_HUD
Definition
defines.h:107
level
level_locals_t level
Definition
g_main.cpp:38
NET_VPrintf
void NET_VPrintf(dbuffer *buf, const char *format, va_list ap, char *str, size_t length)
Definition
netpack.cpp:603
NET_WriteMsg
void NET_WriteMsg(struct net_stream *s, dbuffer &buf)
Enqueue the buffer in the net stream for ONE client.
Definition
netpack.cpp:569
NET_WriteByte
void NET_WriteByte(dbuffer *buf, byte c)
Definition
netpack.cpp:39
NET_WriteConstMsg
void NET_WriteConstMsg(struct net_stream *s, const dbuffer &buf)
Enqueue the buffer in the net stream for MULTIPLE clients.
Definition
netpack.cpp:588
length
QGL_EXTERN GLuint GLsizei GLsizei * length
Definition
r_gl.h:110
i
QGL_EXTERN GLint i
Definition
r_gl.h:113
server.h
Main server include file.
cs_connected
@ cs_connected
Definition
server.h:141
SV_GetNextClient
client_t * SV_GetNextClient(client_t *lastClient)
Iterates through clients.
Definition
sv_main.cpp:152
Q_vsnprintf
int Q_vsnprintf(char *str, size_t size, const char *format, va_list ap)
Safe (null terminating) vsnprintf implementation.
Definition
shared.cpp:535
client_t
Definition
server.h:155
client_t::stream
struct net_stream * stream
Definition
server.h:163
SV_BroadcastPrintf
void SV_BroadcastPrintf(int level, const char *fmt,...)
Sends text to all active clients.
Definition
sv_send.cpp:79
SV_Multicast
void SV_Multicast(int mask, const dbuffer &msg)
Sends the contents of msg to a subset of the clients, then frees msg.
Definition
sv_send.cpp:126
SV_ClientCommand
void SV_ClientCommand(client_t *client, const char *fmt,...)
Definition
sv_send.cpp:40
SV_ClientPrintf
void SV_ClientPrintf(client_t *cl, int level, const char *fmt,...)
Sends text across to be displayed if the level passes.
Definition
sv_send.cpp:58
src
server
sv_send.cpp
Generated on __DATE__ __TIME__ for UFO: Alien Invasion by
1.17.0