2 #include "../client/announcer.qh"
5 #include "constants.qh"
7 #include "../server/autocvars.qh"
8 #include "../server/constants.qh"
9 #include "../server/defs.qh"
10 #include "notifications.qh"
11 #include <server/mutators/all.qh>
14 // ================================================
15 // Unified notification system, written by Samual
16 // Last updated: August, 2013
17 // ================================================
19 string Get_Notif_TypeName(int net_type)
23 case MSG_ANNCE: return "MSG_ANNCE";
24 case MSG_INFO: return "MSG_INFO";
25 case MSG_CENTER: return "MSG_CENTER";
26 case MSG_CENTER_CPID: return "MSG_CENTER_CPID";
27 case MSG_MULTI: return "MSG_MULTI";
28 case MSG_CHOICE: return "MSG_CHOICE";
30 backtrace(sprintf("Get_Notif_TypeName(%d): Improper net type!\n", net_type));
34 entity Get_Notif_Ent(int net_type, int net_name)
38 case MSG_ANNCE: return msg_annce_notifs[net_name - 1];
39 case MSG_INFO: return msg_info_notifs[net_name - 1];
40 case MSG_CENTER: return msg_center_notifs[net_name - 1];
41 case MSG_MULTI: return msg_multi_notifs[net_name - 1];
42 case MSG_CHOICE: return msg_choice_notifs[net_name - 1];
44 backtrace(sprintf("Get_Notif_Ent(%d, %d): Improper net type!\n", net_type, net_name));
49 #ifdef NOTIFICATIONS_DEBUG
50 string Get_Notif_BroadcastName(float broadcast)
54 case NOTIF_ONE: return "NOTIF_ONE";
55 case NOTIF_ONE_ONLY: return "NOTIF_ONE_ONLY";
56 case NOTIF_ALL_EXCEPT: return "NOTIF_ALL_EXCEPT";
57 case NOTIF_ALL: return "NOTIF_ALL";
58 case NOTIF_TEAM: return "NOTIF_TEAM";
59 case NOTIF_TEAM_EXCEPT: return "NOTIF_TEAM_EXCEPT";
61 backtrace(sprintf("Get_Notif_BroadcastName(%d): Improper broadcast!\n", broadcast));
67 string Notification_CheckArgs_TypeName(float net_type, float net_name)
69 // check supplied type and name for errors
70 string checkargs = "";
71 #define CHECKARG_TYPENAME(type) case MSG_##type: \
72 { if(!net_name || (net_name > NOTIF_##type##_COUNT)) \
73 { checkargs = sprintf("Improper name: %d!", net_name); } break; }
76 CHECKARG_TYPENAME(ANNCE)
77 CHECKARG_TYPENAME(INFO)
78 CHECKARG_TYPENAME(CENTER)
79 CHECKARG_TYPENAME(MULTI)
80 CHECKARG_TYPENAME(CHOICE)
81 default: { checkargs = sprintf("Improper type: %d!", checkargs, net_type); break; }
83 #undef CHECKARG_TYPENAME
88 string Notification_CheckArgs(
89 float broadcast, entity client,
90 float net_type, float net_name)
92 // check supplied broadcast, target, type, and name for errors
93 string checkargs = Notification_CheckArgs_TypeName(net_type, net_name);
94 if(checkargs != "") { checkargs = strcat(checkargs, " "); }
100 if(IS_NOT_A_CLIENT(client))
101 { checkargs = sprintf("%sNo client provided!", checkargs); }
105 case NOTIF_ALL_EXCEPT:
107 if(IS_NOT_A_CLIENT(client))
108 { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
115 { checkargs = sprintf("%sEntity provided when world was required!", checkargs); }
122 { checkargs = sprintf("%sTeamplay not active!", checkargs); }
123 //else if (!client.team) { checkargs = sprintf("%sNo team provided!", checkargs); }
127 case NOTIF_TEAM_EXCEPT:
130 { checkargs = sprintf("%sTeamplay not active!", checkargs); }
131 else if(IS_NOT_A_CLIENT(client))
132 { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
136 default: { checkargs = sprintf("%sImproper broadcast: %d!", checkargs, broadcast); break; }
141 float Notification_ShouldSend(float broadcast, entity to_client, entity other_client)
145 case NOTIF_ONE: // send to one client and their spectator
148 (to_client == other_client)
153 (to_client.enemy == other_client)
158 case NOTIF_ONE_ONLY: // send ONLY to one client
160 if(to_client == other_client) { return true; }
163 case NOTIF_TEAM: // send only to X team and their spectators
166 (to_client.team == other_client.team)
171 (to_client.enemy.team == other_client.team)
176 case NOTIF_TEAM_EXCEPT: // send only to X team and their spectators, except for Y person and their spectators
179 (to_client != other_client)
182 (to_client.team == other_client.team)
188 (to_client.enemy != other_client)
190 (to_client.enemy.team == other_client.team)
197 case NOTIF_ALL: // send to everyone
201 case NOTIF_ALL_EXCEPT: // send to everyone except X person and their spectators
204 (to_client != other_client)
209 (to_client.enemy == other_client)
220 // ===============================
221 // Initialization Core Functions
222 // ===============================
224 // used by restartnotifs command to initialize notifications
225 void Destroy_Notification_Entity(entity notif)
227 if(notif.nent_name != "") { strunzone(notif.nent_name); }
228 if(notif.nent_snd != "") { strunzone(notif.nent_snd); }
229 if(notif.nent_args != "") { strunzone(notif.nent_args); }
230 if(notif.nent_hudargs != "") { strunzone(notif.nent_hudargs); }
231 if(notif.nent_icon != "") { strunzone(notif.nent_icon); }
232 if(notif.nent_durcnt != "") { strunzone(notif.nent_durcnt); }
233 if(notif.nent_string != "") { strunzone(notif.nent_string); }
237 void Destroy_All_Notifications()
242 #define DESTROY_LOOP(type,count) MACRO_BEGIN { \
243 for(i = 1; i <= count; ++i) \
245 notif = Get_Notif_Ent(type, i); \
246 if (!notif) { backtrace("Destroy_All_Notifications(): Missing notification entity!\n"); return; } \
247 Destroy_Notification_Entity(notif); \
251 // kill all networked notifications and centerprints
253 Kill_Notification(NOTIF_ALL, world, 0, 0);
255 reset_centerprint_messages();
258 // kill all real notification entities
259 DESTROY_LOOP(MSG_ANNCE, NOTIF_ANNCE_COUNT);
260 DESTROY_LOOP(MSG_INFO, NOTIF_INFO_COUNT);
261 DESTROY_LOOP(MSG_CENTER, NOTIF_CENTER_COUNT);
262 DESTROY_LOOP(MSG_MULTI, NOTIF_MULTI_COUNT);
263 DESTROY_LOOP(MSG_CHOICE, NOTIF_CHOICE_COUNT);
267 string Process_Notif_Line(
276 if(typeId == MSG_INFO)
278 if((chat && autocvar_notification_allow_chatboxprint)
279 || (autocvar_notification_allow_chatboxprint == 2))
281 // pass 1: add ETX char at beginning of line
282 input = strcat("\{3}", input);
284 // pass 2: add ETX char at end of each new line (so that
285 // messages with multiple lines are put through chatbox too)
286 input = strreplace("\n", "\n\{3}", input);
288 // pass 3: strip trailing ETX char
289 if(substring(input, (strlen(input) - 1), 1) == "\{3}")
290 { input = substring(input, 0, (strlen(input) - 1)); }
295 // done to both MSG_INFO and MSG_CENTER
296 if(substring(input, (strlen(input) - 1), 1) == "\n")
300 "^1TRAILING NEW LINE AT END OF NOTIFICATION: ",
301 "^7net_type = %s, net_name = %s, string = %s.\n"
308 input = substring(input, 1, (strlen(input) - 1));
314 string Process_Notif_Args(
320 string selected, remaining = args;
323 for (;(remaining != "");)
325 selected = car(remaining); remaining = cdr(remaining);
329 case 1: // normal args
331 if(sel_num == NOTIF_MAX_ARGS)
335 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
336 "^7net_type = %s, net_name = %s, max args = %d.\n"
346 switch(strtolower(selected))
348 #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { ++sel_num; break; }
349 #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { ++sel_num; break; }
350 #define ARG_CASE_ARG_CS_SV(selected,result) case selected: { ++sel_num; break; }
351 #define ARG_CASE_ARG_CS(selected,result) case selected: { ++sel_num; break; }
352 #define ARG_CASE_ARG_SV(selected,result) case selected: { ++sel_num; break; }
353 #define ARG_CASE_ARG_DC(selected,result)
354 #define ARG_CASE(prog,selected,result) ARG_CASE_##prog(selected,result)
357 #undef ARG_CASE_ARG_DC
358 #undef ARG_CASE_ARG_SV
359 #undef ARG_CASE_ARG_CS
360 #undef ARG_CASE_ARG_CS_SV
361 #undef ARG_CASE_ARG_CS_SV_DC
362 #undef ARG_CASE_ARG_CS_SV_HA
367 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
368 "^7net_type = %s, net_name = %s, args arg = '%s'.\n"
382 if(sel_num == NOTIF_MAX_HUDARGS)
386 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
387 "^7net_type = %s, net_name = %s, max hudargs = %d.\n"
397 switch(strtolower(selected))
399 #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { ++sel_num; break; }
400 #define ARG_CASE_ARG_CS_SV_DC(selected,result)
401 #define ARG_CASE_ARG_CS_SV(selected,result)
402 #define ARG_CASE_ARG_CS(selected,result)
403 #define ARG_CASE_ARG_SV(selected,result)
404 #define ARG_CASE_ARG_DC(selected,result)
405 #define ARG_CASE(prog,selected,result) ARG_CASE_##prog(selected,result)
408 #undef ARG_CASE_ARG_DC
409 #undef ARG_CASE_ARG_SV
410 #undef ARG_CASE_ARG_CS
411 #undef ARG_CASE_ARG_CS_SV
412 #undef ARG_CASE_ARG_CS_SV_DC
413 #undef ARG_CASE_ARG_CS_SV_HA
418 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
419 "^7net_type = %s, net_name = %s, hudargs arg = '%s'.\n"
433 if(sel_num == NOTIF_MAX_DURCNT)
437 "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
438 "^7net_type = %s, net_name = %s, max durcnt = %d.\n"
448 switch(strtolower(selected))
450 #define ARG_CASE_ARG_CS_SV_HA(selected,result)
451 #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { ++sel_num; break; }
452 #define ARG_CASE_ARG_CS_SV(selected,result)
453 #define ARG_CASE_ARG_CS(selected,result)
454 #define ARG_CASE_ARG_SV(selected,result)
455 #define ARG_CASE_ARG_DC(selected,result) case selected: { ++sel_num; break; }
456 #define ARG_CASE(prog,selected,result) ARG_CASE_##prog(selected,result)
459 #undef ARG_CASE_ARG_DC
460 #undef ARG_CASE_ARG_SV
461 #undef ARG_CASE_ARG_CS
462 #undef ARG_CASE_ARG_CS_SV
463 #undef ARG_CASE_ARG_CS_SV_DC
464 #undef ARG_CASE_ARG_CS_SV_HA
467 if(ftos(stof(selected)) != "") { ++sel_num; }
472 "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
473 "^7net_type = %s, net_name = %s, durcnt arg = '%s'.\n"
491 void Create_Notification_Entity(
504 /* MSG_INFO & MSG_CENTER */
523 // =====================
524 // Global Entity Setup
525 // =====================
526 entity notif = new_pure(notification);
531 msg_annce_notifs[nameid - 1] = notif;
532 notif.classname = "msg_annce_notification";
537 msg_info_notifs[nameid - 1] = notif;
538 notif.classname = "msg_info_notification";
543 msg_center_notifs[nameid - 1] = notif;
544 notif.classname = "msg_center_notification";
549 msg_multi_notifs[nameid - 1] = notif;
550 notif.classname = "msg_multi_notification";
555 msg_choice_notifs[nameid - 1] = notif;
556 notif.classname = "msg_choice_notification";
564 "^1NOTIFICATION WITH IMPROPER TYPE: ",
565 "^7net_type = %d, net_name = %s.\n"
570 return; // It's not possible to recover from this one
573 notif.nent_default = var_default;
574 notif.nent_enabled = (1 <= var_cvar);
575 notif.nent_type = typeId;
576 notif.nent_id = nameid;
577 notif.nent_name = strzone(namestring);
579 string typestring = Get_Notif_TypeName(typeId);
581 // Other pre-notif-setup requisites
584 // ====================
585 // Notification Setup
586 // ====================
591 // Set MSG_ANNCE information and handle precaching
593 if (!(GENTLE && (var_cvar == 1)))
597 if(notif.nent_enabled)
599 precache_sound(sprintf("announcer/%s/%s.wav", AnnouncerOption(), snd));
600 notif.nent_channel = channel;
601 notif.nent_snd = strzone(snd);
602 notif.nent_vol = vol;
603 notif.nent_position = position;
610 "^1NOTIFICATION WITH NO SOUND: ",
611 "^7net_type = %s, net_name = %s.\n"
619 else { notif.nent_enabled = false; }
621 notif.nent_enabled = false;
630 // Set MSG_INFO and MSG_CENTER string/float counts
631 notif.nent_stringcount = strnum;
632 notif.nent_floatcount = flnum;
634 // Only initialize arguments if we're either a client or on a dedicated server
636 float should_process_args = server_is_dedicated;
638 float should_process_args = true;
641 if(should_process_args)
643 // ========================
644 // Process Main Arguments
645 // ========================
650 notif.nent_args = strzone(
651 Process_Notif_Args(1, args, typestring, namestring));
653 else if((hudargs == "") && (durcnt ==""))
657 "^1NOTIFICATION HAS ARG COUNTS BUT NO ARGS OR HUDARGS OR DURCNT: ",
658 "^7net_type = %s, net_name = %s, strnum = %d, flnum = %d\n"
670 notif.nent_args = strzone(
671 Process_Notif_Args(1, args, typestring, namestring));
675 // =======================================
676 // Process HUD and Centerprint Arguments
677 // Only processed on CSQC, as these
678 // args are only for HUD features.
679 // =======================================
683 notif.nent_hudargs = strzone(
684 Process_Notif_Args(2, hudargs, typestring, namestring));
686 if(icon != "") { notif.nent_icon = strzone(icon); }
691 "^1NOTIFICATION HAS HUDARGS BUT NO ICON: ",
692 "^7net_type = %s, net_name = %s.\n"
704 "^1NOTIFICATION HAS ICON BUT NO HUDARGS: ",
705 "^7net_type = %s, net_name = %s.\n"
715 notif.nent_durcnt = strzone(
716 Process_Notif_Args(3, durcnt, typestring, namestring));
718 if(cpid != NO_MSG) { notif.nent_cpid = cpid; }
723 "^1NOTIFICATION HAS DURCNT BUT NO CPID: ",
724 "^7net_type = %s, net_name = %s.\n"
732 else if(cpid != NO_MSG) { notif.nent_cpid = cpid; }
736 // ======================
737 // Process Notif String
738 // ======================
739 #define SET_NOTIF_STRING(string,stringname) MACRO_BEGIN { \
740 notif.nent_string = strzone(CCR( \
741 Process_Notif_Line( \
754 if(gentle != "") { SET_NOTIF_STRING(gentle, "GENTLE"); }
755 else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL"); }
757 else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL"); }
758 #undef SET_NOTIF_STRING
760 // Check to make sure a string was chosen
761 if(notif.nent_string == "")
765 "^1EMPTY NOTIFICATION: ",
766 "^7net_type = %s, net_name = %s.\n"
780 // Set MSG_MULTI string/float counts
781 if((anncename == NO_MSG) && (infoname == NO_MSG) && (centername == NO_MSG))
785 "^1NOTIFICATION WITH NO SUBCALLS: ",
786 "^7net_type = %s, net_name = %s.\n"
795 // announcements don't actually need any arguments, so lets not even count them.
796 if(anncename != NO_MSG) { notif.nent_msgannce = msg_annce_notifs[anncename - 1]; }
798 float infoname_stringcount = 0, infoname_floatcount = 0;
799 float centername_stringcount = 0, centername_floatcount = 0;
801 if(infoname != NO_MSG)
803 notif.nent_msginfo = msg_info_notifs[infoname - 1];
804 infoname_stringcount = notif.nent_msginfo.nent_stringcount;
805 infoname_floatcount = notif.nent_msginfo.nent_floatcount;
808 if(centername != NO_MSG)
810 notif.nent_msgcenter = msg_center_notifs[centername - 1];
811 centername_stringcount = notif.nent_msgcenter.nent_stringcount;
812 centername_floatcount = notif.nent_msgcenter.nent_floatcount;
815 // set the requirements of THIS notification to the totals of its subcalls
816 notif.nent_stringcount = max(infoname_stringcount, centername_stringcount);
817 notif.nent_floatcount = max(infoname_floatcount, centername_floatcount);
825 if((chtype == NO_MSG) || (optiona == NO_MSG) || (optionb == NO_MSG))
829 "^1NOTIFICATION IS MISSING CHOICE PARAMS: ",
830 "^7net_type = %s, net_name = %s.\n"
843 notif.nent_optiona = msg_annce_notifs[optiona - 1];
844 notif.nent_optionb = msg_annce_notifs[optionb - 1];
849 notif.nent_optiona = msg_info_notifs[optiona - 1];
850 notif.nent_optionb = msg_info_notifs[optionb - 1];
855 notif.nent_optiona = msg_center_notifs[optiona - 1];
856 notif.nent_optionb = msg_center_notifs[optionb - 1];
861 notif.nent_optiona = msg_multi_notifs[optiona - 1];
862 notif.nent_optionb = msg_multi_notifs[optionb - 1];
865 case MSG_CHOICE: // should we REALLY allow nested options?...
867 notif.nent_optiona = msg_choice_notifs[optiona - 1];
868 notif.nent_optionb = msg_choice_notifs[optionb - 1];
876 "^1NOTIFICATION WITH IMPROPER TYPE: ",
877 "^7net_type = %d, net_name = %s.\n"
886 notif.nent_challow_def = challow_def; // 0: never allowed, 1: allowed in warmup, 2: always allowed
887 notif.nent_challow_var = challow_var; // 0: never allowed, 1: allowed in warmup, 2: always allowed
888 notif.nent_stringcount = max(notif.nent_optiona.nent_stringcount, notif.nent_optionb.nent_stringcount);
889 notif.nent_floatcount = max(notif.nent_optiona.nent_floatcount, notif.nent_optionb.nent_floatcount);
891 /*#ifdef NOTIFICATIONS_DEBUG
892 Debug_Notification(sprintf(
893 "Create_Notification_Entity(...): MSG_CHOICE: %s\n%s\n%s\n",
896 "^ optiona: %s %s : %d %d",
897 Get_Notif_TypeName(notif.nent_optiona.nent_type),
898 notif.nent_optiona.nent_name,
899 notif.nent_optiona.nent_stringcount,
900 notif.nent_optiona.nent_floatcount
903 "^ optionb: %s %s : %d %d",
904 Get_Notif_TypeName(notif.nent_optionb.nent_type),
905 notif.nent_optionb.nent_name,
906 notif.nent_optionb.nent_stringcount,
907 notif.nent_optionb.nent_floatcount
919 "^1NOTIFICATION WITH IMPROPER TYPE: ",
920 "^7net_type = %d, net_name = %s.\n"
930 // now check to see if any errors happened
933 notif.nent_enabled = false; // disable the notification so it can't cause trouble
934 notif_global_error = true; // throw the red flag that an error happened on init
943 // used by MSG_CHOICE to build list of choices
945 void Notification_GetCvars()
947 for(int i = 0; i <= NOTIF_CHOICE_COUNT; ++i)
949 GetCvars_handleFloat(
952 msg_choice_choices[i],
953 sprintf("notification_%s", msg_choice_notifs[i].nent_name)
959 // used to output notifications.cfg file
960 void Dump_Notifications(float fh, float alsoprint)
962 #define NOTIF_WRITE(a) { \
964 if(alsoprint) { LOG_INFO(a); } }
965 #define NOTIF_WRITE_ENTITY(description) { \
968 "seta notification_%s \"%d\" \"%s\"\n", \
969 e.nent_name, e.nent_default, description \
971 NOTIF_WRITE(notif_msg) }
972 #define NOTIF_WRITE_ENTITY_CHOICE(descriptiona,descriptionb) { \
975 "seta notification_%s \"%d\" \"%s\"\n" \
976 "seta notification_%s_ALLOWED \"%d\" \"%s\"\n", \
977 e.nent_name, e.nent_default, descriptiona, \
978 e.nent_name, e.nent_challow_def, descriptionb \
980 NOTIF_WRITE(notif_msg) }
981 #define NOTIF_WRITE_HARDCODED(cvar,default,description) { \
984 "seta notification_%s \"%s\" \"%s\"\n", \
985 cvar, default, description \
987 NOTIF_WRITE(notif_msg) }
993 // Note: This warning only applies to the notifications.cfg file that is output...
995 // You ARE supposed to manually edit this function to add i.e. hard coded
996 // notification variables for mutators or game modes or such and then
997 // regenerate the notifications.cfg file from the new code.
999 NOTIF_WRITE("// ********************************************** //\n");
1000 NOTIF_WRITE("// ** WARNING - DO NOT MANUALLY EDIT THIS FILE ** //\n");
1001 NOTIF_WRITE("// ** ** //\n");
1002 NOTIF_WRITE("// ** This file is automatically generated ** //\n");
1003 NOTIF_WRITE("// ** by code with the command 'dumpnotifs'. ** //\n");
1004 NOTIF_WRITE("// ** ** //\n");
1005 NOTIF_WRITE("// ** If you add a new notification, please ** //\n");
1006 NOTIF_WRITE("// ** regenerate this file with that command ** //\n");
1007 NOTIF_WRITE("// ** making sure that the output matches ** //\n");
1008 NOTIF_WRITE("// ** with the lists and defaults in code. ** //\n");
1009 NOTIF_WRITE("// ** ** //\n");
1010 NOTIF_WRITE("// ********************************************** //\n");
1012 // These notifications will also append their string as a comment...
1013 // This is not necessary, and does not matter if they vary between config versions,
1014 // it is just a semi-helpful tool for those who want to manually change their user settings.
1016 NOTIF_WRITE(sprintf("\n// MSG_ANNCE notifications (count = %d):\n", NOTIF_ANNCE_COUNT));
1017 for(i = 1; i <= NOTIF_ANNCE_COUNT; ++i)
1019 e = Get_Notif_Ent(MSG_ANNCE, i);
1020 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1023 "0 = disabled, 1 = enabled if gentle mode is off, 2 = always enabled"
1027 NOTIF_WRITE(sprintf("\n// MSG_INFO notifications (count = %d):\n", NOTIF_INFO_COUNT));
1028 for(i = 1; i <= NOTIF_INFO_COUNT; ++i)
1030 e = Get_Notif_Ent(MSG_INFO, i);
1031 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1034 "0 = off, 1 = print to console, "
1035 "2 = print to console and chatbox (if notification_allow_chatboxprint is enabled)"
1039 NOTIF_WRITE(sprintf("\n// MSG_CENTER notifications (count = %d):\n", NOTIF_CENTER_COUNT));
1040 for(i = 1; i <= NOTIF_CENTER_COUNT; ++i)
1042 e = Get_Notif_Ent(MSG_CENTER, i);
1043 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1046 "0 = off, 1 = centerprint"
1050 NOTIF_WRITE(sprintf("\n// MSG_MULTI notifications (count = %d):\n", NOTIF_MULTI_COUNT));
1051 for(i = 1; i <= NOTIF_MULTI_COUNT; ++i)
1053 e = Get_Notif_Ent(MSG_MULTI, i);
1054 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1057 "Enable this multiple notification"
1061 NOTIF_WRITE(sprintf("\n// MSG_CHOICE notifications (count = %d):\n", NOTIF_CHOICE_COUNT));
1062 for(i = 1; i <= NOTIF_CHOICE_COUNT; ++i)
1064 e = Get_Notif_Ent(MSG_CHOICE, i);
1065 if (!e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
1067 NOTIF_WRITE_ENTITY_CHOICE(
1068 "Choice for this notification 0 = off, 1 = default message, 2 = verbose message",
1069 "Allow choice for this notification 0 = off, 1 = only in warmup mode, 2 = always"
1073 // edit these to match whichever cvars are used for specific notification options
1074 NOTIF_WRITE("\n// HARD CODED notification variables:\n");
1076 NOTIF_WRITE_HARDCODED(
1077 "allow_chatboxprint", "1",
1078 "Allow INFO notifications to be printed to chat box"
1079 "0 = do not allow, "
1080 "1 = allow only if allowed by individual notification_INFO* cvars, "
1081 "2 = force all INFO notifications to be printed to the chatbox"
1084 NOTIF_WRITE_HARDCODED(
1086 "Print extra debug information on all notification function calls "
1087 "(Requires -DNOTIFICATIONS_DEBUG flag to be enabled on QCSRC compilation)... "
1088 "0 = disabled, 1 = dprint, 2 = print"
1091 NOTIF_WRITE_HARDCODED(
1092 "errors_are_fatal", "1",
1093 "If a notification fails upon initialization, cause a Host_Error to stop the program"
1096 NOTIF_WRITE_HARDCODED(
1097 "item_centerprinttime", "1.5",
1098 "How long to show item information centerprint messages (like 'You got the Electro' or such)"
1101 NOTIF_WRITE_HARDCODED(
1102 "lifetime_mapload", "10",
1103 "Amount of time that notification entities last immediately at mapload (in seconds) "
1104 "to help prevent notifications from being lost on early init (like gamestart countdown)"
1107 NOTIF_WRITE_HARDCODED(
1108 "lifetime_runtime", "0.5",
1109 "Amount of time that notification entities last on the server during runtime (In seconds)"
1112 NOTIF_WRITE_HARDCODED(
1113 "server_allows_location", "1",
1114 "Server side cvar for allowing death messages to show location information too"
1117 NOTIF_WRITE_HARDCODED(
1118 "show_location", "0",
1119 "Append location information to MSG_INFO death/kill messages"
1122 NOTIF_WRITE_HARDCODED(
1123 "show_location_string", "",
1124 "Replacement string piped into sprintf, "
1125 "so you can do different messages like this: ' at the %s' or ' (near %s)'"
1128 NOTIF_WRITE_HARDCODED(
1130 "Print information about sprees in death/kill messages"
1133 NOTIF_WRITE_HARDCODED(
1134 "show_sprees_center", "1",
1135 "Show spree information in MSG_CENTER messages... "
1136 "0 = off, 1 = target (but only for first victim) and attacker"
1139 NOTIF_WRITE_HARDCODED(
1140 "show_sprees_center_specialonly", "1",
1141 "Don't show spree information in MSG_CENTER messages if it isn't an achievement"
1144 NOTIF_WRITE_HARDCODED(
1145 "show_sprees_info", "3",
1146 "Show spree information in MSG_INFO messages... "
1147 "0 = off, 1 = target only, 2 = attacker only, 3 = target and attacker"
1150 NOTIF_WRITE_HARDCODED(
1151 "show_sprees_info_newline", "1",
1152 "Show attacker spree information for MSG_INFO messages on a separate line than the death notification itself"
1155 NOTIF_WRITE_HARDCODED(
1156 "show_sprees_info_specialonly", "1",
1157 "Don't show attacker spree information in MSG_INFO messages if it isn't an achievement"
1160 NOTIF_WRITE(sprintf(
1162 "\n// Notification counts (total = %d): ",
1163 "MSG_ANNCE = %d, MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d, MSG_CHOICE = %d\n"
1168 NOTIF_CENTER_COUNT +
1180 #undef NOTIF_WRITE_HARDCODED
1181 #undef NOTIF_WRITE_ENTITY
1186 // ===============================
1187 // Frontend Notification Pushing
1188 // ===============================
1190 #ifdef NOTIFICATIONS_DEBUG
1191 void Debug_Notification(string input)
1193 switch(autocvar_notification_debug)
1195 case 1: { LOG_TRACE(input); break; }
1196 case 2: { LOG_INFO(input); break; }
1201 string Local_Notification_sprintf(
1202 string input, string args,
1203 string s1, string s2, string s3, string s4,
1204 int f1, float f2, float f3, float f4)
1206 #ifdef NOTIFICATIONS_DEBUG
1207 Debug_Notification(sprintf(
1208 "Local_Notification_sprintf('%s^7', '%s', %s, %s);\n",
1209 MakeConsoleSafe(input),
1211 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1212 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1218 for(sel_num = 0; sel_num < NOTIF_MAX_ARGS; ++sel_num) { arg_slot[sel_num] = ""; }
1222 for(sel_num = 0;(args != "");)
1224 selected = car(args); args = cdr(args);
1225 NOTIF_HIT_MAX(NOTIF_MAX_ARGS, "Local_Notification_sprintf");
1226 switch(strtolower(selected))
1229 #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1230 #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1231 #define ARG_CASE_ARG_CS_SV(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1232 #define ARG_CASE_ARG_CS(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1233 #define ARG_CASE_ARG_SV(selected,result)
1234 #define ARG_CASE_ARG_DC(selected,result)
1236 #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1237 #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1238 #define ARG_CASE_ARG_CS_SV(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1239 #define ARG_CASE_ARG_CS(selected,result)
1240 #define ARG_CASE_ARG_SV(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1241 #define ARG_CASE_ARG_DC(selected,result)
1243 #define ARG_CASE(prog,selected,result) ARG_CASE_##prog(selected,result)
1246 #undef ARG_CASE_ARG_DC
1247 #undef ARG_CASE_ARG_SV
1248 #undef ARG_CASE_ARG_CS
1249 #undef ARG_CASE_ARG_CS_SV
1250 #undef ARG_CASE_ARG_CS_SV_DC
1251 #undef ARG_CASE_ARG_CS_SV_HA
1252 default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
1256 strcat(input, "\n"),
1268 void Local_Notification_sound(
1269 float soundchannel, string soundfile,
1270 float soundvolume, float soundposition)
1272 if((soundfile != prev_soundfile) || (time >= (prev_soundtime + autocvar_cl_announcer_antispam)))
1274 #ifdef NOTIFICATIONS_DEBUG
1275 Debug_Notification(sprintf(
1276 "Local_Notification_sound(world, %f, '%s', %f, %f);\n",
1279 "announcer/%s/%s.wav",
1292 "announcer/%s/%s.wav",
1300 if(prev_soundfile) { strunzone(prev_soundfile); }
1301 prev_soundfile = strzone(soundfile);
1302 prev_soundtime = time;
1306 #ifdef NOTIFICATIONS_DEBUG
1307 Debug_Notification(sprintf(
1309 "Local_Notification_sound(world, %f, '%s', %f, %f) ",
1310 "^1BLOCKED BY ANTISPAM:^7 prevsnd: '%s', timediff: %f, limit: %f\n"
1314 "announcer/%s/%s.wav",
1321 (time - prev_soundtime),
1322 autocvar_cl_announcer_antispam
1328 void Local_Notification_HUD_Notify_Push(
1329 string icon, string hudargs,
1330 string s1, string s2, string s3, string s4,
1331 float f1, float f2, float f3, float f4)
1334 arg_slot[0] = ""; arg_slot[1] = "";
1337 for(sel_num = 0;(hudargs != "");)
1339 selected = car(hudargs); hudargs = cdr(hudargs);
1340 NOTIF_HIT_MAX(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push");
1341 switch(strtolower(selected))
1343 #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1344 #define ARG_CASE_ARG_CS_SV_DC(selected,result)
1345 #define ARG_CASE_ARG_CS_SV(selected,result)
1346 #define ARG_CASE_ARG_CS(selected,result)
1347 #define ARG_CASE_ARG_SV(selected,result)
1348 #define ARG_CASE_ARG_DC(selected,result)
1349 #define ARG_CASE(prog,selected,result) ARG_CASE_##prog(selected,result)
1352 #undef ARG_CASE_ARG_DC
1353 #undef ARG_CASE_ARG_SV
1354 #undef ARG_CASE_ARG_CS
1355 #undef ARG_CASE_ARG_CS_SV
1356 #undef ARG_CASE_ARG_CS_SV_DC
1357 #undef ARG_CASE_ARG_CS_SV_HA
1358 default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
1361 #ifdef NOTIFICATIONS_DEBUG
1362 Debug_Notification(sprintf(
1363 "Local_Notification_HUD_Notify_Push('%s^7', '%s', %s, %s, %s);\n",
1366 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1367 sprintf("%d, %d, %d, %d", f1, f2, f3, f4),
1368 MakeConsoleSafe(sprintf("'%s^7', '%s^7'", stof(arg_slot[0]), stof(arg_slot[1])))
1371 HUD_Notify_Push(icon, arg_slot[0], arg_slot[1]);
1374 void Local_Notification_centerprint_generic(
1375 string input, string durcnt,
1376 int cpid, float f1, float f2)
1378 arg_slot[0] = ""; arg_slot[1] = "";
1380 for(int sel_num = 0;(durcnt != "");)
1382 string selected = car(durcnt); durcnt = cdr(durcnt);
1383 NOTIF_HIT_MAX(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic");
1384 switch(strtolower(selected))
1386 #define ARG_CASE_ARG_CS_SV_HA(selected,result)
1387 #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1388 #define ARG_CASE_ARG_CS_SV(selected,result)
1389 #define ARG_CASE_ARG_CS(selected,result)
1390 #define ARG_CASE_ARG_SV(selected,result)
1391 #define ARG_CASE_ARG_DC(selected,result) case selected: { arg_slot[sel_num] = result; ++sel_num; break; }
1392 #define ARG_CASE(prog,selected,result) ARG_CASE_##prog(selected,result)
1395 #undef ARG_CASE_ARG_DC
1396 #undef ARG_CASE_ARG_SV
1397 #undef ARG_CASE_ARG_CS
1398 #undef ARG_CASE_ARG_CS_SV
1399 #undef ARG_CASE_ARG_CS_SV_DC
1400 #undef ARG_CASE_ARG_CS_SV_HA
1403 if(ftos(stof(selected)) != "") { arg_slot[sel_num] = selected; ++sel_num; }
1404 else { NOTIF_HIT_UNKNOWN(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic") }
1409 #ifdef NOTIFICATIONS_DEBUG
1410 Debug_Notification(sprintf(
1411 "Local_Notification_centerprint_generic('%s^7', '%s', %d, %d, %d, %d);\n",
1412 MakeConsoleSafe(input),
1419 centerprint_generic(cpid, input, stof(arg_slot[0]), stof(arg_slot[1]));
1423 void Local_Notification(int net_type, int net_name, ...count)
1425 // check if this should be aborted
1426 if(net_name == NOTIF_ABORT)
1428 #ifdef NOTIFICATIONS_DEBUG
1429 Debug_Notification(sprintf(
1430 "Local_Notification(%s, %s, ...);\n",
1431 Get_Notif_TypeName(net_type),
1438 // check supplied type and name for errors
1439 string checkargs = Notification_CheckArgs_TypeName(net_type, net_name);
1442 #ifdef NOTIFICATIONS_DEBUG
1443 Debug_Notification(sprintf(
1444 "Local_Notification(%s, %d, ...);\n",
1445 Get_Notif_TypeName(net_type),
1446 Get_Notif_Ent(net_type, net_name).nent_name
1449 backtrace(sprintf("Incorrect usage of Local_Notification: %s\n", checkargs));
1453 // retreive entity of this notification
1454 entity notif = Get_Notif_Ent(net_type, net_name);
1457 #ifdef NOTIFICATIONS_DEBUG
1458 Debug_Notification(sprintf(
1459 "Local_Notification(%s, %d, ...);\n",
1460 Get_Notif_TypeName(net_type),
1464 backtrace("Local_Notification: Could not find notification entity!\n");
1468 // check if the notification is enabled
1469 if (!notif.nent_enabled)
1471 #ifdef NOTIFICATIONS_DEBUG
1472 Debug_Notification(sprintf(
1473 "Local_Notification(%s, %s, ...): Entity was disabled...\n",
1474 Get_Notif_TypeName(net_type),
1481 string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
1482 string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
1483 string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
1484 string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
1485 float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
1486 float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
1487 float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
1488 float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
1490 #ifdef NOTIFICATIONS_DEBUG
1491 Debug_Notification(sprintf(
1492 "Local_Notification(%s, %s, %s, %s);\n",
1493 Get_Notif_TypeName(net_type),
1495 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1496 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1500 if((notif.nent_stringcount + notif.nent_floatcount) > count)
1504 "Not enough arguments for Local_Notification(%s, %s, ...)! ",
1505 "stringcount(%d) + floatcount(%d) > count(%d)\n",
1506 "Check the definition and function call for accuracy...?\n"
1508 Get_Notif_TypeName(net_type),
1510 notif.nent_stringcount,
1511 notif.nent_floatcount,
1516 else if((notif.nent_stringcount + notif.nent_floatcount) < count)
1520 "Too many arguments for Local_Notification(%s, %s, ...)! ",
1521 "stringcount(%d) + floatcount(%d) < count(%d)\n",
1522 "Check the definition and function call for accuracy...?\n"
1524 Get_Notif_TypeName(net_type),
1526 notif.nent_stringcount,
1527 notif.nent_floatcount,
1538 Local_Notification_sound(
1545 backtrace("MSG_ANNCE on server?... Please notify Samual immediately!\n");
1553 Local_Notification_sprintf(
1560 if(notif.nent_icon != "")
1562 if ( notif.nent_iconargs != "" )
1564 notif.nent_icon = Local_Notification_sprintf(
1565 notif.nent_icon,notif.nent_iconargs,
1566 s1, s2, s3, s4, f1, f2, f3, f4);
1567 // remove the newline added by Local_Notification_sprintf
1568 notif.nent_icon = strzone(substring(notif.nent_icon,0,strlen(notif.nent_icon)-1));
1570 Local_Notification_HUD_Notify_Push(
1583 Local_Notification_centerprint_generic(
1584 Local_Notification_sprintf(
1598 if(notif.nent_msginfo)
1599 if(notif.nent_msginfo.nent_enabled)
1601 Local_Notification_WOVA(
1603 notif.nent_msginfo.nent_id,
1604 notif.nent_msginfo.nent_stringcount,
1605 notif.nent_msginfo.nent_floatcount,
1610 if(notif.nent_msgannce)
1611 if(notif.nent_msgannce.nent_enabled)
1613 Local_Notification_WOVA(
1615 notif.nent_msgannce.nent_id,
1620 if(notif.nent_msgcenter)
1621 if(notif.nent_msgcenter.nent_enabled)
1623 Local_Notification_WOVA(
1625 notif.nent_msgcenter.nent_id,
1626 notif.nent_msgcenter.nent_stringcount,
1627 notif.nent_msgcenter.nent_floatcount,
1637 entity found_choice;
1639 if(notif.nent_challow_var && (warmup_stage || (notif.nent_challow_var == 2)))
1641 switch(cvar(sprintf("notification_%s", notif.nent_name)))
1643 case 1: found_choice = notif.nent_optiona; break;
1644 case 2: found_choice = notif.nent_optionb; break;
1645 default: return; // not enabled anyway
1648 else { found_choice = notif.nent_optiona; }
1650 Local_Notification_WOVA(
1651 found_choice.nent_type,
1652 found_choice.nent_id,
1653 found_choice.nent_stringcount,
1654 found_choice.nent_floatcount,
1661 // WOVA = Without Variable Arguments
1662 void Local_Notification_WOVA(
1663 int net_type, float net_name,
1664 float stringcount, float floatcount,
1665 string s1, string s2, string s3, string s4,
1666 float f1, float f2, float f3, float f4)
1668 #define VARITEM(stringc,floatc,args) \
1669 if((stringcount == stringc) && (floatcount == floatc)) \
1670 { Local_Notification(net_type, net_name, args); return; }
1671 EIGHT_VARS_TO_VARARGS_VARLIST
1673 Local_Notification(net_type, net_name); // some notifications don't have any arguments at all
1677 // =========================
1678 // Notification Networking
1679 // =========================
1681 REGISTER_NET_LINKED(ENT_CLIENT_NOTIFICATION)
1684 NET_HANDLE(ENT_CLIENT_NOTIFICATION, bool is_new)
1686 int net_type = ReadByte();
1687 int net_name = ReadShort();
1692 if(net_type == MSG_CENTER_CPID)
1694 #ifdef NOTIFICATIONS_DEBUG
1695 Debug_Notification(sprintf(
1696 "Read_Notification(%d) at %f: net_type = %s, net_name = %d\n",
1699 Get_Notif_TypeName(net_type),
1706 if(net_name == 0) { reset_centerprint_messages(); }
1707 else if(net_name != NO_CPID)
1709 // in this case, net_name IS the cpid we want to kill
1710 centerprint_generic(net_name, "", 0, 0);
1715 "Read_Notification(%d) at %f: ^1TRIED TO KILL NO_CPID CENTERPRINT!\n",
1724 notif = Get_Notif_Ent(net_type, net_name);
1725 if (!notif) { backtrace("Read_Notification: Could not find notification entity!\n"); return; }
1727 #ifdef NOTIFICATIONS_DEBUG
1728 Debug_Notification(sprintf(
1729 "Read_Notification(%d) at %f: net_type = %s, net_name = %s\n",
1732 Get_Notif_TypeName(net_type),
1737 string s1 = ((0 < notif.nent_stringcount) ? ReadString() : "");
1738 string s2 = ((1 < notif.nent_stringcount) ? ReadString() : "");
1739 string s3 = ((2 < notif.nent_stringcount) ? ReadString() : "");
1740 string s4 = ((3 < notif.nent_stringcount) ? ReadString() : "");
1741 float f1 = ((0 < notif.nent_floatcount) ? ReadLong() : 0);
1742 float f2 = ((1 < notif.nent_floatcount) ? ReadLong() : 0);
1743 float f3 = ((2 < notif.nent_floatcount) ? ReadLong() : 0);
1744 float f4 = ((3 < notif.nent_floatcount) ? ReadLong() : 0);
1748 Local_Notification_WOVA(
1750 notif.nent_stringcount,
1751 notif.nent_floatcount,
1760 void Net_Notification_Remove()
1762 if (!self) { backtrace(sprintf("Net_Notification_Remove() at %f: Missing self!?\n", time)); return; }
1764 #ifdef NOTIFICATIONS_DEBUG
1765 Debug_Notification(sprintf(
1766 "Net_Notification_Remove() at %f: %s '%s - %s' notification\n",
1768 ((self.nent_net_name == -1) ? "Killed" : "Removed"),
1769 Get_Notif_TypeName(self.nent_net_type),
1770 self.owner.nent_name
1774 for(int i = 0; i < 4; ++i) { if(self.nent_strings[i]) { strunzone(self.nent_strings[i]); } }
1778 bool Net_Write_Notification(entity this, entity client, int sf)
1780 if(Notification_ShouldSend(self.nent_broadcast, client, self.nent_client))
1782 WriteHeader(MSG_ENTITY, ENT_CLIENT_NOTIFICATION);
1783 WriteByte(MSG_ENTITY, self.nent_net_type);
1784 WriteShort(MSG_ENTITY, self.nent_net_name);
1785 for(int i = 0; i < self.nent_stringcount; ++i) { WriteString(MSG_ENTITY, self.nent_strings[i]); }
1786 for(int i = 0; i < self.nent_floatcount; ++i) { WriteLong(MSG_ENTITY, self.nent_floats[i]); }
1789 else { return false; }
1792 void Kill_Notification(
1793 float broadcast, entity client,
1794 float net_type, float net_name)
1796 #ifdef NOTIFICATIONS_DEBUG
1797 Debug_Notification(sprintf(
1798 "Kill_Notification(%s, '%s', %s, %d);\n",
1799 Get_Notif_BroadcastName(broadcast),
1801 (net_type ? Get_Notif_TypeName(net_type) : "0"),
1806 string checkargs = Notification_CheckArgs(broadcast, client, 1, 1);
1807 if(checkargs != "") { backtrace(sprintf("Incorrect usage of Kill_Notification: %s\n", checkargs)); return; }
1810 float killed_cpid = NO_CPID;
1816 killed_cpid = 0; // kill ALL centerprints
1824 entity notif = Get_Notif_Ent(net_type, net_name);
1825 if (!notif) { backtrace("Kill_Notification: Could not find notification entity!\n"); return; }
1828 killed_cpid = notif.nent_cpid;
1830 killed_cpid = NO_CPID;
1834 killed_cpid = 0; // kill ALL centerprints
1839 case MSG_CENTER_CPID:
1841 killed_cpid = net_name;
1846 if(killed_cpid != NO_CPID)
1848 net_notif = new(net_kill_notification);
1849 make_pure(net_notif);
1850 net_notif.nent_broadcast = broadcast;
1851 net_notif.nent_client = client;
1852 net_notif.nent_net_type = MSG_CENTER_CPID;
1853 net_notif.nent_net_name = killed_cpid;
1854 Net_LinkEntity(net_notif, false, autocvar_notification_lifetime_runtime, Net_Write_Notification);
1857 FOREACH_ENTITY_CLASS("net_notification", true,
1861 if((killed_cpid != NO_CPID) && (it.nent_net_type == MSG_CENTER))
1863 if(it.owner.nent_cpid == killed_cpid)
1865 it.nent_net_name = -1;
1866 it.nextthink = time;
1868 else { continue; } // we ARE looking for a specific CPID, don't kill everything else too
1870 else if(it.nent_net_type == net_type)
1874 if(it.nent_net_name == net_name) { it.nent_net_name = -1; it.nextthink = time; }
1875 else { continue; } // we ARE looking for a certain net_name, don't kill everything else too
1877 else { it.nent_net_name = -1; it.nextthink = time; }
1879 else { continue; } // we ARE looking for a certain net_type, don't kill everything else too
1881 else { it.nent_net_name = -1; it.nextthink = time; }
1885 void Send_Notification(
1886 float broadcast, entity client,
1887 float net_type, float net_name,
1890 // check if this should be aborted
1891 if(net_name == NOTIF_ABORT)
1893 #ifdef NOTIFICATIONS_DEBUG
1894 Debug_Notification(sprintf(
1895 "Send_Notification(%s, '%s', %s, %s, ...);\n",
1896 Get_Notif_BroadcastName(broadcast),
1898 Get_Notif_TypeName(net_type),
1905 // check supplied broadcast, target, type, and name for errors
1906 string checkargs = Notification_CheckArgs(broadcast, client, net_type, net_name);
1909 #ifdef NOTIFICATIONS_DEBUG
1910 Debug_Notification(sprintf(
1911 "Send_Notification(%s, '%s', %s, %s, ...);\n",
1912 Get_Notif_BroadcastName(broadcast),
1914 Get_Notif_TypeName(net_type),
1915 Get_Notif_Ent(net_type, net_name).nent_name
1918 backtrace(sprintf("Incorrect usage of Send_Notification: %s\n", checkargs));
1922 // retreive entity of this notification
1923 entity notif = Get_Notif_Ent(net_type, net_name);
1926 #ifdef NOTIFICATIONS_DEBUG
1927 Debug_Notification(sprintf(
1928 "Send_Notification(%s, '%s', %s, %d, ...);\n",
1929 Get_Notif_BroadcastName(broadcast),
1931 Get_Notif_TypeName(net_type),
1935 backtrace("Send_Notification: Could not find notification entity!\n");
1939 string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
1940 string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
1941 string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
1942 string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
1943 float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
1944 float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
1945 float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
1946 float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
1948 #ifdef NOTIFICATIONS_DEBUG
1949 Debug_Notification(sprintf(
1950 "Send_Notification(%s, %s, %s);\n",
1953 Get_Notif_BroadcastName(broadcast),
1955 Get_Notif_TypeName(net_type),
1958 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
1959 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
1963 if((notif.nent_stringcount + notif.nent_floatcount) > count)
1966 #ifdef NOTIFICATIONS_DEBUG
1967 Get_Notif_BroadcastName(broadcast);
1973 "Not enough arguments for Send_Notification(%s, ...)! ",
1974 "stringcount(%d) + floatcount(%d) > count(%d)\n",
1975 "Check the definition and function call for accuracy...?\n"
1981 Get_Notif_TypeName(net_type),
1984 notif.nent_stringcount,
1985 notif.nent_floatcount,
1990 else if((notif.nent_stringcount + notif.nent_floatcount) < count)
1993 #ifdef NOTIFICATIONS_DEBUG
1994 Get_Notif_BroadcastName(broadcast);
2000 "Too many arguments for Send_Notification(%s, ...)! ",
2001 "stringcount(%d) + floatcount(%d) < count(%d)\n",
2002 "Check the definition and function call for accuracy...?\n"
2008 Get_Notif_TypeName(net_type),
2011 notif.nent_stringcount,
2012 notif.nent_floatcount,
2022 broadcast == NOTIF_ALL
2024 broadcast == NOTIF_ALL_EXCEPT
2028 net_type == MSG_ANNCE
2030 net_type == MSG_CENTER
2034 Local_Notification_WOVA(
2036 notif.nent_stringcount,
2037 notif.nent_floatcount,
2042 if(net_type == MSG_CHOICE)
2044 // THIS GETS TRICKY... now we have to cycle through each possible player (checking broadcast)
2045 // and then do an individual NOTIF_ONE_ONLY recursive call for each one depending on their option...
2046 // It's slow, but it's better than the alternatives:
2047 // 1. Constantly networking all info and letting client decide
2048 // 2. Manually handling each separate call on per-usage basis (See old CTF usage of verbose)
2049 entity found_choice;
2051 #define RECURSE_FROM_CHOICE(ent,action) MACRO_BEGIN { \
2052 if(notif.nent_challow_var && (warmup_stage || (notif.nent_challow_var == 2))) \
2054 switch(ent.msg_choice_choices[net_name - 1]) \
2056 case 1: found_choice = notif.nent_optiona; break; \
2057 case 2: found_choice = notif.nent_optionb; break; \
2061 else { found_choice = notif.nent_optiona; } \
2062 Send_Notification_WOVA( \
2065 found_choice.nent_type, \
2066 found_choice.nent_id, \
2067 found_choice.nent_stringcount, \
2068 found_choice.nent_floatcount, \
2075 case NOTIF_ONE_ONLY: // we can potentially save processing power with this broadcast method
2077 if(IS_REAL_CLIENT(client))
2079 RECURSE_FROM_CHOICE(client, return);
2085 FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(
2086 if(Notification_ShouldSend(broadcast, it, client))
2088 RECURSE_FROM_CHOICE(it, continue);
2097 entity net_notif = new(net_notification);
2098 make_pure(net_notif);
2099 net_notif.owner = notif;
2100 net_notif.nent_broadcast = broadcast;
2101 net_notif.nent_client = client;
2102 net_notif.nent_net_type = net_type;
2103 net_notif.nent_net_name = net_name;
2104 net_notif.nent_stringcount = notif.nent_stringcount;
2105 net_notif.nent_floatcount = notif.nent_floatcount;
2107 for(int i = 0; i < net_notif.nent_stringcount; ++i)
2108 { net_notif.nent_strings[i] = strzone(...(i, string)); }
2109 for(int i = 0; i < net_notif.nent_floatcount; ++i)
2110 { net_notif.nent_floats[i] = ...((net_notif.nent_stringcount + i), float); }
2112 net_notif.think = Net_Notification_Remove;
2113 net_notif.nextthink =
2114 ((time > autocvar_notification_lifetime_mapload)
2116 (time + autocvar_notification_lifetime_runtime)
2118 autocvar_notification_lifetime_mapload
2121 Net_LinkEntity(net_notif, false, 0, Net_Write_Notification);
2125 // WOVA = Without Variable Arguments
2126 void Send_Notification_WOVA(
2127 float broadcast, entity client,
2128 float net_type, float net_name,
2129 float stringcount, float floatcount,
2130 string s1, string s2, string s3, string s4,
2131 float f1, float f2, float f3, float f4)
2133 #ifdef NOTIFICATIONS_DEBUG
2134 entity notif = Get_Notif_Ent(net_type, net_name);
2135 Debug_Notification(sprintf(
2136 "Send_Notification_WOVA(%s, %d, %d, %s, %s);\n",
2139 Get_Notif_BroadcastName(broadcast),
2141 Get_Notif_TypeName(net_type),
2146 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
2147 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
2151 #define VARITEM(stringc,floatc,args) \
2152 if((stringcount == stringc) && (floatcount == floatc)) \
2153 { Send_Notification(broadcast, client, net_type, net_name, args); return; }
2154 EIGHT_VARS_TO_VARARGS_VARLIST
2156 Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
2159 // WOCOVA = Without Counts Or Variable Arguments
2160 void Send_Notification_WOCOVA(
2161 float broadcast, entity client,
2162 float net_type, float net_name,
2163 string s1, string s2, string s3, string s4,
2164 float f1, float f2, float f3, float f4)
2166 entity notif = Get_Notif_Ent(net_type, net_name);
2168 #ifdef NOTIFICATIONS_DEBUG
2169 Debug_Notification(sprintf(
2170 "Send_Notification_WOCOVA(%s, %s, %s);\n",
2173 Get_Notif_BroadcastName(broadcast),
2175 Get_Notif_TypeName(net_type),
2178 MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
2179 sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
2183 #define VARITEM(stringc,floatc,args) \
2184 if((notif.nent_stringcount == stringc) && (notif.nent_floatcount == floatc)) \
2185 { Send_Notification(broadcast, client, net_type, net_name, args); return; }
2186 EIGHT_VARS_TO_VARARGS_VARLIST
2188 Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
2190 #endif // ifdef SVQC