2009-04-20 05:43:20 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
|
|
|
* Zombie:Reloaded
|
|
|
|
*
|
2009-05-06 02:28:09 +02:00
|
|
|
* File: log.inc
|
|
|
|
* Type: Core
|
|
|
|
* Description: Logging API.
|
2009-04-20 05:43:20 +02:00
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
2009-06-01 23:29:26 +02:00
|
|
|
/*
|
|
|
|
* Note: See log.h.inc for header types and defines.
|
2009-04-20 05:43:20 +02:00
|
|
|
*/
|
2009-06-01 23:29:26 +02:00
|
|
|
|
2009-04-20 05:43:20 +02:00
|
|
|
/**
|
2009-06-01 23:29:26 +02:00
|
|
|
* Handle for dynamic string array for module filtering.
|
2009-04-20 05:43:20 +02:00
|
|
|
*/
|
2009-06-01 23:29:26 +02:00
|
|
|
new Handle:LogModuleFilter;
|
2009-04-20 05:43:20 +02:00
|
|
|
|
|
|
|
/**
|
2009-06-01 23:29:26 +02:00
|
|
|
* Cache of current module filter settings. For fast and easy access.
|
2009-04-20 05:43:20 +02:00
|
|
|
*/
|
2009-06-01 23:29:26 +02:00
|
|
|
new LogModuleFilterCache[LogModules];
|
|
|
|
|
2009-04-20 05:43:20 +02:00
|
|
|
/**
|
2009-06-01 23:29:26 +02:00
|
|
|
* Gets a module type as a human readable string.
|
|
|
|
*
|
|
|
|
* @param buffer Destination string buffer.
|
|
|
|
* @param maxlen Size of destination buffer.
|
|
|
|
* @param module Module type to convert.
|
|
|
|
*
|
|
|
|
* @return Number of cells written.
|
2009-04-20 05:43:20 +02:00
|
|
|
*/
|
2009-06-01 23:29:26 +02:00
|
|
|
LogGetModuleNameString(String:buffer[], maxlen, LogModules:module)
|
|
|
|
{
|
|
|
|
switch (module)
|
|
|
|
{
|
|
|
|
case LogModule_Antistick:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Anti-Stick");
|
|
|
|
}
|
|
|
|
case LogModule_Config:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Config");
|
|
|
|
}
|
|
|
|
case LogModule_Cvars:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "CVARs");
|
|
|
|
}
|
|
|
|
case LogModule_Damage:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Damage");
|
|
|
|
}
|
|
|
|
case LogModule_Downloads:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Downloads");
|
|
|
|
}
|
|
|
|
case LogModule_Hitgroups:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Hit Groups");
|
|
|
|
}
|
|
|
|
case LogModule_Infect:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Infect");
|
|
|
|
}
|
|
|
|
case LogModule_Models:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Models");
|
|
|
|
}
|
|
|
|
case LogModule_Playerclasses:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Player Classes");
|
|
|
|
}
|
|
|
|
case LogModule_Soundeffects:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Sound Effects");
|
|
|
|
}
|
|
|
|
case LogModule_Tools:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Tools");
|
|
|
|
}
|
|
|
|
case LogModule_Volfetures:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Volumetric Features");
|
|
|
|
}
|
|
|
|
case LogModule_Weapons:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Weapons");
|
|
|
|
}
|
|
|
|
case LogModule_Weaponrestrict:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Weapon Restrictions");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Module mismatch.
|
|
|
|
return 0;
|
|
|
|
}
|
2009-04-20 05:43:20 +02:00
|
|
|
|
|
|
|
/**
|
2009-06-01 23:29:26 +02:00
|
|
|
* Check if the specified log flag is set.
|
2009-04-20 05:43:20 +02:00
|
|
|
*
|
2009-06-01 23:29:26 +02:00
|
|
|
* @param eventType The log flag to check.
|
|
|
|
* @return True if set, false otherwise.
|
2009-04-20 05:43:20 +02:00
|
|
|
*/
|
2009-06-01 23:29:26 +02:00
|
|
|
bool:LogCheckFlag(eventType)
|
2009-04-20 05:43:20 +02:00
|
|
|
{
|
2009-06-01 23:29:26 +02:00
|
|
|
// Check if eventType is set.
|
|
|
|
if (GetConVarInt(g_hCvarsList[CVAR_LOG_FLAGS]) & eventType)
|
2009-04-20 05:43:20 +02:00
|
|
|
{
|
2009-06-01 23:29:26 +02:00
|
|
|
return true;
|
2009-04-20 05:43:20 +02:00
|
|
|
}
|
2009-06-01 23:29:26 +02:00
|
|
|
else
|
2009-04-20 05:43:20 +02:00
|
|
|
{
|
2009-06-01 23:29:26 +02:00
|
|
|
return false;
|
2009-04-20 05:43:20 +02:00
|
|
|
}
|
2009-06-01 23:29:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the specified module is enabled in the log module filter cache.
|
|
|
|
*
|
|
|
|
* @param module Module to check.
|
|
|
|
* @return True if enabled, false otherwise.
|
|
|
|
*/
|
|
|
|
bool:LogCheckModuleFilter(LogModules:module)
|
|
|
|
{
|
|
|
|
if (LogModuleFilterCache[module])
|
2009-05-14 09:32:01 +02:00
|
|
|
{
|
2009-06-01 23:29:26 +02:00
|
|
|
return true;
|
2009-05-14 09:32:01 +02:00
|
|
|
}
|
2009-06-01 23:29:26 +02:00
|
|
|
else
|
2009-05-14 09:32:01 +02:00
|
|
|
{
|
2009-06-01 23:29:26 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print a formatted message to logs depending on log settings.
|
|
|
|
*
|
|
|
|
* @param isConsole Optional. Specifies whether the log event came from
|
|
|
|
* client 0. Used in console commands, do not mix with
|
|
|
|
* regular log events. Default is false.
|
|
|
|
* @param logType Optional. Log type and action. Default is
|
|
|
|
* LogType_Normal.
|
|
|
|
* @param eventType Optional. A log flag describing What kind of log event
|
|
|
|
* it is. Default is LOG_CORE_EVENTS.
|
|
|
|
* @param module Module the log event were executed in.
|
|
|
|
* @param description Event type or function name. A short descriptive phrase
|
|
|
|
* to group together similar logs.
|
|
|
|
* @param text Log message. Can be formatted.
|
|
|
|
* @param ... Formatting parameters.
|
|
|
|
*/
|
|
|
|
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 if logging is disabled.
|
|
|
|
if (!GetConVarBool(g_hCvarsList[CVAR_LOG]))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if console is ignored.
|
|
|
|
if (isConsole && GetConVarBool(g_hCvarsList[CVAR_LOG_IGNORE_CONSOLE]))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check event type (log flag).
|
|
|
|
if (!LogCheckFlag(eventType))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if module filtering is enabled.
|
|
|
|
if (GetConVarBool(g_hCvarsList[CVAR_LOG_MODULE_FILTER]))
|
|
|
|
{
|
|
|
|
// Check if the specified module is enabled.
|
|
|
|
if (!LogCheckModuleFilter(module))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2009-05-14 09:32:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Format extra parameters into the log buffer.
|
|
|
|
decl String:logbuffer[LOG_MAX_LENGTH_FILE];
|
2009-06-05 05:58:48 +02:00
|
|
|
VFormat(logbuffer, sizeof(logbuffer), text, 7);
|
2009-05-14 09:32:01 +02:00
|
|
|
|
2009-06-01 23:29:26 +02:00
|
|
|
// Get human readable module name.
|
|
|
|
new String:modulename[64];
|
|
|
|
LogGetModuleNameString(modulename, sizeof(modulename), module);
|
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
// Format
|
2009-06-01 23:29:26 +02:00
|
|
|
Format(logbuffer, sizeof(logbuffer), "[%s] - [%s]: %s", modulename, description, logbuffer);
|
2009-04-27 04:00:38 +02:00
|
|
|
|
|
|
|
// Format other parameters onto the log text.
|
2009-06-01 23:29:26 +02:00
|
|
|
switch (logType)
|
2009-04-20 05:43:20 +02:00
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
// Log type is normal.
|
2009-06-01 23:29:26 +02:00
|
|
|
case LogType_Normal:
|
2009-04-20 05:43:20 +02:00
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
LogMessage(logbuffer);
|
2009-04-20 05:43:20 +02:00
|
|
|
}
|
2009-04-27 04:00:38 +02:00
|
|
|
// Log type is error.
|
2009-06-01 23:29:26 +02:00
|
|
|
case LogType_Error:
|
2009-04-20 05:43:20 +02:00
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
LogError(logbuffer);
|
2009-04-20 05:43:20 +02:00
|
|
|
}
|
2009-05-14 09:32:01 +02:00
|
|
|
// Log type is fatal error.
|
2009-06-01 23:29:26 +02:00
|
|
|
case LogType_Fatal:
|
2009-04-29 01:58:41 +02:00
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
SetFailState(logbuffer);
|
2009-04-29 01:58:41 +02:00
|
|
|
}
|
2009-04-20 05:43:20 +02:00
|
|
|
}
|
|
|
|
|
2009-06-01 23:29:26 +02:00
|
|
|
// Note: The phrase "Literal text" is a blank phrase to pass any string we want into it.
|
|
|
|
|
|
|
|
// Check if printing log events to admins is enabled.
|
|
|
|
if (GetConVarBool(g_hCvarsList[CVAR_LOG_PRINT_ADMINS]))
|
2009-04-20 05:43:20 +02:00
|
|
|
{
|
|
|
|
// Print text to admins.
|
2009-06-01 23:29:26 +02:00
|
|
|
TranslationPrintToChatAll(false, true, "Literal text", logbuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if printing log events to public chat is enabled.
|
|
|
|
if (GetConVarBool(g_hCvarsList[CVAR_LOG_PRINT_CHAT]))
|
|
|
|
{
|
|
|
|
TranslationPrintToChatAll(false, false, "Literal text", logbuffer);
|
2009-04-20 05:43:20 +02:00
|
|
|
}
|
|
|
|
}
|