thegame.server
Class GameServerConnection

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--thegame.shared.GameConnection
              |
              +--thegame.server.GameServerConnection
All Implemented Interfaces:
GameConnectionConstants, java.lang.Runnable

public class GameServerConnection
extends GameConnection

The connection to GameClient on the GameServer side.

Version:
0.99 (2000/08/28)
Author:
Erki Suurjaak

Field Summary
protected  GameServer gameServer
          The GameServer the GameServerConnection sends messages to.
protected  boolean isPlayerDrawingCircles
          Is true if the player is drawing circles; is false if the player is drawing crosses.
protected  boolean isReadyForPlayerList
          Is true if the player is ready to receive a playerlist; is false otherwise.
protected  boolean isWaiting
          Is true when the player is waiting for a joining player; is false otherwise.
protected  java.lang.String playerName
          The name of the player on the GameClient side.
protected  GameServerConnection remotePlayer
          The GameServerConnection referencing the remote player.
 
Fields inherited from class thegame.shared.GameConnection
in, isRunning, out, socket
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Fields inherited from interface thegame.shared.GameConnectionConstants
DEFAULT_SERVER_PORT, DELIMITER, P2P_MOVE_MADE_MESSAGE, P2P_NEW_GAME_ACCEPTED_MESSAGE, P2P_NEW_GAME_REFUSED_MESSAGE, P2P_NEW_GAME_REQUESTED_MESSAGE, P2P_PLAYER_SURRENDERED_MESSAGE, P2P_TEXT_MESSAGE, P2P_WINNING_MOVE_MADE_MESSAGE, P2S_CREATE_GAME_MESSAGE, P2S_JOIN_GAME_MESSAGE, P2S_PLAYER_NAME_MESSAGE, P2S_PLAYER_QUIT_MESSAGE, P2S_PLAYER_RETURNED_TO_START_SCREEN_MESSAGE, P2S_PLAYER_WAITED_FOR_NEW_PLAYER_MESSAGE, P2S_READY_FOR_PLAYER_LIST_MESSAGE, PLAYER_TO_SYSTEM_MESSAGES, S2P_JOIN_GAME_FAILED_MESSAGE, S2P_JOIN_GAME_SUCCEEDED_MESSAGE, S2P_PLAYER_DROPPED_MESSAGE, S2P_PLAYER_JOINED_MESSAGE, S2P_PLAYER_LIST_MESSAGE, S2P_PLAYER_NAME_NOT_OK_MESSAGE, S2P_PLAYER_NAME_OK_MESSAGE, S2P_PLAYER_QUIT_MESSAGE, S2P_PLAYER_RETURNED_TO_START_SCREEN_MESSAGE, S2P_SERVER_SHUTDOWN_MESSAGE, SHUTDOWN_MESSAGE
 
Constructor Summary
GameServerConnection(java.net.Socket socket, GameServer gameServer)
          Constructs a GameServerConnection on the specified socket and binds it to the specified GameServer.
 
Method Summary
 boolean getPlayerDrawingCircles()
          Returns the isPlayerDrawingCircles property.
 java.lang.String getPlayerName()
          Returns the name of the player on the GameClient side
 GameServerConnection getRemotePlayer()
          Returns the remotePlayer property.
 boolean isReadyForPlayerList()
          Returns the isReadyForPlayerList property.
 boolean isWaiting()
          Returns the isWaiting property.
 void run()
          The socket is listened on and if a message arrives, it is sent either to gameServer, to remotePlayer, or is discarded.
 void setPlayerDrawingCircles(boolean isPlayerDrawingCircles)
          Sets the isPlayerDrawingCircles property.
 void setPlayerName(java.lang.String playerName)
          Sets the name of the player on the GameClient side
 void setReadyForPlayerList(boolean isReadyForPlayerList)
          Sets the isReadyForPlayerList property.
 void setRemotePlayer(GameServerConnection remotePlayer)
          Sets the remotePlayer property.
 void setWaiting(boolean isWaiting)
          Sets the isWaiting property.
 
Methods inherited from class thegame.shared.GameConnection
close, getMessageBody, getMessageContentsAs1DIntArray, getMessageContentsAs1DStringArray, getMessageContentsAs2DIntArray, getMessageContentsAsBoolean, getMessageID, getReadyToSendForm, send, send, send, send, send, send, setRunning
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

gameServer

protected GameServer gameServer
The GameServer the GameServerConnection sends messages to.

isPlayerDrawingCircles

protected boolean isPlayerDrawingCircles
Is true if the player is drawing circles; is false if the player is drawing crosses.

isReadyForPlayerList

protected boolean isReadyForPlayerList
Is true if the player is ready to receive a playerlist; is false otherwise.

isWaiting

protected boolean isWaiting
Is true when the player is waiting for a joining player; is false otherwise.

playerName

protected java.lang.String playerName
The name of the player on the GameClient side.

remotePlayer

protected GameServerConnection remotePlayer
The GameServerConnection referencing the remote player.
Constructor Detail

GameServerConnection

public GameServerConnection(java.net.Socket socket,
                            GameServer gameServer)
                     throws java.io.IOException
Constructs a GameServerConnection on the specified socket and binds it to the specified GameServer.
Parameters:
socket - the socket to be used (must be already initialized)
gameServer - the GameServer to send messages to
Throws:
java.io.IOException - if an I/O error occurs when constructing the superclass
Method Detail

getPlayerDrawingCircles

public boolean getPlayerDrawingCircles()
Returns the isPlayerDrawingCircles property.
Returns:
the isPlayerDrawingCircles property

getPlayerName

public java.lang.String getPlayerName()
Returns the name of the player on the GameClient side
Returns:
the name of the player on the GameClient side

getRemotePlayer

public GameServerConnection getRemotePlayer()
Returns the remotePlayer property.
Returns:
the remotePlayer property

isReadyForPlayerList

public boolean isReadyForPlayerList()
Returns the isReadyForPlayerList property.
Returns:
the isReadyForPlayerList property

isWaiting

public boolean isWaiting()
Returns the isWaiting property.
Returns:
the isWaiting property

run

public void run()
The socket is listened on and if a message arrives, it is sent either to gameServer, to remotePlayer, or is discarded.
Overrides:
run in class java.lang.Thread

setPlayerDrawingCircles

public void setPlayerDrawingCircles(boolean isPlayerDrawingCircles)
Sets the isPlayerDrawingCircles property.
Parameters:
isPlayerDrawingCircles - true if the player is drawing circles; false it the player is drawing crosses

setPlayerName

public void setPlayerName(java.lang.String playerName)
Sets the name of the player on the GameClient side
Parameters:
playerName - the name of the player on the GameClient side

setReadyForPlayerList

public void setReadyForPlayerList(boolean isReadyForPlayerList)
Sets the isReadyForPlayerList property.
Parameters:
isReadyForPlayerList - true if the player is ready for playerlist; false otherwise

setRemotePlayer

public void setRemotePlayer(GameServerConnection remotePlayer)
Sets the remotePlayer property.
Parameters:
remotePlayer - the GameServerConnection referencing the remote player

setWaiting

public void setWaiting(boolean isWaiting)
Sets the isWaiting property.
Parameters:
isWaiting - true if the player is set waiting; false otherwise