diff --git a/src/java/com/threerings/parlor/client/ParlorCodes.java b/src/java/com/threerings/parlor/client/ParlorCodes.java index 76c031efb..b2115e1bb 100644 --- a/src/java/com/threerings/parlor/client/ParlorCodes.java +++ b/src/java/com/threerings/parlor/client/ParlorCodes.java @@ -1,5 +1,5 @@ // -// $Id: ParlorCodes.java,v 1.2 2001/10/02 02:09:06 mdb Exp $ +// $Id: ParlorCodes.java,v 1.3 2001/10/02 21:52:33 mdb Exp $ package com.threerings.parlor.client; @@ -13,8 +13,14 @@ 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#handleGameReady}. */ + public static final String GAME_READY_NOTIFICATION = "GameReady"; + /** The message identifier for an invitation creation request or - * notification. */ + * 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 @@ -28,11 +34,15 @@ public interface ParlorCodes extends InvocationCodes public static final String INVITE_FAILED_RESPONSE = "InviteFailed"; /** The message identifier for an invitation cancellation request or - * notification. */ + * 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. */ + * 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. */ diff --git a/src/java/com/threerings/parlor/client/ParlorDirector.java b/src/java/com/threerings/parlor/client/ParlorDirector.java index 817dc9f2d..1c1d84743 100644 --- a/src/java/com/threerings/parlor/client/ParlorDirector.java +++ b/src/java/com/threerings/parlor/client/ParlorDirector.java @@ -1,5 +1,5 @@ // -// $Id: ParlorDirector.java,v 1.5 2001/10/02 02:09:06 mdb Exp $ +// $Id: ParlorDirector.java,v 1.6 2001/10/02 21:52:33 mdb Exp $ package com.threerings.parlor.client; @@ -181,6 +181,30 @@ public class ParlorDirector } } + /** + * 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. + * @param config the configuration information for the started game. + */ + public void handleGameReadyNotification (int gameOid, GameConfig config) + { + try { + // create the game controller for this game + GameController ctrl = (GameController) + config.getControllerClass().newInstance(); + + // initialize it and get things underway + ctrl.init(_ctx, gameOid, config); + + } catch (Exception e) { + Log.warning("Unable to instantiate game controller " + + "[goid=" + gameOid + ", config=" + config + + ", error=" + e + "]."); + } + } + /** * Called by the invocation services when another user has invited us * to play a game. diff --git a/src/java/com/threerings/parlor/game/GameManager.java b/src/java/com/threerings/parlor/game/GameManager.java index 0579c7384..d287095a9 100644 --- a/src/java/com/threerings/parlor/game/GameManager.java +++ b/src/java/com/threerings/parlor/game/GameManager.java @@ -1,16 +1,80 @@ // -// $Id: GameManager.java,v 1.1 2001/10/01 02:56:35 mdb Exp $ +// $Id: GameManager.java,v 1.2 2001/10/02 21:52:33 mdb Exp $ package com.threerings.parlor.server; -import java.util.Properties; - +import com.threerings.cocktail.party.data.BodyObject; import com.threerings.cocktail.party.server.PlaceManager; -import com.threerings.cocktail.party.server.PlaceRegistry; +import com.threerings.cocktail.party.server.PartyServer; -public class GameManager extends PlaceManager +import com.threerings.parlor.client.ParlorCodes; +import com.threerings.parlor.data.GameConfig; +import com.threerings.parlor.data.GameObject; + +/** + * The game manager handles the server side management of a game. It + * manipulates the game state in accordance with the logic of the game + * flow and generally manages the whole game playing process. + * + *

The game manager extends the place manager because games are + * implicitly played in a location, the players of the game implicitly + * bodies in that location. + */ +public class GameManager + extends PlaceManager implements ParlorCodes { - public void init (PlaceRegistry registry, Properties config) + /** + * Initializes the game manager with the supplied game configuration + * object. This happens before startup and before the game object has + * been created. + * + * @param config the game configuration. + * @param players the usernames of all of the players in this game or + * null if the game has no specific set of players. + */ + public void init (GameConfig config, String[] players) + { + // keep this info for later + _config = config; + _players = players; + } + + // documentation inherited + protected void didStartup () + { + // obtain a casted reference to our game object + _gameobj = (GameObject)_plobj; + + // 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()), _config }; + for (int i = 0; i < _players.length; i++) { + BodyObject bobj = PartyServer.lookupBody(_players[i]); + // deliver a game ready notification to the player + PartyServer.invmgr.sendNotification( + bobj.getOid(), MODULE_NAME, GAME_READY_NOTIFICATION, args); + } + } + } + + // documentation inherited + protected void bodyEntered (int bodyOid) { } + + // documentation inherited + protected void bodyLeft (int bodyOid) + { + } + + /** A reference to our game configuration. */ + protected GameConfig _config; + + /** The usernames of the players of this game. */ + protected String[] _players; + + /** A reference to our game object. */ + protected GameObject _gameobj; } diff --git a/src/java/com/threerings/parlor/server/ParlorManager.java b/src/java/com/threerings/parlor/server/ParlorManager.java index 68732652d..33ddf8d9e 100644 --- a/src/java/com/threerings/parlor/server/ParlorManager.java +++ b/src/java/com/threerings/parlor/server/ParlorManager.java @@ -1,5 +1,5 @@ // -// $Id: ParlorManager.java,v 1.3 2001/10/02 02:09:06 mdb Exp $ +// $Id: ParlorManager.java,v 1.4 2001/10/02 21:52:33 mdb Exp $ package com.threerings.parlor.server; @@ -10,6 +10,7 @@ import com.threerings.cocktail.cher.server.InvocationManager; import com.threerings.cocktail.cher.server.ServiceFailedException; import com.threerings.cocktail.party.data.BodyObject; +import com.threerings.cocktail.party.server.PartyServer; import com.threerings.parlor.Log; import com.threerings.parlor.client.ParlorCodes; @@ -127,7 +128,7 @@ public class ParlorManager new Integer(invite.inviteId), new Integer(code), arg }; _invmgr.sendNotification( invite.inviter.getOid(), MODULE_NAME, RESPOND_INVITE_ID, args); - + switch (code) { case INVITATION_ACCEPTED: // the invitation was accepted, so we'll need to start up the @@ -163,7 +164,18 @@ public class ParlorManager protected void processAcceptedInvitation (Invitation invite) { - // start up the game and all that... + try { + // create the game manager and begin it's initialization + // process. the game manager will take care of notifying the + // players that the game has been created + Class gmclass = + Class.forName(invite.config.getManagerClassName()); + PartyServer.plreg.createPlace(gmclass); + + } catch (Exception e) { + Log.warning("Unable to create game manager [invite=" + invite + + ", error=" + e + "]."); + } } /**