From 7e3805f069fefb32e01ca05a4f438b7dd38be42a Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 4 Oct 2001 00:29:07 +0000 Subject: [PATCH] More basic stuff. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@392 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- docs/micasa/design.txt | 10 ++ .../threerings/micasa/lobby/LobbyCodes.java | 18 +++ .../threerings/micasa/lobby/LobbyManager.java | 31 +++++ .../threerings/micasa/lobby/LobbyObject.dobj | 10 ++ .../micasa/lobby/LobbyProvider.java | 40 ++++++ .../micasa/lobby/LobbyRegistry.java | 126 ++++++++++++++++++ 6 files changed, 235 insertions(+) create mode 100644 src/java/com/threerings/micasa/lobby/LobbyCodes.java create mode 100644 src/java/com/threerings/micasa/lobby/LobbyManager.java create mode 100644 src/java/com/threerings/micasa/lobby/LobbyObject.dobj create mode 100644 src/java/com/threerings/micasa/lobby/LobbyProvider.java create mode 100644 src/java/com/threerings/micasa/lobby/LobbyRegistry.java diff --git a/docs/micasa/design.txt b/docs/micasa/design.txt index 16f07894e..b58a3848f 100644 --- a/docs/micasa/design.txt +++ b/docs/micasa/design.txt @@ -9,3 +9,13 @@ services and built on top of the Cocktail networking platform. The Mi Casa service is comprised of a server that can be configured to have any number of lobbies in which users can get together to play games. + +* Notes +Maybe move lobby stuff into parlor. + +Move lobby configuration (which lobbies to load) into database. Make it so +that lobbies can be created/destroyed on the fly. + +Sort out a different way for lobbies to get configuration information than +being passed a properties file that was extracted from the server +configuration. We'll want inheritance and all that. diff --git a/src/java/com/threerings/micasa/lobby/LobbyCodes.java b/src/java/com/threerings/micasa/lobby/LobbyCodes.java new file mode 100644 index 000000000..13f5b232a --- /dev/null +++ b/src/java/com/threerings/micasa/lobby/LobbyCodes.java @@ -0,0 +1,18 @@ +// +// $Id: LobbyCodes.java,v 1.1 2001/10/04 00:29:07 mdb Exp $ + +package com.threerings.micasa.lobdy; + +import com.threerings.cocktail.cher.client.InvocationCodes; + +/** + * Contains codes used by the lobby invocation services. + */ +public interface LobbyCodes extends InvocationCodes +{ + /** The module name for the lobby services. */ + public static final String MODULE_NAME = "lobby"; + + /** The message identifier for a get lobbies request. */ + public static final String GET_LOBBIES_REQUEST = "GetLobbies"; +} diff --git a/src/java/com/threerings/micasa/lobby/LobbyManager.java b/src/java/com/threerings/micasa/lobby/LobbyManager.java new file mode 100644 index 000000000..8aadd3ffd --- /dev/null +++ b/src/java/com/threerings/micasa/lobby/LobbyManager.java @@ -0,0 +1,31 @@ +// +// $Id: LobbyManager.java,v 1.1 2001/10/04 00:29:07 mdb Exp $ + +package com.threerings.micasa.lobdy; + +import java.util.Properties; + +import com.threerings.cocktail.party.server.PlaceManager; +import com.threerings.micasa.Log; + +/** + * Takes care of the server side of a particular lobby. + */ +public class LobbyManager extends PlaceManager +{ + /** + * Initializes this lobby manager with its configuration properties. + * + * @exception Exception thrown if a configuration error is detected. + */ + public void init (Properties config) + throws Exception + { + Log.info("Lobby manager initialized."); + } + + protected Class getPlaceObjectClass () + { + return LobbyObject.class; + } +} diff --git a/src/java/com/threerings/micasa/lobby/LobbyObject.dobj b/src/java/com/threerings/micasa/lobby/LobbyObject.dobj new file mode 100644 index 000000000..01c00fb92 --- /dev/null +++ b/src/java/com/threerings/micasa/lobby/LobbyObject.dobj @@ -0,0 +1,10 @@ +// +// $Id: LobbyObject.dobj,v 1.1 2001/10/04 00:29:07 mdb Exp $ + +package com.threerings.micasa.lobdy; + +import com.threerings.cocktail.party.data.PlaceObject; + +public class LobbyObject extends PlaceObject +{ +} diff --git a/src/java/com/threerings/micasa/lobby/LobbyProvider.java b/src/java/com/threerings/micasa/lobby/LobbyProvider.java new file mode 100644 index 000000000..f7a5d72bf --- /dev/null +++ b/src/java/com/threerings/micasa/lobby/LobbyProvider.java @@ -0,0 +1,40 @@ +// +// $Id: LobbyProvider.java,v 1.1 2001/10/04 00:29:07 mdb Exp $ + +package com.threerings.micasa.lobdy; + +import com.threerings.cocktail.cher.server.InvocationProvider; +import com.threerings.cocktail.party.data.BodyObject; + +/** + * Handles server side of lobby-related invocation services. + */ +public class LobbyProvider + extends InvocationProvider implements LobbyCodes +{ + /** + * Constructs a lobby provider instance which will be used to handle + * all lobby-related invocation service requests. This is + * automatically taken care of by the lobby registry, so no other + * entity need instantiate and register a lobby provider. + * + * @param lobreq a reference to the lobby registry active in this + * server. + */ + public LobbyProvider (LobbyRegistry lobreg) + { + _lobreg = lobreg; + } + + /** + * Processes a request by the client to obtain a list of lobbies + * matching the supplied pattern string. + */ + public void handleGetLobbiesRequest ( + BodyObject source, int invid, String pattern) + { + } + + /** A reference to the lobby registry. */ + protected LobbyRegistry _lobreg; +} diff --git a/src/java/com/threerings/micasa/lobby/LobbyRegistry.java b/src/java/com/threerings/micasa/lobby/LobbyRegistry.java new file mode 100644 index 000000000..98638466c --- /dev/null +++ b/src/java/com/threerings/micasa/lobby/LobbyRegistry.java @@ -0,0 +1,126 @@ +// +// $Id: LobbyRegistry.java,v 1.1 2001/10/04 00:29:07 mdb Exp $ + +package com.threerings.micasa.lobdy; + +import java.util.Properties; + +import com.samskivert.util.Config; +import com.samskivert.util.PropertiesUtil; + +import com.threerings.micasa.Log; +import com.threerings.micasa.server.MiCasaServer; + +/** + * The lobby registry is the primary class that coordinates the lobby + * services on the client. It sets up the necessary invocation services + * and keeps track of the lobbies in operation on the server. Only one + * lobby registry should be created on a server. + * + *

