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_WEAPON: return "MSG_WEAPON";
13 case MSG_DEATH: return "MSG_DEATH";
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_WEAPON: return msg_weapon_notifs[net_name - 1];
26 case MSG_DEATH: return msg_death_notifs[net_name - 1];
28 backtrace(sprintf("Get_Notif_Ent(%d, %d): Improper net type!\n", net_type, net_name));
32 string Notification_CheckArgs_TypeName(float net_type, float net_name)
34 // check supplied type and name for errors
35 string checkargs = "";
36 #define CHECKARG_TYPENAME(type) case MSG_##type##: \
37 { if(!net_name || (net_name > NOTIF_##type##_COUNT)) \
38 { checkargs = sprintf("Improper name: %d!", net_name); } break; }
41 CHECKARG_TYPENAME(INFO)
42 CHECKARG_TYPENAME(CENTER)
43 CHECKARG_TYPENAME(WEAPON)
44 CHECKARG_TYPENAME(DEATH)
45 default: { checkargs = sprintf("Improper type: %d!", checkargs, net_type); break; }
47 #undef CHECKARG_TYPENAME
52 string Notification_CheckArgs(float broadcast, entity client, 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_ANY_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 string Process_Notif_Line(
114 if((chat && autocvar_notification_allow_chatboxprint)
115 || (autocvar_notification_allow_chatboxprint == 2))
117 // pass 1: add ETX char at beginning of line
118 input = strcat("\{3}", input);
120 // pass 2: add ETX char at end of each new line (so that
121 // messages with multiple lines are put through chatbox too)
122 input = strreplace("\n", "\n\{3}", input);
124 // pass 3: strip trailing ETX char
125 if(substring(input, (strlen(input) - 1), 1) == "\{3}")
126 { input = substring(input, 0, (strlen(input) - 1)); }
129 if(substring(input, (strlen(input) - 1), 1) != "\n")
133 "^1MISSING/BROKEN NEW LINE AT END OF NOTIFICATION: ",
134 "^7net_type = MSG_%s, net_name = %s, string = %s.\n"
141 return strcat(input, "\n");
147 string Process_Notif_Args(
153 string selected, remaining = args;
156 for(;(remaining != "");)
158 selected = car(remaining); remaining = cdr(remaining);
162 case 1: // normal args
164 if(sel_num == NOTIF_MAX_ARGS)
168 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
169 "^7net_type = MSG_%s, net_name = %s, max args = %d.\n"
179 switch(strtolower(selected))
181 #define ARG_CASE(prog,selected,result) case selected: { ++sel_num; break; }
188 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
189 "^7net_type = MSG_%s, net_name = %s, args arg = '%s'.\n"
203 if(sel_num == NOTIF_MAX_HUDARGS)
207 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
208 "^7net_type = MSG_%s, net_name = %s, max hudargs = %d.\n"
218 switch(strtolower(selected))
220 #define ARG_CASE(prog,selected,result) \
221 #if (prog == ARG_CS_SV_HA) \
222 case selected: { ++sel_num; break; } \
230 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
231 "^7net_type = MSG_%s, net_name = %s, hudargs arg = '%s'.\n"
245 if(sel_num == NOTIF_MAX_DURCNT)
249 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
250 "^7net_type = MSG_%s, net_name = %s, max durcnt = %d.\n"
260 switch(strtolower(selected))
262 #define ARG_CASE(prog,selected,result) \
263 #if (prog == ARG_CS_SV_DC) || (prog == ARG_DC) \
264 case selected: { ++sel_num; break; } \
270 if(ftos(stof(selected)) != "") { ++sel_num; }
275 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
276 "^7net_type = MSG_%s, net_name = %s, durcnt arg = '%s'.\n"
294 void Create_Notification_Entity(
314 // =====================
315 // Global Entity Setup
316 // =====================
317 entity notif = spawn();
318 string typestring = "";
323 typestring = "MSG_INFO";
324 msg_info_notifs[nameid - 1] = notif;
325 notif.classname = "msg_info_notification";
330 typestring = "MSG_CENTER";
331 msg_center_notifs[nameid - 1] = notif;
332 notif.classname = "msg_center_notification";
337 typestring = "MSG_WEAPON";
338 msg_weapon_notifs[nameid - 1] = notif;
339 notif.classname = "msg_weapon_notification";
344 typestring = "MSG_DEATH";
345 msg_death_notifs[nameid - 1] = notif;
346 notif.classname = "msg_death_notification";
353 "^1NOTIFICATION WITH IMPROPER TYPE: ",
354 "^7net_type = %d, net_name = %s.\n"
359 return; // It's not possible to recover from this one
362 notif.nent_default = var_default;
363 notif.nent_name = strzone(namestring);
364 notif.nent_id = nameid;
365 notif.nent_enabled = (1 <= var_cvar);
367 // Other pre-notif-setup requisites
370 // ====================
371 // Notification Setup
372 // ====================
375 // Set MSG_WEAPON and MSG_DEATH string/float counts
376 if((infoname == NO_MSG) && (centername == NO_MSG))
380 "^1NOTIFICATION WITH NO SUBCALLS: ",
381 "^7net_type = %s, net_name = %s.\n"
390 float infoname_stringcount = 0, infoname_floatcount = 0;
391 float centername_stringcount = 0, centername_floatcount = 0;
393 if(infoname != NO_MSG)
395 notif.nent_msginfo = msg_info_notifs[infoname - 1];
396 infoname_stringcount = notif.nent_msginfo.nent_stringcount;
397 infoname_floatcount = notif.nent_msginfo.nent_floatcount;
400 if(centername != NO_MSG)
402 notif.nent_msgcenter = msg_center_notifs[centername - 1];
403 centername_stringcount = notif.nent_msgcenter.nent_stringcount;
404 centername_floatcount = notif.nent_msgcenter.nent_floatcount;
407 // set the requirements of THIS notification to the totals of its subcalls
408 notif.nent_stringcount = max(infoname_stringcount, centername_stringcount);
409 notif.nent_floatcount = max(infoname_floatcount, centername_floatcount);
414 // Set MSG_INFO and MSG_CENTER string/float counts
415 notif.nent_stringcount = strnum;
416 notif.nent_floatcount = flnum;
418 // Only initialize arguments if we're either a client or on a dedicated server
420 float should_process_args = server_is_dedicated;
422 float should_process_args = TRUE;
425 if(should_process_args)
427 // ========================
428 // Process Main Arguments
429 // ========================
434 notif.nent_args = strzone(
435 Process_Notif_Args(1, args, typestring, namestring));
437 else if((hudargs == "") && (durcnt ==""))
441 "^1NOTIFICATION HAS ARG COUNTS BUT NO ARGS OR HUDARGS OR DURCNT: ",
442 "^7net_type = %s, net_name = %s, strnum = %d, flnum = %d\n"
454 notif.nent_args = strzone(
455 Process_Notif_Args(1, args, typestring, namestring));
459 // =======================================
460 // Process HUD and Centerprint Arguments
461 // Only processed on CSQC, as these
462 // args are only for HUD features.
463 // =======================================
467 notif.nent_hudargs = strzone(
468 Process_Notif_Args(2, hudargs, typestring, namestring));
470 if(icon != "") { notif.nent_icon = strzone(icon); }
475 "^1NOTIFICATION HAS HUDARGS BUT NO ICON: ",
476 "^7net_type = MSG_%s, net_name = %s.\n"
488 "^1NOTIFICATION HAS ICON BUT NO HUDARGS: ",
489 "^7net_type = MSG_%s, net_name = %s.\n"
499 notif.nent_durcnt = strzone(
500 Process_Notif_Args(3, durcnt, typestring, namestring));
502 if(cpid != NO_MSG) { notif.nent_cpid = cpid; }
507 "^1NOTIFICATION HAS DURCNT BUT NO CPID: ",
508 "^7net_type = MSG_%s, net_name = %s.\n"
516 else if(cpid != NO_MSG) { notif.nent_cpid = cpid; }
520 // ======================
521 // Process Notif String
522 // ======================
523 #define SET_NOTIF_STRING(string,stringname) \
524 notif.nent_string = strzone(CCR( \
525 Process_Notif_Line( \
537 if(gentle != "") { SET_NOTIF_STRING(gentle, "GENTLE") }
538 else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL") }
540 else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL") }
542 #undef SET_NOTIF_STRING
544 // Check to make sure a string was chosen
545 if(notif.nent_string == "")
549 "^1EMPTY NOTIFICATION: ",
550 "^7net_type = MSG_%s, net_name = %s.\n"
560 // now check to see if any errors happened
563 notif.nent_enabled = FALSE; // disable the notification so it can't cause trouble
564 notif_global_error = TRUE; // throw the red flag that an error happened on init
568 void Destroy_Notification_Entity(entity notif)
570 if(notif.nent_name != "") { strunzone(notif.nent_name); }
571 if(notif.nent_args != "") { strunzone(notif.nent_args); }
572 if(notif.nent_hudargs != "") { strunzone(notif.nent_hudargs); }
573 if(notif.nent_icon != "") { strunzone(notif.nent_icon); }
574 if(notif.nent_durcnt != "") { strunzone(notif.nent_durcnt); }
575 if(notif.nent_string != "") { strunzone(notif.nent_string); }
579 void Destroy_All_Notifications(void)
583 #define DESTROY_LOOP(type,count) \
584 for(i = 1; i <= count; ++i) \
586 notif = Get_Notif_Ent(type, i); \
587 if not(notif) { backtrace("Destroy_All_Notifications(): Missing notification entity!\n"); return; } \
588 Destroy_Notification_Entity(notif); \
591 // kill all networked notifications
593 Kill_Notification(NOTIF_ANY, world, 0, 0);
596 // kill all real notification entities
597 DESTROY_LOOP(MSG_INFO, NOTIF_INFO_COUNT)
598 DESTROY_LOOP(MSG_CENTER, NOTIF_CENTER_COUNT)
599 DESTROY_LOOP(MSG_WEAPON, NOTIF_WEAPON_COUNT)
600 DESTROY_LOOP(MSG_DEATH, NOTIF_DEATH_COUNT)
602 //print("Destroyed all huma-- I mean... notifications.. successfully.\n");
606 // =========================================
607 // Cvar Handling With 'dumpnotifs' Command
608 // =========================================
610 void Dump_Notifications(float fh, float alsoprint)
612 #define NOTIF_WRITE(a) { \
614 if(alsoprint) { print(a); } }
615 #define NOTIF_WRITE_ENTITY(name,default,description) { \
618 "seta notification_%s \"%d\" \"%s\"\n", \
619 name, default, description \
621 NOTIF_WRITE(notif_msg) }
622 #define NOTIF_WRITE_HARDCODED(cvar,default,description) { \
625 "seta notification_%s \"%s\" \"%s\"\n", \
626 cvar, default, description \
628 NOTIF_WRITE(notif_msg) }
634 // Note: This warning only applies to the notifications.cfg file that is output...
636 // You ARE supposed to manually edit this function to add i.e. hard coded
637 // notification variables for mutators or game modes or such and then
638 // regenerate the notifications.cfg file from the new code.
640 NOTIF_WRITE("// ********************************************** //\n");
641 NOTIF_WRITE("// ** WARNING - DO NOT MANUALLY EDIT THIS FILE ** //\n");
642 NOTIF_WRITE("// ** ** //\n");
643 NOTIF_WRITE("// ** This file is automatically generated ** //\n");
644 NOTIF_WRITE("// ** by code with the command 'dumpnotifs'. ** //\n");
645 NOTIF_WRITE("// ** ** //\n");
646 NOTIF_WRITE("// ** If you add a new notification, please ** //\n");
647 NOTIF_WRITE("// ** regenerate this file with that command ** //\n");
648 NOTIF_WRITE("// ** making sure that the output matches ** //\n");
649 NOTIF_WRITE("// ** with the lists and defaults in code. ** //\n");
650 NOTIF_WRITE("// ** ** //\n");
651 NOTIF_WRITE("// ********************************************** //\n");
653 // These notifications will also append their string as a comment...
654 // This is not necessary, and does not matter if they vary between config versions,
655 // it is just a semi-helpful tool for those who want to manually change their user settings.
657 NOTIF_WRITE(sprintf("\n// MSG_INFO notifications (count = %d):\n", NOTIF_INFO_COUNT));
658 for(i = 1; i <= NOTIF_INFO_COUNT; ++i)
660 e = Get_Notif_Ent(MSG_INFO, i);
661 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
662 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)");
665 NOTIF_WRITE(sprintf("\n// MSG_CENTER notifications (count = %d):\n", NOTIF_CENTER_COUNT));
666 for(i = 1; i <= NOTIF_CENTER_COUNT; ++i)
668 e = Get_Notif_Ent(MSG_CENTER, i);
669 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
670 NOTIF_WRITE_ENTITY(e.nent_name, e.nent_default, "Notification control cvar: 0 = off, 1 = centerprint");
673 NOTIF_WRITE(sprintf("\n// MSG_WEAPON notifications (count = %d):\n", NOTIF_WEAPON_COUNT));
674 for(i = 1; i <= NOTIF_WEAPON_COUNT; ++i)
676 e = Get_Notif_Ent(MSG_WEAPON, i);
677 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
678 NOTIF_WRITE_ENTITY(e.nent_name, e.nent_default, "Notification control cvar: 0 = off, 1 = trigger subcalls");
681 NOTIF_WRITE(sprintf("\n// MSG_DEATH notifications (count = %d):\n", NOTIF_DEATH_COUNT));
682 for(i = 1; i <= NOTIF_DEATH_COUNT; ++i)
684 e = Get_Notif_Ent(MSG_DEATH, i);
685 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
686 NOTIF_WRITE_ENTITY(e.nent_name, e.nent_default, "Notification control cvar: 0 = off, 1 = trigger subcalls");
689 // edit these to match whichever cvars are used for specific notification options
690 NOTIF_WRITE("\n// HARD CODED notification variables:\n");
691 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)");
692 NOTIF_WRITE_HARDCODED("show_location", "0", "Append location information to MSG_INFO death/kill messages");
693 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)'");
694 NOTIF_WRITE_HARDCODED("show_sprees", "1", "Print information about sprees in death/kill messages");
695 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");
696 NOTIF_WRITE_HARDCODED("show_sprees_center_specialonly", "1", "Don't show spree information in MSG_CENTER messages if it isn't an achievement");
697 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");
698 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");
699 NOTIF_WRITE_HARDCODED("show_sprees_info_specialonly", "1", "Don't show attacker spree information in MSG_INFO messages if it isn't an achievement");
700 NOTIF_WRITE_HARDCODED("item_centerprinttime", "1.5", "How long to show item information centerprint messages (like 'You got the Electro' or such)");
701 NOTIF_WRITE_HARDCODED("errors_are_fatal", "1", "If a notification fails upon initialization, cause a Host_Error to stop the program");
702 NOTIF_WRITE_HARDCODED("ctf_pickup_team_verbose", "0", "Show extra information if a team mate picks up a flag");
703 NOTIF_WRITE_HARDCODED("ctf_pickup_enemy_verbose", "0", "Show extra information if an enemy picks up a flag");
704 NOTIF_WRITE_HARDCODED("ctf_capture_verbose", "0", "Show extra information when someone captures a flag");
705 NOTIF_WRITE_HARDCODED("frag_verbose", "1", "Show extra information when you frag someone (or when you are fragged");
706 NOTIF_WRITE_HARDCODED("lifetime_runtime", "0.5", "Amount of time that notification entities last on the server during runtime (In seconds)");
707 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)");
709 NOTIF_WRITE(sprintf("\n// Notification counts (total = %d): MSG_INFO = %d, MSG_CENTER = %d, MSG_WEAPON = %d, MSG_DEATH = %d\n",
710 (NOTIF_INFO_COUNT + NOTIF_CENTER_COUNT + NOTIF_WEAPON_COUNT + NOTIF_DEATH_COUNT),
711 NOTIF_INFO_COUNT, NOTIF_CENTER_COUNT, NOTIF_WEAPON_COUNT, NOTIF_DEATH_COUNT));
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(string input, string args,
732 string s1, string s2, string s3, string s4,
733 float f1, float f2, float f3, float f4)
735 #ifdef NOTIFICATIONS_DEBUG
737 "Local_Notification_sprintf('%s^7', '%s', %s, %s);\n",
738 strreplace("\n", "\\n", input),
740 strreplace("\n", "\\n", sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
741 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
747 for(sel_num = 0; sel_num < NOTIF_MAX_ARGS; ++sel_num) { arg_slot[sel_num] = ""; }
751 for(sel_num = 0;(args != "");)
753 selected = car(args); args = cdr(args);
754 NOTIF_HIT_MAX(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
755 switch(strtolower(selected))
757 #define ARG_CASE(prog,selected,result) \
759 #if (prog != ARG_SV) && (prog != ARG_DC) \
760 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
763 #if (prog != ARG_CS) && (prog != ARG_DC) \
764 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
769 default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
772 return sprintf(input, arg_slot[0], arg_slot[1], arg_slot[2], arg_slot[3], arg_slot[4], arg_slot[5], arg_slot[6]);
776 void Local_Notification_HUD_Notify_Push(string icon, string hudargs, string s1, string s2, string s3, string s4)
780 arg_slot[0] = ""; arg_slot[1] = "";
782 for(sel_num = 0;(hudargs != "");)
784 selected = car(hudargs); hudargs = cdr(hudargs);
785 NOTIF_HIT_MAX(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
786 switch(strtolower(selected))
788 #define ARG_CASE(prog,selected,result) \
789 #if (prog == ARG_CS_SV_HA) \
790 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
794 default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
797 #ifdef NOTIFICATIONS_DEBUG
799 "Local_Notification_HUD_Notify_Push('%s^7', '%s', %s, %s);\n",
802 strreplace("\n", "\\n", sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
803 strreplace("\n", "\\n", sprintf("'%s^7', '%s^7'", stof(arg_slot[0]), stof(arg_slot[1])))
806 HUD_Notify_Push(icon, arg_slot[0], arg_slot[1]);
809 void Local_Notification_centerprint_generic(string input, string durcnt, float cpid, float f1, float f2)
813 arg_slot[0] = ""; arg_slot[1] = "";
815 for(sel_num = 0;(durcnt != "");)
817 selected = car(durcnt); durcnt = cdr(durcnt);
818 NOTIF_HIT_MAX(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic")
819 switch(strtolower(selected))
821 #define ARG_CASE(prog,selected,result) \
822 #if (prog == ARG_CS_SV_DC) || (prog == ARG_DC) \
823 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
829 if(ftos(stof(selected)) != "") { arg_slot[sel_num] = selected; ++sel_num; }
830 else { NOTIF_HIT_UNKNOWN(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic") }
835 #ifdef NOTIFICATIONS_DEBUG
837 "Local_Notification_centerprint_generic('%s^7', '%s', %d, %d, %d, %d);\n",
838 strreplace("\n", "\\n", input),
841 stof(arg_slot[0]), stof(arg_slot[1])
844 centerprint_generic(cpid, input, stof(arg_slot[0]), stof(arg_slot[1]));
848 void Local_Notification(float net_type, float net_name, ...count)
850 // check supplied type and name for errors
851 string checkargs = Notification_CheckArgs_TypeName(net_type, net_name);
852 if(checkargs != "") { backtrace(sprintf("Incorrect usage of Local_Notification: %s\n", checkargs)); return; }
854 entity notif = Get_Notif_Ent(net_type, net_name);
855 if not(notif) { backtrace("Local_Notification: Could not find notification entity!\n"); return; }
857 #ifdef NOTIFICATIONS_DEBUG
858 if not(notif.nent_enabled)
861 "Local_Notification(%s, %s): Entity was disabled...\n",
862 Get_Notif_TypeName(net_type),
869 if((notif.nent_stringcount + notif.nent_floatcount) > count)
873 "Not enough arguments for Local_Notification(%s, %s, ...)! ",
874 "stringcount(%d) + floatcount(%d) > count(%d)\n",
875 "Check the definition and function call for accuracy...?\n"
877 Get_Notif_TypeName(net_type), notif.nent_name,
878 notif.nent_stringcount, notif.nent_floatcount, count
882 else if((notif.nent_stringcount + notif.nent_floatcount) < count)
886 "Too many arguments for Local_Notification(%s, %s, ...)! ",
887 "stringcount(%d) + floatcount(%d) < count(%d)\n",
888 "Check the definition and function call for accuracy...?\n"
890 Get_Notif_TypeName(net_type), notif.nent_name,
891 notif.nent_stringcount, notif.nent_floatcount, count
896 string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
897 string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
898 string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
899 string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
900 float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
901 float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
902 float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
903 float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
905 #ifdef NOTIFICATIONS_DEBUG
907 "Local_Notification(%s, %s, %s, %s);\n",
908 Get_Notif_TypeName(net_type),
910 strreplace("\n", "\\n", sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
911 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
920 Local_Notification_sprintf(
927 if(notif.nent_icon != "")
929 Local_Notification_HUD_Notify_Push(
941 Local_Notification_centerprint_generic(
942 Local_Notification_sprintf(
957 if(notif.nent_msginfo)
958 if(notif.nent_msginfo.nent_enabled)
960 Local_Notification_WOVA(
962 notif.nent_msginfo.nent_id,
963 notif.nent_msginfo.nent_stringcount,
964 notif.nent_msginfo.nent_floatcount,
969 if(notif.nent_msgcenter)
970 if(notif.nent_msgcenter.nent_enabled)
972 Local_Notification_WOVA(
974 notif.nent_msgcenter.nent_id,
975 notif.nent_msgcenter.nent_stringcount,
976 notif.nent_msgcenter.nent_floatcount,
986 // WOVA = Without Variable Arguments
987 void Local_Notification_WOVA(float net_type, float net_name,
988 float stringcount, float floatcount,
989 string s1, string s2, string s3, string s4,
990 float f1, float f2, float f3, float f4)
992 #define VARITEM(stringc,floatc,args) \
993 if((stringcount == stringc) && (floatcount == floatc)) \
994 { Local_Notification(net_type, net_name, args); return; }
995 EIGHT_VARS_TO_VARARGS_VARLIST
997 Local_Notification(net_type, net_name); // some notifications don't have any arguments at all
1001 // =========================
1002 // Notification Networking
1003 // =========================
1006 void Read_Notification(float is_new)
1008 float net_type = ReadByte();
1009 float net_name = ReadShort();
1013 if(net_type == MSG_CENTER_KILL)
1017 if(net_name == 0) { reset_centerprint_messages(); }
1020 notif = Get_Notif_Ent(MSG_CENTER, net_name);
1021 if not(notif) { backtrace("Read_Notification: Could not find notification entity!\n"); return; }
1022 centerprint_generic(notif.nent_cpid, "", 0, 0);
1028 notif = Get_Notif_Ent(net_type, net_name);
1029 if not(notif) { backtrace("Read_Notification: Could not find notification entity!\n"); return; }
1031 #ifdef NOTIFICATIONS_DEBUG
1033 "Read_Notification(%d) at %f: net_type = %s, net_name = %s\n",
1036 Get_Notif_TypeName(net_type),
1041 string s1 = ((0 < notif.nent_stringcount) ? ReadString() : "");
1042 string s2 = ((1 < notif.nent_stringcount) ? ReadString() : "");
1043 string s3 = ((2 < notif.nent_stringcount) ? ReadString() : "");
1044 string s4 = ((3 < notif.nent_stringcount) ? ReadString() : "");
1045 float f1 = ((0 < notif.nent_floatcount) ? ReadLong() : 0);
1046 float f2 = ((1 < notif.nent_floatcount) ? ReadLong() : 0);
1047 float f3 = ((2 < notif.nent_floatcount) ? ReadLong() : 0);
1048 float f4 = ((3 < notif.nent_floatcount) ? ReadLong() : 0);
1052 Local_Notification_WOVA(
1054 notif.nent_stringcount,
1055 notif.nent_floatcount,
1064 void Net_Notification_Remove()
1066 #ifdef NOTIFICATIONS_DEBUG
1067 if not(self) { dprint(sprintf("Net_Notification_Remove() at %f: Missing self!?\n", time)); return; }
1068 if(self.nent_net_name == -1)
1071 "Net_Notification_Remove() at %f: Killed '%s' notification\n",
1073 Get_Notif_TypeName(self.nent_net_type)
1079 string checkargs = Notification_CheckArgs_TypeName(self.nent_net_type, self.nent_net_name);
1080 if(checkargs != "") { dprint(sprintf("Incorrect usage of Net_Notification_Remove() at %f: %s\n", time, checkargs)); return; }
1082 #ifdef NOTIFICATIONS_DEBUG
1083 entity realent = Get_Notif_Ent(self.nent_net_type, self.nent_net_name);
1085 "Net_Notification_Remove() at %f: Removed '%s - %s' notification\n",
1087 Get_Notif_TypeName(self.nent_net_type),
1094 for(i = 0; i < 4; ++i) { if(self.nent_strings[i]) { strunzone(self.nent_strings[i]); } }
1098 float Net_Write_Notification(entity client, float sf)
1100 float i, send = FALSE;
1102 switch(self.nent_broadcast)
1104 case NOTIF_ONE: // send to one client and their spectator
1107 (client == self.nent_client)
1110 (client.classname == STR_SPECTATOR)
1112 (client.enemy == self.nent_client)
1117 case NOTIF_ONE_ONLY: // send ONLY to one client
1119 if(client == self.nent_client) { send = TRUE; }
1122 case NOTIF_TEAM: // send only to X team and their spectators
1125 (client.team == self.nent_client.team)
1128 (client.classname == STR_SPECTATOR)
1130 (client.enemy.team == self.nent_client.team)
1135 case NOTIF_TEAM_EXCEPT: // send only to X team and their spectators, except for Y person and their spectators
1138 (client != self.nent_client)
1141 (client.team == self.nent_client.team)
1144 (client.classname == STR_SPECTATOR)
1147 (client.enemy != self.nent_client)
1149 (client.enemy.team == self.nent_client.team)
1156 case NOTIF_ANY: // send to everyone
1161 case NOTIF_ANY_EXCEPT: // send to everyone except X person and their spectators
1164 (client != self.nent_client)
1167 (client.classname == STR_SPECTATOR)
1169 (client.enemy == self.nent_client)
1174 default: { send = FALSE; break; }
1179 WriteByte(MSG_ENTITY, ENT_CLIENT_NOTIFICATION);
1180 WriteByte(MSG_ENTITY, self.nent_net_type);
1181 WriteShort(MSG_ENTITY, self.nent_net_name);
1182 for(i = 0; i < self.nent_stringcount; ++i) { WriteString(MSG_ENTITY, self.nent_strings[i]); }
1183 for(i = 0; i < self.nent_floatcount; ++i) { WriteLong(MSG_ENTITY, self.nent_floats[i]); }
1189 void Kill_Notification(float broadcast, entity client, float net_type, float net_name)
1191 string checkargs = Notification_CheckArgs(broadcast, client, 1, 1);
1192 if(checkargs != "") { backtrace(sprintf("Incorrect usage of Kill_Notification: %s\n", checkargs)); return; }
1194 #ifdef NOTIFICATIONS_DEBUG
1196 "Kill_Notification(%d, '%s', %d, %d);\n",
1204 entity notif, net_notif;
1206 // if no name is provided, just kill ALL the centerprint notifications
1207 if(net_type == MSG_CENTER)
1209 net_notif = spawn();
1210 net_notif.classname = "net_kill_notification";
1211 net_notif.nent_broadcast = broadcast;
1212 net_notif.nent_client = client;
1213 net_notif.nent_net_type = MSG_CENTER_KILL;
1214 net_notif.nent_net_name = net_name;
1215 Net_LinkEntity(net_notif, FALSE, autocvar_notification_lifetime_runtime, Net_Write_Notification);
1218 for(notif = world; (notif = find(notif, classname, "net_notification"));)
1220 // now kill the old send notification entity
1223 if(notif.nent_net_type == net_type)
1227 if(notif.nent_net_name == net_name) { notif.nent_net_name = -1; notif.think(); }
1228 else { continue; } // we ARE looking for a certain net_name, don't kill everything else too
1230 else { notif.nent_net_name = -1; notif.think(); }
1232 else { continue; } // we ARE looking for a certain net_type, don't kill everything else too
1234 else { notif.nent_net_name = -1; notif.think(); }
1238 void Send_Notification(float broadcast, entity client,
1239 float net_type, float net_name, ...count)
1241 // check supplied broadcast, target, type, and name for errors
1242 string checkargs = Notification_CheckArgs(broadcast, client, net_type, net_name);
1243 if(checkargs != "") { backtrace(sprintf("Incorrect usage of Send_Notification: %s\n", checkargs)); return; }
1245 // retreive counts for the arguments of this notification
1246 entity notif = Get_Notif_Ent(net_type, net_name);
1247 if not(notif) { backtrace("Send_Notification: Could not find notification entity!\n"); return; }
1249 if((notif.nent_stringcount + notif.nent_floatcount) > count)
1253 "Not enough arguments for Send_Notification(%d, %s, %s, ...)! ",
1254 "stringcount(%d) + floatcount(%d) > count(%d)\n",
1255 "Check the definition and function call for accuracy...?\n"
1257 broadcast, Get_Notif_TypeName(net_type), notif.nent_name,
1258 notif.nent_stringcount, notif.nent_floatcount, count
1262 else if((notif.nent_stringcount + notif.nent_floatcount) < count)
1266 "Too many arguments for Send_Notification(%d, %s, %s, ...)! ",
1267 "stringcount(%d) + floatcount(%d) < count(%d)\n",
1268 "Check the definition and function call for accuracy...?\n"
1270 broadcast, Get_Notif_TypeName(net_type), notif.nent_name,
1271 notif.nent_stringcount, notif.nent_floatcount, count
1276 #ifdef NOTIFICATIONS_DEBUG
1277 string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
1278 string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
1279 string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
1280 string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
1281 float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
1282 float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
1283 float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
1284 float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
1286 "Send_Notification(%d, %s, %s, %s, %s);\n",
1288 Get_Notif_TypeName(net_type),
1290 strreplace("\n", "\\n", sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1291 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1295 entity net_notif = spawn();
1296 net_notif.classname = "net_notification";
1297 net_notif.nent_broadcast = broadcast;
1298 net_notif.nent_client = client;
1299 net_notif.nent_net_type = net_type;
1300 net_notif.nent_net_name = net_name;
1301 net_notif.nent_stringcount = notif.nent_stringcount;
1302 net_notif.nent_floatcount = notif.nent_floatcount;
1305 for(i = 0; i < net_notif.nent_stringcount; ++i) { net_notif.nent_strings[i] = strzone(...(i, string)); }
1306 for(i = 0; i < net_notif.nent_floatcount; ++i) { net_notif.nent_floats[i] = ...((net_notif.nent_stringcount + i), float); }
1308 net_notif.think = Net_Notification_Remove;
1309 net_notif.nextthink =
1310 ((time > autocvar_notification_lifetime_mapload)
1312 (time + autocvar_notification_lifetime_runtime)
1314 autocvar_notification_lifetime_mapload
1317 Net_LinkEntity(net_notif, FALSE, 0, Net_Write_Notification);
1319 if(server_is_dedicated && (broadcast == NOTIF_ANY || broadcast == NOTIF_ANY_EXCEPT) && (net_type != MSG_CENTER))
1321 Local_Notification_WOVA(
1323 notif.nent_stringcount,
1324 notif.nent_floatcount,
1325 IFSTR(0), IFSTR(1), IFSTR(2), IFSTR(3),
1326 IFFL(0), IFFL(1), IFFL(2), IFFL(3));
1330 // WOVA = Without Variable Arguments
1331 void Send_Notification_WOVA(float broadcast, entity client,
1332 float net_type, float net_name,
1333 string s1, string s2, string s3, string s4,
1334 float f1, float f2, float f3, float f4)
1336 entity notif = Get_Notif_Ent(net_type, net_name);
1338 #ifdef NOTIFICATIONS_DEBUG
1340 "Send_Notification_WOVA(%d, %s, %s, %s, %s - %d %d);\n",
1342 Get_Notif_TypeName(net_type),
1344 sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4),
1345 sprintf("%d, %d, %d, %d", f1, f2, f3, f4),
1346 notif.nent_stringcount, notif.nent_floatcount
1350 #define VARITEM(stringc,floatc,args) \
1351 if((notif.nent_stringcount == stringc) && (notif.nent_floatcount == floatc)) \
1352 { Send_Notification(broadcast, client, net_type, net_name, args); return; }
1353 EIGHT_VARS_TO_VARARGS_VARLIST
1355 Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
1359 // =============================
1360 // LEGACY NOTIFICATION SYSTEMS
1361 // =============================
1363 void Send_CSQC_Centerprint_Generic(entity e, float id, string s, float duration, float countdown_num)
1365 if ((clienttype(e) == CLIENTTYPE_REAL) && (e.flags & FL_CLIENT))
1368 WRITESPECTATABLE_MSG_ONE({
1369 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1370 WriteByte(MSG_ONE, TE_CSQC_CENTERPRINT_GENERIC);
1371 WriteByte(MSG_ONE, id);
1372 WriteString(MSG_ONE, s);
1373 if (id != 0 && s != "")
1375 WriteByte(MSG_ONE, duration);
1376 WriteByte(MSG_ONE, countdown_num);
1381 #endif // ifdef SVQC