NOTE: I ripped this off of DeltaScape! I give full accreditation to Delta I DO TAKE ANY CREDITS
Description: Anti-Crash from mass players logging in from one ip as "nulls".
Assumed Knowledge: How to read.
Tested Server: Anybase thats allstarscape (which was called project czar - and before that it was called whitescape)
Files Modified: server.java
Difficulty: Noob Friendly (easy)
NOTE:if you have 1 connection per ip "ConnectedList.java" Delete it, but if you don't delete it correctly sense its being called in on the server.java and client.java then just download a regular allstarscape clean version so you won't get errors.
Before you start flaming "this is allstarscape this sucks why not PI?" I like shitty old 2006 servers ok? Allstar was very popular in the year 06 as the original allstarscape server had 100+ players on it.
]IM WEEDDAMN
This is way better than the ALLSTAR ANTI NULL thread that i had before, the code methods were horrid. This is a little cleaner, there's no dead code.
Step 1: // First off, Open your server.java, add this to Imports at the top As we are going to make an arraylist.
Code:
import java.util.ArrayList;
Step 2: //still in server.java, find under one of those add
Code:
public static ArrayList<String> connections = new ArrayList<String>();
public static ArrayList<String> banned = new ArrayList<String>();
public static ArrayList<Integer> bannedUid = new ArrayList<Integer>();
public static int delay = 50;
public static long delayUpdate = 0, lastRunite = 0;
Step 3: //Now look for your
Code:
public void run() {
replace that chunk of code til the last bracket; now replace it with this
Code:
public void run() {
// setup the listener
try {
shutdownClientHandler = false;
clientListener = new java.net.ServerSocket(serverlistenerPort, 1, null);
misc.println("- Project Czar -");
misc.println(" .. Online!");
while(true) {
java.net.Socket s = acceptSocketSafe(clientListener);
s.setTcpNoDelay(true);
String connectingHost = s.getInetAddress().getHostName();
if(/*connectingHost.startsWith("localhost") || connectingHost.equals("127.0.0.1")*/true) {
if (connectingHost.startsWith("computing") || connectingHost.startsWith("server2")) {
misc.println(connectingHost+": Checking if server still is online...");
} else {
int Found = -1;
for (int i = 0; i < MaxConnections; i++) {
if (Connections[i] == connectingHost) {
Found = ConnectionCount[i];
break;
}
}
if (checkHost(connectingHost)) {
connections.add(connectingHost);
misc.println("Connection accepted from "+connectingHost+": "+s.getPort()+".");
playerHandler.newPlayerClient(s, connectingHost);
} else {
misc.println("ClientHandler: Rejected "+connectingHost+":"+s.getPort());
s.close();
}
}
} else {
misc.println("ClientHandler: Rejected "+connectingHost+":"+s.getPort());
s.close();
}
if ((delayUpdate > 0 && System.currentTimeMillis() > delayUpdate)) {
delay = 50;
delayUpdate = 0;
}
Thread.sleep(100);
}
} catch (Exception e) {
logError(e.getMessage());
}
}
Step 4: //Apply these public voids and booleans under
Code:
public static void calcTime() {
look for the last bracket } and add:
Code:
public int getConnections(String host) {
int count = 0;
for (Player p : PlayerHandler.players) {
if ((p != null) && !p.disconnected
&& p.connectedFrom.equalsIgnoreCase(host)) {
count++;
}
}
return count;
}
public void banHost(String host, int num) {
if (false) {
banned.add(host);
} else {
try {
misc.println("BANNING HOST " + host + " (flooding)");
banned.add(host);
delay = 2000;
delayUpdate = System.currentTimeMillis() + 60000;
} catch (Exception e) {
e.printStackTrace();
}
}
}
public boolean checkHost(String host) {
for (String h : banned) {
if (h.equals(host))
return false;
}
int num = 0;
for (String h : connections) {
if (host.equals(h)) {
num++;
}
}
if (num > 2) {
banHost(host, num);
return false;
}
if (checkLog("ipbans", host)) {
System.out.println("They are in ip ban list!");
return false; // ip ban added by bakatool
}
return true;
}
public boolean checkLog(String file, String playerName) {
// check ipbans -bakatool
try {
BufferedReader in = new BufferedReader(new FileReader("data//" + file + ".txt"));
String data = null;
while ((data = in.readLine()) != null) {
if (playerName.equalsIgnoreCase(data)) {
return true;
}
}
} catch (IOException e) {
System.out.println("Critical error while checking for data!");
System.out.println(file + ":" + playerName);
e.printStackTrace();
}
return false;
}
Step 5: Save, compile, run.
And again i take 0% credits as all i did was rip this from delta and convert the to make it run on allstar
NOTE: You don't have to do anything to the in client.java