3 #include <client/announcer.qh>
6 #include <common/constants.qh>
7 #include <common/net_linked.qh>
8 #include <common/teams.qh>
9 #include <server/autocvars.qh>
10 #include <server/constants.qh>
11 #include <server/defs.qh>
12 #include <server/mutators/_mod.qh>
15 // ================================================
16 // Unified notification system, written by Samual
17 // Last updated: August, 2013
18 // ================================================
21 string Notification_CheckArgs(
22 NOTIF broadcast, entity client)
24 // check supplied broadcast and target for errors
30 if (IS_NOT_A_CLIENT(client)) {
31 return "No client provided!";
36 case NOTIF_ALL_EXCEPT:
38 if (IS_NOT_A_CLIENT(client)) {
39 return "Exception can't be a non-client!";
47 return "Entity provided when NULL was required!";
55 return "Teamplay not active!";
56 } else if (!client.team) {
57 // checkargs = sprintf("%sNo team provided!", checkargs);
62 case NOTIF_TEAM_EXCEPT:
65 return "Teamplay not active!";
66 } else if (IS_NOT_A_CLIENT(client)) {
67 return "Exception can't be a non-client!";
74 return sprintf("Improper broadcast: %d!", broadcast);
80 bool Notification_ShouldSend(NOTIF broadcast, entity to_client, entity other_client)
86 (to_client == other_client)
91 (to_client.enemy == other_client)
95 return (to_client == other_client);
98 (to_client.team == other_client.team)
103 (to_client.enemy.team == other_client.team)
106 case NOTIF_TEAM_EXCEPT:
108 (to_client != other_client)
111 (to_client.team == other_client.team)
117 (to_client.enemy != other_client)
119 (to_client.enemy.team == other_client.team)
126 case NOTIF_ALL_EXCEPT:
128 (to_client != other_client)
133 (to_client.enemy == other_client)
143 // ===============================
144 // Initialization Core Functions
145 // ===============================
147 // used by restartnotifs command to initialize notifications
148 void Destroy_Notification_Entity(entity notif)
150 if (notif.nent_name != "") strunzone(notif.nent_name);
151 if (notif.nent_snd != "") strunzone(notif.nent_snd);
152 if (notif.nent_args != "") strunzone(notif.nent_args);
153 if (notif.nent_hudargs != "") strunzone(notif.nent_hudargs);
154 if (notif.nent_icon != "") strunzone(notif.nent_icon);
155 if (notif.nent_durcnt != "") strunzone(notif.nent_durcnt);
156 if (notif.nent_string != "") strunzone(notif.nent_string);
160 void Destroy_All_Notifications()
162 // kill all networked notifications and centerprints
164 Kill_Notification(NOTIF_ALL, NULL, MSG_Null, CPID_Null);
166 reset_centerprint_messages();
169 // kill all real notification entities
170 FOREACH(Notifications, true, { Destroy_Notification_Entity(it); });
173 string Process_Notif_Line(
182 if(typeId == MSG_INFO)
184 if((chat && autocvar_notification_allow_chatboxprint)
185 || (autocvar_notification_allow_chatboxprint == 2))
187 // pass 1: add ETX char at beginning of line
188 input = strcat("\{3}", input);
190 // pass 2: add ETX char at end of each new line (so that
191 // messages with multiple lines are put through chatbox too)
192 input = strreplace("\n", "\n\{3}", input);
194 // pass 3: strip trailing ETX char
195 if(substring(input, (strlen(input) - 1), 1) == "\{3}")
196 { input = substring(input, 0, (strlen(input) - 1)); }
201 // done to both MSG_INFO and MSG_CENTER
202 if(substring(input, (strlen(input) - 1), 1) == "\n")
206 "^1TRAILING NEW LINE AT END OF NOTIFICATION: "
207 "^7net_type = %s, net_name = %s, string = %s.\n"
214 input = substring(input, 1, (strlen(input) - 1));
220 string Process_Notif_Args(
226 string selected, remaining = args;
229 for (;(remaining != "");)
231 selected = car(remaining); remaining = cdr(remaining);
235 case 1: // normal args
237 if(sel_num == NOTIF_MAX_ARGS)
241 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: "
242 "^7net_type = %s, net_name = %s, max args = %d.\n"
252 switch(strtolower(selected))
254 #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { ++sel_num; break; }
255 #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { ++sel_num; break; }
256 #define ARG_CASE_ARG_CS_SV(selected,result) case selected: { ++sel_num; break; }
257 #define ARG_CASE_ARG_CS(selected,result) case selected: { ++sel_num; break; }
258 #define ARG_CASE_ARG_SV(selected,result) case selected: { ++sel_num; break; }
259 #define ARG_CASE_ARG_DC(selected,result)
260 #define ARG_CASE(prog,selected,result) ARG_CASE_##prog(selected,result)
263 #undef ARG_CASE_ARG_DC
264 #undef ARG_CASE_ARG_SV
265 #undef ARG_CASE_ARG_CS
266 #undef ARG_CASE_ARG_CS_SV
267 #undef ARG_CASE_ARG_CS_SV_DC
268 #undef ARG_CASE_ARG_CS_SV_HA
273 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: "
274 "^7net_type = %s, net_name = %s, args arg = '%s'.\n"
288 if(sel_num == NOTIF_MAX_HUDARGS)
292 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: "
293 "^7net_type = %s, net_name = %s, max hudargs = %d.\n"
303 switch(strtolower(selected))
305 #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { ++sel_num; break; }
306 #define ARG_CASE_ARG_CS_SV_DC(selected,result)
307 #define ARG_CASE_ARG_CS_SV(selected,result)
308 #define ARG_CASE_ARG_CS(selected,result)
309 #define ARG_CASE_ARG_SV(selected,result)
310 #define ARG_CASE_ARG_DC(selected,result)
311 #define ARG_CASE(prog,selected,result) ARG_CASE_##prog(selected,result)
314 #undef ARG_CASE_ARG_DC
315 #undef ARG_CASE_ARG_SV
316 #undef ARG_CASE_ARG_CS
317 #undef ARG_CASE_ARG_CS_SV
318 #undef ARG_CASE_ARG_CS_SV_DC
319 #undef ARG_CASE_ARG_CS_SV_HA
324 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: "
325 "^7net_type = %s, net_name = %s, hudargs arg = '%s'.\n"
339 if(sel_num == NOTIF_MAX_DURCNT)
343 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: "
344 "^7net_type = %s, net_name = %s, max durcnt = %d.\n"
354 switch(strtolower(selected))
356 #define ARG_CASE_ARG_CS_SV_HA(selected,result)
357 #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { ++sel_num; break; }
358 #define ARG_CASE_ARG_CS_SV(selected,result)
359 #define ARG_CASE_ARG_CS(selected,result)
360 #define ARG_CASE_ARG_SV(selected,result)
361 #define ARG_CASE_ARG_DC(selected,result) case selected: { ++sel_num; break; }
362 #define ARG_CASE(prog,selected,result) ARG_CASE_##prog(selected,result)
365 #undef ARG_CASE_ARG_DC
366 #undef ARG_CASE_ARG_SV
367 #undef ARG_CASE_ARG_CS
368 #undef ARG_CASE_ARG_CS_SV
369 #undef ARG_CASE_ARG_CS_SV_DC
370 #undef ARG_CASE_ARG_CS_SV_HA
373 if(ftos(stof(selected)) != "") { ++sel_num; }
378 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: "
379 "^7net_type = %s, net_name = %s, durcnt arg = '%s'.\n"
397 void Create_Notification_Entity(entity notif,
403 // =====================
404 // Global Entity Setup
405 // =====================
406 notif.nent_default = var_default;
407 notif.nent_enabled = (var_cvar >= 1);
408 notif.nent_type = typeId;
409 notif.nent_name = strzone(namestring);
411 // Other pre-notif-setup requisites
425 "^1NOTIFICATION WITH IMPROPER TYPE: "
426 "^7net_type = %d, net_name = %s.\n"
435 // now check to see if any errors happened
438 notif.nent_enabled = false; // disable the notification so it can't cause trouble
439 notif_global_error = true; // throw the red flag that an error happened on init
443 void Create_Notification_Entity_Annce(entity notif,
452 // Set MSG_ANNCE information and handle precaching
454 MSG typeId = MSG_ANNCE;
455 if (!(GENTLE && (var_cvar == 1)))
459 if(notif.nent_enabled)
461 precache_sound(sprintf("announcer/%s/%s.wav", AnnouncerOption(), snd));
462 notif.nent_channel = channel;
463 notif.nent_snd = strzone(snd);
464 notif.nent_vol = vol;
465 notif.nent_position = position;
470 string typestring = Get_Notif_TypeName(typeId);
473 "^1NOTIFICATION WITH NO SOUND: "
474 "^7net_type = %s, net_name = %s.\n"
482 else { notif.nent_enabled = false; }
484 notif.nent_enabled = false;
489 void Create_Notification_Entity_InfoCenter(entity notif,
494 /* MSG_INFO & MSG_CENTER */
503 MSG typeId = notif.nent_type;
504 // Set MSG_INFO and MSG_CENTER string/float counts
505 notif.nent_stringcount = strnum;
506 notif.nent_floatcount = flnum;
508 // Only initialize arguments if we're either a client or on a dedicated server
510 float should_process_args = server_is_dedicated;
512 float should_process_args = true;
514 string typestring = Get_Notif_TypeName(typeId);
515 if(should_process_args)
517 // ========================
518 // Process Main Arguments
519 // ========================
524 notif.nent_args = strzone(
525 Process_Notif_Args(1, args, typestring, namestring));
527 else if((hudargs == "") && (durcnt ==""))
531 "^1NOTIFICATION HAS ARG COUNTS BUT NO ARGS OR HUDARGS OR DURCNT: "
532 "^7net_type = %s, net_name = %s, strnum = %d, flnum = %d\n"
544 notif.nent_args = strzone(
545 Process_Notif_Args(1, args, typestring, namestring));
549 // =======================================
550 // Process HUD and Centerprint Arguments
551 // Only processed on CSQC, as these
552 // args are only for HUD features.
553 // =======================================
557 notif.nent_hudargs = strzone(
558 Process_Notif_Args(2, hudargs, typestring, namestring));
560 if(icon != "") { notif.nent_icon = strzone(icon); }
565 "^1NOTIFICATION HAS HUDARGS BUT NO ICON: "
566 "^7net_type = %s, net_name = %s.\n"
578 "^1NOTIFICATION HAS ICON BUT NO HUDARGS: "
579 "^7net_type = %s, net_name = %s.\n"
589 notif.nent_durcnt = strzone(Process_Notif_Args(3, durcnt, typestring, namestring));
591 if (cpid == CPID_Null && durcnt != "0 0")
595 "Notification has durcnt but no cpid: "
596 "net_type = %s, net_name = %s."
604 notif.nent_cpid = cpid;
608 // ======================
609 // Process Notif String
610 // ======================
611 #define SET_NOTIF_STRING(string,stringname) MACRO_BEGIN { \
612 notif.nent_string = strzone(CCR( \
613 Process_Notif_Line( \
626 if(gentle != "") { SET_NOTIF_STRING(gentle, "GENTLE"); }
627 else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL"); }
629 else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL"); }
630 #undef SET_NOTIF_STRING
632 // Check to make sure a string was chosen
633 if(notif.nent_string == "")
637 "^1EMPTY NOTIFICATION: "
638 "^7net_type = %s, net_name = %s.\n"
648 void Create_Notification_Entity_Multi(entity notif,
652 Notification anncename,
653 Notification infoname,
654 Notification centername)
656 MSG typeId = MSG_MULTI;
657 // Set MSG_MULTI string/float counts
658 if (!anncename && !infoname && !centername)
660 string typestring = Get_Notif_TypeName(typeId);
663 "^1NOTIFICATION WITH NO SUBCALLS: "
664 "^7net_type = %s, net_name = %s.\n"
673 // announcements don't actually need any arguments, so lets not even count them.
674 if (anncename) { notif.nent_msgannce = anncename; }
676 float infoname_stringcount = 0, infoname_floatcount = 0;
677 float centername_stringcount = 0, centername_floatcount = 0;
681 notif.nent_msginfo = infoname;
682 infoname_stringcount = notif.nent_msginfo.nent_stringcount;
683 infoname_floatcount = notif.nent_msginfo.nent_floatcount;
688 notif.nent_msgcenter = centername;
689 centername_stringcount = notif.nent_msgcenter.nent_stringcount;
690 centername_floatcount = notif.nent_msgcenter.nent_floatcount;
693 // set the requirements of THIS notification to the totals of its subcalls
694 notif.nent_stringcount = max(infoname_stringcount, centername_stringcount);
695 notif.nent_floatcount = max(infoname_floatcount, centername_floatcount);
699 void Create_Notification_Entity_Choice(entity notif,
706 Notification optiona,
707 Notification optionb)
709 MSG typeId = MSG_CHOICE;
710 if (chtype == MSG_Null || !optiona || !optionb)
712 string typestring = Get_Notif_TypeName(typeId);
715 "^1NOTIFICATION IS MISSING CHOICE PARAMS: "
716 "^7net_type = %s, net_name = %s.\n"
725 notif.nent_optiona = optiona;
726 notif.nent_optionb = optionb;
727 notif.nent_challow_def = challow_def; // 0: never allowed, 1: allowed in warmup, 2: always allowed
728 notif.nent_challow_var = challow_var; // 0: never allowed, 1: allowed in warmup, 2: always allowed
729 notif.nent_stringcount = max(notif.nent_optiona.nent_stringcount, notif.nent_optionb.nent_stringcount);
730 notif.nent_floatcount = max(notif.nent_optiona.nent_floatcount, notif.nent_optionb.nent_floatcount);
732 /*#ifdef NOTIFICATIONS_DEBUG
733 Debug_Notification(sprintf(
734 "Create_Notification_Entity(...): MSG_CHOICE: %s\n%s\n%s\n",
737 "^ optiona: %s %s : %d %d",
738 Get_Notif_TypeName(notif.nent_optiona.nent_type),
739 notif.nent_optiona.nent_name,
740 notif.nent_optiona.nent_stringcount,
741 notif.nent_optiona.nent_floatcount
744 "^ optionb: %s %s : %d %d",
745 Get_Notif_TypeName(notif.nent_optionb.nent_type),
746 notif.nent_optionb.nent_name,
747 notif.nent_optionb.nent_stringcount,
748 notif.nent_optionb.nent_floatcount
760 // used by MSG_CHOICE to build list of choices
762 void Notification_GetCvars(entity this)
764 FOREACH(Notifications, it.nent_type == MSG_CHOICE, {
765 GetCvars_handleFloat(
769 msg_choice_choices[it.nent_choice_idx],
770 sprintf("notification_%s", it.nent_name)
776 /** used to output notifications.cfg file */
777 void Dump_Notifications(int fh, bool alsoprint)
779 #define NOTIF_WRITE(a) MACRO_BEGIN { \
781 if (alsoprint) LOG_INFO(a); \
784 #define NOTIF_WRITE_ENTITY(e, description) MACRO_BEGIN { \
785 string notif_msg = sprintf( \
786 "seta notification_%s \"%d\" \"%s\"\n", \
787 e.nent_name, e.nent_default, description \
789 NOTIF_WRITE(notif_msg); \
792 #define NOTIF_WRITE_ENTITY_CHOICE(e, descriptiona, descriptionb) MACRO_BEGIN { \
793 string notif_msg = sprintf( \
794 "seta notification_%s \"%d\" \"%s\"\n" \
795 "seta notification_%s_ALLOWED \"%d\" \"%s\"\n", \
796 e.nent_name, e.nent_default, descriptiona, \
797 e.nent_name, e.nent_challow_def, descriptionb \
799 NOTIF_WRITE(notif_msg); \
802 #define NOTIF_WRITE_HARDCODED(cvar, default, description) MACRO_BEGIN { \
803 string notif_msg = sprintf( \
804 "seta notification_%s \"%s\" \"%s\"\n", \
805 cvar, default, description \
807 NOTIF_WRITE(notif_msg); \
810 // Note: This warning only applies to the notifications.cfg file that is output...
811 // You ARE supposed to manually edit this function to add i.e. hard coded
812 // notification variables for mutators or game modes or such and then
813 // regenerate the notifications.cfg file from the new code.
815 NOTIF_WRITE("// ********************************************** //\n");
816 NOTIF_WRITE("// ** WARNING - DO NOT MANUALLY EDIT THIS FILE ** //\n");
817 NOTIF_WRITE("// ** ** //\n");
818 NOTIF_WRITE("// ** This file is automatically generated ** //\n");
819 NOTIF_WRITE("// ** by code with the command 'dumpnotifs'. ** //\n");
820 NOTIF_WRITE("// ** ** //\n");
821 NOTIF_WRITE("// ** If you add a new notification, please ** //\n");
822 NOTIF_WRITE("// ** regenerate this file with that command ** //\n");
823 NOTIF_WRITE("// ** making sure that the output matches ** //\n");
824 NOTIF_WRITE("// ** with the lists and defaults in code. ** //\n");
825 NOTIF_WRITE("// ** ** //\n");
826 NOTIF_WRITE("// ********************************************** //\n");
828 // These notifications will also append their string as a comment...
829 // This is not necessary, and does not matter if they vary between config versions,
830 // it is just a semi-helpful tool for those who want to manually change their user settings.
832 int NOTIF_ANNCE_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_ANNCE, { ++NOTIF_ANNCE_COUNT; });
833 NOTIF_WRITE(sprintf("\n// MSG_ANNCE notifications (count = %d):\n", NOTIF_ANNCE_COUNT));
834 FOREACH(Notifications, it.nent_type == MSG_ANNCE, {
835 NOTIF_WRITE_ENTITY(it,
836 "0 = disabled, 1 = enabled if gentle mode is off, 2 = always enabled"
840 int NOTIF_INFO_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_INFO, { ++NOTIF_INFO_COUNT; });
841 NOTIF_WRITE(sprintf("\n// MSG_INFO notifications (count = %d):\n", NOTIF_INFO_COUNT));
842 FOREACH(Notifications, it.nent_type == MSG_INFO, {
843 NOTIF_WRITE_ENTITY(it,
844 "0 = off, 1 = print to console, "
845 "2 = print to console and chatbox (if notification_allow_chatboxprint is enabled)"
849 int NOTIF_CENTER_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_CENTER, { ++NOTIF_CENTER_COUNT; });
850 NOTIF_WRITE(sprintf("\n// MSG_CENTER notifications (count = %d):\n", NOTIF_CENTER_COUNT));
851 FOREACH(Notifications, it.nent_type == MSG_CENTER, {
852 NOTIF_WRITE_ENTITY(it,
853 "0 = off, 1 = centerprint"
857 int NOTIF_MULTI_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_MULTI, { ++NOTIF_MULTI_COUNT; });
858 NOTIF_WRITE(sprintf("\n// MSG_MULTI notifications (count = %d):\n", NOTIF_MULTI_COUNT));
859 FOREACH(Notifications, it.nent_type == MSG_MULTI, {
860 NOTIF_WRITE_ENTITY(it,
861 "Enable this multiple notification"
865 int NOTIF_CHOICE_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_CHOICE, { ++NOTIF_CHOICE_COUNT; });
866 NOTIF_WRITE(sprintf("\n// MSG_CHOICE notifications (count = %d):\n", NOTIF_CHOICE_COUNT));
867 FOREACH(Notifications, it.nent_type == MSG_CHOICE, {
868 NOTIF_WRITE_ENTITY_CHOICE(it,
869 "Choice for this notification 0 = off, 1 = default message, 2 = verbose message",
870 "Allow choice for this notification 0 = off, 1 = only in warmup mode, 2 = always"
874 // edit these to match whichever cvars are used for specific notification options
875 NOTIF_WRITE("\n// HARD CODED notification variables:\n");
877 NOTIF_WRITE_HARDCODED(
878 "allow_chatboxprint", "1",
879 "Allow INFO notifications to be printed to chat box"
881 "1 = allow only if allowed by individual notification_INFO* cvars, "
882 "2 = force all INFO notifications to be printed to the chatbox"
885 NOTIF_WRITE_HARDCODED(
887 "Print extra debug information on all notification function calls "
888 "(Requires -DNOTIFICATIONS_DEBUG flag to be enabled on QCSRC compilation)... "
889 "0 = disabled, 1 = dprint, 2 = print"
892 NOTIF_WRITE_HARDCODED(
893 "errors_are_fatal", "1",
894 "If a notification fails upon initialization, cause a Host_Error to stop the program"
897 NOTIF_WRITE_HARDCODED(
898 "item_centerprinttime", "1.5",
899 "How long to show item information centerprint messages (like 'You got the Electro' or such)"
902 NOTIF_WRITE_HARDCODED(
903 "lifetime_mapload", "10",
904 "Amount of time that notification entities last immediately at mapload (in seconds) "
905 "to help prevent notifications from being lost on early init (like gamestart countdown)"
908 NOTIF_WRITE_HARDCODED(
909 "lifetime_runtime", "0.5",
910 "Amount of time that notification entities last on the server during runtime (In seconds)"
913 NOTIF_WRITE_HARDCODED(
914 "server_allows_location", "1",
915 "Server side cvar for allowing death messages to show location information too"
918 NOTIF_WRITE_HARDCODED(
919 "show_location", "0",
920 "Append location information to MSG_INFO death/kill messages"
923 NOTIF_WRITE_HARDCODED(
924 "show_location_string", "",
925 "Replacement string piped into sprintf, "
926 "so you can do different messages like this: ' at the %s' or ' (near %s)'"
929 NOTIF_WRITE_HARDCODED(
931 "Print information about sprees in death/kill messages"
934 NOTIF_WRITE_HARDCODED(
935 "show_sprees_center", "1",
936 "Show spree information in MSG_CENTER messages... "
937 "0 = off, 1 = target (but only for first victim) and attacker"
940 NOTIF_WRITE_HARDCODED(
941 "show_sprees_center_specialonly", "1",
942 "Don't show spree information in MSG_CENTER messages if it isn't an achievement"
945 NOTIF_WRITE_HARDCODED(
946 "show_sprees_info", "3",
947 "Show spree information in MSG_INFO messages... "
948 "0 = off, 1 = target only, 2 = attacker only, 3 = target and attacker"
951 NOTIF_WRITE_HARDCODED(
952 "show_sprees_info_newline", "1",
953 "Show attacker spree information for MSG_INFO messages on a separate line than the death notification itself"
956 NOTIF_WRITE_HARDCODED(
957 "show_sprees_info_specialonly", "1",
958 "Don't show attacker spree information in MSG_INFO messages if it isn't an achievement"
963 "\n// Notification counts (total = %d): "
964 "MSG_ANNCE = %d, MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d, MSG_CHOICE = %d\n"
979 #undef NOTIF_WRITE_HARDCODED
980 #undef NOTIF_WRITE_ENTITY
985 // ===============================
986 // Frontend Notification Pushing
987 // ===============================
989 string Local_Notification_sprintf(
990 string input, string args,
991 string s1, string s2, string s3, string s4,
992 int f1, float f2, float f3, float f4)
994 #ifdef NOTIFICATIONS_DEBUG
995 Debug_Notification(sprintf(
996 "Local_Notification_sprintf('%s^7', '%s', %s, %s);\n",
997 MakeConsoleSafe(input),
999 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1000 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1004 for (int sel_num = 0; sel_num < NOTIF_MAX_ARGS; ++sel_num) { arg_slot[sel_num] = ""; }
1006 for (int sel_num = 0; (args != ""); )
1008 string selected = car(args); args = cdr(args);
1009 NOTIF_HIT_MAX(NOTIF_MAX_ARGS, "Local_Notification_sprintf");
1010 string tmp_s; // used by NOTIF_ARGUMENT_LIST
1011 switch (strtolower(selected))
1013 #define ARG_CASE_ARG_CS_SV_HA(selected, result) case selected: { arg_slot[sel_num++] = result; break; }
1014 #define ARG_CASE_ARG_CS_SV_DC(selected, result) case selected: { arg_slot[sel_num++] = result; break; }
1015 #define ARG_CASE_ARG_CS_SV(selected, result) case selected: { arg_slot[sel_num++] = result; break; }
1017 #define ARG_CASE_ARG_CS(selected, result) case selected: { arg_slot[sel_num++] = result; break; }
1018 #define ARG_CASE_ARG_SV(selected, result)
1020 #define ARG_CASE_ARG_CS(selected, result)
1021 #define ARG_CASE_ARG_SV(selected, result) case selected: { arg_slot[sel_num++] = result; break; }
1023 #define ARG_CASE_ARG_DC(selected, result)
1024 #define ARG_CASE(prog, selected, result) ARG_CASE_##prog(selected, result)
1027 #undef ARG_CASE_ARG_DC
1028 #undef ARG_CASE_ARG_SV
1029 #undef ARG_CASE_ARG_CS
1030 #undef ARG_CASE_ARG_CS_SV
1031 #undef ARG_CASE_ARG_CS_SV_DC
1032 #undef ARG_CASE_ARG_CS_SV_HA
1033 default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
1037 strcat(input, "\n"),
1049 void Local_Notification_sound(
1050 int soundchannel, string soundfile,
1051 float soundvolume, float soundposition)
1053 if ((soundfile != prev_soundfile) || (time >= (prev_soundtime + autocvar_cl_announcer_antispam)))
1055 #ifdef NOTIFICATIONS_DEBUG
1056 Debug_Notification(sprintf(
1057 "Local_Notification_sound(%f, '%s', %f, %f);\n",
1060 "announcer/%s/%s.wav",
1073 "announcer/%s/%s.wav",
1081 if (prev_soundfile) strunzone(prev_soundfile);
1082 prev_soundfile = strzone(soundfile);
1083 prev_soundtime = time;
1087 #ifdef NOTIFICATIONS_DEBUG
1088 Debug_Notification(sprintf(
1090 "Local_Notification_sound(NULL, %f, '%s', %f, %f) "
1091 "^1BLOCKED BY ANTISPAM:^7 prevsnd: '%s', timediff: %f, limit: %f\n"
1095 "announcer/%s/%s.wav",
1102 (time - prev_soundtime),
1103 autocvar_cl_announcer_antispam
1109 void Local_Notification_HUD_Notify_Push(
1110 string icon, string hudargs,
1111 string s1, string s2, string s3, string s4,
1112 float f1, float f2, float f3, float f4)
1114 arg_slot[0] = ""; arg_slot[1] = "";
1116 for (int sel_num = 0; (hudargs != ""); )
1118 string selected = car(hudargs); hudargs = cdr(hudargs);
1119 NOTIF_HIT_MAX(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push");
1120 switch (strtolower(selected))
1122 #define ARG_CASE_ARG_CS_SV_HA(selected, result) case selected: { arg_slot[sel_num++] = result; break; }
1123 #define ARG_CASE_ARG_CS_SV_DC(selected, result)
1124 #define ARG_CASE_ARG_CS_SV(selected, result)
1125 #define ARG_CASE_ARG_CS(selected, result)
1126 #define ARG_CASE_ARG_SV(selected, result)
1127 #define ARG_CASE_ARG_DC(selected, result)
1128 #define ARG_CASE(prog, selected, result) ARG_CASE_##prog(selected, result)
1131 #undef ARG_CASE_ARG_DC
1132 #undef ARG_CASE_ARG_SV
1133 #undef ARG_CASE_ARG_CS
1134 #undef ARG_CASE_ARG_CS_SV
1135 #undef ARG_CASE_ARG_CS_SV_DC
1136 #undef ARG_CASE_ARG_CS_SV_HA
1137 default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
1140 #ifdef NOTIFICATIONS_DEBUG
1141 Debug_Notification(sprintf(
1142 "Local_Notification_HUD_Notify_Push('%s^7', '%s', %s, %s, %s);\n",
1145 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1146 sprintf("%d, %d, %d, %d", f1, f2, f3, f4),
1147 MakeConsoleSafe(sprintf("'%s^7', '%s^7'", stof(arg_slot[0]), stof(arg_slot[1])))
1150 HUD_Notify_Push(icon, arg_slot[0], arg_slot[1]);
1153 void Local_Notification_centerprint_generic(
1154 string input, string durcnt,
1155 CPID cpid, float f1, float f2)
1157 arg_slot[0] = ""; arg_slot[1] = "";
1159 for (int sel_num = 0; (durcnt != ""); )
1161 string selected = car(durcnt); durcnt = cdr(durcnt);
1162 NOTIF_HIT_MAX(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic");
1163 switch (strtolower(selected))
1165 #define ARG_CASE_ARG_CS_SV_HA(selected, result)
1166 #define ARG_CASE_ARG_CS_SV_DC(selected, result) case selected: { arg_slot[sel_num++] = result; break; }
1167 #define ARG_CASE_ARG_CS_SV(selected, result)
1168 #define ARG_CASE_ARG_CS(selected, result)
1169 #define ARG_CASE_ARG_SV(selected, result)
1170 #define ARG_CASE_ARG_DC(selected, result) case selected: { arg_slot[sel_num++] = result; break; }
1171 #define ARG_CASE(prog, selected, result) ARG_CASE_##prog(selected,result)
1174 #undef ARG_CASE_ARG_DC
1175 #undef ARG_CASE_ARG_SV
1176 #undef ARG_CASE_ARG_CS
1177 #undef ARG_CASE_ARG_CS_SV
1178 #undef ARG_CASE_ARG_CS_SV_DC
1179 #undef ARG_CASE_ARG_CS_SV_HA
1182 if (/* wtf */ ftos(stof(selected)) != "") { arg_slot[sel_num++] = selected; }
1183 else { NOTIF_HIT_UNKNOWN(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic") }
1188 #ifdef NOTIFICATIONS_DEBUG
1189 Debug_Notification(sprintf(
1190 "Local_Notification_centerprint_generic('%s^7', '%s', %d, %d, %d, %d);\n",
1191 MakeConsoleSafe(input),
1198 centerprint_generic(ORDINAL(cpid), input, stof(arg_slot[0]), stof(arg_slot[1]));
1202 void Local_Notification(MSG net_type, Notification net_name, ...count)
1204 // retreive entity of this notification
1205 entity notif = net_name;
1208 #ifdef NOTIFICATIONS_DEBUG
1209 Debug_Notification(sprintf(
1210 "Local_Notification(%s, NULL, ...);\n",
1211 Get_Notif_TypeName(net_type)
1214 LOG_WARNF("Incorrect usage of Local_Notification: %s", "Null notification");
1218 // check if the notification is enabled
1219 if (!notif.nent_enabled)
1221 #ifdef NOTIFICATIONS_DEBUG
1222 Debug_Notification(sprintf(
1223 "Local_Notification(%s, %s, ...): Entity was disabled...\n",
1224 Get_Notif_TypeName(net_type),
1231 string s1 = ((notif.nent_stringcount > 0) ? ...(0, string) : "");
1232 string s2 = ((notif.nent_stringcount > 1) ? ...(1, string) : "");
1233 string s3 = ((notif.nent_stringcount > 2) ? ...(2, string) : "");
1234 string s4 = ((notif.nent_stringcount > 3) ? ...(3, string) : "");
1235 float f1 = ((notif.nent_floatcount > 0) ? ...((notif.nent_stringcount + 0), float) : 0);
1236 float f2 = ((notif.nent_floatcount > 1) ? ...((notif.nent_stringcount + 1), float) : 0);
1237 float f3 = ((notif.nent_floatcount > 2) ? ...((notif.nent_stringcount + 2), float) : 0);
1238 float f4 = ((notif.nent_floatcount > 3) ? ...((notif.nent_stringcount + 3), float) : 0);
1240 #ifdef NOTIFICATIONS_DEBUG
1241 Debug_Notification(sprintf(
1242 "Local_Notification(%s, %s, %s, %s);\n",
1243 Get_Notif_TypeName(net_type),
1245 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1246 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1250 if ((notif.nent_stringcount + notif.nent_floatcount) != count)
1254 "Arguments mismatch for Local_Notification(%s, %s, ...)! "
1255 "stringcount(%d) + floatcount(%d) != count(%d)\n"
1256 "Check the definition and function call for accuracy...?\n"
1258 Get_Notif_TypeName(net_type),
1260 notif.nent_stringcount,
1261 notif.nent_floatcount,
1272 Local_Notification_sound(
1279 backtrace("MSG_ANNCE on server?... Please notify Samual immediately!\n");
1287 Local_Notification_sprintf(
1294 if (notif.nent_icon != "")
1296 if (notif.nent_iconargs != "")
1298 string s = Local_Notification_sprintf(
1299 notif.nent_icon,notif.nent_iconargs,
1300 s1, s2, s3, s4, f1, f2, f3, f4);
1301 // remove the trailing newline
1302 notif.nent_icon = strzone(substring(s, 0, -1));
1304 Local_Notification_HUD_Notify_Push(
1317 Local_Notification_centerprint_generic(
1318 Local_Notification_sprintf(
1332 if (notif.nent_msginfo && notif.nent_msginfo.nent_enabled)
1334 Local_Notification_WOVA(
1337 notif.nent_msginfo.nent_stringcount,
1338 notif.nent_msginfo.nent_floatcount,
1343 if (notif.nent_msgannce && notif.nent_msgannce.nent_enabled)
1345 Local_Notification_WOVA(
1347 notif.nent_msgannce,
1352 if (notif.nent_msgcenter && notif.nent_msgcenter.nent_enabled)
1354 Local_Notification_WOVA(
1356 notif.nent_msgcenter,
1357 notif.nent_msgcenter.nent_stringcount,
1358 notif.nent_msgcenter.nent_floatcount,
1368 entity found_choice = notif.nent_optiona;
1369 if (notif.nent_challow_var && (warmup_stage || (notif.nent_challow_var == 2))) {
1370 switch (cvar(sprintf("notification_%s", notif.nent_name)))
1373 case 2: found_choice = notif.nent_optionb; break;
1374 default: return; // not enabled anyway
1378 Local_Notification_WOVA(
1379 found_choice.nent_type,
1381 found_choice.nent_stringcount,
1382 found_choice.nent_floatcount,
1389 // WOVA = Without Variable Arguments
1390 void Local_Notification_WOVA(
1391 MSG net_type, Notification net_name,
1392 float stringcount, float floatcount,
1393 string s1, string s2, string s3, string s4,
1394 float f1, float f2, float f3, float f4)
1396 #define VARITEM(stringc, floatc, args) \
1397 if ((stringcount == stringc) && (floatcount == floatc)) \
1398 { Local_Notification(net_type, net_name, args); return; }
1399 EIGHT_VARS_TO_VARARGS_VARLIST
1401 Local_Notification(net_type, net_name); // some notifications don't have any arguments at all
1405 // =========================
1406 // Notification Networking
1407 // =========================
1409 /** networked as a linked entity to give newly connecting clients some notification context */
1410 REGISTER_NET_LINKED(ENT_CLIENT_NOTIFICATION)
1413 NET_HANDLE(ENT_CLIENT_NOTIFICATION, bool is_new)
1416 MSG net_type = ENUMCAST(MSG, ReadByte());
1417 int net_name = ReadShort();
1420 if (net_type == MSG_CENTER_KILL)
1422 if (!is_new) return;
1424 #ifdef NOTIFICATIONS_DEBUG
1425 Debug_Notification(sprintf(
1426 "Read_Notification(%d) at %f: net_type = %s, cpid = %d\n",
1429 Get_Notif_TypeName(net_type),
1433 int _net_name = net_name;
1434 CPID net_name = ENUMCAST(CPID, _net_name);
1435 if (net_name == CPID_Null) {
1437 reset_centerprint_messages();
1440 centerprint_generic(ORDINAL(net_name), "", 0, 0);
1445 Notification notif = Get_Notif_Ent(net_type, net_name);
1447 #ifdef NOTIFICATIONS_DEBUG
1448 Debug_Notification(sprintf(
1449 "Read_Notification(%d) at %f: net_type = %s, net_name = %s (%d)\n",
1452 Get_Notif_TypeName(net_type),
1453 notif.registered_id,
1459 backtrace("Read_Notification: Could not find notification entity!\n");
1463 string s1 = ((notif.nent_stringcount > 0) ? ReadString() : "");
1464 string s2 = ((notif.nent_stringcount > 1) ? ReadString() : "");
1465 string s3 = ((notif.nent_stringcount > 2) ? ReadString() : "");
1466 string s4 = ((notif.nent_stringcount > 3) ? ReadString() : "");
1467 float f1 = ((notif.nent_floatcount > 0) ? ReadLong() : 0);
1468 float f2 = ((notif.nent_floatcount > 1) ? ReadLong() : 0);
1469 float f3 = ((notif.nent_floatcount > 2) ? ReadLong() : 0);
1470 float f4 = ((notif.nent_floatcount > 3) ? ReadLong() : 0);
1472 if (!is_new) return;
1473 Local_Notification_WOVA(
1475 notif.nent_stringcount,
1476 notif.nent_floatcount,
1483 void Net_Notification_Remove(entity this)
1485 #ifdef NOTIFICATIONS_DEBUG
1486 Debug_Notification(sprintf(
1487 "Net_Notification_Remove() at %f: %s '%s - %s' notification\n",
1489 ((this.nent_net_name == -1) ? "Killed" : "Removed"),
1490 Get_Notif_TypeName(this.nent_net_type),
1491 this.owner.nent_name
1494 for (int i = 0; i < this.nent_stringcount; ++i) { if (this.nent_strings[i]) strunzone(this.nent_strings[i]); }
1498 bool Net_Write_Notification(entity this, entity client, int sf)
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]); }
1509 void Kill_Notification(
1510 NOTIF broadcast, entity client,
1511 /** message group, MSG_Null for all */
1513 /** cpid group, CPID_Null for all */
1516 #ifdef NOTIFICATIONS_DEBUG
1517 Debug_Notification(sprintf(
1518 "Kill_Notification(%s, '%s', %s, %d);\n",
1519 Get_Notif_BroadcastName(broadcast),
1521 (net_type ? Get_Notif_TypeName(net_type) : "0"),
1526 string checkargs = Notification_CheckArgs(broadcast, client);
1527 if (checkargs != "") { LOG_WARNF("Incorrect usage of Kill_Notification: %s", checkargs); return; }
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);
1538 (it.owner.nent_type == net_type || net_type == MSG_Null) && (it.owner.nent_cpid == net_cpid || net_cpid == CPID_Null),
1540 it.nent_net_name = -1;
1541 it.nextthink = time;
1546 void Send_Notification(
1547 NOTIF broadcast, entity client,
1548 MSG net_type, Notification net_name,
1551 if (broadcast != NOTIF_ALL && broadcast != NOTIF_ALL_EXCEPT && !IS_REAL_CLIENT(client)) return;
1552 entity notif = net_name;
1553 string parms = sprintf("%s, '%s', %s, %s",
1554 Get_Notif_BroadcastName(broadcast),
1556 Get_Notif_TypeName(net_type),
1557 net_name.registered_id
1559 #ifdef NOTIFICATIONS_DEBUG
1560 Debug_Notification(sprintf("Send_Notification(%s, ...%d);\n", parms, count));
1565 LOG_WARN("Send_Notification: Could not find notification entity!");
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 != "")
1574 LOG_WARNF("Incorrect usage of Send_Notification: %s", checkargs);
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);
1587 #ifdef NOTIFICATIONS_DEBUG
1588 Debug_Notification(sprintf(
1589 "Send_Notification(%s, %s, %s);\n",
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)
1596 if ((notif.nent_stringcount + notif.nent_floatcount) != count)
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",
1603 notif.nent_stringcount,
1604 notif.nent_floatcount,
1614 broadcast == NOTIF_ALL
1616 broadcast == NOTIF_ALL_EXCEPT
1620 net_type == MSG_ANNCE
1622 net_type == MSG_CENTER
1626 Local_Notification_WOVA(
1628 notif.nent_stringcount,
1629 notif.nent_floatcount,
1634 if (net_type == MSG_CHOICE)
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;
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]) \
1647 case 1: found_choice = notif.nent_optiona; break; \
1648 case 2: found_choice = notif.nent_optionb; break; \
1652 found_choice = notif.nent_optiona; \
1654 Send_Notification_WOVA( \
1657 found_choice.nent_type, \
1659 found_choice.nent_stringcount, \
1660 found_choice.nent_floatcount, \
1667 case NOTIF_ONE_ONLY: // we can potentially save processing power with this broadcast method
1669 if (IS_REAL_CLIENT(client)) {
1670 RECURSE_FROM_CHOICE(client, return);
1676 FOREACH_CLIENT(IS_REAL_CLIENT(it) && Notification_ShouldSend(broadcast, it, client), {
1677 RECURSE_FROM_CHOICE(it, continue);
1685 entity net_notif = new_pure(net_notification);
1686 IL_PUSH(g_notifications, net_notif);
1687 net_notif.owner = notif;
1688 net_notif.nent_broadcast = broadcast;
1689 net_notif.nent_client = client;
1690 net_notif.nent_net_type = net_type;
1691 net_notif.nent_net_name = notif.m_id;
1692 net_notif.nent_stringcount = notif.nent_stringcount;
1693 net_notif.nent_floatcount = notif.nent_floatcount;
1695 for (int i = 0; i < net_notif.nent_stringcount; ++i) {
1696 net_notif.nent_strings[i] = strzone(...(i, string));
1698 for (int i = 0; i < net_notif.nent_floatcount; ++i) {
1699 net_notif.nent_floats[i] = ...((net_notif.nent_stringcount + i), float);
1702 setthink(net_notif, Net_Notification_Remove);
1703 net_notif.nextthink = (time > autocvar_notification_lifetime_mapload)
1704 ? (time + autocvar_notification_lifetime_runtime)
1705 : autocvar_notification_lifetime_mapload;
1707 Net_LinkEntity(net_notif, false, 0, Net_Write_Notification);
1711 // WOVA = Without Variable Arguments
1712 void Send_Notification_WOVA(
1713 NOTIF broadcast, entity client,
1714 MSG net_type, Notification net_name,
1715 float stringcount, float floatcount,
1716 string s1, string s2, string s3, string s4,
1717 float f1, float f2, float f3, float f4)
1719 #ifdef NOTIFICATIONS_DEBUG
1720 entity notif = net_name;
1721 Debug_Notification(sprintf(
1722 "Send_Notification_WOVA(%s, %d, %d, %s, %s);\n",
1725 Get_Notif_BroadcastName(broadcast),
1727 Get_Notif_TypeName(net_type),
1732 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1733 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1737 #define VARITEM(stringc, floatc, args) \
1738 if ((stringcount == stringc) && (floatcount == floatc)) \
1739 { Send_Notification(broadcast, client, net_type, net_name, args); return; }
1740 EIGHT_VARS_TO_VARARGS_VARLIST
1742 Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
1745 // WOCOVA = Without Counts Or Variable Arguments
1746 void Send_Notification_WOCOVA(
1747 NOTIF broadcast, entity client,
1748 MSG net_type, Notification net_name,
1749 string s1, string s2, string s3, string s4,
1750 float f1, float f2, float f3, float f4)
1752 entity notif = net_name;
1754 #ifdef NOTIFICATIONS_DEBUG
1755 Debug_Notification(sprintf(
1756 "Send_Notification_WOCOVA(%s, %s, %s);\n",
1759 Get_Notif_BroadcastName(broadcast),
1761 Get_Notif_TypeName(net_type),
1764 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1765 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1769 #define VARITEM(stringc, floatc, args) \
1770 if ((notif.nent_stringcount == stringc) && (notif.nent_floatcount == floatc)) \
1771 { Send_Notification(broadcast, client, net_type, net_name, args); return; }
1772 EIGHT_VARS_TO_VARARGS_VARLIST
1774 Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
1776 #endif // ifdef SVQC