O noua aventura incepe. LaLeagane - It's all about gaming!

2006 and still counting.

PLUGIN Plugin WarnSystem

Senor LLG

leganar
Joined
May 3, 2018
Messages
244
Reaction score
230
Location
/var/tmp
Autor: Senor
Versiune: beta
Descriere: cu acest plugin poti da warn la useri ! Se va face un API pentru el ! Foloseste MYSQL !
C++:
[/I][/B][/I][/B]
#include <amxmodx>

#if defined USING_MYSQL
#include <sqlx>
#endif

#include <cstrike>
#include <amxmisc>
#include <nvault>

#define MAX_NAME_LENGHT 33
#define MAX_CELLS 33

#define nvault_name "Warn nVault"
#define BAN_TIME 1440

//#define USING_MYSQL
#define USING_NVAULT

new const _warnAcces[] = {"d"}
new const _warnMenuTitle[] = "Warn System^nBy SenorAMXX"

new const _warnReasons[][] =
{
    "Teamming",
    "Bad Language",
    "Trolling",
    "Cheating",
    "Other Reason"
}

#if defined USING_MYSQL
enum(+=111110111011) {TASK_SENORAMXXX}

enum _:DataBase 
{    
    szHost[64], 
    szUser[64], 
    szPassword[64], 
    szDatabase[64], 
    szTable[64]    
}

enum _:PlayersInfo 
{    
    szName[MAX_NAME_LENGHT], 
    szSteamID[32], 
    Warns    
}
new g_pd[MAX_PLAYERS + 1][PlayersInfo]
#endif




#if defined USING_MYSQL
new g_db[DataBase]
#endif



#if defined USING_MYSQL
new Handle:g_szSqlTuple
new Handle:g_iSqlConnection
new g_iTry
new g_SqlError[512]
#endif

new iVault, iEntity, iWarns[MAX_CELLS]

enum _:vvv {max_warns}
new var[vvv]
public plugin_init()
{
    register_plugin("WARN SYSTEM", "1.0", "SenorAMXX")
    register_clcmd("say /warn", "warnMain")
    register_clcmd("say /mywarns", "myWarns")

    var[max_warns] = register_cvar("max_warns", "5")

    #if defined USING_MYSQL
    new iVar

    iVar = create_cvar("plugin_db_host", "hostname")
    bind_pcvar_string(iVar, g_db[szHost], charsmax(g_db[szHost]))

    iVar = create_cvar("plugin_db_user", "user")
    bind_pcvar_string(iVar, g_db[szUser], charsmax(g_db[szUser]))

    iVar = create_cvar("plugin_db_password", "password")
    bind_pcvar_string(iVar, g_db[szPassword], charsmax(g_db[szPassword]))

    iVar = create_cvar("plugin_db_db", "database name")
    bind_pcvar_string(iVar, g_db[szDatabase], charsmax(g_db[szDatabase]))

    iVar = create_cvar("plugin_db_table", "table")
    bind_pcvar_string(iVar, g_db[szTable], charsmax(g_db[szTable]))

    AutoExecConfig()#endif
    set_task(2.0, "connect_db")
    #endif

    #if defined USING_NVAULT
    nvault_open(nvault_name)
    #endif
}
#if defined USING_MYSQL
public plugin_end()
{
    SQL_FreeHandle(g_szSqlTuple)
    SQL_FreeHandle(g_iSqlConnection)
}
public connect_db()
{
    g_iTry += 1
    g_szSqlTuple = SQL_MakeDbTuple(g_db[szHost],g_db[szUser],g_db[szPassword],g_db[szDatabase], 10)

    new error
    g_iSqlConnection = SQL_Connect(g_szSqlTuple, error, g_SqlError, charsmax(g_SqlError))

    if(g_iSqlConnection == Empty_Handle)
    {
        log_amx("[warn_system.amxx] Incorect database settings!")
        SQL_FreeHandle(g_iSqlConnection)

        if(g_iTry < 2)
        {
        connect_db()
        return
        }
    }    
    
    new szQueryData[600]
    formatex(szQueryData, charsmax(szQueryData),"CREATE TABLE IF NOT EXISTS `%s`\
    (`Name` VARCHAR(32) NOT NULL,\
    `SteamID` VARCHAR(32) NOT NULL,\
    `Warns` INT NOT NULL,\
    PRIMARY KEY(Name,SteamID))", g_db[szTable])

    new Handle:iQueries = SQL_PrepareQuery(g_iSqlConnection, szQueryData)

    if(!SQL_Execute(iQueries))
    {
        SQL_QueryError(iQueries, g_SqlError, charsmax(g_SqlError))
        log_amx(g_SqlError)
    }

    SQL_Execute(iQueries)
    SQL_FreeHandle(iQueries)
}

public client_putinserver(id)
{
    get_user_authid(id, g_pd[id][szSteamID], charsmax(g_pd[][szSteamID]))
    get_user_name(id, g_pd[id][szName], charsmax(g_pd[][szSteamID]))
    g_pd[id][Warns] = 0

    if(!is_user_bot(id) || !is_user_hltv(id))    set_task(2.0, "delay_loading_data", id + TASK_SENORAMXXX)
}

public delay_loading_data(id)
{
    id -= TASK_SENORAMXXX
    LoadData(id)
}
#endif

#if defined USING_NVAULT
public client_connect(id)
{
    new steamID[32]
    get_user_authid(id, steamID, charsmax(steamID))
    new key[64], data[256]
    format(key, charsmax(key), "%s - Warns", steamID)
    format(data, charsmax(data), "%i", iWarns[id])
    nvault_get(iVault, key, data, charsmax(data))

    replace_all(data, charsmax(data), "#", " ")

    new chk[32]
    parse(data, chk, charsmax(chk))
    iWarns[id] = str_to_num(chk)

}
#endif

public client_disconnected(id)
{
    #if defined USING_MYSQL
    if(!is_user_bot(id) || !is_user_hltv(id))    SaveData(id)
    #endif

    #if defined USING_NVAULT
    new steamID[32]
    get_user_authid(id, steamID, charsmax(steamID))

    new key[64], data[256]
    format(key, charsmax(key), "%s - Warns", steamID)
    format(data, charsmax(data), "%i", iWarns[id])

    nvault_set(iVault, key, data)
    #endif
}

public warnMain(id)
{
    new title[55]
    formatex(title, charsmax(title), "%s", _warnMenuTitle)
    new menu = menu_create(title, "warnHandler")

    new temp[512 char], btn[10]
    for(new senor; senor < sizeof(_warnReasons); senor++)
    {
        formatex(temp, charsmax(temp), "%s",_warnReasons[senor])
        num_to_str(senor, btn, charsmax(btn))
    }
    menu_display(id, menu)
}

public warnHandler(id, menu, item)
{
    if(item == MENU_EXIT) 
    {
        menu_destroy(menu)
        return PLUGIN_HANDLED
    }
    new data[6], name[MAX_NAME_LENGHT], access, callback
    menu_item_getinfo(menu, item, access, data, charsmax(data), name, charsmax(name), callback)

    iWarns[id] = str_to_num(data)

    new iPlayers[32], iNum, iTempID, name2[MAX_NAME_LENGHT], btn[10]

    new menu = menu_create("Warn a player :","warnHandlerHandler")
    get_players(iPlayers, iNum)

    for(new senor; senor < iNum; senor++)
    {
        iTempID = iPlayers[senor]

        get_user_name(iTempID, name2, charsmax(name2))
        num_to_str(iTempID, btn, charsmax(btn))
        menu_additem(menu, name2, btn, 0)
    }
    menu_display(id, menu, 0)
    return PLUGIN_CONTINUE
}

