UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
sv_send.cpp
Go to the documentation of this file.
1 
6 /*
7 All original material Copyright (C) 2002-2020 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 
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 }
void SV_BroadcastPrintf(int level, const char *fmt,...)
Sends text to all active clients.
Definition: sv_send.cpp:79
int Q_vsnprintf(char *str, size_t size, const char *format, va_list ap)
Safe (null terminating) vsnprintf implementation.
Definition: shared.cpp:535
int messagelevel
Definition: server.h:160
#define MAX_SVC_PRINT
Definition: common.h:160
void NET_VPrintf(dbuffer *buf, const char *format, va_list ap, char *str, size_t length)
Definition: netpack.cpp:603
client_t * SV_GetNextClient(client_t *lastClient)
Iterates through clients.
Definition: sv_main.cpp:152
void Com_Printf(const char *const fmt,...)
Definition: common.cpp:386
int integer
Definition: cvar.h:81
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
QGL_EXTERN GLuint GLsizei GLsizei * length
Definition: r_gl.h:110
void SV_ClientCommand(client_t *client, const char *fmt,...)
Definition: sv_send.cpp:40
Main server include file.
clientBattleScape_t cl
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
#define MAX_SVC_STUFFTEXT
Definition: common.h:159
QGL_EXTERN GLint i
Definition: r_gl.h:113
cvar_t * sv_dedicated
Definition: common.cpp:51
struct net_stream * stream
Definition: server.h:163
void NET_WriteByte(dbuffer *buf, byte c)
Definition: netpack.cpp:39
client_state_t state
Definition: server.h:156
level_locals_t level
Definition: g_main.cpp:38
#define PRINT_HUD
Definition: defines.h:107
void NET_WriteConstMsg(struct net_stream *s, const dbuffer &buf)
Enqueue the buffer in the net stream for MULTIPLE clients.
Definition: netpack.cpp:588
void NET_WriteMsg(struct net_stream *s, dbuffer &buf)
Enqueue the buffer in the net stream for ONE client.
Definition: netpack.cpp:569