/** * @brief Sends the contents of msg to a subset of the clients, then frees msg * @param[in] mask Bitmask of the players to send the multicast to * @param[in,out] msg The message to send to the clients */ void SV_Multicast (int mask, const dbuffer &msg) { /* send the data to all relevant clients */ client_t *cl = nullptr; int j = -1; while ((cl = SV_GetNextClient(cl)) != nullptr) { j++; if (cl->state < cs_connected) continue; if (!(mask & (1 << j))) continue; /* write the message */ NET_WriteConstMsg(cl->stream, msg); } }
/** * @brief Sends text to all active clients */ void SV_BroadcastPrintf (int level, const char *fmt, ...) { va_list argptr; struct dbuffer *msg; client_t *cl; char str[1024]; msg = new_dbuffer(); NET_WriteByte(msg, svc_print); NET_WriteByte(msg, level); va_start(argptr, fmt); NET_VPrintf(msg, fmt, argptr, str, sizeof(str)); va_end(argptr); /* echo to console */ if (sv_dedicated->integer) { char copy[1024]; int i; const int length = sizeof(copy) - 1; va_start(argptr, fmt); Q_vsnprintf(copy, sizeof(copy), fmt, argptr); va_end(argptr); /* mask off high bits */ for (i = 0; i < length && copy[i]; i++) copy[i] = copy[i] & 127; copy[i] = '\0'; Com_Printf("%s", copy); } cl = NULL; while ((cl = SV_GetNextClient(cl)) != NULL) { if (level > cl->messagelevel) continue; if (cl->state < cs_connected) continue; NET_WriteConstMsg(cl->stream, msg); } free_dbuffer(msg); }
/** * @brief Sends the contents of msg to a subset of the clients, then frees msg * @param[in] mask Bitmask of the players to send the multicast to * @param[in,out] msg The message to send to the clients */ void SV_Multicast (int mask, struct dbuffer *msg) { client_t *cl; int j; /* send the data to all relevant clients */ cl = NULL; j = -1; while ((cl = SV_GetNextClient(cl)) != NULL) { j++; if (cl->state < cs_connected) continue; if (!(mask & (1 << j))) continue; /* write the message */ NET_WriteConstMsg(cl->stream, msg); } free_dbuffer(msg); }
/** * @brief Used by SV_Shutdown to send a final message to all * connected clients before the server goes down. * @sa SV_Shutdown */ static void SV_FinalMessage (const char *message, bool reconnect) { client_t *cl; dbuffer msg(2 + strlen(message)); if (reconnect) NET_WriteByte(&msg, svc_reconnect); else NET_WriteByte(&msg, svc_disconnect); NET_WriteString(&msg, message); cl = NULL; while ((cl = SV_GetNextClient(cl)) != NULL) if (cl->state >= cs_connected) { NET_WriteConstMsg(cl->stream, msg); NET_StreamFinished(cl->stream); cl->stream = NULL; } /* make sure, that this is send */ NET_Wait(0); }