UFO: Alien Invasion
Loading...
Searching...
No Matches
sv_send.cpp
Go to the documentation of this file.
1
5
6/*
7All original material Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9Original file from Quake 2 v3.21: quake2-2.31/server/sv_send.c
10Copyright (C) 1997-2001 Id Software, Inc.
11
12This program is free software; you can redistribute it and/or
13modify it under the terms of the GNU General Public License
14as published by the Free Software Foundation; either version 2
15of the License, or (at your option) any later version.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
21See the GNU General Public License for more details.
22
23You should have received a copy of the GNU General Public License
24along with this program; if not, write to the Free Software
25Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27*/
28
29#include "server.h"
30
31/*
32=============================================================================
33EVENT MESSAGES
34=============================================================================
35*/
36
40void SV_ClientCommand (client_t* client, const char* fmt, ...)
41{
42 va_list ap;
43 char str[MAX_SVC_STUFFTEXT];
44 dbuffer msg;
45
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
58void SV_ClientPrintf (client_t* cl, int level, const char* fmt, ...)
59{
60 if (level > cl->messagelevel)
61 return;
62
63 dbuffer msg;
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
79void SV_BroadcastPrintf (int level, const char* fmt, ...)
80{
81 dbuffer msg;
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
126void 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}
clientBattleScape_t cl
cvar_t * sv_dedicated
Definition common.cpp:51
void Com_Printf(const char *const fmt,...)
Definition common.cpp:428
#define MAX_SVC_PRINT
Definition common.h:160
#define MAX_SVC_STUFFTEXT
Definition common.h:159
@ svc_stufftext
Definition common.h:152
@ svc_print
Definition common.h:151
#define PRINT_HUD
Definition defines.h:107
level_locals_t level
Definition g_main.cpp:38
void NET_VPrintf(dbuffer *buf, const char *format, va_list ap, char *str, size_t length)
Definition netpack.cpp:603
void NET_WriteMsg(struct net_stream *s, dbuffer &buf)
Enqueue the buffer in the net stream for ONE client.
Definition netpack.cpp:569
void NET_WriteByte(dbuffer *buf, byte c)
Definition netpack.cpp:39
void NET_WriteConstMsg(struct net_stream *s, const dbuffer &buf)
Enqueue the buffer in the net stream for MULTIPLE clients.
Definition netpack.cpp:588
QGL_EXTERN GLuint GLsizei GLsizei * length
Definition r_gl.h:110
QGL_EXTERN GLint i
Definition r_gl.h:113
Main server include file.
@ cs_connected
Definition server.h:141
client_t * SV_GetNextClient(client_t *lastClient)
Iterates through clients.
Definition sv_main.cpp:152
int Q_vsnprintf(char *str, size_t size, const char *format, va_list ap)
Safe (null terminating) vsnprintf implementation.
Definition shared.cpp:535
struct net_stream * stream
Definition server.h:163
void SV_BroadcastPrintf(int level, const char *fmt,...)
Sends text to all active clients.
Definition sv_send.cpp:79
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
void SV_ClientCommand(client_t *client, const char *fmt,...)
Definition sv_send.cpp:40
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