Class 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
    • Field Detail

      • LOGGER

        private static final java.util.logging.Logger LOGGER
      • 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
      • spectator

        private boolean spectator
      • internalSpectator

        private final boolean internalSpectator
      • 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
    • Constructor Detail

      • SocketClientThread

        SocketClientThread​(java.lang.String host,
                           int port,
                           java.lang.String initialName,
                           boolean isRemote,
                           boolean spectator)
    • Method Detail

      • readOneLine

        private java.lang.String readOneLine()
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • waitForPrompt

        public void waitForPrompt()
                           throws java.net.SocketTimeoutException,
                                  java.net.SocketException,
                                  java.io.IOException
        Throws:
        java.net.SocketTimeoutException
        java.net.SocketException
        java.io.IOException
      • waitForSignonOk

        private java.lang.String waitForSignonOk()
                                          throws java.io.IOException
        Throws:
        java.io.IOException
      • waitForGameInfo

        private java.lang.String waitForGameInfo()
                                          throws java.io.IOException
        Throws:
        java.io.IOException
      • appendToConnectionLog

        public void appendToConnectionLog​(java.lang.String s)
      • 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()
      • 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
      • parseLine

        private void parseLine​(java.lang.String s)
      • callMethod

        private void callMethod​(java.lang.String method,
                                java.util.List<java.lang.String> args)
      • getPrintName

        private java.lang.String getPrintName()
      • sendToServer

        private void sendToServer​(java.lang.String message)
      • signOn

        private void signOn​(java.lang.String loginName,
                            boolean isRemote,
                            int version,
                            java.lang.String buildInfo,
                            boolean spectator)
      • requestGameInfo

        private void requestGameInfo()
      • 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.
      • flee

        public void flee​(Legion legion)
        Specified by:
        flee in interface IServer
      • makeProposal

        public void makeProposal​(java.lang.String proposalString)
        Specified by:
        makeProposal 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
      • 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.
      • 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
      • joinGame

        public void joinGame​(java.lang.String playerName)
        Specified by:
        joinGame in interface IServer
      • watchGame

        public void watchGame()
        Specified by:
        watchGame in interface IServer
      • replyToPing

        public void replyToPing()