How would I do a check in mysql? (Bans)
#1

Hello, alright, Say I banned a players IP.

In a seperate table "Bans" It add's the PlayersSQLID and PlayersIP to the list, how do I check when a player connects if their IP matches any on the list and kick them.

Also how would I remove the id from the list i.e /unban from IN-GAME.

Grant.
Reply
#2

To check if the player is banned (basically by checking if the ip occurs in the bans table):
pawn Код:
stock IsPlayerBanned(playerid) {
    new query[128], player_ip[16], bool:banned = false;
    GetPlayerIp(playerid, player_ip, sizeof(player_ip));
    format(query, sizeof(query), "SELECT * FROM `bans` WHERE `ip` = '%s'", player_ip);
    mysql_query(query);
    mysql_store_result();
    banned = mysql_num_rows>0;
    mysql_free_result();
    return banned;
}
To unban the player (remove his 'record'):
pawn Код:
stock UnbanPlayer(ip[]) {
    new query[128];
    format(query, sizeof(query), "DELETE FROM `bans` WHERE `ip` = '%s'", ip);
    mysql_query(query);
}
Hope that helped.
Reply
#3

Thank you very much, I knew it was a query I just wasnt sure where to check! Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)