View Single Post
Alber9091
Veteran Member
Join Date: Jun 2014
Location: Karachi, Pakistan
Old 10-13-2018 , 11:15   Re: Plugin Request [Admin Command Logs]
Reply With Quote #18

Quote:
Originally Posted by Alber9091 View Post
Brother, if you have time, Can you please help? It woild be appreciated !!!

Thanks in advance !!!
A Friend Shared This On Other Forums, But Its For amxx 1.8.3, 1.90 and above where as, I use 1.8.2, can you please convert it to 1.8.2?
or Help with Darkside Plugin as to be well coded.

PHP Code:
/**
 *    Author: w0w ( https://dev-cs.ru/members/444/ )
 *
 *    Thanks to:
 *    mx?! ( https://dev-cs.ru/members/1111/ )
 *    wopox1337 ( https://dev-cs.ru/members/4/ )
 *
 *    Idea: DrStrange ( https://dev-cs.ru/threads/3792/ )
 */

#include <amxmodx>

#pragma semicolon 1

#define PLUGIN_VERSION "31.10.2018"

/** ------------------------------------------------------------------------------------------------------------------------- */
/** ------------------------------------------------------------------------------------------------------------------------- */
/** ------------------------------------------------------------------------------------------------------------------------- */

// RU: 1 - логируем команды начинающиеся с "amx_"
// EN: 1 - logging all cmds "amx_"
// ES: 1 - registrar todos los comandos que empiezan por "amx_"
// ------------------------------------------------------
// RU: 2 - логируем все команды из g_szCmds
// EN: 2 - logging all cmds from g_szCmds
// ES: 2 - registrar todos los comandos que están en g_szCmds
// ------------------------------------------------------
// RU: 3 - логируем все команды из g_szCmds и те что начинаются с "amx_"
// EN: 3 - logging all cmds from g_szCmds and those which starts with "amx_"
// ES: 3 - registrar todos los comandos que están en g_szCmds o que empiezan por "amx_"
#define TYPE_CMDS_LOG 3

/** ------------------------------------------------------------------------------------------------------------------------- */
/** ------------------------------------------------------------------------------------------------------------------------- */
/** ------------------------------------------------------------------------------------------------------------------------- */

// RU: Если не закомментировано то логирует только если у игрока есть один из флагов
// EN: If it's not commented, it will log only if the player has one of the specified flags
// ES: Si no está comentado, entonces solo se registrarán los comandos de los jugadores que tengan alguno de los siguientes accesos
#define LOG_BY_FLAGS (ADMIN_KICK|ADMIN_BAN|ADMIN_LEVEL_A|ADMIN_RCON|ADMIN_CFG)

/** ------------------------------------------------------------------------------------------------------------------------- */
/** ------------------------------------------------------------------------------------------------------------------------- */
/** ------------------------------------------------------------------------------------------------------------------------- */

// RU: 1 - Логировать все команды в один файл
// EN: 1 - Logging all comands to one file
// ES: 1 - Registrar todos los comandos al mismo documento
// ------------------------------------------------------
// RU: 2 - Логировать все команды в файл, 1 файл - 1 день
// EN: 2 - Logging all comands to a file, 1 file - 1 day
// ES: 2 - Registrar todos los comandos a un documento, un documento - 1 día
// ------------------------------------------------------
// RU: 3 - Логировать все команды в файл, 1 файл - 1 месяц
// EN: 3 - Logging all comands to a file, 1 file - 1 month
// ES: 3 - Registrar todos los comandos a un documento, un documento - 1 mes
#define LOG_FORMAT 2

/** ------------------------------------------------------------------------------------------------------------------------- */
/** ------------------------------------------------------------------------------------------------------------------------- */
/** ------------------------------------------------------------------------------------------------------------------------- */

#if LOG_FORMAT == 1
    // RU: Название файла для логов
    // EN: File name for logs
    // ES: Nombre del archivo donde se guardarán todos los logs
    
new const g_szLogFileName[] = "admin_commands.log";
#elseif LOG_FORMAT == 2
    
new const g_szLogFileFolder[] = "admin_commands";
    new const 
g_szLogFileName[] = "admin_commands_%d-%m-%Y.log";
#elseif LOG_FORMAT == 3
    
new const g_szLogFileFolder[] = "admin_commands";
    new const 
g_szLogFileName[] = "admin_commands_%m-%Y.log";
#endif

#if TYPE_CMDS_LOG == 2 || TYPE_CMDS_LOG == 3
    
