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