public warnHandlerHandler(id, menu, item)
{
    if(item == MENU_EXIT) 
    {
        menu_destroy(menu)
        return PLUGIN_HANDLED
    }
    new data[6], name[MAX_NAME_LENGHT], access, callback
    menu_item_getinfo(menu, item, access, data, charsmax(data), name, charsmax(name), callback)

    iEntity = str_to_num(data)
    get_user_name(iEntity, name, charsmax(name))

    #if defined USING_NVAULT
    if(iWarns[iEntity] == get_pcvar_num(var[max_warns]))    server_cmd("amx_ban ^"%s^" BAN_TIME ^"Ai primit ban^"", name)
    else iWarns[iEntity]++
    #endif

    #if defined USING_MYSQL
    if(g_pd[id][Warns] == get_pcvar_num(var[max_warns]))    server_cmd("amx_ban ^"%s^" BAN_TIME ^"Ai primit ban^"", name)
    else g_pd[id][Warns]++
    #endif

    return PLUGIN_HANDLED

}

#if defined USING_MYSQL
public LoadData(id)
{
    new Handle:iQuery = SQL_PrepareQuery(g_iSqlConnection, "SELECT * FROM `%s` WHERE `SteamID` = '%s';", g_db[szTable], g_pd[id][szSteamID])

    if(!SQL_Execute(iQuery))
    {
        SQL_QueryError(iQuery, g_SqlError, charsmax(g_SqlError))
        log_amx(g_SqlError)
        SQL_FreeHandle(iQuery)
    }

    new szQuery[512]
    new bool:b_found = SQL_NumResults( iQuery ) > 0 ? false : true

    if(b_found)
    {
        formatex(szQuery, charsmax(szQuery), "INSERT INTO `%s`\
            (`Name`,\
            `SteamID`,\
            `Warns`\
            ) VALUES (^"%s^",'%s','0');", g_db[szTable], g_pd[id][szName], g_pd[id][szSteamID])
    }
    else
    {
        formatex(szQuery, charsmax(szQuery), "SELECT \
            `Name`,\
            `Warns`\
            FROM `%s` WHERE `SteamID` = '%s';", g_db[szTable], g_pd[id][szSteamID])
    }

    iQuery = SQL_PrepareQuery(g_iSqlConnection, szQuery)

    if(!SQL_Execute(iQuery))
    {
        SQL_QueryError(iQuery, g_SqlError, charsmax(g_SqlError))
        log_amx(g_SqlError)
    }

    if(!b_found)
    {
        if(SQL_NumResults(iQuery) > 0)    g_pd[id][Warns] = SQL_ReadResult(iQuery, SQL_FieldNameToNum(iQuery, "Warns"))
    }

    SQL_FreeHandle(iQuery)
}

public SaveData(id)
{
    new szQuery[512]
    formatex(szQuery, charsmax(szQuery), "UPDATE `%s`\
    SET `Name`=^"%s^",\
    `Warns`='%d'\
    WHERE `SteamID`='%s';", g_db[szTable], g_pd[id][szName], g_pd[id][Warns],  g_pd[id][szSteamID])
    SQL_ThreadQuery(g_szSqlTuple, "QueryHandler", szQuery)
}

public QueryHandler(iFailState, Handle:iQuery, szError[], iErrorCode)
{
    switch(iFailState)
    {
        case TQUERY_CONNECT_FAILED: 
        {
            log_amx("[SQL Error] Connection failed (%i): %s", iErrorCode, szError)
        }
        case TQUERY_QUERY_FAILED:
        {
            log_amx("[SQL Error] Query failed (%i): %s", iErrorCode, szError)
        }
    }
}
#endif



stock bool: is_admin(id)
{
    if(get_user_flags(id) & read_flags(_warnAcces)) return true
    return false
}

[B][I]
 
Last edited:

Senor LLG

leganar
Joined
May 3, 2018
Messages
244
Reaction score
230
Location
/var/tmp
Pluginul a fost updatat, warn-urile se salveaza pe mysql / nvault ! La warnurile setate din cvar si macro se primeste ban ! Voi adauga native in curand !

PS : Netestat
 
shape1
shape2
shape3
shape4
shape5
shape6
Top