Иконка ресурса

Log Finder 1.1

Нет прав для скачивания
Код:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN  "Log Finder"
#define VERSION "1.1"
#define AUTHOR  "Xpace"

new const LOGS_PATH[] = "addons/amxmodx/logs"
new const OUTPUT_FILE[] = "addons/amxmodx/logs/findlog.log"

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_concmd("amx_findlog", "cmd_findlog", ADMIN_RCON, "<text> - Search logs for matches and save results in findlog.log")
}

public cmd_findlog(id, level, cid)
{
    if(!cmd_access(id, level, cid, 2))
        return PLUGIN_HANDLED

    new search[64]
    read_argv(1, search, charsmax(search))
    trim(search)

    if(!search[0])
    {
        console_print(id, "[LOG-FINDER] You must provide a search term.")
        return PLUGIN_HANDLED
    }

    new modified_search[64]
    copy(modified_search, charsmax(modified_search), search)
    replace_all(modified_search, charsmax(modified_search), ":", "_")

    new pos, file[128], outlen
    new line[512], text[512]
    new fRead, fOut
    new found

    fOut = fopen(OUTPUT_FILE, "w")

    console_print(id, "[LOG-FINDER] Searching for '%s' in %s ...", modified_search, LOGS_PATH)

    while(read_dir(LOGS_PATH, pos++, file, charsmax(file), outlen))
    {
        if(equal(file, ".") || equal(file, ".."))
            continue

        new len = strlen(file)
        if(len < 4)
            continue

        // Only process .log files
        if(!equal(file[len - 4], ".log"))
            continue

        format(text, charsmax(text), "%s/%s", LOGS_PATH, file)
        fRead = fopen(text, "r")

        if(!fRead)
            continue

        new lineNum = 0
        while(!feof(fRead))
        {
            fgets(fRead, line, charsmax(line))
            lineNum++

            if(containi(line, modified_search) != -1)
            {
                found++
                fprintf(fOut, "[%s - line %d] %s", file, lineNum, line)
            }
        }

        fclose(fRead)
    }

    fclose(fOut)

    if(found > 0)
        console_print(id, "[LOG-FINDER] Found %d matches. Results saved to findlog.log", found)
    else
        console_print(id, "[LOG-FINDER] No matches found.")

    return PLUGIN_HANDLED
}
Назад
Верх