diff --git a/src/main/java/com/minecrafttas/tasmod/TASmod.java b/src/main/java/com/minecrafttas/tasmod/TASmod.java index 98e58879..608bdfe5 100644 --- a/src/main/java/com/minecrafttas/tasmod/TASmod.java +++ b/src/main/java/com/minecrafttas/tasmod/TASmod.java @@ -10,6 +10,7 @@ import com.minecrafttas.common.events.EventListener; import com.minecrafttas.common.events.EventServer.EventServerInit; import com.minecrafttas.common.events.EventServer.EventServerStop; +import com.minecrafttas.server.Server; import com.minecrafttas.tasmod.commands.clearinputs.ClearInputsPacket; import com.minecrafttas.tasmod.commands.clearinputs.CommandClearInputs; import com.minecrafttas.tasmod.commands.folder.CommandFolder; @@ -83,6 +84,8 @@ public class TASmod implements ModInitializer, EventServerInit, EventServerStop{ public static final TickScheduler tickSchedulerServer = new TickScheduler(); + public static Server server; + @Override public void onServerInit(MinecraftServer server) { serverInstance = server; @@ -125,9 +128,15 @@ public void onServerInit(MinecraftServer server) { } @Override - public void onServerStop(MinecraftServer server) { + public void onServerStop(MinecraftServer mcserver) { serverInstance=null; packetServer.close(); + try { + if (server != null) server.close(); + } catch (IOException e) { + LOGGER.error("Unable to close TASmod server: {}", e); + e.printStackTrace(); + } } public static MinecraftServer getServerInstance() { @@ -193,5 +202,11 @@ public void onInitialize() { PacketSerializer.registerPacket(PlayUntilPacket.class); + try { + server = new Server(5555); + } catch (Exception e) { + LOGGER.error("Unable to launch TASmod server: {}", e); + } + } } diff --git a/src/main/java/com/minecrafttas/tasmod/TASmodClient.java b/src/main/java/com/minecrafttas/tasmod/TASmodClient.java index 52f81046..606d8660 100644 --- a/src/main/java/com/minecrafttas/tasmod/TASmodClient.java +++ b/src/main/java/com/minecrafttas/tasmod/TASmodClient.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.UUID; import org.lwjgl.input.Keyboard; @@ -15,6 +16,7 @@ import com.minecrafttas.common.events.EventClient.EventPlayerJoinedClientSide; import com.minecrafttas.common.events.EventClient.EventPlayerLeaveClientSide; import com.minecrafttas.common.events.EventListener; +import com.minecrafttas.server.Client; import com.minecrafttas.tasmod.externalGui.InputContainerView; import com.minecrafttas.tasmod.gui.InfoHud; import com.minecrafttas.tasmod.handlers.InterpolationHandler; @@ -71,6 +73,8 @@ public class TASmodClient implements ClientModInitializer, EventClientInit, Even public static InterpolationHandler interpolation = new InterpolationHandler(); + public static Client client; + public static void createTASDir() { File tasDir=new File(tasdirectory); if(!tasDir.exists()) { @@ -125,6 +129,17 @@ protected boolean isKeyDown(KeyBinding i) { EventListener.register(keybindManager); EventListener.register(interpolation); + + try { + // connect to server and authenticate + client = new Client("127.0.0.1", 5555); + UUID uuid = mc.getSession().getProfile().getId(); + if (uuid == null) // dev environment + uuid = UUID.randomUUID(); + client.authenticate(uuid); + } catch (Exception e) { + TASmod.LOGGER.error("Unable to connect TASmod client: {}", e); + } } @Override