Package net.sf.colossus.client
Class SocketClientThread
java.lang.Object
java.lang.Thread
net.sf.colossus.client.SocketClientThread
- All Implemented Interfaces:
Runnable
,IServerConnection
,IServer
Thread to handle server connection on client side.
- Author:
- David Ripton
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private ClientThread
private ClientThread
private boolean
private String
Those are stored at the moment only to be able to reconnectprivate BufferedReader
private String
private final boolean
private boolean
private final Object
private static final Logger
private PrintWriter
private int
private String
private int
private Collection<String>
private String
private boolean
private boolean
private static final String
private boolean
private Socket
private boolean
private String
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
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
ConstructorsConstructorDescriptionSocketClientThread
(String host, int port, String initialName, boolean isRemote, boolean spectator) -
Method Summary
Modifier and TypeMethodDescriptionint
void
acquireAngel
(Legion legion, CreatureType angelType) void
void
applyCarries
(BattleHex hex) void
assignColor
(PlayerColor color) void
assignFirstMarker
(String markerId) void
assignStrikePenalty
(String prompt) private void
callMethod
(String method, List<String> args) void
private void
void
void
static SocketClientThread
createConnection
(String host, int port, String initialName, boolean remote, boolean spectator) void
doBattleMove
(int tag, BattleHex hex) void
doMove
(Legion legion, MasterHex hex, EntrySide entrySide, boolean teleport, CreatureType teleportingLord) void
void
void
void
void
void
void
doNotConcede
(Legion legion) void
void
doRecruit
(Recruitment event) void
doSplit
(Legion parent, String childMarker, List<CreatureType> creaturesToSplit) Executes a split of certain creatures from a legion.void
Handles a summon eventvoid
void
void
void
int
private String
void
boolean
void
void
void
void
makeProposal
(String proposalString) void
mulligan()
void
newGame()
private void
private void
private String
protected static SocketClientThread
recreateConnection
(IServerConnection prevConnection) void
private void
void
requestSyncDelta
(int msgNr, int syncCounter) void
run()
void
void
private void
sendToServer
(String message) void
private void
setWaiting
(boolean val) private void
void
void
stopGame()
void
stopSocketClientThread
(boolean sendConnect) Client originates the dispose: If done because all is over, player chose close etc, send also a disconnect so that server knows client is "gone".void
void
undoBattleMove
(BattleHex hex) void
void
undoRecruit
(Legion legion) void
void
updatePlayerName
(String playerName) private String
private String
void
private String
void
void
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, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Field Details
-
LOGGER
-
clientThread
-
disposedClientThread
-
socket
-
in
-
out
-
goingDown
private boolean goingDown -
selfInterrupted
private boolean selfInterrupted -
serverReceiveTimedout
private boolean serverReceiveTimedout -
host
Those are stored at the moment only to be able to reconnect -
port
private int port -
playerName
-
remote
private boolean remote -
spectator
private boolean spectator -
internalSpectator
private final boolean internalSpectator -
sep
- See Also:
-
reasonFail
-
initialLine
-
variantNameForInit
-
preliminaryPlayerNames
-
isWaitingLock
-
isWaiting
private boolean isWaiting -
ownMessageCounter
private int ownMessageCounter -
abandoned
private boolean abandoned
-
-
Constructor Details
-
SocketClientThread
-
-
Method Details
-
createConnection
public static SocketClientThread createConnection(String host, int port, String initialName, boolean remote, boolean spectator) throws Client.ConnectionInitException - Throws:
Client.ConnectionInitException
-
recreateConnection
protected static SocketClientThread recreateConnection(IServerConnection prevConnection) throws Client.ConnectionInitException - Throws:
Client.ConnectionInitException
-
readOneLine
- Throws:
IOException
-
waitForPrompt
-
waitForSignonOk
- Throws:
IOException
-
waitForGameInfo
- Throws:
IOException
-
getReasonFail
- Specified by:
getReasonFail
in interfaceIServerConnection
-
appendToConnectionLog
-
getVariantNameForInit
- Specified by:
getVariantNameForInit
in interfaceIServerConnection
-
getPreliminaryPlayerNames
- Specified by:
getPreliminaryPlayerNames
in interfaceIServerConnection
-
getIServer
- Specified by:
getIServer
in interfaceIServerConnection
-
setClient
- Specified by:
setClient
in interfaceIServerConnection
-
getDisposedQueueLen
public int getDisposedQueueLen()- Specified by:
getDisposedQueueLen
in interfaceIServerConnection
-
startThread
public void startThread()- Specified by:
startThread
in interfaceIServerConnection
-
run
public void run() -
readAndParseUntilDone
private void readAndParseUntilDone() -
setWaiting
private void setWaiting(boolean val) -
waitForLine
-
isAlreadyDown
public boolean isAlreadyDown()- Specified by:
isAlreadyDown
in interfaceIServerConnection
-
cleanupSocket
private void cleanupSocket() -
interrupt
public void interrupt() -
stopSocketClientThread
public void stopSocketClientThread(boolean sendConnect) Client originates the dispose: If done because all is over, player chose close etc, send also a disconnect so that server knows client is "gone". If done because of actually or suspected "connection dead/problems", just shut down the SCT peacefully, do not inform server, client might want to reconnect later with a new SCT / ClientThread pair.- Specified by:
stopSocketClientThread
in interfaceIServerConnection
- Parameters:
sendConnect
- If true, sends a disconnect message to server
-
abandonAndGetMessageCounter
public int abandonAndGetMessageCounter()- Specified by:
abandonAndGetMessageCounter
in interfaceIServerConnection
-
parseLine
-
callMethod
-
getPrintName
-
sendToServer
-
signOn
-
requestGameInfo
private void requestGameInfo() -
updatePlayerName
- Specified by:
updatePlayerName
in interfaceIServerConnection
-
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
-
acquireAngel
- Specified by:
acquireAngel
in interfaceIServer
-
doSummon
Description copied from interface:IServer
Handles a summon event -
doRecruit
-
engage
-
concede
-
doNotConcede
- Specified by:
doNotConcede
in interfaceIServer
-
flee
-
doNotFlee
-
makeProposal
- Specified by:
makeProposal
in interfaceIServer
-
fight
-
doBattleMove
- Specified by:
doBattleMove
in interfaceIServer
-
strike
-
applyCarries
- Specified by:
applyCarries
in interfaceIServer
-
undoBattleMove
- Specified by:
undoBattleMove
in interfaceIServer
-
assignStrikePenalty
- Specified by:
assignStrikePenalty
in interfaceIServer
-
mulligan
public void mulligan() -
undoSplit
-
undoMove
-
undoRecruit
- 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
-
withdrawFromGame
public void withdrawFromGame()- Specified by:
withdrawFromGame
in interfaceIServer
-
sendDisconnect
public void sendDisconnect()- Specified by:
sendDisconnect
in interfaceIServer
-
stopGame
public void stopGame() -
doSplit
Description copied from interface:IServer
Executes a split of certain creatures from a legion. -
doMove
public void doMove(Legion legion, MasterHex hex, EntrySide entrySide, boolean teleport, CreatureType teleportingLord) -
assignColor
- Specified by:
assignColor
in interfaceIServer
-
assignFirstMarker
- Specified by:
assignFirstMarker
in interfaceIServer
-
newGame
public void newGame() -
loadGame
-
saveGame
-
checkServerConnection
public void checkServerConnection()- Specified by:
checkServerConnection
in interfaceIServer
-
clientConfirmedCatchup
public void clientConfirmedCatchup()- Specified by:
clientConfirmedCatchup
in interfaceIServer
-
joinGame
-
watchGame
public void watchGame() -
requestSyncDelta
public void requestSyncDelta(int msgNr, int syncCounter) - Specified by:
requestSyncDelta
in interfaceIServerConnection
-
replyToPing
public void replyToPing() -
enforcedConnectionException
public void enforcedConnectionException()- Specified by:
enforcedConnectionException
in interfaceIServerConnection
-