Thread: Limit Playername Character Amount

Page 1 of 2 12 LastLast
Results 1 to 10 of 20
  1. #1 Limit Playername Character Amount 
    Community Veteran

    Cascade's Avatar
    Join Date
    Oct 2006
    Posts
    1,023
    Thanks given
    12
    Thanks received
    27
    Rep Power
    912
    Description: This tutorial will allow you to stop players logging onto your server with a name which is deemed by the server owner too long, if they try to logon with a name which is higher than the specified limit this is logged and the account is banned, if they attempt to do this more than a specified amount of times then their IP will be banned.

    Difficulty: 2/10

    Assumed Knowledge: Not much Java knowledge needed, just need to read.

    Tested Server: Haven't actually tested it, but it should work.

    Files/Classes Modified: client class

    Procedure
    Step 1: Open your client class and declare the following

    Code:
    	public static int longNameAttempts;
    	public java.util.HashMap<String, Integer> longAttempts = new java.util.HashMap<String, Integer>();
    	public static final int MAX_CHARACTERS = 15;
    	public static final int MAX_ATTEMPTS = 5;
    I will explain each part of this.

    Code:
    	public static int longNameAttempts;
    The amount of times the user has tried to logon with a name which is too long

    Code:
    	public java.util.HashMap<String, Integer> longAttempts = new java.util.HashMap<String, Integer>();
    Declare the HashMap which will contain the users IP and also how many times they have tried to connect with a name which is too long.

    Code:
    	public static final int MAX_CHARACTERS = 15;
    The max amount of characters that is allowed on your server.

    Code:
    	public static final int MAX_ATTEMPTS = 5;
    The max times a user can "try" and logon with a name which is too long before they are IP banned.


    Step 2: Add the block which will check if the playername is too long.

    Im not going to tell you where exactly to put it but its in the client class and in the initialize method.

    Code:
                     if(playerName.length() > MAX_CHARACTERS-1) {
                    	 appendToBanned(playerName);
                    	 disconnected = true;
                    	 misc.println(new StringBuilder(playerName).append(" was disconnected and banned - " +
                    	 		"name longer than 14 characters ! (").append(connectedFrom).append(")").toString());
                    	 longAttempts.put(connectedFrom, longNameAttempts++);
                    	 
                    	 if(longAttempts.get(connectedFrom) > MAX_ATTEMPTS-1) {
                    		 appendToBannedIP(playerName);
                    		 misc.println(new StringBuilder(playerName).append(" was IP banned, used characters " +
                    		 		"longer that the allowed limit (").append(MAX_CHARACTERS).append(") " +
                    		 				"more than ").append(MAX_ATTEMPTS).append(" times.").toString());
                    		 longNameAttempts = 0;
                    	 }
                     }
    This code is pretty self explanitory but I will explain some parts.

    Code:
     if(longAttempts.get(connectedFrom) > MAX_ATTEMPTS-1) {
    If the attempts that they have made is higher than the max attempts execute this block of code.

    Code:
     longAttempts.put(connectedFrom, longNameAttempts++);
    Put the connected from and also the attempts number in the HashMap while also incrementing it.


    Credits: Me, hopefully this can be used to stop people who like to logon to the server with long names thinking that they wont be able to get banned or somthing like that, normally most clients have name length limited that way but some people edit the clients to bypass this..

    Enjoy. - Cascade/Nathanroys2008
     

  2. #2  
    Member Market Banned Market Banned


    Join Date
    Nov 2006
    Posts
    3,292
    Thanks given
    29
    Thanks received
    22
    Rep Power
    4355
    very nice
    adding it atm...
    gj
    Spoiler for Signature:



    Nick David Matt Kevin Zack Corey Jeff GOD DAMMIT
     

  3. #3  
    Registered Member
    Enjoi's Avatar
    Join Date
    Sep 2008
    Posts
    2,454
    Thanks given
    565
    Thanks received
    281
    Rep Power
    1325
    nice job, lots of people will use this

    9/10
     

  4. #4  
    ( ͡° ͜ʖ ͡°)
    Edgeville's Avatar
    Join Date
    Nov 2007
    Posts
    2,455
    Thanks given
    80
    Thanks received
    428
    Rep Power
    2589
    Nice tut Thanks for this mate

     

  5. #5  
    Member
    Join Date
    Feb 2008
    Posts
    544
    Thanks given
    1
    Thanks received
    1
    Rep Power
    0
    nice thanks alot gonna add it
    she got no monney in the bank yeah she gots no monney in the bank.
    [Only registered and activated users can see links. ]
     

  6. #6  
    Banned

    Join Date
    May 2008
    Posts
    2,327
    Thanks given
    55
    Thanks received
    67
    Rep Power
    0
    sweet lol i was looking 4 this last night cuz of this random spammer......

    how i make it ban them 4ever cuz he keeps switching his ip....

    heres a list of some of the ips hes been using and ips hes been switching etc..

    Code:
    130.139-pool-xdsl-mi.sccoast.net
    116.139-pool-xdsl-mi.sccoast.net
    75.67-212-36-net.sccoast.net
    112.141-pool-xdsl-mi.sccoast.net
    124.67-212-38-net.sccoast.net
    176.136-pool-xdsl-mi.sccoast.net
    how i ban him 4ever even if he switches ip?


    also do i add this in initialize() or run()?

    Code:
                     if(playerName.length() > MAX_CHARACTERS-1) {
                    	 appendToBanned(playerName);
                    	 disconnected = true;
                    	 misc.println(new StringBuilder(playerName).append(" was disconnected and banned - " +
                    	 		"name longer than 14 characters ! (").append(connectedFrom).append(")").toString());
                    	 longAttempts.put(connectedFrom, longNameAttempts++);
                    	 
                    	 if(longAttempts.get(connectedFrom) > MAX_ATTEMPTS-1) {
                    		 appendToBannedIP(playerName);
                    		 misc.println(new StringBuilder(playerName).append(" was IP banned, used characters " +
                    		 		"longer that the allowed limit (").append(MAX_CHARACTERS).append(") " +
                    		 				"more than ").append(MAX_ATTEMPTS).append(" times.").toString());
                    		 longNameAttempts = 0;
                    	 }
                     }
    repp++'d u, thx again (i put under initialize for now)
     

  7. #7  
    .supersyn

    myK-'s Avatar
    Join Date
    Aug 2008
    Posts
    1,778
    Thanks given
    18
    Thanks received
    39
    Rep Power
    399
    Thanks was just bout to do this saved me some time
     

  8. #8  
    Community Veteran

    Cascade's Avatar
    Join Date
    Oct 2006
    Posts
    1,023
    Thanks given
    12
    Thanks received
    27
    Rep Power
    912
    Quote Originally Posted by silabgarza View Post
    sweet lol i was looking 4 this last night cuz of this random spammer......

    how i make it ban them 4ever cuz he keeps switching his ip....

    heres a list of some of the ips hes been using and ips hes been switching etc..

    Code:
    130.139-pool-xdsl-mi.sccoast.net
    116.139-pool-xdsl-mi.sccoast.net
    75.67-212-36-net.sccoast.net
    112.141-pool-xdsl-mi.sccoast.net
    124.67-212-38-net.sccoast.net
    176.136-pool-xdsl-mi.sccoast.net
    how i ban him 4ever even if he switches ip?


    also do i add this in initialize() or run()?

    Code:
                     if(playerName.length() > MAX_CHARACTERS-1) {
                    	 appendToBanned(playerName);
                    	 disconnected = true;
                    	 misc.println(new StringBuilder(playerName).append(" was disconnected and banned - " +
                    	 		"name longer than 14 characters ! (").append(connectedFrom).append(")").toString());
                    	 longAttempts.put(connectedFrom, longNameAttempts++);
                    	 
                    	 if(longAttempts.get(connectedFrom) > MAX_ATTEMPTS-1) {
                    		 appendToBannedIP(playerName);
                    		 misc.println(new StringBuilder(playerName).append(" was IP banned, used characters " +
                    		 		"longer that the allowed limit (").append(MAX_CHARACTERS).append(") " +
                    		 				"more than ").append(MAX_ATTEMPTS).append(" times.").toString());
                    		 longNameAttempts = 0;
                    	 }
                     }
    repp++'d u, thx again (i put under initialize for now)
    Don't put it directly under the initialize void because it hasn't returned the player name at that point.. (Further Down..)


    And its not really on-topic but for the problem you are having banning the persons IP, try ;

    Code:
    if(connectedFrom.contains("sccoast")) {
                       appendToBannedIP(connectedFrom);
                       disconnected = true;
               }
     

  9. #9  
    Donator

    Divide's Avatar
    Join Date
    Dec 2007
    Age
    25
    Posts
    816
    Thanks given
    3
    Thanks received
    0
    Rep Power
    91
    Nice dude.

    ~Dangt351
    [Only registered and activated users can see links. ]

     

  10. #10  
    Expert Programmer


    Join Date
    Dec 2007
    Posts
    2,018
    Thanks given
    52
    Thanks received
    84
    Rep Power
    986
    My experience

    UltimateWorld [1] Details

    There are currently 13/120 players online!

    The server has been up for: 31 hours and 46 minutes

    Ms Lag: 0

    Players Online

    laura k0 u
    hybrid god
    mattrat
    ii noob ii
    blitz jr
    48456L8a8u8g8h8i8n8g8M8a8n8L8a8u8g8h8i8n8g8M8a8n8L 8a8u8g8h8i8n8g8M8a8n8L8a8u8g8h8i8n8g8M8a8n8L8a8u8g 8h8i8n8g8M8a8n8L8a8u8g8h8i8n8g8M8a8n8L8a8u8g8h8i8n 8g8M8a8n848456
    gomomo
    95250L8a8u8g8h8i8n8g8M8a8n8L8a8u8g8h8i8n8g8M8a8n8L 8a8u8g8h8i8n8g8M8a8n8L8a8u8g8h8i8n8g8M8a8n8L8a8u8g 8h8i8n8g8M8a8n8L8a8u8g8h8i8n8g8M8a8n8L8a8u8g8h8i8n 8g8M8a8n895250
    ko m8y
    extreme17
    monk s t rz
    10483IthoughtwhatIddowasIdpretendIwasoneofthosedea fmutesIthoughtwhatIddowasIdpretendIwasoneofthosede afmutesIthoughtwhatIddowasIdpretendIwasoneofthosed eafmutes10483
    26668468686548467846835735735763567865724563475685 78235762464575782467245642567348567234562462456456 437246724562456456472235625
    Thanks, but what difference would that hashmap make? woudlnt

    Nice job I might use it stops hack attempts
    Last edited by Ultimate; 12-08-2008 at 10:50 AM. Reason: Didnt read entire post -.-
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •