diff --git a/src/main/java/io/singularitynet/Client/ClientStateMachine.java b/src/main/java/io/singularitynet/Client/ClientStateMachine.java index 985d5b1..4901492 100755 --- a/src/main/java/io/singularitynet/Client/ClientStateMachine.java +++ b/src/main/java/io/singularitynet/Client/ClientStateMachine.java @@ -43,7 +43,12 @@ import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.GameMenuScreen; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.multiplayer.ConnectScreen; import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.network.ServerAddress; +import net.minecraft.client.network.ServerInfo; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; import net.minecraft.entity.mob.MobEntity; @@ -550,6 +555,7 @@ public boolean onCommand(String command, String ipFrom, DataOutputStream dos) { LOGGER.info("Received from " + ipFrom + ":" + command.substring(0, Math.min(command.length(), 1024))); + boolean keepProcessing = false; // Possible commands: @@ -849,6 +855,7 @@ private void checkForMissionCommand() throws Exception { missionInit.getClientAgentConnection().setAgentIPAddress(comip.ipAddress); LOGGER.info("Mission received: " + missionInit.getMission().getAbout().getSummary()); + LOGGER.debug(missionMessage); csMachine.currentMissionInit = missionInit; ClientStateMachine.this.createMissionControlSocket(); // Move on to next state: @@ -1178,6 +1185,16 @@ protected void execute() { boolean needsNewWorld = worldGenerator != null && worldGenerator.shouldCreateWorld(currentMissionInit(), genOptions); boolean worldCurrentlyExists = world != null; + MinecraftServerConnection serverCon = currentMissionInit().getMinecraftServerConnection(); + LOGGER.debug("checking for server connection in mission init: ", serverCon); + if (serverCon != null && serverCon.getAddress() != null && serverCon.getPort() != 0) { + LOGGER.debug("server connection info is provided " + serverCon.toString() + + " assume world already exists"); + needsNewWorld = false; + worldCurrentlyExists = true; + episodeHasCompleted(ClientState.WAITING_FOR_SERVER_READY); + return; + } List agents = currentMissionInit().getMission().getAgentSection(); String agentName = agents.get(currentMissionInit().getClientRole()).getName(); if (worldCurrentlyExists) { @@ -1203,10 +1220,10 @@ protected void execute() { LOGGER.debug("needsNewWorld && worldCurrentlyExists"); episodeHasCompleted(ClientState.PAUSING_OLD_SERVER); } else { - // We want a new world, and there is currently nothing running, - // so jump to world creation: - LOGGER.debug("needsNewWorld && not worldCurrentlyExists"); - episodeHasCompleted(ClientState.CREATING_NEW_WORLD); + // We want a new world, and there is currently nothing running, + // so jump to world creation: + LOGGER.debug("needsNewWorld && not worldCurrentlyExists"); + episodeHasCompleted(ClientState.CREATING_NEW_WORLD); } } else { // not needNewWorld LOGGER.debug("not need new world"); @@ -1217,7 +1234,7 @@ protected void execute() { as.getAgentStart().setPlacement(null); ClientPlayerEntity player = MinecraftClient.getInstance().player; - if (player.isDead()) player.requestRespawn(); + if (player != null && player.isDead()) player.requestRespawn(); /* if (ClientStateMachine.this.serverHandlers == null) { // We need to use the server's MissionHandlers here: @@ -1234,6 +1251,7 @@ protected void execute() { // boolean isConnectedToRealm = MinecraftClient.getInstance().isConnectedToRealms(); boolean isConnectedToLocal = MinecraftClient.getInstance().isConnectedToLocalServer(); boolean isIntegratedServerRunning = MinecraftClient.getInstance().isIntegratedServerRunning(); + boolean isConnectedToRemote = !isIntegratedServerRunning && player != null; // LOGGER.debug("isConnectedToRealm: " + isConnectedToRealm); LOGGER.debug("isConnectedToLocal: " + isConnectedToLocal); LOGGER.debug("isIntegratedServerRunning: " + isIntegratedServerRunning); @@ -1260,18 +1278,7 @@ public void run() { // Skip all the map loading stuff and go straight to waiting for the server: episodeHasCompleted(ClientState.WAITING_FOR_SERVER_READY); } else { - LOGGER.debug("sending mission to remote Server"); - HashMap map = new HashMap(); - // convert mission init with jaxb serializer - try { - String xmlData = SchemaHelper.serialiseObject(currentMissionInit(), MissionInit.class); - map.put("MissionInit", xmlData); - } catch (JAXBException e) { - episodeHasCompletedWithErrors(ClientState.ERROR_NO_WORLD, "exception while converting mission init to xml" + e.getMessage()); - } - // send mission init to server - ClientPlayNetworking.send(new MessagePayload(new VereyaMessage(VereyaMessageType.CLIENT_MISSION_INIT, 0, map))); - episodeHasCompleted(ClientState.WAITING_FOR_SERVER_READY); + throw new RuntimeException("unexpected condition"); } } else { // not needNewWorld and no world: error // Mission has requested no new world, but there is no current world to play in - this is an error: @@ -1294,6 +1301,7 @@ public class WaitingForServerEpisode extends ErrorAwareEpisode implements IVerey boolean waitingForChunk = false; boolean waitingForPlayer = true; private boolean chunkReady = false; + private boolean sendToRemote = false; protected WaitingForServerEpisode(ClientStateMachine machine) { @@ -1414,8 +1422,7 @@ public void onClientTick(MinecraftClient client) } @Override - protected void execute() throws Exception - { + protected void execute() throws Exception { totalTicks = 0; // Minecraft.getMinecraft().displayGuiScreen(null); // Clear any menu screen that might confuse things. @@ -1424,7 +1431,18 @@ protected void execute() throws Exception //if (agents == null || agents.size() <= currentMissionInit().getClientRole()) // throw new Exception("No agent section for us!"); // TODO this.agentName = agents.get(currentMissionInit().getClientRole()).getName(); -/* + MinecraftServerConnection serverCon = currentMissionInit().getMinecraftServerConnection(); + PlayerEntity player = MinecraftClient.getInstance().player; + boolean isConnectedToRemote = player != null && !MinecraftClient.getInstance().isIntegratedServerRunning(); + if (!isConnectedToRemote && serverCon != null && serverCon.getAddress() != null && serverCon.getPort() != 0) { + ServerAddress srv = new ServerAddress(serverCon.getAddress(), serverCon.getPort()); + LOGGER.debug("connecting to ", srv); + Screen parentScreen = new GameMenuScreen(true); + ServerInfo srvInfo = new ServerInfo("local", srv.getAddress(), ServerInfo.ServerType.LAN); + ConnectScreen.connect(parentScreen, MinecraftClient.getInstance(), srv, srvInfo, true, null); + this.sendToRemote = true; + } + /* if (agents.size() > 1 && currentMissionInit().getClientRole() != 0) { // Multi-agent mission, we should be joining a server. @@ -1451,6 +1469,20 @@ protected void execute() throws Exception protected void handleLan() { + if (this.sendToRemote) { + LOGGER.debug("sending mission to remote Server"); + HashMap map = new HashMap(); + // convert mission init with jaxb serializer + try { + String xmlData = SchemaHelper.serialiseObject(currentMissionInit(), MissionInit.class); + map.put("MissionInit", xmlData); + } catch (JAXBException e) { + episodeHasCompletedWithErrors(ClientState.ERROR_NO_WORLD, "exception while converting mission init to xml" + e.getMessage()); + } + // send mission init to server + ClientPlayNetworking.send(new MessagePayload(new VereyaMessage(VereyaMessageType.CLIENT_MISSION_INIT, 0, map))); + sendToRemote = false; + } // Get our name from the Mission: /*List agents = currentMissionInit().getMission().getAgentSection(); this.agentName = agents.get(currentMissionInit().getClientRole()).getName(); diff --git a/src/main/java/io/singularitynet/Server/VereyaModServer.java b/src/main/java/io/singularitynet/Server/VereyaModServer.java index 91db107..ad313e7 100644 --- a/src/main/java/io/singularitynet/Server/VereyaModServer.java +++ b/src/main/java/io/singularitynet/Server/VereyaModServer.java @@ -65,8 +65,11 @@ public void onInitialize() { SidesMessageHandler.client2server.onMessage(payload, context); }); ServerLifecycleEvents.SERVER_STARTED.register((MinecraftServer server) -> { - - LOGGER.info("Server started"); + String msg = "integrated "; + if (server.isDedicated()){ + msg = "dedicated "; + } + LOGGER.info(msg + "Server started"); if (stateMachine == null ) { this.stateMachine = new ServerStateMachine(ServerState.WAITING_FOR_MOD_READY, null, server); } else {