energyTycoon.server
Class Server

java.lang.Object
  extended by java.lang.Thread
      extended by energyTycoon.server.Server
All Implemented Interfaces:
PowerStationListener, java.lang.Runnable

public class Server
extends java.lang.Thread
implements PowerStationListener

The main server class, manage all games ...

Author:
Léo 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
Server(int maxGame, int maxClient, int port)
          Server constructor
Server(int maxGame, int maxClient, int port, boolean clientMode)
          Server constructor (client mode)
 
Method Summary
 void addPowerStationType(PowerStationType pst)
           
 void createGame(int clientId, java.lang.String gameName, int scriptId, int money, int maxPlayer)
           
 void deleteClient(int clientId)
          a client leave the server
 void deleteGame(int gameId)
          delete the specified game from game list
 java.lang.String getAllPowerStationGroupsDefinition()
          all power station for network
 int getNbClient()
          get the number of clients
 int getNbGame()
          get the number of hosted games
 PowerStationGroup getPowerStationGroupFromName(java.lang.String name)
          get the power station group having the given name
 java.lang.String getScriptFileName(int scriptId)
          get the script name
 boolean isClientMode()
           
 void joinGame(int clientId, int gameId)
          a client try to join a game
 void kill()
           
 void listGames(int clientId)
          send the games list to a client
 void listScripts(int clientId)
          send the scripts list to a client
 void loadPowerStations()
          load power stations groups
 void run()
          run the server (receive client loop)
 void sendGameStart()
          Send all game initialization to all players
 void sendInitialization(int clientId)
          Initialize connection : join game or list games
 void sendMessageToNoGame(java.lang.String message)
          Send a message to all clients without any games
 void setGameInvisible(int gameId)
          Set game not visible on network ( before deleting or starting )
 boolean waitStarted()
          wait the server to be started
 
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

Server

public Server(int maxGame,
              int maxClient,
              int port)
Server constructor

Parameters:
maxGame - maximum game number
maxClient - maximum client number
port - server port

Server

public Server(int maxGame,
              int maxClient,
              int port,
              boolean clientMode)
Server constructor (client mode)

Parameters:
maxGame - maximum game number
maxClient - maximum client number
port - server port
clientMode - is the server run in client mode (just one game)
Method Detail

getNbGame

public int getNbGame()
get the number of hosted games

Returns:
game number

getNbClient

public int getNbClient()
get the number of clients

Returns:
client number

waitStarted

public boolean waitStarted()
wait the server to be started

Returns:
false if the server wasn't able to start

run

public void run()
run the server (receive client loop)

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

sendInitialization

public void sendInitialization(int clientId)
Initialize connection : join game or list games

Parameters:
clientId - client id

listGames

public void listGames(int clientId)
send the games list to a client

Parameters:
clientId - client ID

listScripts

public void listScripts(int clientId)
send the scripts list to a client

Parameters:
clientId - client ID

sendMessageToNoGame

public void sendMessageToNoGame(java.lang.String message)
Send a message to all clients without any games

Parameters:
message - message to send

joinGame

public void joinGame(int clientId,
                     int gameId)
a client try to join a game

Parameters:
clientId - client id
gameId - game id

createGame

public void createGame(int clientId,
                       java.lang.String gameName,
                       int scriptId,
                       int money,
                       int maxPlayer)
Parameters:
clientId - client id creating game
gameName - game name
scriptId - script id
money - money we start with
maxPlayer - maximum player number

deleteClient

public void deleteClient(int clientId)
a client leave the server

Parameters:
clientId - client id to remove

deleteGame

public void deleteGame(int gameId)
delete the specified game from game list

Parameters:
gameId -

setGameInvisible

public void setGameInvisible(int gameId)
Set game not visible on network ( before deleting or starting )

Parameters:
gameId -

sendGameStart

public void sendGameStart()
Send all game initialization to all players


getScriptFileName

public java.lang.String getScriptFileName(int scriptId)
get the script name

Parameters:
scriptId - script id
Returns:
script name

kill

public void kill()

isClientMode

public boolean isClientMode()
Returns:
true if server is run in client mode

loadPowerStations

public void loadPowerStations()
load power stations groups


addPowerStationType

public void addPowerStationType(PowerStationType pst)
Specified by:
addPowerStationType in interface PowerStationListener

getPowerStationGroupFromName

public PowerStationGroup getPowerStationGroupFromName(java.lang.String name)
get the power station group having the given name

Parameters:
name -
Returns:

getAllPowerStationGroupsDefinition

public java.lang.String getAllPowerStationGroupsDefinition()
all power station for network

Returns:
string definition