energyTycoon.server
Class ServerClient

java.lang.Object
  extended by java.lang.Thread
      extended by energyTycoon.server.ServerClient
All Implemented Interfaces:
java.lang.Runnable

public class ServerClient
extends java.lang.Thread

instance of a client on the server

Author:
Leo CARNAUT-DELORD

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ServerClient(int clientId, Server server, java.net.Socket socket)
          ServerClient constructor
 
Method Summary
 int getClientId()
          client ID GET
 java.lang.String getClientName()
          get client Name
 boolean hasAGame()
          return true if the player is in a game (started or not)
 void kill()
           
 void run()
          run the thread : this will send the client if he is in a game or if he receive game list
 void sendError(java.lang.String error, java.lang.String message)
          Send a message error to the client
 void sendInitialization()
          Send initialization to this client (begin connection)
 void sendMessage(java.lang.String message)
          send a message to the client
 void setClientName(java.lang.String name)
          Change the client name
 void setPlayer(NetworkServerPlayer player)
          give a player to this client
 
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
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ServerClient

public ServerClient(int clientId,
                    Server server,
                    java.net.Socket socket)
ServerClient constructor

Parameters:
clientId - client identifier
server - link to the server
socket - listening socket
Method Detail

getClientId

public int getClientId()
client ID GET

Returns:
client id

hasAGame

public boolean hasAGame()
return true if the player is in a game (started or not)

Returns:
true if the player is in a game (started or not)

setPlayer

public void setPlayer(NetworkServerPlayer player)
give a player to this client

Parameters:
player - player to attribute

run

public void run()
run the thread : this will send the client if he is in a game or if he receive game list

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

sendMessage

public void sendMessage(java.lang.String message)
send a message to the client

Parameters:
message - message to send to the client

getClientName

public java.lang.String getClientName()
get client Name

Returns:
client name

sendInitialization

public void sendInitialization()
Send initialization to this client (begin connection)


setClientName

public void setClientName(java.lang.String name)
Change the client name

Parameters:
name - new client name

sendError

public void sendError(java.lang.String error,
                      java.lang.String message)
Send a message error to the client

Parameters:
error - error code
message - error message

kill

public void kill()