Raised This Month: $ Target: $400
 0% 

SQL Error


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 08-29-2009 , 08:36   SQL Error
Reply With Quote #1

Error log:
Quote:
[AMXX] SQL error: can't connect: 'Access denied for user 'dsa'@'78-56-65-107.static.zebra.lt' (using password: YES)'
PHP Code:
#define USING_SQL

#include <amxmodx> 
#include <amxmisc>
#if defined USING_SQL
#include <sqlx>
#endif

//new Vector:AdminList;

new AdminCount;

#define ADMIN_LOOKUP    (1<<0)
#define ADMIN_NORMAL    (1<<1)
#define ADMIN_STEAM        (1<<2)
#define ADMIN_IPADDR    (1<<3)
#define ADMIN_NAME        (1<<4)

new g_cmdLoopback[16]


// pcvars
new amx_mode;
new 
amx_password_field;
new 
amx_default_access;

public 
plugin_init()
{
#if defined USING_SQL
    
register_plugin("Reg systema by aha"AMXX_VERSION_STR"aha")
#else
    
register_plugin("Reg systema by aha"AMXX_VERSION_STR"aha")
#endif
    
register_dictionary("admin.txt")
    
register_dictionary("common.txt")
    
amx_mode=register_cvar("amx_mode""1")
    
amx_password_field=register_cvar("amx_password_field""_pw")
    
amx_default_access=register_cvar("amx_default_access""")

    
register_cvar("amx_vote_ratio""0.02")
    
register_cvar("amx_vote_time""10")
    
register_cvar("amx_vote_answers""1")
    
register_cvar("amx_vote_delay""60")
    
register_cvar("amx_last_voting""0")
    
register_cvar("amx_show_activity""2")
    
register_cvar("amx_votekick_ratio""0.40")
    
register_cvar("amx_voteban_ratio""0.40")
    
register_cvar("amx_votemap_ratio""0.40")

    
set_cvar_float("amx_last_voting"0.0)

#if defined USING_SQL
    
register_srvcmd("amx_sqladmins""adminSql")
    
register_cvar("amx_sms_table""clientai")
#endif
    
register_cvar("amx_sql_host""mysql.dsa.bendras.com")
    
register_cvar("amx_sql_user""dsa")
    
register_cvar("amx_sql_pass""xxx")
    
register_cvar("amx_sql_db""dsa")
    
register_cvar("amx_sql_type""mysql")

    
register_concmd("amx_reloadadmins""cmdReload"ADMIN_CFG)

    
format(g_cmdLoopback15"amxauth%c%c%c%c"random_num('A''Z'), random_num('A''Z'), random_num('A''Z'), random_num('A''Z'))

    
register_clcmd(g_cmdLoopback"ackSignal")

    
remove_user_flags(0read_flags("z"))        // Remove 'user' flag from server rights

    
new configsDir[64]
    
get_configsdir(configsDir63)
    
    
server_cmd("exec %s/amxx.cfg"configsDir)    // Execute main configuration file


    
#if defined USING_SQL
    
server_cmd("amx_sqladmins")
#else
    
format(configsDir63"%s/users.ini"configsDir)
    
loadSettings(configsDir)                    // Load admins accounts
#endif
}

public 
plugin_cfg()
{
    
set_task(6.1"delayed_load")
}

public 
delayed_load()
{
    new 
configFile[128], curMap[64], configDir[128]

    
get_configsdir(configDirsizeof(configDir)-1)
    
get_mapname(curMapsizeof(curMap)-1)

    new 
i=0;
    
    while (
curMap[i] != '_' && curMap[i++] != '^0') {/*do nothing*/}
    
    if (
curMap[i]=='_')
    {
        
// this map has a prefix
        
curMap[i]='^0';
        
formatex(configFilesizeof(configFile)-1"%s/maps/prefix_%s.cfg"configDircurMap);

        if (
file_exists(configFile))
        {
            
server_cmd("exec %s"configFile);
        }
    }

    
get_mapname(curMapsizeof(curMap)-1)

    
    
formatex(configFilesizeof(configFile)-1"%s/maps/%s.cfg"configDircurMap)

    if (
file_exists(configFile))
    {
        
server_cmd("exec %s"configFile)
    }
    
}

