+// used by restartnotifs command to initialize notifications
+void Destroy_Notification_Entity(entity notif)
+{
+ if(notif.nent_name != "") { strunzone(notif.nent_name); }
+ if(notif.nent_snd != "") { strunzone(notif.nent_snd); }
+ if(notif.nent_args != "") { strunzone(notif.nent_args); }
+ if(notif.nent_hudargs != "") { strunzone(notif.nent_hudargs); }
+ if(notif.nent_icon != "") { strunzone(notif.nent_icon); }
+ if(notif.nent_durcnt != "") { strunzone(notif.nent_durcnt); }
+ if(notif.nent_string != "") { strunzone(notif.nent_string); }
+ remove(notif);
+}
+
+void Destroy_All_Notifications(void)
+{
+ entity notif;
+ float i;
+
+ #define DESTROY_LOOP(type,count) \
+ for(i = 1; i <= count; ++i) \
+ { \
+ notif = Get_Notif_Ent(type, i); \
+ if not(notif) { backtrace("Destroy_All_Notifications(): Missing notification entity!\n"); return; } \
+ Destroy_Notification_Entity(notif); \
+ }
+
+ // kill all networked notifications and centerprints
+ #ifdef SVQC
+ Kill_Notification(NOTIF_ALL, world, 0, 0);
+ #else
+ reset_centerprint_messages();
+ #endif
+
+ // kill all real notification entities
+ DESTROY_LOOP(MSG_ANNCE, NOTIF_ANNCE_COUNT)
+ DESTROY_LOOP(MSG_INFO, NOTIF_INFO_COUNT)
+ DESTROY_LOOP(MSG_CENTER, NOTIF_CENTER_COUNT)
+ DESTROY_LOOP(MSG_MULTI, NOTIF_MULTI_COUNT)
+ #undef DESTROY_LOOP
+}
+
+string Process_Notif_Line(
+ float msg_is_info,
+ float chat,
+ string input,
+ string notiftype,
+ string notifname,
+ string stringtype)
+{
+ if(msg_is_info)
+ {
+ #ifdef CSQC
+ if((chat && autocvar_notification_allow_chatboxprint)
+ || (autocvar_notification_allow_chatboxprint == 2))
+ {
+ // pass 1: add ETX char at beginning of line
+ input = strcat("\{3}", input);
+
+ // pass 2: add ETX char at end of each new line (so that
+ // messages with multiple lines are put through chatbox too)
+ input = strreplace("\n", "\n\{3}", input);
+
+ // pass 3: strip trailing ETX char
+ if(substring(input, (strlen(input) - 1), 1) == "\{3}")
+ { input = substring(input, 0, (strlen(input) - 1)); }
+ }
+ #endif
+ if(substring(input, (strlen(input) - 1), 1) != "\n")
+ {
+ print(sprintf(
+ strcat(
+ "^1MISSING/BROKEN NEW LINE AT END OF NOTIFICATION: ",
+ "^7net_type = %s, net_name = %s, string = %s.\n"
+ ),
+ notiftype,
+ notifname,
+ stringtype
+ ));
+ notif_error = TRUE;
+ return strcat(input, "\n");
+ }
+ }
+ return input;
+}
+
+string Process_Notif_Args(
+ float arg_type,
+ string args,
+ string notiftype,
+ string notifname)
+{
+ string selected, remaining = args;
+ float sel_num = 0;
+
+ for(;(remaining != "");)
+ {
+ selected = car(remaining); remaining = cdr(remaining);
+
+ switch(arg_type)
+ {
+ case 1: // normal args
+ {
+ if(sel_num == NOTIF_MAX_ARGS)
+ {
+ print(sprintf(
+ strcat(
+ "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
+ "^7net_type = %s, net_name = %s, max args = %d.\n"
+ ),
+ notiftype,
+ notifname,
+ NOTIF_MAX_ARGS
+ ));
+ notif_error = TRUE;
+ break;
+ }
+
+ switch(strtolower(selected))
+ {
+ #define ARG_CASE(prog,selected,result) \
+ #if (prog != ARG_DC) \
+ case selected: { ++sel_num; break; } \
+ #endif
+ NOTIF_ARGUMENT_LIST
+ #undef ARG_CASE
+ default:
+ {
+ print(sprintf(
+ strcat(
+ "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
+ "^7net_type = %s, net_name = %s, args arg = '%s'.\n"
+ ),
+ notiftype,
+ notifname,
+ selected
+ ));
+ notif_error = TRUE;
+ break;
+ }
+ }
+ break;
+ }
+ case 2: // hudargs
+ {
+ if(sel_num == NOTIF_MAX_HUDARGS)
+ {
+ print(sprintf(
+ strcat(
+ "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
+ "^7net_type = %s, net_name = %s, max hudargs = %d.\n"
+ ),
+ notiftype,
+ notifname,
+ NOTIF_MAX_HUDARGS
+ ));
+ notif_error = TRUE;
+ break;
+ }
+
+ switch(strtolower(selected))
+ {
+ #define ARG_CASE(prog,selected,result) \
+ #if (prog == ARG_CS_SV_HA) \
+ case selected: { ++sel_num; break; } \
+ #endif
+ NOTIF_ARGUMENT_LIST
+ #undef ARG_CASE
+ default:
+ {
+ print(sprintf(
+ strcat(
+ "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
+ "^7net_type = %s, net_name = %s, hudargs arg = '%s'.\n"
+ ),
+ notiftype,
+ notifname,
+ selected
+ ));
+ notif_error = TRUE;
+ break;
+ }
+ }
+ break;
+ }
+ case 3: // durcnt
+ {
+ if(sel_num == NOTIF_MAX_DURCNT)
+ {
+ print(sprintf(
+ strcat(
+ "^1NOTIFICATION HAS TOO MANY ARGUMENTS: ",
+ "^7net_type = %s, net_name = %s, max durcnt = %d.\n"
+ ),
+ notiftype,
+ notifname,
+ NOTIF_MAX_DURCNT
+ ));
+ notif_error = TRUE;
+ break;
+ }
+
+ switch(strtolower(selected))
+ {
+ #define ARG_CASE(prog,selected,result) \
+ #if (prog == ARG_CS_SV_DC) || (prog == ARG_DC) \
+ case selected: { ++sel_num; break; } \
+ #endif
+ NOTIF_ARGUMENT_LIST
+ #undef ARG_CASE
+ default:
+ {
+ if(ftos(stof(selected)) != "") { ++sel_num; }
+ else
+ {
+ print(sprintf(
+ strcat(
+ "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
+ "^7net_type = %s, net_name = %s, durcnt arg = '%s'.\n"
+ ),
+ notiftype,
+ notifname,
+ selected
+ ));
+ notif_error = TRUE;
+ }
+ break;
+ }
+ }
+ break;
+ }
+ }
+ }
+ return args;
+}
+
+void Create_Notification_Entity(
+ float var_default,
+ float var_cvar,
+ float typeid,
+ float nameid,
+ string namestring,
+ float anncename,
+ float infoname,
+ float centername,
+ float channel,
+ string snd,
+ float vol,
+ float position,
+ float strnum,
+ float flnum,
+ string args,
+ string hudargs,
+ string icon,
+ float cpid,
+ string durcnt,
+ string normal,
+ string gentle,
+ float msg_is_info,
+ float msg_is_multi)
+{
+ // =====================
+ // Global Entity Setup
+ // =====================
+ entity notif = spawn();
+ string typestring = "";
+ switch(typeid)
+ {
+ case MSG_ANNCE:
+ {
+ typestring = "MSG_ANNCE";
+ msg_annce_notifs[nameid - 1] = notif;
+ notif.classname = "msg_annce_notification";
+ break;
+ }
+ case MSG_INFO:
+ {
+ typestring = "MSG_INFO";
+ msg_info_notifs[nameid - 1] = notif;
+ notif.classname = "msg_info_notification";
+ break;
+ }
+ case MSG_CENTER:
+ {
+ typestring = "MSG_CENTER";
+ msg_center_notifs[nameid - 1] = notif;
+ notif.classname = "msg_center_notification";
+ break;
+ }
+ case MSG_MULTI:
+ {
+ typestring = "MSG_MULTI";
+ msg_multi_notifs[nameid - 1] = notif;
+ notif.classname = "MSG_MULTI_notification";
+ break;
+ }
+
+ default:
+ {
+ error(sprintf(
+ strcat(
+ "^1NOTIFICATION WITH IMPROPER TYPE: ",
+ "^7net_type = %d, net_name = %s.\n"
+ ),
+ typeid,
+ namestring
+ ));
+ return; // It's not possible to recover from this one
+ }
+ }
+ notif.nent_default = var_default;
+ notif.nent_name = strzone(namestring);
+ notif.nent_id = nameid;
+ notif.nent_enabled = (1 <= var_cvar);
+
+ // Other pre-notif-setup requisites
+ notif_error = FALSE;
+
+ // ====================
+ // Notification Setup
+ // ====================
+ if(msg_is_multi)
+ {
+ // Set MSG_MULTI string/float counts
+ if((anncename == NO_MSG) && (infoname == NO_MSG) && (centername == NO_MSG))
+ {
+ print(sprintf(
+ strcat(
+ "^1NOTIFICATION WITH NO SUBCALLS: ",
+ "^7net_type = %s, net_name = %s.\n"
+ ),
+ typestring,
+ namestring
+ ));
+ notif_error = TRUE;
+ }
+ else
+ {
+ // announcements don't actually need any arguments, so lets not even count them.
+ if(anncename != NO_MSG) { notif.nent_msgannce = msg_annce_notifs[anncename - 1]; }
+
+ float infoname_stringcount = 0, infoname_floatcount = 0;
+ float centername_stringcount = 0, centername_floatcount = 0;
+
+ if(infoname != NO_MSG)
+ {
+ notif.nent_msginfo = msg_info_notifs[infoname - 1];
+ infoname_stringcount = notif.nent_msginfo.nent_stringcount;
+ infoname_floatcount = notif.nent_msginfo.nent_floatcount;
+ }
+
+ if(centername != NO_MSG)
+ {
+ notif.nent_msgcenter = msg_center_notifs[centername - 1];
+ centername_stringcount = notif.nent_msgcenter.nent_stringcount;
+ centername_floatcount = notif.nent_msgcenter.nent_floatcount;
+ }
+
+ // set the requirements of THIS notification to the totals of its subcalls
+ notif.nent_stringcount = max(infoname_stringcount, centername_stringcount);
+ notif.nent_floatcount = max(infoname_floatcount, centername_floatcount);
+ }
+ }
+ else if(typeid == MSG_ANNCE)
+ {
+ // Set MSG_ANNCE information and handle precaching
+ #ifdef CSQC
+ if not(GENTLE && (var_cvar == 1))
+ {
+ if(snd != "")
+ {
+ if(notif.nent_enabled)
+ {
+ precache_sound(sprintf("announcer/%s/%s.wav", autocvar_cl_announcer, snd));
+ notif.nent_channel = channel;
+ notif.nent_snd = strzone(snd);
+ notif.nent_vol = vol;
+ notif.nent_position = position;
+ }
+ }
+ else
+ {
+ print(sprintf(
+ strcat(
+ "^1NOTIFICATION WITH NO SOUND: ",
+ "^7net_type = %s, net_name = %s.\n"
+ ),
+ typestring,
+ namestring
+ ));
+ notif_error = TRUE;
+ }
+ }
+ else { notif.nent_enabled = FALSE; }
+ #else
+ notif.nent_enabled = FALSE;
+ #endif
+ }
+ else
+ {
+ // Set MSG_INFO and MSG_CENTER string/float counts
+ notif.nent_stringcount = strnum;
+ notif.nent_floatcount = flnum;
+
+ // Only initialize arguments if we're either a client or on a dedicated server
+ #ifdef SVQC
+ float should_process_args = server_is_dedicated;
+ #else
+ float should_process_args = TRUE;
+ #endif
+
+ if(should_process_args)
+ {
+ // ========================
+ // Process Main Arguments
+ // ========================
+ if(strnum + flnum)
+ {
+ if(args != "")
+ {
+ notif.nent_args = strzone(
+ Process_Notif_Args(1, args, typestring, namestring));
+ }
+ else if((hudargs == "") && (durcnt ==""))
+ {
+ print(sprintf(
+ strcat(
+ "^1NOTIFICATION HAS ARG COUNTS BUT NO ARGS OR HUDARGS OR DURCNT: ",
+ "^7net_type = %s, net_name = %s, strnum = %d, flnum = %d\n"
+ ),
+ typestring,
+ namestring,
+ strnum,
+ flnum
+ ));
+ notif_error = TRUE;
+ }
+ }
+ else if(args != "")
+ {
+ notif.nent_args = strzone(
+ Process_Notif_Args(1, args, typestring, namestring));
+ }
+
+
+ // =======================================
+ // Process HUD and Centerprint Arguments
+ // Only processed on CSQC, as these
+ // args are only for HUD features.
+ // =======================================
+ #ifdef CSQC
+ if(hudargs != "")
+ {
+ notif.nent_hudargs = strzone(
+ Process_Notif_Args(2, hudargs, typestring, namestring));
+
+ if(icon != "") { notif.nent_icon = strzone(icon); }
+ else
+ {
+ print(sprintf(
+ strcat(
+ "^1NOTIFICATION HAS HUDARGS BUT NO ICON: ",
+ "^7net_type = %s, net_name = %s.\n"
+ ),
+ typestring,
+ namestring
+ ));
+ notif_error = TRUE;
+ }
+ }
+ else if(icon != "")
+ {
+ print(sprintf(
+ strcat(
+ "^1NOTIFICATION HAS ICON BUT NO HUDARGS: ",
+ "^7net_type = %s, net_name = %s.\n"
+ ),
+ typestring,
+ namestring
+ ));
+ notif_error = TRUE;
+ }
+
+ if(durcnt != "")
+ {
+ notif.nent_durcnt = strzone(
+ Process_Notif_Args(3, durcnt, typestring, namestring));
+
+ if(cpid != NO_MSG) { notif.nent_cpid = cpid; }
+ else
+ {
+ print(sprintf(
+ strcat(
+ "^1NOTIFICATION HAS DURCNT BUT NO CPID: ",
+ "^7net_type = %s, net_name = %s.\n"
+ ),
+ typestring,
+ namestring
+ ));
+ notif_error = TRUE;
+ }
+ }
+ else if(cpid != NO_MSG) { notif.nent_cpid = cpid; }
+ #endif
+
+
+ // ======================
+ // Process Notif String
+ // ======================
+ #define SET_NOTIF_STRING(string,stringname) \
+ notif.nent_string = strzone(CCR( \
+ Process_Notif_Line( \
+ msg_is_info, \
+ (var_cvar > 1), \
+ string, \
+ typestring, \
+ namestring, \
+ stringname \
+ )) \
+ );
+
+ if(GENTLE)
+ {
+ if(gentle != "") { SET_NOTIF_STRING(gentle, "GENTLE") }
+ else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL") }
+ }
+ else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL") }
+
+ #undef SET_NOTIF_STRING
+
+ // Check to make sure a string was chosen
+ if(notif.nent_string == "")
+ {
+ print(sprintf(
+ strcat(
+ "^1EMPTY NOTIFICATION: ",
+ "^7net_type = %s, net_name = %s.\n"
+ ),
+ typestring,
+ namestring
+ ));
+ notif_error = TRUE;
+ }
+ }
+ }
+
+ // now check to see if any errors happened
+ if(notif_error)
+ {
+ notif.nent_enabled = FALSE; // disable the notification so it can't cause trouble
+ notif_global_error = TRUE; // throw the red flag that an error happened on init
+ }
+}
+
+
+// =========================================
+// Cvar Handling With 'dumpnotifs' Command
+// =========================================
+