Game Server Library

The GameServer library provides tools for Java applications to query server information from popular game servers.

Downloads and Documentation

Features

Supported Games

Game Engine Basic Info. Players Rules Rcon Server List Example Games
Battlefield: Bad Company 2 Y β
Left 4 Dead Y β β α Left 4 Dead 1, Left 4 Dead 2
Orange Box Y β β α Age of Chivalry, Day of Defeat: Source, Garry's Mod, Synergy, Team Fortress 2, Zombie Panic! Source
Source Y β β α β Counterstrike: Source, Half-Life 2
Battlefield 1942 Y Y β β
Unreal Engine 2 Y β Y America's Army, Killing Floor, Unreal Tournament 2003, Unreal Tournament 2004
Unreal Engine 1 Y Y β β Unreal, Unreal Tournament
Gold Source Y Y Y α β Half-Life 1

Legend: Y=Full functionality; β=Full functionality, but not yet optimized; α=Partial functionality that may be rewritten

Third-party Service Aggregation

Requirements

General

These libraries are required for the basic functioning of this library. This will provide you with JavaBean-like objects.

XML Conversion

This library is required for conversion to XML. This will provide you with JDOM Documents.

Rcon Administration

This library is required to use the Rcon interface on Valve-based servers.

Optional

This library is completely optional, but will make master server list retrieval faster. It will allow the DNS lookups of the master server to be cached.

Tips

Invoke the close() Method

The servers based on UdpServer are cached internally. To retrieve the cached copy of the server, use the getInstance() method. To replace the cached version with a new instance, use the new keyword. To remove the instance from cache, invoke the close() method.

Use Asynchronous Methods

If you need to do multiple queries on the same or multiple servers, it's good to do so asynchronously. By adding a listener and invoking methods that do not contain timeout parameters, you can send a query which will return immediately. Your listener will be called when your queries are complete.

Examples

These examples are shown with no error handling for simplicity.

Error Handling

SourceServer server = SourceServer.getInstance(new InetSocketAddress("127.0.0.2", 27015));
server.addListener(new Listener () {
	@Override
	public void errorHandler(Throwable error, GameServer server) {
		System.err.println("Error querying: " + server);
		error.printStackTrace();
	}
});
   

Query

InetSocketAddress addr = new InetSocketAddress("127.0.0.2", 27015);
SourceServer server = SourceServer.getInstance(addr);
try {
	server.load(2000, Request.INFORMATION, Request.PLAYERS, Request.RULES);
} finally {
	server.close();
}
   

Server List

SourceServerList list = new SourceServerList();
list.gameDir = "synergy";
HashSet<SourceServer> serverList = new HashSet<SourceServer>();
ValveServerList<SourceServer>.ServerIterator servers = list.iterator(10000);
try {
	while (servers.hasNext()) {
		SourceServer server = servers.next();
		serverList.add(server);
		server.addListener(listener);
		server.load(Request.INFORMATION);
	}
} finally {
	servers.close();
}
Thread.sleep(2000);
for (SourceServer server: serverList) {
	System.out.println(server);
}
   

To Do List