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