1 // ================================================
2 // Unified notification system, written by Samual
3 // Last updated: February, 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_MULTI: return "MSG_MULTI";
14 backtrace(sprintf("Get_Notif_TypeName(%d): Improper net type!\n", net_type));
18 entity Get_Notif_Ent(float net_type, float net_name)
22 case MSG_INFO: return msg_info_notifs[net_name - 1];
23 case MSG_CENTER: return msg_center_notifs[net_name - 1];
24 case MSG_MULTI: return msg_multi_notifs[net_name - 1];
26 backtrace(sprintf("Get_Notif_Ent(%d, %d): Improper net type!\n", net_type, net_name));
30 string Notification_CheckArgs_TypeName(float net_type, float net_name)
32 // check supplied type and name for errors
33 string checkargs = "";
34 #define CHECKARG_TYPENAME(type) case MSG_##type##: \
35 { if(!net_name || (net_name > NOTIF_##type##_COUNT)) \
36 { checkargs = sprintf("Improper name: %d!", net_name); } break; }
39 CHECKARG_TYPENAME(INFO)
40 CHECKARG_TYPENAME(CENTER)
41 CHECKARG_TYPENAME(MULTI)
42 default: { checkargs = sprintf("Improper type: %d!", checkargs, net_type); break; }
44 #undef CHECKARG_TYPENAME
49 string Notification_CheckArgs(
50 float broadcast, entity client,
51 float net_type, float net_name)
53 // check supplied broadcast, target, type, and name for errors
54 string checkargs = Notification_CheckArgs_TypeName(net_type, net_name);
55 if(checkargs != "") { checkargs = strcat(checkargs, " "); }
61 if(IS_NOT_A_CLIENT(client))
62 { checkargs = sprintf("%sNo client provided!", checkargs); }
66 case NOTIF_ANY_EXCEPT:
68 if(IS_NOT_A_CLIENT(client))
69 { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
76 { checkargs = sprintf("%sEntity provided when world was required!", checkargs); }
81 case NOTIF_TEAM_EXCEPT:
83 if not(teamplay) { checkargs = sprintf("%sTeamplay not active!", checkargs); }
84 else if(IS_NOT_A_CLIENT(client))
86 if(broadcast == NOTIF_TEAM) { checkargs = sprintf("%sNo client provided!", checkargs); }
87 else { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
92 default: { checkargs = sprintf("%sImproper broadcast: %d!", checkargs, broadcast); break; }
98 // ===============================
99 // Initialization Core Functions
100 // ===============================
102 string Process_Notif_Line(
113 if((chat && autocvar_notification_allow_chatboxprint)
114 || (autocvar_notification_allow_chatboxprint == 2))
116 // pass 1: add ETX char at beginning of line
117 input = strcat("\{3}", input);
119 // pass 2: add ETX char at end of each new line (so that
120 // messages with multiple lines are put through chatbox too)
121 input = strreplace("\n", "\n\{3}", input);
123 // pass 3: strip trailing ETX char
124 if(substring(input, (strlen(input) - 1), 1) == "\{3}")
125 { input = substring(input, 0, (strlen(input) - 1)); }
128 if(substring(input, (strlen(input) - 1), 1) != "\n")
132 "^1MISSING/BROKEN NEW LINE AT END OF NOTIFICATION: ",
133 "^7net_type = %s, net_name = %s, string = %s.\n"
140 return strcat(input, "\n");
146 string Process_Notif_Args(
152 string selected, remaining = args;
155 for(;(remaining != "");)
157 selected = car(remaining); remaining = cdr(remaining);
161 case 1: // normal args
163 if(sel_num == NOTIF_MAX_ARGS)
167 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
168 "^7net_type = %s, net_name = %s, max args = %d.\n"
178 switch(strtolower(selected))
180 #define ARG_CASE(prog,selected,result) case selected: { ++sel_num; break; }
187 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
188 "^7net_type = %s, net_name = %s, args arg = '%s'.\n"
202 if(sel_num == NOTIF_MAX_HUDARGS)
206 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
207 "^7net_type = %s, net_name = %s, max hudargs = %d.\n"
217 switch(strtolower(selected))
219 #define ARG_CASE(prog,selected,result) \
220 #if (prog == ARG_CS_SV_HA) \
221 case selected: { ++sel_num; break; } \
229 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
230 "^7net_type = %s, net_name = %s, hudargs arg = '%s'.\n"
244 if(sel_num == NOTIF_MAX_DURCNT)
248 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
249 "^7net_type = %s, net_name = %s, max durcnt = %d.\n"
259 switch(strtolower(selected))
261 #define ARG_CASE(prog,selected,result) \
262 #if (prog == ARG_CS_SV_DC) || (prog == ARG_DC) \
263 case selected: { ++sel_num; break; } \
269 if(ftos(stof(selected)) != "") { ++sel_num; }
274 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
275 "^7net_type = %s, net_name = %s, durcnt arg = '%s'.\n"
293 void Create_Notification_Entity(
313 // =====================
314 // Global Entity Setup
315 // =====================
316 entity notif = spawn();
317 string typestring = "";
322 typestring = "MSG_INFO";
323 msg_info_notifs[nameid - 1] = notif;
324 notif.classname = "msg_info_notification";
329 typestring = "MSG_CENTER";
330 msg_center_notifs[nameid - 1] = notif;
331 notif.classname = "msg_center_notification";
336 typestring = "MSG_MULTI";
337 msg_multi_notifs[nameid - 1] = notif;
338 notif.classname = "MSG_MULTI_notification";
346 "^1NOTIFICATION WITH IMPROPER TYPE: ",
347 "^7net_type = %d, net_name = %s.\n"
352 return; // It's not possible to recover from this one
355 notif.nent_default = var_default;
356 notif.nent_name = strzone(namestring);
357 notif.nent_id = nameid;
358 notif.nent_enabled = (1 <= var_cvar);
360 // Other pre-notif-setup requisites
363 // ====================
364 // Notification Setup
365 // ====================
368 // Set MSG_MULTI string/float counts
369 if((infoname == NO_MSG) && (centername == NO_MSG))
373 "^1NOTIFICATION WITH NO SUBCALLS: ",
374 "^7net_type = %s, net_name = %s.\n"
383 float infoname_stringcount = 0, infoname_floatcount = 0;
384 float centername_stringcount = 0, centername_floatcount = 0;
386 if(infoname != NO_MSG)
388 notif.nent_msginfo = msg_info_notifs[infoname - 1];
389 infoname_stringcount = notif.nent_msginfo.nent_stringcount;
390 infoname_floatcount = notif.nent_msginfo.nent_floatcount;
393 if(centername != NO_MSG)
395 notif.nent_msgcenter = msg_center_notifs[centername - 1];
396 centername_stringcount = notif.nent_msgcenter.nent_stringcount;
397 centername_floatcount = notif.nent_msgcenter.nent_floatcount;
400 // set the requirements of THIS notification to the totals of its subcalls
401 notif.nent_stringcount = max(infoname_stringcount, centername_stringcount);
402 notif.nent_floatcount = max(infoname_floatcount, centername_floatcount);
407 // Set MSG_INFO and MSG_CENTER string/float counts
408 notif.nent_stringcount = strnum;
409 notif.nent_floatcount = flnum;
411 // Only initialize arguments if we're either a client or on a dedicated server
413 float should_process_args = server_is_dedicated;
415 float should_process_args = TRUE;
418 if(should_process_args)
420 // ========================
421 // Process Main Arguments
422 // ========================
427 notif.nent_args = strzone(
428 Process_Notif_Args(1, args, typestring, namestring));
430 else if((hudargs == "") && (durcnt ==""))
434 "^1NOTIFICATION HAS ARG COUNTS BUT NO ARGS OR HUDARGS OR DURCNT: ",
435 "^7net_type = %s, net_name = %s, strnum = %d, flnum = %d\n"
447 notif.nent_args = strzone(
448 Process_Notif_Args(1, args, typestring, namestring));
452 // =======================================
453 // Process HUD and Centerprint Arguments
454 // Only processed on CSQC, as these
455 // args are only for HUD features.
456 // =======================================
460 notif.nent_hudargs = strzone(
461 Process_Notif_Args(2, hudargs, typestring, namestring));
463 if(icon != "") { notif.nent_icon = strzone(icon); }
468 "^1NOTIFICATION HAS HUDARGS BUT NO ICON: ",
469 "^7net_type = %s, net_name = %s.\n"
481 "^1NOTIFICATION HAS ICON BUT NO HUDARGS: ",
482 "^7net_type = %s, net_name = %s.\n"
492 notif.nent_durcnt = strzone(
493 Process_Notif_Args(3, durcnt, typestring, namestring));
495 if(cpid != NO_MSG) { notif.nent_cpid = cpid; }
500 "^1NOTIFICATION HAS DURCNT BUT NO CPID: ",
501 "^7net_type = %s, net_name = %s.\n"
509 else if(cpid != NO_MSG) { notif.nent_cpid = cpid; }
513 // ======================
514 // Process Notif String
515 // ======================
516 #define SET_NOTIF_STRING(string,stringname) \
517 notif.nent_string = strzone(CCR( \
518 Process_Notif_Line( \
530 if(gentle != "") { SET_NOTIF_STRING(gentle, "GENTLE") }
531 else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL") }
533 else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL") }
535 #undef SET_NOTIF_STRING
537 // Check to make sure a string was chosen
538 if(notif.nent_string == "")
542 "^1EMPTY NOTIFICATION: ",
543 "^7net_type = %s, net_name = %s.\n"
553 // now check to see if any errors happened
556 notif.nent_enabled = FALSE; // disable the notification so it can't cause trouble
557 notif_global_error = TRUE; // throw the red flag that an error happened on init
561 void Destroy_Notification_Entity(entity notif)
563 if(notif.nent_name != "") { strunzone(notif.nent_name); }
564 if(notif.nent_args != "") { strunzone(notif.nent_args); }
565 if(notif.nent_hudargs != "") { strunzone(notif.nent_hudargs); }
566 if(notif.nent_icon != "") { strunzone(notif.nent_icon); }
567 if(notif.nent_durcnt != "") { strunzone(notif.nent_durcnt); }
568 if(notif.nent_string != "") { strunzone(notif.nent_string); }
572 void Destroy_All_Notifications(void)
576 #define DESTROY_LOOP(type,count) \
577 for(i = 1; i <= count; ++i) \
579 notif = Get_Notif_Ent(type, i); \
580 if not(notif) { backtrace("Destroy_All_Notifications(): Missing notification entity!\n"); return; } \
581 Destroy_Notification_Entity(notif); \
584 // kill all networked notifications
586 Kill_Notification(NOTIF_ANY, world, 0, 0);
589 // kill all real notification entities
590 DESTROY_LOOP(MSG_INFO, NOTIF_INFO_COUNT)
591 DESTROY_LOOP(MSG_CENTER, NOTIF_CENTER_COUNT)
592 DESTROY_LOOP(MSG_MULTI, NOTIF_MULTI_COUNT)
597 // =========================================
598 // Cvar Handling With 'dumpnotifs' Command
599 // =========================================
601 void Dump_Notifications(float fh, float alsoprint)
603 #define NOTIF_WRITE(a) { \
605 if(alsoprint) { print(a); } }
606 #define NOTIF_WRITE_ENTITY(name,default,description) { \
609 "seta notification_%s \"%d\" \"%s\"\n", \
610 name, default, description \
612 NOTIF_WRITE(notif_msg) }
613 #define NOTIF_WRITE_HARDCODED(cvar,default,description) { \
616 "seta notification_%s \"%s\" \"%s\"\n", \
617 cvar, default, description \
619 NOTIF_WRITE(notif_msg) }
625 // Note: This warning only applies to the notifications.cfg file that is output...
627 // You ARE supposed to manually edit this function to add i.e. hard coded
628 // notification variables for mutators or game modes or such and then
629 // regenerate the notifications.cfg file from the new code.
631 NOTIF_WRITE("// ********************************************** //\n");
632 NOTIF_WRITE("// ** WARNING - DO NOT MANUALLY EDIT THIS FILE ** //\n");
633 NOTIF_WRITE("// ** ** //\n");
634 NOTIF_WRITE("// ** This file is automatically generated ** //\n");
635 NOTIF_WRITE("// ** by code with the command 'dumpnotifs'. ** //\n");
636 NOTIF_WRITE("// ** ** //\n");
637 NOTIF_WRITE("// ** If you add a new notification, please ** //\n");
638 NOTIF_WRITE("// ** regenerate this file with that command ** //\n");
639 NOTIF_WRITE("// ** making sure that the output matches ** //\n");
640 NOTIF_WRITE("// ** with the lists and defaults in code. ** //\n");
641 NOTIF_WRITE("// ** ** //\n");
642 NOTIF_WRITE("// ********************************************** //\n");
644 // These notifications will also append their string as a comment...
645 // This is not necessary, and does not matter if they vary between config versions,
646 // it is just a semi-helpful tool for those who want to manually change their user settings.
648 NOTIF_WRITE(sprintf("\n// MSG_INFO notifications (count = %d):\n", NOTIF_INFO_COUNT));
649 for(i = 1; i <= NOTIF_INFO_COUNT; ++i)
651 e = Get_Notif_Ent(MSG_INFO, i);
652 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
653 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)");
656 NOTIF_WRITE(sprintf("\n// MSG_CENTER notifications (count = %d):\n", NOTIF_CENTER_COUNT));
657 for(i = 1; i <= NOTIF_CENTER_COUNT; ++i)
659 e = Get_Notif_Ent(MSG_CENTER, i);
660 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
661 NOTIF_WRITE_ENTITY(e.nent_name, e.nent_default, "Notification control cvar: 0 = off, 1 = centerprint");
664 NOTIF_WRITE(sprintf("\n// MSG_MULTI notifications (count = %d):\n", NOTIF_MULTI_COUNT));
665 for(i = 1; i <= NOTIF_MULTI_COUNT; ++i)
667 e = Get_Notif_Ent(MSG_MULTI, i);
668 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
669 NOTIF_WRITE_ENTITY(e.nent_name, e.nent_default, "Notification control cvar: 0 = off, 1 = trigger subcalls");
672 // edit these to match whichever cvars are used for specific notification options
673 NOTIF_WRITE("\n// HARD CODED notification variables:\n");
674 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)");
675 NOTIF_WRITE_HARDCODED("show_location", "0", "Append location information to MSG_INFO death/kill messages");
676 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)'");
677 NOTIF_WRITE_HARDCODED("show_sprees", "1", "Print information about sprees in death/kill messages");
678 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");
679 NOTIF_WRITE_HARDCODED("show_sprees_center_specialonly", "1", "Don't show spree information in MSG_CENTER messages if it isn't an achievement");
680 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");
681 NOTIF_WRITE_HARDCODED("show_sprees_info_newline", "0", "Show attacker spree information for MSG_INFO messages on a separate line than the death notification itself");
682 NOTIF_WRITE_HARDCODED("show_sprees_info_specialonly", "1", "Don't show attacker spree information in MSG_INFO messages if it isn't an achievement");
683 NOTIF_WRITE_HARDCODED("item_centerprinttime", "1.5", "How long to show item information centerprint messages (like 'You got the Electro' or such)");
684 NOTIF_WRITE_HARDCODED("errors_are_fatal", "1", "If a notification fails upon initialization, cause a Host_Error to stop the program");
685 NOTIF_WRITE_HARDCODED("ctf_pickup_team_verbose", "0", "Show extra information if a team mate picks up a flag");
686 NOTIF_WRITE_HARDCODED("ctf_pickup_enemy_verbose", "0", "Show extra information if an enemy picks up a flag");
687 NOTIF_WRITE_HARDCODED("ctf_capture_verbose", "0", "Show extra information when someone captures a flag");
688 NOTIF_WRITE_HARDCODED("frag_verbose", "1", "Show extra information when you frag someone (or when you are fragged");
689 NOTIF_WRITE_HARDCODED("lifetime_runtime", "0.5", "Amount of time that notification entities last on the server during runtime (In seconds)");
690 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)");
694 "\n// Notification counts (total = %d): ",
695 "MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d\n"
708 #undef NOTIF_WRITE_HARDCODED
709 #undef NOTIF_WRITE_ENTITY
714 void Notification_GetCvars()
716 GetCvars_handleFloat(get_cvars_s, get_cvars_f, FRAG_VERBOSE, "notification_frag_verbose");
721 // ===============================
722 // Frontend Notification Pushing
723 // ===============================
725 string Local_Notification_sprintf(
726 string input, string args,
727 string s1, string s2, string s3, string s4,
728 float f1, float f2, float f3, float f4)
730 #ifdef NOTIFICATIONS_DEBUG
732 "Local_Notification_sprintf('%s^7', '%s', %s, %s);\n",
733 strreplace("\n", "\\n", input),
735 strreplace("\n", "\\n", sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
736 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
742 for(sel_num = 0; sel_num < NOTIF_MAX_ARGS; ++sel_num) { arg_slot[sel_num] = ""; }
746 for(sel_num = 0;(args != "");)
748 selected = car(args); args = cdr(args);
749 NOTIF_HIT_MAX(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
750 switch(strtolower(selected))
752 #define ARG_CASE(prog,selected,result) \
754 #if (prog != ARG_SV) && (prog != ARG_DC) \
755 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
758 #if (prog != ARG_CS) && (prog != ARG_DC) \
759 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
764 default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
767 return sprintf(input, arg_slot[0], arg_slot[1], arg_slot[2], arg_slot[3], arg_slot[4], arg_slot[5], arg_slot[6]);
771 void Local_Notification_HUD_Notify_Push(
772 string icon, string hudargs,
773 string s1, string s2, string s3, string s4)
777 arg_slot[0] = ""; arg_slot[1] = "";
779 for(sel_num = 0;(hudargs != "");)
781 selected = car(hudargs); hudargs = cdr(hudargs);
782 NOTIF_HIT_MAX(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
783 switch(strtolower(selected))
785 #define ARG_CASE(prog,selected,result) \
786 #if (prog == ARG_CS_SV_HA) \
787 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
791 default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
794 #ifdef NOTIFICATIONS_DEBUG
796 "Local_Notification_HUD_Notify_Push('%s^7', '%s', %s, %s);\n",
799 strreplace("\n", "\\n", sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
800 strreplace("\n", "\\n", sprintf("'%s^7', '%s^7'", stof(arg_slot[0]), stof(arg_slot[1])))
803 HUD_Notify_Push(icon, arg_slot[0], arg_slot[1]);
806 void Local_Notification_centerprint_generic(
807 string input, string durcnt,
808 float cpid, float f1, float f2)
812 arg_slot[0] = ""; arg_slot[1] = "";
814 for(sel_num = 0;(durcnt != "");)
816 selected = car(durcnt); durcnt = cdr(durcnt);
817 NOTIF_HIT_MAX(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic")
818 switch(strtolower(selected))
820 #define ARG_CASE(prog,selected,result) \
821 #if (prog == ARG_CS_SV_DC) || (prog == ARG_DC) \
822 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
828 if(ftos(stof(selected)) != "") { arg_slot[sel_num] = selected; ++sel_num; }
829 else { NOTIF_HIT_UNKNOWN(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic") }
834 #ifdef NOTIFICATIONS_DEBUG
836 "Local_Notification_centerprint_generic('%s^7', '%s', %d, %d, %d, %d);\n",
837 strreplace("\n", "\\n", input),
840 stof(arg_slot[0]), stof(arg_slot[1])
843 centerprint_generic(cpid, input, stof(arg_slot[0]), stof(arg_slot[1]));
847 void Local_Notification(float net_type, float net_name, ...count)
849 // check supplied type and name for errors
850 string checkargs = Notification_CheckArgs_TypeName(net_type, net_name);
851 if(checkargs != "") { backtrace(sprintf("Incorrect usage of Local_Notification: %s\n", checkargs)); return; }
853 entity notif = Get_Notif_Ent(net_type, net_name);
854 if not(notif) { backtrace("Local_Notification: Could not find notification entity!\n"); return; }
856 #ifdef NOTIFICATIONS_DEBUG
857 if not(notif.nent_enabled)
860 "Local_Notification(%s, %s): Entity was disabled...\n",
861 Get_Notif_TypeName(net_type),
868 if((notif.nent_stringcount + notif.nent_floatcount) > count)
872 "Not enough arguments for Local_Notification(%s, %s, ...)! ",
873 "stringcount(%d) + floatcount(%d) > count(%d)\n",
874 "Check the definition and function call for accuracy...?\n"
876 Get_Notif_TypeName(net_type), notif.nent_name,
877 notif.nent_stringcount, notif.nent_floatcount, count
881 else if((notif.nent_stringcount + notif.nent_floatcount) < count)
885 "Too many arguments for Local_Notification(%s, %s, ...)! ",
886 "stringcount(%d) + floatcount(%d) < count(%d)\n",
887 "Check the definition and function call for accuracy...?\n"
889 Get_Notif_TypeName(net_type), notif.nent_name,
890 notif.nent_stringcount, notif.nent_floatcount, count
895 string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
896 string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
897 string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
898 string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
899 float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
900 float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
901 float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
902 float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
904 #ifdef NOTIFICATIONS_DEBUG
906 "Local_Notification(%s, %s, %s, %s);\n",
907 Get_Notif_TypeName(net_type),
909 strreplace("\n", "\\n", sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
910 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
919 Local_Notification_sprintf(
926 if(notif.nent_icon != "")
928 Local_Notification_HUD_Notify_Push(
940 Local_Notification_centerprint_generic(
941 Local_Notification_sprintf(
955 if(notif.nent_msginfo)
956 if(notif.nent_msginfo.nent_enabled)
958 Local_Notification_WOVA(
960 notif.nent_msginfo.nent_id,
961 notif.nent_msginfo.nent_stringcount,
962 notif.nent_msginfo.nent_floatcount,
967 if(notif.nent_msgcenter)
968 if(notif.nent_msgcenter.nent_enabled)
970 Local_Notification_WOVA(
972 notif.nent_msgcenter.nent_id,
973 notif.nent_msgcenter.nent_stringcount,
974 notif.nent_msgcenter.nent_floatcount,
984 // WOVA = Without Variable Arguments
985 void Local_Notification_WOVA(
986 float net_type, float net_name,
987 float stringcount, float floatcount,
988 string s1, string s2, string s3, string s4,
989 float f1, float f2, float f3, float f4)
991 #define VARITEM(stringc,floatc,args) \
992 if((stringcount == stringc) && (floatcount == floatc)) \
993 { Local_Notification(net_type, net_name, args); return; }
994 EIGHT_VARS_TO_VARARGS_VARLIST
996 Local_Notification(net_type, net_name); // some notifications don't have any arguments at all
1000 // =========================
1001 // Notification Networking
1002 // =========================
1005 void Read_Notification(float is_new)
1007 float net_type = ReadByte();
1008 float net_name = ReadShort();
1012 if(net_type == MSG_CENTER_KILL)
1016 if(net_name == 0) { reset_centerprint_messages(); }
1019 notif = Get_Notif_Ent(MSG_CENTER, net_name);
1020 if not(notif) { backtrace("Read_Notification: Could not find notification entity!\n"); return; }
1021 centerprint_generic(notif.nent_cpid, "", 0, 0);
1027 notif = Get_Notif_Ent(net_type, net_name);
1028 if not(notif) { backtrace("Read_Notification: Could not find notification entity!\n"); return; }
1030 #ifdef NOTIFICATIONS_DEBUG
1032 "Read_Notification(%d) at %f: net_type = %s, net_name = %s\n",
1035 Get_Notif_TypeName(net_type),
1040 string s1 = ((0 < notif.nent_stringcount) ? ReadString() : "");
1041 string s2 = ((1 < notif.nent_stringcount) ? ReadString() : "");
1042 string s3 = ((2 < notif.nent_stringcount) ? ReadString() : "");
1043 string s4 = ((3 < notif.nent_stringcount) ? ReadString() : "");
1044 float f1 = ((0 < notif.nent_floatcount) ? ReadLong() : 0);
1045 float f2 = ((1 < notif.nent_floatcount) ? ReadLong() : 0);
1046 float f3 = ((2 < notif.nent_floatcount) ? ReadLong() : 0);
1047 float f4 = ((3 < notif.nent_floatcount) ? ReadLong() : 0);
1051 Local_Notification_WOVA(
1053 notif.nent_stringcount,
1054 notif.nent_floatcount,
1063 void Net_Notification_Remove()
1065 #ifdef NOTIFICATIONS_DEBUG
1066 if not(self) { dprint(sprintf("Net_Notification_Remove() at %f: Missing self!?\n", time)); return; }
1067 if(self.nent_net_name == -1)
1070 "Net_Notification_Remove() at %f: Killed '%s' notification\n",
1072 Get_Notif_TypeName(self.nent_net_type)
1078 string checkargs = Notification_CheckArgs_TypeName(self.nent_net_type, self.nent_net_name);
1079 if(checkargs != "") { dprint(sprintf("Incorrect usage of Net_Notification_Remove() at %f: %s\n", time, checkargs)); return; }
1081 #ifdef NOTIFICATIONS_DEBUG
1082 entity realent = Get_Notif_Ent(self.nent_net_type, self.nent_net_name);
1084 "Net_Notification_Remove() at %f: Removed '%s - %s' notification\n",
1086 Get_Notif_TypeName(self.nent_net_type),
1093 for(i = 0; i < 4; ++i) { if(self.nent_strings[i]) { strunzone(self.nent_strings[i]); } }
1097 float Net_Write_Notification(entity client, float sf)
1099 float i, send = FALSE;
1101 switch(self.nent_broadcast)
1103 case NOTIF_ONE: // send to one client and their spectator
1106 (client == self.nent_client)
1109 (client.classname == STR_SPECTATOR)
1111 (client.enemy == self.nent_client)
1116 case NOTIF_ONE_ONLY: // send ONLY to one client
1118 if(client == self.nent_client) { send = TRUE; }
1121 case NOTIF_TEAM: // send only to X team and their spectators
1124 (client.team == self.nent_client.team)
1127 (client.classname == STR_SPECTATOR)
1129 (client.enemy.team == self.nent_client.team)
1134 case NOTIF_TEAM_EXCEPT: // send only to X team and their spectators, except for Y person and their spectators
1137 (client != self.nent_client)
1140 (client.team == self.nent_client.team)
1143 (client.classname == STR_SPECTATOR)
1146 (client.enemy != self.nent_client)
1148 (client.enemy.team == self.nent_client.team)
1155 case NOTIF_ANY: // send to everyone
1160 case NOTIF_ANY_EXCEPT: // send to everyone except X person and their spectators
1163 (client != self.nent_client)
1166 (client.classname == STR_SPECTATOR)
1168 (client.enemy == self.nent_client)
1173 default: { send = FALSE; break; }
1178 WriteByte(MSG_ENTITY, ENT_CLIENT_NOTIFICATION);
1179 WriteByte(MSG_ENTITY, self.nent_net_type);
1180 WriteShort(MSG_ENTITY, self.nent_net_name);
1181 for(i = 0; i < self.nent_stringcount; ++i) { WriteString(MSG_ENTITY, self.nent_strings[i]); }
1182 for(i = 0; i < self.nent_floatcount; ++i) { WriteLong(MSG_ENTITY, self.nent_floats[i]); }
1188 void Kill_Notification(
1189 float broadcast, entity client,
1190 float net_type, float net_name)
1192 string checkargs = Notification_CheckArgs(broadcast, client, 1, 1);
1193 if(checkargs != "") { backtrace(sprintf("Incorrect usage of Kill_Notification: %s\n", checkargs)); return; }
1195 #ifdef NOTIFICATIONS_DEBUG
1197 "Kill_Notification(%d, '%s', %d, %d);\n",
1205 entity notif, net_notif;
1207 // if no name is provided, just kill ALL the centerprint notifications
1208 if(net_type == MSG_CENTER)
1210 net_notif = spawn();
1211 net_notif.classname = "net_kill_notification";
1212 net_notif.nent_broadcast = broadcast;
1213 net_notif.nent_client = client;
1214 net_notif.nent_net_type = MSG_CENTER_KILL;
1215 net_notif.nent_net_name = net_name;
1216 Net_LinkEntity(net_notif, FALSE, autocvar_notification_lifetime_runtime, Net_Write_Notification);
1219 for(notif = world; (notif = find(notif, classname, "net_notification"));)
1221 // now kill the old send notification entity
1224 if(notif.nent_net_type == net_type)
1228 if(notif.nent_net_name == net_name) { notif.nent_net_name = -1; notif.think(); }
1229 else { continue; } // we ARE looking for a certain net_name, don't kill everything else too
1231 else { notif.nent_net_name = -1; notif.think(); }
1233 else { continue; } // we ARE looking for a certain net_type, don't kill everything else too
1235 else { notif.nent_net_name = -1; notif.think(); }
1239 void Send_Notification(
1240 float broadcast, entity client,
1241 float net_type, float net_name,
1244 // check supplied broadcast, target, type, and name for errors
1245 string checkargs = Notification_CheckArgs(broadcast, client, net_type, net_name);
1246 if(checkargs != "") { backtrace(sprintf("Incorrect usage of Send_Notification: %s\n", checkargs)); return; }
1248 // retreive counts for the arguments of this notification
1249 entity notif = Get_Notif_Ent(net_type, net_name);
1250 if not(notif) { backtrace("Send_Notification: Could not find notification entity!\n"); return; }
1252 if((notif.nent_stringcount + notif.nent_floatcount) > count)
1256 "Not enough arguments for Send_Notification(%d, %s, %s, ...)! ",
1257 "stringcount(%d) + floatcount(%d) > count(%d)\n",
1258 "Check the definition and function call for accuracy...?\n"
1260 broadcast, Get_Notif_TypeName(net_type), notif.nent_name,
1261 notif.nent_stringcount, notif.nent_floatcount, count
1265 else if((notif.nent_stringcount + notif.nent_floatcount) < count)
1269 "Too many arguments for Send_Notification(%d, %s, %s, ...)! ",
1270 "stringcount(%d) + floatcount(%d) < count(%d)\n",
1271 "Check the definition and function call for accuracy...?\n"
1273 broadcast, Get_Notif_TypeName(net_type), notif.nent_name,
1274 notif.nent_stringcount, notif.nent_floatcount, count
1279 #ifdef NOTIFICATIONS_DEBUG
1280 string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
1281 string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
1282 string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
1283 string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
1284 float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
1285 float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
1286 float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
1287 float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
1289 "Send_Notification(%d, %s, %s, %s, %s);\n",
1291 Get_Notif_TypeName(net_type),
1293 strreplace("\n", "\\n", sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1294 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1298 entity net_notif = spawn();
1299 net_notif.classname = "net_notification";
1300 net_notif.nent_broadcast = broadcast;
1301 net_notif.nent_client = client;
1302 net_notif.nent_net_type = net_type;
1303 net_notif.nent_net_name = net_name;
1304 net_notif.nent_stringcount = notif.nent_stringcount;
1305 net_notif.nent_floatcount = notif.nent_floatcount;
1308 for(i = 0; i < net_notif.nent_stringcount; ++i) { net_notif.nent_strings[i] = strzone(...(i, string)); }
1309 for(i = 0; i < net_notif.nent_floatcount; ++i) { net_notif.nent_floats[i] = ...((net_notif.nent_stringcount + i), float); }
1311 net_notif.think = Net_Notification_Remove;
1312 net_notif.nextthink =
1313 ((time > autocvar_notification_lifetime_mapload)
1315 (time + autocvar_notification_lifetime_runtime)
1317 autocvar_notification_lifetime_mapload
1320 Net_LinkEntity(net_notif, FALSE, 0, Net_Write_Notification);
1322 if(server_is_dedicated && (broadcast == NOTIF_ANY || broadcast == NOTIF_ANY_EXCEPT) && (net_type != MSG_CENTER))
1324 Local_Notification_WOVA(
1326 notif.nent_stringcount,
1327 notif.nent_floatcount,
1328 IFSTR(0), IFSTR(1), IFSTR(2), IFSTR(3),
1329 IFFL(0), IFFL(1), IFFL(2), IFFL(3));
1333 // WOVA = Without Variable Arguments
1334 void Send_Notification_WOVA(
1335 float broadcast, entity client,
1336 float net_type, float net_name,
1337 string s1, string s2, string s3, string s4,
1338 float f1, float f2, float f3, float f4)
1340 entity notif = Get_Notif_Ent(net_type, net_name);
1342 #ifdef NOTIFICATIONS_DEBUG
1344 "Send_Notification_WOVA(%d, %s, %s, %s, %s - %d %d);\n",
1346 Get_Notif_TypeName(net_type),
1348 sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4),
1349 sprintf("%d, %d, %d, %d", f1, f2, f3, f4),
1350 notif.nent_stringcount, notif.nent_floatcount
1354 #define VARITEM(stringc,floatc,args) \
1355 if((notif.nent_stringcount == stringc) && (notif.nent_floatcount == floatc)) \
1356 { Send_Notification(broadcast, client, net_type, net_name, args); return; }
1357 EIGHT_VARS_TO_VARARGS_VARLIST
1359 Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
1363 // =============================
1364 // LEGACY NOTIFICATION SYSTEMS
1365 // =============================
1367 void Send_CSQC_Centerprint_Generic(entity e, float id, string s, float duration, float countdown_num)
1369 if ((clienttype(e) == CLIENTTYPE_REAL) && (e.flags & FL_CLIENT))
1372 WRITESPECTATABLE_MSG_ONE({
1373 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1374 WriteByte(MSG_ONE, TE_CSQC_CENTERPRINT_GENERIC);
1375 WriteByte(MSG_ONE, id);
1376 WriteString(MSG_ONE, s);
1377 if (id != 0 && s != "")
1379 WriteByte(MSG_ONE, duration);
1380 WriteByte(MSG_ONE, countdown_num);
1385 #endif // ifdef SVQC