sv_send.c

Go to the documentation of this file.
00001 
00006 /*
00007 All original material Copyright (C) 2002-2010 UFO: Alien Invasion.
00008 
00009 Original file from Quake 2 v3.21: quake2-2.31/server/sv_send.c
00010 Copyright (C) 1997-2001 Id Software, Inc.
00011 
00012 This program is free software; you can redistribute it and/or
00013 modify it under the terms of the GNU General Public License
00014 as published by the Free Software Foundation; either version 2
00015 of the License, or (at your option) any later version.
00016 
00017 This program is distributed in the hope that it will be useful,
00018 but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00020 
00021 See the GNU General Public License for more details.
00022 
00023 You should have received a copy of the GNU General Public License
00024 along with this program; if not, write to the Free Software
00025 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00026 
00027 */
00028 
00029 #include "server.h"
00030 
00031 /*
00032 =============================================================================
00033 EVENT MESSAGES
00034 =============================================================================
00035 */
00036 
00040 void SV_ClientCommand (client_t *client, const char *fmt, ...)
00041 {
00042     va_list ap;
00043     char str[1024];
00044     struct dbuffer *msg = new_dbuffer();
00045 
00046     NET_WriteByte(msg, svc_stufftext);
00047 
00048     va_start(ap, fmt);
00049     NET_VPrintf(msg, fmt, ap, str, sizeof(str));
00050     va_end(ap);
00051 
00052     NET_WriteMsg(client->stream, msg);
00053 }
00054 
00058 void SV_ClientPrintf (client_t * cl, int level, const char *fmt, ...)
00059 {
00060     va_list argptr;
00061     struct dbuffer *msg;
00062     char str[1024];
00063 
00064     if (level > cl->messagelevel)
00065         return;
00066 
00067     msg = new_dbuffer();
00068     NET_WriteByte(msg, svc_print);
00069     NET_WriteByte(msg, level);
00070 
00071     va_start(argptr, fmt);
00072     NET_VPrintf(msg, fmt, argptr, str, sizeof(str));
00073     va_end(argptr);
00074 
00075     NET_WriteMsg(cl->stream, msg);
00076 }
00077 
00081 void SV_BroadcastPrintf (int level, const char *fmt, ...)
00082 {
00083     va_list argptr;
00084     struct dbuffer *msg;
00085     client_t *cl;
00086     char str[1024];
00087 
00088     msg = new_dbuffer();
00089     NET_WriteByte(msg, svc_print);
00090     NET_WriteByte(msg, level);
00091 
00092     va_start(argptr, fmt);
00093     NET_VPrintf(msg, fmt, argptr, str, sizeof(str));
00094     va_end(argptr);
00095 
00096     /* echo to console */
00097     if (sv_dedicated->integer) {
00098         char copy[1024];
00099         int i;
00100         const int length = sizeof(copy) - 1;
00101 
00102         va_start(argptr, fmt);
00103         Q_vsnprintf(copy, sizeof(copy), fmt, argptr);
00104         va_end(argptr);
00105 
00106         /* mask off high bits */
00107         for (i = 0; i < length && copy[i]; i++)
00108             copy[i] = copy[i] & 127;
00109         copy[i] = '\0';
00110         Com_Printf("%s", copy);
00111     }
00112 
00113     cl = NULL;
00114     while ((cl = SV_GetNextClient(cl)) != NULL) {
00115         if (level > cl->messagelevel)
00116             continue;
00117         if (cl->state < cs_connected)
00118             continue;
00119         NET_WriteConstMsg(cl->stream, msg);
00120     }
00121 
00122     free_dbuffer(msg);
00123 }
00124 
00130 void SV_Multicast (int mask, struct dbuffer *msg)
00131 {
00132     client_t *cl;
00133     int j;
00134 
00135     /* send the data to all relevant clients */
00136     cl = NULL;
00137     j = -1;
00138     while ((cl = SV_GetNextClient(cl)) != NULL) {
00139         j++;
00140         if (cl->state < cs_connected)
00141             continue;
00142         if (!(mask & (1 << j)))
00143             continue;
00144 
00145         /* write the message */
00146         NET_WriteConstMsg(cl->stream, msg);
00147     }
00148 
00149     free_dbuffer(msg);
00150 }
00151 
00155 void SV_StartSound (int mask, const vec3_t origin, const edict_t *entity, const char *sound)
00156 {
00157     vec3_t origin_v;
00158     struct dbuffer *msg;
00159 
00160     /* use the entity origin unless it is a bmodel or explicitly specified */
00161     if (!origin) {
00162         origin = origin_v;
00163         if (entity->solid == SOLID_BSP) {
00164             VectorCenterFromMinsMaxs(entity->mins, entity->maxs, origin_v);
00165             VectorAdd(entity->origin, origin_v, origin_v);
00166         } else {
00167             VectorCopy(entity->origin, origin_v);
00168         }
00169     }
00170 
00171     msg = new_dbuffer();
00172 
00173     NET_WriteByte(msg, svc_sound);
00174     NET_WriteString(msg, sound);
00175     NET_WritePos(msg, origin);
00176 
00177     SV_Multicast(mask, msg);
00178 }

Generated by  doxygen 1.6.2