com.threerings.puzzle.server
Class PuzzleManager

java.lang.Object
  extended by com.threerings.crowd.server.PlaceManager
      extended by com.threerings.parlor.game.server.GameManager
          extended by com.threerings.puzzle.server.PuzzleManager
All Implemented Interfaces:
SpeakHandler.SpeakerValidator, ParlorCodes, GameCodes, PlayManager, InvocationCodes, ChangeListener, MessageListener, InvocationProvider, PuzzleCodes, PuzzleGameProvider

public abstract class PuzzleManager
extends GameManager
implements PuzzleCodes, PuzzleGameProvider

Extends the GameManager with facilities for puzzle games.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.threerings.crowd.server.PlaceManager
PlaceManager.DelegateOp, PlaceManager.MessageHandler
 
Field Summary
protected  Board[] _boards
          The player boards.
protected  long[] _lastProgress
          Tracks the last time we received a progress event from each player in this puzzle.
protected  PuzzleObject _puzobj
          A casted reference to our puzzle game object.
protected  Interval _statusInterval
          The client update interval.
 
Fields inherited from class com.threerings.parlor.game.server.GameManager
_AIs, _aiTicker, _committedState, _gameconfig, _gameEndTracker, _gameobj, _noShowInterval, _pendingOids, _playerCount, _playerOids, _postponedStart, _startmsgs, _stateListener, _tickInterval, AI_TICK_DELAY, DEFAULT_NOSHOW_DELAY, TICK_DELAY
 
Fields inherited from class com.threerings.crowd.server.PlaceManager
_bodyUpdater, _config, _deathListener, _delegates, _dispatcher, _dispatcherFinders, _injector, _invmgr, _locator, _marshallers, _msghandlers, _occInfo, _occListener, _omgr, _plobj, _registry, _shutdownInterval
 
Fields inherited from interface com.threerings.puzzle.data.PuzzleCodes
DEBUG_PUZZLE, DEFAULT_DIFFICULTY, PUZZLE_MESSAGE_BUNDLE
 
Fields inherited from interface com.threerings.presents.data.InvocationCodes
ACCESS_DENIED, E_ACCESS_DENIED, E_INTERNAL_ERROR, GLOBAL_GROUP, INTERNAL_ERROR
 
Fields inherited from interface com.threerings.parlor.data.ParlorCodes
ALREADY_AT_TABLE, BANNED_FROM_TABLE, GAME_ALREADY_STARTED, INVALID_TABLE_POSITION, INVITATION_ACCEPTED, INVITATION_COUNTERED, INVITATION_REFUSED, INVITEE_NOT_ONLINE, MUST_BE_CREATOR, NO_SELF_BOOT, NO_SUCH_TABLE, NOT_AT_TABLE, PARLOR_GROUP, TABLE_POSITION_OCCUPIED
 
Fields inherited from interface com.threerings.parlor.game.data.GameCodes
GAME_CHAT_TYPE, GAME_MESSAGE_BUNDLE, PLAYER_KNOCKED_OUT, WINNERS_AND_LOSERS
 
Constructor Summary
PuzzleManager()
           
 
Method Summary
protected  boolean applyProgressEvent(int pidx, int gevent, Board cboard)
          Called by updateProgress(com.threerings.presents.data.ClientObject, int, int[]) to give the server a chance to apply each game event received from the client to the respective player's server-side board and, someday, confirm their validity.
protected  void applyProgressEvents(int pidx, int[] gevents, Board[] states)
          Applies progress updates received from the client.
protected  void assignWinners(boolean[] winners)
          Overrides the game manager implementation to mark all active players as winners.
protected  boolean checkForInactivity()
          Returns whether checkPlayerActivity(long, int) should be called periodically while the game is in play to make sure players are still active.
protected  void checkPlayerActivity(long tickStamp, int pidx)
          Called periodically for each human player to give puzzles a chance to make sure all such players are engaging in reasonable levels of activity.
protected  boolean compareBeforeApply()
          Returns whether this puzzle compares board states before it applies progress events, or after.
protected  void compareBoards(int pidx, Board boardstate, int gevent, boolean before)
          Compare our server board to the specified sent-back user board.
