/*
* Gamers Own Instant Messenger
* Copyright (C) 2005-2006 Herbert Poul (kahless@sphene.net)
* http://goim.sphene.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package net.sphene.goim.games;
import java.net.InetSocketAddress;
import net.sourceforge.queried.QueriEd;
import net.sourceforge.queried.ServerInfo;
import net.sphene.goim.rcp.beans.GOIMGameItem;
import net.sphene.goim.rcp.extensionpoints.IGame;
import net.sphene.goim.rcp.extensionpoints.GameExtensionPoint.GameExtensionProxy;
import net.sphene.goim.rcp.extensionpoints.game.GameAdapterWithServerName;
public class UnrealTournament2004 extends GameAdapterWithServerName implements IGame {
public @Override ServerQueryInformation queryServer(InetSocketAddress destination) {
ServerQueryInformation query = new ServerQueryInformation();
String ipStr = destination.getAddress().getHostAddress();
int port = destination.getPort()+1; // UT2004 uses game port + 1 for server query
long started = System.currentTimeMillis();
ServerInfo serverInfo = QueriEd.serverQuery("UT2004",ipStr,port);
query.ping = (int)(System.currentTimeMillis() - started);
String serverName = null;
if(serverInfo != null) {
serverName = serverInfo.getName();
query.mapName = serverInfo.getMap();
int realport = Integer.parseInt(serverInfo.getPort());
if(realport != destination.getPort())
System.err.println("ERROR: real port from query: " + realport + " is not the same as current destination port: " + destination.getPort());
query.setPlayerCount(serverInfo.getPlayerCount());
query.setMaxPlayerCount(serverInfo.getMaxPlayers());
System.out.println("Queried server: " + serverName);
} else
System.err.println("Unable to query server.");
query.serverName = serverName;
return query;
}
public GOIMGameItem autoDetect(GameExtensionProxy proxy) {
GOIMGameItem item = autoDetect(proxy,"SOFTWARE\\Unreal Technology\\Installed Apps\\UT2004","Folder","System\\UT2004.exe");
try {
item.version = autoDetectGetRegistryKeyValue("SOFTWARE\\Unreal Technology\\Installed Apps\\UT2004","Version");
} catch(Exception e) {
}
return item;
}
}