Raised This Month: $ Target: $400
 0% 

Gag System [Mysql] doesn't gag !


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dizi
New Member
Join Date: Jul 2011
Old 06-24-2012 , 14:39   Gag System [Mysql] doesn't gag !
Reply With Quote #1

Here is the error i get after typing debug after the plugin:

L 06/24/2012 - 18:55:08: [AMXX] Displaying debug trace (plugin "GagSystem.amxx")
L 06/24/2012 - 18:55:08: [AMXX] Run time error 10: native error (native "SQL_PrepareQuery")
L 06/24/2012 - 18:55:08: [AMXX] [0] GagSystem.sma::CheckGagedPlayer (line 402)
L 06/24/2012 - 18:55:08: [AMXX] [1] GagSystem.sma::cmdSayChat (line 200)


Here is the code:

Code:
#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <unixtime>
#include <sqlx>

#pragma semicolon 1

#define PLUGIN    "Gag System [Sqlx]"
#define AUTHOR    "kostov"
#define VERSION    "1.0"

new Handle:g_iSqlX, Handle:g_iSqlConn;
new iError[512], MsgHudSync, SayText, iTime;
new iCacheUserName[34], bool:iUserGaGed[33];
new iCacheAdmName[34], iCacheUserIp[18];
new iMaxGagTime, iFlagGagTime;

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR);
    
    register_cvar("gag_system", VERSION, FCVAR_SERVER|FCVAR_SPONLY);
    
    iMaxGagTime = register_cvar("amx_maxgag_time", "20");
    iFlagGagTime = register_cvar("amx_maxgag_flag", "d");
    
    register_concmd("amx_gag", "cmdGag", ADMIN_LEVEL_B, "<name> <time> [reason]");
    register_concmd("amx_ungag", "cmdUnGag", ADMIN_LEVEL_B, "<ip>");
    register_concmd("amx_gagmenu", "cmdGagMenu", ADMIN_LEVEL_B);
    register_concmd("amx_gagreason", "cmdGagReason", ADMIN_LEVEL_B);
    register_concmd("amx_gag_clean", "cmdCleanTable", ADMIN_RCON);
    
    register_concmd("say", "cmdSayChat", -1);
    register_concmd("say_team", "cmdSayChat", -1);
    
    MsgHudSync    = CreateHudSyncObj();
    SayText     = get_user_msgid("SayText");
    
    set_task(1.0, "plugin_mysql_init");
    set_task(30.0, "plugin_remove_past_gag");
}

public plugin_end()
{
    if(g_iSqlConn)
    {
        SQL_FreeHandle(g_iSqlConn);
        SQL_FreeHandle(g_iSqlX);
    }
}

public plugin_mysql_init()
{
    new iHost[64], iUser[64], iPass[64], iDb[64], iErrorCode;
    get_cvar_string("amx_sql_host", iHost, sizeof iHost - 1);
    get_cvar_string("amx_sql_user", iUser, sizeof iUser - 1);
    get_cvar_string("amx_sql_pass", iPass, sizeof iPass - 1);
    get_cvar_string("amx_sql_db", iDb, sizeof iDb - 1);
    
    g_iSqlX    = SQL_MakeDbTuple(iHost, iUser, iPass, iDb);
    g_iSqlConn = SQL_Connect(g_iSqlX, iErrorCode, iError, sizeof iError - 1);
    
    if(!g_iSqlConn)
    {
        server_cmd("Could not connect to SQL database!");
        SQL_FreeHandle(g_iSqlConn);
        SQL_FreeHandle(g_iSqlX);
    }
    
    server_cmd("%s Connected!", PLUGIN);
}

public plugin_remove_past_gag()
{
    new Handle:get;
    get = SQL_PrepareQuery(g_iSqlConn, "DELETE FROM `amx_gag` WHERE time <= UNIX_TIMESTAMP(now());");
    SQL_Execute(get);
    SQL_FreeHandle(get);
}

