New service group world order. My enthusiasm for widening is being stretched.

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@177 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Michael Bayne
2007-02-11 01:37:46 +00:00
parent 61d8f478e1
commit 75b34c6bf6
16 changed files with 287 additions and 353 deletions
@@ -423,10 +423,8 @@ public class EZGameManager extends GameManager
super.didStartup();
_gameObj = (EZGameObject) _plobj;
_gameObj.setEzGameService(
(EZGameMarshaller) CrowdServer.invmgr.registerDispatcher(
new EZGameDispatcher(this), false));
(EZGameMarshaller) CrowdServer.invmgr.registerDispatcher(new EZGameDispatcher(this)));
if (isPartyGame()) {
startGame();
@@ -72,6 +72,12 @@ public class ClientController extends Controller
return false;
}
// documentation inherited
public void clientWillLogon (Client client)
{
// nada
}
// documentation inherited
public void clientDidLogon (Client client)
{
@@ -148,6 +148,12 @@ public class LogonPanel extends JPanel
}
}
// documentation inherited from interface
public void clientWillLogon (Client client)
{
// nada
}
// documentation inherited from interface
public void clientDidLogon (Client client)
{
@@ -164,6 +170,7 @@ public class LogonPanel extends JPanel
// documentation inherited from interface
public void clientDidClear (Client client)
{
// nada
}
// documentation inherited from interface
@@ -26,6 +26,7 @@ import com.samskivert.util.*;
import com.threerings.util.StreamableArrayList;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.data.InvocationCodes;
import com.threerings.presents.server.InvocationManager;
import com.threerings.crowd.data.BodyObject;
@@ -37,13 +38,12 @@ import com.threerings.micasa.server.MiCasaConfig;
import com.threerings.micasa.server.MiCasaServer;
/**
* The lobby registry is the primary class that coordinates the lobby
* services on the client. It sets up the necessary invocation services
* and keeps track of the lobbies in operation on the server. Only one
* lobby registry should be created on a server.
* The lobby registry is the primary class that coordinates the lobby services on the client. It
* sets up the necessary invocation services and keeps track of the lobbies in operation on the
* server. Only one lobby registry should be created on a server.
*
* <p> Presently, the lobby registry is configured with lobbies via the
* server configuration. An example configuration follows:
* <p> Presently, the lobby registry is configured with lobbies via the server configuration. An
* example configuration follows:
*
* <pre>
* lobby_ids = foolobby, barlobby, bazlobby
@@ -60,16 +60,13 @@ import com.threerings.micasa.server.MiCasaServer;
* ...
* </pre>
*
* This information will be loaded from the MiCasa server configuration
* which means that it should live in
* <code>rsrc/config/micasa/server.properties</code> somwhere in the
* classpath where it will override the default MiCasa server properties
* file.
* This information will be loaded from the MiCasa server configuration which means that it should
* live in <code>rsrc/config/micasa/server.properties</code> somwhere in the classpath where it
* will override the default MiCasa server properties file.
*
* <p> The <code>UGI</code> or universal game identifier is a string that
* is used to uniquely identify every type of game and also to classify it
* according to meaningful keywords. It is best described with a few
* examples:
* <p> The <code>UGI</code> or universal game identifier is a string that is used to uniquely
* identify every type of game and also to classify it according to meaningful keywords. It is best
* described with a few examples:
*
* <pre>
* backgammon,board,strategy
@@ -77,29 +74,28 @@ import com.threerings.micasa.server.MiCasaServer;
* yahtzee,dice
* </pre>
*
* As you can see, a UGI should start with an identifier uniquely
* identifying the type of game and can be followed by a list of keywords
* that classify it as a member of a particular category of games
* (eg. board, card, dice, partner game, strategy game). A game can belong
* to multiple categories.
* As you can see, a UGI should start with an identifier uniquely identifying the type of game and
* can be followed by a list of keywords that classify it as a member of a particular category of
* games (eg. board, card, dice, partner game, strategy game). A game can belong to multiple
* categories.
*
* <p> As long as the UGIs in use by a particular server make some kind of
* sense, the client will be able to use them to search for lobbies
* containing games of similar types using the provided facilities.
* <p> As long as the UGIs in use by a particular server make some kind of sense, the client will
* be able to use them to search for lobbies containing games of similar types using the provided
* facilities.
*/
public class LobbyRegistry
implements LobbyProvider
{
/**
* Initializes the registry. It will use the supplied configuration
* instance to determine which lobbies to load, etc.
* Initializes the registry. It will use the supplied configuration instance to determine which
* lobbies to load, etc.
*
* @param invmgr a reference to the server's invocation manager.
*/
public void init (InvocationManager invmgr)
{
// register ourselves as an invocation service handler
invmgr.registerDispatcher(new LobbyDispatcher(this), true);
invmgr.registerDispatcher(new LobbyDispatcher(this), InvocationCodes.GLOBAL_GROUP);
// create our lobby managers
String[] lmgrs = null;
@@ -124,8 +120,8 @@ public class LobbyRegistry
}
/**
* Extracts the properties for a lobby from the server config and
* creates and initializes the lobby manager.
* Extracts the properties for a lobby from the server config and creates and initializes the
* lobby manager.
*/
protected void loadLobby (String lobbyId)
{
@@ -136,42 +132,33 @@ public class LobbyRegistry
// get the lobby manager class and UGI
String cfgClass = props.getProperty("config");
if (StringUtil.isBlank(cfgClass)) {
throw new Exception("Missing 'config' definition in " +
"lobby configuration.");
throw new Exception("Missing 'config' definition in lobby configuration.");
}
// create and initialize the lobby config object
LobbyConfig config = (LobbyConfig)
Class.forName(cfgClass).newInstance();
LobbyConfig config = (LobbyConfig)Class.forName(cfgClass).newInstance();
config.init(props);
// create and initialize the lobby manager. it will call
// lobbyReady() when it has obtained a reference to its lobby
// object and is ready to roll
LobbyManager lobmgr = (LobbyManager)
MiCasaServer.plreg.createPlace(config);
// create and initialize the lobby manager. it will call lobbyReady() when it has
// obtained a reference to its lobby object and is ready to roll
LobbyManager lobmgr = (LobbyManager)MiCasaServer.plreg.createPlace(config);
lobmgr.init(this, props);
} catch (Exception e) {
Log.warning("Unable to create lobby manager " +
"[lobbyId=" + lobbyId + ", error=" + e + "].");
Log.warning("Unable to create lobby manager [lobbyId=" + lobbyId +
", error=" + e + "].");
}
}
/**
* Returns information about all lobbies hosting games in the
* specified category.
* Returns information about all lobbies hosting games in the specified category.
*
* @param requester the body object of the client requesting the lobby
* list (which can be used to filter the list based on their
* capabilities).
* @param category the category of game for which the lobbies are
* desired.
* @param target the list into which the matching lobbies will be
* deposited.
* @param requester the body object of the client requesting the lobby list (which can be used
* to filter the list based on their capabilities).
* @param category the category of game for which the lobbies are desired.
* @param target the list into which the matching lobbies will be deposited.
*/
public void getLobbies (BodyObject requester, String category,
List target)
public void getLobbies (BodyObject requester, String category, List target)
{
ArrayList list = (ArrayList)_lobbies.get(category);
if (list != null) {
@@ -180,18 +167,16 @@ public class LobbyRegistry
}
/**
* Returns an array containing the category identifiers of all the
* categories in which lobbies have been registered with the registry.
* Returns an array containing the category identifiers of all the categories in which lobbies
* have been registered with the registry.
*
* @param requester the body object of the client requesting the
* cateogory list (which can be used to filter the list based on their
* capabilities).
* @param requester the body object of the client requesting the cateogory list (which can be
* used to filter the list based on their capabilities).
*/
public String[] getCategories (BodyObject requester)
{
// might want to cache this some day so that we don't recreate it
// every time someone wants it. we can cache the array until the
// category count changes
// might want to cache this some day so that we don't recreate it every time someone wants
// it. we can cache the array until the category count changes
String[] cats = new String[_lobbies.size()];
Iterator iter = _lobbies.keySet().iterator();
for (int i = 0; iter.hasNext(); i++) {
@@ -201,8 +186,8 @@ public class LobbyRegistry
}
/**
* Processes a request by the client to obtain a list of the lobby
* categories available on this server.
* Processes a request by the client to obtain a list of the lobby categories available on this
* server.
*/
public void getCategories (ClientObject caller, CategoriesListener listener)
{
@@ -210,11 +195,10 @@ public class LobbyRegistry
}
/**
* Processes a request by the client to obtain a list of lobbies
* matching the supplied category string.
* Processes a request by the client to obtain a list of lobbies matching the supplied category
* string.
*/
public void getLobbies (ClientObject caller, String category,
LobbiesListener listener)
public void getLobbies (ClientObject caller, String category, LobbiesListener listener)
{
StreamableArrayList target = new StreamableArrayList();
ArrayList list = (ArrayList)_lobbies.get(category);
@@ -225,16 +209,15 @@ public class LobbyRegistry
}
/**
* Called by our lobby managers once they have started up and are
* ready to do their lobby duties.
* Called by our lobby managers once they have started up and are ready to do their lobby
* duties.
*/
protected void lobbyReady (int placeOid, String gameIdent, String name)
{
// create a lobby record
Lobby record = new Lobby(placeOid, gameIdent, name);
// if we don't already have a default lobby, this one is the big
// winner
// if we don't already have a default lobby, this one is the big winner
if (_defLobbyOid == -1) {
_defLobbyOid = placeOid;
}
@@ -256,12 +239,11 @@ public class LobbyRegistry
_lobbies.put(category, catlist);
}
catlist.add(record);
Log.info("Registered lobby [cat=" + category +
", record=" + record + "].");
Log.info("Registered lobby [cat=" + category + ", record=" + record + "].");
}
/** A table containing references to all of our lobby records (in the
* form of category lists. */
/** A table containing references to all of our lobby records (in the form of category
* lists. */
protected HashMap _lobbies = new HashMap();
/** The oid of the default lobby. */
@@ -77,6 +77,12 @@ public class SimulatorController extends Controller
return false;
}
// documentation inherited
public void clientWillLogon (Client client)
{
// nada
}
// documentation inherited
public void clientDidLogon (Client client)
{
@@ -26,6 +26,7 @@ import java.util.ArrayList;
import com.threerings.util.Name;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.data.InvocationCodes;
import com.threerings.presents.dobj.RootDObjectManager;
import com.threerings.presents.server.ClientManager;
import com.threerings.presents.server.ClientResolutionListener;
@@ -44,26 +45,23 @@ import com.threerings.parlor.game.server.GameManager;
import com.threerings.micasa.Log;
/**
* The simulator manager is responsible for handling the simulator
* services on the server side.
* The simulator manager is responsible for handling the simulator services on the server side.
*/
public class SimulatorManager
{
/**
* Initializes the simulator manager manager. This should be called by
* the server that is making use of the simulator services on the
* single instance of simulator manager that it has created.
* Initializes the simulator manager manager. This should be called by the server that is
* making use of the simulator services on the single instance of simulator manager that it has
* created.
*
* @param invmgr a reference to the invocation manager in use by this
* server.
* @param invmgr a reference to the invocation manager in use by this server.
*/
public void init (InvocationManager invmgr, PlaceRegistry plreg,
ClientManager clmgr, RootDObjectManager omgr,
SimulatorServer simserv)
public void init (InvocationManager invmgr, PlaceRegistry plreg, ClientManager clmgr,
RootDObjectManager omgr, SimulatorServer simserv)
{
// register our simulator provider
SimulatorProvider sprov = new SimulatorProvider(this);
invmgr.registerDispatcher(new SimulatorDispatcher(sprov), true);
invmgr.registerDispatcher(new SimulatorDispatcher(sprov), InvocationCodes.GLOBAL_GROUP);
// keep these for later
_plreg = plreg;
@@ -73,19 +71,17 @@ public class SimulatorManager
}
/**
* Creates a game along with the specified number of simulant players
* and forcibly moves all players into the game room.
* Creates a game along with the specified number of simulant players and forcibly moves all
* players into the game room.
*/
public void createGame (
BodyObject source, GameConfig config, String simClass, int playerCount)
public void createGame (BodyObject source, GameConfig config, String simClass, int playerCount)
{
new CreateGameTask(source, config, simClass, playerCount);
}
public class CreateGameTask
{
public CreateGameTask (
BodyObject source, GameConfig config, String simClass,
public CreateGameTask (BodyObject source, GameConfig config, String simClass,
int playerCount)
{
// save off game request info
@@ -95,9 +91,8 @@ public class SimulatorManager
_playerCount = playerCount;
try {
// create the game manager and begin its initialization
// process. the game manager will take care of notifying the
// players that the game has been created
// create the game manager and begin its initialization process. the game manager
// will take care of notifying the players that the game has been created
// configure the game config with the player names
config.players = new Name[_playerCount];
@@ -141,8 +136,7 @@ public class SimulatorManager
}
}
public void resolutionFailed (Name username, Exception cause) {
Log.warning("Unable to create simulant body object " +
"[error=" + cause + "].");
Log.warning("Unable to create simulant body object [error=" + cause + "].");
}
};
@@ -154,8 +148,8 @@ public class SimulatorManager
}
/**
* Called when all simulant body objects are present and the
* simulants are ready to be created.
* Called when all simulant body objects are present and the simulants are ready to be
* created.
*/
protected void createSimulants ()
{
@@ -178,8 +172,8 @@ public class SimulatorManager
// give the simulant a chance to engage in place antics
sim.willEnterPlace(_gobj);
// move the simulant into the game room since they have no
// location director to move them automagically
// move the simulant into the game room since they have no location director to
// move them automagically
try {
_plreg.locprov.moveTo(bobj, _gobj.getOid());
} catch (Exception e) {
@@ -81,7 +81,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
_trickCardGame.setTrickCardGameService(
(TrickCardGameMarshaller)PresentsServer.invmgr.registerDispatcher(
new TrickCardGameDispatcher(this), false));
new TrickCardGameDispatcher(this)));
}
// Documentation inherited.
@@ -36,21 +36,19 @@ import com.threerings.parlor.game.data.GameConfig;
import com.threerings.parlor.util.ParlorContext;
/**
* The parlor director manages the client side of the game configuration
* and matchmaking processes. It is also the entity that is listening for
* game start notifications which it then dispatches the client entity
* that will actually create and display the user interface for the game
* that started.
* The parlor director manages the client side of the game configuration and matchmaking
* processes. It is also the entity that is listening for game start notifications which it then
* dispatches the client entity that will actually create and display the user interface for the
* game that started.
*/
public class ParlorDirector extends BasicDirector
implements ParlorCodes, ParlorReceiver
{
/**
* Constructs a parlor director and provides it with the parlor
* context that it can use to access the client services that it needs
* to provide its own services. Only one parlor director should be
* active in the client at one time and it should be made available
* via the parlor context.
* Constructs a parlor director and provides it with the parlor context that it can use to
* access the client services that it needs to provide its own services. Only one parlor
* director should be active in the client at one time and it should be made available via the
* parlor context.
*
* @param ctx the parlor context in use by the client.
*/
@@ -59,16 +57,13 @@ public class ParlorDirector extends BasicDirector
super(ctx);
_ctx = ctx;
// register ourselves with the invocation director as a parlor
// notification receiver
_ctx.getClient().getInvocationDirector().registerReceiver(
new ParlorDecoder(this));
// register ourselves with the invocation director as a parlor notification receiver
_ctx.getClient().getInvocationDirector().registerReceiver(new ParlorDecoder(this));
}
/**
* Sets the invitation handler, which is the entity that will be
* notified when we receive incoming invitation notifications and when
* invitations have been cancelled.
* Sets the invitation handler, which is the entity that will be notified when we receive
* incoming invitation notifications and when invitations have been cancelled.
*
* @param handler our new invitation handler.
*/
@@ -78,8 +73,8 @@ public class ParlorDirector extends BasicDirector
}
/**
* Adds the specified observer to the list of entities that are
* notified when we receive a game ready notification.
* Adds the specified observer to the list of entities that are notified when we receive a game
* ready notification.
*/
public void addGameReadyObserver (GameReadyObserver observer)
{
@@ -87,8 +82,8 @@ public class ParlorDirector extends BasicDirector
}
/**
* Removes the specified observer from the list of entities that are
* notified when we receive a game ready notification.
* Removes the specified observer from the list of entities that are notified when we receive a
* game ready notification.
*/
public void removeGameReadyObserver (GameReadyObserver observer)
{
@@ -96,24 +91,19 @@ public class ParlorDirector extends BasicDirector
}
/**
* Requests that the named user be invited to a game described by the
* supplied game config.
* Requests that the named user be invited to a game described by the supplied game config.
*
* @param invitee the user to invite.
* @param config the configuration of the game to which the user is
* being invited.
* @param observer the entity that will be notified if this invitation
* is accepted, refused or countered.
* @param config the configuration of the game to which the user is being invited.
* @param observer the entity that will be notified if this invitation is accepted, refused or
* countered.
*
* @return an invitation object that can be used to manage the
* outstanding invitation.
* @return an invitation object that can be used to manage the outstanding invitation.
*/
public Invitation invite (Name invitee, GameConfig config,
InvitationResponseObserver observer)
public Invitation invite (Name invitee, GameConfig config, InvitationResponseObserver observer)
{
// create the invitation record
Invitation invite = new Invitation(
_ctx, _pservice, invitee, config, observer);
Invitation invite = new Invitation(_ctx, _pservice, invitee, config, observer);
// submit the invitation request to the server
_pservice.invite(_ctx.getClient(), invitee, config, invite);
// and return the invitation to the caller
@@ -123,13 +113,10 @@ public class ParlorDirector extends BasicDirector
/**
* Requests that the specified single player game be started.
*
* @param config the configuration of the single player game to be
* started.
* @param listener a listener to be informed of failure if the game
* cannot be started.
* @param config the configuration of the single player game to be started.
* @param listener a listener to be informed of failure if the game cannot be started.
*/
public void startSolitaire (
GameConfig config, InvocationService.ConfirmListener listener)
public void startSolitaire (GameConfig config, InvocationService.ConfirmListener listener)
{
_pservice.startSolitaire(_ctx.getClient(), config, listener);
}
@@ -142,13 +129,6 @@ public class ParlorDirector extends BasicDirector
_pendingInvites.clear();
}
// documentation inherited
protected void fetchServices (Client client)
{
// get a handle on our parlor services
_pservice = (ParlorService)client.requireService(ParlorService.class);
}
// documentation inherited from interface
public void gameIsReady (int gameOid)
{
@@ -161,8 +141,8 @@ public class ParlorDirector extends BasicDirector
handled = grob.receivedGameReady(gameOid) || handled;
}
// if none of the observers took matters into their own hands,
// then we'll head on over to the game room ourselves
// if none of the observers took matters into their own hands, then we'll head on over to
// the game room ourselves
if (!handled) {
_ctx.getLocationDirector().moveTo(gameOid);
}
@@ -172,8 +152,7 @@ public class ParlorDirector extends BasicDirector
public void receivedInvite (int remoteId, Name inviter, GameConfig config)
{
// create an invitation record for this invitation
Invitation invite = new Invitation(
_ctx, _pservice, inviter, config, null);
Invitation invite = new Invitation(_ctx, _pservice, inviter, config, null);
invite.inviteId = remoteId;
// put it in the pending invitations table
@@ -184,22 +163,19 @@ public class ParlorDirector extends BasicDirector
_handler.invitationReceived(invite);
} catch (Exception e) {
Log.warning("Invitation handler choked on invite " +
"notification " + invite + ".");
Log.warning("Invitation handler choked on invite notification " + invite + ".");
Log.logStackTrace(e);
}
}
// documentation inherited from interface
public void receivedInviteResponse (
int remoteId, int code, Object arg)
public void receivedInviteResponse (int remoteId, int code, Object arg)
{
// look up the invitation record for this invitation
Invitation invite = (Invitation)_pendingInvites.get(remoteId);
if (invite == null) {
Log.warning("Have no record of invitation for which we " +
"received a response?! [remoteId=" + remoteId +
", code=" + code + ", arg=" + arg + "].");
Log.warning("Have no record of invitation for which we received a response?! " +
"[remoteId=" + remoteId + ", code=" + code + ", arg=" + arg + "].");
} else {
invite.receivedResponse(code, arg);
@@ -212,9 +188,22 @@ public class ParlorDirector extends BasicDirector
// TBD
}
@Override // from BasicDirector
protected void registerServices (Client client)
{
client.addServiceGroup(PARLOR_GROUP);
}
@Override // from BasicDirector
protected void fetchServices (Client client)
{
// get a handle on our parlor services
_pservice = (ParlorService)client.requireService(ParlorService.class);
}
/**
* Register a new invitation in our pending invitations table. The
* invitation will call this when it knows its invitation id.
* Register a new invitation in our pending invitations table. The invitation will call this
* when it knows its invitation id.
*/
protected void registerInvitation (Invitation invite)
{
@@ -222,8 +211,8 @@ public class ParlorDirector extends BasicDirector
}
/**
* Called by an invitation when it knows it is no longer and can be
* cleared from the pending invitations table.
* Called by an invitation when it knows it is no longer and can be cleared from the pending
* invitations table.
*/
protected void clearInvitation (Invitation invite)
{
@@ -236,15 +225,13 @@ public class ParlorDirector extends BasicDirector
/** Provides access to parlor server side services. */
protected ParlorService _pservice;
/** The entity that has registered itself to handle incoming
* invitation notifications. */
/** The entity that has registered itself to handle incoming invitation notifications. */
protected InvitationHandler _handler;
/** A table of acknowledged (but not yet accepted or refused)
* invitation requests, keyed on invitation id. */
/** A table of acknowledged (but not yet accepted or refused) invitation requests, keyed on
* invitation id. */
protected HashIntMap _pendingInvites = new HashIntMap();
/** We notify the entities on this list when we get a game ready
* notification. */
/** We notify the entities on this list when we get a game ready notification. */
protected ArrayList _grobs = new ArrayList();
}
@@ -28,6 +28,9 @@ import com.threerings.presents.data.InvocationCodes;
*/
public interface ParlorCodes extends InvocationCodes
{
/** Defines our invocation services group. */
public static final String PARLOR_GROUP = "parlor";
/** The response code for an accepted invitation. */
public static final int INVITATION_ACCEPTED = 0;
@@ -36,10 +36,9 @@ import com.threerings.parlor.game.data.GameConfig;
import com.threerings.parlor.game.server.GameManager;
/**
* The parlor manager is responsible for the parlor services in
* aggregate. This includes maintaining the registry of active games,
* handling the necessary coordination for the matchmaking services and
* anything else that falls outside the scope of an actual in-progress
* The parlor manager is responsible for the parlor services in aggregate. This includes
* maintaining the registry of active games, handling the necessary coordination for the
* matchmaking services and anything else that falls outside the scope of an actual in-progress
* game.
*/
public class ParlorManager
@@ -49,41 +48,36 @@ public class ParlorManager
public ParlorProvider parprov;
/**
* Initializes the parlor manager. This should be called by the server
* that is making use of the parlor services on the single instance of
* parlor manager that it has created.
* Initializes the parlor manager. This should be called by the server that is making use of
* the parlor services on the single instance of parlor manager that it has created.
*
* @param invmgr a reference to the invocation manager in use by this
* server.
* @param plreg a reference to the place registry to be used by the
* parlor manager when creating game places.
* @param invmgr a reference to the invocation manager in use by this server.
* @param plreg a reference to the place registry to be used by the parlor manager when
* creating game places.
*/
public void init (InvocationManager invmgr, PlaceRegistry plreg)
{
// create and register our invocation provider
parprov = new ParlorProvider(this);
invmgr.registerDispatcher(new ParlorDispatcher(parprov), true);
invmgr.registerDispatcher(new ParlorDispatcher(parprov), PARLOR_GROUP);
// keep this for later
_plreg = plreg;
}
/**
* Issues an invitation from the <code>inviter</code> to the
* <code>invitee</code> for a game as described by the supplied config
* object.
* Issues an invitation from the <code>inviter</code> to the <code>invitee</code> for a game as
* described by the supplied config object.
*
* @param inviter the player initiating the invitation.
* @param invitee the player being invited.
* @param config the configuration of the game being proposed.
*
* @return the invitation identifier for the newly created invitation
* record.
* @return the invitation identifier for the newly created invitation record.
*
* @exception InvocationException thrown if the invitation was not
* able to be processed for some reason (like the invited player has
* requested not to be disturbed). The explanation will be provided in
* the message data of the exception.
* @exception InvocationException thrown if the invitation was not able to be processed for
* some reason (like the invited player has requested not to be disturbed). The explanation
* will be provided in the message data of the exception.
*/
public int invite (BodyObject inviter, BodyObject invitee,
GameConfig config)
@@ -92,9 +86,8 @@ public class ParlorManager
// Log.info("Received invitation request [inviter=" + inviter +
// ", invitee=" + invitee + ", config=" + config + "].");
// here we should check to make sure the invitee hasn't muted the
// inviter, and that the inviter isn't shunned and all that other
// access control type stuff
// here we should check to make sure the invitee hasn't muted the inviter, and that the
// inviter isn't shunned and all that other access control type stuff
// create a new invitation record for this invitation
Invitation invite = new Invitation(inviter, invitee, config);
@@ -103,31 +96,25 @@ public class ParlorManager
_invites.put(invite.inviteId, invite);
// deliver an invite notification to the invitee
ParlorSender.sendInvite(
invitee, invite.inviteId, inviter.getVisibleName(), config);
ParlorSender.sendInvite(invitee, invite.inviteId, inviter.getVisibleName(), config);
// and let the caller know the invite id we assigned
return invite.inviteId;
}
/**
* Effects a response to an invitation (accept, refuse or counter),
* made by the specified source user with the specified arguments.
* Effects a response to an invitation (accept, refuse or counter), made by the specified
* source user with the specified arguments.
*
* @param source the body object of the user that is issuing this
* response.
* @param inviteId the identifier of the invitation to which we are
* responding.
* @param code the response code (either {@link
* #INVITATION_ACCEPTED}, {@link #INVITATION_REFUSED} or {@link
* #INVITATION_COUNTERED}).
* @param arg the argument that goes along with the response: an
* explanatory message in the case of a refusal (the empty string, not
* null, if no message was provided) or the new game configuration in
* the case of a counter-invitation.
* @param source the body object of the user that is issuing this response.
* @param inviteId the identifier of the invitation to which we are responding.
* @param code the response code (either {@link #INVITATION_ACCEPTED}, {@link
* #INVITATION_REFUSED} or {@link #INVITATION_COUNTERED}).
* @param arg the argument that goes along with the response: an explanatory message in the
* case of a refusal (the empty string, not null, if no message was provided) or the new game
* configuration in the case of a counter-invitation.
*/
public void respondToInvite (BodyObject source, int inviteId, int code,
Object arg)
public void respondToInvite (BodyObject source, int inviteId, int code, Object arg)
{
// look up the invitation
Invitation invite = (Invitation)_invites.get(inviteId);
@@ -146,23 +133,21 @@ public class ParlorManager
return;
}
// let the other user know that a response was made to this
// invitation
// let the other user know that a response was made to this invitation
ParlorSender.sendInviteResponse(
invite.inviter, invite.inviteId, code, arg);
switch (code) {
case INVITATION_ACCEPTED:
// the invitation was accepted, so we'll need to start up the
// game and get the necessary balls rolling
// the invitation was accepted, so we'll need to start up the game and get the
// necessary balls rolling
processAcceptedInvitation(invite);
// and remove the invitation from the pending table
_invites.remove(inviteId);
break;
case INVITATION_REFUSED:
// remove the invitation record from the pending table as it
// is no longer pending
// remove the invitation record from the pending table as it is no longer pending
_invites.remove(inviteId);
break;
@@ -172,9 +157,8 @@ public class ParlorManager
break;
default:
Log.warning("Requested to respond to invitation with " +
"unknown response code [source=" + source +
", invite=" + invite + ", code=" + code +
Log.warning("Requested to respond to invitation with unknown response code " +
"[source=" + source + ", invite=" + invite + ", code=" + code +
", arg=" + arg + "].");
break;
}
@@ -183,8 +167,7 @@ public class ParlorManager
/**
* Requests that an outstanding invitation be cancelled.
*
* @param source the body object of the user that is making the
* request.
* @param source the body object of the user that is making the request.
* @param inviteId the unique id of the invitation to be cancelled.
*/
public void cancelInvite (BodyObject source, int inviteId)
@@ -193,8 +176,7 @@ public class ParlorManager
}
/**
* Starts up and configures the game manager for an accepted
* invitation.
* Starts up and configures the game manager for an accepted invitation.
*/
protected void processAcceptedInvitation (Invitation invite)
{
@@ -202,25 +184,21 @@ public class ParlorManager
Log.info("Creating game manager [invite=" + invite + "].");
// configure the game config with the player info
invite.config.players = new Name[] {
invite.invitee.getVisibleName(),
invite.config.players = new Name[] { invite.invitee.getVisibleName(),
invite.inviter.getVisibleName() };
// create the game manager and begin it's initialization process;
// the game manager will take care of notifying the players that
// the game has been created
// create the game manager and begin it's initialization process; the game manager will
// take care of notifying the players that the game has been created
_plreg.createPlace(invite.config);
} catch (Exception e) {
Log.warning("Unable to create game manager [invite=" + invite +
", error=" + e + "].");
Log.warning("Unable to create game manager [invite=" + invite + ", error=" + e + "].");
Log.logStackTrace(e);
}
}
/**
* The invitation record is used by the parlor manager to keep track
* of pending invitations.
* The invitation record is used by the parlor manager to keep track of pending invitations.
*/
protected static class Invitation
{
@@ -237,11 +215,9 @@ public class ParlorManager
public GameConfig config;
/**
* Constructs a new invitation with the specified participants and
* configuration.
* Constructs a new invitation with the specified participants and configuration.
*/
public Invitation (BodyObject inviter, BodyObject invitee,
GameConfig config)
public Invitation (BodyObject inviter, BodyObject invitee, GameConfig config)
{
this.inviter = inviter;
this.invitee = invitee;
@@ -249,8 +225,8 @@ public class ParlorManager
}
/**
* Swaps the inviter and invitee which is necessary when the
* invitee responds with a counter-invitation.
* Swaps the inviter and invitee which is necessary when the invitee responds with a
* counter-invitation.
*/
public void swapControl ()
{
@@ -266,7 +242,6 @@ public class ParlorManager
/** The table of pending invitations. */
protected HashIntMap _invites = new HashIntMap();
/** A counter used to generate unique identifiers for invitation
* records. */
/** A counter used to generate unique identifiers for invitation records. */
protected static int _nextInviteId = 0;
}
@@ -188,7 +188,7 @@ public abstract class PuzzleManager extends GameManager
// create and fill in our game service object
PuzzleGameMarshaller service = (PuzzleGameMarshaller)
_invmgr.registerDispatcher(new PuzzleGameDispatcher(this), false);
_invmgr.registerDispatcher(new PuzzleGameDispatcher(this));
_puzobj.setPuzzleGameService(service);
}
@@ -248,8 +248,7 @@ public class StageSceneManager extends SpotSceneManager
// register and fill in our stage scene service
StageSceneMarshaller service = (StageSceneMarshaller)
StageServer.invmgr.registerDispatcher(
new StageSceneDispatcher(this), false);
StageServer.invmgr.registerDispatcher(new StageSceneDispatcher(this));
_ssobj.setStageSceneService(service);
}
@@ -495,6 +495,12 @@ public class SceneDirector extends BasicDirector
_sservice = null;
}
// documentation inherited from interface
protected void registerServices (Client client)
{
client.addServiceGroup(WHIRLED_GROUP);
}
// documentation inherited from interface
protected void fetchServices (Client client)
{
@@ -28,6 +28,9 @@ import com.threerings.crowd.data.LocationCodes;
*/
public interface SceneCodes extends LocationCodes
{
/** Defines our invocation services group. */
public static final String WHIRLED_GROUP = "whirled";
/** The message identifier for scene update messages. */
public static final String SCENE_UPDATE = "scene_update";
}
@@ -35,26 +35,23 @@ import com.threerings.crowd.server.PlaceRegistry;
import com.threerings.whirled.Log;
import com.threerings.whirled.data.Scene;
import com.threerings.whirled.data.SceneCodes;
import com.threerings.whirled.data.SceneModel;
import com.threerings.whirled.server.persist.SceneRepository;
import com.threerings.whirled.util.SceneFactory;
import com.threerings.whirled.util.UpdateList;
/**
* The scene registry is responsible for the management of all scenes. It
* handles interaction with the scene repository and ensures that scenes
* are loaded into memory when needed and flushed from memory when not
* needed.
* The scene registry is responsible for the management of all scenes. It handles interaction with
* the scene repository and ensures that scenes are loaded into memory when needed and flushed from
* memory when not needed.
*
* <p> The scene repository also takes care of bridging from the blocking,
* synchronous world of the scene repository to the non-blocking
* asynchronous world of the distributed object event queue. Thus its
* interfaces for accessing scenes are structured so as to not block the
* dobjmgr thread while waiting for scenes to be read from or written to
* the repository.
* <p> The scene repository also takes care of bridging from the blocking, synchronous world of the
* scene repository to the non-blocking asynchronous world of the distributed object event
* queue. Thus its interfaces for accessing scenes are structured so as to not block the dobjmgr
* thread while waiting for scenes to be read from or written to the repository.
*
* <p><em>Note:</em> All access to the scene registry should take place
* from the dobjmgr thread.
* <p><em>Note:</em> All access to the scene registry should take place from the dobjmgr thread.
*/
public class SceneRegistry
{
@@ -64,8 +61,7 @@ public class SceneRegistry
public static interface ConfigFactory
{
/**
* Creates the place config instance appropriate to the specified
* scene.
* Creates the place config instance appropriate to the specified scene.
*/
PlaceConfig createPlaceConfig (SceneModel model);
}
@@ -74,8 +70,8 @@ public class SceneRegistry
public SceneProvider sceneprov;
/**
* Constructs a scene registry, instructing it to load and store
* scenes using the supplied scene repository.
* Constructs a scene registry, instructing it to load and store scenes using the supplied
* scene repository.
*/
public SceneRegistry (InvocationManager invmgr, SceneRepository screp,
SceneFactory scfact, ConfigFactory confact)
@@ -86,14 +82,14 @@ public class SceneRegistry
// create/register a scene provider with the invocation services
sceneprov = new SceneProvider(CrowdServer.plreg.locprov, this);
invmgr.registerDispatcher(new SceneDispatcher(sceneprov), true);
invmgr.registerDispatcher(new SceneDispatcher(sceneprov), SceneCodes.WHIRLED_GROUP);
}
/**
* Fetches the scene manager assosciated with the specified scene.
*
* @return the scene manager for the specified scene or null if no
* scene manager is loaded for that scene.
* @return the scene manager for the specified scene or null if no scene manager is loaded for
* that scene.
*/
public SceneManager getSceneManager (int sceneId)
{
@@ -101,8 +97,7 @@ public class SceneRegistry
}
/**
* Returns a reference to the scene repository in use by this
* registry.
* Returns a reference to the scene repository in use by this registry.
*/
public SceneRepository getSceneRepository ()
{
@@ -110,9 +105,8 @@ public class SceneRegistry
}
/**
* Returns {@link SceneManager#where} for the specified scene or
* <code>null:sceneId</code> if no scene manager exists for that
* scene.
* Returns {@link SceneManager#where} for the specified scene or <code>null:sceneId</code> if
* no scene manager exists for that scene.
*/
public String where (int sceneId)
{
@@ -121,39 +115,35 @@ public class SceneRegistry
}
/**
* Because scenes must be loaded from the scene repository and this
* must not be done on the dobjmgr thread, the interface for resolving
* scenes requires that the entity that wishes for a scene to be
* resolved implement this callback interface so that it can be
* notified when a scene has been loaded and initialized.
* Because scenes must be loaded from the scene repository and this must not be done on the
* dobjmgr thread, the interface for resolving scenes requires that the entity that wishes for
* a scene to be resolved implement this callback interface so that it can be notified when a
* scene has been loaded and initialized.
*/
public static interface ResolutionListener
{
/**
* Called when the scene has been successfully resolved. The scene
* manager instance provided can be used to obtain a reference to
* the scene, or the scene distributed object.
* Called when the scene has been successfully resolved. The scene manager instance
* provided can be used to obtain a reference to the scene, or the scene distributed
* object.
*/
public void sceneWasResolved (SceneManager scmgr);
/**
* Called if some failure occurred in the scene resolution
* process.
* Called if some failure occurred in the scene resolution process.
*/
public void sceneFailedToResolve (int sceneId, Exception reason);
}
/**
* Requests that the specified scene be resolved, which means loaded into
* the server and initialized if the scene is not currently active. The
* supplied callback instance will be notified, on the dobjmgr thread, when
* the scene has been resolved. If the scene is already active, it will be
* notified immediately (before the call to {@link #resolveScene} returns).
* Requests that the specified scene be resolved, which means loaded into the server and
* initialized if the scene is not currently active. The supplied callback instance will be
* notified, on the dobjmgr thread, when the scene has been resolved. If the scene is already
* active, it will be notified immediately (before the call to {@link #resolveScene} returns).
*
* @param sceneId the id of the scene to resolve.
* @param target a reference to a callback instance that will be notified
* when the scene has been resolved (which may be immediately if the scene
* is already active).
* @param target a reference to a callback instance that will be notified when the scene has
* been resolved (which may be immediately if the scene is already active).
*/
public void resolveScene (int sceneId, ResolutionListener target)
{
@@ -168,37 +158,31 @@ public class SceneRegistry
Log.debug("Resolving scene [id=" + sceneId + "].");
}
// otherwise we've got to resolve the scene and call them back
// later; we can manipulate the penders table with impunity here
// because we only do so on the dobjmgr thread
// otherwise we've got to resolve the scene and call them back later; we can manipulate the
// penders table with impunity here because we only do so on the dobjmgr thread
ArrayList penders = (ArrayList)_penders.get(sceneId);
// if we're already in the process of resolving this scene, just
// add these guys to the list to be notified when it finally is
// resolved
// if we're already in the process of resolving this scene, just add these guys to the list
// to be notified when it finally is resolved
if (penders != null) {
penders.add(target);
} else {
// otherwise we've got to initiate the resolution process.
// first we create the penders list
// otherwise we've got to initiate the resolution process, create the penders list
_penders.put(sceneId, penders = new ArrayList());
penders.add(target);
// i don't like cluttering up method declarations with final
// keywords...
// i don't like cluttering up method declarations with final keywords...
final int fsceneId = sceneId;
if (Log.debug()) {
Log.debug("Invoking scene lookup [id=" + sceneId + "].");
}
// then we queue up an execution unit that'll load the scene
// and initialize it and all that
// then we queue up an execution unit that'll load the scene and initialize it etc.
WhirledServer.invoker.postUnit(new Invoker.Unit() {
// this is run on the invoker thread
public boolean invoke ()
{
public boolean invoke () {
try {
_model = _screp.loadSceneModel(fsceneId);
_updates = _screp.loadUpdates(fsceneId);
@@ -209,23 +193,19 @@ public class SceneRegistry
}
// this is run on the dobjmgr thread
public void handleResult ()
{
public void handleResult () {
if (_cause != null) {
processFailedResolution(fsceneId, _cause);
} else if (_model != null) {
processSuccessfulResolution(_model, _updates);
} else {
Log.warning("Scene loading unit finished with " +
"neither a scene nor a reason for " +
"failure!?");
Log.warning("Scene loading unit finished with neither a scene nor a " +
"reason for failure!?");
}
}
public String toString ()
{
return "SceneRegistry.SceneLoader " +
(_model == null ? "" : _model.name) +
public String toString () {
return "SceneRegistry.SceneLoader " + (_model == null ? "" : _model.name) +
"(" + fsceneId + ")";
}
@@ -242,28 +222,24 @@ public class SceneRegistry
protected void processSuccessfulResolution (
SceneModel model, final UpdateList updates)
{
// now that the scene is loaded, we can create a scene manager for
// it. that will be initialized by the place registry and when
// that is finally complete, then we can let our penders know
// what's up
// now that the scene is loaded, we can create a scene manager for it. that will be
// initialized by the place registry and when that is finally complete, then we can let our
// penders know what's up
try {
// first create our scene instance
final Scene scene = _scfact.createScene(
model, _confact.createPlaceConfig(model));
final Scene scene = _scfact.createScene(model, _confact.createPlaceConfig(model));
// now create our scene manager
CrowdServer.plreg.createPlace(scene.getPlaceConfig(),
new PlaceRegistry.PreStartupHook() {
CrowdServer.plreg.createPlace(
scene.getPlaceConfig(), new PlaceRegistry.PreStartupHook() {
public void invoke (PlaceManager pmgr) {
((SceneManager)pmgr).setSceneData(
scene, updates, SceneRegistry.this);
((SceneManager)pmgr).setSceneData(scene, updates, SceneRegistry.this);
}
});
// when the scene manager completes its startup procedings, it will
// call back to the scene registry and let us know that we can turn
// the penders loose
// when the scene manager completes its startup procedings, it will call back to the
// scene registry and let us know that we can turn the penders loose
} catch (Exception e) {
// so close, but no cigar
@@ -276,8 +252,7 @@ public class SceneRegistry
*/
protected void processFailedResolution (int sceneId, Exception cause)
{
Log.info("Failed to resolve scene [sceneId=" + sceneId +
", cause=" + cause + "].");
Log.info("Failed to resolve scene [sceneId=" + sceneId + ", cause=" + cause + "].");
Log.logStackTrace(cause);
// alas things didn't work out, notify our penders
@@ -296,8 +271,8 @@ public class SceneRegistry
}
/**
* Called by the scene manager once it has started up (meaning that it
* has its place object and is ready to roll).
* Called by the scene manager once it has started up (meaning that it has its place object and
* is ready to roll).
*/
protected void sceneManagerDidStart (SceneManager scmgr)
{
@@ -306,8 +281,7 @@ public class SceneRegistry
_scenemgrs.put(sceneId, scmgr);
if (Log.debug()) {
Log.debug("Registering scene manager [scid=" + sceneId +
", scmgr=" + scmgr + "].");
Log.debug("Registering scene manager [scid=" + sceneId + ", scmgr=" + scmgr + "].");
}
// now notify any penders
@@ -331,8 +305,7 @@ public class SceneRegistry
protected void unmapSceneManager (SceneManager scmgr)
{
if (_scenemgrs.remove(scmgr.getScene().getId()) == null) {
Log.warning("Requested to unmap unmapped scene manager " +
"[scmgr=" + scmgr + "].");
Log.warning("Requested to unmap unmapped scene manager [scmgr=" + scmgr + "].");
return;
}
@@ -347,8 +320,7 @@ public class SceneRegistry
/** Used to generate place configs for our scenes. */
protected ConfigFactory _confact;
/** The entity via which we create scene instances from scene
* models. */
/** The entity via which we create scene instances from scene models. */
protected SceneFactory _scfact;
/** A mapping from scene ids to scene managers. */
@@ -29,11 +29,12 @@ import com.threerings.crowd.server.PlaceRegistry;
import com.threerings.whirled.server.SceneRegistry;
import com.threerings.whirled.zone.Log;
import com.threerings.whirled.zone.data.ZoneCodes;
import com.threerings.whirled.zone.util.ZoneUtil;
/**
* The zone registry takes care of mapping zone requests to the
* appropriate registered zone manager.
* The zone registry takes care of mapping zone requests to the appropriate registered zone
* manager.
*/
public class ZoneRegistry
{
@@ -43,29 +44,25 @@ public class ZoneRegistry
/**
* Creates a zone manager with the supplied configuration.
*/
public ZoneRegistry (InvocationManager invmgr, PlaceRegistry plreg,
SceneRegistry screg)
public ZoneRegistry (InvocationManager invmgr, PlaceRegistry plreg, SceneRegistry screg)
{
// create a zone provider and register it with the invocation
// services
// create a zone provider and register it with the invocation services
zoneprov = new ZoneProvider(plreg.locprov, this, screg);
invmgr.registerDispatcher(new ZoneDispatcher(zoneprov), true);
invmgr.registerDispatcher(new ZoneDispatcher(zoneprov), ZoneCodes.WHIRLED_GROUP);
}
/**
* Registers the supplied zone manager as the manager for the
* specified zone type. Zone types are 7 bits and managers are
* responsible for making sure they don't use a zone type that
* collides with another manager (given that we have only three zone
* types at present, this doesn't seem unreasonable).
* Registers the supplied zone manager as the manager for the specified zone type. Zone types
* are 7 bits and managers are responsible for making sure they don't use a zone type that
* collides with another manager (given that we have only three zone types at present, this
* doesn't seem unreasonable).
*/
public void registerZoneManager (byte zoneType, ZoneManager manager)
{
ZoneManager old = (ZoneManager)_managers.get(zoneType);
if (old != null) {
Log.warning("Zone manager already registered with requested " +
"type [type=" + zoneType + ", old=" + old +
", new=" + manager + "].");
Log.warning("Zone manager already registered with requested type [type=" + zoneType +
", old=" + old + ", new=" + manager + "].");
} else {
_managers.put(zoneType, manager);
}
@@ -74,8 +71,7 @@ public class ZoneRegistry
/**
* Returns the zone manager that handles the specified zone id.
*
* @param qualifiedZoneId the qualified zone id for which the manager
* should be looked up.
* @param qualifiedZoneId the qualified zone id for which the manager should be looked up.
*/
public ZoneManager getZoneManager (int qualifiedZoneId)
{