4 #include "constants.qh"
6 #include "../server/autocvars.qh"
7 #include "../server/constants.qh"
8 #include "../server/defs.qh"
9 #include "notifications.qh"
10 #include "../server/mutators/all.qh"
13 // ================================================
14 // Unified notification system, written by Samual
15 // Last updated: August, 2013
16 // ================================================
18 string Get_Notif_TypeName(int net_type)
22 case MSG_ANNCE: return "MSG_ANNCE";
23 case MSG_INFO: return "MSG_INFO";
24 case MSG_CENTER: return "MSG_CENTER";
25 case MSG_CENTER_CPID: return "MSG_CENTER_CPID";
26 case MSG_MULTI: return "MSG_MULTI";
27 case MSG_CHOICE: return "MSG_CHOICE";
29 backtrace(sprintf("Get_Notif_TypeName(%d): Improper net type!\n", net_type));
33 entity Get_Notif_Ent(int net_type, int net_name)
37 case MSG_ANNCE: return msg_annce_notifs[net_name - 1];
38 case MSG_INFO: return msg_info_notifs[net_name - 1];
39 case MSG_CENTER: return msg_center_notifs[net_name - 1];
40 case MSG_MULTI: return msg_multi_notifs[net_name - 1];
41 case MSG_CHOICE: return msg_choice_notifs[net_name - 1];
43 backtrace(sprintf("Get_Notif_Ent(%d, %d): Improper net type!\n", net_type, net_name));
48 #ifdef NOTIFICATIONS_DEBUG
49 string Get_Notif_BroadcastName(float broadcast)
53 case NOTIF_ONE: return "NOTIF_ONE";
54 case NOTIF_ONE_ONLY: return "NOTIF_ONE_ONLY";
55 case NOTIF_ALL_EXCEPT: return "NOTIF_ALL_EXCEPT";
56 case NOTIF_ALL: return "NOTIF_ALL";
57 case NOTIF_TEAM: return "NOTIF_TEAM";
58 case NOTIF_TEAM_EXCEPT: return "NOTIF_TEAM_EXCEPT";
60 backtrace(sprintf("Get_Notif_BroadcastName(%d): Improper broadcast!\n", broadcast));
66 string Notification_CheckArgs_TypeName(float net_type, float net_name)
68 // check supplied type and name for errors
69 string checkargs = "";
70 #define CHECKARG_TYPENAME(type) case MSG_##type: \
71 { if(!net_name || (net_name > NOTIF_##type##_COUNT)) \
72 { checkargs = sprintf("Improper name: %d!", net_name); } break; }
75 CHECKARG_TYPENAME(ANNCE)
76 CHECKARG_TYPENAME(INFO)
77 CHECKARG_TYPENAME(CENTER)
78 CHECKARG_TYPENAME(MULTI)
79 CHECKARG_TYPENAME(CHOICE)
80 default: { checkargs = sprintf("Improper type: %d!", checkargs, net_type); break; }
82 #undef CHECKARG_TYPENAME
87 string Notification_CheckArgs(
88 float broadcast, entity client,
89 float net_type, float net_name)
91 // check supplied broadcast, target, type, and name for errors
92 string checkargs = Notification_CheckArgs_TypeName(net_type, net_name);
93 if(checkargs != "") { checkargs = strcat(checkargs, " "); }
99 if(IS_NOT_A_CLIENT(client))
100 { checkargs = sprintf("%sNo client provided!", checkargs); }
104 case NOTIF_ALL_EXCEPT:
106 if(IS_NOT_A_CLIENT(client))
107 { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
114 { checkargs = sprintf("%sEntity provided when world was required!", checkargs); }
121 { checkargs = sprintf("%sTeamplay not active!", checkargs); }
122 //else if (!client.team) { checkargs = sprintf("%sNo team provided!", checkargs); }
126 case NOTIF_TEAM_EXCEPT:
129 { checkargs = sprintf("%sTeamplay not active!", checkargs); }
130 else if(IS_NOT_A_CLIENT(client))
131 { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
135 default: { checkargs = sprintf("%sImproper broadcast: %d!", checkargs, broadcast); break; }
140 float Notification_ShouldSend(float broadcast, entity to_client, entity other_client)
144 case NOTIF_ONE: // send to one client and their spectator
147 (to_client == other_client)
152 (to_client.enemy == other_client)
157 case NOTIF_ONE_ONLY: // send ONLY to one client
159 if(to_client == other_client) { return true; }
162 case NOTIF_TEAM: // send only to X team and their spectators
165 (to_client.team == other_client.team)
170 (to_client.enemy.team == other_client.team)
175 case NOTIF_TEAM_EXCEPT: // send only to X team and their spectators, except for Y person and their spectators
178 (to_client != other_client)
181 (to_client.team == other_client.team)
187 (to_client.enemy != other_client)
189 (to_client.enemy.team == other_client.team)
196 case NOTIF_ALL: // send to everyone
200 case NOTIF_ALL_EXCEPT: // send to everyone except X person and their spectators
203 (to_client != other_client)
208 (to_client.enemy == other_client)
219 // ===============================
220 // Initialization Core Functions
221 // ===============================
223 // used by restartnotifs command to initialize notifications
224 void Destroy_Notification_Entity(entity notif)
226 if(notif.nent_name != "") { strunzone(notif.nent_name); }
227 if(notif.nent_snd != "") { strunzone(notif.nent_snd); }
228 if(notif.nent_args != "") { strunzone(notif.nent_args); }
229 if(notif.nent_hudargs != "") { strunzone(notif.nent_hudargs); }
230 if(notif.nent_icon != "") { strunzone(notif.nent_icon); }
231 if(notif.nent_durcnt != "") { strunzone(notif.nent_durcnt); }
232 if(notif.nent_string != "") { strunzone(notif.nent_string); }
236 void Destroy_All_Notifications(void)
241 #define DESTROY_LOOP(type,count) do { \
242 for(i = 1; i <= count; ++i) \
244 notif = Get_Notif_Ent(type, i); \
245 if (!notif) { backtrace("Destroy_All_Notifications(): Missing notification entity!\n"); return; } \
246 Destroy_Notification_Entity(notif); \
250 // kill all networked notifications and centerprints
252 Kill_Notification(NOTIF_ALL, world, 0, 0);
254 reset_centerprint_messages();
257 // kill all real notification entities
258 DESTROY_LOOP(MSG_ANNCE, NOTIF_ANNCE_COUNT);
259 DESTROY_LOOP(MSG_INFO, NOTIF_INFO_COUNT);
260 DESTROY_LOOP(MSG_CENTER, NOTIF_CENTER_COUNT);
261 DESTROY_LOOP(MSG_MULTI, NOTIF_MULTI_COUNT);
262 DESTROY_LOOP(MSG_CHOICE, NOTIF_CHOICE_COUNT);
266 string Process_Notif_Line(
275 if(typeId == MSG_INFO)
277 if((chat && autocvar_notification_allow_chatboxprint)
278 || (autocvar_notification_allow_chatboxprint == 2))
280 // pass 1: add ETX char at beginning of line
281 input = strcat("\{3}", input);
283 // pass 2: add ETX char at end of each new line (so that
284 // messages with multiple lines are put through chatbox too)
285 input = strreplace("\n", "\n\{3}", input);
287 // pass 3: strip trailing ETX char
288 if(substring(input, (strlen(input) - 1), 1) == "\{3}")
289 { input = substring(input, 0, (strlen(input) - 1)); }
294 // done to both MSG_INFO and MSG_CENTER
295 if(substring(input, (strlen(input) - 1), 1) == "\n")
299 "^1TRAILING NEW LINE AT END OF NOTIFICATION: ",
300 "^7net_type = %s, net_name = %s, string = %s.\n"
307 input = substring(input, 1, (strlen(input) - 1));
313 string Process_Notif_Args(
319 string selected, remaining = args;
322 for (;(remaining != "");)
324 selected = car(remaining); remaining = cdr(remaining);
328 case 1: // normal args
330 if(sel_num == NOTIF_MAX_ARGS)
334 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
335 "^7net_type = %s, net_name = %s, max args = %d.\n"
345 switch(strtolower(selected))
347 #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { ++sel_num; break; }
348 #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { ++sel_num; break; }
349 #define ARG_CASE_ARG_CS_SV(selected,result) case selected: { ++sel_num; break; }
350 #define ARG_CASE_ARG_CS(selected,result) case selected: { ++sel_num; break; }
351 #define ARG_CASE_ARG_SV(selected,result) case selected: { ++sel_num; break; }
352 #define ARG_CASE_ARG_DC(selected,result)
353 #define ARG_CASE(prog,selected,result) ARG_CASE_##prog(selected,result)
356 #undef ARG_CASE_ARG_DC
357 #undef ARG_CASE_ARG_SV
358 #undef ARG_CASE_ARG_CS
359 #undef ARG_CASE_ARG_CS_SV
360 #undef ARG_CASE_ARG_CS_SV_DC
361 #undef ARG_CASE_ARG_CS_SV_HA
366 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
367 "^7net_type = %s, net_name = %s, args arg = '%s'.\n"
381 if(sel_num == NOTIF_MAX_HUDARGS)
385 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
386 "^7net_type = %s, net_name = %s, max hudargs = %d.\n"
396 switch(strtolower(selected))
398 #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { ++sel_num; break; }
399 #define ARG_CASE_ARG_CS_SV_DC(selected,result)
400 #define ARG_CASE_ARG_CS_SV(selected,result)
401 #define ARG_CASE_ARG_CS(selected,result)
402 #define ARG_CASE_ARG_SV(selected,result)
403 #define ARG_CASE_ARG_DC(selected,result)
404 #define ARG_CASE(prog,selected,result) ARG_CASE_##prog(selected,result)
407 #undef ARG_CASE_ARG_DC
408 #undef ARG_CASE_ARG_SV
409 #undef ARG_CASE_ARG_CS
410 #undef ARG_CASE_ARG_CS_SV
411 #undef ARG_CASE_ARG_CS_SV_DC
412 #undef ARG_CASE_ARG_CS_SV_HA
417 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
418 "^7net_type = %s, net_name = %s, hudargs arg = '%s'.\n"
432 if(sel_num == NOTIF_MAX_DURCNT)
436 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
437 "^7net_type = %s, net_name = %s, max durcnt = %d.\n"
447 switch(strtolower(selected))
449 #define ARG_CASE_ARG_CS_SV_HA(selected,result)
450 #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { ++sel_num; break; }
451 #define ARG_CASE_ARG_CS_SV(selected,result)
452 #define ARG_CASE_ARG_CS(selected,result)
453 #define ARG_CASE_ARG_SV(selected,result)
454 #define ARG_CASE_ARG_DC(selected,result) case selected: { ++sel_num; break; }
455 #define ARG_CASE(prog,selected,result) ARG_CASE_##prog(selected,result)
458 #undef ARG_CASE_ARG_DC
459 #undef ARG_CASE_ARG_SV
460 #undef ARG_CASE_ARG_CS
461 #undef ARG_CASE_ARG_CS_SV
462 #undef ARG_CASE_ARG_CS_SV_DC
463 #undef ARG_CASE_ARG_CS_SV_HA
466 if(ftos(stof(selected)) != "") { ++sel_num; }
471 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
472 "^7net_type = %s, net_name = %s, durcnt arg = '%s'.\n"
490 void Create_Notification_Entity(
503 /* MSG_INFO & MSG_CENTER */
522 // =====================
523 // Global Entity Setup
524 // =====================
525 entity notif = spawn();
530 msg_annce_notifs[nameid - 1] = notif;
531 notif.classname = "msg_annce_notification";
536 msg_info_notifs[nameid - 1] = notif;
537 notif.classname = "msg_info_notification";
542 msg_center_notifs[nameid - 1] = notif;
543 notif.classname = "msg_center_notification";
548 msg_multi_notifs[nameid - 1] = notif;
549 notif.classname = "msg_multi_notification";
554 msg_choice_notifs[nameid - 1] = notif;
555 notif.classname = "msg_choice_notification";
563 "^1NOTIFICATION WITH IMPROPER TYPE: ",
564 "^7net_type = %d, net_name = %s.\n"
569 return; // It's not possible to recover from this one
572 notif.nent_default = var_default;
573 notif.nent_enabled = (1 <= var_cvar);
574 notif.nent_type = typeId;
575 notif.nent_id = nameid;
576 notif.nent_name = strzone(namestring);
578 string typestring = Get_Notif_TypeName(typeId);
580 // Other pre-notif-setup requisites
583 // ====================
584 // Notification Setup
585 // ====================
590 // Set MSG_ANNCE information and handle precaching
592 if (!(GENTLE && (var_cvar == 1)))
596 if(notif.nent_enabled)
598 precache_sound(sprintf("announcer/%s/%s.wav", autocvar_cl_announcer, snd));
599 notif.nent_channel = channel;
600 notif.nent_snd = strzone(snd);
601 notif.nent_vol = vol;
602 notif.nent_position = position;
609 "^1NOTIFICATION WITH NO SOUND: ",
610 "^7net_type = %s, net_name = %s.\n"
618 else { notif.nent_enabled = false; }
620 notif.nent_enabled = false;
629 // Set MSG_INFO and MSG_CENTER string/float counts
630 notif.nent_stringcount = strnum;
631 notif.nent_floatcount = flnum;
633 // Only initialize arguments if we're either a client or on a dedicated server
635 float should_process_args = server_is_dedicated;
637 float should_process_args = true;
640 if(should_process_args)
642 // ========================
643 // Process Main Arguments
644 // ========================
649 notif.nent_args = strzone(
650 Process_Notif_Args(1, args, typestring, namestring));
652 else if((hudargs == "") && (durcnt ==""))
656 "^1NOTIFICATION HAS ARG COUNTS BUT NO ARGS OR HUDARGS OR DURCNT: ",
657 "^7net_type = %s, net_name = %s, strnum = %d, flnum = %d\n"
669 notif.nent_args = strzone(
670 Process_Notif_Args(1, args, typestring, namestring));
674 // =======================================
675 // Process HUD and Centerprint Arguments
676 // Only processed on CSQC, as these
677 // args are only for HUD features.
678 // =======================================
682 notif.nent_hudargs = strzone(
683 Process_Notif_Args(2, hudargs, typestring, namestring));
685 if(icon != "") { notif.nent_icon = strzone(icon); }
690 "^1NOTIFICATION HAS HUDARGS BUT NO ICON: ",
691 "^7net_type = %s, net_name = %s.\n"
703 "^1NOTIFICATION HAS ICON BUT NO HUDARGS: ",
704 "^7net_type = %s, net_name = %s.\n"
714 notif.nent_durcnt = strzone(
715 Process_Notif_Args(3, durcnt, typestring, namestring));
717 if(cpid != NO_MSG) { notif.nent_cpid = cpid; }
722 "^1NOTIFICATION HAS DURCNT BUT NO CPID: ",
723 "^7net_type = %s, net_name = %s.\n"
731 else if(cpid != NO_MSG) { notif.nent_cpid = cpid; }
735 // ======================
736 // Process Notif String
737 // ======================
738 #define SET_NOTIF_STRING(string,stringname) do { \
739 notif.nent_string = strzone(CCR( \
740 Process_Notif_Line( \
753 if(gentle != "") { SET_NOTIF_STRING(gentle, "GENTLE"); }
754 else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL"); }
756 else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL"); }
757 #undef SET_NOTIF_STRING
759 // Check to make sure a string was chosen
760 if(notif.nent_string == "")
764 "^1EMPTY NOTIFICATION: ",
765 "^7net_type = %s, net_name = %s.\n"
779 // Set MSG_MULTI string/float counts
780 if((anncename == NO_MSG) && (infoname == NO_MSG) && (centername == NO_MSG))
784 "^1NOTIFICATION WITH NO SUBCALLS: ",
785 "^7net_type = %s, net_name = %s.\n"
794 // announcements don't actually need any arguments, so lets not even count them.
795 if(anncename != NO_MSG) { notif.nent_msgannce = msg_annce_notifs[anncename - 1]; }
797 float infoname_stringcount = 0, infoname_floatcount = 0;
798 float centername_stringcount = 0, centername_floatcount = 0;
800 if(infoname != NO_MSG)
802 notif.nent_msginfo = msg_info_notifs[infoname - 1];
803 infoname_stringcount = notif.nent_msginfo.nent_stringcount;
804 infoname_floatcount = notif.nent_msginfo.nent_floatcount;
807 if(centername != NO_MSG)
809 notif.nent_msgcenter = msg_center_notifs[centername - 1];
810 centername_stringcount = notif.nent_msgcenter.nent_stringcount;
811 centername_floatcount = notif.nent_msgcenter.nent_floatcount;
814 // set the requirements of THIS notification to the totals of its subcalls
815 notif.nent_stringcount = max(infoname_stringcount, centername_stringcount);
816 notif.nent_floatcount = max(infoname_floatcount, centername_floatcount);
824 if((chtype == NO_MSG) || (optiona == NO_MSG) || (optionb == NO_MSG))
828 "^1NOTIFICATION IS MISSING CHOICE PARAMS: ",
829 "^7net_type = %s, net_name = %s.\n"
842 notif.nent_optiona = msg_annce_notifs[optiona - 1];
843 notif.nent_optionb = msg_annce_notifs[optionb - 1];
848 notif.nent_optiona = msg_info_notifs[optiona - 1];
849 notif.nent_optionb = msg_info_notifs[optionb - 1];
854 notif.nent_optiona = msg_center_notifs[optiona - 1];
855 notif.nent_optionb = msg_center_notifs[optionb - 1];
860 notif.nent_optiona = msg_multi_notifs[optiona - 1];
861 notif.nent_optionb = msg_multi_notifs[optionb - 1];
864 case MSG_CHOICE: // should we REALLY allow nested options?...
866 notif.nent_optiona = msg_choice_notifs[optiona - 1];
867 notif.nent_optionb = msg_choice_notifs[optionb - 1];
875 "^1NOTIFICATION WITH IMPROPER TYPE: ",
876 "^7net_type = %d, net_name = %s.\n"
885 notif.nent_challow_def = challow_def; // 0: never allowed, 1: allowed in warmup, 2: always allowed
886 notif.nent_challow_var = challow_var; // 0: never allowed, 1: allowed in warmup, 2: always allowed
887 notif.nent_stringcount = max(notif.nent_optiona.nent_stringcount, notif.nent_optionb.nent_stringcount);
888 notif.nent_floatcount = max(notif.nent_optiona.nent_floatcount, notif.nent_optionb.nent_floatcount);
890 /*#ifdef NOTIFICATIONS_DEBUG
891 Debug_Notification(sprintf(
892 "Create_Notification_Entity(...): MSG_CHOICE: %s\n%s\n%s\n",
895 "^ optiona: %s %s : %d %d",
896 Get_Notif_TypeName(notif.nent_optiona.nent_type),
897 notif.nent_optiona.nent_name,
898 notif.nent_optiona.nent_stringcount,
899 notif.nent_optiona.nent_floatcount
902 "^ optionb: %s %s : %d %d",
903 Get_Notif_TypeName(notif.nent_optionb.nent_type),
904 notif.nent_optionb.nent_name,
905 notif.nent_optionb.nent_stringcount,
906 notif.nent_optionb.nent_floatcount
918 "^1NOTIFICATION WITH IMPROPER TYPE: ",
919 "^7net_type = %d, net_name = %s.\n"
929 // now check to see if any errors happened
932 notif.nent_enabled = false; // disable the notification so it can't cause trouble
933 notif_global_error = true; // throw the red flag that an error happened on init
942 // used by MSG_CHOICE to build list of choices
944 void Notification_GetCvars(void)
946 for(int i = 0; i <= NOTIF_CHOICE_COUNT; ++i)
948 GetCvars_handleFloat(
951 msg_choice_choices[i],
952 sprintf("notification_%s", msg_choice_notifs[i].nent_name)
958 // used to output notifications.cfg file
959 void Dump_Notifications(float fh, float alsoprint)
961 #define NOTIF_WRITE(a) { \
963 if(alsoprint) { LOG_INFO(a); } }
964 #define NOTIF_WRITE_ENTITY(description) { \
967 "seta notification_%s \"%d\" \"%s\"\n", \
968 e.nent_name, e.nent_default, description \
970 NOTIF_WRITE(notif_msg) }
971 #define NOTIF_WRITE_ENTITY_CHOICE(descriptiona,descriptionb) { \
974 "seta notification_%s \"%d\" \"%s\"\n" \
975 "seta notification_%s_ALLOWED \"%d\" \"%s\"\n", \
976 e.nent_name, e.nent_default, descriptiona, \
977 e.nent_name, e.nent_challow_def, descriptionb \
979 NOTIF_WRITE(notif_msg) }
980 #define NOTIF_WRITE_HARDCODED(cvar,default,description) { \
983 "seta notification_%s \"%s\" \"%s\"\n", \
984 cvar, default, description \
986 NOTIF_WRITE(notif_msg) }
992 // Note: This warning only applies to the notifications.cfg file that is output...
994 // You ARE supposed to manually edit this function to add i.e. hard coded
995 // notification variables for mutators or game modes or such and then
996 // regenerate the notifications.cfg file from the new code.
998 NOTIF_WRITE("// ********************************************** //\n");
999 NOTIF_WRITE("// ** WARNING - DO NOT MANUALLY EDIT THIS FILE ** //\n");
1000 NOTIF_WRITE("// ** ** //\n");
1001 NOTIF_WRITE("// ** This file is automatically generated ** //\n");
1002 NOTIF_WRITE("// ** by code with the command 'dumpnotifs'. ** //\n");
1003 NOTIF_WRITE("// ** ** //\n");
1004 NOTIF_WRITE("// ** If you add a new notification, please ** //\n");
1005 NOTIF_WRITE("// ** regenerate this file with that command ** //\n");
1006 NOTIF_WRITE("// ** making sure that the output matches ** //\n");
1007 NOTIF_WRITE("// ** with the lists and defaults in code. ** //\n");
1008 NOTIF_WRITE("// ** ** //\n");
1009 NOTIF_WRITE("// ********************************************** //\n");
1011 // These notifications will also append their string as a comment...
1012 // This is not necessary, and does not matter if they vary between config versions,
1013 // it is just a semi-helpful tool for those who want to manually change their user settings.
1015 NOTIF_WRITE(sprintf("\n// MSG_ANNCE notifications (count = %d):\n", NOTIF_ANNCE_COUNT));
1016 for(i = 1; i <= NOTIF_ANNCE_COUNT; ++i)
1018 e = Get_Notif_Ent(MSG_ANNCE, i);
1019 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1022 "0 = disabled, 1 = enabled if gentle mode is off, 2 = always enabled"
1026 NOTIF_WRITE(sprintf("\n// MSG_INFO notifications (count = %d):\n", NOTIF_INFO_COUNT));
1027 for(i = 1; i <= NOTIF_INFO_COUNT; ++i)
1029 e = Get_Notif_Ent(MSG_INFO, i);
1030 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1033 "0 = off, 1 = print to console, "
1034 "2 = print to console and chatbox (if notification_allow_chatboxprint is enabled)"
1038 NOTIF_WRITE(sprintf("\n// MSG_CENTER notifications (count = %d):\n", NOTIF_CENTER_COUNT));
1039 for(i = 1; i <= NOTIF_CENTER_COUNT; ++i)
1041 e = Get_Notif_Ent(MSG_CENTER, i);
1042 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1045 "0 = off, 1 = centerprint"
1049 NOTIF_WRITE(sprintf("\n// MSG_MULTI notifications (count = %d):\n", NOTIF_MULTI_COUNT));
1050 for(i = 1; i <= NOTIF_MULTI_COUNT; ++i)
1052 e = Get_Notif_Ent(MSG_MULTI, i);
1053 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1056 "Enable this multiple notification"
1060 NOTIF_WRITE(sprintf("\n// MSG_CHOICE notifications (count = %d):\n", NOTIF_CHOICE_COUNT));
1061 for(i = 1; i <= NOTIF_CHOICE_COUNT; ++i)
1063 e = Get_Notif_Ent(MSG_CHOICE, i);
1064 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1066 NOTIF_WRITE_ENTITY_CHOICE(
1067 "Choice for this notification 0 = off, 1 = default message, 2 = verbose message",
1068 "Allow choice for this notification 0 = off, 1 = only in warmup mode, 2 = always"
1072 // edit these to match whichever cvars are used for specific notification options
1073 NOTIF_WRITE("\n// HARD CODED notification variables:\n");
1075 NOTIF_WRITE_HARDCODED(
1076 "allow_chatboxprint", "1",
1077 "Allow INFO notifications to be printed to chat box"
1078 "0 = do not allow, "
1079 "1 = allow only if allowed by individual notification_INFO* cvars, "
1080 "2 = force all INFO notifications to be printed to the chatbox"
1083 NOTIF_WRITE_HARDCODED(
1085 "Print extra debug information on all notification function calls "
1086 "(Requires -DNOTIFICATIONS_DEBUG flag to be enabled on QCSRC compilation)... "
1087 "0 = disabled, 1 = dprint, 2 = print"
1090 NOTIF_WRITE_HARDCODED(
1091 "errors_are_fatal", "1",
1092 "If a notification fails upon initialization, cause a Host_Error to stop the program"
1095 NOTIF_WRITE_HARDCODED(
1096 "item_centerprinttime", "1.5",
1097 "How long to show item information centerprint messages (like 'You got the Electro' or such)"
1100 NOTIF_WRITE_HARDCODED(
1101 "lifetime_mapload", "10",
1102 "Amount of time that notification entities last immediately at mapload (in seconds) "
1103 "to help prevent notifications from being lost on early init (like gamestart countdown)"
1106 NOTIF_WRITE_HARDCODED(
1107 "lifetime_runtime", "0.5",
1108 "Amount of time that notification entities last on the server during runtime (In seconds)"
1111 NOTIF_WRITE_HARDCODED(
1112 "server_allows_location", "1",
1113 "Server side cvar for allowing death messages to show location information too"
1116 NOTIF_WRITE_HARDCODED(
1117 "show_location", "0",
1118 "Append location information to MSG_INFO death/kill messages"
1121 NOTIF_WRITE_HARDCODED(
1122 "show_location_string", "",
1123 "Replacement string piped into sprintf, "
1124 "so you can do different messages like this: ' at the %s' or ' (near %s)'"
1127 NOTIF_WRITE_HARDCODED(
1129 "Print information about sprees in death/kill messages"
1132 NOTIF_WRITE_HARDCODED(
1133 "show_sprees_center", "1",
1134 "Show spree information in MSG_CENTER messages... "
1135 "0 = off, 1 = target (but only for first victim) and attacker"
1138 NOTIF_WRITE_HARDCODED(
1139 "show_sprees_center_specialonly", "1",
1140 "Don't show spree information in MSG_CENTER messages if it isn't an achievement"
1143 NOTIF_WRITE_HARDCODED(
1144 "show_sprees_info", "3",
1145 "Show spree information in MSG_INFO messages... "
1146 "0 = off, 1 = target only, 2 = attacker only, 3 = target and attacker"
1149 NOTIF_WRITE_HARDCODED(
1150 "show_sprees_info_newline", "1",
1151 "Show attacker spree information for MSG_INFO messages on a separate line than the death notification itself"
1154 NOTIF_WRITE_HARDCODED(
1155 "show_sprees_info_specialonly", "1",
1156 "Don't show attacker spree information in MSG_INFO messages if it isn't an achievement"
1159 NOTIF_WRITE(sprintf(
1161 "\n// Notification counts (total = %d): ",
1162 "MSG_ANNCE = %d, MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d, MSG_CHOICE = %d\n"
1167 NOTIF_CENTER_COUNT +
1179 #undef NOTIF_WRITE_HARDCODED
1180 #undef NOTIF_WRITE_ENTITY
1185 // ===============================
1186 // Frontend Notification Pushing
1187 // ===============================
1189 #ifdef NOTIFICATIONS_DEBUG
1190 void Debug_Notification(string input)
1192 switch(autocvar_notification_debug)
1194 case 1: { LOG_TRACE(input); break; }
1195 case 2: { LOG_INFO(input); break; }
1200 string Local_Notification_sprintf(
1201 string input, string args,
1202 string s1, string s2, string s3, string s4,
1203 int f1, float f2, float f3, float f4)
1205 #ifdef NOTIFICATIONS_DEBUG
1206 Debug_Notification(sprintf(
1207 "Local_Notification_sprintf('%s^7', '%s', %s, %s);\n",
1208 MakeConsoleSafe(input),
1210 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1211 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1217 for(sel_num = 0; sel_num < NOTIF_MAX_ARGS; ++sel_num) { arg_slot[sel_num] = ""; }
1221 for(sel_num = 0;(args != "");)
1223 selected = car(args); args = cdr(args);
1224 NOTIF_HIT_MAX(NOTIF_MAX_ARGS, "Local_Notification_sprintf");
1225 switch(strtolower(selected))
1228 #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1229 #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1230 #define ARG_CASE_ARG_CS_SV(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1231 #define ARG_CASE_ARG_CS(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1232 #define ARG_CASE_ARG_SV(selected,result)
1233 #define ARG_CASE_ARG_DC(selected,result)
1235 #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1236 #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1237 #define ARG_CASE_ARG_CS_SV(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1238 #define ARG_CASE_ARG_CS(selected,result)
1239 #define ARG_CASE_ARG_SV(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1240 #define ARG_CASE_ARG_DC(selected,result)
1242 #define ARG_CASE(prog,selected,result) ARG_CASE_##prog(selected,result)
1245 #undef ARG_CASE_ARG_DC
1246 #undef ARG_CASE_ARG_SV
1247 #undef ARG_CASE_ARG_CS
1248 #undef ARG_CASE_ARG_CS_SV
1249 #undef ARG_CASE_ARG_CS_SV_DC
1250 #undef ARG_CASE_ARG_CS_SV_HA
1251 default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
1255 strcat(input, "\n"),
1267 void Local_Notification_sound(
1268 float soundchannel, string soundfile,
1269 float soundvolume, float soundposition)
1271 if((soundfile != prev_soundfile) || (time >= (prev_soundtime + autocvar_cl_announcer_antispam)))
1273 #ifdef NOTIFICATIONS_DEBUG
1274 Debug_Notification(sprintf(
1275 "Local_Notification_sound(world, %f, '%s', %f, %f);\n",
1278 "announcer/%s/%s.wav",
1279 autocvar_cl_announcer,
1291 "announcer/%s/%s.wav",
1292 autocvar_cl_announcer,
1299 if(prev_soundfile) { strunzone(prev_soundfile); }
1300 prev_soundfile = strzone(soundfile);
1301 prev_soundtime = time;
1305 #ifdef NOTIFICATIONS_DEBUG
1306 Debug_Notification(sprintf(
1308 "Local_Notification_sound(world, %f, '%s', %f, %f) ",
1309 "^1BLOCKED BY ANTISPAM:^7 prevsnd: '%s', timediff: %f, limit: %f\n"
1313 "announcer/%s/%s.wav",
1314 autocvar_cl_announcer,
1320 (time - prev_soundtime),
1321 autocvar_cl_announcer_antispam
1327 void Local_Notification_HUD_Notify_Push(
1328 string icon, string hudargs,
1329 string s1, string s2, string s3, string s4,
1330 float f1, float f2, float f3, float f4)
1333 arg_slot[0] = ""; arg_slot[1] = "";
1336 for(sel_num = 0;(hudargs != "");)
1338 selected = car(hudargs); hudargs = cdr(hudargs);
1339 NOTIF_HIT_MAX(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push");
1340 switch(strtolower(selected))
1342 #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1343 #define ARG_CASE_ARG_CS_SV_DC(selected,result)
1344 #define ARG_CASE_ARG_CS_SV(selected,result)
1345 #define ARG_CASE_ARG_CS(selected,result)
1346 #define ARG_CASE_ARG_SV(selected,result)
1347 #define ARG_CASE_ARG_DC(selected,result)
1348 #define ARG_CASE(prog,selected,result) ARG_CASE_##prog(selected,result)
1351 #undef ARG_CASE_ARG_DC
1352 #undef ARG_CASE_ARG_SV
1353 #undef ARG_CASE_ARG_CS
1354 #undef ARG_CASE_ARG_CS_SV
1355 #undef ARG_CASE_ARG_CS_SV_DC
1356 #undef ARG_CASE_ARG_CS_SV_HA
1357 default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
1360 #ifdef NOTIFICATIONS_DEBUG
1361 Debug_Notification(sprintf(
1362 "Local_Notification_HUD_Notify_Push('%s^7', '%s', %s, %s, %s);\n",
1365 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1366 sprintf("%d, %d, %d, %d", f1, f2, f3, f4),
1367 MakeConsoleSafe(sprintf("'%s^7', '%s^7'", stof(arg_slot[0]), stof(arg_slot[1])))
1370 HUD_Notify_Push(icon, arg_slot[0], arg_slot[1]);
1373 void Local_Notification_centerprint_generic(
1374 string input, string durcnt,
1375 int cpid, float f1, float f2)
1377 arg_slot[0] = ""; arg_slot[1] = "";
1379 for(int sel_num = 0;(durcnt != "");)
1381 string selected = car(durcnt); durcnt = cdr(durcnt);
1382 NOTIF_HIT_MAX(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic");
1383 switch(strtolower(selected))
1385 #define ARG_CASE_ARG_CS_SV_HA(selected,result)
1386 #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1387 #define ARG_CASE_ARG_CS_SV(selected,result)
1388 #define ARG_CASE_ARG_CS(selected,result)
1389 #define ARG_CASE_ARG_SV(selected,result)
1390 #define ARG_CASE_ARG_DC(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1391 #define ARG_CASE(prog,selected,result) ARG_CASE_##prog(selected,result)
1394 #undef ARG_CASE_ARG_DC
1395 #undef ARG_CASE_ARG_SV
1396 #undef ARG_CASE_ARG_CS
1397 #undef ARG_CASE_ARG_CS_SV
1398 #undef ARG_CASE_ARG_CS_SV_DC
1399 #undef ARG_CASE_ARG_CS_SV_HA
1402 if(ftos(stof(selected)) != "") { arg_slot[sel_num] = selected; ++sel_num; }
1403 else { NOTIF_HIT_UNKNOWN(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic") }
1408 #ifdef NOTIFICATIONS_DEBUG
1409 Debug_Notification(sprintf(
1410 "Local_Notification_centerprint_generic('%s^7', '%s', %d, %d, %d, %d);\n",
1411 MakeConsoleSafe(input),
1418 centerprint_generic(cpid, input, stof(arg_slot[0]), stof(arg_slot[1]));
1422 void Local_Notification(int net_type, int net_name, ...count)
1424 // check if this should be aborted
1425 if(net_name == NOTIF_ABORT)
1427 #ifdef NOTIFICATIONS_DEBUG
1428 Debug_Notification(sprintf(
1429 "Local_Notification(%s, %s, ...);\n",
1430 Get_Notif_TypeName(net_type),
1437 // check supplied type and name for errors
1438 string checkargs = Notification_CheckArgs_TypeName(net_type, net_name);
1441 #ifdef NOTIFICATIONS_DEBUG
1442 Debug_Notification(sprintf(
1443 "Local_Notification(%s, %d, ...);\n",
1444 Get_Notif_TypeName(net_type),
1445 Get_Notif_Ent(net_type, net_name).nent_name
1448 backtrace(sprintf("Incorrect usage of Local_Notification: %s\n", checkargs));
1452 // retreive entity of this notification
1453 entity notif = Get_Notif_Ent(net_type, net_name);
1456 #ifdef NOTIFICATIONS_DEBUG
1457 Debug_Notification(sprintf(
1458 "Local_Notification(%s, %d, ...);\n",
1459 Get_Notif_TypeName(net_type),
1463 backtrace("Local_Notification: Could not find notification entity!\n");
1467 // check if the notification is enabled
1468 if (!notif.nent_enabled)
1470 #ifdef NOTIFICATIONS_DEBUG
1471 Debug_Notification(sprintf(
1472 "Local_Notification(%s, %s, ...): Entity was disabled...\n",
1473 Get_Notif_TypeName(net_type),
1480 string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
1481 string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
1482 string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
1483 string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
1484 float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
1485 float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
1486 float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
1487 float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
1489 #ifdef NOTIFICATIONS_DEBUG
1490 Debug_Notification(sprintf(
1491 "Local_Notification(%s, %s, %s, %s);\n",
1492 Get_Notif_TypeName(net_type),
1494 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1495 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1499 if((notif.nent_stringcount + notif.nent_floatcount) > count)
1503 "Not enough arguments for Local_Notification(%s, %s, ...)! ",
1504 "stringcount(%d) + floatcount(%d) > count(%d)\n",
1505 "Check the definition and function call for accuracy...?\n"
1507 Get_Notif_TypeName(net_type),
1509 notif.nent_stringcount,
1510 notif.nent_floatcount,
1515 else if((notif.nent_stringcount + notif.nent_floatcount) < count)
1519 "Too many arguments for Local_Notification(%s, %s, ...)! ",
1520 "stringcount(%d) + floatcount(%d) < count(%d)\n",
1521 "Check the definition and function call for accuracy...?\n"
1523 Get_Notif_TypeName(net_type),
1525 notif.nent_stringcount,
1526 notif.nent_floatcount,
1537 Local_Notification_sound(
1544 backtrace("MSG_ANNCE on server?... Please notify Samual immediately!\n");
1552 void(string) echo = CSQC_Parse_Print;
1554 void(string, ...) echo = print;
1557 Local_Notification_sprintf(
1564 if(notif.nent_icon != "")
1566 if ( notif.nent_iconargs != "" )
1568 notif.nent_icon = Local_Notification_sprintf(
1569 notif.nent_icon,notif.nent_iconargs,
1570 s1, s2, s3, s4, f1, f2, f3, f4);
1571 // remove the newline added by Local_Notification_sprintf
1572 notif.nent_icon = strzone(substring(notif.nent_icon,0,strlen(notif.nent_icon)-1));
1574 Local_Notification_HUD_Notify_Push(
1587 Local_Notification_centerprint_generic(
1588 Local_Notification_sprintf(
1602 if(notif.nent_msginfo)
1603 if(notif.nent_msginfo.nent_enabled)
1605 Local_Notification_WOVA(
1607 notif.nent_msginfo.nent_id,
1608 notif.nent_msginfo.nent_stringcount,
1609 notif.nent_msginfo.nent_floatcount,
1614 if(notif.nent_msgannce)
1615 if(notif.nent_msgannce.nent_enabled)
1617 Local_Notification_WOVA(
1619 notif.nent_msgannce.nent_id,
1624 if(notif.nent_msgcenter)
1625 if(notif.nent_msgcenter.nent_enabled)
1627 Local_Notification_WOVA(
1629 notif.nent_msgcenter.nent_id,
1630 notif.nent_msgcenter.nent_stringcount,
1631 notif.nent_msgcenter.nent_floatcount,
1641 entity found_choice;
1643 if(notif.nent_challow_var && (warmup_stage || (notif.nent_challow_var == 2)))
1645 switch(cvar(sprintf("notification_%s", notif.nent_name)))
1647 case 1: found_choice = notif.nent_optiona; break;
1648 case 2: found_choice = notif.nent_optionb; break;
1649 default: return; // not enabled anyway
1652 else { found_choice = notif.nent_optiona; }
1654 Local_Notification_WOVA(
1655 found_choice.nent_type,
1656 found_choice.nent_id,
1657 found_choice.nent_stringcount,
1658 found_choice.nent_floatcount,
1665 // WOVA = Without Variable Arguments
1666 void Local_Notification_WOVA(
1667 int net_type, float net_name,
1668 float stringcount, float floatcount,
1669 string s1, string s2, string s3, string s4,
1670 float f1, float f2, float f3, float f4)
1672 #define VARITEM(stringc,floatc,args) \
1673 if((stringcount == stringc) && (floatcount == floatc)) \
1674 { Local_Notification(net_type, net_name, args); return; }
1675 EIGHT_VARS_TO_VARARGS_VARLIST
1677 Local_Notification(net_type, net_name); // some notifications don't have any arguments at all
1681 // =========================
1682 // Notification Networking
1683 // =========================
1686 void Read_Notification(float is_new)
1688 int net_type = ReadByte();
1689 int net_name = ReadShort();
1693 if(net_type == MSG_CENTER_CPID)
1695 #ifdef NOTIFICATIONS_DEBUG
1696 Debug_Notification(sprintf(
1697 "Read_Notification(%d) at %f: net_type = %s, net_name = %d\n",
1700 Get_Notif_TypeName(net_type),
1707 if(net_name == 0) { reset_centerprint_messages(); }
1708 else if(net_name != NO_CPID)
1710 // in this case, net_name IS the cpid we want to kill
1711 centerprint_generic(net_name, "", 0, 0);
1716 "Read_Notification(%d) at %f: ^1TRIED TO KILL NO_CPID CENTERPRINT!\n",
1725 notif = Get_Notif_Ent(net_type, net_name);
1726 if (!notif) { backtrace("Read_Notification: Could not find notification entity!\n"); return; }
1728 #ifdef NOTIFICATIONS_DEBUG
1729 Debug_Notification(sprintf(
1730 "Read_Notification(%d) at %f: net_type = %s, net_name = %s\n",
1733 Get_Notif_TypeName(net_type),
1738 string s1 = ((0 < notif.nent_stringcount) ? ReadString() : "");
1739 string s2 = ((1 < notif.nent_stringcount) ? ReadString() : "");
1740 string s3 = ((2 < notif.nent_stringcount) ? ReadString() : "");
1741 string s4 = ((3 < notif.nent_stringcount) ? ReadString() : "");
1742 float f1 = ((0 < notif.nent_floatcount) ? ReadLong() : 0);
1743 float f2 = ((1 < notif.nent_floatcount) ? ReadLong() : 0);
1744 float f3 = ((2 < notif.nent_floatcount) ? ReadLong() : 0);
1745 float f4 = ((3 < notif.nent_floatcount) ? ReadLong() : 0);
1749 Local_Notification_WOVA(
1751 notif.nent_stringcount,
1752 notif.nent_floatcount,
1761 void Net_Notification_Remove()
1763 if (!self) { backtrace(sprintf("Net_Notification_Remove() at %f: Missing self!?\n", time)); return; }
1765 #ifdef NOTIFICATIONS_DEBUG
1766 Debug_Notification(sprintf(
1767 "Net_Notification_Remove() at %f: %s '%s - %s' notification\n",
1769 ((self.nent_net_name == -1) ? "Killed" : "Removed"),
1770 Get_Notif_TypeName(self.nent_net_type),
1771 self.owner.nent_name
1775 for(int i = 0; i < 4; ++i) { if(self.nent_strings[i]) { strunzone(self.nent_strings[i]); } }
1779 bool Net_Write_Notification(entity this, entity client, int sf)
1781 if(Notification_ShouldSend(self.nent_broadcast, client, self.nent_client))
1783 WriteByte(MSG_ENTITY, ENT_CLIENT_NOTIFICATION);
1784 WriteByte(MSG_ENTITY, self.nent_net_type);
1785 WriteShort(MSG_ENTITY, self.nent_net_name);
1786 for(int i = 0; i < self.nent_stringcount; ++i) { WriteString(MSG_ENTITY, self.nent_strings[i]); }
1787 for(int i = 0; i < self.nent_floatcount; ++i) { WriteLong(MSG_ENTITY, self.nent_floats[i]); }
1790 else { return false; }
1793 void Kill_Notification(
1794 float broadcast, entity client,
1795 float net_type, float net_name)
1797 #ifdef NOTIFICATIONS_DEBUG
1798 Debug_Notification(sprintf(
1799 "Kill_Notification(%s, '%s', %s, %d);\n",
1800 Get_Notif_BroadcastName(broadcast),
1802 (net_type ? Get_Notif_TypeName(net_type) : "0"),
1807 string checkargs = Notification_CheckArgs(broadcast, client, 1, 1);
1808 if(checkargs != "") { backtrace(sprintf("Incorrect usage of Kill_Notification: %s\n", checkargs)); return; }
1810 entity notif, net_notif;
1811 float killed_cpid = NO_CPID;
1817 killed_cpid = 0; // kill ALL centerprints
1825 entity notif = Get_Notif_Ent(net_type, net_name);
1826 if (!notif) { backtrace("Kill_Notification: Could not find notification entity!\n"); return; }
1829 killed_cpid = notif.nent_cpid;
1831 killed_cpid = NO_CPID;
1835 killed_cpid = 0; // kill ALL centerprints
1840 case MSG_CENTER_CPID:
1842 killed_cpid = net_name;
1847 if(killed_cpid != NO_CPID)
1849 net_notif = spawn();
1850 net_notif.classname = "net_kill_notification";
1851 net_notif.nent_broadcast = broadcast;
1852 net_notif.nent_client = client;
1853 net_notif.nent_net_type = MSG_CENTER_CPID;
1854 net_notif.nent_net_name = killed_cpid;
1855 Net_LinkEntity(net_notif, false, autocvar_notification_lifetime_runtime, Net_Write_Notification);
1858 for(notif = world; (notif = find(notif, classname, "net_notification"));)
1862 if((killed_cpid != NO_CPID) && (notif.nent_net_type == MSG_CENTER))
1864 if(notif.owner.nent_cpid == killed_cpid)
1866 notif.nent_net_name = -1;
1867 notif.nextthink = time;
1869 else { continue; } // we ARE looking for a specific CPID, don't kill everything else too
1871 else if(notif.nent_net_type == net_type)
1875 if(notif.nent_net_name == net_name) { notif.nent_net_name = -1; notif.nextthink = time; }
1876 else { continue; } // we ARE looking for a certain net_name, don't kill everything else too
1878 else { notif.nent_net_name = -1; notif.nextthink = time; }
1880 else { continue; } // we ARE looking for a certain net_type, don't kill everything else too
1882 else { notif.nent_net_name = -1; notif.nextthink = time; }
1886 void Send_Notification(
1887 float broadcast, entity client,
1888 float net_type, float net_name,
1891 // check if this should be aborted
1892 if(net_name == NOTIF_ABORT)
1894 #ifdef NOTIFICATIONS_DEBUG
1895 Debug_Notification(sprintf(
1896 "Send_Notification(%s, '%s', %s, %s, ...);\n",
1897 Get_Notif_BroadcastName(broadcast),
1899 Get_Notif_TypeName(net_type),
1906 // check supplied broadcast, target, type, and name for errors
1907 string checkargs = Notification_CheckArgs(broadcast, client, net_type, net_name);
1910 #ifdef NOTIFICATIONS_DEBUG
1911 Debug_Notification(sprintf(
1912 "Send_Notification(%s, '%s', %s, %s, ...);\n",
1913 Get_Notif_BroadcastName(broadcast),
1915 Get_Notif_TypeName(net_type),
1916 Get_Notif_Ent(net_type, net_name).nent_name
1919 backtrace(sprintf("Incorrect usage of Send_Notification: %s\n", checkargs));
1923 // retreive entity of this notification
1924 entity notif = Get_Notif_Ent(net_type, net_name);
1927 #ifdef NOTIFICATIONS_DEBUG
1928 Debug_Notification(sprintf(
1929 "Send_Notification(%s, '%s', %s, %d, ...);\n",
1930 Get_Notif_BroadcastName(broadcast),
1932 Get_Notif_TypeName(net_type),
1936 backtrace("Send_Notification: Could not find notification entity!\n");
1940 string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
1941 string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
1942 string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
1943 string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
1944 float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
1945 float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
1946 float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
1947 float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
1949 #ifdef NOTIFICATIONS_DEBUG
1950 Debug_Notification(sprintf(
1951 "Send_Notification(%s, %s, %s);\n",
1954 Get_Notif_BroadcastName(broadcast),
1956 Get_Notif_TypeName(net_type),
1959 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1960 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1964 if((notif.nent_stringcount + notif.nent_floatcount) > count)
1967 #ifdef NOTIFICATIONS_DEBUG
1968 Get_Notif_BroadcastName(broadcast);
1974 "Not enough arguments for Send_Notification(%s, ...)! ",
1975 "stringcount(%d) + floatcount(%d) > count(%d)\n",
1976 "Check the definition and function call for accuracy...?\n"
1982 Get_Notif_TypeName(net_type),
1985 notif.nent_stringcount,
1986 notif.nent_floatcount,
1991 else if((notif.nent_stringcount + notif.nent_floatcount) < count)
1994 #ifdef NOTIFICATIONS_DEBUG
1995 Get_Notif_BroadcastName(broadcast);
2001 "Too many arguments for Send_Notification(%s, ...)! ",
2002 "stringcount(%d) + floatcount(%d) < count(%d)\n",
2003 "Check the definition and function call for accuracy...?\n"
2009 Get_Notif_TypeName(net_type),
2012 notif.nent_stringcount,
2013 notif.nent_floatcount,
2023 broadcast == NOTIF_ALL
2025 broadcast == NOTIF_ALL_EXCEPT
2029 net_type == MSG_ANNCE
2031 net_type == MSG_CENTER
2035 Local_Notification_WOVA(
2037 notif.nent_stringcount,
2038 notif.nent_floatcount,
2043 if(net_type == MSG_CHOICE)
2045 // THIS GETS TRICKY... now we have to cycle through each possible player (checking broadcast)
2046 // and then do an individual NOTIF_ONE_ONLY recursive call for each one depending on their option...
2047 // It's slow, but it's better than the alternatives:
2048 // 1. Constantly networking all info and letting client decide
2049 // 2. Manually handling each separate call on per-usage basis (See old CTF usage of verbose)
2050 entity found_choice;
2052 #define RECURSE_FROM_CHOICE(ent,action) do { \
2053 if(notif.nent_challow_var && (warmup_stage || (notif.nent_challow_var == 2))) \
2055 switch(ent.msg_choice_choices[net_name - 1]) \
2057 case 1: found_choice = notif.nent_optiona; break; \
2058 case 2: found_choice = notif.nent_optionb; break; \
2062 else { found_choice = notif.nent_optiona; } \
2063 Send_Notification_WOVA( \
2066 found_choice.nent_type, \
2067 found_choice.nent_id, \
2068 found_choice.nent_stringcount, \
2069 found_choice.nent_floatcount, \
2076 case NOTIF_ONE_ONLY: // we can potentially save processing power with this broadcast method
2078 if(IS_REAL_CLIENT(client))
2080 RECURSE_FROM_CHOICE(client, return);
2087 FOR_EACH_REALCLIENT(to)
2089 if(Notification_ShouldSend(broadcast, to, client))
2091 RECURSE_FROM_CHOICE(to, continue);
2100 entity net_notif = spawn();
2101 net_notif.owner = notif;
2102 net_notif.classname = "net_notification";
2103 net_notif.nent_broadcast = broadcast;
2104 net_notif.nent_client = client;
2105 net_notif.nent_net_type = net_type;
2106 net_notif.nent_net_name = net_name;
2107 net_notif.nent_stringcount = notif.nent_stringcount;
2108 net_notif.nent_floatcount = notif.nent_floatcount;
2110 for(int i = 0; i < net_notif.nent_stringcount; ++i)
2111 { net_notif.nent_strings[i] = strzone(...(i, string)); }
2112 for(int i = 0; i < net_notif.nent_floatcount; ++i)
2113 { net_notif.nent_floats[i] = ...((net_notif.nent_stringcount + i), float); }
2115 net_notif.think = Net_Notification_Remove;
2116 net_notif.nextthink =
2117 ((time > autocvar_notification_lifetime_mapload)
2119 (time + autocvar_notification_lifetime_runtime)
2121 autocvar_notification_lifetime_mapload
2124 Net_LinkEntity(net_notif, false, 0, Net_Write_Notification);
2128 // WOVA = Without Variable Arguments
2129 void Send_Notification_WOVA(
2130 float broadcast, entity client,
2131 float net_type, float net_name,
2132 float stringcount, float floatcount,
2133 string s1, string s2, string s3, string s4,
2134 float f1, float f2, float f3, float f4)
2136 #ifdef NOTIFICATIONS_DEBUG
2137 entity notif = Get_Notif_Ent(net_type, net_name);
2138 Debug_Notification(sprintf(
2139 "Send_Notification_WOVA(%s, %d, %d, %s, %s);\n",
2142 Get_Notif_BroadcastName(broadcast),
2144 Get_Notif_TypeName(net_type),
2149 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
2150 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
2154 #define VARITEM(stringc,floatc,args) \
2155 if((stringcount == stringc) && (floatcount == floatc)) \
2156 { Send_Notification(broadcast, client, net_type, net_name, args); return; }
2157 EIGHT_VARS_TO_VARARGS_VARLIST
2159 Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
2162 // WOCOVA = Without Counts Or Variable Arguments
2163 void Send_Notification_WOCOVA(
2164 float broadcast, entity client,
2165 float net_type, float net_name,
2166 string s1, string s2, string s3, string s4,
2167 float f1, float f2, float f3, float f4)
2169 entity notif = Get_Notif_Ent(net_type, net_name);
2171 #ifdef NOTIFICATIONS_DEBUG
2172 Debug_Notification(sprintf(
2173 "Send_Notification_WOCOVA(%s, %s, %s);\n",
2176 Get_Notif_BroadcastName(broadcast),
2178 Get_Notif_TypeName(net_type),
2181 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
2182 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
2186 #define VARITEM(stringc,floatc,args) \
2187 if((notif.nent_stringcount == stringc) && (notif.nent_floatcount == floatc)) \
2188 { Send_Notification(broadcast, client, net_type, net_name, args); return; }
2189 EIGHT_VARS_TO_VARARGS_VARLIST
2191 Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
2193 #endif // ifdef SVQC