1 // ================================================
2 // Unified notification system, written by Samual
3 // Last updated: March, 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";
16 backtrace(sprintf("Get_Notif_TypeName(%d): Improper net type!\n", net_type));
20 entity Get_Notif_Ent(float net_type, float net_name)
24 case MSG_ANNCE: return msg_annce_notifs[net_name - 1];
25 case MSG_INFO: return msg_info_notifs[net_name - 1];
26 case MSG_CENTER: return msg_center_notifs[net_name - 1];
27 case MSG_MULTI: return msg_multi_notifs[net_name - 1];
29 backtrace(sprintf("Get_Notif_Ent(%d, %d): Improper net type!\n", net_type, net_name));
33 string Notification_CheckArgs_TypeName(float net_type, float net_name)
35 // check supplied type and name for errors
36 string checkargs = "";
37 #define CHECKARG_TYPENAME(type) case MSG_##type##: \
38 { if(!net_name || (net_name > NOTIF_##type##_COUNT)) \
39 { checkargs = sprintf("Improper name: %d!", net_name); } break; }
42 CHECKARG_TYPENAME(ANNCE)
43 CHECKARG_TYPENAME(INFO)
44 CHECKARG_TYPENAME(CENTER)
45 CHECKARG_TYPENAME(MULTI)
46 default: { checkargs = sprintf("Improper type: %d!", checkargs, net_type); break; }
48 #undef CHECKARG_TYPENAME
53 string Notification_CheckArgs(
54 float broadcast, entity client,
55 float net_type, float net_name)
57 // check supplied broadcast, target, type, and name for errors
58 string checkargs = Notification_CheckArgs_TypeName(net_type, net_name);
59 if(checkargs != "") { checkargs = strcat(checkargs, " "); }
65 if(IS_NOT_A_CLIENT(client))
66 { checkargs = sprintf("%sNo client provided!", checkargs); }
70 case NOTIF_ALL_EXCEPT:
72 if(IS_NOT_A_CLIENT(client))
73 { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
80 { checkargs = sprintf("%sEntity provided when world was required!", checkargs); }
85 case NOTIF_TEAM_EXCEPT:
87 if not(teamplay) { checkargs = sprintf("%sTeamplay not active!", checkargs); }
88 else if(IS_NOT_A_CLIENT(client))
90 if(broadcast == NOTIF_TEAM) { checkargs = sprintf("%sNo client provided!", checkargs); }
91 else { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
96 default: { checkargs = sprintf("%sImproper broadcast: %d!", checkargs, broadcast); break; }
102 // ===============================
103 // Initialization Core Functions
104 // ===============================
106 // used by restartnotifs command to initialize notifications
107 void Destroy_Notification_Entity(entity notif)
109 if(notif.nent_name != "") { strunzone(notif.nent_name); }
110 if(notif.nent_snd != "") { strunzone(notif.nent_snd); }
111 if(notif.nent_args != "") { strunzone(notif.nent_args); }
112 if(notif.nent_hudargs != "") { strunzone(notif.nent_hudargs); }
113 if(notif.nent_icon != "") { strunzone(notif.nent_icon); }
114 if(notif.nent_durcnt != "") { strunzone(notif.nent_durcnt); }
115 if(notif.nent_string != "") { strunzone(notif.nent_string); }
119 void Destroy_All_Notifications(void)
124 #define DESTROY_LOOP(type,count) \
125 for(i = 1; i <= count; ++i) \
127 notif = Get_Notif_Ent(type, i); \
128 if not(notif) { backtrace("Destroy_All_Notifications(): Missing notification entity!\n"); return; } \
129 Destroy_Notification_Entity(notif); \
132 // kill all networked notifications and centerprints
134 Kill_Notification(NOTIF_ALL, world, 0, 0);
136 reset_centerprint_messages();
139 // kill all real notification entities
140 DESTROY_LOOP(MSG_ANNCE, NOTIF_ANNCE_COUNT)
141 DESTROY_LOOP(MSG_INFO, NOTIF_INFO_COUNT)
142 DESTROY_LOOP(MSG_CENTER, NOTIF_CENTER_COUNT)
143 DESTROY_LOOP(MSG_MULTI, NOTIF_MULTI_COUNT)
147 string Process_Notif_Line(
158 if((chat && autocvar_notification_allow_chatboxprint)
159 || (autocvar_notification_allow_chatboxprint == 2))
161 // pass 1: add ETX char at beginning of line
162 input = strcat("\{3}", input);
164 // pass 2: add ETX char at end of each new line (so that
165 // messages with multiple lines are put through chatbox too)
166 input = strreplace("\n", "\n\{3}", input);
168 // pass 3: strip trailing ETX char
169 if(substring(input, (strlen(input) - 1), 1) == "\{3}")
170 { input = substring(input, 0, (strlen(input) - 1)); }
173 if(substring(input, (strlen(input) - 1), 1) != "\n")
177 "^1MISSING/BROKEN NEW LINE AT END OF NOTIFICATION: ",
178 "^7net_type = %s, net_name = %s, string = %s.\n"
185 return strcat(input, "\n");
191 string Process_Notif_Args(
197 string selected, remaining = args;
200 for(;(remaining != "");)
202 selected = car(remaining); remaining = cdr(remaining);
206 case 1: // normal args
208 if(sel_num == NOTIF_MAX_ARGS)
212 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
213 "^7net_type = %s, net_name = %s, max args = %d.\n"
223 switch(strtolower(selected))
225 #define ARG_CASE(prog,selected,result) \
226 #if (prog != ARG_DC) \
227 case selected: { ++sel_num; break; } \
235 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
236 "^7net_type = %s, net_name = %s, args arg = '%s'.\n"
250 if(sel_num == NOTIF_MAX_HUDARGS)
254 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
255 "^7net_type = %s, net_name = %s, max hudargs = %d.\n"
265 switch(strtolower(selected))
267 #define ARG_CASE(prog,selected,result) \
268 #if (prog == ARG_CS_SV_HA) \
269 case selected: { ++sel_num; break; } \
277 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
278 "^7net_type = %s, net_name = %s, hudargs arg = '%s'.\n"
292 if(sel_num == NOTIF_MAX_DURCNT)
296 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
297 "^7net_type = %s, net_name = %s, max durcnt = %d.\n"
307 switch(strtolower(selected))
309 #define ARG_CASE(prog,selected,result) \
310 #if (prog == ARG_CS_SV_DC) || (prog == ARG_DC) \
311 case selected: { ++sel_num; break; } \
317 if(ftos(stof(selected)) != "") { ++sel_num; }
322 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
323 "^7net_type = %s, net_name = %s, durcnt arg = '%s'.\n"
341 void Create_Notification_Entity(
366 // =====================
367 // Global Entity Setup
368 // =====================
369 entity notif = spawn();
370 string typestring = "";
375 typestring = "MSG_ANNCE";
376 msg_annce_notifs[nameid - 1] = notif;
377 notif.classname = "msg_annce_notification";
382 typestring = "MSG_INFO";
383 msg_info_notifs[nameid - 1] = notif;
384 notif.classname = "msg_info_notification";
389 typestring = "MSG_CENTER";
390 msg_center_notifs[nameid - 1] = notif;
391 notif.classname = "msg_center_notification";
396 typestring = "MSG_MULTI";
397 msg_multi_notifs[nameid - 1] = notif;
398 notif.classname = "MSG_MULTI_notification";
406 "^1NOTIFICATION WITH IMPROPER TYPE: ",
407 "^7net_type = %d, net_name = %s.\n"
412 return; // It's not possible to recover from this one
415 notif.nent_default = var_default;
416 notif.nent_name = strzone(namestring);
417 notif.nent_id = nameid;
418 notif.nent_enabled = (1 <= var_cvar);
420 // Other pre-notif-setup requisites
423 // ====================
424 // Notification Setup
425 // ====================
428 // Set MSG_MULTI string/float counts
429 if((anncename == NO_MSG) && (infoname == NO_MSG) && (centername == NO_MSG))
433 "^1NOTIFICATION WITH NO SUBCALLS: ",
434 "^7net_type = %s, net_name = %s.\n"
443 // announcements don't actually need any arguments, so lets not even count them.
444 if(anncename != NO_MSG) { notif.nent_msgannce = msg_annce_notifs[anncename - 1]; }
446 float infoname_stringcount = 0, infoname_floatcount = 0;
447 float centername_stringcount = 0, centername_floatcount = 0;
449 if(infoname != NO_MSG)
451 notif.nent_msginfo = msg_info_notifs[infoname - 1];
452 infoname_stringcount = notif.nent_msginfo.nent_stringcount;
453 infoname_floatcount = notif.nent_msginfo.nent_floatcount;
456 if(centername != NO_MSG)
458 notif.nent_msgcenter = msg_center_notifs[centername - 1];
459 centername_stringcount = notif.nent_msgcenter.nent_stringcount;
460 centername_floatcount = notif.nent_msgcenter.nent_floatcount;
463 // set the requirements of THIS notification to the totals of its subcalls
464 notif.nent_stringcount = max(infoname_stringcount, centername_stringcount);
465 notif.nent_floatcount = max(infoname_floatcount, centername_floatcount);
468 else if(typeid == MSG_ANNCE)
470 // Set MSG_ANNCE information and handle precaching
472 if not(GENTLE && (var_cvar == 1))
476 if(notif.nent_enabled)
478 precache_sound(sprintf("announcer/%s/%s.wav", autocvar_cl_announcer, snd));
479 notif.nent_channel = channel;
480 notif.nent_snd = strzone(snd);
481 notif.nent_vol = vol;
482 notif.nent_position = position;
489 "^1NOTIFICATION WITH NO SOUND: ",
490 "^7net_type = %s, net_name = %s.\n"
498 else { notif.nent_enabled = FALSE; }
500 notif.nent_enabled = FALSE;
505 // Set MSG_INFO and MSG_CENTER string/float counts
506 notif.nent_stringcount = strnum;
507 notif.nent_floatcount = flnum;
509 // Only initialize arguments if we're either a client or on a dedicated server
511 float should_process_args = server_is_dedicated;
513 float should_process_args = TRUE;
516 if(should_process_args)
518 // ========================
519 // Process Main Arguments
520 // ========================
525 notif.nent_args = strzone(
526 Process_Notif_Args(1, args, typestring, namestring));
528 else if((hudargs == "") && (durcnt ==""))
532 "^1NOTIFICATION HAS ARG COUNTS BUT NO ARGS OR HUDARGS OR DURCNT: ",
533 "^7net_type = %s, net_name = %s, strnum = %d, flnum = %d\n"
545 notif.nent_args = strzone(
546 Process_Notif_Args(1, args, typestring, namestring));
550 // =======================================
551 // Process HUD and Centerprint Arguments
552 // Only processed on CSQC, as these
553 // args are only for HUD features.
554 // =======================================
558 notif.nent_hudargs = strzone(
559 Process_Notif_Args(2, hudargs, typestring, namestring));
561 if(icon != "") { notif.nent_icon = strzone(icon); }
566 "^1NOTIFICATION HAS HUDARGS BUT NO ICON: ",
567 "^7net_type = %s, net_name = %s.\n"
579 "^1NOTIFICATION HAS ICON BUT NO HUDARGS: ",
580 "^7net_type = %s, net_name = %s.\n"
590 notif.nent_durcnt = strzone(
591 Process_Notif_Args(3, durcnt, typestring, namestring));
593 if(cpid != NO_MSG) { notif.nent_cpid = cpid; }
598 "^1NOTIFICATION HAS DURCNT BUT NO CPID: ",
599 "^7net_type = %s, net_name = %s.\n"
607 else if(cpid != NO_MSG) { notif.nent_cpid = cpid; }
611 // ======================
612 // Process Notif String
613 // ======================
614 #define SET_NOTIF_STRING(string,stringname) \
615 notif.nent_string = strzone(CCR( \
616 Process_Notif_Line( \
628 if(gentle != "") { SET_NOTIF_STRING(gentle, "GENTLE") }
629 else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL") }
631 else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL") }
633 #undef SET_NOTIF_STRING
635 // Check to make sure a string was chosen
636 if(notif.nent_string == "")
640 "^1EMPTY NOTIFICATION: ",
641 "^7net_type = %s, net_name = %s.\n"
651 // now check to see if any errors happened
654 notif.nent_enabled = FALSE; // disable the notification so it can't cause trouble
655 notif_global_error = TRUE; // throw the red flag that an error happened on init
660 // =========================================
661 // Cvar Handling With 'dumpnotifs' Command
662 // =========================================
664 void Dump_Notifications(float fh, float alsoprint)
666 #define NOTIF_WRITE(a) { \
668 if(alsoprint) { print(a); } }
669 #define NOTIF_WRITE_ENTITY(name,default,description) { \
672 "seta notification_%s \"%d\" \"%s\"\n", \
673 name, default, description \
675 NOTIF_WRITE(notif_msg) }
676 #define NOTIF_WRITE_HARDCODED(cvar,default,description) { \
679 "seta notification_%s \"%s\" \"%s\"\n", \
680 cvar, default, description \
682 NOTIF_WRITE(notif_msg) }
688 // Note: This warning only applies to the notifications.cfg file that is output...
690 // You ARE supposed to manually edit this function to add i.e. hard coded
691 // notification variables for mutators or game modes or such and then
692 // regenerate the notifications.cfg file from the new code.
694 NOTIF_WRITE("// ********************************************** //\n");
695 NOTIF_WRITE("// ** WARNING - DO NOT MANUALLY EDIT THIS FILE ** //\n");
696 NOTIF_WRITE("// ** ** //\n");
697 NOTIF_WRITE("// ** This file is automatically generated ** //\n");
698 NOTIF_WRITE("// ** by code with the command 'dumpnotifs'. ** //\n");
699 NOTIF_WRITE("// ** ** //\n");
700 NOTIF_WRITE("// ** If you add a new notification, please ** //\n");
701 NOTIF_WRITE("// ** regenerate this file with that command ** //\n");
702 NOTIF_WRITE("// ** making sure that the output matches ** //\n");
703 NOTIF_WRITE("// ** with the lists and defaults in code. ** //\n");
704 NOTIF_WRITE("// ** ** //\n");
705 NOTIF_WRITE("// ********************************************** //\n");
707 // These notifications will also append their string as a comment...
708 // This is not necessary, and does not matter if they vary between config versions,
709 // it is just a semi-helpful tool for those who want to manually change their user settings.
711 NOTIF_WRITE(sprintf("\n// MSG_ANNCE notifications (count = %d):\n", NOTIF_ANNCE_COUNT));
712 for(i = 1; i <= NOTIF_ANNCE_COUNT; ++i)
714 e = Get_Notif_Ent(MSG_ANNCE, i);
715 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
716 NOTIF_WRITE_ENTITY(e.nent_name, e.nent_default, "Notification control cvar: 0 = disabled, 1 = enabled if gentle mode is off, 2 = always enabled)");
719 NOTIF_WRITE(sprintf("\n// MSG_INFO notifications (count = %d):\n", NOTIF_INFO_COUNT));
720 for(i = 1; i <= NOTIF_INFO_COUNT; ++i)
722 e = Get_Notif_Ent(MSG_INFO, i);
723 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
724 NOTIF_WRITE_ENTITY(e.nent_name, e.nent_default, "Notification control cvar: 0 = off, 1 = print to console, 2 = print to console and chatbox (if notification_allow_chatboxprint is enabled)");
727 NOTIF_WRITE(sprintf("\n// MSG_CENTER notifications (count = %d):\n", NOTIF_CENTER_COUNT));
728 for(i = 1; i <= NOTIF_CENTER_COUNT; ++i)
730 e = Get_Notif_Ent(MSG_CENTER, i);
731 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
732 NOTIF_WRITE_ENTITY(e.nent_name, e.nent_default, "Notification control cvar: 0 = off, 1 = centerprint");
735 NOTIF_WRITE(sprintf("\n// MSG_MULTI notifications (count = %d):\n", NOTIF_MULTI_COUNT));
736 for(i = 1; i <= NOTIF_MULTI_COUNT; ++i)
738 e = Get_Notif_Ent(MSG_MULTI, i);
739 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
740 NOTIF_WRITE_ENTITY(e.nent_name, e.nent_default, "Notification control cvar: 0 = off, 1 = trigger subcalls");
743 // edit these to match whichever cvars are used for specific notification options
744 NOTIF_WRITE("\n// HARD CODED notification variables:\n");
745 NOTIF_WRITE_HARDCODED("allow_chatboxprint", "1", "Allow notifications to be printed to chat box by setting notification cvar to 2 (You can also set this cvar to 2 to force ALL notifications to be printed to the chatbox)");
746 NOTIF_WRITE_HARDCODED("ctf_capture_verbose", "0", "Show extra information when someone captures a flag");
747 NOTIF_WRITE_HARDCODED("ctf_pickup_enemy_verbose", "0", "Show extra information if an enemy picks up a flag");
748 NOTIF_WRITE_HARDCODED("ctf_pickup_team_verbose", "0", "Show extra information if a team mate picks up a flag");
749 NOTIF_WRITE_HARDCODED("errors_are_fatal", "1", "If a notification fails upon initialization, cause a Host_Error to stop the program");
750 NOTIF_WRITE_HARDCODED("frag_verbose", "1", "Show extra information when you frag someone (or when you are fragged");
751 NOTIF_WRITE_HARDCODED("item_centerprinttime", "1.5", "How long to show item information centerprint messages (like 'You got the Electro' or such)");
752 NOTIF_WRITE_HARDCODED("lifetime_mapload", "10", "Amount of time that notification entities last immediately at mapload (in seconds) to help prevent notifications from being lost on early init (like gamestart countdown)");
753 NOTIF_WRITE_HARDCODED("lifetime_runtime", "0.5", "Amount of time that notification entities last on the server during runtime (In seconds)");
754 NOTIF_WRITE_HARDCODED("server_allows_frag_verbose", "1", "Server side cvar for showing extra information in frag messages... 0 = no extra frag information, 1 = frag information only in warmup, 2 = frag information allowed all the time");
755 NOTIF_WRITE_HARDCODED("server_allows_location", "1", "Server side cvar for allowing death messages to show location information too");
756 NOTIF_WRITE_HARDCODED("show_location", "0", "Append location information to MSG_INFO death/kill messages");
757 NOTIF_WRITE_HARDCODED("show_location_string", "", "Replacement string piped into sprintf, so you can do different messages like this: ' at the %s' or ' (near %s)'");
758 NOTIF_WRITE_HARDCODED("show_sprees", "1", "Print information about sprees in death/kill messages");
759 NOTIF_WRITE_HARDCODED("show_sprees_center", "1", "Show spree information in MSG_CENTER messages... 0 = off, 1 = target (but only for first victim) and attacker");
760 NOTIF_WRITE_HARDCODED("show_sprees_center_specialonly", "1", "Don't show spree information in MSG_CENTER messages if it isn't an achievement");
761 NOTIF_WRITE_HARDCODED("show_sprees_info", "3", "Show spree information in MSG_INFO messages... 0 = off, 1 = target only, 2 = attacker only, 3 = target and attacker");
762 NOTIF_WRITE_HARDCODED("show_sprees_info_newline", "1", "Show attacker spree information for MSG_INFO messages on a separate line than the death notification itself");
763 NOTIF_WRITE_HARDCODED("show_sprees_info_specialonly", "1", "Don't show attacker spree information in MSG_INFO messages if it isn't an achievement");
767 "\n// Notification counts (total = %d): ",
768 "MSG_ANNCE = %d, MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d\n"
783 #undef NOTIF_WRITE_HARDCODED
784 #undef NOTIF_WRITE_ENTITY
789 void Notification_GetCvars()
791 GetCvars_handleFloat(get_cvars_s, get_cvars_f, FRAG_VERBOSE, "notification_frag_verbose");
796 // ===============================
797 // Frontend Notification Pushing
798 // ===============================
800 string Local_Notification_sprintf(
801 string input, string args,
802 string s1, string s2, string s3, string s4,
803 float f1, float f2, float f3, float f4)
805 #ifdef NOTIFICATIONS_DEBUG
807 "Local_Notification_sprintf('%s^7', '%s', %s, %s);\n",
808 MakeConsoleSafe(input),
810 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
811 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
817 for(sel_num = 0; sel_num < NOTIF_MAX_ARGS; ++sel_num) { arg_slot[sel_num] = ""; }
821 for(sel_num = 0;(args != "");)
823 selected = car(args); args = cdr(args);
824 NOTIF_HIT_MAX(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
825 switch(strtolower(selected))
827 #define ARG_CASE(prog,selected,result) \
829 #if (prog != ARG_SV) && (prog != ARG_DC) \
830 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
833 #if (prog != ARG_CS) && (prog != ARG_DC) \
834 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
839 default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
842 return sprintf(input, arg_slot[0], arg_slot[1], arg_slot[2], arg_slot[3], arg_slot[4], arg_slot[5], arg_slot[6]);
846 void Local_Notification_sound(
847 float soundchannel, string soundfile,
848 float soundvolume, float soundposition)
850 if((soundfile != prev_soundfile) || (time >= (prev_soundtime + autocvar_cl_announcer_antispam)))
852 #ifdef NOTIFICATIONS_DEBUG
854 "Local_Notification_sound(world, %f, '%s', %f, %f);\n",
857 "announcer/%s/%s.wav",
858 autocvar_cl_announcer,
870 "announcer/%s/%s.wav",
871 autocvar_cl_announcer,
878 if(prev_soundfile) { strunzone(prev_soundfile); }
879 prev_soundfile = strzone(soundfile);
880 prev_soundtime = time;
884 #ifdef NOTIFICATIONS_DEBUG
886 "Local_Notification_sound(world, %f, '%s', %f, %f) ^1BLOCKED BY ANTISPAM:^7 prevsnd: '%s', time/prevtime: %f, limit: %f\n",
889 "announcer/%s/%s.wav",
890 autocvar_cl_announcer,
896 (time - prev_soundtime),
897 autocvar_cl_announcer_antispam
902 void Local_Notification_HUD_Notify_Push(
903 string icon, string hudargs,
904 string s1, string s2, string s3, string s4)
908 arg_slot[0] = ""; arg_slot[1] = "";
910 for(sel_num = 0;(hudargs != "");)
912 selected = car(hudargs); hudargs = cdr(hudargs);
913 NOTIF_HIT_MAX(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
914 switch(strtolower(selected))
916 #define ARG_CASE(prog,selected,result) \
917 #if (prog == ARG_CS_SV_HA) \
918 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
922 default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
925 #ifdef NOTIFICATIONS_DEBUG
927 "Local_Notification_HUD_Notify_Push('%s^7', '%s', %s, %s);\n",
930 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
931 MakeConsoleSafe(sprintf("'%s^7', '%s^7'", stof(arg_slot[0]), stof(arg_slot[1])))
934 HUD_Notify_Push(icon, arg_slot[0], arg_slot[1]);
937 void Local_Notification_centerprint_generic(
938 string input, string durcnt,
939 float cpid, float f1, float f2)
943 arg_slot[0] = ""; arg_slot[1] = "";
945 for(sel_num = 0;(durcnt != "");)
947 selected = car(durcnt); durcnt = cdr(durcnt);
948 NOTIF_HIT_MAX(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic")
949 switch(strtolower(selected))
951 #define ARG_CASE(prog,selected,result) \
952 #if (prog == ARG_CS_SV_DC) || (prog == ARG_DC) \
953 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
959 if(ftos(stof(selected)) != "") { arg_slot[sel_num] = selected; ++sel_num; }
960 else { NOTIF_HIT_UNKNOWN(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic") }
965 #ifdef NOTIFICATIONS_DEBUG
967 "Local_Notification_centerprint_generic('%s^7', '%s', %d, %d, %d, %d);\n",
968 MakeConsoleSafe(input),
971 stof(arg_slot[0]), stof(arg_slot[1])
974 centerprint_generic(cpid, input, stof(arg_slot[0]), stof(arg_slot[1]));
978 void Local_Notification(float net_type, float net_name, ...count)
980 // check supplied type and name for errors
981 string checkargs = Notification_CheckArgs_TypeName(net_type, net_name);
982 if(checkargs != "") { backtrace(sprintf("Incorrect usage of Local_Notification: %s\n", checkargs)); return; }
984 entity notif = Get_Notif_Ent(net_type, net_name);
985 if not(notif) { backtrace("Local_Notification: Could not find notification entity!\n"); return; }
986 if not(notif.nent_enabled)
988 #ifdef NOTIFICATIONS_DEBUG
990 "Local_Notification(%s, %s): Entity was disabled...\n",
991 Get_Notif_TypeName(net_type),
998 if((notif.nent_stringcount + notif.nent_floatcount) > count)
1002 "Not enough arguments for Local_Notification(%s, %s, ...)! ",
1003 "stringcount(%d) + floatcount(%d) > count(%d)\n",
1004 "Check the definition and function call for accuracy...?\n"
1006 Get_Notif_TypeName(net_type), notif.nent_name,
1007 notif.nent_stringcount, notif.nent_floatcount, count
1011 else if((notif.nent_stringcount + notif.nent_floatcount) < count)
1015 "Too many arguments for Local_Notification(%s, %s, ...)! ",
1016 "stringcount(%d) + floatcount(%d) < count(%d)\n",
1017 "Check the definition and function call for accuracy...?\n"
1019 Get_Notif_TypeName(net_type), notif.nent_name,
1020 notif.nent_stringcount, notif.nent_floatcount, count
1025 string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
1026 string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
1027 string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
1028 string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
1029 float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
1030 float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
1031 float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
1032 float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
1034 #ifdef NOTIFICATIONS_DEBUG
1036 "Local_Notification(%s, %s, %s, %s);\n",
1037 Get_Notif_TypeName(net_type),
1039 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1040 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1049 Local_Notification_sound(
1056 backtrace("MSG_ANNCE on server?... Please notify Samual immediately!\n");
1064 Local_Notification_sprintf(
1071 if(notif.nent_icon != "")
1073 Local_Notification_HUD_Notify_Push(
1085 Local_Notification_centerprint_generic(
1086 Local_Notification_sprintf(
1100 if(notif.nent_msginfo)
1101 if(notif.nent_msginfo.nent_enabled)
1103 Local_Notification_WOVA(
1105 notif.nent_msginfo.nent_id,
1106 notif.nent_msginfo.nent_stringcount,
1107 notif.nent_msginfo.nent_floatcount,
1112 if(notif.nent_msgannce)
1113 if(notif.nent_msgannce.nent_enabled)
1115 Local_Notification_WOVA(
1117 notif.nent_msgannce.nent_id,
1122 if(notif.nent_msgcenter)
1123 if(notif.nent_msgcenter.nent_enabled)
1125 Local_Notification_WOVA(
1127 notif.nent_msgcenter.nent_id,
1128 notif.nent_msgcenter.nent_stringcount,
1129 notif.nent_msgcenter.nent_floatcount,
1139 // WOVA = Without Variable Arguments
1140 void Local_Notification_WOVA(
1141 float net_type, float net_name,
1142 float stringcount, float floatcount,
1143 string s1, string s2, string s3, string s4,
1144 float f1, float f2, float f3, float f4)
1146 #define VARITEM(stringc,floatc,args) \
1147 if((stringcount == stringc) && (floatcount == floatc)) \
1148 { Local_Notification(net_type, net_name, args); return; }
1149 EIGHT_VARS_TO_VARARGS_VARLIST
1151 Local_Notification(net_type, net_name); // some notifications don't have any arguments at all
1155 // =========================
1156 // Notification Networking
1157 // =========================
1160 void Read_Notification(float is_new)
1162 float net_type = ReadByte();
1163 float net_name = ReadShort();
1167 if(net_type == MSG_CENTER_CPID)
1169 #ifdef NOTIFICATIONS_DEBUG
1171 "Read_Notification(%d) at %f: net_type = %s, net_name = %d\n",
1174 Get_Notif_TypeName(net_type),
1181 if(net_name == 0) { reset_centerprint_messages(); }
1182 else if(net_name != NO_CPID)
1184 // in this case, net_name IS the cpid we want to kill
1185 centerprint_generic(net_name, "", 0, 0);
1190 "Read_Notification(%d) at %f: ^1TRIED TO KILL NO_CPID CENTERPRINT!\n",
1199 notif = Get_Notif_Ent(net_type, net_name);
1200 if not(notif) { backtrace("Read_Notification: Could not find notification entity!\n"); return; }
1202 #ifdef NOTIFICATIONS_DEBUG
1204 "Read_Notification(%d) at %f: net_type = %s, net_name = %s\n",
1207 Get_Notif_TypeName(net_type),
1212 string s1 = ((0 < notif.nent_stringcount) ? ReadString() : "");
1213 string s2 = ((1 < notif.nent_stringcount) ? ReadString() : "");
1214 string s3 = ((2 < notif.nent_stringcount) ? ReadString() : "");
1215 string s4 = ((3 < notif.nent_stringcount) ? ReadString() : "");
1216 float f1 = ((0 < notif.nent_floatcount) ? ReadLong() : 0);
1217 float f2 = ((1 < notif.nent_floatcount) ? ReadLong() : 0);
1218 float f3 = ((2 < notif.nent_floatcount) ? ReadLong() : 0);
1219 float f4 = ((3 < notif.nent_floatcount) ? ReadLong() : 0);
1223 Local_Notification_WOVA(
1225 notif.nent_stringcount,
1226 notif.nent_floatcount,
1235 void Net_Notification_Remove()
1237 if not(self) { backtrace(sprintf("Net_Notification_Remove() at %f: Missing self!?\n", time)); return; }
1239 #ifdef NOTIFICATIONS_DEBUG
1241 "Net_Notification_Remove() at %f: %s '%s - %s' notification\n",
1243 ((self.nent_net_name == -1) ? "Killed" : "Removed"),
1244 Get_Notif_TypeName(self.nent_net_type),
1245 self.owner.nent_name
1250 for(i = 0; i < 4; ++i) { if(self.nent_strings[i]) { strunzone(self.nent_strings[i]); } }
1254 float Net_Write_Notification(entity client, float sf)
1256 float i, send = FALSE;
1258 switch(self.nent_broadcast)
1260 case NOTIF_ONE: // send to one client and their spectator
1263 (client == self.nent_client)
1268 (client.enemy == self.nent_client)
1273 case NOTIF_ONE_ONLY: // send ONLY to one client
1275 if(client == self.nent_client) { send = TRUE; }
1278 case NOTIF_TEAM: // send only to X team and their spectators
1281 (client.team == self.nent_client.team)
1286 (client.enemy.team == self.nent_client.team)
1291 case NOTIF_TEAM_EXCEPT: // send only to X team and their spectators, except for Y person and their spectators
1294 (client != self.nent_client)
1297 (client.team == self.nent_client.team)
1303 (client.enemy != self.nent_client)
1305 (client.enemy.team == self.nent_client.team)
1312 case NOTIF_ALL: // send to everyone
1317 case NOTIF_ALL_EXCEPT: // send to everyone except X person and their spectators
1320 (client != self.nent_client)
1325 (client.enemy == self.nent_client)
1330 default: { send = FALSE; break; }
1335 WriteByte(MSG_ENTITY, ENT_CLIENT_NOTIFICATION);
1336 WriteByte(MSG_ENTITY, self.nent_net_type);
1337 WriteShort(MSG_ENTITY, self.nent_net_name);
1338 for(i = 0; i < self.nent_stringcount; ++i) { WriteString(MSG_ENTITY, self.nent_strings[i]); }
1339 for(i = 0; i < self.nent_floatcount; ++i) { WriteLong(MSG_ENTITY, self.nent_floats[i]); }
1345 void Kill_Notification(
1346 float broadcast, entity client,
1347 float net_type, float net_name)
1349 string checkargs = Notification_CheckArgs(broadcast, client, 1, 1);
1350 if(checkargs != "") { backtrace(sprintf("Incorrect usage of Kill_Notification: %s\n", checkargs)); return; }
1352 #ifdef NOTIFICATIONS_DEBUG
1354 "Kill_Notification(%d, '%s', %s, %d);\n",
1357 (net_type ? Get_Notif_TypeName(net_type) : "0"),
1362 entity notif, net_notif;
1363 float killed_cpid = NO_CPID;
1369 killed_cpid = 0; // kill ALL centerprints
1377 entity notif = Get_Notif_Ent(net_type, net_name);
1378 if not(notif) { backtrace("Kill_Notification: Could not find notification entity!\n"); return; }
1381 killed_cpid = notif.nent_cpid;
1383 killed_cpid = NO_CPID;
1387 killed_cpid = 0; // kill ALL centerprints
1392 case MSG_CENTER_CPID:
1394 killed_cpid = net_name;
1399 if(killed_cpid != NO_CPID)
1401 net_notif = spawn();
1402 net_notif.classname = "net_kill_notification";
1403 net_notif.nent_broadcast = broadcast;
1404 net_notif.nent_client = client;
1405 net_notif.nent_net_type = MSG_CENTER_CPID;
1406 net_notif.nent_net_name = killed_cpid;
1407 Net_LinkEntity(net_notif, FALSE, autocvar_notification_lifetime_runtime, Net_Write_Notification);
1410 for(notif = world; (notif = find(notif, classname, "net_notification"));)
1414 if(killed_cpid != NO_CPID)
1416 if(notif.owner.nent_cpid == killed_cpid)
1418 notif.nent_net_name = -1;
1419 notif.nextthink = time;
1421 else { continue; } // we ARE looking for a specific CPID, don't kill everything else too
1423 else if(notif.nent_net_type == net_type)
1427 if(notif.nent_net_name == net_name) { notif.nent_net_name = -1; notif.nextthink = time; }
1428 else { continue; } // we ARE looking for a certain net_name, don't kill everything else too
1430 else { notif.nent_net_name = -1; notif.nextthink = time; }
1432 else { continue; } // we ARE looking for a certain net_type, don't kill everything else too
1434 else { notif.nent_net_name = -1; notif.nextthink = time; }
1438 void Send_Notification(
1439 float broadcast, entity client,
1440 float net_type, float net_name,
1443 // check supplied broadcast, target, type, and name for errors
1444 string checkargs = Notification_CheckArgs(broadcast, client, net_type, net_name);
1445 if(checkargs != "") { backtrace(sprintf("Incorrect usage of Send_Notification: %s\n", checkargs)); return; }
1447 // retreive counts for the arguments of this notification
1448 entity notif = Get_Notif_Ent(net_type, net_name);
1449 if not(notif) { backtrace("Send_Notification: Could not find notification entity!\n"); return; }
1451 if((notif.nent_stringcount + notif.nent_floatcount) > count)
1455 "Not enough arguments for Send_Notification(%d, %s, %s, ...)! ",
1456 "stringcount(%d) + floatcount(%d) > count(%d)\n",
1457 "Check the definition and function call for accuracy...?\n"
1459 broadcast, Get_Notif_TypeName(net_type), notif.nent_name,
1460 notif.nent_stringcount, notif.nent_floatcount, count
1464 else if((notif.nent_stringcount + notif.nent_floatcount) < count)
1468 "Too many arguments for Send_Notification(%d, %s, %s, ...)! ",
1469 "stringcount(%d) + floatcount(%d) < count(%d)\n",
1470 "Check the definition and function call for accuracy...?\n"
1472 broadcast, Get_Notif_TypeName(net_type), notif.nent_name,
1473 notif.nent_stringcount, notif.nent_floatcount, count
1478 #ifdef NOTIFICATIONS_DEBUG
1479 string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
1480 string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
1481 string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
1482 string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
1483 float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
1484 float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
1485 float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
1486 float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
1488 "Send_Notification(%d, %s, %s, %s, %s);\n",
1490 Get_Notif_TypeName(net_type),
1492 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1493 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1497 entity net_notif = spawn();
1498 net_notif.owner = notif;
1499 net_notif.classname = "net_notification";
1500 net_notif.nent_broadcast = broadcast;
1501 net_notif.nent_client = client;
1502 net_notif.nent_net_type = net_type;
1503 net_notif.nent_net_name = net_name;
1504 net_notif.nent_stringcount = notif.nent_stringcount;
1505 net_notif.nent_floatcount = notif.nent_floatcount;
1508 for(i = 0; i < net_notif.nent_stringcount; ++i) { net_notif.nent_strings[i] = strzone(...(i, string)); }
1509 for(i = 0; i < net_notif.nent_floatcount; ++i) { net_notif.nent_floats[i] = ...((net_notif.nent_stringcount + i), float); }
1511 net_notif.think = Net_Notification_Remove;
1512 net_notif.nextthink =
1513 ((time > autocvar_notification_lifetime_mapload)
1515 (time + autocvar_notification_lifetime_runtime)
1517 autocvar_notification_lifetime_mapload
1520 Net_LinkEntity(net_notif, FALSE, 0, Net_Write_Notification);
1522 if(server_is_dedicated && (broadcast == NOTIF_ALL || broadcast == NOTIF_ALL_EXCEPT) && (net_type != MSG_ANNCE) && (net_type != MSG_CENTER))
1524 Local_Notification_WOVA(
1526 notif.nent_stringcount,
1527 notif.nent_floatcount,
1528 IFSTR(0), IFSTR(1), IFSTR(2), IFSTR(3),
1529 IFFL(0), IFFL(1), IFFL(2), IFFL(3));
1533 // WOVA = Without Variable Arguments
1534 void Send_Notification_WOVA(
1535 float broadcast, entity client,
1536 float net_type, float net_name,
1537 string s1, string s2, string s3, string s4,
1538 float f1, float f2, float f3, float f4)
1540 entity notif = Get_Notif_Ent(net_type, net_name);
1542 #ifdef NOTIFICATIONS_DEBUG
1544 "Send_Notification_WOVA(%d, %s, %s, %s, %s);\n",
1546 Get_Notif_TypeName(net_type),
1548 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1549 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1553 #define VARITEM(stringc,floatc,args) \
1554 if((notif.nent_stringcount == stringc) && (notif.nent_floatcount == floatc)) \
1555 { Send_Notification(broadcast, client, net_type, net_name, args); return; }
1556 EIGHT_VARS_TO_VARARGS_VARLIST
1558 Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
1560 #endif // ifdef SVQC