From 4b66f688ab219d5c8c3d7cf72e28c3e8e6ef0397 Mon Sep 17 00:00:00 2001 From: richard Date: Sun, 14 Jun 2009 19:10:30 +0200 Subject: [PATCH] New log features, class attribute and minior changes. See details. Made new log CVAR for overriding filters on error log types: zr_log_error_override. If this is on, errors are always logged, independent of flags and filters. Now all non-error logging can be completely disabled without complex flags or filtering. Made new class attribute ("has_napalm", ClassGetHasNapalm) that specifies if the class have or can trhow napalm grenades. Implemented usage in napalm module. Added team id validation in class attributes. Improved formatting of log messages in cvars module. Known issue: Commands in config for adding modules to log filter are executed too late. Otherwise the module filter works fine. --- .../sourcemod/configs/zr/playerclasses.txt | 7 ++++ src/zombiereloaded.sp | 2 +- src/zr/config.inc | 2 +- src/zr/cvars.inc | 6 ++- src/zr/event.inc | 5 ++- src/zr/log.inc | 5 ++- src/zr/napalm.inc | 20 +++++++--- src/zr/playerclasses/attributes.inc | 32 ++++++++++++++++ src/zr/playerclasses/classcommands.inc | 5 +++ src/zr/playerclasses/filtertools.inc | 8 +++- src/zr/playerclasses/playerclasses.inc | 38 ++++++++++++------- 11 files changed, 102 insertions(+), 28 deletions(-) diff --git a/cstrike/addons/sourcemod/configs/zr/playerclasses.txt b/cstrike/addons/sourcemod/configs/zr/playerclasses.txt index f3a5bfa..b483987 100644 --- a/cstrike/addons/sourcemod/configs/zr/playerclasses.txt +++ b/cstrike/addons/sourcemod/configs/zr/playerclasses.txt @@ -69,6 +69,7 @@ "fov" "90" // Effects + "has_napalm" "0" "napalm_time" "10.0" // Player behaviour @@ -110,6 +111,7 @@ "fov" "90" // Effects + "has_napalm" "0" "napalm_time" "5.0" // Player behaviour @@ -151,6 +153,7 @@ "fov" "90" // Effects + "has_napalm" "0" "napalm_time" "15.0" // Player behaviour @@ -192,6 +195,7 @@ "fov" "90" // Effects + "has_napalm" "0" "napalm_time" "20.0" // Player behaviour @@ -239,6 +243,7 @@ "fov" "90" // Effects + "has_napalm" "1" "napalm_time" "0.0" // Player behaviour @@ -280,6 +285,7 @@ "fov" "90" // Effects + "has_napalm" "0" "napalm_time" "0.0" // Player behaviour @@ -321,6 +327,7 @@ "fov" "90" // Effects + "has_napalm" "1" "napalm_time" "0.0" // Player behaviour diff --git a/src/zombiereloaded.sp b/src/zombiereloaded.sp index d362ea6..3e1189c 100644 --- a/src/zombiereloaded.sp +++ b/src/zombiereloaded.sp @@ -112,9 +112,9 @@ public bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max) public OnPluginStart() { // Forward event to modules. + LogInit(); // Doesn't depend on CVARs. TranslationInit(); CvarsInit(); - LogInit(); ToolsInit(); CommandsInit(); WeaponsInit(); diff --git a/src/zr/config.inc b/src/zr/config.inc index 5c1cf5f..d20d489 100644 --- a/src/zr/config.inc +++ b/src/zr/config.inc @@ -192,7 +192,7 @@ ConfigOnCommandsCreate() } /** - * Load plugin configs. + * Load plugin configs. Executes map configs. */ ConfigLoad() { diff --git a/src/zr/cvars.inc b/src/zr/cvars.inc index 3ec7f2a..d772078 100644 --- a/src/zr/cvars.inc +++ b/src/zr/cvars.inc @@ -44,6 +44,7 @@ enum CvarsList Handle:CVAR_LOG_FLAGS, Handle:CVAR_LOG_MODULE_FILTER, Handle:CVAR_LOG_IGNORE_CONSOLE, + Handle:CVAR_LOG_ERROR_OVERRIDE, Handle:CVAR_LOG_PRINT_ADMINS, Handle:CVAR_LOG_PRINT_CHAT, Handle:CVAR_CONFIG_PATH_MODELS, @@ -207,6 +208,7 @@ CvarsCreate() g_hCvarsList[CVAR_LOG_FLAGS] = CreateConVar("zr_log_flags", "3", "A bit field that specify what event types to log. See logging section (3.3) in manual for details."); g_hCvarsList[CVAR_LOG_MODULE_FILTER] = CreateConVar("zr_log_module_filter", "0", "Enable module filtering. Only log events from listed modules will be logged."); g_hCvarsList[CVAR_LOG_IGNORE_CONSOLE] = CreateConVar("zr_log_ignore_console", "1", "Don't log events triggered by console commands that are executed by the console itself, like commands in configs. Enable this command to avoid spamming logs with events like weapon restrictions."); + g_hCvarsList[CVAR_LOG_ERROR_OVERRIDE] = CreateConVar("zr_log_error_override", "1", "Always log error messages. Overrides module filter and logging flags."); g_hCvarsList[CVAR_LOG_PRINT_ADMINS] = CreateConVar("zr_log_print_admins", "0", "Print log events to admin chat in addition to the log file."); g_hCvarsList[CVAR_LOG_PRINT_CHAT] = CreateConVar("zr_log_print_chat", "0", "Print log events to public chat in addition to the log file."); @@ -518,7 +520,7 @@ public CvarsHookLocked(Handle:cvar, const String:oldvalue[], const String:newval SetConVarInt(g_hAutoTeamBalance, CVARS_AUTOTEAMBALANCE_LOCKED); // If log flag check fails, then don't log. - LogEvent(false, LogType_Normal, LOG_CORE_EVENTS, LogModule_Cvars, "Cvar Locked", "Cvar \"mp_autoteambalance\" was reverted back to \"CVARS_AUTOTEAMBALANCE_LOCKED\"."); + LogEvent(false, LogType_Normal, LOG_CORE_EVENTS, LogModule_Cvars, "Cvar Locked", "Cvar \"mp_autoteambalance\" was reverted back to %d.", CVARS_AUTOTEAMBALANCE_LOCKED); } // If cvar is mp_limitteams, then continue. else if (cvar == g_hLimitTeams) @@ -533,7 +535,7 @@ public CvarsHookLocked(Handle:cvar, const String:oldvalue[], const String:newval SetConVarInt(g_hLimitTeams, CVARS_LIMITTEAMS_LOCKED); // If log flag check fails, then don't log. - LogEvent(false, LogType_Normal, LOG_CORE_EVENTS, LogModule_Cvars, "Cvar Locked", "Cvar \"mp_limitteams\" was reverted back to \"CVARS_LIMITTEAMS_LOCKED\"."); + LogEvent(false, LogType_Normal, LOG_CORE_EVENTS, LogModule_Cvars, "Cvar Locked", "Cvar \"mp_limitteams\" was reverted back to %d.", CVARS_LIMITTEAMS_LOCKED); } } diff --git a/src/zr/event.inc b/src/zr/event.inc index 921efa3..55a629c 100644 --- a/src/zr/event.inc +++ b/src/zr/event.inc @@ -230,7 +230,7 @@ public Action:EventPlayerHurt(Handle:event, const String:name[], bool:dontBroadc InfectOnClientHurt(index, attacker, weapon); SEffectsOnClientHurt(index); KnockbackOnClientHurt(index, attacker, weapon, hitgroup, dmg_health); - NapalmOnClientHurt(index, weapon); + NapalmOnClientHurt(index, attacker, weapon); ZHPOnClientHurt(index); } @@ -300,9 +300,10 @@ public Action:EventPlayerJump(Handle:event, const String:name[], bool:dontBroadc public Action:EventWeaponFire(Handle:event, const String:name[], bool:dontBroadcast) { // Get all required event info. + new index = GetClientOfUserId(GetEventInt(event, "userid")); decl String:weapon[32]; GetEventString(event, "weapon", weapon, sizeof(weapon)); // Forward event to modules. - NapalmOnWeaponFire(weapon); + NapalmOnWeaponFire(index, weapon); } diff --git a/src/zr/log.inc b/src/zr/log.inc index 251f864..642fabb 100644 --- a/src/zr/log.inc +++ b/src/zr/log.inc @@ -258,8 +258,8 @@ bool:LogCheckModuleFilter(LogModules:module) */ LogEvent(bool:isConsole = false, LogTypes:logType = LogType_Normal, eventType = LOG_CORE_EVENTS, LogModules:module, const String:description[], const String:text[], any:...) { - // Only do filter and flag checks if the log type isn't a fatal error. - if (logType != LogType_Fatal) + // Check filter overrides. Always log fatal errors, and check error override setting on error log types. + if ((logType != LogType_Fatal && logType != LogType_Error) || (logType == LogType_Error && !GetConVarBool(g_hCvarsList[CVAR_LOG_ERROR_OVERRIDE]))) { // Check if logging is disabled. if (!GetConVarBool(g_hCvarsList[CVAR_LOG])) @@ -333,6 +333,7 @@ LogEvent(bool:isConsole = false, LogTypes:logType = LogType_Normal, eventType = // Check if printing log events to public chat is enabled. if (GetConVarBool(g_hCvarsList[CVAR_LOG_PRINT_CHAT])) { + // Print text to public chat. TranslationPrintToChatAll(false, false, "Literal text", logbuffer); } } diff --git a/src/zr/napalm.inc b/src/zr/napalm.inc index bb142ab..f68a2c5 100644 --- a/src/zr/napalm.inc +++ b/src/zr/napalm.inc @@ -34,9 +34,10 @@ * Client has been hurt. * * @param client The client index. + * @param attacker The attacker index. * @param weapon The weapon name. */ -NapalmOnClientHurt(client, const String:weapon[]) +NapalmOnClientHurt(client, attacker, const String:weapon[]) { // If player isn't a zombie, then stop. if (!InfectIsClientInfected(client)) @@ -51,6 +52,12 @@ NapalmOnClientHurt(client, const String:weapon[]) return; } + // If the attacker can't throw napalm grenades, then stop. + if (ClassGetHasNapalm(attacker)) + { + return; + } + // If weapon is a grenade, then ignite player. if (StrEqual(weapon, "hegrenade", false)) { @@ -76,9 +83,10 @@ NapalmOnClientDeath(client) /** * Weapon has been fired. * - * @param weapon The weapon name. + * @param client The client index. + * @param weapon The weapon name. */ -NapalmOnWeaponFire(const String:weapon[]) +NapalmOnWeaponFire(client, const String:weapon[]) { // If grenade fire is disabled, then stop. new bool:napalmignite = GetConVarBool(g_hCvarsList[CVAR_NAPALM_IGNITE]); @@ -87,11 +95,11 @@ NapalmOnWeaponFire(const String:weapon[]) return; } - // If human class can't throw napalm grenades, then stop. (TODO) - /*if () + // If human class can't throw napalm grenades, then stop. + if (!ClassGetHasNapalm(client)) { return; - }*/ + } // If weapon isn't a grenade, then stop. if (!StrEqual(weapon, "hegrenade", false)) diff --git a/src/zr/playerclasses/attributes.inc b/src/zr/playerclasses/attributes.inc index 468160f..615ff8a 100644 --- a/src/zr/playerclasses/attributes.inc +++ b/src/zr/playerclasses/attributes.inc @@ -461,6 +461,38 @@ stock ClassGetFOV(index, cachetype = ZR_CLASS_CACHE_PLAYER) * ------------------------------------ */ +/** + * Gets the napalm setting from the specified class. + * + * @param index Index of the class in a class cache or a client index, + * depending on the cache type specified. + * @param cachetype Optional. Specifies what class cache to read from. Options: + * ZR_CLASS_CACHE_ORIGINAL - Unchanced class data. + * ZR_CLASS_CACHE_MODIFIED - Changed/newest class data. + * ZR_CLASS_CACHE_PLAYER (default) - Player cache. If this one + * is used, index will be used as a client index. + * @return True if the class has napalm grenades, false otherwise. + */ +stock bool:ClassGetHasNapalm(index, cachetype = ZR_CLASS_CACHE_PLAYER) +{ + switch (cachetype) + { + case ZR_CLASS_CACHE_ORIGINAL: + { + return ClassData[index][class_has_napalm]; + } + case ZR_CLASS_CACHE_MODIFIED: + { + return ClassDataCache[index][class_has_napalm]; + } + case ZR_CLASS_CACHE_PLAYER: + { + return ClassPlayerCache[index][class_has_napalm]; + } + } + return false; +} + /** * Gets the napalm grenades time from the specified class. * diff --git a/src/zr/playerclasses/classcommands.inc b/src/zr/playerclasses/classcommands.inc index d221cf4..23dc0be 100644 --- a/src/zr/playerclasses/classcommands.inc +++ b/src/zr/playerclasses/classcommands.inc @@ -396,6 +396,11 @@ stock bool:ClassModifyBoolean(classindex, attributeflag, bool:value) ClassDataCache[classindex][class_no_fall_damage] = bool:value; return true; } + case ZR_CLASS_FLAG_HAS_NAPALM: + { + ClassDataCache[classindex][class_has_napalm] = bool:value; + return true; + } } // Invalid flag or multiple flags combined. diff --git a/src/zr/playerclasses/filtertools.inc b/src/zr/playerclasses/filtertools.inc index cbc03e1..cc58b69 100644 --- a/src/zr/playerclasses/filtertools.inc +++ b/src/zr/playerclasses/filtertools.inc @@ -106,6 +106,12 @@ stock ClassValidateAttributes(classindex) new flags; + // Team. + if (ClassData[classindex][class_team] < ZR_CLASS_TEAM_MIN || ClassData[classindex][class_team] > ZR_CLASS_TEAM_MAX) + { + flags += ZR_CLASS_FLAG_TEAM; + } + // Name. if (strlen(ClassData[classindex][class_name]) < ZR_CLASS_NAME_MIN) { @@ -116,7 +122,7 @@ stock ClassValidateAttributes(classindex) decl String:name[64]; strcopy(name, sizeof(name), ClassData[classindex][class_name]); - // Check for reserved name keyworks. + // Check for reserved name keyworks. These aren't allowed as names. if (StrEqual(name, "all", false) || StrEqual(name, "humans", false) || StrEqual(name, "zombies", false) || diff --git a/src/zr/playerclasses/playerclasses.inc b/src/zr/playerclasses/playerclasses.inc index cef3f74..87c230b 100644 --- a/src/zr/playerclasses/playerclasses.inc +++ b/src/zr/playerclasses/playerclasses.inc @@ -121,6 +121,7 @@ #define ZR_CLASS_DEFAULT_OVERLAY_PATH "overlays/zr/zvision" #define ZR_CLASS_DEFAULT_NVGS true #define ZR_CLASS_DEFAULT_FOV 90 +#define ZR_CLASS_DEFAULT_HAS_NAPALM 1 #define ZR_CLASS_DEFAULT_NAPALM_TIME 10.0 #define ZR_CLASS_DEFAULT_IMMUNITY_MODE ZR_CLASS_IMMUNITY_DISABLED #define ZR_CLASS_DEFAULT_IMMUNITY_AMOUNT 0.0 @@ -141,6 +142,8 @@ /** * @section Attribute limit values. Used when validating. */ +#define ZR_CLASS_TEAM_MIN 0 +#define ZR_CLASS_TEAM_MAX 2 #define ZR_CLASS_NAME_MIN 1 #define ZR_CLASS_DESCRIPTION_MIN 1 /** Model path is checked for existance. */ @@ -192,19 +195,20 @@ #define ZR_CLASS_FLAG_OVERLAY_PATH (1<<9) #define ZR_CLASS_FLAG_NVGS (1<<10) #define ZR_CLASS_FLAG_FOV (1<<11) -#define ZR_CLASS_FLAG_NAPALM_TIME (1<<12) -#define ZR_CLASS_FLAG_IMMUNITY_MODE (1<<13) -#define ZR_CLASS_FLAG_IMMUNITY_AMOUNT (1<<14) -#define ZR_CLASS_FLAG_NO_FALL_DAMAGE (1<<15) -#define ZR_CLASS_FLAG_HEALTH (1<<16) -#define ZR_CLASS_FLAG_HEALTH_REGEN_INTERVAL (1<<17) -#define ZR_CLASS_FLAG_HEALTH_REGEN_AMOUNT (1<<18) -#define ZR_CLASS_FLAG_HEALTH_INFECT_GAIN (1<<19) -#define ZR_CLASS_FLAG_KILL_BONUS (1<<20) -#define ZR_CLASS_FLAG_SPEED (1<<21) -#define ZR_CLASS_FLAG_KNOCKBACK (1<<22) -#define ZR_CLASS_FLAG_JUMP_HEIGHT (1<<23) -#define ZR_CLASS_FLAG_JUMP_DISTANCE (1<<24) +#define ZR_CLASS_FLAG_HAS_NAPALM (1<<12) +#define ZR_CLASS_FLAG_NAPALM_TIME (1<<13) +#define ZR_CLASS_FLAG_IMMUNITY_MODE (1<<14) +#define ZR_CLASS_FLAG_IMMUNITY_AMOUNT (1<<15) +#define ZR_CLASS_FLAG_NO_FALL_DAMAGE (1<<16) +#define ZR_CLASS_FLAG_HEALTH (1<<17) +#define ZR_CLASS_FLAG_HEALTH_REGEN_INTERVAL (1<<18) +#define ZR_CLASS_FLAG_HEALTH_REGEN_AMOUNT (1<<19) +#define ZR_CLASS_FLAG_HEALTH_INFECT_GAIN (1<<20) +#define ZR_CLASS_FLAG_KILL_BONUS (1<<21) +#define ZR_CLASS_FLAG_SPEED (1<<22) +#define ZR_CLASS_FLAG_KNOCKBACK (1<<23) +#define ZR_CLASS_FLAG_JUMP_HEIGHT (1<<24) +#define ZR_CLASS_FLAG_JUMP_DISTANCE (1<<25) /** * @endsection */ @@ -234,6 +238,7 @@ enum ClassAttributes class_fov, /* Effects */ + bool:class_has_napalm, Float:class_napalm_time, /* Player behaviour */ @@ -420,6 +425,7 @@ ClassLoad() /* Effects */ + ClassData[ClassCount][class_has_napalm] = bool:KvGetNum(kvClassData, "have_napalm", ZR_CLASS_DEFAULT_HAS_NAPALM); ClassData[ClassCount][class_napalm_time] = KvGetFloat(kvClassData, "napalm_time", ZR_CLASS_DEFAULT_NAPALM_TIME); @@ -528,6 +534,7 @@ bool:ClassReloadDataCache() ClassDataCache[classindex][class_fov] = ClassData[classindex][class_fov]; /* Effects */ + ClassDataCache[classindex][class_has_napalm] = ClassData[classindex][class_has_napalm]; ClassDataCache[classindex][class_napalm_time] = ClassData[classindex][class_napalm_time]; /* Player behaviour */ @@ -591,6 +598,7 @@ bool:ClassReloadPlayerCache(client, classindex, cachetype = ZR_CLASS_CACHE_MODIF ClassPlayerCache[client][class_fov] = ClassData[classindex][class_fov]; /* Effects */ + ClassPlayerCache[client][class_has_napalm] = ClassData[classindex][class_has_napalm]; ClassPlayerCache[client][class_napalm_time] = ClassData[classindex][class_napalm_time]; /* Player behaviour */ @@ -628,6 +636,7 @@ bool:ClassReloadPlayerCache(client, classindex, cachetype = ZR_CLASS_CACHE_MODIF ClassPlayerCache[client][class_fov] = ClassDataCache[classindex][class_fov]; /* Effects */ + ClassPlayerCache[client][class_has_napalm] = ClassDataCache[classindex][class_has_napalm]; ClassPlayerCache[client][class_napalm_time] = ClassDataCache[classindex][class_napalm_time]; /* Player behaviour */ @@ -794,6 +803,9 @@ ClassDumpData(index, cachetype, String:buffer[], maxlen) Format(attribute, sizeof(attribute), "fov: \"%d\"\n", ClassGetFOV(index, cachetype)); cellcount += StrCat(buffer, maxlen, attribute); + Format(attribute, sizeof(attribute), "has_napalm: \"%d\"\n", ClassGetHasNapalm(index, cachetype)); + cellcount += StrCat(buffer, maxlen, attribute); + Format(attribute, sizeof(attribute), "napalm_time: \"%f\"\n", ClassGetNapalmTime(index, cachetype)); cellcount += StrCat(buffer, maxlen, attribute);