net.barkerjr.gameserver
Class GameServer

java.lang.Object
  extended by net.barkerjr.gameserver.Base
      extended by net.barkerjr.gameserver.GameServer
Direct Known Subclasses:
BattlefieldBadCompany2Server, UdpServer

public abstract class GameServer
extends Base

Provides generic parsing and querying servers

Since:
2007-10-25
Author:
BarkerJr

Nested Class Summary
static class GameServer.Dedicated
          The server type
static class GameServer.Request
          The type of request to place
 class GameServer.RequestTimeoutException
          Provides a container for the requests which failed to load
 
Field Summary
 InetSocketAddress address
          The address of this server
 int botCount
          The number of bots on the server
protected  GameServer.Dedicated dedicated
          The dedicated status of the server
 String gameDirectory
          The directory of the game
protected static int IPTOS_RELIABILITY
          The type-of-service to send queries under
 String map
          The map the server is playing
 int maximumPlayers
          The maximum players allowed
 String name
          The name of the server
static Namespace namespace
          Deprecated. 2009-05-02, use JDOM.toJDOM(GameServer).getRootElement().getNamespace()
 int numberOfPlayers
          The number of players in the server
 boolean passwordRequired
          If a password is required to connect
protected  Players players
          The players in the server
protected  Set<Plugin> plugins
          Any listeners which should be triggered when a load is in progress
protected  HashMap<String,String> rules
          The rules on the server
 Calendar updated
          The time the server was last updated
protected  String version
          The version of the server
 
Fields inherited from class net.barkerjr.gameserver.Base
listeners
 
Constructor Summary
GameServer(InetSocketAddress address)
          Stores the address for later use
 
Method Summary
 void addPlugin(Plugin... plugins)
          Adds the given plugins to the server
 boolean equals(Object obj)
          Determines if this server's address is the same as the other server's address
protected  void fireChangeEvent(GameServer.Request request)
          Fires the change event in all listeners for this server
protected  void fireLoadEvent(GameServer.Request request)
          Fires the load event in all listeners for this server
 int getBotCount()
          The number of bots on the server
 GameServer.Dedicated getDedicated()
          The type of server this is
 String getGameDirectory()
          The directory the game is running
 String getIP()
          The address of this server
 String getMap()
          The map the server is running
 int getMaximumPlayers()
          The maximum players allowed by the server
 String getName()
          The name of the server
 int getNumberOfPlayers()
          The number of players in the server
 Players getPlayers()
          The players in the server
 Collection<Plugin> getPlugins()
          The plugins in this server
 int getPort()
          The port of this server
 Map<String,String> getRules()
          The server rules
 String getUpdated()
          The time the server was last updated
 String getVersion()
          The version the server is running
protected  void handleError(Throwable error)
          Sends error to the listeners, if there are any
 int hashCode()
          Fetches the hashcode of the address of this server
 boolean isPasswordRequired()
          If a password is required to connect
 void load(GameServer.Request... requests)
          Loads the given requests asynchronously
 void load(int msToWait, GameServer.Request... requests)
          Loads the given requests synchronously and returns once they are all loaded
protected  void replaceChild(Element element, Element child)
          Deprecated. since 2010-03-23
 JSONObject toJsonObject()
          Deprecated. since 2010-03-23, use JSON.toJSON(GameServer)
 String toString()
           
 Document toXmlDocument()
          Deprecated. since 2010-03-23, use JDOM.toJDOM(GameServer)
 
Methods inherited from class net.barkerjr.gameserver.Base
addListener, removeListener
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

IPTOS_RELIABILITY

protected static final int IPTOS_RELIABILITY
The type-of-service to send queries under

Since:
2010-03-15
See Also:
DatagramSocket.setTrafficClass(int), Constant Field Values

address

public final InetSocketAddress address
The address of this server

Since:
2007-11-28

plugins

protected Set<Plugin> plugins
Any listeners which should be triggered when a load is in progress

Since:
2007-11-28

namespace

@Deprecated
public static final Namespace namespace
Deprecated. 2009-05-02, use JDOM.toJDOM(GameServer).getRootElement().getNamespace()
The namespace for this server

Since:
2008-02-03

updated

public Calendar updated
The time the server was last updated

Since:
2009-05-02

name

public String name
The name of the server

Since:
2009-05-02

map

public String map
The map the server is playing

Since:
2009-05-02

passwordRequired

public boolean passwordRequired
If a password is required to connect

Since:
2009-05-02

numberOfPlayers

public int numberOfPlayers
The number of players in the server

Since:
2009-05-02

maximumPlayers

public int maximumPlayers
The maximum players allowed

Since:
2009-05-02

botCount

public int botCount
The number of bots on the server

Since:
2009-05-02

players

protected Players players
The players in the server

Since:
2009-05-02

gameDirectory

public String gameDirectory
The directory of the game

Since:
2009-05-02

rules

protected HashMap<String,String> rules
The rules on the server

Since:
2009-05-02

version

protected String version
The version of the server

Since:
2009-05-02

dedicated

protected GameServer.Dedicated dedicated
The dedicated status of the server

Since:
2009-05-02
Constructor Detail

GameServer

public GameServer(InetSocketAddress address)
Stores the address for later use

Parameters:
address - the address of the server
Since:
2007-10-25
Method Detail

toString

public String toString()
Overrides:
toString in class Object
Returns:
the data as an XML string
Since:
2007-10-25

toXmlDocument

@Deprecated
public Document toXmlDocument()
                       throws InvocationTargetException
Deprecated. since 2010-03-23, use JDOM.toJDOM(GameServer)

Converts the server into an XML Document

Returns:
the document describing this server
Throws:
InvocationTargetException - if JDOM.toJDOM(GameServer) throws it
Since:
2009-05-02

toJsonObject

@Deprecated
public JSONObject toJsonObject()
                        throws JSONException
Deprecated. since 2010-03-23, use JSON.toJSON(GameServer)

Converts the server into a JSON object

Returns:
the object describing this server
Throws:
JSONException - if an error occurs
Since:
2009-05-02

fireLoadEvent

protected void fireLoadEvent(GameServer.Request request)
Fires the load event in all listeners for this server

Parameters:
request - the type of request to fire
Since:
2007-11-10

fireChangeEvent

protected void fireChangeEvent(GameServer.Request request)
Fires the change event in all listeners for this server

Parameters:
request - the type of request to fire
Since:
2007-11-10

replaceChild

@Deprecated
protected void replaceChild(Element element,
                                       Element child)
Deprecated. since 2010-03-23

Replaces any child with the same tag name with this one. This is a shallow replacement

Parameters:
element - the parent element
child - the child element
Since:
2007-10-25

handleError

protected void handleError(Throwable error)
Sends error to the listeners, if there are any

Overrides:
handleError in class Base
Parameters:
error - the error to send
Since:
2007-10-25

load

public void load(int msToWait,
                 GameServer.Request... requests)
          throws IOException,
                 InterruptedException,
                 GameServer.RequestTimeoutException
Loads the given requests synchronously and returns once they are all loaded

Parameters:
msToWait - the number of milliseconds to block while waiting for a reply from the server
requests - the requests to load
Throws:
IOException - if there was an error sending or receiving the data
GameServer.RequestTimeoutException - if the server did not respond in the specified time
InterruptedException - if the thread was interrupted before the data was loaded
Since:
2007-11-10

load

public void load(GameServer.Request... requests)
          throws IOException
Loads the given requests asynchronously

Parameters:
requests - the requests to load
Throws:
IOException - if there was an error sending or receiving the data
Since:
2007-11-10

addPlugin

public void addPlugin(Plugin... plugins)
Adds the given plugins to the server

Parameters:
plugins - the plugins to install
Since:
2007-11-28

equals

public boolean equals(Object obj)
Determines if this server's address is the same as the other server's address

Overrides:
equals in class Object
Since:
2008-02-03
See Also:
InetSocketAddress.equals(Object)

hashCode

public int hashCode()
Fetches the hashcode of the address of this server

Overrides:
hashCode in class Object
Since:
2008-02-03
See Also:
InetSocketAddress.hashCode()

getIP

public String getIP()
The address of this server

Returns:
the address of this server
Since:
2009-05-02

getPort

public int getPort()
The port of this server

Returns:
the port of this server
Since:
2009-05-02

getUpdated

public String getUpdated()
The time the server was last updated

Returns:
the time the server was last updated
Since:
2009-05-02

getName

public String getName()
The name of the server

Returns:
the name of the server
Since:
2009-05-02

isPasswordRequired

public boolean isPasswordRequired()
If a password is required to connect

Returns:
if a password is required to connect
Since:
2009-05-02

getNumberOfPlayers

public int getNumberOfPlayers()
The number of players in the server

Returns:
the number of players in the server
Since:
2009-05-02

getMaximumPlayers

public int getMaximumPlayers()
The maximum players allowed by the server

Returns:
the maximum players allowed by the server
Since:
2009-05-02

getBotCount

public int getBotCount()
The number of bots on the server

Returns:
the number of bots on the server
Since:
2009-05-02

getPlayers

public Players getPlayers()
The players in the server

Returns:
the players in the server
Since:
2009-05-02

getMap

public String getMap()
The map the server is running

Returns:
the map the server is running
Since:
2009-05-02

getGameDirectory

public String getGameDirectory()
The directory the game is running

Returns:
the directory the game is running
Since:
2009-05-02

getRules

public Map<String,String> getRules()
The server rules

Returns:
the server rules
Since:
2009-05-02

getVersion

public String getVersion()
The version the server is running

Returns:
the version the server is running
Since:
2009-05-02

getDedicated

public GameServer.Dedicated getDedicated()
The type of server this is

Returns:
the type of server this is
Since:
2009-05-02

getPlugins

public Collection<Plugin> getPlugins()
The plugins in this server

Returns:
the plugins in this server
Since:
2010-03-23