/*
* 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.battlefield;
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 Battlefield1942 extends GameAdapterWithServerName
implements IGame {
@Override
public int requiredPacketCountForDestination(GOIMGameItem game, InetSocketAddress destination, int sourceport) {
int port = destination.getPort();
if(port == 14567) // Default Game Port
return 2;
else if(port == 23000) // Query Port
return 10;
return super.requiredPacketCountForDestination(game, destination, sourceport);
}
@Override
public GOIMGameItem autoDetect(GameExtensionProxy proxy) {
return autoDetect(proxy,"SOFTWARE\\EA GAMES\\Battlefield 1942","GameDir","bf1942.exe");
}
public @Override ServerQueryInformation queryServer(InetSocketAddress destination) {
ServerQueryInformation query = new ServerQueryInformation();
String ipStr = destination.getAddress().getHostAddress();
//int port = currentDestination.getPort()+1; // AA uses gameport + 1 for query
int port = 23000; // BF2 always uses the same port ?
long started = System.currentTimeMillis();
ServerInfo serverInfo = QueriEd.serverQuery("BF",ipStr,port);
query.ping = (int)(System.currentTimeMillis() - started);
String serverName = null;
if(serverInfo != null) {
serverName = serverInfo.getName();
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;
}
}