Skip to content

Usage Examples Java

Sebastian Staudt edited this page Sep 26, 2020 · 4 revisions

Querying game servers Querying a GoldSrc game server listening on IP 192.168.0.114 and port 27016

InetAddress serverIp = InetAddress.getByName("192.168.0.114");
GoldSrcServer server = new GoldSrcServer(serverIp, 27016);
server.initialize();
System.out.println(server.getPlayers());

Querying master servers Querying the GoldSrc master server and getting a random GoldSrc server

Random randomizer = new Random();
MasterServer master = new MasterServer(MasterServer.GOLDSRC_MASTER_SERVER);   
Vector<InetSocketAddress> servers = master.getServers();
InetSocketAddress randomServer = servers.elementAt(
  randomizer.nextInt(servers.size())
);
GoldSrcServer server = new GoldSrcServer(randomServer.getAddress(),
  randomServer.getPort()
);

Controlling game servers using RCON Executing the command status on a local Source server and displaying the output

InetAddress serverIp = InetAddress.getByName("127.0.0.1");
SourceServer server = new SourceServer(serverIp);
try {
  server.rconAuth("passw0rd");
  System.out.println(server.rconExec("status"));
}
catch(RCONNoAuthException e) {
  System.err.println("Could not authenticate with the game server.");
}

Getting information from the Steam Community Getting the Steam Community profile of Valve's Adrian Finol and his TF2 achievements

SteamId id = SteamId.create("demomenz");
GameStats stats = id.getGameStats("tf2");
List<GameAchievement> achievements = stats.getAchievements();
Clone this wiki locally