]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/notifications.qc
More updates for hunting down the MOTD bug
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / notifications.qc
1 // ================================================
2 //  Unified notification system, written by Samual
3 //  Last updated: February, 2013
4 // ================================================
5
6 string Get_Notif_TypeName(float net_type)
7 {
8         switch(net_type)
9         {
10                 case MSG_INFO: return "MSG_INFO";
11                 case MSG_CENTER: return "MSG_CENTER";
12                 case MSG_WEAPON: return "MSG_WEAPON";
13                 case MSG_DEATH: return "MSG_DEATH";
14         }
15         backtrace(sprintf("Get_Notif_TypeName(%d): Improper net type!\n", net_type));
16         return "your ass";
17 }
18
19 entity Get_Notif_Ent(float net_type, float net_name)
20 {
21         switch(net_type)
22         {
23                 case MSG_INFO: return msg_info_notifs[net_name - 1];
24                 case MSG_CENTER: return msg_center_notifs[net_name - 1];
25                 case MSG_WEAPON: return msg_weapon_notifs[net_name - 1];
26                 case MSG_DEATH: return msg_death_notifs[net_name - 1];
27         }
28         backtrace(sprintf("Get_Notif_Ent(%d, %d): Improper net type!\n", net_type, net_name));
29         return world;
30 }
31
32 string Notification_CheckArgs_TypeName(float net_type, float net_name)
33 {
34         // check supplied type and name for errors
35         string checkargs = "";
36         #define CHECKARG_TYPENAME(type) case MSG_##type##: \
37                 { if(!net_name || (net_name > NOTIF_##type##_COUNT)) \
38                 { checkargs = sprintf("Improper name: %d!", net_name); } break; }
39         switch(net_type)
40         {
41                 CHECKARG_TYPENAME(INFO)
42                 CHECKARG_TYPENAME(CENTER)
43                 CHECKARG_TYPENAME(WEAPON)
44                 CHECKARG_TYPENAME(DEATH)
45                 default: { checkargs = sprintf("Improper type: %d!", checkargs, net_type); break; }
46         }
47         #undef CHECKARG_TYPENAME
48         return checkargs;
49 }
50
51 #ifdef SVQC
52 string Notification_CheckArgs(float broadcast, entity client, float net_type, float net_name)
53 {
54         // check supplied broadcast, target, type, and name for errors
55         string checkargs = Notification_CheckArgs_TypeName(net_type, net_name);
56         if(checkargs != "") { checkargs = strcat(checkargs, " "); }
57         switch(broadcast)
58         {
59                 case NOTIF_ONE:
60                 case NOTIF_ONE_ONLY:
61                 {
62                         if(IS_NOT_A_CLIENT(client))
63                                 { checkargs = sprintf("%sNo client provided!", checkargs); }
64                         break;
65                 }
66                 
67                 case NOTIF_ANY_EXCEPT:
68                 {
69                         if(IS_NOT_A_CLIENT(client))
70                                 { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
71                         break;
72                 }
73                 
74                 case NOTIF_ANY:
75                 {
76                         if(client)
77                                 { checkargs = sprintf("%sEntity provided when world was required!", checkargs); }
78                         break;
79                 }
80                 
81                 case NOTIF_TEAM:
82                 case NOTIF_TEAM_EXCEPT:
83                 {
84                         if not(teamplay) { checkargs = sprintf("%sTeamplay not active!", checkargs); }
85                         else if(IS_NOT_A_CLIENT(client))
86                         {
87                                 if(broadcast == NOTIF_TEAM) { checkargs = sprintf("%sNo client provided!", checkargs); }
88                                 else { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
89                         }
90                         break;
91                 }
92                 
93                 default: { checkargs = sprintf("%sImproper broadcast: %d!", checkargs, broadcast); break; }
94         }
95         return checkargs;
96 }
97 #endif
98
99 // ===============================
100 //  Frontend Notification Pushing
101 // ===============================
102
103 void Dump_Notifications(float fh, float alsoprint)
104 {
105         #define NOTIF_WRITE(a) { \
106                 fputs(fh, a); \
107                 if(alsoprint) { print(a); } }
108         #define NOTIF_WRITE_ENTITY(name,default,description) { \
109                 notif_msg = \
110                         sprintf( \
111                                 "seta notification_%s \"%d\" \"%s\"\n", \
112                                 name, default, description \
113                         ); \
114                 NOTIF_WRITE(notif_msg) }
115         #define NOTIF_WRITE_HARDCODED(cvar,default,description) { \
116                 notif_msg = \
117                         sprintf( \
118                                 "seta notification_%s \"%s\" \"%s\"\n", \
119                                 cvar, default, description \
120                         ); \
121                 NOTIF_WRITE(notif_msg) }
122
123         string notif_msg;
124         float i;
125         entity e;
126
127         // Note: This warning only applies to the notifications.cfg file that is output...
128
129         // You ARE supposed to manually edit this function to add i.e. hard coded
130         // notification variables for mutators or game modes or such and then
131         // regenerate the notifications.cfg file from the new code.
132
133         NOTIF_WRITE("// ********************************************** //\n");
134         NOTIF_WRITE("// ** WARNING - DO NOT MANUALLY EDIT THIS FILE ** //\n");
135         NOTIF_WRITE("// **                                          ** //\n");
136         NOTIF_WRITE("// **  This file is automatically generated    ** //\n");
137         NOTIF_WRITE("// **  by code with the command 'dumpnotifs'.  ** //\n");
138         NOTIF_WRITE("// **                                          ** //\n");
139         NOTIF_WRITE("// **  If you add a new notification, please   ** //\n");
140         NOTIF_WRITE("// **  regenerate this file with that command  ** //\n");
141         NOTIF_WRITE("// **  making sure that the output matches     ** //\n");
142         NOTIF_WRITE("// **  with the lists and defaults in code.    ** //\n");
143         NOTIF_WRITE("// **                                          ** //\n");
144         NOTIF_WRITE("// ********************************************** //\n");
145
146         // These notifications will also append their string as a comment...
147         // This is not necessary, and does not matter if they vary between config versions,
148         // it is just a semi-helpful tool for those who want to manually change their user settings.
149
150         NOTIF_WRITE(sprintf("\n// MSG_INFO notifications (count = %d):\n", NOTIF_INFO_COUNT));
151         for(i = 1; i <= NOTIF_INFO_COUNT; ++i)
152         {
153                 e = Get_Notif_Ent(MSG_INFO, i);
154                 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
155                 NOTIF_WRITE_ENTITY(e.nent_name, e.nent_default, "Notification control cvar: 0 = off, 1 = print to console, 2 = print to console and chatbox (if notification_allow_chatboxprint is enabled)");
156         }
157
158         NOTIF_WRITE(sprintf("\n// MSG_CENTER notifications (count = %d):\n", NOTIF_CENTER_COUNT));
159         for(i = 1; i <= NOTIF_CENTER_COUNT; ++i)
160         {
161                 e = Get_Notif_Ent(MSG_CENTER, i);
162                 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
163                 NOTIF_WRITE_ENTITY(e.nent_name, e.nent_default, "Notification control cvar: 0 = off, 1 = centerprint");
164         }
165
166         NOTIF_WRITE(sprintf("\n// MSG_WEAPON notifications (count = %d):\n", NOTIF_WEAPON_COUNT));
167         for(i = 1; i <= NOTIF_WEAPON_COUNT; ++i)
168         {
169                 e = Get_Notif_Ent(MSG_WEAPON, i);
170                 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
171                 NOTIF_WRITE_ENTITY(e.nent_name, e.nent_default, "Notification control cvar: 0 = off, 1 = trigger subcalls");
172         }
173
174         NOTIF_WRITE(sprintf("\n// MSG_DEATH notifications (count = %d):\n", NOTIF_DEATH_COUNT));
175         for(i = 1; i <= NOTIF_DEATH_COUNT; ++i)
176         {
177                 e = Get_Notif_Ent(MSG_DEATH, i);
178                 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
179                 NOTIF_WRITE_ENTITY(e.nent_name, e.nent_default, "Notification control cvar: 0 = off, 1 = trigger subcalls");
180         }
181
182         // edit these to match whichever cvars are used for specific notification options
183         NOTIF_WRITE("\n// HARD CODED notification variables:\n");
184         NOTIF_WRITE_HARDCODED("allow_chatboxprint",                             "1",    "Allow notifications to be printed to chat box by setting notification cvar to 2 (You can also set this cvar to 2 to force ALL notifications to be printed to the chatbox)");
185         NOTIF_WRITE_HARDCODED("show_location",                                          "0",    "Append location information to MSG_INFO death/kill messages");
186         NOTIF_WRITE_HARDCODED("show_location_string",                           "",     "Replacement string piped into sprintf, so you can do different messages like this: ' at the %s' or ' (near %s)'");
187         NOTIF_WRITE_HARDCODED("show_sprees",                                            "1",    "Print information about sprees in death/kill messages");
188         NOTIF_WRITE_HARDCODED("show_sprees_center",                             "1",    "Show spree information in MSG_CENTER messages... 0 = off, 1 = target (but only for first victim) and attacker");
189         NOTIF_WRITE_HARDCODED("show_sprees_center_specialonly",         "1",    "Don't show spree information in MSG_CENTER messages if it isn't an achievement");
190         NOTIF_WRITE_HARDCODED("show_sprees_info",                                       "3",    "Show spree information in MSG_INFO messages... 0 = off, 1 = target only, 2 = attacker only, 3 = target and attacker");
191         NOTIF_WRITE_HARDCODED("show_sprees_info_newline",                       "0",    "Show attacker spree information for MSG_INFO messages on a separate line than the death notification itself");
192         NOTIF_WRITE_HARDCODED("show_sprees_info_specialonly",           "1",    "Don't show attacker spree information in MSG_INFO messages if it isn't an achievement");
193         NOTIF_WRITE_HARDCODED("item_centerprinttime",                           "1.5",  "How long to show item information centerprint messages (like 'You got the Electro' or such)");
194         NOTIF_WRITE_HARDCODED("errors_are_fatal",                                       "1",    "If a notification fails upon initialization, cause a Host_Error to stop the program");
195         NOTIF_WRITE_HARDCODED("ctf_pickup_team_verbose",                        "0",    "Show extra information if a team mate picks up a flag");
196         NOTIF_WRITE_HARDCODED("ctf_pickup_enemy_verbose",                       "0",    "Show extra information if an enemy picks up a flag");
197         NOTIF_WRITE_HARDCODED("ctf_capture_verbose",                            "0",    "Show extra information when someone captures a flag");
198         NOTIF_WRITE_HARDCODED("frag_verbose",                                           "1",    "Show extra information when you frag someone (or when you are fragged");
199         NOTIF_WRITE_HARDCODED("lifetime_runtime",                                       "0.5",  "Amount of time that notification entities last on the server during runtime (In seconds)");
200         NOTIF_WRITE_HARDCODED("lifetime_mapload",                                       "10",   "Amount of time that notification entities last immediately at mapload (in seconds) to help prevent notifications from being lost on early init (like gamestart countdown)");
201
202         NOTIF_WRITE(sprintf("\n// Notification counts (total = %d): MSG_INFO = %d, MSG_CENTER = %d, MSG_WEAPON = %d, MSG_DEATH = %d\n",
203                 (NOTIF_INFO_COUNT + NOTIF_CENTER_COUNT + NOTIF_WEAPON_COUNT + NOTIF_DEATH_COUNT), 
204                 NOTIF_INFO_COUNT, NOTIF_CENTER_COUNT, NOTIF_WEAPON_COUNT, NOTIF_DEATH_COUNT));
205         
206         return;
207         #undef NOTIF_WRITE_HARDCODED
208         #undef NOTIF_WRITE_ENTITY
209         #undef NOTIF_WRITE
210 }
211
212 #ifdef SVQC
213 void Notification_GetCvars()
214 {
215         GetCvars_handleFloat(get_cvars_s, get_cvars_f, FRAG_VERBOSE, "notification_frag_verbose");
216 }
217 #endif
218
219 string Local_Notification_sprintf(string input, string args, 
220         string s1, string s2, string s3, string s4,
221         float f1, float f2, float f3, float f4)
222 {
223         #ifdef NOTIFICATIONS_DEBUG
224         dprint(
225                 sprintf("Local_Notification_sprintf('%s^7', '%s', %s, %s);\n",
226                         strreplace("\n", "\\n", input),
227                         args,
228                         strreplace("\n", "\\n", sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
229                         sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
230                 )
231         );
232         #endif
233         
234         string selected;
235         float sel_num;
236         for(sel_num = 0; sel_num < NOTIF_MAX_ARGS; ++sel_num) { arg_slot[sel_num] = ""; }
237
238         string tmp_s;
239
240         for(sel_num = 0;(args != "");)
241         {
242                 selected = car(args); args = cdr(args);
243                 NOTIF_HIT_MAX(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
244                 switch(strtolower(selected))
245                 {
246                         #define ARG_CASE(prog,selected,result) \
247                                 #ifdef CSQC \
248                                         #if (prog != ARG_SV) && (prog != ARG_DC) \
249                                                 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
250                                         #endif \
251                                 #else \
252                                         #if (prog != ARG_CS) && (prog != ARG_DC) \
253                                                 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
254                                         #endif \
255                                 #endif
256                         NOTIF_ARGUMENT_LIST
257                         #undef ARG_CASE
258                         default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
259                 }
260         }
261         return sprintf(input, arg_slot[0], arg_slot[1], arg_slot[2], arg_slot[3], arg_slot[4], arg_slot[5], arg_slot[6]);
262 }
263
264 #ifdef CSQC
265 void Local_Notification_HUD_Notify_Push(string icon, string hudargs, string s1, string s2, string s3, string s4)
266 {
267         string selected;
268         float sel_num;
269         arg_slot[0] = ""; arg_slot[1] = "";
270
271         for(sel_num = 0;(hudargs != "");)
272         {
273                 selected = car(hudargs); hudargs = cdr(hudargs);
274                 NOTIF_HIT_MAX(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
275                 switch(strtolower(selected))
276                 {
277                         #define ARG_CASE(prog,selected,result) \
278                                 #if (prog == ARG_CS_SV_HA) \
279                                         case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
280                                 #endif
281                         NOTIF_ARGUMENT_LIST
282                         #undef ARG_CASE
283                         default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
284                 }
285         }
286         #ifdef NOTIFICATIONS_DEBUG
287         dprint(
288                 sprintf("Local_Notification_HUD_Notify_Push('%s^7', '%s', %s, %s);\n",
289                         icon,
290                         hudargs,
291                         strreplace("\n", "\\n", sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
292                         strreplace("\n", "\\n", sprintf("'%s^7', '%s^7'", stof(arg_slot[0]), stof(arg_slot[1])))
293                 )
294         );
295         #endif
296         HUD_Notify_Push(icon, arg_slot[0], arg_slot[1]);
297 }
298
299 void Local_Notification_centerprint_generic(string input, string durcnt, float cpid, float f1, float f2)
300 {
301         string selected;
302         float sel_num;
303         arg_slot[0] = ""; arg_slot[1] = "";
304
305         for(sel_num = 0;(durcnt != "");)
306         {
307                 selected = car(durcnt); durcnt = cdr(durcnt);
308                 NOTIF_HIT_MAX(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic")
309                 switch(strtolower(selected))
310                 {
311                         #define ARG_CASE(prog,selected,result) \
312                                 #if (prog == ARG_CS_SV_DC) || (prog == ARG_DC) \
313                                         case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
314                                 #endif
315                         NOTIF_ARGUMENT_LIST
316                         #undef ARG_CASE
317                         default:
318                         {
319                                 if(ftos(stof(selected)) != "") { arg_slot[sel_num] = selected; ++sel_num; }
320                                 else { NOTIF_HIT_UNKNOWN(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic") }
321                                 break;
322                         }
323                 }
324         }
325         #ifdef NOTIFICATIONS_DEBUG
326         dprint(
327                 sprintf("Local_Notification_centerprint_generic('%s^7', '%s', %d, %d, %d, %d);\n",
328                         strreplace("\n", "\\n", input),
329                         durcnt,
330                         f1, f2,
331                         stof(arg_slot[0]), stof(arg_slot[1])
332                 )
333         );
334         #endif
335         centerprint_generic(cpid, input, stof(arg_slot[0]), stof(arg_slot[1]));
336 }
337 #endif
338
339 void Local_Notification(float net_type, float net_name, ...count)
340 {
341         // check supplied type and name for errors
342         string checkargs = Notification_CheckArgs_TypeName(net_type, net_name);
343         if(checkargs != "") { backtrace(sprintf("Incorrect usage of Local_Notification: %s\n", checkargs)); return; }
344
345         entity notif = Get_Notif_Ent(net_type, net_name);
346         if not(notif) { backtrace("Local_Notification: Could not find notification entity!\n"); return; }
347
348         #ifdef NOTIFICATIONS_DEBUG
349         if not(notif.nent_enabled) { dprint(sprintf("Local_Notification(%s, %s): Entity was disabled...\n", Get_Notif_TypeName(net_type), notif.nent_name)); return; }
350         #endif
351         
352         if((notif.nent_stringcount + notif.nent_floatcount) > count)
353         {
354                 backtrace(sprintf(
355                         strcat(
356                                 "Not enough arguments for Local_Notification(%s, %s, ...)! ",
357                                 "stringcount(%d) + floatcount(%d) > count(%d)\n", 
358                                 "Check the definition and function call for accuracy...?\n"
359                         ),
360                         Get_Notif_TypeName(net_type), notif.nent_name, notif.nent_stringcount, notif.nent_floatcount, count));
361                 return;
362         }
363         else if((notif.nent_stringcount + notif.nent_floatcount) < count)
364         {
365                 backtrace(sprintf(
366                         strcat(
367                                 "Too many arguments for Local_Notification(%s, %s, ...)! ",
368                                 "stringcount(%d) + floatcount(%d) < count(%d)\n",
369                                 "Check the definition and function call for accuracy...?\n"
370                         ),
371                         Get_Notif_TypeName(net_type), notif.nent_name, notif.nent_stringcount, notif.nent_floatcount, count));
372                 return;
373         }
374
375         string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
376         string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
377         string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
378         string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
379         float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
380         float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
381         float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
382         float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
383
384         #ifdef NOTIFICATIONS_DEBUG
385         dprint(
386                 sprintf("Local_Notification(%s, %s, %s, %s);\n",
387                         Get_Notif_TypeName(net_type),
388                         notif.nent_name,
389                         strreplace("\n", "\\n", sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
390                         sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
391                 )
392         );
393         #endif
394         
395         switch(net_type)
396         {
397                 case MSG_INFO:
398                 {
399                         print(
400                                 Local_Notification_sprintf(
401                                         notif.nent_string,
402                                         notif.nent_args, 
403                                         s1, s2, s3, s4,
404                                         f1, f2, f3, f4)
405                         );
406                         #ifdef CSQC 
407                         if(notif.nent_icon != "")
408                         {
409                                 Local_Notification_HUD_Notify_Push(
410                                         notif.nent_icon,
411                                         notif.nent_hudargs,
412                                         s1, s2, s3, s4);
413                         } 
414                         #endif 
415                         break;
416                 }
417                 
418                 #ifdef CSQC
419                 case MSG_CENTER:
420                 {
421                         Local_Notification_centerprint_generic(
422                                 Local_Notification_sprintf(
423                                         notif.nent_string,
424                                         notif.nent_args, 
425                                         s1, s2, s3, s4,
426                                         f1, f2, f3, f4),
427                                 notif.nent_durcnt,
428                                 notif.nent_cpid,
429                                 f1, f2);
430                         break;
431                 }
432                 #endif
433                 
434                 case MSG_WEAPON:
435                 case MSG_DEATH:
436                 {
437                         if(notif.nent_msginfo)
438                         if(notif.nent_msginfo.nent_enabled)
439                         {
440                                 Local_Notification_WOVA(
441                                         MSG_INFO,
442                                         notif.nent_msginfo.nent_id, 
443                                         notif.nent_msginfo.nent_stringcount, 
444                                         notif.nent_msginfo.nent_floatcount, 
445                                         s1, s2, s3, s4,
446                                         f1, f2, f3, f4);
447                         }
448                         #ifdef CSQC
449                         if(notif.nent_msgcenter)
450                         if(notif.nent_msgcenter.nent_enabled)
451                         {
452                                 Local_Notification_WOVA(
453                                         MSG_CENTER,
454                                         notif.nent_msgcenter.nent_id, 
455                                         notif.nent_msgcenter.nent_stringcount, 
456                                         notif.nent_msgcenter.nent_floatcount, 
457                                         s1, s2, s3, s4,
458                                         f1, f2, f3, f4); 
459                         }
460                         #endif
461                         break;
462                 }
463         }
464 }
465
466 // WOVA = Without Variable Arguments 
467 void Local_Notification_WOVA(float net_type, float net_name,
468         float stringcount, float floatcount,
469         string s1, string s2, string s3, string s4,
470         float f1, float f2, float f3, float f4)
471 {
472         #define VARITEM(stringc,floatc,args) \
473                 if((stringcount == stringc) && (floatcount == floatc)) \
474                         { Local_Notification(net_type, net_name, args); return; }
475         EIGHT_VARS_TO_VARARGS_VARLIST
476         #undef VARITEM
477         Local_Notification(net_type, net_name); // some notifications don't have any arguments at all
478 }
479
480
481 // =========================
482 //  Notification Networking
483 // =========================
484
485 #ifdef CSQC
486 void Read_Notification(float is_new)
487 {
488         float net_type = ReadByte();
489         float net_name = ReadShort();
490
491         if(net_type == MSG_CENTER_KILL)
492         {
493                 if(is_new)
494                 {
495                         if(net_name == 0) { reset_centerprint_messages(); }
496                         else
497                         {
498                                 entity notif = Get_Notif_Ent(MSG_CENTER, net_name);
499                                 if not(notif) { backtrace("Read_Notification: Could not find notification entity!\n"); return; }
500                                 centerprint_generic(notif.nent_cpid, "", 0, 0);
501                         }
502                 }
503         }
504         else
505         {
506                 entity notif = Get_Notif_Ent(net_type, net_name);
507                 if not(notif) { backtrace("Read_Notification: Could not find notification entity!\n"); return; }
508
509                 #ifdef NOTIFICATIONS_DEBUG
510                 dprint(sprintf("Read_Notification(%d) at %f: net_type = %s, net_name = %s\n", is_new, time, Get_Notif_TypeName(net_type), notif.nent_name));
511                 #endif
512
513                 string s1 = ((0 < notif.nent_stringcount) ? ReadString() : "");
514                 string s2 = ((1 < notif.nent_stringcount) ? ReadString() : "");
515                 string s3 = ((2 < notif.nent_stringcount) ? ReadString() : "");
516                 string s4 = ((3 < notif.nent_stringcount) ? ReadString() : "");
517                 float f1 = ((0 < notif.nent_floatcount) ? ReadLong() : 0);
518                 float f2 = ((1 < notif.nent_floatcount) ? ReadLong() : 0);
519                 float f3 = ((2 < notif.nent_floatcount) ? ReadLong() : 0);
520                 float f4 = ((3 < notif.nent_floatcount) ? ReadLong() : 0);
521         
522                 if(is_new)
523                 {
524                         Local_Notification_WOVA(
525                                 net_type, net_name,
526                                 notif.nent_stringcount,
527                                 notif.nent_floatcount,
528                                 s1, s2, s3, s4,
529                                 f1, f2, f3, f4);
530                 }
531         }
532 }
533 #endif
534
535 #ifdef SVQC
536 void Net_Notification_Remove()
537 {
538         #ifdef NOTIFICATIONS_DEBUG
539         if not(self) { dprint(sprintf("Net_Notification_Remove() at %f: Missing self!?\n", time)); return; }
540         if(self.nent_net_name == -1)
541         {
542                 dprint(
543                         sprintf(
544                                 "Net_Notification_Remove() at %f: Killed '%s' notification\n",
545                                 time,
546                                 Get_Notif_TypeName(self.nent_net_type)
547                         )
548                 );
549         }
550         else
551         #endif
552         {
553                 string checkargs = Notification_CheckArgs_TypeName(self.nent_net_type, self.nent_net_name);
554                 if(checkargs != "") { dprint(sprintf("Incorrect usage of Net_Notification_Remove() at %f: %s\n", time, checkargs)); return; }
555
556                 #ifdef NOTIFICATIONS_DEBUG
557                 entity realent = Get_Notif_Ent(self.nent_net_type, self.nent_net_name);
558                 dprint(
559                         sprintf(
560                                 "Net_Notification_Remove() at %f: Removed '%s - %s' notification\n",
561                                 time,
562                                 Get_Notif_TypeName(self.nent_net_type), 
563                                 realent.nent_name
564                         )
565                 );
566                 #endif
567         }
568         
569         float i;
570         for(i = 0; i < 4; ++i) { if(self.nent_strings[i]) { strunzone(self.nent_strings[i]); } }
571         remove(self);
572 }
573
574 float Net_Write_Notification(entity client, float sf)
575 {
576         float i, send = FALSE;
577         
578         switch(self.nent_broadcast)
579         {
580                 case NOTIF_ONE: // send to one client and their spectator
581                 {
582                         if(
583                                 (client == self.nent_client)
584                                 ||
585                                 (
586                                         (client.classname == STR_SPECTATOR)
587                                         &&
588                                         (client.enemy == self.nent_client)
589                                 )
590                         ) { send = TRUE; }
591                         break;
592                 }
593                 case NOTIF_ONE_ONLY: // send ONLY to one client
594                 {
595                         if(client == self.nent_client) { send = TRUE; }
596                         break;
597                 }
598                 case NOTIF_TEAM: // send only to X team and their spectators
599                 {
600                         if(
601                                 (client.team == self.nent_client.team)
602                                 ||
603                                 (
604                                         (client.classname == STR_SPECTATOR)
605                                         &&
606                                         (client.enemy.team == self.nent_client.team)
607                                 )
608                         ) { send = TRUE; }
609                         break;
610                 }
611                 case NOTIF_TEAM_EXCEPT: // send only to X team and their spectators, except for Y person and their spectators
612                 {
613                         if(
614                                 (client != self.nent_client)
615                                 &&
616                                 (
617                                         (client.team == self.nent_client.team)
618                                         ||
619                                         (
620                                                 (client.classname == STR_SPECTATOR)
621                                                 &&
622                                                 (
623                                                         (client.enemy != self.nent_client)
624                                                         &&
625                                                         (client.enemy.team == self.nent_client.team)
626                                                 )
627                                         )
628                                 )
629                         ) { send = TRUE; }
630                         break;
631                 }
632                 case NOTIF_ANY: // send to everyone
633                 {
634                         send = TRUE;
635                         break;
636                 }
637                 case NOTIF_ANY_EXCEPT: // send to everyone except X person and their spectators
638                 {
639                         if(
640                                 (client != self.nent_client)
641                                 &&
642                                 !(
643                                         (client.classname == STR_SPECTATOR)
644                                         &&
645                                         (client.enemy == self.nent_client)
646                                 )
647                         ) { send = TRUE; }
648                         break;
649                 }
650                 default: { send = FALSE; break; }
651         }
652
653         if(send)
654         {               
655                 WriteByte(MSG_ENTITY, ENT_CLIENT_NOTIFICATION);
656                 WriteByte(MSG_ENTITY, self.nent_net_type);
657                 WriteShort(MSG_ENTITY, self.nent_net_name);
658                 for(i = 0; i < self.nent_stringcount; ++i) { WriteString(MSG_ENTITY, self.nent_strings[i]); } 
659                 for(i = 0; i < self.nent_floatcount; ++i) { WriteLong(MSG_ENTITY, self.nent_floats[i]); }
660         }
661
662         return send; 
663 }
664
665 void Kill_Notification(float broadcast, entity client, float net_type, float net_name)
666 {
667         string checkargs = Notification_CheckArgs(broadcast, client, 1, 1);
668         if(checkargs != "") { backtrace(sprintf("Incorrect usage of Kill_Notification: %s\n", checkargs)); return; }
669
670         #ifdef NOTIFICATIONS_DEBUG
671         dprint(
672                 sprintf("Kill_Notification(%d, '%s', %d, %d);\n",
673                         broadcast,
674                         client.netname,
675                         net_type,
676                         net_name
677                 )
678         );
679         #endif
680
681         entity notif, net_notif;
682
683         // if no name is provided, just kill ALL the centerprint notifications
684         if(net_type == MSG_CENTER)
685         {
686                 net_notif = spawn();
687                 net_notif.classname = "net_kill_notification";
688                 net_notif.nent_broadcast = broadcast;
689                 net_notif.nent_client = client;
690                 net_notif.nent_net_type = MSG_CENTER_KILL;
691                 net_notif.nent_net_name = net_name;
692                 Net_LinkEntity(net_notif, FALSE, autocvar_notification_lifetime_runtime, Net_Write_Notification);
693         }
694
695         for(notif = world; (notif = find(notif, classname, "net_notification"));)
696         {
697                 // now kill the old send notification entity
698                 if(net_type)
699                 {
700                         if(notif.nent_net_type == net_type)
701                         {
702                                 if(net_name)
703                                 {
704                                         if(notif.nent_net_name == net_name) { notif.nent_net_name = -1; notif.think(); }
705                                         else { continue; } // we ARE looking for a certain net_name, don't kill everything else too
706                                 }
707                                 else { notif.nent_net_name = -1; notif.think(); }
708                         }
709                         else { continue; } // we ARE looking for a certain net_type, don't kill everything else too
710                 }
711                 else { notif.nent_net_name = -1; notif.think(); }
712         }
713 }
714
715 void Send_Notification(float broadcast, entity client,
716         float net_type, float net_name, ...count)
717 {
718         // check supplied broadcast, target, type, and name for errors
719         string checkargs = Notification_CheckArgs(broadcast, client, net_type, net_name);
720         if(checkargs != "") { backtrace(sprintf("Incorrect usage of Send_Notification: %s\n", checkargs)); return; }
721
722         // retreive counts for the arguments of this notification
723         entity notif = Get_Notif_Ent(net_type, net_name);
724         if not(notif) { backtrace("Send_Notification: Could not find notification entity!\n"); return; }
725
726         if((notif.nent_stringcount + notif.nent_floatcount) > count)
727         {
728                 backtrace(sprintf(
729                         strcat(
730                                 "Not enough arguments for Send_Notification(%d, %s, %s, ...)! ",
731                                 "stringcount(%d) + floatcount(%d) > count(%d)\n", 
732                                 "Check the definition and function call for accuracy...?\n"
733                         ),
734                         broadcast, Get_Notif_TypeName(net_type), notif.nent_name, notif.nent_stringcount, notif.nent_floatcount, count));
735                 return;
736         }
737         else if((notif.nent_stringcount + notif.nent_floatcount) < count)
738         {
739                 backtrace(sprintf(
740                         strcat(
741                                 "Too many arguments for Send_Notification(%d, %s, %s, ...)! ",
742                                 "stringcount(%d) + floatcount(%d) < count(%d)\n",
743                                 "Check the definition and function call for accuracy...?\n"
744                         ),
745                         broadcast, Get_Notif_TypeName(net_type), notif.nent_name, notif.nent_stringcount, notif.nent_floatcount, count));
746                 return;
747         }
748
749         #ifdef NOTIFICATIONS_DEBUG
750         string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
751         string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
752         string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
753         string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
754         float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
755         float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
756         float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
757         float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
758         dprint(
759                 sprintf("Send_Notification(%d, %s, %s, %s, %s);\n",
760                         broadcast,
761                         Get_Notif_TypeName(net_type),
762                         notif.nent_name,
763                         strreplace("\n", "\\n", sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
764                         sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
765                 )
766         );
767         #endif
768
769         entity net_notif = spawn();
770         net_notif.classname = "net_notification";
771         net_notif.nent_broadcast = broadcast;
772         net_notif.nent_client = client;
773         net_notif.nent_net_type = net_type;
774         net_notif.nent_net_name = net_name;
775         net_notif.nent_stringcount = notif.nent_stringcount;
776         net_notif.nent_floatcount = notif.nent_floatcount;
777         
778         float i;
779         for(i = 0; i < net_notif.nent_stringcount; ++i) { net_notif.nent_strings[i] = strzone(...(i, string)); }
780         for(i = 0; i < net_notif.nent_floatcount; ++i) { net_notif.nent_floats[i] = ...((net_notif.nent_stringcount + i), float); }
781
782         net_notif.think = Net_Notification_Remove;
783         net_notif.nextthink =
784                 ((time > autocvar_notification_lifetime_mapload)
785                 ?
786                         (time + autocvar_notification_lifetime_runtime)
787                         :
788                         autocvar_notification_lifetime_mapload
789                 ); 
790
791         Net_LinkEntity(net_notif, FALSE, 0, Net_Write_Notification);
792
793         if(server_is_dedicated && (broadcast == NOTIF_ANY || broadcast == NOTIF_ANY_EXCEPT) && (net_type != MSG_CENTER))
794         {
795                 Local_Notification_WOVA(
796                         net_type, net_name,
797                         notif.nent_stringcount,
798                         notif.nent_floatcount,
799                         IFSTR(0), IFSTR(1), IFSTR(2), IFSTR(3),
800                         IFFL(0), IFFL(1), IFFL(2), IFFL(3));
801         }
802 }
803
804 // WOVA = Without Variable Arguments 
805 void Send_Notification_WOVA(float broadcast, entity client,
806         float net_type, float net_name,
807         string s1, string s2, string s3, string s4,
808         float f1, float f2, float f3, float f4)
809 {
810         entity notif = Get_Notif_Ent(net_type, net_name);
811         
812         #ifdef NOTIFICATIONS_DEBUG
813         dprint(
814                 sprintf("Send_Notification_WOVA(%d, %s, %s, %s, %s - %d %d);\n",
815                         broadcast,
816                         Get_Notif_TypeName(net_type),
817                         notif.nent_name,
818                         sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4),
819                         sprintf("%d, %d, %d, %d", f1, f2, f3, f4),
820                         notif.nent_stringcount, notif.nent_floatcount
821                 )
822         );
823         #endif
824         
825         #define VARITEM(stringc,floatc,args) \
826                 if((notif.nent_stringcount == stringc) && (notif.nent_floatcount == floatc)) \
827                         { Send_Notification(broadcast, client, net_type, net_name, args); return; }
828         EIGHT_VARS_TO_VARARGS_VARLIST
829         #undef VARITEM
830         Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
831 }
832
833
834 // =============================
835 //  LEGACY NOTIFICATION SYSTEMS
836 // =============================
837
838 void Send_CSQC_Centerprint_Generic(entity e, float id, string s, float duration, float countdown_num)
839 {
840         if ((clienttype(e) == CLIENTTYPE_REAL) && (e.flags & FL_CLIENT))
841         {
842                 msg_entity = e;
843                 WRITESPECTATABLE_MSG_ONE({
844                         WriteByte(MSG_ONE, SVC_TEMPENTITY);
845                         WriteByte(MSG_ONE, TE_CSQC_CENTERPRINT_GENERIC);
846                         WriteByte(MSG_ONE, id);
847                         WriteString(MSG_ONE, s);
848                         if (id != 0 && s != "")
849                         {
850                                 WriteByte(MSG_ONE, duration);
851                                 WriteByte(MSG_ONE, countdown_num);
852                         }
853                 });
854         }
855 }
856 #endif // ifdef SVQC