net.sf.colossus.webclient
Class WebClientSocketThread

java.lang.Object
  extended by java.lang.Thread
      extended by net.sf.colossus.webclient.WebClientSocketThread
All Implemented Interfaces:
java.lang.Runnable, IWebServer

public class WebClientSocketThread
extends java.lang.Thread
implements IWebServer

This implements the webserver/client communication at client side. It implements the server interface on client side; i.e. something server wanted to execute for a client, is read from the client socket input stream, parsed, and executed by the (WebClient)SocketThread. This also contains the methods which are called by the client (WebClient's GUI) and are sent over the socket to the server (note that those calls mostly happen in the EDT).

Author:
Clemens Katzer

Nested Class Summary
private  class WebClientSocketThread.AckWaiter
           
 class WebClientSocketThread.WcstException
           
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
private  WebClientSocketThread.AckWaiter ackWaiter
           
private  java.nio.charset.Charset charset
           
private  java.lang.String email
           
private  WebClientSocketThread.WcstException failedException
           
private  boolean force
           
private  java.util.HashMap<java.lang.String,GameInfo> gameHash
           
private  java.lang.String hostname
           
private  java.io.BufferedReader in
           
private  boolean loggedIn
           
private static java.util.logging.Logger LOGGER
           
private  java.io.PrintWriter out
           
private  java.lang.String password
           
private  int port
           
private static java.lang.String sep
           
private  java.net.Socket socket
           
private  boolean stillNeedsRun
           
private  java.lang.String username
           
private  IWebClient webClient
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Fields inherited from interface net.sf.colossus.webcommon.IWebServer
Cancel, ChangePassword, ChatSubmit, ConfirmRegistration, Echo, Enroll, generalChatName, LocallyGameOver, Login, Logout, PingResponse, Propose, RegisterUser, RequestUserAttention, RereadLoginMessage, ShutdownServer, Start, StartAtPlayer, StartedByPlayer, Unenroll, WebProtocolSeparator
 
Constructor Summary
WebClientSocketThread(WebClient wcGUI, java.lang.String hostname, int port, java.lang.String username, java.lang.String password, boolean force, java.lang.String email, java.lang.String confCode, java.util.HashMap<java.lang.String,GameInfo> gameHash)
           
 
Method Summary
 void cancelGame(java.lang.String gameId, java.lang.String byUser)
           
 java.lang.String changeProperties(java.lang.String username, java.lang.String oldPW, java.lang.String newPW, java.lang.String email, java.lang.Boolean isAdminObj)
           
 void chatSubmit(java.lang.String chatId, java.lang.String sender, java.lang.String message)
           
private  void cleanup()
           
private  void confirm(java.lang.String confCode)
          Send the confirmation code
private  void connect()
           
 void dispose()
           
 void enrollUserToGame(java.lang.String gameId, java.lang.String username)
           
 WebClientSocketThread.WcstException getException()
           
 java.lang.String getOneLine()
           
private  void handleAckNack(java.lang.String command, java.lang.String[] tokens)
           
 void informLocallyGameOver(java.lang.String gameId)
           
 void informStartedByPlayer(java.lang.String gameId)
           
private  void login()
           
 void logout()
           
 void pingResponse(java.lang.String arg1, java.lang.String arg2, java.lang.String arg3)
           
 GameInfo proposeGame(java.lang.String initiator, java.lang.String variant, java.lang.String viewmode, long startAt, int duration, java.lang.String summary, java.lang.String expire, boolean unlimitedMulligans, boolean balancedTowers, int min, int target, int max)
           
private  void register()
          Initial registration attempt
 void requestUserAttention(long when, java.lang.String sender, boolean isAdmin, java.lang.String recipient, java.lang.String message, int beepCount, long beepInterval, boolean windows)
           
private  GameInfo restoreGameInfo(java.lang.String[] tokens)
           
 void run()
           
private  void send(java.lang.String s)
           
 void shutdownServer()
           
 void startGame(java.lang.String gameId, User byUser)
           
 void startGameOnPlayerHost(java.lang.String gameId, java.lang.String hostingPlayer, java.lang.String playerHost, int port)
          A game was started by a WebClient user locally on his computer and is ready to accept the other players as remote client; so we notify them and tell them host and port to where to connect.
 boolean stillNeedsRun()
           
 void submitAnyText(java.lang.String text)
           
 void unenrollUserFromGame(java.lang.String gameId, java.lang.String username)
           
private  void writeLog(java.lang.String s)
           
 
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, interrupt, 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
 

Field Detail

LOGGER

private static final java.util.logging.Logger LOGGER

webClient

private IWebClient webClient

gameHash

private final java.util.HashMap<java.lang.String,GameInfo> gameHash

hostname

private java.lang.String hostname

port

private final int port

username

private java.lang.String username

password

private java.lang.String password

force

private boolean force

email

private java.lang.String email

socket

private java.net.Socket socket

in

private java.io.BufferedReader in

out

private java.io.PrintWriter out

stillNeedsRun

private boolean stillNeedsRun

sep

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

loggedIn

private boolean loggedIn

ackWaiter

private WebClientSocketThread.AckWaiter ackWaiter

failedException

private WebClientSocketThread.WcstException failedException

charset

private final java.nio.charset.Charset charset
Constructor Detail

WebClientSocketThread

public WebClientSocketThread(WebClient wcGUI,
                             java.lang.String hostname,
                             int port,
                             java.lang.String username,
                             java.lang.String password,
                             boolean force,
                             java.lang.String email,
                             java.lang.String confCode,
                             java.util.HashMap<java.lang.String,GameInfo> gameHash)
Method Detail

getOneLine

public java.lang.String getOneLine()
                            throws java.io.IOException
Throws:
java.io.IOException

getException

public WebClientSocketThread.WcstException getException()

connect

private void connect()
              throws WebClientSocketThread.WcstException
Throws:
WebClientSocketThread.WcstException

register

private void register()
               throws WebClientSocketThread.WcstException
Initial registration attempt

Throws:
WebClientSocketThread.WcstException

confirm

private void confirm(java.lang.String confCode)
              throws WebClientSocketThread.WcstException
Send the confirmation code

Throws:
WebClientSocketThread.WcstException

login

private void login()
            throws WebClientSocketThread.WcstException
Throws:
WebClientSocketThread.WcstException

stillNeedsRun

public boolean stillNeedsRun()

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

restoreGameInfo

private GameInfo restoreGameInfo(java.lang.String[] tokens)

cleanup

private void cleanup()

dispose

public void dispose()

send

private void send(java.lang.String s)

logout

public void logout()
Specified by:
logout in interface IWebServer

changeProperties

public java.lang.String changeProperties(java.lang.String username,
                                         java.lang.String oldPW,
                                         java.lang.String newPW,
                                         java.lang.String email,
                                         java.lang.Boolean isAdminObj)
Specified by:
changeProperties in interface IWebServer

handleAckNack

private void handleAckNack(java.lang.String command,
                           java.lang.String[] tokens)

proposeGame

public GameInfo proposeGame(java.lang.String initiator,
                            java.lang.String variant,
                            java.lang.String viewmode,
                            long startAt,
                            int duration,
                            java.lang.String summary,
                            java.lang.String expire,
                            boolean unlimitedMulligans,
                            boolean balancedTowers,
                            int min,
                            int target,
                            int max)
Specified by:
proposeGame in interface IWebServer

enrollUserToGame

public void enrollUserToGame(java.lang.String gameId,
                             java.lang.String username)
Specified by:
enrollUserToGame in interface IWebServer

unenrollUserFromGame

public void unenrollUserFromGame(java.lang.String gameId,
                                 java.lang.String username)
Specified by:
unenrollUserFromGame in interface IWebServer

cancelGame

public void cancelGame(java.lang.String gameId,
                       java.lang.String byUser)
Specified by:
cancelGame in interface IWebServer

startGame

public void startGame(java.lang.String gameId,
                      User byUser)
Specified by:
startGame in interface IWebServer

informStartedByPlayer

public void informStartedByPlayer(java.lang.String gameId)
Specified by:
informStartedByPlayer in interface IWebServer

informLocallyGameOver

public void informLocallyGameOver(java.lang.String gameId)
Specified by:
informLocallyGameOver in interface IWebServer

startGameOnPlayerHost

public void startGameOnPlayerHost(java.lang.String gameId,
                                  java.lang.String hostingPlayer,
                                  java.lang.String playerHost,
                                  int port)
Description copied from interface: IWebServer
A game was started by a WebClient user locally on his computer and is ready to accept the other players as remote client; so we notify them and tell them host and port to where to connect.

Specified by:
startGameOnPlayerHost in interface IWebServer

chatSubmit

public void chatSubmit(java.lang.String chatId,
                       java.lang.String sender,
                       java.lang.String message)
Specified by:
chatSubmit in interface IWebServer

pingResponse

public void pingResponse(java.lang.String arg1,
                         java.lang.String arg2,
                         java.lang.String arg3)

requestUserAttention

public void requestUserAttention(long when,
                                 java.lang.String sender,
                                 boolean isAdmin,
                                 java.lang.String recipient,
                                 java.lang.String message,
                                 int beepCount,
                                 long beepInterval,
                                 boolean windows)
Specified by:
requestUserAttention in interface IWebServer

shutdownServer

public void shutdownServer()
Specified by:
shutdownServer in interface IWebServer

submitAnyText

public void submitAnyText(java.lang.String text)

writeLog

private void writeLog(java.lang.String s)