SA-MP Forums Archive
How would I do a check in mysql? (Bans) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How would I do a check in mysql? (Bans) (/showthread.php?tid=312794)



How would I do a check in mysql? (Bans) - Dokins - 22.01.2012

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.


Re: How would I do a check in mysql? (Bans) - Sinner - 22.01.2012

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.


Re: How would I do a check in mysql? (Bans) - Dokins - 22.01.2012

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