From 26a15a0b15d19f271a13711a5d87e7876b1a1b23 Mon Sep 17 00:00:00 2001 From: Sen Date: Sun, 4 May 2025 01:07:17 +0200 Subject: [PATCH] remove game ipc --- java/src/game/ServerProcess.java | 146 ------------------------------- 1 file changed, 146 deletions(-) delete mode 100644 java/src/game/ServerProcess.java diff --git a/java/src/game/ServerProcess.java b/java/src/game/ServerProcess.java deleted file mode 100644 index a418d29..0000000 --- a/java/src/game/ServerProcess.java +++ /dev/null @@ -1,146 +0,0 @@ -package game; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileFilter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.util.function.Consumer; - -import game.log.Log; -import game.util.Tuple; -import game.util.Util; - -public class ServerProcess { - private final Consumer monitor; - private final ProcessBuilder builder; - - private Process process; - private PrintWriter writer; - private boolean running; - private String message; - private int total; - private int progress = -1; - private int lastTick; - - public ServerProcess(Consumer monitor, File dir, int minMem, int maxMem, int port) { - this.monitor = monitor; - File jar = new File("game.jar"); - String path; - if(jar.exists()) { - path = jar.getAbsolutePath(); - } - else { - path = new File("../bin").getAbsolutePath() + File.pathSeparator + new File("../data").getAbsolutePath(); - for(File file : new File("../lib").listFiles(new FileFilter() { - public boolean accept(File pathname) { - return pathname.getName().endsWith(".jar") && !pathname.getName().endsWith("-sources.jar"); - } - })) { - path += File.pathSeparator + file.getAbsolutePath(); - } - } - this.builder = new ProcessBuilder("java", "-Xms" + minMem + "M", "-Xmx" + maxMem + "M", "-cp", path, - "-Dserver.port=" + port, dir == null ? "-Dserver.debug" : "-Dserver.pipe", "game.Server") - .directory(dir).redirectErrorStream(true); - } - - public void start() { - if(this.builder.directory() != null) - this.builder.directory().mkdirs(); - try { - this.process = this.builder.start(); - } - catch(IOException e) { - Log.SYSTEM.error(e, "Konnte Server nicht starten"); - this.process = null; - } -// this.builder = null; - if(this.process == null) - return; - Thread con = new Thread(new Runnable() { - private final BufferedReader reader = new BufferedReader(new InputStreamReader(new BufferedInputStream(ServerProcess.this.process.getInputStream()))); - - public void run() { - while(true) { - String line; - try { - line = this.reader.readLine(); - } - catch(IOException e) { - line = null; - } - if(line == null) - break; - if(line.startsWith("#")) { - line = line.substring(1); - Tuple data = Util.getKeyValue(line); - if(data.first.equals("running")) - ServerProcess.this.running = Boolean.parseBoolean(data.second); - else if(data.first.equals("message")) - ServerProcess.this.message = data.second; - else if(data.first.equals("total")) - ServerProcess.this.total = Integer.parseInt(data.second); - else if(data.first.equals("progress")) - ServerProcess.this.progress = Integer.parseInt(data.second); - else if(data.first.equals("tick")) - ServerProcess.this.lastTick = Integer.parseInt(data.second); - else if(data.first.equals("console")) - ServerProcess.this.monitor.accept(data.second); - Log.SYSTEM.trace("server cmd %s -- %s", data.first, data.second); - continue; - } - System.err.println(line); - } - } - }, "Server console listener"); - con.setDaemon(true); - con.start(); - this.writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new BufferedOutputStream(this.process.getOutputStream()))), true); - } - - public boolean isStarted() { - return this.running; - } - - public boolean isStopped() { - return !this.running; - } - - public String getMessage() { - return this.message; - } - - public int getProgress() { - return this.progress; - } - - public int getTotal() { - return this.total; - } - - public int getLastTick() { - return this.lastTick; - } - - public void shutdown() { - try { - this.writer.println("#end"); - } - catch(Exception e) { - } - } - - public void runCommand(String cmd) { - try { - this.writer.println(cmd); - } - catch(Exception e) { - } - } -}