protected  int computeDifficulty()
          When a puzzle game starts, the manager is given the opportunity to configure the puzzle difficulty based on information known about the player.
protected  void didShutdown()
           
protected  void didStartup()
           
protected  void gameDidEnd()
          Called after the game has transitioned to the GameObject.GAME_OVER state.
protected  void gameDidStart()
          Called after the game start notification was dispatched.
protected  void gameWillStart()
          Called when the game is about to start, but before the game start notification has been delivered to the players.
 Board[] getBoards()
          Returns the boards for all players.
 BoardSummary getBoardSummary(int pidx)
          Returns the board summary for the given player index.
protected  long getStatusInterval()
          Returns the frequency with which puzzle status updates are broadcast to the players (which is accomplished via a call to sendStatusUpdate() which in turn calls updateStatus() wherein derived classes can participate in the status update).
protected  void handleBoardNotEqual()
          Handles the server and client states being out of sync when in debug mode.
protected  void initBoards()
          Creates and initializes boards and board summaries (if desired per needsBoardSummaries()) for each player.
 boolean needsBoardSummaries()
          Returns whether this puzzle cares to make use of per-player board summaries that are sent periodically to all users in the puzzle via sendStatusUpdate().
protected  boolean needsPlayerBoard(int pidx)
          Returns whether this puzzle needs a board for the given player index.
protected abstract  Board newBoard(int pidx)
          Creates and returns a new starting board for the given player.
protected abstract  BoardSummary newBoardSummary(Board board)
          Creates and returns a new board summary for the given board.
protected  void playerGameDidEnd(int pidx)
          Called when a player has been marked as knocked out but before the knock-out status update has been sent to the players.
protected  void sendStatusUpdate()
          Updates (in one puzzle object transaction) all periodically updated status information.
protected  boolean summarizeAIBoard()
          Override to have board summaries for AIs automatically generated.
protected  void systemMessage(String msg)
          Send a system message with the puzzle bundle.
protected  void systemMessage(String msg, boolean waitForStart)
          Send a system message with the puzzle bundle.
protected  void tick(long tickStamp)
          Gives game managers an opportunity to perform periodic processing that is not driven by events generated by the player.
 void updateBoardSummaries()
          Applies updateBoardSummary on all the players' boards.
 void updateBoardSummary(int pidx)
          Calls BoardSummary.summarize() on the given player's board summary to refresh the summary information in preparation for sending along to the client(s).
 void updateProgress(ClientObject caller, int sessionId, int[] events)
          Handles a PuzzleGameService.updateProgress(int, int[]) request.
 void updateProgressSync(ClientObject caller, int sessionId, int[] events, Board[] states)
          Called when the puzzle manager receives a progress update.
protected  void updateStatus()
          A puzzle periodically (default of once every 5 seconds but configurable by puzzle) updates status information that is visible to the user.
protected  void updateSummaryOnDeath(int pidx)
          Updates the board summary for a player who has been eliminated and performs an update to communicate this change.
 
Methods inherited from class com.threerings.parlor.game.server.GameManager
addPlayer, addPlayerAt, allPlayersReady, announcePlayerGameOver, bodyLeft, cancelGame, checkForNoShows, checkShutdownInterval, checkWritePermission, didInit, endGame, endPlayerGame, gameWasCancelled, gameWillEnd, gameWillReset, getGameConfig, getGameId, getMatchType, getNoShowTime, getPlayer, getPlayerCount, getPlayerDisplayName, getPlayerGameOverMessage, getPlayerIndex, getPlayerName, getPlayerOid, getPlayerPersistentId, getPlayerPersistentId, getPlayerSlots, getPresentPlayerIndex, getSessionId, handlePartialNoShow, isActivePlayer, isAgent, isAI, isPlayer, needsAITick, needsNoShowTimer, occupantInRoom, placeBecameEmpty, playerIsReady, playerReady, playersAllHere, playerWasAdded, playerWasRemoved, playerWasReplaced, removePlayer, replacePlayer, reportPlayerKnockedOut, reportWinnersAndLosers, resetGame, setAI, shouldConcludeGame, shouldEndGame, startAITicker, startGame, startWithoutHumans, stateDidChange, stopAITicker, systemMessage, systemMessage, tickAI, tickAIs
 
