Fix for 2 Major Reasons Servers Crash! v. 2.2!
Purpose: To make your server automaticaly restart when all the players are kicked and can't log in when it says on your runserver.bat (playername) is already online, or if it says (playername) can't log in because there is too many people online. Enjoy it because I spent all day on it.
Source: Any as far as I know
Difficulty: 2/10
Needed skills: copy and paste, mouse clicking, How to press Ctrl + F
Classes modified: client.class
Credits: Nintendo_G
Version: 2.2
Open up client.java
Search for this:
Code:
public void staticAnimation
You should see this:
Code:
public void staticAnimation(int graphicID, int playerX, int playerY, int heightLevel) { /*Used from phates old stuff*/ // credits to phate for this bit :P
outStream.createFrame(85);
outStream.writeByteC(playerY - (mapRegionY * 8));
outStream.writeByteC(playerX - (mapRegionX * 8));
outStream.createFrame(4);
outStream.writeByte(0);
outStream.writeWord(graphicID); // Graphic ID
outStream.writeByte(heightLevel); // Height above gorund
outStream.writeWord(0); // Pause before casting
}
Under all of that add this:
Code:
public void resetserver()
{
misc.println("RESETING SERVER!!!");
misc.println("Saving all games...");
PlayerHandler.kickAllPlayers = true;
misc.println("GAME SUCCESSFULLY SAVED FOR ALL PLAYERS");
closeListener();
runserver();
}
public static int serverlistenerPort = 43594; //43594=default
public void runserver()
{
try
{
String File = "runserver.bat"; // File specified
String Dir = "./"+File; // Directory specified
Runtime.getRuntime().exec(Dir);
server.shutdownClientHandler = false;
server.clientListener = new java.net.ServerSocket(serverlistenerPort, 1, null);
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
public void closeListener()
{
try {
server.shutdownClientHandler = true;
if(server.clientListener != null) server.clientListener.close();
server.clientListener = null;
}
catch(java.lang.Exception __ex)
{
__ex.printStackTrace();
}
}
Now search for this:
Code:
appendToLR(playerName+" failed to logon because there is too many players online.");
Under that line add this:
Code:
Now search for this:
Code:
println_debug(playerName+" is already online.");
Under that line add this:
Now search for this:
Code:
println_debug(playerName+" is already online.");
Under that line add this:
Now save, compile, run. Now it will automatically reset your server if everybody gets disconnected and can't log in. Enjoy! It's simple, but effective . Comment on what you think of version 2.2!
This was made by Nintendo_G on moparscape and I added this because i don't see it here.