]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/notifications/all.qc
Merge branch 'terencehill/notifications_fix' into 'master'
[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         FOREACH(Notifications, it.nent_type == MSG_CHOICE, {
764                 GetCvars_handleFloat(
765                         get_cvars_s,
766                         get_cvars_f,
767                         msg_choice_choices[it.nent_choice_idx],
768                         sprintf("notification_%s", it.nent_name)
769                 );
770         });
771 }
772 #endif
773
774 /** used to output notifications.cfg file */
775 void Dump_Notifications(int fh, bool alsoprint)
776 {
777         #define NOTIF_WRITE(a) MACRO_BEGIN { \
778                 fputs(fh, a); \
779                 if (alsoprint) LOG_INFO(a); \
780         } MACRO_END
781
782         #define NOTIF_WRITE_ENTITY(e, description) MACRO_BEGIN { \
783                 string notif_msg = sprintf( \
784                         "seta notification_%s \"%d\" \"%s\"\n", \
785                         e.nent_name, e.nent_default, description \
786                 ); \
787                 NOTIF_WRITE(notif_msg); \
788         } MACRO_END
789
790         #define NOTIF_WRITE_ENTITY_CHOICE(e, descriptiona, descriptionb) MACRO_BEGIN { \
791                 string notif_msg = sprintf( \
792                         "seta notification_%s \"%d\" \"%s\"\n" \
793                         "seta notification_%s_ALLOWED \"%d\" \"%s\"\n", \
794                         e.nent_name, e.nent_default, descriptiona, \
795                         e.nent_name, e.nent_challow_def, descriptionb \
796                 ); \
797                 NOTIF_WRITE(notif_msg); \
798         } MACRO_END
799
800         #define NOTIF_WRITE_HARDCODED(cvar, default, description) MACRO_BEGIN { \
801                 string notif_msg = sprintf( \
802                         "seta notification_%s \"%s\" \"%s\"\n", \
803                         cvar, default, description \
804                 ); \
805                 NOTIF_WRITE(notif_msg); \
806         } MACRO_END
807
808         // Note: This warning only applies to the notifications.cfg file that is output...
809         // You ARE supposed to manually edit this function to add i.e. hard coded
810         // notification variables for mutators or game modes or such and then
811         // regenerate the notifications.cfg file from the new code.
812
813         NOTIF_WRITE("// ********************************************** //\n");
814         NOTIF_WRITE("// ** WARNING - DO NOT MANUALLY EDIT THIS FILE ** //\n");
815         NOTIF_WRITE("// **                                          ** //\n");
816         NOTIF_WRITE("// **  This file is automatically generated    ** //\n");
817         NOTIF_WRITE("// **  by code with the command 'dumpnotifs'.  ** //\n");
818         NOTIF_WRITE("// **                                          ** //\n");
819         NOTIF_WRITE("// **  If you add a new notification, please   ** //\n");
820         NOTIF_WRITE("// **  regenerate this file with that command  ** //\n");
821         NOTIF_WRITE("// **  making sure that the output matches     ** //\n");
822         NOTIF_WRITE("// **  with the lists and defaults in code.    ** //\n");
823         NOTIF_WRITE("// **                                          ** //\n");
824         NOTIF_WRITE("// ********************************************** //\n");
825
826         // These notifications will also append their string as a comment...
827         // This is not necessary, and does not matter if they vary between config versions,
828         // it is just a semi-helpful tool for those who want to manually change their user settings.
829
830         int NOTIF_ANNCE_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_ANNCE, { ++NOTIF_ANNCE_COUNT; });
831         NOTIF_WRITE(sprintf("\n// MSG_ANNCE notifications (count = %d):\n", NOTIF_ANNCE_COUNT));
832         FOREACH(Notifications, it.nent_type == MSG_ANNCE, {
833                 NOTIF_WRITE_ENTITY(it,
834                         "0 = disabled, 1 = enabled if gentle mode is off, 2 = always enabled"
835                 );
836         });
837
838         int NOTIF_INFO_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_INFO, { ++NOTIF_INFO_COUNT; });
839         NOTIF_WRITE(sprintf("\n// MSG_INFO notifications (count = %d):\n", NOTIF_INFO_COUNT));
840         FOREACH(Notifications, it.nent_type == MSG_INFO, {
841                 NOTIF_WRITE_ENTITY(it,
842                         "0 = off, 1 = print to console, "
843                         "2 = print to console and chatbox (if notification_allow_chatboxprint is enabled)"
844                 );
845         });
846
847         int NOTIF_CENTER_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_CENTER, { ++NOTIF_CENTER_COUNT; });
848         NOTIF_WRITE(sprintf("\n// MSG_CENTER notifications (count = %d):\n", NOTIF_CENTER_COUNT));
849         FOREACH(Notifications, it.nent_type == MSG_CENTER, {
850                 NOTIF_WRITE_ENTITY(it,
851                         "0 = off, 1 = centerprint"
852                 );
853         });
854
855         int NOTIF_MULTI_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_MULTI, { ++NOTIF_MULTI_COUNT; });
856         NOTIF_WRITE(sprintf("\n// MSG_MULTI notifications (count = %d):\n", NOTIF_MULTI_COUNT));
857         FOREACH(Notifications, it.nent_type == MSG_MULTI, {
858                 NOTIF_WRITE_ENTITY(it,
859                         "Enable this multiple notification"
860                 );
861         });
862
863         int NOTIF_CHOICE_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_CHOICE, { ++NOTIF_CHOICE_COUNT; });
864         NOTIF_WRITE(sprintf("\n// MSG_CHOICE notifications (count = %d):\n", NOTIF_CHOICE_COUNT));
865         FOREACH(Notifications, it.nent_type == MSG_CHOICE, {
866                 NOTIF_WRITE_ENTITY_CHOICE(it,
867                         "Choice for this notification 0 = off, 1 = default message, 2 = verbose message",
868                         "Allow choice for this notification 0 = off, 1 = only in warmup mode, 2 = always"
869                 );
870         });
871
872         // edit these to match whichever cvars are used for specific notification options
873         NOTIF_WRITE("\n// HARD CODED notification variables:\n");
874
875         NOTIF_WRITE_HARDCODED(
876                 "allow_chatboxprint", "1",
877                 "Allow INFO notifications to be printed to chat box"
878                 "0 = do not allow, "
879                 "1 = allow only if allowed by individual notification_INFO* cvars, "
880                 "2 = force all INFO notifications to be printed to the chatbox"
881         );
882
883         NOTIF_WRITE_HARDCODED(
884                 "debug", "0",
885                 "Print extra debug information on all notification function calls "
886                 "(Requires -DNOTIFICATIONS_DEBUG flag to be enabled on QCSRC compilation)... "
887                 "0 = disabled, 1 = dprint, 2 = print"
888         );
889
890         NOTIF_WRITE_HARDCODED(
891                 "errors_are_fatal", "1",
892                 "If a notification fails upon initialization, cause a Host_Error to stop the program"
893         );
894
895         NOTIF_WRITE_HARDCODED(
896                 "item_centerprinttime", "1.5",
897                 "How long to show item information centerprint messages (like 'You got the Electro' or such)"
898         );
899
900         NOTIF_WRITE_HARDCODED(
901                 "lifetime_mapload", "10",
902                 "Amount of time that notification entities last immediately at mapload (in seconds) "
903                 "to help prevent notifications from being lost on early init (like gamestart countdown)"
904         );
905
906         NOTIF_WRITE_HARDCODED(
907                 "lifetime_runtime", "0.5",
908                 "Amount of time that notification entities last on the server during runtime (In seconds)"
909         );
910
911         NOTIF_WRITE_HARDCODED(
912                 "server_allows_location", "1",
913                 "Server side cvar for allowing death messages to show location information too"
914         );
915
916         NOTIF_WRITE_HARDCODED(
917                 "show_location", "0",
918                 "Append location information to MSG_INFO death/kill messages"
919         );
920
921         NOTIF_WRITE_HARDCODED(
922                 "show_location_string", "",
923                 "Replacement string piped into sprintf, "
924                 "so you can do different messages like this: ' at the %s' or ' (near %s)'"
925         );
926
927         NOTIF_WRITE_HARDCODED(
928                 "show_sprees", "1",
929                 "Print information about sprees in death/kill messages"
930         );
931
932         NOTIF_WRITE_HARDCODED(
933                 "show_sprees_center", "1",
934                 "Show spree information in MSG_CENTER messages... "
935                 "0 = off, 1 = target (but only for first victim) and attacker"
936         );
937
938         NOTIF_WRITE_HARDCODED(
939                 "show_sprees_center_specialonly", "1",
940                 "Don't show spree information in MSG_CENTER messages if it isn't an achievement"
941         );
942
943         NOTIF_WRITE_HARDCODED(
944                 "show_sprees_info", "3",
945                 "Show spree information in MSG_INFO messages... "
946                 "0 = off, 1 = target only, 2 = attacker only, 3 = target and attacker"
947         );
948
949         NOTIF_WRITE_HARDCODED(
950                 "show_sprees_info_newline", "1",
951                 "Show attacker spree information for MSG_INFO messages on a separate line than the death notification itself"
952         );
953
954         NOTIF_WRITE_HARDCODED(
955                 "show_sprees_info_specialonly", "1",
956                 "Don't show attacker spree information in MSG_INFO messages if it isn't an achievement"
957         );
958
959         NOTIF_WRITE(sprintf(
960                 (
961                         "\n// Notification counts (total = %d): "
962                         "MSG_ANNCE = %d, MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d, MSG_CHOICE = %d\n"
963                 ),
964                 (
965                         NOTIF_ANNCE_COUNT +
966                         NOTIF_INFO_COUNT +
967                         NOTIF_CENTER_COUNT +
968                         NOTIF_MULTI_COUNT +
969                         NOTIF_CHOICE_COUNT
970                 ),
971                 NOTIF_ANNCE_COUNT,
972                 NOTIF_INFO_COUNT,
973                 NOTIF_CENTER_COUNT,
974                 NOTIF_MULTI_COUNT,
975                 NOTIF_CHOICE_COUNT
976         ));
977         #undef NOTIF_WRITE_HARDCODED
978         #undef NOTIF_WRITE_ENTITY
979         #undef NOTIF_WRITE
980 }
981
982
983 // ===============================
984 //  Frontend Notification Pushing
985 // ===============================
986
987 string Local_Notification_sprintf(
988         string input, string args,
989         string s1, string s2, string s3, string s4,
990         int f1, float f2, float f3, float f4)
991 {
992         #ifdef NOTIFICATIONS_DEBUG
993         Debug_Notification(sprintf(
994                 "Local_Notification_sprintf('%s^7', '%s', %s, %s);\n",
995                 MakeConsoleSafe(input),
996                 args,
997                 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
998                 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
999         ));
1000         #endif
1001
1002         for (int sel_num = 0; sel_num < NOTIF_MAX_ARGS; ++sel_num) { arg_slot[sel_num] = ""; }
1003
1004         for (int sel_num = 0; (args != ""); )
1005         {
1006                 string selected = car(args); args = cdr(args);
1007                 NOTIF_HIT_MAX(NOTIF_MAX_ARGS, "Local_Notification_sprintf");
1008                 string tmp_s; // used by NOTIF_ARGUMENT_LIST
1009                 switch (strtolower(selected))
1010                 {
1011                         #define ARG_CASE_ARG_CS_SV_HA(selected, result) case selected: { arg_slot[sel_num++] = result; break; }
1012                         #define ARG_CASE_ARG_CS_SV_DC(selected, result) case selected: { arg_slot[sel_num++] = result; break; }
1013                         #define ARG_CASE_ARG_CS_SV(selected, result)    case selected: { arg_slot[sel_num++] = result; break; }
1014 #ifdef CSQC
1015                         #define ARG_CASE_ARG_CS(selected, result)       case selected: { arg_slot[sel_num++] = result; break; }
1016                         #define ARG_CASE_ARG_SV(selected, result)
1017 #else
1018                         #define ARG_CASE_ARG_CS(selected, result)
1019                         #define ARG_CASE_ARG_SV(selected, result)       case selected: { arg_slot[sel_num++] = result; break; }
1020 #endif
1021                         #define ARG_CASE_ARG_DC(selected, result)
1022                         #define ARG_CASE(prog, selected, result)        ARG_CASE_##prog(selected, result)
1023                         NOTIF_ARGUMENT_LIST
1024                         #undef ARG_CASE
1025                         #undef ARG_CASE_ARG_DC
1026                         #undef ARG_CASE_ARG_SV
1027                         #undef ARG_CASE_ARG_CS
1028                         #undef ARG_CASE_ARG_CS_SV
1029                         #undef ARG_CASE_ARG_CS_SV_DC
1030                         #undef ARG_CASE_ARG_CS_SV_HA
1031                         default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
1032                 }
1033         }
1034         return sprintf(
1035                 strcat(input, "\n"),
1036                 arg_slot[0],
1037                 arg_slot[1],
1038                 arg_slot[2],
1039                 arg_slot[3],
1040                 arg_slot[4],
1041                 arg_slot[5],
1042                 arg_slot[6]
1043         );
1044 }
1045
1046 #ifdef CSQC
1047 void Local_Notification_sound(
1048         int soundchannel, string soundfile,
1049         float soundvolume, float soundposition)
1050 {
1051         if ((soundfile != prev_soundfile) || (time >= (prev_soundtime + autocvar_cl_announcer_antispam)))
1052         {
1053                 #ifdef NOTIFICATIONS_DEBUG
1054                 Debug_Notification(sprintf(
1055                         "Local_Notification_sound(%f, '%s', %f, %f);\n",
1056                         soundchannel,
1057                         sprintf(
1058                                 "announcer/%s/%s.wav",
1059                                 AnnouncerOption(),
1060                                 soundfile
1061                         ),
1062                         soundvolume,
1063                         soundposition
1064                 ));
1065                 #endif
1066
1067                 _sound(
1068                         NULL,
1069                         soundchannel,
1070                         sprintf(
1071                                 "announcer/%s/%s.wav",
1072                                 AnnouncerOption(),
1073                                 soundfile
1074                         ),
1075                         soundvolume,
1076                         soundposition
1077                 );
1078
1079                 if (prev_soundfile) strunzone(prev_soundfile);
1080                 prev_soundfile = strzone(soundfile);
1081                 prev_soundtime = time;
1082         }
1083         else
1084         {
1085                 #ifdef NOTIFICATIONS_DEBUG
1086                 Debug_Notification(sprintf(
1087                         (
1088                                 "Local_Notification_sound(world, %f, '%s', %f, %f) "
1089                                 "^1BLOCKED BY ANTISPAM:^7 prevsnd: '%s', timediff: %f, limit: %f\n"
1090                          ),
1091                         soundchannel,
1092                         sprintf(
1093                                 "announcer/%s/%s.wav",
1094                                 AnnouncerOption(),
1095                                 soundfile
1096                         ),
1097                         soundvolume,
1098                         soundposition,
1099                         prev_soundfile,
1100                         (time - prev_soundtime),
1101                         autocvar_cl_announcer_antispam
1102                 ));
1103                 #endif
1104         }
1105 }
1106
1107 void Local_Notification_HUD_Notify_Push(
1108         string icon, string hudargs,
1109         string s1, string s2, string s3, string s4,
1110         float f1, float f2, float f3, float f4)
1111 {
1112         arg_slot[0] = ""; arg_slot[1] = "";
1113
1114         for (int sel_num = 0; (hudargs != ""); )
1115         {
1116                 string selected = car(hudargs); hudargs = cdr(hudargs);
1117                 NOTIF_HIT_MAX(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push");
1118                 switch (strtolower(selected))
1119                 {
1120                         #define ARG_CASE_ARG_CS_SV_HA(selected, result) case selected: { arg_slot[sel_num++] = result; break; }
1121                         #define ARG_CASE_ARG_CS_SV_DC(selected, result)
1122                         #define ARG_CASE_ARG_CS_SV(selected, result)
1123                         #define ARG_CASE_ARG_CS(selected, result)
1124                         #define ARG_CASE_ARG_SV(selected, result)
1125                         #define ARG_CASE_ARG_DC(selected, result)
1126                         #define ARG_CASE(prog, selected, result)        ARG_CASE_##prog(selected, result)
1127                         NOTIF_ARGUMENT_LIST
1128                         #undef ARG_CASE
1129                         #undef ARG_CASE_ARG_DC
1130                         #undef ARG_CASE_ARG_SV
1131                         #undef ARG_CASE_ARG_CS
1132                         #undef ARG_CASE_ARG_CS_SV
1133                         #undef ARG_CASE_ARG_CS_SV_DC
1134                         #undef ARG_CASE_ARG_CS_SV_HA
1135                         default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
1136                 }
1137         }
1138         #ifdef NOTIFICATIONS_DEBUG
1139         Debug_Notification(sprintf(
1140                 "Local_Notification_HUD_Notify_Push('%s^7', '%s', %s, %s, %s);\n",
1141                 icon,
1142                 hudargs,
1143                 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1144                 sprintf("%d, %d, %d, %d", f1, f2, f3, f4),
1145                 MakeConsoleSafe(sprintf("'%s^7', '%s^7'", stof(arg_slot[0]), stof(arg_slot[1])))
1146         ));
1147         #endif
1148         HUD_Notify_Push(icon, arg_slot[0], arg_slot[1]);
1149 }
1150
1151 void Local_Notification_centerprint_generic(
1152         string input, string durcnt,
1153         CPID cpid, float f1, float f2)
1154 {
1155         arg_slot[0] = ""; arg_slot[1] = "";
1156
1157         for (int sel_num = 0; (durcnt != ""); )
1158         {
1159                 string selected = car(durcnt); durcnt = cdr(durcnt);
1160                 NOTIF_HIT_MAX(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic");
1161                 switch (strtolower(selected))
1162                 {
1163                         #define ARG_CASE_ARG_CS_SV_HA(selected, result)
1164                         #define ARG_CASE_ARG_CS_SV_DC(selected, result) case selected: { arg_slot[sel_num++] = result; break; }
1165                         #define ARG_CASE_ARG_CS_SV(selected, result)
1166                         #define ARG_CASE_ARG_CS(selected, result)
1167                         #define ARG_CASE_ARG_SV(selected, result)
1168                         #define ARG_CASE_ARG_DC(selected, result)       case selected: { arg_slot[sel_num++] = result; break; }
1169                         #define ARG_CASE(prog, selected, result)        ARG_CASE_##prog(selected,result)
1170                         NOTIF_ARGUMENT_LIST
1171                         #undef ARG_CASE
1172                         #undef ARG_CASE_ARG_DC
1173                         #undef ARG_CASE_ARG_SV
1174                         #undef ARG_CASE_ARG_CS
1175                         #undef ARG_CASE_ARG_CS_SV
1176                         #undef ARG_CASE_ARG_CS_SV_DC
1177                         #undef ARG_CASE_ARG_CS_SV_HA
1178                         default:
1179                         {
1180                                 if (/* wtf */ ftos(stof(selected)) != "") { arg_slot[sel_num++] = selected; }
1181                                 else { NOTIF_HIT_UNKNOWN(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic") }
1182                                 break;
1183                         }
1184                 }
1185         }
1186         #ifdef NOTIFICATIONS_DEBUG
1187         Debug_Notification(sprintf(
1188                 "Local_Notification_centerprint_generic('%s^7', '%s', %d, %d, %d, %d);\n",
1189                 MakeConsoleSafe(input),
1190                 durcnt,
1191                 f1, f2,
1192                 stof(arg_slot[0]),
1193                 stof(arg_slot[1])
1194         ));
1195         #endif
1196         centerprint_generic(ORDINAL(cpid), input, stof(arg_slot[0]), stof(arg_slot[1]));
1197 }
1198 #endif
1199
1200 void Local_Notification(MSG net_type, Notification net_name, ...count)
1201 {
1202         // retreive entity of this notification
1203         entity notif = net_name;
1204         if (!notif)
1205         {
1206                 #ifdef NOTIFICATIONS_DEBUG
1207                 Debug_Notification(sprintf(
1208                         "Local_Notification(%s, NULL, ...);\n",
1209                         Get_Notif_TypeName(net_type)
1210                 ));
1211                 #endif
1212                 LOG_WARNINGF("Incorrect usage of Local_Notification: %s\n", "Null notification");
1213                 return;
1214         }
1215
1216         // check if the notification is enabled
1217         if (!notif.nent_enabled)
1218         {
1219                 #ifdef NOTIFICATIONS_DEBUG
1220                 Debug_Notification(sprintf(
1221                         "Local_Notification(%s, %s, ...): Entity was disabled...\n",
1222                         Get_Notif_TypeName(net_type),
1223                         notif.nent_name
1224                 ));
1225                 #endif
1226                 return;
1227         }
1228
1229         string s1 = ((notif.nent_stringcount > 0) ? ...(0, string) : "");
1230         string s2 = ((notif.nent_stringcount > 1) ? ...(1, string) : "");
1231         string s3 = ((notif.nent_stringcount > 2) ? ...(2, string) : "");
1232         string s4 = ((notif.nent_stringcount > 3) ? ...(3, string) : "");
1233         float f1 =  ((notif.nent_floatcount  > 0) ? ...((notif.nent_stringcount + 0), float) : 0);
1234         float f2 =  ((notif.nent_floatcount  > 1) ? ...((notif.nent_stringcount + 1), float) : 0);
1235         float f3 =  ((notif.nent_floatcount  > 2) ? ...((notif.nent_stringcount + 2), float) : 0);
1236         float f4 =  ((notif.nent_floatcount  > 3) ? ...((notif.nent_stringcount + 3), float) : 0);
1237
1238         #ifdef NOTIFICATIONS_DEBUG
1239         Debug_Notification(sprintf(
1240                 "Local_Notification(%s, %s, %s, %s);\n",
1241                 Get_Notif_TypeName(net_type),
1242                 notif.nent_name,
1243                 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1244                 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1245         ));
1246         #endif
1247
1248         if ((notif.nent_stringcount + notif.nent_floatcount) != count)
1249         {
1250                 backtrace(sprintf(
1251                         (
1252                                 "Arguments mismatch for Local_Notification(%s, %s, ...)! "
1253                                 "stringcount(%d) + floatcount(%d) != count(%d)\n"
1254                                 "Check the definition and function call for accuracy...?\n"
1255                         ),
1256                         Get_Notif_TypeName(net_type),
1257                         notif.nent_name,
1258                         notif.nent_stringcount,
1259                         notif.nent_floatcount,
1260                         count
1261                 ));
1262                 return;
1263         }
1264
1265         switch (net_type)
1266         {
1267                 case MSG_ANNCE:
1268                 {
1269                         #ifdef CSQC
1270                         Local_Notification_sound(
1271                                 notif.nent_channel,
1272                                 notif.nent_snd,
1273                                 notif.nent_vol,
1274                                 notif.nent_position
1275                         );
1276                         #else
1277                         backtrace("MSG_ANNCE on server?... Please notify Samual immediately!\n");
1278                         #endif
1279                         break;
1280                 }
1281
1282                 case MSG_INFO:
1283                 {
1284                         print(
1285                                 Local_Notification_sprintf(
1286                                         notif.nent_string,
1287                                         notif.nent_args,
1288                                         s1, s2, s3, s4,
1289                                         f1, f2, f3, f4)
1290                         );
1291                         #ifdef CSQC
1292                         if (notif.nent_icon != "")
1293                         {
1294                                 if (notif.nent_iconargs != "")
1295                                 {
1296                                         string s = Local_Notification_sprintf(
1297                                                 notif.nent_icon,notif.nent_iconargs,
1298                                                 s1, s2, s3, s4, f1, f2, f3, f4);
1299                                         // remove the trailing newline
1300                                         notif.nent_icon = strzone(substring(s, 0, -1));
1301                                 }
1302                                 Local_Notification_HUD_Notify_Push(
1303                                         notif.nent_icon,
1304                                         notif.nent_hudargs,
1305                                         s1, s2, s3, s4,
1306                                         f1, f2, f3, f4);
1307                         }
1308                         #endif
1309                         break;
1310                 }
1311
1312                 #ifdef CSQC
1313                 case MSG_CENTER:
1314                 {
1315                         Local_Notification_centerprint_generic(
1316                                 Local_Notification_sprintf(
1317                                         notif.nent_string,
1318                                         notif.nent_args,
1319                                         s1, s2, s3, s4,
1320                                         f1, f2, f3, f4),
1321                                 notif.nent_durcnt,
1322                                 notif.nent_cpid,
1323                                 f1, f2);
1324                         break;
1325                 }
1326                 #endif
1327
1328                 case MSG_MULTI:
1329                 {
1330                         if (notif.nent_msginfo && notif.nent_msginfo.nent_enabled)
1331                         {
1332                                 Local_Notification_WOVA(
1333                                         MSG_INFO,
1334                                         notif.nent_msginfo,
1335                                         notif.nent_msginfo.nent_stringcount,
1336                                         notif.nent_msginfo.nent_floatcount,
1337                                         s1, s2, s3, s4,
1338                                         f1, f2, f3, f4);
1339                         }
1340                         #ifdef CSQC
1341                         if (notif.nent_msgannce && notif.nent_msgannce.nent_enabled)
1342                         {
1343                                 Local_Notification_WOVA(
1344                                         MSG_ANNCE,
1345                                         notif.nent_msgannce,
1346                                         0, 0,
1347                                         "", "", "", "",
1348                                         0, 0, 0, 0);
1349                         }
1350                         if (notif.nent_msgcenter && notif.nent_msgcenter.nent_enabled)
1351                         {
1352                                 Local_Notification_WOVA(
1353                                         MSG_CENTER,
1354                                         notif.nent_msgcenter,
1355                                         notif.nent_msgcenter.nent_stringcount,
1356                                         notif.nent_msgcenter.nent_floatcount,
1357                                         s1, s2, s3, s4,
1358                                         f1, f2, f3, f4);
1359                         }
1360                         #endif
1361                         break;
1362                 }
1363
1364                 case MSG_CHOICE:
1365                 {
1366                         entity found_choice = notif.nent_optiona;
1367                         if (notif.nent_challow_var && (warmup_stage || (notif.nent_challow_var == 2))) {
1368                                 switch (cvar(sprintf("notification_%s", notif.nent_name)))
1369                                 {
1370                                         case 1: break;
1371                                         case 2: found_choice = notif.nent_optionb; break;
1372                                         default: return; // not enabled anyway
1373                                 }
1374                         }
1375
1376                         Local_Notification_WOVA(
1377                                 found_choice.nent_type,
1378                                 found_choice,
1379                                 found_choice.nent_stringcount,
1380                                 found_choice.nent_floatcount,
1381                                 s1, s2, s3, s4,
1382                                 f1, f2, f3, f4);
1383                 }
1384         }
1385 }
1386
1387 // WOVA = Without Variable Arguments
1388 void Local_Notification_WOVA(
1389         MSG net_type, Notification net_name,
1390         float stringcount, float floatcount,
1391         string s1, string s2, string s3, string s4,
1392         float f1, float f2, float f3, float f4)
1393 {
1394         #define VARITEM(stringc, floatc, args) \
1395                 if ((stringcount == stringc) && (floatcount == floatc)) \
1396                 { Local_Notification(net_type, net_name, args); return; }
1397         EIGHT_VARS_TO_VARARGS_VARLIST
1398         #undef VARITEM
1399         Local_Notification(net_type, net_name); // some notifications don't have any arguments at all
1400 }
1401
1402
1403 // =========================
1404 //  Notification Networking
1405 // =========================
1406
1407 /** networked as a linked entity to give newly connecting clients some notification context */
1408 REGISTER_NET_LINKED(ENT_CLIENT_NOTIFICATION)
1409
1410 #ifdef CSQC
1411 NET_HANDLE(ENT_CLIENT_NOTIFICATION, bool is_new)
1412 {
1413         make_pure(this);
1414         MSG net_type = ENUMCAST(MSG, ReadByte());
1415         int net_name = ReadShort();
1416     return = true;
1417
1418         if (net_type == MSG_CENTER_KILL)
1419     {
1420         if (!is_new) return;
1421         // killing
1422         #ifdef NOTIFICATIONS_DEBUG
1423         Debug_Notification(sprintf(
1424             "Read_Notification(%d) at %f: net_type = %s, cpid = %d\n",
1425             is_new,
1426             time,
1427             Get_Notif_TypeName(net_type),
1428             net_name
1429         ));
1430         #endif
1431         int _net_name = net_name;
1432         CPID net_name = ENUMCAST(CPID, _net_name);
1433         if (net_name == CPID_Null) {
1434             // kill all
1435             reset_centerprint_messages();
1436         } else {
1437             // kill group
1438             centerprint_generic(ORDINAL(net_name), "", 0, 0);
1439         }
1440         return;
1441     }
1442
1443         Notification notif = Get_Notif_Ent(net_type, net_name);
1444
1445         #ifdef NOTIFICATIONS_DEBUG
1446         Debug_Notification(sprintf(
1447                 "Read_Notification(%d) at %f: net_type = %s, net_name = %s (%d)\n",
1448                 is_new,
1449                 time,
1450                 Get_Notif_TypeName(net_type),
1451                 notif.registered_id,
1452                 net_name
1453         ));
1454         #endif
1455
1456     if (!notif) {
1457         backtrace("Read_Notification: Could not find notification entity!\n");
1458         return false;
1459     }
1460
1461     string s1 = ((notif.nent_stringcount > 0) ? ReadString() : "");
1462     string s2 = ((notif.nent_stringcount > 1) ? ReadString() : "");
1463     string s3 = ((notif.nent_stringcount > 2) ? ReadString() : "");
1464     string s4 = ((notif.nent_stringcount > 3) ? ReadString() : "");
1465     float f1 = ((notif.nent_floatcount > 0) ? ReadLong() : 0);
1466     float f2 = ((notif.nent_floatcount > 1) ? ReadLong() : 0);
1467     float f3 = ((notif.nent_floatcount > 2) ? ReadLong() : 0);
1468     float f4 = ((notif.nent_floatcount > 3) ? ReadLong() : 0);
1469
1470     if (!is_new) return;
1471     Local_Notification_WOVA(
1472         net_type, notif,
1473         notif.nent_stringcount,
1474         notif.nent_floatcount,
1475         s1, s2, s3, s4,
1476         f1, f2, f3, f4);
1477 }
1478 #endif
1479
1480 #ifdef SVQC
1481 void Net_Notification_Remove()
1482 {
1483         SELFPARAM();
1484         #ifdef NOTIFICATIONS_DEBUG
1485         Debug_Notification(sprintf(
1486                 "Net_Notification_Remove() at %f: %s '%s - %s' notification\n",
1487                 time,
1488                 ((this.nent_net_name == -1) ? "Killed" : "Removed"),
1489                 Get_Notif_TypeName(this.nent_net_type),
1490                 this.owner.nent_name
1491         ));
1492         #endif
1493         for (int i = 0; i < this.nent_stringcount; ++i) { if (this.nent_strings[i]) strunzone(this.nent_strings[i]); }
1494         remove(this);
1495 }
1496
1497 bool Net_Write_Notification(entity this, entity client, int sf)
1498 {
1499         if (!Notification_ShouldSend(this.nent_broadcast, client, this.nent_client)) return false;
1500         WriteHeader(MSG_ENTITY, ENT_CLIENT_NOTIFICATION);
1501         WriteByte(MSG_ENTITY, ORDINAL(this.nent_net_type));
1502         WriteShort(MSG_ENTITY, this.nent_net_name);
1503         for (int i = 0; i < this.nent_stringcount; ++i) { WriteString(MSG_ENTITY, this.nent_strings[i]); }
1504         for (int i = 0; i < this.nent_floatcount; ++i) { WriteLong(MSG_ENTITY, this.nent_floats[i]); }
1505         return true;
1506 }
1507
1508 void Kill_Notification(
1509         NOTIF broadcast, entity client,
1510         /** message group, MSG_Null for all */
1511         MSG net_type,
1512         /** cpid group, CPID_Null for all */
1513         CPID net_cpid)
1514 {
1515         #ifdef NOTIFICATIONS_DEBUG
1516         Debug_Notification(sprintf(
1517                 "Kill_Notification(%s, '%s', %s, %d);\n",
1518                 Get_Notif_BroadcastName(broadcast),
1519                 client.netname,
1520                 (net_type ? Get_Notif_TypeName(net_type) : "0"),
1521                 net_cpid
1522         ));
1523         #endif
1524
1525         string checkargs = Notification_CheckArgs(broadcast, client);
1526         if (checkargs != "") { LOG_WARNINGF("Incorrect usage of Kill_Notification: %s", checkargs); return; }
1527
1528         entity net_notif = new_pure(net_kill_notification);
1529         net_notif.nent_broadcast = broadcast;
1530         net_notif.nent_client = client;
1531         net_notif.nent_net_type = MSG_CENTER_KILL;
1532         net_notif.nent_net_name = ORDINAL(net_cpid);
1533         Net_LinkEntity(net_notif, false, autocvar_notification_lifetime_runtime, Net_Write_Notification);
1534
1535         FOREACH_ENTITY_CLASS(
1536                 "net_notification",
1537                 (it.owner.nent_type == net_type || net_type == MSG_Null) && (it.owner.nent_cpid == net_cpid || net_cpid == CPID_Null),
1538                 {
1539                         it.nent_net_name = -1;
1540                         it.nextthink = time;
1541                 }
1542         );
1543 }
1544
1545 void Send_Notification(
1546         NOTIF broadcast, entity client,
1547         MSG net_type, Notification net_name,
1548         ...count)
1549 {
1550     if (broadcast != NOTIF_ALL && broadcast != NOTIF_ALL_EXCEPT && !IS_REAL_CLIENT(client)) return;
1551         entity notif = net_name;
1552         string parms = sprintf("%s, '%s', %s, %s",
1553                 Get_Notif_BroadcastName(broadcast),
1554                 client.classname,
1555                 Get_Notif_TypeName(net_type),
1556                 net_name.registered_id
1557         );
1558         #ifdef NOTIFICATIONS_DEBUG
1559         Debug_Notification(sprintf("Send_Notification(%s, ...%d);\n", parms, count));
1560         #endif
1561
1562         if (!notif)
1563         {
1564                 LOG_WARNING("Send_Notification: Could not find notification entity!");
1565                 return;
1566         }
1567
1568         // check supplied broadcast, target, type, and name for errors
1569         string checkargs = Notification_CheckArgs(broadcast, client);
1570     if (!net_name) { checkargs = sprintf("No notification provided! %s", checkargs); }
1571         if (checkargs != "")
1572         {
1573                 LOG_WARNINGF("Incorrect usage of Send_Notification: %s", checkargs);
1574                 return;
1575         }
1576
1577         string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
1578         string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
1579         string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
1580         string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
1581         float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
1582         float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
1583         float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
1584         float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
1585
1586         #ifdef NOTIFICATIONS_DEBUG
1587         Debug_Notification(sprintf(
1588                 "Send_Notification(%s, %s, %s);\n",
1589                 parms,
1590                 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1591                 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1592         ));
1593         #endif
1594
1595         if ((notif.nent_stringcount + notif.nent_floatcount) != count)
1596         {
1597                 LOG_WARNINGF(
1598                         "Argument mismatch for Send_Notification(%s, ...)! "
1599                         "stringcount(%d) + floatcount(%d) != count(%d)\n"
1600                         "Check the definition and function call for accuracy...?\n",
1601                         parms,
1602                         notif.nent_stringcount,
1603                         notif.nent_floatcount,
1604                         count
1605                 );
1606                 return;
1607         }
1608
1609         if (
1610                 server_is_dedicated
1611                 &&
1612                 (
1613                         broadcast == NOTIF_ALL
1614                         ||
1615                         broadcast == NOTIF_ALL_EXCEPT
1616                 )
1617                 &&
1618                 !(
1619                         net_type == MSG_ANNCE
1620                         ||
1621                         net_type == MSG_CENTER
1622                 )
1623         )
1624         {
1625                 Local_Notification_WOVA(
1626                         net_type, net_name,
1627                         notif.nent_stringcount,
1628                         notif.nent_floatcount,
1629                         s1, s2, s3, s4,
1630                         f1, f2, f3, f4);
1631         }
1632
1633         if (net_type == MSG_CHOICE)
1634         {
1635                 // THIS GETS TRICKY... now we have to cycle through each possible player (checking broadcast)
1636                 // and then do an individual NOTIF_ONE_ONLY recursive call for each one depending on their option...
1637                 // It's slow, but it's better than the alternatives:
1638                 //   1. Constantly networking all info and letting client decide
1639                 //   2. Manually handling each separate call on per-usage basis (See old CTF usage of verbose)
1640                 entity found_choice;
1641
1642                 #define RECURSE_FROM_CHOICE(ent,action) MACRO_BEGIN { \
1643                         if (notif.nent_challow_var && (warmup_stage || (notif.nent_challow_var == 2))) { \
1644                                 switch (ent.msg_choice_choices[net_name.nent_choice_idx]) \
1645                                 { \
1646                                         case 1: found_choice = notif.nent_optiona; break; \
1647                                         case 2: found_choice = notif.nent_optionb; break; \
1648                                         default: action; \
1649                                 } \
1650                         } else { \
1651                                 found_choice = notif.nent_optiona; \
1652                         } \
1653                         Send_Notification_WOVA( \
1654                                 NOTIF_ONE_ONLY, \
1655                                 ent, \
1656                                 found_choice.nent_type, \
1657                                 found_choice, \
1658                                 found_choice.nent_stringcount, \
1659                                 found_choice.nent_floatcount, \
1660                                 s1, s2, s3, s4, \
1661                                 f1, f2, f3, f4); \
1662                 } MACRO_END
1663
1664                 switch (broadcast)
1665                 {
1666                         case NOTIF_ONE_ONLY: // we can potentially save processing power with this broadcast method
1667                         {
1668                                 if (IS_REAL_CLIENT(client)) {
1669                                         RECURSE_FROM_CHOICE(client, return);
1670                                 }
1671                                 break;
1672                         }
1673                         default:
1674                         {
1675                                 FOREACH_CLIENT(IS_REAL_CLIENT(it) && Notification_ShouldSend(broadcast, it, client), {
1676                                         RECURSE_FROM_CHOICE(it, continue);
1677                                 });
1678                                 break;
1679                         }
1680                 }
1681         }
1682         else
1683         {
1684                 entity net_notif = new_pure(net_notification);
1685                 net_notif.owner = notif;
1686                 net_notif.nent_broadcast = broadcast;
1687                 net_notif.nent_client = client;
1688                 net_notif.nent_net_type = net_type;
1689                 net_notif.nent_net_name = notif.m_id;
1690                 net_notif.nent_stringcount = notif.nent_stringcount;
1691                 net_notif.nent_floatcount = notif.nent_floatcount;
1692
1693                 for (int i = 0; i < net_notif.nent_stringcount; ++i) {
1694                         net_notif.nent_strings[i] = strzone(...(i, string));
1695                 }
1696                 for (int i = 0; i < net_notif.nent_floatcount; ++i) {
1697                         net_notif.nent_floats[i] = ...((net_notif.nent_stringcount + i), float);
1698                 }
1699
1700                 net_notif.think = Net_Notification_Remove;
1701                 net_notif.nextthink = (time > autocvar_notification_lifetime_mapload)
1702                         ? (time + autocvar_notification_lifetime_runtime)
1703                         : autocvar_notification_lifetime_mapload;
1704
1705                 Net_LinkEntity(net_notif, false, 0, Net_Write_Notification);
1706         }
1707 }
1708
1709 // WOVA = Without Variable Arguments
1710 void Send_Notification_WOVA(
1711         NOTIF broadcast, entity client,
1712         MSG net_type, Notification net_name,
1713         float stringcount, float floatcount,
1714         string s1, string s2, string s3, string s4,
1715         float f1, float f2, float f3, float f4)
1716 {
1717         #ifdef NOTIFICATIONS_DEBUG
1718         entity notif = net_name;
1719         Debug_Notification(sprintf(
1720                 "Send_Notification_WOVA(%s, %d, %d, %s, %s);\n",
1721                 sprintf(
1722                         "%s, '%s', %s, %s",
1723                         Get_Notif_BroadcastName(broadcast),
1724                         client.classname,
1725                         Get_Notif_TypeName(net_type),
1726                         notif.nent_name
1727                 ),
1728                 stringcount,
1729                 floatcount,
1730                 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1731                 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1732         ));
1733         #endif
1734
1735         #define VARITEM(stringc, floatc, args) \
1736                 if ((stringcount == stringc) && (floatcount == floatc)) \
1737                 { Send_Notification(broadcast, client, net_type, net_name, args); return; }
1738         EIGHT_VARS_TO_VARARGS_VARLIST
1739         #undef VARITEM
1740         Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
1741 }
1742
1743 // WOCOVA = Without Counts Or Variable Arguments
1744 void Send_Notification_WOCOVA(
1745         NOTIF broadcast, entity client,
1746         MSG net_type, Notification net_name,
1747         string s1, string s2, string s3, string s4,
1748         float f1, float f2, float f3, float f4)
1749 {
1750         entity notif = net_name;
1751
1752         #ifdef NOTIFICATIONS_DEBUG
1753         Debug_Notification(sprintf(
1754                 "Send_Notification_WOCOVA(%s, %s, %s);\n",
1755                 sprintf(
1756                         "%s, '%s', %s, %s",
1757                         Get_Notif_BroadcastName(broadcast),
1758                         client.classname,
1759                         Get_Notif_TypeName(net_type),
1760                         notif.nent_name
1761                 ),
1762                 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1763                 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1764         ));
1765         #endif
1766
1767         #define VARITEM(stringc, floatc, args) \
1768                 if ((notif.nent_stringcount == stringc) && (notif.nent_floatcount == floatc)) \
1769                 { Send_Notification(broadcast, client, net_type, net_name, args); return; }
1770         EIGHT_VARS_TO_VARARGS_VARLIST
1771         #undef VARITEM
1772         Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
1773 }
1774 #endif // ifdef SVQC