Raised This Month: $51 Target: $400
 12% 

[ANY] Threaded Mysql Bans


Post New Thread Reply   
 
Thread Tools Display Modes
benjibau
Veteran Member
Join Date: Jul 2009
Location: France (Nord 59)
Old 03-16-2013 , 20:27   Re: [ANY] Threaded Mysql Bans
Reply With Quote #71

I trying to add server name on the database but i have multiple error.
Code:
L 03/17/2013 - 01:04:51: [SM] Native "SQL_EscapeString" reported: Invalid database Handle 0 (error: 4)
L 03/17/2013 - 01:04:51: [SM] Displaying call stack trace for plugin "mysqlt_bans.smx":
L 03/17/2013 - 01:04:51: [SM]   [0]  Line 110, /home/groups/sourcemod/upload_tmp/phpobX9ps.sp::OnClientPostAdminCheck()
L 03/17/2013 - 01:05:43: [SM] Native "SQL_EscapeString" reported: Invalid database Handle 0 (error: 4)
L 03/17/2013 - 01:05:43: [SM] Displaying call stack trace for plugin "mysqlt_bans.smx":
L 03/17/2013 - 01:05:43: [SM]   [0]  Line 129, /home/groups/sourcemod/upload_tmp/phpobX9ps.sp::OnBanClient()
L 03/17/2013 - 01:20:43: [SM] Native "SQL_EscapeString" reported: Invalid database Handle 0 (error: 4)
L 03/17/2013 - 01:20:43: [SM] Displaying call stack trace for plugin "mysqlt_bans.smx":
L 03/17/2013 - 01:20:43: [SM]   [0]  Line 150, /home/groups/sourcemod/upload_tmp/phpAx5aDo.sp::OnRemoveBan()
The code:
PHP Code:
#include <sourcemod>
#include <sdktools>
#define PLUGIN_VERSION "1.3"

public Plugin:myinfo = {
    
name "[ANY] MySQL-T Bans",
    
author "senseless",
    
description "Threaded steam id based mysql bans",
    
version PLUGIN_VERSION,
    
url "https://forums.alliedmods.net/showthread.php?p=1759904"
};

new 
Handle:hDatabase INVALID_HANDLE;

public 
OnPluginStart() {
    
VerifyTable();
    
StartSQL();
    
CreateConVar("sm_mybans_version"PLUGIN_VERSION"MYSQL-T Bans Version"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY)
}

StartSQL() {
    
SQL_TConnect(GotDatabase);
}
 
public 
GotDatabase(Handle:ownerHandle:hndl, const String:error[], any:data) {
    if (
hndl == INVALID_HANDLE) {
        
LogError("[MYBans] Database Connection Error: %s"error);
    } else {
        
hDatabase hndl;
    }
}

public 
T_AuthCheck(Handle:ownerHandle:hndl, const String:error[], any:data) {
    new 
client;
     
decl ban_length;    
    
decl String:steam_id[32];
     
decl String:ban_reason[100];
     
decl ban_remaining;
    
decl String:query[255];
        
    if ((
client GetClientOfUserId(data)) == 0) {
        return;
    }

    
GetClientAuthString(clientsteam_idsizeof(steam_id));

    new 
buffer_len strlen(steam_id) * 1
    
new String:v_steam_id[buffer_len]
    
SQL_EscapeString(hDatabasesteam_idv_steam_idbuffer_len)
 
    if (
hndl == INVALID_HANDLE) {
        
LogError("[MYBans] Query failed! %s"error);
        
KickClient(client"Error: Reattempt connection");
    }

    if(
SQL_FetchRow(hndl)) {
        
ban_length SQL_FetchInt(hndl,0);
        
SQL_FetchString(hndl,1,ban_reason,sizeof(ban_reason));
        if (
ban_length == 0) {
                
KickClient(client,"You have been Banned for %s"ban_reason);
                return;
        }
        
ban_remaining SQL_FetchInt(hndl,2);
        if (
ban_remaining <= ban_length) {
            
KickClient(client,"You have been Banned for %s"ban_reason);
        } else {
            
Format(querysizeof(query), "DELETE FROM my_bans WHERE steam_id='%s'"v_steam_id);
            
SQL_TQuery(hDatabaseT_MYUnBanquery);
            
LogMessage("[MYBans] User %s has been unbanned by elapse of time."v_steam_id);
        }
    }
}

public 
T_MYBan(Handle:ownerHandle:hndl, const String:error[], any:data) {
    if (
hndl == INVALID_HANDLE) {
        
LogError("[MYBans] Query failed! %s"error);
    }
    return;
}

