1 package net.sourceforge.queried;
2
3
4 import java.io.UnsupportedEncodingException;
5 import java.util.ArrayList;
6 import java.util.Iterator;
7
8
9 public class Demo {
10 public static void main(String[] args) {
11 try {
12
13
14 check("BF2142", "213.115.191.17", 29900);
15 } catch (UnsupportedEncodingException e) {
16
17 e.printStackTrace();
18 }
19 }
20
21 private static void check(String gameType, String ip, int port) throws UnsupportedEncodingException {
22 System.out.println("ServerInfo [" + gameType + "]:");
23
24 ServerInfo serverInfo = QueriEd.serverQuery(gameType, ip, port);
25
26 if (serverInfo == null) {
27 System.out.println("ServerInfo == null");
28 } else {
29 System.out.println(
30 serverInfo.getName() +
31 "\nIP: " + serverInfo.getIp() + ":" + serverInfo.getPort() +
32 "\nGame: " + serverInfo.getGame() +
33 "\nMap: " + serverInfo.getMap() +
34 "\nPlayers: " + serverInfo.getPlayerCount() + "/" + serverInfo.getMaxPlayers() +
35 "\nVersion: " + serverInfo.getGameVersion());
36 System.out.println(
37 "Tickets: Team1: " + serverInfo.getTeam1Tickets()
38 + " :: Team2: " + serverInfo.getTeam2Tickets());
39 }
40
41 System.out.println("PlayerInfo:");
42
43 ArrayList playerInfo = QueriEd.playerQuery(gameType, ip, port);
44
45 if (playerInfo != null && playerInfo.size() > 0) {
46 Iterator iter = playerInfo.iterator();
47 int count = 1;
48
49 while (iter.hasNext()) {
50 PlayerInfo pInfo = (PlayerInfo) iter.next();
51
52 System.out.println(
53 count + ") " + pInfo.getName() + " [" + pInfo.getScore()
54 + "/" + pInfo.getKills() + "/" + pInfo.getDeaths() + "]"
55 + "ping: " + pInfo.getPing() + " rate: "
56 + pInfo.getRate());
57 System.out.println("Clan: " + pInfo.getClan());
58 count++;
59 }
60 } else {
61 System.out.println("No players");
62 }
63 System.out.println("");
64 System.out.println("");
65
66 Iterator games = QueriEd.getSupportedGames().keySet().iterator();
67
68 System.out.print("Supported games");
69 while (games.hasNext()) {
70 String gameKey = (String) games.next();
71
72 System.out.print(" : " + gameKey);
73 }
74 System.out.println();
75 }
76
77 }