From dd4b1c69c3083e061d08d6fb35931fa7318821aa Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 31 Oct 2002 23:27:16 +0000 Subject: [PATCH] Added broadcast chat mechanism. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1875 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../crowd/chat/client/ChatDirector.java | 19 +++++++++- .../crowd/chat/client/ChatService.java | 12 +++++- .../threerings/crowd/chat/data/ChatCodes.java | 6 ++- .../crowd/chat/data/ChatMarshaller.java | 18 ++++++++- .../crowd/chat/server/ChatDispatcher.java | 12 +++++- .../crowd/chat/server/ChatProvider.java | 37 +++++++++++++++++-- 6 files changed, 93 insertions(+), 11 deletions(-) diff --git a/src/java/com/threerings/crowd/chat/client/ChatDirector.java b/src/java/com/threerings/crowd/chat/client/ChatDirector.java index 840f4ec44..5377034fa 100644 --- a/src/java/com/threerings/crowd/chat/client/ChatDirector.java +++ b/src/java/com/threerings/crowd/chat/client/ChatDirector.java @@ -1,5 +1,5 @@ // -// $Id: ChatDirector.java,v 1.36 2002/10/30 01:47:12 ray Exp $ +// $Id: ChatDirector.java,v 1.37 2002/10/31 23:27:16 mdb Exp $ package com.threerings.crowd.chat; @@ -290,6 +290,23 @@ public class ChatDirector extends BasicDirector speakService.speak(_ctx.getClient(), message, mode); } + /** + * Requests to send a site-wide broadcast message. + * + * @param message the contents of the message. + */ + public void requestBroadcast (String message) + { + _cservice.broadcast( + _ctx.getClient(), message, new ChatService.InvocationListener () { + public void requestFailed (String reason) { + displayFeedbackMessage( + _bundle, MessageBundle.compose( + "m.broadcast_failed", reason)); + } + }); + } + /** * Requests that a tell message be delivered to the specified target * user. diff --git a/src/java/com/threerings/crowd/chat/client/ChatService.java b/src/java/com/threerings/crowd/chat/client/ChatService.java index a2810d5b9..8824f6298 100644 --- a/src/java/com/threerings/crowd/chat/client/ChatService.java +++ b/src/java/com/threerings/crowd/chat/client/ChatService.java @@ -1,5 +1,5 @@ // -// $Id: ChatService.java,v 1.9 2002/10/30 01:47:12 ray Exp $ +// $Id: ChatService.java,v 1.10 2002/10/31 23:27:16 mdb Exp $ package com.threerings.crowd.chat; @@ -45,4 +45,14 @@ public interface ChatService extends InvocationService */ public void tell (Client client, String target, String message, TellListener listener); + + /** + * Requests that a message be broadcast to all users in the system. + * + * @param client a connected, operational client instance. + * @param message the contents of the message. + * @param listener the reference that will receive a failure response. + */ + public void broadcast (Client client, String message, + InvocationListener listener); } diff --git a/src/java/com/threerings/crowd/chat/data/ChatCodes.java b/src/java/com/threerings/crowd/chat/data/ChatCodes.java index e33152636..8f3ceaaf0 100644 --- a/src/java/com/threerings/crowd/chat/data/ChatCodes.java +++ b/src/java/com/threerings/crowd/chat/data/ChatCodes.java @@ -1,5 +1,5 @@ // -// $Id: ChatCodes.java,v 1.12 2002/10/30 01:47:12 ray Exp $ +// $Id: ChatCodes.java,v 1.13 2002/10/31 23:27:16 mdb Exp $ package com.threerings.crowd.chat; @@ -38,6 +38,10 @@ public interface ChatCodes extends InvocationCodes * actually an emote. */ public static final byte EMOTE_MODE = 2; + /** A {@link SpeakService#speak} mode to indicate that a speak is + * actually a server-wide broadcast. */ + public static final byte BROADCAST_MODE = 3; + /** An error code delivered when the user targeted for a tell * notification is not online. */ public static final String USER_NOT_ONLINE = "m.user_not_online"; diff --git a/src/java/com/threerings/crowd/chat/data/ChatMarshaller.java b/src/java/com/threerings/crowd/chat/data/ChatMarshaller.java index 955e2b75d..e25be1445 100644 --- a/src/java/com/threerings/crowd/chat/data/ChatMarshaller.java +++ b/src/java/com/threerings/crowd/chat/data/ChatMarshaller.java @@ -1,11 +1,12 @@ // -// $Id: ChatMarshaller.java,v 1.3 2002/10/30 01:47:12 ray Exp $ +// $Id: ChatMarshaller.java,v 1.4 2002/10/31 23:27:16 mdb Exp $ package com.threerings.crowd.chat; import com.threerings.crowd.chat.ChatService; import com.threerings.crowd.chat.ChatService.TellListener; import com.threerings.presents.client.Client; +import com.threerings.presents.client.InvocationService.InvocationListener; import com.threerings.presents.data.InvocationMarshaller; import com.threerings.presents.dobj.InvocationResponseEvent; @@ -80,5 +81,18 @@ public class ChatMarshaller extends InvocationMarshaller }); } - // Generated on 17:55:05 10/29/02. + /** The method id used to dispatch {@link #broadcast} requests. */ + public static final int BROADCAST = 2; + + // documentation inherited from interface + public void broadcast (Client arg1, String arg2, InvocationListener arg3) + { + ListenerMarshaller listener3 = new ListenerMarshaller(); + listener3.listener = arg3; + sendRequest(arg1, BROADCAST, new Object[] { + arg2, listener3 + }); + } + + // Generated on 13:40:31 10/31/02. } diff --git a/src/java/com/threerings/crowd/chat/server/ChatDispatcher.java b/src/java/com/threerings/crowd/chat/server/ChatDispatcher.java index cb9daa9e4..81c041741 100644 --- a/src/java/com/threerings/crowd/chat/server/ChatDispatcher.java +++ b/src/java/com/threerings/crowd/chat/server/ChatDispatcher.java @@ -1,5 +1,5 @@ // -// $Id: ChatDispatcher.java,v 1.3 2002/10/30 01:47:12 ray Exp $ +// $Id: ChatDispatcher.java,v 1.4 2002/10/31 23:27:16 mdb Exp $ package com.threerings.crowd.chat; @@ -7,6 +7,7 @@ import com.threerings.crowd.chat.ChatMarshaller; import com.threerings.crowd.chat.ChatService; import com.threerings.crowd.chat.ChatService.TellListener; import com.threerings.presents.client.Client; +import com.threerings.presents.client.InvocationService.InvocationListener; import com.threerings.presents.data.ClientObject; import com.threerings.presents.data.InvocationMarshaller; import com.threerings.presents.server.InvocationDispatcher; @@ -45,10 +46,17 @@ public class ChatDispatcher extends InvocationDispatcher ); return; + case ChatMarshaller.BROADCAST: + ((ChatProvider)provider).broadcast( + source, + (String)args[0], (InvocationListener)args[1] + ); + return; + default: super.dispatchRequest(source, methodId, args); } } - // Generated on 17:55:05 10/29/02. + // Generated on 13:40:31 10/31/02. } diff --git a/src/java/com/threerings/crowd/chat/server/ChatProvider.java b/src/java/com/threerings/crowd/chat/server/ChatProvider.java index c119a026b..7ebe63c5a 100644 --- a/src/java/com/threerings/crowd/chat/server/ChatProvider.java +++ b/src/java/com/threerings/crowd/chat/server/ChatProvider.java @@ -1,8 +1,14 @@ // -// $Id: ChatProvider.java,v 1.15 2002/10/30 01:56:17 ray Exp $ +// $Id: ChatProvider.java,v 1.16 2002/10/31 23:27:16 mdb Exp $ package com.threerings.crowd.chat; +import java.util.Iterator; + +import com.threerings.util.MessageBundle; +import com.threerings.util.TimeUtil; + +import com.threerings.presents.client.InvocationService.InvocationListener; import com.threerings.presents.data.ClientObject; import com.threerings.presents.dobj.DObjectManager; import com.threerings.presents.dobj.MessageEvent; @@ -14,13 +20,11 @@ import com.threerings.presents.server.InvocationProvider; import com.threerings.crowd.Log; import com.threerings.crowd.data.BodyObject; import com.threerings.crowd.data.OccupantInfo; +import com.threerings.crowd.data.PlaceObject; import com.threerings.crowd.server.CrowdServer; import com.threerings.crowd.chat.ChatService.TellListener; -import com.threerings.util.MessageBundle; -import com.threerings.util.TimeUtil; - /** * The chat provider handles the server side of the chat-related * invocation services. @@ -28,6 +32,9 @@ import com.threerings.util.TimeUtil; public class ChatProvider implements ChatCodes, InvocationProvider { + /** The access control identifier for broadcast chat privileges. */ + public static final String BROADCAST_TOKEN = "crowd.chat.broadcast"; + /** * Initializes the chat services and registers a chat provider with * the invocation manager. @@ -77,6 +84,28 @@ public class ChatProvider } } + /** + * Processes a {@link ClientService#broadcast} request. + */ + public void broadcast (ClientObject caller, String message, + InvocationListener listener) + throws InvocationException + { + BodyObject body = (BodyObject)caller; + + // make sure the requesting user has broadcast privileges + if (CrowdServer.actrl.checkAccess(body, BROADCAST_TOKEN)) { + throw new InvocationException(ACCESS_DENIED); + } + + Iterator iter = CrowdServer.plreg.enumeratePlaces(); + while (iter.hasNext()) { + PlaceObject plobj = (PlaceObject)iter.next(); + SpeakProvider.sendSpeak(plobj, body.username, null, + message, BROADCAST_MODE); + } + } + /** * Delivers a tell notification to the specified target player, * originating with the specified speaker.