[MySQL Threads 1.2] Crash на линуксе

Сообщения
673
Реакции
242
Помог
11 раз(а)
Добрый вечер форум

Сделал рефакторинг кода по БД на основе модуля MySQL Threads 1.2 (Первоисточник)

На виндовсе все работает как часы, шустро и быстро
но как только заливаю на сервер линукс, то после смены карты последует краш,

[New LWP 22389]
[New LWP 22387]
[New LWP 22430]
[New LWP 22388]
[New LWP 22392]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Program terminated with signal 11, Segmentation fault.
#0 0xffffffff in ?? ()
#0 0xffffffff in ?? ()
#1 0xf1c22347 in end_server () from cstrike/addons/amxmodx/modules/mysqlt_amxx_i386.so
#2 0xf1c22440 in cli_safe_read () from cstrike/addons/amxmodx/modules/mysqlt_amxx_i386.so
#3 0xf1c2532f in ?? () from cstrike/addons/amxmodx/modules/mysqlt_amxx_i386.so
#4 0xf1c21324 in mysql_real_query () from cstrike/addons/amxmodx/modules/mysqlt_amxx_i386.so
#5 0xf1c1698f in ?? () from cstrike/addons/amxmodx/modules/mysqlt_amxx_i386.so
#6 0xf1c16b73 in ?? () from cstrike/addons/amxmodx/modules/mysqlt_amxx_i386.so
#7 0xf1c138b8 in ?? () from cstrike/addons/amxmodx/modules/mysqlt_amxx_i386.so
#8 0xf1c154ef in ?? () from cstrike/addons/amxmodx/modules/mysqlt_amxx_i386.so
#9 0xf1c15bab in ?? () from cstrike/addons/amxmodx/modules/mysqlt_amxx_i386.so
#10 0xf1c1639b in ?? () from cstrike/addons/amxmodx/modules/mysqlt_amxx_i386.so
#11 0xf76cdb2c in start_thread () from /lib/libpthread.so.0
#12 0xf75fe17e in clone () from /lib/libc.so.6
No symbol table info available.
From To Syms Read Shared Object Library
0xf7734914 0xf777ac78 Yes ./libstdc++.so.6
0xf76e2a90 0xf76e397c Yes (*) /lib/libdl.so.2
0xf76cb780 0xf76d7857 Yes (*) /lib/libpthread.so.0
0xf751d320 0xf766391b Yes (*) /lib/libc.so.6
0xf74c8460 0xf74f2c06 Yes (*) /lib/libm.so.6
0xf74b0e04 0xf74c0490 Yes ./libgcc_s.so.1
0xf77d18a0 0xf77ec261 Yes (*) /lib/ld-linux.so.2
0xf6d99c90 0xf6eb2951 Yes (*) /game/engine_i486.so
0xf6d03900 0xf6d06dca Yes (*) /lib/librt.so.1
0xf6cf15c0 0xf6cfbd74 Yes (*) ./libsteam_api.so
0xf6cd6f40 0xf6ce88f8 Yes (*) /game/filesystem_stdio.so
0xf58a0200 0xf67393c4 Yes (*) /.steam/sdk32/steamclient.so
0xf2f786a0 0xf2fbaf70 Yes (*) /game/./cstrike/addons/metamod/dlls/metamod_i386.so
0xf2d458e0 0xf2ec0e00 Yes (*) /game/cstrike/dlls/cs.so
0xf2c38d00 0xf2c39f40 Yes (*) /game/cstrike/addons/snac/SafeNameAndChat.so
0xf2c105b0 0xf2c26ca0 Yes (*) /game/cstrike/addons/reunion/reunion_mm_i386.so
0xf2be6b40 0xf2bf00b0 Yes (*) /game/cstrike/addons/reauthcheck/reauthcheck_mm_i386.so
0xf2aa0f80 0xf2ba4fe0 Yes (*) /game/cstrike/addons/revoice/revoice_mm_i386.so
0xf28ba8f0 0xf291da07 Yes (*) /game/cstrike/addons/amxmodx/dlls/amxmodx_mm_i386.so
0xf280e010 0xf2877d59 Yes (*) /game/cstrike/addons/unprecacher/unprecacher_i386.so
0xf264e9d0 0xf267ad6c Yes (*) cstrike/addons/amxmodx/modules/fakemeta_amxx_i386.so
0xf1fbe790 0xf2056fc5 Yes (*) cstrike/addons/amxmodx/modules/mysql_amxx_i386.so
0xf25cbd20 0xf26095a0 Yes (*) cstrike/addons/amxmodx/modules/reapi_amxx_i386.so
0xf2598d50 0xf25a8460 Yes (*) cstrike/addons/amxmodx/modules/cstrike_amxx_i386.so
0xf25225d0 0xf256b548 Yes (*) cstrike/addons/amxmodx/modules/regex_amxx_i386.so
0xf24c4b60 0xf250c624 Yes (*) cstrike/addons/amxmodx/modules/hamsandwich_amxx_i386.so
0xf249c9b0 0xf24a0a08 Yes (*) cstrike/addons/amxmodx/modules/nvault_amxx_i386.so
0xf2484290 0xf249080c Yes (*) cstrike/addons/amxmodx/modules/engine_amxx_i386.so
0xf2468cf0 0xf246de64 Yes (*) cstrike/addons/amxmodx/modules/vdf_amxx_i386.so
0xf1c10ba0 0xf1cc2e18 Yes (*) cstrike/addons/amxmodx/modules/mysqlt_amxx_i386.so
0xf2441660 0xf2445f84 Yes (*) cstrike/addons/amxmodx/modules/fun_amxx_i386.so
0xf1a84a50 0xf1a8bfb9 Yes (*) /lib/libnss_files.so.2
0xf1a5ec00 0xf1a6206e Yes (*) /lib/libnss_dns.so.2
0xf1a466a0 0xf1a55694 Yes (*) /lib/libresolv.so.2
0xea311e80 0xeadf9040 Yes (*) ./steamclient.so
0xf185f670 0xf18d5020 Yes (*) ./crashhandler.so
(*): Shared library is missing debugging information.
Stack level 0, frame at 0xef213160:
eip = 0xffffffff; saved eip 0xf1c22347
called by frame at 0xef213190
Arglist at 0xef213158, args:
Locals at 0xef213158, Previous frame's sp is 0xef213160
Saved registers:
eip at 0xef21315c
End of crash report
----------------------------------------------

Грешу на обработку plugin_end() так он срабатывает после смены карт, но вроде я сделал все правильно, закрыл соеденение

Не могли бы вы помочь

Код:
#include <amxmodx>
#include <mysqlt>
//#include <sqlx>


#define        PLUGIN_NAME         "MysqL Core"
#define        PLUGIN_VERSION      "1.0"
#define        PLUGIN_AUTHOR          "DalgaPups"


const QUERY_LENGTH =    1472    // размер переменной sql запроса

enum _:STATS
{
    STATS_DATA_1,
    STATS_DATA_2,
    STATS_DATA_3,
    STATS_DATA_4,
    STATS_DATA_5,
    STATS_DATA_6[MAX_NAME_LENGTH],
    STATS_DATA_7,
    STATS_DATA_8,
    STATS_INFLICTOR_NAME[MAX_NAME_LENGTH],
    STATS_DATE[MAX_NAME_LENGTH]
};

enum _:sql_que_type    // тип sql запроса
{
    SQL_INITDB,
    SQL_IGNORE,
    SQL_LOAD,
    SQL_CHECK
}

enum _:EXT_DATA_STRUCT {
    EXT_DATA__SQL,
    EXT_DATA__USERID,
    EXT_DATA__INDEX
}



new g_iStatsPlayers[MAX_PLAYERS + 1][STATS];

const SQL_CONNECTION_TIMEOUT = 10;

new bool:g_iSql = false,
    Handle:g_hDBSaveOther,
    Handle:g_Connection


new g_szRankTable[32];



public plugin_init( )
{
    register_plugin
    (
        PLUGIN_NAME,
        PLUGIN_VERSION,
        PLUGIN_AUTHOR
    );

    new szPath[64], szPathFile[128];
    get_localinfo("amxx_configsdir", szPath, charsmax(szPath));
   
    formatex(szPathFile, charsmax(szPathFile), "%s/jb_engine/mysql_regs.cfg", szPath);
    if(file_exists(szPathFile))
        RegisterMysqlSystems(szPathFile);

    SqlInit();

    //cvars_init();
}

RegisterMysqlSystems(cfg[])
{
    register_cvar("jbe_mysql_sql_host", "", FCVAR_PROTECTED);
    register_cvar("jbe_mysql_sql_user", "", FCVAR_PROTECTED);
    register_cvar("jbe_mysql_sql_password", "", FCVAR_PROTECTED);
    register_cvar("jbe_mysql_sql_database",  "", FCVAR_PROTECTED);
    register_cvar("jbe_sql_prefixes_table",  "", FCVAR_PROTECTED);

    ExecCfg(cfg);
}

ExecCfg(const cfg[])
{
    server_cmd("exec %s", cfg);
    server_exec();
}


public plugin_natives()
{
    register_native("jbe_is_user_data", "jbe_is_user_data", true);
    register_native("jbe_set_user_data", "jbe_set_user_data", true);
    register_native("jbe_block_reasons", "jbe_block_reasons");
    register_native("jbe_mysql_block_date", "jbe_mysql_block_date", false);
    register_native("jbe_mysql_block_inf_name", "jbe_mysql_block_inf_name", false);
    register_native("jbe_mysql_block_time", "jbe_mysql_block_time", true);
    register_native("jbe_mysql_block_reason", "jbe_mysql_block_reason", false);
    register_native("jbe_mysql_block_start_time", "jbe_mysql_block_start_time", true);
}

public jbe_mysql_block_date(plugin_id, num_params)
{
    new id;
    id=get_param(1);
   
    return set_string(2, g_iStatsPlayers[id][STATS_DATE], get_param(3));
}

public jbe_mysql_block_inf_name(plugin_id, num_params)
{
    new id;
    id=get_param(1);
   
    return set_string(2, g_iStatsPlayers[id][STATS_INFLICTOR_NAME], get_param(3));
}

public jbe_mysql_block_reason(plugin_id, num_params)
{
    new id;
    id=get_param(1);
   
    return set_string(2, g_iStatsPlayers[id][STATS_DATA_6], get_param(3));
}

public jbe_mysql_block_time(id) return g_iStatsPlayers[id][STATS_DATA_7];
public jbe_mysql_block_start_time(id) return g_iStatsPlayers[id][STATS_DATA_8];


public jbe_block_reasons(plugins_params, num_params)
{
    new id = get_param(1);

    new szTemp[32];
    get_string(2, szTemp, charsmax(szTemp));
   
    copy(g_iStatsPlayers[id][STATS_DATA_6], 31, szTemp);
    g_iStatsPlayers[id][STATS_DATA_7] = get_param(3);

    g_iStatsPlayers[id][STATS_DATA_8] = get_param(4);

    g_iStatsPlayers[id][STATS_INFLICTOR_NAME] = get_param(5);

    new szName[MAX_NAME_LENGTH];
    get_string(5, szName, MAX_NAME_LENGTH - 1);
    copy(g_iStatsPlayers[id][STATS_INFLICTOR_NAME], MAX_NAME_LENGTH - 1, szName);

    if(g_iSql)
    {
        new query[QUERY_LENGTH],que_len
        new szAuthID[35];

        //server_print("Проверка - %s", g_iStatsPlayers[iPlayer][STATS_DATA_6])

        get_user_authid(id, szAuthID, charsmax(szAuthID));

        que_len += formatex(query[que_len],charsmax(query) - que_len,"\
        UPDATE `%s` SET \
        \
        `DATA_1` = '%i',\
        `DATA_7` = '%i',\
        `DATA_8` = '%i',\
        `DATA_INFLICTOR` = '%s',\
        `DATE_BLOCK` = NOW() \
        \
        WHERE `AUTH` = '%s'",
        g_szRankTable,    

                        g_iStatsPlayers[id][STATS_DATA_1],
                        g_iStatsPlayers[id][STATS_DATA_7],
                        g_iStatsPlayers[id][STATS_DATA_8],
                        g_iStatsPlayers[id][STATS_INFLICTOR_NAME],  

        szAuthID);

        new sData[EXT_DATA_STRUCT];
        sData[EXT_DATA__SQL] = SQL_IGNORE;
        mysql_query(g_Connection, "selectQueryHandler", query, sData, sizeof sData);

        //server_print("%s", g_iStatsPlayers[id][STATS_DATA_6]);
    }
}
   
