DragonDagger 317
Welcome to DragonDagger's Official Forums!
Enjoy your stay.
DragonDagger 317
Welcome to DragonDagger's Official Forums!
Enjoy your stay.
DragonDagger 317
Would you like to react to this message? Create an account in a few clicks or log in to continue.

DragonDagger 317

DragonDagger's Official Forums
 
HomeDDLatest imagesSearchRegisterLog in
Donations welcomed, we're trying to get the golden server position on runelocus server status page!
Webclient is OUT! Click Play Now in the Forums Homepage

 

 stop fake connections/syi/null 2 i think

Go down 
+4
shawn
pker for ev
l0ve
angelife
8 posters
AuthorMessage
angelife
Global Administrator
Global Administrator
angelife


DD Posts DD Posts : 173
Join date : 2009-08-06
Age : 28
Location : farmington CT

stop fake connections/syi/null 2 i think Empty
PostSubject: stop fake connections/syi/null 2 i think   stop fake connections/syi/null 2 i think I_icon_minitimeSat Aug 08, 2009 3:56 pm

ConnectionFilter.java
----------------------------

What does this do?
This ConnectionFilter will filter out fast and normal client connection speeds usually if you connect 3 or more times within 10ms it's not a real client. So if that does happen it will temporarily ban that hostname until it is done flooding the server. With the extra features i added, like the isWasFlooder will print in the server if a person logs on in a real client and they have tryed to flood the server before, so you will know they tryed
Note: This tutorial is not compatible with Grahams Remove Thread-Per-Client.

Step 1
Make a new java file named ConnectionFilter.java and put this in it.

Code:
  import java.util.ArrayList;
       
        /**
        * Filters out fast and normal client connection speeds.
        * SYI/DoS Flooding Protection.
        * @author Gnarly
        *
        */
        public class ConnectionFilter
        {
       
            private static ArrayList<String> HOST_LIST = new ArrayList<String>();
            private static ArrayList<String> CONNECTIONS = new ArrayList<String>();
       
            private int cycle;
            private boolean isFlooder;
            private boolean wasFlooder;
            private boolean wasConnected;
       
            public ConnectionFilter()
            {
                System.out.println("[ConnectionFilter] - Initialized");
            }
       
            /**
            * Setter for isFlooder boolean
            * @param isFlooder
            */
            private void setFlooder(boolean isFlooder)
            {
                this.isFlooder = isFlooder;
            }
       
            /**
            * Setter for wasFlooder boolean
            * @param wasFlooder
            */
            private void setWasFlooder(boolean wasFlooder)
            {
                this.wasFlooder = wasFlooder;
            }
           
            /**
            * Setter for wasConnected boolean
            * @param wasConnected
            */
            private void setWasConnected(boolean wasConnected)
            {
                this.wasConnected = wasConnected;
            }
           
            /**
            * @return isFlooder
            */
            private boolean isFlooder()
            {
                return isFlooder;
            }
       
            /**
            * @return isWasFlooder
            */
            private boolean isWasFlooder()
            {
                return wasFlooder;
            }
           
            /**
            * @return wasConnected
            */
            @SuppressWarnings("unused")
            private boolean isWasConnected()
            {
                return wasConnected;
            }
           
            /**
            * Setter for HOST_LIST array
            * @param hOST_LIST ArrayList
            */
            public static void setHOST_LIST(ArrayList<String> hOST_LIST)
            {
                HOST_LIST = hOST_LIST;
            }
       
            /**
            * @return ArrayList HOST_LIST
            * @param getHOST_LIST ArrayList
            */
            public static ArrayList<String> getHOST_LIST()
            {
                return HOST_LIST;
            }
       
            /**
            * Setter for CONNECTIONS array
            * @param cONNECTIONS ArrayList
            */
            public static void setCONNECTIONS(ArrayList<String> cONNECTIONS)
            {
                CONNECTIONS = cONNECTIONS;
            }
       
            /**
            * @return ArrayList CONNECTIONS
            * @param getConnections ArrayList
            */
            public static ArrayList<String> getCONNECTIONS()
            {
                return CONNECTIONS;
            }
       
            /**
            * Adds a hostname to the HOST_LIST array list
            * @param host String
            */
            public void add(String host)
            {
                System.out.println((new StringBuilder("[ConnectionFilter] Temporarily banning ")).append(host).append(" (Massive Connecting Flooding)").toString());
                getHOST_LIST().add(host);
            }
       
            /**
            * Checks for any blocked hostnames
            * @param host String
            */
            public boolean blocked(String host)
            {
                for (String h : HOST_LIST)
                {
                    if (h.equals(host))
                        return true;
                }
               
                int n = 0;
                for (String h : CONNECTIONS)
                {
                    if (host.equals(h))
                    {
                        n++;
                    }
                }
               
                if (n > 2)
                {
                    add(host);
                    setFlooder(true);
                    return true;
                }
               
                if(isFlooder())
                    return true;
               
                if(isWasFlooder())
                {
                    /* Handle anything you want to do to a person that tryed flooding the server in the past. */
                }
                return false;
            }
       
            /**
            * 500ms Process, used for clearing out the array's after a given time in the cycle
            */
            public void process()
            {
                if(cycle % 10 == 0)
                {
                    getCONNECTIONS().clear();
                    setWasConnected(true);
                }
                if(cycle % 500 == 0)
                {
                    getHOST_LIST().clear();
                    setFlooder(false);
                    setWasFlooder(true);
                }
                if(cycle > 10000)
                {
                    cycle = 0;
                }
                cycle++;
            }
       
        }

Step 2
Open Server.java.

2.1)
declare
Code:
public static ConnectionFilter ConnectionFilter = null;
this makes the filter a static class

2.2)
under
Code:
public static void main(String args[]) {

add
Code:
ConnectionFilter = new ConnectionFilter();
this will start the connectionfilter when the server starts

2.3)
find
Code:
while(!shutdownServer) {
under it add
Code:
ConnectionFilter.process();
This will make the process() method in ConnectionFilter run at 500ms

2.4)
find
Code:
playerHandler.newPlayerClient(s, connectingHost);
above it add
Code:
if(!ConnectionFilter.blocked(connectingHost)) {
and under it add
Code:
} else
{
    System.out.println("[ConnectionFilter] Rejected "+connectingHost+" [Massive flooding]");
    s.close();
    System.gc();
}

System.out.println() will print in the server console
s.close(); will close the current socket the player used.
System.gc(); is gc > garbage collect and will collect unused garbage from your RAM that the server used.
That basicly is checking to see if the connecting host is NOT blocked (the ! is saying "if is not") . And if it is it will add the new player.
Now save and close Server.java

Step 3
Open playerHandler.java and find
Code:
newPlayerClient
and scroll down a little bit untill you find
Code:
(new Thread(newClient)).start();

and under it add
Code:
ConnectionFilter.getCONNECTIONS().add(connectedFrom);

This will remove the host from the connections array if the player gets disconnected.
Now save and close playerHandler.java

remember to back up your files!

-owlfanatic77
Back to top Go down
l0ve
Junior Member
l0ve


DD Posts DD Posts : 43
Join date : 2009-08-08
Age : 31
Location : New Zealand

stop fake connections/syi/null 2 i think Empty
PostSubject: Re: stop fake connections/syi/null 2 i think   stop fake connections/syi/null 2 i think I_icon_minitimeSat Aug 08, 2009 4:11 pm

o.O someone knows their coding :p nice guide i hope it gets added
Back to top Go down
pker for ev
Global Moderator
Global Moderator
pker for ev


DD Posts DD Posts : 365
Join date : 2009-07-21
Age : 28
Location : Hood River OR

stop fake connections/syi/null 2 i think Empty
PostSubject: Re: stop fake connections/syi/null 2 i think   stop fake connections/syi/null 2 i think I_icon_minitimeTue Aug 11, 2009 12:53 am

