net.sf.colossus.webserver
Class WebServerClient

java.lang.Object
  extended by net.sf.colossus.webserver.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 Summary
private  int clientVersion
          Client side version
private  WebServerClientSocketThread cst
          The client socket thread that handled the low-level connection stuff
private  long gameStartsNowSent
          Time when last gameStartsNowSent was sent (in ms since epoch)
private  long gameStartsSoonSent
          Time when last gameStartsSoonSent was sent (in ms since epoch)
private  boolean loggedIn
          Whether or not this WebServerClient is at the moment logged in
private static java.util.logging.Logger LOGGER
           
private static java.lang.String sep
           
private  WebServer server
          The web server object that is managing all WebServerClients
private  java.lang.String unverifiedUsername
          During registration request and sending of confirmation code, we do not have a user yet.
private  User user
          The user associated with this WebClient connection
 
Fields inherited from interface net.sf.colossus.webcommon.IWebClient
alreadyLoggedIn, chatDeliver, connectionClosed, didEnroll, didUnenroll, forcedLogout, gameCancelled, gameInfo, gameStarted, gameStartsNow, gameStartsSoon, generalMessage, grantAdmin, pingRequest, requestAttention, systemMessage, tooManyUsers, userInfo
 
Constructor Summary
WebServerClient(WebServer server, java.net.Socket socket)
           
 
Method Summary
 void chatDeliver(java.lang.String chatId, long when, java.lang.String sender, java.lang.String message, boolean resent)
           
 void connectionReset(boolean forcedLogout)
           
 void deliverGeneralMessage(long when, boolean error, java.lang.String title, java.lang.String message)
           
 void didEnroll(java.lang.String gameId, java.lang.String username)
           
 void didUnenroll(java.lang.String gameId, java.lang.String username)
           
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.
 void gameCancelled(java.lang.String gameId, java.lang.String byUser)
           
 void gameInfo(GameInfo gi)
           
 void gameStartsNow(java.lang.String gameId, int port, java.lang.String hostingHost)
           
 void gameStartsSoon(java.lang.String gameId, java.lang.String byUser)
           
 int getClientVersion()
           
 boolean getLoggedIn()
           
 java.lang.String getUnverifiedUsername()
           
(package private)  User getUser()
           
(package private)  java.lang.String getUsername()
           
 WebServerClientSocketThread getWSCSThread()
           
 void grantAdminStatus()
           
 void handleLogout()
           
 boolean parseLine(java.lang.String fromClient)
           
 void requestAttention(long when, java.lang.String byUser, boolean byAdmin, java.lang.String message, int beepCount, long beepInterval, boolean windows)
           
 void requestPing(java.lang.String arg1, java.lang.String arg2, java.lang.String arg3)
           
 void requestPingIfNeeded(long now)
           
 void requestPingNow()
           
private  void sendToClient(java.lang.String s)
           
private  void setClientVersion(int version)
           
 void setLoggedIn(boolean val)
           
 void setUnverifiedUsername(java.lang.String name)
           
private  void setUser(User u)
           
 void startThread()
           
 void systemMessage(long now, java.lang.String message)
           
 void userInfo(int loggedin, int enrolled, int playing, int dead, long ago, java.lang.String text)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

private static final java.util.logging.Logger LOGGER

sep

private static final java.lang.String sep
See Also:
Constant Field Values

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 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()

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

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)

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)

grantAdminStatus

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

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

gameInfo

public void gameInfo(GameInfo gi)
Specified by:
gameInfo 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

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