Methods inherited from class com.threerings.crowd.server.PlaceManager
addDelegate, addDispatcher, addOccupantInfo, addProvider, applyToDelegates, applyToOccupants, bodyEntered, bodyUpdated, bodyWillEnter, bodyWillLeave, cancelShutdowner, checkPermissions, createPlaceObject, createSpeakHandler, getAccessController, getConfig, getLocation, getPlaceObject, getPlaceObjectClass, idleUnloadPeriod, init, isValidSpeaker, messageReceived, permissionsFailed, ratifyBodyEntry, registerMessageHandler, shouldCreateSpeakService, shouldDeclareEmpty, shutdown, startup, toString, toString, updateOccupantInfo, where
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_puzobj

protected PuzzleObject _puzobj
A casted reference to our puzzle game object.


_boards

protected Board[] _boards
The player boards.


_statusInterval

protected Interval _statusInterval
The client update interval.


_lastProgress

protected long[] _lastProgress
Tracks the last time we received a progress event from each player in this puzzle.

Constructor Detail

PuzzleManager

public PuzzleManager()
Method Detail

getBoards

public Board[] getBoards()
Returns the boards for all players.


getBoardSummary

public BoardSummary getBoardSummary(int pidx)
Returns the board summary for the given player index.


needsBoardSummaries

public boolean needsBoardSummaries()
Returns whether this puzzle cares to make use of per-player board summaries that are sent periodically to all users in the puzzle via sendStatusUpdate(). The default implementation returns false.


compareBeforeApply

protected boolean compareBeforeApply()
Returns whether this puzzle compares board states before it applies progress events, or after. The default implementation returns true.


handleBoardNotEqual

protected void handleBoardNotEqual()
Handles the server and client states being out of sync when in debug mode. The default implementation halts the server.


updateBoardSummary

public void updateBoardSummary(int pidx)
Calls BoardSummary.summarize() on the given player's board summary to refresh the summary information in preparation for sending along to the client(s).

Parameters:
pidx - the player index of the player whose board is to be summarized.

updateBoardSummaries

public void updateBoardSummaries()
Applies updateBoardSummary on all the players' boards. AI board summaries should be updated by the AI logic.


playerGameDidEnd

protected void playerGameDidEnd(int pidx)
Description copied from class: GameManager
Called when a player has been marked as knocked out but before the knock-out status update has been sent to the players. Any status information that needs be updated in light of the knocked out player can be updated here.

Overrides:
playerGameDidEnd in class GameManager

updateSummaryOnDeath

protected void updateSummaryOnDeath(int pidx)
Updates the board summary for a player who has been eliminated and performs an update to communicate this change.


summarizeAIBoard

protected boolean summarizeAIBoard()
Override to have board summaries for AIs automatically generated.


didStartup

protected void didStartup()
Overrides:
didStartup in class GameManager

gameWillStart

protected void gameWillStart()
Description copied from class: GameManager
Called when the game is about to start, but before the game start notification has been delivered to the players. Derived classes should override this if they need to perform some pre-start activities, but should be sure to call super.gameWillStart().

Overrides:
gameWillStart in class GameManager

getStatusInterval

protected long getStatusInterval()
Returns the frequency with which puzzle status updates are broadcast to the players (which is accomplished via a call to sendStatusUpdate() which in turn calls updateStatus() wherein derived classes can participate in the status update). Returning O (the default) indicates that a periodic status update is not desired.


computeDifficulty

protected int computeDifficulty()
When a puzzle game starts, the manager is given the opportunity to configure the puzzle difficulty based on information known about the player. Additionally, when the game resets due to the player clearing the board, etc. this will be called again, so the difficulty can be ramped up as the player progresses. In situations where ratings and experience are tracked, the difficulty can be seeded based on the players prior performance.


gameDidStart

protected void gameDidStart()
Description copied from class: GameManager
Called after the game start notification was dispatched. Derived classes can override this to put whatever wheels they might need into motion now that the game is started (if anything other than transitioning the game to GameObject.IN_PLAY is necessary), but should be sure to call super.gameDidStart().

Overrides:
gameDidStart in class GameManager

sendStatusUpdate

