Chat revamp, phase 1.

- Repackaged crowd/chat
- All messages are delivered to the client via ChatMessage messages,
  including tells.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2631 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2003-06-03 21:41:33 +00:00
parent 368cd940b6
commit 40afe3cb94
33 changed files with 218 additions and 416 deletions
@@ -1,7 +1,7 @@
//
// $Id: SpeakProvider.java,v 1.4 2003/03/30 02:52:41 mdb Exp $
// $Id: SpeakProvider.java,v 1.5 2003/06/03 21:41:33 ray Exp $
package com.threerings.crowd.chat;
package com.threerings.crowd.chat.server;
import com.samskivert.util.ObserverList;
@@ -13,6 +13,11 @@ import com.threerings.presents.server.InvocationProvider;
import com.threerings.crowd.Log;
import com.threerings.crowd.data.BodyObject;
import com.threerings.crowd.chat.data.ChatCodes;
import com.threerings.crowd.chat.data.ChatMessage;
import com.threerings.crowd.chat.data.SystemMessage;
import com.threerings.crowd.chat.data.UserMessage;
/**
* Provides the back-end of the chat speaking facilities. A server entity
* can make "speech" available among the subscribers of a particular
@@ -37,28 +42,6 @@ public class SpeakProvider
public boolean isValidSpeaker (DObject speakObj, ClientObject speaker);
}
/**
* An interface to be implemented by entities that would like to be
* notified of all speak messages.
*/
public static interface SpeakObserver
{
/**
* Called with the relevant details for every speak message sent
* by the speak provider.
*/
public void handleSpeakMessage (DObject speakObj, String speaker,
String bundle, String message,
byte mode);
/**
* Called with the relevant details for every system speak message
* sent by the speak provider.
*/
public void handleSystemSpeakMessage (
DObject speakObj, String bundle, String message);
}
/**
* Creates a speak provider that will provide speech on the supplied
* distributed object.
@@ -80,7 +63,11 @@ public class SpeakProvider
public void speak (ClientObject caller, String message, byte mode)
{
// ensure that the speaker is valid
if (!_validator.isValidSpeaker(_speakObj, caller)) {
// TODO: broadcast should be handled more like a system message
// rather than as a mode for a user message so that we don't
// have to do this validation here. Or not.
if ((mode == BROADCAST_MODE) ||
!_validator.isValidSpeaker(_speakObj, caller)) {
Log.warning("Refusing invalid speak request " +
"[caller=" + caller.who() +
", speakObj=" + _speakObj.which() +
@@ -93,24 +80,6 @@ public class SpeakProvider
}
}
/**
* Registers the supplied speak observer to be notified of all speak
* messages.
*/
public static void addSpeakObserver (SpeakObserver obs)
{
_observers.add(obs);
}
/**
* Removes the supplied speak observer from the list of observers to
* be notified of all speak messages.
*/
public static void removeSpeakObserver (SpeakObserver obs)
{
_observers.remove(obs);
}
/**
* Sends a speak notification to the specified place object
* originating with the specified speaker (the speaker optionally
@@ -152,17 +121,7 @@ public class SpeakProvider
public static void sendSpeak (DObject speakObj, String speaker,
String bundle, String message, byte mode)
{
// pass the message along to all observers
notifyObservers(speakObj, speaker, bundle, message, mode);
// post the message to the relevant object
Object[] outargs = null;
if (bundle == null) {
outargs = new Object[] { speaker, message, new Byte(mode) };
} else {
outargs = new Object[] { speaker, bundle, message, new Byte(mode) };
}
speakObj.postMessage(SPEAK_NOTIFICATION, outargs);
sendMessage(speakObj, new UserMessage(message, bundle, speaker, mode));
}
/**
@@ -180,60 +139,16 @@ public class SpeakProvider
public static void sendSystemSpeak (
DObject speakObj, String bundle, String message)
{
// pass the message along to all observers
notifyObservers(speakObj, null, bundle, message,
ChatCodes.DEFAULT_MODE);
// post the message to the relevant object
speakObj.postMessage(
SYSTEM_NOTIFICATION, new Object[] { bundle, message });
sendMessage(speakObj, new SystemMessage(message, bundle));
}
/**
* Notifies all registered speak observers of the supplied speak
* message.
* Send the specified message on the specified object.
*/
protected static void notifyObservers (DObject speakObj, String speaker,
String bundle, String message,
byte mode)
public static void sendMessage (DObject speakObj, ChatMessage msg)
{
_spokenOp.setMessage(speakObj, speaker, bundle, message, mode);
_observers.apply(_spokenOp);
}
protected static class SpokenOp implements ObserverList.ObserverOp
{
/**
* Sets the message information to be passed along to all {@link
* SpeakObserver}s.
*/
public void setMessage (DObject speakObj, String speaker, String bundle,
String message, byte mode)
{
_speakObj = speakObj;
_speaker = speaker;
_bundle = bundle;
_message = message;
_mode = mode;
}
// documentation inherited
public boolean apply (Object observer)
{
if (_speaker == null) {
((SpeakObserver)observer).handleSystemSpeakMessage(
_speakObj, _bundle, _message);
} else {
((SpeakObserver)observer).handleSpeakMessage(
_speakObj, _speaker, _bundle, _message, _mode);
}
return true;
}
protected DObject _speakObj;
protected String _speaker, _bundle, _message;
protected byte _mode;
// post the message to the relevant object
speakObj.postMessage(CHAT_NOTIFICATION, new Object[] { msg });
}
/** Our speech object. */
@@ -241,11 +156,4 @@ public class SpeakProvider
/** The entity that will validate our speakers. */
protected SpeakerValidator _validator;
/** The observers to be notified of all speak messages. */
protected static ObserverList _observers =
new ObserverList(ObserverList.FAST_UNSAFE_NOTIFY);
/** The operation used to notify observers of speak messages. */
protected static SpokenOp _spokenOp = new SpokenOp();
}