More progress. Brought things into line with the Party services which now

provide some of what we were going to provide with the Parlor services.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@403 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-10-06 00:25:29 +00:00
parent def7b5802d
commit 7d3e13dba4
6 changed files with 55 additions and 99 deletions
@@ -1,5 +1,5 @@
// //
// $Id: ParlorDirector.java,v 1.7 2001/10/03 03:43:14 mdb Exp $ // $Id: ParlorDirector.java,v 1.8 2001/10/06 00:25:29 mdb Exp $
package com.threerings.parlor.client; package com.threerings.parlor.client;
@@ -191,26 +191,10 @@ public class ParlorDirector
* player is ready to begin. * player is ready to begin.
* *
* @param gameOid the object id of the game object. * @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) public void handleGameReadyNotification (int gameOid)
{ {
Log.info("Handling game ready [goid=" + gameOid + Log.info("Handling game ready [goid=" + gameOid + "].");
", config=" + 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 + "].");
}
} }
/** /**
@@ -1,5 +1,5 @@
// //
// $Id: GameConfig.java,v 1.4 2001/10/03 03:43:37 mdb Exp $ // $Id: GameConfig.java,v 1.5 2001/10/06 00:25:29 mdb Exp $
package com.threerings.parlor.data; package com.threerings.parlor.data;
@@ -7,7 +7,7 @@ import java.io.IOException;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import com.threerings.cocktail.cher.io.Streamable; import com.threerings.cocktail.party.data.PlaceConfig;
/** /**
* The game config class encapsulates the configuration information for a * The game config class encapsulates the configuration information for a
@@ -31,34 +31,16 @@ import com.threerings.cocktail.cher.io.Streamable;
* information and overriding {@link #writeTo} and {@link #readFrom} to * information and overriding {@link #writeTo} and {@link #readFrom} to
* provide code to serialize and unserialize the additional fields. * provide code to serialize and unserialize the additional fields.
*/ */
public abstract class GameConfig implements Streamable public abstract class GameConfig extends PlaceConfig
{ {
/** Indicates whether or not this game is rated. */ /** Indicates whether or not this game is rated. */
public boolean rated = false; public boolean rated = false;
/**
* Returns the class that should be used to create a controller for
* this game. The controller class must derive from {@link
* com.threerings.parlor.client.GameController}.
*/
public abstract Class getControllerClass ();
/**
* Returns the name of the class that should be used to create a
* manager for this game. The manager class must derive from {@link
* com.threerings.parlor.server.GameManager}. <em>Note:</em> this
* method differs from {@link #getControllerClass} because we want to
* avoid compile time linkage of the game config object (which is used
* on the client) to server code. This allows a code optimizer (DashO
* Pro, for example) to remove the server code from the client,
* knowing that it is never used.
*/
public abstract String getManagerClassName ();
// documentation inherited // documentation inherited
public void writeTo (DataOutputStream out) public void writeTo (DataOutputStream out)
throws IOException throws IOException
{ {
super.writeTo(out);
out.writeBoolean(rated); out.writeBoolean(rated);
} }
@@ -66,33 +48,14 @@ public abstract class GameConfig implements Streamable
public void readFrom (DataInputStream in) public void readFrom (DataInputStream in)
throws IOException throws IOException
{ {
super.readFrom(in);
rated = in.readBoolean(); rated = in.readBoolean();
} }
/** // documentation inherited
* Generates a string representation of this object by calling the
* overridable {@link #toString(StringBuffer)} which builds up the
* string in a manner friendly to derived classes.
*/
public String toString ()
{
StringBuffer buf = new StringBuffer();
buf.append("[");
toString(buf);
buf.append("]");
return buf.toString();
}
/**
* An extensible mechanism for generating a string representation of
* this object. Derived classes should override this method, calling
* super and then appending their own data to the supplied string
* buffer. The regular {@link #toString} function will call this
* derived function to generate its string.
*/
protected void toString (StringBuffer buf) protected void toString (StringBuffer buf)
{ {
buf.append("type=").append(getClass().getName()); super.toString(buf);
buf.append(", rated=").append(rated); buf.append(", rated=").append(rated);
} }
} }
@@ -1,5 +1,5 @@
// //
// $Id: GameController.java,v 1.1 2001/10/01 06:19:15 mdb Exp $ // $Id: GameController.java,v 1.2 2001/10/06 00:25:29 mdb Exp $
package com.threerings.parlor.client; package com.threerings.parlor.client;
@@ -8,6 +8,9 @@ import java.awt.event.ActionEvent;
import com.samskivert.swing.Controller; import com.samskivert.swing.Controller;
import com.threerings.cocktail.cher.dobj.*; import com.threerings.cocktail.cher.dobj.*;
import com.threerings.cocktail.party.client.PlaceController;
import com.threerings.cocktail.party.data.PlaceConfig;
import com.threerings.cocktail.party.util.PartyContext;
import com.threerings.parlor.Log; import com.threerings.parlor.Log;
import com.threerings.parlor.data.GameConfig; import com.threerings.parlor.data.GameConfig;
@@ -24,7 +27,8 @@ import com.threerings.parlor.util.ParlorContext;
* subscription to the game object and dispatch of commands and * subscription to the game object and dispatch of commands and
* distributed object events. * distributed object events.
*/ */
public class GameController extends Controller implements Subscriber public abstract class GameController
extends PlaceController implements Subscriber
{ {
/** /**
* Initializes this game controller with the game configuration that * Initializes this game controller with the game configuration that
@@ -33,21 +37,17 @@ public class GameController extends Controller implements Subscriber
* game-specific configuration parameters but they should be sure to * game-specific configuration parameters but they should be sure to
* call <code>super.init</code> in such cases. * call <code>super.init</code> in such cases.
* *
* @param gameOid the object id of the game object for the game we are * @param ctx the client context.
* intended to control.
* @param config the configuration of the game we are intended to * @param config the configuration of the game we are intended to
* control. * control.
*/ */
public void init (ParlorContext ctx, int gameOid, GameConfig config) public void init (PartyContext ctx, PlaceConfig config)
{ {
// keep a reference to our context super.init(ctx, config);
_ctx = ctx;
// subscribe to the game object // cast our references
_ctx.getDObjectManager().subscribeToObject(gameOid, this); _ctx = (ParlorContext)ctx;
_config = (GameConfig)config;
// keep the config around for later
_config = config;
} }
/** /**
@@ -57,21 +57,21 @@ public class GameController extends Controller implements Subscriber
*/ */
public boolean handleAction (ActionEvent action) public boolean handleAction (ActionEvent action)
{ {
return false; return super.handleAction(action);
} }
// documentation inherited // documentation inherited
public void objectAvailable (DObject object) public void objectAvailable (DObject object)
{ {
// keep a reference around to the game object Log.warning("Got call to objectAvailable()?! " +
_gobj = (GameObject)object; "[object=" + object + "].");
} }
// documentation inherited // documentation inherited
public void requestFailed (int oid, ObjectAccessException cause) public void requestFailed (int oid, ObjectAccessException cause)
{ {
Log.warning("Unable to subscribe to game object!? [oid=" + oid + Log.warning("Got call to requestFailed()?! " +
", cause=" + cause + "]."); "[oid=" + oid + ", cause=" + cause + "].");
} }
// documentation inherited // documentation inherited
@@ -1,5 +1,5 @@
// //
// $Id: GameManager.java,v 1.3 2001/10/03 03:44:27 mdb Exp $ // $Id: GameManager.java,v 1.4 2001/10/06 00:25:29 mdb Exp $
package com.threerings.parlor.server; package com.threerings.parlor.server;
@@ -24,27 +24,34 @@ import com.threerings.parlor.data.GameObject;
public class GameManager public class GameManager
extends PlaceManager implements ParlorCodes extends PlaceManager implements ParlorCodes
{ {
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;
}
/** /**
* Initializes the game manager with the supplied game configuration * Initializes the game manager with the supplied game configuration
* object. This happens before startup and before the game object has * object. This happens before startup and before the game object has
* been created. * been created.
* *
* @param config the game configuration.
* @param players the usernames of all of the players in this game or * @param players the usernames of all of the players in this game or
* null if the game has no specific set of players. * null if the game has no specific set of players.
*/ */
public void init (GameConfig config, String[] players) public void setPlayers (String[] players)
{ {
// keep this info for later // keep this info for later
_config = config;
_players = players; _players = players;
} }
protected Class getPlaceObjectClass ()
{
return GameObject.class;
}
// documentation inherited // documentation inherited
protected void didStartup () protected void didStartup ()
{ {
@@ -55,7 +62,7 @@ public class GameManager
// we have a specific set of players) // we have a specific set of players)
if (_players != null) { if (_players != null) {
Object[] args = new Object[] { Object[] args = new Object[] {
new Integer(_gameobj.getOid()), _config }; new Integer(_gameobj.getOid()) };
for (int i = 0; i < _players.length; i++) { for (int i = 0; i < _players.length; i++) {
BodyObject bobj = PartyServer.lookupBody(_players[i]); BodyObject bobj = PartyServer.lookupBody(_players[i]);
// deliver a game ready notification to the player // deliver a game ready notification to the player
@@ -76,7 +83,7 @@ public class GameManager
} }
/** A reference to our game configuration. */ /** A reference to our game configuration. */
protected GameConfig _config; protected GameConfig _gconfig;
/** The usernames of the players of this game. */ /** The usernames of the players of this game. */
protected String[] _players; protected String[] _players;
@@ -1,5 +1,5 @@
// //
// $Id: ParlorManager.java,v 1.5 2001/10/03 03:45:16 mdb Exp $ // $Id: ParlorManager.java,v 1.6 2001/10/06 00:25:29 mdb Exp $
package com.threerings.parlor.server; package com.threerings.parlor.server;
@@ -168,9 +168,6 @@ public class ParlorManager
protected void processAcceptedInvitation (Invitation invite) protected void processAcceptedInvitation (Invitation invite)
{ {
try { try {
Class gmclass =
Class.forName(invite.config.getManagerClassName());
// Log.info("Creating game manager [invite=" + invite + // Log.info("Creating game manager [invite=" + invite +
// ", class=" + gmclass.getName() + "]."); // ", class=" + gmclass.getName() + "].");
@@ -180,12 +177,12 @@ public class ParlorManager
// started up (which is done by the place registry once the // started up (which is done by the place registry once the
// game object creation has completed) // game object creation has completed)
GameManager gmgr = (GameManager) GameManager gmgr = (GameManager)
PartyServer.plreg.createPlace(gmclass); PartyServer.plreg.createPlace(invite.config);
// provide the game manager with some initialization info // provide the game manager with some initialization info
String[] players = new String[] { String[] players = new String[] {
invite.invitee.username, invite.inviter.username }; invite.invitee.username, invite.inviter.username };
gmgr.init(invite.config, players); gmgr.setPlayers(players);
} catch (Exception e) { } catch (Exception e) {
Log.warning("Unable to create game manager [invite=" + invite + Log.warning("Unable to create game manager [invite=" + invite +
@@ -1,11 +1,16 @@
// //
// $Id: TestController.java,v 1.1 2001/10/03 03:45:44 mdb Exp $ // $Id: TestController.java,v 1.2 2001/10/06 00:25:29 mdb Exp $
package com.threerings.parlor.test; package com.threerings.parlor.test;
import com.threerings.cocktail.party.client.PlaceView;
import com.threerings.parlor.client.GameController; import com.threerings.parlor.client.GameController;
public class TestController extends GameController public class TestController extends GameController
{ {
// nothing doing public PlaceView createPlaceView ()
{
// nothing doing
return null;
}
} }