Class WebServerClient

java.lang.Object
net.sf.colossus.webserver.WebServerClient
All Implemented Interfaces:
IWebClient

public class WebServerClient extends Object implements IWebClient
This class represents an actual WebServer client. Mostly it contains the client's state data (logged in, client version, user and user name, and such). It holds the reference to the actual socket thread that is waiting for input from client. This class here provides the parsing of commands coming from clients to convert them into actual calls to to on the server object, and it also provides the methods which the server calls on the client (=translates method calls into text to send them over the socket). TODO: The "parse messages" still contains some blocks and processing which should rather be in the actual socket thread object (during split into client and actual socket thread just copied the whole if-elseif-else block to here).
  • Field Details

    • LOGGER

      private static final Logger LOGGER
    • sep

      private static final String sep
      See Also:
    • cst

      private final WebServerClientSocketThread cst
      The client socket thread that handled the low-level connection stuff
    • server

      private WebServer server
      The web server object that is managing all WebServerClients
    • loggedIn

      private boolean loggedIn
      Whether or not this WebServerClient is at the moment logged in
    • clientVersion

      private int clientVersion
      Client side version
    • user

      private User user
      The user associated with this WebClient connection
    • unverifiedUsername

      private String unverifiedUsername
      During registration request and sending of confirmation code, we do not have a user yet. The parseLine sets then this variable according to the username argument which was send from client.
    • gameStartsNowSent

      private long gameStartsNowSent
      Time when last gameStartsNowSent was sent (in ms since epoch)
    • gameStartsSoonSent

      private long gameStartsSoonSent
      Time when last gameStartsSoonSent was sent (in ms since epoch)
  • Constructor Details

    • WebServerClient

      public WebServerClient(WebServer server, Socket socket)
  • Method Details

    • startThread

      public void startThread()
    • getWSCSThread

      public WebServerClientSocketThread getWSCSThread()
    • setClientVersion

      private void setClientVersion(int version)
    • getClientVersion

      public int getClientVersion()
      Specified by:
      getClientVersion in interface IWebClient
    • setUser

      private void setUser(User u)
    • getUser

      User getUser()
    • getUsername

      String getUsername()
    • setUnverifiedUsername

      public void setUnverifiedUsername(String name)
    • getUnverifiedUsername

      public String getUnverifiedUsername()
    • requestPingIfNeeded

      public void requestPingIfNeeded(long now)
    • requestPingNow

      public void requestPingNow()
    • setLoggedIn

      public void setLoggedIn(boolean val)
    • getLoggedIn

      public boolean getLoggedIn()
    • handleLogout

      public void handleLogout()
    • parseLine

      public boolean parseLine(String fromClient)
    • makeCaseMismatchWarning

      private List<String> makeCaseMismatchWarning(String name)
    • processChatLine

      public void processChatLine(String chatId, String sender, String message)
    • ensureNotAlreadyLoggedIn

      private String ensureNotAlreadyLoggedIn(String username, boolean force)
      if password is okay, check first whether same user is already logged in with another connection; if yes, when force is not set (1st try), send back the "already logged in"; reacting on that, client will prompt whether to force the old connection out, and if user answers yes, will send a 2nd login message, this time with force flag set.
    • systemMessage

      public void systemMessage(long now, String message)
      Specified by:
      systemMessage in interface IWebClient
    • sendToClient

      private void sendToClient(String s)
    • grantAdminStatus

      public void grantAdminStatus()
      Specified by:
      grantAdminStatus in interface IWebClient
    • didEnroll

      public void didEnroll(String gameId, String username)
      Specified by:
      didEnroll in interface IWebClient
    • didUnenroll

      public void didUnenroll(String gameId, String username)
      Specified by:
      didUnenroll in interface IWebClient
    • gameCancelled

      public void gameCancelled(String gameId, String byUser)
      Specified by:
      gameCancelled in interface IWebClient
    • userInfo

      public void userInfo(int loggedin, int enrolled, int playing, int dead, long ago, String text)
      Specified by:
      userInfo in interface IWebClient
    • gameInfo

      public void gameInfo(GameInfo gi)
      Specified by:
      gameInfo in interface IWebClient
    • gameStartsSoon

      public void gameStartsSoon(String gameId, String byUser)
      Specified by:
      gameStartsSoon in interface IWebClient
    • gameStartsNow

      public void gameStartsNow(String gameId, int port, String hostingHost)
      Specified by:
      gameStartsNow in interface IWebClient
    • chatDeliver

      public void chatDeliver(String chatId, long when, String sender, String message, boolean resent)
      Specified by:
      chatDeliver in interface IWebClient
    • deliverGeneralMessage

      public void deliverGeneralMessage(long when, boolean error, String title, String message)
      Specified by:
      deliverGeneralMessage in interface IWebClient
    • requestAttention

      public void requestAttention(long when, String byUser, boolean byAdmin, String message, int beepCount, long beepInterval, boolean windows)
      Specified by:
      requestAttention in interface IWebClient
    • watchGameInfo

      public void watchGameInfo(String gameId, String host, int port)
      Specified by:
      watchGameInfo in interface IWebClient
    • requestPing

      public void requestPing(String arg1, String arg2, String arg3)
    • connectionReset

      public void connectionReset(boolean forcedLogout)
      Specified by:
      connectionReset in interface IWebClient