From 9a94b31e47114753a7894ce476b57ef3848f488d Mon Sep 17 00:00:00 2001 From: "notzed@gmail.com" Date: Mon, 28 Oct 2013 09:59:11 +0000 Subject: [PATCH] Dont hardcode game location, removed some debug. git-svn-id: file:///home/notzed/svn/duskz/trunk@18 b8b59bfb-1aa4-4687-8f88-a62eeb14c21e --- DuskServer/src/duskz/server/entityz/Game.java | 11 ------ .../src/duskz/server/entityz/GameServer.java | 34 +++++++++++++++++-- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/DuskServer/src/duskz/server/entityz/Game.java b/DuskServer/src/duskz/server/entityz/Game.java index 6fce193..d7860aa 100644 --- a/DuskServer/src/duskz/server/entityz/Game.java +++ b/DuskServer/src/duskz/server/entityz/Game.java @@ -865,15 +865,4 @@ public class Game { public Faction getFaction(String name) { return factions.get(name); } - - public static void main(String[] args) throws IOException { - Game g = new Game(); - - g.init(new File("/home/notzed/dusk/game")); - - String[] names = {"z", "fuckface", "god", "root", "default"}; - for (String n : names) { - System.out.println("good name: " + n + " " + g.isGoodName(n)); - } - } } diff --git a/DuskServer/src/duskz/server/entityz/GameServer.java b/DuskServer/src/duskz/server/entityz/GameServer.java index c327271..3621335 100644 --- a/DuskServer/src/duskz/server/entityz/GameServer.java +++ b/DuskServer/src/duskz/server/entityz/GameServer.java @@ -53,12 +53,40 @@ public class GameServer { MasterClock clockThread; ConnectionManager connectionThread; + static void usage(String why) { + System.err.println(); + System.err.println("Usage: gameserver [ path-to-game ]"); + System.err.println(); + System.err.println(" Game may also be started from within a game directory."); + System.err.println(); + System.err.println(why); + } + /** * Creates a new DuskServer object; */ public static void main(String args[]) { // TODO: parse arguments for game data location - File path = new File("/home/notzed/dusk/game"); + File path = null; + + for (int i = 0; i < args.length; i++) { + String cmd = args[i]; + + if (cmd.startsWith("-")) { + // some args + } else { + path = new File(cmd); + } + } + + if (path == null) { + path = new File("."); + + if (!new File(path, "config").exists()) { + usage("No game found"); + return; + } + } GameServer server = new GameServer(); @@ -101,11 +129,11 @@ public class GameServer { serverSocket = new ServerSocket(game.port, 25); } catch (Exception e) { game.log.printf(e, "Server init failed", e); - e.printStackTrace(); + usage(e.getLocalizedMessage()); + e.printStackTrace(System.err); abort(); } - connectionThread.start(); clockThread.start(); } -- 2.39.2