Class ClientHandler
java.lang.Object
net.sf.colossus.server.ClientHandlerStub
net.sf.colossus.server.ClientHandler
- All Implemented Interfaces:
IClient
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).
- Author:
- David Ripton
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) ByteBufferprivate intprivate final Charsetprivate final Stringprivate intprivate intprivate final CharsetDecoderprivate static final Stringprivate boolean(package private) Stringprivate final CharsetEncoderbooleanDebug stuff, only for testing/development purposesprivate Stringprivate Stringprivate static final Loggerprivate static final intprivate intprivate boolean(package private) int(package private) LinkedList<String> The queue in which messages are stored, until they were really written.private final SelectionKey(package private) intprivate final SocketChannelprivate booleanprivate booleanprivate longprivate boolean(package private) intFields inherited from class ClientHandlerStub
counter, isCommitPoint, isGone, messageCounter, playerName, redoQueue, sep, server, signonName -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidprivate voidcallMethod(String method, List<String> args) This is the longish if-elseif-else block which deserialized all client-to-server calls back from String to actual methodCalls.booleanbooleanprotected booleanprotected booleanvoidvoidvoidcloneRedoQueue(ClientHandler oldCH) protected voidprivate voidconfirmCommitPoint(int confirmedNr) Remove the messages in redoQueue prior to given commit pointvoidbooleanvoidServer side disposes a client (and informs it about it first) To be used only for "disposeAllClients()", otherwise setIsGone reason is misleading.private voiddoCallMethodInTryBlock(String line, String method, List<String> li) protected voidenqueueToRedoQueue(int messageNr, String message) voidprotected voidSelector reported that client became writable again (after a prior write attempt had not written all bytes).private voidhandleEncoding(String msg) longvoidbooleanisGone()booleanprotected booleanisStub()booleanbooleanvoidprocessInput(ByteBuffer byteBuffer) private voidprivate BattleHexresolveBattleHex(String hexLabel) private CreatureTyperesolveCreatureType(String name) private CreatureTypeThere 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 LegionresolveLegion(String markerId) private MasterHexresolveMasterHex(String hexLabel) protected voidsendToClient(String message) private voidsendViaChannel(String msg) private voidsendViaChannelRaw(String msg) voidprivate voidbooleanvoidsyncAfterReconnect(int lastReceivedMessageNr, int syncRequestNumber) Re-send all data after the message from which we know client got itbooleanprivate voidwithdrawIfNeeded(boolean explicit) Make sure player is withdrawn from game.Methods inherited from class ClientHandlerStub
addCreature, appendToConnectionLog, askAcquireAngel, askChooseStrikePenalty, askConcede, askFlee, askNegotiate, askPickColor, askPickFirstMarker, cleanupBattle, confirmWhenCaughtUp, createSummonAngel, didMove, didRecruit, didSplit, didSummon, doReinforce, getClientName, getPlayerName, getSignonName, initBattle, initBoard, kickPhase, log, messageFromServer, nak, nextEngagement, pingRequest, placeNewChit, removeCreature, removeDeadBattleChits, removeLegion, revealCreatures, revealEngagedCreatures, serverConfirmsConnection, setBoardActive, setColor, setIsGone, setLegionStatus, setPlayerName, setupBattleFight, setupBattleMove, setupBattleRecruit, setupBattleSummon, setupFight, setupMove, setupMuster, setupSplit, setupTurnState, syncOption, tellBattleMove, tellEngagement, tellEngagementResults, tellGameOver, tellInitialGameInfo, tellLegionLocation, tellMovementRoll, tellPlayerElim, tellProposal, tellRedo, tellReplay, tellSlowResults, tellStrikeResults, tellSyncCompleted, tellWhatsHappening, undidMove, undidRecruit, undidSplit, updateCreatureCount, updateOnePlayersInfo, updatePlayerInfoMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface IClient
addCreature, appendToConnectionLog, askAcquireAngel, askChooseStrikePenalty, askConcede, askFlee, askNegotiate, askPickColor, askPickFirstMarker, cleanupBattle, confirmWhenCaughtUp, createSummonAngel, didMove, didRecruit, didSplit, didSummon, doReinforce, initBattle, initBoard, kickPhase, log, messageFromServer, nak, nextEngagement, pingRequest, placeNewChit, removeCreature, removeDeadBattleChits, removeLegion, revealCreatures, revealEngagedCreatures, serverConfirmsConnection, setBoardActive, setColor, setLegionStatus, setPlayerName, setupBattleFight, setupBattleMove, setupBattleRecruit, setupBattleSummon, setupFight, setupMove, setupMuster, setupSplit, setupTurnState, syncOption, tellBattleMove, tellEngagement, tellEngagementResults, tellGameOver, tellLegionLocation, tellMovementRoll, tellPlayerElim, tellProposal, tellRedo, tellReplay, tellSlowResults, tellStrikeResults, tellSyncCompleted, tellWhatsHappening, undidMove, undidRecruit, undidSplit, updateCreatureCount, updateOnePlayersInfo, updatePlayerInfo
-
Field Details
-
LOGGER
-
socketChannel
-
selectorKey
-
clientVersion
private int clientVersion -
spectator
private boolean spectator -
didExplicitDisconnect
private boolean didExplicitDisconnect -
withdrawnAlready
private boolean withdrawnAlready -
cantSendMessageRepeated
private int cantSendMessageRepeated -
temporarilyDisconnected
private boolean temporarilyDisconnected -
obsolete
private boolean obsolete -
incompleteInput
-
incompleteText
-
DEFAULT_CHAR_SET
-
CHARSET_NAME
-
charset
-
encoder
-
decoder
-
commitPointCounter
private int commitPointCounter -
MAX_KEEP_LINES
private static final int MAX_KEEP_LINES- See Also:
-
recentlyProcessedLines
-
newCounter
private int newCounter -
bb
ByteBuffer bb -
encodedMsg
String encodedMsg -
should
int should -
writtenTotal
int writtenTotal -
previousRetries
int previousRetries -
temporarilyInTrouble
private long temporarilyInTrouble -
queue
LinkedList<String> queueThe queue in which messages are stored, until they were really written. Usually empty; stuff piles up only when writing to socket fails, e.g. network or client too slow. -
fakeDisconnect
public boolean fakeDisconnectDebug stuff, only for testing/development purposes
-
-
Constructor Details
-
ClientHandler
ClientHandler(Server server, SocketChannel channel, SelectionKey selKey)
-
-
Method Details
-
getSelectorKey
-
getSocketChannel
-
isGone
public boolean isGone() -
isStub
protected boolean isStub()- Overrides:
isStubin classClientHandlerStub
-
isSpectator
public boolean isSpectator() -
didExplicitDisconnect
public boolean didExplicitDisconnect() -
setTemporarilyDisconnected
public void setTemporarilyDisconnected() -
isTemporarilyDisconnected
public boolean isTemporarilyDisconnected() -
canHandlePingRequest
protected boolean canHandlePingRequest()- Overrides:
canHandlePingRequestin classClientHandlerStub
-
canHandleNewVariantXML
protected boolean canHandleNewVariantXML() -
disposeClient
public void disposeClient()Server side disposes a client (and informs it about it first) To be used only for "disposeAllClients()", otherwise setIsGone reason is misleading.- Specified by:
disposeClientin interfaceIClient- Overrides:
disposeClientin classClientHandlerStub
-
processInput
-
sendViaChannel
-
flushQueuedContent
protected void flushQueuedContent()Description copied from class:ClientHandlerStubSelector reported that client became writable again (after a prior write attempt had not written all bytes). Now start/try writing the message(s) which are still in the queue.- Overrides:
flushQueuedContentin classClientHandlerStub
-
enqueueToRedoQueue
- Overrides:
enqueueToRedoQueuein classClientHandlerStub
-
commitPoint
protected void commitPoint()- Overrides:
commitPointin classClientHandlerStub
-
confirmCommitPoint
private void confirmCommitPoint(int confirmedNr) Remove the messages in redoQueue prior to given commit point- Parameters:
confirmedNr- Commit point from which we now know that client has successfully received it
-
supportsReconnect
public boolean supportsReconnect()- Overrides:
supportsReconnectin classClientHandlerStub
-
canHandleBattleMoveNak
public boolean canHandleBattleMoveNak() -
canHandleAdvancedSync
public boolean canHandleAdvancedSync()- Overrides:
canHandleAdvancedSyncin classClientHandlerStub
-
cloneRedoQueue
-
initRedoQueueFromStub
-
reEnqueue
-
syncAfterReconnect
public void syncAfterReconnect(int lastReceivedMessageNr, int syncRequestNumber) Re-send all data after the message from which we know client got it- Parameters:
lastReceivedMessageNr- Last message which client did still receivesyncRequestNumber- Every request has own unique id, so we don't mix them
-
isTemporarilyInTrouble
public boolean isTemporarilyInTrouble() -
howLongAlreadyInTrouble
public long howLongAlreadyInTrouble() -
setTemporarilyInTrouble
private void setTemporarilyInTrouble() -
clearTemporarilyInTrouble
public void clearTemporarilyInTrouble() -
handleEncoding
-
sendViaChannelRaw
-
attemptWritingToChannel
private void attemptWritingToChannel() -
withdrawIfNeeded
private void withdrawIfNeeded(boolean explicit) Make sure player is withdrawn from game. Explicit if via Withdraw message from client, implicit because of disconnect message or connection problems. This is just a wrapper for the both situations where for !withdrawnAlready should be checked- Parameters:
explicit- Whether client has requested withdraw explicitly
-
declareObsolete
public void declareObsolete() -
dumpLastProcessedLines
-
doCallMethodInTryBlock
-
callMethod
-
resolveBattleHex
-
resolveCreatureType
-
resolveCreatureTypeNullOk
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. TODO What to do with the "Anything"?- Parameters:
name- Name of the creatureType to find, might be "null"- Returns:
- CreatureType for that name, or null if name is "null"
-
resolveMasterHex
-
resolveLegion
-
sendToClient
- Overrides:
sendToClientin classClientHandlerStub
-
fakeDisconnectClient
public void fakeDisconnectClient() -
clearDisconnectClient
public void clearDisconnectClient() -
wasFakeDisconnectFlagSet
public boolean wasFakeDisconnectFlagSet()
-