net.sf.colossus.server
Class Server

java.lang.Object
  extended by java.lang.Thread
      extended by net.sf.colossus.server.Server
All Implemented Interfaces:
java.lang.Runnable, IServer

public final class Server
extends java.lang.Thread
implements IServer

Class Server lives on the server side and handles all communcation with the clients. It talks to the server classes locally, and to the Clients via the network protocol.

Author:
David Ripton

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
private  java.nio.channels.SelectionKey acceptKey
           
private  java.util.List<java.nio.channels.SocketChannel> activeSocketChannelList
           
private  java.nio.ByteBuffer byteBuffer
           
private  java.lang.String caughtUpAction
           
private  java.util.List<ClientHandler> channelChanges
           
private  java.util.Map<Player,IClient> clientMap
          Map of players to their clients.
private  java.util.List<IClient> clients
          Maybe also save things like the originating IP, in case a connection breaks and we need to authenticate reconnects.
private  boolean disposeAllClientsDone
           
private  java.lang.Object disposeAllClientsDoneMutex
           
private static java.lang.Thread fileServerThread
           
private  boolean forceShutDown
           
private  GameServerSide game
           
private  int gameStartupTimeoutSecs
          Timeout how long server waits for clients before giving up; in normal/local games 0, meaning forever; in public server usage set to WEBGAMES_STARTUP_TIMEOUT_SECS
private  java.lang.Object guiRequestMutex
           
private  java.lang.String guiRequestSaveFilename
           
private  boolean guiRequestSaveFlag
           
private  boolean initiateDisposal
           
private  boolean inPauseState
           
private  long lastPingRound
          How many ms ago last ping round was done.
private static java.util.logging.Logger LOGGER
           
private  boolean obsolete
           
(package private)  ClientHandler overriddenCH
           
private  int PING_REQUEST_INTERVAL_SEC
           
private  int port
          Server socket port.
(package private)  ClientHandler processingCH
           
private  MessageRecorder recorder
           
private  java.util.List<IClient> remoteClients
           
private  java.util.List<RemoteLogHandler> remoteLogHandlers
           
private  java.util.List<java.lang.String> rolls
           
private  java.nio.channels.Selector selector
           
private  boolean sendPingRequests
          Will be set to true after all clients are properly connected
private  boolean serverRunning
           
private  java.net.ServerSocket serverSocket
           
private  boolean shuttingDown
           
private  java.util.List<IClient> spectatorClients
           
private  int spectators
           
private  long startInititatedTime
          When server started to listed for clients
private static StartupProgress startLog
           
private  boolean stopAcceptingFlag
           
private  int strikeNumber
           
private  CreatureServerSide striker
           
private  CreatureServerSide target
           
private  int timeoutDuringGame
           
private  int timeoutDuringShutdown
           
private  int timeoutDuringStart
           
private  int waitingForPlayers
          Number of player clients we're waiting for to *connect*
private  int waitingForPlayersToJoin
          Number of player clients we're waiting for to *join* - when last one has joined, then kick of newGame2() or loadGame2()
private  java.util.HashSet<IClient> waitingToCatchup
           
private  java.lang.Object waitUntilOverMutex
           
private static int WEBGAMES_STARTUP_TIMEOUT_SECS
          How long in public server games socket shall wait for Clients.
private  java.lang.Object wfptjSemaphor
          Semaphor for synchronized access to waitingForPlayersToJoin
private  WhatNextManager whatNextManager
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Fields inherited from interface net.sf.colossus.server.IServer
CLIENT_VERSION, MINIMUM_CLIENT_VERSION
 
Constructor Summary
Server(GameServerSide game, WhatNextManager whatNextMgr, int port)
           
 
Method Summary
 void acquireAngel(Legion legion, CreatureType angelType)
           
private  void actOnAllCaughtUp()
           
(package private)  java.lang.String addClient(IClient client, java.lang.String playerName, boolean remote, int clientVersion, java.lang.String buildInfo)
          Add a Client.
private  void addRemoteClient(IClient client, Player player)
           
(package private)  void allCleanupBattle()
           
(package private)  void allFullyUpdateAllLegionContents(java.lang.String reason)
           
(package private)  void allFullyUpdateLegionStatus()
           
(package private)  void allInitBattle(MasterHex masterHex)
           
(package private)  void allInitBoard()
           
(package private)  void allLog(java.lang.String message)
          DO NOT USE: package so that it can be called from Log4J Appender.
(package private)  void allPlaceNewChit(CreatureServerSide critter)
           
(package private)  void allRemoveDeadBattleChits()
           
(package private)  void allRemoveLegion(Legion legion)
           
(package private)  void allRequestConfirmCatchup(java.lang.String action)
           
(package private)  void allRequestPingIfNeeded()
          IF last ping round is at least PING_REQUEST_INTERVAL_SEC seconds ago, then send a ping request to all clients (except those which are in trouble anyway).
