From 97a8417d4e1616d5bb6f90f2f9a3783ff61be227 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 10 Apr 2007 17:05:48 +0000 Subject: [PATCH] Listen for object death on table participants when we're not in a place and can't rely on hearing that they left the place to clean up after them. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@274 c613c5cb-e716-0410-b11b-feb51c14d237 --- .../parlor/server/TableManager.java | 65 +++++++++++++------ 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/src/java/com/threerings/parlor/server/TableManager.java b/src/java/com/threerings/parlor/server/TableManager.java index a7368d7b..9e9c208e 100644 --- a/src/java/com/threerings/parlor/server/TableManager.java +++ b/src/java/com/threerings/parlor/server/TableManager.java @@ -60,7 +60,7 @@ import com.threerings.parlor.game.server.GameManager; * of a table matchmaking service on a particular distributed object. */ public class TableManager - implements ParlorCodes, OidListListener, TableProvider + implements ParlorCodes, TableProvider { /** * Creates a table manager that will manage tables in the supplied distributed object (which @@ -77,7 +77,7 @@ public class TableManager // if our table is in a "place" add ourselves as a listener so that we can tell if a user // leaves the place without leaving their table if (_dobj instanceof PlaceObject) { - _dobj.addListener(this); + _dobj.addListener(_leaveListener); } } @@ -91,7 +91,7 @@ public class TableManager _tlobj.setTableService(null); } if (_dobj instanceof PlaceObject) { - _dobj.removeListener(this); + _dobj.removeListener(_leaveListener); } _tlobj = null; _dobj = null; @@ -277,9 +277,15 @@ public class TableManager protected void notePlayerAdded (Table table, int playerOid) { _boidMap.put(playerOid, table); - - // TODO: if we're not in a place, listen to the player's BodyObject for object death so - // that we remove them from their table if they logoff + // if we're in a place, we're done + if (_dobj instanceof PlaceObject) { + return; + } + // if not, listen to their BodyObject for death so that we remove them if they logoff + BodyObject body = (BodyObject)PresentsServer.omgr.getObject(playerOid); + if (body != null) { + body.addListener(_deathListener); + } } /** @@ -288,7 +294,12 @@ public class TableManager protected boolean notePlayerRemoved (Table table, int playerOid) { boolean removed = (_boidMap.remove(playerOid) != null); - // TODO: remove our BodyObject death listener + if (!(_dobj instanceof PlaceObject)) { + BodyObject body = (BodyObject)PresentsServer.omgr.getObject(playerOid); + if (body != null) { + body.removeListener(_deathListener); + } + } return removed; } @@ -403,22 +414,13 @@ public class TableManager _tlobj.updateTables(table); } - // documentation inherited - public void objectAdded (ObjectAddedEvent event) + /** + * Called when a body is known to have left either the room that contains our tables or logged + * off of the server. + */ + protected void bodyLeft (int bodyOid) { - // nothing doing - } - - // documentation inherited - public void objectRemoved (ObjectRemovedEvent event) - { - // if an occupant departed, see if they are in a pending table - if (!event.getName().equals(PlaceObject.OCCUPANTS)) { - return; - } - // look up the table to which this occupant is mapped - int bodyOid = event.getOid(); Table pender = _boidMap.remove(bodyOid); if (pender == null) { return; @@ -440,6 +442,27 @@ public class TableManager } } + /** Listens for players leaving the place that contains our tables. */ + protected OidListListener _leaveListener = new OidListListener() { + public void objectAdded (ObjectAddedEvent event) { + // nothing doing + } + public void objectRemoved (ObjectRemovedEvent event) { + // if an occupant departed, see if they are in a pending table + if (event.getName().equals(PlaceObject.OCCUPANTS)) { + bodyLeft(event.getOid()); + } + } + }; + + /** Listens for the death of body objects that are in tables. This is used when we are not + * managing tables in a place but rather across the whole server. */ + protected ObjectDeathListener _deathListener = new ObjectDeathListener() { + public void objectDestroyed (ObjectDestroyedEvent event) { + bodyLeft(event.getTargetOid()); + } + }; + /** A reference to the distributed object in which we're managing tables. */ protected DObject _dobj;