improved state management
This commit is contained in:
parent
36d7d767dd
commit
1158a6fe34
|
@ -711,6 +711,7 @@ public class IntegratedServer {
|
|||
if(currentProcess != null) {
|
||||
currentProcess.mainLoop();
|
||||
if(currentProcess.isServerStopped()) {
|
||||
sendIPCPacket(new IPCPacketFFProcessKeepAlive(IPCPacket01StopServer.ID));
|
||||
currentProcess = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,11 @@ public class WorkerListenThread {
|
|||
|
||||
public void stopListening() {
|
||||
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) {
|
||||
|
|
|
@ -396,6 +396,7 @@ public abstract class MinecraftServer implements ICommandSender, Runnable {
|
|||
this.getLogAgent().logSevereException(
|
||||
"Encountered an unexpected exception " + var48.getClass().getSimpleName(), var48);
|
||||
var48.printStackTrace();
|
||||
IntegratedServer.throwExceptionToClient("Encountered an unexpected exception", var48);
|
||||
} finally {
|
||||
try {
|
||||
this.stopServer();
|
||||
|
|
|
@ -61,7 +61,12 @@ public class IntegratedServer {
|
|||
}
|
||||
|
||||
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() {
|
||||
|
@ -72,7 +77,7 @@ public class IntegratedServer {
|
|||
}
|
||||
|
||||
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";
|
||||
throw new IllegalStateException(msg);
|
||||
}
|
||||
|
@ -131,6 +136,7 @@ public class IntegratedServer {
|
|||
}
|
||||
|
||||
public static void requestWorldList() {
|
||||
ensureReady();
|
||||
statusState = IntegratedState.WORLD_LISTING;
|
||||
worlds.clear();
|
||||
sendIPCPacket(new IPCPacket0EListWorlds());
|
||||
|
@ -282,6 +288,8 @@ public class IntegratedServer {
|
|||
callFailed = true;
|
||||
break;
|
||||
case IPCPacket01StopServer.ID:
|
||||
statusState = IntegratedState.WORLD_NONE;
|
||||
break;
|
||||
case IPCPacket03DeleteWorld.ID:
|
||||
case IPCPacket04RenameWorld.ID:
|
||||
case IPCPacket07ImportWorld.ID:
|
||||
|
|
|
@ -590,7 +590,7 @@ public class Minecraft implements Runnable {
|
|||
}
|
||||
|
||||
public void stopServerAndDisplayGuiScreen(GuiScreen par1GuiScreen) {
|
||||
if(IntegratedServer.isWorldRunning()) {
|
||||
if(!IntegratedServer.isReady()) {
|
||||
IntegratedServer.unloadWorld();
|
||||
displayGuiScreen(new GuiScreenSingleplayerLoading(par1GuiScreen, "saving world", () -> IntegratedServer.isReady()));
|
||||
}else {
|
||||
|
|
|
@ -58,6 +58,7 @@ public class GuiSelectWorld extends GuiScreen {
|
|||
private GuiButton buttonRename;
|
||||
private GuiButton buttonBackup;
|
||||
|
||||
private boolean hasRequestedWorlds = false;
|
||||
private boolean waitingForWorlds = false;
|
||||
|
||||
public GuiSelectWorld(GuiScreen par1GuiScreen) {
|
||||
|
@ -72,8 +73,14 @@ public class GuiSelectWorld extends GuiScreen {
|
|||
this.screenTitle = var1.translateKey("selectWorld.title");
|
||||
this.saveList = new LinkedList();
|
||||
|
||||
if(IntegratedServer.isReady()) {
|
||||
hasRequestedWorlds = true;
|
||||
waitingForWorlds = true;
|
||||
IntegratedServer.requestWorldList();
|
||||
}else {
|
||||
IntegratedServer.unloadWorld();
|
||||
hasRequestedWorlds = false;
|
||||
}
|
||||
|
||||
this.localizedWorldText = var1.translateKey("selectWorld.world");
|
||||
this.localizedMustConvertText = var1.translateKey("selectWorld.conversion");
|
||||
|
@ -86,7 +93,11 @@ public class GuiSelectWorld extends GuiScreen {
|
|||
}
|
||||
|
||||
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;
|
||||
this.loadSaves();
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ import net.lax1dude.eaglercraft.DefaultSkinRenderer;
|
|||
import net.lax1dude.eaglercraft.EaglerAdapter;
|
||||
import net.lax1dude.eaglercraft.IntegratedServer;
|
||||
import net.lax1dude.eaglercraft.EaglercraftRandom;
|
||||
import net.lax1dude.eaglercraft.GuiScreenSingleplayerException;
|
||||
import net.lax1dude.eaglercraft.GuiScreenSingleplayerLoading;
|
||||
import net.lax1dude.eaglercraft.Voice;
|
||||
import net.lax1dude.eaglercraft.WebsocketNetworkManager;
|
||||
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));
|
||||
}
|
||||
}else {
|
||||
if(!(this.mc.currentScreen instanceof GuiDisconnected)) {
|
||||
this.mc.displayGuiScreen(new GuiDisconnected(backToMenu(), "disconnect.disconnected", "disconnect.endOfStream", null));
|
||||
if(!(this.mc.currentScreen instanceof GuiDisconnected) && !(this.mc.currentScreen instanceof GuiScreenSingleplayerException) &&
|
||||
!(this.mc.currentScreen instanceof GuiScreenSingleplayerLoading)) {
|
||||
this.mc.stopServerAndDisplayGuiScreen(new GuiDisconnected(backToMenu(), "disconnect.disconnected", "disconnect.endOfStream", null));
|
||||
}
|
||||
}
|
||||
this.disconnected = true;
|
||||
|
@ -505,10 +508,10 @@ public class NetClientHandler extends NetHandler {
|
|||
this.mc.loadWorld((WorldClient) null);
|
||||
if(par1Packet255KickDisconnect.reason.equalsIgnoreCase("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")) {
|
||||
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 {
|
||||
this.mc.stopServerAndDisplayGuiScreen(new GuiDisconnected(backToMenu(), "disconnect.disconnected", "disconnect.genericReason", new Object[] { par1Packet255KickDisconnect.reason }));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user