(package private)  void allRevealCreatures(Legion legion, java.util.List<CreatureType> creatureNames, java.lang.String reason)
           
(package private)  void allRevealEngagedLegion(Legion legion, boolean isAttacker, java.lang.String reason)
          pass to all clients the 'revealEngagedCreatures' message, then fire an 'revealEvent' to the history.
(package private)  void allRevealLegion(Legion legion, java.util.List<CreatureType> creatures, java.lang.String reason)
          Call from History during load game only
(package private)  void allRevealLegion(Legion legion, java.lang.String reason)
           
(package private)  void allSetColor()
          Hack to set color on load game.
(package private)  void allSetupBattleFight()
           
(package private)  void allSetupBattleMove()
           
(package private)  void allSetupBattleRecruit()
           
(package private)  void allSetupBattleSummon()
           
(package private)  void allSetupFight()
           
(package private)  void allSetupMove()
           
(package private)  void allSetupMuster()
           
(package private)  void allSetupSplit()
           
(package private)  void allSetupTurnState()
          Needed if loading game outside the split phase.
(package private)  void allSyncOption(java.lang.String optname, boolean value)
           
(package private)  void allSyncOption(java.lang.String optname, int value)
           
(package private)  void allSyncOption(java.lang.String optname, java.lang.String value)
           
(package private)  void allTellAddCreature(AddCreatureAction event, boolean updateHistory, java.lang.String reason)
           
(package private)  void allTellAllLegionLocations()
           
(package private)  void allTellBattleMove(int tag, BattleHex startingHex, BattleHex endingHex, boolean undo)
           
(package private)  void allTellCarryResults(CreatureServerSide carryTarget, int carryDamageDone, int carryDamageLeft, java.util.Set<java.lang.String> carryTargetDescriptions)
           
(package private)  void allTellDidMove(Legion legion, MasterHex startingHex, MasterHex hex, EntrySide entrySide, boolean teleport, CreatureType teleportingLord)
           
(package private)  void allTellDidSplit(Legion parent, Legion child, int turn, boolean history)
          Called from game after this legion was split off, or by history
(package private)  void allTellDidSummon(Legion receivingLegion, Legion donorLegion, CreatureType summon)
           
(package private)  void allTellEngagement(MasterHex hex, Legion attacker, Legion defender)
           
(package private)  void allTellEngagementResults(Legion winner, java.lang.String method, int points, int turns)
           
(package private)  void allTellGameOver(java.lang.String message, boolean disposeFollows)
           
(package private)  void allTellHexDamageResults(CreatureServerSide target, int damage)
           
(package private)  void allTellLegionLocation(Legion legion)
           
(package private)  void allTellMovementRoll(int roll)
           
(package private)  void allTellPlayerElim(Player eliminatedPlayer, Player slayer, boolean updateHistory)
           
(package private)  void allTellRedo(boolean val)
           
(package private)  void allTellRemoveCreature(Legion legion, CreatureType creature, boolean updateHistory, java.lang.String reason)
           
(package private)  void allTellReplay(boolean val, int maxTurn)
           
(package private)  void allTellStrikeResults(CreatureServerSide striker, CreatureServerSide target, int strikeNumber, java.util.List<java.lang.String> rolls, int damage, int carryDamageLeft, java.util.Set<java.lang.String> carryTargetDescriptions)
           
 void allTellUndidMove(Legion legion, MasterHex formerHex, MasterHex currentHex, boolean splitLegionHasForcedMove)
           
(package private)  void allUpdateCreatureCount(CreatureType type, int count, int deadCount)
           
(package private)  void allUpdatePlayerInfo()
           
(package private)  void allUpdatePlayerInfo(boolean treatDeadAsAlive)
           
private  boolean anyNonAiSocketsLeft()
           
 void applyCarries(BattleHex hex)
           
(package private)  void askAcquireAngel(PlayerServerSide player, Legion legion, java.util.List<CreatureType> recruits)
          Find out if the player wants to acquire an angel or archangel.
(package private)  void askChooseStrikePenalty(java.util.SortedSet<PenaltyOption> penaltyOptions)
          Takes a Set of PenaltyOptions.
(package private)  void askConcede(Legion ally, Legion enemy)
          Ask ally's player whether he wants to concede with ally.
(package private)  void askFlee(Legion ally, Legion enemy)
          Ask ally's player whether he wants to flee with ally.
(package private)  void askPickColor(Player player, java.util.List<PlayerColor> colorsLeft)
           
(package private)  void askPickFirstMarker(Player player)
           
 void assignColor(PlayerColor color)
           
 void assignFirstMarker(java.lang.String markerId)
           
 void assignStrikePenalty(java.lang.String prompt)
           
 void checkServerConnection()
           
 void cleanup()
           
 void cleanupStartlog()
           
 void clientConfirmedCatchup()
           
 void clientWontConfirmCatchup(ClientHandler ch, java.lang.String reason)
          Check whether client is currently expected to send a caught-Up confirmation.
