|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
vooga.engine.networking.server.Handler
vooga.engine.networking.server.ClientHandler
public abstract class ClientHandler
Abstract class that lays some of the groundwork for communicating between clients over the network. There is one instance of a ClientHandler subclass for each time the game is run and a static list of the current running ClientHandler subclasses. ClientHandler 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 ClientHandlers that are part of the same game session. It also knows the number of players it needs for the game to start, and in its run method waits to start the game until that number is fulfilled. Classes that extend ClientHandler must extend the firstRun() method which is where the programmer puts anything that needs to be sent before the game is begun. Subclasses of ClientHandler will also subclass run (while calling super.run() as the first line of the method) in order to add whatever game specific code they need to send messages to the other players in their 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<ClientHandler> |
handlers
|
protected int |
numberOfPlayers
|
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 | |
---|---|
ClientHandler(VoogaDaemon daemon,
GameSocket socket,
int numberOfPlayers,
int gameNumber)
Static method to return the XML document with the list of games that can be run on the networking Vooga servers. |
Method Summary | |
---|---|
protected static void |
broadcastToAll(java.lang.String message,
ClientHandler sender)
Broadcast (send) a message to everyone in the sender's game session. |
protected static void |
broadcastToOthers(java.lang.String chat,
ClientHandler sender)
Broadcast (send) a message to everyone in the sender's game session but the sender. |
abstract void |
firstRun()
Abstract method that is called by run() right after the correct number of players are found and before the game has to start. |
ClientHandler |
getFirstPlayer(int gameNumber)
|
int |
getPlayers(int gameNumber)
|
void |
run()
Each time a ClientHandler is started, add itself to the list of handlers, send out "wait" to all the players until the correct number of players is met, and then call firstRun() which is where the user will put any code that needs to be run right after the correct number of players are found. |
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 |
---|
protected int numberOfPlayers
protected static java.util.List<ClientHandler> handlers
Constructor Detail |
---|
public ClientHandler(VoogaDaemon daemon, GameSocket socket, int numberOfPlayers, int gameNumber)
daemon
- the VoogaDaemon that initialized this object; used to increment the numberOfGames when the correct amount of players is metsocket
- the socket that clients will be communicating throughnumberOfPlayers
- the number of players necessary to play the gamegameNumber
- this individual instance's number in relation to all the run games on the server, used to group clients in a common game sessionMethod Detail |
---|
public void run()
run
in interface java.lang.Runnable
run
in class Handler
public abstract void firstRun()
protected static void broadcastToAll(java.lang.String message, ClientHandler sender)
message
- the message to sendsender
- the handler who is sending the messageprotected static void broadcastToOthers(java.lang.String chat, ClientHandler sender)
message
- the message to sendsender
- the handler who is sending the methodpublic int getPlayers(int gameNumber)
gameNumber
- the id of the game session
public ClientHandler getFirstPlayer(int gameNumber)
gameNumber
- the id of the game session
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |