More progress on game creation and match making.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@377 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-10-02 21:52:33 +00:00
parent e08ea92b23
commit db81e60bcb
4 changed files with 124 additions and 14 deletions
@@ -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; package com.threerings.parlor.client;
@@ -13,8 +13,14 @@ public interface ParlorCodes extends InvocationCodes
/** The module name for the parlor services. */ /** The module name for the parlor services. */
public static final String MODULE_NAME = "parlor"; 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 /** 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"; public static final String INVITE_ID = "Invite";
/** The response identifier for an accepted invite request. This is /** 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"; public static final String INVITE_FAILED_RESPONSE = "InviteFailed";
/** The message identifier for an invitation cancellation request or /** 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"; public static final String CANCEL_INVITE_ID = "CancelInvite";
/** The message identifier for an invitation response request or /** 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"; public static final String RESPOND_INVITE_ID = "RespondInvite";
/** The response code for an accepted invitation. */ /** The response code for an accepted invitation. */
@@ -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; 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 * Called by the invocation services when another user has invited us
* to play a game. * to play a game.
@@ -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; 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.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.
*
* <p> 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;
} }
@@ -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; 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.cher.server.ServiceFailedException;
import com.threerings.cocktail.party.data.BodyObject; import com.threerings.cocktail.party.data.BodyObject;
import com.threerings.cocktail.party.server.PartyServer;
import com.threerings.parlor.Log; import com.threerings.parlor.Log;
import com.threerings.parlor.client.ParlorCodes; import com.threerings.parlor.client.ParlorCodes;
@@ -163,7 +164,18 @@ public class ParlorManager
protected void processAcceptedInvitation (Invitation invite) 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 + "].");
}
} }
/** /**