jfreerails.network
Class FreerailsClient

java.lang.Object
  extended by jfreerails.network.FreerailsClient
All Implemented Interfaces:
ClientControlInterface, MoveReceiver, ServerCommandReceiver, UntriedMoveReceiver, GameModel
Direct Known Subclasses:
GUIClient

public class FreerailsClient
extends java.lang.Object
implements ClientControlInterface, GameModel, UntriedMoveReceiver, ServerCommandReceiver

A client for FreerailsGameServer.

Author:
Luke

Nested Class Summary
 
Nested classes/interfaces inherited from interface jfreerails.controller.ClientControlInterface
ClientControlInterface.ClientProperty
 
Field Summary
private  MovePrecommitter committer
           
protected  Connection2Server connection2Server
           
private static java.util.logging.Logger logger
           
private  MoveChainFork moveFork
           
private  java.util.HashMap<java.lang.String,java.io.Serializable> properties
           
private  World world
           
 
Constructor Summary
FreerailsClient()
           
 
Method Summary
protected  void clientUpdates()
          Empty method called by update(), subclasses should override this method instead of overriding update().
 LogOnResponse connect(GameServer server, java.lang.String username, java.lang.String password)
          Connects this client to a local server.
 LogOnResponse connect(java.lang.String address, int port, java.lang.String username, java.lang.String password)
          Connects this client to a remote server.
 void disconnect()
          Disconnect the client from the server.
protected  long getLastTickTime()
           
 MoveChainFork getMoveFork()
           
 java.io.Serializable getProperty(ClientControlInterface.ClientProperty propertyName)
           
 World getWorld()
           
protected  void newWorld(World w)
          Subclasses should override this method if they need to respond the the world being changed.
(package private)  void processMessage(FreerailsSerializable message)
          Processes a message received from the server.
 void processMove(Move move)
          Sends move to the server.
 void processPreMove(PreMove pm)
           
(package private)  FreerailsSerializable read()
           
 void resetProperties(java.util.HashMap newProperties)
           
 void sendCommand(Message2Server c)
           
 void setGameModel(FreerailsMutableSerializable o)
          Called when a new game is started or a game is loaded.
 void setProperty(ClientControlInterface.ClientProperty propertyName, java.io.Serializable value)
          Sets a property, for example, the list of saved games.
 MoveStatus tryDoMove(Move move)
          Tests a move before sending it to the server.
 void update()
          Reads and deals with all outstanding messages from the server.
(package private)  void write(FreerailsSerializable fs)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final java.util.logging.Logger logger

connection2Server

protected Connection2Server connection2Server

properties

private final java.util.HashMap<java.lang.String,java.io.Serializable> properties

moveFork

private final MoveChainFork moveFork

world

private World world

committer

private MovePrecommitter committer
Constructor Detail

FreerailsClient

public FreerailsClient()
Method Detail

getMoveFork

public final MoveChainFork getMoveFork()

connect

public final LogOnResponse connect(java.lang.String address,
                                   int port,
                                   java.lang.String username,
                                   java.lang.String password)
Connects this client to a remote server.


connect

public final LogOnResponse connect(GameServer server,
                                   java.lang.String username,
                                   java.lang.String password)
Connects this client to a local server.


disconnect

public final void disconnect()
Disconnect the client from the server.


setGameModel

public final void setGameModel(FreerailsMutableSerializable o)
Description copied from interface: ClientControlInterface
Called when a new game is started or a game is loaded.

Specified by:
setGameModel in interface ClientControlInterface

newWorld

protected void newWorld(World w)
Subclasses should override this method if they need to respond the the world being changed.


setProperty

public void setProperty(ClientControlInterface.ClientProperty propertyName,
                        java.io.Serializable value)
Description copied from interface: ClientControlInterface
Sets a property, for example, the list of saved games.

Specified by:
setProperty in interface ClientControlInterface

getProperty

public final java.io.Serializable getProperty(ClientControlInterface.ClientProperty propertyName)

resetProperties

public final void resetProperties(java.util.HashMap newProperties)

read

final FreerailsSerializable read()

write

final void write(FreerailsSerializable fs)

update

public final void update()
Reads and deals with all outstanding messages from the server.

Specified by:
update in interface GameModel

clientUpdates

protected void clientUpdates()
Empty method called by update(), subclasses should override this method instead of overriding update().


processMessage

final void processMessage(FreerailsSerializable message)
                   throws java.io.IOException
Processes a message received from the server.

Throws:
java.io.IOException

getWorld

public final World getWorld()

processMove

public final void processMove(Move move)
Sends move to the server.

Specified by:
processMove in interface MoveReceiver

tryDoMove

public final MoveStatus tryDoMove(Move move)
Tests a move before sending it to the server.

Specified by:
tryDoMove in interface UntriedMoveReceiver

sendCommand

public void sendCommand(Message2Server c)
Specified by:
sendCommand in interface ServerCommandReceiver

processPreMove

public void processPreMove(PreMove pm)
Specified by:
processPreMove in interface UntriedMoveReceiver

getLastTickTime

protected long getLastTickTime()