From 18833d7eb728c1092d2886082de3567369b936d7 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Thu, 20 Oct 2005 07:17:02 +0000 Subject: [PATCH] Added an isPrivate variable to GameObject. Set it if a table game is created as being private. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3738 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../parlor/game/data/GameObject.java | 22 +++++++++++++++++++ .../parlor/server/TableManager.java | 18 ++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/java/com/threerings/parlor/game/data/GameObject.java b/src/java/com/threerings/parlor/game/data/GameObject.java index 164b5f118..194280f1b 100644 --- a/src/java/com/threerings/parlor/game/data/GameObject.java +++ b/src/java/com/threerings/parlor/game/data/GameObject.java @@ -49,6 +49,9 @@ public class GameObject extends PlaceObject /** The field name of the isRated field. */ public static final String IS_RATED = "isRated"; + /** The field name of the isPrivate field. */ + public static final String IS_PRIVATE = "isPrivate"; + /** The field name of the players field. */ public static final String PLAYERS = "players"; @@ -93,6 +96,9 @@ public class GameObject extends PlaceObject /** Indicates whether or not this game is rated. */ public boolean isRated; + /** Indicates whether the game is "private". */ + public boolean isPrivate; + /** The usernames of the players involved in this game. */ public Name[] players; @@ -289,6 +295,22 @@ public class GameObject extends PlaceObject this.isRated = value; } + /** + * Requests that the isPrivate field be set to the + * specified value. The local value will be updated immediately and an + * event will be propagated through the system to notify all listeners + * that the attribute did change. Proxied copies of this object (on + * clients) will apply the value change when they received the + * attribute changed notification. + */ + public void setIsPrivate (boolean value) + { + boolean ovalue = this.isPrivate; + requestAttributeChange( + IS_PRIVATE, new Boolean(value), new Boolean(ovalue)); + this.isPrivate = value; + } + /** * Requests that the players field be set to the * specified value. The local value will be updated immediately and an diff --git a/src/java/com/threerings/parlor/server/TableManager.java b/src/java/com/threerings/parlor/server/TableManager.java index 3140088dc..f53a6312b 100644 --- a/src/java/com/threerings/parlor/server/TableManager.java +++ b/src/java/com/threerings/parlor/server/TableManager.java @@ -28,6 +28,7 @@ import com.samskivert.util.HashIntMap; import com.samskivert.util.StringUtil; import com.threerings.util.Name; +import com.threerings.presents.dobj.ChangeListener; import com.threerings.presents.dobj.ObjectAddedEvent; import com.threerings.presents.dobj.ObjectDeathListener; import com.threerings.presents.dobj.ObjectDestroyedEvent; @@ -47,6 +48,7 @@ import com.threerings.parlor.data.Table; import com.threerings.parlor.data.TableConfig; import com.threerings.parlor.data.TableLobbyObject; import com.threerings.parlor.game.data.GameConfig; +import com.threerings.parlor.game.data.GameObject; import com.threerings.parlor.game.server.GameManager; /** @@ -285,6 +287,9 @@ public class TableManager // update the table with the newly created game object table.gameOid = plobj.getOid(); + // configure the privacy of the game + ((GameObject) plobj).setIsPrivate(table.tconfig.privateTable); + // clear the occupant to table mappings as this game is underway for (int i = 0; i < table.bodyOids.length; i++) { _boidMap.remove(table.bodyOids[i]); @@ -292,11 +297,7 @@ public class TableManager // add an object death listener to unmap the table when the game // finally goes away - plobj.addListener(new ObjectDeathListener() { - public void objectDestroyed (ObjectDestroyedEvent event) { - unmapTable(event.getTargetOid()); - } - }); + plobj.addListener(_gameDeathListener); // and then update the lobby object that contains the table _tlobj.updateTables(table); @@ -370,4 +371,11 @@ public class TableManager /** A mapping from body oid to table. */ protected HashIntMap _boidMap = new HashIntMap(); + + /** A listener that prunes tables after the game dies. */ + protected ChangeListener _gameDeathListener = new ObjectDeathListener() { + public void objectDestroyed (ObjectDestroyedEvent event) { + unmapTable(event.getTargetOid()); + } + }; }