final class ClientHandler extends java.lang.Object implements IClient
Modifier and Type | Class and Description |
---|---|
private class |
ClientHandler.MessageForClient
here starts some stuff needed for the "synchronization in disconnect case"
|
Modifier and Type | Field and Description |
---|---|
(package private) java.nio.ByteBuffer |
bb |
private int |
cantSendMessageRepeated |
private java.nio.charset.Charset |
charset |
private java.lang.String |
CHARSET_NAME |
private int |
clientVersion |
private int |
commitPointCounter |
private static int |
counter |
private java.nio.charset.CharsetDecoder |
decoder |
private static java.lang.String |
DEFAULT_CHAR_SET |
private boolean |
didExplicitDisconnect |
(package private) java.lang.String |
encodedMsg |
private java.nio.charset.CharsetEncoder |
encoder |
boolean |
fakeDisconnect
Debug stuff, only for testing/development purposes
|
private java.lang.String |
incompleteInput |
private java.lang.String |
incompleteText |
private boolean |
isCommitPoint |
private boolean |
isGone |
private static java.util.logging.Logger |
LOGGER |
private static int |
MAX_KEEP_LINES |
private int |
messageCounter |
private boolean |
obsolete |
private java.lang.String |
playerName |
private java.lang.String |
previousInfoStringsString |
(package private) int |
previousRetries |
(package private) java.util.LinkedList<java.lang.String> |
queue
The queue in which messages are stored, until they were really written.
|
private java.util.ArrayList<java.lang.String> |
recentlyProcessedLines |
private java.util.ArrayList<ClientHandler.MessageForClient> |
redoQueue |
private java.nio.channels.SelectionKey |
selectorKey |
private static java.lang.String |
sep |
private Server |
server |
(package private) int |
should |
private java.lang.String |
signonName |
private java.nio.channels.SocketChannel |
socketChannel |
private boolean |
temporarilyDisconnected |
private long |
temporarilyInTrouble |
private boolean |
withdrawnAlready |
(package private) int |
writtenTotal |
Constructor and Description |
---|
ClientHandler(Server server,
java.nio.channels.SocketChannel channel,
java.nio.channels.SelectionKey selKey) |
Modifier and Type | Method and Description |
---|---|
void |
addCreature(Legion legion,
CreatureType creature,
java.lang.String reason) |
void |
appendToConnectionLog(java.lang.String message) |
void |
askAcquireAngel(Legion legion,
java.util.List<CreatureType> recruits) |
void |
askChooseStrikePenalty(java.util.List<java.lang.String> choices) |
void |
askConcede(Legion ally,
Legion enemy) |
void |
askFlee(Legion ally,
Legion enemy) |
void |
askNegotiate(Legion attacker,
Legion defender) |
void |
askPickColor(java.util.List<PlayerColor> colorsLeft) |
void |
askPickFirstMarker() |
private void |
attemptWritingToChannel() |
private void |
callMethod(java.lang.String method,
java.util.List<java.lang.String> args) |
boolean |
canHandleAdvancedSync() |
boolean |
canHandleBattleMoveNak() |
void |
cleanupBattle() |
void |
clearDisconnectClient() |
void |
clearTemporarilyInTrouble() |
void |
cloneRedoQueue(ClientHandler oldCH) |
private void |
commitPoint() |
private void |
confirmCommitPoint(int confirmedNr)
Remove the messages in redoQueue prior to given commit point
|
void |
confirmWhenCaughtUp() |
void |
createSummonAngel(Legion legion) |
void |
declareObsolete() |
boolean |
didExplicitDisconnect() |
void |
didMove(Legion legion,
MasterHex startingHex,
MasterHex currentHex,
EntrySide entrySide,
boolean teleport,
CreatureType teleportingLord,
boolean splitLegionHasForcedMove) |
void |
didRecruit(Legion legion,
CreatureType recruit,
CreatureType recruiter,
int numRecruiters) |
void |
didSplit(MasterHex hex,
Legion parent,
Legion child,
int childHeight,
java.util.List<CreatureType> splitoffs,
int turn) |
void |
didSummon(Legion summoner,
Legion donor,
CreatureType summon) |
void |
disposeClient()
Server side disposes a client (and informs it about it first)
To be used only for "disposeAllClients()", otherwise setIsGone
reason is misleading.
|
private void |
doCallMethodInTryBlock(java.lang.String line,
java.lang.String method,
java.util.List<java.lang.String> li) |
void |
doReinforce(Legion legion) |
java.lang.String |
dumpLastProcessedLines() |
private void |
enqueueToRedoQueue(int messageNr,
java.lang.String message) |
void |
fakeDisconnectClient() |
java.lang.String |
getPlayerName() |
java.nio.channels.SelectionKey |
getSelectorKey() |
java.lang.String |
getSignonName() |
java.nio.channels.SocketChannel |
getSocketChannel() |
private void |
handleEncoding(java.lang.String msg) |
long |
howLongAlreadyInTrouble() |
void |
initBattle(MasterHex hex,
int battleTurnNumber,
Player battleActivePlayer,
BattlePhase battlePhase,
Legion attacker,
Legion defender) |
void |
initBoard() |
boolean |
isGone() |
boolean |
isTemporarilyDisconnected() |
boolean |
isTemporarilyInTrouble() |
void |
kickPhase() |
void |
log(java.lang.String message) |
void |
messageFromServer(java.lang.String message) |
void |
nak(java.lang.String reason,
java.lang.String errmsg) |
void |
nextEngagement() |
void |
pingRequest() |
void |
placeNewChit(java.lang.String imageName,
boolean inverted,
int tag,
BattleHex hex) |
void |
processInput(java.nio.ByteBuffer byteBuffer) |
void |
removeCreature(Legion legion,
CreatureType creature,
java.lang.String reason) |
void |
removeDeadBattleChits() |
void |
removeLegion(Legion legion) |
private BattleHex |
resolveBattleHex(java.lang.String hexLabel) |
private CreatureType |
resolveCreatureType(java.lang.String name) |
private CreatureType |
resolveCreatureTypeNullOk(java.lang.String name)
There are cases where "null" comes over network and is not meant to
be resolved to a CreatureType, namely:
teleportingLord if no teleport; null recruiter; decline Acquire.
|
private Legion |
resolveLegion(java.lang.String markerId) |
private MasterHex |
resolveMasterHex(java.lang.String hexLabel) |
void |
revealCreatures(Legion legion,
java.util.List<CreatureType> creatures,
java.lang.String reason) |
void |
revealEngagedCreatures(Legion legion,
java.util.List<CreatureType> creatures,
boolean isAttacker,
java.lang.String reason)
print the 'revealEngagagedCreature'-message,
args: markerId, isAttacker, list of creature names
|
void |
sendToClient(java.lang.String message) |
private void |
sendViaChannel(java.lang.String msg) |
private void |
sendViaChannelRaw(java.lang.String msg) |
void |
serverConfirmsConnection() |
void |
setBoardActive(boolean val) |
void |
setColor(PlayerColor color) |
void |
setIsGone(java.lang.String reason) |
void |
setLegionStatus(Legion legion,
boolean moved,
boolean teleported,
EntrySide entrySide,
CreatureType lastRecruit) |
void |
setPlayerName(java.lang.String playerName) |
void |
setTemporarilyDisconnected() |
private void |
setTemporarilyInTrouble() |
void |
setupBattleFight(BattlePhase battlePhase,
Player battleActivePlayer) |
void |
setupBattleMove(Player battleActivePlayer,
int battleTurnNumber) |
void |
setupBattleRecruit(Player battleActivePlayer,
int battleTurnNumber) |
void |
setupBattleSummon(Player battleActivePlayer,
int battleTurnNumber) |
void |
setupFight() |
void |
setupMove() |
void |
setupMuster() |
void |
setupSplit(Player activePlayer,
int turnNumber) |
void |
setupTurnState(Player activePlayer,
int turnNumber) |
boolean |
supportsReconnect() |
void |
syncAfterReconnect(int lastReceivedMessageNr,
int syncRequestNumber)
Re-send all data after the message from which we know client got it
|
void |
syncOption(java.lang.String optname,
java.lang.String value) |
void |
tellBattleMove(int tag,
BattleHex startingHex,
BattleHex endingHex,
boolean undo) |
void |
tellEngagement(MasterHex hex,
Legion attacker,
Legion defender) |
void |
tellEngagementResults(Legion winner,
java.lang.String method,
int points,
int turns) |
void |
tellGameOver(java.lang.String message,
boolean disposeFollows) |
void |
tellInitialGameInfo(java.lang.String variantName,
java.util.Collection<java.lang.String> playerNames) |
void |
tellLegionLocation(Legion legion,
MasterHex hex) |
void |
tellMovementRoll(int roll) |
void |
tellPlayerElim(Player player,
Player slayer) |
void |
tellProposal(java.lang.String proposalString) |
void |
tellRedo(boolean val) |
void |
tellReplay(boolean val,
int maxTurn) |
void |
tellSlowResults(int targetTag,
int slowValue) |
void |
tellStrikeResults(int strikerTag,
int targetTag,
int strikeNumber,
java.util.List<java.lang.String> rolls,
int damage,
boolean killed,
boolean wasCarry,
int carryDamageLeft,
java.util.Set<java.lang.String> carryTargetDescriptions) |
void |
tellSyncCompleted(int syncRequestNumber) |
void |
tellWhatsHappening(java.lang.String message) |
void |
undidMove(Legion legion,
MasterHex formerHex,
MasterHex currentHex,
boolean splitLegionHasForcedMove) |
void |
undidRecruit(Legion legion,
CreatureType recruit) |
void |
undidSplit(Legion splitoff,
Legion survivor,
int turn) |
void |
updateCreatureCount(CreatureType type,
int count,
int deadCount) |
void |
updatePlayerInfo(java.util.List<java.lang.String> infoStrings) |
boolean |
wasFakeDisconnectFlagSet() |
private void |
withdrawIfNeeded(boolean explicit)
Make sure player is withdrawn from game.
|
private static final java.util.logging.Logger LOGGER
private final Server server
private final java.nio.channels.SocketChannel socketChannel
private final java.nio.channels.SelectionKey selectorKey
private java.lang.String playerName
private java.lang.String signonName
private int clientVersion
private boolean isGone
private boolean didExplicitDisconnect
private boolean withdrawnAlready
private int cantSendMessageRepeated
private boolean temporarilyDisconnected
private boolean obsolete
private static final java.lang.String sep
private java.lang.String previousInfoStringsString
private static int counter
private java.lang.String incompleteInput
private java.lang.String incompleteText
private static final java.lang.String DEFAULT_CHAR_SET
private final java.lang.String CHARSET_NAME
private final java.nio.charset.Charset charset
private final java.nio.charset.CharsetEncoder encoder
private final java.nio.charset.CharsetDecoder decoder
private int messageCounter
private int commitPointCounter
private final java.util.ArrayList<ClientHandler.MessageForClient> redoQueue
private static final int MAX_KEEP_LINES
private final java.util.ArrayList<java.lang.String> recentlyProcessedLines
private boolean isCommitPoint
java.nio.ByteBuffer bb
java.lang.String encodedMsg
int should
int writtenTotal
int previousRetries
private long temporarilyInTrouble
java.util.LinkedList<java.lang.String> queue
public boolean fakeDisconnect
ClientHandler(Server server, java.nio.channels.SocketChannel channel, java.nio.channels.SelectionKey selKey)
public java.nio.channels.SelectionKey getSelectorKey()
public java.nio.channels.SocketChannel getSocketChannel()
public boolean isGone()
public void setIsGone(java.lang.String reason)
public boolean didExplicitDisconnect()
public void setTemporarilyDisconnected()
public boolean isTemporarilyDisconnected()
public void processInput(java.nio.ByteBuffer byteBuffer)
private void sendViaChannel(java.lang.String msg)
private void enqueueToRedoQueue(int messageNr, java.lang.String message)
private void commitPoint()
private void confirmCommitPoint(int confirmedNr)
confirmedNr
- Commit point from which we now know that client has
successfully received itpublic boolean supportsReconnect()
public boolean canHandleBattleMoveNak()
public boolean canHandleAdvancedSync()
public void cloneRedoQueue(ClientHandler oldCH)
public void syncAfterReconnect(int lastReceivedMessageNr, int syncRequestNumber)
lastReceivedMessageNr
- Last message which client did still receivesyncRequestNumber
- Every request has own unique id, so we don't mix thempublic boolean isTemporarilyInTrouble()
public long howLongAlreadyInTrouble()
private void setTemporarilyInTrouble()
public void clearTemporarilyInTrouble()
private void handleEncoding(java.lang.String msg)
private void sendViaChannelRaw(java.lang.String msg)
private void attemptWritingToChannel()
private void doCallMethodInTryBlock(java.lang.String line, java.lang.String method, java.util.List<java.lang.String> li)
public java.lang.String dumpLastProcessedLines()
private void callMethod(java.lang.String method, java.util.List<java.lang.String> args)
private BattleHex resolveBattleHex(java.lang.String hexLabel)
private CreatureType resolveCreatureType(java.lang.String name)
private CreatureType resolveCreatureTypeNullOk(java.lang.String name)
name
- Name of the creatureType to find, might be "null"private void withdrawIfNeeded(boolean explicit)
explicit
- Whether client has requested withdraw explicitlyprivate MasterHex resolveMasterHex(java.lang.String hexLabel)
private Legion resolveLegion(java.lang.String markerId)
public void sendToClient(java.lang.String message)
public void disposeClient()
disposeClient
in interface IClient
public void tellEngagement(MasterHex hex, Legion attacker, Legion defender)
tellEngagement
in interface IClient
public void tellEngagementResults(Legion winner, java.lang.String method, int points, int turns)
tellEngagementResults
in interface IClient
public void tellWhatsHappening(java.lang.String message)
tellWhatsHappening
in interface IClient
public void tellMovementRoll(int roll)
tellMovementRoll
in interface IClient
public void syncOption(java.lang.String optname, java.lang.String value)
syncOption
in interface IClient
public void updatePlayerInfo(java.util.List<java.lang.String> infoStrings)
updatePlayerInfo
in interface IClient
public void setColor(PlayerColor color)
public void updateCreatureCount(CreatureType type, int count, int deadCount)
updateCreatureCount
in interface IClient
public void removeLegion(Legion legion)
removeLegion
in interface IClient
public void setLegionStatus(Legion legion, boolean moved, boolean teleported, EntrySide entrySide, CreatureType lastRecruit)
setLegionStatus
in interface IClient
public void addCreature(Legion legion, CreatureType creature, java.lang.String reason)
addCreature
in interface IClient
public void removeCreature(Legion legion, CreatureType creature, java.lang.String reason)
removeCreature
in interface IClient
public void revealCreatures(Legion legion, java.util.List<CreatureType> creatures, java.lang.String reason)
revealCreatures
in interface IClient
public void revealEngagedCreatures(Legion legion, java.util.List<CreatureType> creatures, boolean isAttacker, java.lang.String reason)
revealEngagedCreatures
in interface IClient
markerId
- legion marker name that is currently in battlecreatures
- List of creatures in this legionisAttacker
- true for attacker, false for defenderreason
- why this was revealedpublic void removeDeadBattleChits()
removeDeadBattleChits
in interface IClient
public void placeNewChit(java.lang.String imageName, boolean inverted, int tag, BattleHex hex)
placeNewChit
in interface IClient
public void tellReplay(boolean val, int maxTurn)
tellReplay
in interface IClient
public void setPlayerName(java.lang.String playerName)
setPlayerName
in interface IClient
public java.lang.String getSignonName()
public java.lang.String getPlayerName()
public void createSummonAngel(Legion legion)
createSummonAngel
in interface IClient
public void askAcquireAngel(Legion legion, java.util.List<CreatureType> recruits)
askAcquireAngel
in interface IClient
public void askChooseStrikePenalty(java.util.List<java.lang.String> choices)
askChooseStrikePenalty
in interface IClient
public void tellGameOver(java.lang.String message, boolean disposeFollows)
tellGameOver
in interface IClient
public void tellPlayerElim(Player player, Player slayer)
tellPlayerElim
in interface IClient
public void askConcede(Legion ally, Legion enemy)
askConcede
in interface IClient
public void askNegotiate(Legion attacker, Legion defender)
askNegotiate
in interface IClient
public void tellProposal(java.lang.String proposalString)
tellProposal
in interface IClient
public void tellSlowResults(int targetTag, int slowValue)
tellSlowResults
in interface IClient
public void tellStrikeResults(int strikerTag, int targetTag, int strikeNumber, java.util.List<java.lang.String> rolls, int damage, boolean killed, boolean wasCarry, int carryDamageLeft, java.util.Set<java.lang.String> carryTargetDescriptions)
tellStrikeResults
in interface IClient
public void initBattle(MasterHex hex, int battleTurnNumber, Player battleActivePlayer, BattlePhase battlePhase, Legion attacker, Legion defender)
initBattle
in interface IClient
public void cleanupBattle()
cleanupBattle
in interface IClient
public void nextEngagement()
nextEngagement
in interface IClient
public void doReinforce(Legion legion)
doReinforce
in interface IClient
public void didRecruit(Legion legion, CreatureType recruit, CreatureType recruiter, int numRecruiters)
didRecruit
in interface IClient
public void undidRecruit(Legion legion, CreatureType recruit)
undidRecruit
in interface IClient
public void setupTurnState(Player activePlayer, int turnNumber)
setupTurnState
in interface IClient
public void setupSplit(Player activePlayer, int turnNumber)
setupSplit
in interface IClient
public void setupFight()
setupFight
in interface IClient
public void setupMuster()
setupMuster
in interface IClient
public void setupBattleSummon(Player battleActivePlayer, int battleTurnNumber)
setupBattleSummon
in interface IClient
public void setupBattleRecruit(Player battleActivePlayer, int battleTurnNumber)
setupBattleRecruit
in interface IClient
public void setupBattleMove(Player battleActivePlayer, int battleTurnNumber)
setupBattleMove
in interface IClient
public void setupBattleFight(BattlePhase battlePhase, Player battleActivePlayer)
setupBattleFight
in interface IClient
public void tellLegionLocation(Legion legion, MasterHex hex)
tellLegionLocation
in interface IClient
public void tellBattleMove(int tag, BattleHex startingHex, BattleHex endingHex, boolean undo)
tellBattleMove
in interface IClient
public void didMove(Legion legion, MasterHex startingHex, MasterHex currentHex, EntrySide entrySide, boolean teleport, CreatureType teleportingLord, boolean splitLegionHasForcedMove)
public void undidMove(Legion legion, MasterHex formerHex, MasterHex currentHex, boolean splitLegionHasForcedMove)
public void didSummon(Legion summoner, Legion donor, CreatureType summon)
public void undidSplit(Legion splitoff, Legion survivor, int turn)
undidSplit
in interface IClient
public void didSplit(MasterHex hex, Legion parent, Legion child, int childHeight, java.util.List<CreatureType> splitoffs, int turn)
public void askPickColor(java.util.List<PlayerColor> colorsLeft)
askPickColor
in interface IClient
public void askPickFirstMarker()
askPickFirstMarker
in interface IClient
public void nak(java.lang.String reason, java.lang.String errmsg)
public void setBoardActive(boolean val)
setBoardActive
in interface IClient
public void tellInitialGameInfo(java.lang.String variantName, java.util.Collection<java.lang.String> playerNames)
public void confirmWhenCaughtUp()
confirmWhenCaughtUp
in interface IClient
public void serverConfirmsConnection()
serverConfirmsConnection
in interface IClient
public void pingRequest()
pingRequest
in interface IClient
public void messageFromServer(java.lang.String message)
messageFromServer
in interface IClient
public void appendToConnectionLog(java.lang.String message)
appendToConnectionLog
in interface IClient
public void tellSyncCompleted(int syncRequestNumber)
tellSyncCompleted
in interface IClient
public void declareObsolete()
public void fakeDisconnectClient()
public void clearDisconnectClient()
public boolean wasFakeDisconnectFlagSet()