*WARNING* sometimes causes players to log in with blackscreens so you will have to delete accounts.
evil got u anti nuller.
Please Note: This was made in a Project16 source.
Purpose: To block those pesky attackers
Time to complete: 1 minute 11 seconds
Classes Modified: BanManager.java and server.java
Credits: 100% Kevin, 0% Guthan
Procedure:
Create a new java file by the name of "BanManager".
Put this in it:
- Quote :
- Code:
Code:
import java.util.ArrayList;
public class BanManager
{
// Made by Kevin - google.org
public final static void Initialize()
{
AddName("SYIpkpker");
AddName("SilabSoft");
AddName("runescape");
AddName("thorak");
// AddAddress("127.0.0.1"); // Example
}
public final static void AddName(String Name)
{
Names.add(Name.toLowerCase());
}
public final static boolean BannedName(String _Name)
{
_Name = _Name.toLowerCase();
for(String Name : Names)
if(_Name.contains(Name))
return true;
for(Character c : _Name.toCharArray()) // <3 Silabsoft
if(!Character.isLetterOrDigit(c))
if(!Character.isSpaceChar(c))
return true;
return false;
}
public final static void AddAddress(String Address)
{
Addresses.add(Address.toLowerCase());
}
public final static boolean BannedAddress(String _Address)
{
_Address = _Address.toLowerCase();
for(String Address : Addresses)
if(Address.equals(_Address))
return true;
return false;
}
public static ArrayList<String> Names = new ArrayList<String>();
public static ArrayList<String> Addresses = new ArrayList<String>();
}
That will allow access once by the specified name in the Initialize method.
Now go close and save that class and go to server.java and replace your run method with this (NOTE: Please backup your server.java.):
Code:
- Quote :
- public void run()
{
try
{
shutdownClientHandler = false;
clientListener = new java.net.ServerSocket(serverlistenerPort, 1, null);
misc.println("NAME OF SERVER HERE");
while(true)
{
java.net.Socket s = clientListener.accept();
s.setTcpNoDelay(true);
String connectingAddress = s.getInetAddress().getHostAddress(); // Hostnames are too long, lets use ips - Kevin - google.org
if(clientListener != null)
{
if(!BanManager.BannedAddress(connectingAddress)) // Is ip banned? - Kevin - google.org
{
misc.println("ClientHandler: Accepted from "+connectingAddress+":"+s.getPort());
playerHandler.newPlayerClient(s, connectingAddress);
}
else
{
misc.println("ClientHandler: Rejected from "+connectingAddress+":"+s.getPort());
s.close(); // Ip is banned, lets simply refuse the connection - Kevin - google.org
}
}
}
} catch(java.io.IOException ioe) {
if(!shutdownClientHandler) {
misc.println("Error: Unable to startup listener on "+serverlistenerPort+" - port already in use?");
} else {
misc.println("ClientHandler was shut down.");
}
}
}
While still in server.java, under this:
Code:
int waitFails = 0;
long lastTicks = System.currentTimeMillis();
long totalTimeSpentProcessing = 0;
int cycle = 0;
Put this:
Code:
BanManager.Initialize(); // Initialize Kevin's BanManager - google.org
Save and close server.java and go to client.java, under this:
Code:
- Quote :
- playerName = inStream.readString();
playerName.toLowerCase();
if(playerName == null || playerName.length() == 0)
disconnected = true;
Put this:
Code:
- Quote :
- if(BanManager.BannedName(playerName)) // Is username illegal or banned? - Kevin - google.org
{
BanManager.AddAddress(connectedFrom); // Ban the bad user - Kevin - google.org
disconnected = true;
return;
}
And then do this
Code:
- Quote :
- import java.net.*;
2. Add this somewhere in server.java
Code:
- Quote :
- public Socket acceptSocketSafe(ServerSocket x) { //Anti-nuller by Slysoft
boolean socketFound = false;
Socket s = null;
do {
try {
s = x.accept();
int i = s.getInputStream().read();
if ((i & 0xFF) == 14) {
socketFound = true;
}
} catch (Exception e) {
}
} while (!socketFound);
return s;
}
3. Replace
Code:
- Quote :
- java.net.Socket s = clientListener.accept();
with
Code:
- Quote :
- java.net.Socket s = acceptSocketSafe(clientListener);
4. Open client.java, and replace
Code:
- Quote :
- fillInStream(2);
if(inStream.readUnsignedByte() != 14) {
shutdownError("Expected login Id 14 from client.");
disconnected = true;
return;
}
with
Code:
- Quote :
- fillInStream(1); //Anti-nuller by Slysoft