public 
T_MYUnBan(Handle:ownerHandle:hndl, const String:error[], any:data) {
    if (
hndl == INVALID_HANDLE) {
        
LogError("[MYBans] Query failed! %s"error);
    }
    return;
}

public 
OnClientPostAdminCheck(client) {

    if(
IsFakeClient(client)) {
        return;
    }
    
    
decl String:steam_id[32];
    
decl String:query[255];

    
GetClientAuthString(clientsteam_idsizeof(steam_id));

    new 
buffer_len strlen(steam_id) * 1
    
new String:v_steam_id[buffer_len]
    
SQL_EscapeString(hDatabasesteam_idv_steam_idbuffer_len)

    
Format(querysizeof(query), "SELECT ban_length, ban_reason, (now()-timestamp)/60 FROM my_bans WHERE steam_id = '%s'"v_steam_id);
    
SQL_TQuery(hDatabaseT_AuthCheckqueryGetClientUserId(client));
}                                                

public 
Action:OnBanClient(clienttimeflags, const String:reason[], const String:kick_message[], const String:command[], any:admin) {
    
decl String:query[255];
    
decl String:steam_id[32];
     
decl String:player_name[65];
     
decl String:source[65];

    new 
Handle:convar FindConVar("hostname")
    
decl String:ServerName[64]
    
GetConVarStringconvarServerNamesizeof(ServerName))
    
    
GetClientAuthString(clientsteam_idsizeof(steam_id));
    
GetClientName(clientplayer_namesizeof(player_name));
    
GetClientName(adminsourcesizeof(source));

    new 
buffer_len strlen(steam_id) * 1
    
new String:v_steam_id[buffer_len]
    
SQL_EscapeString(hDatabasesteam_idv_steam_idbuffer_len)

    
buffer_len strlen(reason) * 1
    
new String:v_reason[buffer_len]
    
SQL_EscapeString(hDatabasereasonv_reasonbuffer_len)

    
buffer_len strlen(source) * 1
    
new String:v_source[buffer_len]
    
SQL_EscapeString(hDatabasesourcev_sourcebuffer_len)

    
buffer_len strlen(player_name) * 1
    
new String:v_player_name[buffer_len]
    
SQL_EscapeString(hDatabaseplayer_namev_player_namebuffer_len)

    
Format(querysizeof(query), "REPLACE INTO my_bans (player_name, steam_id, ban_length, ban_reason, banned_by, servername, timestamp) VALUES ('%s','%s','%d','%s','%s', '%s',CURRENT_TIMESTAMP)"v_player_namev_steam_idtimev_reasonv_sourceServerName);
    
SQL_TQuery(hDatabaseT_MYBanquery);
    
KickClient(client,"You have been Banned for %s"reason);
    
ReplyToCommand(admin"[MYBans] User %s has been banned for %d minutes"steam_idtime);
    
LogMessage("[MYBans] User %s has been banned for %d minutes"steam_idtime);
    return 
Plugin_Stop;
}

public 
Action:OnRemoveBan(const String:steam_id[], flags, const String:command[], any:admin) {
    
decl String:query[255];

    new 
buffer_len strlen(steam_id) * 1
    
new String:v_steam_id[buffer_len]
    
SQL_EscapeString(hDatabasesteam_idv_steam_idbuffer_len)

    
Format(querysizeof(query), "DELETE FROM my_bans WHERE steam_id='%s'"v_steam_id);
    
SQL_TQuery(hDatabaseT_MYUnBanquery);
    
ReplyToCommand(admin"[MYBans] User %s has been unbanned"steam_id);
    
LogMessage("[MYBans] User %s has been unbanned."steam_id);
    return 
Plugin_Stop;
}

