net.barkerjr.gameserver.valve
Class ValveServer

java.lang.Object
  extended by net.barkerjr.gameserver.Base
      extended by net.barkerjr.gameserver.GameServer
          extended by net.barkerjr.gameserver.UdpServer
              extended by net.barkerjr.gameserver.valve.ValveServer
All Implemented Interfaces:
Closeable
Direct Known Subclasses:
GoldSourceServer, SourceServer

public abstract class ValveServer
extends UdpServer

Provides generic parsing and querying for Valve servers

Since:
2007-10-25
Author:
BarkerJr
See Also:
Specification

Nested Class Summary
static class ValveServer.OperatingSystem
          The operating system the server is running
 
Nested classes/interfaces inherited from class net.barkerjr.gameserver.GameServer
GameServer.Dedicated, GameServer.Request, GameServer.RequestTimeoutException
 
Field Summary
protected  String rconPassword
          The rcon password for this server
 
Fields inherited from class net.barkerjr.gameserver.UdpServer
servers
 
Fields inherited from class net.barkerjr.gameserver.GameServer
address, botCount, dedicated, gameDirectory, IPTOS_RELIABILITY, map, maximumPlayers, name, namespace, numberOfPlayers, passwordRequired, players, plugins, rules, updated, version
 
Fields inherited from class net.barkerjr.gameserver.Base
listeners
 
Constructor Summary
protected ValveServer(InetSocketAddress address)
          Sets up the basic server information and DOM
 
Method Summary
 int getApplicationId()
          The application ID
 String getGameDescription()
          The description of the game that is running
 ValveServer.OperatingSystem getOperatingSystem()
          The operating system running on the server
 TheShip getShip()
          Statistics about The Ship servers
protected  void handleMessage(int code, ReplyStream stream)
          Handles A (Challenge), D (Players), E (Rules), and Information responses
protected  void handlePlayers(ReplyStream stream)
          Handles D (Players) responses from the server
 boolean isVacSecure()
          If the server uses VAC security
 void load(GameServer.Request... requests)
          Supports: Request.INFORMATION Request.PLAYERS Request.RULES Loads the given requests asynchronously
protected  void loadChallenge()
          Requests (Asynchronously) the challenge code from the server
 void loadInformation()
          Asynchronously loads the generic server information.
 void loadPlayers()
          Asynchronously loads the player list.
 void loadRules()
          Asynchronously loads the rules.
protected  void parseData(byte[] data)
          Parses the packet header and reassembles reply fragments.
protected abstract  SequenceDvo parsePacketNumber(ReplyStream buffer)
          Determines which packet in the multi-packet response this is
 void sendRcon(String... commands)
          Sends the given command to the server
abstract  String sendRcon(String command)
          Sends the given command to the server and waits for a reply.
 void setRconPassword(String password)
          Sets the server rcon password
 JSONObject toJsonObject()
          Deprecated. since 2010-03-23, use JSON.toJSON(GameServer)
 
Methods inherited from class net.barkerjr.gameserver.UdpServer
close, sendData, sendData
 
Methods inherited from class net.barkerjr.gameserver.GameServer
addPlugin, equals, fireChangeEvent, fireLoadEvent, getBotCount, getDedicated, getGameDirectory, getIP, getMap, getMaximumPlayers, getName, getNumberOfPlayers, getPlayers, getPlugins, getPort, getRules, getUpdated, getVersion, handleError, hashCode, isPasswordRequired, load, replaceChild, toString, toXmlDocument
 
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

rconPassword

protected String rconPassword
The rcon password for this server

Since:
2008-02-03
Constructor Detail

ValveServer

protected ValveServer(InetSocketAddress address)
Sets up the basic server information and DOM

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

parseData

protected void parseData(byte[] data)
                  throws IOException
Parses the packet header and reassembles reply fragments. If this is the only packet in the reply, we send it to the handler now, otherwise we put it in a map for later. If we have all the pieces, we send the parts to be reassembled.

Specified by:
parseData in class UdpServer
Parameters:
data - the packet we received
Throws:
IOException - if there is an error decompressing the packets
Since:
2007-10-25

parsePacketNumber

protected abstract SequenceDvo parsePacketNumber(ReplyStream buffer)
Determines which packet in the multi-packet response this is

Parameters:
buffer - the packet data
Returns:
a DVO containing this packet's sequence number, and the total number of packets to expect
Since:
2007-10-25

handleMessage

protected void handleMessage(int code,
                             ReplyStream stream)
Handles A (Challenge), D (Players), E (Rules), and Information responses

Parameters:
code - the message type
stream - the message itself
Since:
2007-10-25

handlePlayers

protected void handlePlayers(ReplyStream stream)
Handles D (Players) responses from the server

Parameters:
stream - the message from the server
Since:
2009-10-06

load

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

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

loadInformation

public void loadInformation()
                     throws IOException
Asynchronously loads the generic server information. This method will return as soon as the request is sent to the server, without waiting for a reply. Add a listener if you need to be notified after the reply is parsed.

Throws:
IOException - if there was an error sending the request
Since:
2007-10-25
See Also:
Base.addListener(Listener)

loadPlayers

public void loadPlayers()
                 throws IOException
Asynchronously loads the player list. This method will return as soon as the request is sent to the server, without waiting for a reply. Add a listener if you need to be notified after the reply is parsed.

Throws:
IOException - if there was an error sending the request
Since:
2007-10-25
See Also:
Base.addListener(Listener)

loadRules

public void loadRules()
               throws IOException
Asynchronously loads the rules. This method will return as soon as the request is sent to the server, without waiting for a reply. Add a listener if you need to be notified after the reply is parsed.

Throws:
IOException - if there was an error sending the request
Since:
2007-10-25
See Also:
Base.addListener(Listener)

loadChallenge

protected void loadChallenge()
                      throws IOException
Requests (Asynchronously) the challenge code from the server

Throws:
IOException - if there was an error sending the request
Since:
2007-10-25

setRconPassword

public void setRconPassword(String password)
Sets the server rcon password

Parameters:
password - the password to store
Since:
2008-02-03

sendRcon

public abstract String sendRcon(String command)
                         throws FailedLoginException,
                                SocketTimeoutException
Sends the given command to the server and waits for a reply.

Parameters:
command - the command to send
Returns:
the response from the server
Throws:
FailedLoginException - if the password set by setRconPassword(String) is bad
SocketTimeoutException - if there was an error contacting the server
Since:
2008-02-03

sendRcon

public void sendRcon(String... commands)
Sends the given command to the server

Parameters:
commands - the commands to send
Since:
2008-02-03

getGameDescription

public String getGameDescription()
The description of the game that is running

Returns:
the description of the game that is running
Since:
2009-05-02

getApplicationId

public int getApplicationId()
The application ID

Returns:
the application ID
Since:
2009-05-02

getOperatingSystem

public ValveServer.OperatingSystem getOperatingSystem()
The operating system running on the server

Returns:
the operating system running on the server
Since:
2009-05-02

isVacSecure

public boolean isVacSecure()
If the server uses VAC security

Returns:
if the server uses VAC security
Since:
2009-05-02

getShip

public TheShip getShip()
Statistics about The Ship servers

Returns:
statistics about The Ship servers
Since:
2009-05-02

toJsonObject

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

Description copied from class: GameServer
Converts the server into a JSON object

Overrides:
toJsonObject in class GameServer
Returns:
the object describing this server
Throws:
JSONException - if an error occurs
Since:
2009-05-02