new const g_szCmds[][] =
    {
        
"amx_map",
        
"amx_vote",
        
"amx_votemap",
        
"amx_votekick",
        
"amx_voteban",
        
"amx_cancelvote",
        
"amx_cvar",
        
"amx_nick",
        
"amx_rcon",
        
"amx_gag",
        
"amx_ungag",
        
"amx_addgag",
        
"amx_exec",
        
"amx_teleportmenu",
        
"amx_restrict",
        
"amx_restmenu",
        
"amx_statscfg",
        
"amx_statscfgmenu",
        
"amx_addadmin",
        
"amx_pause",
        
"amx_plugincvarmenu",
        
"amx_on",
        
"amx_off",
        
"amx_cvarmenu",
        
"amx_pausecfg",
        
"amx_pausecfgmenu",
        
"amx_cmdmenu",
        
"amx_clcmdmenu",
        
"amx_cfgmenu",
        
"amx_speechmenu",
        
"amx_teammenu",
        
"amxmodmenu"
    
};
#endif

// Compability AMXX 1.8.3
#if !defined MAX_AUTHID_LENGTH
    #define MAX_AUTHID_LENGTH 64
#endif

#if !defined MAX_IP_LENGTH
    #define MAX_IP_LENGTH 16
#endif

new g_szLogFile[128];

public 
plugin_init()
{
    
register_plugin("Admin Commands Log"PLUGIN_VERSION"w0w");

    new 
szLogsDir[64];
    
get_localinfo("amxx_logs"szLogsDircharsmax(szLogsDir));

#if LOG_FORMAT == 2 || LOG_FORMAT == 3
    
new szBigBuff[PLATFORM_MAX_PATH];

    
formatex(szBigBuffcharsmax(szBigBuff), "%s/%s"szLogsDirg_szLogFileFolder);
    if(!
dir_exists(szBigBuff)) mkdir(szBigBuff);

    
get_time(fmt("%s/%s/%s"szLogsDirg_szLogFileFolderg_szLogFileName), g_szLogFilecharsmax(g_szLogFile));
#else
    
formatex(g_szLogFilecharsmax(g_szLogFile), "%s/%s"szLogsDirg_szLogFileName);
#endif
}

public 
client_command(id)
{
#if defined LOG_BY_FLAGS
    // The player doesn't have any flag from LOG_BY_FLAGS
    
if(!(get_user_flags(id) & LOG_BY_FLAGS))
        return 
PLUGIN_CONTINUE;
#endif

    
new szCommand[64]; read_argv(0szCommandcharsmax(szCommand));

#if TYPE_CMDS_LOG == 1
    // If do not start with amx_ or it's not any symbol after amx_
    
if(containi(szCommand"amx_") == -|| !szCommand[4])
        return 
PLUGIN_CONTINUE;
#elseif TYPE_CMDS_LOG == 2
    
if(!func_CommandExists(szCommand))
        return 
PLUGIN_CONTINUE;
#elseif TYPE_CMDS_LOG == 3
    
if(!func_CommandExists(szCommand) && containi(szCommand"amx_") == -1)
        return 
PLUGIN_CONTINUE;
#endif

    
new szArgs[64]; read_args(szArgscharsmax(szArgs));

    if(
szArgs[0])
        
func_LogToFile(idszCommandszArgs);
    else 
func_LogToFile(idszCommand);

    return 
PLUGIN_CONTINUE;
}

#if TYPE_CMDS_LOG == 2 || TYPE_CMDS_LOG == 3
func_CommandExists(szCommand[])
{
    new 
bool:bFound;

    for(new 
isizeof(g_szCmds); i++)
    {
        if(
containi(szCommandg_szCmds[i]) == 0)
        {
            
bFound true;
            break;
        }
    }

    return 
bFound;
}
#endif

func_LogToFile(idszCommand[], szArgs[] = "")
{
    new 
szAuthID[MAX_AUTHID_LENGTH]; get_user_authid(idszAuthIDcharsmax(szAuthID));
    new 
szIP[MAX_IP_LENGTH]; get_user_ip(idszIPcharsmax(szIP), 1);

    if(
szArgs[0])
        
log_to_file(g_szLogFile"%n (<%s> <%s>) ---> %s %s"idszAuthIDszIPszCommandszArgs);
    else 
log_to_file(g_szLogFile"%n (<%s> <%s>) ---> %s"idszAuthIDszIPszCommand);


Last edited by Alber9091; 10-31-2018 at 17:20.
Alber9091 is offline