this is yet another good guide for arti so i hope it helps but i gtg to bed i need to get up early so im going to bed night!
Back to top Go down
shawn
Haxor IRL
shawn


DD Posts DD Posts : 214
Join date : 2009-08-01
Age : 57
Location : Washington State

stop fake connections/syi/null 2 i think Empty
PostSubject: Re: stop fake connections/syi/null 2 i think   stop fake connections/syi/null 2 i think I_icon_minitimeTue Aug 11, 2009 2:25 pm

Thanks dude this is going to help the server out alot.
Back to top Go down
im real pb
Senior Member
im real pb


DD Posts DD Posts : 110
Join date : 2009-07-29

stop fake connections/syi/null 2 i think Empty
PostSubject: Re: stop fake connections/syi/null 2 i think   stop fake connections/syi/null 2 i think I_icon_minitimeWed Aug 12, 2009 10:13 am

wow owl your a good coder XD
Back to top Go down
bllc!
Haxor IRL
bllc!


DD Posts DD Posts : 235
Join date : 2009-08-12

stop fake connections/syi/null 2 i think Empty
PostSubject: Re: stop fake connections/syi/null 2 i think   stop fake connections/syi/null 2 i think I_icon_minitimeThu Aug 20, 2009 9:51 pm

wow nice guide o.o


Last edited by bllc! on Wed Aug 26, 2009 2:41 pm; edited 1 time in total
Back to top Go down
Guest
Guest




stop fake connections/syi/null 2 i think Empty
PostSubject: Re: stop fake connections/syi/null 2 i think   stop fake connections/syi/null 2 i think I_icon_minitimeTue Aug 25, 2009 10:50 pm

goodjob leeching and still doesn't work very good and
Back to top Go down
angelife
Global Administrator
Global Administrator
angelife


DD Posts DD Posts : 173
Join date : 2009-08-06
Age : 28
Location : farmington CT

stop fake connections/syi/null 2 i think Empty
PostSubject: Re: stop fake connections/syi/null 2 i think   stop fake connections/syi/null 2 i think I_icon_minitimeWed Aug 26, 2009 8:52 am

Guest wrote:
goodjob leeching and still doesn't work very good and

dude get a life. if your gonna post acually register so its not all "guest this" crap-.-
Back to top Go down
pker for ev
Global Moderator
Global Moderator
pker for ev


DD Posts DD Posts : 365
Join date : 2009-07-21
Age : 28
Location : Hood River OR

stop fake connections/syi/null 2 i think Empty
PostSubject: Re: stop fake connections/syi/null 2 i think   stop fake connections/syi/null 2 i think I_icon_minitimeWed Aug 26, 2009 12:45 pm

im real pb wrote:
wow owl your a good coder XD
hell yea he is XD
Back to top Go down
The chosen 1
Junior Member



DD Posts DD Posts : 39
Join date : 2009-08-29

stop fake connections/syi/null 2 i think Empty
PostSubject: gj   stop fake connections/syi/null 2 i think I_icon_minitimeMon Aug 31, 2009 1:51 am

lol i wish i had this for meh own server Very Happy

ps:i wont use without your permission though
Back to top Go down
Get At Me
Junior Member



DD Posts DD Posts : 24
Join date : 2009-08-31

stop fake connections/syi/null 2 i think Empty
PostSubject: Re: stop fake connections/syi/null 2 i think   stop fake connections/syi/null 2 i think I_icon_minitimeThu Sep 03, 2009 7:52 am

niiiiiice, imma use this for my server when i finish it
Back to top Go down
Sponsored content





stop fake connections/syi/null 2 i think Empty
PostSubject: Re: stop fake connections/syi/null 2 i think   stop fake connections/syi/null 2 i think I_icon_minitime

Back to top Go down
 
stop fake connections/syi/null 2 i think
Back to top 
Page 1 of 1
 Similar topics
-
» null null null
» in case of null
» read for null fix (hopefully)
» How to stop lag
» stop lying!!!!

Permissions in this forum:You cannot reply to topics in this forum
DragonDagger 317  :: General :: Guide Section-
Jump to: