IP Ban system
#1

I'm trying to make a ban system with IP banning..
pawn Код:
enum pInfo
{
    pPass,
    pIP[16],
    pCash,
    pScore,
    pDonator,
    pAdmin,
    pHeals,
    pKills,
    pDeaths,
    pBanned,
    pBanReason,
}
new PlayerInfo[MAX_PLAYERS][pInfo];

forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password",PlayerInfo[playerid][pPass]);
    INI_Int("Cash",PlayerInfo[playerid][pCash]);
    INI_Int("Score",PlayerInfo[playerid][pScore]);
    INI_Int("Donator",PlayerInfo[playerid][pDonator]);
    INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    INI_Int("Heals",PlayerInfo[playerid][pHeals]);
    INI_Int("Kills",PlayerInfo[playerid][pKills]);
    INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
    INI_Int("Banned",PlayerInfo[playerid][pBanned]);
    return 1;
}

//On Player Connect
public OnPlayerConnect(playerid)
{
    new string[128];
    new pname[24];
    if(PlayerInfo[playerid][pBanned] == 1)
    {
      format(string,sizeof(string),"[BANNED] You are currently banned from the server. [Reason: %s]",PlayerInfo[playerid][pBanReason]);
      SendClientMessage(playerid, COLOR_RED,string);
      SendClientMessage(playerid, COLOR_RED,"[BANNED] Please Ban Appeal on our forums at www.trd.com");
      SetTimerEx("KickPlayer",1000,false,"i",playerid);
      return 1;
    }
    //OTHER CODES
    return 1;
}

//On Player Disconnect.
public OnPlayerDisconnect(playerid, reason)
{
    new string[128];
    new pname[24];

    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"Player's Data");
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Score",GetPlayerScore(playerid));
    INI_WriteInt(File,"Donator",PlayerInfo[playerid][pDonator]);
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"Heals",PlayerInfo[playerid][pHeals]);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_WriteInt(File,"Banned",PlayerInfo[playerid][pBanned]);
    INI_Close(File);
    //OTHER CODES
    return 1;
}