private  void closeSocketAndSelector()
          Close serverSocket and selector, if needed
 void concede(Legion legion)
           
(package private)  void createSummonAngel(Legion legion)
           
private  int decrementWaitingForPlayersToJoin()
          Decrement the number of players we wait for to join by one in a thread-safe way, and return the new value.
(package private)  void didRecruit(AddCreatureAction event, CreatureType recruiter)
           
private  void disableAutoCloseStartupLog()
           
 void disconnect()
           
private  void disconnectChannel(java.nio.channels.SocketChannel sc, java.nio.channels.SelectionKey key)
          Close the SocketChannel, cancel the selection key and unregister the SocketChannel from list of active SocketChannels.
(package private)  void disposeAllClients()
           
 void doBattleMove(int tag, BattleHex hex)
           
 void doMove(Legion legion, MasterHex hex, EntrySide entrySide, boolean teleport, CreatureType teleportingLord)
           
 void doneWithBattleMoves()
           
 void doneWithEngagements()
           
 void doneWithMoves()
           
 void doneWithRecruits()
           
 void doneWithSplits()
           
 void doneWithStrikes()
           
 void doNotConcede(Legion legion)
           
 void doNotFlee(Legion legion)
           
 void doRecruit(Recruitment event)
          Handle mustering for legion.
 void doSetWhatToDoNext(WhatNextManager.WhatToDoNext whatToDoNext, boolean triggerQuitTimer)
           
 void doSplit(Legion parent, java.lang.String childId, java.util.List<CreatureType> creaturesToSplit)
          Executes a split of certain creatures from a legion.
 void doSummon(Summoning event)
          Handles a summon event
 void engage(MasterHex hex)
           
 void externShutdown()
          Shutdown initiated by outside, i.e.
 void fight(MasterHex hex)
           
 void flee(Legion legion)
           
private  PlayerServerSide getActivePlayerSS()
           
private  IClient getClient(Player player)
           
 int getClientCount()
           
 GameServerSide getGame()
           
(package private)  int getIntOption(java.lang.String optname)
           
private  Player getPlayer()
          The player, for which data from socket is currently processed.
private  java.util.List<java.lang.String> getPlayerInfo(boolean treatDeadAsAlive)
           
(package private)  java.lang.String getPlayerName()
          Name of the player, for which data from socket is currently processed.
 MessageRecorder getRecorder()
           
private  void handleChannelChanges()
           
 boolean handleGuiRequests()
           
private  void handleOutsideChanges(int timeout, boolean stillWaitingForClients)
           
private  void handleSelectedKeys()
           
(package private)  void initFileServer()
           
 void initiateSaveGame(java.lang.String filename)
           
(package private)  void initSocketServer()
           
private  void initWaitingForPlayersToJoin(int count)
          Initialize the number of players we wait for to join (thread-safe)
private  boolean isActivePlayer()
          returns true if the active player is the player owning the connection from which data is currently processed
private  boolean isBattleActivePlayer()
           
 boolean isClientGone(Player player)
           
 boolean isKnownClient(java.net.InetAddress requester)
           
 boolean isServerRunning()
           
 void joinGame(java.lang.String playerName)
           
(package private)  void kickPhase()
           
 void leaveCarryMode()
           
 void loadFailed()
           
 void loadGame(java.lang.String filename)
           
(package private)  void logToStartLog(java.lang.String message)
           
 void makeProposal(java.lang.String proposalString)
          playerName makes a proposal.
 void mulligan()
           
 void newGame()
           
(package private)  void nextEngagement()
           
 void notifyThatGameFinished()
           
(package private)  void oneRevealLegion(Legion legion, Player player, java.lang.String reason)
           
(package private)  void oneRevealLegion(Player player, Legion legion, java.util.List<CreatureType> creatureNames, java.lang.String reason)
          Call from History during load game only
(package private)  void oneSetOption(Player player, java.lang.String optname, boolean value)
           
(package private)  void oneSetOption(Player player, java.lang.String optname, java.lang.String value)
           
(package private)  void othersTellOneHasNetworkTrouble(ClientHandler chInTrouble)
           
(package private)  void othersTellOnesTroubleIsOver(ClientHandler chInTrouble)
           
 void overrideProcessingCH(Player player)
           
(package private)  void queueClientHandlerForChannelChanges(ClientHandler ch)
          Put the ClientHandler into the queue to be removed from selector on next possible opportunity
private  int readFromChannel(java.nio.channels.SelectionKey key, java.nio.channels.SocketChannel sc)
           
(package private)  void reinforce(Legion legion)
           
(package private)  void repeatTellOneHasNetworkTrouble()
           
 void replyToRequestGameInfo()
           
 void restoreProcessingCH()
           
 void run()
           
 void saveGame(java.lang.String filename)
           
 void saveGame(java.lang.String filename, boolean autoSave)
           
 void setBoardVisibility(Player player, boolean val)
           
 void setObsolete()
           
 void setPauseState(boolean newState)
           
(package private)  void setPlayerName(Player player, java.lang.String newName)
          Used to change a player name after color is assigned.
 void sleepFor(long millis)
           
 void startGame()
          When the last player has *joined* (not just connected), he calls this here, and this will proceed with either loadGame2() or newGame2().
 void startupProgressAbort()
           
 void startupProgressQuit()
           
private  void stopAccepting()
           
 void stopFileServer()
           
 void stopGame()
           
 void stopServerRunning()
           
 void strike(int tag, BattleHex hex)
           
(package private)  void tellProposal(Player player, Proposal proposal)
          Tell playerName about proposal.
(package private)  void triggerDispose()
           
(package private)  void twoNegotiate(Legion attacker, Legion defender)
           
(package private)  void undidRecruit(Legion legion, CreatureType recruit, boolean reinforced)
           
(package private)  void undidSplit(Legion splitoff, Legion survivor, boolean updateHistory, int turn)
           
 void undoBattleMove(BattleHex hex)
           
 void undoMove(Legion legion)
           
 void undoRecruit(Legion legion)
           
 void undoSplit(Legion splitoff)
           
 void unregisterSocketChannel(java.nio.channels.SocketChannel socketChannel)
           
(package private)  boolean waitForClients()
           
 void waitOnSelector(int timeout, boolean stillWaitingForClients)
           
 void waitUntilGameFinishes()
           
 void withdrawFromGame()
          Withdraw the currently active player (if it is a real one, and withdrawal still makes sense).
 void withdrawFromGame(java.lang.String playerName)
          Withdraw a specific player of which we know only the name; e.g.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOGGER

private static final java.util.logging.Logger LOGGER

startLog

private static StartupProgress startLog

game

private GameServerSide game

whatNextManager

private final WhatNextManager whatNextManager

recorder

private final MessageRecorder recorder

clients

private final java.util.List<IClient> clients
Maybe also save things like the originating IP, in case a connection breaks and we need to authenticate reconnects. Do not share these references.


remoteClients

private final java.util.List<IClient> remoteClients

spectatorClients

private final java.util.List<IClient> spectatorClients

remoteLogHandlers

private final java.util.List<RemoteLogHandler> remoteLogHandlers

clientMap

private final java.util.Map<Player,IClient> clientMap
Map of players to their clients.


activeSocketChannelList

private final java.util.List<java.nio.channels.SocketChannel> activeSocketChannelList

waitingForPlayers

private int waitingForPlayers
Number of player clients we're waiting for to *connect*


waitingForPlayersToJoin

private int waitingForPlayersToJoin
Number of player clients we're waiting for to *join* - when last one has joined, then kick of newGame2() or loadGame2()


wfptjSemaphor

private final java.lang.Object wfptjSemaphor
Semaphor for synchronized access to waitingForPlayersToJoin


sendPingRequests

private boolean sendPingRequests
Will be set to true after all clients are properly connected


spectators

private int spectators

port

private final int port
Server socket port.


striker

private CreatureServerSide striker

target

private CreatureServerSide target

strikeNumber

private int strikeNumber

rolls

private java.util.List<java.lang.String> rolls

serverSocket

private java.net.ServerSocket serverSocket

selector

private java.nio.channels.Selector selector

acceptKey

private java.nio.channels.SelectionKey acceptKey

stopAcceptingFlag

private boolean stopAcceptingFlag

guiRequestMutex

private final java.lang.Object guiRequestMutex

guiRequestSaveFlag

private boolean guiRequestSaveFlag

guiRequestSaveFilename

private java.lang.String guiRequestSaveFilename

inPauseState

private boolean inPauseState

fileServerThread

private static java.lang.Thread fileServerThread

serverRunning

private boolean serverRunning

obsolete

private boolean obsolete

shuttingDown

private boolean shuttingDown

forceShutDown

private boolean forceShutDown

initiateDisposal

private boolean initiateDisposal

caughtUpAction

private java.lang.String caughtUpAction

timeoutDuringStart

private final int timeoutDuringStart
See Also:
Constant Field Values

timeoutDuringGame

private final int timeoutDuringGame
See Also:
Constant Field Values

timeoutDuringShutdown

private final int timeoutDuringShutdown
See Also:
Constant Field Values

WEBGAMES_STARTUP_TIMEOUT_SECS

private static final int WEBGAMES_STARTUP_TIMEOUT_SECS
How long in public server games socket shall wait for Clients.

See Also:
Constant Field Values

PING_REQUEST_INTERVAL_SEC

private final int PING_REQUEST_INTERVAL_SEC
See Also:
Constant Field Values

lastPingRound

private long lastPingRound
How many ms ago last ping round was done.


startInititatedTime

private long startInititatedTime
When server started to listed for clients


