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_INFO: return "MSG_INFO";
11 case MSG_CENTER: return "MSG_CENTER";
12 case MSG_CENTER_CPID: return "MSG_CENTER_CPID";
13 case MSG_MULTI: return "MSG_MULTI";
15 backtrace(sprintf("Get_Notif_TypeName(%d): Improper net type!\n", net_type));
19 entity Get_Notif_Ent(float net_type, float net_name)
23 case MSG_INFO: return msg_info_notifs[net_name - 1];
24 case MSG_CENTER: return msg_center_notifs[net_name - 1];
25 case MSG_MULTI: return msg_multi_notifs[net_name - 1];
27 backtrace(sprintf("Get_Notif_Ent(%d, %d): Improper net type!\n", net_type, net_name));
31 string Notification_CheckArgs_TypeName(float net_type, float net_name)
33 // check supplied type and name for errors
34 string checkargs = "";
35 #define CHECKARG_TYPENAME(type) case MSG_##type##: \
36 { if(!net_name || (net_name > NOTIF_##type##_COUNT)) \
37 { checkargs = sprintf("Improper name: %d!", net_name); } break; }
40 CHECKARG_TYPENAME(INFO)
41 CHECKARG_TYPENAME(CENTER)
42 CHECKARG_TYPENAME(MULTI)
43 default: { checkargs = sprintf("Improper type: %d!", checkargs, net_type); break; }
45 #undef CHECKARG_TYPENAME
50 string Notification_CheckArgs(
51 float broadcast, entity client,
52 float net_type, float net_name)
54 // check supplied broadcast, target, type, and name for errors
55 string checkargs = Notification_CheckArgs_TypeName(net_type, net_name);
56 if(checkargs != "") { checkargs = strcat(checkargs, " "); }
62 if(IS_NOT_A_CLIENT(client))
63 { checkargs = sprintf("%sNo client provided!", checkargs); }
67 case NOTIF_ALL_EXCEPT:
69 if(IS_NOT_A_CLIENT(client))
70 { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
77 { checkargs = sprintf("%sEntity provided when world was required!", checkargs); }
82 case NOTIF_TEAM_EXCEPT:
84 if not(teamplay) { checkargs = sprintf("%sTeamplay not active!", checkargs); }
85 else if(IS_NOT_A_CLIENT(client))
87 if(broadcast == NOTIF_TEAM) { checkargs = sprintf("%sNo client provided!", checkargs); }
88 else { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
93 default: { checkargs = sprintf("%sImproper broadcast: %d!", checkargs, broadcast); break; }
99 // ===============================
100 // Initialization Core Functions
101 // ===============================
103 // used by restartnotifs command to initialize notifications
104 void Destroy_Notification_Entity(entity notif)
106 if(notif.nent_name != "") { strunzone(notif.nent_name); }
107 if(notif.nent_args != "") { strunzone(notif.nent_args); }
108 if(notif.nent_hudargs != "") { strunzone(notif.nent_hudargs); }
109 if(notif.nent_icon != "") { strunzone(notif.nent_icon); }
110 if(notif.nent_durcnt != "") { strunzone(notif.nent_durcnt); }
111 if(notif.nent_string != "") { strunzone(notif.nent_string); }
115 void Destroy_All_Notifications(void)
120 #define DESTROY_LOOP(type,count) \
121 for(i = 1; i <= count; ++i) \
123 notif = Get_Notif_Ent(type, i); \
124 if not(notif) { backtrace("Destroy_All_Notifications(): Missing notification entity!\n"); return; } \
125 Destroy_Notification_Entity(notif); \
128 // kill all networked notifications
130 Kill_Notification(NOTIF_ALL, world, 0, 0);
133 // kill all real notification entities
134 DESTROY_LOOP(MSG_INFO, NOTIF_INFO_COUNT)
135 DESTROY_LOOP(MSG_CENTER, NOTIF_CENTER_COUNT)
136 DESTROY_LOOP(MSG_MULTI, NOTIF_MULTI_COUNT)
140 string Process_Notif_Line(
151 if((chat && autocvar_notification_allow_chatboxprint)
152 || (autocvar_notification_allow_chatboxprint == 2))
154 // pass 1: add ETX char at beginning of line
155 input = strcat("\{3}", input);
157 // pass 2: add ETX char at end of each new line (so that
158 // messages with multiple lines are put through chatbox too)
159 input = strreplace("\n", "\n\{3}", input);
161 // pass 3: strip trailing ETX char
162 if(substring(input, (strlen(input) - 1), 1) == "\{3}")
163 { input = substring(input, 0, (strlen(input) - 1)); }
166 if(substring(input, (strlen(input) - 1), 1) != "\n")
170 "^1MISSING/BROKEN NEW LINE AT END OF NOTIFICATION: ",
171 "^7net_type = %s, net_name = %s, string = %s.\n"
178 return strcat(input, "\n");
184 string Process_Notif_Args(
190 string selected, remaining = args;
193 for(;(remaining != "");)
195 selected = car(remaining); remaining = cdr(remaining);
199 case 1: // normal args
201 if(sel_num == NOTIF_MAX_ARGS)
205 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
206 "^7net_type = %s, net_name = %s, max args = %d.\n"
216 switch(strtolower(selected))
218 #define ARG_CASE(prog,selected,result) \
219 #if (prog != ARG_DC) \
220 case selected: { ++sel_num; break; } \
228 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
229 "^7net_type = %s, net_name = %s, args arg = '%s'.\n"
243 if(sel_num == NOTIF_MAX_HUDARGS)
247 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
248 "^7net_type = %s, net_name = %s, max hudargs = %d.\n"
258 switch(strtolower(selected))
260 #define ARG_CASE(prog,selected,result) \
261 #if (prog == ARG_CS_SV_HA) \
262 case selected: { ++sel_num; break; } \
270 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
271 "^7net_type = %s, net_name = %s, hudargs arg = '%s'.\n"
285 if(sel_num == NOTIF_MAX_DURCNT)
289 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
290 "^7net_type = %s, net_name = %s, max durcnt = %d.\n"
300 switch(strtolower(selected))
302 #define ARG_CASE(prog,selected,result) \
303 #if (prog == ARG_CS_SV_DC) || (prog == ARG_DC) \
304 case selected: { ++sel_num; break; } \
310 if(ftos(stof(selected)) != "") { ++sel_num; }
315 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
316 "^7net_type = %s, net_name = %s, durcnt arg = '%s'.\n"
334 void Create_Notification_Entity(
354 // =====================
355 // Global Entity Setup
356 // =====================
357 entity notif = spawn();
358 string typestring = "";
363 typestring = "MSG_INFO";
364 msg_info_notifs[nameid - 1] = notif;
365 notif.classname = "msg_info_notification";
370 typestring = "MSG_CENTER";
371 msg_center_notifs[nameid - 1] = notif;
372 notif.classname = "msg_center_notification";
377 typestring = "MSG_MULTI";
378 msg_multi_notifs[nameid - 1] = notif;
379 notif.classname = "MSG_MULTI_notification";
387 "^1NOTIFICATION WITH IMPROPER TYPE: ",
388 "^7net_type = %d, net_name = %s.\n"
393 return; // It's not possible to recover from this one
396 notif.nent_default = var_default;
397 notif.nent_name = strzone(namestring);
398 notif.nent_id = nameid;
399 notif.nent_enabled = (1 <= var_cvar);
401 // Other pre-notif-setup requisites
404 // ====================
405 // Notification Setup
406 // ====================
409 // Set MSG_MULTI string/float counts
410 if((infoname == NO_MSG) && (centername == NO_MSG))
414 "^1NOTIFICATION WITH NO SUBCALLS: ",
415 "^7net_type = %s, net_name = %s.\n"
424 float infoname_stringcount = 0, infoname_floatcount = 0;
425 float centername_stringcount = 0, centername_floatcount = 0;
427 if(infoname != NO_MSG)
429 notif.nent_msginfo = msg_info_notifs[infoname - 1];
430 infoname_stringcount = notif.nent_msginfo.nent_stringcount;
431 infoname_floatcount = notif.nent_msginfo.nent_floatcount;
434 if(centername != NO_MSG)
436 notif.nent_msgcenter = msg_center_notifs[centername - 1];
437 centername_stringcount = notif.nent_msgcenter.nent_stringcount;
438 centername_floatcount = notif.nent_msgcenter.nent_floatcount;
441 // set the requirements of THIS notification to the totals of its subcalls
442 notif.nent_stringcount = max(infoname_stringcount, centername_stringcount);
443 notif.nent_floatcount = max(infoname_floatcount, centername_floatcount);
448 // Set MSG_INFO and MSG_CENTER string/float counts
449 notif.nent_stringcount = strnum;
450 notif.nent_floatcount = flnum;
452 // Only initialize arguments if we're either a client or on a dedicated server
454 float should_process_args = server_is_dedicated;
456 float should_process_args = TRUE;
459 if(should_process_args)
461 // ========================
462 // Process Main Arguments
463 // ========================
468 notif.nent_args = strzone(
469 Process_Notif_Args(1, args, typestring, namestring));
471 else if((hudargs == "") && (durcnt ==""))
475 "^1NOTIFICATION HAS ARG COUNTS BUT NO ARGS OR HUDARGS OR DURCNT: ",
476 "^7net_type = %s, net_name = %s, strnum = %d, flnum = %d\n"
488 notif.nent_args = strzone(
489 Process_Notif_Args(1, args, typestring, namestring));
493 // =======================================
494 // Process HUD and Centerprint Arguments
495 // Only processed on CSQC, as these
496 // args are only for HUD features.
497 // =======================================
501 notif.nent_hudargs = strzone(
502 Process_Notif_Args(2, hudargs, typestring, namestring));
504 if(icon != "") { notif.nent_icon = strzone(icon); }
509 "^1NOTIFICATION HAS HUDARGS BUT NO ICON: ",
510 "^7net_type = %s, net_name = %s.\n"
522 "^1NOTIFICATION HAS ICON BUT NO HUDARGS: ",
523 "^7net_type = %s, net_name = %s.\n"
533 notif.nent_durcnt = strzone(
534 Process_Notif_Args(3, durcnt, typestring, namestring));
536 if(cpid != NO_MSG) { notif.nent_cpid = cpid; }
541 "^1NOTIFICATION HAS DURCNT BUT NO CPID: ",
542 "^7net_type = %s, net_name = %s.\n"
550 else if(cpid != NO_CPID) { notif.nent_cpid = cpid; }
554 // ======================
555 // Process Notif String
556 // ======================
557 #define SET_NOTIF_STRING(string,stringname) \
558 notif.nent_string = strzone(CCR( \
559 Process_Notif_Line( \
571 if(gentle != "") { SET_NOTIF_STRING(gentle, "GENTLE") }
572 else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL") }
574 else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL") }
576 #undef SET_NOTIF_STRING
578 // Check to make sure a string was chosen
579 if(notif.nent_string == "")
583 "^1EMPTY NOTIFICATION: ",
584 "^7net_type = %s, net_name = %s.\n"
594 // now check to see if any errors happened
597 notif.nent_enabled = FALSE; // disable the notification so it can't cause trouble
598 notif_global_error = TRUE; // throw the red flag that an error happened on init
603 // =========================================
604 // Cvar Handling With 'dumpnotifs' Command
605 // =========================================
607 void Dump_Notifications(float fh, float alsoprint)
609 #define NOTIF_WRITE(a) { \
611 if(alsoprint) { print(a); } }
612 #define NOTIF_WRITE_ENTITY(name,default,description) { \
615 "seta notification_%s \"%d\" \"%s\"\n", \
616 name, default, description \
618 NOTIF_WRITE(notif_msg) }
619 #define NOTIF_WRITE_HARDCODED(cvar,default,description) { \
622 "seta notification_%s \"%s\" \"%s\"\n", \
623 cvar, default, description \
625 NOTIF_WRITE(notif_msg) }
631 // Note: This warning only applies to the notifications.cfg file that is output...
633 // You ARE supposed to manually edit this function to add i.e. hard coded
634 // notification variables for mutators or game modes or such and then
635 // regenerate the notifications.cfg file from the new code.
637 NOTIF_WRITE("// ********************************************** //\n");
638 NOTIF_WRITE("// ** WARNING - DO NOT MANUALLY EDIT THIS FILE ** //\n");
639 NOTIF_WRITE("// ** ** //\n");
640 NOTIF_WRITE("// ** This file is automatically generated ** //\n");
641 NOTIF_WRITE("// ** by code with the command 'dumpnotifs'. ** //\n");
642 NOTIF_WRITE("// ** ** //\n");
643 NOTIF_WRITE("// ** If you add a new notification, please ** //\n");
644 NOTIF_WRITE("// ** regenerate this file with that command ** //\n");
645 NOTIF_WRITE("// ** making sure that the output matches ** //\n");
646 NOTIF_WRITE("// ** with the lists and defaults in code. ** //\n");
647 NOTIF_WRITE("// ** ** //\n");
648 NOTIF_WRITE("// ********************************************** //\n");
650 // These notifications will also append their string as a comment...
651 // This is not necessary, and does not matter if they vary between config versions,
652 // it is just a semi-helpful tool for those who want to manually change their user settings.
654 NOTIF_WRITE(sprintf("\n// MSG_INFO notifications (count = %d):\n", NOTIF_INFO_COUNT));
655 for(i = 1; i <= NOTIF_INFO_COUNT; ++i)
657 e = Get_Notif_Ent(MSG_INFO, i);
658 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
659 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)");
662 NOTIF_WRITE(sprintf("\n// MSG_CENTER notifications (count = %d):\n", NOTIF_CENTER_COUNT));
663 for(i = 1; i <= NOTIF_CENTER_COUNT; ++i)
665 e = Get_Notif_Ent(MSG_CENTER, i);
666 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
667 NOTIF_WRITE_ENTITY(e.nent_name, e.nent_default, "Notification control cvar: 0 = off, 1 = centerprint");
670 NOTIF_WRITE(sprintf("\n// MSG_MULTI notifications (count = %d):\n", NOTIF_MULTI_COUNT));
671 for(i = 1; i <= NOTIF_MULTI_COUNT; ++i)
673 e = Get_Notif_Ent(MSG_MULTI, i);
674 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
675 NOTIF_WRITE_ENTITY(e.nent_name, e.nent_default, "Notification control cvar: 0 = off, 1 = trigger subcalls");
678 // edit these to match whichever cvars are used for specific notification options
679 NOTIF_WRITE("\n// HARD CODED notification variables:\n");
680 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)");
681 NOTIF_WRITE_HARDCODED("show_location", "0", "Append location information to MSG_INFO death/kill messages");
682 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)'");
683 NOTIF_WRITE_HARDCODED("show_sprees", "1", "Print information about sprees in death/kill messages");
684 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");
685 NOTIF_WRITE_HARDCODED("show_sprees_center_specialonly", "1", "Don't show spree information in MSG_CENTER messages if it isn't an achievement");
686 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");
687 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");
688 NOTIF_WRITE_HARDCODED("show_sprees_info_specialonly", "1", "Don't show attacker spree information in MSG_INFO messages if it isn't an achievement");
689 NOTIF_WRITE_HARDCODED("item_centerprinttime", "1.5", "How long to show item information centerprint messages (like 'You got the Electro' or such)");
690 NOTIF_WRITE_HARDCODED("errors_are_fatal", "1", "If a notification fails upon initialization, cause a Host_Error to stop the program");
691 NOTIF_WRITE_HARDCODED("ctf_pickup_team_verbose", "0", "Show extra information if a team mate picks up a flag");
692 NOTIF_WRITE_HARDCODED("ctf_pickup_enemy_verbose", "0", "Show extra information if an enemy picks up a flag");
693 NOTIF_WRITE_HARDCODED("ctf_capture_verbose", "0", "Show extra information when someone captures a flag");
694 NOTIF_WRITE_HARDCODED("frag_verbose", "1", "Show extra information when you frag someone (or when you are fragged");
695 NOTIF_WRITE_HARDCODED("lifetime_runtime", "0.5", "Amount of time that notification entities last on the server during runtime (In seconds)");
696 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)");
700 "\n// Notification counts (total = %d): ",
701 "MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d\n"
714 #undef NOTIF_WRITE_HARDCODED
715 #undef NOTIF_WRITE_ENTITY
720 void Notification_GetCvars()
722 GetCvars_handleFloat(get_cvars_s, get_cvars_f, FRAG_VERBOSE, "notification_frag_verbose");
727 // ===============================
728 // Frontend Notification Pushing
729 // ===============================
731 string Local_Notification_sprintf(
732 string input, string args,
733 string s1, string s2, string s3, string s4,
734 float f1, float f2, float f3, float f4)
736 #ifdef NOTIFICATIONS_DEBUG
738 "Local_Notification_sprintf('%s^7', '%s', %s, %s);\n",
739 strreplace("\n", "\\n", input),
741 strreplace("\n", "\\n", sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
742 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
748 for(sel_num = 0; sel_num < NOTIF_MAX_ARGS; ++sel_num) { arg_slot[sel_num] = ""; }
752 for(sel_num = 0;(args != "");)
754 selected = car(args); args = cdr(args);
755 NOTIF_HIT_MAX(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
756 switch(strtolower(selected))
758 #define ARG_CASE(prog,selected,result) \
760 #if (prog != ARG_SV) && (prog != ARG_DC) \
761 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
764 #if (prog != ARG_CS) && (prog != ARG_DC) \
765 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
770 default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
773 return sprintf(input, arg_slot[0], arg_slot[1], arg_slot[2], arg_slot[3], arg_slot[4], arg_slot[5], arg_slot[6]);
777 void Local_Notification_HUD_Notify_Push(
778 string icon, string hudargs,
779 string s1, string s2, string s3, string s4)
783 arg_slot[0] = ""; arg_slot[1] = "";
785 for(sel_num = 0;(hudargs != "");)
787 selected = car(hudargs); hudargs = cdr(hudargs);
788 NOTIF_HIT_MAX(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
789 switch(strtolower(selected))
791 #define ARG_CASE(prog,selected,result) \
792 #if (prog == ARG_CS_SV_HA) \
793 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
797 default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
800 #ifdef NOTIFICATIONS_DEBUG
802 "Local_Notification_HUD_Notify_Push('%s^7', '%s', %s, %s);\n",
805 strreplace("\n", "\\n", sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
806 strreplace("\n", "\\n", sprintf("'%s^7', '%s^7'", stof(arg_slot[0]), stof(arg_slot[1])))
809 HUD_Notify_Push(icon, arg_slot[0], arg_slot[1]);
812 void Local_Notification_centerprint_generic(
813 string input, string durcnt,
814 float cpid, float f1, float f2)
818 arg_slot[0] = ""; arg_slot[1] = "";
820 for(sel_num = 0;(durcnt != "");)
822 selected = car(durcnt); durcnt = cdr(durcnt);
823 NOTIF_HIT_MAX(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic")
824 switch(strtolower(selected))
826 #define ARG_CASE(prog,selected,result) \
827 #if (prog == ARG_CS_SV_DC) || (prog == ARG_DC) \
828 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
834 if(ftos(stof(selected)) != "") { arg_slot[sel_num] = selected; ++sel_num; }
835 else { NOTIF_HIT_UNKNOWN(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic") }
840 #ifdef NOTIFICATIONS_DEBUG
842 "Local_Notification_centerprint_generic('%s^7', '%s', %d, %d, %d, %d);\n",
843 strreplace("\n", "\\n", input),
846 stof(arg_slot[0]), stof(arg_slot[1])
849 centerprint_generic(cpid, input, stof(arg_slot[0]), stof(arg_slot[1]));
853 void Local_Notification(float net_type, float net_name, ...count)
855 // check supplied type and name for errors
856 string checkargs = Notification_CheckArgs_TypeName(net_type, net_name);
857 if(checkargs != "") { backtrace(sprintf("Incorrect usage of Local_Notification: %s\n", checkargs)); return; }
859 entity notif = Get_Notif_Ent(net_type, net_name);
860 if not(notif) { backtrace("Local_Notification: Could not find notification entity!\n"); return; }
862 #ifdef NOTIFICATIONS_DEBUG
863 if not(notif.nent_enabled)
866 "Local_Notification(%s, %s): Entity was disabled...\n",
867 Get_Notif_TypeName(net_type),
874 if((notif.nent_stringcount + notif.nent_floatcount) > count)
878 "Not enough arguments for Local_Notification(%s, %s, ...)! ",
879 "stringcount(%d) + floatcount(%d) > count(%d)\n",
880 "Check the definition and function call for accuracy...?\n"
882 Get_Notif_TypeName(net_type), notif.nent_name,
883 notif.nent_stringcount, notif.nent_floatcount, count
887 else if((notif.nent_stringcount + notif.nent_floatcount) < count)
891 "Too many arguments for Local_Notification(%s, %s, ...)! ",
892 "stringcount(%d) + floatcount(%d) < count(%d)\n",
893 "Check the definition and function call for accuracy...?\n"
895 Get_Notif_TypeName(net_type), notif.nent_name,
896 notif.nent_stringcount, notif.nent_floatcount, count
901 string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
902 string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
903 string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
904 string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
905 float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
906 float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
907 float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
908 float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
910 #ifdef NOTIFICATIONS_DEBUG
912 "Local_Notification(%s, %s, %s, %s);\n",
913 Get_Notif_TypeName(net_type),
915 strreplace("\n", "\\n", sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
916 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
925 Local_Notification_sprintf(
932 if(notif.nent_icon != "")
934 Local_Notification_HUD_Notify_Push(
946 Local_Notification_centerprint_generic(
947 Local_Notification_sprintf(
961 if(notif.nent_msginfo)
962 if(notif.nent_msginfo.nent_enabled)
964 Local_Notification_WOVA(
966 notif.nent_msginfo.nent_id,
967 notif.nent_msginfo.nent_stringcount,
968 notif.nent_msginfo.nent_floatcount,
973 if(notif.nent_msgcenter)
974 if(notif.nent_msgcenter.nent_enabled)
976 Local_Notification_WOVA(
978 notif.nent_msgcenter.nent_id,
979 notif.nent_msgcenter.nent_stringcount,
980 notif.nent_msgcenter.nent_floatcount,
990 // WOVA = Without Variable Arguments
991 void Local_Notification_WOVA(
992 float net_type, float net_name,
993 float stringcount, float floatcount,
994 string s1, string s2, string s3, string s4,
995 float f1, float f2, float f3, float f4)
997 #define VARITEM(stringc,floatc,args) \
998 if((stringcount == stringc) && (floatcount == floatc)) \
999 { Local_Notification(net_type, net_name, args); return; }
1000 EIGHT_VARS_TO_VARARGS_VARLIST
1002 Local_Notification(net_type, net_name); // some notifications don't have any arguments at all
1006 // =========================
1007 // Notification Networking
1008 // =========================
1011 void Read_Notification(float is_new)
1013 float net_type = ReadByte();
1014 float net_name = ReadShort();
1018 if(net_type == MSG_CENTER_CPID)
1020 #ifdef NOTIFICATIONS_DEBUG
1022 "Read_Notification(%d) at %f: net_type = %s, net_name = %d\n",
1025 Get_Notif_TypeName(net_type),
1032 if(net_name == 0) { reset_centerprint_messages(); }
1033 else if(net_name != NO_CPID)
1035 // in this case, net_name IS the cpid we want to kill
1036 centerprint_generic(net_name, "", 0, 0);
1041 "Read_Notification(%d) at %f: ^1TRIED TO KILL NO_CPID CENTERPRINT!\n",
1050 notif = Get_Notif_Ent(net_type, net_name);
1051 if not(notif) { backtrace("Read_Notification: Could not find notification entity!\n"); return; }
1053 #ifdef NOTIFICATIONS_DEBUG
1055 "Read_Notification(%d) at %f: net_type = %s, net_name = %s\n",
1058 Get_Notif_TypeName(net_type),
1063 string s1 = ((0 < notif.nent_stringcount) ? ReadString() : "");
1064 string s2 = ((1 < notif.nent_stringcount) ? ReadString() : "");
1065 string s3 = ((2 < notif.nent_stringcount) ? ReadString() : "");
1066 string s4 = ((3 < notif.nent_stringcount) ? ReadString() : "");
1067 float f1 = ((0 < notif.nent_floatcount) ? ReadLong() : 0);
1068 float f2 = ((1 < notif.nent_floatcount) ? ReadLong() : 0);
1069 float f3 = ((2 < notif.nent_floatcount) ? ReadLong() : 0);
1070 float f4 = ((3 < notif.nent_floatcount) ? ReadLong() : 0);
1074 Local_Notification_WOVA(
1076 notif.nent_stringcount,
1077 notif.nent_floatcount,
1086 void Net_Notification_Remove()
1088 if not(self) { dprint(sprintf("Net_Notification_Remove() at %f: Missing self!?\n", time)); return; }
1090 #ifdef NOTIFICATIONS_DEBUG
1092 "Net_Notification_Remove() at %f: %s '%s - %s' notification\n",
1094 ((self.nent_net_name == -1) ? "Killed" : "Removed"),
1095 Get_Notif_TypeName(self.nent_net_type),
1096 self.owner.nent_name
1101 for(i = 0; i < 4; ++i) { if(self.nent_strings[i]) { strunzone(self.nent_strings[i]); } }
1105 float Net_Write_Notification(entity client, float sf)
1107 float i, send = FALSE;
1109 switch(self.nent_broadcast)
1111 case NOTIF_ONE: // send to one client and their spectator
1114 (client == self.nent_client)
1119 (client.enemy == self.nent_client)
1124 case NOTIF_ONE_ONLY: // send ONLY to one client
1126 if(client == self.nent_client) { send = TRUE; }
1129 case NOTIF_TEAM: // send only to X team and their spectators
1132 (client.team == self.nent_client.team)
1137 (client.enemy.team == self.nent_client.team)
1142 case NOTIF_TEAM_EXCEPT: // send only to X team and their spectators, except for Y person and their spectators
1145 (client != self.nent_client)
1148 (client.team == self.nent_client.team)
1154 (client.enemy != self.nent_client)
1156 (client.enemy.team == self.nent_client.team)
1163 case NOTIF_ALL: // send to everyone
1168 case NOTIF_ALL_EXCEPT: // send to everyone except X person and their spectators
1171 (client != self.nent_client)
1176 (client.enemy == self.nent_client)
1181 default: { send = FALSE; break; }
1186 WriteByte(MSG_ENTITY, ENT_CLIENT_NOTIFICATION);
1187 WriteByte(MSG_ENTITY, self.nent_net_type);
1188 WriteShort(MSG_ENTITY, self.nent_net_name);
1189 for(i = 0; i < self.nent_stringcount; ++i) { WriteString(MSG_ENTITY, self.nent_strings[i]); }
1190 for(i = 0; i < self.nent_floatcount; ++i) { WriteLong(MSG_ENTITY, self.nent_floats[i]); }
1196 void Kill_Notification(
1197 float broadcast, entity client,
1198 float net_type, float net_name)
1200 string checkargs = Notification_CheckArgs(broadcast, client, 1, 1);
1201 if(checkargs != "") { backtrace(sprintf("Incorrect usage of Kill_Notification: %s\n", checkargs)); return; }
1203 #ifdef NOTIFICATIONS_DEBUG
1205 "Kill_Notification(%d, '%s', %d, %d);\n",
1213 entity notif, net_notif;
1214 float killed_cpid = NO_CPID;
1220 killed_cpid = 0; // kill ALL centerprints
1228 entity notif = Get_Notif_Ent(net_type, net_name);
1229 if not(notif) { backtrace("Kill_Notification: Could not find notification entity!\n"); return; }
1230 killed_cpid = notif.nent_cpid;
1234 killed_cpid = 0; // kill ALL centerprints
1239 case MSG_CENTER_CPID:
1241 killed_cpid = net_name;
1246 if(killed_cpid != NO_CPID)
1248 net_notif = spawn();
1249 net_notif.classname = "net_kill_notification";
1250 net_notif.nent_broadcast = broadcast;
1251 net_notif.nent_client = client;
1252 net_notif.nent_net_type = MSG_CENTER_CPID;
1253 net_notif.nent_net_name = killed_cpid;
1254 Net_LinkEntity(net_notif, FALSE, autocvar_notification_lifetime_runtime, Net_Write_Notification);
1257 for(notif = world; (notif = find(notif, classname, "net_notification"));)
1261 if(killed_cpid != NO_CPID)
1263 if(notif.owner.nent_cpid == killed_cpid)
1265 notif.nent_net_name = -1;
1266 notif.nextthink = time;
1268 else { continue; } // we ARE looking for a specific CPID, don't kill everything else too
1270 else if(notif.nent_net_type == net_type)
1274 if(notif.nent_net_name == net_name) { notif.nent_net_name = -1; notif.nextthink = time; }
1275 else { continue; } // we ARE looking for a certain net_name, don't kill everything else too
1277 else { notif.nent_net_name = -1; notif.nextthink = time; }
1279 else { continue; } // we ARE looking for a certain net_type, don't kill everything else too
1281 else { notif.nent_net_name = -1; notif.nextthink = time; }
1285 void Send_Notification(
1286 float broadcast, entity client,
1287 float net_type, float net_name,
1290 // check supplied broadcast, target, type, and name for errors
1291 string checkargs = Notification_CheckArgs(broadcast, client, net_type, net_name);
1292 if(checkargs != "") { backtrace(sprintf("Incorrect usage of Send_Notification: %s\n", checkargs)); return; }
1294 // retreive counts for the arguments of this notification
1295 entity notif = Get_Notif_Ent(net_type, net_name);
1296 if not(notif) { backtrace("Send_Notification: Could not find notification entity!\n"); return; }
1298 if((notif.nent_stringcount + notif.nent_floatcount) > count)
1302 "Not enough arguments for Send_Notification(%d, %s, %s, ...)! ",
1303 "stringcount(%d) + floatcount(%d) > count(%d)\n",
1304 "Check the definition and function call for accuracy...?\n"
1306 broadcast, Get_Notif_TypeName(net_type), notif.nent_name,
1307 notif.nent_stringcount, notif.nent_floatcount, count
1311 else if((notif.nent_stringcount + notif.nent_floatcount) < count)
1315 "Too many arguments for Send_Notification(%d, %s, %s, ...)! ",
1316 "stringcount(%d) + floatcount(%d) < count(%d)\n",
1317 "Check the definition and function call for accuracy...?\n"
1319 broadcast, Get_Notif_TypeName(net_type), notif.nent_name,
1320 notif.nent_stringcount, notif.nent_floatcount, count
1325 #ifdef NOTIFICATIONS_DEBUG
1326 string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
1327 string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
1328 string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
1329 string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
1330 float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
1331 float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
1332 float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
1333 float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
1335 "Send_Notification(%d, %s, %s, %s, %s);\n",
1337 Get_Notif_TypeName(net_type),
1339 strreplace("\n", "\\n", sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1340 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1344 entity net_notif = spawn();
1345 net_notif.owner = notif;
1346 net_notif.classname = "net_notification";
1347 net_notif.nent_broadcast = broadcast;
1348 net_notif.nent_client = client;
1349 net_notif.nent_net_type = net_type;
1350 net_notif.nent_net_name = net_name;
1351 net_notif.nent_stringcount = notif.nent_stringcount;
1352 net_notif.nent_floatcount = notif.nent_floatcount;
1355 for(i = 0; i < net_notif.nent_stringcount; ++i) { net_notif.nent_strings[i] = strzone(...(i, string)); }
1356 for(i = 0; i < net_notif.nent_floatcount; ++i) { net_notif.nent_floats[i] = ...((net_notif.nent_stringcount + i), float); }
1358 net_notif.think = Net_Notification_Remove;
1359 net_notif.nextthink =
1360 ((time > autocvar_notification_lifetime_mapload)
1362 (time + autocvar_notification_lifetime_runtime)
1364 autocvar_notification_lifetime_mapload
1367 Net_LinkEntity(net_notif, FALSE, 0, Net_Write_Notification);
1369 if(server_is_dedicated && (broadcast == NOTIF_ALL || broadcast == NOTIF_ALL_EXCEPT) && (net_type != MSG_CENTER))
1371 Local_Notification_WOVA(
1373 notif.nent_stringcount,
1374 notif.nent_floatcount,
1375 IFSTR(0), IFSTR(1), IFSTR(2), IFSTR(3),
1376 IFFL(0), IFFL(1), IFFL(2), IFFL(3));
1380 // WOVA = Without Variable Arguments
1381 void Send_Notification_WOVA(
1382 float broadcast, entity client,
1383 float net_type, float net_name,
1384 string s1, string s2, string s3, string s4,
1385 float f1, float f2, float f3, float f4)
1387 entity notif = Get_Notif_Ent(net_type, net_name);
1389 #ifdef NOTIFICATIONS_DEBUG
1391 "Send_Notification_WOVA(%d, %s, %s, %s, %s - %d %d);\n",
1393 Get_Notif_TypeName(net_type),
1395 sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4),
1396 sprintf("%d, %d, %d, %d", f1, f2, f3, f4),
1397 notif.nent_stringcount, notif.nent_floatcount
1401 #define VARITEM(stringc,floatc,args) \
1402 if((notif.nent_stringcount == stringc) && (notif.nent_floatcount == floatc)) \
1403 { Send_Notification(broadcast, client, net_type, net_name, args); return; }
1404 EIGHT_VARS_TO_VARARGS_VARLIST
1406 Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
1408 #endif // ifdef SVQC