Unban IP command
#1

Hi, I was wondering how i'd go about making a /unban [ip] command, I am using mysql if it helps.

Thanks.
Reply
#2

SendRconCommand("unbanip");
?
Reply
#3

Well, as your ban system is MySQL, you can just search for the IP specified (or in this case you will use the command params) in the table specified, and delete the whole row.
Reply
#4

pawn Код:
command(unban, playerid, params[])
{
    new ip[17];
    if (sscanf(params, "s[17]", ip))SendClientMessage(playerid, -1, "* Use: /unban [ip]");
   
    new query[100];
    format(query, 100, "SELECT `ip` FROM `bans` WHERE `ip` = '%s' LIMIT 1", ip);
    mysql_query(query);
    mysql_store_result();
   
    if (mysql_num_rows()) // Found Ip
    {
        format(query, 100, "DELET FROM `bans` WHERE `ip` = '%s'", ip);
        mysql_query(query);
        SendClientMessage(playerid, -1, "Ip successful deleted from banlist!");
    }
    else SendClientMessage(playerid, -1, "ERROR: INVALID PLAYER IP!");
    mysql_free_result();
    return 1;
}
In this ex i'm using zcmd and sscanf because i dont using strcmp or something else.
Reply
#5

I can think of 2 methods, be real careful with where to put ` and ' or it wont work:

Method 1, you have a users table and you put a field to '1' when a player is banned:
pawn Код:
//To ban a user
mysql_query("UPDATE `your_users_table` SET `your_banned_field` = 1 WHERE `your_ip_field` = 'the_players_ip'");

// To unban a user
mysql_query("UPDATE `your_user_table` SET `your_banned_field` = 0 WHERE `your_ip_field` = 'the_players_ip'");

//EXAMPLE
mysql_query("UPDATE `users` SET `banned` = 0 WHERE `ip` = '127.0.0.1'");
method 2, you have a seperate table with bans:
pawn Код:
//To ban a user
mysql_query("INSERT INTO `your_banned_users_table` (`your_ip_field`) VALUES('the_players_ip')");

// To unban a user
mysql_query("DELETE FROM `your_banned_users_table` WHERE `your_ip_field` = 'the_players_ip'");

//EXAMPLE
mysql_query("DELETE FROM `bans` WHERE `ip` = '127.0.0.1'");
Hope that makes sense to you. If it's not you can always PM me.
Reply
#6

Sinner is that you? its me [SP]Mr.Kakashi[WP]

come here

https://sampforum.blast.hk/showthread.php?tid=292530

its about ban system
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)