public cmdGag(id, level, cid)
{
    if(!cmd_access(id, level, cid, 3))
    {
        return PLUGIN_HANDLED;
    }
    
    new iArg[32], iTime[5], iReason[129];
    read_argv(1, iArg, sizeof iArg - 1);
    read_argv(2, iTime, sizeof iTime - 1);
    read_argv(3, iReason, sizeof iReason - 1);
    
    new AdminName[33]; 
    get_user_name(id, AdminName, sizeof AdminName - 1);
    
    new iPlayer = cmd_target(id, iArg, CMDTARGET_OBEY_IMMUNITY | CMDTARGET_ALLOW_SELF);
    new iGetTime = str_to_num(iTime);
    
    new PlayerIp[18];
    get_user_ip(iPlayer, PlayerIp, sizeof PlayerIp - 1, 1);
    
    if(!iPlayer)
    {
        client_print(id, print_console, "Cannot find player %s", iArg);
    } else {
        new iGetCvar[16];
        get_pcvar_string(iFlagGagTime, iGetCvar, sizeof iGetCvar - 1);
        if(iGetTime > get_pcvar_num(iMaxGagTime))
        {
            if(!(get_user_flags(id) & read_flags(iGetCvar)))
            {
                client_print(id, print_console, "You have no right to gag more than %d minutes", get_pcvar_num(iMaxGagTime));
                return PLUGIN_HANDLED;
            }
        }
        GagPlayer(id, iArg, PlayerIp, iGetTime, iReason, AdminName);
    }
    
    return PLUGIN_HANDLED;
}

public cmdUnGag(id, level, cid)
{
    if(!cmd_access(id, level, cid, 1))
    {
        return PLUGIN_HANDLED;
    }
    
    new PlayerIp[33];
    read_argv(1, PlayerIp, sizeof PlayerIp - 1);
    UnGagPlayer(id, PlayerIp);
    
    return PLUGIN_HANDLED;
}

public cmdCleanTable(id, level, cid)
{
    if(!cmd_access(id, level, cid, 1))
    {
        return PLUGIN_HANDLED;
    }
    
    TruncateTableMenu(id);
    return PLUGIN_HANDLED;
}

public TruncateTableMenu(id)
{
    new iMenu = menu_create("\wAre you sure you want to empty database?", "TruncateTableMenuFunc");
    menu_additem(iMenu, "\rYes", "1", 0);
    menu_additem(iMenu, "\rNo", "2", 0);
    menu_setprop(iMenu, MPROP_EXIT, MEXIT_ALL);
    menu_display(id, iMenu, 0);
}

public TruncateTableMenuFunc(id, iMenu, Item)
{
    if(Item == MENU_EXIT)
    {
        menu_destroy(iMenu);
        return PLUGIN_HANDLED;
    }
    
    new iData[6], iName[64];
    new access, callback;
    
    menu_item_getinfo(iMenu, Item, access, iData, charsmax(iData), iName, sizeof iName - 1, callback);

    new iKey = str_to_num(iData);
    
    switch(iKey)
    {
        case 1:
        {
            new Handle:iTruncate;
            iTruncate = SQL_PrepareQuery(g_iSqlConn, "TRUNCATE TABLE `amx_gag`");
            if(SQL_Execute(iTruncate))
            {
                Gaged(id, "^4The table was cleared ^3successfully^1!");
            } else {
                Gaged(id, "^4There was a problem, the table is not cleared^4!");
            }
            SQL_FreeHandle(iTruncate);
        }
        case 2:
        {
            return PLUGIN_CONTINUE;
        }
    }
    
    menu_destroy(iMenu);
    return PLUGIN_HANDLED;
}

public cmdSayChat(id)
{
    new iGetUserIp[18];
    get_user_ip(id, iGetUserIp, sizeof iGetUserIp - 1, 1);
    CheckGagedPlayer(id, iGetUserIp);
    
    if(iUserGaGed[id])
    {
        return PLUGIN_HANDLED;
    }
    
    return PLUGIN_CONTINUE;
}

public client_PreThink(id)
{
    if(is_user_connected(id))
    {
        if(iUserGaGed[id])
        {
            set_speak(id, SPEAK_MUTED);
        } else {
            set_speak(id, SPEAK_NORMAL);
        }
    }
}

public client_connect(id)
{
    iUserGaGed[id] = false;
}

public client_disconnect(id)
{
    iUserGaGed[id] = false;
}

