|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object soc.server.GameHandler
public abstract class GameHandler
Server class to handle game-specific actions and messages for a type of game.
Currently, these concepts are common to all hosted game types:
SOCGame.resetAsCopy()
and SOCGameListAtServer.resetBoard(String)
.
SOCServer
manages the "boundary" of the game: The list of all games;
joining and leaving players and bots; creating and destroying games; game start time and the board reset framework.
GameHandler
and SOCGame
.
Game reset details are handled by SOCGame.resetAsCopy()
.
processCommand(SOCGame, SOCMessageForGame, StringConnection)
,
called for each SOCMessageForGame
sent to the server about this handler's game.
SOCServer.messageToGame(String, soc.message.SOCMessage)
or SOCServer.messageToPlayer(StringConnection, soc.message.SOCMessage)
.
Field Summary | |
---|---|
protected SOCServer |
srv
|
Constructor Summary | |
---|---|
protected |
GameHandler(SOCServer server)
|
Method Summary | |
---|---|
abstract void |
endTurnIfInactive(SOCGame ga,
long currentTimeMillis)
The server's timer thread thinks this game is inactive because of a robot bug. |
abstract java.lang.String[] |
getDebugCommandsHelp()
Get the debug commands for this game type, if any, used with processDebugCommand(StringConnection, String, String, String) . |
abstract void |
joinGame(SOCGame gameData,
StringConnection c,
boolean isReset,
boolean isTakingOver)
Client has been approved to join game; send the entire state of the game to client. |
abstract boolean |
leaveGame(SOCGame ga,
StringConnection c)
This member (player or observer) has left the game. |
abstract boolean |
processCommand(SOCGame ga,
SOCMessageForGame mes,
StringConnection c)
Process one command from a client player of this game. |
abstract boolean |
processDebugCommand(StringConnection debugCli,
java.lang.String gaName,
java.lang.String dcmd,
java.lang.String dcmdU)
Look for a potential debug command in a text message sent by the "debug" client/player. |
abstract void |
sitDown_sendPrivateInfo(SOCGame ga,
StringConnection c,
int pn)
When player has just sat down at a seat, send them all the private information. |
abstract void |
startGame(SOCGame ga)
Do the things you need to do to start a game and send its data to the clients. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final SOCServer srv
Constructor Detail |
---|
protected GameHandler(SOCServer server)
Method Detail |
---|
public abstract boolean processCommand(SOCGame ga, SOCMessageForGame mes, StringConnection c)
Some game messages (such as player sits down, or board reset voting) are handled the same for all game types.
These are handled at SOCServer
; they should be ignored here and not appear in your switch statement.
Called from SOCServer
message treater loop. Caller will catch any thrown Exceptions.
ga
- Game in which client c
is sending msg
.
Never null; from SOCMessageForGame.getGame()
.mes
- Message from client c
. Never null.c
- Client sending msg
. Never null.
public abstract boolean processDebugCommand(StringConnection debugCli, java.lang.String gaName, java.lang.String dcmd, java.lang.String dcmdU)
Server-wide debug commands are processed before gametype-specific debug commands;
see SOCServer.processDebugCommand(StringConnection, String, String, String)
.
debugCli
- Client sending the potential debug commandgaName
- Game in which the message is sentdcmd
- Text message which may be a debug commanddcmdU
- dcmd
as uppercase, for efficiency (it's already been uppercased in caller)
dcmd
is a recognized debug command, false otherwisegetDebugCommandsHelp()
public abstract java.lang.String[] getDebugCommandsHelp()
processDebugCommand(StringConnection, String, String, String)
.
If client types the *help*
debug command, the server will
send them all the general debug command help, and these strings.
SOCServer.DEBUG_COMMANDS_HELP
,
or null
if no gametype-specific debug commandspublic abstract void joinGame(SOCGame gameData, StringConnection c, boolean isReset, boolean isTakingOver)
Among other messages, player names are sent via SITDOWN, and pieces on board sent by PUTPIECE. See comments here for further details. If isTakingOver, assume the game already started and send any details about pieces, number of items, cards in hand, etc. The group of messages sent here ends with GAMEMEMBERS, SETTURN and GAMESTATE.
gameData
- Game to joinc
- The connection of joining clientisReset
- Game is a board-reset of an existing game. This is always false when
called from SOCServer instead of from inside the GameHandler.
Not all game types may be reset.isTakingOver
- Client is re-joining; this connection replaces an earlier one which
is defunct because of a network problem.
If isTakingOver, don't send anything to other players.SOCServer.connectToGame(StringConnection, String, java.util.Map)
,
SOCServer.createOrJoinGameIfUserOK(StringConnection, String, String, String, java.util.Map)
public abstract void sitDown_sendPrivateInfo(SOCGame ga, StringConnection c, int pn)
Called from SOCServer.sitDown(SOCGame, StringConnection, int, boolean, boolean)
.
Locks: Assumes ga.takeMonitor() is held, and should remain held.
ga
- the gamec
- the connection for the playerpn
- which seat the player is takingpublic abstract void startGame(SOCGame ga)
Send all game members the piece counts, other public information for the game and each player,
set up and send the board layout, game state, and finally send the STARTGAME
and TURN
messages.
Set game state to SOCGame.READY
or higher, from an earlier/lower state.
ga
- the gamepublic abstract void endTurnIfInactive(SOCGame ga, long currentTimeMillis)
SOCForceEndTurnThread
.
The server checks SOCGame.lastActionTime
to decide inaction.
The game could also seem inactive if we're waiting for another human player to decide something.
Games with state >= SOCGame.OVER
, and games which haven't started yet
(SOCGame.getCurrentPlayerNumber()
== -1), are ignored.
The default timeout is SOCServer.ROBOT_FORCE_ENDTURN_SECONDS
. You may calculate and use
a longer timeout if it makes sense in the current conditions, such as waiting for a human player
to ignore or respond to a trade offer.
ga
- Game to checkcurrentTimeMillis
- The time when called, from System.currentTimeMillis()
public abstract boolean leaveGame(SOCGame ga, StringConnection c)
SOCGame.removePlayer(String)
.
If the game still has other players, continue it, otherwise it will be ended after
returning from leaveGame
. Send messages out to other game members.
Locks: Has gameList.takeMonitorForGame(gm)
when calling this method; does not have SOCGame.takeMonitor()
.
ga
- The gamec
- The member connection which left.
The server has already removed c
from the list of game members.
If c
is being dropped because of an error,
StringConnection.disconnect()
has already been called.
Don't exclude c
from any communication about leaving the game,
in case they are still connected and in other games.
isBotsOnly
flag is false)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |