Package net.sourceforge.queried

Examples of net.sourceforge.queried.ServerInfo


  public static ServerInfo getDetails(int localPort, String ipStr, int port, int infoType, int queryType,
          int gameType) {

    String queryResult = Util.getInfo(localPort, ipStr, port, infoType, queryType, gameType);

    ServerInfo serverInfo = null;
    if (queryResult != null && queryResult.length() > 0) {
      serverInfo = new ServerInfo();
      serverInfo.setGame(Util.getPartGS2(queryResult, "gamename"));
      serverInfo.setGameVersion(Util.getPartGS2(queryResult, "gamever"));
      serverInfo.setIp(ipStr);
      serverInfo.setPort(Util.getPartGS2(queryResult, "hostport"));
      serverInfo.setName(Util.getPartGS2(queryResult, "hostname"));
      serverInfo.setMap(Util.getPartGS2(queryResult, "mapname"));
      serverInfo.setPlayerCount(Util.getPartGS2(queryResult, "numplayers"));
      serverInfo.setMaxPlayers(Util.getPartGS2(queryResult, "maxplayers"));
      serverInfo.setFullResponse(queryResult);
    }

    return serverInfo;
  }
View Full Code Here


        return null;
      } else if (buf[0] != buf[1] || buf[1] != buf[2] || buf[2] != buf[3] || buf[4] != 'm') {
        return null;
      }

      ServerInfo serverInfo = new ServerInfo();

      int off = 5;

      InetAddress inettst;
      try {
        inettst = InetAddress.getByName(ipStr);
        serverInfo.setIp(inettst.getHostAddress());
      } catch (UnknownHostException e) {
        serverInfo.setIp(ipStr);
      }

      serverInfo.setPort(port + "");

      while (buf[off] != 0) {
        off++;
      }

      off++;

      StringBuffer netName = new StringBuffer(20);
      while (buf[off] != 0) {
        netName.append((char) (buf[off++] & 255));
      }
      serverInfo.setName(netName.toString());

      off++;

      StringBuffer mapName = new StringBuffer(20);
      while (buf[off] != 0) {
        mapName.append((char) (buf[off++] & 255));
      }
      serverInfo.setMap(mapName.toString());

      off++;

      // skip game directory
      while (buf[off] != 0) {
        off++;
      }

      off++;

      StringBuffer gameDesc = new StringBuffer(20);
      while (buf[off] != 0) {
        gameDesc.append((char) (buf[off++] & 255));
      }
      serverInfo.setGame(gameDesc.toString());

      off++;

      int playerCount = buf[off] & 255;
      serverInfo.setPlayerCount(playerCount + "");

      off++;

      int maxPlayerCount = buf[off] & 255;
      serverInfo.setMaxPlayers(maxPlayerCount + "");
      serverInfo.setFullResponse(new String(buf));

      return serverInfo;
    } catch (UnsupportedEncodingException ex) {
      throw new IllegalStateException(ex);
    }
View Full Code Here

    if (queryResult == null || queryResult.length() == 0) {
      return null;
    }

    ServerInfo serverInfo = new ServerInfo();
    try {
      // verify we got what we wanted
      int[] offsetHolder = {0};
      if (queryResult.charAt(0) == 128) {
        offsetHolder[0] = 4;
      }
      if (queryResult.charAt(offsetHolder[0]) != 0) {
        return null;
      }
      offsetHolder[0]++;

      serverInfo.setIp(ipStr);

      getInt(queryResult, offsetHolder); // ignore server id
      getString(queryResult, offsetHolder); // ignore server ip (because it's not reliable)
      serverInfo.setPort(Integer.toString(getInt(queryResult, offsetHolder))); // ignore game port
      getInt(queryResult, offsetHolder); // ignore query port
      serverInfo.setName(getString(queryResult, offsetHolder)); // server name
      serverInfo.setMap(getString(queryResult, offsetHolder)); // map
      serverInfo.setGame(getString(queryResult, offsetHolder)); // game type
      serverInfo.setPlayerCount(Integer.toString(getInt(queryResult, offsetHolder))); // currently playing
      serverInfo.setMaxPlayers(Integer.toString(getInt(queryResult, offsetHolder))); // max players
      getInt(queryResult, offsetHolder); // ignore ping
      serverInfo.setFullResponse(queryResult);

    } catch (StringIndexOutOfBoundsException e) {
      return null;
    }

    // attempt to get game version also.. it's available through
    // the game info query

    queryResult =
            Util.getInfo(localPort, ipStr, port, "\u0078\u0000\u0000\u0000\u0001", infoType, queryType, gameType);

    if (queryResult == null || queryResult.length() == 0) {
      return serverInfo;
    }

    try {
      // verify we got what we wanted
      int[] offsetHolder = {0};
      if (queryResult.charAt(0) == 128) {
        offsetHolder[0] = 4;
      }
      if (queryResult.charAt(offsetHolder[0]) == 1) {
        offsetHolder[0]++;

        // loop through the key-value pairs
        while (offsetHolder[0] < queryResult.length()) {
          String key = getString(queryResult, offsetHolder);
          String value = getString(queryResult, offsetHolder);
          if (key.equals("ServerVersion")) {
            serverInfo.setGameVersion(value);
            break;
          }
        }
      }
View Full Code Here

  public static ServerInfo getDetails(int localPort, String ipStr, int port, int infoType, int queryType,
          int gameType) {

    String queryResult = Util.getInfo(localPort, ipStr, port, infoType, queryType, gameType);
    ServerInfo serverInfo = null;
    if (queryResult != null && queryResult.length() > 0) {
      serverInfo = new ServerInfo();
      serverInfo.setGame(Util.getPartGS2(queryResult, "gamename"));
      serverInfo.setGameVersion(Util.getPartGS2(queryResult, "gamever"));
      serverInfo.setIp(ipStr);
      serverInfo.setPort(Util.getPartGS2(queryResult, "hostport"));
      serverInfo.setName(Util.getPartGS2(queryResult, "hostname"));
      serverInfo.setMap(Util.getPartGS2(queryResult, "mapname"));
      serverInfo.setPlayerCount(Util.getPartGS2(queryResult, "numplayers"));
      serverInfo.setMaxPlayers(Util.getPartGS2(queryResult, "maxplayers"));
      serverInfo.setFullResponse(queryResult);
    }

    return serverInfo;
  }
View Full Code Here

TOP

Related Classes of net.sourceforge.queried.ServerInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.