i++; if (i<args.length) { if (args[i].equals("-port")) { i++; if (i<args.length) { usePort = Integer.decode(args[i]).intValue(); } else { i--; usePort = PreferenceManager.getClientPreferences().getLastServerPort(); } } else { i--; usePort = PreferenceManager.getClientPreferences().getLastServerPort(); } }  megamek.common.Compute.d6();  Server dedicated = new Server(PreferenceManager.getClientPreferences().getLastServerPass(), usePort);  dedicated.getGame().getOptions().loadOptions(null); if (null != savegameFileName) { dedicated.loadGame(new File(savegameFileName)); } return; } else if (args[i].equals("-log")) {  i++; if (i >= args.length || args[i].equals("none") || args[i].equals("off")) {
CommandLineParser cp = new CommandLineParser(args);  try { cp.parse(); String lf = cp.getLogFilename(); if (lf != null ) { if (lf.equals("none") || lf.equals("off")) {
    public static void main(String[] args) {        int usePort = 2346;        String logFileName = "megameklog.txt"; //$NON-NLS-1$        if (PreferenceManager.getClientPreferences().stampFilenames()) {            logFileName = StringUtil.addDateTimeStamp(logFileName);        }        for (int i = 0; i < args.length; i++) {            if (args[i].equals("-testdice")) { //$NON-NLS-1$                TestDice.testDice();                return;            } else if (args[i].equals("-dedicated")) { //$NON-NLS-1$                // Next argument may be the savegame file's name.                String savegameFileName = null;                i++;                if (i >= args.length || args[i].startsWith("-")) { //$NON-NLS-1$                    // no filename -- bump the argument processing back up                    i--;                } else {                    savegameFileName = args[i];                }                // Next argument may be "-port <number>"                i++;                if (i<args.length) {                    if (args[i].equals("-port")) { //$NON-NLS-1$                        i++;                        if (i<args.length) {                            usePort = Integer.decode(args[i]).intValue();                        } else {                            i--;                            usePort = PreferenceManager.getClientPreferences().getLastServerPort();                        }                    } else {                        i--;                        usePort = PreferenceManager.getClientPreferences().getLastServerPort();                    }                }                // kick off a RNG check                megamek.common.Compute.d6();                // start server                Server dedicated = new Server(PreferenceManager.getClientPreferences().getLastServerPass(),                        usePort);                // load game options from xml file if available                dedicated.getGame().getOptions().loadOptions(null);                if (null != savegameFileName) {                    dedicated.loadGame(new File(savegameFileName));                }                return;            } else if (args[i].equals("-log")) { //$NON-NLS-1$                // Next argument is the log file's name.                i++;                if (i >= args.length || args[i].equals("none") || args[i].equals("off")) { //$NON-NLS-1$ //$NON-NLS-2$                    logFileName = null;                } else {                    logFileName = args[i];                }            } else if (args[i].equals("-testxml")) { //$NON-NLS-1$                // Next argument is the log file's name.                i++;                if (i >= args.length) {                    System.err.println("The '-testxml' flag requires a file name."); //$NON-NLS-1$                } else {                    new TinyXMLTest("xml", args[i]); //$NON-NLS-1$                }                return;            }        }        // Redirect output to logfiles, unless turned off.        if (logFileName != null) {            try {                System.out.println("Redirecting output to " + logFileName); //$NON-NLS-1$                String sLogDir = PreferenceManager.getClientPreferences().getLogDirectory();                File logDir = new File(sLogDir);                if (!logDir.exists()) {                    logDir.mkdir();                }                PrintStream ps = new PrintStream(new BufferedOutputStream(new FileOutputStream(sLogDir + File.separator + logFileName), 64));                System.setOut(ps);                System.setErr(ps);            } catch (Exception e) {                System.err.println("Unable to redirect output to " + logFileName); //$NON-NLS-1$                e.printStackTrace();            }        } // End log-to-file        new MegaMek();    }