Quantcast
Channel: SA-MP Forums - Filterscripts
Viewing all articles
Browse latest Browse all 595

[Include] Ban System [MySQL R39-4 + TextDraw]

$
0
0
I know there are already systems as well, but this is my first system in MySQL.

TABLE AND CONNECTION
The first thing is to connect to the database and should normally be inserted into OnGameModeInit / OnFilterScriptInit.
The connection is established and the table is automatically created only provide the correct information.
Code:

mysql_ban_connect(const host[], const user[], const database[], const password[]);
Example to usage:
Code:

mysql_ban_connect("localhost", "root", "server_samp", "password");
PLAYER CHECKING
We can check if the player will be banned is online or not with the following function (remembering that the check is in string and not as integer as IsPlayerConnected):
Code:

bool:mysql_ban_player_check(Find[])
Example to usage:
Code:

//CHECKING THE NAME
GetPlayerName(playerid, Name, 24);
if(mysql_ban_player_check(Name) == true)
{
    //Player On
}
else
{
    //Player Off
}

//CHECKING THE IP
GetPlayerIp(playerid, IP, 16);
if(mysql_ban_player_check(IP) == true)
{
    //Player On
}
else
{
    //Player Off
}

BAN THE PLAYER
Code:

mysql_ban_player(Player_Name[], Player_IP[], Ban_By[], Reason[], Ban_Type, Time);
Example to usage:
Code:

mysql_ban_player("UserName", "127.0.0.1", "F1N4L", "TEST", PERMANENT, 0);
NOTE: When placing a permanent Ban, regardless of the time you guys put, will not change anything.
The permanent Ban is basically A ban of the 20 years, or even technically permanent. The check whether it is permanent or not is if the days are greater than 3650 ( +- 10 years).

By default already defines macros and can run on GM / FS without problems, just be easier to switch between the type of ban:

UNBANNED THE PLAYER
Code:

mysql_ban_remove(Banned[]);
Example to usage:
Code:

//CHECKING THE NAME
if(mysql_ban_player_check("F1N4L") == true)
{
    //Column found
}
else
{
    //Column not found
}

//CHECKING THE IP
if(mysql_ban_player_check("127.0.0.1") == true)
{
    //Column found
}
else
{
    //Column not found
}

CHECKING THE CONNECTING
I created the hook in the include purposely so the only necessary and main things are the connection of stocks to the database and to ban, so the check will occur in the include.
Code:

mysql_banned_check(playerid);
APPLYING IN PRACTICE:
Code:

public OnFilterScriptInit() // or OnGameModeInit
{
        mysql_ban_connect("localhost", "root", "server_samp", "password");
       
        return 1;
}

IN THE COMMANDS BELOW HAVE EXAMPLES OF PROPER USE SYSTEM

Code:

CMD:banname(playerid, params[])
{
        new BannedName[24], BannedByName[24], Reason[20], BanType, Time, String[128];
       
        if(sscanf(params, "s[24]iis[20]", BannedName, BanType, Time, Reason)) return SendClientMessage(playerid, -1, "/ban [name] [Tipo: 0 = permanent | 1 = minutes | 2 = hours | 3 = days] [time] [reason]");
       
        if(BanType < 0 || BanType > 3) return SendClientMessage(playerid, -1, "Incorrect type of ban! Uses: 0 = permanent | 1 = minutes | 2 = hours | 3 = days");
       
        GetPlayerName(playerid, BannedByName, sizeof BannedByName);
       
        if(mysql_ban_player_check(BannedName) == true)
        {
                switch(BanType)
                {
                        case 0: format(String, sizeof String, "Admin% s Online banned player %s. Reason: %s. Time: PERMANENT", BannedByName, BannedName, Reason);
                        case 1: format(String, sizeof String, "Admin% s Online banned player %s. Reason: %s. Time: %i Minutes", BannedByName, BannedName, Reason, Time);
                        case 2: format(String, sizeof String, "Admin% s Online banned player %s. Reason: %s. Time: %i Hours", BannedByName, BannedName, Reason, Time);
                        case 3: format(String, sizeof String, "Admin% s Online banned player %s. Reason: %s. Time: %i Days", BannedByName, BannedName, Reason, Time);
                }
        }
        else
        {
                switch(BanType)
                {
                        case 0: format(String, sizeof String, "Admin% s Offline banned player %s. Reason: %s. Time: PERMANENT", BannedByName, BannedName, Reason);
                        case 1: format(String, sizeof String, "Admin% s Offline banned player %s. Reason: %s. Time: %i Minutes", BannedByName, BannedName, Reason, Time);
                        case 2: format(String, sizeof String, "Admin% s Offline banned player %s. Reason: %s. Time: %i Hours", BannedByName, BannedName, Reason, Time);
                        case 3: format(String, sizeof String, "Admin% s Offline banned player %s. Reason: %s. Time: %i Days", BannedByName, BannedName, Reason, Time);
                }
        }
        SendClientMessageToAll(-1, String);
       
        mysql_ban_player(BannedName, "0.0.0.0", BannedByName, Reason, BanType, Time);
       
        return 1;
}

CMD:banip(playerid, params[])
{
        new BannedIP[24], BannedByName[24], Reason[20], BanType, Time, String[128];
       
        if(sscanf(params, "s[16]iis[20]", BannedIP, BanType, Time, Reason)) return SendClientMessage(playerid, -1, "/ban [name] [Tipo: 0 = permanent | 1 = minutes | 2 = hours | 3 = days] [time] [reason]");
       
        if(BanType < 0 || BanType > 3) return SendClientMessage(playerid, -1, "Incorrect type of ban! Uses: 0 = permanent | 1 = minutes | 2 = hours | 3 = days");
       
        GetPlayerName(playerid, BannedByName, sizeof BannedByName);
       
        if(mysql_ban_player_check(BannedIP) == true)
        {
                switch(BanType)
                {
                        case 0: format(String, sizeof String, "Admin% s Online banned the IP range's. Reason: %s. Time: PERMANENT", BannedByName, BannedIP, Reason);
                        case 1: format(String, sizeof String, "Admin% s Online banned the IP range's. Reason: %s. Time: %i Minutes", BannedByName, BannedIP, Reason, Time);
                        case 2: format(String, sizeof String, "Admin% s Online banned the IP range's. Reason: %s. Time: %i Hours", BannedByName, BannedIP, Reason, Time);
                        case 3: format(String, sizeof String, "Admin% s Online banned the IP range's. Reason: %s. Time: %i Days", BannedByName, BannedIP, Reason, Time);
                }
        }
        else
        {
                switch(BanType)
                {
                        case 0: format(String, sizeof String, "Admin% s Offline banned the IP range's. Reason: %s. Time: PERMANENT", BannedByName, BannedIP, Reason);
                        case 1: format(String, sizeof String, "Admin% s Offline banned the IP range's. Reason: %s. Time: %i Minutes", BannedByName, BannedIP, Reason, Time);
                        case 2: format(String, sizeof String, "Admin% s Offline banned the IP range's. Reason: %s. Time: %i Hours", BannedByName, BannedIP, Reason, Time);
                        case 3: format(String, sizeof String, "Admin% s Offline banned the IP range's. Reason: %s. Time: %i Days", BannedByName, BannedIP, Reason, Time);
                }
        }
        SendClientMessageToAll(-1, String);
       
        mysql_ban_player("N/A", BannedIP, BannedByName, Reason, BanType, Time);
       
        return 1;
}

CMD:banid(playerid, params[])
{
        new Banned, BannedIP[24], BannedName[24], BannedByName[24], Reason[20], BanType, Time, String[128];
       
        if(sscanf(params, "uiis[20]", Banned, BanType, Time, Reason)) return SendClientMessage(playerid, -1, "/ban [id/name] [Tipo: 0 = permanent | 1 = minutes | 2 = hours | 3 = days] [time] [reason]");
       
        if(!IsPlayerConnected(Banned)) return SendClientMessage(playerid, -1, "Jogador não conectado!");
       
        if(BanType < 0 || BanType > 3) return SendClientMessage(playerid, -1, "Incorrect type of ban! Uses: 0 = permanent | 1 = minutes | 2 = hours | 3 = days");
       
        GetPlayerName(playerid, BannedByName, sizeof BannedByName);
       
        GetPlayerName(Banned, BannedName, sizeof BannedName);
        GetPlayerIp(Banned, BannedIP, sizeof BannedIP);
       
        if(mysql_ban_player_check(BannedIP) == true)
        {
                switch(BanType)
                {
                        case 0: format(String, sizeof String, "Admin% s Online banned player %s [IP: %s]. Reason: %s. Time: PERMANENT", BannedByName, BannedName,  BannedIP, Reason);
                        case 1: format(String, sizeof String, "Admin% s Online banned player %s [IP: %s]. Reason: %s. Time: %i Minutes", BannedByName, BannedName, BannedIP, Reason, Time);
                        case 2: format(String, sizeof String, "Admin% s Online banned player %s [IP: %s]. Reason: %s. Time: %i Hours", BannedByName, BannedName, BannedIP, Reason, Time);
                        case 3: format(String, sizeof String, "Admin% s Online banned player %s [IP: %s]. Reason: %s. Time: %i Days", BannedByName, BannedName, BannedIP, Reason, Time);
                }
                SendClientMessageToAll(-1, String);
        }
        else SendClientMessage(playerid, -1, "Player ID don't connected!");
       
        mysql_ban_player(BannedName, BannedIP, BannedByName, Reason, BanType, Time);
       
        return 1;
}

CMD:banremove(playerid, params[])
{
        if(isnull(params)) return SendClientMessage(playerid, -1, "/banremove [name/ip]");
       
        if(mysql_ban_remove_check(params) == true)
        {
                mysql_ban_remove(params);
                SendClientMessage(playerid, -1, "Player/IP found and successfully unbanned!");
        }
        else SendClientMessage(playerid, -1, "Player/IP not found in the database!");
       
        return 1;
}



Download:
PASTEBIN

Créditos:
a_samp // By SA-MP Team
zcmd // By Zeex
sscanf // By Y_Less
a_mysql // By BlueG
Script // By F1N4L

Viewing all articles
Browse latest Browse all 595

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>