gameStartupTimeoutSecs

private int gameStartupTimeoutSecs
Timeout how long server waits for clients before giving up; in normal/local games 0, meaning forever; in public server usage set to WEBGAMES_STARTUP_TIMEOUT_SECS


disposeAllClientsDoneMutex

private final java.lang.Object disposeAllClientsDoneMutex

disposeAllClientsDone

private boolean disposeAllClientsDone

byteBuffer

private final java.nio.ByteBuffer byteBuffer

processingCH

ClientHandler processingCH

overriddenCH

ClientHandler overriddenCH

channelChanges

private final java.util.List<ClientHandler> channelChanges

waitUntilOverMutex

private final java.lang.Object waitUntilOverMutex

waitingToCatchup

private final java.util.HashSet<IClient> waitingToCatchup
Constructor Detail

Server

Server(GameServerSide game,
       WhatNextManager whatNextMgr,
       int port)
Method Detail

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

initFileServer

void initFileServer()

isKnownClient

public boolean isKnownClient(java.net.InetAddress requester)

initSocketServer

void initSocketServer()

waitForClients

boolean waitForClients()

overrideProcessingCH

public void overrideProcessingCH(Player player)

restoreProcessingCH

public void restoreProcessingCH()

waitOnSelector

public void waitOnSelector(int timeout,
                           boolean stillWaitingForClients)

handleOutsideChanges

private void handleOutsideChanges(int timeout,
                                  boolean stillWaitingForClients)
                           throws java.io.IOException
Throws:
java.io.IOException

handleSelectedKeys

private void handleSelectedKeys()
                         throws java.io.IOException,
                                java.nio.channels.ClosedChannelException
Throws:
java.io.IOException
java.nio.channels.ClosedChannelException

sleepFor

public void sleepFor(long millis)

handleChannelChanges

private void handleChannelChanges()
                           throws java.io.IOException
Throws:
java.io.IOException

externShutdown

public void externShutdown()
Shutdown initiated by outside, i.e. NOT by the Server thread itself. Right now, this is used by StartupProgressDialog's abort button.


stopAccepting

private void stopAccepting()
                    throws java.io.IOException
Throws:
java.io.IOException

closeSocketAndSelector

private void closeSocketAndSelector()
Close serverSocket and selector, if needed


readFromChannel

private int readFromChannel(java.nio.channels.SelectionKey key,
                            java.nio.channels.SocketChannel sc)
                     throws java.io.IOException
Throws:
java.io.IOException

queueClientHandlerForChannelChanges

void queueClientHandlerForChannelChanges(ClientHandler ch)
Put the ClientHandler into the queue to be removed from selector on next possible opportunity


notifyThatGameFinished

public void notifyThatGameFinished()

waitUntilGameFinishes

public void waitUntilGameFinishes()

stopServerRunning

public void stopServerRunning()

isServerRunning

public boolean isServerRunning()

stopFileServer

public void stopFileServer()

disconnectChannel

private void disconnectChannel(java.nio.channels.SocketChannel sc,
                               java.nio.channels.SelectionKey key)
                        throws java.io.IOException
Close the SocketChannel, cancel the selection key and unregister the SocketChannel from list of active SocketChannels.

Parameters:
sc - SocketChannel of the client
key - Key for that SocketChannel
Throws:
java.io.IOException

unregisterSocketChannel

public void unregisterSocketChannel(java.nio.channels.SocketChannel socketChannel)

setBoardVisibility

public void setBoardVisibility(Player player,
                               boolean val)

isClientGone

public boolean isClientGone(Player player)

anyNonAiSocketsLeft

private boolean anyNonAiSocketsLeft()

setObsolete

public void setObsolete()

getPlayerName

java.lang.String getPlayerName()
Name of the player, for which data from socket is currently processed.


getPlayer

private Player getPlayer()
The player, for which data from socket is currently processed.


isActivePlayer

private boolean isActivePlayer()
returns true if the active player is the player owning the connection from which data is currently processed


getActivePlayerSS

private PlayerServerSide getActivePlayerSS()

isBattleActivePlayer

private boolean isBattleActivePlayer()

addClient

java.lang.String addClient(IClient client,
                           java.lang.String playerName,
                           boolean remote,
                           int clientVersion,
                           java.lang.String buildInfo)
Add a Client.

Parameters:
client -
playerName -
remote -
clientVersion -
Returns:
Reason why adding Client was refused, null if all is fine.

startGame

public void startGame()
When the last player has *joined* (not just connected), he calls this here, and this will proceed with either loadGame2() or newGame2().


initWaitingForPlayersToJoin

private void initWaitingForPlayersToJoin(int count)
Initialize the number of players we wait for to join (thread-safe)

Parameters:
count - the number of players that are expected to join

decrementWaitingForPlayersToJoin

private int decrementWaitingForPlayersToJoin()
Decrement the number of players we wait for to join by one in a thread-safe way, and return the new value.

