diff --git a/src/java/com/threerings/crowd/chat/client/ChatDirector.java b/src/java/com/threerings/crowd/chat/client/ChatDirector.java
new file mode 100644
index 000000000..60cb752a9
--- /dev/null
+++ b/src/java/com/threerings/crowd/chat/client/ChatDirector.java
@@ -0,0 +1,147 @@
+//
+// $Id: ChatDirector.java,v 1.1 2001/08/02 23:46:47 mdb Exp $
+
+package com.threerings.cocktail.party.chat;
+
+import java.util.ArrayList;
+import com.threerings.cocktail.cher.dobj.*;
+
+import com.threerings.cocktail.party.Log;
+import com.threerings.cocktail.party.client.LocationObserver;
+import com.threerings.cocktail.party.data.PlaceObject;
+import com.threerings.cocktail.party.util.PartyContext;
+
+/**
+ * The chat manager is the client side coordinator of all chat related
+ * services. It handles both place constrainted chat as well as direct
+ * messaging.
+ */
+public class ChatManager
+ implements LocationObserver, Subscriber
+{
+ /**
+ * Creates a chat manager and initializes it with the supplied
+ * context. The chat manager will register itself as a location
+ * observer so that it can automatically process place constrained
+ * chat.
+ */
+ public ChatManager (PartyContext ctx)
+ {
+ // keep the context around
+ _ctx = ctx;
+
+ // register ourselves as a location observer
+ _ctx.getLocationManager().addLocationObserver(this);
+ }
+
+ /**
+ * Adds the supplied chat display to the chat display list. It will
+ * subsequently be notified of incoming chat messages as well as tell
+ * responses.
+ */
+ public void addChatDisplay (ChatDisplay display)
+ {
+ _displays.add(display);
+ }
+
+ /**
+ * Removes the specified chat display from the chat display list. The
+ * display will no longer receive chat related notifications.
+ */
+ public void removeChatDisplay (ChatDisplay display)
+ {
+ _displays.remove(display);
+ }
+
+ /**
+ * Requests that a speak message be generated and delivered to all
+ * users that occupy the place object that we currently occupy.
+ *
+ * @param message the contents of the speak message.
+ *
+ * @return an id which can be used to coordinate this speak request
+ * with the response that will be delivered to all active chat
+ * displays when it arrives.
+ */
+ public int requestSpeak (String message)
+ {
+ }
+
+ /**
+ * Requests that a tell message be delivered to the specified target
+ * user.
+ *
+ * @param target the username of the user to which the tell message
+ * should be delivered.
+ * @param message the contents of the tell message.
+ *
+ * @return an id which can be used to coordinate this request with the
+ * tell response that will be delivered to all active chat displays
+ * when it arrives.
+ */
+ public int requestTell (String target, String message)
+ {
+ return -1;
+ }
+
+ public boolean locationMayChange (int placeId)
+ {
+ // we accept all location change requests
+ return true;
+ }
+
+ public void locationDidChange (PlaceObject place)
+ {
+ if (_place != null) {
+ // unsubscribe from our old object
+ _place.removeSubscriber(this);
+ }
+
+ // subscribe to the new object
+ _place = place;
+ _place.addSubscriber(this);
+ }
+
+ public void locationChangeFailed (int placeId, String reason)
+ {
+ // nothing we care about
+ }
+
+ public void objectAvailable (DObject object)
+ {
+ // nothing to do here
+ }
+
+ public void requestFailed (int oid, ObjectAccessException cause)
+ {
+ // nothing to do here
+ }
+
+ public boolean handleEvent (DEvent event, DObject target)
+ {
+ // we only care about message events
+ if (!(event instanceof MessageEvent)) {
+ return true;
+ }
+
+ // and only those of proper name
+ MessageEvent mevt = (MessageEvent)event;
+ String name = mevt.getName();
+ if (name.equals(ChatService.SPEAK_NOTIFICATION)) {
+ handleSpeakMessage(mevt.getArgs());
+ }
+
+ return true;
+ }
+
+ protected void handleSpeakMessage (Object[] args)
+ {
+ String speaker = (String)args[0];
+ String message = (String)args[1];
+ }
+
+ protected PartyContext _ctx;
+ protected PlaceObject _place;
+
+ protected ArrayList _displays = new ArrayList();
+}
diff --git a/src/java/com/threerings/crowd/chat/client/ChatDisplay.java b/src/java/com/threerings/crowd/chat/client/ChatDisplay.java
new file mode 100644
index 000000000..284d19365
--- /dev/null
+++ b/src/java/com/threerings/crowd/chat/client/ChatDisplay.java
@@ -0,0 +1,56 @@
+//
+// $Id: ChatDisplay.java,v 1.1 2001/08/02 23:46:47 mdb Exp $
+
+package com.threerings.cocktail.party.chat;
+
+/**
+ * A chat display provides a means by which chat messages can be
+ * displayed. The chat display will be notified when chat messages of
+ * various sorts have been received by the client.
+ */
+public interface ChatDisplay
+{
+ /**
+ * Called to display a speak message. A speak message is one that is
+ * broadcast to all occupants of a particular place. A speak message
+ * originated by this client will result in a subsequent call to this
+ * method after the speak message is accepted by the server and
+ * broadcast to everyone in the place.
+ *
+ * @param speaker the username of the speaker.
+ * @param message the text of the message.
+ */
+ public void displaySpeakMessage (String speaker, String message);
+
+ /**
+ * Called to display a tell message. A tell message is one that is
+ * delivered directly from one user to another regardless of their
+ * location in the system.
+ *
+ * @param speaker the username of the speaker.
+ * @param message the text of the message.
+ */
+ public void displayTellMessage (String speaker, String message);
+
+ /**
+ * Called in response to a chat request (either speak or tell) that
+ * originated on this client. The request id supplied will match the
+ * one returned when the request was generated and the status will
+ * either indicate success (by being equal to
+ * Codes.SUCCESS) or failure (in which case it will
+ * contain a message failure code which can be converted into a
+ * displayable string).
+ *
+ *
A chat display should track outstanding chat requests so that + * it can properly handle the response when it arrives. + * + * @param reqid the request id of the request that resulted in this + * response. + * @param status the message code indicating whether the chat request + * was successful or not. + * + * @see ChatManager#requestSpeak + * @see ChatManager#requestTell + */ + public void handleResponse (int reqid, String status); +} diff --git a/src/java/com/threerings/crowd/chat/client/ChatService.java b/src/java/com/threerings/crowd/chat/client/ChatService.java index bb4d53c8e..a834a5f7d 100644 --- a/src/java/com/threerings/crowd/chat/client/ChatService.java +++ b/src/java/com/threerings/crowd/chat/client/ChatService.java @@ -1,8 +1,24 @@ // -// $Id: ChatService.java,v 1.1 2001/07/20 20:07:37 mdb Exp $ +// $Id: ChatService.java,v 1.2 2001/08/02 23:46:47 mdb Exp $ package com.threerings.cocktail.party.chat; +/** + * The chat services provide a mechanism by which the client can broadcast + * chat messages to all clients that are subscribed to a particular place + * object or directly to a particular client. These services should not be + * used directly, but instead should be accessed via the chat manager. + * + * @see ChatManager + */ public class ChatService { + /** The module name for the chat services. */ + public static final String MODULE = "chat"; + + /** The message identifier for a speak request message. */ + public static final String SPEAK_REQUEST = "spkreq"; + + /** The message identifier for a speak notification message. */ + public static final String SPEAK_NOTIFICATION = "spknot"; }