The great invocation services rethink of 2002! Rearchitected the remote
method invocation services and converted everything to the new style. Could this be my biggest checkin ever? git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1642 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -0,0 +1,191 @@
|
||||
//
|
||||
// $Id: Invitation.java,v 1.1 2002/08/14 19:07:52 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.client;
|
||||
|
||||
import com.threerings.parlor.Log;
|
||||
import com.threerings.parlor.data.ParlorCodes;
|
||||
import com.threerings.parlor.game.GameConfig;
|
||||
import com.threerings.parlor.util.ParlorContext;
|
||||
|
||||
/**
|
||||
* The invitation class is used to track information related to
|
||||
* outstanding invitations generated by or targeted to this client.
|
||||
*/
|
||||
public class Invitation
|
||||
implements ParlorCodes, ParlorService.InviteListener
|
||||
{
|
||||
/** The unique id for this invitation (as assigned by the
|
||||
* server). This is -1 until we receive an acknowledgement from
|
||||
* the server that our invitation was delivered. */
|
||||
public int inviteId = -1;
|
||||
|
||||
/** The name of the other user involved in this invitation. */
|
||||
public String opponent;
|
||||
|
||||
/** The configuration of the game to be created. */
|
||||
public GameConfig config;
|
||||
|
||||
/** Constructs a new invitation record. */
|
||||
public Invitation (ParlorContext ctx, ParlorService pservice,
|
||||
String opponent, GameConfig config,
|
||||
InvitationResponseObserver observer)
|
||||
{
|
||||
_ctx = ctx;
|
||||
_pservice = pservice;
|
||||
_observer = observer;
|
||||
this.opponent = opponent;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts this invitation.
|
||||
*/
|
||||
public void accept ()
|
||||
{
|
||||
// generate the invocation service request
|
||||
_pservice.respond(_ctx.getClient(), inviteId,
|
||||
INVITATION_ACCEPTED, null, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refuses this invitation.
|
||||
*
|
||||
* @param message the message to deliver to the inviting user
|
||||
* explaining the reason for the refusal or null if no message is to
|
||||
* be provided.
|
||||
*/
|
||||
public void refuse (String message)
|
||||
{
|
||||
// generate the invocation service request
|
||||
_pservice.respond(_ctx.getClient(), inviteId,
|
||||
INVITATION_REFUSED, message, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels this invitation.
|
||||
*/
|
||||
public void cancel ()
|
||||
{
|
||||
// if the invitation has not yet been acknowleged by the
|
||||
// server, we make a note that it should be cancelled when we
|
||||
// do receive the acknowlegement
|
||||
if (inviteId == -1) {
|
||||
_cancelled = true;
|
||||
|
||||
} else {
|
||||
// otherwise, generate the invocation service request
|
||||
_pservice.cancel(_ctx.getClient(), inviteId, this);
|
||||
// and remove it from the pending table
|
||||
_ctx.getParlorDirector().clearInvitation(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Counters this invitation with an invitation with different game
|
||||
* configuration parameters.
|
||||
*
|
||||
* @param config the updated game configuration.
|
||||
* @param observer the entity that will be notified if this
|
||||
* counter-invitation is accepted, refused or countered.
|
||||
*/
|
||||
public void counter (GameConfig config, InvitationResponseObserver observer)
|
||||
{
|
||||
// update our observer (who will eventually be hearing back from
|
||||
// the other client about their counter-invitation)
|
||||
_observer = observer;
|
||||
|
||||
// generate the invocation service request
|
||||
_pservice.respond(_ctx.getClient(), inviteId,
|
||||
INVITATION_COUNTERED, config, this);
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void inviteReceived (int inviteId)
|
||||
{
|
||||
// fill in our invitation id
|
||||
inviteId = inviteId;
|
||||
|
||||
// if the invitation was cancelled before we heard back about
|
||||
// it, we need to send off a cancellation request now
|
||||
if (_cancelled) {
|
||||
_pservice.cancel(_ctx.getClient(), inviteId, this);
|
||||
} else {
|
||||
// otherwise, put it in the pending invites table
|
||||
_ctx.getParlorDirector().registerInvitation(this);
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void requestFailed (String reason)
|
||||
{
|
||||
// let the observer know what's up
|
||||
_observer.invitationRefused(this, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the parlor director when we receive a response to an
|
||||
* invitation initiated by this client.
|
||||
*/
|
||||
protected void receivedResponse (int code, Object arg)
|
||||
{
|
||||
// make sure we have an observer to notify
|
||||
if (_observer == null) {
|
||||
Log.warning("No observer registered for invitation " +
|
||||
this + ".");
|
||||
return;
|
||||
}
|
||||
|
||||
// notify the observer
|
||||
try {
|
||||
switch (code) {
|
||||
case INVITATION_ACCEPTED:
|
||||
_observer.invitationAccepted(this);
|
||||
break;
|
||||
|
||||
case INVITATION_REFUSED:
|
||||
_observer.invitationRefused(this, (String)arg);
|
||||
break;
|
||||
|
||||
case INVITATION_COUNTERED:
|
||||
_observer.invitationCountered(this, (GameConfig)arg);
|
||||
break;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.warning("Invitation response observer choked on response " +
|
||||
"[code=" + code + ", arg=" + arg +
|
||||
", invite=" + this + "].");
|
||||
Log.logStackTrace(e);
|
||||
}
|
||||
|
||||
// unless the invitation was countered, we can remove it from the
|
||||
// pending table because it's resolved
|
||||
if (code != INVITATION_COUNTERED) {
|
||||
_ctx.getParlorDirector().clearInvitation(this);
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns a string representation of this invitation record. */
|
||||
public String toString ()
|
||||
{
|
||||
return "[inviteId=" + inviteId + ", opponent=" + opponent +
|
||||
", config=" + config + ", observer=" + _observer +
|
||||
", cancelled=" + _cancelled + "]";
|
||||
}
|
||||
|
||||
/** Provides access to client services. */
|
||||
protected ParlorContext _ctx;
|
||||
|
||||
/** Provides access to parlor services. */
|
||||
protected ParlorService _pservice;
|
||||
|
||||
/** The entity to notify when we receive a response for this
|
||||
* invitation. */
|
||||
protected InvitationResponseObserver _observer;
|
||||
|
||||
/** A flag indicating that we were requested to cancel this
|
||||
* invitation before we even heard back with an acknowledgement
|
||||
* that it was received by the server. */
|
||||
protected boolean _cancelled = false;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: InvitationHandler.java,v 1.2 2001/10/11 21:08:21 mdb Exp $
|
||||
// $Id: InvitationHandler.java,v 1.3 2002/08/14 19:07:52 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.client;
|
||||
|
||||
@@ -16,18 +16,14 @@ public interface InvitationHandler
|
||||
/**
|
||||
* Called when an invitation is received from another player.
|
||||
*
|
||||
* @param inviteId this invitation's unique id.
|
||||
* @param inviter the username of the user that sent the invitation.
|
||||
* @param config the configuration of the game to which we are being
|
||||
* invited.
|
||||
* @param invite the received invitation.
|
||||
*/
|
||||
public void invitationReceived (int inviteId, String inviter,
|
||||
GameConfig config);
|
||||
public void invitationReceived (Invitation invite);
|
||||
|
||||
/**
|
||||
* Called when an invitation is cancelled by the inviting player.
|
||||
*
|
||||
* @param inviteId this invitation's unique id.
|
||||
* @param invite the cancelled invitation.
|
||||
*/
|
||||
public void invitationCancelled (int inviteId);
|
||||
public void invitationCancelled (Invitation invite);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: InvitationResponseObserver.java,v 1.5 2001/10/11 21:08:21 mdb Exp $
|
||||
// $Id: InvitationResponseObserver.java,v 1.6 2002/08/14 19:07:52 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.client;
|
||||
|
||||
@@ -17,30 +17,27 @@ public interface InvitationResponseObserver
|
||||
/**
|
||||
* Called if the invitation was accepted.
|
||||
*
|
||||
* @param inviteId the unique id of the invitation for which we
|
||||
* received a response.
|
||||
* @param invite the invitation for which we received a response.
|
||||
*/
|
||||
public void invitationAccepted (int inviteId);
|
||||
public void invitationAccepted (Invitation invite);
|
||||
|
||||
/**
|
||||
* Called if the invitation was refused.
|
||||
*
|
||||
* @param inviteId the unique id of the invitation for which we
|
||||
* received a response.
|
||||
* @param invite the invitation for which we received a response.
|
||||
* @param message a message provided by the invited user explaining
|
||||
* the reason for their refusal, or the empty string if no message was
|
||||
* provided.
|
||||
*/
|
||||
public void invitationRefused (int inviteId, String message);
|
||||
public void invitationRefused (Invitation invite, String message);
|
||||
|
||||
/**
|
||||
* Called if the invitation was countered with an alternate game
|
||||
* configuration.
|
||||
*
|
||||
* @param inviteId the unique id of the invitation for which we
|
||||
* received a response.
|
||||
* @param invite the invitation for which we received a response.
|
||||
* @param config the game configuration proposed by the invited
|
||||
* player.
|
||||
*/
|
||||
public void invitationCountered (int inviteId, GameConfig config);
|
||||
public void invitationCountered (Invitation invite, GameConfig config);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
//
|
||||
// $Id: ParlorDecoder.java,v 1.1 2002/08/14 19:07:52 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.client;
|
||||
|
||||
import com.threerings.parlor.client.ParlorReceiver;
|
||||
import com.threerings.parlor.game.GameConfig;
|
||||
import com.threerings.presents.client.InvocationDecoder;
|
||||
|
||||
/**
|
||||
* Dispatches calls to a {@link ParlorReceiver} instance.
|
||||
*/
|
||||
public class ParlorDecoder extends InvocationDecoder
|
||||
{
|
||||
/** The generated hash code used to identify this receiver class. */
|
||||
public static final String RECEIVER_CODE = "5ef9ee0d359c42a9024498ee9aad119a";
|
||||
|
||||
/** The method id used to dispatch {@link ParlorReceiver#gameIsReady}
|
||||
* notifications. */
|
||||
public static final int GAME_IS_READY = 1;
|
||||
|
||||
/** The method id used to dispatch {@link ParlorReceiver#receivedInvite}
|
||||
* notifications. */
|
||||
public static final int RECEIVED_INVITE = 2;
|
||||
|
||||
/** The method id used to dispatch {@link ParlorReceiver#receivedInviteResponse}
|
||||
* notifications. */
|
||||
public static final int RECEIVED_INVITE_RESPONSE = 3;
|
||||
|
||||
/** The method id used to dispatch {@link ParlorReceiver#receivedInviteCancellation}
|
||||
* notifications. */
|
||||
public static final int RECEIVED_INVITE_CANCELLATION = 4;
|
||||
|
||||
/**
|
||||
* Creates a decoder that may be registered to dispatch invocation
|
||||
* service notifications to the specified receiver.
|
||||
*/
|
||||
public ParlorDecoder (ParlorReceiver receiver)
|
||||
{
|
||||
this.receiver = receiver;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public String getReceiverCode ()
|
||||
{
|
||||
return RECEIVER_CODE;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void dispatchNotification (int methodId, Object[] args)
|
||||
{
|
||||
switch (methodId) {
|
||||
case GAME_IS_READY:
|
||||
((ParlorReceiver)receiver).gameIsReady(
|
||||
((Integer)args[0]).intValue()
|
||||
);
|
||||
return;
|
||||
|
||||
case RECEIVED_INVITE:
|
||||
((ParlorReceiver)receiver).receivedInvite(
|
||||
((Integer)args[0]).intValue(), (String)args[1], (GameConfig)args[2]
|
||||
);
|
||||
return;
|
||||
|
||||
case RECEIVED_INVITE_RESPONSE:
|
||||
((ParlorReceiver)receiver).receivedInviteResponse(
|
||||
((Integer)args[0]).intValue(), ((Integer)args[1]).intValue(), (Object)args[2]
|
||||
);
|
||||
return;
|
||||
|
||||
case RECEIVED_INVITE_CANCELLATION:
|
||||
((ParlorReceiver)receiver).receivedInviteCancellation(
|
||||
((Integer)args[0]).intValue()
|
||||
);
|
||||
return;
|
||||
|
||||
default:
|
||||
super.dispatchNotification(methodId, args);
|
||||
}
|
||||
}
|
||||
|
||||
// Generated on 11:25:47 08/12/02.
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ParlorDirector.java,v 1.15 2002/04/15 16:28:02 shaper Exp $
|
||||
// $Id: ParlorDirector.java,v 1.16 2002/08/14 19:07:52 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.client;
|
||||
|
||||
@@ -7,7 +7,8 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import com.samskivert.util.HashIntMap;
|
||||
|
||||
import com.threerings.presents.client.InvocationReceiver;
|
||||
import com.threerings.presents.client.BasicDirector;
|
||||
import com.threerings.presents.client.Client;
|
||||
|
||||
import com.threerings.parlor.Log;
|
||||
import com.threerings.parlor.data.ParlorCodes;
|
||||
@@ -21,8 +22,8 @@ import com.threerings.parlor.util.ParlorContext;
|
||||
* that will actually create and display the user interface for the game
|
||||
* that started.
|
||||
*/
|
||||
public class ParlorDirector
|
||||
implements ParlorCodes, InvocationReceiver
|
||||
public class ParlorDirector extends BasicDirector
|
||||
implements ParlorCodes, ParlorReceiver
|
||||
{
|
||||
/**
|
||||
* Constructs a parlor director and provides it with the parlor
|
||||
@@ -35,12 +36,16 @@ public class ParlorDirector
|
||||
*/
|
||||
public ParlorDirector (ParlorContext ctx)
|
||||
{
|
||||
super(ctx);
|
||||
_ctx = ctx;
|
||||
|
||||
// register ourselves with the invocation director as handling
|
||||
// parlor notifications
|
||||
_ctx.getClient().getInvocationDirector().
|
||||
registerReceiver(MODULE_NAME, this);
|
||||
// register as a session observer
|
||||
_ctx.getClient().addClientObserver(this);
|
||||
|
||||
// register ourselves with the invocation director as a parlor
|
||||
// notification receiver
|
||||
_ctx.getClient().getInvocationDirector().registerReceiver(
|
||||
new ParlorDecoder(this));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,135 +88,30 @@ public class ParlorDirector
|
||||
* @param observer the entity that will be notified if this invitation
|
||||
* is accepted, refused or countered.
|
||||
*
|
||||
* @return a unique id associated with this invitation that can be
|
||||
* used to discern between various outstanding invitations by the
|
||||
* invitation observer.
|
||||
* @return an invitation object that can be used to manage the
|
||||
* outstanding invitation.
|
||||
*/
|
||||
public int invite (String invitee, GameConfig config,
|
||||
InvitationResponseObserver observer)
|
||||
public Invitation invite (String invitee, GameConfig config,
|
||||
InvitationResponseObserver observer)
|
||||
{
|
||||
// generate the invocation service request
|
||||
int invid = ParlorService.invite(
|
||||
_ctx.getClient(), invitee, config, this);
|
||||
|
||||
// create an invitation record and put it in the submitted table
|
||||
Invitation invite = new Invitation(invitee, config, observer);
|
||||
_submittedInvites.put(invid, invite);
|
||||
return invite.inviteId;
|
||||
// create the invitation record
|
||||
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
|
||||
return invite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept an invitation.
|
||||
*
|
||||
* @param inviteId the id of the invitation to accept.
|
||||
*/
|
||||
public void accept (int inviteId)
|
||||
// documentation inherited
|
||||
protected void fetchServices (Client client)
|
||||
{
|
||||
Invitation invite = getInviteByLocalId(inviteId);
|
||||
if (invite == null) {
|
||||
// complain if we didn't find a matching invitation
|
||||
Log.warning("Received request to accept non-existent " +
|
||||
"invitation [inviteId=" + inviteId + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
// generate the invocation service request
|
||||
ParlorService.respond(_ctx.getClient(), invite.remoteId,
|
||||
INVITATION_ACCEPTED, null, this);
|
||||
// get a handle on our parlor services
|
||||
_pservice = (ParlorService)client.requireService(ParlorService.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refuse an invitation.
|
||||
*
|
||||
* @param inviteId the id of the invitation to accept.
|
||||
* @param message the message to deliver to the inviting user
|
||||
* explaining the reason for the refusal or null if no message is to
|
||||
* be provided.
|
||||
*/
|
||||
public void refuse (int inviteId, String message)
|
||||
{
|
||||
Invitation invite = getInviteByLocalId(inviteId);
|
||||
if (invite == null) {
|
||||
// complain if we didn't find a matching invitation
|
||||
Log.warning("Received request to accept non-existent " +
|
||||
"invitation [inviteId=" + inviteId + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
// generate the invocation service request
|
||||
ParlorService.respond(_ctx.getClient(), invite.remoteId,
|
||||
INVITATION_REFUSED, message, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Counters a received invitation with an invitation with different
|
||||
* game configuration parameters.
|
||||
*
|
||||
* @param inviteId the id of the received invitation.
|
||||
* @param config the updated game configuration.
|
||||
* @param observer the entity that will be notified if this
|
||||
* counter-invitation is accepted, refused or countered.
|
||||
*/
|
||||
public void counter (int inviteId, GameConfig config,
|
||||
InvitationResponseObserver observer)
|
||||
{
|
||||
Invitation invite = getInviteByLocalId(inviteId);
|
||||
if (invite == null) {
|
||||
// complain if we didn't find a matching invitation
|
||||
Log.warning("Received request to counter non-existent " +
|
||||
"invitation [inviteId=" + inviteId +
|
||||
", config=" + config + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
// update the invitation record with the observer (who will
|
||||
// eventually be hearing back from the other client about their
|
||||
// counter-invitation)
|
||||
invite.observer = observer;
|
||||
|
||||
// generate the invocation service request
|
||||
ParlorService.respond(_ctx.getClient(), invite.remoteId,
|
||||
INVITATION_COUNTERED, config, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Issues a request to cancel an outstanding invitation.
|
||||
*
|
||||
* @param inviteId the id of the invitation to cancel.
|
||||
*/
|
||||
public void cancel (int inviteId)
|
||||
{
|
||||
// look up the invitation record (oh the two separate key spaces
|
||||
// humanity)
|
||||
Invitation invite = getInviteByLocalId(inviteId);
|
||||
if (invite == null) {
|
||||
// complain if we didn't find a matching invitation
|
||||
Log.warning("Received request to cancel non-existent " +
|
||||
"invitation [inviteId=" + inviteId + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
// if the invitation has not yet been acknowleged by the server,
|
||||
// we make a note that it should be cancelled when we do receive
|
||||
// the acknowlegement
|
||||
if (invite.remoteId == -1) {
|
||||
invite.cancelled = true;
|
||||
|
||||
} else {
|
||||
// otherwise, generate the invocation service request
|
||||
ParlorService.cancel(_ctx.getClient(), invite.remoteId, this);
|
||||
// and remove it from the pending table
|
||||
_pendingInvites.remove(invite.remoteId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the invocation services when a game in which we are a
|
||||
* player is ready to begin.
|
||||
*
|
||||
* @param gameOid the object id of the game object.
|
||||
*/
|
||||
public void handleGameReadyNotification (int gameOid)
|
||||
// documentation inherited from interface
|
||||
public void gameIsReady (int gameOid)
|
||||
{
|
||||
Log.info("Handling game ready [goid=" + gameOid + "].");
|
||||
|
||||
@@ -229,55 +129,31 @@ public class ParlorDirector
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the invocation services when another user has invited us
|
||||
* to play a game.
|
||||
*
|
||||
* @param remoteId the unique indentifier for this invitation (used
|
||||
* when countering or responding).
|
||||
* @param inviter the username of the inviting user.
|
||||
* @param config the configuration information for the game to which
|
||||
* we've been invited.
|
||||
*/
|
||||
public void handleInviteNotification (
|
||||
// documentation inherited from interface
|
||||
public void receivedInvite (
|
||||
int remoteId, String inviter, GameConfig config)
|
||||
{
|
||||
// create an invitation record for this invitation
|
||||
Invitation invite = new Invitation(inviter, config, null);
|
||||
invite.remoteId = remoteId;
|
||||
Invitation invite = new Invitation(
|
||||
_ctx, _pservice, inviter, config, null);
|
||||
invite.inviteId = remoteId;
|
||||
|
||||
// put it in the pending invitations table
|
||||
_pendingInvites.put(remoteId, invite);
|
||||
|
||||
try {
|
||||
// notify the invitation handler of the incoming invitation
|
||||
_handler.invitationReceived(invite.inviteId, inviter, config);
|
||||
_handler.invitationReceived(invite);
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.warning("Invitation handler choked on invite " +
|
||||
"notification [inviteId=" + invite.inviteId +
|
||||
", inviter=" + inviter +
|
||||
", config=" + config + "].");
|
||||
"notification " + invite + ".");
|
||||
Log.logStackTrace(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the invocation services when another user has responded
|
||||
* to our invitation by either accepting, refusing or countering it.
|
||||
*
|
||||
* @param remoteId the unique indentifier for the invitation.
|
||||
* @param code the response code, either {@link
|
||||
* ParlorCodes#INVITATION_ACCEPTED} or {@link
|
||||
* ParlorCodes#INVITATION_REFUSED} or {@link
|
||||
* ParlorCodes#INVITATION_COUNTERED}.
|
||||
* @param arg in the case of a refused invitation, a string
|
||||
* containing a message provided by the invited user explaining the
|
||||
* reason for refusal (the empty string if no explanation was
|
||||
* provided). In the case of a countered invitation, a new game config
|
||||
* object with the modified game configuration.
|
||||
*/
|
||||
public void handleRespondInviteNotification (
|
||||
// documentation inherited from interface
|
||||
public void receivedInviteResponse (
|
||||
int remoteId, int code, Object arg)
|
||||
{
|
||||
// look up the invitation record for this invitation
|
||||
@@ -286,226 +162,50 @@ public class ParlorDirector
|
||||
Log.warning("Have no record of invitation for which we " +
|
||||
"received a response?! [remoteId=" + remoteId +
|
||||
", code=" + code + ", arg=" + arg + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure we have an observer to notify
|
||||
if (invite.observer == null) {
|
||||
Log.warning("No observer registered for invitation " +
|
||||
invite + ".");
|
||||
return;
|
||||
}
|
||||
|
||||
// notify the observer
|
||||
try {
|
||||
switch (code) {
|
||||
case INVITATION_ACCEPTED:
|
||||
invite.observer.invitationAccepted(invite.inviteId);
|
||||
break;
|
||||
|
||||
case INVITATION_REFUSED:
|
||||
invite.observer.invitationRefused(
|
||||
invite.inviteId, (String)arg);
|
||||
break;
|
||||
|
||||
case INVITATION_COUNTERED:
|
||||
invite.observer.invitationCountered(
|
||||
invite.inviteId, (GameConfig)arg);
|
||||
break;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.warning("Invitation response observer choked on response " +
|
||||
"[code=" + code + ", arg=" + arg +
|
||||
", invite=" + invite + "].");
|
||||
Log.logStackTrace(e);
|
||||
}
|
||||
|
||||
// unless the invitation was countered, we can remove it from the
|
||||
// pending table because it's resolved
|
||||
if (code != INVITATION_COUNTERED) {
|
||||
_pendingInvites.remove(remoteId);
|
||||
} else {
|
||||
invite.receivedResponse(code, arg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the invocation services when an outstanding invitation
|
||||
* has been cancelled by the inviting user.
|
||||
*
|
||||
* @param remoteId the unique indentifier for the invitation.
|
||||
*/
|
||||
public void handleCancelInviteNotification (int remoteId)
|
||||
// documentation inherited from interface
|
||||
public void receivedInviteCancellation (int remoteId)
|
||||
{
|
||||
// TBD
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the invocation services when an invitation request was
|
||||
* received by the server and delivered to the intended invitee.
|
||||
*
|
||||
* @param invid the invocation id of the invitation request.
|
||||
* Register a new invitation in our pending invitations table. The
|
||||
* invitation will call this when it knows its invitation id.
|
||||
*/
|
||||
public void handleInviteReceived (int invid, int remoteId)
|
||||
protected void registerInvitation (Invitation invite)
|
||||
{
|
||||
// remove the invitation record from the submitted table and put
|
||||
// it in the pending table
|
||||
Invitation invite = (Invitation)_submittedInvites.remove(invid);
|
||||
if (invite == null) {
|
||||
Log.warning("Received accepted notification for non-existent " +
|
||||
"invitation request!? [invid=" + invid +
|
||||
", remoteId=" + remoteId + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
// now that we know the invitation's unique id, keep track of it
|
||||
invite.remoteId = remoteId;
|
||||
|
||||
// if the invitation was cancelled before we heard back about it,
|
||||
// we need to send off a cancellation request now
|
||||
if (invite.cancelled) {
|
||||
// generate the invocation service request to cancel it
|
||||
ParlorService.cancel(_ctx.getClient(), invite.remoteId, this);
|
||||
|
||||
} else {
|
||||
// otherwise, put it in the new table
|
||||
_pendingInvites.put(remoteId, invite);
|
||||
}
|
||||
_pendingInvites.put(invite.inviteId, invite);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the invocation services when an invitation request failed
|
||||
* or was rejected for some reason (this is different than an
|
||||
* invitation being refused by the invitee which is handled by {@link
|
||||
* #handleRespondInviteNotification}).
|
||||
*
|
||||
* @param invid the invocation id of the invitation request.
|
||||
* @param reason a reason code explaining the failure.
|
||||
* Called by an invitation when it knows it is no longer and can be
|
||||
* cleared from the pending invitations table.
|
||||
*/
|
||||
public void handleInviteFailed (int invid, String reason)
|
||||
protected void clearInvitation (Invitation invite)
|
||||
{
|
||||
Log.info("Handling invite failed [invid=" + invid +
|
||||
", reason=" + reason + "].");
|
||||
|
||||
// remove the invitation record from the submitted table and let
|
||||
// the observer know that we're hosed
|
||||
Invitation invite = (Invitation)_submittedInvites.remove(invid);
|
||||
if (invite == null) {
|
||||
Log.warning("Received failed notification for non-existent " +
|
||||
"invitation request!? [invid=" + invid +
|
||||
", reason=" + reason + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
// let the observer know what's up
|
||||
try {
|
||||
invite.observer.invitationRefused(invite.inviteId, reason);
|
||||
} catch (Exception e) {
|
||||
Log.warning("Invite observer choked on refusal notification " +
|
||||
"[invite=" + invite + ", reason=" + reason + "].");
|
||||
Log.logStackTrace(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The invitation class is used to track information related to
|
||||
* outstanding invitations generated by or targeted to this client.
|
||||
*/
|
||||
protected static class Invitation
|
||||
{
|
||||
/** A unique id for this invitation assigned on the client which
|
||||
* is only used to allow the invitation observers to discriminate
|
||||
* between multiple outstanding invitations. We'd use the remote
|
||||
* id here except that that is not known until we receive the
|
||||
* acknowlegedment from the server and we need to provide the
|
||||
* caller with some sort of unique id at the time the request is
|
||||
* generated. */
|
||||
public int inviteId = _localInvitationId++;
|
||||
|
||||
/** The unique id for this invitation (as assigned by the
|
||||
* server). This is -1 until we receive an acknowledgement from
|
||||
* the server that our invitation was delivered. */
|
||||
public int remoteId = -1;
|
||||
|
||||
/** The name of the other user involved in this invitation. */
|
||||
public String opponent;
|
||||
|
||||
/** The configuration of the game to be created. */
|
||||
public GameConfig config;
|
||||
|
||||
/** The entity to notify when we receive a response for this
|
||||
* invitation. */
|
||||
public InvitationResponseObserver observer;
|
||||
|
||||
/** A flag indicating that we were requested to cancel this
|
||||
* invitation before we even heard back with an acknowledgement
|
||||
* that it was received by the server. */
|
||||
public boolean cancelled = false;
|
||||
|
||||
/** Constructs a new invitation record. */
|
||||
public Invitation (String opponent, GameConfig config,
|
||||
InvitationResponseObserver observer)
|
||||
{
|
||||
this.opponent = opponent;
|
||||
this.config = config;
|
||||
this.observer = observer;
|
||||
}
|
||||
|
||||
/** Returns a string representation of this invitation record. */
|
||||
public String toString ()
|
||||
{
|
||||
return "[inviteId=" + inviteId + ", remoteId=" + remoteId +
|
||||
", opponent=" + opponent + ", config=" + config +
|
||||
", observer=" + observer + ", cancelled=" + cancelled + "]";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up an invitation by its local unique identifier. Oh the dual
|
||||
* uid space humanity!
|
||||
*/
|
||||
protected Invitation getInviteByLocalId (int inviteId)
|
||||
{
|
||||
// first search the pending invites which is where we're most
|
||||
// likely to find it
|
||||
Iterator iter = _pendingInvites.values().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Invitation match = (Invitation)iter.next();
|
||||
if (match.inviteId == inviteId) {
|
||||
return match;
|
||||
}
|
||||
}
|
||||
|
||||
// if that didn't work, look in the submitted invites
|
||||
iter = _submittedInvites.values().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Invitation match = (Invitation)iter.next();
|
||||
if (match.inviteId == inviteId) {
|
||||
return match;
|
||||
}
|
||||
}
|
||||
|
||||
// il n'existe pas
|
||||
return null;
|
||||
_pendingInvites.remove(invite.inviteId);
|
||||
}
|
||||
|
||||
/** An active parlor context. */
|
||||
protected ParlorContext _ctx;
|
||||
|
||||
/** Provides access to parlor server side services. */
|
||||
protected ParlorService _pservice;
|
||||
|
||||
/** The entity that has registered itself to handle incoming
|
||||
* invitation notifications. */
|
||||
protected InvitationHandler _handler;
|
||||
|
||||
/** A table of submitted (but not acknowledged) invitation requests,
|
||||
* keyed on invocation request id. */
|
||||
protected HashIntMap _submittedInvites = new HashIntMap();
|
||||
|
||||
/** A table of acknowledged (but not yet accepted or refused)
|
||||
* invitation requests, keyed on invitation id. */
|
||||
protected HashIntMap _pendingInvites = new HashIntMap();
|
||||
|
||||
/** A counter used to assign a unique id to every invitation. */
|
||||
protected static int _localInvitationId = 0;
|
||||
|
||||
/** We notify the entities on this list when we get a game ready
|
||||
* notification. */
|
||||
protected ArrayList _grobs = new ArrayList();
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// $Id: ParlorReceiver.java,v 1.1 2002/08/14 19:07:52 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.client;
|
||||
|
||||
import com.threerings.presents.client.InvocationReceiver;
|
||||
|
||||
import com.threerings.parlor.data.ParlorCodes;
|
||||
import com.threerings.parlor.game.GameConfig;
|
||||
|
||||
/**
|
||||
* Defines, for the parlor services, a set of notifications delivered
|
||||
* asynchronously by the server to the client. These are handled by the
|
||||
* {@link ParlorDirector}.
|
||||
*/
|
||||
public interface ParlorReceiver extends InvocationReceiver
|
||||
{
|
||||
/**
|
||||
* Dispatched to the client when a game in which they are a
|
||||
* participant is ready for play. The client will then enter the game
|
||||
* room which will trigger the loading of the appropriate game UI code
|
||||
* and generally get things started.
|
||||
*
|
||||
* @param gameOid the object id of the game object.
|
||||
*/
|
||||
public void gameIsReady (int gameOid);
|
||||
|
||||
/**
|
||||
* Called by the invocation services when another user has invited us
|
||||
* to play a game.
|
||||
*
|
||||
* @param remoteId the unique indentifier for this invitation (used
|
||||
* when countering or responding).
|
||||
* @param inviter the username of the inviting user.
|
||||
* @param config the configuration information for the game to which
|
||||
* we've been invited.
|
||||
*/
|
||||
public void receivedInvite (
|
||||
int remoteId, String inviter, GameConfig config);
|
||||
|
||||
/**
|
||||
* Called by the invocation services when another user has responded
|
||||
* to our invitation by either accepting, refusing or countering it.
|
||||
*
|
||||
* @param remoteId the indentifier for the invitation on question.
|
||||
* @param code the response code, either {@link
|
||||
* ParlorCodes#INVITATION_ACCEPTED} or {@link
|
||||
* ParlorCodes#INVITATION_REFUSED} or {@link
|
||||
* ParlorCodes#INVITATION_COUNTERED}.
|
||||
* @param arg in the case of a refused invitation, a string
|
||||
* containing a message provided by the invited user explaining the
|
||||
* reason for refusal (the empty string if no explanation was
|
||||
* provided). In the case of a countered invitation, a new game config
|
||||
* object with the modified game configuration.
|
||||
*/
|
||||
public void receivedInviteResponse (
|
||||
int remoteId, int code, Object arg);
|
||||
|
||||
/**
|
||||
* Called by the invocation services when an outstanding invitation
|
||||
* has been cancelled by the inviting user.
|
||||
*
|
||||
* @param remoteId the indentifier of the cancelled invitation.
|
||||
*/
|
||||
public void receivedInviteCancellation (int remoteId);
|
||||
}
|
||||
@@ -1,27 +1,33 @@
|
||||
//
|
||||
// $Id: ParlorService.java,v 1.12 2002/04/15 16:28:02 shaper Exp $
|
||||
// $Id: ParlorService.java,v 1.13 2002/08/14 19:07:52 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.client;
|
||||
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.client.InvocationDirector;
|
||||
import com.threerings.presents.client.InvocationService;
|
||||
|
||||
import com.threerings.parlor.Log;
|
||||
import com.threerings.parlor.data.ParlorCodes;
|
||||
import com.threerings.parlor.game.GameConfig;
|
||||
|
||||
/**
|
||||
* This class provides an interface to the various parlor services that
|
||||
* are directly invokable by the client (by means of the invocation
|
||||
* services). Presently these services are limited to the various
|
||||
* matchmaking mechanisms. It is unlikely that client code will want to
|
||||
* make direct use of this class, instead they would make use of the
|
||||
* programmatic interface provided by the {@link ParlorDirector}.
|
||||
*
|
||||
* @see ParlorDirector
|
||||
* Provides an interface to the various parlor invocation services.
|
||||
* Presently these services are limited to the various matchmaking
|
||||
* mechanisms. It is unlikely that client code will want to make direct
|
||||
* use of this class, instead they would make use of the programmatic
|
||||
* interface provided by the {@link ParlorDirector}.
|
||||
*/
|
||||
public class ParlorService implements ParlorCodes
|
||||
public interface ParlorService extends InvocationService
|
||||
{
|
||||
/**
|
||||
* Used to communicate responses to {@link #invite} requests.
|
||||
*/
|
||||
public static interface InviteListener extends InvocationListener
|
||||
{
|
||||
/**
|
||||
* Called in response to a successful {@link #invite} request.
|
||||
*/
|
||||
public void inviteReceived (int inviteId);
|
||||
}
|
||||
|
||||
/**
|
||||
* You probably don't want to call this directly, but want to generate
|
||||
* your invitation request via {@link ParlorDirector#invite}. Requests
|
||||
@@ -33,18 +39,10 @@ public class ParlorService implements ParlorCodes
|
||||
* @param invitee the username of the user to be invited.
|
||||
* @param config a game config object detailing the type and
|
||||
* configuration of the game to be created.
|
||||
* @param rsptgt the object reference that will receive and process
|
||||
* the response.
|
||||
*
|
||||
* @return the invocation request id of the generated request.
|
||||
* @param listener will receive and process the response.
|
||||
*/
|
||||
public static int invite (Client client, String invitee,
|
||||
GameConfig config, Object rsptgt)
|
||||
{
|
||||
InvocationDirector invdir = client.getInvocationDirector();
|
||||
Object[] args = new Object[] { invitee, config };
|
||||
return invdir.invoke(MODULE_NAME, INVITE_ID, args, rsptgt);
|
||||
}
|
||||
public void invite (Client client, String invitee, GameConfig config,
|
||||
InviteListener listener);
|
||||
|
||||
/**
|
||||
* You probably don't want to call this directly, but want to call one
|
||||
@@ -62,21 +60,10 @@ public class ParlorService implements ParlorCodes
|
||||
* the case of an invitation refusal or an updated game configuration
|
||||
* object in the case of a counter-invitation, or null in the case of
|
||||
* an accepted invitation).
|
||||
* @param rsptgt the object reference that will receive and process
|
||||
* the response.
|
||||
*
|
||||
* @return the invocation request id of the generated request.
|
||||
* @param listener will receive and process the response.
|
||||
*/
|
||||
public static int respond (Client client, int inviteId, int code,
|
||||
Object arg, Object rsptgt)
|
||||
{
|
||||
InvocationDirector invdir = client.getInvocationDirector();
|
||||
Object[] args = new Object[] {
|
||||
new Integer(inviteId), new Integer(code), null };
|
||||
// we can't have a null argument so we use the empty string
|
||||
args[2] = (arg == null) ? "" : arg;
|
||||
return invdir.invoke(MODULE_NAME, RESPOND_INVITE_ID, args, rsptgt);
|
||||
}
|
||||
public void respond (Client client, int inviteId, int code, Object arg,
|
||||
InvocationListener listener);
|
||||
|
||||
/**
|
||||
* You probably don't want to call this directly, but want to call
|
||||
@@ -86,16 +73,18 @@ public class ParlorService implements ParlorCodes
|
||||
* @param client a connected, operational client instance.
|
||||
* @param inviteId the unique id previously assigned by the server to
|
||||
* this invitation.
|
||||
* @param rsptgt the object reference that will receive and process
|
||||
* the response.
|
||||
*
|
||||
* @return the invocation request id of the generated request.
|
||||
* @param listener will receive and process the response.
|
||||
*/
|
||||
public static int cancel (Client client, int inviteId, Object rsptgt)
|
||||
public void cancel (Client client, int inviteId,
|
||||
InvocationListener listener);
|
||||
|
||||
/**
|
||||
* Used to communicate responses to {@link #createTable}, {@link
|
||||
* #joinTable}, and {@link #leaveTable} requests.
|
||||
*/
|
||||
public static interface TableListener extends InvocationListener
|
||||
{
|
||||
InvocationDirector invdir = client.getInvocationDirector();
|
||||
Object[] args = new Object[] { new Integer(inviteId) };
|
||||
return invdir.invoke(MODULE_NAME, CANCEL_INVITE_ID, args, rsptgt);
|
||||
public void tableCreated (int tableId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,18 +97,10 @@ public class ParlorService implements ParlorCodes
|
||||
* created table.
|
||||
* @param config the game config for the game to be matchmade by the
|
||||
* table.
|
||||
* @param rsptgt the object reference that will receive and process
|
||||
* the response.
|
||||
*
|
||||
* @return the invocation request id of the generated request.
|
||||
* @param listener will receive and process the response.
|
||||
*/
|
||||
public static int createTable (
|
||||
Client client, int lobbyOid, GameConfig config, Object rsptgt)
|
||||
{
|
||||
InvocationDirector invdir = client.getInvocationDirector();
|
||||
Object[] args = new Object[] { new Integer(lobbyOid), config };
|
||||
return invdir.invoke(MODULE_NAME, CREATE_TABLE_REQUEST, args, rsptgt);
|
||||
}
|
||||
public void createTable (Client client, int lobbyOid, GameConfig config,
|
||||
TableListener listener);
|
||||
|
||||
/**
|
||||
* You probably don't want to call this directly, but want to call
|
||||
@@ -132,41 +113,22 @@ public class ParlorService implements ParlorCodes
|
||||
* to be added.
|
||||
* @param position the position at the table to which this user desires
|
||||
* to be added.
|
||||
* @param rsptgt the object reference that will receive and process
|
||||
* the response.
|
||||
*
|
||||
* @return the invocation request id of the generated request.
|
||||
* @param listener will receive and process the response.
|
||||
*/
|
||||
public static int joinTable (Client client, int lobbyOid, int tableId,
|
||||
int position, Object rsptgt)
|
||||
{
|
||||
InvocationDirector invdir = client.getInvocationDirector();
|
||||
Object[] args = new Object[] { new Integer(lobbyOid),
|
||||
new Integer(tableId),
|
||||
new Integer(position) };
|
||||
return invdir.invoke(MODULE_NAME, JOIN_TABLE_REQUEST, args, rsptgt);
|
||||
}
|
||||
public void joinTable (Client client, int lobbyOid, int tableId,
|
||||
int position, InvocationListener listener);
|
||||
|
||||
/**
|
||||
* You probably don't want to call this directly, but want to call
|
||||
* {@link TableDirector#leaveTable}. Requests that the current user
|
||||
* be removed from the specified table.
|
||||
* {@link TableDirector#leaveTable}. Requests that the current user be
|
||||
* removed from the specified table.
|
||||
*
|
||||
* @param client a connected, operational client instance.
|
||||
* @param lobbyOid the oid of the lobby that contains the table.
|
||||
* @param tableId the unique id of the table from which this user
|
||||
* wishes to be removed.
|
||||
* @param rsptgt the object reference that will receive and process
|
||||
* the response.
|
||||
*
|
||||
* @return the invocation request id of the generated request.
|
||||
* @param listener will receive and process the response.
|
||||
*/
|
||||
public static int leaveTable (
|
||||
Client client, int lobbyOid, int tableId, Object rsptgt)
|
||||
{
|
||||
InvocationDirector invdir = client.getInvocationDirector();
|
||||
Object[] args = new Object[] { new Integer(lobbyOid),
|
||||
new Integer(tableId) };
|
||||
return invdir.invoke(MODULE_NAME, LEAVE_TABLE_REQUEST, args, rsptgt);
|
||||
}
|
||||
public void leaveTable (Client client, int lobbyOid, int tableId,
|
||||
InvocationListener listener);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
//
|
||||
// $Id: TableDirector.java,v 1.7 2002/04/17 18:26:29 mdb Exp $
|
||||
// $Id: TableDirector.java,v 1.8 2002/08/14 19:07:52 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.threerings.presents.client.BasicDirector;
|
||||
import com.threerings.presents.client.Client;
|
||||
|
||||
import com.threerings.presents.dobj.EntryAddedEvent;
|
||||
import com.threerings.presents.dobj.EntryUpdatedEvent;
|
||||
import com.threerings.presents.dobj.EntryRemovedEvent;
|
||||
import com.threerings.presents.dobj.EntryUpdatedEvent;
|
||||
import com.threerings.presents.dobj.SetListener;
|
||||
|
||||
import com.threerings.crowd.data.BodyObject;
|
||||
@@ -37,8 +40,8 @@ import com.threerings.parlor.util.ParlorContext;
|
||||
* lobby in which the table matchmaking takes place implements the {@link
|
||||
* TableLobbyObject} interface.
|
||||
*/
|
||||
public class TableDirector
|
||||
implements SetListener
|
||||
public class TableDirector extends BasicDirector
|
||||
implements SetListener, ParlorService.TableListener
|
||||
{
|
||||
/**
|
||||
* Creates a new table director to manage tables with the specified
|
||||
@@ -54,6 +57,8 @@ public class TableDirector
|
||||
public TableDirector (
|
||||
ParlorContext ctx, String tableField, TableObserver observer)
|
||||
{
|
||||
super(ctx);
|
||||
|
||||
// keep track of this stuff
|
||||
_ctx = ctx;
|
||||
_tableField = tableField;
|
||||
@@ -140,8 +145,7 @@ public class TableDirector
|
||||
}
|
||||
|
||||
// go ahead and issue the create request
|
||||
ParlorService.createTable(
|
||||
_ctx.getClient(), _lobby.getOid(), config, this);
|
||||
_pservice.createTable(_ctx.getClient(), _lobby.getOid(), config, this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,8 +170,8 @@ public class TableDirector
|
||||
}
|
||||
|
||||
// issue the join request
|
||||
ParlorService.joinTable(
|
||||
_ctx.getClient(), _lobby.getOid(), tableId, position, this);
|
||||
_pservice.joinTable(_ctx.getClient(), _lobby.getOid(), tableId,
|
||||
position, this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,8 +189,14 @@ public class TableDirector
|
||||
}
|
||||
|
||||
// issue the leave request
|
||||
ParlorService.leaveTable(
|
||||
_ctx.getClient(), _lobby.getOid(), tableId, this);
|
||||
_pservice.leaveTable(_ctx.getClient(), _lobby.getOid(), tableId, this);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected void fetchServices (Client client)
|
||||
{
|
||||
// get a handle on our parlor services
|
||||
_pservice = (ParlorService)client.requireService(ParlorService.class);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
@@ -234,54 +244,19 @@ public class TableDirector
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the invocation services when a table creation request was
|
||||
* received by the server and the table was successfully created.
|
||||
*
|
||||
* @param invid the invocation id of the invitation request.
|
||||
*/
|
||||
public void handleTableCreated (int invid, int tableId)
|
||||
// documentation inherited from interface
|
||||
public void tableCreated (int tableId)
|
||||
{
|
||||
// nothing much to do here
|
||||
Log.info("Table creation succeeded [tableId=" + tableId + "].");
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the invocation services when a table creation request
|
||||
* failed or was rejected for some reason.
|
||||
*
|
||||
* @param invid the invocation id of the creation request.
|
||||
* @param reason a reason code explaining the failure.
|
||||
*/
|
||||
public void handleCreateTableFailed (int invid, String reason)
|
||||
// documentation inherited from interface
|
||||
public void requestFailed (String reason)
|
||||
{
|
||||
Log.warning("Table creation failed [reason=" + reason + "].");
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the invocation services when a join table request failed
|
||||
* or was rejected for some reason.
|
||||
*
|
||||
* @param invid the invocation id of the join request.
|
||||
* @param reason a reason code explaining the failure.
|
||||
*/
|
||||
public void handleJoinTableFailed (int invid, String reason)
|
||||
{
|
||||
Log.warning("Join table failed [reason=" + reason + "].");
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the invocation services when a leave table request failed
|
||||
* or was rejected for some reason.
|
||||
*
|
||||
* @param invid the invocation id of the leave request.
|
||||
* @param reason a reason code explaining the failure.
|
||||
*/
|
||||
public void handleLeaveTableFailed (int invid, String reason)
|
||||
{
|
||||
Log.warning("Leave table failed [reason=" + reason + "].");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if we're a member of this table and notes it as our
|
||||
* table, if so.
|
||||
@@ -338,6 +313,9 @@ public class TableDirector
|
||||
/** A context by which we can access necessary client services. */
|
||||
protected ParlorContext _ctx;
|
||||
|
||||
/** Parlor server-side services. */
|
||||
protected ParlorService _pservice;
|
||||
|
||||
/** The place object in which we're currently managing tables. */
|
||||
protected PlaceObject _lobby;
|
||||
|
||||
|
||||
@@ -1,48 +1,15 @@
|
||||
//
|
||||
// $Id: ParlorCodes.java,v 1.3 2002/04/17 18:26:29 mdb Exp $
|
||||
// $Id: ParlorCodes.java,v 1.4 2002/08/14 19:07:53 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.data;
|
||||
|
||||
import com.threerings.presents.data.InvocationCodes;
|
||||
|
||||
import com.threerings.parlor.client.ParlorDirector;
|
||||
import com.threerings.parlor.client.TableDirector;
|
||||
|
||||
/**
|
||||
* Contains codes used by the parlor invocation services.
|
||||
*/
|
||||
public interface ParlorCodes extends InvocationCodes
|
||||
{
|
||||
/** The module name for the parlor services. */
|
||||
public static final String MODULE_NAME = "parlor";
|
||||
|
||||
/** The message identifier for a game ready notification. This is
|
||||
* mapped by the invocation services to a call to {@link
|
||||
* ParlorDirector#handleGameReadyNotification}. */
|
||||
public static final String GAME_READY_NOTIFICATION = "GameReady";
|
||||
|
||||
/** The message identifier for an invitation creation request or
|
||||
* notification. The notification is mapped by the invocation services
|
||||
* to a call to {@link ParlorDirector#handleInviteNotification}. */
|
||||
public static final String INVITE_ID = "Invite";
|
||||
|
||||
/** The response identifier for an accepted invite request. This is
|
||||
* mapped by the invocation services to a call to {@link
|
||||
* ParlorDirector#handleInviteReceived}. */
|
||||
public static final String INVITE_RECEIVED_RESPONSE = "InviteReceived";
|
||||
|
||||
/** The message identifier for an invitation cancellation request or
|
||||
* notification. The notification is mapped by the invocation services
|
||||
* to a call to {@link
|
||||
* ParlorDirector#handleCancelInviteNotification}. */
|
||||
public static final String CANCEL_INVITE_ID = "CancelInvite";
|
||||
|
||||
/** The message identifier for an invitation response request or
|
||||
* notification. The notification is mapped by the invocation services
|
||||
* to a call to {@link
|
||||
* ParlorDirector#handleRespondInviteNotification}. */
|
||||
public static final String RESPOND_INVITE_ID = "RespondInvite";
|
||||
|
||||
/** The response code for an accepted invitation. */
|
||||
public static final int INVITATION_ACCEPTED = 0;
|
||||
|
||||
@@ -57,20 +24,6 @@ public interface ParlorCodes extends InvocationCodes
|
||||
* received. */
|
||||
public static final String INVITEE_NOT_ONLINE = "m.invitee_not_online";
|
||||
|
||||
/** The message identifier for a create table request. */
|
||||
public static final String CREATE_TABLE_REQUEST = "CreateTable";
|
||||
|
||||
/** The response identifier for a table created response. This is
|
||||
* mapped by the invocation services to a call to {@link
|
||||
* TableDirector#handleTableCreated}. */
|
||||
public static final String TABLE_CREATED_RESPONSE = "TableCreated";
|
||||
|
||||
/** The message identifier for a join table request. */
|
||||
public static final String JOIN_TABLE_REQUEST = "JoinTable";
|
||||
|
||||
/** The message identifier for a leave table request. */
|
||||
public static final String LEAVE_TABLE_REQUEST = "LeaveTable";
|
||||
|
||||
/** An error code returned when a user requests to join a table that
|
||||
* doesn't exist. */
|
||||
public static final String NO_SUCH_TABLE = "m.no_such_table";
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
//
|
||||
// $Id: ParlorMarshaller.java,v 1.1 2002/08/14 19:07:53 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.data;
|
||||
|
||||
import com.threerings.parlor.client.ParlorService;
|
||||
import com.threerings.parlor.client.ParlorService.InviteListener;
|
||||
import com.threerings.parlor.client.ParlorService.TableListener;
|
||||
import com.threerings.parlor.game.GameConfig;
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.client.InvocationService.InvocationListener;
|
||||
import com.threerings.presents.data.InvocationMarshaller;
|
||||
import com.threerings.presents.dobj.InvocationResponseEvent;
|
||||
|
||||
/**
|
||||
* Provides the implementation of the {@link ParlorService} interface
|
||||
* that marshalls the arguments and delivers the request to the provider
|
||||
* on the server. Also provides an implementation of the response listener
|
||||
* interfaces that marshall the response arguments and deliver them back
|
||||
* to the requesting client.
|
||||
*/
|
||||
public class ParlorMarshaller extends InvocationMarshaller
|
||||
implements ParlorService
|
||||
{
|
||||
// documentation inherited
|
||||
public static class InviteMarshaller extends ListenerMarshaller
|
||||
implements InviteListener
|
||||
{
|
||||
/** The method id used to dispatch {@link #inviteReceived}
|
||||
* responses. */
|
||||
public static final int INVITE_RECEIVED = 0;
|
||||
|
||||
// documentation inherited from interface
|
||||
public void inviteReceived (int arg1)
|
||||
{
|
||||
omgr.postEvent(new InvocationResponseEvent(
|
||||
callerOid, requestId, INVITE_RECEIVED,
|
||||
new Object[] { new Integer(arg1) }));
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void dispatchResponse (int methodId, Object[] args)
|
||||
{
|
||||
switch (methodId) {
|
||||
case INVITE_RECEIVED:
|
||||
((InviteListener)listener).inviteReceived(
|
||||
((Integer)args[0]).intValue());
|
||||
return;
|
||||
|
||||
default:
|
||||
super.dispatchResponse(methodId, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public static class TableMarshaller extends ListenerMarshaller
|
||||
implements TableListener
|
||||
{
|
||||
/** The method id used to dispatch {@link #tableCreated}
|
||||
* responses. */
|
||||
public static final int TABLE_CREATED = 0;
|
||||
|
||||
// documentation inherited from interface
|
||||
public void tableCreated (int arg1)
|
||||
{
|
||||
omgr.postEvent(new InvocationResponseEvent(
|
||||
callerOid, requestId, TABLE_CREATED,
|
||||
new Object[] { new Integer(arg1) }));
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void dispatchResponse (int methodId, Object[] args)
|
||||
{
|
||||
switch (methodId) {
|
||||
case TABLE_CREATED:
|
||||
((TableListener)listener).tableCreated(
|
||||
((Integer)args[0]).intValue());
|
||||
return;
|
||||
|
||||
default:
|
||||
super.dispatchResponse(methodId, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The method id used to dispatch {@link #invite} requests. */
|
||||
public static final int INVITE = 1;
|
||||
|
||||
// documentation inherited from interface
|
||||
public void invite (Client arg1, String arg2, GameConfig arg3, InviteListener arg4)
|
||||
{
|
||||
InviteMarshaller listener4 = new InviteMarshaller();
|
||||
listener4.listener = arg4;
|
||||
sendRequest(arg1, INVITE, new Object[] {
|
||||
arg2, arg3, listener4
|
||||
});
|
||||
}
|
||||
|
||||
/** The method id used to dispatch {@link #respond} requests. */
|
||||
public static final int RESPOND = 2;
|
||||
|
||||
// documentation inherited from interface
|
||||
public void respond (Client arg1, int arg2, int arg3, Object arg4, InvocationListener arg5)
|
||||
{
|
||||
ListenerMarshaller listener5 = new ListenerMarshaller();
|
||||
listener5.listener = arg5;
|
||||
sendRequest(arg1, RESPOND, new Object[] {
|
||||
new Integer(arg2), new Integer(arg3), arg4, listener5
|
||||
});
|
||||
}
|
||||
|
||||
/** The method id used to dispatch {@link #cancel} requests. */
|
||||
public static final int CANCEL = 3;
|
||||
|
||||
// documentation inherited from interface
|
||||
public void cancel (Client arg1, int arg2, InvocationListener arg3)
|
||||
{
|
||||
ListenerMarshaller listener3 = new ListenerMarshaller();
|
||||
listener3.listener = arg3;
|
||||
sendRequest(arg1, CANCEL, new Object[] {
|
||||
new Integer(arg2), listener3
|
||||
});
|
||||
}
|
||||
|
||||
/** The method id used to dispatch {@link #createTable} requests. */
|
||||
public static final int CREATE_TABLE = 4;
|
||||
|
||||
// documentation inherited from interface
|
||||
public void createTable (Client arg1, int arg2, GameConfig arg3, TableListener arg4)
|
||||
{
|
||||
TableMarshaller listener4 = new TableMarshaller();
|
||||
listener4.listener = arg4;
|
||||
sendRequest(arg1, CREATE_TABLE, new Object[] {
|
||||
new Integer(arg2), arg3, listener4
|
||||
});
|
||||
}
|
||||
|
||||
/** The method id used to dispatch {@link #joinTable} requests. */
|
||||
public static final int JOIN_TABLE = 5;
|
||||
|
||||
// documentation inherited from interface
|
||||
public void joinTable (Client arg1, int arg2, int arg3, int arg4, InvocationListener arg5)
|
||||
{
|
||||
ListenerMarshaller listener5 = new ListenerMarshaller();
|
||||
listener5.listener = arg5;
|
||||
sendRequest(arg1, JOIN_TABLE, new Object[] {
|
||||
new Integer(arg2), new Integer(arg3), new Integer(arg4), listener5
|
||||
});
|
||||
}
|
||||
|
||||
/** The method id used to dispatch {@link #leaveTable} requests. */
|
||||
public static final int LEAVE_TABLE = 6;
|
||||
|
||||
// documentation inherited from interface
|
||||
public void leaveTable (Client arg1, int arg2, int arg3, InvocationListener arg4)
|
||||
{
|
||||
ListenerMarshaller listener4 = new ListenerMarshaller();
|
||||
listener4.listener = arg4;
|
||||
sendRequest(arg1, LEAVE_TABLE, new Object[] {
|
||||
new Integer(arg2), new Integer(arg3), listener4
|
||||
});
|
||||
}
|
||||
|
||||
// Class file generated on 00:26:01 08/11/02.
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: Table.java,v 1.10 2002/07/23 05:54:52 mdb Exp $
|
||||
// $Id: Table.java,v 1.11 2002/08/14 19:07:53 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.data;
|
||||
|
||||
@@ -237,7 +237,7 @@ public class Table
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public Object getKey ()
|
||||
public Comparable getKey ()
|
||||
{
|
||||
return tableId;
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
//
|
||||
// $Id: GameCodes.java,v 1.4 2002/04/15 16:28:02 shaper Exp $
|
||||
|
||||
package com.threerings.parlor.game;
|
||||
|
||||
import com.threerings.presents.data.InvocationCodes;
|
||||
|
||||
/**
|
||||
* Contains codes used by the game services.
|
||||
*/
|
||||
public interface GameCodes extends InvocationCodes
|
||||
{
|
||||
/** The message identifier for a player ready notification. This is
|
||||
* delivered by the game controller when the client has loaded the
|
||||
* user interface for the game and is ready to play. */
|
||||
public static final String PLAYER_READY_NOTIFICATION = "PlayerReady";
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: GameController.java,v 1.17 2002/06/18 02:35:10 shaper Exp $
|
||||
// $Id: GameController.java,v 1.18 2002/08/14 19:07:53 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.game;
|
||||
|
||||
@@ -31,7 +31,7 @@ import com.threerings.parlor.util.ParlorContext;
|
||||
* distributed object events.
|
||||
*/
|
||||
public abstract class GameController extends PlaceController
|
||||
implements AttributeChangeListener, GameCodes
|
||||
implements AttributeChangeListener
|
||||
{
|
||||
/**
|
||||
* Initializes this game controller with the game configuration that
|
||||
@@ -70,10 +70,16 @@ public abstract class GameController extends PlaceController
|
||||
// and add ourselves as a listener
|
||||
_gobj.addListener(this);
|
||||
|
||||
// finally let the game manager know that we're ready to roll
|
||||
MessageEvent mevt = new MessageEvent(
|
||||
_gobj.getOid(), PLAYER_READY_NOTIFICATION, null);
|
||||
_ctx.getDObjectManager().postEvent(mevt);
|
||||
// we don't want to claim to be finished until any derived classes
|
||||
// that overrode this method have executed, so we'll queue up a
|
||||
// runnable here that will let the game manager know that we're
|
||||
// ready on the next pass through the distributed event loop
|
||||
_ctx.getClient().getInvoker().invokeLater(new Runnable() {
|
||||
public void run () {
|
||||
// finally let the game manager know that we're ready to roll
|
||||
_gobj.service.playerReady(_ctx.getClient());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// $Id: GameDispatcher.java,v 1.1 2002/08/14 19:07:53 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.game;
|
||||
|
||||
import com.threerings.parlor.game.GameMarshaller;
|
||||
import com.threerings.parlor.game.GameService;
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import com.threerings.presents.data.InvocationMarshaller;
|
||||
import com.threerings.presents.server.InvocationDispatcher;
|
||||
import com.threerings.presents.server.InvocationException;
|
||||
|
||||
/**
|
||||
* Dispatches requests to the {@link GameProvider}.
|
||||
*/
|
||||
public class GameDispatcher extends InvocationDispatcher
|
||||
{
|
||||
/**
|
||||
* Creates a dispatcher that may be registered to dispatch invocation
|
||||
* service requests for the specified provider.
|
||||
*/
|
||||
public GameDispatcher (GameProvider provider)
|
||||
{
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public InvocationMarshaller createMarshaller ()
|
||||
{
|
||||
return new GameMarshaller();
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void dispatchRequest (
|
||||
ClientObject source, int methodId, Object[] args)
|
||||
throws InvocationException
|
||||
{
|
||||
switch (methodId) {
|
||||
case GameMarshaller.PLAYER_READY:
|
||||
((GameProvider)provider).playerReady(
|
||||
source
|
||||
|
||||
);
|
||||
return;
|
||||
|
||||
default:
|
||||
super.dispatchRequest(source, methodId, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: GameManager.java,v 1.37 2002/06/19 23:41:25 shaper Exp $
|
||||
// $Id: GameManager.java,v 1.38 2002/08/14 19:07:53 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.game;
|
||||
|
||||
@@ -7,11 +7,12 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import com.threerings.presents.dobj.AttributeChangeListener;
|
||||
import com.threerings.presents.dobj.AttributeChangedEvent;
|
||||
import com.threerings.presents.dobj.MessageEvent;
|
||||
|
||||
import com.threerings.crowd.chat.ChatProvider;
|
||||
import com.threerings.crowd.chat.SpeakProvider;
|
||||
|
||||
import com.threerings.crowd.data.BodyObject;
|
||||
import com.threerings.crowd.data.PlaceObject;
|
||||
@@ -23,6 +24,7 @@ import com.threerings.crowd.server.PlaceManagerDelegate;
|
||||
|
||||
import com.threerings.parlor.Log;
|
||||
import com.threerings.parlor.data.ParlorCodes;
|
||||
import com.threerings.parlor.server.ParlorSender;
|
||||
|
||||
/**
|
||||
* The game manager handles the server side management of a game. It
|
||||
@@ -34,34 +36,15 @@ import com.threerings.parlor.data.ParlorCodes;
|
||||
* bodies in that location.
|
||||
*/
|
||||
public class GameManager extends PlaceManager
|
||||
implements ParlorCodes, GameCodes, AttributeChangeListener
|
||||
implements ParlorCodes, GameProvider, AttributeChangeListener
|
||||
{
|
||||
// documentation inherited
|
||||
protected Class getPlaceObjectClass ()
|
||||
{
|
||||
return GameObject.class;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected void didInit ()
|
||||
{
|
||||
super.didInit();
|
||||
|
||||
// cast our configuration object (do we need to do this?)
|
||||
_gconfig = (GameConfig)_config;
|
||||
|
||||
// register our message handlers
|
||||
MessageHandler handler = new PlayerReadyHandler();
|
||||
registerMessageHandler(PLAYER_READY_NOTIFICATION, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the game manager with the supplied game configuration
|
||||
* object. This happens before startup and before the game object has
|
||||
* been created.
|
||||
* Provides the game manager with a list of the usernames of all
|
||||
* players in the game. This happens before startup and before the
|
||||
* game object has been created.
|
||||
*
|
||||
* @param players the usernames of all of the players in this game or
|
||||
* null if the game has no specific set of players.
|
||||
* a zero-length array if the game has no specific set of players.
|
||||
*/
|
||||
public void setPlayers (String[] players)
|
||||
{
|
||||
@@ -167,8 +150,9 @@ public class GameManager extends PlaceManager
|
||||
public void systemMessage (
|
||||
String msgbundle, String msg, boolean waitForStart)
|
||||
{
|
||||
if (waitForStart && ((_gameobj == null) ||
|
||||
(_gameobj.state == GameObject.AWAITING_PLAYERS))) {
|
||||
if (waitForStart &&
|
||||
((_gameobj == null) ||
|
||||
(_gameobj.state == GameObject.AWAITING_PLAYERS))) {
|
||||
// queue up the message.
|
||||
if (_startmsgs == null) {
|
||||
_startmsgs = new ArrayList();
|
||||
@@ -179,7 +163,13 @@ public class GameManager extends PlaceManager
|
||||
}
|
||||
|
||||
// otherwise, just deliver the message
|
||||
ChatProvider.sendSystemMessage(_gameobj.getOid(), msgbundle, msg);
|
||||
SpeakProvider.sendSystemSpeak(_gameobj, msgbundle, msg);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected Class getPlaceObjectClass ()
|
||||
{
|
||||
return GameObject.class;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
@@ -193,24 +183,27 @@ public class GameManager extends PlaceManager
|
||||
// stick the players into the game object
|
||||
_gameobj.setPlayers(_players);
|
||||
|
||||
// create and fill in our game service object
|
||||
GameMarshaller service = (GameMarshaller)
|
||||
_invmgr.registerDispatcher(new GameDispatcher(this), false);
|
||||
_gameobj.setService(service);
|
||||
|
||||
// let the players of this game know that we're ready to roll (if
|
||||
// we have a specific set of players)
|
||||
if (_players != null) {
|
||||
Object[] args = new Object[] {
|
||||
new Integer(_gameobj.getOid()) };
|
||||
int gameOid = _gameobj.getOid();
|
||||
for (int i = 0; i < _players.length; i++) {
|
||||
BodyObject bobj = CrowdServer.lookupBody(_players[i]);
|
||||
if (bobj == null) {
|
||||
Log.warning("Unable to deliver game ready to " +
|
||||
"non-existent player " +
|
||||
"[gameOid=" + _gameobj.getOid() +
|
||||
"[gameOid=" + gameOid +
|
||||
", player=" + _players[i] + "].");
|
||||
continue;
|
||||
}
|
||||
|
||||
// deliver a game ready notification to the player
|
||||
CrowdServer.invmgr.sendNotification(
|
||||
bobj.getOid(), MODULE_NAME, GAME_READY_NOTIFICATION, args);
|
||||
ParlorSender.gameIsReady(bobj, gameOid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -448,6 +441,35 @@ public class GameManager extends PlaceManager
|
||||
});
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void playerReady (ClientObject caller)
|
||||
{
|
||||
BodyObject plobj = (BodyObject)caller;
|
||||
|
||||
// make a note of this player's oid
|
||||
int pidx = _gameobj.getPlayerIndex(plobj.username);
|
||||
if (pidx == -1) {
|
||||
Log.warning("Received playerReady() from non-player? " +
|
||||
"[caller=" + caller + "].");
|
||||
return;
|
||||
}
|
||||
_playerOids[pidx] = plobj.getOid();
|
||||
|
||||
// and check to see if we're all set
|
||||
boolean allSet = true;
|
||||
for (int ii = 0; ii < _players.length; ii++) {
|
||||
if ((_playerOids[ii] == 0) &&
|
||||
((_AIs == null) || (_AIs[ii] == -1))) {
|
||||
allSet = false;
|
||||
}
|
||||
}
|
||||
|
||||
// if everyone is now ready to go, make a note of it
|
||||
if (allSet) {
|
||||
playersAllHere();
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void attributeChanged (AttributeChangedEvent event)
|
||||
{
|
||||
@@ -463,39 +485,6 @@ public class GameManager extends PlaceManager
|
||||
}
|
||||
}
|
||||
|
||||
/** Handles player ready notifications. */
|
||||
protected class PlayerReadyHandler implements MessageHandler
|
||||
{
|
||||
public void handleEvent (MessageEvent event, PlaceManager pmgr)
|
||||
{
|
||||
int cloid = event.getSourceOid();
|
||||
BodyObject body = (BodyObject)CrowdServer.omgr.getObject(cloid);
|
||||
if (body == null) {
|
||||
Log.warning("Player sent am ready notification and then " +
|
||||
"disappeared [event=" + event + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
// make a note of this player's oid and check to see if we're
|
||||
// all set at the same time
|
||||
boolean allSet = true;
|
||||
for (int i = 0; i < _players.length; i++) {
|
||||
if (_players[i].equals(body.username)) {
|
||||
_playerOids[i] = body.getOid();
|
||||
}
|
||||
if ((_playerOids[i] == 0) &&
|
||||
((_AIs == null) || (_AIs[i] == -1))) {
|
||||
allSet = false;
|
||||
}
|
||||
}
|
||||
|
||||
// if everyone is now ready to go, make a note of it
|
||||
if (allSet) {
|
||||
playersAllHere();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A helper operation to distribute AI ticks to our delegates.
|
||||
*/
|
||||
@@ -515,9 +504,6 @@ public class GameManager extends PlaceManager
|
||||
protected byte _level;
|
||||
}
|
||||
|
||||
/** A reference to our game configuration. */
|
||||
protected GameConfig _gconfig;
|
||||
|
||||
/** A reference to our game object. */
|
||||
protected GameObject _gameobj;
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// $Id: GameMarshaller.java,v 1.1 2002/08/14 19:07:53 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.game;
|
||||
|
||||
import com.threerings.parlor.game.GameService;
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.data.InvocationMarshaller;
|
||||
import com.threerings.presents.dobj.InvocationResponseEvent;
|
||||
|
||||
/**
|
||||
* Provides the implementation of the {@link GameService} interface
|
||||
* that marshalls the arguments and delivers the request to the provider
|
||||
* on the server. Also provides an implementation of the response listener
|
||||
* interfaces that marshall the response arguments and deliver them back
|
||||
* to the requesting client.
|
||||
*/
|
||||
public class GameMarshaller extends InvocationMarshaller
|
||||
implements GameService
|
||||
{
|
||||
/** The method id used to dispatch {@link #playerReady} requests. */
|
||||
public static final int PLAYER_READY = 1;
|
||||
|
||||
// documentation inherited from interface
|
||||
public void playerReady (Client arg1)
|
||||
{
|
||||
sendRequest(arg1, PLAYER_READY, new Object[] {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
// Class file generated on 00:26:01 08/11/02.
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: GameObject.dobj,v 1.10 2002/08/09 23:34:10 shaper Exp $
|
||||
// $Id: GameObject.dobj,v 1.11 2002/08/14 19:07:53 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.game;
|
||||
|
||||
@@ -33,6 +33,9 @@ public class GameObject extends PlaceObject
|
||||
/** A game state constant indicating that the game was cancelled. */
|
||||
public static final int CANCELLED = GAME_OVER+3;
|
||||
|
||||
/** Provides general game invocation services. */
|
||||
public GameMarshaller service;
|
||||
|
||||
/** The game state, one of {@link #AWAITING_PLAYERS}, {@link #IN_PLAY},
|
||||
* {@link #GAME_OVER}, or {@link #CANCELLED}. */
|
||||
public int state;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: GameObject.java,v 1.5 2002/08/09 23:34:10 shaper Exp $
|
||||
// $Id: GameObject.java,v 1.6 2002/08/14 19:07:53 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.game;
|
||||
|
||||
@@ -20,6 +20,9 @@ import com.threerings.crowd.data.PlaceObject;
|
||||
*/
|
||||
public class GameObject extends PlaceObject
|
||||
{
|
||||
/** The field name of the <code>service</code> field. */
|
||||
public static final String SERVICE = "service";
|
||||
|
||||
/** The field name of the <code>state</code> field. */
|
||||
public static final String STATE = "state";
|
||||
|
||||
@@ -45,6 +48,9 @@ public class GameObject extends PlaceObject
|
||||
/** A game state constant indicating that the game was cancelled. */
|
||||
public static final int CANCELLED = GAME_OVER+3;
|
||||
|
||||
/** Provides general game invocation services. */
|
||||
public GameMarshaller service;
|
||||
|
||||
/** The game state, one of {@link #AWAITING_PLAYERS}, {@link #IN_PLAY},
|
||||
* {@link #GAME_OVER}, or {@link #CANCELLED}. */
|
||||
public int state;
|
||||
@@ -68,6 +74,20 @@ public class GameObject extends PlaceObject
|
||||
ListUtil.indexOfEqual(players, username);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the <code>service</code> field be set to the specified
|
||||
* value. The local value will be updated immediately and an event
|
||||
* will be propagated through the system to notify all listeners that
|
||||
* the attribute did change. Proxied copies of this object (on
|
||||
* clients) will apply the value change when they received the
|
||||
* attribute changed notification.
|
||||
*/
|
||||
public void setService (GameMarshaller service)
|
||||
{
|
||||
this.service = service;
|
||||
requestAttributeChange(SERVICE, service);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the <code>state</code> field be set to the specified
|
||||
* value. The local value will be updated immediately and an event
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// $Id: GameProvider.java,v 1.1 2002/08/14 19:07:53 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.game;
|
||||
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import com.threerings.presents.server.InvocationProvider;
|
||||
|
||||
/**
|
||||
* Provides access to the server-side implementation of the game
|
||||
* invocation services.
|
||||
*/
|
||||
public interface GameProvider extends InvocationProvider
|
||||
{
|
||||
/**
|
||||
* Called when the client has sent a {@link GameService#playerReady}
|
||||
* service request.
|
||||
*/
|
||||
public void playerReady (ClientObject caller);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// $Id: GameService.java,v 1.1 2002/08/14 19:07:53 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.game;
|
||||
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.client.InvocationService;
|
||||
|
||||
/**
|
||||
* Provides services used by game clients to request that actions be taken
|
||||
* by the game manager.
|
||||
*/
|
||||
public interface GameService extends InvocationService
|
||||
{
|
||||
/**
|
||||
* Lets the game manager know that the calling player is in the game
|
||||
* room and ready to play.
|
||||
*/
|
||||
public void playerReady (Client client);
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
//
|
||||
// $Id: ParlorDispatcher.java,v 1.1 2002/08/14 19:07:54 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.server;
|
||||
|
||||
import com.threerings.parlor.client.ParlorService;
|
||||
import com.threerings.parlor.client.ParlorService.InviteListener;
|
||||
import com.threerings.parlor.client.ParlorService.TableListener;
|
||||
import com.threerings.parlor.data.ParlorMarshaller;
|
||||
import com.threerings.parlor.game.GameConfig;
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.client.InvocationService.InvocationListener;
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import com.threerings.presents.data.InvocationMarshaller;
|
||||
import com.threerings.presents.server.InvocationDispatcher;
|
||||
import com.threerings.presents.server.InvocationException;
|
||||
|
||||
/**
|
||||
* Dispatches requests to the {@link ParlorProvider}.
|
||||
*/
|
||||
public class ParlorDispatcher extends InvocationDispatcher
|
||||
{
|
||||
/**
|
||||
* Creates a dispatcher that may be registered to dispatch invocation
|
||||
* service requests for the specified provider.
|
||||
*/
|
||||
public ParlorDispatcher (ParlorProvider provider)
|
||||
{
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public InvocationMarshaller createMarshaller ()
|
||||
{
|
||||
return new ParlorMarshaller();
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void dispatchRequest (
|
||||
ClientObject source, int methodId, Object[] args)
|
||||
throws InvocationException
|
||||
{
|
||||
switch (methodId) {
|
||||
case ParlorMarshaller.INVITE:
|
||||
((ParlorProvider)provider).invite(
|
||||
source,
|
||||
(String)args[0], (GameConfig)args[1], (InviteListener)args[2]
|
||||
);
|
||||
return;
|
||||
|
||||
case ParlorMarshaller.RESPOND:
|
||||
((ParlorProvider)provider).respond(
|
||||
source,
|
||||
((Integer)args[0]).intValue(), ((Integer)args[1]).intValue(), (Object)args[2], (InvocationListener)args[3]
|
||||
);
|
||||
return;
|
||||
|
||||
case ParlorMarshaller.CANCEL:
|
||||
((ParlorProvider)provider).cancel(
|
||||
source,
|
||||
((Integer)args[0]).intValue(), (InvocationListener)args[1]
|
||||
);
|
||||
return;
|
||||
|
||||
case ParlorMarshaller.CREATE_TABLE:
|
||||
((ParlorProvider)provider).createTable(
|
||||
source,
|
||||
((Integer)args[0]).intValue(), (GameConfig)args[1], (TableListener)args[2]
|
||||
);
|
||||
return;
|
||||
|
||||
case ParlorMarshaller.JOIN_TABLE:
|
||||
((ParlorProvider)provider).joinTable(
|
||||
source,
|
||||
((Integer)args[0]).intValue(), ((Integer)args[1]).intValue(), ((Integer)args[2]).intValue(), (InvocationListener)args[3]
|
||||
);
|
||||
return;
|
||||
|
||||
case ParlorMarshaller.LEAVE_TABLE:
|
||||
((ParlorProvider)provider).leaveTable(
|
||||
source,
|
||||
((Integer)args[0]).intValue(), ((Integer)args[1]).intValue(), (InvocationListener)args[2]
|
||||
);
|
||||
return;
|
||||
|
||||
default:
|
||||
super.dispatchRequest(source, methodId, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
//
|
||||
// $Id: ParlorManager.java,v 1.18 2002/04/15 16:28:02 shaper Exp $
|
||||
// $Id: ParlorManager.java,v 1.19 2002/08/14 19:07:54 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.server;
|
||||
|
||||
import com.samskivert.util.HashIntMap;
|
||||
|
||||
import com.threerings.presents.server.InvocationException;
|
||||
import com.threerings.presents.server.InvocationManager;
|
||||
import com.threerings.presents.server.ServiceFailedException;
|
||||
|
||||
import com.threerings.crowd.data.BodyObject;
|
||||
import com.threerings.crowd.server.CrowdServer;
|
||||
import com.threerings.crowd.server.PlaceRegistry;
|
||||
|
||||
import com.threerings.parlor.Log;
|
||||
import com.threerings.parlor.data.ParlorCodes;
|
||||
@@ -26,6 +26,9 @@ import com.threerings.parlor.game.GameManager;
|
||||
public class ParlorManager
|
||||
implements ParlorCodes
|
||||
{
|
||||
/** Provides the server-side implementation of the parlor services. */
|
||||
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
|
||||
@@ -33,15 +36,17 @@ public class ParlorManager
|
||||
*
|
||||
* @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)
|
||||
public void init (InvocationManager invmgr, PlaceRegistry plreg)
|
||||
{
|
||||
// register our invocation provider
|
||||
ParlorProvider pprov = new ParlorProvider(this);
|
||||
invmgr.registerProvider(MODULE_NAME, pprov);
|
||||
// create and register our invocation provider
|
||||
parprov = new ParlorProvider(this);
|
||||
invmgr.registerDispatcher(new ParlorDispatcher(parprov), true);
|
||||
|
||||
// keep this around for later
|
||||
_invmgr = invmgr;
|
||||
// keep this for later
|
||||
_plreg = plreg;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,14 +61,14 @@ public class ParlorManager
|
||||
* @return the invitation identifier for the newly created invitation
|
||||
* record.
|
||||
*
|
||||
* @exception ServiceFailedException thrown if the invitation was not
|
||||
* @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)
|
||||
throws ServiceFailedException
|
||||
throws InvocationException
|
||||
{
|
||||
// Log.info("Received invitation request [inviter=" + inviter +
|
||||
// ", invitee=" + invitee + ", config=" + config + "].");
|
||||
@@ -79,10 +84,8 @@ public class ParlorManager
|
||||
_invites.put(invite.inviteId, invite);
|
||||
|
||||
// deliver an invite notification to the invitee
|
||||
Object[] args = new Object[] {
|
||||
new Integer(invite.inviteId), inviter.username, config };
|
||||
_invmgr.sendNotification(
|
||||
invitee.getOid(), MODULE_NAME, INVITE_ID, args);
|
||||
ParlorSender.sendInvite(invitee, invite.inviteId,
|
||||
inviter.username, config);
|
||||
|
||||
// and let the caller know the invite id we assigned
|
||||
return invite.inviteId;
|
||||
@@ -126,10 +129,8 @@ public class ParlorManager
|
||||
|
||||
// let the other user know that a response was made to this
|
||||
// invitation
|
||||
Object[] args = new Object[] {
|
||||
new Integer(invite.inviteId), new Integer(code), arg };
|
||||
_invmgr.sendNotification(
|
||||
invite.inviter.getOid(), MODULE_NAME, RESPOND_INVITE_ID, args);
|
||||
ParlorSender.sendInviteResponse(
|
||||
invite.inviter, invite.inviteId, code, arg);
|
||||
|
||||
switch (code) {
|
||||
case INVITATION_ACCEPTED:
|
||||
@@ -187,7 +188,7 @@ public class ParlorManager
|
||||
// started up (which is done by the place registry once the
|
||||
// game object creation has completed)
|
||||
GameManager gmgr = (GameManager)
|
||||
CrowdServer.plreg.createPlace(invite.config, null);
|
||||
_plreg.createPlace(invite.config, null);
|
||||
|
||||
// provide the game manager with the player list
|
||||
gmgr.setPlayers(new String[] {
|
||||
@@ -242,8 +243,8 @@ public class ParlorManager
|
||||
}
|
||||
}
|
||||
|
||||
/** A reference to the invocation manager in operation on this server. */
|
||||
protected InvocationManager _invmgr;
|
||||
/** The place registry with which we operate. */
|
||||
protected PlaceRegistry _plreg;
|
||||
|
||||
/** The table of pending invitations. */
|
||||
protected HashIntMap _invites = new HashIntMap();
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
//
|
||||
// $Id: ParlorProvider.java,v 1.12 2002/04/17 18:26:30 mdb Exp $
|
||||
// $Id: ParlorProvider.java,v 1.13 2002/08/14 19:07:54 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.server;
|
||||
|
||||
import com.threerings.presents.client.InvocationService.InvocationListener;
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import com.threerings.presents.server.InvocationException;
|
||||
import com.threerings.presents.server.InvocationProvider;
|
||||
import com.threerings.presents.server.ServiceFailedException;
|
||||
|
||||
import com.threerings.crowd.data.BodyObject;
|
||||
import com.threerings.crowd.server.CrowdServer;
|
||||
import com.threerings.crowd.server.PlaceManager;
|
||||
|
||||
import com.threerings.parlor.Log;
|
||||
import com.threerings.parlor.client.ParlorService.InviteListener;
|
||||
import com.threerings.parlor.client.ParlorService.TableListener;
|
||||
import com.threerings.parlor.data.ParlorCodes;
|
||||
import com.threerings.parlor.game.GameConfig;
|
||||
|
||||
@@ -20,7 +24,7 @@ import com.threerings.parlor.game.GameConfig;
|
||||
* Primarily these are the matchmaking mechanisms.
|
||||
*/
|
||||
public class ParlorProvider
|
||||
extends InvocationProvider implements ParlorCodes
|
||||
implements InvocationProvider, ParlorCodes
|
||||
{
|
||||
/**
|
||||
* Constructs a parlor provider instance which will be used to handle
|
||||
@@ -40,82 +44,79 @@ public class ParlorProvider
|
||||
* Processes a request from the client to invite another user to play
|
||||
* a game.
|
||||
*/
|
||||
public void handleInviteRequest (
|
||||
BodyObject source, int invid, String invitee, GameConfig config)
|
||||
throws ServiceFailedException
|
||||
public void invite (ClientObject caller, String invitee,
|
||||
GameConfig config, InviteListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
// Log.info("Handling invite request [source=" + source +
|
||||
// ", invid=" + invid + ", invitee=" + invitee +
|
||||
// ", config=" + config + "].");
|
||||
// ", invitee=" + invitee + ", config=" + config + "].");
|
||||
|
||||
BodyObject source = (BodyObject)caller;
|
||||
String rsp = null;
|
||||
|
||||
// ensure that the invitee is online at present
|
||||
BodyObject target = CrowdServer.lookupBody(invitee);
|
||||
if (target == null) {
|
||||
throw new ServiceFailedException(INVITEE_NOT_ONLINE);
|
||||
throw new InvocationException(INVITEE_NOT_ONLINE);
|
||||
}
|
||||
|
||||
// submit the invite request to the parlor manager
|
||||
int inviteId = _pmgr.invite(source, target, config);
|
||||
sendResponse(source, invid, INVITE_RECEIVED_RESPONSE,
|
||||
new Integer(inviteId));
|
||||
listener.inviteReceived(inviteId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a request from the client to respond to an outstanding
|
||||
* invitation by accepting, refusing, or countering it.
|
||||
*/
|
||||
public void handleRespondInviteRequest (
|
||||
BodyObject source, int invid, int inviteId, int code, Object arg)
|
||||
public void respond (ClientObject caller, int inviteId, int code,
|
||||
Object arg, InvocationListener listener)
|
||||
{
|
||||
// pass this on to the parlor manager
|
||||
_pmgr.respondToInvite(source, inviteId, code, arg);
|
||||
_pmgr.respondToInvite((BodyObject)caller, inviteId, code, arg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a request from the client to cancel an outstanding
|
||||
* invitation.
|
||||
*/
|
||||
public void handleCancelInviteRequest (
|
||||
BodyObject source, int invid, int inviteId)
|
||||
public void cancel (ClientObject caller, int inviteId,
|
||||
InvocationListener listener)
|
||||
{
|
||||
// pass this on to the parlor manager
|
||||
_pmgr.cancelInvite(source, inviteId);
|
||||
_pmgr.cancelInvite((BodyObject)caller, inviteId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a request from the client to create a new table.
|
||||
*/
|
||||
public void handleCreateTableRequest (
|
||||
BodyObject source, int invid, int lobbyOid, GameConfig config)
|
||||
throws ServiceFailedException
|
||||
public void createTable (ClientObject caller, int lobbyOid,
|
||||
GameConfig config, TableListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
Log.info("Handling create table request [source=" + source +
|
||||
", invid=" + invid + ", lobbyOid=" + lobbyOid +
|
||||
", config=" + config + "].");
|
||||
Log.info("Handling create table request [caller=" + caller +
|
||||
", lobbyOid=" + lobbyOid + ", config=" + config + "].");
|
||||
|
||||
// pass the creation request on to the table manager
|
||||
TableManager tmgr = getTableManager(lobbyOid);
|
||||
int tableId = tmgr.createTable(source, config);
|
||||
sendResponse(source, invid, TABLE_CREATED_RESPONSE,
|
||||
new Integer(tableId));
|
||||
int tableId = tmgr.createTable((BodyObject)caller, config);
|
||||
listener.tableCreated(tableId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a request from the client to join an existing table.
|
||||
*/
|
||||
public void handleJoinTableRequest (
|
||||
BodyObject source, int invid, int lobbyOid, int tableId, int position)
|
||||
throws ServiceFailedException
|
||||
public void joinTable (ClientObject caller, int lobbyOid, int tableId,
|
||||
int position, InvocationListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
Log.info("Handling join table request [source=" + source +
|
||||
", invid=" + invid + ", lobbyOid=" + lobbyOid +
|
||||
", tableId=" + tableId + ", position=" + position + "].");
|
||||
Log.info("Handling join table request [caller=" + caller +
|
||||
", lobbyOid=" + lobbyOid + ", tableId=" + tableId +
|
||||
", position=" + position + "].");
|
||||
|
||||
// pass the join request on to the table manager
|
||||
TableManager tmgr = getTableManager(lobbyOid);
|
||||
tmgr.joinTable(source, tableId, position);
|
||||
tmgr.joinTable((BodyObject)caller, tableId, position);
|
||||
|
||||
// there is normally no success response. the client will see
|
||||
// themselves show up in the table that they joined
|
||||
@@ -124,17 +125,16 @@ public class ParlorProvider
|
||||
/**
|
||||
* Processes a request from the client to leave an existing table.
|
||||
*/
|
||||
public void handleLeaveTableRequest (
|
||||
BodyObject source, int invid, int lobbyOid, int tableId)
|
||||
throws ServiceFailedException
|
||||
public void leaveTable (ClientObject caller, int lobbyOid, int tableId,
|
||||
InvocationListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
Log.info("Handling leave table request [source=" + source +
|
||||
", invid=" + invid + ", lobbyOid=" + lobbyOid +
|
||||
", tableId=" + tableId + "].");
|
||||
Log.info("Handling leave table request [caller=" + caller +
|
||||
", lobbyOid=" + lobbyOid + ", tableId=" + tableId + "].");
|
||||
|
||||
// pass the join request on to the table manager
|
||||
TableManager tmgr = getTableManager(lobbyOid);
|
||||
tmgr.leaveTable(source, tableId);
|
||||
tmgr.leaveTable((BodyObject)caller, tableId);
|
||||
|
||||
// there is normally no success response. the client will see
|
||||
// themselves removed from the table they just left
|
||||
@@ -145,25 +145,25 @@ public class ParlorProvider
|
||||
* casts it to a table lobby manager and obtains the associated table
|
||||
* manager reference.
|
||||
*
|
||||
* @exception ServiceFailedException thrown if something goes wrong
|
||||
* @exception InvocationException thrown if something goes wrong
|
||||
* along the way like no place manager exists or the place manager
|
||||
* that does exist doesn't implement table lobby manager.
|
||||
*/
|
||||
protected TableManager getTableManager (int lobbyOid)
|
||||
throws ServiceFailedException
|
||||
throws InvocationException
|
||||
{
|
||||
PlaceManager plmgr = CrowdServer.plreg.getPlaceManager(lobbyOid);
|
||||
if (plmgr == null) {
|
||||
Log.warning("No place manager exists from which to obtain " +
|
||||
"table manager reference [ploid=" + lobbyOid + "].");
|
||||
throw new ServiceFailedException(INTERNAL_ERROR);
|
||||
throw new InvocationException(INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
// sanity check
|
||||
if (!(plmgr instanceof TableManagerProvider)) {
|
||||
Log.warning("Place manager not a table lobby manager " +
|
||||
"[plmgr=" + plmgr + "].");
|
||||
throw new ServiceFailedException(INTERNAL_ERROR);
|
||||
throw new InvocationException(INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
return ((TableManagerProvider)plmgr).getTableManager();
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
//
|
||||
// $Id: ParlorSender.java,v 1.1 2002/08/14 19:07:54 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.server;
|
||||
|
||||
import com.threerings.parlor.client.ParlorDecoder;
|
||||
import com.threerings.parlor.client.ParlorReceiver;
|
||||
import com.threerings.parlor.game.GameConfig;
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import com.threerings.presents.server.InvocationSender;
|
||||
|
||||
/**
|
||||
* Used to issue notifications to a {@link ParlorReceiver} instance on a
|
||||
* client.
|
||||
*/
|
||||
public class ParlorSender extends InvocationSender
|
||||
{
|
||||
/**
|
||||
* Issues a notification that will result in a call to {@link
|
||||
* ParlorReceiver#gameIsReady} on a client.
|
||||
*/
|
||||
public static void gameIsReady (
|
||||
ClientObject target, int arg1)
|
||||
{
|
||||
sendNotification(
|
||||
target, ParlorDecoder.RECEIVER_CODE, ParlorDecoder.GAME_IS_READY,
|
||||
new Object[] { new Integer(arg1) });
|
||||
}
|
||||
|
||||
/**
|
||||
* Issues a notification that will result in a call to {@link
|
||||
* ParlorReceiver#receivedInvite} on a client.
|
||||
*/
|
||||
public static void sendInvite (
|
||||
ClientObject target, int arg1, String arg2, GameConfig arg3)
|
||||
{
|
||||
sendNotification(
|
||||
target, ParlorDecoder.RECEIVER_CODE, ParlorDecoder.RECEIVED_INVITE,
|
||||
new Object[] { new Integer(arg1), arg2, arg3 });
|
||||
}
|
||||
|
||||
/**
|
||||
* Issues a notification that will result in a call to {@link
|
||||
* ParlorReceiver#receivedInviteResponse} on a client.
|
||||
*/
|
||||
public static void sendInviteResponse (
|
||||
ClientObject target, int arg1, int arg2, Object arg3)
|
||||
{
|
||||
sendNotification(
|
||||
target, ParlorDecoder.RECEIVER_CODE, ParlorDecoder.RECEIVED_INVITE_RESPONSE,
|
||||
new Object[] { new Integer(arg1), new Integer(arg2), arg3 });
|
||||
}
|
||||
|
||||
/**
|
||||
* Issues a notification that will result in a call to {@link
|
||||
* ParlorReceiver#receivedInviteCancellation} on a client.
|
||||
*/
|
||||
public static void sendInviteCancellation (
|
||||
ClientObject target, int arg1)
|
||||
{
|
||||
sendNotification(
|
||||
target, ParlorDecoder.RECEIVER_CODE, ParlorDecoder.RECEIVED_INVITE_CANCELLATION,
|
||||
new Object[] { new Integer(arg1) });
|
||||
}
|
||||
|
||||
// Generated on 11:25:47 08/12/02.
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: TableManager.java,v 1.6 2002/07/23 05:54:52 mdb Exp $
|
||||
// $Id: TableManager.java,v 1.7 2002/08/14 19:07:54 mdb Exp $
|
||||
|
||||
package com.threerings.parlor.server;
|
||||
|
||||
@@ -14,7 +14,7 @@ import com.threerings.presents.dobj.ObjectDeathListener;
|
||||
import com.threerings.presents.dobj.ObjectDestroyedEvent;
|
||||
import com.threerings.presents.dobj.ObjectRemovedEvent;
|
||||
import com.threerings.presents.dobj.OidListListener;
|
||||
import com.threerings.presents.server.ServiceFailedException;
|
||||
import com.threerings.presents.server.InvocationException;
|
||||
|
||||
import com.threerings.crowd.data.BodyObject;
|
||||
import com.threerings.crowd.data.PlaceObject;
|
||||
@@ -69,12 +69,12 @@ public class TableManager
|
||||
*
|
||||
* @return the id of the newly created table.
|
||||
*
|
||||
* @exception ServiceFailedException thrown if the table creation was
|
||||
* @exception InvocationException thrown if the table creation was
|
||||
* not able processed for some reason. The explanation will be
|
||||
* provided in the message data of the exception.
|
||||
*/
|
||||
public int createTable (BodyObject creator, GameConfig config)
|
||||
throws ServiceFailedException
|
||||
throws InvocationException
|
||||
{
|
||||
// make sure the game config implements TableConfig
|
||||
if (!(config instanceof TableConfig)) {
|
||||
@@ -82,7 +82,7 @@ public class TableManager
|
||||
"using the table services [creator=" + creator +
|
||||
", lobby=" + _plobj.getOid() +
|
||||
", config=" + config + "].");
|
||||
throw new ServiceFailedException(INTERNAL_ERROR);
|
||||
throw new InvocationException(INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
// make sure the creator is an occupant of the lobby in which
|
||||
@@ -91,7 +91,7 @@ public class TableManager
|
||||
Log.warning("Requested to create a table in a lobby not " +
|
||||
"occupied by the creator [creator=" + creator +
|
||||
", loboid=" + _plobj.getOid() + "].");
|
||||
throw new ServiceFailedException(INTERNAL_ERROR);
|
||||
throw new InvocationException(INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
// create a brand spanking new table
|
||||
@@ -105,7 +105,7 @@ public class TableManager
|
||||
"table!? [table=" + table + ", creator=" + creator +
|
||||
", error=" + error + "].");
|
||||
// bail out now and abort the table creation process
|
||||
throw new ServiceFailedException(error);
|
||||
throw new InvocationException(error);
|
||||
}
|
||||
|
||||
// stick the table into the table lobby object
|
||||
@@ -126,7 +126,7 @@ public class TableManager
|
||||
* the specified position. If the user successfully joins the table,
|
||||
* the function will return normally. If they are not able to join for
|
||||
* some reason (the slot is already full, etc.), a {@link
|
||||
* ServiceFailedException} will be thrown with a message code that
|
||||
* InvocationException} will be thrown with a message code that
|
||||
* describes the reason for failure. If the user does successfully
|
||||
* join, they will be added to the table entry in the tables set in
|
||||
* the place object that is hosting the table.
|
||||
@@ -136,17 +136,17 @@ public class TableManager
|
||||
* @param tableId the id of the table to be joined.
|
||||
* @param position the position at which to join the table.
|
||||
*
|
||||
* @exception ServiceFailedException thrown if the joining was not
|
||||
* able processed for some reason. The explanation will be provided in
|
||||
* the message data of the exception.
|
||||
* @exception InvocationException thrown if the joining was not able
|
||||
* processed for some reason. The explanation will be provided in the
|
||||
* message data of the exception.
|
||||
*/
|
||||
public void joinTable (BodyObject joiner, int tableId, int position)
|
||||
throws ServiceFailedException
|
||||
throws InvocationException
|
||||
{
|
||||
// look the table up
|
||||
Table table = (Table)_tables.get(tableId);
|
||||
if (table == null) {
|
||||
throw new ServiceFailedException(NO_SUCH_TABLE);
|
||||
throw new InvocationException(NO_SUCH_TABLE);
|
||||
}
|
||||
|
||||
// request that the user be added to the table at that position
|
||||
@@ -154,7 +154,7 @@ public class TableManager
|
||||
table.setOccupant(position, joiner.username, joiner.getOid());
|
||||
// if that failed, report the error
|
||||
if (error != null) {
|
||||
throw new ServiceFailedException(error);
|
||||
throw new InvocationException(error);
|
||||
}
|
||||
|
||||
// determine whether or not it's time to start the game
|
||||
@@ -188,29 +188,29 @@ public class TableManager
|
||||
* table. If the user successfully leaves the table, the function will
|
||||
* return normally. If they are not able to leave for some reason
|
||||
* (they aren't sitting at the table, etc.), a {@link
|
||||
* ServiceFailedException} will be thrown with a message code that
|
||||
* InvocationException} will be thrown with a message code that
|
||||
* describes the reason for failure.
|
||||
*
|
||||
* @param leaver the body object of the user that wishes to leave the
|
||||
* table.
|
||||
* @param tableId the id of the table to be left.
|
||||
*
|
||||
* @exception ServiceFailedException thrown if the leaving was not
|
||||
* able processed for some reason. The explanation will be provided in
|
||||
* the message data of the exception.
|
||||
* @exception InvocationException thrown if the leaving was not able
|
||||
* processed for some reason. The explanation will be provided in the
|
||||
* message data of the exception.
|
||||
*/
|
||||
public void leaveTable (BodyObject leaver, int tableId)
|
||||
throws ServiceFailedException
|
||||
throws InvocationException
|
||||
{
|
||||
// look the table up
|
||||
Table table = (Table)_tables.get(tableId);
|
||||
if (table == null) {
|
||||
throw new ServiceFailedException(NO_SUCH_TABLE);
|
||||
throw new InvocationException(NO_SUCH_TABLE);
|
||||
}
|
||||
|
||||
// request that the user be removed from the table
|
||||
if (!table.clearOccupant(leaver.username)) {
|
||||
throw new ServiceFailedException(NOT_AT_TABLE);
|
||||
throw new InvocationException(NOT_AT_TABLE);
|
||||
}
|
||||
|
||||
// remove the mapping from this user to the table
|
||||
|
||||
Reference in New Issue
Block a user