From: <sno...@us...> - 2006-04-04 00:54:11
|
Revision: 40 Author: snowdog_ Date: 2006-04-03 17:54:00 -0700 (Mon, 03 Apr 2006) ViewCVS: http://svn.sourceforge.net/openrpg/?rev=40&view=rev Log Message: ----------- Added basic command line arg handling routines including a switch to run console based server. Modified Paths: -------------- trunk/src/openrpg2/Client.java trunk/src/openrpg2/Server.java trunk/src/openrpg2/client/core/ORPGClient.java trunk/src/openrpg2/common/core/ORPGConstants.java trunk/src/openrpg2/server/core/ORPGServer.java Added Paths: ----------- trunk/src/openrpg2/common/util/ArgumentParser.java Modified: trunk/src/openrpg2/Client.java =================================================================== --- trunk/src/openrpg2/Client.java 2006-04-01 10:26:35 UTC (rev 39) +++ trunk/src/openrpg2/Client.java 2006-04-04 00:54:00 UTC (rev 40) @@ -6,7 +6,10 @@ package openrpg2; +import java.util.HashMap; import openrpg2.client.core.ORPGClient; +import openrpg2.common.core.ORPGConstants; +import openrpg2.common.util.ArgumentParser; /** * @@ -14,8 +17,8 @@ */ public class Client { - + /** Startup Class for OpenRPG2. Handles any pre-application start activities that need done.*/ public Client() { } @@ -27,17 +30,42 @@ */ public static void main(String[] args) { + HashMap argMap = ArgumentParser.parseArgs(args); + if (argMap.containsKey("-help")){ showConsoleHelp(); } + if (argMap.containsKey("v")){ showVersion(); } + if (argMap.containsKey("check")){ doDiagnosticCheck(); } - //TODO handle command line args here boolean runclient = true; - - if (runclient == true){ + + + if (runclient == true){ //start the client - ORPGClient orpg = new ORPGClient(); + ORPGClient orpg = new ORPGClient(argMap); orpg.execute(); - } - else{ + } else{ //do some ther function... perhaps auto-testing or diagnostics? } } + + private static void doDiagnosticCheck(){ + //TODO: do some directory checking, network probing, or whatever then exit + System.err.println("ERROR: -check COMMAND NOT IMPLEMENTED YET"); + System.exit(ORPGConstants.NORMAL_TERMINATION); + } + + private static void showConsoleHelp(){ + StringBuffer helpString = new StringBuffer(); + helpString.append(ORPGConstants.getOpenRPG2Name()); + helpString.append(" Client Command Line Help\n"); + helpString.append("--help Display this help message and exit\n"); + helpString.append("-v Print version information and exit\n"); + helpString.append("-check Does system checks and diagnostics then exits\n"); + System.out.println(helpString.toString()); + System.exit(ORPGConstants.NORMAL_TERMINATION); + } + + private static void showVersion(){ + System.out.println(ORPGConstants.getVersionString()); + System.exit(ORPGConstants.NORMAL_TERMINATION); + } } \ No newline at end of file Modified: trunk/src/openrpg2/Server.java =================================================================== --- trunk/src/openrpg2/Server.java 2006-04-01 10:26:35 UTC (rev 39) +++ trunk/src/openrpg2/Server.java 2006-04-04 00:54:00 UTC (rev 40) @@ -20,6 +20,9 @@ package openrpg2; +import java.util.HashMap; +import openrpg2.common.core.ORPGConstants; +import openrpg2.common.util.ArgumentParser; import openrpg2.server.core.ORPGServer; /** @@ -28,8 +31,8 @@ */ public class Server { - + /** Startup Class for OpenRPG2. Handles any pre-application start activities that need done.*/ public Server() { } @@ -41,18 +44,53 @@ */ public static void main(String[] args) { - System.out.println("Server running"); + boolean runserver = true; + + + HashMap argmap = ArgumentParser.parseArgs(args); //TODO handle command line args here - boolean runserver = true; + + if (argmap.containsKey("-help")){ showConsoleHelp(); } + if (argmap.containsKey("v")){ showVersion(); } + if (argmap.containsKey("check")){ doDiagnosticCheck(); } + - if (runserver == true){ - //start the client - ORPGServer orpg = new ORPGServer(); - + if (argmap.containsKey("c")){ + //Launch the console based server + System.err.println("ERROR: CONSOLE BASED SERVER NOT IMPLEMENTED"); } else{ - //do some ther function... perhaps auto-testing or diagnostics? - } - System.out.println("main() exit"); + //start the GUI-based server + ORPGServer orpg = new ORPGServer(argmap); + + } + } + + private static void doDiagnosticCheck(){ + //TODO: do some directory checking, network probing, or whatever then exit + System.err.println("ERROR: -check COMMAND NOT IMPLEMENTED YET"); + System.exit(ORPGConstants.NORMAL_TERMINATION); + } + + private static void showConsoleHelp(){ + StringBuffer helpString = new StringBuffer(); + helpString.append(ORPGConstants.getOpenRPG2Name()); + helpString.append(" Server Command Line Help\n"); + helpString.append("--help Display this help message and exit\n"); + helpString.append("-v Print version information and exit\n"); + helpString.append("-c Run the server in nongraphical console mode\n"); + helpString.append("-check Does system checks and diagnostics then exits\n"); + System.out.println(helpString.toString()); + System.exit(ORPGConstants.NORMAL_TERMINATION); + } + + private static void showVersion(){ + System.out.println(ORPGConstants.getVersionString()); + System.exit(ORPGConstants.NORMAL_TERMINATION); + } + + + + } \ No newline at end of file Modified: trunk/src/openrpg2/client/core/ORPGClient.java =================================================================== --- trunk/src/openrpg2/client/core/ORPGClient.java 2006-04-01 10:26:35 UTC (rev 39) +++ trunk/src/openrpg2/client/core/ORPGClient.java 2006-04-04 00:54:00 UTC (rev 40) @@ -19,14 +19,12 @@ */ package openrpg2.client.core; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; +import java.util.HashMap; import javax.swing.JMenuItem; import openrpg2.common.core.SplashScreen; import openrpg2.common.core.logging.DevConsole; import openrpg2.common.core.ORPGConstants; import openrpg2.common.core.engine.Engine; -import openrpg2.common.core.gui.GUIManager; import openrpg2.common.core.logging.SystemLogger; import openrpg2.common.core.network.NetworkClient; import openrpg2.common.core.network.NetworkClientModule; @@ -39,9 +37,11 @@ private JMenuItem menuItem_quit = null; private DevConsole devconsole = new DevConsole(); private SystemLogger sysLogger = null; + private HashMap argMap = null; - public ORPGClient() { + public ORPGClient(HashMap argmap) { + argMap = argmap; sysLogger = new SystemLogger(devconsole); devconsole.postSystemInfo(); devconsole.postUserInfo(); Modified: trunk/src/openrpg2/common/core/ORPGConstants.java =================================================================== --- trunk/src/openrpg2/common/core/ORPGConstants.java 2006-04-01 10:26:35 UTC (rev 39) +++ trunk/src/openrpg2/common/core/ORPGConstants.java 2006-04-04 00:54:00 UTC (rev 40) @@ -27,7 +27,11 @@ */ public abstract class ORPGConstants { //"official" OpenRPG2 Application Name - static final public String OPENRPG2_NAME = "OpenRPG2 (alpha)"; + static final public String OPENRPG2_NAME = "OpenRPG2"; + static final public String OPENRPG2_NAME_SUFFIX = "(alpha)"; + static final public int OPENRPG2_MAJOR_VERSION = 2; + static final public int OPENRPG2_MINOR_VERSION = 0; + static final public int OPENRPG2_MICRO_VERSION = 1; //ORPGMESSAGE HEADER CONSTANTS @@ -47,6 +51,7 @@ static final public int OPMODE_DEFAULT = OPMODE_CLIENT; //default as client //TERMINATION CODES ( for use with System.Exit() ) + static final public int NORMAL_TERMINATION = 0; static final public int FATAL_NO_NETWORK_HOOK = 10; static final public int FATAL_NO_MODULE_LOADER = 11; static final public int FATAL_NETWORK_MODULE_FAIL = 12; @@ -56,4 +61,23 @@ */ public ORPGConstants() {} + static public String getOpenRPG2Name(){ + return OPENRPG2_NAME+" "+OPENRPG2_NAME_SUFFIX; + } + + static public String getVersionString(){ + StringBuffer n = new StringBuffer(); + n.append(OPENRPG2_NAME); + n.append(" "); + n.append(OPENRPG2_MAJOR_VERSION); + n.append("."); + n.append(OPENRPG2_MINOR_VERSION); + n.append("."); + n.append(OPENRPG2_MICRO_VERSION); + n.append(" "); + n.append(OPENRPG2_NAME_SUFFIX); + + return n.toString(); + } + } Added: trunk/src/openrpg2/common/util/ArgumentParser.java =================================================================== --- trunk/src/openrpg2/common/util/ArgumentParser.java (rev 0) +++ trunk/src/openrpg2/common/util/ArgumentParser.java 2006-04-04 00:54:00 UTC (rev 40) @@ -0,0 +1,76 @@ +/* + * ArgumentParser.java + * + * Author: snowdog + * Created: April 3, 2006, 5:38 PM + * + * $Id$ + * + * ==================================================================== + * Copyright (C) 2005-2006 The OpenRPG Project (www.openrpg.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License on www.gnu.org for more details. + * ==================================================================== + */ + +package openrpg2.common.util; + +import java.util.HashMap; + +/** + * + * @author snowdog + */ + +public class ArgumentParser { + + /** Creates a new instance of ArgumentParser */ + public ArgumentParser() { + + } + + public static HashMap parseArgs( String[] args ){ + HashMap a = new HashMap(); + String currentKey = null; + String currentValue = null; + + for (int i = 0; i < args.length; i++){ + String c = args[i]; + + if (c.startsWith("-")){ + if (currentKey != null ){ + //close out active key/vals before processing next cmd arg + a.put(currentKey, currentValue); + currentKey = null; + currentValue = null; + } + c = c.substring(1, c.length()); + c.trim(); + currentKey = c; + + }else{ + if (currentKey != null){ + if (currentValue == null){ + currentValue = c; + } else{ + currentValue = currentValue +" "+c; + } + } + } + } + if (currentKey != null ){ + //close out active key/vals before processing next cmd arg + a.put(currentKey, currentValue); + } + + return a; + } +} Modified: trunk/src/openrpg2/server/core/ORPGServer.java =================================================================== --- trunk/src/openrpg2/server/core/ORPGServer.java 2006-04-01 10:26:35 UTC (rev 39) +++ trunk/src/openrpg2/server/core/ORPGServer.java 2006-04-04 00:54:00 UTC (rev 40) @@ -21,7 +21,7 @@ package openrpg2.server.core; import java.net.InetSocketAddress; -import javax.swing.JFrame; +import java.util.HashMap; import openrpg2.common.core.logging.DevConsole; import openrpg2.common.core.ORPGConstants; import openrpg2.common.core.engine.Engine; @@ -38,7 +38,7 @@ public class ORPGServer { /** Creates a new instance of ORPGServer */ - public ORPGServer() { + public ORPGServer(HashMap argmap) { DevConsole d = new DevConsole(); SystemLogger sysLogger = new SystemLogger(d); @@ -53,6 +53,7 @@ ServerModuleLoader ml = new ServerModuleLoader(); ml.setNetworkModule(new NetworkServerModule(server)); Engine thor = new Engine(server, ml, ORPGConstants.OPMODE_SERVER); + server.setServerAddress(new InetSocketAddress(NetworkConnection.DEFAULT_HOST, NetworkConnection.DEFAULT_PORT)); server.startServer(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |