SA-MP Forums Archive
Filescripts Antiddos please !! - 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: Filescripts Antiddos please !! (/showthread.php?tid=589552)



Filescripts Antiddos please !! - skiplovebra - 20.09.2015

This is my code a little searching on the Internet and write another useful someone can see it is correct and what needs further ?? Here is the code by writing and his Markoni added
Код:
#include <a_samp>
#include <FileFunctions>

#define ATTACK_TYPE_PLAYERID 1
#define ATTACK_TYPE_IP 2

new File:ServerLogFile;
new addostimer;

main()
{
	print("|----------------------------------|");
	print("| Anti DDOS Attack   © 2013      |");
	print("|            by Markoni            |");
	print("|----------------------------------|");
}

public OnFilterScriptInit()
{
	ServerLogFile = fileOpen("server_log.txt", io_Read);
	addostimer = SetTimer("AntiDDoS", 100, true);
	return 1;
}

public OnFilterScriptExit()
{
	KillTimer(addostimer);
	return 1;
}

forward AntiDDoS();
public AntiDDoS()
{
	if(!ServerLogFile)
	{
		print("DDosProtect FS: Error opening server_log.txt!");
		KillTimer(addostimer);
	}
	else
	{
		new string[128];
		new strarr[2][20];
		fileSeek(ServerLogFile, -128, seek_End);
		while(fileRead(ServerLogFile, string)){}// только последнюю строку

		new pos = strfind(string, "Invalid client connecting from ", true, 10);
		if(pos == 11)
		{
			OnDDosAttackAttempt(ATTACK_TYPE_IP, INVALID_PLAYER_ID, string[pos+31]);
		}

		pos = strfind(string, "Warning: /rcon command exploit from: ", true, 10);
		if(pos == 11){
			split(string[pos+37], strarr, ':');
			OnDDosAttackAttempt(ATTACK_TYPE_PLAYERID, strval(strarr[0]), strarr[1]);
		}

		pos = strfind(string, "Warning: PlayerDialogResponse PlayerId: ", true, 10);
		if(pos == 11){
			// Бывают случаи ложного срабатывания, реакция не на первое срабатывание
			new idx = 0;
			new plid = strval(strtok(string[pos+39], idx));
			SetPVarInt(plid, "dialogDDosAtt", GetPVarInt(plid, "dialogDDosAtt")+1);
			print("");
			if(GetPVarInt(plid, "dialogDDosAtt") > 2)OnDDosAttackAttempt(ATTACK_TYPE_PLAYERID, plid, " ");
		}

		pos = strfind(string, "Warning: PlayerDialogResponse crash exploit from PlayerId: ", true, 10);
		if(pos == 11){
			new idx = 0;
			OnDDosAttackAttempt(ATTACK_TYPE_PLAYERID, strval(strtok(string[pos+59], idx)), " ");
		}

		pos = strfind(string, "Packet was modified, sent by id: ", true, 10);
		if(pos == 11){
		    split(string[pos+33], strarr, ',');
			OnDDosAttackAttempt(ATTACK_TYPE_PLAYERID, strval(strarr[0]), " ");
		}

		pos = strfind(string, "Remote Port Refused for Player: ", true, 10);
		if(pos == 11){
			new idx = 0;
			OnDDosAttackAttempt(ATTACK_TYPE_PLAYERID, strval(strtok(string[pos+32], idx)), " ");
		}

		if(strfind(string, " due to a 'server full' attack") != -1)
		{
			pos = strfind(string, "Blocking ", true, 10);
			if(pos == 12)
			{
				new idx = 0;
				OnDDosAttackAttempt(ATTACK_TYPE_IP, INVALID_PLAYER_ID, strtok(string[pos+9], idx));
			}
		}
	}
}

forward OnDDosAttackAttempt(type, playerid, ip[]);
public OnDDosAttackAttempt(type, playerid, ip[])
{
    new string[128];
	if(type == ATTACK_TYPE_PLAYERID)
	{//block a playerid
		BanEx(playerid, "DDOS protect");
		printf("DDosProtect FS: Blocked attack from playerid %d", playerid);

	}else if(type == ATTACK_TYPE_IP)
	{//block an ip address
        format(string, sizeof(string), "banip %s", ip);
		SendRconCommand(string);
		printf("DDosProtect FS: Blocked attack from ip: %s", ip);
	}
	// printf лучше не удалять, чтобы не вызвать повторного срабатывания
}

stock strtok(const string[], &index)
{
	new length = strlen(string);
	while ((index < length) && (string[index] <= ' '))
	{
		index++;
	}

	new offset = index;
	new result[20];
	while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
	{
		result[index - offset] = string[index];
		index++;
	}
	result[index - offset] = EOS;
	return result;
}

stock split(const strsrc[], strdest[][], delimiter)
{
	new i, li;
	new aNum;
	new len;
	while(i <= strlen(strsrc)){
		if(strsrc[i]==delimiter || i==strlen(strsrc)){
			len = strmid(strdest[aNum], strsrc, li, i, 128);
			strdest[aNum][len] = 0;
			li = i+1;
			aNum++;
		}
		i++;
	}
	return 1;
}

// © MazaHACKa;



Re: Filescripts Antiddos please !! - M0HAMMAD - 20.09.2015

if your getting ddos add a port on your vps like: IP:PORT and install anti ddos on your vps.
it's better !


Re: Filescripts Antiddos please !! - skiplovebra - 20.09.2015

Quote:
Originally Posted by M0HAMMAD
Посмотреть сообщение
if your getting ddos add a port on your vps like: IP:PORT and install anti ddos on your vps.
it's better !
reviews you say I do not understand?


Re : Filescripts Antiddos please !! - KillerDVX - 20.09.2015

A filterscript cannot stop DDOS, as M0HAMMAD said, you should add more farewall to your vps to lower the attacks.


Re: Filescripts Antiddos please !! - Lordzy - 20.09.2015

Purchase a DDoS protected VPS or game-server, this filterscript won't help you get rid of DDoS attacks.


Re: Filescripts Antiddos please !! - skiplovebra - 20.09.2015

There are many anti-DDoS server in Vietnam by filescripts very effective.


Re : Filescripts Antiddos please !! - KillerDVX - 20.09.2015

No, how could a filterscript protect your server dude ?


Re: Re : Filescripts Antiddos please !! - skiplovebra - 20.09.2015

Quote:
Originally Posted by KillerDVX
Посмотреть сообщение
No, how could a filterscript protect your server dude ?
Since their servers in Vietnam should not know where rent and anti-DDoS firewall how you spend vps win 2008


Re: Filescripts Antiddos please !! - NexySamp - 20.09.2015

A FS wont help your server from getting atacked.You need to get a ddos protected server hosting.FS can stop join floods or boot spawners etc...