net.sf.colossus.client
Class SocketClientThread
java.lang.Object
java.lang.Thread
net.sf.colossus.client.SocketClientThread
- All Implemented Interfaces:
- java.lang.Runnable, IServerConnection, IServer
final class SocketClientThread
- extends java.lang.Thread
- implements IServer, IServerConnection
Thread to handle server connection on client side.
- Author:
- David Ripton
Nested classes/interfaces inherited from class java.lang.Thread |
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary |
SocketClientThread(java.lang.String host,
int port,
java.lang.String initialName,
boolean isRemote)
|
Method Summary |
int |
abandonAndGetMessageCounter()
|
void |
acquireAngel(Legion legion,
CreatureType angelType)
|
void |
appendToConnectionLog(java.lang.String s)
|
void |
applyCarries(BattleHex hex)
|
void |
assignColor(PlayerColor color)
|
void |
assignFirstMarker(java.lang.String markerId)
|
void |
assignStrikePenalty(java.lang.String prompt)
|
private void |
callMethod(java.lang.String method,
java.util.List<java.lang.String> args)
|
void |
checkServerConnection()
|
private void |
cleanupSocket()
|
void |
clientConfirmedCatchup()
|
void |
concede(Legion legion)
|
static SocketClientThread |
createConnection(java.lang.String host,
int port,
java.lang.String playerName,
boolean remote)
|
void |
doBattleMove(int tag,
BattleHex hex)
|
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)
|
void |
doSplit(Legion parent,
java.lang.String childMarker,
java.util.List<CreatureType> creaturesToSplit)
Executes a split of certain creatures from a legion. |
void |
doSummon(Summoning event)
Handles a summon event |
void |
enforcedConnectionException()
|
void |
engage(MasterHex hex)
|
void |
fight(MasterHex hex)
|
void |
flee(Legion legion)
|
int |
getDisposedQueueLen()
|
IServer |
getIServer()
|
private java.lang.String |
getNameMaybe()
|
java.util.Collection<java.lang.String> |
getPreliminaryPlayerNames()
|
java.lang.String |
getReasonFail()
|
java.lang.String |
getVariantNameForInit()
|
void |
interrupt()
|
boolean |
isAlreadyDown()
|
void |
joinGame(java.lang.String playerName)
|
void |
leaveCarryMode()
|
void |
loadGame(java.lang.String filename)
|
void |
makeProposal(java.lang.String proposalString)
|
void |
mulligan()
|
void |
newGame()
|
private void |
parseLine(java.lang.String s)
|
private void |
readAndParseUntilDone()
|
protected static SocketClientThread |
recreateConnection(IServerConnection prevConnection)
|
void |
replyToPing()
|
private void |
requestGameInfo()
|
void |
requestSyncDelta(int msgNr,
int syncCounter)
|
void |
run()
|
void |
saveGame(java.lang.String filename)
|
void |
sendDisconnect()
|
private void |
sendToServer(java.lang.String message)
|
void |
setClient(Client client)
|
private void |
setWaiting(boolean val)
|
private void |
signOn(java.lang.String loginName,
boolean isRemote,
int version,
java.lang.String buildInfo)
|
void |
startThread()
|
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 |
strike(int tag,
BattleHex hex)
|
void |
undoBattleMove(BattleHex hex)
|
void |
undoMove(Legion legion)
|
void |
undoRecruit(Legion legion)
|
void |
undoSplit(Legion splitoff)
|
void |
updateThreadName(java.lang.String playerName)
Set the thread name to playerName |
private java.lang.String |
waitForLine()
|
void |
waitForPrompt()
|
void |
withdrawFromGame()
|
Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
LOGGER
private static final java.util.logging.Logger LOGGER
clientThread
private ClientThread clientThread
disposedClientThread
private ClientThread disposedClientThread
socket
private java.net.Socket socket
in
private java.io.BufferedReader in
out
private java.io.PrintWriter out
goingDown
private boolean goingDown
selfInterrupted
private boolean selfInterrupted
serverReceiveTimedout
private boolean serverReceiveTimedout
host
private java.lang.String host
- Those are stored at the moment only to be able to reconnect
port
private int port
playerName
private java.lang.String playerName
remote
private boolean remote
sep
private static final java.lang.String sep
- See Also:
- Constant Field Values
reasonFail
private java.lang.String reasonFail
initialLine
private java.lang.String initialLine
variantNameForInit
private java.lang.String variantNameForInit
preliminaryPlayerNames
private java.util.Collection<java.lang.String> preliminaryPlayerNames
isWaitingLock
private final java.lang.Object isWaitingLock
isWaiting
private boolean isWaiting
ownMessageCounter
private int ownMessageCounter
abandoned
private boolean abandoned
SocketClientThread
SocketClientThread(java.lang.String host,
int port,
java.lang.String initialName,
boolean isRemote)
createConnection
public static SocketClientThread createConnection(java.lang.String host,
int port,
java.lang.String playerName,
boolean remote)
throws Client.ConnectionInitException
- Throws:
Client.ConnectionInitException
recreateConnection
protected static SocketClientThread recreateConnection(IServerConnection prevConnection)
throws Client.ConnectionInitException
- Throws:
Client.ConnectionInitException
waitForPrompt
public void waitForPrompt()
throws java.net.SocketTimeoutException,
java.net.SocketException,
java.io.IOException
- Throws:
java.net.SocketTimeoutException
java.net.SocketException
java.io.IOException
getReasonFail
public java.lang.String getReasonFail()
- Specified by:
getReasonFail
in interface IServerConnection
appendToConnectionLog
public void appendToConnectionLog(java.lang.String s)
getVariantNameForInit
public java.lang.String getVariantNameForInit()
- Specified by:
getVariantNameForInit
in interface IServerConnection
getPreliminaryPlayerNames
public java.util.Collection<java.lang.String> getPreliminaryPlayerNames()
- Specified by:
getPreliminaryPlayerNames
in interface IServerConnection
getIServer
public IServer getIServer()
- Specified by:
getIServer
in interface IServerConnection
setClient
public void setClient(Client client)
- Specified by:
setClient
in interface IServerConnection
getDisposedQueueLen
public int getDisposedQueueLen()
- Specified by:
getDisposedQueueLen
in interface IServerConnection
startThread
public void startThread()
- Specified by:
startThread
in interface IServerConnection
run
public void run()
- Specified by:
run
in interface java.lang.Runnable
- Overrides:
run
in class java.lang.Thread
readAndParseUntilDone
private void readAndParseUntilDone()
setWaiting
private void setWaiting(boolean val)
waitForLine
private java.lang.String waitForLine()
isAlreadyDown
public boolean isAlreadyDown()
- Specified by:
isAlreadyDown
in interface IServerConnection
cleanupSocket
private void cleanupSocket()
interrupt
public void interrupt()
- Overrides:
interrupt
in class java.lang.Thread
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 interface IServerConnection
- Parameters:
sendConnect
- If true, sends a disconnect message to server
abandonAndGetMessageCounter
public int abandonAndGetMessageCounter()
- Specified by:
abandonAndGetMessageCounter
in interface IServerConnection
parseLine
private void parseLine(java.lang.String s)
callMethod
private void callMethod(java.lang.String method,
java.util.List<java.lang.String> args)
getNameMaybe
private java.lang.String getNameMaybe()
sendToServer
private void sendToServer(java.lang.String message)
signOn
private void signOn(java.lang.String loginName,
boolean isRemote,
int version,
java.lang.String buildInfo)
requestGameInfo
private void requestGameInfo()
updateThreadName
public void updateThreadName(java.lang.String playerName)
- Set the thread name to playerName
- Specified by:
updateThreadName
in interface IServerConnection
leaveCarryMode
public void leaveCarryMode()
- Specified by:
leaveCarryMode
in interface IServer
doneWithBattleMoves
public void doneWithBattleMoves()
- Specified by:
doneWithBattleMoves
in interface IServer
doneWithStrikes
public void doneWithStrikes()
- Specified by:
doneWithStrikes
in interface IServer
acquireAngel
public void acquireAngel(Legion legion,
CreatureType angelType)
- Specified by:
acquireAngel
in interface IServer
doSummon
public void doSummon(Summoning event)
- Description copied from interface:
IServer
- Handles a summon event
- Specified by:
doSummon
in interface IServer
- Parameters:
event
- The summon event or null if summoning is not wanted.
doRecruit
public void doRecruit(Recruitment event)
- Specified by:
doRecruit
in interface IServer
engage
public void engage(MasterHex hex)
- Specified by:
engage
in interface IServer
concede
public void concede(Legion legion)
- Specified by:
concede
in interface IServer
doNotConcede
public void doNotConcede(Legion legion)
- Specified by:
doNotConcede
in interface IServer
flee
public void flee(Legion legion)
- Specified by:
flee
in interface IServer
doNotFlee
public void doNotFlee(Legion legion)
- Specified by:
doNotFlee
in interface IServer
makeProposal
public void makeProposal(java.lang.String proposalString)
- Specified by:
makeProposal
in interface IServer
fight
public void fight(MasterHex hex)
- Specified by:
fight
in interface IServer
doBattleMove
public void doBattleMove(int tag,
BattleHex hex)
- Specified by:
doBattleMove
in interface IServer
strike
public void strike(int tag,
BattleHex hex)
- Specified by:
strike
in interface IServer
applyCarries
public void applyCarries(BattleHex hex)
- Specified by:
applyCarries
in interface IServer
undoBattleMove
public void undoBattleMove(BattleHex hex)
- Specified by:
undoBattleMove
in interface IServer
assignStrikePenalty
public void assignStrikePenalty(java.lang.String prompt)
- Specified by:
assignStrikePenalty
in interface IServer
mulligan
public void mulligan()
- Specified by:
mulligan
in interface IServer
undoSplit
public void undoSplit(Legion splitoff)
- Specified by:
undoSplit
in interface IServer
undoMove
public void undoMove(Legion legion)
- Specified by:
undoMove
in interface IServer
undoRecruit
public void undoRecruit(Legion legion)
- Specified by:
undoRecruit
in interface IServer
doneWithSplits
public void doneWithSplits()
- Specified by:
doneWithSplits
in interface IServer
doneWithMoves
public void doneWithMoves()
- Specified by:
doneWithMoves
in interface IServer
doneWithEngagements
public void doneWithEngagements()
- Specified by:
doneWithEngagements
in interface IServer
doneWithRecruits
public void doneWithRecruits()
- Specified by:
doneWithRecruits
in interface IServer
withdrawFromGame
public void withdrawFromGame()
- Specified by:
withdrawFromGame
in interface IServer
sendDisconnect
public void sendDisconnect()
- Specified by:
sendDisconnect
in interface IServer
stopGame
public void stopGame()
- Specified by:
stopGame
in interface IServer
doSplit
public void doSplit(Legion parent,
java.lang.String childMarker,
java.util.List<CreatureType> creaturesToSplit)
- Description copied from interface:
IServer
- Executes a split of certain creatures from a legion.
- Specified by:
doSplit
in interface IServer
- Parameters:
parent
- The legion to split the creatures out of.childMarker
- A marker for the new legion.creaturesToSplit
- The creatures to split out.
doMove
public void doMove(Legion legion,
MasterHex hex,
EntrySide entrySide,
boolean teleport,
CreatureType teleportingLord)
- Specified by:
doMove
in interface IServer
assignColor
public void assignColor(PlayerColor color)
- Specified by:
assignColor
in interface IServer
assignFirstMarker
public void assignFirstMarker(java.lang.String markerId)
- Specified by:
assignFirstMarker
in interface IServer
newGame
public void newGame()
- Specified by:
newGame
in interface IServer
loadGame
public void loadGame(java.lang.String filename)
- Specified by:
loadGame
in interface IServer
saveGame
public void saveGame(java.lang.String filename)
- Specified by:
saveGame
in interface IServer
checkServerConnection
public void checkServerConnection()
- Specified by:
checkServerConnection
in interface IServer
clientConfirmedCatchup
public void clientConfirmedCatchup()
- Specified by:
clientConfirmedCatchup
in interface IServer
joinGame
public void joinGame(java.lang.String playerName)
- Specified by:
joinGame
in interface IServer
requestSyncDelta
public void requestSyncDelta(int msgNr,
int syncCounter)
- Specified by:
requestSyncDelta
in interface IServerConnection
replyToPing
public void replyToPing()
enforcedConnectionException
public void enforcedConnectionException()
- Specified by:
enforcedConnectionException
in interface IServerConnection