Package net.sf.colossus.server
Class Server
- java.lang.Object
-
- java.lang.Thread
-
- 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 Modifier and Type Class Description classServer.WithdrawInfo
-
Field Summary
Fields Modifier and Type Field Description private java.nio.channels.SelectionKeyacceptKeyprivate java.util.List<java.nio.channels.SocketChannel>activeSocketChannelListList of SocketChannels that are currently activeprivate java.nio.ByteBufferbyteBufferprivate java.lang.StringcaughtUpActionprivate java.util.List<ClientHandlerStub>channelChangesprivate ClientHandlerStubclientStubprivate booleandisposeAllClientsDoneprivate java.lang.ObjectdisposeAllClientsDoneMutexprivate static java.lang.ThreadfileServerThreadprivate java.util.Map<java.lang.String,Server.WithdrawInfo>forcedWithdrawsClientHandlers to be withdrawn, together with some related (timing) data; selector thread will do it then when it's the right time for itprivate booleanforceShutDownprivate GameServerSidegameprivate intgameStartupTimeoutSecsTimeout 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_SECSprivate java.lang.ObjectguiRequestMutexprivate java.lang.StringguiRequestSaveFilenameprivate booleanguiRequestSaveFlagprivate java.util.List<IClient>iClientsRecipients for everything send to "each client" - including the stubprivate booleaninitiateDisposalprivate booleaninPauseStateprivate longlastPingRoundHow many ms ago last ping round was done.private static java.util.logging.LoggerLOGGERprivate booleanobsolete(package private) ClientHandleroverriddenCHprivate intPING_REQUEST_INTERVAL_SECprivate java.util.Map<Player,IClient>playerToClientMapMap of players to their clients.private intportServer socket port.(package private) ClientHandlerprocessingCHprivate java.util.List<ClientHandler>realClientsOnly real ClientHandlers (excluding the stub)private MessageRecorderrecorderprivate java.util.List<IClient>remoteClientsprivate java.util.List<RemoteLogHandler>remoteLogHandlersprivate java.util.List<java.lang.String>rollsprivate java.nio.channels.Selectorselectorprivate booleansendPingRequestsWill be set to true after all clients are properly connectedprivate booleanserverRunningprivate java.net.ServerSocketserverSocketprivate booleanshuttingDownprivate intspectatorsprivate longstartInititatedTimeWhen server started to listed for clientsprivate static StartupProgressstartLogprivate booleanstopAcceptingFlagprivate intstrikeNumberprivate CreatureServerSidestrikerprivate CreatureServerSidetargetprivate inttimeoutDuringGameprivate inttimeoutDuringShutdownprivate inttimeoutDuringStartprivate intwaitingForClientsNumber of player clients we're waiting for to *connect*private intwaitingForPlayersToJoinNumber 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>waitingToCatchupprivate java.lang.ObjectwaitUntilOverMutexprivate static intWEBGAMES_STARTUP_TIMEOUT_SECSHow long in public server games socket shall wait for Clients.private java.lang.ObjectwfptjSemaphorSemaphor for synchronized access to waitingForPlayersToJoinprivate WhatNextManagerwhatNextManager-
Fields inherited from interface net.sf.colossus.server.IServer
CLIENT_VERSION, CLIENT_VERSION_CAN_HANDLE_NAK, CLIENT_VERSION_CAN_RECONNECT, CLIENT_VERSION_UNDERSTANDS_PING, CLIENT_VERSION_VARIANT_XML_OK, MINIMUM_CLIENT_VERSION
-
-
Constructor Summary
Constructors Constructor Description Server(GameServerSide game, WhatNextManager whatNextMgr, int port)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidacquireAngel(Legion legion, CreatureType angelType)private voidactOnAllCaughtUp()(package private) java.lang.StringaddClient(ClientHandler client, java.lang.String playerName, boolean remote, int clientVersion, java.lang.String buildInfo, boolean spectator)Add a Client.private voidaddRemoteClient(IClient client, Player player)(package private) voidallCleanupBattle()(package private) voidallFullyUpdateAllLegionContents(java.lang.String reason)(package private) voidallFullyUpdateLegionStatus()(package private) voidallInitBattle(MasterHex masterHex)(package private) voidallInitBoard()(package private) voidallLog(java.lang.String message)DO NOT USE: package so that it can be called from Log4J Appender.(package private) voidallPlaceNewChit(CreatureServerSide critter)(package private) voidallRemoveDeadBattleChits()(package private) voidallRemoveLegion(Legion legion)(package private) voidallRequestConfirmCatchup(java.lang.String action, boolean skipInTrouble)(package private) voidallRequestPingIfNeeded()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) voidallRevealCreatures(Legion legion, java.util.List<CreatureType> creatureNames, java.lang.String reason)(package private) voidallRevealEngagedLegion(Legion legion, boolean isAttacker, java.lang.String reason)pass to all clients the 'revealEngagedCreatures' message, then fire an 'revealEvent' to the history.(package private) voidallRevealLegion(Legion legion, java.lang.String reason)(package private) voidallRevealLegion(Legion legion, java.util.List<CreatureType> creatures, java.lang.String reason)Call from History during load game only(package private) voidallSetColor()Hack to set color on load game.(package private) voidallSetupBattleFight()(package private) voidallSetupBattleMove()(package private) voidallSetupBattleRecruit()(package private) voidallSetupBattleSummon()(package private) voidallSetupFight()(package private) voidallSetupMove()(package private) voidallSetupMuster()(package private) voidallSetupSplit()(package private) voidallSetupTurnState()Needed if loading game outside the split phase.(package private) voidallSyncOption(java.lang.String optname, boolean value)(package private) voidallSyncOption(java.lang.String optname, int value)(package private) voidallSyncOption(java.lang.String optname, java.lang.String value)(package private) voidallTellAddCreature(AddCreatureAction event, boolean updateHistory, java.lang.String reason)(package private) voidallTellAllLegionLocations()(package private) voidallTellBattleMove(int tag, BattleHex startingHex, BattleHex endingHex, boolean undo)(package private) voidallTellCarryResults(CreatureServerSide carryTarget, int carryDamageDone, int carryDamageLeft, java.util.Set<java.lang.String> carryTargetDescriptions)(package private) voidallTellDidMove(Legion legion, MasterHex startingHex, MasterHex hex, EntrySide entrySide, boolean teleport, CreatureType teleportingLord)(package private) voidallTellDidSplit(Legion parent, Legion child, int turn, boolean history)Called from game after this legion was split off, or by history(package private) voidallTellDidSummon(Legion receivingLegion, Legion donorLegion, CreatureType summon)(package private) voidallTellEngagement(MasterHex hex, Legion attacker, Legion defender)(package private) voidallTellEngagementResults(Legion winner, java.lang.String method, int points, int turns)(package private) voidallTellGameOver(java.lang.String message, boolean disposeFollows)(package private) voidallTellHexDamageResults(CreatureServerSide target, int damage)(package private) voidallTellHexSlowResults(CreatureServerSide target, int slowValue)(package private) voidallTellLegionLocation(Legion legion)(package private) voidallTellMovementRoll(int roll)(package private) voidallTellPlayerElim(Player eliminatedPlayer, Player slayer, boolean updateHistory)(package private) voidallTellRedo(boolean val)(package private) voidallTellRemoveCreature(Legion legion, CreatureType creature, boolean updateHistory, java.lang.String reason)(package private) voidallTellReplay(boolean val, int maxTurn)(package private) voidallTellStrikeResults(CreatureServerSide striker, CreatureServerSide target, int strikeNumber, java.util.List<java.lang.String> rolls, int damage, int carryDamageLeft, java.util.Set<java.lang.String> carryTargetDescriptions)voidallTellUndidMove(Legion legion, MasterHex formerHex, MasterHex currentHex, boolean splitLegionHasForcedMove)(package private) voidallUpdateCreatureCount(CreatureType type, int count, int deadCount)(package private) voidallUpdatePlayerInfo(boolean treatDeadAsAlive, java.lang.String reason)(package private) voidallUpdatePlayerInfo(java.lang.String reason)private booleananyNonAiSocketsLeft()(package private) voidappendToConnLogs(ClientHandler chInTrouble, java.lang.String message)voidapplyCarries(BattleHex hex)(package private) voidaskAcquireAngel(PlayerServerSide player, Legion legion, java.util.List<CreatureType> recruits)Find out if the player wants to acquire an angel or archangel.(package private) voidaskChooseStrikePenalty(java.util.SortedSet<PenaltyOption> penaltyOptions)Takes a Set of PenaltyOptions.(package private) voidaskConcede(Legion ally, Legion enemy)Ask ally's player whether he wants to concede with ally.(package private) voidaskFlee(Legion ally, Legion enemy)Ask ally's player whether he wants to flee with ally.(package private) voidaskPickColor(Player player, java.util.List<PlayerColor> colorsLeft)(package private) voidaskPickFirstMarker(Player player)voidassignColor(PlayerColor color)voidassignFirstMarker(java.lang.String markerId)voidassignStrikePenalty(java.lang.String prompt)voidcheckServerConnection()voidcleanupStartlog()voidclientConfirmedCatchup()voidclientWontConfirmCatchup(ClientHandler ch, java.lang.String reason)Check whether client is currently expected to send a caught-Up confirmation.private voidcloseSocketAndSelector()Close serverSocket and selector, if neededvoidconcede(Legion legion)voidcreateClientHandlerStub()(package private) voidcreateSummonAngel(Legion legion)(package private) voiddidRecruit(AddCreatureAction event, CreatureType recruiter)private voiddisableAutoCloseStartupLog()private voiddisconnectChannel(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) voiddisposeAllClients()voiddoBattleMove(int tag, BattleHex hex)voiddoCleanup()voiddoMove(Legion legion, MasterHex hex, EntrySide entrySide, boolean teleport, CreatureType teleportingLord)voiddoneWithBattleMoves()voiddoneWithEngagements()voiddoneWithMoves()voiddoneWithRecruits()voiddoneWithSplits()voiddoneWithStrikes()voiddoNotConcede(Legion legion)voiddoNotFlee(Legion legion)voiddoRecruit(Recruitment event)Handle mustering for legion.voiddoSetWhatToDoNext(WhatNextManager.WhatToDoNext whatToDoNext, boolean triggerQuitTimer)voiddoSplit(Legion parent, java.lang.String childId, java.util.List<CreatureType> creaturesToSplit)Executes a split of certain creatures from a legion.voiddoSummon(Summoning event)Handles a summon eventvoidenforcedDisconnectClient(java.lang.String name)voidengage(MasterHex hex)voidexternShutdown()Shutdown initiated by outside, i.e.voidfight(MasterHex hex)voidflee(Legion legion)private PlayerServerSidegetActivePlayerSS()private IClientgetClient(Player player)ClientHandlergetClientHandlerByName(java.lang.String name)Might be a player or a spectator (but not a stub)GameServerSidegetGame()(package private) intgetIntOption(java.lang.String optname)private PlayergetPlayer()The player, for which data from socket is currently processed.private java.util.List<java.lang.String>getPlayerInfo(boolean treatDeadAsAlive)(package private) java.lang.StringgetPlayerName()Name of the player, for which data from socket is currently processed.MessageRecordergetRecorder()private voidhandleChannelChanges()private voidhandleForcedWithdraws()booleanhandleGuiRequests()Handle GUI-initiated requests: Save and Pauseprivate voidhandleOutsideChanges(boolean wasTimeout, boolean stillWaitingForClients)private inthandleReadFromChannel(java.nio.channels.SelectionKey key, java.nio.channels.SocketChannel sc)private voidhandleSelectedKeys()(package private) voidinitFileServer()voidinitiateSaveGame(java.lang.String filename)(package private) voidinitSocketServer()private voidinitWaitingForPlayersToJoin(int count)Initialize the number of players we wait for to join (thread-safe)private booleanisActivePlayer()returns true if the active player is the player owning the connection from which data is currently processedprivate booleanisBattleActivePlayer()booleanisClientGone(Player player)private java.lang.StringisDoneWithStrikesOk()Validates that it it OK to be "done with strikes" now for executing playerbooleanisKnownClient(java.net.InetAddress requester)booleanisServerRunning()booleanisWithdrawalIrrelevant()voidjoinGame(java.lang.String playerName)(package private) voidkickPhase()voidleaveCarryMode()voidloadFailed()voidloadGame(java.lang.String filename)(package private) voidlogToStartLog(java.lang.String message)voidmakeProposal(java.lang.String proposalString)playerName makes a proposal.voidmulligan()voidnewGame()(package private) voidnextEngagement()voidnotifyThatGameFinished()(package private) voidoneRevealLegion(Legion legion, Player player, java.lang.String reason)(package private) voidoneRevealLegion(Player player, Legion legion, java.util.List<CreatureType> creatureNames, java.lang.String reason)Call from History during load game only(package private) voidoneSetOption(Player player, java.lang.String optname, boolean value)(package private) voidoneSetOption(Player player, java.lang.String optname, java.lang.String value)(package private) voidothersTellOneHasNetworkTrouble(ClientHandler chInTrouble)(package private) voidothersTellOnesTroubleIsOver(ClientHandler chInTrouble)(package private) voidothersTellReconnectCompleted(ClientHandler chInTrouble)(package private) voidothersTellReconnectOngoing(ClientHandler chInTrouble)(package private) voidothersTellRemainingTime(ClientHandler chInTrouble, int secondsLeft)voidoverrideProcessingCH(Player player)private voidprocessByteBuffer()(package private) voidqueueClientHandlerForChannelChanges(ClientHandlerStub ch)Put the ClientHandler into the queue to be removed from selector on next possible opportunity(package private) voidreinforce(Legion legion)(package private) voidrepeatTellOneHasNetworkTrouble()voidreplyToRequestGameInfo()voidrequestSyncDelta(int lastReceivedMessageNr, int syncRequestNumber)voidrestoreProcessingCH()voidrun()voidsaveGame(java.lang.String filename)voidsaveGame(java.lang.String filename, boolean autoSave)voidsendDisconnect()voidsetBoardVisibility(Player player, boolean val)voidsetObsolete()voidsetPauseState(boolean newState)(package private) voidsetPlayerName(Player player, java.lang.String newName)Used to change a player name after color is assigned.(package private) voidstartFileServerIfNotRunning()voidstartGame()When the last player has *joined* (not just connected), he calls this here, and this will proceed with either loadGame2() or newGame2().voidstartupProgressAbort()voidstartupProgressQuit()private voidstopAccepting()voidstopFileServer()voidstopGame()voidstopServerRunning()voidstrike(int tag, BattleHex hex)(package private) voidtellProposal(Player player, Proposal proposal)Tell playerName about proposal.(package private) voidtriggerDispose()private voidtriggerWithdrawIfDoesNotReconnect(long intervalLen, int intervals)(package private) voidtwoNegotiate(Legion attacker, Legion defender)(package private) voidundidRecruit(Legion legion, CreatureType recruit, boolean reinforced)(package private) voidundidSplit(Legion splitoff, Legion survivor, boolean updateHistory, int turn)voidundoBattleMove(BattleHex hex)voidundoMove(Legion legion)voidundoRecruit(Legion legion)voidundoSplit(Legion splitoff)voidunregisterSocketChannel(java.nio.channels.SocketChannel socketChannel)(package private) booleanwaitForClients()voidwaitOnSelector(int timeout, boolean stillWaitingForClients)voidwaitUntilGameFinishes()voidwatchGame()voidwithdrawFromGame()Withdraw the player for which data was currently processed on socket (if it is a real one, and withdrawal still makes sense).voidwithdrawFromGame(java.lang.String playerName)Withdraw a specific player of which we know only the name; e.g.private voidwithdrawFromGameIfRelevant(java.lang.Exception gotException, boolean didDisconnect)Something with the connection of "processingCH" which makes perhaps Withdraw necessary.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
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
-
clientStub
private ClientHandlerStub clientStub
-
iClients
private final java.util.List<IClient> iClients
Recipients for everything send to "each client" - including the stub
-
realClients
private final java.util.List<ClientHandler> realClients
Only real ClientHandlers (excluding the stub)
-
remoteClients
private final java.util.List<IClient> remoteClients
-
remoteLogHandlers
private final java.util.List<RemoteLogHandler> remoteLogHandlers
-
playerToClientMap
private final java.util.Map<Player,IClient> playerToClientMap
Map of players to their clients.
-
activeSocketChannelList
private final java.util.List<java.nio.channels.SocketChannel> activeSocketChannelList
List of SocketChannels that are currently active
-
forcedWithdraws
private final java.util.Map<java.lang.String,Server.WithdrawInfo> forcedWithdraws
ClientHandlers to be withdrawn, together with some related (timing) data; selector thread will do it then when it's the right time for it
-
waitingForClients
private int waitingForClients
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<ClientHandlerStub> 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:
runin interfacejava.lang.Runnable- Overrides:
runin classjava.lang.Thread
-
initFileServer
void initFileServer()
-
startFileServerIfNotRunning
void startFileServerIfNotRunning()
-
isKnownClient
public boolean isKnownClient(java.net.InetAddress requester)
-
initSocketServer
void initSocketServer()
-
waitForClients
boolean waitForClients()
-
createClientHandlerStub
public void createClientHandlerStub()
-
overrideProcessingCH
public void overrideProcessingCH(Player player)
-
restoreProcessingCH
public void restoreProcessingCH()
-
waitOnSelector
public void waitOnSelector(int timeout, boolean stillWaitingForClients)
-
handleForcedWithdraws
private void handleForcedWithdraws()
-
handleOutsideChanges
private void handleOutsideChanges(boolean wasTimeout, boolean stillWaitingForClients)
-
handleSelectedKeys
private void handleSelectedKeys() throws java.io.IOException, java.nio.channels.ClosedChannelException- Throws:
java.io.IOExceptionjava.nio.channels.ClosedChannelException
-
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
-
handleReadFromChannel
private int handleReadFromChannel(java.nio.channels.SelectionKey key, java.nio.channels.SocketChannel sc) throws java.io.IOException- Throws:
java.io.IOException
-
processByteBuffer
private void processByteBuffer()
-
withdrawFromGameIfRelevant
private void withdrawFromGameIfRelevant(java.lang.Exception gotException, boolean didDisconnect)Something with the connection of "processingCH" which makes perhaps Withdraw necessary. If client seems to support reconnect, mark CH to be temp. disconnected, otherwise take care of the proper withdrawal.- Parameters:
gotException- An exception, if calling this was caused by an (IO)Exception, otherwise null, i.e. it was triggered by EOF.didDisconnect- whether an explicit dicsonnect request message had been received already from that client ( = no point to wait for reconnect attempt).
-
triggerWithdrawIfDoesNotReconnect
private void triggerWithdrawIfDoesNotReconnect(long intervalLen, int intervals)
-
queueClientHandlerForChannelChanges
void queueClientHandlerForChannelChanges(ClientHandlerStub 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.IOExceptionClose the SocketChannel, cancel the selection key and unregister the SocketChannel from list of active SocketChannels.- Parameters:
sc- SocketChannel of the clientkey- 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.
-
getClientHandlerByName
public ClientHandler getClientHandlerByName(java.lang.String name)
Might be a player or a spectator (but not a stub)- Parameters:
name- Name of the player/client/spectator for which ClientHandler is needed
-
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(ClientHandler client, java.lang.String playerName, boolean remote, int clientVersion, java.lang.String buildInfo, boolean spectator)
Add a Client.- Parameters:
client-playerName-remote-clientVersion-spectator-- 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
-
disposeAllClients
void disposeAllClients()
-
loadFailed
public void loadFailed()
-
cleanupStartlog
public void cleanupStartlog()
-
doCleanup
public void doCleanup()
-
allUpdatePlayerInfo
void allUpdatePlayerInfo(boolean treatDeadAsAlive, java.lang.String reason)
-
allUpdatePlayerInfo
void allUpdatePlayerInfo(java.lang.String reason)
-
allUpdateCreatureCount
void allUpdateCreatureCount(CreatureType type, int count, int deadCount)
-
allTellMovementRoll
void allTellMovementRoll(int roll)
-
leaveCarryMode
public void leaveCarryMode()
- Specified by:
leaveCarryModein interfaceIServer
-
doneWithBattleMoves
public void doneWithBattleMoves()
- Specified by:
doneWithBattleMovesin interfaceIServer
-
doneWithStrikes
public void doneWithStrikes()
- Specified by:
doneWithStrikesin interfaceIServer
-
isDoneWithStrikesOk
private java.lang.String isDoneWithStrikesOk()
Validates that it it OK to be "done with strikes" now for executing player- Returns:
- reason why it's not OK; null if all is ok
-
allInitBoard
void allInitBoard()
-
allTellReplay
void allTellReplay(boolean val, int maxTurn)
-
allTellRedo
void allTellRedo(boolean val)
-
allRequestConfirmCatchup
void allRequestConfirmCatchup(java.lang.String action, boolean skipInTrouble)
-
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)
-
othersTellReconnectOngoing
void othersTellReconnectOngoing(ClientHandler chInTrouble)
-
othersTellRemainingTime
void othersTellRemainingTime(ClientHandler chInTrouble, int secondsLeft)
-
othersTellReconnectCompleted
void othersTellReconnectCompleted(ClientHandler chInTrouble)
-
appendToConnLogs
void appendToConnLogs(ClientHandler chInTrouble, java.lang.String message)
-
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:
acquireAngelin interfaceIServer
-
createSummonAngel
void createSummonAngel(Legion legion)
-
reinforce
void reinforce(Legion legion)
-
doSummon
public void doSummon(Summoning event)
Description copied from interface:IServerHandles a summon event
-
doRecruit
public void doRecruit(Recruitment event)
Handle mustering for legion. if recruiting with nothing, recruiterName is a non-null String that contains "null".
-
didRecruit
void didRecruit(AddCreatureAction event, CreatureType recruiter)
-
undidRecruit
void undidRecruit(Legion legion, CreatureType recruit, boolean reinforced)
-
askConcede
void askConcede(Legion ally, Legion enemy)
Ask ally's player whether he wants to concede with ally.
-
doNotConcede
public void doNotConcede(Legion legion)
- Specified by:
doNotConcedein interfaceIServer
-
askFlee
void askFlee(Legion ally, Legion enemy)
Ask ally's player whether he wants to flee with ally.
-
makeProposal
public void makeProposal(java.lang.String proposalString)
playerName makes a proposal.- Specified by:
makeProposalin interfaceIServer
-
doBattleMove
public void doBattleMove(int tag, BattleHex hex)- Specified by:
doBattleMovein interfaceIServer
-
allTellBattleMove
void allTellBattleMove(int tag, BattleHex startingHex, BattleHex endingHex, boolean undo)
-
applyCarries
public void applyCarries(BattleHex hex)
- Specified by:
applyCarriesin interfaceIServer
-
undoBattleMove
public void undoBattleMove(BattleHex hex)
- Specified by:
undoBattleMovein interfaceIServer
-
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)
-
allTellHexSlowResults
void allTellHexSlowResults(CreatureServerSide target, int slowValue)
-
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:
assignStrikePenaltyin interfaceIServer
-
allInitBattle
void allInitBattle(MasterHex masterHex)
-
allCleanupBattle
void allCleanupBattle()
-
allTellUndidMove
public void allTellUndidMove(Legion legion, MasterHex formerHex, MasterHex currentHex, boolean splitLegionHasForcedMove)
-
undoRecruit
public void undoRecruit(Legion legion)
- Specified by:
undoRecruitin interfaceIServer
-
doneWithSplits
public void doneWithSplits()
- Specified by:
doneWithSplitsin interfaceIServer
-
doneWithMoves
public void doneWithMoves()
- Specified by:
doneWithMovesin interfaceIServer
-
doneWithEngagements
public void doneWithEngagements()
- Specified by:
doneWithEngagementsin interfaceIServer
-
doneWithRecruits
public void doneWithRecruits()
- Specified by:
doneWithRecruitsin interfaceIServer
-
isWithdrawalIrrelevant
public boolean isWithdrawalIrrelevant()
-
withdrawFromGame
public void withdrawFromGame()
Withdraw the player for which data was currently processed on socket (if it is a real one, and withdrawal still makes sense).- Specified by:
withdrawFromGamein interfaceIServer
-
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
-
sendDisconnect
public void sendDisconnect()
- Specified by:
sendDisconnectin interfaceIServer
-
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:IServerExecutes a split of certain creatures from a legion.
-
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)
-
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 battleisAttacker- 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(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)
-
loadGame
public void loadGame(java.lang.String filename)
-
saveGame
public void saveGame(java.lang.String filename)
-
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()
Handle GUI-initiated requests: Save and Pause- Returns:
- true if it did something (saving the game)
-
checkServerConnection
public void checkServerConnection()
- Specified by:
checkServerConnectionin interfaceIServer
-
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:
clientConfirmedCatchupin interfaceIServer
-
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:
assignColorin interfaceIServer
-
askPickFirstMarker
void askPickFirstMarker(Player player)
-
assignFirstMarker
public void assignFirstMarker(java.lang.String markerId)
- Specified by:
assignFirstMarkerin interfaceIServer
-
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()
-
requestSyncDelta
public void requestSyncDelta(int lastReceivedMessageNr, int syncRequestNumber)
-
joinGame
public void joinGame(java.lang.String playerName)
-
enforcedDisconnectClient
public void enforcedDisconnectClient(java.lang.String name)
-
-