2 #include <client/announcer.qh>
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>
11 #include <server/mutators/all.qh>
14 // ================================================
15 // Unified notification system, written by Samual
16 // Last updated: August, 2013
17 // ================================================
20 string Notification_CheckArgs(
21 NOTIF broadcast, entity client)
23 // check supplied broadcast and target for errors
29 if (IS_NOT_A_CLIENT(client)) {
30 return "No client provided!";
35 case NOTIF_ALL_EXCEPT:
37 if (IS_NOT_A_CLIENT(client)) {
38 return "Exception can't be a non-client!";
46 return "Entity provided when world was required!";
54 return "Teamplay not active!";
55 } else if (!client.team) {
56 // checkargs = sprintf("%sNo team provided!", checkargs);
61 case NOTIF_TEAM_EXCEPT:
64 return "Teamplay not active!";
65 } else if (IS_NOT_A_CLIENT(client)) {
66 return "Exception can't be a non-client!";
73 return sprintf("Improper broadcast: %d!", broadcast);
79 bool Notification_ShouldSend(NOTIF broadcast, entity to_client, entity other_client)
85 (to_client == other_client)
90 (to_client.enemy == other_client)
94 return (to_client == other_client);
97 (to_client.team == other_client.team)
102 (to_client.enemy.team == other_client.team)
105 case NOTIF_TEAM_EXCEPT:
107 (to_client != other_client)
110 (to_client.team == other_client.team)
116 (to_client.enemy != other_client)
118 (to_client.enemy.team == other_client.team)
125 case NOTIF_ALL_EXCEPT:
127 (to_client != other_client)
132 (to_client.enemy == other_client)
142 // ===============================
143 // Initialization Core Functions
144 // ===============================
146 // used by restartnotifs command to initialize notifications
147 void Destroy_Notification_Entity(entity notif)
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);
159 void Destroy_All_Notifications()
161 // kill all networked notifications and centerprints
163 Kill_Notification(NOTIF_ALL, NULL, MSG_Null, CPID_Null);
165 reset_centerprint_messages();
168 // kill all real notification entities
169 FOREACH(Notifications, true, { Destroy_Notification_Entity(it); });
172 string Process_Notif_Line(
181 if(typeId == MSG_INFO)
183 if((chat && autocvar_notification_allow_chatboxprint)
184 || (autocvar_notification_allow_chatboxprint == 2))
186 // pass 1: add ETX char at beginning of line
187 input = strcat("\{3}", input);
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);
193 // pass 3: strip trailing ETX char
194 if(substring(input, (strlen(input) - 1), 1) == "\{3}")
195 { input = substring(input, 0, (strlen(input) - 1)); }
200 // done to both MSG_INFO and MSG_CENTER
201 if(substring(input, (strlen(input) - 1), 1) == "\n")
205 "^1TRAILING NEW LINE AT END OF NOTIFICATION: "
206 "^7net_type = %s, net_name = %s, string = %s.\n"
213 input = substring(input, 1, (strlen(input) - 1));
219 string Process_Notif_Args(
225 string selected, remaining = args;
228 for (;(remaining != "");)
230 selected = car(remaining); remaining = cdr(remaining);
234 case 1: // normal args
236 if(sel_num == NOTIF_MAX_ARGS)
240 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: "
241 "^7net_type = %s, net_name = %s, max args = %d.\n"
251 switch(strtolower(selected))
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)
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
272 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: "
273 "^7net_type = %s, net_name = %s, args arg = '%s'.\n"
287 if(sel_num == NOTIF_MAX_HUDARGS)
291 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: "
292 "^7net_type = %s, net_name = %s, max hudargs = %d.\n"
302 switch(strtolower(selected))
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)
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
323 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: "
324 "^7net_type = %s, net_name = %s, hudargs arg = '%s'.\n"
338 if(sel_num == NOTIF_MAX_DURCNT)
342 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: "
343 "^7net_type = %s, net_name = %s, max durcnt = %d.\n"
353 switch(strtolower(selected))
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)
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
372 if(ftos(stof(selected)) != "") { ++sel_num; }
377 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: "
378 "^7net_type = %s, net_name = %s, durcnt arg = '%s'.\n"
396 void Create_Notification_Entity(entity notif,
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);
410 // Other pre-notif-setup requisites
424 "^1NOTIFICATION WITH IMPROPER TYPE: "
425 "^7net_type = %d, net_name = %s.\n"
434 // now check to see if any errors happened
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
442 void Create_Notification_Entity_Annce(entity notif,
451 // Set MSG_ANNCE information and handle precaching
453 MSG typeId = MSG_ANNCE;
454 if (!(GENTLE && (var_cvar == 1)))
458 if(notif.nent_enabled)
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;
469 string typestring = Get_Notif_TypeName(typeId);
472 "^1NOTIFICATION WITH NO SOUND: "
473 "^7net_type = %s, net_name = %s.\n"
481 else { notif.nent_enabled = false; }
483 notif.nent_enabled = false;
488 void Create_Notification_Entity_InfoCenter(entity notif,
493 /* MSG_INFO & MSG_CENTER */
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;
507 // Only initialize arguments if we're either a client or on a dedicated server
509 float should_process_args = server_is_dedicated;
511 float should_process_args = true;
513 string typestring = Get_Notif_TypeName(typeId);
514 if(should_process_args)
516 // ========================
517 // Process Main Arguments
518 // ========================
523 notif.nent_args = strzone(
524 Process_Notif_Args(1, args, typestring, namestring));
526 else if((hudargs == "") && (durcnt ==""))
530 "^1NOTIFICATION HAS ARG COUNTS BUT NO ARGS OR HUDARGS OR DURCNT: "
531 "^7net_type = %s, net_name = %s, strnum = %d, flnum = %d\n"
543 notif.nent_args = strzone(
544 Process_Notif_Args(1, args, typestring, namestring));
548 // =======================================
549 // Process HUD and Centerprint Arguments
550 // Only processed on CSQC, as these
551 // args are only for HUD features.
552 // =======================================
556 notif.nent_hudargs = strzone(
557 Process_Notif_Args(2, hudargs, typestring, namestring));
559 if(icon != "") { notif.nent_icon = strzone(icon); }
564 "^1NOTIFICATION HAS HUDARGS BUT NO ICON: "
565 "^7net_type = %s, net_name = %s.\n"
577 "^1NOTIFICATION HAS ICON BUT NO HUDARGS: "
578 "^7net_type = %s, net_name = %s.\n"
588 notif.nent_durcnt = strzone(Process_Notif_Args(3, durcnt, typestring, namestring));
590 if (cpid == CPID_Null && durcnt != "0 0")
594 "Notification has durcnt but no cpid: "
595 "net_type = %s, net_name = %s."
603 notif.nent_cpid = cpid;
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( \
625 if(gentle != "") { SET_NOTIF_STRING(gentle, "GENTLE"); }
626 else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL"); }
628 else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL"); }
629 #undef SET_NOTIF_STRING
631 // Check to make sure a string was chosen
632 if(notif.nent_string == "")
636 "^1EMPTY NOTIFICATION: "
637 "^7net_type = %s, net_name = %s.\n"
647 void Create_Notification_Entity_Multi(entity notif,
651 Notification anncename,
652 Notification infoname,
653 Notification centername)
655 MSG typeId = MSG_MULTI;
656 // Set MSG_MULTI string/float counts
657 if (!anncename && !infoname && !centername)
659 string typestring = Get_Notif_TypeName(typeId);
662 "^1NOTIFICATION WITH NO SUBCALLS: "
663 "^7net_type = %s, net_name = %s.\n"
672 // announcements don't actually need any arguments, so lets not even count them.
673 if (anncename) { notif.nent_msgannce = anncename; }
675 float infoname_stringcount = 0, infoname_floatcount = 0;
676 float centername_stringcount = 0, centername_floatcount = 0;
680 notif.nent_msginfo = infoname;
681 infoname_stringcount = notif.nent_msginfo.nent_stringcount;
682 infoname_floatcount = notif.nent_msginfo.nent_floatcount;
687 notif.nent_msgcenter = centername;
688 centername_stringcount = notif.nent_msgcenter.nent_stringcount;
689 centername_floatcount = notif.nent_msgcenter.nent_floatcount;
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);
698 void Create_Notification_Entity_Choice(entity notif,
705 Notification optiona,
706 Notification optionb)
708 MSG typeId = MSG_CHOICE;
709 if (chtype == MSG_Null || !optiona || !optionb)
711 string typestring = Get_Notif_TypeName(typeId);
714 "^1NOTIFICATION IS MISSING CHOICE PARAMS: "
715 "^7net_type = %s, net_name = %s.\n"
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);
731 /*#ifdef NOTIFICATIONS_DEBUG
732 Debug_Notification(sprintf(
733 "Create_Notification_Entity(...): MSG_CHOICE: %s\n%s\n%s\n",
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
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
759 // used by MSG_CHOICE to build list of choices
761 void Notification_GetCvars()
764 FOREACH(Notifications, it.nent_type == MSG_CHOICE, {
765 GetCvars_handleFloat(
768 msg_choice_choices[idx++],
769 sprintf("notification_%s", it.nent_name)
775 /** used to output notifications.cfg file */
776 void Dump_Notifications(int fh, bool alsoprint)
778 #define NOTIF_WRITE(a) MACRO_BEGIN { \
780 if (alsoprint) LOG_INFO(a); \
783 #define NOTIF_WRITE_ENTITY(e, description) MACRO_BEGIN { \
784 string notif_msg = sprintf( \
785 "seta notification_%s \"%d\" \"%s\"\n", \
786 e.nent_name, e.nent_default, description \
788 NOTIF_WRITE(notif_msg); \
791 #define NOTIF_WRITE_ENTITY_CHOICE(e, descriptiona, descriptionb) MACRO_BEGIN { \
792 string notif_msg = sprintf( \
793 "seta notification_%s \"%d\" \"%s\"\n" \
794 "seta notification_%s_ALLOWED \"%d\" \"%s\"\n", \
795 e.nent_name, e.nent_default, descriptiona, \
796 e.nent_name, e.nent_challow_def, descriptionb \
798 NOTIF_WRITE(notif_msg); \
801 #define NOTIF_WRITE_HARDCODED(cvar, default, description) MACRO_BEGIN { \
802 string notif_msg = sprintf( \
803 "seta notification_%s \"%s\" \"%s\"\n", \
804 cvar, default, description \
806 NOTIF_WRITE(notif_msg); \
809 // Note: This warning only applies to the notifications.cfg file that is output...
810 // You ARE supposed to manually edit this function to add i.e. hard coded
811 // notification variables for mutators or game modes or such and then
812 // regenerate the notifications.cfg file from the new code.
814 NOTIF_WRITE("// ********************************************** //\n");
815 NOTIF_WRITE("// ** WARNING - DO NOT MANUALLY EDIT THIS FILE ** //\n");
816 NOTIF_WRITE("// ** ** //\n");
817 NOTIF_WRITE("// ** This file is automatically generated ** //\n");
818 NOTIF_WRITE("// ** by code with the command 'dumpnotifs'. ** //\n");
819 NOTIF_WRITE("// ** ** //\n");
820 NOTIF_WRITE("// ** If you add a new notification, please ** //\n");
821 NOTIF_WRITE("// ** regenerate this file with that command ** //\n");
822 NOTIF_WRITE("// ** making sure that the output matches ** //\n");
823 NOTIF_WRITE("// ** with the lists and defaults in code. ** //\n");
824 NOTIF_WRITE("// ** ** //\n");
825 NOTIF_WRITE("// ********************************************** //\n");
827 // These notifications will also append their string as a comment...
828 // This is not necessary, and does not matter if they vary between config versions,
829 // it is just a semi-helpful tool for those who want to manually change their user settings.
831 int NOTIF_ANNCE_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_ANNCE, { ++NOTIF_ANNCE_COUNT; });
832 NOTIF_WRITE(sprintf("\n// MSG_ANNCE notifications (count = %d):\n", NOTIF_ANNCE_COUNT));
833 FOREACH(Notifications, it.nent_type == MSG_ANNCE, {
834 NOTIF_WRITE_ENTITY(it,
835 "0 = disabled, 1 = enabled if gentle mode is off, 2 = always enabled"
839 int NOTIF_INFO_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_INFO, { ++NOTIF_INFO_COUNT; });
840 NOTIF_WRITE(sprintf("\n// MSG_INFO notifications (count = %d):\n", NOTIF_INFO_COUNT));
841 FOREACH(Notifications, it.nent_type == MSG_INFO, {
842 NOTIF_WRITE_ENTITY(it,
843 "0 = off, 1 = print to console, "
844 "2 = print to console and chatbox (if notification_allow_chatboxprint is enabled)"
848 int NOTIF_CENTER_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_CENTER, { ++NOTIF_CENTER_COUNT; });
849 NOTIF_WRITE(sprintf("\n// MSG_CENTER notifications (count = %d):\n", NOTIF_CENTER_COUNT));
850 FOREACH(Notifications, it.nent_type == MSG_CENTER, {
851 NOTIF_WRITE_ENTITY(it,
852 "0 = off, 1 = centerprint"
856 int NOTIF_MULTI_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_MULTI, { ++NOTIF_MULTI_COUNT; });
857 NOTIF_WRITE(sprintf("\n// MSG_MULTI notifications (count = %d):\n", NOTIF_MULTI_COUNT));
858 FOREACH(Notifications, it.nent_type == MSG_MULTI, {
859 NOTIF_WRITE_ENTITY(it,
860 "Enable this multiple notification"
864 int NOTIF_CHOICE_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_CHOICE, { ++NOTIF_CHOICE_COUNT; });
865 NOTIF_WRITE(sprintf("\n// MSG_CHOICE notifications (count = %d):\n", NOTIF_CHOICE_COUNT));
866 FOREACH(Notifications, it.nent_type == MSG_CHOICE, {
867 NOTIF_WRITE_ENTITY_CHOICE(it,
868 "Choice for this notification 0 = off, 1 = default message, 2 = verbose message",
869 "Allow choice for this notification 0 = off, 1 = only in warmup mode, 2 = always"
873 // edit these to match whichever cvars are used for specific notification options
874 NOTIF_WRITE("\n// HARD CODED notification variables:\n");
876 NOTIF_WRITE_HARDCODED(
877 "allow_chatboxprint", "1",
878 "Allow INFO notifications to be printed to chat box"
880 "1 = allow only if allowed by individual notification_INFO* cvars, "
881 "2 = force all INFO notifications to be printed to the chatbox"
884 NOTIF_WRITE_HARDCODED(
886 "Print extra debug information on all notification function calls "
887 "(Requires -DNOTIFICATIONS_DEBUG flag to be enabled on QCSRC compilation)... "
888 "0 = disabled, 1 = dprint, 2 = print"
891 NOTIF_WRITE_HARDCODED(
892 "errors_are_fatal", "1",
893 "If a notification fails upon initialization, cause a Host_Error to stop the program"
896 NOTIF_WRITE_HARDCODED(
897 "item_centerprinttime", "1.5",
898 "How long to show item information centerprint messages (like 'You got the Electro' or such)"
901 NOTIF_WRITE_HARDCODED(
902 "lifetime_mapload", "10",
903 "Amount of time that notification entities last immediately at mapload (in seconds) "
904 "to help prevent notifications from being lost on early init (like gamestart countdown)"
907 NOTIF_WRITE_HARDCODED(
908 "lifetime_runtime", "0.5",
909 "Amount of time that notification entities last on the server during runtime (In seconds)"
912 NOTIF_WRITE_HARDCODED(
913 "server_allows_location", "1",
914 "Server side cvar for allowing death messages to show location information too"
917 NOTIF_WRITE_HARDCODED(
918 "show_location", "0",
919 "Append location information to MSG_INFO death/kill messages"
922 NOTIF_WRITE_HARDCODED(
923 "show_location_string", "",
924 "Replacement string piped into sprintf, "
925 "so you can do different messages like this: ' at the %s' or ' (near %s)'"
928 NOTIF_WRITE_HARDCODED(
930 "Print information about sprees in death/kill messages"
933 NOTIF_WRITE_HARDCODED(
934 "show_sprees_center", "1",
935 "Show spree information in MSG_CENTER messages... "
936 "0 = off, 1 = target (but only for first victim) and attacker"
939 NOTIF_WRITE_HARDCODED(
940 "show_sprees_center_specialonly", "1",
941 "Don't show spree information in MSG_CENTER messages if it isn't an achievement"
944 NOTIF_WRITE_HARDCODED(
945 "show_sprees_info", "3",
946 "Show spree information in MSG_INFO messages... "
947 "0 = off, 1 = target only, 2 = attacker only, 3 = target and attacker"
950 NOTIF_WRITE_HARDCODED(
951 "show_sprees_info_newline", "1",
952 "Show attacker spree information for MSG_INFO messages on a separate line than the death notification itself"
955 NOTIF_WRITE_HARDCODED(
956 "show_sprees_info_specialonly", "1",
957 "Don't show attacker spree information in MSG_INFO messages if it isn't an achievement"
962 "\n// Notification counts (total = %d): "
963 "MSG_ANNCE = %d, MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d, MSG_CHOICE = %d\n"
978 #undef NOTIF_WRITE_HARDCODED
979 #undef NOTIF_WRITE_ENTITY
984 // ===============================
985 // Frontend Notification Pushing
986 // ===============================
988 string Local_Notification_sprintf(
989 string input, string args,
990 string s1, string s2, string s3, string s4,
991 int f1, float f2, float f3, float f4)
993 #ifdef NOTIFICATIONS_DEBUG
994 Debug_Notification(sprintf(
995 "Local_Notification_sprintf('%s^7', '%s', %s, %s);\n",
996 MakeConsoleSafe(input),
998 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
999 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1003 for (int sel_num = 0; sel_num < NOTIF_MAX_ARGS; ++sel_num) { arg_slot[sel_num] = ""; }
1005 for (int sel_num = 0; (args != ""); )
1007 string selected = car(args); args = cdr(args);
1008 NOTIF_HIT_MAX(NOTIF_MAX_ARGS, "Local_Notification_sprintf");
1009 string tmp_s; // used by NOTIF_ARGUMENT_LIST
1010 switch (strtolower(selected))
1012 #define ARG_CASE_ARG_CS_SV_HA(selected, result) case selected: { arg_slot[sel_num++] = result; break; }
1013 #define ARG_CASE_ARG_CS_SV_DC(selected, result) case selected: { arg_slot[sel_num++] = result; break; }
1014 #define ARG_CASE_ARG_CS_SV(selected, result) case selected: { arg_slot[sel_num++] = result; break; }
1016 #define ARG_CASE_ARG_CS(selected, result) case selected: { arg_slot[sel_num++] = result; break; }
1017 #define ARG_CASE_ARG_SV(selected, result)
1019 #define ARG_CASE_ARG_CS(selected, result)
1020 #define ARG_CASE_ARG_SV(selected, result) case selected: { arg_slot[sel_num++] = result; break; }
1022 #define ARG_CASE_ARG_DC(selected, result)
1023 #define ARG_CASE(prog, selected, result) ARG_CASE_##prog(selected, result)
1026 #undef ARG_CASE_ARG_DC
1027 #undef ARG_CASE_ARG_SV
1028 #undef ARG_CASE_ARG_CS
1029 #undef ARG_CASE_ARG_CS_SV
1030 #undef ARG_CASE_ARG_CS_SV_DC
1031 #undef ARG_CASE_ARG_CS_SV_HA
1032 default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
1036 strcat(input, "\n"),
1048 void Local_Notification_sound(
1049 int soundchannel, string soundfile,
1050 float soundvolume, float soundposition)
1052 if ((soundfile != prev_soundfile) || (time >= (prev_soundtime + autocvar_cl_announcer_antispam)))
1054 #ifdef NOTIFICATIONS_DEBUG
1055 Debug_Notification(sprintf(
1056 "Local_Notification_sound(%f, '%s', %f, %f);\n",
1059 "announcer/%s/%s.wav",
1072 "announcer/%s/%s.wav",
1080 if (prev_soundfile) strunzone(prev_soundfile);
1081 prev_soundfile = strzone(soundfile);
1082 prev_soundtime = time;
1086 #ifdef NOTIFICATIONS_DEBUG
1087 Debug_Notification(sprintf(
1089 "Local_Notification_sound(world, %f, '%s', %f, %f) "
1090 "^1BLOCKED BY ANTISPAM:^7 prevsnd: '%s', timediff: %f, limit: %f\n"
1094 "announcer/%s/%s.wav",
1101 (time - prev_soundtime),
1102 autocvar_cl_announcer_antispam
1108 void Local_Notification_HUD_Notify_Push(
1109 string icon, string hudargs,
1110 string s1, string s2, string s3, string s4,
1111 float f1, float f2, float f3, float f4)
1113 arg_slot[0] = ""; arg_slot[1] = "";
1115 for (int sel_num = 0; (hudargs != ""); )
1117 string selected = car(hudargs); hudargs = cdr(hudargs);
1118 NOTIF_HIT_MAX(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push");
1119 switch (strtolower(selected))
1121 #define ARG_CASE_ARG_CS_SV_HA(selected, result) case selected: { arg_slot[sel_num++] = result; break; }
1122 #define ARG_CASE_ARG_CS_SV_DC(selected, result)
1123 #define ARG_CASE_ARG_CS_SV(selected, result)
1124 #define ARG_CASE_ARG_CS(selected, result)
1125 #define ARG_CASE_ARG_SV(selected, result)
1126 #define ARG_CASE_ARG_DC(selected, result)
1127 #define ARG_CASE(prog, selected, result) ARG_CASE_##prog(selected, result)
1130 #undef ARG_CASE_ARG_DC
1131 #undef ARG_CASE_ARG_SV
1132 #undef ARG_CASE_ARG_CS
1133 #undef ARG_CASE_ARG_CS_SV
1134 #undef ARG_CASE_ARG_CS_SV_DC
1135 #undef ARG_CASE_ARG_CS_SV_HA
1136 default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
1139 #ifdef NOTIFICATIONS_DEBUG
1140 Debug_Notification(sprintf(
1141 "Local_Notification_HUD_Notify_Push('%s^7', '%s', %s, %s, %s);\n",
1144 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1145 sprintf("%d, %d, %d, %d", f1, f2, f3, f4),
1146 MakeConsoleSafe(sprintf("'%s^7', '%s^7'", stof(arg_slot[0]), stof(arg_slot[1])))
1149 HUD_Notify_Push(icon, arg_slot[0], arg_slot[1]);
1152 void Local_Notification_centerprint_generic(
1153 string input, string durcnt,
1154 CPID cpid, float f1, float f2)
1156 arg_slot[0] = ""; arg_slot[1] = "";
1158 for (int sel_num = 0; (durcnt != ""); )
1160 string selected = car(durcnt); durcnt = cdr(durcnt);
1161 NOTIF_HIT_MAX(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic");
1162 switch (strtolower(selected))
1164 #define ARG_CASE_ARG_CS_SV_HA(selected, result)
1165 #define ARG_CASE_ARG_CS_SV_DC(selected, result) case selected: { arg_slot[sel_num++] = result; break; }
1166 #define ARG_CASE_ARG_CS_SV(selected, result)
1167 #define ARG_CASE_ARG_CS(selected, result)
1168 #define ARG_CASE_ARG_SV(selected, result)
1169 #define ARG_CASE_ARG_DC(selected, result) case selected: { arg_slot[sel_num++] = result; break; }
1170 #define ARG_CASE(prog, selected, result) ARG_CASE_##prog(selected,result)
1173 #undef ARG_CASE_ARG_DC
1174 #undef ARG_CASE_ARG_SV
1175 #undef ARG_CASE_ARG_CS
1176 #undef ARG_CASE_ARG_CS_SV
1177 #undef ARG_CASE_ARG_CS_SV_DC
1178 #undef ARG_CASE_ARG_CS_SV_HA
1181 if (/* wtf */ ftos(stof(selected)) != "") { arg_slot[sel_num++] = selected; }
1182 else { NOTIF_HIT_UNKNOWN(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic") }
1187 #ifdef NOTIFICATIONS_DEBUG
1188 Debug_Notification(sprintf(
1189 "Local_Notification_centerprint_generic('%s^7', '%s', %d, %d, %d, %d);\n",
1190 MakeConsoleSafe(input),
1197 centerprint_generic(ORDINAL(cpid), input, stof(arg_slot[0]), stof(arg_slot[1]));
1201 void Local_Notification(MSG net_type, Notification net_name, ...count)
1203 // retreive entity of this notification
1204 entity notif = net_name;
1207 #ifdef NOTIFICATIONS_DEBUG
1208 Debug_Notification(sprintf(
1209 "Local_Notification(%s, NULL, ...);\n",
1210 Get_Notif_TypeName(net_type)
1213 LOG_WARNINGF("Incorrect usage of Local_Notification: %s\n", "Null notification");
1217 // check if the notification is enabled
1218 if (!notif.nent_enabled)
1220 #ifdef NOTIFICATIONS_DEBUG
1221 Debug_Notification(sprintf(
1222 "Local_Notification(%s, %s, ...): Entity was disabled...\n",
1223 Get_Notif_TypeName(net_type),
1230 string s1 = ((notif.nent_stringcount > 0) ? ...(0, string) : "");
1231 string s2 = ((notif.nent_stringcount > 1) ? ...(1, string) : "");
1232 string s3 = ((notif.nent_stringcount > 2) ? ...(2, string) : "");
1233 string s4 = ((notif.nent_stringcount > 3) ? ...(3, string) : "");
1234 float f1 = ((notif.nent_floatcount > 0) ? ...((notif.nent_stringcount + 0), float) : 0);
1235 float f2 = ((notif.nent_floatcount > 1) ? ...((notif.nent_stringcount + 1), float) : 0);
1236 float f3 = ((notif.nent_floatcount > 2) ? ...((notif.nent_stringcount + 2), float) : 0);
1237 float f4 = ((notif.nent_floatcount > 3) ? ...((notif.nent_stringcount + 3), float) : 0);
1239 #ifdef NOTIFICATIONS_DEBUG
1240 Debug_Notification(sprintf(
1241 "Local_Notification(%s, %s, %s, %s);\n",
1242 Get_Notif_TypeName(net_type),
1244 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1245 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1249 if ((notif.nent_stringcount + notif.nent_floatcount) != count)
1253 "Arguments mismatch for Local_Notification(%s, %s, ...)! "
1254 "stringcount(%d) + floatcount(%d) != count(%d)\n"
1255 "Check the definition and function call for accuracy...?\n"
1257 Get_Notif_TypeName(net_type),
1259 notif.nent_stringcount,
1260 notif.nent_floatcount,
1271 Local_Notification_sound(
1278 backtrace("MSG_ANNCE on server?... Please notify Samual immediately!\n");
1286 Local_Notification_sprintf(
1293 if (notif.nent_icon != "")
1295 if (notif.nent_iconargs != "")
1297 string s = Local_Notification_sprintf(
1298 notif.nent_icon,notif.nent_iconargs,
1299 s1, s2, s3, s4, f1, f2, f3, f4);
1300 // remove the trailing newline
1301 notif.nent_icon = strzone(substring(s, 0, -1));
1303 Local_Notification_HUD_Notify_Push(
1316 Local_Notification_centerprint_generic(
1317 Local_Notification_sprintf(
1331 if (notif.nent_msginfo && notif.nent_msginfo.nent_enabled)
1333 Local_Notification_WOVA(
1336 notif.nent_msginfo.nent_stringcount,
1337 notif.nent_msginfo.nent_floatcount,
1342 if (notif.nent_msgannce && notif.nent_msgannce.nent_enabled)
1344 Local_Notification_WOVA(
1346 notif.nent_msgannce,
1351 if (notif.nent_msgcenter && notif.nent_msgcenter.nent_enabled)
1353 Local_Notification_WOVA(
1355 notif.nent_msgcenter,
1356 notif.nent_msgcenter.nent_stringcount,
1357 notif.nent_msgcenter.nent_floatcount,
1367 entity found_choice = notif.nent_optiona;
1368 if (notif.nent_challow_var && (warmup_stage || (notif.nent_challow_var == 2))) {
1369 switch (cvar(sprintf("notification_%s", notif.nent_name)))
1372 case 2: found_choice = notif.nent_optionb; break;
1373 default: return; // not enabled anyway
1377 Local_Notification_WOVA(
1378 found_choice.nent_type,
1380 found_choice.nent_stringcount,
1381 found_choice.nent_floatcount,
1388 // WOVA = Without Variable Arguments
1389 void Local_Notification_WOVA(
1390 MSG net_type, Notification net_name,
1391 float stringcount, float floatcount,
1392 string s1, string s2, string s3, string s4,
1393 float f1, float f2, float f3, float f4)
1395 #define VARITEM(stringc, floatc, args) \
1396 if ((stringcount == stringc) && (floatcount == floatc)) \
1397 { Local_Notification(net_type, net_name, args); return; }
1398 EIGHT_VARS_TO_VARARGS_VARLIST
1400 Local_Notification(net_type, net_name); // some notifications don't have any arguments at all
1404 // =========================
1405 // Notification Networking
1406 // =========================
1408 /** networked as a linked entity to give newly connecting clients some notification context */
1409 REGISTER_NET_LINKED(ENT_CLIENT_NOTIFICATION)
1412 NET_HANDLE(ENT_CLIENT_NOTIFICATION, bool is_new)
1415 MSG net_type = ENUMCAST(MSG, ReadByte());
1416 int net_name = ReadShort();
1419 if (net_type == MSG_CENTER_KILL)
1421 if (!is_new) return;
1423 #ifdef NOTIFICATIONS_DEBUG
1424 Debug_Notification(sprintf(
1425 "Read_Notification(%d) at %f: net_type = %s, cpid = %d\n",
1428 Get_Notif_TypeName(net_type),
1432 int _net_name = net_name;
1433 CPID net_name = ENUMCAST(CPID, _net_name);
1434 if (net_name == CPID_Null) {
1436 reset_centerprint_messages();
1439 centerprint_generic(ORDINAL(net_name), "", 0, 0);
1444 Notification notif = Get_Notif_Ent(net_type, net_name);
1446 #ifdef NOTIFICATIONS_DEBUG
1447 Debug_Notification(sprintf(
1448 "Read_Notification(%d) at %f: net_type = %s, net_name = %s (%d)\n",
1451 Get_Notif_TypeName(net_type),
1452 notif.registered_id,
1458 backtrace("Read_Notification: Could not find notification entity!\n");
1462 string s1 = ((notif.nent_stringcount > 0) ? ReadString() : "");
1463 string s2 = ((notif.nent_stringcount > 1) ? ReadString() : "");
1464 string s3 = ((notif.nent_stringcount > 2) ? ReadString() : "");
1465 string s4 = ((notif.nent_stringcount > 3) ? ReadString() : "");
1466 float f1 = ((notif.nent_floatcount > 0) ? ReadLong() : 0);
1467 float f2 = ((notif.nent_floatcount > 1) ? ReadLong() : 0);
1468 float f3 = ((notif.nent_floatcount > 2) ? ReadLong() : 0);
1469 float f4 = ((notif.nent_floatcount > 3) ? ReadLong() : 0);
1471 if (!is_new) return;
1472 Local_Notification_WOVA(
1474 notif.nent_stringcount,
1475 notif.nent_floatcount,
1482 void Net_Notification_Remove()
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_WARNINGF("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);
1536 FOREACH_ENTITY_CLASS(
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 entity notif = net_name;
1552 string parms = sprintf("%s, '%s', %s, %s",
1553 Get_Notif_BroadcastName(broadcast),
1555 Get_Notif_TypeName(net_type),
1556 net_name.registered_id
1558 #ifdef NOTIFICATIONS_DEBUG
1559 Debug_Notification(sprintf("Send_Notification(%s, ...%d);\n", parms, count));
1564 LOG_WARNING("Send_Notification: Could not find notification entity!");
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 != "")
1573 LOG_WARNINGF("Incorrect usage of Send_Notification: %s", checkargs);
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);
1586 #ifdef NOTIFICATIONS_DEBUG
1587 Debug_Notification(sprintf(
1588 "Send_Notification(%s, %s, %s);\n",
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)
1595 if ((notif.nent_stringcount + notif.nent_floatcount) != count)
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",
1602 notif.nent_stringcount,
1603 notif.nent_floatcount,
1613 broadcast == NOTIF_ALL
1615 broadcast == NOTIF_ALL_EXCEPT
1619 net_type == MSG_ANNCE
1621 net_type == MSG_CENTER
1625 Local_Notification_WOVA(
1627 notif.nent_stringcount,
1628 notif.nent_floatcount,
1633 if (net_type == MSG_CHOICE)
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;
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]) \
1646 case 1: found_choice = notif.nent_optiona; break; \
1647 case 2: found_choice = notif.nent_optionb; break; \
1651 found_choice = notif.nent_optiona; \
1653 Send_Notification_WOVA( \
1656 found_choice.nent_type, \
1658 found_choice.nent_stringcount, \
1659 found_choice.nent_floatcount, \
1666 case NOTIF_ONE_ONLY: // we can potentially save processing power with this broadcast method
1668 if (IS_REAL_CLIENT(client)) {
1669 RECURSE_FROM_CHOICE(client, return);
1675 FOREACH_CLIENT(IS_REAL_CLIENT(it) && Notification_ShouldSend(broadcast, it, client), {
1676 RECURSE_FROM_CHOICE(it, continue);
1684 entity net_notif = new(net_notification);
1685 make_pure(net_notif);
1686 net_notif.owner = notif;
1687 net_notif.nent_broadcast = broadcast;
1688 net_notif.nent_client = client;
1689 net_notif.nent_net_type = net_type;
1690 net_notif.nent_net_name = notif.m_id;
1691 net_notif.nent_stringcount = notif.nent_stringcount;
1692 net_notif.nent_floatcount = notif.nent_floatcount;
1694 for (int i = 0; i < net_notif.nent_stringcount; ++i) {
1695 net_notif.nent_strings[i] = strzone(...(i, string));
1697 for (int i = 0; i < net_notif.nent_floatcount; ++i) {
1698 net_notif.nent_floats[i] = ...((net_notif.nent_stringcount + i), float);
1701 net_notif.think = Net_Notification_Remove;
1702 net_notif.nextthink = (time > autocvar_notification_lifetime_mapload)
1703 ? (time + autocvar_notification_lifetime_runtime)
1704 : autocvar_notification_lifetime_mapload;
1706 Net_LinkEntity(net_notif, false, 0, Net_Write_Notification);
1710 // WOVA = Without Variable Arguments
1711 void Send_Notification_WOVA(
1712 NOTIF broadcast, entity client,
1713 MSG net_type, Notification net_name,
1714 float stringcount, float floatcount,
1715 string s1, string s2, string s3, string s4,
1716 float f1, float f2, float f3, float f4)
1718 #ifdef NOTIFICATIONS_DEBUG
1719 entity notif = net_name;
1720 Debug_Notification(sprintf(
1721 "Send_Notification_WOVA(%s, %d, %d, %s, %s);\n",
1724 Get_Notif_BroadcastName(broadcast),
1726 Get_Notif_TypeName(net_type),
1731 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1732 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1736 #define VARITEM(stringc, floatc, args) \
1737 if ((stringcount == stringc) && (floatcount == floatc)) \
1738 { Send_Notification(broadcast, client, net_type, net_name, args); return; }
1739 EIGHT_VARS_TO_VARARGS_VARLIST
1741 Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
1744 // WOCOVA = Without Counts Or Variable Arguments
1745 void Send_Notification_WOCOVA(
1746 NOTIF broadcast, entity client,
1747 MSG net_type, Notification net_name,
1748 string s1, string s2, string s3, string s4,
1749 float f1, float f2, float f3, float f4)
1751 entity notif = net_name;
1753 #ifdef NOTIFICATIONS_DEBUG
1754 Debug_Notification(sprintf(
1755 "Send_Notification_WOCOVA(%s, %s, %s);\n",
1758 Get_Notif_BroadcastName(broadcast),
1760 Get_Notif_TypeName(net_type),
1763 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1764 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1768 #define VARITEM(stringc, floatc, args) \
1769 if ((notif.nent_stringcount == stringc) && (notif.nent_floatcount == floatc)) \
1770 { Send_Notification(broadcast, client, net_type, net_name, args); return; }
1771 EIGHT_VARS_TO_VARARGS_VARLIST
1773 Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
1775 #endif // ifdef SVQC