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()
763 FOREACH(Notifications, it.nent_type == MSG_CHOICE, {
764 GetCvars_handleFloat(
767 msg_choice_choices[it.nent_choice_idx],
768 sprintf("notification_%s", it.nent_name)
774 /** used to output notifications.cfg file */
775 void Dump_Notifications(int fh, bool alsoprint)
777 #define NOTIF_WRITE(a) MACRO_BEGIN { \
779 if (alsoprint) LOG_INFO(a); \
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 \
787 NOTIF_WRITE(notif_msg); \
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 \
797 NOTIF_WRITE(notif_msg); \
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 \
805 NOTIF_WRITE(notif_msg); \
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.
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");
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.
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"
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)"
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"
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"
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"
872 // edit these to match whichever cvars are used for specific notification options
873 NOTIF_WRITE("\n// HARD CODED notification variables:\n");
875 NOTIF_WRITE_HARDCODED(
876 "allow_chatboxprint", "1",
877 "Allow INFO notifications to be printed to chat box"
879 "1 = allow only if allowed by individual notification_INFO* cvars, "
880 "2 = force all INFO notifications to be printed to the chatbox"
883 NOTIF_WRITE_HARDCODED(
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"
890 NOTIF_WRITE_HARDCODED(
891 "errors_are_fatal", "1",
892 "If a notification fails upon initialization, cause a Host_Error to stop the program"
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)"
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)"
906 NOTIF_WRITE_HARDCODED(
907 "lifetime_runtime", "0.5",
908 "Amount of time that notification entities last on the server during runtime (In seconds)"
911 NOTIF_WRITE_HARDCODED(
912 "server_allows_location", "1",
913 "Server side cvar for allowing death messages to show location information too"
916 NOTIF_WRITE_HARDCODED(
917 "show_location", "0",
918 "Append location information to MSG_INFO death/kill messages"
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)'"
927 NOTIF_WRITE_HARDCODED(
929 "Print information about sprees in death/kill messages"
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"
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"
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"
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"
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"
961 "\n// Notification counts (total = %d): "
962 "MSG_ANNCE = %d, MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d, MSG_CHOICE = %d\n"
977 #undef NOTIF_WRITE_HARDCODED
978 #undef NOTIF_WRITE_ENTITY
983 // ===============================
984 // Frontend Notification Pushing
985 // ===============================
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)
992 #ifdef NOTIFICATIONS_DEBUG
993 Debug_Notification(sprintf(
994 "Local_Notification_sprintf('%s^7', '%s', %s, %s);\n",
995 MakeConsoleSafe(input),
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)
1002 for (int sel_num = 0; sel_num < NOTIF_MAX_ARGS; ++sel_num) { arg_slot[sel_num] = ""; }
1004 for (int sel_num = 0; (args != ""); )
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))
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; }
1015 #define ARG_CASE_ARG_CS(selected, result) case selected: { arg_slot[sel_num++] = result; break; }
1016 #define ARG_CASE_ARG_SV(selected, result)
1018 #define ARG_CASE_ARG_CS(selected, result)
1019 #define ARG_CASE_ARG_SV(selected, result) case selected: { arg_slot[sel_num++] = result; break; }
1021 #define ARG_CASE_ARG_DC(selected, result)
1022 #define ARG_CASE(prog, selected, result) ARG_CASE_##prog(selected, result)
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")
1035 strcat(input, "\n"),
1047 void Local_Notification_sound(
1048 int soundchannel, string soundfile,
1049 float soundvolume, float soundposition)
1051 if ((soundfile != prev_soundfile) || (time >= (prev_soundtime + autocvar_cl_announcer_antispam)))
1053 #ifdef NOTIFICATIONS_DEBUG
1054 Debug_Notification(sprintf(
1055 "Local_Notification_sound(%f, '%s', %f, %f);\n",
1058 "announcer/%s/%s.wav",
1071 "announcer/%s/%s.wav",
1079 if (prev_soundfile) strunzone(prev_soundfile);
1080 prev_soundfile = strzone(soundfile);
1081 prev_soundtime = time;
1085 #ifdef NOTIFICATIONS_DEBUG
1086 Debug_Notification(sprintf(
1088 "Local_Notification_sound(world, %f, '%s', %f, %f) "
1089 "^1BLOCKED BY ANTISPAM:^7 prevsnd: '%s', timediff: %f, limit: %f\n"
1093 "announcer/%s/%s.wav",
1100 (time - prev_soundtime),
1101 autocvar_cl_announcer_antispam
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)
1112 arg_slot[0] = ""; arg_slot[1] = "";
1114 for (int sel_num = 0; (hudargs != ""); )
1116 string selected = car(hudargs); hudargs = cdr(hudargs);
1117 NOTIF_HIT_MAX(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push");
1118 switch (strtolower(selected))
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)
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")
1138 #ifdef NOTIFICATIONS_DEBUG
1139 Debug_Notification(sprintf(
1140 "Local_Notification_HUD_Notify_Push('%s^7', '%s', %s, %s, %s);\n",
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])))
1148 HUD_Notify_Push(icon, arg_slot[0], arg_slot[1]);
1151 void Local_Notification_centerprint_generic(
1152 string input, string durcnt,
1153 CPID cpid, float f1, float f2)
1155 arg_slot[0] = ""; arg_slot[1] = "";
1157 for (int sel_num = 0; (durcnt != ""); )
1159 string selected = car(durcnt); durcnt = cdr(durcnt);
1160 NOTIF_HIT_MAX(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic");
1161 switch (strtolower(selected))
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)
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
1180 if (/* wtf */ ftos(stof(selected)) != "") { arg_slot[sel_num++] = selected; }
1181 else { NOTIF_HIT_UNKNOWN(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic") }
1186 #ifdef NOTIFICATIONS_DEBUG
1187 Debug_Notification(sprintf(
1188 "Local_Notification_centerprint_generic('%s^7', '%s', %d, %d, %d, %d);\n",
1189 MakeConsoleSafe(input),
1196 centerprint_generic(ORDINAL(cpid), input, stof(arg_slot[0]), stof(arg_slot[1]));
1200 void Local_Notification(MSG net_type, Notification net_name, ...count)
1202 // retreive entity of this notification
1203 entity notif = net_name;
1206 #ifdef NOTIFICATIONS_DEBUG
1207 Debug_Notification(sprintf(
1208 "Local_Notification(%s, NULL, ...);\n",
1209 Get_Notif_TypeName(net_type)
1212 LOG_WARNINGF("Incorrect usage of Local_Notification: %s\n", "Null notification");
1216 // check if the notification is enabled
1217 if (!notif.nent_enabled)
1219 #ifdef NOTIFICATIONS_DEBUG
1220 Debug_Notification(sprintf(
1221 "Local_Notification(%s, %s, ...): Entity was disabled...\n",
1222 Get_Notif_TypeName(net_type),
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);
1238 #ifdef NOTIFICATIONS_DEBUG
1239 Debug_Notification(sprintf(
1240 "Local_Notification(%s, %s, %s, %s);\n",
1241 Get_Notif_TypeName(net_type),
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)
1248 if ((notif.nent_stringcount + notif.nent_floatcount) != count)
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"
1256 Get_Notif_TypeName(net_type),
1258 notif.nent_stringcount,
1259 notif.nent_floatcount,
1270 Local_Notification_sound(
1277 backtrace("MSG_ANNCE on server?... Please notify Samual immediately!\n");
1285 Local_Notification_sprintf(
1292 if (notif.nent_icon != "")
1294 if (notif.nent_iconargs != "")
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));
1302 Local_Notification_HUD_Notify_Push(
1315 Local_Notification_centerprint_generic(
1316 Local_Notification_sprintf(
1330 if (notif.nent_msginfo && notif.nent_msginfo.nent_enabled)
1332 Local_Notification_WOVA(
1335 notif.nent_msginfo.nent_stringcount,
1336 notif.nent_msginfo.nent_floatcount,
1341 if (notif.nent_msgannce && notif.nent_msgannce.nent_enabled)
1343 Local_Notification_WOVA(
1345 notif.nent_msgannce,
1350 if (notif.nent_msgcenter && notif.nent_msgcenter.nent_enabled)
1352 Local_Notification_WOVA(
1354 notif.nent_msgcenter,
1355 notif.nent_msgcenter.nent_stringcount,
1356 notif.nent_msgcenter.nent_floatcount,
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)))
1371 case 2: found_choice = notif.nent_optionb; break;
1372 default: return; // not enabled anyway
1376 Local_Notification_WOVA(
1377 found_choice.nent_type,
1379 found_choice.nent_stringcount,
1380 found_choice.nent_floatcount,
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)
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
1399 Local_Notification(net_type, net_name); // some notifications don't have any arguments at all
1403 // =========================
1404 // Notification Networking
1405 // =========================
1407 /** networked as a linked entity to give newly connecting clients some notification context */
1408 REGISTER_NET_LINKED(ENT_CLIENT_NOTIFICATION)
1411 NET_HANDLE(ENT_CLIENT_NOTIFICATION, bool is_new)
1414 MSG net_type = ENUMCAST(MSG, ReadByte());
1415 int net_name = ReadShort();
1418 if (net_type == MSG_CENTER_KILL)
1420 if (!is_new) return;
1422 #ifdef NOTIFICATIONS_DEBUG
1423 Debug_Notification(sprintf(
1424 "Read_Notification(%d) at %f: net_type = %s, cpid = %d\n",
1427 Get_Notif_TypeName(net_type),
1431 int _net_name = net_name;
1432 CPID net_name = ENUMCAST(CPID, _net_name);
1433 if (net_name == CPID_Null) {
1435 reset_centerprint_messages();
1438 centerprint_generic(ORDINAL(net_name), "", 0, 0);
1443 Notification notif = Get_Notif_Ent(net_type, net_name);
1445 #ifdef NOTIFICATIONS_DEBUG
1446 Debug_Notification(sprintf(
1447 "Read_Notification(%d) at %f: net_type = %s, net_name = %s (%d)\n",
1450 Get_Notif_TypeName(net_type),
1451 notif.registered_id,
1457 backtrace("Read_Notification: Could not find notification entity!\n");
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);
1470 if (!is_new) return;
1471 Local_Notification_WOVA(
1473 notif.nent_stringcount,
1474 notif.nent_floatcount,
1481 void Net_Notification_Remove()
1484 #ifdef NOTIFICATIONS_DEBUG
1485 Debug_Notification(sprintf(
1486 "Net_Notification_Remove() at %f: %s '%s - %s' notification\n",
1488 ((this.nent_net_name == -1) ? "Killed" : "Removed"),
1489 Get_Notif_TypeName(this.nent_net_type),
1490 this.owner.nent_name
1493 for (int i = 0; i < this.nent_stringcount; ++i) { if (this.nent_strings[i]) strunzone(this.nent_strings[i]); }
1497 bool Net_Write_Notification(entity this, entity client, int sf)
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]); }
1508 void Kill_Notification(
1509 NOTIF broadcast, entity client,
1510 /** message group, MSG_Null for all */
1512 /** cpid group, CPID_Null for all */
1515 #ifdef NOTIFICATIONS_DEBUG
1516 Debug_Notification(sprintf(
1517 "Kill_Notification(%s, '%s', %s, %d);\n",
1518 Get_Notif_BroadcastName(broadcast),
1520 (net_type ? Get_Notif_TypeName(net_type) : "0"),
1525 string checkargs = Notification_CheckArgs(broadcast, client);
1526 if (checkargs != "") { LOG_WARNINGF("Incorrect usage of Kill_Notification: %s", checkargs); return; }
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);
1535 FOREACH_ENTITY_CLASS(
1537 (it.owner.nent_type == net_type || net_type == MSG_Null) && (it.owner.nent_cpid == net_cpid || net_cpid == CPID_Null),
1539 it.nent_net_name = -1;
1540 it.nextthink = time;
1545 void Send_Notification(
1546 NOTIF broadcast, entity client,
1547 MSG net_type, Notification net_name,
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),
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_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;
1693 for (int i = 0; i < net_notif.nent_stringcount; ++i) {
1694 net_notif.nent_strings[i] = strzone(...(i, string));
1696 for (int i = 0; i < net_notif.nent_floatcount; ++i) {
1697 net_notif.nent_floats[i] = ...((net_notif.nent_stringcount + i), float);
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;
1705 Net_LinkEntity(net_notif, false, 0, Net_Write_Notification);
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)
1717 #ifdef NOTIFICATIONS_DEBUG
1718 entity notif = net_name;
1719 Debug_Notification(sprintf(
1720 "Send_Notification_WOVA(%s, %d, %d, %s, %s);\n",
1723 Get_Notif_BroadcastName(broadcast),
1725 Get_Notif_TypeName(net_type),
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)
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
1740 Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
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)
1750 entity notif = net_name;
1752 #ifdef NOTIFICATIONS_DEBUG
1753 Debug_Notification(sprintf(
1754 "Send_Notification_WOCOVA(%s, %s, %s);\n",
1757 Get_Notif_BroadcastName(broadcast),
1759 Get_Notif_TypeName(net_type),
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)
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
1772 Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
1774 #endif // ifdef SVQC