Returns:
The number of players that still need to join

getClientCount

public int getClientCount()

addRemoteClient

private void addRemoteClient(IClient client,
                             Player player)

disposeAllClients

void disposeAllClients()

loadFailed

public void loadFailed()

cleanupStartlog

public void cleanupStartlog()

cleanup

public void cleanup()

allUpdatePlayerInfo

void allUpdatePlayerInfo(boolean treatDeadAsAlive)

allUpdatePlayerInfo

void allUpdatePlayerInfo()

allUpdateCreatureCount

void allUpdateCreatureCount(CreatureType type,
                            int count,
                            int deadCount)

allTellMovementRoll

void allTellMovementRoll(int roll)

leaveCarryMode

public void leaveCarryMode()
Specified by:
leaveCarryMode in interface IServer

doneWithBattleMoves

public void doneWithBattleMoves()
Specified by:
doneWithBattleMoves in interface IServer

doneWithStrikes

public void doneWithStrikes()
Specified by:
doneWithStrikes in interface IServer

getClient

private IClient getClient(Player player)

allInitBoard

void allInitBoard()

allTellReplay

void allTellReplay(boolean val,
                   int maxTurn)

allTellRedo

void allTellRedo(boolean val)

allRequestConfirmCatchup

void allRequestConfirmCatchup(java.lang.String action)

allTellAllLegionLocations

void allTellAllLegionLocations()

allTellLegionLocation

void allTellLegionLocation(Legion legion)

allRemoveLegion

void allRemoveLegion(Legion legion)

allTellPlayerElim

void allTellPlayerElim(Player eliminatedPlayer,
                       Player slayer,
                       boolean updateHistory)

repeatTellOneHasNetworkTrouble

void repeatTellOneHasNetworkTrouble()

othersTellOneHasNetworkTrouble

void othersTellOneHasNetworkTrouble(ClientHandler chInTrouble)

othersTellOnesTroubleIsOver

void othersTellOnesTroubleIsOver(ClientHandler chInTrouble)

allRequestPingIfNeeded

void allRequestPingIfNeeded()
IF last ping round is at least PING_REQUEST_INTERVAL_SEC seconds ago, then send a ping request to all clients (except those which are in trouble anyway).


allTellGameOver

void allTellGameOver(java.lang.String message,
                     boolean disposeFollows)

allSetupTurnState

void allSetupTurnState()
Needed if loading game outside the split phase.


allSetupSplit

void allSetupSplit()

allSetupMove

void allSetupMove()

allSetupFight

void allSetupFight()

allSetupMuster

void allSetupMuster()

kickPhase

void kickPhase()

allSetupBattleSummon

void allSetupBattleSummon()

allSetupBattleRecruit

void allSetupBattleRecruit()

allSetupBattleMove

void allSetupBattleMove()

allSetupBattleFight

void allSetupBattleFight()

allPlaceNewChit

void allPlaceNewChit(CreatureServerSide critter)

allRemoveDeadBattleChits

void allRemoveDeadBattleChits()

allTellEngagementResults

void allTellEngagementResults(Legion winner,
                              java.lang.String method,
                              int points,
                              int turns)

nextEngagement

void nextEngagement()

askAcquireAngel

void askAcquireAngel(PlayerServerSide player,
                     Legion legion,
                     java.util.List<CreatureType> recruits)
Find out if the player wants to acquire an angel or archangel.


acquireAngel

public void acquireAngel(Legion legion,
                         CreatureType angelType)
Specified by:
acquireAngel in interface IServer

createSummonAngel

void createSummonAngel(Legion legion)

reinforce

void reinforce(Legion legion)

doSummon

public void doSummon(Summoning event)
Description copied from interface: IServer
Handles a summon event

Specified by:
doSummon in interface IServer
Parameters:
event - The summon event or null if summoning is not wanted.

doRecruit

public void doRecruit(Recruitment event)
Handle mustering for legion. if recruiting with nothing, recruiterName is a non-null String that contains "null".

Specified by:
doRecruit in interface IServer

didRecruit

void didRecruit(AddCreatureAction event,
                CreatureType recruiter)

undidRecruit

void undidRecruit(Legion legion,
                  CreatureType recruit,
                  boolean reinforced)

engage

public void engage(MasterHex hex)
Specified by:
engage in interface IServer

allTellEngagement

void allTellEngagement(MasterHex hex,
                       Legion attacker,
                       Legion defender)

askConcede

void askConcede(Legion ally,
                Legion enemy)
Ask ally's player whether he wants to concede with ally.


concede

public void concede(Legion legion)
Specified by:
concede in interface IServer

doNotConcede

public void doNotConcede(Legion legion)
Specified by:
doNotConcede in interface IServer

askFlee

void askFlee(Legion ally,
             Legion enemy)
Ask ally's player whether he wants to flee with ally.


flee