//Ban command
dcmd_ban(playerid,params[])
{
    new string[128];
    new ID;
    new cmdreason[100];
    new pname[MAX_PLAYER_NAME];
    new tname[MAX_PLAYER_NAME];
    if(sscanf(params,"us[100]",ID,cmdreason))
    {
        SendClientMessage(playerid,COLOR_ERROR,"[USAGE] /Ban (Player Name/ID) (Reason)");
        return 1;
    }
    if(!IsPlayerConnected(ID))
    {
        format(string,sizeof(string),"[ERROR] The player ID you entered is not connected to the server.");
        SendClientMessage(playerid,COLOR_RED,string);
        return 1;
    }
    if(PlayerInfo[ID][pAdmin] > PlayerInfo[playerid][pAdmin])
    {
        format(string,sizeof(string),"[ERROR] You cannot use this command on a higher administration level.");
        SendClientMessage(playerid,COLOR_RED,string);
        return 1;
    }
    GetPlayerName(playerid,pname,sizeof(pname));
    GetPlayerName(ID,tname,sizeof(tname));
    if(PlayerInfo[ID][pBanned] == 1)
    {
        format(string,sizeof(string),"[ERROR] %s(%d) is already banned from the server. [Reason: %s]",tname,ID,PlayerInfo[ID][pBanReason]);
        SendClientMessage(playerid,COLOR_RED,string);
        return 1;
    }
    if(InAdminMode[ID] == 1)
    {
        format(string,sizeof(string),"[ERROR] Admin %s(%d) is currently in admin mode.",tname,ID);
        SendClientMessage(playerid,COLOR_RED,string);
        return 1;
    }
    format(string, sizeof(string), "~r~BANNED!");
    GameTextForPlayer(ID, string, 3000, 1);
   
    new pIPp[16];
    GetPlayerIp(playerid, pIPp, sizeof(pIPp));
    PlayerInfo[ID][pIP] =pIPp;
    new INI:File = INI_Open(UserPath(ID));
    INI_SetTag(File,"Player's Data");
    INI_WriteString(File,"IP",pIPp);
    INI_WriteString(File,"BanReason",cmdreason);
    INI_WriteInt(File,"Banned",1);
    INI_Close(File);
    PlayerInfo[ID][pBanned] =1;

    format(string,sizeof(string),"[BANNED] An Administrator has banned you from the server. [Reason: %s]",cmdreason);
    SendClientMessage(ID,COLOR_RED,string);

    format(string,sizeof(string),"[ADMIN BAN] Administrator has banned %s(%d). [Reason: %s]",tname,ID,cmdreason);
    SendClientMessageToAll(COLOR_PINK,string);

    format(string,sizeof(string),"1[ADMIN BAN] Administrator has kicked banned. [Reason: %s]",tname,ID,cmdreason);
    IRC_GroupSay(gGroupID,IRC_CHANNEL,string);

    format(string,sizeof(string),"[ADMIN RADIO] Administrator %s(%d) has banned %s(%d). [Reason: %s]",pname,playerid,tname,ID,cmdreason);
    SendAdminMessage(COLOR_PINK,string);
    IRC_GroupSay(gGroupID,IRC_ADMINCHANNEL,string);
    SetTimerEx("KickPlayer",1000,false,"i",ID);
    return 1;
}
Код:
[Player's Data]
Password = 310641585
Cash = 0
Score = 0
Donator = 0
Admin = 0
Heals = 0
Kills = 0
Deaths = 0
IPBanned = 0
NameBanned = 0
IP = 41.130.xx.xx
BanReason = 
Banned = 1
I need to configure if there is IP in the .ini, then player is banned
and also the BanReason isn't written correctly..

Any help?
Reply
#2

The way I would do this is by checking if any text has been entered in 'cmdreason'.

You can check this by the sample of code written below. You can also set a max size of the string length so it's not cut off if people enter a message longer than 100 characters by using strlen.
PHP код:
if (isnull(cmdreason)) // Checking if any reason is entered.
        
return false// Returns a false value 
Going back to your IP question, you can simply update the IP by saving the new one every time the player disconnects. This keeps an IP in the players .ini file all the time.

If you're saying that when the IP is shown in a players file, he is banned.. The 'banned' line in your .txt file is a better way of saying the player is banned, you shouldn't be detecting if an IP is shown to say if he is banned.

I don't know, I may not have understood what you have been trying to say and I am sorry if I have.

- Firewire
Reply
#3

I want to ban the player FROM the IP, waiitt, I need to make a .ini file with all banned IPs, and if a player IP matches the one listed, he is banned.. that's what I mean

any help would be appreciated
Reply
#4

Thank you so much ******
Reply
#5

what if I want to add OnPlayerConnect to read from samp.ban the time/date/reason etc?
Reply
#6

still with the BanReason not showing..
pawn Код:
dcmd_ban(playerid,params[])
{
    new string[128];
    new ID;
    new cmdreason[100];
    new pname[MAX_PLAYER_NAME];
    new tname[MAX_PLAYER_NAME];
    if(sscanf(params,"us[100]",ID,cmdreason))
    {
        SendClientMessage(playerid,COLOR_ERROR,"[USAGE] /ban (Player Name/ID) (Reason)");
        return 1;
    }
    if(!IsPlayerConnected(ID))
    {
        format(string,sizeof(string),"[ERROR] The player ID you entered is not connected to the server.");
        SendClientMessage(playerid,COLOR_RED,string);
        return 1;
    }
    if(PlayerInfo[ID][pAdmin] > PlayerInfo[playerid][pAdmin])
    {
        format(string,sizeof(string),"[ERROR] You cannot use this command on a higher administration level.");
        SendClientMessage(playerid,COLOR_RED,string);
        return 1;
    }
    GetPlayerName(playerid,pname,sizeof(pname));
    GetPlayerName(ID,tname,sizeof(tname));
    if(PlayerInfo[ID][pBanned] == 1)
    {
        format(string,sizeof(string),"[ERROR] %s(%d) is already banned from the server. [Reason: %s]",tname,ID,PlayerInfo[ID][pBanReason]);
        SendClientMessage(playerid,COLOR_RED,string);
        return 1;
    }
    if(InAdminMode[ID] == 1)
    {
        format(string,sizeof(string),"[ERROR] Admin %s(%d) is currently in admin mode.",tname,ID);
        SendClientMessage(playerid,COLOR_RED,string);
        return 1;
    }
    format(string, sizeof(string), "~r~BANNED!");
    GameTextForPlayer(ID, string, 3000, 1);

    new pIPp[16];
    GetPlayerIp(playerid, pIPp, sizeof(pIPp));
    PlayerInfo[ID][pIP] =pIPp;
    new INI:File = INI_Open(UserPath(ID));
    INI_SetTag(File,"Player's Data");
    INI_WriteString(File,"IP",pIPp);
    INI_WriteString(File,"BanReason",cmdreason);
    INI_Close(File);
    PlayerInfo[ID][pBanned] =1;

    format(string,sizeof(string),"[BANNED] An Administrator has banned you from the server. [Reason: %s]",cmdreason);
    SendClientMessage(ID,COLOR_RED,string);
    SetTimerEx("KickPlayer",1000,false,"i",ID);
   
    format(string,sizeof(string),"[ADMIN BAN] Administrator has banned %s(%d). [Reason: %s]",tname,ID,cmdreason);
    SendClientMessageToAll(COLOR_PINK,string);

    format(string,sizeof(string),"1[ADMIN BAN] Administrator has kicked banned. [Reason: %s]",tname,ID,cmdreason);
    IRC_GroupSay(gGroupID,IRC_CHANNEL,string);

    format(string,sizeof(string),"[ADMIN RADIO] Administrator %s(%d) has banned %s(%d). [Reason: %s]",pname,playerid,tname,ID,cmdreason);
    SendAdminMessage(COLOR_PINK,string);
    IRC_GroupSay(gGroupID,IRC_ADMINCHANNEL,string);
    return 1;
}
//=======================================================================//
public OnPlayerConnect(playerid)
{
    new string[128];
    new pname[24];
    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        if(PlayerInfo[playerid][pBanned] == 1)
        {
          format(string,sizeof(string),"[BANNED] You are currently banned from the server. [Reason: %s]",PlayerInfo[playerid][pBanReason]);  //Reason isn't shown, and in the .ini it's written normally
          SendClientMessage(playerid, COLOR_RED,string);
          SendClientMessage(playerid, COLOR_RED,"[BANNED] Please Ban Appeal on our forums at www.trd.com");
          SetTimerEx("KickPlayer",1000,false,"i",playerid);
          return 1;
        }
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"{FF0000}The Real Deathmactch","{FFFFFF}Welcome back to the server! \n Type your password below to login.","Login","Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_WELCOMERULES, DIALOG_STYLE_MSGBOX, "{FF0000}Server Rules", "{FF0000}1.{FFFFFF}Listen to and obey admins.\n\n{FF0000}2.{FFFFFF}Don't spam.\n\n{FF0000}3.{FFFFFF}Team-Killing is forbidden.\n\n{FF0000}4.{FFFFFF}Never shoot Air-To-Ground missles.\n\n{FF0000}5.{FFFFFF}Do not hack or use cheats.\n\n{FF0000}6.{FFFFFF}Respect all players and admins.\n\n{FF0000}7.{FFFFFF}Never abuse a bug.\n\n{FF0000}8.{FFFFFF}Army & Gang should NEVER attack Medics.","Accept","Decline");
    }
    //OTHER CODES
    return 1;
}
Reply
#7

In the above post, you used "LoadUser_data". I prefer to use
pawn Код:
INI_ParseFile(UserPath(playerid), "LoadUser_data", .bExtra = true, .extra = playerid);
Also, in the LoadUser_data I'm not seeing the function getting the banned reason. You must not only write the ban reason but also load it.
Reply
#8

Whats the difference between
pawn Код:
INI_ParseFile(UserPath(playerid), "LoadUser_data", .bExtra = true, .extra = playerid); //yours
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid); //mine
@Lordz, and also when I add this line to LoadUser
pawn Код:
INI_Int("BanReason",PlayerInfo[playerid][pBanReason]);
It doesn't get loaded, same
Reply
#9

I'm still down to number two, Why isn't the reason getting called?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)