|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.colossus.server.ClientHandler
final class ClientHandler
Holds all data specific to one client connection. (Earlier this was the class ServerSocketThread, but since changing to NIO it's not an own thread any more.) The code in here is (should be) executed exclusively by the server thread as reaction to something happening on the selector - first the client connection being accepted, and then later always when data from client was received (usually from THIS client, but there might be other cases).
Field Summary | |
---|---|
(package private) java.nio.ByteBuffer |
bb
|
private java.nio.charset.Charset |
charset
|
private java.lang.String |
CHARSET_NAME
|
private int |
clientVersion
|
private static int |
counter
|
private java.nio.charset.CharsetDecoder |
decoder
|
private static java.lang.String |
DEFAULT_CHAR_SET
|
(package private) java.lang.String |
encodedMsg
|
private java.nio.charset.CharsetEncoder |
encoder
|
private java.lang.String |
incompleteInput
|
private java.lang.String |
incompleteText
|
private boolean |
isGone
|
private int |
isGoneMessageRepeated
|
private static java.util.logging.Logger |
LOGGER
|
private java.lang.String |
playerName
|
(package private) int |
previousRetries
|
(package private) java.util.LinkedList<java.lang.String> |
queue
|
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 long |
temporarilyInTrouble
|
private boolean |
withdrawnAlready
|
(package private) int |
writtenTotal
|
Constructor Summary | |
---|---|
ClientHandler(Server server,
java.nio.channels.SocketChannel channel,
java.nio.channels.SelectionKey selKey)
|
Method Summary | |
---|---|
void |
addCreature(Legion legion,
CreatureType creature,
java.lang.String reason)
|
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)
|
void |
cleanupBattle()
|
void |
clearTemporarilyInTrouble()
|
void |
confirmWhenCaughtUp()
|
void |
createSummonAngel(Legion legion)
|
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 |
dispose()
Server side disposes a client (and informs it about it first) |
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 |
getPlayerName()
|
java.nio.channels.SelectionKey |
getSelectorKey()
|
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 |
isTemporarilyInTrouble()
|
void |
kickPhase()
|
void |
log(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(boolean val)
|
void |
setLegionStatus(Legion legion,
boolean moved,
boolean teleported,
EntrySide entrySide,
CreatureType lastRecruit)
|
void |
setPlayerName(java.lang.String playerName)
|
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)
|
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 |
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)
|
private void |
withdrawIfNeeded(boolean explicit)
Make sure player is withdrawn from game. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
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 withdrawnAlready
private int isGoneMessageRepeated
private static final java.lang.String sep
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
java.nio.ByteBuffer bb
java.lang.String encodedMsg
int should
int writtenTotal
int previousRetries
private long temporarilyInTrouble
java.util.LinkedList<java.lang.String> queue
Constructor Detail |
---|
ClientHandler(Server server, java.nio.channels.SocketChannel channel, java.nio.channels.SelectionKey selKey)
Method Detail |
---|
public java.nio.channels.SelectionKey getSelectorKey()
public java.nio.channels.SocketChannel getSocketChannel()
public boolean isGone()
public void setIsGone(boolean val)
public void processInput(java.nio.ByteBuffer byteBuffer)
private void sendViaChannel(java.lang.String msg)
public 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)
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 dispose()
dispose
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)
setColor
in interface IClient
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 tellRedo(boolean val)
tellRedo
in interface IClient
public void initBoard()
initBoard
in interface IClient
public void setPlayerName(java.lang.String playerName)
setPlayerName
in interface IClient
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 askFlee(Legion ally, Legion enemy)
askFlee
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 setupMove()
setupMove
in interface IClient
public void setupFight()
setupFight
in interface IClient
public void setupMuster()
setupMuster
in interface IClient
public void kickPhase()
kickPhase
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)
didMove
in interface IClient
public void undidMove(Legion legion, MasterHex formerHex, MasterHex currentHex, boolean splitLegionHasForcedMove)
undidMove
in interface IClient
public void didSummon(Legion summoner, Legion donor, CreatureType summon)
didSummon
in interface IClient
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)
didSplit
in interface IClient
public void askPickColor(java.util.List<PlayerColor> colorsLeft)
askPickColor
in interface IClient
public void askPickFirstMarker()
askPickFirstMarker
in interface IClient
public void log(java.lang.String message)
log
in interface IClient
public void nak(java.lang.String reason, java.lang.String errmsg)
nak
in interface IClient
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
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |