}
#endif
+// ===============================
+// Initialization Core Functions
+// ===============================
+
+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 = MSG_%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 = MSG_%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) case selected: { ++sel_num; break; }
+ NOTIF_ARGUMENT_LIST
+ #undef ARG_CASE
+ default:
+ {
+ print(sprintf(
+ strcat(
+ "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ",
+ "^7net_type = MSG_%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 = MSG_%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 = MSG_%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 = MSG_%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 = MSG_%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 infoname,
+ float centername,
+ 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_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_WEAPON:
+ {
+ typestring = "MSG_WEAPON";
+ msg_weapon_notifs[nameid - 1] = notif;
+ notif.classname = "msg_weapon_notification";
+ break;
+ }
+ case MSG_DEATH:
+ {
+ typestring = "MSG_DEATH";
+ msg_death_notifs[nameid - 1] = notif;
+ notif.classname = "msg_death_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_WEAPON and MSG_DEATH string/float counts
+ if((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
+ {
+ 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
+ {
+ // 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 = MSG_%s, net_name = %s.\n"
+ ),
+ typestring,
+ namestring
+ ));
+ notif_error = TRUE;
+ }
+ }
+ else if(icon != "")
+ {
+ print(sprintf(
+ strcat(
+ "^1NOTIFICATION HAS ICON BUT NO HUDARGS: ",
+ "^7net_type = MSG_%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 = MSG_%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 = MSG_%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
+ }
+}
+
+
// ===============================
// Frontend Notification Pushing
// ===============================
float f1, float f2, float f3, float f4)
{
#ifdef NOTIFICATIONS_DEBUG
- dprint(
- sprintf("Local_Notification_sprintf('%s^7', '%s', %s, %s);\n",
- strreplace("\n", "\\n", input),
- args,
- strreplace("\n", "\\n", sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
- sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
- )
- );
+ dprint(sprintf(
+ "Local_Notification_sprintf('%s^7', '%s', %s, %s);\n",
+ strreplace("\n", "\\n", input),
+ args,
+ strreplace("\n", "\\n", sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
+ sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
+ ));
#endif
string selected;
}
}
#ifdef NOTIFICATIONS_DEBUG
- dprint(
- sprintf("Local_Notification_HUD_Notify_Push('%s^7', '%s', %s, %s);\n",
- icon,
- hudargs,
- strreplace("\n", "\\n", sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
- strreplace("\n", "\\n", sprintf("'%s^7', '%s^7'", stof(arg_slot[0]), stof(arg_slot[1])))
- )
- );
+ dprint(sprintf(
+ "Local_Notification_HUD_Notify_Push('%s^7', '%s', %s, %s);\n",
+ icon,
+ hudargs,
+ strreplace("\n", "\\n", sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
+ strreplace("\n", "\\n", sprintf("'%s^7', '%s^7'", stof(arg_slot[0]), stof(arg_slot[1])))
+ ));
#endif
HUD_Notify_Push(icon, arg_slot[0], arg_slot[1]);
}
}
}
#ifdef NOTIFICATIONS_DEBUG
- dprint(
- sprintf("Local_Notification_centerprint_generic('%s^7', '%s', %d, %d, %d, %d);\n",
- strreplace("\n", "\\n", input),
- durcnt,
- f1, f2,
- stof(arg_slot[0]), stof(arg_slot[1])
- )
- );
+ dprint(sprintf(
+ "Local_Notification_centerprint_generic('%s^7', '%s', %d, %d, %d, %d);\n",
+ strreplace("\n", "\\n", input),
+ durcnt,
+ f1, f2,
+ stof(arg_slot[0]), stof(arg_slot[1])
+ ));
#endif
centerprint_generic(cpid, input, stof(arg_slot[0]), stof(arg_slot[1]));
}
if not(notif) { backtrace("Local_Notification: Could not find notification entity!\n"); return; }
#ifdef NOTIFICATIONS_DEBUG
- if not(notif.nent_enabled) { dprint(sprintf("Local_Notification(%s, %s): Entity was disabled...\n", Get_Notif_TypeName(net_type), notif.nent_name)); return; }
+ if not(notif.nent_enabled)
+ {
+ dprint(sprintf(
+ "Local_Notification(%s, %s): Entity was disabled...\n",
+ Get_Notif_TypeName(net_type),
+ notif.nent_name
+ ));
+ return;
+ }
#endif
if((notif.nent_stringcount + notif.nent_floatcount) > count)
"stringcount(%d) + floatcount(%d) > count(%d)\n",
"Check the definition and function call for accuracy...?\n"
),
- Get_Notif_TypeName(net_type), notif.nent_name, notif.nent_stringcount, notif.nent_floatcount, count));
+ Get_Notif_TypeName(net_type), notif.nent_name,
+ notif.nent_stringcount, notif.nent_floatcount, count
+ ));
return;
}
else if((notif.nent_stringcount + notif.nent_floatcount) < count)
"stringcount(%d) + floatcount(%d) < count(%d)\n",
"Check the definition and function call for accuracy...?\n"
),
- Get_Notif_TypeName(net_type), notif.nent_name, notif.nent_stringcount, notif.nent_floatcount, count));
+ Get_Notif_TypeName(net_type), notif.nent_name,
+ notif.nent_stringcount, notif.nent_floatcount, count
+ ));
return;
}
float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
#ifdef NOTIFICATIONS_DEBUG
- dprint(
- sprintf("Local_Notification(%s, %s, %s, %s);\n",
- Get_Notif_TypeName(net_type),
- notif.nent_name,
- strreplace("\n", "\\n", sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
- sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
- )
- );
+ dprint(sprintf(
+ "Local_Notification(%s, %s, %s, %s);\n",
+ Get_Notif_TypeName(net_type),
+ notif.nent_name,
+ strreplace("\n", "\\n", sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
+ sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
+ ));
#endif
switch(net_type)
float net_type = ReadByte();
float net_name = ReadShort();
+ entity notif;
+
if(net_type == MSG_CENTER_KILL)
{
if(is_new)
if(net_name == 0) { reset_centerprint_messages(); }
else
{
- entity notif = Get_Notif_Ent(MSG_CENTER, net_name);
+ notif = Get_Notif_Ent(MSG_CENTER, net_name);
if not(notif) { backtrace("Read_Notification: Could not find notification entity!\n"); return; }
centerprint_generic(notif.nent_cpid, "", 0, 0);
}
}
else
{
- entity notif = Get_Notif_Ent(net_type, net_name);
+ notif = Get_Notif_Ent(net_type, net_name);
if not(notif) { backtrace("Read_Notification: Could not find notification entity!\n"); return; }
#ifdef NOTIFICATIONS_DEBUG
- dprint(sprintf("Read_Notification(%d) at %f: net_type = %s, net_name = %s\n", is_new, time, Get_Notif_TypeName(net_type), notif.nent_name));
+ dprint(sprintf(
+ "Read_Notification(%d) at %f: net_type = %s, net_name = %s\n",
+ is_new,
+ time,
+ Get_Notif_TypeName(net_type),
+ notif.nent_name
+ ));
#endif
string s1 = ((0 < notif.nent_stringcount) ? ReadString() : "");
if not(self) { dprint(sprintf("Net_Notification_Remove() at %f: Missing self!?\n", time)); return; }
if(self.nent_net_name == -1)
{
- dprint(
- sprintf(
- "Net_Notification_Remove() at %f: Killed '%s' notification\n",
- time,
- Get_Notif_TypeName(self.nent_net_type)
- )
- );
+ dprint(sprintf(
+ "Net_Notification_Remove() at %f: Killed '%s' notification\n",
+ time,
+ Get_Notif_TypeName(self.nent_net_type)
+ ));
}
else
#endif
#ifdef NOTIFICATIONS_DEBUG
entity realent = Get_Notif_Ent(self.nent_net_type, self.nent_net_name);
- dprint(
- sprintf(
- "Net_Notification_Remove() at %f: Removed '%s - %s' notification\n",
- time,
- Get_Notif_TypeName(self.nent_net_type),
- realent.nent_name
- )
- );
+ dprint(sprintf(
+ "Net_Notification_Remove() at %f: Removed '%s - %s' notification\n",
+ time,
+ Get_Notif_TypeName(self.nent_net_type),
+ realent.nent_name
+ ));
#endif
}
if(checkargs != "") { backtrace(sprintf("Incorrect usage of Kill_Notification: %s\n", checkargs)); return; }
#ifdef NOTIFICATIONS_DEBUG
- dprint(
- sprintf("Kill_Notification(%d, '%s', %d, %d);\n",
- broadcast,
- client.netname,
- net_type,
- net_name
- )
- );
+ dprint(sprintf(
+ "Kill_Notification(%d, '%s', %d, %d);\n",
+ broadcast,
+ client.netname,
+ net_type,
+ net_name
+ ));
#endif
entity notif, net_notif;
"stringcount(%d) + floatcount(%d) > count(%d)\n",
"Check the definition and function call for accuracy...?\n"
),
- broadcast, Get_Notif_TypeName(net_type), notif.nent_name, notif.nent_stringcount, notif.nent_floatcount, count));
+ broadcast, Get_Notif_TypeName(net_type), notif.nent_name,
+ notif.nent_stringcount, notif.nent_floatcount, count
+ ));
return;
}
else if((notif.nent_stringcount + notif.nent_floatcount) < count)
"stringcount(%d) + floatcount(%d) < count(%d)\n",
"Check the definition and function call for accuracy...?\n"
),
- broadcast, Get_Notif_TypeName(net_type), notif.nent_name, notif.nent_stringcount, notif.nent_floatcount, count));
+ broadcast, Get_Notif_TypeName(net_type), notif.nent_name,
+ notif.nent_stringcount, notif.nent_floatcount, count
+ ));
return;
}
float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
- dprint(
- sprintf("Send_Notification(%d, %s, %s, %s, %s);\n",
- broadcast,
- Get_Notif_TypeName(net_type),
- notif.nent_name,
- strreplace("\n", "\\n", sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
- sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
- )
- );
+ dprint(sprintf(
+ "Send_Notification(%d, %s, %s, %s, %s);\n",
+ broadcast,
+ Get_Notif_TypeName(net_type),
+ notif.nent_name,
+ strreplace("\n", "\\n", sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)),
+ sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
+ ));
#endif
entity net_notif = spawn();
entity notif = Get_Notif_Ent(net_type, net_name);
#ifdef NOTIFICATIONS_DEBUG
- dprint(
- sprintf("Send_Notification_WOVA(%d, %s, %s, %s, %s - %d %d);\n",
- broadcast,
- Get_Notif_TypeName(net_type),
- notif.nent_name,
- sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4),
- sprintf("%d, %d, %d, %d", f1, f2, f3, f4),
- notif.nent_stringcount, notif.nent_floatcount
- )
- );
+ dprint(sprintf(
+ "Send_Notification_WOVA(%d, %s, %s, %s, %s - %d %d);\n",
+ broadcast,
+ Get_Notif_TypeName(net_type),
+ notif.nent_name,
+ sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4),
+ sprintf("%d, %d, %d, %d", f1, f2, f3, f4),
+ notif.nent_stringcount, notif.nent_floatcount
+ ));
#endif
#define VARITEM(stringc,floatc,args) \
.string nent_strings[4];
.float nent_floats[4];
-string Process_Notif_Line(float check_newline, float chat, string input, string notiftype, string notifname, string stringtype)
-{
- if(check_newline)
- {
- #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("^1MISSING/BROKEN NEW LINE AT END OF NOTIFICATION: ^7net_type = MSG_%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("^1NOTIFICATION HAS TOO MANY ARGUMENTS: ^7net_type = MSG_%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) case selected: { ++sel_num; break; }
- NOTIF_ARGUMENT_LIST
- #undef ARG_CASE
- default:
- {
- print(sprintf("^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ^7net_type = MSG_%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("^1NOTIFICATION HAS TOO MANY ARGUMENTS: ^7net_type = MSG_%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("^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ^7net_type = MSG_%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("^1NOTIFICATION HAS TOO MANY ARGUMENTS: ^7net_type = MSG_%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("^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: ^7net_type = MSG_%s, net_name = %s, durcnt arg = '%s'.\n",
- notiftype, notifname, selected));
- notif_error = TRUE;
- }
- break;
- }
- }
- break;
- }
- }
- }
- return args;
-}
-
-#define CREATE_NOTIF_ENTITY(default,type,name,infoname,centername,strnum,flnum,args,hudargs,icon,cpid,durcnt,normal,gentle,check_newline,subcalls) \
-{ \
- notif_error = FALSE; \
- \
- /* global entity setup */ \
- entity notif = spawn(); \
- msg_##type##_notifs[name - 1] = notif; \
- notif.classname = "msg_#type#_notification"; \
- notif.nent_default = default; \
- notif.nent_name = strzone(#name); \
- notif.nent_id = name; \
- notif.nent_enabled = (1 <= autocvar_notification_##name); \
- \
- /* notification specific settings */ \
- #if subcalls /* MSG_DEATH and MSG_WEAPON */ \
- #if (infoname == NO_MSG) && (centername == NO_MSG) \
- print(sprintf("^1NOTIFICATION WITH NO SUBCALLS: ^7net_type = MSG_%s, net_name = %s.\n", strtoupper(#type), #name)); \
- notif_error = TRUE; \
- #else \
- float infoname_stringcount = 0, infoname_floatcount = 0, 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; \
- #endif \
- #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; \
- #endif \
- /* set the requirements of THIS notification to the total requirements of its subcalls */ \
- notif.nent_stringcount = max(infoname_stringcount, centername_stringcount); \
- notif.nent_floatcount = max(infoname_floatcount, centername_floatcount); \
- #endif \
- #else /* MSG_INFO and MSG_CENTER */ \
- notif.nent_stringcount = strnum; \
- notif.nent_floatcount = flnum; \
- \
- /* only initialize this information if we're on a client or a dedicated server */ \
- #ifdef SVQC \
- if(server_is_dedicated) { \
- #endif \
- \
- if(strnum + flnum) \
- { \
- if(args != "") { notif.nent_args = strzone(Process_Notif_Args(1, args, strtoupper(#type), #name)); } \
- else if((hudargs == "") && (durcnt =="")) { print(sprintf("^1NOTIFICATION HAS ARG COUNTS BUT NO ARGS OR HUDARGS OR DURCNT: ^7net_type = MSG_%s, net_name = %s, strnum = %d, flnum = %d\n", strtoupper(#type), #name, strnum, flnum)); notif_error = TRUE; } \
- } \
- else if(args != "") { notif.nent_args = strzone(Process_Notif_Args(1, args, strtoupper(#type), #name)); } \
- \
- #ifdef CSQC \
- /* MSG_INFO only */ \
- if(hudargs != "") \
- { \
- notif.nent_hudargs = strzone(Process_Notif_Args(2, hudargs, strtoupper(#type), #name)); \
- if(icon != "") { notif.nent_icon = strzone(icon); } \
- else { print(sprintf("^1NOTIFICATION HAS HUDARGS BUT NO ICON: ^7net_type = MSG_%s, net_name = %s.\n", strtoupper(#type), #name)); notif_error = TRUE; } \
- } \
- else if(icon != "") { print(sprintf("^1NOTIFICATION HAS ICON BUT NO HUDARGS: ^7net_type = MSG_%s, net_name = %s.\n", strtoupper(#type), #name)); notif_error = TRUE; } \
- \
- /* MSG_CENTER only */ \
- if(durcnt != "") \
- { \
- notif.nent_durcnt = strzone(Process_Notif_Args(3, durcnt, strtoupper(#type), #name)); \
- if(cpid != NO_MSG) { notif.nent_cpid = cpid; } \
- else { print(sprintf("^1NOTIFICATION HAS DURCNT BUT NO CPID: ^7net_type = MSG_%s, net_name = %s.\n", strtoupper(#type), #name)); notif_error = TRUE; } \
- } \
- else if(cpid != NO_MSG) { notif.nent_cpid = cpid; } \
- #endif \
- \
- /* string setup */ \
- /* select gentle/normal string and bake color codes in on init, this way it does not need to be re-processed at run time */ \
- float nent_chat = (autocvar_notification_##name > 1); \
- if(GENTLE) \
- { \
- if(gentle != "") { notif.nent_string = strzone(CCR(Process_Notif_Line(check_newline, nent_chat, gentle, strtoupper(#type), #name, "GENTLE"))); } \
- else if(normal != "") { notif.nent_string = strzone(CCR(Process_Notif_Line(check_newline, nent_chat, normal, strtoupper(#type), #name, "NORMAL"))); } \
- } \
- else if(normal != "") { notif.nent_string = strzone(CCR(Process_Notif_Line(check_newline, nent_chat, normal, strtoupper(#type), #name, "NORMAL"))); } \
- if(notif.nent_string == "") { print(sprintf("^1EMPTY NOTIFICATION: ^7net_type = MSG_%s, net_name = %s.\n", strtoupper(#type), #name)); notif_error = TRUE; } \
- #ifdef SVQC \
- } \
- #endif \
- #endif \
- \
- /* 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 */ \
- } \
-}
+void Create_Notification_Entity(
+ float var_default,
+ float var_cvar,
+ float typeid,
+ float nameid,
+ string namestring,
+ float infoname,
+ float centername,
+ 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);
#define MSG_INFO_NOTIF(default,name,strnum,flnum,args,hudargs,icon,normal,gentle) \
NOTIF_ADD_AUTOCVAR(name, default) \
{ \
SET_FIELD_COUNT(name, NOTIF_FIRST, NOTIF_INFO_COUNT) \
CHECK_MAX_COUNT(name, NOTIF_MAX, NOTIF_INFO_COUNT, "notifications") \
- CREATE_NOTIF_ENTITY( \
- default, /* default */ \
- info, /* type */ \
- name, /* name */ \
- NO_MSG, /* infoname */ \
- NO_MSG, /* centername */ \
- strnum, /* strnum */ \
- flnum, /* flnum */ \
- args, /* args */ \
- hudargs, /* hudargs */ \
- icon, /* icon */ \
- NO_MSG, /* cpid */ \
- "", /* durcnt */ \
- normal, /* normal */ \
- gentle, /* gentle */ \
- 1, /* check_newline */ \
- 0) /* subcalls */ \
+ Create_Notification_Entity( \
+ default, /* var_default */ \
+ autocvar_notification_##name, /* var_cvar */ \
+ MSG_INFO, /* typeid */ \
+ name, /* nameid */ \
+ strtoupper(#name), /* namestring */ \
+ NO_MSG, /* infoname */ \
+ NO_MSG, /* centername */ \
+ strnum, /* strnum */ \
+ flnum, /* flnum */ \
+ args, /* args */ \
+ hudargs, /* hudargs */ \
+ icon, /* icon */ \
+ NO_MSG, /* cpid */ \
+ "", /* durcnt */ \
+ normal, /* normal */ \
+ gentle, /* gentle */ \
+ TRUE, /* msg_is_info */ \
+ FALSE); /* msg_is_multi */ \
} \
ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotification_##name)
SET_FIELD_COUNT(name, NOTIF_FIRST, NOTIF_CENTER_COUNT) \
SET_FIELD_COUNT(cpid, NOTIF_FIRST, NOTIF_CPID_COUNT) \
CHECK_MAX_COUNT(name, NOTIF_MAX, NOTIF_CENTER_COUNT, "notifications") \
- CREATE_NOTIF_ENTITY( \
- default, /* default */ \
- center, /* type */ \
- name, /* name */ \
- NO_MSG, /* infoname */ \
- NO_MSG, /* centername */ \
- strnum, /* strnum */ \
- flnum, /* flnum */ \
- args, /* args */ \
- "", /* hudargs */ \
- "", /* icon */ \
- cpid, /* cpid */ \
- durcnt, /* durcnt */ \
- normal, /* normal */ \
- gentle, /* gentle */ \
- 0, /* check_newline */ \
- 0) /* subcalls */ \
+ Create_Notification_Entity( \
+ default, /* var_default */ \
+ autocvar_notification_##name, /* var_cvar */ \
+ MSG_CENTER, /* typeid */ \
+ name, /* nameid */ \
+ strtoupper(#name), /* namestring */ \
+ NO_MSG, /* infoname */ \
+ NO_MSG, /* centername */ \
+ strnum, /* strnum */ \
+ flnum, /* flnum */ \
+ args, /* args */ \
+ "", /* hudargs */ \
+ "", /* icon */ \
+ cpid, /* cpid */ \
+ durcnt, /* durcnt */ \
+ normal, /* normal */ \
+ gentle, /* gentle */ \
+ FALSE, /* msg_is_info */ \
+ FALSE); /* msg_is_multi */ \
} \
ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotification_##name)
{ \
SET_FIELD_COUNT(name, NOTIF_FIRST, NOTIF_WEAPON_COUNT) \
CHECK_MAX_COUNT(name, NOTIF_MAX, NOTIF_WEAPON_COUNT, "notifications") \
- CREATE_NOTIF_ENTITY( \
- default, /* default */ \
- weapon, /* type */ \
- name, /* name */ \
- infoname, /* infoname */ \
- centername, /* centername */ \
- NO_MSG, /* strnum */ \
- NO_MSG, /* flnum */ \
- "", /* args */ \
- "", /* hudargs */ \
- "", /* icon */ \
- NO_MSG, /* cpid */ \
- "", /* durcnt */ \
- "", /* normal */ \
- "", /* gentle */ \
- 0, /* check_newline */ \
- 1) /* subcalls */ \
+ Create_Notification_Entity( \
+ default, /* var_default */ \
+ autocvar_notification_##name, /* var_cvar */ \
+ MSG_WEAPON, /* typeid */ \
+ name, /* nameid */ \
+ strtoupper(#name), /* namestring */ \
+ infoname, /* infoname */ \
+ centername, /* centername */ \
+ NO_MSG, /* strnum */ \
+ NO_MSG, /* flnum */ \
+ "", /* args */ \
+ "", /* hudargs */ \
+ "", /* icon */ \
+ NO_MSG, /* cpid */ \
+ "", /* durcnt */ \
+ "", /* normal */ \
+ "", /* gentle */ \
+ FALSE, /* msg_is_info */ \
+ TRUE); /* msg_is_multi */ \
} \
ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotification_##name)
{ \
SET_FIELD_COUNT(name, NOTIF_FIRST, NOTIF_DEATH_COUNT) \
CHECK_MAX_COUNT(name, NOTIF_MAX, NOTIF_DEATH_COUNT, "notifications") \
- CREATE_NOTIF_ENTITY( \
- default, /* default */ \
- death, /* type */ \
- name, /* name */ \
- infoname, /* infoname */ \
- centername, /* centername */ \
- NO_MSG, /* strnum */ \
- NO_MSG, /* flnum */ \
- "", /* args */ \
- "", /* hudargs */ \
- "", /* icon */ \
- NO_MSG, /* cpid */ \
- "", /* durcnt */ \
- "", /* normal */ \
- "", /* gentle */ \
- 0, /* check_newline */ \
- 1) /* subcalls */ \
+ Create_Notification_Entity( \
+ default, /* var_default */ \
+ autocvar_notification_##name, /* var_cvar */ \
+ MSG_DEATH, /* typeid */ \
+ name, /* nameid */ \
+ strtoupper(#name), /* namestring */ \
+ infoname, /* infoname */ \
+ centername, /* centername */ \
+ NO_MSG, /* strnum */ \
+ NO_MSG, /* flnum */ \
+ "", /* args */ \
+ "", /* hudargs */ \
+ "", /* icon */ \
+ NO_MSG, /* cpid */ \
+ "", /* durcnt */ \
+ "", /* normal */ \
+ "", /* gentle */ \
+ FALSE, /* msg_is_info */ \
+ TRUE); /* msg_is_multi */ \
} \
ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotification_##name)