]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/notifications.qc
Update more include paths to simplify log output
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / notifications.qc
1 #if defined(CSQC)
2         #include "../client/announcer.qh"
3 #elif defined(MENUQC)
4 #elif defined(SVQC)
5     #include "constants.qh"
6     #include "teams.qh"
7     #include "../server/autocvars.qh"
8     #include "../server/constants.qh"
9     #include "../server/defs.qh"
10     #include "notifications.qh"
11     #include <server/mutators/all.qh>
12 #endif
13
14 // ================================================
15 //  Unified notification system, written by Samual
16 //  Last updated: August, 2013
17 // ================================================
18
19 string Get_Notif_TypeName(int net_type)
20 {
21         switch(net_type)
22         {
23                 case MSG_ANNCE: return "MSG_ANNCE";
24                 case MSG_INFO: return "MSG_INFO";
25                 case MSG_CENTER: return "MSG_CENTER";
26                 case MSG_CENTER_CPID: return "MSG_CENTER_CPID";
27                 case MSG_MULTI: return "MSG_MULTI";
28                 case MSG_CHOICE: return "MSG_CHOICE";
29         }
30         backtrace(sprintf("Get_Notif_TypeName(%d): Improper net type!\n", net_type));
31         return "";
32 }
33
34 entity Get_Notif_Ent(int net_type, int net_name)
35 {
36         switch(net_type)
37         {
38                 case MSG_ANNCE: return msg_annce_notifs[net_name - 1];
39                 case MSG_INFO: return msg_info_notifs[net_name - 1];
40                 case MSG_CENTER: return msg_center_notifs[net_name - 1];
41                 case MSG_MULTI: return msg_multi_notifs[net_name - 1];
42                 case MSG_CHOICE: return msg_choice_notifs[net_name - 1];
43         }
44         backtrace(sprintf("Get_Notif_Ent(%d, %d): Improper net type!\n", net_type, net_name));
45         return world;
46 }
47
48 #ifdef SVQC
49 #ifdef NOTIFICATIONS_DEBUG
50 string Get_Notif_BroadcastName(float broadcast)
51 {
52         switch(broadcast)
53         {
54                 case NOTIF_ONE: return "NOTIF_ONE";
55                 case NOTIF_ONE_ONLY: return "NOTIF_ONE_ONLY";
56                 case NOTIF_ALL_EXCEPT: return "NOTIF_ALL_EXCEPT";
57                 case NOTIF_ALL: return "NOTIF_ALL";
58                 case NOTIF_TEAM: return "NOTIF_TEAM";
59                 case NOTIF_TEAM_EXCEPT: return "NOTIF_TEAM_EXCEPT";
60         }
61         backtrace(sprintf("Get_Notif_BroadcastName(%d): Improper broadcast!\n", broadcast));
62         return "";
63 }
64 #endif
65 #endif
66
67 string Notification_CheckArgs_TypeName(float net_type, float net_name)
68 {
69         // check supplied type and name for errors
70         string checkargs = "";
71         #define CHECKARG_TYPENAME(type) case MSG_##type: \
72                 { if(!net_name || (net_name > NOTIF_##type##_COUNT)) \
73                 { checkargs = sprintf("Improper name: %d!", net_name); } break; }
74         switch(net_type)
75         {
76                 CHECKARG_TYPENAME(ANNCE)
77                 CHECKARG_TYPENAME(INFO)
78                 CHECKARG_TYPENAME(CENTER)
79                 CHECKARG_TYPENAME(MULTI)
80                 CHECKARG_TYPENAME(CHOICE)
81                 default: { checkargs = sprintf("Improper type: %d!", checkargs, net_type); break; }
82         }
83         #undef CHECKARG_TYPENAME
84         return checkargs;
85 }
86
87 #ifdef SVQC
88 string Notification_CheckArgs(
89         float broadcast, entity client,
90         float net_type, float net_name)
91 {
92         // check supplied broadcast, target, type, and name for errors
93         string checkargs = Notification_CheckArgs_TypeName(net_type, net_name);
94         if(checkargs != "") { checkargs = strcat(checkargs, " "); }
95         switch(broadcast)
96         {
97                 case NOTIF_ONE:
98                 case NOTIF_ONE_ONLY:
99                 {
100                         if(IS_NOT_A_CLIENT(client))
101                                 { checkargs = sprintf("%sNo client provided!", checkargs); }
102                         break;
103                 }
104
105                 case NOTIF_ALL_EXCEPT:
106                 {
107                         if(IS_NOT_A_CLIENT(client))
108                                 { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
109                         break;
110                 }
111
112                 case NOTIF_ALL:
113                 {
114                         if(client)
115                                 { checkargs = sprintf("%sEntity provided when world was required!", checkargs); }
116                         break;
117                 }
118
119                 case NOTIF_TEAM:
120                 {
121                         if (!teamplay)
122                                 { checkargs = sprintf("%sTeamplay not active!", checkargs); }
123                         //else if (!client.team) { checkargs = sprintf("%sNo team provided!", checkargs); }
124                         break;
125                 }
126
127                 case NOTIF_TEAM_EXCEPT:
128                 {
129                         if (!teamplay)
130                                 { checkargs = sprintf("%sTeamplay not active!", checkargs); }
131                         else if(IS_NOT_A_CLIENT(client))
132                                 { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
133                         break;
134                 }
135
136                 default: { checkargs = sprintf("%sImproper broadcast: %d!", checkargs, broadcast); break; }
137         }
138         return checkargs;
139 }
140
141 float Notification_ShouldSend(float broadcast, entity to_client, entity other_client)
142 {
143         switch(broadcast)
144         {
145                 case NOTIF_ONE: // send to one client and their spectator
146                 {
147                         if(
148                                 (to_client == other_client)
149                                 ||
150                                 (
151                                         IS_SPEC(to_client)
152                                         &&
153                                         (to_client.enemy == other_client)
154                                 )
155                         ) { return true; }
156                         break;
157                 }
158                 case NOTIF_ONE_ONLY: // send ONLY to one client
159                 {
160                         if(to_client == other_client) { return true; }
161                         break;
162                 }
163                 case NOTIF_TEAM: // send only to X team and their spectators
164                 {
165                         if(
166                                 (to_client.team == other_client.team)
167                                 ||
168                                 (
169                                         IS_SPEC(to_client)
170                                         &&
171                                         (to_client.enemy.team == other_client.team)
172                                 )
173                         ) { return true; }
174                         break;
175                 }
176                 case NOTIF_TEAM_EXCEPT: // send only to X team and their spectators, except for Y person and their spectators
177                 {
178                         if(
179                                 (to_client != other_client)
180                                 &&
181                                 (
182                                         (to_client.team == other_client.team)
183                                         ||
184                                         (
185                                                 IS_SPEC(to_client)
186                                                 &&
187                                                 (
188                                                         (to_client.enemy != other_client)
189                                                         &&
190                                                         (to_client.enemy.team == other_client.team)
191                                                 )
192                                         )
193                                 )
194                         ) { return true; }
195                         break;
196                 }
197                 case NOTIF_ALL: // send to everyone
198                 {
199                         return true;
200                 }
201                 case NOTIF_ALL_EXCEPT: // send to everyone except X person and their spectators
202                 {
203                         if(
204                                 (to_client != other_client)
205                                 &&
206                                 !(
207                                         IS_SPEC(to_client)
208                                         &&
209                                         (to_client.enemy == other_client)
210                                 )
211                         ) { return true; }
212                         break;
213                 }
214         }
215         return false;
216 }
217
218 #endif
219
220 // ===============================
221 //  Initialization Core Functions
222 // ===============================
223
224 // used by restartnotifs command to initialize notifications
225 void Destroy_Notification_Entity(entity notif)
226 {
227         if(notif.nent_name != "") { strunzone(notif.nent_name); }
228         if(notif.nent_snd != "") { strunzone(notif.nent_snd); }
229         if(notif.nent_args != "") { strunzone(notif.nent_args); }
230         if(notif.nent_hudargs != "") { strunzone(notif.nent_hudargs); }
231         if(notif.nent_icon != "") { strunzone(notif.nent_icon); }
232         if(notif.nent_durcnt != "") { strunzone(notif.nent_durcnt); }
233         if(notif.nent_string != "") { strunzone(notif.nent_string); }
234         remove(notif);
235 }
236
237 void Destroy_All_Notifications()
238 {
239         entity notif;
240         int i;
241
242         #define DESTROY_LOOP(type,count) MACRO_BEGIN { \
243                 for(i = 1; i <= count; ++i) \
244                 { \
245                         notif = Get_Notif_Ent(type, i); \
246                         if (!notif) { backtrace("Destroy_All_Notifications(): Missing notification entity!\n"); return; } \
247                         Destroy_Notification_Entity(notif); \
248                 } \
249         } MACRO_END
250
251         // kill all networked notifications and centerprints
252         #ifdef SVQC
253         Kill_Notification(NOTIF_ALL, world, 0, 0);
254         #else
255         reset_centerprint_messages();
256         #endif
257
258         // kill all real notification entities
259         DESTROY_LOOP(MSG_ANNCE, NOTIF_ANNCE_COUNT);
260         DESTROY_LOOP(MSG_INFO, NOTIF_INFO_COUNT);
261         DESTROY_LOOP(MSG_CENTER, NOTIF_CENTER_COUNT);
262         DESTROY_LOOP(MSG_MULTI, NOTIF_MULTI_COUNT);
263         DESTROY_LOOP(MSG_CHOICE, NOTIF_CHOICE_COUNT);
264         #undef DESTROY_LOOP
265 }
266
267 string Process_Notif_Line(
268         int typeId,
269         bool chat,
270         string input,
271         string notiftype,
272         string notifname,
273         string stringtype)
274 {
275         #ifdef CSQC
276         if(typeId == MSG_INFO)
277         {
278                 if((chat && autocvar_notification_allow_chatboxprint)
279                         || (autocvar_notification_allow_chatboxprint == 2))
280                 {
281                         // pass 1: add ETX char at beginning of line
282                         input = strcat("\{3}", input);
283
284                         // pass 2: add ETX char at end of each new line (so that
285                         // messages with multiple lines are put through chatbox too)
286                         input = strreplace("\n", "\n\{3}", input);
287
288                         // pass 3: strip trailing ETX char
289                         if(substring(input, (strlen(input) - 1), 1) == "\{3}")
290                                 { input = substring(input, 0, (strlen(input) - 1)); }
291                 }
292         }
293         #endif
294
295         // done to both MSG_INFO and MSG_CENTER
296         if(substring(input, (strlen(input) - 1), 1) == "\n")
297         {
298                 LOG_INFOF(
299                         strcat(
300                                 "^1TRAILING NEW LINE AT END OF NOTIFICATION: ",
301                                 "^7net_type = %s, net_name = %s, string = %s.\n"
302                         ),
303                         notiftype,
304                         notifname,
305                         stringtype
306                 );
307                 notif_error = true;
308                 input = substring(input, 1, (strlen(input) - 1));
309         }
310
311         return input;
312 }
313
314 string Process_Notif_Args(
315         float arg_type,
316         string args,
317         string notiftype,
318         string notifname)
319 {
320         string selected, remaining = args;
321         float sel_num = 0;
322
323         for (;(remaining != "");)
324         {
325                 selected = car(remaining); remaining = cdr(remaining);
326
327                 switch(arg_type)
328                 {
329                         case 1: // normal args
330                         {
331                                 if(sel_num == NOTIF_MAX_ARGS)
332                                 {
333                                         LOG_INFOF(
334                                                 strcat(
335                                                         "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
336                                                         "^7net_type = %s, net_name = %s, max args = %d.\n"
337                                                 ),
338                                                 notiftype,
339                                                 notifname,
340                                                 NOTIF_MAX_ARGS
341                                         );
342                                         notif_error = true;
343                                         break;
344                                 }
345
346                                 switch(strtolower(selected))
347                                 {
348                                         #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { ++sel_num; break; }
349                                         #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { ++sel_num; break; }
350                                         #define ARG_CASE_ARG_CS_SV(selected,result)    case selected: { ++sel_num; break; }
351                                         #define ARG_CASE_ARG_CS(selected,result)       case selected: { ++sel_num; break; }
352                                         #define ARG_CASE_ARG_SV(selected,result)       case selected: { ++sel_num; break; }
353                                         #define ARG_CASE_ARG_DC(selected,result)
354                                         #define ARG_CASE(prog,selected,result)         ARG_CASE_##prog(selected,result)
355                                         NOTIF_ARGUMENT_LIST
356                                         #undef ARG_CASE
357                                         #undef ARG_CASE_ARG_DC
358                                         #undef ARG_CASE_ARG_SV
359                                         #undef ARG_CASE_ARG_CS
360                                         #undef ARG_CASE_ARG_CS_SV
361                                         #undef ARG_CASE_ARG_CS_SV_DC
362                                         #undef ARG_CASE_ARG_CS_SV_HA
363                                         default:
364                                         {
365                                                 LOG_INFOF(
366                                                         strcat(
367                                                                 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
368                                                                 "^7net_type = %s, net_name = %s, args arg = '%s'.\n"
369                                                         ),
370                                                         notiftype,
371                                                         notifname,
372                                                         selected
373                                                 );
374                                                 notif_error = true;
375                                                 break;
376                                         }
377                                 }
378                                 break;
379                         }
380                         case 2: // hudargs
381                         {
382                                 if(sel_num == NOTIF_MAX_HUDARGS)
383                                 {
384                                         LOG_INFOF(
385                                                 strcat(
386                                                         "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
387                                                         "^7net_type = %s, net_name = %s, max hudargs = %d.\n"
388                                                 ),
389                                                 notiftype,
390                                                 notifname,
391                                                 NOTIF_MAX_HUDARGS
392                                         );
393                                         notif_error = true;
394                                         break;
395                                 }
396
397                                 switch(strtolower(selected))
398                                 {
399                                         #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { ++sel_num; break; }
400                                         #define ARG_CASE_ARG_CS_SV_DC(selected,result)
401                                         #define ARG_CASE_ARG_CS_SV(selected,result)
402                                         #define ARG_CASE_ARG_CS(selected,result)
403                                         #define ARG_CASE_ARG_SV(selected,result)
404                                         #define ARG_CASE_ARG_DC(selected,result)
405                                         #define ARG_CASE(prog,selected,result)         ARG_CASE_##prog(selected,result)
406                                         NOTIF_ARGUMENT_LIST
407                                         #undef ARG_CASE
408                                         #undef ARG_CASE_ARG_DC
409                                         #undef ARG_CASE_ARG_SV
410                                         #undef ARG_CASE_ARG_CS
411                                         #undef ARG_CASE_ARG_CS_SV
412                                         #undef ARG_CASE_ARG_CS_SV_DC
413                                         #undef ARG_CASE_ARG_CS_SV_HA
414                                         default:
415                                         {
416                                                 LOG_INFOF(
417                                                         strcat(
418                                                                 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
419                                                                 "^7net_type = %s, net_name = %s, hudargs arg = '%s'.\n"
420                                                         ),
421                                                         notiftype,
422                                                         notifname,
423                                                         selected
424                                                 );
425                                                 notif_error = true;
426                                                 break;
427                                         }
428                                 }
429                                 break;
430                         }
431                         case 3: // durcnt
432                         {
433                                 if(sel_num == NOTIF_MAX_DURCNT)
434                                 {
435                                         LOG_INFOF(
436                                                 strcat(
437                                                         "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
438                                                         "^7net_type = %s, net_name = %s, max durcnt = %d.\n"
439                                                 ),
440                                                 notiftype,
441                                                 notifname,
442                                                 NOTIF_MAX_DURCNT
443                                         );
444                                         notif_error = true;
445                                         break;
446                                 }
447
448                                 switch(strtolower(selected))
449                                 {
450                                         #define ARG_CASE_ARG_CS_SV_HA(selected,result)
451                                         #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { ++sel_num; break; }
452                                         #define ARG_CASE_ARG_CS_SV(selected,result)
453                                         #define ARG_CASE_ARG_CS(selected,result)
454                                         #define ARG_CASE_ARG_SV(selected,result)
455                                         #define ARG_CASE_ARG_DC(selected,result)       case selected: { ++sel_num; break; }
456                                         #define ARG_CASE(prog,selected,result)         ARG_CASE_##prog(selected,result)
457                                         NOTIF_ARGUMENT_LIST
458                                         #undef ARG_CASE
459                                         #undef ARG_CASE_ARG_DC
460                                         #undef ARG_CASE_ARG_SV
461                                         #undef ARG_CASE_ARG_CS
462                                         #undef ARG_CASE_ARG_CS_SV
463                                         #undef ARG_CASE_ARG_CS_SV_DC
464                                         #undef ARG_CASE_ARG_CS_SV_HA
465                                         default:
466                                         {
467                                                 if(ftos(stof(selected)) != "") { ++sel_num; }
468                                                 else
469                                                 {
470                                                         LOG_INFOF(
471                                                                 strcat(
472                                                                         "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
473                                                                         "^7net_type = %s, net_name = %s, durcnt arg = '%s'.\n"
474                                                                 ),
475                                                                 notiftype,
476                                                                 notifname,
477                                                                 selected
478                                                         );
479                                                         notif_error = true;
480                                                 }
481                                                 break;
482                                         }
483                                 }
484                                 break;
485                         }
486                 }
487         }
488         return args;
489 }
490
491 void Create_Notification_Entity(
492         float var_default,
493         float var_cvar,
494         int typeId,
495         int nameid,
496         string namestring,
497         int strnum,
498         int flnum,
499         /* MSG_ANNCE */
500         float channel,
501         string snd,
502         float vol,
503         float position,
504         /* MSG_INFO & MSG_CENTER */
505         string args,
506         string hudargs,
507         string icon,
508         float cpid,
509         string durcnt,
510         string normal,
511         string gentle,
512         /* MSG_MULTI */
513         int anncename,
514         int infoname,
515         int centername,
516         /* MSG_CHOICE */
517         float challow_def,
518         float challow_var,
519         int chtype,
520         int optiona,
521         int optionb)
522 {
523         // =====================
524         //  Global Entity Setup
525         // =====================
526         entity notif = new_pure(notification);
527         switch(typeId)
528         {
529                 case MSG_ANNCE:
530                 {
531                         msg_annce_notifs[nameid - 1] = notif;
532                         notif.classname = "msg_annce_notification";
533                         break;
534                 }
535                 case MSG_INFO:
536                 {
537                         msg_info_notifs[nameid - 1] = notif;
538                         notif.classname = "msg_info_notification";
539                         break;
540                 }
541                 case MSG_CENTER:
542                 {
543                         msg_center_notifs[nameid - 1] = notif;
544                         notif.classname = "msg_center_notification";
545                         break;
546                 }
547                 case MSG_MULTI:
548                 {
549                         msg_multi_notifs[nameid - 1] = notif;
550                         notif.classname = "msg_multi_notification";
551                         break;
552                 }
553                 case MSG_CHOICE:
554                 {
555                         msg_choice_notifs[nameid - 1] = notif;
556                         notif.classname = "msg_choice_notification";
557                         break;
558                 }
559
560                 default:
561                 {
562                         error(sprintf(
563                                 strcat(
564                                         "^1NOTIFICATION WITH IMPROPER TYPE: ",
565                                         "^7net_type = %d, net_name = %s.\n"
566                                 ),
567                                 typeId,
568                                 namestring
569                         ));
570                         return; // It's not possible to recover from this one
571                 }
572         }
573         notif.nent_default = var_default;
574         notif.nent_enabled = (1 <= var_cvar);
575         notif.nent_type = typeId;
576         notif.nent_id = nameid;
577         notif.nent_name = strzone(namestring);
578
579         string typestring = Get_Notif_TypeName(typeId);
580
581         // Other pre-notif-setup requisites
582         notif_error = false;
583
584         // ====================
585         //  Notification Setup
586         // ====================
587         switch(typeId)
588         {
589                 case MSG_ANNCE:
590                 {
591                         // Set MSG_ANNCE information and handle precaching
592                         #ifdef CSQC
593                         if (!(GENTLE && (var_cvar == 1)))
594                         {
595                                 if(snd != "")
596                                 {
597                                         if(notif.nent_enabled)
598                                         {
599                                                 precache_sound(sprintf("announcer/%s/%s.wav", AnnouncerOption(), snd));
600                                                 notif.nent_channel = channel;
601                                                 notif.nent_snd = strzone(snd);
602                                                 notif.nent_vol = vol;
603                                                 notif.nent_position = position;
604                                         }
605                                 }
606                                 else
607                                 {
608                                         LOG_INFOF(
609                                                 strcat(
610                                                         "^1NOTIFICATION WITH NO SOUND: ",
611                                                         "^7net_type = %s, net_name = %s.\n"
612                                                 ),
613                                                 typestring,
614                                                 namestring
615                                         );
616                                         notif_error = true;
617                                 }
618                         }
619                         else { notif.nent_enabled = false; }
620                         #else
621                         notif.nent_enabled = false;
622                         #endif
623
624                         break;
625                 }
626
627                 case MSG_INFO:
628                 case MSG_CENTER:
629                 {
630                         // Set MSG_INFO and MSG_CENTER string/float counts
631                         notif.nent_stringcount = strnum;
632                         notif.nent_floatcount = flnum;
633
634                         // Only initialize arguments if we're either a client or on a dedicated server
635                         #ifdef SVQC
636                         float should_process_args = server_is_dedicated;
637                         #else
638                         float should_process_args = true;
639                         #endif
640
641                         if(should_process_args)
642                         {
643                                 // ========================
644                                 //  Process Main Arguments
645                                 // ========================
646                                 if(strnum + flnum)
647                                 {
648                                         if(args != "")
649                                         {
650                                                 notif.nent_args = strzone(
651                                                         Process_Notif_Args(1, args, typestring, namestring));
652                                         }
653                                         else if((hudargs == "") && (durcnt ==""))
654                                         {
655                                                 LOG_INFOF(
656                                                         strcat(
657                                                                 "^1NOTIFICATION HAS ARG COUNTS BUT NO ARGS OR HUDARGS OR DURCNT: ",
658                                                                 "^7net_type = %s, net_name = %s, strnum = %d, flnum = %d\n"
659                                                         ),
660                                                         typestring,
661                                                         namestring,
662                                                         strnum,
663                                                         flnum
664                                                 );
665                                                 notif_error = true;
666                                         }
667                                 }
668                                 else if(args != "")
669                                 {
670                                         notif.nent_args = strzone(
671                                                 Process_Notif_Args(1, args, typestring, namestring));
672                                 }
673
674
675                                 // =======================================
676                                 //  Process HUD and Centerprint Arguments
677                                 //    Only processed on CSQC, as these
678                                 //    args are only for HUD features.
679                                 // =======================================
680                                 #ifdef CSQC
681                                 if(hudargs != "")
682                                 {
683                                         notif.nent_hudargs = strzone(
684                                                 Process_Notif_Args(2, hudargs, typestring, namestring));
685
686                                         if(icon != "") { notif.nent_icon = strzone(icon); }
687                                         else
688                                         {
689                                                 LOG_INFOF(
690                                                         strcat(
691                                                                 "^1NOTIFICATION HAS HUDARGS BUT NO ICON: ",
692                                                                 "^7net_type = %s, net_name = %s.\n"
693                                                         ),
694                                                         typestring,
695                                                         namestring
696                                                 );
697                                                 notif_error = true;
698                                         }
699                                 }
700                                 else if(icon != "")
701                                 {
702                                         LOG_INFOF(
703                                                 strcat(
704                                                         "^1NOTIFICATION HAS ICON BUT NO HUDARGS: ",
705                                                         "^7net_type = %s, net_name = %s.\n"
706                                                 ),
707                                                 typestring,
708                                                 namestring
709                                         );
710                                         notif_error = true;
711                                 }
712
713                                 if(durcnt != "")
714                                 {
715                                         notif.nent_durcnt = strzone(
716                                                 Process_Notif_Args(3, durcnt, typestring, namestring));
717
718                                         if(cpid != NO_MSG) { notif.nent_cpid = cpid; }
719                                         else
720                                         {
721                                                 LOG_INFOF(
722                                                         strcat(
723                                                                 "^1NOTIFICATION HAS DURCNT BUT NO CPID: ",
724                                                                 "^7net_type = %s, net_name = %s.\n"
725                                                         ),
726                                                         typestring,
727                                                         namestring
728                                                 );
729                                                 notif_error = true;
730                                         }
731                                 }
732                                 else if(cpid != NO_MSG) { notif.nent_cpid = cpid; }
733                                 #endif
734
735
736                                 // ======================
737                                 //  Process Notif String
738                                 // ======================
739                                 #define SET_NOTIF_STRING(string,stringname) MACRO_BEGIN { \
740                                         notif.nent_string = strzone(CCR( \
741                                                 Process_Notif_Line( \
742                                                         typeId, \
743                                                         (var_cvar > 1), \
744                                                         string, \
745                                                         typestring, \
746                                                         namestring, \
747                                                         stringname \
748                                                 )) \
749                                         ); \
750                                 } MACRO_END
751
752                                 if(GENTLE)
753                                 {
754                                         if(gentle != "") { SET_NOTIF_STRING(gentle, "GENTLE"); }
755                                         else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL"); }
756                                 }
757                                 else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL"); }
758                                 #undef SET_NOTIF_STRING
759
760                                 // Check to make sure a string was chosen
761                                 if(notif.nent_string == "")
762                                 {
763                                         LOG_INFOF(
764                                                 strcat(
765                                                         "^1EMPTY NOTIFICATION: ",
766                                                         "^7net_type = %s, net_name = %s.\n"
767                                                 ),
768                                                 typestring,
769                                                 namestring
770                                         );
771                                         notif_error = true;
772                                 }
773                         }
774
775                         break;
776                 }
777
778                 case MSG_MULTI:
779                 {
780                         // Set MSG_MULTI string/float counts
781                         if((anncename == NO_MSG) && (infoname == NO_MSG) && (centername == NO_MSG))
782                         {
783                                 LOG_INFOF(
784                                         strcat(
785                                                 "^1NOTIFICATION WITH NO SUBCALLS: ",
786                                                 "^7net_type = %s, net_name = %s.\n"
787                                         ),
788                                         typestring,
789                                         namestring
790                                 );
791                                 notif_error = true;
792                         }
793                         else
794                         {
795                                 // announcements don't actually need any arguments, so lets not even count them.
796                                 if(anncename != NO_MSG) { notif.nent_msgannce = msg_annce_notifs[anncename - 1]; }
797
798                                 float infoname_stringcount = 0, infoname_floatcount = 0;
799                                 float centername_stringcount = 0, centername_floatcount = 0;
800
801                                 if(infoname != NO_MSG)
802                                 {
803                                         notif.nent_msginfo = msg_info_notifs[infoname - 1];
804                                         infoname_stringcount = notif.nent_msginfo.nent_stringcount;
805                                         infoname_floatcount = notif.nent_msginfo.nent_floatcount;
806                                 }
807
808                                 if(centername != NO_MSG)
809                                 {
810                                         notif.nent_msgcenter = msg_center_notifs[centername - 1];
811                                         centername_stringcount = notif.nent_msgcenter.nent_stringcount;
812                                         centername_floatcount = notif.nent_msgcenter.nent_floatcount;
813                                 }
814
815                                 // set the requirements of THIS notification to the totals of its subcalls
816                                 notif.nent_stringcount = max(infoname_stringcount, centername_stringcount);
817                                 notif.nent_floatcount = max(infoname_floatcount, centername_floatcount);
818                         }
819
820                         break;
821                 }
822
823                 case MSG_CHOICE:
824                 {
825                         if((chtype == NO_MSG) || (optiona == NO_MSG) || (optionb == NO_MSG))
826                         {
827                                 LOG_INFOF(
828                                         strcat(
829                                                 "^1NOTIFICATION IS MISSING CHOICE PARAMS: ",
830                                                 "^7net_type = %s, net_name = %s.\n"
831                                         ),
832                                         typestring,
833                                         namestring
834                                 );
835                                 notif_error = true;
836                         }
837                         else
838                         {
839                                 switch(chtype)
840                                 {
841                                         case MSG_ANNCE:
842                                         {
843                                                 notif.nent_optiona = msg_annce_notifs[optiona - 1];
844                                                 notif.nent_optionb = msg_annce_notifs[optionb - 1];
845                                                 break;
846                                         }
847                                         case MSG_INFO:
848                                         {
849                                                 notif.nent_optiona = msg_info_notifs[optiona - 1];
850                                                 notif.nent_optionb = msg_info_notifs[optionb - 1];
851                                                 break;
852                                         }
853                                         case MSG_CENTER:
854                                         {
855                                                 notif.nent_optiona = msg_center_notifs[optiona - 1];
856                                                 notif.nent_optionb = msg_center_notifs[optionb - 1];
857                                                 break;
858                                         }
859                                         case MSG_MULTI:
860                                         {
861                                                 notif.nent_optiona = msg_multi_notifs[optiona - 1];
862                                                 notif.nent_optionb = msg_multi_notifs[optionb - 1];
863                                                 break;
864                                         }
865                                         case MSG_CHOICE: // should we REALLY allow nested options?...
866                                         {
867                                                 notif.nent_optiona = msg_choice_notifs[optiona - 1];
868                                                 notif.nent_optionb = msg_choice_notifs[optionb - 1];
869                                                 break;
870                                         }
871
872                                         default:
873                                         {
874                                                 LOG_INFOF(
875                                                         strcat(
876                                                                 "^1NOTIFICATION WITH IMPROPER TYPE: ",
877                                                                 "^7net_type = %d, net_name = %s.\n"
878                                                         ),
879                                                         typeId,
880                                                         namestring
881                                                 );
882                                                 notif_error = true;
883                                                 break;
884                                         }
885                                 }
886                                 notif.nent_challow_def = challow_def; // 0: never allowed, 1: allowed in warmup, 2: always allowed
887                                 notif.nent_challow_var = challow_var; // 0: never allowed, 1: allowed in warmup, 2: always allowed
888                                 notif.nent_stringcount = max(notif.nent_optiona.nent_stringcount, notif.nent_optionb.nent_stringcount);
889                                 notif.nent_floatcount = max(notif.nent_optiona.nent_floatcount, notif.nent_optionb.nent_floatcount);
890
891                                 /*#ifdef NOTIFICATIONS_DEBUG
892                                 Debug_Notification(sprintf(
893                                         "Create_Notification_Entity(...): MSG_CHOICE: %s\n%s\n%s\n",
894                                         notif.nent_name,
895                                         sprintf(
896                                                 "^ optiona: %s %s : %d %d",
897                                                 Get_Notif_TypeName(notif.nent_optiona.nent_type),
898                                                 notif.nent_optiona.nent_name,
899                                                 notif.nent_optiona.nent_stringcount,
900                                                 notif.nent_optiona.nent_floatcount
901                                         ),
902                                         sprintf(
903                                                 "^ optionb: %s %s : %d %d",
904                                                 Get_Notif_TypeName(notif.nent_optionb.nent_type),
905                                                 notif.nent_optionb.nent_name,
906                                                 notif.nent_optionb.nent_stringcount,
907                                                 notif.nent_optionb.nent_floatcount
908                                         )
909                                 ));
910                                 #endif*/
911                         }
912                         break;
913                 }
914
915                 default:
916                 {
917                         LOG_INFOF(
918                                 strcat(
919                                         "^1NOTIFICATION WITH IMPROPER TYPE: ",
920                                         "^7net_type = %d, net_name = %s.\n"
921                                 ),
922                                 typeId,
923                                 namestring
924                         );
925                         notif_error = true;
926                         break;
927                 }
928         }
929
930         // now check to see if any errors happened
931         if(notif_error)
932         {
933                 notif.nent_enabled = false; // disable the notification so it can't cause trouble
934                 notif_global_error = true; // throw the red flag that an error happened on init
935         }
936 }
937
938
939 // ===============
940 //  Cvar Handling
941 // ===============
942
943 // used by MSG_CHOICE to build list of choices
944 #ifdef SVQC
945 void Notification_GetCvars()
946 {
947         for(int i = 0; i <= NOTIF_CHOICE_COUNT; ++i)
948         {
949                 GetCvars_handleFloat(
950                         get_cvars_s,
951                         get_cvars_f,
952                         msg_choice_choices[i],
953                         sprintf("notification_%s", msg_choice_notifs[i].nent_name)
954                 );
955         }
956 }
957 #endif
958
959 // used to output notifications.cfg file
960 void Dump_Notifications(float fh, float alsoprint)
961 {
962         #define NOTIF_WRITE(a) { \
963                 fputs(fh, a); \
964                 if(alsoprint) { LOG_INFO(a); } }
965         #define NOTIF_WRITE_ENTITY(description) { \
966                 notif_msg = \
967                         sprintf( \
968                                 "seta notification_%s \"%d\" \"%s\"\n", \
969                                 e.nent_name, e.nent_default, description \
970                         ); \
971                 NOTIF_WRITE(notif_msg) }
972         #define NOTIF_WRITE_ENTITY_CHOICE(descriptiona,descriptionb) { \
973                 notif_msg = \
974                         sprintf( \
975                                 "seta notification_%s \"%d\" \"%s\"\n" \
976                                 "seta notification_%s_ALLOWED \"%d\" \"%s\"\n", \
977                                 e.nent_name, e.nent_default, descriptiona, \
978                                 e.nent_name, e.nent_challow_def, descriptionb \
979                         ); \
980                 NOTIF_WRITE(notif_msg) }
981         #define NOTIF_WRITE_HARDCODED(cvar,default,description) { \
982                 notif_msg = \
983                         sprintf( \
984                                 "seta notification_%s \"%s\" \"%s\"\n", \
985                                 cvar, default, description \
986                         ); \
987                 NOTIF_WRITE(notif_msg) }
988
989         string notif_msg;
990         int i;
991         entity e;
992
993         // Note: This warning only applies to the notifications.cfg file that is output...
994
995         // You ARE supposed to manually edit this function to add i.e. hard coded
996         // notification variables for mutators or game modes or such and then
997         // regenerate the notifications.cfg file from the new code.
998
999         NOTIF_WRITE("// ********************************************** //\n");
1000         NOTIF_WRITE("// ** WARNING - DO NOT MANUALLY EDIT THIS FILE ** //\n");
1001         NOTIF_WRITE("// **                                          ** //\n");
1002         NOTIF_WRITE("// **  This file is automatically generated    ** //\n");
1003         NOTIF_WRITE("// **  by code with the command 'dumpnotifs'.  ** //\n");
1004         NOTIF_WRITE("// **                                          ** //\n");
1005         NOTIF_WRITE("// **  If you add a new notification, please   ** //\n");
1006         NOTIF_WRITE("// **  regenerate this file with that command  ** //\n");
1007         NOTIF_WRITE("// **  making sure that the output matches     ** //\n");
1008         NOTIF_WRITE("// **  with the lists and defaults in code.    ** //\n");
1009         NOTIF_WRITE("// **                                          ** //\n");
1010         NOTIF_WRITE("// ********************************************** //\n");
1011
1012         // These notifications will also append their string as a comment...
1013         // This is not necessary, and does not matter if they vary between config versions,
1014         // it is just a semi-helpful tool for those who want to manually change their user settings.
1015
1016         NOTIF_WRITE(sprintf("\n// MSG_ANNCE notifications (count = %d):\n", NOTIF_ANNCE_COUNT));
1017         for(i = 1; i <= NOTIF_ANNCE_COUNT; ++i)
1018         {
1019                 e = Get_Notif_Ent(MSG_ANNCE, i);
1020                 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1021
1022                 NOTIF_WRITE_ENTITY(
1023                         "0 = disabled, 1 = enabled if gentle mode is off, 2 = always enabled"
1024                 );
1025         }
1026
1027         NOTIF_WRITE(sprintf("\n// MSG_INFO notifications (count = %d):\n", NOTIF_INFO_COUNT));
1028         for(i = 1; i <= NOTIF_INFO_COUNT; ++i)
1029         {
1030                 e = Get_Notif_Ent(MSG_INFO, i);
1031                 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1032
1033                 NOTIF_WRITE_ENTITY(
1034                         "0 = off, 1 = print to console, "
1035                         "2 = print to console and chatbox (if notification_allow_chatboxprint is enabled)"
1036                 );
1037         }
1038
1039         NOTIF_WRITE(sprintf("\n// MSG_CENTER notifications (count = %d):\n", NOTIF_CENTER_COUNT));
1040         for(i = 1; i <= NOTIF_CENTER_COUNT; ++i)
1041         {
1042                 e = Get_Notif_Ent(MSG_CENTER, i);
1043                 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1044
1045                 NOTIF_WRITE_ENTITY(
1046                         "0 = off, 1 = centerprint"
1047                 );
1048         }
1049
1050         NOTIF_WRITE(sprintf("\n// MSG_MULTI notifications (count = %d):\n", NOTIF_MULTI_COUNT));
1051         for(i = 1; i <= NOTIF_MULTI_COUNT; ++i)
1052         {
1053                 e = Get_Notif_Ent(MSG_MULTI, i);
1054                 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1055
1056                 NOTIF_WRITE_ENTITY(
1057                         "Enable this multiple notification"
1058                 );
1059         }
1060
1061         NOTIF_WRITE(sprintf("\n// MSG_CHOICE notifications (count = %d):\n", NOTIF_CHOICE_COUNT));
1062         for(i = 1; i <= NOTIF_CHOICE_COUNT; ++i)
1063         {
1064                 e = Get_Notif_Ent(MSG_CHOICE, i);
1065                 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1066
1067                 NOTIF_WRITE_ENTITY_CHOICE(
1068                         "Choice for this notification 0 = off, 1 = default message, 2 = verbose message",
1069                         "Allow choice for this notification 0 = off, 1 = only in warmup mode, 2 = always"
1070                 );
1071         }
1072
1073         // edit these to match whichever cvars are used for specific notification options
1074         NOTIF_WRITE("\n// HARD CODED notification variables:\n");
1075
1076         NOTIF_WRITE_HARDCODED(
1077                 "allow_chatboxprint", "1",
1078                 "Allow INFO notifications to be printed to chat box"
1079                 "0 = do not allow, "
1080                 "1 = allow only if allowed by individual notification_INFO* cvars, "
1081                 "2 = force all INFO notifications to be printed to the chatbox"
1082         );
1083
1084         NOTIF_WRITE_HARDCODED(
1085                 "debug", "0",
1086                 "Print extra debug information on all notification function calls "
1087                 "(Requires -DNOTIFICATIONS_DEBUG flag to be enabled on QCSRC compilation)... "
1088                 "0 = disabled, 1 = dprint, 2 = print"
1089         );
1090
1091         NOTIF_WRITE_HARDCODED(
1092                 "errors_are_fatal", "1",
1093                 "If a notification fails upon initialization, cause a Host_Error to stop the program"
1094         );
1095
1096         NOTIF_WRITE_HARDCODED(
1097                 "item_centerprinttime", "1.5",
1098                 "How long to show item information centerprint messages (like 'You got the Electro' or such)"
1099         );
1100
1101         NOTIF_WRITE_HARDCODED(
1102                 "lifetime_mapload", "10",
1103                 "Amount of time that notification entities last immediately at mapload (in seconds) "
1104                 "to help prevent notifications from being lost on early init (like gamestart countdown)"
1105         );
1106
1107         NOTIF_WRITE_HARDCODED(
1108                 "lifetime_runtime", "0.5",
1109                 "Amount of time that notification entities last on the server during runtime (In seconds)"
1110         );
1111
1112         NOTIF_WRITE_HARDCODED(
1113                 "server_allows_location", "1",
1114                 "Server side cvar for allowing death messages to show location information too"
1115         );
1116
1117         NOTIF_WRITE_HARDCODED(
1118                 "show_location", "0",
1119                 "Append location information to MSG_INFO death/kill messages"
1120         );
1121
1122         NOTIF_WRITE_HARDCODED(
1123                 "show_location_string", "",
1124                 "Replacement string piped into sprintf, "
1125                 "so you can do different messages like this: ' at the %s' or ' (near %s)'"
1126         );
1127
1128         NOTIF_WRITE_HARDCODED(
1129                 "show_sprees", "1",
1130                 "Print information about sprees in death/kill messages"
1131         );
1132
1133         NOTIF_WRITE_HARDCODED(
1134                 "show_sprees_center", "1",
1135                 "Show spree information in MSG_CENTER messages... "
1136                 "0 = off, 1 = target (but only for first victim) and attacker"
1137         );
1138
1139         NOTIF_WRITE_HARDCODED(
1140                 "show_sprees_center_specialonly", "1",
1141                 "Don't show spree information in MSG_CENTER messages if it isn't an achievement"
1142         );
1143
1144         NOTIF_WRITE_HARDCODED(
1145                 "show_sprees_info", "3",
1146                 "Show spree information in MSG_INFO messages... "
1147                 "0 = off, 1 = target only, 2 = attacker only, 3 = target and attacker"
1148         );
1149
1150         NOTIF_WRITE_HARDCODED(
1151                 "show_sprees_info_newline", "1",
1152                 "Show attacker spree information for MSG_INFO messages on a separate line than the death notification itself"
1153         );
1154
1155         NOTIF_WRITE_HARDCODED(
1156                 "show_sprees_info_specialonly", "1",
1157                 "Don't show attacker spree information in MSG_INFO messages if it isn't an achievement"
1158         );
1159
1160         NOTIF_WRITE(sprintf(
1161                 strcat(
1162                         "\n// Notification counts (total = %d): ",
1163                         "MSG_ANNCE = %d, MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d, MSG_CHOICE = %d\n"
1164                 ),
1165                 (
1166                         NOTIF_ANNCE_COUNT +
1167                         NOTIF_INFO_COUNT +
1168                         NOTIF_CENTER_COUNT +
1169                         NOTIF_MULTI_COUNT +
1170                         NOTIF_CHOICE_COUNT
1171                 ),
1172                 NOTIF_ANNCE_COUNT,
1173                 NOTIF_INFO_COUNT,
1174                 NOTIF_CENTER_COUNT,
1175                 NOTIF_MULTI_COUNT,
1176                 NOTIF_CHOICE_COUNT
1177         ));
1178
1179         return;
1180         #undef NOTIF_WRITE_HARDCODED
1181         #undef NOTIF_WRITE_ENTITY
1182         #undef NOTIF_WRITE
1183 }
1184
1185
1186 // ===============================
1187 //  Frontend Notification Pushing
1188 // ===============================
1189
1190 #ifdef NOTIFICATIONS_DEBUG
1191 void Debug_Notification(string input)
1192 {
1193         switch(autocvar_notification_debug)
1194         {
1195                 case 1: { LOG_TRACE(input); break; }
1196                 case 2: { LOG_INFO(input); break; }
1197         }
1198 }
1199 #endif
1200
1201 string Local_Notification_sprintf(
1202         string input, string args,
1203         string s1, string s2, string s3, string s4,
1204         int f1, float f2, float f3, float f4)
1205 {
1206         #ifdef NOTIFICATIONS_DEBUG
1207         Debug_Notification(sprintf(
1208                 "Local_Notification_sprintf('%s^7', '%s', %s, %s);\n",
1209                 MakeConsoleSafe(input),
1210                 args,
1211                 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1212                 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1213         ));
1214         #endif
1215
1216         string selected;
1217         int sel_num;
1218         for(sel_num = 0; sel_num < NOTIF_MAX_ARGS; ++sel_num) { arg_slot[sel_num] = ""; }
1219
1220         string tmp_s;
1221
1222         for(sel_num = 0;(args != "");)
1223         {
1224                 selected = car(args); args = cdr(args);
1225                 NOTIF_HIT_MAX(NOTIF_MAX_ARGS, "Local_Notification_sprintf");
1226                 switch(strtolower(selected))
1227                 {
1228                         #ifdef CSQC
1229                         #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1230                         #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1231                         #define ARG_CASE_ARG_CS_SV(selected,result)    case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1232                         #define ARG_CASE_ARG_CS(selected,result)       case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1233                         #define ARG_CASE_ARG_SV(selected,result)
1234                         #define ARG_CASE_ARG_DC(selected,result)
1235                         #else
1236                         #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1237                         #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1238                         #define ARG_CASE_ARG_CS_SV(selected,result)    case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1239                         #define ARG_CASE_ARG_CS(selected,result)
1240                         #define ARG_CASE_ARG_SV(selected,result)       case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1241                         #define ARG_CASE_ARG_DC(selected,result)
1242                         #endif
1243                         #define ARG_CASE(prog,selected,result)         ARG_CASE_##prog(selected,result)
1244                         NOTIF_ARGUMENT_LIST
1245                         #undef ARG_CASE
1246                         #undef ARG_CASE_ARG_DC
1247                         #undef ARG_CASE_ARG_SV
1248                         #undef ARG_CASE_ARG_CS
1249                         #undef ARG_CASE_ARG_CS_SV
1250                         #undef ARG_CASE_ARG_CS_SV_DC
1251                         #undef ARG_CASE_ARG_CS_SV_HA
1252                         default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
1253                 }
1254         }
1255         return sprintf(
1256                 strcat(input, "\n"),
1257                 arg_slot[0],
1258                 arg_slot[1],
1259                 arg_slot[2],
1260                 arg_slot[3],
1261                 arg_slot[4],
1262                 arg_slot[5],
1263                 arg_slot[6]
1264         );
1265 }
1266
1267 #ifdef CSQC
1268 void Local_Notification_sound(
1269         float soundchannel, string soundfile,
1270         float soundvolume, float soundposition)
1271 {
1272         if((soundfile != prev_soundfile) || (time >= (prev_soundtime + autocvar_cl_announcer_antispam)))
1273         {
1274                 #ifdef NOTIFICATIONS_DEBUG
1275                 Debug_Notification(sprintf(
1276                         "Local_Notification_sound(world, %f, '%s', %f, %f);\n",
1277                         soundchannel,
1278                         sprintf(
1279                                 "announcer/%s/%s.wav",
1280                                 AnnouncerOption(),
1281                                 soundfile
1282                         ),
1283                         soundvolume,
1284                         soundposition
1285                 ));
1286                 #endif
1287
1288                 _sound(
1289                         world,
1290                         soundchannel,
1291                         sprintf(
1292                                 "announcer/%s/%s.wav",
1293                                 AnnouncerOption(),
1294                                 soundfile
1295                         ),
1296                         soundvolume,
1297                         soundposition
1298                 );
1299
1300                 if(prev_soundfile) { strunzone(prev_soundfile); }
1301                 prev_soundfile = strzone(soundfile);
1302                 prev_soundtime = time;
1303         }
1304         else
1305         {
1306                 #ifdef NOTIFICATIONS_DEBUG
1307                 Debug_Notification(sprintf(
1308                         strcat(
1309                                 "Local_Notification_sound(world, %f, '%s', %f, %f) ",
1310                                 "^1BLOCKED BY ANTISPAM:^7 prevsnd: '%s', timediff: %f, limit: %f\n"
1311                          ),
1312                         soundchannel,
1313                         sprintf(
1314                                 "announcer/%s/%s.wav",
1315                                 AnnouncerOption(),
1316                                 soundfile
1317                         ),
1318                         soundvolume,
1319                         soundposition,
1320                         prev_soundfile,
1321                         (time - prev_soundtime),
1322                         autocvar_cl_announcer_antispam
1323                 ));
1324                 #endif
1325         }
1326 }
1327
1328 void Local_Notification_HUD_Notify_Push(
1329         string icon, string hudargs,
1330         string s1, string s2, string s3, string s4,
1331         float f1, float f2, float f3, float f4)
1332 {
1333         string selected;
1334         arg_slot[0] = ""; arg_slot[1] = "";
1335
1336         int sel_num;
1337         for(sel_num = 0;(hudargs != "");)
1338         {
1339                 selected = car(hudargs); hudargs = cdr(hudargs);
1340                 NOTIF_HIT_MAX(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push");
1341                 switch(strtolower(selected))
1342                 {
1343                         #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1344                         #define ARG_CASE_ARG_CS_SV_DC(selected,result)
1345                         #define ARG_CASE_ARG_CS_SV(selected,result)
1346                         #define ARG_CASE_ARG_CS(selected,result)
1347                         #define ARG_CASE_ARG_SV(selected,result)
1348                         #define ARG_CASE_ARG_DC(selected,result)
1349                         #define ARG_CASE(prog,selected,result)         ARG_CASE_##prog(selected,result)
1350                         NOTIF_ARGUMENT_LIST
1351                         #undef ARG_CASE
1352                         #undef ARG_CASE_ARG_DC
1353                         #undef ARG_CASE_ARG_SV
1354                         #undef ARG_CASE_ARG_CS
1355                         #undef ARG_CASE_ARG_CS_SV
1356                         #undef ARG_CASE_ARG_CS_SV_DC
1357                         #undef ARG_CASE_ARG_CS_SV_HA
1358                         default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
1359                 }
1360         }
1361         #ifdef NOTIFICATIONS_DEBUG
1362         Debug_Notification(sprintf(
1363                 "Local_Notification_HUD_Notify_Push('%s^7', '%s', %s, %s, %s);\n",
1364                 icon,
1365                 hudargs,
1366                 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1367                 sprintf("%d, %d, %d, %d", f1, f2, f3, f4),
1368                 MakeConsoleSafe(sprintf("'%s^7', '%s^7'", stof(arg_slot[0]), stof(arg_slot[1])))
1369         ));
1370         #endif
1371         HUD_Notify_Push(icon, arg_slot[0], arg_slot[1]);
1372 }
1373
1374 void Local_Notification_centerprint_generic(
1375         string input, string durcnt,
1376         int cpid, float f1, float f2)
1377 {
1378         arg_slot[0] = ""; arg_slot[1] = "";
1379
1380         for(int sel_num = 0;(durcnt != "");)
1381         {
1382                 string selected = car(durcnt); durcnt = cdr(durcnt);
1383                 NOTIF_HIT_MAX(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic");
1384                 switch(strtolower(selected))
1385                 {
1386                         #define ARG_CASE_ARG_CS_SV_HA(selected,result)
1387                         #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1388                         #define ARG_CASE_ARG_CS_SV(selected,result)
1389                         #define ARG_CASE_ARG_CS(selected,result)
1390                         #define ARG_CASE_ARG_SV(selected,result)
1391                         #define ARG_CASE_ARG_DC(selected,result)       case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1392                         #define ARG_CASE(prog,selected,result)         ARG_CASE_##prog(selected,result)
1393                         NOTIF_ARGUMENT_LIST
1394                         #undef ARG_CASE
1395                         #undef ARG_CASE_ARG_DC
1396                         #undef ARG_CASE_ARG_SV
1397                         #undef ARG_CASE_ARG_CS
1398                         #undef ARG_CASE_ARG_CS_SV
1399                         #undef ARG_CASE_ARG_CS_SV_DC
1400                         #undef ARG_CASE_ARG_CS_SV_HA
1401                         default:
1402                         {
1403                                 if(ftos(stof(selected)) != "") { arg_slot[sel_num] = selected; ++sel_num; }
1404                                 else { NOTIF_HIT_UNKNOWN(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic") }
1405                                 break;
1406                         }
1407                 }
1408         }
1409         #ifdef NOTIFICATIONS_DEBUG
1410         Debug_Notification(sprintf(
1411                 "Local_Notification_centerprint_generic('%s^7', '%s', %d, %d, %d, %d);\n",
1412                 MakeConsoleSafe(input),
1413                 durcnt,
1414                 f1, f2,
1415                 stof(arg_slot[0]),
1416                 stof(arg_slot[1])
1417         ));
1418         #endif
1419         centerprint_generic(cpid, input, stof(arg_slot[0]), stof(arg_slot[1]));
1420 }
1421 #endif
1422
1423 void Local_Notification(int net_type, int net_name, ...count)
1424 {
1425         // check if this should be aborted
1426         if(net_name == NOTIF_ABORT)
1427         {
1428                 #ifdef NOTIFICATIONS_DEBUG
1429                 Debug_Notification(sprintf(
1430                         "Local_Notification(%s, %s, ...);\n",
1431                         Get_Notif_TypeName(net_type),
1432                         "NOTIF_ABORT"
1433                 ));
1434                 #endif
1435                 return;
1436         }
1437
1438         // check supplied type and name for errors
1439         string checkargs = Notification_CheckArgs_TypeName(net_type, net_name);
1440         if(checkargs != "")
1441         {
1442                 #ifdef NOTIFICATIONS_DEBUG
1443                 Debug_Notification(sprintf(
1444                         "Local_Notification(%s, %d, ...);\n",
1445                         Get_Notif_TypeName(net_type),
1446                         Get_Notif_Ent(net_type, net_name).nent_name
1447                 ));
1448                 #endif
1449                 backtrace(sprintf("Incorrect usage of Local_Notification: %s\n", checkargs));
1450                 return;
1451         }
1452
1453         // retreive entity of this notification
1454         entity notif = Get_Notif_Ent(net_type, net_name);
1455         if (!notif)
1456         {
1457                 #ifdef NOTIFICATIONS_DEBUG
1458                 Debug_Notification(sprintf(
1459                         "Local_Notification(%s, %d, ...);\n",
1460                         Get_Notif_TypeName(net_type),
1461                         net_name
1462                 ));
1463                 #endif
1464                 backtrace("Local_Notification: Could not find notification entity!\n");
1465                 return;
1466         }
1467
1468         // check if the notification is enabled
1469         if (!notif.nent_enabled)
1470         {
1471                 #ifdef NOTIFICATIONS_DEBUG
1472                 Debug_Notification(sprintf(
1473                         "Local_Notification(%s, %s, ...): Entity was disabled...\n",
1474                         Get_Notif_TypeName(net_type),
1475                         notif.nent_name
1476                 ));
1477                 #endif
1478                 return;
1479         }
1480
1481         string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
1482         string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
1483         string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
1484         string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
1485         float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
1486         float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
1487         float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
1488         float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
1489
1490         #ifdef NOTIFICATIONS_DEBUG
1491         Debug_Notification(sprintf(
1492                 "Local_Notification(%s, %s, %s, %s);\n",
1493                 Get_Notif_TypeName(net_type),
1494                 notif.nent_name,
1495                 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1496                 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1497         ));
1498         #endif
1499
1500         if((notif.nent_stringcount + notif.nent_floatcount) > count)
1501         {
1502                 backtrace(sprintf(
1503                         strcat(
1504                                 "Not enough arguments for Local_Notification(%s, %s, ...)! ",
1505                                 "stringcount(%d) + floatcount(%d) > count(%d)\n",
1506                                 "Check the definition and function call for accuracy...?\n"
1507                         ),
1508                         Get_Notif_TypeName(net_type),
1509                         notif.nent_name,
1510                         notif.nent_stringcount,
1511                         notif.nent_floatcount,
1512                         count
1513                 ));
1514                 return;
1515         }
1516         else if((notif.nent_stringcount + notif.nent_floatcount) < count)
1517         {
1518                 backtrace(sprintf(
1519                         strcat(
1520                                 "Too many arguments for Local_Notification(%s, %s, ...)! ",
1521                                 "stringcount(%d) + floatcount(%d) < count(%d)\n",
1522                                 "Check the definition and function call for accuracy...?\n"
1523                         ),
1524                         Get_Notif_TypeName(net_type),
1525                         notif.nent_name,
1526                         notif.nent_stringcount,
1527                         notif.nent_floatcount,
1528                         count
1529                 ));
1530                 return;
1531         }
1532
1533         switch(net_type)
1534         {
1535                 case MSG_ANNCE:
1536                 {
1537                         #ifdef CSQC
1538                         Local_Notification_sound(
1539                                 notif.nent_channel,
1540                                 notif.nent_snd,
1541                                 notif.nent_vol,
1542                                 notif.nent_position
1543                         );
1544                         #else
1545                         backtrace("MSG_ANNCE on server?... Please notify Samual immediately!\n");
1546                         #endif
1547                         break;
1548                 }
1549
1550                 case MSG_INFO:
1551                 {
1552                         print(
1553                                 Local_Notification_sprintf(
1554                                         notif.nent_string,
1555                                         notif.nent_args,
1556                                         s1, s2, s3, s4,
1557                                         f1, f2, f3, f4)
1558                         );
1559                         #ifdef CSQC
1560                         if(notif.nent_icon != "")
1561                         {
1562                                 if ( notif.nent_iconargs != "" )
1563                                 {
1564                                         notif.nent_icon = Local_Notification_sprintf(
1565                                                 notif.nent_icon,notif.nent_iconargs,
1566                                                 s1, s2, s3, s4, f1, f2, f3, f4);
1567                                         // remove the newline added by Local_Notification_sprintf
1568                                         notif.nent_icon = strzone(substring(notif.nent_icon,0,strlen(notif.nent_icon)-1));
1569                                 }
1570                                 Local_Notification_HUD_Notify_Push(
1571                                         notif.nent_icon,
1572                                         notif.nent_hudargs,
1573                                         s1, s2, s3, s4,
1574                                         f1, f2, f3, f4);
1575                         }
1576                         #endif
1577                         break;
1578                 }
1579
1580                 #ifdef CSQC
1581                 case MSG_CENTER:
1582                 {
1583                         Local_Notification_centerprint_generic(
1584                                 Local_Notification_sprintf(
1585                                         notif.nent_string,
1586                                         notif.nent_args,
1587                                         s1, s2, s3, s4,
1588                                         f1, f2, f3, f4),
1589                                 notif.nent_durcnt,
1590                                 notif.nent_cpid,
1591                                 f1, f2);
1592                         break;
1593                 }
1594                 #endif
1595
1596                 case MSG_MULTI:
1597                 {
1598                         if(notif.nent_msginfo)
1599                         if(notif.nent_msginfo.nent_enabled)
1600                         {
1601                                 Local_Notification_WOVA(
1602                                         MSG_INFO,
1603                                         notif.nent_msginfo.nent_id,
1604                                         notif.nent_msginfo.nent_stringcount,
1605                                         notif.nent_msginfo.nent_floatcount,
1606                                         s1, s2, s3, s4,
1607                                         f1, f2, f3, f4);
1608                         }
1609                         #ifdef CSQC
1610                         if(notif.nent_msgannce)
1611                         if(notif.nent_msgannce.nent_enabled)
1612                         {
1613                                 Local_Notification_WOVA(
1614                                         MSG_ANNCE,
1615                                         notif.nent_msgannce.nent_id,
1616                                         0, 0,
1617                                         "", "", "", "",
1618                                         0, 0, 0, 0);
1619                         }
1620                         if(notif.nent_msgcenter)
1621                         if(notif.nent_msgcenter.nent_enabled)
1622                         {
1623                                 Local_Notification_WOVA(
1624                                         MSG_CENTER,
1625                                         notif.nent_msgcenter.nent_id,
1626                                         notif.nent_msgcenter.nent_stringcount,
1627                                         notif.nent_msgcenter.nent_floatcount,
1628                                         s1, s2, s3, s4,
1629                                         f1, f2, f3, f4);
1630                         }
1631                         #endif
1632                         break;
1633                 }
1634
1635                 case MSG_CHOICE:
1636                 {
1637                         entity found_choice;
1638
1639                         if(notif.nent_challow_var && (warmup_stage || (notif.nent_challow_var == 2)))
1640                         {
1641                                 switch(cvar(sprintf("notification_%s", notif.nent_name)))
1642                                 {
1643                                         case 1: found_choice = notif.nent_optiona; break;
1644                                         case 2: found_choice = notif.nent_optionb; break;
1645                                         default: return; // not enabled anyway
1646                                 }
1647                         }
1648                         else { found_choice = notif.nent_optiona; }
1649
1650                         Local_Notification_WOVA(
1651                                 found_choice.nent_type,
1652                                 found_choice.nent_id,
1653                                 found_choice.nent_stringcount,
1654                                 found_choice.nent_floatcount,
1655                                 s1, s2, s3, s4,
1656                                 f1, f2, f3, f4);
1657                 }
1658         }
1659 }
1660
1661 // WOVA = Without Variable Arguments
1662 void Local_Notification_WOVA(
1663         int net_type, float net_name,
1664         float stringcount, float floatcount,
1665         string s1, string s2, string s3, string s4,
1666         float f1, float f2, float f3, float f4)
1667 {
1668         #define VARITEM(stringc,floatc,args) \
1669                 if((stringcount == stringc) && (floatcount == floatc)) \
1670                         { Local_Notification(net_type, net_name, args); return; }
1671         EIGHT_VARS_TO_VARARGS_VARLIST
1672         #undef VARITEM
1673         Local_Notification(net_type, net_name); // some notifications don't have any arguments at all
1674 }
1675
1676
1677 // =========================
1678 //  Notification Networking
1679 // =========================
1680
1681 REGISTER_NET_LINKED(ENT_CLIENT_NOTIFICATION)
1682
1683 #ifdef CSQC
1684 NET_HANDLE(ENT_CLIENT_NOTIFICATION, bool is_new)
1685 {
1686         int net_type = ReadByte();
1687         int net_name = ReadShort();
1688         return = true;
1689
1690         entity notif;
1691
1692         if(net_type == MSG_CENTER_CPID)
1693         {
1694                 #ifdef NOTIFICATIONS_DEBUG
1695                 Debug_Notification(sprintf(
1696                         "Read_Notification(%d) at %f: net_type = %s, net_name = %d\n",
1697                         is_new,
1698                         time,
1699                         Get_Notif_TypeName(net_type),
1700                         net_name
1701                 ));
1702                 #endif
1703
1704                 if(is_new)
1705                 {
1706                         if(net_name == 0) { reset_centerprint_messages(); }
1707                         else if(net_name != NO_CPID)
1708                         {
1709                                 // in this case, net_name IS the cpid we want to kill
1710                                 centerprint_generic(net_name, "", 0, 0);
1711                         }
1712                         else
1713                         {
1714                                 backtrace(sprintf(
1715                                         "Read_Notification(%d) at %f: ^1TRIED TO KILL NO_CPID CENTERPRINT!\n",
1716                                         is_new,
1717                                         time
1718                                 ));
1719                         }
1720                 }
1721         }
1722         else
1723         {
1724                 notif = Get_Notif_Ent(net_type, net_name);
1725                 if (!notif) { backtrace("Read_Notification: Could not find notification entity!\n"); return; }
1726
1727                 #ifdef NOTIFICATIONS_DEBUG
1728                 Debug_Notification(sprintf(
1729                         "Read_Notification(%d) at %f: net_type = %s, net_name = %s\n",
1730                         is_new,
1731                         time,
1732                         Get_Notif_TypeName(net_type),
1733                         notif.nent_name
1734                 ));
1735                 #endif
1736
1737                 string s1 = ((0 < notif.nent_stringcount) ? ReadString() : "");
1738                 string s2 = ((1 < notif.nent_stringcount) ? ReadString() : "");
1739                 string s3 = ((2 < notif.nent_stringcount) ? ReadString() : "");
1740                 string s4 = ((3 < notif.nent_stringcount) ? ReadString() : "");
1741                 float f1 = ((0 < notif.nent_floatcount) ? ReadLong() : 0);
1742                 float f2 = ((1 < notif.nent_floatcount) ? ReadLong() : 0);
1743                 float f3 = ((2 < notif.nent_floatcount) ? ReadLong() : 0);
1744                 float f4 = ((3 < notif.nent_floatcount) ? ReadLong() : 0);
1745
1746                 if(is_new)
1747                 {
1748                         Local_Notification_WOVA(
1749                                 net_type, net_name,
1750                                 notif.nent_stringcount,
1751                                 notif.nent_floatcount,
1752                                 s1, s2, s3, s4,
1753                                 f1, f2, f3, f4);
1754                 }
1755         }
1756 }
1757 #endif
1758
1759 #ifdef SVQC
1760 void Net_Notification_Remove()
1761 {SELFPARAM();
1762         if (!self) { backtrace(sprintf("Net_Notification_Remove() at %f: Missing self!?\n", time)); return; }
1763
1764         #ifdef NOTIFICATIONS_DEBUG
1765         Debug_Notification(sprintf(
1766                 "Net_Notification_Remove() at %f: %s '%s - %s' notification\n",
1767                 time,
1768                 ((self.nent_net_name == -1) ? "Killed" : "Removed"),
1769                 Get_Notif_TypeName(self.nent_net_type),
1770                 self.owner.nent_name
1771         ));
1772         #endif
1773
1774         for(int i = 0; i < 4; ++i) { if(self.nent_strings[i]) { strunzone(self.nent_strings[i]); } }
1775         remove(self);
1776 }
1777
1778 bool Net_Write_Notification(entity this, entity client, int sf)
1779 {
1780         if(Notification_ShouldSend(self.nent_broadcast, client, self.nent_client))
1781         {
1782                 WriteHeader(MSG_ENTITY, ENT_CLIENT_NOTIFICATION);
1783                 WriteByte(MSG_ENTITY, self.nent_net_type);
1784                 WriteShort(MSG_ENTITY, self.nent_net_name);
1785                 for(int i = 0; i < self.nent_stringcount; ++i) { WriteString(MSG_ENTITY, self.nent_strings[i]); }
1786                 for(int i = 0; i < self.nent_floatcount; ++i) { WriteLong(MSG_ENTITY, self.nent_floats[i]); }
1787                 return true;
1788         }
1789         else { return false; }
1790 }
1791
1792 void Kill_Notification(
1793         float broadcast, entity client,
1794         float net_type, float net_name)
1795 {
1796         #ifdef NOTIFICATIONS_DEBUG
1797         Debug_Notification(sprintf(
1798                 "Kill_Notification(%s, '%s', %s, %d);\n",
1799                 Get_Notif_BroadcastName(broadcast),
1800                 client.netname,
1801                 (net_type ? Get_Notif_TypeName(net_type) : "0"),
1802                 net_name
1803         ));
1804         #endif
1805
1806         string checkargs = Notification_CheckArgs(broadcast, client, 1, 1);
1807         if(checkargs != "") { backtrace(sprintf("Incorrect usage of Kill_Notification: %s\n", checkargs)); return; }
1808
1809         entity notif, net_notif;
1810         float killed_cpid = NO_CPID;
1811
1812         switch(net_type)
1813         {
1814                 case 0:
1815                 {
1816                         killed_cpid = 0; // kill ALL centerprints
1817                         break;
1818                 }
1819
1820                 case MSG_CENTER:
1821                 {
1822                         if(net_name)
1823                         {
1824                                 entity notif = Get_Notif_Ent(net_type, net_name);
1825                                 if (!notif) { backtrace("Kill_Notification: Could not find notification entity!\n"); return; }
1826
1827                                 if(notif.nent_cpid)
1828                                         killed_cpid = notif.nent_cpid;
1829                                 else
1830                                         killed_cpid = NO_CPID;
1831                         }
1832                         else
1833                         {
1834                                 killed_cpid = 0; // kill ALL centerprints
1835                         }
1836                         break;
1837                 }
1838
1839                 case MSG_CENTER_CPID:
1840                 {
1841                         killed_cpid = net_name;
1842                         break;
1843                 }
1844         }
1845
1846         if(killed_cpid != NO_CPID)
1847         {
1848                 net_notif = new(net_kill_notification);
1849                 make_pure(net_notif);
1850                 net_notif.nent_broadcast = broadcast;
1851                 net_notif.nent_client = client;
1852                 net_notif.nent_net_type = MSG_CENTER_CPID;
1853                 net_notif.nent_net_name = killed_cpid;
1854                 Net_LinkEntity(net_notif, false, autocvar_notification_lifetime_runtime, Net_Write_Notification);
1855         }
1856
1857         for(notif = world; (notif = find(notif, classname, "net_notification"));)
1858         {
1859                 if(net_type)
1860                 {
1861                         if((killed_cpid != NO_CPID) && (notif.nent_net_type == MSG_CENTER))
1862                         {
1863                                 if(notif.owner.nent_cpid == killed_cpid)
1864                                 {
1865                                         notif.nent_net_name = -1;
1866                                         notif.nextthink = time;
1867                                 }
1868                                 else { continue; } // we ARE looking for a specific CPID, don't kill everything else too
1869                         }
1870                         else if(notif.nent_net_type == net_type)
1871                         {
1872                                 if(net_name)
1873                                 {
1874                                         if(notif.nent_net_name == net_name) { notif.nent_net_name = -1; notif.nextthink = time; }
1875                                         else { continue; } // we ARE looking for a certain net_name, don't kill everything else too
1876                                 }
1877                                 else { notif.nent_net_name = -1; notif.nextthink = time; }
1878                         }
1879                         else { continue; } // we ARE looking for a certain net_type, don't kill everything else too
1880                 }
1881                 else { notif.nent_net_name = -1; notif.nextthink = time; }
1882         }
1883 }
1884
1885 void Send_Notification(
1886         float broadcast, entity client,
1887         float net_type, float net_name,
1888         ...count)
1889 {
1890         // check if this should be aborted
1891         if(net_name == NOTIF_ABORT)
1892         {
1893                 #ifdef NOTIFICATIONS_DEBUG
1894                 Debug_Notification(sprintf(
1895                         "Send_Notification(%s, '%s', %s, %s, ...);\n",
1896                         Get_Notif_BroadcastName(broadcast),
1897                         client.classname,
1898                         Get_Notif_TypeName(net_type),
1899                         "NOTIF_ABORT"
1900                 ));
1901                 #endif
1902                 return;
1903         }
1904
1905         // check supplied broadcast, target, type, and name for errors
1906         string checkargs = Notification_CheckArgs(broadcast, client, net_type, net_name);
1907         if(checkargs != "")
1908         {
1909                 #ifdef NOTIFICATIONS_DEBUG
1910                 Debug_Notification(sprintf(
1911                         "Send_Notification(%s, '%s', %s, %s, ...);\n",
1912                         Get_Notif_BroadcastName(broadcast),
1913                         client.classname,
1914                         Get_Notif_TypeName(net_type),
1915                         Get_Notif_Ent(net_type, net_name).nent_name
1916                 ));
1917                 #endif
1918                 backtrace(sprintf("Incorrect usage of Send_Notification: %s\n", checkargs));
1919                 return;
1920         }
1921
1922         // retreive entity of this notification
1923         entity notif = Get_Notif_Ent(net_type, net_name);
1924         if (!notif)
1925         {
1926                 #ifdef NOTIFICATIONS_DEBUG
1927                 Debug_Notification(sprintf(
1928                         "Send_Notification(%s, '%s', %s, %d, ...);\n",
1929                         Get_Notif_BroadcastName(broadcast),
1930                         client.classname,
1931                         Get_Notif_TypeName(net_type),
1932                         net_name
1933                 ));
1934                 #endif
1935                 backtrace("Send_Notification: Could not find notification entity!\n");
1936                 return;
1937         }
1938
1939         string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
1940         string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
1941         string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
1942         string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
1943         float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
1944         float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
1945         float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
1946         float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
1947
1948         #ifdef NOTIFICATIONS_DEBUG
1949         Debug_Notification(sprintf(
1950                 "Send_Notification(%s, %s, %s);\n",
1951                 sprintf(
1952                         "%s, '%s', %s, %s",
1953                         Get_Notif_BroadcastName(broadcast),
1954                         client.classname,
1955                         Get_Notif_TypeName(net_type),
1956                         notif.nent_name
1957                 ),
1958                 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1959                 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1960         ));
1961         #endif
1962
1963         if((notif.nent_stringcount + notif.nent_floatcount) > count)
1964         {
1965                 string s =
1966                 #ifdef NOTIFICATIONS_DEBUG
1967                 Get_Notif_BroadcastName(broadcast);
1968                 #else
1969                 ftos(broadcast);
1970                 #endif
1971                 backtrace(sprintf(
1972                         strcat(
1973                                 "Not enough arguments for Send_Notification(%s, ...)! ",
1974                                 "stringcount(%d) + floatcount(%d) > count(%d)\n",
1975                                 "Check the definition and function call for accuracy...?\n"
1976                         ),
1977                         sprintf(
1978                                 "%s, '%s', %s, %s",
1979                                 s,
1980                                 client.classname,
1981                                 Get_Notif_TypeName(net_type),
1982                                 notif.nent_name
1983                         ),
1984                         notif.nent_stringcount,
1985                         notif.nent_floatcount,
1986                         count
1987                 ));
1988                 return;
1989         }
1990         else if((notif.nent_stringcount + notif.nent_floatcount) < count)
1991         {
1992                 string s =
1993                 #ifdef NOTIFICATIONS_DEBUG
1994                 Get_Notif_BroadcastName(broadcast);
1995                 #else
1996                 ftos(broadcast);
1997                 #endif
1998                 backtrace(sprintf(
1999                         strcat(
2000                                 "Too many arguments for Send_Notification(%s, ...)! ",
2001                                 "stringcount(%d) + floatcount(%d) < count(%d)\n",
2002                                 "Check the definition and function call for accuracy...?\n"
2003                         ),
2004                         sprintf(
2005                                 "%s, '%s', %s, %s",
2006                                 s,
2007                                 client.classname,
2008                                 Get_Notif_TypeName(net_type),
2009                                 notif.nent_name
2010                         ),
2011                         notif.nent_stringcount,
2012                         notif.nent_floatcount,
2013                         count
2014                 ));
2015                 return;
2016         }
2017
2018         if(
2019                 server_is_dedicated
2020                 &&
2021                 (
2022                         broadcast == NOTIF_ALL
2023                         ||
2024                         broadcast == NOTIF_ALL_EXCEPT
2025                 )
2026                 &&
2027                 !(
2028                         net_type == MSG_ANNCE
2029                         ||
2030                         net_type == MSG_CENTER
2031                 )
2032         )
2033         {
2034                 Local_Notification_WOVA(
2035                         net_type, net_name,
2036                         notif.nent_stringcount,
2037                         notif.nent_floatcount,
2038                         s1, s2, s3, s4,
2039                         f1, f2, f3, f4);
2040         }
2041
2042         if(net_type == MSG_CHOICE)
2043         {
2044                 // THIS GETS TRICKY... now we have to cycle through each possible player (checking broadcast)
2045                 // and then do an individual NOTIF_ONE_ONLY recursive call for each one depending on their option...
2046                 // It's slow, but it's better than the alternatives:
2047                 //   1. Constantly networking all info and letting client decide
2048                 //   2. Manually handling each separate call on per-usage basis (See old CTF usage of verbose)
2049                 entity found_choice;
2050
2051                 #define RECURSE_FROM_CHOICE(ent,action) MACRO_BEGIN { \
2052                         if(notif.nent_challow_var && (warmup_stage || (notif.nent_challow_var == 2))) \
2053                         { \
2054                                 switch(ent.msg_choice_choices[net_name - 1]) \
2055                                 { \
2056                                         case 1: found_choice = notif.nent_optiona; break; \
2057                                         case 2: found_choice = notif.nent_optionb; break; \
2058                                         default: action; \
2059                                 } \
2060                         } \
2061                         else { found_choice = notif.nent_optiona; } \
2062                         Send_Notification_WOVA( \
2063                                 NOTIF_ONE_ONLY, \
2064                                 ent, \
2065                                 found_choice.nent_type, \
2066                                 found_choice.nent_id, \
2067                                 found_choice.nent_stringcount, \
2068                                 found_choice.nent_floatcount, \
2069                                 s1, s2, s3, s4, \
2070                                 f1, f2, f3, f4); \
2071                 } MACRO_END
2072
2073                 switch(broadcast)
2074                 {
2075                         case NOTIF_ONE_ONLY: // we can potentially save processing power with this broadcast method
2076                         {
2077                                 if(IS_REAL_CLIENT(client))
2078                                 {
2079                                         RECURSE_FROM_CHOICE(client, return);
2080                                 }
2081                                 break;
2082                         }
2083                         default:
2084                         {
2085                                 FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(
2086                                         if(Notification_ShouldSend(broadcast, it, client))
2087                                         {
2088                                                 RECURSE_FROM_CHOICE(it, continue);
2089                                         }
2090                                 ));
2091                                 break;
2092                         }
2093                 }
2094         }
2095         else
2096         {
2097                 entity net_notif = new(net_notification);
2098                 make_pure(net_notif);
2099                 net_notif.owner = notif;
2100                 net_notif.nent_broadcast = broadcast;
2101                 net_notif.nent_client = client;
2102                 net_notif.nent_net_type = net_type;
2103                 net_notif.nent_net_name = net_name;
2104                 net_notif.nent_stringcount = notif.nent_stringcount;
2105                 net_notif.nent_floatcount = notif.nent_floatcount;
2106
2107                 for(int i = 0; i < net_notif.nent_stringcount; ++i)
2108                         { net_notif.nent_strings[i] = strzone(...(i, string)); }
2109                 for(int i = 0; i < net_notif.nent_floatcount; ++i)
2110                         { net_notif.nent_floats[i] = ...((net_notif.nent_stringcount + i), float); }
2111
2112                 net_notif.think = Net_Notification_Remove;
2113                 net_notif.nextthink =
2114                         ((time > autocvar_notification_lifetime_mapload)
2115                         ?
2116                                 (time + autocvar_notification_lifetime_runtime)
2117                                 :
2118                                 autocvar_notification_lifetime_mapload
2119                         );
2120
2121                 Net_LinkEntity(net_notif, false, 0, Net_Write_Notification);
2122         }
2123 }
2124
2125 // WOVA = Without Variable Arguments
2126 void Send_Notification_WOVA(
2127         float broadcast, entity client,
2128         float net_type, float net_name,
2129         float stringcount, float floatcount,
2130         string s1, string s2, string s3, string s4,
2131         float f1, float f2, float f3, float f4)
2132 {
2133         #ifdef NOTIFICATIONS_DEBUG
2134         entity notif = Get_Notif_Ent(net_type, net_name);
2135         Debug_Notification(sprintf(
2136                 "Send_Notification_WOVA(%s, %d, %d, %s, %s);\n",
2137                 sprintf(
2138                         "%s, '%s', %s, %s",
2139                         Get_Notif_BroadcastName(broadcast),
2140                         client.classname,
2141                         Get_Notif_TypeName(net_type),
2142                         notif.nent_name
2143                 ),
2144                 stringcount,
2145                 floatcount,
2146                 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
2147                 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
2148         ));
2149         #endif
2150
2151         #define VARITEM(stringc,floatc,args) \
2152                 if((stringcount == stringc) && (floatcount == floatc)) \
2153                         { Send_Notification(broadcast, client, net_type, net_name, args); return; }
2154         EIGHT_VARS_TO_VARARGS_VARLIST
2155         #undef VARITEM
2156         Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
2157 }
2158
2159 // WOCOVA = Without Counts Or Variable Arguments
2160 void Send_Notification_WOCOVA(
2161         float broadcast, entity client,
2162         float net_type, float net_name,
2163         string s1, string s2, string s3, string s4,
2164         float f1, float f2, float f3, float f4)
2165 {
2166         entity notif = Get_Notif_Ent(net_type, net_name);
2167
2168         #ifdef NOTIFICATIONS_DEBUG
2169         Debug_Notification(sprintf(
2170                 "Send_Notification_WOCOVA(%s, %s, %s);\n",
2171                 sprintf(
2172                         "%s, '%s', %s, %s",
2173                         Get_Notif_BroadcastName(broadcast),
2174                         client.classname,
2175                         Get_Notif_TypeName(net_type),
2176                         notif.nent_name
2177                 ),
2178                 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
2179                 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
2180         ));
2181         #endif
2182
2183         #define VARITEM(stringc,floatc,args) \
2184                 if((notif.nent_stringcount == stringc) && (notif.nent_floatcount == floatc)) \
2185                         { Send_Notification(broadcast, client, net_type, net_name, args); return; }
2186         EIGHT_VARS_TO_VARARGS_VARLIST
2187         #undef VARITEM
2188         Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
2189 }
2190 #endif // ifdef SVQC