public jbe_is_user_data(player, iType)
{
    switch(iType)
    {
        case 1: return g_iStatsPlayers[player][STATS_DATA_1];
        case 2: return g_iStatsPlayers[player][STATS_DATA_2];
        case 3: return g_iStatsPlayers[player][STATS_DATA_3];
        case 4: return g_iStatsPlayers[player][STATS_DATA_4];
        case 5: return g_iStatsPlayers[player][STATS_DATA_5];
        case 7: return g_iStatsPlayers[player][STATS_DATA_7];
        case 8: return g_iStatsPlayers[player][STATS_DATA_8];
    }
    return PLUGIN_HANDLED;
}

public jbe_set_user_data(player, iType, iNum)
{
    switch(iType)
    {
        case 1: g_iStatsPlayers[player][STATS_DATA_1] = iNum;
        case 2: g_iStatsPlayers[player][STATS_DATA_2] = iNum;
        case 3: g_iStatsPlayers[player][STATS_DATA_3] = iNum;
        case 4: g_iStatsPlayers[player][STATS_DATA_4] = iNum;
        case 5: g_iStatsPlayers[player][STATS_DATA_5] = iNum;
    }
    return PLUGIN_HANDLED;
}

public SqlInit()
{
    new    g_szRankHost[128],
        g_szRankUser[64],
        g_szRankPassword[64],
        g_szRankDataBase[64];

    get_cvar_string("jbe_mysql_sql_host",             g_szRankHost,         charsmax(g_szRankHost));
    get_cvar_string("jbe_mysql_sql_user",             g_szRankUser,         charsmax(g_szRankUser));
    get_cvar_string("jbe_mysql_sql_password",         g_szRankPassword,    charsmax(g_szRankPassword));
    get_cvar_string("jbe_mysql_sql_database",         g_szRankDataBase,     charsmax(g_szRankDataBase));
    get_cvar_string("jbe_sql_prefixes_table",            g_szRankTable,         charsmax(g_szRankTable));


    g_hDBSaveOther = mysql_makehost
    (
        g_szRankHost,
        g_szRankUser,
        g_szRankPassword,
        g_szRankDataBase,
        SQL_CONNECTION_TIMEOUT
    );
   
    new error[32], errnum
    g_Connection = mysql_connect(g_hDBSaveOther, errnum, error, 31)

    if(g_Connection == Empty_Handle)
    {
        new szText[128];
        formatex(szText, charsmax(szText), "%s", error);
        log_to_file("mysqlt.log", "[MYSQL_SAVE_BLOCK] MYSQL ERROR: #%d", errnum);
        log_to_file("mysqlt.log", "[MYSQL_SAVE_BLOCK] %s", szText);
        return;
    }
   
    mysql_free(g_hDBSaveOther);

   
    new query[QUERY_LENGTH],que_len
    que_len += formatex(query[que_len],charsmax(query) - que_len,"CREATE TABLE IF NOT EXISTS `%s`\
    (\
        `id`        int(11) NOT NULL AUTO_INCREMENT,\
        `AUTH`       varchar(35) NOT NULL,\
        `DATA_1`     int(11) NOT NULL, \
        `DATA_2`     int(11) NOT NULL, \
        `DATA_3`     int(11) NOT NULL, \
        `DATA_4`     int(11) NOT NULL, \
        `DATA_5`     int(11) NOT NULL, \
        `DATA_6`       varchar(35) NOT NULL COLLATE 'utf8_general_ci',\
        `DATA_7`     int(11) NOT NULL, \
        `DATA_8`     int(11) NOT NULL, \
        `DATA_INFLICTOR`     varchar(35) NOT NULL, \
        `DATE_BLOCK` DATETIME,\
        PRIMARY KEY (id)\
    )", g_szRankTable);


    new sData[EXT_DATA_STRUCT];
    sData[EXT_DATA__SQL] = SQL_INITDB;
    mysql_query(g_Connection, "selectQueryHandler", query, sData, sizeof sData);
}


public client_disconnected(iPlayer)
{
    if(g_iSql)
    {
        new query[QUERY_LENGTH],que_len
        new szAuthID[35];

        //server_print("Проверка - %s", g_iStatsPlayers[iPlayer][STATS_DATA_6])

       

        get_user_authid(iPlayer, szAuthID, charsmax(szAuthID));

        que_len += formatex(query[que_len],charsmax(query) - que_len,"\
        UPDATE `%s` SET \
        `DATA_1` = '%i',\
        `DATA_2` = '%i',\
        `DATA_3` = '%i',\
        `DATA_4` = '%i',\
        `DATA_5`= '%i',\
        `DATA_6` = '%s',\
        `DATA_7`= '%i',\
        `DATA_8`= '%i',\
        `DATA_INFLICTOR` = '%s'\
        WHERE `AUTH` = '%s'",
        g_szRankTable,     g_iStatsPlayers[iPlayer][STATS_DATA_1],
                        g_iStatsPlayers[iPlayer][STATS_DATA_2],
                        g_iStatsPlayers[iPlayer][STATS_DATA_3],
                        g_iStatsPlayers[iPlayer][STATS_DATA_4],
                        g_iStatsPlayers[iPlayer][STATS_DATA_5],
                        g_iStatsPlayers[iPlayer][STATS_DATA_6],
                        g_iStatsPlayers[iPlayer][STATS_DATA_7],
                        g_iStatsPlayers[iPlayer][STATS_DATA_8],
                        g_iStatsPlayers[iPlayer][STATS_INFLICTOR_NAME],
                        szAuthID);
        new sData[EXT_DATA_STRUCT];
        sData[EXT_DATA__SQL] = SQL_IGNORE;
        mysql_query(g_Connection, "selectQueryHandler", query, sData, sizeof sData);
    }

    g_iStatsPlayers[iPlayer][STATS_DATA_1] = 0;
    g_iStatsPlayers[iPlayer][STATS_DATA_2] = 0;
    g_iStatsPlayers[iPlayer][STATS_DATA_3] = 0;
    g_iStatsPlayers[iPlayer][STATS_DATA_4] = 0;
    g_iStatsPlayers[iPlayer][STATS_DATA_5] = 0;
    g_iStatsPlayers[iPlayer][STATS_DATA_6] = "";
    g_iStatsPlayers[iPlayer][STATS_DATA_7] = 0;
    g_iStatsPlayers[iPlayer][STATS_DATA_8] = 0;
    g_iStatsPlayers[iPlayer][STATS_INFLICTOR_NAME] = "";
    g_iStatsPlayers[iPlayer][STATS_DATE] = "";
}

public client_putinserver( iPlayer )
{
    g_iStatsPlayers[iPlayer][STATS_DATA_1] = 0;
    g_iStatsPlayers[iPlayer][STATS_DATA_2] = 0;
    g_iStatsPlayers[iPlayer][STATS_DATA_3] = 0;
    g_iStatsPlayers[iPlayer][STATS_DATA_4] = 0;
    g_iStatsPlayers[iPlayer][STATS_DATA_5] = 0;
    g_iStatsPlayers[iPlayer][STATS_DATA_6] = "";
    g_iStatsPlayers[iPlayer][STATS_DATA_7] = 0;
    g_iStatsPlayers[iPlayer][STATS_DATA_8] = 0;
    g_iStatsPlayers[iPlayer][STATS_INFLICTOR_NAME] = "";
    g_iStatsPlayers[iPlayer][STATS_DATE] = "";

    if(g_iSql)
    {
        new query[QUERY_LENGTH], que_len, szAuthID[35];
        get_user_authid(iPlayer, szAuthID, charsmax(szAuthID));

        que_len += formatex(query[que_len],charsmax(query) - que_len,"SELECT * FROM %s WHERE (`AUTH` = '%s')", g_szRankTable, szAuthID);
           
        new sData[EXT_DATA_STRUCT];
        sData[EXT_DATA__SQL] = SQL_LOAD;
        sData[EXT_DATA__INDEX] = iPlayer;
       
        mysql_query(g_Connection, "selectQueryHandler", query, sData, sizeof sData);
    }
}

public plugin_end()
{
    if(g_Connection != Empty_Handle)
    {
        if(g_iSql)
        {
            mysql_free(g_Connection);
            g_iSql = false;
        }
    }
}



public selectQueryHandler(failstate, err[], errNum, data[], datalen)
{
    switch(failstate)
    {
        case TQUERY_CONNECT_FAILED:  // ошибка соединения с mysql сервером
        {
            new szText[128];
            formatex(szText, charsmax(szText), "[Проблемы с БД. Код ошибки: #%d]", errNum);
            log_amx("%s", szText)
            log_amx("%s",err)
           
            return PLUGIN_HANDLED
        }
        case TQUERY_QUERY_FAILED:  // ошибка SQL запроса
        {
            new lastQue[QUERY_LENGTH]
            mysql_get_query(lastQue,charsmax(lastQue)) // узнаем последний SQL запрос

            new szText[128];
            formatex(szText, charsmax(szText), "[Проблемы с БД. Код ошибки: #%d]", errNum);
           
            log_amx("%s", szText)
            log_amx("%s",err)
            log_amx("[ SQL ] %s",lastQue)
           
            return PLUGIN_HANDLED
        }
    }
   
   
    switch(data[EXT_DATA__SQL])
    {
        case SQL_INITDB:
        {
            g_iSql = true;
            new szText[128];
            formatex(szText, charsmax(szText), "[MySql] Дополнительное хранение об игроке успешно загружено. DB delay: %.12f sec", datalen);
            log_amx(szText);
            mysql_performance(50, 50, 6);
        }
        case SQL_CHECK:
        {
            new iPlayer = data[EXT_DATA__INDEX];
            if(!is_user_connected(iPlayer)) return PLUGIN_CONTINUE

            if(mysql_num_results())
            {
                g_iStatsPlayers[iPlayer][STATS_DATA_1] = 0;
                g_iStatsPlayers[iPlayer][STATS_DATA_6] = "";
                g_iStatsPlayers[iPlayer][STATS_DATA_7] = 0;
                g_iStatsPlayers[iPlayer][STATS_DATA_8] = 0;
                g_iStatsPlayers[iPlayer][STATS_INFLICTOR_NAME] = "";
                g_iStatsPlayers[iPlayer][STATS_DATE] = "";
            }
        }
        case SQL_LOAD:
        {
            new iPlayer = data[EXT_DATA__INDEX];
            if(!is_user_connected(iPlayer)) return PLUGIN_CONTINUE

            new szAuthID[MAX_AUTHID_LENGTH];
            get_user_authid(iPlayer, szAuthID, MAX_AUTHID_LENGTH - 1);
           
            switch(mysql_num_results())
            {
                case 0:
                {
                    new query[QUERY_LENGTH], que_len
                    que_len += formatex(query[que_len],charsmax(query) - que_len, "INSERT INTO %s \
                        (\
                        AUTH, \
                        `DATA_1`,\
                        `DATA_2`,\
                        `DATA_3`,\
                        `DATA_4`,\
                        `DATA_5`,\
                        `DATA_6`,\
                        `DATA_7`,\
                        `DATA_8`,\
                        `DATA_INFLICTOR`,\
                        `DATE_BLOCK`\
                        ) \
                        \
                        VALUES (\
                        '%s', \
                        0, \
                        0,\
                        0,\
                        0,\
                        0,\
                        0,\
                        0,\
                        0,\
                        0,\
                        NOW()\
                        );", g_szRankTable, szAuthID);  
                    new sData[EXT_DATA_STRUCT];
                    sData[EXT_DATA__SQL] = SQL_IGNORE;
                    mysql_query(g_Connection, "selectQueryHandler", query, sData, sizeof sData);
                }
                default:
                {
               
                    while(mysql_more_results())
                    {
                        /*g_iStatsPlayers[iPlayer][STATS_DATA_1]     = SQL_ReadResult(queryHandle, 2)
                        g_iStatsPlayers[iPlayer][STATS_DATA_2]     = SQL_ReadResult(queryHandle, 3)
                        g_iStatsPlayers[iPlayer][STATS_DATA_3]     = SQL_ReadResult(queryHandle, 4)
                        g_iStatsPlayers[iPlayer][STATS_DATA_4]     = SQL_ReadResult(queryHandle, 5)
                        g_iStatsPlayers[iPlayer][STATS_DATA_5]     = SQL_ReadResult(queryHandle, 6)
                        SQL_ReadResult(queryHandle, 7, g_iStatsPlayers[iPlayer][STATS_DATA_6], 31)
                        g_iStatsPlayers[iPlayer][STATS_DATA_7]     = SQL_ReadResult(queryHandle, 8)
                        g_iStatsPlayers[iPlayer][STATS_DATA_8]     = SQL_ReadResult(queryHandle, 9)

                        SQL_ReadResult(queryHandle, 10, g_iStatsPlayers[iPlayer][STATS_INFLICTOR_NAME], 31)
                        SQL_ReadResult(queryHandle, 11, g_iStatsPlayers[iPlayer][STATS_DATE], 31)*/
                       
                        g_iStatsPlayers[iPlayer][STATS_DATA_1] = mysql_read_result2("DATA_1")
                        g_iStatsPlayers[iPlayer][STATS_DATA_2] = mysql_read_result2("DATA_2")
                        g_iStatsPlayers[iPlayer][STATS_DATA_3] = mysql_read_result2("DATA_3")
                        g_iStatsPlayers[iPlayer][STATS_DATA_4] = mysql_read_result2("DATA_4")
                        g_iStatsPlayers[iPlayer][STATS_DATA_5] = mysql_read_result2("DATA_5")
                        mysql_read_result2("DATA_6", g_iStatsPlayers[iPlayer][STATS_DATA_6], 31)
                        g_iStatsPlayers[iPlayer][STATS_DATA_7] = mysql_read_result2("DATA_7")
                        g_iStatsPlayers[iPlayer][STATS_DATA_8] = mysql_read_result2("DATA_8")
                        mysql_read_result2("DATA_INFLICTOR", g_iStatsPlayers[iPlayer][STATS_INFLICTOR_NAME], 31)
                        mysql_read_result2("DATE_BLOCK", g_iStatsPlayers[iPlayer][STATS_DATE], 31)


                        //server_print("Проверка - %s", g_iStatsPlayers[iPlayer][STATS_DATA_6])

                        if(g_iStatsPlayers[iPlayer][STATS_DATA_1])
                        {
                            new query[QUERY_LENGTH],que_len

                            new szAuthID[MAX_AUTHID_LENGTH];
                            get_user_authid(iPlayer, szAuthID, MAX_AUTHID_LENGTH - 1);

                            que_len += formatex(query[que_len],charsmax(query) - que_len,"SELECT * FROM %s WHERE (`AUTH` = '%s' AND (`DATA_8` + `DATA_7`) < UNIX_TIMESTAMP(NOW()) AND `DATA_7` > '0')", g_szRankTable, szAuthID);
                               
                            new sData[EXT_DATA_STRUCT];
                            sData[EXT_DATA__SQL] = SQL_CHECK;
                            sData[EXT_DATA__INDEX] = iPlayer;
                           
                            mysql_query(g_Connection, "selectQueryHandler", query, sData, sizeof sData);
                            break;
                        }

                        mysql_next_row();
                    }
                }
            }
        }
        case SQL_IGNORE: {}
    }

    return PLUGIN_HANDLED
}
21 Ноя 2019
так для общей представление
19834
 
Последнее редактирование:
Сообщения
673
Реакции
242
Помог
11 раз(а)
Код:
#include <amxmodx>
#include <sqlx>


#define        PLUGIN_NAME         "MysqL Core"
#define        PLUGIN_VERSION      "1.0"
#define        PLUGIN_AUTHOR          "DalgaPups"


const QUERY_LENGTH =    1472    // размер переменной sql запроса

enum _:STATS
{
    STATS_DATA_1,
    STATS_DATA_2,
    STATS_DATA_3,
    STATS_DATA_4,
    STATS_DATA_5,
    STATS_DATA_6[MAX_NAME_LENGTH],
    STATS_DATA_7,
    STATS_DATA_8,
    STATS_INFLICTOR_NAME[MAX_NAME_LENGTH],
    STATS_DATE[MAX_NAME_LENGTH]
};

enum _:sql_que_type    // тип sql запроса
{
    SQL_INITDB,
    SQL_INGORE,
    SQL_LOAD,
    SQL_CHECK
}

enum _:EXT_DATA_STRUCT {
    EXT_DATA__SQL,
    EXT_DATA__USERID,
    EXT_DATA__INDEX
}

new g_iStatsPlayers[MAX_PLAYERS + 1][STATS];

const SQL_CONNECTION_TIMEOUT = 10;

new bool:g_iSql = false,
    Handle:g_hDBHandle;


new g_szRankTable[32];



public plugin_init( )
{
    register_plugin
    (
        PLUGIN_NAME,
        PLUGIN_VERSION,
        PLUGIN_AUTHOR
    );

    new szPath[64], szPathFile[128];
    get_localinfo("amxx_configsdir", szPath, charsmax(szPath));
    
    formatex(szPathFile, charsmax(szPathFile), "%s/jb_engine/mysql_regs.cfg", szPath);
    if(file_exists(szPathFile))
        RegisterMysqlSystems(szPathFile);

    SqlInit();

    //cvars_init();
}

RegisterMysqlSystems(cfg[])
{
    register_cvar("jbe_mysql_sql_host", "", FCVAR_PROTECTED);
    register_cvar("jbe_mysql_sql_user", "", FCVAR_PROTECTED);
    register_cvar("jbe_mysql_sql_password", "", FCVAR_PROTECTED);
    register_cvar("jbe_mysql_sql_database",  "", FCVAR_PROTECTED);
    register_cvar("jbe_sql_prefixes_table",  "", FCVAR_PROTECTED);

    ExecCfg(cfg);
}

ExecCfg(const cfg[])
{
    server_cmd("exec %s", cfg);
    server_exec();
}


public plugin_natives()
{
    register_native("jbe_is_user_data", "jbe_is_user_data", true);
    register_native("jbe_set_user_data", "jbe_set_user_data", true);
    register_native("jbe_block_reasons", "jbe_block_reasons");
    register_native("jbe_mysql_block_date", "jbe_mysql_block_date", false);
    register_native("jbe_mysql_block_inf_name", "jbe_mysql_block_inf_name", false);
    register_native("jbe_mysql_block_time", "jbe_mysql_block_time", true);
    register_native("jbe_mysql_block_reason", "jbe_mysql_block_reason", false);
    register_native("jbe_mysql_block_start_time", "jbe_mysql_block_start_time", true);
}

public jbe_mysql_block_date(plugin_id, num_params)
{
    new id;
    id=get_param(1);
    
    return set_string(2, g_iStatsPlayers[id][STATS_DATE], get_param(3));
}

public jbe_mysql_block_inf_name(plugin_id, num_params)
{
    new id;
    id=get_param(1);
    
    return set_string(2, g_iStatsPlayers[id][STATS_INFLICTOR_NAME], get_param(3));
}

public jbe_mysql_block_reason(plugin_id, num_params)
{
    new id;
    id=get_param(1);
    
    return set_string(2, g_iStatsPlayers[id][STATS_DATA_6], get_param(3));
}

public jbe_mysql_block_time(id) return g_iStatsPlayers[id][STATS_DATA_7];
public jbe_mysql_block_start_time(id) return g_iStatsPlayers[id][STATS_DATA_8];


public jbe_block_reasons(plugins_params, num_params)
{
    new id = get_param(1);

    new szTemp[32];
    get_string(2, szTemp, charsmax(szTemp));
    
    copy(g_iStatsPlayers[id][STATS_DATA_6], 31, szTemp);
    g_iStatsPlayers[id][STATS_DATA_7] = get_param(3);

    g_iStatsPlayers[id][STATS_DATA_8] = get_param(4);

    g_iStatsPlayers[id][STATS_INFLICTOR_NAME] = get_param(5);

    new szName[MAX_NAME_LENGTH];
    get_string(5, szName, MAX_NAME_LENGTH - 1);
    copy(g_iStatsPlayers[id][STATS_INFLICTOR_NAME], MAX_NAME_LENGTH - 1, szName);

    if(g_iSql)
    {
        new query[QUERY_LENGTH],que_len
        new szAuthID[35];

        //server_print("Проверка - %s", g_iStatsPlayers[iPlayer][STATS_DATA_6])

        get_user_authid(id, szAuthID, charsmax(szAuthID));

        que_len += formatex(query[que_len],charsmax(query) - que_len,"\
        UPDATE `%s` SET \
        \
        `DATA_1` = '%i',\
        `DATA_7` = '%i',\
        `DATA_8` = '%i',\
        `DATA_INFLICTOR` = '%s',\
        `DATE_BLOCK` = NOW() \
        \
        WHERE `AUTH` = '%s'",
        g_szRankTable,     

                        g_iStatsPlayers[id][STATS_DATA_1],
                        g_iStatsPlayers[id][STATS_DATA_7],
                        g_iStatsPlayers[id][STATS_DATA_8], 
                        g_iStatsPlayers[id][STATS_INFLICTOR_NAME],   

        szAuthID);

        new sData[EXT_DATA_STRUCT];
        sData[EXT_DATA__SQL] = SQL_INGORE;
        SQL_ThreadQuery(g_hDBHandle, "selectQueryHandler", query, sData, sizeof sData);

        //server_print("%s", g_iStatsPlayers[id][STATS_DATA_6]);
    }
}
    
public jbe_is_user_data(player, iType)
{
    switch(iType)
    {
        case 1: return g_iStatsPlayers[player][STATS_DATA_1];
        case 2: return g_iStatsPlayers[player][STATS_DATA_2];
        case 3: return g_iStatsPlayers[player][STATS_DATA_3];
        case 4: return g_iStatsPlayers[player][STATS_DATA_4];
        case 5: return g_iStatsPlayers[player][STATS_DATA_5];
        case 7: return g_iStatsPlayers[player][STATS_DATA_7];
        case 8: return g_iStatsPlayers[player][STATS_DATA_8];
    }
    return PLUGIN_HANDLED;
}

public jbe_set_user_data(player, iType, iNum)
{
    switch(iType)
    {
        case 1: g_iStatsPlayers[player][STATS_DATA_1] = iNum;
        case 2: g_iStatsPlayers[player][STATS_DATA_2] = iNum;
        case 3: g_iStatsPlayers[player][STATS_DATA_3] = iNum;
        case 4: g_iStatsPlayers[player][STATS_DATA_4] = iNum;
        case 5: g_iStatsPlayers[player][STATS_DATA_5] = iNum;
    }
    return PLUGIN_HANDLED;
}

public SqlInit()
{
    new    g_szRankHost[128],
        g_szRankUser[64],
        g_szRankPassword[64],
        g_szRankDataBase[64];

    get_cvar_string("jbe_mysql_sql_host",             g_szRankHost,         charsmax(g_szRankHost));
    get_cvar_string("jbe_mysql_sql_user",             g_szRankUser,         charsmax(g_szRankUser));
    get_cvar_string("jbe_mysql_sql_password",         g_szRankPassword,    charsmax(g_szRankPassword));
    get_cvar_string("jbe_mysql_sql_database",         g_szRankDataBase,     charsmax(g_szRankDataBase));
    get_cvar_string("jbe_sql_prefixes_table",            g_szRankTable,         charsmax(g_szRankTable));


    g_hDBHandle = SQL_MakeDbTuple
    (
        g_szRankHost,
        g_szRankUser,
        g_szRankPassword,
        g_szRankDataBase,
        SQL_CONNECTION_TIMEOUT
    );

    #if AMXX_VERSION_NUM >= 183
        SQL_SetCharset(g_hDBHandle,"utf8")
    #endif
    
    new query[QUERY_LENGTH],que_len
    que_len += formatex(query[que_len],charsmax(query) - que_len,"CREATE TABLE IF NOT EXISTS `%s`\
    (\
        `id`        int(11) NOT NULL AUTO_INCREMENT,\
        `AUTH`       varchar(35) NOT NULL,\
        `DATA_1`     int(11) NOT NULL, \
        `DATA_2`     int(11) NOT NULL, \
        `DATA_3`     int(11) NOT NULL, \
        `DATA_4`     int(11) NOT NULL, \
        `DATA_5`     int(11) NOT NULL, \
        `DATA_6`       varchar(35) NOT NULL COLLATE 'utf8_general_ci',\
        `DATA_7`     int(11) NOT NULL, \
        `DATA_8`     int(11) NOT NULL, \
        `DATA_INFLICTOR`     varchar(35) NOT NULL, \
        `DATE_BLOCK` DATETIME,\
        PRIMARY KEY (id)\
    )", g_szRankTable);


    new sData[EXT_DATA_STRUCT];
    sData[EXT_DATA__SQL] = SQL_INITDB;
    SQL_ThreadQuery(g_hDBHandle, "selectQueryHandler", query, sData, sizeof sData);
}


