Dont hardcode game location, removed some debug.
authornotzed@gmail.com <notzed@gmail.com@b8b59bfb-1aa4-4687-8f88-a62eeb14c21e>
Mon, 28 Oct 2013 09:59:11 +0000 (09:59 +0000)
committernotzed@gmail.com <notzed@gmail.com@b8b59bfb-1aa4-4687-8f88-a62eeb14c21e>
Mon, 28 Oct 2013 09:59:11 +0000 (09:59 +0000)
git-svn-id: file:///home/notzed/svn/duskz/trunk@18 b8b59bfb-1aa4-4687-8f88-a62eeb14c21e

DuskServer/src/duskz/server/entityz/Game.java
DuskServer/src/duskz/server/entityz/GameServer.java

index 6fce193..d7860aa 100644 (file)
@@ -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));
-               }
-       }
 }
index c327271..3621335 100644 (file)
@@ -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();
        }