4 #include "../dpdefs/progsdefs.qh"
5 #include "../dpdefs/dpextensions.qh"
6 #include "constants.qh"
9 #include "../server/autocvars.qh"
10 #include "../server/constants.qh"
11 #include "../server/defs.qh"
12 #include "notifications.qh"
13 #include "../server/mutators/mutators_include.qh"
16 // ================================================
17 // Unified notification system, written by Samual
18 // Last updated: August, 2013
19 // ================================================
21 string Get_Notif_TypeName(int net_type)
25 case MSG_ANNCE: return "MSG_ANNCE";
26 case MSG_INFO: return "MSG_INFO";
27 case MSG_CENTER: return "MSG_CENTER";
28 case MSG_CENTER_CPID: return "MSG_CENTER_CPID";
29 case MSG_MULTI: return "MSG_MULTI";
30 case MSG_CHOICE: return "MSG_CHOICE";
32 backtrace(sprintf("Get_Notif_TypeName(%d): Improper net type!\n", net_type));
36 entity Get_Notif_Ent(int net_type, int net_name)
40 case MSG_ANNCE: return msg_annce_notifs[net_name - 1];
41 case MSG_INFO: return msg_info_notifs[net_name - 1];
42 case MSG_CENTER: return msg_center_notifs[net_name - 1];
43 case MSG_MULTI: return msg_multi_notifs[net_name - 1];
44 case MSG_CHOICE: return msg_choice_notifs[net_name - 1];
46 backtrace(sprintf("Get_Notif_Ent(%d, %d): Improper net type!\n", net_type, net_name));
51 #ifdef NOTIFICATIONS_DEBUG
52 string Get_Notif_BroadcastName(float broadcast)
56 case NOTIF_ONE: return "NOTIF_ONE";
57 case NOTIF_ONE_ONLY: return "NOTIF_ONE_ONLY";
58 case NOTIF_ALL_EXCEPT: return "NOTIF_ALL_EXCEPT";
59 case NOTIF_ALL: return "NOTIF_ALL";
60 case NOTIF_TEAM: return "NOTIF_TEAM";
61 case NOTIF_TEAM_EXCEPT: return "NOTIF_TEAM_EXCEPT";
63 backtrace(sprintf("Get_Notif_BroadcastName(%d): Improper broadcast!\n", broadcast));
69 string Notification_CheckArgs_TypeName(float net_type, float net_name)
71 // check supplied type and name for errors
72 string checkargs = "";
73 #define CHECKARG_TYPENAME(type) case MSG_##type##: \
74 { if(!net_name || (net_name > NOTIF_##type##_COUNT)) \
75 { checkargs = sprintf("Improper name: %d!", net_name); } break; }
78 CHECKARG_TYPENAME(ANNCE)
79 CHECKARG_TYPENAME(INFO)
80 CHECKARG_TYPENAME(CENTER)
81 CHECKARG_TYPENAME(MULTI)
82 CHECKARG_TYPENAME(CHOICE)
83 default: { checkargs = sprintf("Improper type: %d!", checkargs, net_type); break; }
85 #undef CHECKARG_TYPENAME
90 string Notification_CheckArgs(
91 float broadcast, entity client,
92 float net_type, float net_name)
94 // check supplied broadcast, target, type, and name for errors
95 string checkargs = Notification_CheckArgs_TypeName(net_type, net_name);
96 if(checkargs != "") { checkargs = strcat(checkargs, " "); }
102 if(IS_NOT_A_CLIENT(client))
103 { checkargs = sprintf("%sNo client provided!", checkargs); }
107 case NOTIF_ALL_EXCEPT:
109 if(IS_NOT_A_CLIENT(client))
110 { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
117 { checkargs = sprintf("%sEntity provided when world was required!", checkargs); }
124 { checkargs = sprintf("%sTeamplay not active!", checkargs); }
125 //else if (!client.team) { checkargs = sprintf("%sNo team provided!", checkargs); }
129 case NOTIF_TEAM_EXCEPT:
132 { checkargs = sprintf("%sTeamplay not active!", checkargs); }
133 else if(IS_NOT_A_CLIENT(client))
134 { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
138 default: { checkargs = sprintf("%sImproper broadcast: %d!", checkargs, broadcast); break; }
143 float Notification_ShouldSend(float broadcast, entity to_client, entity other_client)
147 case NOTIF_ONE: // send to one client and their spectator
150 (to_client == other_client)
155 (to_client.enemy == other_client)
160 case NOTIF_ONE_ONLY: // send ONLY to one client
162 if(to_client == other_client) { return true; }
165 case NOTIF_TEAM: // send only to X team and their spectators
168 (to_client.team == other_client.team)
173 (to_client.enemy.team == other_client.team)
178 case NOTIF_TEAM_EXCEPT: // send only to X team and their spectators, except for Y person and their spectators
181 (to_client != other_client)
184 (to_client.team == other_client.team)
190 (to_client.enemy != other_client)
192 (to_client.enemy.team == other_client.team)
199 case NOTIF_ALL: // send to everyone
203 case NOTIF_ALL_EXCEPT: // send to everyone except X person and their spectators
206 (to_client != other_client)
211 (to_client.enemy == other_client)
222 // ===============================
223 // Initialization Core Functions
224 // ===============================
226 // used by restartnotifs command to initialize notifications
227 void Destroy_Notification_Entity(entity notif)
229 if(notif.nent_name != "") { strunzone(notif.nent_name); }
230 if(notif.nent_snd != "") { strunzone(notif.nent_snd); }
231 if(notif.nent_args != "") { strunzone(notif.nent_args); }
232 if(notif.nent_hudargs != "") { strunzone(notif.nent_hudargs); }
233 if(notif.nent_icon != "") { strunzone(notif.nent_icon); }
234 if(notif.nent_durcnt != "") { strunzone(notif.nent_durcnt); }
235 if(notif.nent_string != "") { strunzone(notif.nent_string); }
239 void Destroy_All_Notifications(void)
244 #define DESTROY_LOOP(type,count) do { \
245 for(i = 1; i <= count; ++i) \
247 notif = Get_Notif_Ent(type, i); \
248 if (!notif) { backtrace("Destroy_All_Notifications(): Missing notification entity!\n"); return; } \
249 Destroy_Notification_Entity(notif); \
253 // kill all networked notifications and centerprints
255 Kill_Notification(NOTIF_ALL, world, 0, 0);
257 reset_centerprint_messages();
260 // kill all real notification entities
261 DESTROY_LOOP(MSG_ANNCE, NOTIF_ANNCE_COUNT);
262 DESTROY_LOOP(MSG_INFO, NOTIF_INFO_COUNT);
263 DESTROY_LOOP(MSG_CENTER, NOTIF_CENTER_COUNT);
264 DESTROY_LOOP(MSG_MULTI, NOTIF_MULTI_COUNT);
265 DESTROY_LOOP(MSG_CHOICE, NOTIF_CHOICE_COUNT);
269 string Process_Notif_Line(
278 if(typeId == MSG_INFO)
280 if((chat && autocvar_notification_allow_chatboxprint)
281 || (autocvar_notification_allow_chatboxprint == 2))
283 // pass 1: add ETX char at beginning of line
284 input = strcat("\{3}", input);
286 // pass 2: add ETX char at end of each new line (so that
287 // messages with multiple lines are put through chatbox too)
288 input = strreplace("\n", "\n\{3}", input);
290 // pass 3: strip trailing ETX char
291 if(substring(input, (strlen(input) - 1), 1) == "\{3}")
292 { input = substring(input, 0, (strlen(input) - 1)); }
297 // done to both MSG_INFO and MSG_CENTER
298 if(substring(input, (strlen(input) - 1), 1) == "\n")
302 "^1TRAILING NEW LINE AT END OF NOTIFICATION: ",
303 "^7net_type = %s, net_name = %s, string = %s.\n"
310 input = substring(input, 1, (strlen(input) - 1));
316 string Process_Notif_Args(
322 string selected, remaining = args;
325 for(0;(remaining != "");)
327 selected = car(remaining); remaining = cdr(remaining);
331 case 1: // normal args
333 if(sel_num == NOTIF_MAX_ARGS)
337 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
338 "^7net_type = %s, net_name = %s, max args = %d.\n"
348 switch(strtolower(selected))
350 #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { ++sel_num; break; }
351 #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { ++sel_num; break; }
352 #define ARG_CASE_ARG_CS_SV(selected,result) case selected: { ++sel_num; break; }
353 #define ARG_CASE_ARG_CS(selected,result) case selected: { ++sel_num; break; }
354 #define ARG_CASE_ARG_SV(selected,result) case selected: { ++sel_num; break; }
355 #define ARG_CASE_ARG_DC(selected,result)
356 #define ARG_CASE(prog,selected,result) ARG_CASE_##prog(selected,result)
359 #undef ARG_CASE_ARG_DC
360 #undef ARG_CASE_ARG_SV
361 #undef ARG_CASE_ARG_CS
362 #undef ARG_CASE_ARG_CS_SV
363 #undef ARG_CASE_ARG_CS_SV_DC
364 #undef ARG_CASE_ARG_CS_SV_HA
369 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
370 "^7net_type = %s, net_name = %s, args arg = '%s'.\n"
384 if(sel_num == NOTIF_MAX_HUDARGS)
388 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
389 "^7net_type = %s, net_name = %s, max hudargs = %d.\n"
399 switch(strtolower(selected))
401 #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { ++sel_num; break; }
402 #define ARG_CASE_ARG_CS_SV_DC(selected,result)
403 #define ARG_CASE_ARG_CS_SV(selected,result)
404 #define ARG_CASE_ARG_CS(selected,result)
405 #define ARG_CASE_ARG_SV(selected,result)
406 #define ARG_CASE_ARG_DC(selected,result)
407 #define ARG_CASE(prog,selected,result) ARG_CASE_##prog(selected,result)
410 #undef ARG_CASE_ARG_DC
411 #undef ARG_CASE_ARG_SV
412 #undef ARG_CASE_ARG_CS
413 #undef ARG_CASE_ARG_CS_SV
414 #undef ARG_CASE_ARG_CS_SV_DC
415 #undef ARG_CASE_ARG_CS_SV_HA
420 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
421 "^7net_type = %s, net_name = %s, hudargs arg = '%s'.\n"
435 if(sel_num == NOTIF_MAX_DURCNT)
439 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
440 "^7net_type = %s, net_name = %s, max durcnt = %d.\n"
450 switch(strtolower(selected))
452 #define ARG_CASE_ARG_CS_SV_HA(selected,result)
453 #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { ++sel_num; break; }
454 #define ARG_CASE_ARG_CS_SV(selected,result)
455 #define ARG_CASE_ARG_CS(selected,result)
456 #define ARG_CASE_ARG_SV(selected,result)
457 #define ARG_CASE_ARG_DC(selected,result) case selected: { ++sel_num; break; }
458 #define ARG_CASE(prog,selected,result) ARG_CASE_##prog(selected,result)
461 #undef ARG_CASE_ARG_DC
462 #undef ARG_CASE_ARG_SV
463 #undef ARG_CASE_ARG_CS
464 #undef ARG_CASE_ARG_CS_SV
465 #undef ARG_CASE_ARG_CS_SV_DC
466 #undef ARG_CASE_ARG_CS_SV_HA
469 if(ftos(stof(selected)) != "") { ++sel_num; }
474 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
475 "^7net_type = %s, net_name = %s, durcnt arg = '%s'.\n"
493 void Create_Notification_Entity(
506 /* MSG_INFO & MSG_CENTER */
525 // =====================
526 // Global Entity Setup
527 // =====================
528 entity notif = spawn();
533 msg_annce_notifs[nameid - 1] = notif;
534 notif.classname = "msg_annce_notification";
539 msg_info_notifs[nameid - 1] = notif;
540 notif.classname = "msg_info_notification";
545 msg_center_notifs[nameid - 1] = notif;
546 notif.classname = "msg_center_notification";
551 msg_multi_notifs[nameid - 1] = notif;
552 notif.classname = "msg_multi_notification";
557 msg_choice_notifs[nameid - 1] = notif;
558 notif.classname = "msg_choice_notification";
566 "^1NOTIFICATION WITH IMPROPER TYPE: ",
567 "^7net_type = %d, net_name = %s.\n"
572 return; // It's not possible to recover from this one
575 notif.nent_default = var_default;
576 notif.nent_enabled = (1 <= var_cvar);
577 notif.nent_type = typeId;
578 notif.nent_id = nameid;
579 notif.nent_name = strzone(namestring);
581 string typestring = Get_Notif_TypeName(typeId);
583 // Other pre-notif-setup requisites
586 // ====================
587 // Notification Setup
588 // ====================
593 // Set MSG_ANNCE information and handle precaching
595 if (!(GENTLE && (var_cvar == 1)))
599 if(notif.nent_enabled)
601 precache_sound(sprintf("announcer/%s/%s.wav", autocvar_cl_announcer, snd));
602 notif.nent_channel = channel;
603 notif.nent_snd = strzone(snd);
604 notif.nent_vol = vol;
605 notif.nent_position = position;
612 "^1NOTIFICATION WITH NO SOUND: ",
613 "^7net_type = %s, net_name = %s.\n"
621 else { notif.nent_enabled = false; }
623 notif.nent_enabled = false;
632 // Set MSG_INFO and MSG_CENTER string/float counts
633 notif.nent_stringcount = strnum;
634 notif.nent_floatcount = flnum;
636 // Only initialize arguments if we're either a client or on a dedicated server
638 float should_process_args = server_is_dedicated;
640 float should_process_args = true;
643 if(should_process_args)
645 // ========================
646 // Process Main Arguments
647 // ========================
652 notif.nent_args = strzone(
653 Process_Notif_Args(1, args, typestring, namestring));
655 else if((hudargs == "") && (durcnt ==""))
659 "^1NOTIFICATION HAS ARG COUNTS BUT NO ARGS OR HUDARGS OR DURCNT: ",
660 "^7net_type = %s, net_name = %s, strnum = %d, flnum = %d\n"
672 notif.nent_args = strzone(
673 Process_Notif_Args(1, args, typestring, namestring));
677 // =======================================
678 // Process HUD and Centerprint Arguments
679 // Only processed on CSQC, as these
680 // args are only for HUD features.
681 // =======================================
685 notif.nent_hudargs = strzone(
686 Process_Notif_Args(2, hudargs, typestring, namestring));
688 if(icon != "") { notif.nent_icon = strzone(icon); }
693 "^1NOTIFICATION HAS HUDARGS BUT NO ICON: ",
694 "^7net_type = %s, net_name = %s.\n"
706 "^1NOTIFICATION HAS ICON BUT NO HUDARGS: ",
707 "^7net_type = %s, net_name = %s.\n"
717 notif.nent_durcnt = strzone(
718 Process_Notif_Args(3, durcnt, typestring, namestring));
720 if(cpid != NO_MSG) { notif.nent_cpid = cpid; }
725 "^1NOTIFICATION HAS DURCNT BUT NO CPID: ",
726 "^7net_type = %s, net_name = %s.\n"
734 else if(cpid != NO_MSG) { notif.nent_cpid = cpid; }
738 // ======================
739 // Process Notif String
740 // ======================
741 #define SET_NOTIF_STRING(string,stringname) do { \
742 notif.nent_string = strzone(CCR( \
743 Process_Notif_Line( \
756 if(gentle != "") { SET_NOTIF_STRING(gentle, "GENTLE"); }
757 else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL"); }
759 else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL"); }
760 #undef SET_NOTIF_STRING
762 // Check to make sure a string was chosen
763 if(notif.nent_string == "")
767 "^1EMPTY NOTIFICATION: ",
768 "^7net_type = %s, net_name = %s.\n"
782 // Set MSG_MULTI string/float counts
783 if((anncename == NO_MSG) && (infoname == NO_MSG) && (centername == NO_MSG))
787 "^1NOTIFICATION WITH NO SUBCALLS: ",
788 "^7net_type = %s, net_name = %s.\n"
797 // announcements don't actually need any arguments, so lets not even count them.
798 if(anncename != NO_MSG) { notif.nent_msgannce = msg_annce_notifs[anncename - 1]; }
800 float infoname_stringcount = 0, infoname_floatcount = 0;
801 float centername_stringcount = 0, centername_floatcount = 0;
803 if(infoname != NO_MSG)
805 notif.nent_msginfo = msg_info_notifs[infoname - 1];
806 infoname_stringcount = notif.nent_msginfo.nent_stringcount;
807 infoname_floatcount = notif.nent_msginfo.nent_floatcount;
810 if(centername != NO_MSG)
812 notif.nent_msgcenter = msg_center_notifs[centername - 1];
813 centername_stringcount = notif.nent_msgcenter.nent_stringcount;
814 centername_floatcount = notif.nent_msgcenter.nent_floatcount;
817 // set the requirements of THIS notification to the totals of its subcalls
818 notif.nent_stringcount = max(infoname_stringcount, centername_stringcount);
819 notif.nent_floatcount = max(infoname_floatcount, centername_floatcount);
827 if((chtype == NO_MSG) || (optiona == NO_MSG) || (optionb == NO_MSG))
831 "^1NOTIFICATION IS MISSING CHOICE PARAMS: ",
832 "^7net_type = %s, net_name = %s.\n"
845 notif.nent_optiona = msg_annce_notifs[optiona - 1];
846 notif.nent_optionb = msg_annce_notifs[optionb - 1];
851 notif.nent_optiona = msg_info_notifs[optiona - 1];
852 notif.nent_optionb = msg_info_notifs[optionb - 1];
857 notif.nent_optiona = msg_center_notifs[optiona - 1];
858 notif.nent_optionb = msg_center_notifs[optionb - 1];
863 notif.nent_optiona = msg_multi_notifs[optiona - 1];
864 notif.nent_optionb = msg_multi_notifs[optionb - 1];
867 case MSG_CHOICE: // should we REALLY allow nested options?...
869 notif.nent_optiona = msg_choice_notifs[optiona - 1];
870 notif.nent_optionb = msg_choice_notifs[optionb - 1];
878 "^1NOTIFICATION WITH IMPROPER TYPE: ",
879 "^7net_type = %d, net_name = %s.\n"
888 notif.nent_challow_def = challow_def; // 0: never allowed, 1: allowed in warmup, 2: always allowed
889 notif.nent_challow_var = challow_var; // 0: never allowed, 1: allowed in warmup, 2: always allowed
890 notif.nent_stringcount = max(notif.nent_optiona.nent_stringcount, notif.nent_optionb.nent_stringcount);
891 notif.nent_floatcount = max(notif.nent_optiona.nent_floatcount, notif.nent_optionb.nent_floatcount);
893 /*#ifdef NOTIFICATIONS_DEBUG
894 Debug_Notification(sprintf(
895 "Create_Notification_Entity(...): MSG_CHOICE: %s\n%s\n%s\n",
898 "^ optiona: %s %s : %d %d",
899 Get_Notif_TypeName(notif.nent_optiona.nent_type),
900 notif.nent_optiona.nent_name,
901 notif.nent_optiona.nent_stringcount,
902 notif.nent_optiona.nent_floatcount
905 "^ optionb: %s %s : %d %d",
906 Get_Notif_TypeName(notif.nent_optionb.nent_type),
907 notif.nent_optionb.nent_name,
908 notif.nent_optionb.nent_stringcount,
909 notif.nent_optionb.nent_floatcount
921 "^1NOTIFICATION WITH IMPROPER TYPE: ",
922 "^7net_type = %d, net_name = %s.\n"
932 // now check to see if any errors happened
935 notif.nent_enabled = false; // disable the notification so it can't cause trouble
936 notif_global_error = true; // throw the red flag that an error happened on init
945 // used by MSG_CHOICE to build list of choices
947 void Notification_GetCvars(void)
950 for(i = 0; i <= NOTIF_CHOICE_COUNT; ++i)
952 GetCvars_handleFloat(
955 msg_choice_choices[i],
956 sprintf("notification_%s", msg_choice_notifs[i].nent_name)
962 // used to output notifications.cfg file
963 void Dump_Notifications(float fh, float alsoprint)
965 #define NOTIF_WRITE(a) { \
967 if(alsoprint) { print(a); } }
968 #define NOTIF_WRITE_ENTITY(description) { \
971 "seta notification_%s \"%d\" \"%s\"\n", \
972 e.nent_name, e.nent_default, description \
974 NOTIF_WRITE(notif_msg) }
975 #define NOTIF_WRITE_ENTITY_CHOICE(descriptiona,descriptionb) { \
978 "seta notification_%s \"%d\" \"%s\"\n" \
979 "seta notification_%s_ALLOWED \"%d\" \"%s\"\n", \
980 e.nent_name, e.nent_default, descriptiona, \
981 e.nent_name, e.nent_challow_def, descriptionb \
983 NOTIF_WRITE(notif_msg) }
984 #define NOTIF_WRITE_HARDCODED(cvar,default,description) { \
987 "seta notification_%s \"%s\" \"%s\"\n", \
988 cvar, default, description \
990 NOTIF_WRITE(notif_msg) }
996 // Note: This warning only applies to the notifications.cfg file that is output...
998 // You ARE supposed to manually edit this function to add i.e. hard coded
999 // notification variables for mutators or game modes or such and then
1000 // regenerate the notifications.cfg file from the new code.
1002 NOTIF_WRITE("// ********************************************** //\n");
1003 NOTIF_WRITE("// ** WARNING - DO NOT MANUALLY EDIT THIS FILE ** //\n");
1004 NOTIF_WRITE("// ** ** //\n");
1005 NOTIF_WRITE("// ** This file is automatically generated ** //\n");
1006 NOTIF_WRITE("// ** by code with the command 'dumpnotifs'. ** //\n");
1007 NOTIF_WRITE("// ** ** //\n");
1008 NOTIF_WRITE("// ** If you add a new notification, please ** //\n");
1009 NOTIF_WRITE("// ** regenerate this file with that command ** //\n");
1010 NOTIF_WRITE("// ** making sure that the output matches ** //\n");
1011 NOTIF_WRITE("// ** with the lists and defaults in code. ** //\n");
1012 NOTIF_WRITE("// ** ** //\n");
1013 NOTIF_WRITE("// ********************************************** //\n");
1015 // These notifications will also append their string as a comment...
1016 // This is not necessary, and does not matter if they vary between config versions,
1017 // it is just a semi-helpful tool for those who want to manually change their user settings.
1019 NOTIF_WRITE(sprintf("\n// MSG_ANNCE notifications (count = %d):\n", NOTIF_ANNCE_COUNT));
1020 for(i = 1; i <= NOTIF_ANNCE_COUNT; ++i)
1022 e = Get_Notif_Ent(MSG_ANNCE, i);
1023 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1026 "0 = disabled, 1 = enabled if gentle mode is off, 2 = always enabled"
1030 NOTIF_WRITE(sprintf("\n// MSG_INFO notifications (count = %d):\n", NOTIF_INFO_COUNT));
1031 for(i = 1; i <= NOTIF_INFO_COUNT; ++i)
1033 e = Get_Notif_Ent(MSG_INFO, i);
1034 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1037 "0 = off, 1 = print to console, "
1038 "2 = print to console and chatbox (if notification_allow_chatboxprint is enabled)"
1042 NOTIF_WRITE(sprintf("\n// MSG_CENTER notifications (count = %d):\n", NOTIF_CENTER_COUNT));
1043 for(i = 1; i <= NOTIF_CENTER_COUNT; ++i)
1045 e = Get_Notif_Ent(MSG_CENTER, i);
1046 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1049 "0 = off, 1 = centerprint"
1053 NOTIF_WRITE(sprintf("\n// MSG_MULTI notifications (count = %d):\n", NOTIF_MULTI_COUNT));
1054 for(i = 1; i <= NOTIF_MULTI_COUNT; ++i)
1056 e = Get_Notif_Ent(MSG_MULTI, i);
1057 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1060 "Enable this multiple notification"
1064 NOTIF_WRITE(sprintf("\n// MSG_CHOICE notifications (count = %d):\n", NOTIF_CHOICE_COUNT));
1065 for(i = 1; i <= NOTIF_CHOICE_COUNT; ++i)
1067 e = Get_Notif_Ent(MSG_CHOICE, i);
1068 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1070 NOTIF_WRITE_ENTITY_CHOICE(
1071 "Choice for this notification 0 = off, 1 = default message, 2 = verbose message",
1072 "Allow choice for this notification 0 = off, 1 = only in warmup mode, 2 = always"
1076 // edit these to match whichever cvars are used for specific notification options
1077 NOTIF_WRITE("\n// HARD CODED notification variables:\n");
1079 NOTIF_WRITE_HARDCODED(
1080 "allow_chatboxprint", "1",
1081 "Allow INFO notifications to be printed to chat box"
1082 "0 = do not allow, "
1083 "1 = allow only if allowed by individual notification_INFO* cvars, "
1084 "2 = force all INFO notifications to be printed to the chatbox"
1087 NOTIF_WRITE_HARDCODED(
1089 "Print extra debug information on all notification function calls "
1090 "(Requires -DNOTIFICATIONS_DEBUG flag to be enabled on QCSRC compilation)... "
1091 "0 = disabled, 1 = dprint, 2 = print"
1094 NOTIF_WRITE_HARDCODED(
1095 "errors_are_fatal", "1",
1096 "If a notification fails upon initialization, cause a Host_Error to stop the program"
1099 NOTIF_WRITE_HARDCODED(
1100 "item_centerprinttime", "1.5",
1101 "How long to show item information centerprint messages (like 'You got the Electro' or such)"
1104 NOTIF_WRITE_HARDCODED(
1105 "lifetime_mapload", "10",
1106 "Amount of time that notification entities last immediately at mapload (in seconds) "
1107 "to help prevent notifications from being lost on early init (like gamestart countdown)"
1110 NOTIF_WRITE_HARDCODED(
1111 "lifetime_runtime", "0.5",
1112 "Amount of time that notification entities last on the server during runtime (In seconds)"
1115 NOTIF_WRITE_HARDCODED(
1116 "server_allows_location", "1",
1117 "Server side cvar for allowing death messages to show location information too"
1120 NOTIF_WRITE_HARDCODED(
1121 "show_location", "0",
1122 "Append location information to MSG_INFO death/kill messages"
1125 NOTIF_WRITE_HARDCODED(
1126 "show_location_string", "",
1127 "Replacement string piped into sprintf, "
1128 "so you can do different messages like this: ' at the %s' or ' (near %s)'"
1131 NOTIF_WRITE_HARDCODED(
1133 "Print information about sprees in death/kill messages"
1136 NOTIF_WRITE_HARDCODED(
1137 "show_sprees_center", "1",
1138 "Show spree information in MSG_CENTER messages... "
1139 "0 = off, 1 = target (but only for first victim) and attacker"
1142 NOTIF_WRITE_HARDCODED(
1143 "show_sprees_center_specialonly", "1",
1144 "Don't show spree information in MSG_CENTER messages if it isn't an achievement"
1147 NOTIF_WRITE_HARDCODED(
1148 "show_sprees_info", "3",
1149 "Show spree information in MSG_INFO messages... "
1150 "0 = off, 1 = target only, 2 = attacker only, 3 = target and attacker"
1153 NOTIF_WRITE_HARDCODED(
1154 "show_sprees_info_newline", "1",
1155 "Show attacker spree information for MSG_INFO messages on a separate line than the death notification itself"
1158 NOTIF_WRITE_HARDCODED(
1159 "show_sprees_info_specialonly", "1",
1160 "Don't show attacker spree information in MSG_INFO messages if it isn't an achievement"
1163 NOTIF_WRITE(sprintf(
1165 "\n// Notification counts (total = %d): ",
1166 "MSG_ANNCE = %d, MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d, MSG_CHOICE = %d\n"
1171 NOTIF_CENTER_COUNT +
1183 #undef NOTIF_WRITE_HARDCODED
1184 #undef NOTIF_WRITE_ENTITY
1189 // ===============================
1190 // Frontend Notification Pushing
1191 // ===============================
1193 #ifdef NOTIFICATIONS_DEBUG
1194 void Debug_Notification(string input)
1196 switch(autocvar_notification_debug)
1198 case 1: { dprint(input); break; }
1199 case 2: { print(input); break; }
1204 string Local_Notification_sprintf(
1205 string input, string args,
1206 string s1, string s2, string s3, string s4,
1207 int f1, float f2, float f3, float f4)
1209 #ifdef NOTIFICATIONS_DEBUG
1210 Debug_Notification(sprintf(
1211 "Local_Notification_sprintf('%s^7', '%s', %s, %s);\n",
1212 MakeConsoleSafe(input),
1214 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1215 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1221 for(sel_num = 0; sel_num < NOTIF_MAX_ARGS; ++sel_num) { arg_slot[sel_num] = ""; }
1225 for(sel_num = 0;(args != "");)
1227 selected = car(args); args = cdr(args);
1228 NOTIF_HIT_MAX(NOTIF_MAX_ARGS, "Local_Notification_sprintf");
1229 switch(strtolower(selected))
1232 #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1233 #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1234 #define ARG_CASE_ARG_CS_SV(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1235 #define ARG_CASE_ARG_CS(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1236 #define ARG_CASE_ARG_SV(selected,result)
1237 #define ARG_CASE_ARG_DC(selected,result)
1239 #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1240 #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1241 #define ARG_CASE_ARG_CS_SV(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1242 #define ARG_CASE_ARG_CS(selected,result)
1243 #define ARG_CASE_ARG_SV(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1244 #define ARG_CASE_ARG_DC(selected,result)
1246 #define ARG_CASE(prog,selected,result) ARG_CASE_##prog(selected,result)
1249 #undef ARG_CASE_ARG_DC
1250 #undef ARG_CASE_ARG_SV
1251 #undef ARG_CASE_ARG_CS
1252 #undef ARG_CASE_ARG_CS_SV
1253 #undef ARG_CASE_ARG_CS_SV_DC
1254 #undef ARG_CASE_ARG_CS_SV_HA
1255 default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
1259 strcat(input, "\n"),
1271 void Local_Notification_sound(
1272 float soundchannel, string soundfile,
1273 float soundvolume, float soundposition)
1275 if((soundfile != prev_soundfile) || (time >= (prev_soundtime + autocvar_cl_announcer_antispam)))
1277 #ifdef NOTIFICATIONS_DEBUG
1278 Debug_Notification(sprintf(
1279 "Local_Notification_sound(world, %f, '%s', %f, %f);\n",
1282 "announcer/%s/%s.wav",
1283 autocvar_cl_announcer,
1295 "announcer/%s/%s.wav",
1296 autocvar_cl_announcer,
1303 if(prev_soundfile) { strunzone(prev_soundfile); }
1304 prev_soundfile = strzone(soundfile);
1305 prev_soundtime = time;
1309 #ifdef NOTIFICATIONS_DEBUG
1310 Debug_Notification(sprintf(
1312 "Local_Notification_sound(world, %f, '%s', %f, %f) ",
1313 "^1BLOCKED BY ANTISPAM:^7 prevsnd: '%s', timediff: %f, limit: %f\n"
1317 "announcer/%s/%s.wav",
1318 autocvar_cl_announcer,
1324 (time - prev_soundtime),
1325 autocvar_cl_announcer_antispam
1331 void Local_Notification_HUD_Notify_Push(
1332 string icon, string hudargs,
1333 string s1, string s2, string s3, string s4,
1334 float f1, float f2, float f3, float f4)
1337 arg_slot[0] = ""; arg_slot[1] = "";
1340 for(sel_num = 0;(hudargs != "");)
1342 selected = car(hudargs); hudargs = cdr(hudargs);
1343 NOTIF_HIT_MAX(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push");
1344 switch(strtolower(selected))
1346 #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1347 #define ARG_CASE_ARG_CS_SV_DC(selected,result)
1348 #define ARG_CASE_ARG_CS_SV(selected,result)
1349 #define ARG_CASE_ARG_CS(selected,result)
1350 #define ARG_CASE_ARG_SV(selected,result)
1351 #define ARG_CASE_ARG_DC(selected,result)
1352 #define ARG_CASE(prog,selected,result) ARG_CASE_##prog(selected,result)
1355 #undef ARG_CASE_ARG_DC
1356 #undef ARG_CASE_ARG_SV
1357 #undef ARG_CASE_ARG_CS
1358 #undef ARG_CASE_ARG_CS_SV
1359 #undef ARG_CASE_ARG_CS_SV_DC
1360 #undef ARG_CASE_ARG_CS_SV_HA
1361 default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
1364 #ifdef NOTIFICATIONS_DEBUG
1365 Debug_Notification(sprintf(
1366 "Local_Notification_HUD_Notify_Push('%s^7', '%s', %s, %s, %s);\n",
1369 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1370 sprintf("%d, %d, %d, %d", f1, f2, f3, f4),
1371 MakeConsoleSafe(sprintf("'%s^7', '%s^7'", stof(arg_slot[0]), stof(arg_slot[1])))
1374 HUD_Notify_Push(icon, arg_slot[0], arg_slot[1]);
1377 void Local_Notification_centerprint_generic(
1378 string input, string durcnt,
1379 int cpid, float f1, float f2)
1381 arg_slot[0] = ""; arg_slot[1] = "";
1383 for(int sel_num = 0;(durcnt != "");)
1385 string selected = car(durcnt); durcnt = cdr(durcnt);
1386 NOTIF_HIT_MAX(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic");
1387 switch(strtolower(selected))
1389 #define ARG_CASE_ARG_CS_SV_HA(selected,result)
1390 #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1391 #define ARG_CASE_ARG_CS_SV(selected,result)
1392 #define ARG_CASE_ARG_CS(selected,result)
1393 #define ARG_CASE_ARG_SV(selected,result)
1394 #define ARG_CASE_ARG_DC(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1395 #define ARG_CASE(prog,selected,result) ARG_CASE_##prog(selected,result)
1398 #undef ARG_CASE_ARG_DC
1399 #undef ARG_CASE_ARG_SV
1400 #undef ARG_CASE_ARG_CS
1401 #undef ARG_CASE_ARG_CS_SV
1402 #undef ARG_CASE_ARG_CS_SV_DC
1403 #undef ARG_CASE_ARG_CS_SV_HA
1406 if(ftos(stof(selected)) != "") { arg_slot[sel_num] = selected; ++sel_num; }
1407 else { NOTIF_HIT_UNKNOWN(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic") }
1412 #ifdef NOTIFICATIONS_DEBUG
1413 Debug_Notification(sprintf(
1414 "Local_Notification_centerprint_generic('%s^7', '%s', %d, %d, %d, %d);\n",
1415 MakeConsoleSafe(input),
1422 centerprint_generic(cpid, input, stof(arg_slot[0]), stof(arg_slot[1]));
1426 void Local_Notification(int net_type, int net_name, ...count)
1428 // check if this should be aborted
1429 if(net_name == NOTIF_ABORT)
1431 #ifdef NOTIFICATIONS_DEBUG
1432 Debug_Notification(sprintf(
1433 "Local_Notification(%s, %s, ...);\n",
1434 Get_Notif_TypeName(net_type),
1441 // check supplied type and name for errors
1442 string checkargs = Notification_CheckArgs_TypeName(net_type, net_name);
1445 #ifdef NOTIFICATIONS_DEBUG
1446 Debug_Notification(sprintf(
1447 "Local_Notification(%s, %d, ...);\n",
1448 Get_Notif_TypeName(net_type),
1449 Get_Notif_Ent(net_type, net_name).nent_name
1452 backtrace(sprintf("Incorrect usage of Local_Notification: %s\n", checkargs));
1456 // retreive entity of this notification
1457 entity notif = Get_Notif_Ent(net_type, net_name);
1460 #ifdef NOTIFICATIONS_DEBUG
1461 Debug_Notification(sprintf(
1462 "Local_Notification(%s, %d, ...);\n",
1463 Get_Notif_TypeName(net_type),
1467 backtrace("Local_Notification: Could not find notification entity!\n");
1471 // check if the notification is enabled
1472 if (!notif.nent_enabled)
1474 #ifdef NOTIFICATIONS_DEBUG
1475 Debug_Notification(sprintf(
1476 "Local_Notification(%s, %s, ...): Entity was disabled...\n",
1477 Get_Notif_TypeName(net_type),
1484 string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
1485 string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
1486 string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
1487 string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
1488 float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
1489 float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
1490 float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
1491 float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
1493 #ifdef NOTIFICATIONS_DEBUG
1494 Debug_Notification(sprintf(
1495 "Local_Notification(%s, %s, %s, %s);\n",
1496 Get_Notif_TypeName(net_type),
1498 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1499 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1503 if((notif.nent_stringcount + notif.nent_floatcount) > count)
1507 "Not enough arguments for Local_Notification(%s, %s, ...)! ",
1508 "stringcount(%d) + floatcount(%d) > count(%d)\n",
1509 "Check the definition and function call for accuracy...?\n"
1511 Get_Notif_TypeName(net_type),
1513 notif.nent_stringcount,
1514 notif.nent_floatcount,
1519 else if((notif.nent_stringcount + notif.nent_floatcount) < count)
1523 "Too many arguments for Local_Notification(%s, %s, ...)! ",
1524 "stringcount(%d) + floatcount(%d) < count(%d)\n",
1525 "Check the definition and function call for accuracy...?\n"
1527 Get_Notif_TypeName(net_type),
1529 notif.nent_stringcount,
1530 notif.nent_floatcount,
1541 Local_Notification_sound(
1548 backtrace("MSG_ANNCE on server?... Please notify Samual immediately!\n");
1556 Local_Notification_sprintf(
1563 if(notif.nent_icon != "")
1565 Local_Notification_HUD_Notify_Push(
1578 Local_Notification_centerprint_generic(
1579 Local_Notification_sprintf(
1593 if(notif.nent_msginfo)
1594 if(notif.nent_msginfo.nent_enabled)
1596 Local_Notification_WOVA(
1598 notif.nent_msginfo.nent_id,
1599 notif.nent_msginfo.nent_stringcount,
1600 notif.nent_msginfo.nent_floatcount,
1605 if(notif.nent_msgannce)
1606 if(notif.nent_msgannce.nent_enabled)
1608 Local_Notification_WOVA(
1610 notif.nent_msgannce.nent_id,
1615 if(notif.nent_msgcenter)
1616 if(notif.nent_msgcenter.nent_enabled)
1618 Local_Notification_WOVA(
1620 notif.nent_msgcenter.nent_id,
1621 notif.nent_msgcenter.nent_stringcount,
1622 notif.nent_msgcenter.nent_floatcount,
1632 entity found_choice;
1634 if(notif.nent_challow_var && (warmup_stage || (notif.nent_challow_var == 2)))
1636 switch(cvar_string(sprintf("notification_%s", notif.nent_name)))
1638 case 1: found_choice = notif.nent_optiona; break;
1639 case 2: found_choice = notif.nent_optionb; break;
1640 default: return; // not enabled anyway
1643 else { found_choice = notif.nent_optiona; }
1645 Local_Notification_WOVA(
1646 found_choice.nent_type,
1647 found_choice.nent_id,
1648 found_choice.nent_stringcount,
1649 found_choice.nent_floatcount,
1656 // WOVA = Without Variable Arguments
1657 void Local_Notification_WOVA(
1658 int net_type, float net_name,
1659 float stringcount, float floatcount,
1660 string s1, string s2, string s3, string s4,
1661 float f1, float f2, float f3, float f4)
1663 #define VARITEM(stringc,floatc,args) \
1664 if((stringcount == stringc) && (floatcount == floatc)) \
1665 { Local_Notification(net_type, net_name, args); return; }
1666 EIGHT_VARS_TO_VARARGS_VARLIST
1668 Local_Notification(net_type, net_name); // some notifications don't have any arguments at all
1672 // =========================
1673 // Notification Networking
1674 // =========================
1677 void Read_Notification(float is_new)
1679 int net_type = ReadByte();
1680 int net_name = ReadShort();
1684 if(net_type == MSG_CENTER_CPID)
1686 #ifdef NOTIFICATIONS_DEBUG
1687 Debug_Notification(sprintf(
1688 "Read_Notification(%d) at %f: net_type = %s, net_name = %d\n",
1691 Get_Notif_TypeName(net_type),
1698 if(net_name == 0) { reset_centerprint_messages(); }
1699 else if(net_name != NO_CPID)
1701 // in this case, net_name IS the cpid we want to kill
1702 centerprint_generic(net_name, "", 0, 0);
1707 "Read_Notification(%d) at %f: ^1TRIED TO KILL NO_CPID CENTERPRINT!\n",
1716 notif = Get_Notif_Ent(net_type, net_name);
1717 if (!notif) { backtrace("Read_Notification: Could not find notification entity!\n"); return; }
1719 #ifdef NOTIFICATIONS_DEBUG
1720 Debug_Notification(sprintf(
1721 "Read_Notification(%d) at %f: net_type = %s, net_name = %s\n",
1724 Get_Notif_TypeName(net_type),
1729 string s1 = ((0 < notif.nent_stringcount) ? ReadString() : "");
1730 string s2 = ((1 < notif.nent_stringcount) ? ReadString() : "");
1731 string s3 = ((2 < notif.nent_stringcount) ? ReadString() : "");
1732 string s4 = ((3 < notif.nent_stringcount) ? ReadString() : "");
1733 float f1 = ((0 < notif.nent_floatcount) ? ReadLong() : 0);
1734 float f2 = ((1 < notif.nent_floatcount) ? ReadLong() : 0);
1735 float f3 = ((2 < notif.nent_floatcount) ? ReadLong() : 0);
1736 float f4 = ((3 < notif.nent_floatcount) ? ReadLong() : 0);
1740 Local_Notification_WOVA(
1742 notif.nent_stringcount,
1743 notif.nent_floatcount,
1752 void Net_Notification_Remove()
1754 if (!self) { backtrace(sprintf("Net_Notification_Remove() at %f: Missing self!?\n", time)); return; }
1756 #ifdef NOTIFICATIONS_DEBUG
1757 Debug_Notification(sprintf(
1758 "Net_Notification_Remove() at %f: %s '%s - %s' notification\n",
1760 ((self.nent_net_name == -1) ? "Killed" : "Removed"),
1761 Get_Notif_TypeName(self.nent_net_type),
1762 self.owner.nent_name
1767 for(i = 0; i < 4; ++i) { if(self.nent_strings[i]) { strunzone(self.nent_strings[i]); } }
1771 float Net_Write_Notification(entity client, float sf)
1773 if(Notification_ShouldSend(self.nent_broadcast, client, self.nent_client))
1776 WriteByte(MSG_ENTITY, ENT_CLIENT_NOTIFICATION);
1777 WriteByte(MSG_ENTITY, self.nent_net_type);
1778 WriteShort(MSG_ENTITY, self.nent_net_name);
1779 for(i = 0; i < self.nent_stringcount; ++i) { WriteString(MSG_ENTITY, self.nent_strings[i]); }
1780 for(i = 0; i < self.nent_floatcount; ++i) { WriteLong(MSG_ENTITY, self.nent_floats[i]); }
1783 else { return false; }
1786 void Kill_Notification(
1787 float broadcast, entity client,
1788 float net_type, float net_name)
1790 #ifdef NOTIFICATIONS_DEBUG
1791 Debug_Notification(sprintf(
1792 "Kill_Notification(%s, '%s', %s, %d);\n",
1793 Get_Notif_BroadcastName(broadcast),
1795 (net_type ? Get_Notif_TypeName(net_type) : "0"),
1800 string checkargs = Notification_CheckArgs(broadcast, client, 1, 1);
1801 if(checkargs != "") { backtrace(sprintf("Incorrect usage of Kill_Notification: %s\n", checkargs)); return; }
1803 entity notif, net_notif;
1804 float killed_cpid = NO_CPID;
1810 killed_cpid = 0; // kill ALL centerprints
1818 entity notif = Get_Notif_Ent(net_type, net_name);
1819 if (!notif) { backtrace("Kill_Notification: Could not find notification entity!\n"); return; }
1822 killed_cpid = notif.nent_cpid;
1824 killed_cpid = NO_CPID;
1828 killed_cpid = 0; // kill ALL centerprints
1833 case MSG_CENTER_CPID:
1835 killed_cpid = net_name;
1840 if(killed_cpid != NO_CPID)
1842 net_notif = spawn();
1843 net_notif.classname = "net_kill_notification";
1844 net_notif.nent_broadcast = broadcast;
1845 net_notif.nent_client = client;
1846 net_notif.nent_net_type = MSG_CENTER_CPID;
1847 net_notif.nent_net_name = killed_cpid;
1848 Net_LinkEntity(net_notif, false, autocvar_notification_lifetime_runtime, Net_Write_Notification);
1851 for(notif = world; (notif = find(notif, classname, "net_notification"));)
1855 if((killed_cpid != NO_CPID) && (notif.nent_net_type == MSG_CENTER))
1857 if(notif.owner.nent_cpid == killed_cpid)
1859 notif.nent_net_name = -1;
1860 notif.nextthink = time;
1862 else { continue; } // we ARE looking for a specific CPID, don't kill everything else too
1864 else if(notif.nent_net_type == net_type)
1868 if(notif.nent_net_name == net_name) { notif.nent_net_name = -1; notif.nextthink = time; }
1869 else { continue; } // we ARE looking for a certain net_name, don't kill everything else too
1871 else { notif.nent_net_name = -1; notif.nextthink = time; }
1873 else { continue; } // we ARE looking for a certain net_type, don't kill everything else too
1875 else { notif.nent_net_name = -1; notif.nextthink = time; }
1879 void Send_Notification(
1880 float broadcast, entity client,
1881 float net_type, float net_name,
1884 // check if this should be aborted
1885 if(net_name == NOTIF_ABORT)
1887 #ifdef NOTIFICATIONS_DEBUG
1888 Debug_Notification(sprintf(
1889 "Send_Notification(%s, '%s', %s, %s, ...);\n",
1890 Get_Notif_BroadcastName(broadcast),
1892 Get_Notif_TypeName(net_type),
1899 // check supplied broadcast, target, type, and name for errors
1900 string checkargs = Notification_CheckArgs(broadcast, client, net_type, net_name);
1903 #ifdef NOTIFICATIONS_DEBUG
1904 Debug_Notification(sprintf(
1905 "Send_Notification(%s, '%s', %s, %s, ...);\n",
1906 Get_Notif_BroadcastName(broadcast),
1908 Get_Notif_TypeName(net_type),
1909 Get_Notif_Ent(net_type, net_name).nent_name
1912 backtrace(sprintf("Incorrect usage of Send_Notification: %s\n", checkargs));
1916 // retreive entity of this notification
1917 entity notif = Get_Notif_Ent(net_type, net_name);
1920 #ifdef NOTIFICATIONS_DEBUG
1921 Debug_Notification(sprintf(
1922 "Send_Notification(%s, '%s', %s, %d, ...);\n",
1923 Get_Notif_BroadcastName(broadcast),
1925 Get_Notif_TypeName(net_type),
1929 backtrace("Send_Notification: Could not find notification entity!\n");
1933 string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
1934 string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
1935 string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
1936 string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
1937 float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
1938 float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
1939 float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
1940 float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
1942 #ifdef NOTIFICATIONS_DEBUG
1943 Debug_Notification(sprintf(
1944 "Send_Notification(%s, %s, %s);\n",
1947 Get_Notif_BroadcastName(broadcast),
1949 Get_Notif_TypeName(net_type),
1952 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1953 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1957 if((notif.nent_stringcount + notif.nent_floatcount) > count)
1961 "Not enough arguments for Send_Notification(%s, ...)! ",
1962 "stringcount(%d) + floatcount(%d) > count(%d)\n",
1963 "Check the definition and function call for accuracy...?\n"
1966 #ifdef NOTIFICATIONS_DEBUG
1968 Get_Notif_BroadcastName(broadcast),
1974 Get_Notif_TypeName(net_type),
1977 notif.nent_stringcount,
1978 notif.nent_floatcount,
1983 else if((notif.nent_stringcount + notif.nent_floatcount) < count)
1987 "Too many arguments for Send_Notification(%s, ...)! ",
1988 "stringcount(%d) + floatcount(%d) < count(%d)\n",
1989 "Check the definition and function call for accuracy...?\n"
1992 #ifdef NOTIFICATIONS_DEBUG
1994 Get_Notif_BroadcastName(broadcast),
2000 Get_Notif_TypeName(net_type),
2003 notif.nent_stringcount,
2004 notif.nent_floatcount,
2014 broadcast == NOTIF_ALL
2016 broadcast == NOTIF_ALL_EXCEPT
2020 net_type == MSG_ANNCE
2022 net_type == MSG_CENTER
2026 Local_Notification_WOVA(
2028 notif.nent_stringcount,
2029 notif.nent_floatcount,
2034 if(net_type == MSG_CHOICE)
2036 // THIS GETS TRICKY... now we have to cycle through each possible player (checking broadcast)
2037 // and then do an individual NOTIF_ONE_ONLY recursive call for each one depending on their option...
2038 // It's slow, but it's better than the alternatives:
2039 // 1. Constantly networking all info and letting client decide
2040 // 2. Manually handling each separate call on per-usage basis (See old CTF usage of verbose)
2041 entity found_choice;
2043 #define RECURSE_FROM_CHOICE(ent,action) \
2044 if(notif.nent_challow_var && (warmup_stage || (notif.nent_challow_var == 2))) \
2046 switch(ent.msg_choice_choices[net_name - 1]) \
2048 case 1: found_choice = notif.nent_optiona; break; \
2049 case 2: found_choice = notif.nent_optionb; break; \
2053 else { found_choice = notif.nent_optiona; } \
2054 Send_Notification_WOVA( \
2057 found_choice.nent_type, \
2058 found_choice.nent_id, \
2059 found_choice.nent_stringcount, \
2060 found_choice.nent_floatcount, \
2066 case NOTIF_ONE_ONLY: // we can potentially save processing power with this broadcast method
2068 if(IS_REAL_CLIENT(client))
2069 { RECURSE_FROM_CHOICE(client, return) }
2075 FOR_EACH_REALCLIENT(to)
2076 { if(Notification_ShouldSend(broadcast, to, client))
2077 { RECURSE_FROM_CHOICE(to, continue) } }
2084 entity net_notif = spawn();
2085 net_notif.owner = notif;
2086 net_notif.classname = "net_notification";
2087 net_notif.nent_broadcast = broadcast;
2088 net_notif.nent_client = client;
2089 net_notif.nent_net_type = net_type;
2090 net_notif.nent_net_name = net_name;
2091 net_notif.nent_stringcount = notif.nent_stringcount;
2092 net_notif.nent_floatcount = notif.nent_floatcount;
2095 for(i = 0; i < net_notif.nent_stringcount; ++i)
2096 { net_notif.nent_strings[i] = strzone(...(i, string)); }
2097 for(i = 0; i < net_notif.nent_floatcount; ++i)
2098 { net_notif.nent_floats[i] = ...((net_notif.nent_stringcount + i), float); }
2100 net_notif.think = Net_Notification_Remove;
2101 net_notif.nextthink =
2102 ((time > autocvar_notification_lifetime_mapload)
2104 (time + autocvar_notification_lifetime_runtime)
2106 autocvar_notification_lifetime_mapload
2109 Net_LinkEntity(net_notif, false, 0, Net_Write_Notification);
2113 // WOVA = Without Variable Arguments
2114 void Send_Notification_WOVA(
2115 float broadcast, entity client,
2116 float net_type, float net_name,
2117 float stringcount, float floatcount,
2118 string s1, string s2, string s3, string s4,
2119 float f1, float f2, float f3, float f4)
2121 #ifdef NOTIFICATIONS_DEBUG
2122 entity notif = Get_Notif_Ent(net_type, net_name);
2123 Debug_Notification(sprintf(
2124 "Send_Notification_WOVA(%s, %d, %d, %s, %s);\n",
2127 Get_Notif_BroadcastName(broadcast),
2129 Get_Notif_TypeName(net_type),
2134 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
2135 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
2139 #define VARITEM(stringc,floatc,args) \
2140 if((stringcount == stringc) && (floatcount == floatc)) \
2141 { Send_Notification(broadcast, client, net_type, net_name, args); return; }
2142 EIGHT_VARS_TO_VARARGS_VARLIST
2144 Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
2147 // WOCOVA = Without Counts Or Variable Arguments
2148 void Send_Notification_WOCOVA(
2149 float broadcast, entity client,
2150 float net_type, float net_name,
2151 string s1, string s2, string s3, string s4,
2152 float f1, float f2, float f3, float f4)
2154 entity notif = Get_Notif_Ent(net_type, net_name);
2156 #ifdef NOTIFICATIONS_DEBUG
2157 Debug_Notification(sprintf(
2158 "Send_Notification_WOCOVA(%s, %s, %s);\n",
2161 Get_Notif_BroadcastName(broadcast),
2163 Get_Notif_TypeName(net_type),
2166 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
2167 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
2171 #define VARITEM(stringc,floatc,args) \
2172 if((notif.nent_stringcount == stringc) && (notif.nent_floatcount == floatc)) \
2173 { Send_Notification(broadcast, client, net_type, net_name, args); return; }
2174 EIGHT_VARS_TO_VARARGS_VARLIST
2176 Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
2178 #endif // ifdef SVQC