bool:VerifyTable() {

    
decl String:error[255];
    
decl String:query[512];

    new 
Handle:db SQL_Connect("my_bans"trueerrorsizeof(error));
    if (
db == INVALID_HANDLE) {
        
LogError("[MYBans] Could Not Connect to Database, error: %s"error);
        return 
false;
    }
    
    
Format(query,sizeof(query), "%s%s%s%s%s%s%s%s%s%s%s%s",
        
"CREATE TABLE IF NOT EXISTS `my_bans` (",
        
"  `id` int(11) NOT NULL auto_increment,",
        
"  `steam_id` varchar(32) NOT NULL,",
        
"  `player_name` varchar(65) NOT NULL,",
        
"  `ban_length` int(1) NOT NULL default '0',",
        
"  `ban_reason` varchar(100) NOT NULL,",
        
"  `banned_by` varchar(100) NOT NULL,",
        
"  `servername` varchar(100) NOT NULL,",
        
"  `timestamp` timestamp NOT NULL default '0000-00-00 00:00:00' on update CURRENT_TIMESTAMP,",
        
"  PRIMARY KEY  (`id`),",
        
"  UNIQUE KEY `steam_id` (`steam_id`)",
        
") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; ");

    new 
bool:success SQL_FastQuery(dbquery);
    if(!
success) {
        
SQL_GetError(dberrorsizeof(error));
        
LogError("[MYBans] Unable to verify mysql_bans table:%s"query);
    }

    
CloseHandle(db);
    return 
true;



Solved i make a mistake on my database.cfg i forget made my_ban ^^.

Last edited by benjibau; 03-16-2013 at 21:12. Reason: Solved
benjibau is offline
Send a message via MSN to benjibau
sneakret
Member
Join Date: Jul 2012
Old 05-18-2013 , 07:23   Re: [ANY] Threaded Mysql Bans
Reply With Quote #72

I made some changes to this plugin:
  • Switched from LogMessage to LogAction and put more information in the log message.
  • Included the duration of the ban in the kick message.
  • Changed the logic so that the ban_remaining variable actually contains the amount of time remaining in the ban.
  • Intercepted the sm_addban command.
  • Include the admin's Steam ID to the database (in addition to the name).

I think that covers it. Here's the code:

PHP Code:
#include <sourcemod>
#include <sdktools>
#define PLUGIN_VERSION "1.3 (enhanced)"

public Plugin:myinfo = {
    
name "[ANY] MySQL-T Bans",
    
author "senseless",
    
description "Threaded steam id based mysql bans",
    
version PLUGIN_VERSION,
    
url "https://forums.alliedmods.net/showthread.php?p=1759904"
};

new 
Handle:hDatabase INVALID_HANDLE;

public 
OnPluginStart() {
    
VerifyTable();
    
StartSQL();
    
CreateConVar("sm_mybans_version"PLUGIN_VERSION"MYSQL-T Bans Version"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
    
AddCommandListener(OnAddBan"sm_addban");
}

public 
Action:OnAddBan(client, const String:command[], argc) {
    if (
argc 2)
    {
        
PrintToChat(
            
client,
            
"[SM] Usage: %s <minutes|0> <#userid|name> [reason]",
            
command);
        return 
Plugin_Handled;
    }

    
decl String:arguments[256];
    
GetCmdArgString(argumentssizeof(arguments));

    
decl String:time_string[10];
    
decl len;
    
len BreakString(argumentstime_stringsizeof(time_string));

    
decl String:steam_id[32];
    
decl next_len;
    
next_len BreakString(arguments[len], steam_idsizeof(steam_id));
    if (
next_len != -1)
    {
        
len += next_len;
    }
    else
    {
        
len 0;
        
arguments[0] = '\0';
    }

    
decl String:ban_reason[100];
    
next_len BreakString(arguments[len], ban_reasonsizeof(ban_reason));
    if (
next_len != -1)
    {
        
len += next_len;
    }
    else
    {
        
len 0;
        
arguments[0] = '\0';
    }

    new 
time StringToInt(time_string);

    
decl String:duration_string[60];
    
GetDurationString(duration_stringsizeof(duration_string), time);

    if (
client != 0) {
        
MyBanClient(steam_id"(sm_addban)"timeban_reasonclient);
        
LogAction(client0"%L banned Steam ID %s (%s): %s"clientsteam_idduration_stringban_reason);
    } else {
        
MyBanClient(steam_id"(sm_addban)"timeban_reasonclient);
        
LogAction(00"Console banned Steam ID %s (%s): %s"steam_idduration_stringban_reason);
    }
    
ReplyToCommand(client"[MYBans] Banned Steam ID %s (%s): %s"steam_idduration_stringban_reason);

    return 
Plugin_Stop;
}

GetDurationString(String:duration_string[], duration_string_sizeduration)
{
    if (
duration == 0) {
        
strcopy(duration_stringduration_string_size"permanently");
    } else {
        
Format(duration_stringduration_string_size"%d %s"duration, (duration == 1) ? "minute" "minutes");
    }
}

StartSQL() {
    
SQL_TConnect(GotDatabase);
}

public 
GotDatabase(Handle:ownerHandle:hndl, const String:error[], any:data) {
    if (
hndl == INVALID_HANDLE) {
        
LogError("[MYBans] Database Connection Error: %s"error);
    } else {
        
hDatabase hndl;
    }
}

public 
T_AuthCheck(Handle:ownerHandle:hndl, const String:error[], any:data) {
    new 
client;
    
decl ban_length;    
    
decl String:steam_id[32];
    
decl String:ban_reason[100];
    
decl ban_remaining;
    
decl String:query[255];
        
    if ((
client GetClientOfUserId(data)) == 0) {
        return;
    }

    
GetClientAuthString(clientsteam_idsizeof(steam_id));

    new 
buffer_len strlen(steam_id) * 1
    
new String:v_steam_id[buffer_len]
    
SQL_EscapeString(hDatabasesteam_idv_steam_idbuffer_len)

    if (
hndl == INVALID_HANDLE) {
        
LogError("[MYBans] Query failed! %s"error);
        
KickClient(client"Error: Reattempt connection");
    }

    if(
SQL_FetchRow(hndl)) {
        
ban_length SQL_FetchInt(hndl,0);
        
SQL_FetchString(hndl,1,ban_reason,sizeof(ban_reason));

        if (
ban_length == 0) {
            
ban_remaining 0;
        } else {
            
ban_remaining ban_length SQL_FetchInt(hndl,2);
        }

        if (
ban_length == || ban_remaining 0) {
            
decl String:duration_string[60];
            
GetDurationString(duration_stringsizeof(duration_string), ban_remaining);
            
KickClient(client,"Banned (%s): %s"duration_stringban_reason);
        } else {
            
Format(querysizeof(query), "DELETE FROM my_bans WHERE steam_id='%s'"v_steam_id);
            
SQL_TQuery(hDatabaseT_MYUnBanquery);
            
LogAction(00"Allowing %L to connect. Ban has expired."client);
        }
    }
}

public 
T_MYBan(Handle:ownerHandle:hndl, const String:error[], any:data) {
    if (
hndl == INVALID_HANDLE) {
        
LogError("[MYBans] Query failed! %s"error);
    }
    return;
}

public 
T_MYUnBan(Handle:ownerHandle:hndl, const String:error[], any:data) {
    if (
hndl == INVALID_HANDLE) {
        
LogError("[MYBans] Query failed! %s"error);
    }
    return;
}

public 
OnClientPostAdminCheck(client) {

    if(
IsFakeClient(client)) {
        return;
    }

    
decl String:steam_id[32];
    
decl String:query[255];

    
GetClientAuthString(clientsteam_idsizeof(steam_id));

    new 
buffer_len strlen(steam_id) * 1
    
new String:v_steam_id[buffer_len]
    
SQL_EscapeString(hDatabasesteam_idv_steam_idbuffer_len)

    
Format(querysizeof(query), "SELECT ban_length, ban_reason, (now()-timestamp)/60 FROM my_bans WHERE steam_id = '%s'"v_steam_id);
    
SQL_TQuery(hDatabaseT_AuthCheckqueryGetClientUserId(client));
}

MyBanClient(const String:steam_id[], const String:player_name[], time, const String:reason[], admin) {
    
decl String:query[255];
    
decl String:source[100];

    if (
admin == 0) {
        
strcopy(sourcesizeof(source), "Console");
    } else {
        
Format(sourcesizeof(source), "%L"admin);
    }

    new 
buffer_len strlen(steam_id) * 1
    
new String:v_steam_id[buffer_len]
    
SQL_EscapeString(hDatabasesteam_idv_steam_idbuffer_len)

    
buffer_len strlen(reason) * 1
    
new String:v_reason[buffer_len]
    
SQL_EscapeString(hDatabasereasonv_reasonbuffer_len)

    
buffer_len strlen(source) * 1
    
new String:v_source[buffer_len]
    
SQL_EscapeString(hDatabasesourcev_sourcebuffer_len)

    
buffer_len strlen(player_name) * 1
    
new String:v_player_name[buffer_len]
    
SQL_EscapeString(hDatabaseplayer_namev_player_namebuffer_len)

    
Format(querysizeof(query), "REPLACE INTO my_bans (player_name, steam_id, ban_length, ban_reason, banned_by, timestamp) VALUES ('%s','%s','%d','%s','%s',CURRENT_TIMESTAMP)"v_player_namev_steam_idtimev_reasonv_source);
    
SQL_TQuery(hDatabaseT_MYBanquery);
}

public 
Action:OnBanClient(clienttimeflags, const String:reason[], const String:kick_message[], const String:command[], any:admin) {
    
decl String:steam_id[32];
    
decl String:player_name[65];
    
GetClientAuthString(clientsteam_idsizeof(steam_id));
    
GetClientName(clientplayer_namesizeof(player_name));
    
MyBanClient(steam_idplayer_nametimereasonadmin);
    
decl String:duration_string[60];
    
GetDurationString(duration_stringsizeof(duration_string), time);
    
KickClient(client,"Banned (%s): %s"duration_stringreason);
    
LogAction(adminclient"%L banned %L (%s): %s"adminclientduration_stringreason);
    return 
Plugin_Stop;
}

public 
Action:OnRemoveBan(const String:steam_id[], flags, const String:command[], any:admin) {
    
decl String:query[255];

    new 
buffer_len strlen(steam_id) * 1
    
new String:v_steam_id[buffer_len]
    
SQL_EscapeString(hDatabasesteam_idv_steam_idbuffer_len)

    
Format(querysizeof(query), "DELETE FROM my_bans WHERE steam_id='%s'"v_steam_id);
    
SQL_TQuery(hDatabaseT_MYUnBanquery);
    
ReplyToCommand(admin"[MYBans] User %s has been unbanned"steam_id);
    
LogAction(admin0"%L unbanned Steam ID %s."adminsteam_id);
    return 
Plugin_Stop;
}

bool:VerifyTable() {
    
decl String:error[255];
    
decl String:query[512];

    new 
Handle:db SQL_Connect("default"trueerrorsizeof(error));
    if (
db == INVALID_HANDLE) {
        
LogError("[MYBans] Could Not Connect to Database, error: %s"error);
        return 
false;
    }

    
Format(query,sizeof(query), "%s%s%s%s%s%s%s%s%s%s%s",
        
"CREATE TABLE IF NOT EXISTS `my_bans` (",
        
"  `id` int(11) NOT NULL auto_increment,",
        
"  `steam_id` varchar(32) NOT NULL,",
        
"  `player_name` varchar(65) NOT NULL,",
        
"  `ban_length` int(1) NOT NULL default '0',",
        
"  `ban_reason` varchar(100) NOT NULL,",
        
"  `banned_by` varchar(100) NOT NULL,",
        
"  `timestamp` timestamp NOT NULL default '0000-00-00 00:00:00' on update CURRENT_TIMESTAMP,",
        
"  PRIMARY KEY  (`id`),",
        
"  UNIQUE KEY `steam_id` (`steam_id`)",
        
") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; ");

    new 
bool:success SQL_FastQuery(dbquery);
    if(!
success) {
        
SQL_GetError(dberrorsizeof(error));
        
LogError("[MYBans] Unable to verify mysql_bans table:%s"query);
    }

    
CloseHandle(db);
    return 
true;

sneakret is offline
Brakmar
Junior Member
Join Date: May 2013
Old 05-17-2014 , 07:34   Re: [ANY] Threaded Mysql Bans
Reply With Quote #73

Quote:
Originally Posted by sneakret View Post
I made some changes to this plugin:
  • Switched from LogMessage to LogAction and put more information in the log message.
  • Included the duration of the ban in the kick message.
  • Changed the logic so that the ban_remaining variable actually contains the amount of time remaining in the ban.
  • Intercepted the sm_addban command.
  • Include the admin's Steam ID to the database (in addition to the name).

I think that covers it. Here's the code:

PHP Code:
#include <sourcemod>
#include <sdktools>
#define PLUGIN_VERSION "1.3 (enhanced)"

public Plugin:myinfo = {
    
name "[ANY] MySQL-T Bans",
    
author "senseless",
    
description "Threaded steam id based mysql bans",
    
version PLUGIN_VERSION,
    
url "https://forums.alliedmods.net/showthread.php?p=1759904"
};

new 
Handle:hDatabase INVALID_HANDLE;

public 
OnPluginStart() {
    
VerifyTable();
    
StartSQL();
    
CreateConVar("sm_mybans_version"PLUGIN_VERSION"MYSQL-T Bans Version"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
    
AddCommandListener(OnAddBan"sm_addban");
}

public 
Action:OnAddBan(client, const String:command[], argc) {
    if (
argc 2)
    {
        
PrintToChat(
            
client,
            
"[SM] Usage: %s <minutes|0> <#userid|name> [reason]",
            
command);
        return 
Plugin_Handled;
    }

    
decl String:arguments[256];
    
GetCmdArgString(argumentssizeof(arguments));

    
decl String:time_string[10];
    
decl len;
    
len BreakString(argumentstime_stringsizeof(time_string));

    
decl String:steam_id[32];
    
decl next_len;
    
next_len BreakString(arguments[len], steam_idsizeof(steam_id));
    if (
next_len != -1)
    {
        
len += next_len;
    }
    else
    {
        
len 0;
        
arguments[0] = '\0';
    }

    
decl String:ban_reason[100];
    
next_len BreakString(arguments[len], ban_reasonsizeof(ban_reason));
    if (
next_len != -1)
    {
        
len += next_len;
    }
    else
    {
        
len 0;
        
arguments[0] = '\0';
    }

    new 
time StringToInt(time_string);

    
decl String:duration_string[60];
    
GetDurationString(duration_stringsizeof(duration_string), time);

    if (
client != 0) {
        
MyBanClient(steam_id"(sm_addban)"timeban_reasonclient);
        
LogAction(client0"%L banned Steam ID %s (%s): %s"clientsteam_idduration_stringban_reason);
    } else {
        
MyBanClient(steam_id"(sm_addban)"timeban_reasonclient);
        
LogAction(00"Console banned Steam ID %s (%s): %s"steam_idduration_stringban_reason);
    }
    
ReplyToCommand(client"[MYBans] Banned Steam ID %s (%s): %s"steam_idduration_stringban_reason);

    return 
Plugin_Stop;
}

GetDurationString(String:duration_string[], duration_string_sizeduration)
{
    if (
duration == 0) {
        
strcopy(duration_stringduration_string_size"permanently");
    } else {
        
Format(duration_stringduration_string_size"%d %s"duration, (duration == 1) ? "minute" "minutes");
    }
}

StartSQL() {
    
SQL_TConnect(GotDatabase);
}

public 
GotDatabase(Handle:ownerHandle:hndl, const String:error[], any:data) {
    if (
hndl == INVALID_HANDLE) {
        
LogError("[MYBans] Database Connection Error: %s"error);
    } else {
        
hDatabase hndl;
    }
}

public 
T_AuthCheck(Handle:ownerHandle:hndl, const String:error[], any:data) {
    new 
client;
    
decl ban_length;    
    
decl String:steam_id[32];
    
decl String:ban_reason[100];
    
decl ban_remaining;
    
decl String:query[255];
        
    if ((
client GetClientOfUserId(data)) == 0) {
        return;
    }

    
GetClientAuthString(clientsteam_idsizeof(steam_id));

    new 
buffer_len strlen(steam_id) * 1
    
new String:v_steam_id[buffer_len]
    
SQL_EscapeString(hDatabasesteam_idv_steam_idbuffer_len)

    if (
hndl == INVALID_HANDLE) {
        
LogError("[MYBans] Query failed! %s"error);
        
KickClient(client"Error: Reattempt connection");
    }

    if(
SQL_FetchRow(hndl)) {
        
ban_length SQL_FetchInt(hndl,0);
        
SQL_FetchString(hndl,1,ban_reason,sizeof(ban_reason));

        if (
ban_length == 0) {
            
ban_remaining 0;
        } else {
            
ban_remaining ban_length SQL_FetchInt(hndl,2);
        }

        if (
ban_length == || ban_remaining 0) {
            
decl String:duration_string[60];
            
GetDurationString(duration_stringsizeof(duration_string), ban_remaining);
            
KickClient(client,"Banned (%s): %s"duration_stringban_reason);
        } else {
            
Format(querysizeof(query), "DELETE FROM my_bans WHERE steam_id='%s'"v_steam_id);
            
SQL_TQuery(hDatabaseT_MYUnBanquery);
            
LogAction(00"Allowing %L to connect. Ban has expired."client);
        }
    }
}

public 
T_MYBan(Handle:ownerHandle:hndl, const String:error[], any:data) {
    if (
hndl == INVALID_HANDLE) {
        
LogError("[MYBans] Query failed! %s"error);
    }
    return;
}

public 
T_MYUnBan(Handle:ownerHandle:hndl, const String:error[], any:data) {
    if (
hndl == INVALID_HANDLE) {
        
LogError("[MYBans] Query failed! %s"error);
    }
    return;
}

public 
OnClientPostAdminCheck(client) {

    if(
IsFakeClient(client)) {
        return;
    }

    
decl String:steam_id[32];
    
decl String:query[255];

    
GetClientAuthString(clientsteam_idsizeof(steam_id));

    new 
buffer_len strlen(steam_id) * 1
    
new String:v_steam_id[buffer_len]
    
SQL_EscapeString(hDatabasesteam_idv_steam_idbuffer_len)

    
Format(querysizeof(query), "SELECT ban_length, ban_reason, (now()-timestamp)/60 FROM my_bans WHERE steam_id = '%s'"v_steam_id);
    
SQL_TQuery(hDatabaseT_AuthCheckqueryGetClientUserId(client));
}

MyBanClient(const String:steam_id[], const String:player_name[], time, const String:reason[], admin) {
    
decl String:query[255];
    
decl String:source[100];

    if (
admin == 0) {
        
strcopy(sourcesizeof(source), "Console");
    } else {
        
Format(sourcesizeof(source), "%L"admin);
    }

    new 
buffer_len strlen(steam_id) * 1
    
new String:v_steam_id[buffer_len]
    
SQL_EscapeString(hDatabasesteam_idv_steam_idbuffer_len)

    
buffer_len strlen(reason) * 1
    
new String:v_reason[buffer_len]
    
SQL_EscapeString(hDatabasereasonv_reasonbuffer_len)

    
buffer_len strlen(source) * 1
    
new String:v_source[buffer_len]
    
SQL_EscapeString(hDatabasesourcev_sourcebuffer_len)

    
buffer_len strlen(player_name) * 1
    
new String:v_player_name[buffer_len]
    
SQL_EscapeString(hDatabaseplayer_namev_player_namebuffer_len)

    
Format(querysizeof(query), "REPLACE INTO my_bans (player_name, steam_id, ban_length, ban_reason, banned_by, timestamp) VALUES ('%s','%s','%d','%s','%s',CURRENT_TIMESTAMP)"v_player_namev_steam_idtimev_reasonv_source);
    
SQL_TQuery(hDatabaseT_MYBanquery);
}

public 
Action:OnBanClient(clienttimeflags, const String:reason[], const String:kick_message[], const String:command[], any:admin) {
    
decl String:steam_id[32];
    
decl String:player_name[65];
    
GetClientAuthString(clientsteam_idsizeof(steam_id));
    
GetClientName(clientplayer_namesizeof(player_name));
    
MyBanClient(steam_idplayer_nametimereasonadmin);
    
decl String:duration_string[60];
    
GetDurationString(duration_stringsizeof(duration_string), time);
    
KickClient(client,"Banned (%s): %s"duration_stringreason);
    
LogAction(adminclient"%L banned %L (%s): %s"adminclientduration_stringreason);
    return 
Plugin_Stop;
}

public 
Action:OnRemoveBan(const String:steam_id[], flags, const String:command[], any:admin) {
    
decl String:query[255];

    new 
buffer_len strlen(steam_id) * 1
    
new String:v_steam_id[buffer_len]
    
SQL_EscapeString(hDatabasesteam_idv_steam_idbuffer_len)

    
Format(querysizeof(query), "DELETE FROM my_bans WHERE steam_id='%s'"v_steam_id);
    
SQL_TQuery(hDatabaseT_MYUnBanquery);
    
ReplyToCommand(admin"[MYBans] User %s has been unbanned"steam_id);
    
LogAction(admin0"%L unbanned Steam ID %s."adminsteam_id);
    return 
Plugin_Stop;
}

bool:VerifyTable() {
    
decl String:error[255];
    
decl String:query[512];

    new 
Handle:db SQL_Connect("default"trueerrorsizeof(error));
    if (
db == INVALID_HANDLE) {
        
LogError("[MYBans] Could Not Connect to Database, error: %s"error);
        return 
false;
    }

    
Format(query,sizeof(query), "%s%s%s%s%s%s%s%s%s%s%s",
        
"CREATE TABLE IF NOT EXISTS `my_bans` (",
        
"  `id` int(11) NOT NULL auto_increment,",
        
"  `steam_id` varchar(32) NOT NULL,",
        
"  `player_name` varchar(65) NOT NULL,",
        
"  `ban_length` int(1) NOT NULL default '0',",
        
"  `ban_reason` varchar(100) NOT NULL,",
        
"  `banned_by` varchar(100) NOT NULL,",
        
"  `timestamp` timestamp NOT NULL default '0000-00-00 00:00:00' on update CURRENT_TIMESTAMP,",
        
"  PRIMARY KEY  (`id`),",
        
"  UNIQUE KEY `steam_id` (`steam_id`)",
        
") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; ");

    new 
bool:success SQL_FastQuery(dbquery);
    if(!
success) {
        
SQL_GetError(dberrorsizeof(error));
        
LogError("[MYBans] Unable to verify mysql_bans table:%s"query);
    }

    
CloseHandle(db);
    return 
true;


Hi,

I have a problem with the plugins.

The sm_addban command is available for visitors !

How repair this ?

Cordially
Brakmar is offline
rautamiekka
Veteran Member
Join Date: Jan 2009
Location: Finland
Old 05-17-2014 , 08:47   Re: [ANY] Threaded Mysql Bans
Reply With Quote #74

Quote:
Originally Posted by sneakret View Post
I made some changes to this plugin:
  • Switched from LogMessage to LogAction and put more information in the log message.
  • Included the duration of the ban in the kick message.
  • Changed the logic so that the ban_remaining variable actually contains the amount of time remaining in the ban.
  • Intercepted the sm_addban command.
  • Include the admin's Steam ID to the database (in addition to the name).

I think that covers it. Here's the code:

PHP Code:
... 
Good work. I'd recommend adding LIMIT keywords to the SQL for extra speed: if you know that you'll have a certain count of rows, add
Code:
LIMIT #
where # is the count of rows. Like in the case where you DELETE the ban, there can't be more than 1. If there is, something else is wrong.
__________________
Links to posts I received Karma from:
Big thanks to all who gave Karma

Last edited by rautamiekka; 05-17-2014 at 08:48.
rautamiekka is offline
Send a message via ICQ to rautamiekka Send a message via AIM to rautamiekka Send a message via MSN to rautamiekka Send a message via Yahoo to rautamiekka Send a message via Skype™ to rautamiekka
Cerium
Member
Join Date: Dec 2013
Old 07-02-2014 , 10:13   Re: [ANY] Threaded Mysql Bans
Reply With Quote #75

Is this plugin still working?
__________________
Cerium is offline
lyric
Veteran Member
Join Date: Sep 2012
Old 07-02-2014 , 22:23   Re: [ANY] Threaded Mysql Bans
Reply With Quote #76

Quote:
Originally Posted by Cerium View Post
Is this plugin still working?
yes
__________________
lyric is offline
Cerium
Member
Join Date: Dec 2013
Old 07-03-2014 , 06:14   Re: [ANY] Threaded Mysql Bans
Reply With Quote #77

Possible to add IP ban to this plugin?
__________________
Cerium is offline
rautamiekka
Veteran Member
Join Date: Jan 2009
Location: Finland
Old 08-01-2014 , 05:54   Re: [ANY] Threaded Mysql Bans
Reply With Quote #78

senseit, we got a situation here:

CS:GO has its own Steam ID format from the usual, with a catch: the first number in the ID, 'STEAM_#', where '#' is a number, is 1 instead of 0 or whatever, otherwise the ID is identical.

This sort of requires rewriting of the plugin. It seems Miraculix, owner of CSS Bank, rewrote the plugin so that it strips the 'STEAM_#:' part of the ID, leaving just the second number, the second colon, and the number sequence for this reason. For example, my usual SID is STEAM_0:1:11268321, but in CS:GO it is STEAM_1:1:11268321. So, CSS Bank strips 'STEAM_1:' and leaves '1:11268321'.

You should do this too so that the database doesn't need to be polluted by nearly identical IDs.
__________________
Links to posts I received Karma from:
Big thanks to all who gave Karma
rautamiekka is offline
Send a message via ICQ to rautamiekka Send a message via AIM to rautamiekka Send a message via MSN to rautamiekka Send a message via Yahoo to rautamiekka Send a message via Skype™ to rautamiekka
Cruckes
Member
Join Date: Jun 2014
Location: Finland
Old 08-23-2014 , 16:46   Re: [ANY] Threaded Mysql Bans
Reply With Quote #79

How do I add to admin's name to ban reason?
Like:
Quote:
You been banned by: [admin's name] for [reason].
Lines 118-120:
Quote:
new String:banned_by[32];

GetClientName(client, banned_by, 32);
Line 145:
Quote:
KickClient(client,"You have been Banned by %s for %s", banned_by, reason);

Last edited by Cruckes; 08-24-2014 at 05:55. Reason: Nevermind, got the "webpanel", so I don't need that.
Cruckes is offline
Brakmar
Junior Member
Join Date: May 2013
Old 08-25-2014 , 15:18   Re: [ANY] Threaded Mysql Bans
Reply With Quote #80

Hi,

I have a problem with your plugins sneakret.

The sm_addban command is available for visitors !

How repair this ?

Cordially

Last edited by Brakmar; 08-25-2014 at 15:19.
Brakmar is offline
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 23:08.


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