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 // edit these to match whichever cvars are used for specific notification options
791 NOTIF_WRITE("\n// HARD CODED notification variables:\n");
793 NOTIF_WRITE_HARDCODED(
794 "allow_chatboxprint", "1",
795 "Allow notifications to be printed to chat box by setting notification cvar to 2 "
796 "(You can also set this cvar to 2 to force ALL notifications to be printed to the chatbox)"
799 NOTIF_WRITE_HARDCODED(
800 "ctf_capture_verbose", "0",
801 "Show extra information when someone captures a flag"
804 NOTIF_WRITE_HARDCODED(
805 "ctf_pickup_enemy_verbose", "0",
806 "Show extra information if an enemy picks up a flag"
809 NOTIF_WRITE_HARDCODED(
810 "ctf_pickup_team_verbose", "0",
811 "Show extra information if a team mate picks up a flag"
814 NOTIF_WRITE_HARDCODED(
816 "Print extra debug information on all notification function calls "
817 "(Requires -DNOTIFICATIONS_DEBUG flag to be enabled on QCSRC compilation)... "
818 "0 = disabled, 1 = dprint, 2 = print"
821 NOTIF_WRITE_HARDCODED(
822 "errors_are_fatal", "1",
823 "If a notification fails upon initialization, cause a Host_Error to stop the program"
826 NOTIF_WRITE_HARDCODED(
828 "Show extra information when you frag someone (or when you are fragged"
831 NOTIF_WRITE_HARDCODED(
832 "item_centerprinttime", "1.5",
833 "How long to show item information centerprint messages (like 'You got the Electro' or such)"
836 NOTIF_WRITE_HARDCODED(
837 "lifetime_mapload", "10",
838 "Amount of time that notification entities last immediately at mapload (in seconds) "
839 "to help prevent notifications from being lost on early init (like gamestart countdown)"
842 NOTIF_WRITE_HARDCODED(
843 "lifetime_runtime", "0.5",
844 "Amount of time that notification entities last on the server during runtime (In seconds)"
847 NOTIF_WRITE_HARDCODED(
848 "server_allows_frag_verbose", "1",
849 "Server side cvar for showing extra information in frag messages... 0 = no extra frag information, "
850 "1 = frag information only in warmup, 2 = frag information allowed all the time"
853 NOTIF_WRITE_HARDCODED(
854 "server_allows_location", "1",
855 "Server side cvar for allowing death messages to show location information too"
858 NOTIF_WRITE_HARDCODED(
859 "show_location", "0",
860 "Append location information to MSG_INFO death/kill messages"
863 NOTIF_WRITE_HARDCODED(
864 "show_location_string", "",
865 "Replacement string piped into sprintf, "
866 "so you can do different messages like this: ' at the %s' or ' (near %s)'"
869 NOTIF_WRITE_HARDCODED(
871 "Print information about sprees in death/kill messages"
874 NOTIF_WRITE_HARDCODED(
875 "show_sprees_center", "1",
876 "Show spree information in MSG_CENTER messages... "
877 "0 = off, 1 = target (but only for first victim) and attacker"
880 NOTIF_WRITE_HARDCODED(
881 "show_sprees_center_specialonly", "1",
882 "Don't show spree information in MSG_CENTER messages if it isn't an achievement"
885 NOTIF_WRITE_HARDCODED(
886 "show_sprees_info", "3",
887 "Show spree information in MSG_INFO messages... "
888 "0 = off, 1 = target only, 2 = attacker only, 3 = target and attacker"
891 NOTIF_WRITE_HARDCODED(
892 "show_sprees_info_newline", "1",
893 "Show attacker spree information for MSG_INFO messages on a separate line than the death notification itself"
896 NOTIF_WRITE_HARDCODED(
897 "show_sprees_info_specialonly", "1",
898 "Don't show attacker spree information in MSG_INFO messages if it isn't an achievement"
903 "\n// Notification counts (total = %d): ",
904 "MSG_ANNCE = %d, MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d\n"
919 #undef NOTIF_WRITE_HARDCODED
920 #undef NOTIF_WRITE_ENTITY
925 void Notification_GetCvars()
927 GetCvars_handleFloat(get_cvars_s, get_cvars_f, FRAG_VERBOSE, "notification_frag_verbose");
932 // ===============================
933 // Frontend Notification Pushing
934 // ===============================
936 #ifdef NOTIFICATIONS_DEBUG
937 void Debug_Notification(string input)
939 switch(autocvar_notification_debug)
941 case 1: { dprint(input); break; }
942 case 2: { print(input); break; }
947 string Local_Notification_sprintf(
948 string input, string args,
949 string s1, string s2, string s3, string s4,
950 float f1, float f2, float f3, float f4)
952 #ifdef NOTIFICATIONS_DEBUG
953 Debug_Notification(sprintf(
954 "Local_Notification_sprintf('%s^7', '%s', %s, %s);\n",
955 MakeConsoleSafe(input),
957 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
958 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
964 for(sel_num = 0; sel_num < NOTIF_MAX_ARGS; ++sel_num) { arg_slot[sel_num] = ""; }
968 for(sel_num = 0;(args != "");)
970 selected = car(args); args = cdr(args);
971 NOTIF_HIT_MAX(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
972 switch(strtolower(selected))
974 #define ARG_CASE(prog,selected,result) \
976 #if (prog != ARG_SV) && (prog != ARG_DC) \
977 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
980 #if (prog != ARG_CS) && (prog != ARG_DC) \
981 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
986 default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
989 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]);
993 void Local_Notification_sound(
994 float soundchannel, string soundfile,
995 float soundvolume, float soundposition)
997 if((soundfile != prev_soundfile) || (time >= (prev_soundtime + autocvar_cl_announcer_antispam)))
999 #ifdef NOTIFICATIONS_DEBUG
1000 Debug_Notification(sprintf(
1001 "Local_Notification_sound(world, %f, '%s', %f, %f);\n",
1004 "announcer/%s/%s.wav",
1005 autocvar_cl_announcer,
1017 "announcer/%s/%s.wav",
1018 autocvar_cl_announcer,
1025 if(prev_soundfile) { strunzone(prev_soundfile); }
1026 prev_soundfile = strzone(soundfile);
1027 prev_soundtime = time;
1031 #ifdef NOTIFICATIONS_DEBUG
1032 Debug_Notification(sprintf(
1034 "Local_Notification_sound(world, %f, '%s', %f, %f) ",
1035 "^1BLOCKED BY ANTISPAM:^7 prevsnd: '%s', timediff: %f, limit: %f\n"
1039 "announcer/%s/%s.wav",
1040 autocvar_cl_announcer,
1046 (time - prev_soundtime),
1047 autocvar_cl_announcer_antispam
1053 void Local_Notification_HUD_Notify_Push(
1054 string icon, string hudargs,
1055 string s1, string s2, string s3, string s4)
1059 arg_slot[0] = ""; arg_slot[1] = "";
1061 for(sel_num = 0;(hudargs != "");)
1063 selected = car(hudargs); hudargs = cdr(hudargs);
1064 NOTIF_HIT_MAX(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
1065 switch(strtolower(selected))
1067 #define ARG_CASE(prog,selected,result) \
1068 #if (prog == ARG_CS_SV_HA) \
1069 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
1073 default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
1076 #ifdef NOTIFICATIONS_DEBUG
1077 Debug_Notification(sprintf(
1078 "Local_Notification_HUD_Notify_Push('%s^7', '%s', %s, %s);\n",
1081 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1082 MakeConsoleSafe(sprintf("'%s^7', '%s^7'", stof(arg_slot[0]), stof(arg_slot[1])))
1085 HUD_Notify_Push(icon, arg_slot[0], arg_slot[1]);
1088 void Local_Notification_centerprint_generic(
1089 string input, string durcnt,
1090 float cpid, float f1, float f2)
1094 arg_slot[0] = ""; arg_slot[1] = "";
1096 for(sel_num = 0;(durcnt != "");)
1098 selected = car(durcnt); durcnt = cdr(durcnt);
1099 NOTIF_HIT_MAX(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic")
1100 switch(strtolower(selected))
1102 #define ARG_CASE(prog,selected,result) \
1103 #if (prog == ARG_CS_SV_DC) || (prog == ARG_DC) \
1104 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
1110 if(ftos(stof(selected)) != "") { arg_slot[sel_num] = selected; ++sel_num; }
1111 else { NOTIF_HIT_UNKNOWN(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic") }
1116 #ifdef NOTIFICATIONS_DEBUG
1117 Debug_Notification(sprintf(
1118 "Local_Notification_centerprint_generic('%s^7', '%s', %d, %d, %d, %d);\n",
1119 MakeConsoleSafe(input),
1122 stof(arg_slot[0]), stof(arg_slot[1])
1125 centerprint_generic(cpid, input, stof(arg_slot[0]), stof(arg_slot[1]));
1129 void Local_Notification(float net_type, float net_name, ...count)
1131 // check supplied type and name for errors
1132 string checkargs = Notification_CheckArgs_TypeName(net_type, net_name);
1133 if(checkargs != "") { backtrace(sprintf("Incorrect usage of Local_Notification: %s\n", checkargs)); return; }
1135 entity notif = Get_Notif_Ent(net_type, net_name);
1136 if not(notif) { backtrace("Local_Notification: Could not find notification entity!\n"); return; }
1137 if not(notif.nent_enabled)
1139 #ifdef NOTIFICATIONS_DEBUG
1140 Debug_Notification(sprintf(
1141 "Local_Notification(%s, %s): Entity was disabled...\n",
1142 Get_Notif_TypeName(net_type),
1149 if((notif.nent_stringcount + notif.nent_floatcount) > count)
1153 "Not enough arguments for Local_Notification(%s, %s, ...)! ",
1154 "stringcount(%d) + floatcount(%d) > count(%d)\n",
1155 "Check the definition and function call for accuracy...?\n"
1157 Get_Notif_TypeName(net_type), notif.nent_name,
1158 notif.nent_stringcount, notif.nent_floatcount, count
1162 else if((notif.nent_stringcount + notif.nent_floatcount) < count)
1166 "Too many 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
1176 string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
1177 string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
1178 string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
1179 string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
1180 float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
1181 float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
1182 float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
1183 float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
1185 #ifdef NOTIFICATIONS_DEBUG
1186 Debug_Notification(sprintf(
1187 "Local_Notification(%s, %s, %s, %s);\n",
1188 Get_Notif_TypeName(net_type),
1190 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1191 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1200 Local_Notification_sound(
1207 backtrace("MSG_ANNCE on server?... Please notify Samual immediately!\n");
1215 Local_Notification_sprintf(
1222 if(notif.nent_icon != "")
1224 Local_Notification_HUD_Notify_Push(
1236 Local_Notification_centerprint_generic(
1237 Local_Notification_sprintf(
1251 if(notif.nent_msginfo)
1252 if(notif.nent_msginfo.nent_enabled)
1254 Local_Notification_WOVA(
1256 notif.nent_msginfo.nent_id,
1257 notif.nent_msginfo.nent_stringcount,
1258 notif.nent_msginfo.nent_floatcount,
1263 if(notif.nent_msgannce)
1264 if(notif.nent_msgannce.nent_enabled)
1266 Local_Notification_WOVA(
1268 notif.nent_msgannce.nent_id,
1273 if(notif.nent_msgcenter)
1274 if(notif.nent_msgcenter.nent_enabled)
1276 Local_Notification_WOVA(
1278 notif.nent_msgcenter.nent_id,
1279 notif.nent_msgcenter.nent_stringcount,
1280 notif.nent_msgcenter.nent_floatcount,
1290 // WOVA = Without Variable Arguments
1291 void Local_Notification_WOVA(
1292 float net_type, float net_name,
1293 float stringcount, float floatcount,
1294 string s1, string s2, string s3, string s4,
1295 float f1, float f2, float f3, float f4)
1297 #define VARITEM(stringc,floatc,args) \
1298 if((stringcount == stringc) && (floatcount == floatc)) \
1299 { Local_Notification(net_type, net_name, args); return; }
1300 EIGHT_VARS_TO_VARARGS_VARLIST
1302 Local_Notification(net_type, net_name); // some notifications don't have any arguments at all
1306 // =========================
1307 // Notification Networking
1308 // =========================
1311 void Read_Notification(float is_new)
1313 float net_type = ReadByte();
1314 float net_name = ReadShort();
1318 if(net_type == MSG_CENTER_CPID)
1320 #ifdef NOTIFICATIONS_DEBUG
1321 Debug_Notification(sprintf(
1322 "Read_Notification(%d) at %f: net_type = %s, net_name = %d\n",
1325 Get_Notif_TypeName(net_type),
1332 if(net_name == 0) { reset_centerprint_messages(); }
1333 else if(net_name != NO_CPID)
1335 // in this case, net_name IS the cpid we want to kill
1336 centerprint_generic(net_name, "", 0, 0);
1341 "Read_Notification(%d) at %f: ^1TRIED TO KILL NO_CPID CENTERPRINT!\n",
1350 notif = Get_Notif_Ent(net_type, net_name);
1351 if not(notif) { backtrace("Read_Notification: Could not find notification entity!\n"); return; }
1353 #ifdef NOTIFICATIONS_DEBUG
1354 Debug_Notification(sprintf(
1355 "Read_Notification(%d) at %f: net_type = %s, net_name = %s\n",
1358 Get_Notif_TypeName(net_type),
1363 string s1 = ((0 < notif.nent_stringcount) ? ReadString() : "");
1364 string s2 = ((1 < notif.nent_stringcount) ? ReadString() : "");
1365 string s3 = ((2 < notif.nent_stringcount) ? ReadString() : "");
1366 string s4 = ((3 < notif.nent_stringcount) ? ReadString() : "");
1367 float f1 = ((0 < notif.nent_floatcount) ? ReadLong() : 0);
1368 float f2 = ((1 < notif.nent_floatcount) ? ReadLong() : 0);
1369 float f3 = ((2 < notif.nent_floatcount) ? ReadLong() : 0);
1370 float f4 = ((3 < notif.nent_floatcount) ? ReadLong() : 0);
1374 Local_Notification_WOVA(
1376 notif.nent_stringcount,
1377 notif.nent_floatcount,
1386 void Net_Notification_Remove()
1388 if not(self) { backtrace(sprintf("Net_Notification_Remove() at %f: Missing self!?\n", time)); return; }
1390 #ifdef NOTIFICATIONS_DEBUG
1391 Debug_Notification(sprintf(
1392 "Net_Notification_Remove() at %f: %s '%s - %s' notification\n",
1394 ((self.nent_net_name == -1) ? "Killed" : "Removed"),
1395 Get_Notif_TypeName(self.nent_net_type),
1396 self.owner.nent_name
1401 for(i = 0; i < 4; ++i) { if(self.nent_strings[i]) { strunzone(self.nent_strings[i]); } }
1405 float Net_Write_Notification(entity client, float sf)
1407 float i, send = FALSE;
1409 switch(self.nent_broadcast)
1411 case NOTIF_ONE: // send to one client and their spectator
1414 (client == self.nent_client)
1419 (client.enemy == self.nent_client)
1424 case NOTIF_ONE_ONLY: // send ONLY to one client
1426 if(client == self.nent_client) { send = TRUE; }
1429 case NOTIF_TEAM: // send only to X team and their spectators
1432 (client.team == self.nent_client.team)
1437 (client.enemy.team == self.nent_client.team)
1442 case NOTIF_TEAM_EXCEPT: // send only to X team and their spectators, except for Y person and their spectators
1445 (client != self.nent_client)
1448 (client.team == self.nent_client.team)
1454 (client.enemy != self.nent_client)
1456 (client.enemy.team == self.nent_client.team)
1463 case NOTIF_ALL: // send to everyone
1468 case NOTIF_ALL_EXCEPT: // send to everyone except X person and their spectators
1471 (client != self.nent_client)
1476 (client.enemy == self.nent_client)
1481 default: { send = FALSE; break; }
1486 WriteByte(MSG_ENTITY, ENT_CLIENT_NOTIFICATION);
1487 WriteByte(MSG_ENTITY, self.nent_net_type);
1488 WriteShort(MSG_ENTITY, self.nent_net_name);
1489 for(i = 0; i < self.nent_stringcount; ++i) { WriteString(MSG_ENTITY, self.nent_strings[i]); }
1490 for(i = 0; i < self.nent_floatcount; ++i) { WriteLong(MSG_ENTITY, self.nent_floats[i]); }
1496 void Kill_Notification(
1497 float broadcast, entity client,
1498 float net_type, float net_name)
1500 string checkargs = Notification_CheckArgs(broadcast, client, 1, 1);
1501 if(checkargs != "") { backtrace(sprintf("Incorrect usage of Kill_Notification: %s\n", checkargs)); return; }
1503 #ifdef NOTIFICATIONS_DEBUG
1504 Debug_Notification(sprintf(
1505 "Kill_Notification(%d, '%s', %s, %d);\n",
1508 (net_type ? Get_Notif_TypeName(net_type) : "0"),
1513 entity notif, net_notif;
1514 float killed_cpid = NO_CPID;
1520 killed_cpid = 0; // kill ALL centerprints
1528 entity notif = Get_Notif_Ent(net_type, net_name);
1529 if not(notif) { backtrace("Kill_Notification: Could not find notification entity!\n"); return; }
1532 killed_cpid = notif.nent_cpid;
1534 killed_cpid = NO_CPID;
1538 killed_cpid = 0; // kill ALL centerprints
1543 case MSG_CENTER_CPID:
1545 killed_cpid = net_name;
1550 if(killed_cpid != NO_CPID)
1552 net_notif = spawn();
1553 net_notif.classname = "net_kill_notification";
1554 net_notif.nent_broadcast = broadcast;
1555 net_notif.nent_client = client;
1556 net_notif.nent_net_type = MSG_CENTER_CPID;
1557 net_notif.nent_net_name = killed_cpid;
1558 Net_LinkEntity(net_notif, FALSE, autocvar_notification_lifetime_runtime, Net_Write_Notification);
1561 for(notif = world; (notif = find(notif, classname, "net_notification"));)
1565 if((killed_cpid != NO_CPID) && (notif.nent_net_type == MSG_CENTER))
1567 if(notif.owner.nent_cpid == killed_cpid)
1569 notif.nent_net_name = -1;
1570 notif.nextthink = time;
1572 else { continue; } // we ARE looking for a specific CPID, don't kill everything else too
1574 else if(notif.nent_net_type == net_type)
1578 if(notif.nent_net_name == net_name) { notif.nent_net_name = -1; notif.nextthink = time; }
1579 else { continue; } // we ARE looking for a certain net_name, don't kill everything else too
1581 else { notif.nent_net_name = -1; notif.nextthink = time; }
1583 else { continue; } // we ARE looking for a certain net_type, don't kill everything else too
1585 else { notif.nent_net_name = -1; notif.nextthink = time; }
1589 void Send_Notification(
1590 float broadcast, entity client,
1591 float net_type, float net_name,
1594 // check supplied broadcast, target, type, and name for errors
1595 string checkargs = Notification_CheckArgs(broadcast, client, net_type, net_name);
1596 if(checkargs != "") { backtrace(sprintf("Incorrect usage of Send_Notification: %s\n", checkargs)); return; }
1598 // retreive counts for the arguments of this notification
1599 entity notif = Get_Notif_Ent(net_type, net_name);
1600 if not(notif) { backtrace("Send_Notification: Could not find notification entity!\n"); return; }
1602 if((notif.nent_stringcount + notif.nent_floatcount) > count)
1606 "Not enough arguments for Send_Notification(%d, %s, %s, ...)! ",
1607 "stringcount(%d) + floatcount(%d) > count(%d)\n",
1608 "Check the definition and function call for accuracy...?\n"
1610 broadcast, Get_Notif_TypeName(net_type), notif.nent_name,
1611 notif.nent_stringcount, notif.nent_floatcount, count
1615 else if((notif.nent_stringcount + notif.nent_floatcount) < count)
1619 "Too many 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
1629 #ifdef NOTIFICATIONS_DEBUG
1630 string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
1631 string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
1632 string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
1633 string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
1634 float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
1635 float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
1636 float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
1637 float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
1638 Debug_Notification(sprintf(
1639 "Send_Notification(%d, %s, %s, %s, %s);\n",
1641 Get_Notif_TypeName(net_type),
1643 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1644 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1648 entity net_notif = spawn();
1649 net_notif.owner = notif;
1650 net_notif.classname = "net_notification";
1651 net_notif.nent_broadcast = broadcast;
1652 net_notif.nent_client = client;
1653 net_notif.nent_net_type = net_type;
1654 net_notif.nent_net_name = net_name;
1655 net_notif.nent_stringcount = notif.nent_stringcount;
1656 net_notif.nent_floatcount = notif.nent_floatcount;
1659 for(i = 0; i < net_notif.nent_stringcount; ++i)
1660 { net_notif.nent_strings[i] = strzone(...(i, string)); }
1661 for(i = 0; i < net_notif.nent_floatcount; ++i)
1662 { net_notif.nent_floats[i] = ...((net_notif.nent_stringcount + i), float); }
1664 net_notif.think = Net_Notification_Remove;
1665 net_notif.nextthink =
1666 ((time > autocvar_notification_lifetime_mapload)
1668 (time + autocvar_notification_lifetime_runtime)
1670 autocvar_notification_lifetime_mapload
1673 Net_LinkEntity(net_notif, FALSE, 0, Net_Write_Notification);
1679 broadcast == NOTIF_ALL
1681 broadcast == NOTIF_ALL_EXCEPT
1685 net_type == MSG_ANNCE
1687 net_type == MSG_CENTER
1691 Local_Notification_WOVA(
1693 notif.nent_stringcount,
1694 notif.nent_floatcount,
1695 IFSTR(0), IFSTR(1), IFSTR(2), IFSTR(3),
1696 IFFL(0), IFFL(1), IFFL(2), IFFL(3));
1700 // WOVA = Without Variable Arguments
1701 void Send_Notification_WOVA(
1702 float broadcast, entity client,
1703 float net_type, float net_name,
1704 string s1, string s2, string s3, string s4,
1705 float f1, float f2, float f3, float f4)
1707 entity notif = Get_Notif_Ent(net_type, net_name);
1709 #ifdef NOTIFICATIONS_DEBUG
1710 Debug_Notification(sprintf(
1711 "Send_Notification_WOVA(%d, %s, %s, %s, %s);\n",
1713 Get_Notif_TypeName(net_type),
1715 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1716 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1720 #define VARITEM(stringc,floatc,args) \
1721 if((notif.nent_stringcount == stringc) && (notif.nent_floatcount == floatc)) \
1722 { Send_Notification(broadcast, client, net_type, net_name, args); return; }
1723 EIGHT_VARS_TO_VARARGS_VARLIST
1725 Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
1727 #endif // ifdef SVQC