public commonQueryHandler(queryState, Handle: queryHandle, exception[], error) {
    SQL_FreeHandle(queryHandle);
}

public client_disconnected(iPlayer)
{
    if(g_iSql)
    {
        new query[QUERY_LENGTH],que_len
        new szAuthID[35];

        //server_print("Проверка - %s", g_iStatsPlayers[iPlayer][STATS_DATA_6])

        

        get_user_authid(iPlayer, szAuthID, charsmax(szAuthID));

        que_len += formatex(query[que_len],charsmax(query) - que_len,"\
        UPDATE `%s` SET \
        `DATA_1` = '%i',\
        `DATA_2` = '%i',\
        `DATA_3` = '%i',\
        `DATA_4` = '%i',\
        `DATA_5`= '%i',\
        `DATA_6` = '%s',\
        `DATA_7`= '%i',\
        `DATA_8`= '%i',\
        `DATA_INFLICTOR` = '%s'\
        WHERE `AUTH` = '%s'", 
        g_szRankTable,     g_iStatsPlayers[iPlayer][STATS_DATA_1],
                        g_iStatsPlayers[iPlayer][STATS_DATA_2],
                        g_iStatsPlayers[iPlayer][STATS_DATA_3],
                        g_iStatsPlayers[iPlayer][STATS_DATA_4],
                        g_iStatsPlayers[iPlayer][STATS_DATA_5],
                        g_iStatsPlayers[iPlayer][STATS_DATA_6],
                        g_iStatsPlayers[iPlayer][STATS_DATA_7],
                        g_iStatsPlayers[iPlayer][STATS_DATA_8], 
                        g_iStatsPlayers[iPlayer][STATS_INFLICTOR_NAME],
                        szAuthID);
        new sData[EXT_DATA_STRUCT];
        sData[EXT_DATA__SQL] = SQL_INGORE;
        SQL_ThreadQuery(g_hDBHandle, "selectQueryHandler", query, sData, sizeof sData);
    }

    g_iStatsPlayers[iPlayer][STATS_DATA_1] = 0;
    g_iStatsPlayers[iPlayer][STATS_DATA_2] = 0;
    g_iStatsPlayers[iPlayer][STATS_DATA_3] = 0;
    g_iStatsPlayers[iPlayer][STATS_DATA_4] = 0;
    g_iStatsPlayers[iPlayer][STATS_DATA_5] = 0;
    g_iStatsPlayers[iPlayer][STATS_DATA_6] = "";
    g_iStatsPlayers[iPlayer][STATS_DATA_7] = 0;
    g_iStatsPlayers[iPlayer][STATS_DATA_8] = 0;
    g_iStatsPlayers[iPlayer][STATS_INFLICTOR_NAME] = "";
    g_iStatsPlayers[iPlayer][STATS_DATE] = "";
}

public client_putinserver( iPlayer )
{
    g_iStatsPlayers[iPlayer][STATS_DATA_1] = 0;
    g_iStatsPlayers[iPlayer][STATS_DATA_2] = 0;
    g_iStatsPlayers[iPlayer][STATS_DATA_3] = 0;
    g_iStatsPlayers[iPlayer][STATS_DATA_4] = 0;
    g_iStatsPlayers[iPlayer][STATS_DATA_5] = 0;
    g_iStatsPlayers[iPlayer][STATS_DATA_6] = "";
    g_iStatsPlayers[iPlayer][STATS_DATA_7] = 0;
    g_iStatsPlayers[iPlayer][STATS_DATA_8] = 0;
    g_iStatsPlayers[iPlayer][STATS_INFLICTOR_NAME] = "";
    g_iStatsPlayers[iPlayer][STATS_DATE] = "";

    if(g_iSql)
    {
        new query[QUERY_LENGTH], que_len, szAuthID[35];
        get_user_authid(iPlayer, szAuthID, charsmax(szAuthID));

        que_len += formatex(query[que_len],charsmax(query) - que_len,"SELECT * FROM %s WHERE (`AUTH` = '%s')", g_szRankTable, szAuthID);
            
        new sData[EXT_DATA_STRUCT];
        sData[EXT_DATA__SQL] = SQL_LOAD;
        sData[EXT_DATA__INDEX] = iPlayer;
        
        SQL_ThreadQuery(g_hDBHandle, "selectQueryHandler", query, sData, sizeof sData);
    }
}
 
public plugin_end()
{
    if(g_hDBHandle != Empty_Handle)
    {
        if(g_iSql)
        {
            SQL_FreeHandle(g_hDBHandle);
            g_iSql = false;
        }
    }
}



