Correct Method of subnet banning?

Started by Mötley, May 20, 2016, 02:20 PM

Previous topic - Next topic

Mötley

Okay I have never built a subnet ban so It is complicating for me to do it correctly.

What I have currently is a little junked as they are still in a beta forum.
Everything works just fine I could just use help and pointers. as I am not to knowing on subbans


The Command

    if ( cmd == "subban" ) {
      if ( !text ) {
MessagePlayer( "[Syntax] - /" + cmd + " <Nick/ID> <Reason>", player );
         return true;
      }
 
      local plr = FindPlayer(text.tointeger());
     
      if ( !plr ) {
        MessagePlayer( "[Error] - Unknown Player..", player );
        return true;
      }
 
      local params = split(plr.IP, ".");
      params[ 0 ].tointeger ( );
      params[ 1 ].tointeger ( );
      params[ 2 ].tointeger ( );

      Language("English", "Administrator " + player.Name + " Banned " + plr.Name, player, Red );
      Language("Spanish", "Administracion " + player.Name + " Prohibido subred " + plr.Name, player, Red );
      BanSubnet ( params[ 0 ], params[ 1 ], params[ 2 ] );
      KickPlayer( plr );
      return true;
    }

Unfortunetly in the next part I am using Ini as I cant seem to configure a way to add each splinted IP into hashes.
function BanSubnet ( A, B, C ) {

local Final = A + "." + B + "." + C + ".*";

WriteIniInteger ( "Subnets.ini", Final, "1", A.tointeger ( ) );
WriteIniInteger ( "Subnets.ini", Final, "2", B.tointeger ( ) );
WriteIniInteger ( "Subnets.ini", Final, "3", C.tointeger ( ) );
}

And the subnet added to file
[192.168.19.*]
1                              = 192
2                              = 168
3                              = 19

**If you have other method/idea's that are not related to sqlite please let me know as I want to remove ini

The next part is part of the player joining processes

function onPlayerJoin( player ) {
local params = split(player.IP, ".");
params[ 0 ].tointeger ( );
params[ 1 ].tointeger ( );
params[ 2 ].tointeger ( );
local Final = params[ 0 ] + "." + params[ 1 ] + "." + params[ 2 ] + ".*";

if ( params[ 0 ] = ReadIniInteger ( "Subnets.ini", Final, "1" ) )
{

if ( params[ 1 ] = ReadIniInteger ( "Subnets.ini", Final, "2" ) )
{

if ( params[ 2 ] = ReadIniInteger ( "Subnets.ini", Final, "3" ) )
{

ClientMessage("This subnet IP is banned from here!",player,225,0,0);
KickPlayer ( player );
}
}
    }
}
I feel that I am doing a lot wrong on player join as there is a lot that I do not agree with as the methods I used where not that great. Any communication on better/correct ways are appericiated

Thijn

First of all, .tointeger() returns an int. It doesn't change the original value. So these snippets are completely useless and do nothing:
params[ 0 ].tointeger ( );
 params[ 1 ].tointeger ( );
 params[ 2 ].tointeger ( );

Secondly, I would save the subnet as a string all attached. The same way you call your INI group: 123.123.123.*
On join you'd only need to get that 1 string, and compare it.

Mötley

Wow!. Thanks Thijn I knew somethings were Incorrect(but the subnet works for some reason.)
I will continue to play with this real soon,.
I want to format the entire subnet into one line and retrieve it some how so I could convert the subnet's into hashes which is a really fun goal I am aiming for as it's possible,.. But I have never seen it only in sq_Lite scripting, and I just do not know if hashes can retrieve data like that,
I think it would have to be formatted i think and added and received specially, As well I would have to configure a name for the hash( maybe same style [192.168.19.*]
with maybe

[192.168.19.*] "+Reason+" just a wack example as if i add the players name if the player did a evade and had another VPN or another location etc it would just overwrite the other hash save of the subnet, so I have to chose wisely, I should of looked into snippets before building this as I have never done sub bans as everyone else knows it's best to not use as many players could be banned, so I prefer to not use, This is just for a release of hashing.

DizzasTeR

local player_ip = "123.456.789.101";
local ipsplit = split( player_ip, "." );
local subnet = ipsplit[0] + "." + ipsplit[1];
// BanSubnet( subnet, reason, admin, /* your other arguments */ );

// Now when a player joins
function onPlayerJoin( player ) {
    local ipsplit = split( player.IP, "." );
    local subnet = ipsplit[0] + "." + ipsplit[1];
    /* Check if 'subnet' exists in banned subnet records */
    /* if any subnet like above exists in banned records, then kick the player, otherwise allow */
}

Mötley

Thank you @Doom_Kill3R I will modify this version a little.
My problem is since I went back to the beginning of where I started hashes I began to get old scripting methods mixed with my newer methods instead of using valid scripting methods so this has been a odd build as well an extreme experience on where my scripting has gotten today. I will play with that code before I go to work and attempt to post what I currently have.


ysc3839

Quote from: Doom_Kill3R on May 20, 2016, 05:34 PMlocal player_ip = "123.456.789.101";
local ipsplit = split( player_ip, "." );
local subnet = ipsplit[0] + "." + ipsplit[1];
// BanSubnet( subnet, reason, admin, /* your other arguments */ );

// Now when a player joins
function onPlayerJoin( player ) {
    local ipsplit = split( player.IP, "." );
    local subnet = ipsplit[0] + "." + ipsplit[1];
    /* Check if 'subnet' exists in banned subnet records */
    /* if any subnet like above exists in banned records, then kick the player, otherwise allow */
}
You should check IP in the "onLoginAttempt".

Mötley

@ysc3839 at first I thought the idea seemed a little odd until I thought on the fact of I am already locking players out of spawning into the server unless there account is activated.
This could prevent awful kick usages as the ban kick could be to fast onPlayerJoin(player); kicking wrongful players. as well opens a debate on there subnet. and other reasons.


http://forum.vc-mp.org/?topic=346.msg2107#msg2107

I read Into Diego^ version and noticed a lot of mess ups I currently did,
As well he only gets two sections of the ip which is a VERY strong subnet ban. maybe my version is more accurate and less harsh or my version is just plain out sucks

His ip usage
 000.000Mine
000.000.00

I will leave that up to others to respond,
I have been working on something very interesting and might post some codes out late tomorrow.
And I think this should work with hashes but I am not to sure.

ysc3839

Quote from: Mötley on May 21, 2016, 04:16 AM@ysc3839 at first I thought the idea seemed a little odd until I thought on the fact of I am already locking players out of spawning into the server unless there account is activated.
This could prevent awful kick usages as the ban kick could be to fast onPlayerJoin(player); kicking wrongful players. as well opens a debate on there subnet. and other reasons.


http://forum.vc-mp.org/?topic=346.msg2107#msg2107

I read Into Diego^ version and noticed a lot of mess ups I currently did,
As well he only gets two sections of the ip which is a VERY strong subnet ban. maybe my version is more accurate and less harsh or my version is just plain out sucks

His ip usage
 000.000Mine
000.000.00

I will leave that up to others to respond,
I have been working on something very interesting and might post some codes out late tomorrow.
And I think this should work with hashes but I am not to sure.
I don't understand what you say. :(

KAKAN

Quote from: Mötley on May 21, 2016, 04:16 AM@ysc3839 at first I thought the idea seemed a little odd until I thought on the fact of I am already locking players out of spawning into the server unless there account is activated.
This could prevent awful kick usages as the ban kick could be to fast onPlayerJoin(player); kicking wrongful players. as well opens a debate on there subnet. and other reasons.


http://forum.vc-mp.org/?topic=346.msg2107#msg2107

I read Into Diego^ version and noticed a lot of mess ups I currently did,
As well he only gets two sections of the ip which is a VERY strong subnet ban. maybe my version is more accurate and less harsh or my version is just plain out sucks

His ip usage
 000.000Mine
000.000.00

I will leave that up to others to respond,
I have been working on something very interesting and might post some codes out late tomorrow.
And I think this should work with hashes but I am not to sure.
That's what subnet is.
it should be: 000.000
Today, my ip is: 117.203.210.148
After some time, it might be: 117.203.212.168
Here, your subnet ban will fail as the 3rd ip is changed, which in first was 210, and in second, was 212.
The subnet might change, but not frequently.
And the subnet in my IP is: 117.203
Hope you get it :)
oh no

