org.xistrat.net
Class F4Server

java.lang.Object
  extended by org.xistrat.net.F4Server
All Implemented Interfaces:
java.lang.Runnable

public class F4Server
extends java.lang.Object
implements java.lang.Runnable

F4Server is to be run as a daemon. It spawns F4Daemon to handle single games.
This servers is configurable to allow for N games in parallel. It dispatches game request to the appropriate F4Daemon, depending on a game id.

First: a player decides to setup a new game: It chooses a name (must be unique) and receives a unique ID. Once a game has ended its slot is freed to allow for other games.

Second: A client decides to join a game, selected from a list: from now on it plays with a specific F4Daemon.

It is the main server class, and the one that contains the actual "main".

Since:
0.5.42

Field Summary
static int DOUBLE_NAME
           
static int PORT
           
static int TOO_MANY
           
 
Constructor Summary
F4Server(int port, int maxDaemons, boolean verbose, boolean undo)
           
 
Method Summary
 int addGame(java.lang.String gameName, java.lang.String position, boolean verbose, boolean undo, java.lang.String komi)
          add a new match (also called game).
 void gameFinish(F4Daemon daemon)
          Remove won game from list
 java.lang.String[] getGameList()
           
 java.lang.String[] getPositionList()
           
 void login(org.xistrat.net.MiniListener ml, java.lang.String game, java.lang.String alias)
           
static void main(java.lang.String[] args)
          Starts the main server:
 void notifyNewGame()
           
 void run()
          run sends empty messages to players to unblock socket reading
 void startGame(F4Daemon daemon)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PORT

public static final int PORT
See Also:
Constant Field Values

DOUBLE_NAME

public static final int DOUBLE_NAME
See Also:
Constant Field Values

TOO_MANY

public static final int TOO_MANY
See Also:
Constant Field Values
Constructor Detail

F4Server

public F4Server(int port,
                int maxDaemons,
                boolean verbose,
                boolean undo)
Parameters:
undo - true in case undoing is enabled
Method Detail

main

public static void main(java.lang.String[] args)
Starts the main server:

Parameters:
args - some cmd line options

addGame

public int addGame(java.lang.String gameName,
                   java.lang.String position,
                   boolean verbose,
                   boolean undo,
                   java.lang.String komi)
add a new match (also called game).

Parameters:
gameName - a game name, any string can be
position - all the figures to start with
verbose - if much verbose output is desired
undo - if undoing a move is supported or not
komi - the komi (only in case of the game of Go)
Returns:
an int holding the id, or -1 if the name is already used, or -2 if the max number of daemons is reached

getGameList

public java.lang.String[] getGameList()

getPositionList

public java.lang.String[] getPositionList()

run

public void run()
run

sends empty messages to players to unblock socket reading

Specified by:
run in interface java.lang.Runnable

notifyNewGame

public void notifyNewGame()

gameFinish

public void gameFinish(F4Daemon daemon)
Remove won game from list


login

public void login(org.xistrat.net.MiniListener ml,
                  java.lang.String game,
                  java.lang.String alias)

startGame

public void startGame(F4Daemon daemon)