Class WebServerClient

  • All Implemented Interfaces:
    IWebClient

    public class WebServerClient
    extends java.lang.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 Detail

      • LOGGER

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

      • WebServerClient

        public WebServerClient​(WebServer server,
                               java.net.Socket socket)
    • Method Detail

      • startThread

        public void startThread()
      • setClientVersion

        private void setClientVersion​(int version)
      • setUser

        private void setUser​(User u)
      • getUser

        User getUser()
      • getUsername

        java.lang.String getUsername()
      • setUnverifiedUsername

        public void setUnverifiedUsername​(java.lang.String name)
      • getUnverifiedUsername

        public java.lang.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​(java.lang.String fromClient)
      • makeCaseMismatchWarning

        private java.util.List<java.lang.String> makeCaseMismatchWarning​(java.lang.String name)
      • processChatLine

        public void processChatLine​(java.lang.String chatId,
                                    java.lang.String sender,
                                    java.lang.String message)
      • ensureNotAlreadyLoggedIn

        private java.lang.String ensureNotAlreadyLoggedIn​(java.lang.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,
                                  java.lang.String message)
        Specified by:
        systemMessage in interface IWebClient
      • sendToClient

        private void sendToClient​(java.lang.String s)
      • didEnroll

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

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

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

        public void userInfo​(int loggedin,
                             int enrolled,
                             int playing,
                             int dead,
                             long ago,
                             java.lang.String text)
        Specified by:
        userInfo in interface IWebClient
      • gameStartsSoon

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

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

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

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

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

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

        public void requestPing​(java.lang.String arg1,
                                java.lang.String arg2,
                                java.lang.String arg3)
      • connectionReset

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