vooga.engine.networking.server
Class ChatHandler

java.lang.Object
  extended by java.lang.Thread
      extended by vooga.engine.networking.server.Handler
          extended by vooga.engine.networking.server.ChatHandler
All Implemented Interfaces:
java.lang.Runnable

public class ChatHandler
extends Handler

Class that handles communicating through chats over the network. There is one instance of ChatHandler for each time the game is run and a static list of the current running ChatHandlers. ChatHandler extends the Handler class so it also extends Thread and has a socket to send and receive chats through as well as a session ID to group ChatHandlers that are part of the same game session.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected static java.util.List<ChatHandler> handlers
           
 
Fields inherited from class vooga.engine.networking.server.Handler
sessionID, socket
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ChatHandler(GameSocket socket, int sessionID)
          Initializes ChatHandler with a socket to send and receive chats through and the chat's game session ID.
 
Method Summary
protected static void broadcast(java.lang.String chat, ChatHandler sender)
          Broadcast (send) the chat to everyone connected to this handler's game session besIDes the sender.
 void run()
          When the thread starts, add this handler to the game's list of ChatHandlers, then keep looking for messages to read from the socket and send out to all the players.
 
Methods inherited from class vooga.engine.networking.server.Handler
getSessionID, getSocket
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, 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, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

handlers

protected static java.util.List<ChatHandler> handlers
Constructor Detail

ChatHandler

public ChatHandler(GameSocket socket,
                   int sessionID)
Initializes ChatHandler with a socket to send and receive chats through and the chat's game session ID.

Parameters:
socket - the socket to send and receive chats through
sessionID - the ID of the chat's game session
Method Detail

run

public void run()
When the thread starts, add this handler to the game's list of ChatHandlers, then keep looking for messages to read from the socket and send out to all the players.

Specified by:
run in interface java.lang.Runnable
Specified by:
run in class Handler

broadcast

protected static void broadcast(java.lang.String chat,
                                ChatHandler sender)
Broadcast (send) the chat to everyone connected to this handler's game session besIDes the sender.

Parameters:
chat - the chat to send to the other players
sender - the handler who is sending the chat