25
25
26
26
#include " v_textcolors.h"
27
27
28
+ #ifdef SERVER_APP
29
+ void SV_BasePrintAllPlayers (const int printlevel, const std::string& str);
30
+ void SV_BasePrintButPlayer (const int printlevel, const int player_id, const std::string& str);
31
+ #endif
32
+
28
33
size_t C_BasePrint (const int printlevel, const char * color_code, const std::string& str);
29
34
30
35
template <typename ... ARGS>
@@ -67,3 +72,59 @@ size_t PrintFmt(const int printlevel, const fmt::string_view format, const ARGS&
67
72
{
68
73
return C_BasePrint (printlevel, TEXTCOLOR_NORMAL, fmt::format (format, args...));
69
74
}
75
+
76
+ /* *
77
+ * @brief Print to all clients in a server, or to the local player offline.
78
+ *
79
+ * @note This could really use a new name, like "ServerPrintf".
80
+ *
81
+ * @param printlevel PRINT_* constant designating what kind of print this is.
82
+ * @param format printf-style format string.
83
+ * @param args printf-style arguments.
84
+ */
85
+ template <typename ... ARGS>
86
+ void SV_BroadcastPrintf (int printlevel, const fmt::string_view format, const ARGS&... args)
87
+ {
88
+ if (!serverside)
89
+ return ;
90
+
91
+ std::string string = fmt::sprintf (format, args...);
92
+ C_BasePrint (printlevel, TEXTCOLOR_NORMAL, string);
93
+
94
+ #ifdef SERVER_APP
95
+ // Hacky code to display messages as normal ones to clients
96
+ if (printlevel == PRINT_NORCON)
97
+ printlevel = PRINT_HIGH;
98
+
99
+ SV_BasePrintAllPlayers (printlevel, string);
100
+ #endif
101
+ }
102
+
103
+ /* *
104
+ * @brief Print to all clients in a server, or to the local player offline.
105
+ *
106
+ * @note This could really use a new name, like "ServerPrintf".
107
+ *
108
+ * @param format printf-style format string.
109
+ * @param args printf-style arguments.
110
+ */
111
+ template <typename ... ARGS>
112
+ void SV_BroadcastPrintf (const fmt::string_view format, const ARGS&... args)
113
+ {
114
+ SV_BroadcastPrintf (PRINT_NORCON, format, args...);
115
+ }
116
+
117
+ #ifdef SERVER_APP
118
+ template <typename ... ARGS>
119
+ void SV_BroadcastPrintfButPlayer (int printlevel, int player_id, const fmt::string_view format, const ARGS&... args)
120
+ {
121
+ std::string string = fmt::sprintf (format, args...);
122
+ C_BasePrint (printlevel, TEXTCOLOR_NORMAL, string); // print to the console
123
+
124
+ // Hacky code to display messages as normal ones to clients
125
+ if (printlevel == PRINT_NORCON)
126
+ printlevel = PRINT_HIGH;
127
+
128
+ SV_BasePrintButPlayer (printlevel, player_id, string);
129
+ }
130
+ #endif
0 commit comments