public selectQueryHandler(failstate, Handle: queryHandle, err[], errNum, data[], datalen)
{
    switch(failstate)
    {
        case TQUERY_CONNECT_FAILED:  // ошибка соединения с mysql сервером
        {
            new szText[128];
            formatex(szText, charsmax(szText), "[Проблемы с БД. Код ошибки: #%d]", errNum);
            log_amx("%s", szText)
            log_amx("%s",err)
            
            return PLUGIN_HANDLED
        }
        case TQUERY_QUERY_FAILED:  // ошибка SQL запроса
        {
            new lastQue[QUERY_LENGTH]
            SQL_GetQueryString(queryHandle,lastQue,charsmax(lastQue)) // узнаем последний SQL запрос

            new szText[128];
            formatex(szText, charsmax(szText), "[Проблемы с БД. Код ошибки: #%d]", errNum);
            
            log_amx("%s", szText)
            log_amx("%s",err)
            log_amx("[ SQL ] %s",lastQue)
            
            return PLUGIN_HANDLED
        }
    }
    
    
    switch(data[EXT_DATA__SQL])
    {
        case SQL_INITDB:
        {
            g_iSql = true;
            new szText[128];
            formatex(szText, charsmax(szText), "[MySql] Дополнительное хранение об игроке успешно загружено. DB delay: %.12f sec", datalen);
            log_amx(szText);
        }
        case SQL_CHECK:
        {
            new iPlayer = data[EXT_DATA__INDEX];
            if(!is_user_connected(iPlayer)) return PLUGIN_CONTINUE

            if(SQL_NumResults(queryHandle))
            {
                g_iStatsPlayers[iPlayer][STATS_DATA_1] = 0;
                g_iStatsPlayers[iPlayer][STATS_DATA_6] = "";
                g_iStatsPlayers[iPlayer][STATS_DATA_7] = 0;
                g_iStatsPlayers[iPlayer][STATS_DATA_8] = 0;
                g_iStatsPlayers[iPlayer][STATS_INFLICTOR_NAME] = "";
                g_iStatsPlayers[iPlayer][STATS_DATE] = "";
            }
        }
        case SQL_LOAD:
        {
            new iPlayer = data[EXT_DATA__INDEX];
            if(!is_user_connected(iPlayer)) return PLUGIN_CONTINUE

            new szAuthID[MAX_AUTHID_LENGTH];
            get_user_authid(iPlayer, szAuthID, MAX_AUTHID_LENGTH - 1);
            switch(SQL_NumResults(queryHandle))
            {
                case 0:
                {
                    new query[QUERY_LENGTH], que_len
                    que_len += formatex(query[que_len],charsmax(query) - que_len, "INSERT INTO %s \
                        (\
                        AUTH, \
                        `DATA_1`,\
                        `DATA_2`,\
                        `DATA_3`,\
                        `DATA_4`,\
                        `DATA_5`,\
                        `DATA_6`,\
                        `DATA_7`,\
                        `DATA_8`,\
                        `DATA_INFLICTOR`,\
                        `DATE_BLOCK`\
                        ) \
                        \
                        VALUES (\
                        '%s', \
                        0, \
                        0,\
                        0,\
                        0,\
                        0,\
                        0,\
                        0,\
                        0,\
                        0,\
                        NOW()\
                        );", g_szRankTable, szAuthID);   
                    new sData[EXT_DATA_STRUCT];
                    sData[EXT_DATA__SQL] = SQL_INGORE;
                    SQL_ThreadQuery(g_hDBHandle, "selectQueryHandler", query, sData, sizeof sData);
                }
                default:
                {
                    g_iStatsPlayers[iPlayer][STATS_DATA_1]     = SQL_ReadResult(queryHandle, 2)
                    g_iStatsPlayers[iPlayer][STATS_DATA_2]     = SQL_ReadResult(queryHandle, 3)
                    g_iStatsPlayers[iPlayer][STATS_DATA_3]     = SQL_ReadResult(queryHandle, 4)
                    g_iStatsPlayers[iPlayer][STATS_DATA_4]     = SQL_ReadResult(queryHandle, 5)
                    g_iStatsPlayers[iPlayer][STATS_DATA_5]     = SQL_ReadResult(queryHandle, 6)
                    SQL_ReadResult(queryHandle, 7, g_iStatsPlayers[iPlayer][STATS_DATA_6], 31)
                    g_iStatsPlayers[iPlayer][STATS_DATA_7]     = SQL_ReadResult(queryHandle, 8)
                    g_iStatsPlayers[iPlayer][STATS_DATA_8]     = SQL_ReadResult(queryHandle, 9)

                    SQL_ReadResult(queryHandle, 10, g_iStatsPlayers[iPlayer][STATS_INFLICTOR_NAME], 31)
                    SQL_ReadResult(queryHandle, 11, g_iStatsPlayers[iPlayer][STATS_DATE], 31)


                    //server_print("Проверка - %s", g_iStatsPlayers[iPlayer][STATS_DATA_6])

                    if(g_iStatsPlayers[iPlayer][STATS_DATA_1])
                    {
                        new query[QUERY_LENGTH],que_len

                        new szAuthID[MAX_AUTHID_LENGTH];
                        get_user_authid(iPlayer, szAuthID, MAX_AUTHID_LENGTH - 1);

                        que_len += formatex(query[que_len],charsmax(query) - que_len,"SELECT * FROM %s WHERE (`AUTH` = '%s' AND (`DATA_8` + `DATA_7`) < UNIX_TIMESTAMP(NOW()) AND `DATA_7` > '0')", g_szRankTable, szAuthID);
                            
                        new sData[EXT_DATA_STRUCT];
                        sData[EXT_DATA__SQL] = SQL_CHECK;
                        sData[EXT_DATA__INDEX] = iPlayer;
                        
                        SQL_ThreadQuery(g_hDBHandle, "selectQueryHandler", query, sData, sizeof sData);
                    }

                    SQL_NextRow(queryHandle);
                }
            }
        }
        case SQL_INGORE: {}
    }

    return PLUGIN_HANDLED
}
21 Ноя 2019
Делал дебаг, отключал
SqlInit();
Обработка не шла, и карта не падала, все же падает когда уже соединен, и подгружено инфы об игроке
 
Сообщения
432
Реакции
410
Помог
14 раз(а)
Грешу на обработку plugin_end() так он срабатывает после смены карт, но вроде я сделал все правильно, закрыл соеденение
Модуль сам закрывает соединения, можно не заморачиваться.
 
Сообщения
673
Реакции
242
Помог
11 раз(а)
voed, действительно, краши прекратилась, благадарю... а есть инфа что соеденение действительно закрылась и она не висит в памяти?исходник модуля есть, но я не могу понять сошку))
 
Последнее редактирование:

Пользователи, просматривающие эту тему

Сейчас на форуме нет ни одного пользователя.
Сверху Снизу