Class MainRoom

java.lang.Object
  extended by MainRoom
All Implemented Interfaces:
Room

public class MainRoom
extends java.lang.Object
implements Room

Main Room for Users This is the main control for the server. It holds a collection of clients in the main room and available games to connect to.


Field Summary
 
Fields inherited from interface Room
ADD_USER, CHAT, COLOR_CHANGE, CREATE, DRAW, END_SESSION, ERASE, ERROR, GAME_INFO, JOIN, LEAVE_GAME, LOGIN, LOGOUT, NEW_ILLUSTRATOR, REMOVE_USER, SIZE_CHANGE, START, STOP, TOPIC_REQUEST
 
Constructor Summary
MainRoom()
          Construct and initialize the server
 
Method Summary
 void addNewClient(Client newClient)
          Adds a new client to the set of current clients Starts a new thread that waits for another client
 boolean containsUser(java.lang.String userName)
          Checks to see if a given user is in the room.
 void handleMsg(java.lang.String msg, Client sender)
          Handles messages from client
static void main(java.lang.String[] args)
           
 Client removeClient(java.lang.String userName)
          Remove a client from the room.
 void removeGame(GameRoom game)
          Removes the given game from the game list
 boolean sendTo(java.lang.String userName, java.lang.String msg)
          Sends a given message to a given client
 void sendToAllClients(java.lang.String message)
          Sends a message to all clients
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MainRoom

public MainRoom()
Construct and initialize the server

Method Detail

addNewClient

public void addNewClient(Client newClient)
Adds a new client to the set of current clients Starts a new thread that waits for another client

Specified by:
addNewClient in interface Room
Parameters:
newClient - The new client that is joining the server

sendTo

public boolean sendTo(java.lang.String userName,
                      java.lang.String msg)
Sends a given message to a given client

Parameters:
userName - The name of the user to send the message to
msg - The message that is being sent

sendToAllClients

public void sendToAllClients(java.lang.String message)
Sends a message to all clients

Parameters:
message - The message that is sent to every client

removeClient

public Client removeClient(java.lang.String userName)
Remove a client from the room. This room does not have any direct reference to a client after it has been removed

Specified by:
removeClient in interface Room
Parameters:
userName - The name of the client that is being removed
Returns:
The client that has just been removed

handleMsg

public void handleMsg(java.lang.String msg,
                      Client sender)
Handles messages from client

Specified by:
handleMsg in interface Room
Parameters:
msg - the message or command that is being sent
sender - the client who sent the message

containsUser

public boolean containsUser(java.lang.String userName)
Checks to see if a given user is in the room.

Specified by:
containsUser in interface Room
Parameters:
userName - the user name to search for
Returns:
true if the room contains the given user name, otherwise false

removeGame

public void removeGame(GameRoom game)
Removes the given game from the game list

Parameters:
game - the game that is being removed

main

public static void main(java.lang.String[] args)