diff --git a/java/src/game/Server.java b/java/src/game/Server.java index d775668..59071e9 100755 --- a/java/src/game/Server.java +++ b/java/src/game/Server.java @@ -107,6 +107,8 @@ public final class Server implements IThreadListener { private final Map warps = Maps.newTreeMap(); private final CommandEnvironment scriptEnv = new CommandEnvironment(this); private final boolean debug; + private final boolean ipcpipe; + private final String token; private WorldServer space; private ChannelFuture endpoint; @@ -135,17 +137,24 @@ public final class Server implements IThreadListener { public static void main(String[] args) { Util.checkOs(); Registry.setup("Server thread"); - final Server server = new Server(false); + boolean debug = Boolean.parseBoolean(System.getProperty("server.debug", "false")); + boolean ipc = debug || Boolean.parseBoolean(System.getProperty("server.pipe", "false"));; + String token = System.getProperty("server.token", null); + int port = Integer.parseInt(System.getProperty("server.port", "" + Config.PORT)); + int distance = Integer.parseInt(System.getProperty("server.distance", "" + 0)); + final Server server = new Server(debug, ipc, token); Registry.addShutdownHook(new Runnable() { public void run() { server.stopServer(); } }); - server.run(); + server.run(port, distance); } - private Server(boolean debug) { + private Server(boolean debug, boolean ipc, String token) { this.debug = debug; + this.ipcpipe = ipc; + this.token = token; } public CommandEnvironment getScriptEnvironment() { @@ -245,12 +254,14 @@ public final class Server implements IThreadListener { } } - public void run() { + public void run(int port, int distance) { long time = System.currentTimeMillis(); Log.JNI.info("Starte Server Version " + Config.VERSION); if(!this.debug) { this.setMessage("Welt wird erstellt und geladen"); FolderInfo info = Region.loadWorldInfo(null); + if(distance > 0) + Config.set("viewDistance", "" + distance, null); // if(dtime == -1L) // { // dtime = World.START_TIME; //// Config.set("spawnDim", "1", null); @@ -289,6 +300,8 @@ public final class Server implements IThreadListener { Config.set("weatherChanges", "false", null); Config.set("mobSpawning", "false", null); Config.set("spawnRadius", "0", null); + if(distance > 0) + Config.set("viewDistance", "" + distance, null); this.worlds.add(this.space = new WorldServer(this, World.START_TIME, Space.INSTANCE, true)); this.dimensions.put(this.space.dimension.getDimensionId(), this.space); @@ -301,7 +314,8 @@ public final class Server implements IThreadListener { } WorldServer.loadWarps(dim, this.warps); } -// this.openLAN(); + if(port >= 0) + this.bind(port); } Log.JNI.info("Server gestartet in " + String.format("%.1f", (double)(System.currentTimeMillis() - time) / 1000.0) + " Sekunden"); while(this.running) { @@ -1105,21 +1119,21 @@ public final class Server implements IThreadListener { } public void bind(int port) { - this.schedule(new Runnable() { - public void run() { - if(port >= 0) { - try { - Server.this.setLanEndpoint(port); - } - catch(IOException e) { - Log.JNI.error(e, "**** KONNTE NICHT AN PORT " + port + " ANBINDEN!"); - } - } - else { - Server.this.unsetLanEndpoint(); - } +// this.schedule(new Runnable() { +// public void run() { + if(port >= 0) { + try { + Server.this.setLanEndpoint(port); } - }); + catch(IOException e) { + Log.JNI.error(e, "**** KONNTE NICHT AN PORT " + port + " ANBINDEN!"); + } + } + else { + Server.this.unsetLanEndpoint(); + } +// } +// }); } public void shutdown() { diff --git a/java/src/game/ServerProcess.java b/java/src/game/ServerProcess.java index efdbb4f..b5516aa 100644 --- a/java/src/game/ServerProcess.java +++ b/java/src/game/ServerProcess.java @@ -28,8 +28,10 @@ public class ServerProcess { for(int z = 0; z < key.length; z++) { sb.append(String.format("%02x", key[z] & 255)); } - this.builder = new ProcessBuilder("java", "-Xms", minMem + "M", "-Xmx", maxMem + "M", "-jar", "game.jar", "game.Server", - "-p", "" + port, "-d", "" + distance, "-t", sb.toString()).directory(dir).redirectErrorStream(true); + File jar = new File("game.jar"); + this.builder = new ProcessBuilder("java", "-Xms" + minMem + "M", "-Xmx" + maxMem + "M", "-cp", jar.exists() ? jar.getAbsolutePath() : new File("../bin").getAbsolutePath(), + "-Dserver.port=" + port, "-Dserver.distance=" + distance, "-Dserver.token=" + sb.toString(), dir == null ? "-Dserver.debug" : "-Dserver.pipe", "game.Server") + .directory(dir).redirectErrorStream(true); } public void start() { @@ -69,9 +71,10 @@ public class ServerProcess { ServerProcess.this.total = Integer.parseInt(data.second); if(data.first.equals("progress")) ServerProcess.this.progress = Integer.parseInt(data.second); + Log.SYSTEM.info("server cmd %s -- %s", data.first, data.second); continue; } - Log.SYSTEM.info("==SERVER== %s", line); + System.err.println(line); } } }, "Server console listener"); diff --git a/java/src/game/network/NetConnection.java b/java/src/game/network/NetConnection.java index 6ec4c02..859f200 100755 --- a/java/src/game/network/NetConnection.java +++ b/java/src/game/network/NetConnection.java @@ -95,6 +95,7 @@ public class NetConnection extends SimpleChannelInboundHandler else { comp = "Interner Fehler: " + p_exceptionCaught_2_; + Log.SYSTEM.error(p_exceptionCaught_2_, "Fehler in der Verbindung mit %s", this.getCutAddress()); } this.closeChannel(comp); diff --git a/java/src/game/packet/SPacketCharacterList.java b/java/src/game/packet/SPacketCharacterList.java index 9e50e49..a0b7fe3 100644 --- a/java/src/game/packet/SPacketCharacterList.java +++ b/java/src/game/packet/SPacketCharacterList.java @@ -8,6 +8,7 @@ import java.util.Map.Entry; import game.collect.Maps; import game.entity.npc.Alignment; import game.entity.npc.PlayerCharacter; +import game.log.Log; import game.network.ClientPlayer; import game.network.Player; import game.world.BlockPos; @@ -24,17 +25,21 @@ public class SPacketCharacterList implements Packet { public SPacketCharacterList(int selected) { this.selected = selected; + Log.SYSTEM.info("PPPPPPPPPPPPPPPPP selected" + selected); } public SPacketCharacterList(int selected, int index, PlayerCharacter conns) { this.players.put(index, conns); this.selected = selected; + Log.SYSTEM.info("PPPPPPPPPPPPPPPPP selected " + selected + " @ " + index + " : " + (conns == null ? "[null]" : conns.name + " - " + conns.dim)); } public SPacketCharacterList(int selected, Iterable conns) { int pos = 0; + Log.SYSTEM.info("PPPPPPPPPPPPPPPPP list selected" + selected); for(PlayerCharacter conn : conns) { this.players.put(pos++, conn); + Log.SYSTEM.info("PPPPPPPPPPPPPPPPP list : " + conn.name + " - " + conn.dim); } this.selected = selected; } diff --git a/java/src/game/util/Util.java b/java/src/game/util/Util.java index a5d079c..03a44cd 100644 --- a/java/src/game/util/Util.java +++ b/java/src/game/util/Util.java @@ -1,10 +1,14 @@ package game.util; import java.awt.GraphicsEnvironment; +import java.util.List; +import java.util.Map; import java.util.function.Function; import javax.swing.JOptionPane; +import game.collect.Lists; +import game.collect.Maps; import game.log.Log; import game.properties.IStringSerializable; @@ -322,4 +326,53 @@ int utf_len(const char *str) { public static Tuple getKeyValue(String text) { return getKeyValue(text, ' '); } + + private static Object parseObject(String arg) { + try { + return Float.parseFloat(arg); + } + catch(NumberFormatException e) { + } + try { + return Integer.parseInt(arg); + } + catch(NumberFormatException e) { + } + return arg; + } + + public static Map parseArgsSimple(String[] args) { + Map map = Maps.newHashMap(); + List list = Lists.newArrayList(); + String option = null; + boolean parse = true; + for(int z = 0; z < args.length; z++) { + String arg = args[z]; + if(arg.startsWith("--")) { + if(arg.length() == 2) { + parse = false; + continue; + } + if(option != null) + map.put(option, null); + option = arg.substring(2); + } + else if(arg.startsWith("-") && arg.length() == 2) { + if(option != null) + map.put(option, null); + option = arg.substring(1); + } + else if(option != null) { + map.put(option, parseObject(arg)); + option = null; + } + else { + list.add(parseObject(arg)); + } + } + if(option != null) + map.put(option, null); + map.put("__pos", list); + return map; + } } diff --git a/java/src/game/window/Window.java b/java/src/game/window/Window.java index c69c2a1..dbd79b4 100644 --- a/java/src/game/window/Window.java +++ b/java/src/game/window/Window.java @@ -31,7 +31,7 @@ import game.log.Log; public abstract class Window { public static long getTime() { - return glfwGetTimerValue() / (glfwGetTimerFrequency() / 1000000L); + return System.nanoTime() / 1000L; // glfwGetTimerValue() / (glfwGetTimerFrequency() / 1000000L); } public static void setWindowed(int xpos, int ypos, int xsize, int ysize) { if(window != NULL)