loadSettings(szFilename[])
{
    new 
File=fopen(szFilename,"r");
    
    if (
File)
    {
        new 
Text[512];
        new 
Flags[32];
        new 
Access[32]
        new 
AuthData[44];
        new 
Password[32];
        
        while (!
feof(File))
        {
            
fgets(File,Text,sizeof(Text)-1);
            
            
trim(Text);
            
            
// comment
            
if (Text[0]==';'
            {
                continue;
            }
            
            
Flags[0]=0;
            
Access[0]=0;
            
AuthData[0]=0;
            
Password[0]=0;
            
            
// not enough parameters
            
if (parse(Text,AuthData,sizeof(AuthData)-1,Password,sizeof(Password)-1,Access,sizeof(Access)-1,Flags,sizeof(Flags)-1) < 2)
            {
                continue;
            }
            
            
admins_push(AuthData,Password,read_flags(Access),read_flags(Flags));

            
AdminCount++;
        }
        
        
fclose(File);
    }

    if (
AdminCount == 1)
    {
        
server_print("[AMXX] %L"LANG_SERVER"LOADED_ADMIN");
    }
    else
    {
        
server_print("[AMXX] %L"LANG_SERVER"LOADED_ADMINS"AdminCount);
    }
    
    return 
1;
}

#if defined USING_SQL
public adminSql()
{
    new 
table[32], error[128], type[12], errno
    
        
new Handle:info SQL_MakeDbTuple("mysql.dsa.bendras.com","dsa","xxxx","dsa")  // regsistema 
    
new Handle:sql SQL_Connect(infoerrnoerror127)
    
    
get_cvar_string("amx_sms_table"table31)
    
    
SQL_GetAffinity(type11)
    
    if (
sql == Empty_Handle)
    {
        
server_print("[AMXX] %L"LANG_SERVER"SQL_CANT_CON"error)
        
        
//backup to users.ini
        
new configsDir[64]
        
        
get_configsdir(configsDir63)
        
format(configsDir63"%s/users.ini"configsDir)
        
loadSettings(configsDir// Load admins accounts

        
return PLUGIN_HANDLED
    
}

    new 
Handle:query
    
    
if (equali(type"sqlite"))
    {
        if (!
sqlite_TableExists(sqltable))
        {
            
//SQL_QueryAndIgnore(sql, "CREATE TABLE %s ( auth TEXT NOT NULL DEFAULT '', password TEXT NOT NULL DEFAULT '', access TEXT NOT NULL DEFAULT '', flags TEXT NOT NULL DEFAULT '' )", table)
        
}

        
query SQL_PrepareQuery(sql"SELECT name, pass, access, flags FROM %s"table)
    } else {
        
//SQL_QueryAndIgnore(sql, "CREATE TABLE IF NOT EXISTS `%s` ( `auth` VARCHAR( 32 ) NOT NULL, `password` VARCHAR( 32 ) NOT NULL, `access` VARCHAR( 32 ) NOT NULL, `flags` VARCHAR( 32 ) NOT NULL ) COMMENT = 'AMX Mod X Admins'", table)
        
query SQL_PrepareQuery(sql,"SELECT `name`,`pass`,`access`,`flags` FROM `%s`"table)
    }

    if (!
SQL_Execute(query))
    {
        
SQL_QueryError(queryerror127)
        
server_print("[AMXX] %L"LANG_SERVER"SQL_CANT_LOAD_ADMINS"error)
    } else if (!
SQL_NumResults(query)) {
        
server_print("[AMXX] %L"LANG_SERVER"NO_ADMINS")
    } else {
        
        
AdminCount 0
        
        
/** do this incase people change the query order and forget to modify below */
        
new qcolAuth SQL_FieldNameToNum(query"name")
        new 
qcolPass SQL_FieldNameToNum(query"pass")
        new 
qcolAccess SQL_FieldNameToNum(query"access")
        new 
qcolFlags SQL_FieldNameToNum(query"flags")
        
        new 
AuthData[44];
        new 
Password[44];
        new 
Access[32];
        new 
Flags[32];
        
        while (
SQL_MoreResults(query))
        {
            
SQL_ReadResult(queryqcolAuthAuthDatasizeof(AuthData)-1);
            
SQL_ReadResult(queryqcolPassPasswordsizeof(Password)-1);
            
SQL_ReadResult(queryqcolAccessAccesssizeof(Access)-1);
            
SQL_ReadResult(queryqcolFlagsFlagssizeof(Flags)-1);
    
            
admins_push(AuthData,Password,read_flags(Access),read_flags(Flags));
    
            ++
AdminCount;
            
SQL_NextRow(query)
        }
    
        if (
AdminCount == 1)
        {
            
server_print("[AMXX] %L"LANG_SERVER"SQL_LOADED_ADMIN")
        }
        else
        {
            
server_print("[AMXX] %L"LANG_SERVER"SQL_LOADED_ADMINS"AdminCount)
        }
        
        
SQL_FreeHandle(query)
        
SQL_FreeHandle(sql)
        
SQL_FreeHandle(info)
    }
    
    return 
PLUGIN_HANDLED
}
#endif

public cmdReload(idlevelcid)
{
    if (!
cmd_access(idlevelcid1))
        return 
PLUGIN_HANDLED

    
//strip original flags (patch submitted by mrhunt)
    
remove_user_flags(0read_flags("z"))
    
    
admins_flush();

#if !defined USING_SQL
    
new filename[128]
    
    
get_configsdir(filename127)
    
format(filename63"%s/users.ini"filename)

    
AdminCount 0;
    
loadSettings(filename);        // Re-Load admins accounts

    
if (id != 0)
    {
        if (
AdminCount == 1)
        {
            
console_print(id"[AMXX] %L"LANG_SERVER"LOADED_ADMIN");
        }
        else
        {
            
console_print(id"[AMXX] %L"LANG_SERVER"LOADED_ADMINS"AdminCount);
        }
    }
#else
    
AdminCount 0
    adminSql
()

    if (
id != 0)
    {
        if (
AdminCount == 1)
            
console_print(id"[AMXX] %L"LANG_SERVER"SQL_LOADED_ADMIN")
        else
            
console_print(id"[AMXX] %L"LANG_SERVER"SQL_LOADED_ADMINS"AdminCount)
    }
#endif

    
new players[32], numpv
    
new name[32]
    
get_players(playersnum)
    for (new 
i=0i<numi++)
    {
        
pv players[i]
        
get_user_name(pvname31)
        
accessUser(pvname)
    }

    return 
PLUGIN_HANDLED
}

getAccess(idname[], authid[], ip[], password[])
{
    new 
index = -1
    
new result 0
    
    
static Count;
    static 
Flags;
    static 
Access;
    static 
AuthData[44];
    static 
Password[32];
    
    
Count=admins_num();
    for (new 
0Count; ++i)
    {
        
Flags=admins_lookup(i,AdminProp_Flags);
        
admins_lookup(i,AdminProp_Auth,AuthData,sizeof(AuthData)-1);
        
        if (
Flags FLAG_AUTHID)
        {
            if (
equal(authidAuthData))
            {
                
index i
                
break
            }
        }
        else if (
Flags FLAG_IP)
        {
            new 
strlen(AuthData)
            
            if (
AuthData[1] == '.')        /* check if this is not a xxx.xxx. format */
            
{
                if (
equal(AuthDataipc))
                {
                    
index i
                    
break
                }
            }                                    
/* in other case an IP must just match */
            
else if (equal(ipAuthData))
            {
                
index i
                
break
            }
        } 
        else 
        {
            if (
Flags FLAG_TAG)
            {
                if (
containi(nameAuthData) != -1)
                {
                    
index i
                    
break
                }
            }
            else if (
equali(nameAuthData))
            {
                
index i
                
break
            }
        }
    }

    if (
index != -1)
    {
        
Access=admins_lookup(index,AdminProp_Access);

        if (
Flags FLAG_NOPASS)
        {
            
result |= 8
            
new sflags[32]
            
            
get_flags(Accesssflags31)
            
set_user_flags(idAccess)
            
            
log_amx("Login: ^"%s<%d><%s><>^" became an admin (account ^"%s^") (access ^"%s^") (address ^"%s^")"nameget_user_userid(id), authidAuthDatasflagsip)
        }
        else 
        {
        
            
admins_lookup(index,AdminProp_Password,Password,sizeof(Password)-1);

            if (
equal(passwordPassword))
            {
                
result |= 12
                set_user_flags
(idAccess)
                
                new 
sflags[32]
                
get_flags(Accesssflags31)
                
                
log_amx("Login: ^"%s<%d><%s><>^" became an admin (account ^"%s^") (access ^"%s^") (address ^"%s^")"nameget_user_userid(id), authidAuthDatasflagsip)
            } 
            else 
            {
                
result |= 1
                
                
if (Flags FLAG_KICK)
                {
                    
result |= 2
                    log_amx
("Login: ^"%s<%d><%s><>^" kicked due to invalid password (account ^"%s^") (address ^"%s^")"nameget_user_userid(id), authidAuthDataip)
                }
            }
        }
    }
    else if (
get_pcvar_float(amx_mode) == 2.0)
    {
        
result |= 2
    

    else 
    {
        new 
defaccess[32]
        
        
get_pcvar_string(amx_default_accessdefaccess31)
        
        if (!
strlen(defaccess))
        {
            
copy(defaccess32"z")
        }
        
        new 
idefaccess read_flags(defaccess)
        
        if (
idefaccess)
        {
            
result |= 8
            set_user_flags
(ididefaccess)
        }
    }
    
    return 
result
}

accessUser(idname[] = "")
{
    
remove_user_flags(id)
    
    new 
userip[32], userauthid[32], password[32], passfield[32], username[32]
    
    
get_user_ip(iduserip311)
    
get_user_authid(iduserauthid31)
    
    if (
name[0])
    {
        
copy(username31name)
    }
    else
    {
        
get_user_name(idusername31)
    }
    
    
get_pcvar_string(amx_password_fieldpassfield31)
    
get_user_info(idpassfieldpassword31)
    
    new 
result getAccess(idusernameuserauthiduserippassword)
    
    if (
result 1)
    {
        
client_cmd(id"echo ^"* %L^""id"INV_PAS")
    }
    
    if (
result 2)
    {
        
client_cmd(id"%s"g_cmdLoopback)
        return 
PLUGIN_HANDLED
    
}
    
    if (
result 4)
    {
        
client_cmd(id"echo ^"* %L^""id"PAS_ACC")
    }
    
    if (
result 8)
    {
        
client_cmd(id"echo ^"* %L^""id"PRIV_SET")
    }
    
    return 
PLUGIN_CONTINUE
}

public 
client_infochanged(id)
{
    if (!
is_user_connected(id) || !get_pcvar_num(amx_mode))
    {
        return 
PLUGIN_CONTINUE
    
}

    new 
newname[32], oldname[32]
    
    
get_user_name(idoldname31)
    
get_user_info(id"name"newname31)

    if (!
equali(newnameoldname))
    {
        
accessUser(idnewname)
    }

    return 
PLUGIN_CONTINUE
}

public 
ackSignal(id)
{
    
server_cmd("kick #%d ^"%L^""get_user_userid(id), id"NO_ENTRY")
    return 
PLUGIN_HANDLED
}

public 
client_putinserver(id)
  return 
get_pcvar_num(amx_mode) ? accessUser(id) : PLUGIN_CONTINUE 
Quote:
xxx
- is a mine password of mysql db, hidden but in real it's correct
Attached Files
File Type: sma Get Plugin or Get Source (admin_sql.sma - 659 views - 11.5 KB)
__________________

Last edited by xbatista; 08-29-2009 at 08:42.
xbatista is offline
Send a message via Skype™ to xbatista
 


Thread Tools
Display Modes

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 15:14.


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