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:
@@ -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.inviter.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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user