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