protected void sendStatusUpdate()
Updates (in one puzzle object transaction) all periodically updated status information.


updateStatus

protected void updateStatus()
A puzzle periodically (default of once every 5 seconds but configurable by puzzle) updates status information that is visible to the user. Derived classes can override this method and effect their updates by generating events on the puzzle object and they will be packaged into the update transaction.


systemMessage

protected void systemMessage(String msg)
Send a system message with the puzzle bundle.


systemMessage

protected void systemMessage(String msg,
                             boolean waitForStart)
Send a system message with the puzzle bundle.

Parameters:
waitForStart - if true, the message will not be sent until the game has started.

initBoards

protected void initBoards()
Creates and initializes boards and board summaries (if desired per needsBoardSummaries()) for each player.


needsPlayerBoard

protected boolean needsPlayerBoard(int pidx)
Returns whether this puzzle needs a board for the given player index. The default implementation only creates boards for occupied player slots. Derived classes may wish to override this method if they have specialized board needs, e.g., they need only a single board for all players.


gameDidEnd

protected void gameDidEnd()
Description copied from class: GameManager
Called after the game has transitioned to the GameObject.GAME_OVER state. Derived classes should override this to perform any post-game activities, but should be sure to call super.gameDidEnd().

Overrides:
gameDidEnd in class GameManager

didShutdown

protected void didShutdown()
Overrides:
didShutdown in class GameManager

applyProgressEvents

protected void applyProgressEvents(int pidx,
                                   int[] gevents,
                                   Board[] states)
Applies progress updates received from the client. If puzzle debugging is enabled, this also compares the client board dumps provided along with each puzzle event.


compareBoards

protected void compareBoards(int pidx,
                             Board boardstate,
                             int gevent,
                             boolean before)
Compare our server board to the specified sent-back user board.


applyProgressEvent

protected boolean applyProgressEvent(int pidx,
                                     int gevent,
                                     Board cboard)
Called by updateProgress(com.threerings.presents.data.ClientObject, int, int[]) to give the server a chance to apply each game event received from the client to the respective player's server-side board and, someday, confirm their validity. Derived classes that make use of the progress updating functionality should be sure to override this method to perform their game-specific event application antics. They should first perform a call to super() to see if the event is handled there.

Parameters:
pidx - the player index that submitted the progress event.
gevent - the progress event itself.
cboard - a snapshot of the board on the client if the client has board syncing enabled (which is only enabled when debugging).
Returns:
true to indicate that the event was handled.

assignWinners

protected void assignWinners(boolean[] winners)
Overrides the game manager implementation to mark all active players as winners. Derived classes may wish to override this method in order to customize the winning conditions.

Overrides:
assignWinners in class GameManager

newBoard

protected abstract Board newBoard(int pidx)
Creates and returns a new starting board for the given player.


newBoardSummary

protected abstract BoardSummary newBoardSummary(Board board)
Creates and returns a new board summary for the given board. Puzzles that do not make use of board summaries should implement this method and return null.


updateProgress

public void updateProgress(ClientObject caller,
                           int sessionId,
                           int[] events)
Description copied from interface: PuzzleGameProvider
Handles a PuzzleGameService.updateProgress(int, int[]) request.

Specified by:
updateProgress in interface PuzzleGameProvider

updateProgressSync

public void updateProgressSync(ClientObject caller,
                               int sessionId,
                               int[] events,
                               Board[] states)
Called when the puzzle manager receives a progress update. It checks to make sure that the progress update is valid and the puzzle is still in play and then applies the updates via applyProgressEvents(int, int[], com.threerings.puzzle.data.Board[]).

Specified by:
updateProgressSync in interface PuzzleGameProvider

tick

protected void tick(long tickStamp)
Description copied from class: GameManager
Gives game managers an opportunity to perform periodic processing that is not driven by events generated by the player.

Overrides:
tick in class GameManager

checkForInactivity

protected boolean checkForInactivity()
Returns whether checkPlayerActivity(long, int) should be called periodically while the game is in play to make sure players are still active.


checkPlayerActivity

protected void checkPlayerActivity(long tickStamp,
                                   int pidx)
Called periodically for each human player to give puzzles a chance to make sure all such players are engaging in reasonable levels of activity. The default implementation does naught.