Mötley

#9
Now I considered not beta, But I have not added Message all to language support so for now I am using MessagePlayer until I add the support for languange

Command
   if ( cmd == "sub" ) {
     if ((Level < AdminFlagTypes.Sub)) {
       UnknownCommand(player);
       return true;
     }     

    if ( !text ) {
       Language("English", "Subnet ban player: /sub [id]", player, Red );
       Language("Spanish", "Subred jugador prohibición: / sub [id]", player, Red );
       return true;
     }
 
     local plr = FindPlayer(text.tointeger());
 
     if ( !plr ) {
       Language("English", "[Player.ID] " + text + " is not online.", player, Red );
       Language("Spanish", "[Player.ID] " + text + " no esta en linea.", player, Red );
       return true;
     }

     local ip = plr.IP;
     local sub = split( ip, "." );
     HAdd( "HSH_IP", plr.Name + " IP", "" + sub[0].tofloat() + "." + sub[1].tofloat() + "" );
     Language("English", "Administrator " + player.Name + " Banned " + plr.Name, player, Red );
     Language("Spanish", "Administracion " + player.Name + " Prohibido subred " + plr.Name, player, Red );
     KickPlayer( plr );
   
     return true;
    }   

On Join
function onPlayerJoin( player )
{
  local ipsplit = split( player.IP, "." );
  local sub = ipsplit[0] + "." + ipsplit[1];
  local q = HGet( "HSH_IP", player + " IP" );
  if ((sub) == q ) {
    Language("English", "You were caught in a mass subnet", player, Red);
    Language("Spanish", "Fueron capturados en una subred de masas", player, Red);
    KickPlayer( player );
    return true;
  }
 
  Account[ player.ID ] = Player( player );
}
Any pointers?
Other than not message.
It made more sense when I read a different version
I still need to add the IP where HGet player is. so there more accurate of course


New out put of the hash subnet, since The other way is to get the players name then the subnet now it matches the subnet then reads the subnet,

192.168 [Subnet]
192.168

KAKAN

off-topic: Well, I'll give you a good suggestion, instead of having 2 lines of the function Language everywhere, just use this function:-
function Lang( player, TextInEnglish, TextInSpanish )
{
  local lang = stats[ player.ID ].Language; //change it to whatever you want.
  switch( lang.tolower() )
  {
    case "english": return MessagePlayer( TextInEnglish, player );
    case "spanish": return MessagePlayer( TextInSpanish, player );
    default: break;
   }
}
Just an example, use it how you like :)
oh no

ysc3839

Quote from: KAKAN on May 22, 2016, 01:59 AMoff-topic: Well, I'll give you a good suggestion, instead of having 2 lines of the function Language everywhere, just use this function:-
function Lang( player, TextInEnglish, TextInSpanish )
{
  local lang = stats[ player.ID ].Language; //change it to whatever you want.
  switch( lang.tolower() )
  {
    case "english": return MessagePlayer( TextInEnglish, player );
    case "spanish": return MessagePlayer( TextInSpanish, player );
    default: break;
   }
}
Just an example, use it how you like :)
I think this code isn't very good. You should store language strings in language files. You can see the "GNU gettext".