1 package net.sourceforge.queried.gametypes;
2
3 import java.util.ArrayList;
4 import java.util.Collections;
5
6 import net.sourceforge.queried.PlayerInfo;
7 import net.sourceforge.queried.ScoreComparator;
8 import net.sourceforge.queried.ServerInfo;
9 import net.sourceforge.queried.Util;
10
11 public class AAServerInfo {
12
13 public static ServerInfo getDetails(int localPort, String ipStr, int port, int infoType, int queryType,
14 int gameType) {
15
16 String queryResult = Util.getInfo(localPort, ipStr, port, infoType, queryType, gameType);
17 ServerInfo serverInfo = null;
18 if(queryResult != null && queryResult.length() > 0) {
19 serverInfo = new ServerInfo();
20 serverInfo.setGame(Util.getPartGS2(queryResult, "gamename"));
21 serverInfo.setGameVersion(Util.getPartGS2(queryResult, "gamever"));
22 serverInfo.setIp(ipStr);
23 serverInfo.setPort(Util.getPartGS2(queryResult, "hostport"));
24 serverInfo.setName(Util.getPartGS2(queryResult, "hostname"));
25 serverInfo.setMap(Util.getPartGS2(queryResult, "mapname"));
26 serverInfo.setPlayerCount(Util.getPartGS2(queryResult, "numplayers"));
27 serverInfo.setMaxPlayers(Util.getPartGS2(queryResult, "maxplayers"));
28 serverInfo.setFullResponse(queryResult);
29 }
30
31 return serverInfo;
32 }
33
34 public static ArrayList getPlayers(int localPort, String ipStr, int port, int infoType, int queryType,
35 int gameType) {
36
37 String recStr = Util.getInfo(localPort, ipStr, port, infoType, queryType, gameType);
38 char chr = 00;
39
40 int start = recStr.indexOf("enemy_"+ chr + chr) + 8;
41 int end = recStr.indexOf("score_t" + chr) - 1;
42 String stripped = recStr.substring(start, end);
43 ArrayList playerInfo = new ArrayList();
44 String[] pieces = stripped.split(chr+"");
45 for(int i=0; i < pieces.length; i++) {
46
47 PlayerInfo player = new PlayerInfo();
48
49 int leader = Integer.parseInt(pieces[i++]);
50
51 int goal = Integer.parseInt(pieces[i++]);
52 player.setScore(leader + goal);
53
54 i++;
55
56 player.setName(pieces[i++]);
57
58 i++;
59
60 i++;
61
62 player.setDeaths(Integer.parseInt(pieces[i++]));
63
64 player.setKills(Integer.parseInt(pieces[i]));
65 playerInfo.add(player);
66 }
67 Collections.sort(playerInfo, new ScoreComparator());
68
69 return playerInfo;
70 }
71 }