From feb7355804df7fae19c9c1ee325ff3d83665917d Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Fri, 3 Dec 2004 23:47:19 +0000 Subject: [PATCH] Go back to defaultly broadcasting to game objects, in case someone ever creates a traditional lobby->room server with narya, and instead allow a broadcast object to be registered with the ChatProvider to which all broadcasts will be sent. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3261 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../crowd/chat/server/ChatProvider.java | 58 ++++++++++++++----- .../threerings/parlor/game/GameObject.dobj | 8 --- .../threerings/parlor/game/GameObject.java | 8 --- 3 files changed, 44 insertions(+), 30 deletions(-) diff --git a/src/java/com/threerings/crowd/chat/server/ChatProvider.java b/src/java/com/threerings/crowd/chat/server/ChatProvider.java index 1875178bf..7b2accf5a 100644 --- a/src/java/com/threerings/crowd/chat/server/ChatProvider.java +++ b/src/java/com/threerings/crowd/chat/server/ChatProvider.java @@ -1,5 +1,5 @@ // -// $Id: ChatProvider.java,v 1.30 2004/08/27 02:12:32 mdb Exp $ +// $Id$ // // Narya library - tools for developing networked games // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved @@ -30,6 +30,7 @@ import com.threerings.util.TimeUtil; import com.threerings.presents.client.InvocationService.InvocationListener; import com.threerings.presents.data.ClientObject; +import com.threerings.presents.dobj.DObject; import com.threerings.presents.dobj.DObjectManager; import com.threerings.presents.server.InvocationException; @@ -86,6 +87,18 @@ public class ChatProvider _comAuth = comAuth; } + /** + * Set an object to which all broadcasts should be sent, rather + * than iterating over the place objects and sending to each of them. + * + * @param object an object to send all broadcasts, or null to send to + * each place object instead. + */ + public static void setAlternateBroadcastObject (DObject object) + { + _broadcastObject = object; + } + /** * Initializes the chat services and registers a chat provider with * the invocation manager. @@ -176,25 +189,39 @@ public class ChatProvider public static void broadcast (Name from, String bundle, String msg, boolean attention) { - Iterator iter = CrowdServer.plreg.enumeratePlaces(); - while (iter.hasNext()) { - PlaceObject plobj = (PlaceObject)iter.next(); - if (plobj.shouldBroadcast()) { - if (from == null) { - if (attention) { - SpeakProvider.sendAttention(plobj, bundle, msg); - } else { - SpeakProvider.sendInfo(plobj, bundle, msg); - } + if (_broadcastObject != null) { + broadcastTo(_broadcastObject, from, bundle, msg, attention); - } else { - SpeakProvider.sendSpeak(plobj, from, bundle, msg, - BROADCAST_MODE); + } else { + Iterator iter = CrowdServer.plreg.enumeratePlaces(); + while (iter.hasNext()) { + PlaceObject plobj = (PlaceObject)iter.next(); + if (plobj.shouldBroadcast()) { + broadcastTo(plobj, from, bundle, msg, attention); } } } } + /** + * Direct a broadcast to the specified object. + */ + protected static void broadcastTo (DObject object, + Name from, String bundle, String msg, boolean attention) + { + if (from == null) { + if (attention) { + SpeakProvider.sendAttention(object, bundle, msg); + } else { + SpeakProvider.sendInfo(object, bundle, msg); + } + + } else { + SpeakProvider.sendSpeak(object, from, bundle, msg, + BROADCAST_MODE); + } + } + /** * Processes a {@link ClientService#away} request. */ @@ -239,4 +266,7 @@ public class ChatProvider /** The entity that will authorize our chatters. */ protected static CommunicationAuthorizer _comAuth; + + /** An alternative object to which broadcasts should be sent. */ + protected static DObject _broadcastObject; } diff --git a/src/java/com/threerings/parlor/game/GameObject.dobj b/src/java/com/threerings/parlor/game/GameObject.dobj index e807d036b..234f72f0d 100644 --- a/src/java/com/threerings/parlor/game/GameObject.dobj +++ b/src/java/com/threerings/parlor/game/GameObject.dobj @@ -75,14 +75,6 @@ public class GameObject extends PlaceObject /** The player index of the creating player if this is a party game. */ public int creator; - // documentation inherited - public boolean shouldBroadcast () - { - // we do not broadcast to games because the users will get it - // on their scene objects - return false; - } - /** * Returns the number of players in the game. */ diff --git a/src/java/com/threerings/parlor/game/GameObject.java b/src/java/com/threerings/parlor/game/GameObject.java index 07724cdb6..c0930c30d 100644 --- a/src/java/com/threerings/parlor/game/GameObject.java +++ b/src/java/com/threerings/parlor/game/GameObject.java @@ -96,14 +96,6 @@ public class GameObject extends PlaceObject /** The player index of the creating player if this is a party game. */ public int creator; - // documentation inherited - public boolean shouldBroadcast () - { - // we do not broadcast to games because the users will get it - // on their scene objects - return false; - } - /** * Returns the number of players in the game. */