// // $Id$ // // Vilya library - tools for developing networked games // Copyright (C) 2002-2007 Three Rings Design, Inc., All Rights Reserved // http://www.threerings.net/code/vilya/ // // This library is free software; you can redistribute it and/or modify it // under the terms of the GNU Lesser General Public License as published // by the Free Software Foundation; either version 2.1 of the License, or // (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA package com.threerings.micasa.lobby; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.StringTokenizer; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.samskivert.util.StringUtil; import com.google.inject.Inject; import com.threerings.util.StreamableArrayList; import com.threerings.presents.data.ClientObject; import com.threerings.presents.data.InvocationCodes; import com.threerings.presents.server.InvocationManager; import com.threerings.crowd.data.BodyObject; import com.threerings.crowd.server.PlaceRegistry; import com.threerings.micasa.lobby.LobbyService.CategoriesListener; import com.threerings.micasa.lobby.LobbyService.LobbiesListener; import com.threerings.micasa.server.MiCasaConfig; import static com.threerings.micasa.Log.log; /** * 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.ugi =* * This information will be loaded from the MiCasa server configuration which means that it should * live in* foolobby.name = * foolobby.config1 = some config value * foolobby.config2 = some other config value * * barlobby.mgrclass = com.threerings.micasa.lobby.LobbyManager * barlobby.ugi = * barlobby.name = * ... *
rsrc/config/micasa/server.properties somwhere in the classpath where it
* will override the default MiCasa server properties file.
*
* The UGI or universal game identifier is a string that is used to uniquely
* identify every type of game and also to classify it according to meaningful keywords. It is best
* described with a few examples:
*
*
* backgammon,board,strategy * spades,card,partner * yahtzee,dice ** * As you can see, a UGI should start with an identifier uniquely identifying the type of game and * can be followed by a list of keywords that classify it as a member of a particular category of * games (eg. board, card, dice, partner game, strategy game). A game can belong to multiple * categories. * *
As long as the UGIs in use by a particular server make some kind of sense, the client will
* be able to use them to search for lobbies containing games of similar types using the provided
* facilities.
*/
public class LobbyRegistry
implements LobbyProvider
{
@Inject public LobbyRegistry (InvocationManager invmgr)
{
// register ourselves as an invocation service handler
invmgr.registerDispatcher(new LobbyDispatcher(this), InvocationCodes.GLOBAL_GROUP);
}
/**
* Initializes the registry, creating our default lobbies.
*/
public void init ()
{
// create our lobby managers
String[] lmgrs = null;
lmgrs = MiCasaConfig.config.getValue(LOBIDS_KEY, lmgrs);
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]);
}
}
}
/**
* Returns the oid of the default lobby.
*/
public int getDefaultLobbyOid ()
{
return _defLobbyOid;
}
/**
* 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 = MiCasaConfig.config.getSubProperties(lobbyId);
// get the lobby manager class and UGI
String cfgClass = props.getProperty("config");
if (StringUtil.isBlank(cfgClass)) {
throw new Exception("Missing 'config' definition in lobby configuration.");
}
// 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)_plreg.createPlace(config);
lobmgr.init(this, props);
} catch (Exception e) {
log.warning("Unable to create lobby manager [lobbyId=" + lobbyId +
", error=" + e + "].");
}
}
/**
* Returns information about all lobbies hosting games in the specified category.
*
* @param requester the body object of the client requesting the lobby list (which can be used
* to filter the list based on their capabilities).
* @param category the category of game for which the lobbies are desired.
* @param target the list into which the matching lobbies will be deposited.
*/
public void getLobbies (BodyObject requester, String category, List