com.asdf.client
Class LobbyController

java.lang.Object
  extended by com.asdf.client.LobbyController
All Implemented Interfaces:
MessageHandler

public class LobbyController
extends java.lang.Object
implements MessageHandler

LobbyController is the centerpiece of the programs client side. It handles starting of game clients, gets available games on server, lists running games and gets details of selected games. It also handles logging in into server. It runs the whole multigame browser. It is also task of this class to send join and create game requests to the server. Commands through LobbyView are processed in this LobbyController. Communication to server is done through ConnectionHandler using XML -protocol defined by message.xsd.

Author:
asdf

Field Summary
static java.lang.String PLUGIN_PATH
           
static java.lang.String TEST_PATH
           
 
Constructor Summary
LobbyController(ConnectionHandler connection)
          Sole constructor for LobbyController.
 
Method Summary
 void dispose()
          Called to get member frame disappear.
 ConnectionHandler getConnectionHandler()
          Gets the ConnectionHandler used by lobby.
 long getID()
          Returns the sessionID of this MessageHandler.
 Message getMessageTemplate()
          Create Message already containing correct sessionID
 XMLTools getXMLParserInstance()
           
 void handleRequest(Request req)
          Stub method, since LobbyController does not serve any requests.
 void handleResponse(Response rsp)
          Handle response sent by the server.
 void handleStateUpdate(StateUpdate stateUp)
          Stub method, since LobbyController does not handle any stateUpdates.
static void lobbyToFront()
          Brings lobby's view to front.
 void requestAvailableGames()
          Request a list of available games from server.
 void requestCreateAccount(java.lang.String account, java.lang.String passwd, java.lang.String accountType)
          Sends a create account request to server.
 void requestCreateGame(CreateGameRequest greq)
          Sends a create game request to server.
 void requestGameDetails(java.lang.String gameID)
          Requests details of selected game from server.
 void requestGameList(java.lang.String gameType, java.lang.String gameVariant)
          Requests a list of games of the given gameType and gameVariant.
 boolean requestJoinGame()
          Sends a join game request to server.
 void requestLogIn(java.lang.String account, java.lang.String password)
          Requests login from server.
 void requestLogOut()
          Requests logout from server.
 void setAvailableGames(AvailableGamesResponse response)
          Sets available games visible in GUI and updates LobbyModel if necessary.
 void setConnectionHandler(ConnectionHandler connection)
          Sets a ConnectionHandler for lobby.
 void setCreateGameDetails()
          Loads dynamically CreateGamePanel for the chosen game type (chosen in LobbyView) and sets it visible.
 void setEmptyGamesHidden(boolean b)
          If b, then sets empty games hidden, if not b set empty games visible in LobbyView.
 void setFullGamesHidden(boolean b)
          If b, then sets full games hidden, if not b set full games visible in LobbyView.
 void setGameDetails(GameDetailsResponse response)
          Sets details of selected game visible in GUI or shows panel for creating games.
 void setGameList(GameListResponse response, Filter filter)
          Sets list of selected game visible in GUI and updates LobbyModel if necessary.
 void setID(long id)
          Sets sessionID for lobby.
 void setLogin(LoginResponse response)
          Sets user logged in in LobbyModel and LobbyFrame.
 void setLogout(GenericResponse response)
          Sets user logged out in LobbyModel and LobbyFrame.
 void showGamesWithNameContaining(java.lang.String s)
           
 void showGamesWithPlayers(int min, int max)
           
 void startGameClient(GameResponse rsp)
          Loads dynamically a game client plugin of a type chosen from LobbyView, initializes it with parameters received from server, sets its connection handler and starts it.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TEST_PATH

public static final java.lang.String TEST_PATH
See Also:
Constant Field Values

PLUGIN_PATH

public static final java.lang.String PLUGIN_PATH
See Also:
Constant Field Values
Constructor Detail

LobbyController

public LobbyController(ConnectionHandler connection)
Sole constructor for LobbyController.

Parameters:
connection - ConnectionHandler to handle communication between client's lobby and server.
Method Detail

lobbyToFront

public static void lobbyToFront()
Brings lobby's view to front.


startGameClient

public void startGameClient(GameResponse rsp)
Loads dynamically a game client plugin of a type chosen from LobbyView, initializes it with parameters received from server, sets its connection handler and starts it.

Parameters:
rsp - Parameters used to initialize game client.

setAvailableGames

public void setAvailableGames(AvailableGamesResponse response)
Sets available games visible in GUI and updates LobbyModel if necessary.

Parameters:
response - AvailableGamesResponse sent by server.

setGameDetails

public void setGameDetails(GameDetailsResponse response)
Sets details of selected game visible in GUI or shows panel for creating games.

Parameters:
response - GameDetailsResponse sent by server.

setCreateGameDetails

public void setCreateGameDetails()
Loads dynamically CreateGamePanel for the chosen game type (chosen in LobbyView) and sets it visible.


setGameList

public void setGameList(GameListResponse response,
                        Filter filter)
Sets list of selected game visible in GUI and updates LobbyModel if necessary.

Parameters:
response - GameListResponse sent by server.

requestAvailableGames

public void requestAvailableGames()
Request a list of available games from server.


requestGameList

public void requestGameList(java.lang.String gameType,
                            java.lang.String gameVariant)
Requests a list of games of the given gameType and gameVariant.

Parameters:
gameType - Game type available on server.
gameVariant - Game variant of the given game type.

requestGameDetails

public void requestGameDetails(java.lang.String gameID)
Requests details of selected game from server.

Parameters:
gameID - GameID of selected game.

getXMLParserInstance

public XMLTools getXMLParserInstance()

requestLogOut

public void requestLogOut()
Requests logout from server.


requestLogIn

public void requestLogIn(java.lang.String account,
                         java.lang.String password)
Requests login from server.

Parameters:
account -
password -

setLogin

public void setLogin(LoginResponse response)
Sets user logged in in LobbyModel and LobbyFrame.

Parameters:
response - Response from server to login request.

setLogout

public void setLogout(GenericResponse response)
Sets user logged out in LobbyModel and LobbyFrame.

Parameters:
response - Response from server to logout request.

requestJoinGame

public boolean requestJoinGame()
Sends a join game request to server.

Returns:
false if user was not logged in, true if request was sent

setFullGamesHidden

public void setFullGamesHidden(boolean b)
If b, then sets full games hidden, if not b set full games visible in LobbyView.

Parameters:
b - a boolean

setEmptyGamesHidden

public void setEmptyGamesHidden(boolean b)
If b, then sets empty games hidden, if not b set empty games visible in LobbyView.

Parameters:
b - a boolean

showGamesWithPlayers

public void showGamesWithPlayers(int min,
                                 int max)

dispose

public void dispose()
Called to get member frame disappear.


getMessageTemplate

public Message getMessageTemplate()
Create Message already containing correct sessionID

Returns:
New Message object

handleResponse

public void handleResponse(Response rsp)
Handle response sent by the server.

Specified by:
handleResponse in interface MessageHandler
Parameters:
rsp - Response sent by server. Response is an object generated from XML message using JAXB.

requestCreateGame

public void requestCreateGame(CreateGameRequest greq)
Sends a create game request to server. Note that CreateGameRequests must be given by CreateGamePanel of the chosen game type. LobbyController has no idea what kind of parameters are used in creating any kind of games.

Parameters:
greq - Request to create a game received from CreateGamePanel.

getID

public long getID()
Description copied from interface: MessageHandler
Returns the sessionID of this MessageHandler.

Specified by:
getID in interface MessageHandler
Returns:
SessionID of this MessageHandler.

requestCreateAccount

public void requestCreateAccount(java.lang.String account,
                                 java.lang.String passwd,
                                 java.lang.String accountType)
Sends a create account request to server.

Parameters:
account - Name of the account.
passwd - Password for the account.
accountType - Type of the account. Currently only AccountType.REGULAR_USER.

handleRequest

public void handleRequest(Request req)
Stub method, since LobbyController does not serve any requests.

Specified by:
handleRequest in interface MessageHandler
Parameters:
req - Request sent by server. Request is an object generated from XML message using JAXB.

handleStateUpdate

public void handleStateUpdate(StateUpdate stateUp)
Stub method, since LobbyController does not handle any stateUpdates.

Specified by:
handleStateUpdate in interface MessageHandler
Parameters:
stateUp - StateUpdate sent by server. StateUpdate is an object generated from XML message using JAXB.

setID

public void setID(long id)
Sets sessionID for lobby.

Specified by:
setID in interface MessageHandler
Parameters:
id - Semi-Unique sessionID.

setConnectionHandler

public void setConnectionHandler(ConnectionHandler connection)
Sets a ConnectionHandler for lobby.

Specified by:
setConnectionHandler in interface MessageHandler
Parameters:
connection - ConnectionHandler to be used.

getConnectionHandler

public ConnectionHandler getConnectionHandler()
Gets the ConnectionHandler used by lobby.

Specified by:
getConnectionHandler in interface MessageHandler
Returns:
ConnectionHandler used by the implementing class.

showGamesWithNameContaining

public void showGamesWithNameContaining(java.lang.String s)