SA-MP Forums Archive
Any way to make this faster? - 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: Any way to make this faster? (/showthread.php?tid=594947)



Any way to make this faster? - MafiaOink - 26.11.2015

So this is my Range Banning code:
Код:
stock BanRange(l1)
{
    printf("[BanRange] Banning Range Starting from: %d", l1);
	new docmd[128], ipttl[128];
	for(new i=1;i<256;i++)
	{
		for(new b=0;b<256;b++)
		{
		    for(new c=0;c<256;c++)
		    {
			    format(ipttl, sizeof(ipttl), "%d.%d.%d.%d", l1, i, b, c);
			    format(docmd, 128, "banip %s", ipttl);
			    SendRconCommand(docmd);
			}
		}
	}
	return 1;
}
Its slow and it would take hours to ban one range..
Anyway to make it more faster? or optimize it?


Re: Any way to make this faster? - jamesbond007 - 26.11.2015

cant u do 123.*.*.* and it bans all?


Re: Any way to make this faster? - iKarim - 26.11.2015

This would ban all ips lol, you're looping through 256 ip part inside a 256 loop both inside 256 loop which loops through: 16777216 ip part. impossible to do this, and your code isn't a range ban code, it bans each n every ip.


Re: Any way to make this faster? - cawfee - 26.11.2015

Provided you're using sscanf and zcmd, you could always use this:

Код:
CMD:banip(playerid, params[])
{
	new given_ip[16];
	if(sscanf(params, "s[16]", given_ip))
	{
	     // Invalid input...
	    return false;
	}

        new str[25];
	str = "banip ";
	strcat(str, given_ip);
	SendRconCommand(str);
	return true;
}



Re: Any way to make this faster? - MafiaOink - 26.11.2015

Quote:
Originally Posted by PawnHunter
Посмотреть сообщение
This would ban all ips lol, you're looping through 256 ip part inside a 256 loop both inside 256 loop which loops through: 16777216 ip part. impossible to do this, and your code isn't a range ban code, it bans each n every ip.
It dosent ban each and every IP..
It will ban all the IPs under the first line e.g. 192

and cawfee

You cant directly set a string, You have to format it.
So that would return errors

+ The hell? ip isn't even declared on that command so it would basically send this: "banip " with no parameters.


Re: Any way to make this faster? - iKarim - 26.11.2015

You can't ban IPs like that, can you explain me your code?
All I can see this loops banning 11.*.*.*
{11.1.1.1, 11.1.1.2, 11.1.1.3, etc etc etc, 11.255.255.255}
and you're looping through 16777216 ip part.


Re: Any way to make this faster? - cawfee - 26.11.2015

Quote:
Originally Posted by MafiaOink
Посмотреть сообщение
It dosent ban each and every IP..
It will ban all the IPs under the first line e.g. 192

and cawfee

You cant directly set a string, You have to format it.
So that would return errors

+ The hell? ip isn't even declared on that command so it would basically send this: "banip " with no parameters.
My bad. Try it now. And by the way, format is not required in this case. Eliminating the need for format actually makes it slightly faster too.


Re: Any way to make this faster? - iKarim - 26.11.2015

If you can't make your own range ban system, use RCON.
Quote:

/rcon banip [ip/iprange]

Use: /rcon banip 11.*.*.*, and none of this range will be able to access server.


Re: Any way to make this faster? - Vince - 26.11.2015

An entire class A range should never be range banned as that is way too broad. A class A range is in most cases shared by several different countries.

The 192 class A range (192.0.0.0 through 192.255.255.255) is in fact shared - and I'm not making this up - by no less than 104 different countries. Here's the top 5:

CountryNumer of IP addresses
United States11247369
Canada924255
Finland488406
Japan392666
Sweden337251



Re: Any way to make this faster? - Jefff - 26.11.2015

Loled
pawn Код:
stock BanRange(l1)
{
    new str[16];
    printf("[BanRange] Banning Range Starting from: %d", l1);
    format(str, sizeof(str), "banip %d.*.*.*", l1);
    SendRconCommand(str);
    return 1;
}
? xD