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
12 public class D3ServerInfo {
13
14 public static ServerInfo getDetails(int localPort, String ipStr, int port, int infoType, int queryType,
15 int gameType) {
16
17 String queryResult = Util.getInfo(localPort, ipStr, port, "getInfo", infoType, queryType, gameType);
18 if(queryResult == null || queryResult.length() < 1) {
19 return null;
20 }
21
22 queryResult = queryResult.replaceAll("\\^([0-9a-wyzA-WYZ]|x[0-9a-fA-F]{6})", "");
23 ServerInfo serverInfo = null;
24 if(queryResult != null && queryResult.length() > 0) {
25 serverInfo = new ServerInfo();
26 String[] plyrs = queryResult.split("�>");
27
28 serverInfo.setGame(Util.getPartGS2(queryResult, "si_gameType"));
29 serverInfo.setIp(ipStr);
30 serverInfo.setPort(port +"");
31 serverInfo.setName(Util.getPartGS2(queryResult, "si_name"));
32 serverInfo.setPlayerCount(plyrs.length - 1 + "");
33 serverInfo.setMaxPlayers(Util.getPartGS2(queryResult, "si_maxPlayers"));
34 serverInfo.setMap(Util.getPartGS2(queryResult, "si_map"));
35 serverInfo.setFullResponse(queryResult);
36 }
37
38 return serverInfo;
39 }
40
41 public static ArrayList getPlayers(int localPort, String ipStr, int port, int infoType, int queryType,
42 int gameType) {
43
44 ArrayList playerInfo = new ArrayList();
45 String queryResult = Util.getInfo(localPort, ipStr, port, "getstatus", infoType, queryType, gameType);
46 if(queryResult == null || queryResult.length() < 1) {
47 return playerInfo;
48 }
49
50 if(queryResult != null || queryResult.length() > 0) {
51 queryResult = queryResult.replaceAll("\\^([0-9a-wyzA-WYZ]|x[0-9a-fA-F]{6})", "");
52
53 queryResult = queryResult.substring(0, queryResult.length() - 2);
54 char chr = 00;
55 String[] plyrs = queryResult.split("�>");
56 for(int x=1; x < plyrs.length; x++) {
57 String plyr = plyrs[x];
58 String name = plyrs[x].substring(2, plyrs[x].length() - 4);
59
60 PlayerInfo player = new PlayerInfo();
61 player.setDeaths(-9999);
62 player.setKills(-9999);
63 player.setName(name);
64 player.setScore(-9999);
65 playerInfo.add(player);
66 }
67 Collections.sort(playerInfo, new ScoreComparator());
68 }
69
70 return playerInfo;
71
72 }
73
74 }