/**
  * create a profile based on command line arguments
  *
  * <ul>
  *   <li>-u: username
  *   <li>-p: password
  *   <li>-c: character name (defaults to username)
  *   <li>-h: hostname
  *   <li>-P: port
  *   <li>-S: pre authentication seed
  * </ul>
  *
  * @param args command line arguments
  * @return profile
  */
 public static Profile createFromCommandline(String[] args) {
   Profile profile = new Profile();
   int i = 0;
   while (i != args.length) {
     if (args[i].equals("-u")) {
       profile.setUser(args[i + 1]);
     } else if (args[i].equals("-p")) {
       profile.setPassword(args[i + 1]);
     } else if (args[i].equals("-c")) {
       profile.setCharacter(args[i + 1]);
     } else if (args[i].equals("-h")) {
       profile.setHost(args[i + 1]);
     } else if (args[i].equals("-P")) {
       profile.setPort(Integer.parseInt(args[i + 1]));
     } else if (args[i].equals("-S")) {
       profile.setSeed(args[i + 1]);
     }
     i++;
   }
   if (profile.getCharacter() == null) {
     profile.setCharacter(profile.getUser());
   }
   return profile;
 }
  /**
   * Decode a login profile from a string.
   *
   * @param info The string encoded profile.
   * @return A login profile.
   */
  static Profile decode(final String info) {
    String[] params;
    Profile profile;
    String s;

    params = info.split("\n");

    profile = new Profile();

    /*
     * Server Host
     */
    if (params.length > 0) {
      s = params[0];

      for (final String host : OLD_SERVER_HOSTS) {
        if (s.equals(host)) {
          s = NEW_SERVER_HOST;
          break;
        }
      }

      if (s.length() != 0) {
        profile.setHost(s);
      }
    }

    /*
     * User
     */
    if (params.length > 1) {
      s = params[1];

      if (s.length() != 0) {
        profile.setUser(s);
      }
    }

    /*
     * Password
     */
    if (params.length > 2) {
      s = params[2];

      if (s.length() != 0) {
        profile.setPassword(s);
      }
    }

    /*
     * Server Port
     */
    if (params.length > 3) {
      s = params[3];

      if (s.length() != 0) {
        try {
          profile.setPort(Integer.parseInt(s));
        } catch (final NumberFormatException ex) {
          // use default port if port is not a number number
        }
      }
    }

    /*
     * Server Protocol (TCP/UDP)
     */
    // params[4]
    //
    // ignore this token for compatibility reasons
    // just add what every you want behind it
    return profile;
  }