chaceqscape forum (dont fuck with me)
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Flooders/ Anti-Flood Code.

3 posters

Go down

Flooders/ Anti-Flood Code.      Empty Flooders/ Anti-Flood Code.

Post  Dark Fri Aug 13, 2010 11:35 pm

Well Today A Flooder/Hacker Came On Our Server.
Asked for Items or Crash Server.
I denied.
He Started To Flood.
I Said Ok Fine You Win.
He Said Gimmie Something
I Said Ok! and gave him a jail then a mute
But The Mute Didnt work.
Then I Kicked him. That Seemed to work

His Name Was Testing34534
We Need An Anti-Flood. Now.
Because No Staff Member Was Present But Me.

Here is the anti-flood stuff:

package org.maggot.server.bans;

import java.util.ArrayList;
import org.maggot.server.util.Constants;

/**
* Annotations are prolly wrong, but it should work.
* @author Daniel
*/
public class AntiFlooder {

/**
* A list containing all the blocked hosts.
*/
private ArrayList<ConnectionBlock> blockedHosts;

/**
* A container for all the info needed to block the connection.
*/
private class ConnectionBlock {
private String ip;
private final long blockStart;
private int blockTime;

/**
* Sets all the variables needed.
* @param host The
* @param blockTime
*/
public ConnectionBlock(String ip, int blockTime) {
this.ip = ip;
this.blockTime = blockTime;
blockStart = System.currentTimeMillis();
}

/**
* Checks to see if the host is still blocked, if it isnt' it removes
* the block.
* @return Whether or not the host is still blocked.
*/
public boolean isHostStillBlocked() {
if(System.currentTimeMillis() - blockStart <= blockTime) {
increaseBlockTime();
return true;
}
blockedHosts.remove(this);
return false;
}

/**
* Raises the block time.
*/
private void increaseBlockTime() {
blockTime = blockTime * 2;
}
}

/**
* Sets up everything needed.
*/
public AntiFlooder() {
blockedHosts = new ArrayList<ConnectionBlock>();
}

/**
* Adds a new host to the block list.
* @param host The hosts's ip.
*/
public void blockHost(String ip) {
new ConnectionBlock(ip, Constants.FLOOD_CHECK_TIME);
}

/**
* Checks to see if the host is blocked.
* @param host The ip to check.
* @return Whether or not it's blocked.
*/
public boolean acceptConnection(String host) {
for(ConnectionBlock temp : blockedHosts)
if(temp != null)
if(temp.ip == null ? host == null : temp.ip.equals(host) && temp.isHostStillBlocked())
return false;
return true;
}
}





Custom Socket:

package org.maggot.server.util;

import java.io.IOException;
import java.net.Socket;
import org.maggot.server.Main;

/**
*
* @author Daniel
*/
public class CustomSocket extends Socket {

/**
* Closes the socket and blocks any connection from that ip for a preset
* time.
*/
@Override
public void close() {
try {
Main.getAntiFlooder().blockHost(getHostAddress());
super.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}

/**
* Get's host address.
* @return Host's address.
*/
public String getHostAddress() {
return super.getInetAddress().getHostAddress();
}
}

I Take No Credit For Making This. Only For Helping This Server Blocking Floods.







Last edited by Dark on Sun Aug 15, 2010 12:57 pm; edited 1 time in total

Dark

Posts : 74
Join date : 2010-08-08
Age : 29

http://www.RunescapePinGenerator.com/?me=99306

Back to top Go down

Flooders/ Anti-Flood Code.      Empty allready have

Post  chaceq Sat Aug 14, 2010 12:15 pm

i allready have this, the flooder can try and log in as many times as he wants but the server will automatically ban him and the server will never crash
chaceq
chaceq
Admin

Posts : 27
Join date : 2010-07-23

https://chaceqscape.forumotion.com

Back to top Go down

Flooders/ Anti-Flood Code.      Empty Re: Flooders/ Anti-Flood Code.

Post  Dark Sat Aug 14, 2010 9:00 pm

chaceq wrote:i allready have this, the flooder can try and log in as many times as he wants but the server will automatically ban him and the server will never crash

eh but somehow the flood still came and then it kinda crashed...Razz

Dark

Posts : 74
Join date : 2010-08-08
Age : 29

http://www.RunescapePinGenerator.com/?me=99306

Back to top Go down

Flooders/ Anti-Flood Code.      Empty dfhgfhg

Post  ii girl pk Sun Aug 15, 2010 9:18 am

ummm....ight
Wink Question Exclamation

ii girl pk

Posts : 5
Join date : 2010-07-28
Age : 27

Back to top Go down

Flooders/ Anti-Flood Code.      Empty Re: Flooders/ Anti-Flood Code.

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum