improved state management

This commit is contained in:
LAX1DUDE 2022-08-02 01:56:28 -07:00
parent 36d7d767dd
commit 1158a6fe34
7 changed files with 40 additions and 11 deletions

View File

@ -711,6 +711,7 @@ public class IntegratedServer {
if(currentProcess != null) { if(currentProcess != null) {
currentProcess.mainLoop(); currentProcess.mainLoop();
if(currentProcess.isServerStopped()) { if(currentProcess.isServerStopped()) {
sendIPCPacket(new IPCPacketFFProcessKeepAlive(IPCPacket01StopServer.ID));
currentProcess = null; currentProcess = null;
} }
} }

View File

@ -32,6 +32,11 @@ public class WorkerListenThread {
public void stopListening() { public void stopListening() {
this.isListening = false; this.isListening = false;
List<String> names = new ArrayList();
names.addAll(channels.keySet());
for(int i = 0, l = names.size(); i < l; ++i) {
closeChannel(names.get(i));
}
} }
public boolean openChannel(String player) { public boolean openChannel(String player) {

View File

@ -396,6 +396,7 @@ public abstract class MinecraftServer implements ICommandSender, Runnable {
this.getLogAgent().logSevereException( this.getLogAgent().logSevereException(
"Encountered an unexpected exception " + var48.getClass().getSimpleName(), var48); "Encountered an unexpected exception " + var48.getClass().getSimpleName(), var48);
var48.printStackTrace(); var48.printStackTrace();
IntegratedServer.throwExceptionToClient("Encountered an unexpected exception", var48);
} finally { } finally {
try { try {
this.stopServer(); this.stopServer();

View File

@ -61,7 +61,12 @@ public class IntegratedServer {
} }
public static boolean isWorldRunning() { public static boolean isWorldRunning() {
return statusState == IntegratedState.WORLD_LOADED || statusState == IntegratedState.WORLD_PAUSED; return statusState == IntegratedState.WORLD_LOADED || statusState == IntegratedState.WORLD_PAUSED ||
statusState == IntegratedState.WORLD_LOADING || statusState == IntegratedState.WORLD_SAVING;
}
public static boolean isWorldReady() {
return statusState == IntegratedState.WORLD_LOADED || statusState == IntegratedState.WORLD_LOADING;
} }
private static void ensureReady() { private static void ensureReady() {
@ -72,7 +77,7 @@ public class IntegratedServer {
} }
private static void ensureWorldReady() { private static void ensureWorldReady() {
if(!isWorldRunning()) { if(!isWorldReady()) {
String msg = "Server is in state " + statusState + " '" + IntegratedState.getStateName(statusState) + "' which is not the 'WORLD_LOADED' state for the requested IPC operation"; String msg = "Server is in state " + statusState + " '" + IntegratedState.getStateName(statusState) + "' which is not the 'WORLD_LOADED' state for the requested IPC operation";
throw new IllegalStateException(msg); throw new IllegalStateException(msg);
} }
@ -131,6 +136,7 @@ public class IntegratedServer {
} }
public static void requestWorldList() { public static void requestWorldList() {
ensureReady();
statusState = IntegratedState.WORLD_LISTING; statusState = IntegratedState.WORLD_LISTING;
worlds.clear(); worlds.clear();
sendIPCPacket(new IPCPacket0EListWorlds()); sendIPCPacket(new IPCPacket0EListWorlds());
@ -282,6 +288,8 @@ public class IntegratedServer {
callFailed = true; callFailed = true;
break; break;
case IPCPacket01StopServer.ID: case IPCPacket01StopServer.ID:
statusState = IntegratedState.WORLD_NONE;
break;
case IPCPacket03DeleteWorld.ID: case IPCPacket03DeleteWorld.ID:
case IPCPacket04RenameWorld.ID: case IPCPacket04RenameWorld.ID:
case IPCPacket07ImportWorld.ID: case IPCPacket07ImportWorld.ID:

View File

@ -590,7 +590,7 @@ public class Minecraft implements Runnable {
} }
public void stopServerAndDisplayGuiScreen(GuiScreen par1GuiScreen) { public void stopServerAndDisplayGuiScreen(GuiScreen par1GuiScreen) {
if(IntegratedServer.isWorldRunning()) { if(!IntegratedServer.isReady()) {
IntegratedServer.unloadWorld(); IntegratedServer.unloadWorld();
displayGuiScreen(new GuiScreenSingleplayerLoading(par1GuiScreen, "saving world", () -> IntegratedServer.isReady())); displayGuiScreen(new GuiScreenSingleplayerLoading(par1GuiScreen, "saving world", () -> IntegratedServer.isReady()));
}else { }else {

View File

@ -58,6 +58,7 @@ public class GuiSelectWorld extends GuiScreen {
private GuiButton buttonRename; private GuiButton buttonRename;
private GuiButton buttonBackup; private GuiButton buttonBackup;
private boolean hasRequestedWorlds = false;
private boolean waitingForWorlds = false; private boolean waitingForWorlds = false;
public GuiSelectWorld(GuiScreen par1GuiScreen) { public GuiSelectWorld(GuiScreen par1GuiScreen) {
@ -72,8 +73,14 @@ public class GuiSelectWorld extends GuiScreen {
this.screenTitle = var1.translateKey("selectWorld.title"); this.screenTitle = var1.translateKey("selectWorld.title");
this.saveList = new LinkedList(); this.saveList = new LinkedList();
if(IntegratedServer.isReady()) {
hasRequestedWorlds = true;
waitingForWorlds = true; waitingForWorlds = true;
IntegratedServer.requestWorldList(); IntegratedServer.requestWorldList();
}else {
IntegratedServer.unloadWorld();
hasRequestedWorlds = false;
}
this.localizedWorldText = var1.translateKey("selectWorld.world"); this.localizedWorldText = var1.translateKey("selectWorld.world");
this.localizedMustConvertText = var1.translateKey("selectWorld.conversion"); this.localizedMustConvertText = var1.translateKey("selectWorld.conversion");
@ -86,7 +93,11 @@ public class GuiSelectWorld extends GuiScreen {
} }
public void updateScreen() { public void updateScreen() {
if(waitingForWorlds && IntegratedServer.getWorldList() != null) { if(!hasRequestedWorlds && IntegratedServer.isReady()) {
hasRequestedWorlds = true;
waitingForWorlds = true;
IntegratedServer.requestWorldList();
}else if(waitingForWorlds && IntegratedServer.getWorldList() != null) {
waitingForWorlds = false; waitingForWorlds = false;
this.loadSaves(); this.loadSaves();
} }

View File

@ -14,6 +14,8 @@ import net.lax1dude.eaglercraft.DefaultSkinRenderer;
import net.lax1dude.eaglercraft.EaglerAdapter; import net.lax1dude.eaglercraft.EaglerAdapter;
import net.lax1dude.eaglercraft.IntegratedServer; import net.lax1dude.eaglercraft.IntegratedServer;
import net.lax1dude.eaglercraft.EaglercraftRandom; import net.lax1dude.eaglercraft.EaglercraftRandom;
import net.lax1dude.eaglercraft.GuiScreenSingleplayerException;
import net.lax1dude.eaglercraft.GuiScreenSingleplayerLoading;
import net.lax1dude.eaglercraft.Voice; import net.lax1dude.eaglercraft.Voice;
import net.lax1dude.eaglercraft.WebsocketNetworkManager; import net.lax1dude.eaglercraft.WebsocketNetworkManager;
import net.lax1dude.eaglercraft.WorkerNetworkManager; import net.lax1dude.eaglercraft.WorkerNetworkManager;
@ -123,8 +125,9 @@ public class NetClientHandler extends NetHandler {
this.mc.displayGuiScreen(new GuiDisconnected(backToMenu(), "disconnect.disconnected", "RateLimit." + r.name(), null)); this.mc.displayGuiScreen(new GuiDisconnected(backToMenu(), "disconnect.disconnected", "RateLimit." + r.name(), null));
} }
}else { }else {
if(!(this.mc.currentScreen instanceof GuiDisconnected)) { if(!(this.mc.currentScreen instanceof GuiDisconnected) && !(this.mc.currentScreen instanceof GuiScreenSingleplayerException) &&
this.mc.displayGuiScreen(new GuiDisconnected(backToMenu(), "disconnect.disconnected", "disconnect.endOfStream", null)); !(this.mc.currentScreen instanceof GuiScreenSingleplayerLoading)) {
this.mc.stopServerAndDisplayGuiScreen(new GuiDisconnected(backToMenu(), "disconnect.disconnected", "disconnect.endOfStream", null));
} }
} }
this.disconnected = true; this.disconnected = true;
@ -505,10 +508,10 @@ public class NetClientHandler extends NetHandler {
this.mc.loadWorld((WorldClient) null); this.mc.loadWorld((WorldClient) null);
if(par1Packet255KickDisconnect.reason.equalsIgnoreCase("BLOCKED")) { if(par1Packet255KickDisconnect.reason.equalsIgnoreCase("BLOCKED")) {
EaglerAdapter.logRateLimit(netManager.getServerURI(), RateLimit.BLOCKED); EaglerAdapter.logRateLimit(netManager.getServerURI(), RateLimit.BLOCKED);
this.mc.stopServerAndDisplayGuiScreen(new GuiDisconnected(backToMenu(), "disconnect.ratelimit.kickBlocked", "disconnect.endOfStream", (Object[])null)); this.mc.displayGuiScreen(new GuiDisconnected(backToMenu(), "disconnect.ratelimit.kickBlocked", "disconnect.endOfStream", (Object[])null));
}else if(par1Packet255KickDisconnect.reason.equalsIgnoreCase("LOCKED")) { }else if(par1Packet255KickDisconnect.reason.equalsIgnoreCase("LOCKED")) {
EaglerAdapter.logRateLimit(netManager.getServerURI(), RateLimit.LOCKED); EaglerAdapter.logRateLimit(netManager.getServerURI(), RateLimit.LOCKED);
this.mc.stopServerAndDisplayGuiScreen(new GuiDisconnected(backToMenu(), "disconnect.ratelimit.kickLocked", "disconnect.endOfStream", (Object[])null)); this.mc.displayGuiScreen(new GuiDisconnected(backToMenu(), "disconnect.ratelimit.kickLocked", "disconnect.endOfStream", (Object[])null));
}else { }else {
this.mc.stopServerAndDisplayGuiScreen(new GuiDisconnected(backToMenu(), "disconnect.disconnected", "disconnect.genericReason", new Object[] { par1Packet255KickDisconnect.reason })); this.mc.stopServerAndDisplayGuiScreen(new GuiDisconnected(backToMenu(), "disconnect.disconnected", "disconnect.genericReason", new Object[] { par1Packet255KickDisconnect.reason }));
} }