/* Script generated by Pawn Studio */
#include <amxmodx>
#include <amxmisc>
#include <mysqlt>
#include <fakemeta>
#define PLUGIN "xd"
#define AUTHOR "Hypnotize"
#define VERSION "1.0"
new const HOST[] = "";
new const USUARIO[] = "k1s";
new const PASSWORD[] = "";
new const DB[] = "test_pin";
new const szTableP[] = "mysql_admins";
new Handle:g_isTuple, Handle:g_Connection;
new g_password[ 33 ][ 32 ];
new iNombre[ 33 ][ 32 ];
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
// Add your own code here
MySQL_Init( );
register_forward(FM_ClientUserInfoChanged, "ClientUserInfoChanged")
remove_user_flags(0, read_flags("z"))
register_concmd("amx_admins", "adminSql");
server_cmd("amx_admins");
}
public client_putinserver( id )
{
get_user_name( id, iNombre[ id ], charsmax( iNombre ) );
new Query[ 300 ], iData[ 2 ];
iData[ 0 ] = id;
iData[ 1 ] = 1;
formatex( Query , charsmax( Query ) , "SELECT fecha FROM %s WHERE authid = ^"%s^"", szTableP, iNombre[ id ] );
mysql_query(g_Connection, "fnCargar", Query, iData, 2 );
}
public ClientUserInfoChanged(id)
{
static const name[] = "name"
static szOldName[32], szNewName[32]
pev(id, pev_netname, szOldName, charsmax(szOldName))
if( szOldName[0] )
{
get_user_info(id, name, szNewName, charsmax(szNewName))
if( !equal(szOldName, szNewName) )
{
set_user_info(id, name, szOldName)
return FMRES_HANDLED
}
}
return FMRES_IGNORED
}
public adminSql( )
{
new Query[ 300 ];
formatex( Query , charsmax( Query ) , "SELECT authid, password, access, flags FROM %s", szTableP );
mysql_query(g_Connection, "fnAdmins", Query );
}
public MySQL_Init( )
{
g_isTuple = mysql_makehost(HOST, USUARIO, PASSWORD, DB);
new error[ 32 ], errnum;
g_Connection = mysql_connect(g_isTuple, errnum, error, 31);
if(errnum)
{
log_to_file("mysqlt.log", "ERROR1: [%d]- [%s]", errnum, error)
return pause( "a" );
}
new szTable[ 1000 ], len = 0;
len += format(szTable[len], charsmax(szTable) - len, "CREATE TABLE IF NOT EXISTS %s", szTableP);
len += format(szTable[len], charsmax(szTable) - len, "( id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,");
len += format(szTable[len], charsmax(szTable) - len, "authid varchar(110) NOT NULL UNIQUE,");
len += format(szTable[len], charsmax(szTable) - len, "password varchar(110) NOT NULL,");
len += format(szTable[len], charsmax(szTable) - len, "access varchar(50) NOT NULL,");
len += format(szTable[len], charsmax(szTable) - len, "flags varchar(10) NOT NULL,");
len += format(szTable[len], charsmax(szTable) - len, "fecha varchar(50) )");
mysql_query(g_Connection, "QueryCreateTable", szTable);
return PLUGIN_CONTINUE;
}
public QueryCreateTable(failstate, error[], error2, data[], size, Float:queuetime)
{
switch ( failstate )
{
case TQUERY_CONNECT_FAILED: log_to_file("SQL_LOG_TQ.txt", "Failed to connect to database [%i]: %s", error2, error)
case TQUERY_QUERY_FAILED: log_to_file("SQL_LOG_TQ.txt", "Error on query for creating table [%i]: %s", error2, error)
}
return PLUGIN_HANDLED;
}
public fnCargar(failstate, error[], error2, data[], size, Float:queuetime)
{
static id; id = data[ 0 ];
if( !is_user_connected( id ) ) return;
switch( failstate ) {
case TQUERY_CONNECT_FAILED: {
log_to_file( "SQL_LOG_TQ.txt", "Error en la conexion al MySQL [%i]: %s", error2, error );
return;
}
case TQUERY_QUERY_FAILED:
log_to_file( "SQL_LOG_TQ.txt", "Error en la consulta al MySQL [%i]: %s", error2, error );
}
switch( data[ 1 ] )
{
case 1:
{
if( mysql_num_results( ) )
{
new szDate[60];
mysql_read_result(0, szDate, sizeof(szDate));
replace_all(szDate, charsmax(szDate), "/", " ");
new Dia[100]; get_time("%d/%m/%Y", Dia, charsmax(Dia))
new szDay[10], szMonth[10], szYear[10];
parse(szDate, szDay, charsmax(szDay), szMonth, charsmax(szMonth), szYear, charsmax(szYear));
new szDay2[10], szMonth2[10], szYear2[10];
replace_all(Dia, charsmax(Dia), "/", " ");
parse(Dia, szDay2, charsmax(szDay2), szMonth2, charsmax(szMonth2), szYear2, charsmax(szYear2));
if( str_to_num(szDay2) >= str_to_num(szDay) && str_to_num(szMonth2) >= str_to_num(szMonth) && str_to_num(szYear2) >= str_to_num(szYear) )
{
new Query[ 300 ];
formatex( Query , charsmax( Query ) , "DELETE FROM %s WHERE authid = ^"%s^"", szTableP, iNombre[ id ] );
mysql_query(g_Connection, "fnCargarAdmin", Query );
}
else
{
adminSql( );
}
}
}
}
}
public fnCargarAdmin(failstate, error[], errnum, data[], size, Float:queuetime)
{
if(failstate != TQUERY_SUCCESS)
{
log_to_file("mysqlt.log", "ERROR1: [%d]- [%s]", errnum, error)
return PLUGIN_HANDLED;
}
if( mysql_affected_rows() )
{
adminSql( );
}
return PLUGIN_CONTINUE;
}
public fnAdmins(failstate, error[], errnum, data[], size, Float:queuetime)
{
if(failstate != TQUERY_SUCCESS)
{
log_to_file("mysqlt.log", "ERROR2: [%d]- [%s]", errnum, error)
return PLUGIN_HANDLED;
}
static id;
id = data[0];
if(!mysql_num_results())
{
remove_user_flags(id);
return PLUGIN_HANDLED;
}
if( mysql_num_results( ) )
{
new Authid[33], Password[33], Access[33], Flags[33];
while( mysql_more_results( ) )
{
mysql_read_result(0, Authid, sizeof(Authid));
mysql_read_result(1, Password, sizeof(Password));
mysql_read_result(2, Access, sizeof(Access));
mysql_read_result(3, Flags, sizeof(Flags));
admins_push(Authid, Password, read_flags(Access), read_flags(Flags));
mysql_next_row();
}
}
users_access();
return PLUGIN_CONTINUE;
}
stock users_access(){
new players[32];
new iNum;
get_players(players, iNum);
for(--iNum; iNum >= 0; iNum--){
SetFlags(players[iNum]);
}
}
stock SetFlags(id, name[] = ""){
remove_user_flags(id);
new szName[32];
get_user_info(id, "_pw", g_password[id], sizeof(g_password[]));
if(name[0])
copy(szName, sizeof(szName), name);
else
get_user_name(id, szName, 31);
new result = lookup_access(id, szName, g_password[id])
if(result & 1)
{
server_cmd("kick #%d ^"Ingresa la setinfo de tu administrador^"", get_user_userid(id));
return PLUGIN_HANDLED;
}
if(result & 2){
server_cmd("kick #%d ^"Ingresa la setinfo de tu administrador^"", get_user_userid(id));
return PLUGIN_HANDLED;
}
if(result & 4)
client_cmd(id, "echo ^"*Password validated!^"");
if(result & 8)
client_cmd(id, "echo ^"* Privilegios establecidos!^"");
return PLUGIN_CONTINUE;
}
stock lookup_access(id, username[], password[]) {
new index = -1, result = 0;
new i, adminname[32], adminpassword[32], count = admins_num()-1;
for(i = count; i >= 0; i--) {
admins_lookup(i, AdminProp_Auth, adminname, charsmax(adminname));
if(equali(username, adminname)) {
index = i;
break;
}
}
if(index != -1) {
new access = admins_lookup(index, AdminProp_Access), ip[32], steamid[32];
admins_lookup(index, AdminProp_Password, adminpassword, charsmax(adminpassword));
get_user_ip(id, ip, charsmax(ip), 1);
get_user_authid(id, steamid, charsmax(steamid));
if(equal(password, adminpassword)) {
result |= 12;
set_user_flags(id, access);
new sflags[32];
get_flags(access, sflags, charsmax(sflags));
log_amx("[AMXX] Login: ^"%s<%d><%s><>^" became an admin (access ^"%s^") (address ^"%s^")", username, get_user_userid(id), steamid, sflags, ip);
}
else {
result |= 1;
if(admins_lookup(index, AdminProp_Flags) & FLAG_KICK) {
result |= 2;
log_amx("[AMXX] Login: ^"%s<%d><%s><>^" kicked due to invalid password (address ^"%s^")", username, get_user_userid(id), steamid, ip);
}
}
}
else {
new access = read_flags("z");
if(access) {
result |= 8;
set_user_flags(id, access);
}
}
return result;
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang3082\\ f0\\ fs16 \n\\ par }
*/