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>
@@ -78,3 +83,59 @@ size_t PrintFmt(const int printlevel, const fmt::string_view format, const ARGS&
78
83
{
79
84
return C_BasePrint (printlevel, TEXTCOLOR_NORMAL, fmt::format (format, args...));
80
85
}
86
+
87
+ /* *
88
+ * @brief Print to all clients in a server, or to the local player offline.
89
+ *
90
+ * @note This could really use a new name, like "ServerPrintf".
91
+ *
92
+ * @param printlevel PRINT_* constant designating what kind of print this is.
93
+ * @param format printf-style format string.
94
+ * @param args printf-style arguments.
95
+ */
96
+ template <typename ... ARGS>
97
+ void SV_BroadcastPrintf (int printlevel, const fmt::string_view format, const ARGS&... args)
98
+ {
99
+ if (!serverside)
100
+ return ;
101
+
102
+ std::string string = fmt::sprintf (format, args...);
103
+ C_BasePrint (printlevel, TEXTCOLOR_NORMAL, string);
104
+
105
+ #ifdef SERVER_APP
106
+ // Hacky code to display messages as normal ones to clients
107
+ if (printlevel == PRINT_NORCON)
108
+ printlevel = PRINT_HIGH;
109
+
110
+ SV_BasePrintAllPlayers (printlevel, string);
111
+ #endif
112
+ }
113
+
114
+ /* *
115
+ * @brief Print to all clients in a server, or to the local player offline.
116
+ *
117
+ * @note This could really use a new name, like "ServerPrintf".
118
+ *
119
+ * @param format printf-style format string.
120
+ * @param args printf-style arguments.
121
+ */
122
+ template <typename ... ARGS>
123
+ void SV_BroadcastPrintf (const fmt::string_view format, const ARGS&... args)
124
+ {
125
+ SV_BroadcastPrintf (PRINT_NORCON, format, args...);
126
+ }
127
+
128
+ #ifdef SERVER_APP
129
+ template <typename ... ARGS>
130
+ void SV_BroadcastPrintfButPlayer (int printlevel, int player_id, const fmt::string_view format, const ARGS&... args)
131
+ {
132
+ std::string string = fmt::sprintf (format, args...);
133
+ C_BasePrint (printlevel, TEXTCOLOR_NORMAL, string); // print to the console
134
+
135
+ // Hacky code to display messages as normal ones to clients
136
+ if (printlevel == PRINT_NORCON)
137
+ printlevel = PRINT_HIGH;
138
+
139
+ SV_BasePrintButPlayer (printlevel, player_id, string);
140
+ }
141
+ #endif
0 commit comments