public void flee(Legion legion)
Specified by:
flee in interface IServer

doNotFlee

public void doNotFlee(Legion legion)
Specified by:
doNotFlee in interface IServer

twoNegotiate

void twoNegotiate(Legion attacker,
                  Legion defender)

makeProposal

public void makeProposal(java.lang.String proposalString)
playerName makes a proposal.

Specified by:
makeProposal in interface IServer

tellProposal

void tellProposal(Player player,
                  Proposal proposal)
Tell playerName about proposal.


fight

public void fight(MasterHex hex)
Specified by:
fight in interface IServer

doBattleMove

public void doBattleMove(int tag,
                         BattleHex hex)
Specified by:
doBattleMove in interface IServer

allTellBattleMove

void allTellBattleMove(int tag,
                       BattleHex startingHex,
                       BattleHex endingHex,
                       boolean undo)

strike

public void strike(int tag,
                   BattleHex hex)
Specified by:
strike in interface IServer

applyCarries

public void applyCarries(BattleHex hex)
Specified by:
applyCarries in interface IServer

undoBattleMove

public void undoBattleMove(BattleHex hex)
Specified by:
undoBattleMove in interface IServer

allTellStrikeResults

void allTellStrikeResults(CreatureServerSide striker,
                          CreatureServerSide target,
                          int strikeNumber,
                          java.util.List<java.lang.String> rolls,
                          int damage,
                          int carryDamageLeft,
                          java.util.Set<java.lang.String> carryTargetDescriptions)

allTellCarryResults

void allTellCarryResults(CreatureServerSide carryTarget,
                         int carryDamageDone,
                         int carryDamageLeft,
                         java.util.Set<java.lang.String> carryTargetDescriptions)

allTellHexDamageResults

void allTellHexDamageResults(CreatureServerSide target,
                             int damage)

askChooseStrikePenalty

void askChooseStrikePenalty(java.util.SortedSet<PenaltyOption> penaltyOptions)
Takes a Set of PenaltyOptions.


assignStrikePenalty

public void assignStrikePenalty(java.lang.String prompt)
Specified by:
assignStrikePenalty in interface IServer

allInitBattle

void allInitBattle(MasterHex masterHex)

allCleanupBattle

void allCleanupBattle()

mulligan

public void mulligan()
Specified by:
mulligan in interface IServer

undoSplit

public void undoSplit(Legion splitoff)
Specified by:
undoSplit in interface IServer

undidSplit

void undidSplit(Legion splitoff,
                Legion survivor,
                boolean updateHistory,
                int turn)

undoMove

public void undoMove(Legion legion)
Specified by:
undoMove in interface IServer

allTellUndidMove

public void allTellUndidMove(Legion legion,
                             MasterHex formerHex,
                             MasterHex currentHex,
                             boolean splitLegionHasForcedMove)

undoRecruit

public void undoRecruit(Legion legion)
Specified by:
undoRecruit in interface IServer

doneWithSplits

public void doneWithSplits()
Specified by:
doneWithSplits in interface IServer

doneWithMoves

public void doneWithMoves()
Specified by:
doneWithMoves in interface IServer

doneWithEngagements

public void doneWithEngagements()
Specified by:
doneWithEngagements in interface IServer

doneWithRecruits

public void doneWithRecruits()
Specified by:
doneWithRecruits in interface IServer

withdrawFromGame

public void withdrawFromGame()
Withdraw the currently active player (if it is a real one, and withdrawal still makes sense).

Specified by:
withdrawFromGame in interface IServer

withdrawFromGame

public void withdrawFromGame(java.lang.String playerName)
Withdraw a specific player of which we know only the name; e.g. when one clientHandler when trying to write to another clientHandler encountered closed socket.

Parameters:
playerName - Name of the player to withdraw

disconnect

public void disconnect()
Specified by:
disconnect in interface IServer

stopGame

public void stopGame()
Specified by:
stopGame in interface IServer

triggerDispose

void triggerDispose()

getPlayerInfo

private java.util.List<java.lang.String> getPlayerInfo(boolean treatDeadAsAlive)

doSplit

public void doSplit(Legion parent,
                    java.lang.String childId,
                    java.util.List<CreatureType> creaturesToSplit)
Description copied from interface: IServer
Executes a split of certain creatures from a legion.

Specified by:
doSplit in interface IServer
Parameters:
parent - The legion to split the creatures out of.
childId - A marker for the new legion.
creaturesToSplit - The creatures to split out.

allTellDidSplit

void allTellDidSplit(Legion parent,
                     Legion child,
                     int turn,
                     boolean history)
Called from game after this legion was split off, or by history


doMove

public void doMove(Legion legion,
                   MasterHex hex,
                   EntrySide entrySide,
                   boolean teleport,
                   CreatureType teleportingLord)
Specified by:
doMove in interface IServer

allTellDidMove

void allTellDidMove(Legion legion,
                    MasterHex startingHex,
                    MasterHex hex,
                    EntrySide entrySide,
                    boolean teleport,
                    CreatureType teleportingLord)

allTellDidSummon

void allTellDidSummon(Legion receivingLegion,
                      Legion donorLegion,
                      CreatureType summon)

allTellAddCreature

void allTellAddCreature(AddCreatureAction event,
                        boolean updateHistory,
                        java.lang.String reason)

allTellRemoveCreature

void allTellRemoveCreature(Legion legion,
                           CreatureType creature,
                           boolean updateHistory,
                           java.lang.String reason)

allRevealLegion

void allRevealLegion(Legion legion,
                     java.lang.String reason)

allRevealEngagedLegion

void allRevealEngagedLegion(Legion legion,
                            boolean isAttacker,
                            java.lang.String reason)
pass to all clients the 'revealEngagedCreatures' message, then fire an 'revealEvent' to the history.

Parameters:
legion - the legion marker to reveal which is in a battle
isAttacker - true if the 'legion' is the atackker in the battle, false for the defender.

allRevealLegion

void allRevealLegion(Legion legion,
                     java.util.List<CreatureType> creatures,
                     java.lang.String reason)
Call from History during load game only


oneRevealLegion

void oneRevealLegion(Legion legion,
                     Player player,
                     java.lang.String reason)

oneRevealLegion

void oneRevealLegion(Player player,
                     Legion legion,
                     java.util.List<CreatureType> creatureNames,
                     java.lang.String reason)
Call from History during load game only


allFullyUpdateLegionStatus

void allFullyUpdateLegionStatus()

allFullyUpdateAllLegionContents

void allFullyUpdateAllLegionContents(java.lang.String reason)

allRevealCreatures

void allRevealCreatures(Legion legion,
                        java.util.List<CreatureType> creatureNames,
                        java.lang.String reason)

newGame

public void newGame()
Specified by:
newGame in interface IServer

loadGame

public void loadGame(java.lang.String filename)
Specified by:
loadGame in interface IServer

saveGame

public void saveGame(java.lang.String filename)
Specified by:
saveGame in interface IServer

saveGame

public void saveGame(java.lang.String filename,
                     boolean autoSave)

initiateSaveGame

public void initiateSaveGame(java.lang.String filename)

setPauseState

public void setPauseState(boolean newState)

handleGuiRequests

public boolean handleGuiRequests()

checkServerConnection

public void checkServerConnection()
Specified by:
checkServerConnection in interface IServer

clientWontConfirmCatchup

public void clientWontConfirmCatchup(ClientHandler ch,
                                     java.lang.String reason)
Check whether client is currently expected to send a caught-Up confirmation. If yes: it won't happen, so act accordingly. If no : even better so, so just do nothing.

Parameters:
reason - Reason why client won't send the confirmation (typically disconnected or something).

clientConfirmedCatchup

public void clientConfirmedCatchup()
Specified by:
clientConfirmedCatchup in interface IServer

actOnAllCaughtUp

private void actOnAllCaughtUp()

setPlayerName

void setPlayerName(Player player,
                   java.lang.String newName)
Used to change a player name after color is assigned.


askPickColor

void askPickColor(Player player,
                  java.util.List<PlayerColor> colorsLeft)

assignColor

public void assignColor(PlayerColor color)
Specified by:
assignColor in interface IServer

askPickFirstMarker

void askPickFirstMarker(Player player)

assignFirstMarker

public void assignFirstMarker(java.lang.String markerId)
Specified by:
assignFirstMarker in interface IServer

allSetColor

void allSetColor()
Hack to set color on load game.


getIntOption

int getIntOption(java.lang.String optname)

oneSetOption

void oneSetOption(Player player,
                  java.lang.String optname,
                  java.lang.String value)

oneSetOption

void oneSetOption(Player player,
                  java.lang.String optname,
                  boolean value)

allSyncOption

void allSyncOption(java.lang.String optname,
                   java.lang.String value)

allSyncOption

void allSyncOption(java.lang.String optname,
                   boolean value)

allSyncOption

void allSyncOption(java.lang.String optname,
                   int value)

allLog

void allLog(java.lang.String message)
DO NOT USE: package so that it can be called from Log4J Appender.


logToStartLog

void logToStartLog(java.lang.String message)

disableAutoCloseStartupLog

private void disableAutoCloseStartupLog()

doSetWhatToDoNext

public void doSetWhatToDoNext(WhatNextManager.WhatToDoNext whatToDoNext,
                              boolean triggerQuitTimer)

startupProgressAbort

public void startupProgressAbort()

startupProgressQuit

public void startupProgressQuit()

getGame

public GameServerSide getGame()

getRecorder

public MessageRecorder getRecorder()

replyToRequestGameInfo

public void replyToRequestGameInfo()

joinGame

public void joinGame(java.lang.String playerName)
Specified by:
joinGame in interface IServer