public static void start(String[] args) { CommandLineParser cp = new CommandLineParser(args); try { cp.parse(); String savegameFileName = cp.getGameFilename(); int usePort; if (cp.getPort() != -1) { usePort = cp.getPort(); } else { usePort = PreferenceManager.getClientPreferences() .getLastServerPort(); String announceUrl = cp.getAnnounceUrl(); String password = cp.getPassword();
private void parsePort() throws ParseException { if (getToken() == TOK_LITERAL) { int newPort = -1; try { newPort = Integer.decode(getTokenValue()).intValue(); } catch (NumberFormatException e) { //ignore, leave at -1 } if ((newPort < 0) || (newPort > 65535)) { error("invalid port number"); //$NON-NLS-1$ } port = newPort; } else { error("port number expected"); //$NON-NLS-1$ } }
@Override protected void start() throws ParseException { while (hasNext()) { int tokType = getToken(); switch (tokType) { case TOK_OPTION: if (getTokenValue().equals(OPTION_PORT)) { nextToken(); parsePort(); } else if (getTokenValue().equals(OPTION_ANNOUNCE)) { nextToken(); parseAnnounce(); } else if (getTokenValue().equals(OPTION_PASSWORD)) { nextToken(); parsePassword(); } break; case TOK_LITERAL: gameFilename = getTokenValue(); nextToken(); break; case TOK_EOF: // Do nothing, although this shouldn't happen break; default: error("unexpected input"); //$NON-NLS-1$ } nextToken(); } }
private void parseAnnounce() throws ParseException { if (getToken() == TOK_LITERAL) { announceUrl = getTokenValue(); } else { error("meta server announce URL expected"); //$NON-NLS-1$ } }
private void parsePassword() throws ParseException { if (getToken() == TOK_LITERAL) { password = getTokenValue(); } else { error("password expected"); //$NON-NLS-1$ } }