From d2d9de37c103b4e9a4d45db2ecaa90e65d757159 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sat, 4 Aug 2001 01:55:41 +0000 Subject: [PATCH] Added code to track a username to body object mapping for all users with active sessions (even if they are currently disconnected). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@178 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/crowd/server/CrowdClient.java | 18 +++++++++- .../threerings/crowd/server/CrowdServer.java | 34 ++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/java/com/threerings/crowd/server/CrowdClient.java b/src/java/com/threerings/crowd/server/CrowdClient.java index 30e8f74bb..184660882 100644 --- a/src/java/com/threerings/crowd/server/CrowdClient.java +++ b/src/java/com/threerings/crowd/server/CrowdClient.java @@ -1,5 +1,5 @@ // -// $Id: CrowdClient.java,v 1.1 2001/08/03 02:28:20 mdb Exp $ +// $Id: CrowdClient.java,v 1.2 2001/08/04 01:55:41 mdb Exp $ package com.threerings.cocktail.party.server; @@ -14,15 +14,31 @@ public class PartyClient extends CherClient { protected void sessionWillStart () { + super.sessionWillStart(); + // cast our client object to a body object _bodobj = (BodyObject)_clobj; // and configure our username _bodobj.setUsername(_username); + + // register our body object mapping + PartyServer.mapBody(_username, _bodobj); } protected void sessionWillResume () { + super.sessionWillResume(); + + // nothing to do here presently + } + + protected void sessionDidTerminate () + { + super.sessionDidTerminate(); + + // unregister our body object mapping + PartyServer.unmapBody(_username); } protected BodyObject _bodobj; diff --git a/src/java/com/threerings/crowd/server/CrowdServer.java b/src/java/com/threerings/crowd/server/CrowdServer.java index ec88e4f04..8f66a0a12 100644 --- a/src/java/com/threerings/crowd/server/CrowdServer.java +++ b/src/java/com/threerings/crowd/server/CrowdServer.java @@ -1,9 +1,10 @@ // -// $Id: CrowdServer.java,v 1.4 2001/08/03 02:28:20 mdb Exp $ +// $Id: CrowdServer.java,v 1.5 2001/08/04 01:55:41 mdb Exp $ package com.threerings.cocktail.party.server; import java.io.IOException; +import java.util.HashMap; import com.threerings.cocktail.cher.server.CherServer; @@ -49,6 +50,34 @@ public class PartyServer extends CherServer Log.info("Party server initialized."); } + /** + * The party server maintains a mapping of username to body object for + * all active users on the server. This should only be called from the + * dobjmgr thread. + */ + public static BodyObject lookupBody (String username) + { + return (BodyObject)_bodymap.get(username); + } + + /** + * Called by the party client to map a username to a particular body + * object. This should only be called from the dobjmgr thread. + */ + protected static void mapBody (String username, BodyObject bodobj) + { + _bodymap.put(username, bodobj); + } + + /** + * Called by the party client to unmap a username from a particular + * body object. This should only be called from the dobjmgr thread. + */ + protected static void unmapBody (String username) + { + _bodymap.remove(username); + } + public static void main (String[] args) { PartyServer server = new PartyServer(); @@ -61,6 +90,9 @@ public class PartyServer extends CherServer } } + /** We use this to map usernames to body objects. */ + protected static HashMap _bodymap = new HashMap(); + // the path to the config file protected final static String CONFIG_PATH = "rsrc/config/cocktail/party/server";