public cmdGagMenu(id, level, cid)
{
    if(!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED;
    
    new iMenu = menu_create("\rGag Menu:", "cmdGagMenuFunc");
    new iPlayers[32], iNum, iTarget;
    new UserName[34], szTempID[10];
    get_players(iPlayers, iNum);
    for(new i; i < iNum; i++)
    {
        iTarget = iPlayers[i];
        get_user_name(iTarget, UserName, sizeof UserName - 1);
        num_to_str(iTarget, szTempID, charsmax(szTempID));
        menu_additem(iMenu, UserName, szTempID, _, menu_makecallback("GagMenuPlayers"));
    }

    menu_display(id, iMenu, 0);
    return PLUGIN_HANDLED;
}

public GagMenuPlayers(iClient, iMenu, Item)
{
    new iAccess, Info[3], iCallback;
    menu_item_getinfo(iMenu, Item, iAccess, Info, sizeof Info - 1, _, _, iCallback);
    
    new iGetID = str_to_num(Info);
    
    if(access(iGetID, ADMIN_IMMUNITY))
    {
        return ITEM_DISABLED;
    } 
    
    if(iUserGaGed[iGetID])
    {
        return ITEM_DISABLED;
    }
    
    return ITEM_ENABLED;
}

public cmdGagMenuFunc(id, iMenu, Item)
{
    if(Item == MENU_EXIT)
    {
        menu_destroy(iMenu);
        return PLUGIN_HANDLED;
    }

    new iData[6], iName[64];
    new access, callback;
    menu_item_getinfo(iMenu, Item, access, iData, charsmax(iData), iName, charsmax(iName), callback);

    new iTarget = str_to_num(iData);
    get_user_name(iTarget, iCacheUserName, sizeof iCacheUserName - 1);
    get_user_name(id, iCacheAdmName, sizeof iCacheAdmName - 1);
    get_user_ip(iTarget, iCacheUserIp, sizeof iCacheUserIp - 1, 1);
    cmdGagMenuTime(id);
    menu_destroy(iMenu);
    return PLUGIN_HANDLED;
}

public cmdGagMenuTime(id)
{
    new iMenu = menu_create("\wSelect minutes?", "cmdGagMenuTimeFunc");
    menu_additem(iMenu, "\y1 minute", "1");
    menu_additem(iMenu, "\y5 minutes", "5");
    menu_additem(iMenu, "\y10 minutes", "10");
    menu_additem(iMenu, "\y15 minutes", "15");
    menu_additem(iMenu, "\y20 minutes", "20");
    menu_setprop(iMenu, MPROP_EXIT, MEXIT_ALL);
    menu_display(id, iMenu, 0);
}

public cmdGagMenuTimeFunc(id, iMenu, Item)
{
    if(Item == MENU_EXIT)
    {
        menu_destroy(iMenu);
        return PLUGIN_HANDLED;
    }
    new iData[6];
    new access, callback;
    menu_item_getinfo(iMenu, Item, access, iData, sizeof iData - 1, _, _, callback);
    iTime = str_to_num(iData);
    client_cmd(id, "messagemode amx_gagreason");
    menu_destroy(iMenu);
    return PLUGIN_HANDLED;
}

public cmdGagReason(id, level, cid)
{
    if(!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED;
    
    new iReason[64];
    read_argv(1, iReason, sizeof iReason - 1);
    GagPlayer(id, iCacheUserName, iCacheUserIp, iTime, iReason, iCacheAdmName);
    return PLUGIN_HANDLED;
}

stock GagPlayer(id, const iPlayer[], const PlayerIp[], iTime, const iReason[], const iAdminName[])
{
    new Handle:get;
    get = SQL_PrepareQuery(g_iSqlConn, "SELECT `player_ip` FROM `amx_gag` WHERE `player_ip` = ^"%s^"", PlayerIp);
    
    new ExpireDate = time() + (iTime * 60);
    
    if(SQL_Execute(get))
    {
        if(SQL_NumResults(get) > 0)
        {
            SQL_FreeHandle(get);
            client_print(id, print_console, "User ^"%s^" is already gaged", iPlayer);
        } else {
            new Handle:set;
            set = SQL_PrepareQuery(g_iSqlConn, "INSERT INTO `amx_gag` VALUES(NULL, ^"%s^", '%s', '%d', ^"%s^", ^"%s^")", iPlayer, PlayerIp, ExpireDate, iReason, iAdminName);
            SQL_Execute(set);
            SQL_FreeHandle(set);
            SQL_FreeHandle(get);
            client_print(id, print_console, "Player is gaged successfully!");
            
            switch(get_cvar_num("amx_show_activity"))
            {
                case 1:
                {
                    set_hudmessage(0, 255, 0, 0.05, 0.30, 0, 6.0, 12.0, 0.1, 0.2, 12);
                    ShowSyncHudMsg(0, MsgHudSync, "%s has been gaged. ^nReason: %s", iPlayer, iReason);
                }
                case 2:
                {
                    set_hudmessage(0, 255, 0, 0.05, 0.30, 0, 6.0, 12.0, 0.1, 0.2, 12);
                    ShowSyncHudMsg(0, MsgHudSync, "%s has been gaged. ^nReason: %s ^nBy admin %s", iPlayer, iReason, iAdminName);
                }
            }
        }
    } else {
        SQL_FreeHandle(get);
    }
}

stock UnGagPlayer(id, const PlayerIp[])
{
    new Handle:get;
    get = SQL_PrepareQuery(g_iSqlConn, "SELECT * FROM `amx_gag` WHERE `player_ip`= ^"%s^"", PlayerIp);
    
    if(SQL_Execute(get))
    {
        if(SQL_NumResults(get) > 0)
        {
            new iGetId = SQL_ReadResult(get, 0);
            new Handle:del;
            del = SQL_PrepareQuery(g_iSqlConn, "DELETE FROM `amx_gag` WHERE `id` = '%d'", iGetId);
            SQL_Execute(del);
            client_print(id, print_console, "Gag has been removed successfully!");
            SQL_FreeHandle(del);
            SQL_FreeHandle(get);
        } else {
            SQL_FreeHandle(get);
            client_print(id, print_console, "No user with that ipaddres in the database!");
        }
    } else {
        SQL_FreeHandle(get);
    }
}

stock CheckGagedPlayer(id, const iPlayerIP[])
{
    new Handle:get;
    get = SQL_PrepareQuery(g_iSqlConn, "SELECT * FROM `amx_gag` WHERE `player_ip` = ^"%s^"", iPlayerIP);
    
    if(SQL_Execute(get))
    {
        if(SQL_NumResults(get) > 0)
        {
            new iGetId = SQL_ReadResult(get, 0);
            new ExpireDate[11]; SQL_ReadResult(get, 3, ExpireDate, sizeof ExpireDate - 1);
            new iGetReason[129]; SQL_ReadResult(get, 4, iGetReason, sizeof iGetReason - 1);
            if(strlen(ExpireDate) > 0)
            {
                if(time() < str_to_num(ExpireDate))
                {
                    new iGagChat[512], iMonth, iDay, iYear, iHour, iMinute, iSecond;
                    new iUnixTime = str_to_num(ExpireDate);
                    UnixToTime(iUnixTime , iYear , iMonth , iDay , iHour , iMinute , iSecond );
                    formatex(iGagChat, sizeof iGagChat - 1, "^4You are gaged^1! Your gag will expire on: ^3%02d/%02d/%02d - %02d:%02d:%02d ^1: Reason: ^4%s", iDay, iMonth, iYear, iHour + 2, iMinute , iSecond, iGetReason);
                    Gaged(id, "%s", iGagChat);
                    iUserGaGed[id] = true;
                    SQL_FreeHandle(get);
                } else {
                    new Handle:del;
                    del = SQL_PrepareQuery(g_iSqlConn, "DELETE FROM `amx_gag` WHERE `id` = '%d'", iGetId);
                    iUserGaGed[id] = false;
                    SQL_Execute(del);
                    SQL_FreeHandle(del);
                    SQL_FreeHandle(get);
                }
            }
        } else {
            iUserGaGed[id] = false;
        }
    } else {
        SQL_FreeHandle(get);
    }
}

stock Gaged(const id, const input[], any:...)
{
    new count = 1, players[32];
    static msg[191];
    vformat(msg, 190, input, 3);
    if (id) players[0] = id; else get_players(players, count, "ch");
    {
        for (new i = 0; i < count; i++)
        {
            if (is_user_connected(players[i]))
            {
                message_begin(MSG_ONE_UNRELIABLE, SayText, _, players[i]) ; 
                write_byte(players[i]);
                write_string(msg);
                message_end();
            }
        }
    }
}
Dizi is offline
Old 06-26-2012, 15:49
Dizi
This message has been deleted by Exolent[jNr]. Reason: Don't bump until 2 weeks have passed since last post.
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:12.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode