cz.cuni.amis.pogamut.ut2004.server.impl
Class AbstractUT2004Server<WORLD_VIEW extends IWorldView,ACT extends IAct>

java.lang.Object
  extended by cz.cuni.amis.pogamut.base.agent.impl.AbstractAgent
      extended by cz.cuni.amis.pogamut.base.agent.impl.AbstractObservingAgent<WORLD_VIEW>
          extended by cz.cuni.amis.pogamut.base.agent.impl.AbstractGhostAgent<WORLD_VIEW,ACT>
              extended by cz.cuni.amis.pogamut.base.server.AbstractWorldServer<WORLD_VIEW,ACT,IUT2004Bot>
                  extended by cz.cuni.amis.pogamut.ut2004.server.impl.AbstractUT2004Server<WORLD_VIEW,ACT>
All Implemented Interfaces:
IAgent, IGhostAgent, IObservingAgent, IComponent, IComponentAware, IControllable, IWorldAgentsObserver<IUT2004Bot>, IWorldServer<IUT2004Bot>, IUnrealServer<IUT2004Bot>, IUT2004Server
Direct Known Subclasses:
UT2004Server

public abstract class AbstractUT2004Server<WORLD_VIEW extends IWorldView,ACT extends IAct>
extends AbstractWorldServer<WORLD_VIEW,ACT,IUT2004Bot>
implements IUT2004Server

Abstract class - ancestor of all UT2004 server controls.

It counts with GameBots2004 protocol therefore taking care of:

  1. ReadyCommandRequest - sending automatically ready(), override readyCommandRequested() if you're not comfortable with this
  2. Password - when password is requested it calls method createPasswordReply()

Also introducing user-method for setting up custom worldview listeners that is called before Ready message is sent - prePrepareServer().

You may use setPassword() method to specify the password before starting the agent.


Field Summary
 
Fields inherited from class cz.cuni.amis.pogamut.base.server.AbstractWorldServer
worldAddress
 
Fields inherited from class cz.cuni.amis.pogamut.base.agent.impl.AbstractAgent
events, INTROSPECTION_ROOT_NAME, log
 
Constructor Summary
AbstractUT2004Server(IAgentId agentId, IAgentLogger agentLogger, IComponentBus bus, SocketConnection connection, WORLD_VIEW worldView, ACT act)
           
 
Method Summary
 void connectNativeBot(java.lang.String botName, java.lang.String botType)
          Connects a UT native bot to the current map.
protected  PasswordReply createPasswordReply()
          This method is called whenever the Password event is caught telling us the world is locked and is requiring a password.
 ObservableCollection<IUT2004Bot> getAgents()
          Instances of the IAgent interface returned might not be the agents themselves as they can run on remote machines.
 java.util.Collection<MapList> getAvailableMaps()
           
 GameInfo getGameInfo()
           
 Flag<java.lang.Double> getGameSpeedFlag()
          The flag raises events even when the game speed was changed by another UTServer instance or directly in game.
 UT2004Map getMap()
          Get current map from the server
 java.lang.String getMapName()
           
 java.util.List<Mutator> getMutators()
          Reeturns list of all mutators available on the server.
 ObservableCollection<? extends NativeUT2004BotAdapter> getNativeAgents()
          Returns list of all non pogamut players connected to the game server.
 PasswordReply getPasswordReply()
          Instance of the password reply command that was sent upon receivieng request for the password (the world is locked).
 ObservableCollection<Player> getPlayers()
          Returns list of all players connected to the game server.
 WORLD_VIEW getWorldView()
          Returns abstraction for the agent's world.
protected  void killAgent()
          Called during kill() method - override to provide custom ruthless stopping (killing) behavior of the agent.
protected  void readyCommandRequested()
          This method is called whenever HelloBot message is parsed - the GameBots2004 is awaiting the bot to reply with Ready command to begin the handshake.
protected  void reset()
          Called during stop/kill/reset events.
protected  void resetAgent()
          Called whenever the IComponentBus broadcast IResetEvent to reset all agent's components as well as an agent.
 void setAddress(java.lang.String host, int port)
          Sets the address of the server to different location - does not automatically reconnect, use IAgent.stop() and IAgent.start().
 void setPassword(java.lang.String password)
          Specify the password that should be used if required by the world.
protected  void startAgent()
          Called during start() method - override to provide custom starting behavior of the agent.
protected  void startPausedAgent()
          Called during startPaused() method - override to provide custom starting-paused behavior of the agent.
protected  void stopAgent()
          Called during stop() method - override to provide custom stopping behavior of the agent.
 
Methods inherited from class cz.cuni.amis.pogamut.base.server.AbstractWorldServer
getWorldAddress
 
Methods inherited from class cz.cuni.amis.pogamut.base.agent.impl.AbstractGhostAgent
getAct
 
Methods inherited from class cz.cuni.amis.pogamut.base.agent.impl.AbstractAgent
addDependency, addDependency, addDependency, addJMXComponents, awaitState, awaitState, componentFatalError, componentStarted, componentStarted, componentStopped, componentStopping, createAgentJMX, createIntrospection, equals, getComponentId, getEventBus, getIntrospection, getJMX, getLog, getLogger, getName, getState, hashCode, inState, kill, notInState, pause, pauseAgent, preKillAgent, preStopAgent, resetEvent, resume, resumeAgent, setState, start, startPaused, stop, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface cz.cuni.amis.pogamut.ut2004.server.IUT2004Server
setGameMap
 
Methods inherited from interface cz.cuni.amis.pogamut.base.server.IWorldServer
getWorldAddress
 
Methods inherited from interface cz.cuni.amis.pogamut.base.agent.IGhostAgent
getAct
 
Methods inherited from interface cz.cuni.amis.pogamut.base.agent.IAgent
getComponentId, getIntrospection, getLogger, getName, getState, kill, pause, resume, start, startPaused, stop
 
Methods inherited from interface cz.cuni.amis.pogamut.base.component.IComponentAware
getEventBus
 

Constructor Detail

AbstractUT2004Server

@Inject
public AbstractUT2004Server(IAgentId agentId,
                                   IAgentLogger agentLogger,
                                   IComponentBus bus,
                                   SocketConnection connection,
                                   WORLD_VIEW worldView,
                                   ACT act)
Method Detail

setAddress

public void setAddress(java.lang.String host,
                       int port)
Description copied from interface: IUT2004Server
Sets the address of the server to different location - does not automatically reconnect, use IAgent.stop() and IAgent.start().

Specified by:
setAddress in interface IUnrealServer<IUT2004Bot>
Specified by:
setAddress in interface IUT2004Server

setPassword

public void setPassword(java.lang.String password)
Specify the password that should be used if required by the world.

Parameters:
password -

readyCommandRequested

protected void readyCommandRequested()
This method is called whenever HelloBot message is parsed - the GameBots2004 is awaiting the bot to reply with Ready command to begin the handshake.


getPasswordReply

public PasswordReply getPasswordReply()
Instance of the password reply command that was sent upon receivieng request for the password (the world is locked).

If null the password was not required by the time the bot connected to the world.

Returns:

createPasswordReply

protected PasswordReply createPasswordReply()
This method is called whenever the Password event is caught telling us the world is locked and is requiring a password.

May return null - in that case an empty password is sent to the server (which will probably result in closing the connection and termination of the agent).

This message is then saved to private field passwordReply and is accessible via getPasswordReply() method if required to be probed during the bot's runtime.

Note that if setPassword() method is called before this one it will use provided password via that method.


getGameInfo

public GameInfo getGameInfo()

getWorldView

public WORLD_VIEW getWorldView()
Description copied from class: AbstractObservingAgent
Returns abstraction for the agent's world. That can be anything the range is broad ... from chess board to the UT2004 3D environment.

The implementation may be different as the user needs.

Specified by:
getWorldView in interface IObservingAgent
Overrides:
getWorldView in class AbstractObservingAgent<WORLD_VIEW extends IWorldView>

getAvailableMaps

public java.util.Collection<MapList> getAvailableMaps()
Specified by:
getAvailableMaps in interface IUnrealServer<IUT2004Bot>
Specified by:
getAvailableMaps in interface IUT2004Server
Returns:
List of all maps available on the UT server

getGameSpeedFlag

public Flag<java.lang.Double> getGameSpeedFlag()
Description copied from interface: IUT2004Server
The flag raises events even when the game speed was changed by another UTServer instance or directly in game.

Specified by:
getGameSpeedFlag in interface IUnrealServer<IUT2004Bot>
Specified by:
getGameSpeedFlag in interface IUT2004Server
Returns:
Speed of the game.

getMapName

public java.lang.String getMapName()
Specified by:
getMapName in interface IUnrealServer<IUT2004Bot>
Specified by:
getMapName in interface IUT2004Server
Returns:
Name of the current map.

getPlayers

public ObservableCollection<Player> getPlayers()
Description copied from interface: IUT2004Server
Returns list of all players connected to the game server. The difference compared to the getAgents() method is that this method can return even the native bots, human players etc.

Custom-bots (created by Pogamut platform) can be recognized. They have non-null+non-empty Player.getJmx() field.

Specified by:
getPlayers in interface IUnrealServer<IUT2004Bot>
Specified by:
getPlayers in interface IUT2004Server
Returns:
List of all players on the server.

getMutators

public java.util.List<Mutator> getMutators()
Description copied from interface: IUT2004Server
Reeturns list of all mutators available on the server. Mutators can be used to modify the game (eg. disable weapons, change game speed).

Specified by:
getMutators in interface IUnrealServer<IUT2004Bot>
Specified by:
getMutators in interface IUT2004Server
Returns:
List of all mutators available on the server.

getAgents

public ObservableCollection<IUT2004Bot> getAgents()
Description copied from interface: IWorldAgentsObserver
Instances of the IAgent interface returned might not be the agents themselves as they can run on remote machines. In this case it will be proxy objects that can control those agents.

Specified by:
getAgents in interface IWorldAgentsObserver<IUT2004Bot>
Returns:
List of all Pogamut based agents in the world.

getNativeAgents

public ObservableCollection<? extends NativeUT2004BotAdapter> getNativeAgents()
Description copied from interface: IUT2004Server
Returns list of all non pogamut players connected to the game server. Collection contains NativeBotAdapter classes, this means that you can deal with the players like with Pogamut agents.

Specified by:
getNativeAgents in interface IUnrealServer<IUT2004Bot>
Specified by:
getNativeAgents in interface IUT2004Server
Returns:
List of all players on the server.

connectNativeBot

public void connectNativeBot(java.lang.String botName,
                             java.lang.String botType)
Description copied from interface: IUT2004Server
Connects a UT native bot to the current map.

Specified by:
connectNativeBot in interface IUnrealServer<IUT2004Bot>
Specified by:
connectNativeBot in interface IUT2004Server

getMap

public UT2004Map getMap()
Description copied from interface: IUT2004Server
Get current map from the server

Specified by:
getMap in interface IUnrealServer<IUT2004Bot>
Specified by:
getMap in interface IUT2004Server
Returns:
Map of current level.

reset

protected void reset()
Called during stop/kill/reset events.


resetAgent

protected void resetAgent()
Description copied from class: AbstractAgent
Called whenever the IComponentBus broadcast IResetEvent to reset all agent's components as well as an agent. Clean up your private data structure, get ready to be started again.

WARNING: DO NOT CALL ON YOUR OWN, CALLED FROM THE AbstractAgent.resetEvent(IResetEvent) AUTOMATICALLY.

If you override this method don't forget to call super.resetAgent() as the first method.

Overrides:
resetAgent in class AbstractAgent

stopAgent

protected void stopAgent()
Description copied from class: AbstractAgent
Called during stop() method - override to provide custom stopping behavior of the agent.

WARNING: DO NOT CALL ON YOUR OWN, ALWAYS USE PUBLIC INTERFACE (stop()).

If you override this method don't forget to call super.stopAgent() as the first method.

Overrides:
stopAgent in class AbstractAgent

killAgent

protected void killAgent()
Description copied from class: AbstractAgent
Called during kill() method - override to provide custom ruthless stopping (killing) behavior of the agent.

WARNING: DO NOT CALL ON YOUR OWN, ALWAYS USE PUBLIC INTERFACE (kill()).

If you override this method don't forget to call super.killAgent() as the first method.

Overrides:
killAgent in class AbstractAgent

startAgent

protected void startAgent()
Description copied from class: AbstractAgent
Called during start() method - override to provide custom starting behavior of the agent.

WARNING: DO NOT CALL ON YOUR OWN, ALWAYS USE PUBLIC INTERFACE (start()), but that should not be needed!

If you override this method don't forget to call super.startAgent() as the first method.

Overrides:
startAgent in class AbstractAgent

startPausedAgent

protected void startPausedAgent()
Description copied from class: AbstractAgent
Called during startPaused() method - override to provide custom starting-paused behavior of the agent.

WARNING: DO NOT CALL ON YOUR OWN, ALWAYS USE PUBLIC INTERFACE (startPaused()), but that should not be needed!

If you override this method don't forget to call super.startPausedAgent() as the first method.

Overrides:
startPausedAgent in class AbstractAgent