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