Presently, the lobby registry is configured with lobbies via the + * server configuration. An example configuration follows: + * + *

+ * lobby_ids = foolobby, barlobby, bazlobby
+ *
+ * foolobby.mgrclass = com.threerings.micasa.lobby.LobbyManager
+ * foolobby.config1 = some config value
+ * foolobby.config2 = some other config value
+ *
+ * barlobby.mgrclass = com.threerings.micasa.lobby.LobbyManager
+ * ...
+ * 
+ * + * This information will be loaded from the MiCasa server configuration + * which means that it should live in + * rsrc/config/micasa/server.properties somwhere in the + * classpath where it will override the default MiCasa server properties + * file. + */ +public class LobbyRegistry +{ + /** + * A simple class for keeping track of information for each lobby in + * operation on the server. + */ + public static class Lobby + { + /** The object id of the lobby place object. */ + public int placeOid; + + /** The human readable name of the lobby. */ + public String name; + } + + /** + * Initializes the registry. It will use the supplied configuration + * instance to determine which lobbies to load, etc. + */ + public void init (Config config) + { + _config = config; + + // create our lobby managers + String[] lmgrs = config.getValue(LOBIDS_KEY, (String[])null); + if (lmgrs == null || lmgrs.length == 0) { + Log.warning("No lobbies specified in config file (via '" + + LOBIDS_KEY + "' parameter."); + + } else { + for (int i = 0; i < lmgrs.length; i++) { + loadLobby(lmgrs[i]); + } + } + } + + /** + * Extracts the properties for a lobby from the server config and + * creates and initializes the lobby manager. + */ + protected void loadLobby (String lobbyId) + { + try { + // extract the properties for this lobby + Properties props = + _config.getProperties(MiCasaServer.CONFIG_KEY); + props = PropertiesUtil.getSubProperties(props, lobbyId); + + // get the lobby manager class + String lmgrClass = props.getProperty("mgrclass"); + if (lmgrClass == null) { + throw new Exception("Missing 'mgrclass' definition in " + + "lobby configuration."); + } + + // instantiate the manager class and create the lobby + LobbyManager lobmgr = (LobbyManager) + MiCasaServer.plreg.createPlace(Class.forName(lmgrClass)); + + // initialize the manager + lobmgr.init(props); + + } catch (Exception e) { + Log.warning("Unable to create lobby manager " + + "[lobbyId=" + lobbyId + ", error=" + e + "]."); + } + } + + /** + * Returns information about all lobbies matching the supplied pattern + * string. Presently the pattern is interpreted as a simple prefix and + * all lobbies matching that prefix will be returned. + * + * @param pattern the pattern to match or null if all lobbies should + * be returned. + */ + public Lobby[] getLobbies (String pattern) + { + return null; + } + + protected Config _config; + + /** The configuration key for the lobby managers list. */ + protected static final String LOBIDS_KEY = + MiCasaServer.CONFIG_KEY + ".lobby_ids"; +}