1 // ================================================
2 // Unified notification system, written by Samual
3 // Last updated: June, 2013
4 // ================================================
6 string Get_Notif_TypeName(float net_type)
10 case MSG_ANNCE: return "MSG_ANNCE";
11 case MSG_INFO: return "MSG_INFO";
12 case MSG_CENTER: return "MSG_CENTER";
13 case MSG_CENTER_CPID: return "MSG_CENTER_CPID";
14 case MSG_MULTI: return "MSG_MULTI";
15 case MSG_CHOICE: return "MSG_CHOICE";
17 backtrace(sprintf("Get_Notif_TypeName(%d): Improper net type!\n", net_type));
21 entity Get_Notif_Ent(float net_type, float net_name)
25 case MSG_ANNCE: return msg_annce_notifs[net_name - 1];
26 case MSG_INFO: return msg_info_notifs[net_name - 1];
27 case MSG_CENTER: return msg_center_notifs[net_name - 1];
28 case MSG_MULTI: return msg_multi_notifs[net_name - 1];
29 case MSG_CHOICE: return msg_choice_notifs[net_name - 1];
31 backtrace(sprintf("Get_Notif_Ent(%d, %d): Improper net type!\n", net_type, net_name));
35 string Notification_CheckArgs_TypeName(float net_type, float net_name)
37 // check supplied type and name for errors
38 string checkargs = "";
39 #define CHECKARG_TYPENAME(type) case MSG_##type##: \
40 { if(!net_name || (net_name > NOTIF_##type##_COUNT)) \
41 { checkargs = sprintf("Improper name: %d!", net_name); } break; }
44 CHECKARG_TYPENAME(ANNCE)
45 CHECKARG_TYPENAME(INFO)
46 CHECKARG_TYPENAME(CENTER)
47 CHECKARG_TYPENAME(MULTI)
48 CHECKARG_TYPENAME(CHOICE)
49 default: { checkargs = sprintf("Improper type: %d!", checkargs, net_type); break; }
51 #undef CHECKARG_TYPENAME
56 string Notification_CheckArgs(
57 float broadcast, entity client,
58 float net_type, float net_name)
60 // check supplied broadcast, target, type, and name for errors
61 string checkargs = Notification_CheckArgs_TypeName(net_type, net_name);
62 if(checkargs != "") { checkargs = strcat(checkargs, " "); }
68 if(IS_NOT_A_CLIENT(client))
69 { checkargs = sprintf("%sNo client provided!", checkargs); }
73 case NOTIF_ALL_EXCEPT:
75 if(IS_NOT_A_CLIENT(client))
76 { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
83 { checkargs = sprintf("%sEntity provided when world was required!", checkargs); }
88 case NOTIF_TEAM_EXCEPT:
90 if not(teamplay) { checkargs = sprintf("%sTeamplay not active!", checkargs); }
91 else if(IS_NOT_A_CLIENT(client))
93 if(broadcast == NOTIF_TEAM) { checkargs = sprintf("%sNo client provided!", checkargs); }
94 else { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
99 default: { checkargs = sprintf("%sImproper broadcast: %d!", checkargs, broadcast); break; }
105 // ===============================
106 // Initialization Core Functions
107 // ===============================
109 // used by restartnotifs command to initialize notifications
110 void Destroy_Notification_Entity(entity notif)
112 if(notif.nent_name != "") { strunzone(notif.nent_name); }
113 if(notif.nent_snd != "") { strunzone(notif.nent_snd); }
114 if(notif.nent_args != "") { strunzone(notif.nent_args); }
115 if(notif.nent_hudargs != "") { strunzone(notif.nent_hudargs); }
116 if(notif.nent_icon != "") { strunzone(notif.nent_icon); }
117 if(notif.nent_durcnt != "") { strunzone(notif.nent_durcnt); }
118 if(notif.nent_string != "") { strunzone(notif.nent_string); }
122 void Destroy_All_Notifications(void)
127 #define DESTROY_LOOP(type,count) \
128 for(i = 1; i <= count; ++i) \
130 notif = Get_Notif_Ent(type, i); \
131 if not(notif) { backtrace("Destroy_All_Notifications(): Missing notification entity!\n"); return; } \
132 Destroy_Notification_Entity(notif); \
135 // kill all networked notifications and centerprints
137 Kill_Notification(NOTIF_ALL, world, 0, 0);
139 reset_centerprint_messages();
142 // kill all real notification entities
143 DESTROY_LOOP(MSG_ANNCE, NOTIF_ANNCE_COUNT)
144 DESTROY_LOOP(MSG_INFO, NOTIF_INFO_COUNT)
145 DESTROY_LOOP(MSG_CENTER, NOTIF_CENTER_COUNT)
146 DESTROY_LOOP(MSG_MULTI, NOTIF_MULTI_COUNT)
147 DESTROY_LOOP(MSG_CHOICE, NOTIF_CHOICE_COUNT)
151 string Process_Notif_Line(
160 if(typeid == MSG_INFO)
162 if((chat && autocvar_notification_allow_chatboxprint)
163 || (autocvar_notification_allow_chatboxprint == 2))
165 // pass 1: add ETX char at beginning of line
166 input = strcat("\{3}", input);
168 // pass 2: add ETX char at end of each new line (so that
169 // messages with multiple lines are put through chatbox too)
170 input = strreplace("\n", "\n\{3}", input);
172 // pass 3: strip trailing ETX char
173 if(substring(input, (strlen(input) - 1), 1) == "\{3}")
174 { input = substring(input, 0, (strlen(input) - 1)); }
179 // done to both MSG_INFO and MSG_CENTER
180 if(substring(input, (strlen(input) - 1), 1) == "\n")
184 "^1TRAILING NEW LINE AT END OF NOTIFICATION: ",
185 "^7net_type = %s, net_name = %s, string = %s.\n"
192 input = substring(input, 1, (strlen(input) - 1));
198 string Process_Notif_Args(
204 string selected, remaining = args;
207 for(;(remaining != "");)
209 selected = car(remaining); remaining = cdr(remaining);
213 case 1: // normal args
215 if(sel_num == NOTIF_MAX_ARGS)
219 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
220 "^7net_type = %s, net_name = %s, max args = %d.\n"
230 switch(strtolower(selected))
232 #define ARG_CASE(prog,selected,result) \
233 #if (prog != ARG_DC) \
234 case selected: { ++sel_num; break; } \
242 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
243 "^7net_type = %s, net_name = %s, args arg = '%s'.\n"
257 if(sel_num == NOTIF_MAX_HUDARGS)
261 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
262 "^7net_type = %s, net_name = %s, max hudargs = %d.\n"
272 switch(strtolower(selected))
274 #define ARG_CASE(prog,selected,result) \
275 #if (prog == ARG_CS_SV_HA) \
276 case selected: { ++sel_num; break; } \
284 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
285 "^7net_type = %s, net_name = %s, hudargs arg = '%s'.\n"
299 if(sel_num == NOTIF_MAX_DURCNT)
303 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
304 "^7net_type = %s, net_name = %s, max durcnt = %d.\n"
314 switch(strtolower(selected))
316 #define ARG_CASE(prog,selected,result) \
317 #if (prog == ARG_CS_SV_DC) || (prog == ARG_DC) \
318 case selected: { ++sel_num; break; } \
324 if(ftos(stof(selected)) != "") { ++sel_num; }
329 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
330 "^7net_type = %s, net_name = %s, durcnt arg = '%s'.\n"
348 void Create_Notification_Entity(
374 // =====================
375 // Global Entity Setup
376 // =====================
377 entity notif = spawn();
378 string typestring = "";
383 typestring = "MSG_ANNCE";
384 msg_annce_notifs[nameid - 1] = notif;
385 notif.classname = "msg_annce_notification";
390 typestring = "MSG_INFO";
391 msg_info_notifs[nameid - 1] = notif;
392 notif.classname = "msg_info_notification";
397 typestring = "MSG_CENTER";
398 msg_center_notifs[nameid - 1] = notif;
399 notif.classname = "msg_center_notification";
404 typestring = "MSG_MULTI";
405 msg_multi_notifs[nameid - 1] = notif;
406 notif.classname = "msg_multi_notification";
411 typestring = "MSG_CHOICE";
412 msg_choice_notifs[nameid - 1] = notif;
413 notif.classname = "msg_choice_notification";
421 "^1NOTIFICATION WITH IMPROPER TYPE: ",
422 "^7net_type = %d, net_name = %s.\n"
427 return; // It's not possible to recover from this one
430 notif.nent_default = var_default;
431 notif.nent_name = strzone(namestring);
432 notif.nent_id = nameid;
433 notif.nent_enabled = (1 <= var_cvar);
435 // Other pre-notif-setup requisites
438 // ====================
439 // Notification Setup
440 // ====================
445 // Set MSG_ANNCE information and handle precaching
447 if not(GENTLE && (var_cvar == 1))
451 if(notif.nent_enabled)
453 precache_sound(sprintf("announcer/%s/%s.wav", autocvar_cl_announcer, snd));
454 notif.nent_channel = channel;
455 notif.nent_snd = strzone(snd);
456 notif.nent_vol = vol;
457 notif.nent_position = position;
464 "^1NOTIFICATION WITH NO SOUND: ",
465 "^7net_type = %s, net_name = %s.\n"
473 else { notif.nent_enabled = FALSE; }
475 notif.nent_enabled = FALSE;
484 // Set MSG_INFO and MSG_CENTER string/float counts
485 notif.nent_stringcount = strnum;
486 notif.nent_floatcount = flnum;
488 // Only initialize arguments if we're either a client or on a dedicated server
490 float should_process_args = server_is_dedicated;
492 float should_process_args = TRUE;
495 if(should_process_args)
497 // ========================
498 // Process Main Arguments
499 // ========================
504 notif.nent_args = strzone(
505 Process_Notif_Args(1, args, typestring, namestring));
507 else if((hudargs == "") && (durcnt ==""))
511 "^1NOTIFICATION HAS ARG COUNTS BUT NO ARGS OR HUDARGS OR DURCNT: ",
512 "^7net_type = %s, net_name = %s, strnum = %d, flnum = %d\n"
524 notif.nent_args = strzone(
525 Process_Notif_Args(1, args, typestring, namestring));
529 // =======================================
530 // Process HUD and Centerprint Arguments
531 // Only processed on CSQC, as these
532 // args are only for HUD features.
533 // =======================================
537 notif.nent_hudargs = strzone(
538 Process_Notif_Args(2, hudargs, typestring, namestring));
540 if(icon != "") { notif.nent_icon = strzone(icon); }
545 "^1NOTIFICATION HAS HUDARGS BUT NO ICON: ",
546 "^7net_type = %s, net_name = %s.\n"
558 "^1NOTIFICATION HAS ICON BUT NO HUDARGS: ",
559 "^7net_type = %s, net_name = %s.\n"
569 notif.nent_durcnt = strzone(
570 Process_Notif_Args(3, durcnt, typestring, namestring));
572 if(cpid != NO_MSG) { notif.nent_cpid = cpid; }
577 "^1NOTIFICATION HAS DURCNT BUT NO CPID: ",
578 "^7net_type = %s, net_name = %s.\n"
586 else if(cpid != NO_MSG) { notif.nent_cpid = cpid; }
590 // ======================
591 // Process Notif String
592 // ======================
593 #define SET_NOTIF_STRING(string,stringname) \
594 notif.nent_string = strzone(CCR( \
595 Process_Notif_Line( \
607 if(gentle != "") { SET_NOTIF_STRING(gentle, "GENTLE") }
608 else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL") }
610 else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL") }
612 #undef SET_NOTIF_STRING
614 // Check to make sure a string was chosen
615 if(notif.nent_string == "")
619 "^1EMPTY NOTIFICATION: ",
620 "^7net_type = %s, net_name = %s.\n"
634 // Set MSG_MULTI string/float counts
635 if((anncename == NO_MSG) && (infoname == NO_MSG) && (centername == NO_MSG))
639 "^1NOTIFICATION WITH NO SUBCALLS: ",
640 "^7net_type = %s, net_name = %s.\n"
649 // announcements don't actually need any arguments, so lets not even count them.
650 if(anncename != NO_MSG) { notif.nent_msgannce = msg_annce_notifs[anncename - 1]; }
652 float infoname_stringcount = 0, infoname_floatcount = 0;
653 float centername_stringcount = 0, centername_floatcount = 0;
655 if(infoname != NO_MSG)
657 notif.nent_msginfo = msg_info_notifs[infoname - 1];
658 infoname_stringcount = notif.nent_msginfo.nent_stringcount;
659 infoname_floatcount = notif.nent_msginfo.nent_floatcount;
662 if(centername != NO_MSG)
664 notif.nent_msgcenter = msg_center_notifs[centername - 1];
665 centername_stringcount = notif.nent_msgcenter.nent_stringcount;
666 centername_floatcount = notif.nent_msgcenter.nent_floatcount;
669 // set the requirements of THIS notification to the totals of its subcalls
670 notif.nent_stringcount = max(infoname_stringcount, centername_stringcount);
671 notif.nent_floatcount = max(infoname_floatcount, centername_floatcount);
682 default: print("DAFUQ?\n"); notif_error = TRUE; break;
685 // now check to see if any errors happened
688 notif.nent_enabled = FALSE; // disable the notification so it can't cause trouble
689 notif_global_error = TRUE; // throw the red flag that an error happened on init
694 // =========================================
695 // Cvar Handling With 'dumpnotifs' Command
696 // =========================================
698 void Dump_Notifications(float fh, float alsoprint)
700 #define NOTIF_WRITE(a) { \
702 if(alsoprint) { print(a); } }
703 #define NOTIF_WRITE_ENTITY(description) { \
706 "seta notification_%s \"%d\" \"%s\"\n", \
707 e.nent_name, e.nent_default, description \
709 NOTIF_WRITE(notif_msg) }
710 #define NOTIF_WRITE_HARDCODED(cvar,default,description) { \
713 "seta notification_%s \"%s\" \"%s\"\n", \
714 cvar, default, description \
716 NOTIF_WRITE(notif_msg) }
722 // Note: This warning only applies to the notifications.cfg file that is output...
724 // You ARE supposed to manually edit this function to add i.e. hard coded
725 // notification variables for mutators or game modes or such and then
726 // regenerate the notifications.cfg file from the new code.
728 NOTIF_WRITE("// ********************************************** //\n");
729 NOTIF_WRITE("// ** WARNING - DO NOT MANUALLY EDIT THIS FILE ** //\n");
730 NOTIF_WRITE("// ** ** //\n");
731 NOTIF_WRITE("// ** This file is automatically generated ** //\n");
732 NOTIF_WRITE("// ** by code with the command 'dumpnotifs'. ** //\n");
733 NOTIF_WRITE("// ** ** //\n");
734 NOTIF_WRITE("// ** If you add a new notification, please ** //\n");
735 NOTIF_WRITE("// ** regenerate this file with that command ** //\n");
736 NOTIF_WRITE("// ** making sure that the output matches ** //\n");
737 NOTIF_WRITE("// ** with the lists and defaults in code. ** //\n");
738 NOTIF_WRITE("// ** ** //\n");
739 NOTIF_WRITE("// ********************************************** //\n");
741 // These notifications will also append their string as a comment...
742 // This is not necessary, and does not matter if they vary between config versions,
743 // it is just a semi-helpful tool for those who want to manually change their user settings.
745 NOTIF_WRITE(sprintf("\n// MSG_ANNCE notifications (count = %d):\n", NOTIF_ANNCE_COUNT));
746 for(i = 1; i <= NOTIF_ANNCE_COUNT; ++i)
748 e = Get_Notif_Ent(MSG_ANNCE, i);
749 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
752 "Notification control cvar: 0 = disabled, 1 = enabled if gentle mode is off, 2 = always enabled)"
756 NOTIF_WRITE(sprintf("\n// MSG_INFO notifications (count = %d):\n", NOTIF_INFO_COUNT));
757 for(i = 1; i <= NOTIF_INFO_COUNT; ++i)
759 e = Get_Notif_Ent(MSG_INFO, i);
760 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
763 "Notification control cvar: 0 = off, 1 = print to console, "
764 "2 = print to console and chatbox (if notification_allow_chatboxprint is enabled)"
768 NOTIF_WRITE(sprintf("\n// MSG_CENTER notifications (count = %d):\n", NOTIF_CENTER_COUNT));
769 for(i = 1; i <= NOTIF_CENTER_COUNT; ++i)
771 e = Get_Notif_Ent(MSG_CENTER, i);
772 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
775 "Notification control cvar: 0 = off, 1 = centerprint"
779 NOTIF_WRITE(sprintf("\n// MSG_MULTI notifications (count = %d):\n", NOTIF_MULTI_COUNT));
780 for(i = 1; i <= NOTIF_MULTI_COUNT; ++i)
782 e = Get_Notif_Ent(MSG_MULTI, i);
783 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
786 "Notification control cvar: 0 = off, 1 = trigger subcalls"
790 NOTIF_WRITE(sprintf("\n// MSG_CHOICE notifications (count = %d):\n", NOTIF_CHOICE_COUNT));
791 for(i = 1; i <= NOTIF_CHOICE_COUNT; ++i)
793 e = Get_Notif_Ent(MSG_CHOICE, i);
794 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
797 "Notification control cvar: 0 = off, 1 = trigger option A subcall, 2 = trigger option B subcall"
801 // edit these to match whichever cvars are used for specific notification options
802 NOTIF_WRITE("\n// HARD CODED notification variables:\n");
804 NOTIF_WRITE_HARDCODED(
805 "allow_chatboxprint", "1",
806 "Allow notifications to be printed to chat box by setting notification cvar to 2 "
807 "(You can also set this cvar to 2 to force ALL notifications to be printed to the chatbox)"
810 NOTIF_WRITE_HARDCODED(
811 "ctf_capture_verbose", "0",
812 "Show extra information when someone captures a flag"
815 NOTIF_WRITE_HARDCODED(
816 "ctf_pickup_enemy_verbose", "0",
817 "Show extra information if an enemy picks up a flag"
820 NOTIF_WRITE_HARDCODED(
821 "ctf_pickup_team_verbose", "0",
822 "Show extra information if a team mate picks up a flag"
825 NOTIF_WRITE_HARDCODED(
827 "Print extra debug information on all notification function calls "
828 "(Requires -DNOTIFICATIONS_DEBUG flag to be enabled on QCSRC compilation)... "
829 "0 = disabled, 1 = dprint, 2 = print"
832 NOTIF_WRITE_HARDCODED(
833 "errors_are_fatal", "1",
834 "If a notification fails upon initialization, cause a Host_Error to stop the program"
837 NOTIF_WRITE_HARDCODED(
839 "Show extra information when you frag someone (or when you are fragged"
842 NOTIF_WRITE_HARDCODED(
843 "item_centerprinttime", "1.5",
844 "How long to show item information centerprint messages (like 'You got the Electro' or such)"
847 NOTIF_WRITE_HARDCODED(
848 "lifetime_mapload", "10",
849 "Amount of time that notification entities last immediately at mapload (in seconds) "
850 "to help prevent notifications from being lost on early init (like gamestart countdown)"
853 NOTIF_WRITE_HARDCODED(
854 "lifetime_runtime", "0.5",
855 "Amount of time that notification entities last on the server during runtime (In seconds)"
858 NOTIF_WRITE_HARDCODED(
859 "server_allows_frag_verbose", "1",
860 "Server side cvar for showing extra information in frag messages... 0 = no extra frag information, "
861 "1 = frag information only in warmup, 2 = frag information allowed all the time"
864 NOTIF_WRITE_HARDCODED(
865 "server_allows_location", "1",
866 "Server side cvar for allowing death messages to show location information too"
869 NOTIF_WRITE_HARDCODED(
870 "show_location", "0",
871 "Append location information to MSG_INFO death/kill messages"
874 NOTIF_WRITE_HARDCODED(
875 "show_location_string", "",
876 "Replacement string piped into sprintf, "
877 "so you can do different messages like this: ' at the %s' or ' (near %s)'"
880 NOTIF_WRITE_HARDCODED(
882 "Print information about sprees in death/kill messages"
885 NOTIF_WRITE_HARDCODED(
886 "show_sprees_center", "1",
887 "Show spree information in MSG_CENTER messages... "
888 "0 = off, 1 = target (but only for first victim) and attacker"
891 NOTIF_WRITE_HARDCODED(
892 "show_sprees_center_specialonly", "1",
893 "Don't show spree information in MSG_CENTER messages if it isn't an achievement"
896 NOTIF_WRITE_HARDCODED(
897 "show_sprees_info", "3",
898 "Show spree information in MSG_INFO messages... "
899 "0 = off, 1 = target only, 2 = attacker only, 3 = target and attacker"
902 NOTIF_WRITE_HARDCODED(
903 "show_sprees_info_newline", "1",
904 "Show attacker spree information for MSG_INFO messages on a separate line than the death notification itself"
907 NOTIF_WRITE_HARDCODED(
908 "show_sprees_info_specialonly", "1",
909 "Don't show attacker spree information in MSG_INFO messages if it isn't an achievement"
914 "\n// Notification counts (total = %d): ",
915 "MSG_ANNCE = %d, MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d, MSG_CHOICE = %d\n"
932 #undef NOTIF_WRITE_HARDCODED
933 #undef NOTIF_WRITE_ENTITY
938 void Notification_GetCvars()
940 GetCvars_handleFloat(get_cvars_s, get_cvars_f, FRAG_VERBOSE, "notification_frag_verbose");
945 // ===============================
946 // Frontend Notification Pushing
947 // ===============================
949 #ifdef NOTIFICATIONS_DEBUG
950 void Debug_Notification(string input)
952 switch(autocvar_notification_debug)
954 case 1: { dprint(input); break; }
955 case 2: { print(input); break; }
960 string Local_Notification_sprintf(
961 string input, string args,
962 string s1, string s2, string s3, string s4,
963 float f1, float f2, float f3, float f4)
965 #ifdef NOTIFICATIONS_DEBUG
966 Debug_Notification(sprintf(
967 "Local_Notification_sprintf('%s^7', '%s', %s, %s);\n",
968 MakeConsoleSafe(input),
970 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
971 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
977 for(sel_num = 0; sel_num < NOTIF_MAX_ARGS; ++sel_num) { arg_slot[sel_num] = ""; }
981 for(sel_num = 0;(args != "");)
983 selected = car(args); args = cdr(args);
984 NOTIF_HIT_MAX(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
985 switch(strtolower(selected))
987 #define ARG_CASE(prog,selected,result) \
989 #if (prog != ARG_SV) && (prog != ARG_DC) \
990 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
993 #if (prog != ARG_CS) && (prog != ARG_DC) \
994 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
999 default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
1002 return sprintf(strcat(input, "\n"), arg_slot[0], arg_slot[1], arg_slot[2], arg_slot[3], arg_slot[4], arg_slot[5], arg_slot[6]);
1006 void Local_Notification_sound(
1007 float soundchannel, string soundfile,
1008 float soundvolume, float soundposition)
1010 if((soundfile != prev_soundfile) || (time >= (prev_soundtime + autocvar_cl_announcer_antispam)))
1012 #ifdef NOTIFICATIONS_DEBUG
1013 Debug_Notification(sprintf(
1014 "Local_Notification_sound(world, %f, '%s', %f, %f);\n",
1017 "announcer/%s/%s.wav",
1018 autocvar_cl_announcer,
1030 "announcer/%s/%s.wav",
1031 autocvar_cl_announcer,
1038 if(prev_soundfile) { strunzone(prev_soundfile); }
1039 prev_soundfile = strzone(soundfile);
1040 prev_soundtime = time;
1044 #ifdef NOTIFICATIONS_DEBUG
1045 Debug_Notification(sprintf(
1047 "Local_Notification_sound(world, %f, '%s', %f, %f) ",
1048 "^1BLOCKED BY ANTISPAM:^7 prevsnd: '%s', timediff: %f, limit: %f\n"
1052 "announcer/%s/%s.wav",
1053 autocvar_cl_announcer,
1059 (time - prev_soundtime),
1060 autocvar_cl_announcer_antispam
1066 void Local_Notification_HUD_Notify_Push(
1067 string icon, string hudargs,
1068 string s1, string s2, string s3, string s4)
1072 arg_slot[0] = ""; arg_slot[1] = "";
1074 for(sel_num = 0;(hudargs != "");)
1076 selected = car(hudargs); hudargs = cdr(hudargs);
1077 NOTIF_HIT_MAX(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
1078 switch(strtolower(selected))
1080 #define ARG_CASE(prog,selected,result) \
1081 #if (prog == ARG_CS_SV_HA) \
1082 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
1086 default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
1089 #ifdef NOTIFICATIONS_DEBUG
1090 Debug_Notification(sprintf(
1091 "Local_Notification_HUD_Notify_Push('%s^7', '%s', %s, %s);\n",
1094 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1095 MakeConsoleSafe(sprintf("'%s^7', '%s^7'", stof(arg_slot[0]), stof(arg_slot[1])))
1098 HUD_Notify_Push(icon, arg_slot[0], arg_slot[1]);
1101 void Local_Notification_centerprint_generic(
1102 string input, string durcnt,
1103 float cpid, float f1, float f2)
1107 arg_slot[0] = ""; arg_slot[1] = "";
1109 for(sel_num = 0;(durcnt != "");)
1111 selected = car(durcnt); durcnt = cdr(durcnt);
1112 NOTIF_HIT_MAX(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic")
1113 switch(strtolower(selected))
1115 #define ARG_CASE(prog,selected,result) \
1116 #if (prog == ARG_CS_SV_DC) || (prog == ARG_DC) \
1117 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
1123 if(ftos(stof(selected)) != "") { arg_slot[sel_num] = selected; ++sel_num; }
1124 else { NOTIF_HIT_UNKNOWN(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic") }
1129 #ifdef NOTIFICATIONS_DEBUG
1130 Debug_Notification(sprintf(
1131 "Local_Notification_centerprint_generic('%s^7', '%s', %d, %d, %d, %d);\n",
1132 MakeConsoleSafe(input),
1135 stof(arg_slot[0]), stof(arg_slot[1])
1138 centerprint_generic(cpid, input, stof(arg_slot[0]), stof(arg_slot[1]));
1142 void Local_Notification(float net_type, float net_name, ...count)
1144 // check supplied type and name for errors
1145 string checkargs = Notification_CheckArgs_TypeName(net_type, net_name);
1146 if(checkargs != "") { backtrace(sprintf("Incorrect usage of Local_Notification: %s\n", checkargs)); return; }
1148 entity notif = Get_Notif_Ent(net_type, net_name);
1149 if not(notif) { backtrace("Local_Notification: Could not find notification entity!\n"); return; }
1150 if not(notif.nent_enabled)
1152 #ifdef NOTIFICATIONS_DEBUG
1153 Debug_Notification(sprintf(
1154 "Local_Notification(%s, %s): Entity was disabled...\n",
1155 Get_Notif_TypeName(net_type),
1162 if((notif.nent_stringcount + notif.nent_floatcount) > count)
1166 "Not enough arguments for Local_Notification(%s, %s, ...)! ",
1167 "stringcount(%d) + floatcount(%d) > count(%d)\n",
1168 "Check the definition and function call for accuracy...?\n"
1170 Get_Notif_TypeName(net_type), notif.nent_name,
1171 notif.nent_stringcount, notif.nent_floatcount, count
1175 else if((notif.nent_stringcount + notif.nent_floatcount) < count)
1179 "Too many arguments for Local_Notification(%s, %s, ...)! ",
1180 "stringcount(%d) + floatcount(%d) < count(%d)\n",
1181 "Check the definition and function call for accuracy...?\n"
1183 Get_Notif_TypeName(net_type), notif.nent_name,
1184 notif.nent_stringcount, notif.nent_floatcount, count
1189 string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
1190 string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
1191 string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
1192 string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
1193 float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
1194 float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
1195 float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
1196 float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
1198 #ifdef NOTIFICATIONS_DEBUG
1199 Debug_Notification(sprintf(
1200 "Local_Notification(%s, %s, %s, %s);\n",
1201 Get_Notif_TypeName(net_type),
1203 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1204 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1213 Local_Notification_sound(
1220 backtrace("MSG_ANNCE on server?... Please notify Samual immediately!\n");
1228 Local_Notification_sprintf(
1235 if(notif.nent_icon != "")
1237 Local_Notification_HUD_Notify_Push(
1249 Local_Notification_centerprint_generic(
1250 Local_Notification_sprintf(
1264 if(notif.nent_msginfo)
1265 if(notif.nent_msginfo.nent_enabled)
1267 Local_Notification_WOVA(
1269 notif.nent_msginfo.nent_id,
1270 notif.nent_msginfo.nent_stringcount,
1271 notif.nent_msginfo.nent_floatcount,
1276 if(notif.nent_msgannce)
1277 if(notif.nent_msgannce.nent_enabled)
1279 Local_Notification_WOVA(
1281 notif.nent_msgannce.nent_id,
1286 if(notif.nent_msgcenter)
1287 if(notif.nent_msgcenter.nent_enabled)
1289 Local_Notification_WOVA(
1291 notif.nent_msgcenter.nent_id,
1292 notif.nent_msgcenter.nent_stringcount,
1293 notif.nent_msgcenter.nent_floatcount,
1303 // WOVA = Without Variable Arguments
1304 void Local_Notification_WOVA(
1305 float net_type, float net_name,
1306 float stringcount, float floatcount,
1307 string s1, string s2, string s3, string s4,
1308 float f1, float f2, float f3, float f4)
1310 #define VARITEM(stringc,floatc,args) \
1311 if((stringcount == stringc) && (floatcount == floatc)) \
1312 { Local_Notification(net_type, net_name, args); return; }
1313 EIGHT_VARS_TO_VARARGS_VARLIST
1315 Local_Notification(net_type, net_name); // some notifications don't have any arguments at all
1319 // =========================
1320 // Notification Networking
1321 // =========================
1324 void Read_Notification(float is_new)
1326 float net_type = ReadByte();
1327 float net_name = ReadShort();
1331 if(net_type == MSG_CENTER_CPID)
1333 #ifdef NOTIFICATIONS_DEBUG
1334 Debug_Notification(sprintf(
1335 "Read_Notification(%d) at %f: net_type = %s, net_name = %d\n",
1338 Get_Notif_TypeName(net_type),
1345 if(net_name == 0) { reset_centerprint_messages(); }
1346 else if(net_name != NO_CPID)
1348 // in this case, net_name IS the cpid we want to kill
1349 centerprint_generic(net_name, "", 0, 0);
1354 "Read_Notification(%d) at %f: ^1TRIED TO KILL NO_CPID CENTERPRINT!\n",
1363 notif = Get_Notif_Ent(net_type, net_name);
1364 if not(notif) { backtrace("Read_Notification: Could not find notification entity!\n"); return; }
1366 #ifdef NOTIFICATIONS_DEBUG
1367 Debug_Notification(sprintf(
1368 "Read_Notification(%d) at %f: net_type = %s, net_name = %s\n",
1371 Get_Notif_TypeName(net_type),
1376 string s1 = ((0 < notif.nent_stringcount) ? ReadString() : "");
1377 string s2 = ((1 < notif.nent_stringcount) ? ReadString() : "");
1378 string s3 = ((2 < notif.nent_stringcount) ? ReadString() : "");
1379 string s4 = ((3 < notif.nent_stringcount) ? ReadString() : "");
1380 float f1 = ((0 < notif.nent_floatcount) ? ReadLong() : 0);
1381 float f2 = ((1 < notif.nent_floatcount) ? ReadLong() : 0);
1382 float f3 = ((2 < notif.nent_floatcount) ? ReadLong() : 0);
1383 float f4 = ((3 < notif.nent_floatcount) ? ReadLong() : 0);
1387 Local_Notification_WOVA(
1389 notif.nent_stringcount,
1390 notif.nent_floatcount,
1399 void Net_Notification_Remove()
1401 if not(self) { backtrace(sprintf("Net_Notification_Remove() at %f: Missing self!?\n", time)); return; }
1403 #ifdef NOTIFICATIONS_DEBUG
1404 Debug_Notification(sprintf(
1405 "Net_Notification_Remove() at %f: %s '%s - %s' notification\n",
1407 ((self.nent_net_name == -1) ? "Killed" : "Removed"),
1408 Get_Notif_TypeName(self.nent_net_type),
1409 self.owner.nent_name
1414 for(i = 0; i < 4; ++i) { if(self.nent_strings[i]) { strunzone(self.nent_strings[i]); } }
1418 float Net_Write_Notification(entity client, float sf)
1420 float i, send = FALSE;
1422 switch(self.nent_broadcast)
1424 case NOTIF_ONE: // send to one client and their spectator
1427 (client == self.nent_client)
1432 (client.enemy == self.nent_client)
1437 case NOTIF_ONE_ONLY: // send ONLY to one client
1439 if(client == self.nent_client) { send = TRUE; }
1442 case NOTIF_TEAM: // send only to X team and their spectators
1445 (client.team == self.nent_client.team)
1450 (client.enemy.team == self.nent_client.team)
1455 case NOTIF_TEAM_EXCEPT: // send only to X team and their spectators, except for Y person and their spectators
1458 (client != self.nent_client)
1461 (client.team == self.nent_client.team)
1467 (client.enemy != self.nent_client)
1469 (client.enemy.team == self.nent_client.team)
1476 case NOTIF_ALL: // send to everyone
1481 case NOTIF_ALL_EXCEPT: // send to everyone except X person and their spectators
1484 (client != self.nent_client)
1489 (client.enemy == self.nent_client)
1494 default: { send = FALSE; break; }
1499 WriteByte(MSG_ENTITY, ENT_CLIENT_NOTIFICATION);
1500 WriteByte(MSG_ENTITY, self.nent_net_type);
1501 WriteShort(MSG_ENTITY, self.nent_net_name);
1502 for(i = 0; i < self.nent_stringcount; ++i) { WriteString(MSG_ENTITY, self.nent_strings[i]); }
1503 for(i = 0; i < self.nent_floatcount; ++i) { WriteLong(MSG_ENTITY, self.nent_floats[i]); }
1509 void Kill_Notification(
1510 float broadcast, entity client,
1511 float net_type, float net_name)
1513 string checkargs = Notification_CheckArgs(broadcast, client, 1, 1);
1514 if(checkargs != "") { backtrace(sprintf("Incorrect usage of Kill_Notification: %s\n", checkargs)); return; }
1516 #ifdef NOTIFICATIONS_DEBUG
1517 Debug_Notification(sprintf(
1518 "Kill_Notification(%d, '%s', %s, %d);\n",
1521 (net_type ? Get_Notif_TypeName(net_type) : "0"),
1526 entity notif, net_notif;
1527 float killed_cpid = NO_CPID;
1533 killed_cpid = 0; // kill ALL centerprints
1541 entity notif = Get_Notif_Ent(net_type, net_name);
1542 if not(notif) { backtrace("Kill_Notification: Could not find notification entity!\n"); return; }
1545 killed_cpid = notif.nent_cpid;
1547 killed_cpid = NO_CPID;
1551 killed_cpid = 0; // kill ALL centerprints
1556 case MSG_CENTER_CPID:
1558 killed_cpid = net_name;
1563 if(killed_cpid != NO_CPID)
1565 net_notif = spawn();
1566 net_notif.classname = "net_kill_notification";
1567 net_notif.nent_broadcast = broadcast;
1568 net_notif.nent_client = client;
1569 net_notif.nent_net_type = MSG_CENTER_CPID;
1570 net_notif.nent_net_name = killed_cpid;
1571 Net_LinkEntity(net_notif, FALSE, autocvar_notification_lifetime_runtime, Net_Write_Notification);
1574 for(notif = world; (notif = find(notif, classname, "net_notification"));)
1578 if((killed_cpid != NO_CPID) && (notif.nent_net_type == MSG_CENTER))
1580 if(notif.owner.nent_cpid == killed_cpid)
1582 notif.nent_net_name = -1;
1583 notif.nextthink = time;
1585 else { continue; } // we ARE looking for a specific CPID, don't kill everything else too
1587 else if(notif.nent_net_type == net_type)
1591 if(notif.nent_net_name == net_name) { notif.nent_net_name = -1; notif.nextthink = time; }
1592 else { continue; } // we ARE looking for a certain net_name, don't kill everything else too
1594 else { notif.nent_net_name = -1; notif.nextthink = time; }
1596 else { continue; } // we ARE looking for a certain net_type, don't kill everything else too
1598 else { notif.nent_net_name = -1; notif.nextthink = time; }
1602 void Send_Notification(
1603 float broadcast, entity client,
1604 float net_type, float net_name,
1607 // check supplied broadcast, target, type, and name for errors
1608 string checkargs = Notification_CheckArgs(broadcast, client, net_type, net_name);
1609 if(checkargs != "") { backtrace(sprintf("Incorrect usage of Send_Notification: %s\n", checkargs)); return; }
1611 // retreive counts for the arguments of this notification
1612 entity notif = Get_Notif_Ent(net_type, net_name);
1613 if not(notif) { backtrace("Send_Notification: Could not find notification entity!\n"); return; }
1615 if((notif.nent_stringcount + notif.nent_floatcount) > count)
1619 "Not enough arguments for Send_Notification(%d, %s, %s, ...)! ",
1620 "stringcount(%d) + floatcount(%d) > count(%d)\n",
1621 "Check the definition and function call for accuracy...?\n"
1623 broadcast, Get_Notif_TypeName(net_type), notif.nent_name,
1624 notif.nent_stringcount, notif.nent_floatcount, count
1628 else if((notif.nent_stringcount + notif.nent_floatcount) < count)
1632 "Too many arguments for Send_Notification(%d, %s, %s, ...)! ",
1633 "stringcount(%d) + floatcount(%d) < count(%d)\n",
1634 "Check the definition and function call for accuracy...?\n"
1636 broadcast, Get_Notif_TypeName(net_type), notif.nent_name,
1637 notif.nent_stringcount, notif.nent_floatcount, count
1642 #ifdef NOTIFICATIONS_DEBUG
1643 string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
1644 string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
1645 string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
1646 string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
1647 float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
1648 float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
1649 float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
1650 float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
1651 Debug_Notification(sprintf(
1652 "Send_Notification(%d, %s, %s, %s, %s);\n",
1654 Get_Notif_TypeName(net_type),
1656 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1657 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1661 entity net_notif = spawn();
1662 net_notif.owner = notif;
1663 net_notif.classname = "net_notification";
1664 net_notif.nent_broadcast = broadcast;
1665 net_notif.nent_client = client;
1666 net_notif.nent_net_type = net_type;
1667 net_notif.nent_net_name = net_name;
1668 net_notif.nent_stringcount = notif.nent_stringcount;
1669 net_notif.nent_floatcount = notif.nent_floatcount;
1672 for(i = 0; i < net_notif.nent_stringcount; ++i)
1673 { net_notif.nent_strings[i] = strzone(...(i, string)); }
1674 for(i = 0; i < net_notif.nent_floatcount; ++i)
1675 { net_notif.nent_floats[i] = ...((net_notif.nent_stringcount + i), float); }
1677 net_notif.think = Net_Notification_Remove;
1678 net_notif.nextthink =
1679 ((time > autocvar_notification_lifetime_mapload)
1681 (time + autocvar_notification_lifetime_runtime)
1683 autocvar_notification_lifetime_mapload
1686 Net_LinkEntity(net_notif, FALSE, 0, Net_Write_Notification);
1692 broadcast == NOTIF_ALL
1694 broadcast == NOTIF_ALL_EXCEPT
1698 net_type == MSG_ANNCE
1700 net_type == MSG_CENTER
1704 Local_Notification_WOVA(
1706 notif.nent_stringcount,
1707 notif.nent_floatcount,
1708 IFSTR(0), IFSTR(1), IFSTR(2), IFSTR(3),
1709 IFFL(0), IFFL(1), IFFL(2), IFFL(3));
1713 // WOVA = Without Variable Arguments
1714 void Send_Notification_WOVA(
1715 float broadcast, entity client,
1716 float net_type, float net_name,
1717 string s1, string s2, string s3, string s4,
1718 float f1, float f2, float f3, float f4)
1720 entity notif = Get_Notif_Ent(net_type, net_name);
1722 #ifdef NOTIFICATIONS_DEBUG
1723 Debug_Notification(sprintf(
1724 "Send_Notification_WOVA(%d, %s, %s, %s, %s);\n",
1726 Get_Notif_TypeName(net_type),
1728 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1729 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1733 #define VARITEM(stringc,floatc,args) \
1734 if((notif.nent_stringcount == stringc) && (notif.nent_floatcount == floatc)) \
1735 { Send_Notification(broadcast, client, net_type, net_name, args); return; }
1736 EIGHT_VARS_TO_VARARGS_VARLIST
1738 Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
1740 #endif // ifdef SVQC