Sorted out some basic invitation stuff so that we can force an invitation
to take place for testing. Will flesh all the rest out later. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@426 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: LobbyConfig.java,v 1.1 2001/10/09 00:48:34 mdb Exp $
|
||||
// $Id: LobbyConfig.java,v 1.2 2001/10/09 20:22:51 mdb Exp $
|
||||
|
||||
package com.threerings.micasa.lobby;
|
||||
|
||||
@@ -7,8 +7,13 @@ import java.io.IOException;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
import java.util.Properties;
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.cocktail.party.data.PlaceConfig;
|
||||
|
||||
import com.threerings.parlor.data.GameConfig;
|
||||
|
||||
public class LobbyConfig extends PlaceConfig
|
||||
{
|
||||
// documentation inherited
|
||||
@@ -23,11 +28,36 @@ public class LobbyConfig extends PlaceConfig
|
||||
return "com.threerings.micasa.lobby.LobbyManager";
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates and returns a game config instance using the game
|
||||
* config classname provided by the lobby configuration parameters.
|
||||
*
|
||||
* @exception Exception thrown if a problem occurs loading or
|
||||
* instantiating the class.
|
||||
*/
|
||||
public GameConfig getGameConfig ()
|
||||
throws Exception
|
||||
{
|
||||
return (GameConfig)Class.forName(_gameConfigClass).newInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes this lobby config object with the properties that are
|
||||
* used to configure the lobby. This is called on the server when the
|
||||
* lobby is loaded.
|
||||
*/
|
||||
public void init (Properties config)
|
||||
throws Exception
|
||||
{
|
||||
_gameConfigClass = getConfigValue(config, "game_config");
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void writeTo (DataOutputStream out)
|
||||
throws IOException
|
||||
{
|
||||
super.writeTo(out);
|
||||
out.writeUTF(_gameConfigClass);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
@@ -35,11 +65,30 @@ public class LobbyConfig extends PlaceConfig
|
||||
throws IOException
|
||||
{
|
||||
super.readFrom(in);
|
||||
_gameConfigClass = in.readUTF();
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected void toString (StringBuffer buf)
|
||||
{
|
||||
super.toString(buf);
|
||||
buf.append(", game_config=").append(_gameConfigClass);
|
||||
}
|
||||
|
||||
/** Looks up a configuration property in the supplied properties
|
||||
* object and throws an exception if it's not found. */
|
||||
protected String getConfigValue (Properties config, String key)
|
||||
throws Exception
|
||||
{
|
||||
String value = config.getProperty(key);
|
||||
if (StringUtil.blank(value)) {
|
||||
throw new Exception("Missing '" + key + "' definition in " +
|
||||
"lobby configuration.");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/** The name of the game config class that represents the type of game
|
||||
* we are matchmaking for in this lobby. */
|
||||
protected String _gameConfigClass;
|
||||
}
|
||||
|
||||
@@ -1,26 +1,34 @@
|
||||
//
|
||||
// $Id: LobbyController.java,v 1.3 2001/10/09 18:20:08 mdb Exp $
|
||||
// $Id: LobbyController.java,v 1.4 2001/10/09 20:22:51 mdb Exp $
|
||||
|
||||
package com.threerings.micasa.lobby;
|
||||
|
||||
import com.threerings.cocktail.party.data.PlaceConfig;
|
||||
import com.threerings.cocktail.party.data.PlaceObject;
|
||||
import com.threerings.cocktail.party.client.PlaceController;
|
||||
import com.threerings.cocktail.party.client.PlaceView;
|
||||
import com.threerings.cocktail.party.util.PartyContext;
|
||||
|
||||
import com.threerings.parlor.client.*;
|
||||
import com.threerings.parlor.data.GameConfig;
|
||||
|
||||
import com.threerings.micasa.Log;
|
||||
import com.threerings.micasa.util.MiCasaContext;
|
||||
|
||||
public class LobbyController extends PlaceController
|
||||
public class LobbyController
|
||||
extends PlaceController
|
||||
implements InvitationHandler, InvitationResponseObserver
|
||||
{
|
||||
public void init (PartyContext ctx, PlaceConfig config)
|
||||
{
|
||||
// cast our context reference
|
||||
_ctx = (MiCasaContext)ctx;
|
||||
_config = (LobbyConfig)config;
|
||||
|
||||
super.init(ctx, config);
|
||||
|
||||
Log.info("Lobby controller created [config=" + config + "].");
|
||||
// register ourselves as the invitation handler
|
||||
_ctx.getParlorDirector().setInvitationHandler(this);
|
||||
}
|
||||
|
||||
protected PlaceView createPlaceView ()
|
||||
@@ -28,5 +36,58 @@ public class LobbyController extends PlaceController
|
||||
return new LobbyPanel(_ctx);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void willEnterPlace (PlaceObject plobj)
|
||||
{
|
||||
super.willEnterPlace(plobj);
|
||||
|
||||
// if we're testing and a system property has been specified
|
||||
// requesting that we invite another player, do so now
|
||||
String invitee = System.getProperty("invitee");
|
||||
if (invitee != null) {
|
||||
// create a game config object
|
||||
try {
|
||||
GameConfig config = _config.getGameConfig();
|
||||
_ctx.getParlorDirector().invite(invitee, config, this);
|
||||
} catch (Exception e) {
|
||||
Log.warning("Error instantiating game config.");
|
||||
Log.logStackTrace(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void invitationReceived (int inviteId, String inviter,
|
||||
GameConfig config)
|
||||
{
|
||||
Log.info("Invitation received [inviteId=" + inviteId +
|
||||
", inviter=" + inviter + ", config=" + config + "].");
|
||||
|
||||
// accept the invitation. we're game...
|
||||
_ctx.getParlorDirector().accept(inviteId);
|
||||
}
|
||||
|
||||
public void invitationCancelled (int inviteId)
|
||||
{
|
||||
Log.info("Invitation cancelled [inviteId=" + inviteId + "].");
|
||||
}
|
||||
|
||||
public void invitationAccepted (int inviteId)
|
||||
{
|
||||
Log.info("Invitation accepted [inviteId=" + inviteId + "].");
|
||||
}
|
||||
|
||||
public void invitationRefused (int inviteId, String message)
|
||||
{
|
||||
Log.info("Invitation refused [inviteId=" + inviteId +
|
||||
", message=" + message + "].");
|
||||
}
|
||||
|
||||
public void invitationCountered (int inviteId, GameConfig config)
|
||||
{
|
||||
Log.info("Invitation countered [inviteId=" + inviteId +
|
||||
", config=" + config + "].");
|
||||
}
|
||||
|
||||
protected MiCasaContext _ctx;
|
||||
protected LobbyConfig _config;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: LobbyRegistry.java,v 1.4 2001/10/09 19:24:11 mdb Exp $
|
||||
// $Id: LobbyRegistry.java,v 1.5 2001/10/09 20:22:51 mdb Exp $
|
||||
|
||||
package com.threerings.micasa.lobby;
|
||||
|
||||
@@ -120,15 +120,16 @@ public class LobbyRegistry implements LobbyCodes
|
||||
"lobby configuration.");
|
||||
}
|
||||
|
||||
// instantiate the manager class and create the lobby
|
||||
// create and initialize the lobby config object
|
||||
LobbyConfig config = (LobbyConfig)
|
||||
Class.forName(cfgClass).newInstance();
|
||||
config.init(props);
|
||||
|
||||
// create and initialize the lobby manager. it will call
|
||||
// lobbyReady() when it has obtained a reference to its lobby
|
||||
// object and is ready to roll
|
||||
LobbyManager lobmgr = (LobbyManager)
|
||||
MiCasaServer.plreg.createPlace(config);
|
||||
|
||||
// initialize the lobby manager. it will call lobbyReady()
|
||||
// when it has obtained a reference to its lobby object and is
|
||||
// ready to roll
|
||||
lobmgr.init(this, props);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user