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:
@@ -1,11 +1,11 @@
|
||||
//
|
||||
// $Id: ChatDispatcher.java,v 1.4 2002/10/31 23:27:16 mdb Exp $
|
||||
// $Id: ChatDispatcher.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.threerings.crowd.chat.ChatMarshaller;
|
||||
import com.threerings.crowd.chat.ChatService;
|
||||
import com.threerings.crowd.chat.ChatService.TellListener;
|
||||
import com.threerings.crowd.chat.client.ChatService;
|
||||
import com.threerings.crowd.chat.client.ChatService.TellListener;
|
||||
import com.threerings.crowd.chat.data.ChatMarshaller;
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.client.InvocationService.InvocationListener;
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
@@ -57,6 +57,4 @@ public class ChatDispatcher extends InvocationDispatcher
|
||||
super.dispatchRequest(source, methodId, args);
|
||||
}
|
||||
}
|
||||
|
||||
// Generated on 13:40:31 10/31/02.
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// $Id: ChatProvider.java,v 1.18 2002/11/01 01:01:27 mdb Exp $
|
||||
// $Id: ChatProvider.java,v 1.19 2003/06/03 21:41:33 ray Exp $
|
||||
|
||||
package com.threerings.crowd.chat;
|
||||
package com.threerings.crowd.chat.server;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
@@ -23,7 +23,9 @@ 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.crowd.chat.client.ChatService.TellListener;
|
||||
import com.threerings.crowd.chat.data.ChatCodes;
|
||||
import com.threerings.crowd.chat.data.UserMessage;
|
||||
|
||||
/**
|
||||
* The chat provider handles the server side of the chat-related
|
||||
@@ -123,7 +125,8 @@ public class ChatProvider
|
||||
public static void sendTellMessage (
|
||||
BodyObject target, String speaker, String bundle, String message)
|
||||
{
|
||||
ChatSender.sendTell(target, speaker, bundle, message);
|
||||
SpeakProvider.sendMessage(target,
|
||||
new UserMessage(message, bundle, speaker, DEFAULT_MODE));
|
||||
}
|
||||
|
||||
/** The distributed object manager used by the chat services. */
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
//
|
||||
// $Id: ChatSender.java,v 1.2 2002/08/20 19:38:13 mdb Exp $
|
||||
|
||||
package com.threerings.crowd.chat;
|
||||
|
||||
import com.threerings.crowd.chat.ChatDecoder;
|
||||
import com.threerings.crowd.chat.ChatReceiver;
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import com.threerings.presents.server.InvocationSender;
|
||||
|
||||
/**
|
||||
* Used to issue notifications to a {@link ChatReceiver} instance on a
|
||||
* client.
|
||||
*
|
||||
* <p> Generated from <code>
|
||||
* $Id: ChatSender.java,v 1.2 2002/08/20 19:38:13 mdb Exp $
|
||||
* </code>
|
||||
*/
|
||||
public class ChatSender extends InvocationSender
|
||||
{
|
||||
/**
|
||||
* Issues a notification that will result in a call to {@link
|
||||
* ChatReceiver#receivedTell} on a client.
|
||||
*/
|
||||
public static void sendTell (
|
||||
ClientObject target, String arg1, String arg2, String arg3)
|
||||
{
|
||||
sendNotification(
|
||||
target, ChatDecoder.RECEIVER_CODE, ChatDecoder.RECEIVED_TELL,
|
||||
new Object[] { arg1, arg2, arg3 });
|
||||
}
|
||||
|
||||
// Generated on 12:36:59 08/20/02.
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
//
|
||||
// $Id: SpeakDispatcher.java,v 1.2 2002/08/20 19:38:13 mdb Exp $
|
||||
// $Id: SpeakDispatcher.java,v 1.3 2003/06/03 21:41:33 ray Exp $
|
||||
|
||||
package com.threerings.crowd.chat;
|
||||
package com.threerings.crowd.chat.server;
|
||||
|
||||
import com.threerings.crowd.chat.SpeakMarshaller;
|
||||
import com.threerings.crowd.chat.SpeakService;
|
||||
import com.threerings.crowd.chat.client.SpeakService;
|
||||
import com.threerings.crowd.chat.data.SpeakMarshaller;
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import com.threerings.presents.data.InvocationMarshaller;
|
||||
@@ -13,10 +13,6 @@ import com.threerings.presents.server.InvocationException;
|
||||
|
||||
/**
|
||||
* Dispatches requests to the {@link SpeakProvider}.
|
||||
*
|
||||
* <p> Generated from <code>
|
||||
* $Id: SpeakDispatcher.java,v 1.2 2002/08/20 19:38:13 mdb Exp $
|
||||
* </code>
|
||||
*/
|
||||
public class SpeakDispatcher extends InvocationDispatcher
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user