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 class
Server.WithdrawInfo
-
Field Summary
Fields Modifier and Type Field Description private java.nio.channels.SelectionKey
acceptKey
private java.util.List<java.nio.channels.SocketChannel>
activeSocketChannelList
List of SocketChannels that are currently activeprivate java.nio.ByteBuffer
byteBuffer
private java.lang.String
caughtUpAction
private java.util.List<ClientHandlerStub>
channelChanges
private ClientHandlerStub
clientStub
private boolean
disposeAllClientsDone
private java.lang.Object
disposeAllClientsDoneMutex
private static java.lang.Thread
fileServerThread
private 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 itprivate 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_SECSprivate java.lang.Object
guiRequestMutex
private java.lang.String
guiRequestSaveFilename
private boolean
guiRequestSaveFlag
private java.util.List<IClient>
iClients
Recipients for everything send to "each client" - including the stubprivate 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 java.util.Map<Player,IClient>
playerToClientMap
Map of players to their clients.private int
port
Server socket port.(package private) ClientHandler
processingCH
private java.util.List<ClientHandler>
realClients
Only real ClientHandlers (excluding the stub)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 connectedprivate boolean
serverRunning
private java.net.ServerSocket
serverSocket
private boolean
shuttingDown
private int
spectators
private long
startInititatedTime
When server started to listed for clientsprivate 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
waitingForClients
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 waitingForPlayersToJoinprivate WhatNextManager
whatNextManager
-
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 void
acquireAngel(Legion legion, CreatureType angelType)
private void
actOnAllCaughtUp()
(package private) java.lang.String
addClient(ClientHandler client, java.lang.String playerName, boolean remote, int clientVersion, java.lang.String buildInfo, boolean spectator)
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, boolean skipInTrouble)
(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.lang.String reason)
(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
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
allTellHexSlowResults(CreatureServerSide target, int slowValue)
(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(boolean treatDeadAsAlive, java.lang.String reason)
(package private) void
allUpdatePlayerInfo(java.lang.String reason)
private boolean
anyNonAiSocketsLeft()
(package private) void
appendToConnLogs(ClientHandler chInTrouble, java.lang.String message)
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
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 neededvoid
concede(Legion legion)
void
createClientHandlerStub()
(package private) void
createSummonAngel(Legion legion)
(package private) void
didRecruit(AddCreatureAction event, CreatureType recruiter)
private void
disableAutoCloseStartupLog()
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
doCleanup()
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 eventvoid
enforcedDisconnectClient(java.lang.String name)
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)
ClientHandler
getClientHandlerByName(java.lang.String name)
Might be a player or a spectator (but not a stub)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()
private void
handleForcedWithdraws()
boolean
handleGuiRequests()
Handle GUI-initiated requests: Save and Pauseprivate void
handleOutsideChanges(boolean wasTimeout, boolean stillWaitingForClients)
private int
handleReadFromChannel(java.nio.channels.SelectionKey key, java.nio.channels.SocketChannel sc)
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 processedprivate boolean
isBattleActivePlayer()
boolean
isClientGone(Player player)
private java.lang.String
isDoneWithStrikesOk()
Validates that it it OK to be "done with strikes" now for executing playerboolean
isKnownClient(java.net.InetAddress requester)
boolean
isServerRunning()
boolean
isWithdrawalIrrelevant()
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)
(package private) void
othersTellReconnectCompleted(ClientHandler chInTrouble)
(package private) void
othersTellReconnectOngoing(ClientHandler chInTrouble)
(package private) void
othersTellRemainingTime(ClientHandler chInTrouble, int secondsLeft)
void
overrideProcessingCH(Player player)
private void
processByteBuffer()
(package private) void
queueClientHandlerForChannelChanges(ClientHandlerStub ch)
Put the ClientHandler into the queue to be removed from selector on next possible opportunity(package private) void
reinforce(Legion legion)
(package private) void
repeatTellOneHasNetworkTrouble()
void
replyToRequestGameInfo()
void
requestSyncDelta(int lastReceivedMessageNr, int syncRequestNumber)
void
restoreProcessingCH()
void
run()
void
saveGame(java.lang.String filename)
void
saveGame(java.lang.String filename, boolean autoSave)
void
sendDisconnect()
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.(package private) void
startFileServerIfNotRunning()
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()
private void
triggerWithdrawIfDoesNotReconnect(long intervalLen, int intervals)
(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
watchGame()
void
withdrawFromGame()
Withdraw the player for which data was currently processed on socket (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.private void
withdrawFromGameIfRelevant(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:
run
in interfacejava.lang.Runnable
- Overrides:
run
in 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.IOException
java.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.IOException
Close 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:
leaveCarryMode
in interfaceIServer
-
doneWithBattleMoves
public void doneWithBattleMoves()
- Specified by:
doneWithBattleMoves
in interfaceIServer
-
doneWithStrikes
public void doneWithStrikes()
- Specified by:
doneWithStrikes
in 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:
acquireAngel
in interfaceIServer
-
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
-
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:
doNotConcede
in 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:
makeProposal
in interfaceIServer
-
doBattleMove
public void doBattleMove(int tag, BattleHex hex)
- Specified by:
doBattleMove
in interfaceIServer
-
allTellBattleMove
void allTellBattleMove(int tag, BattleHex startingHex, BattleHex endingHex, boolean undo)
-
applyCarries
public void applyCarries(BattleHex hex)
- Specified by:
applyCarries
in interfaceIServer
-
undoBattleMove
public void undoBattleMove(BattleHex hex)
- Specified by:
undoBattleMove
in 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:
assignStrikePenalty
in 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:
undoRecruit
in interfaceIServer
-
doneWithSplits
public void doneWithSplits()
- Specified by:
doneWithSplits
in interfaceIServer
-
doneWithMoves
public void doneWithMoves()
- Specified by:
doneWithMoves
in interfaceIServer
-
doneWithEngagements
public void doneWithEngagements()
- Specified by:
doneWithEngagements
in interfaceIServer
-
doneWithRecruits
public void doneWithRecruits()
- Specified by:
doneWithRecruits
in 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:
withdrawFromGame
in 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:
sendDisconnect
in 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:IServer
Executes 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:
checkServerConnection
in 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:
clientConfirmedCatchup
in 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:
assignColor
in interfaceIServer
-
askPickFirstMarker
void askPickFirstMarker(Player player)
-
assignFirstMarker
public void assignFirstMarker(java.lang.String markerId)
- Specified by:
assignFirstMarker
in 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)
-
-