very nice
adding it atm...
gj
|
|
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
I will explain each part of this.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;
The amount of times the user has tried to logon with a name which is too longCode:public static int longNameAttempts;
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 java.util.HashMap<String, Integer> longAttempts = new java.util.HashMap<String, Integer>();
The max amount of characters that is allowed on your server.Code:public static final int MAX_CHARACTERS = 15;
The max times a user can "try" and logon with a name which is too long before they are IP banned.Code:public static final int MAX_ATTEMPTS = 5;
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.
This code is pretty self explanitory but I will explain some parts.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; } }
If the attempts that they have made is higher than the max attempts execute this block of code.Code:if(longAttempts.get(connectedFrom) > MAX_ATTEMPTS-1) {
Put the connected from and also the attempts number in the HashMap while also incrementing it.Code:longAttempts.put(connectedFrom, longNameAttempts++);
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

very nice
adding it atm...
gj
nice job, lots of people will use this
9/10![]()
Nice tutThanks for this mate
![]()


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..
how i ban him 4ever even if he switches ip?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
also do i add this in initialize() or run()?
repp++'d u, thx again (i put under initialize for now)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; } }
Thanks was just bout to do this saved me some time![]()
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; }

My experience
Thanks, but what difference would that hashmap make? woudlntUltimateWorld [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
Nice job I might use itstops hack attempts
Last edited by Ultimate; 12-08-2008 at 10:50 AM. Reason: Didnt read entire post -.-
| « Full Firemaking | Dodian Fix: Fishing animation when you can't fish » |
| Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |