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