More support for chatting.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@160 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// $Id: ChatMessageHandler.java,v 1.1 2001/08/03 02:14:41 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.party.chat;
|
||||
|
||||
import com.threerings.cocktail.cher.dobj.MessageEvent;
|
||||
|
||||
import com.threerings.cocktail.party.Log;
|
||||
import com.threerings.cocktail.party.data.BodyObject;
|
||||
import com.threerings.cocktail.party.data.PlaceObject;
|
||||
import com.threerings.cocktail.party.server.PartyServer;
|
||||
import com.threerings.cocktail.party.server.PlaceManager;
|
||||
|
||||
/**
|
||||
* The chat message handler handles chat messages that are issued on a
|
||||
* place object with the intention of speaking to everyone in that place.
|
||||
*/
|
||||
public class ChatMessageHandler implements PlaceManager.MessageHandler
|
||||
{
|
||||
public void handleEvent (MessageEvent event, PlaceObject target)
|
||||
{
|
||||
// presently we do no ratification of chat messages, so we just
|
||||
// generate a chat notification with the message and name of the
|
||||
// speaker
|
||||
int soid = event.getSourceOid();
|
||||
BodyObject source = (BodyObject)PartyServer.omgr.getObject(soid);
|
||||
if (source == null) {
|
||||
Log.info("Chatter went away. Dropping chat request " +
|
||||
"[req=" + event + "].");
|
||||
return;
|
||||
}
|
||||
|
||||
// parse our incoming arguments
|
||||
Object[] inargs = event.getArgs();
|
||||
int reqid = ((Integer)inargs[0]).intValue();
|
||||
String message = (String)inargs[1];
|
||||
|
||||
// and generate a chat notification
|
||||
Object[] outargs = new Object[] { source.username, message };
|
||||
MessageEvent nevt = new MessageEvent(
|
||||
target.getOid(), ChatService.SPEAK_NOTIFICATION, outargs);
|
||||
PartyServer.omgr.postEvent(nevt);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ChatDirector.java,v 1.2 2001/08/02 23:47:21 mdb Exp $
|
||||
// $Id: ChatDirector.java,v 1.3 2001/08/03 02:14:41 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.party.chat;
|
||||
|
||||
@@ -61,13 +61,25 @@ public class ChatManager
|
||||
*
|
||||
* @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.
|
||||
* displays when it arrives, or -1 if we were unable to make the
|
||||
* request because we are not currently in a place.
|
||||
*/
|
||||
public int requestSpeak (String message)
|
||||
{
|
||||
// make sure we're currently in a place
|
||||
if (_place == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// dispatch a speak request on the active place object
|
||||
int reqid = _ctx.getClient().getInvocationManager().nextInvocationId();
|
||||
Object[] args = new Object[] { new Integer(reqid), message };
|
||||
MessageEvent mevt = new MessageEvent(
|
||||
_place.getOid(), ChatService.SPEAK_REQUEST, args);
|
||||
_ctx.getDObjectManager().postEvent(mevt);
|
||||
return reqid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that a tell message be delivered to the specified target
|
||||
* user.
|
||||
@@ -139,6 +151,12 @@ public class ChatManager
|
||||
{
|
||||
String speaker = (String)args[0];
|
||||
String message = (String)args[1];
|
||||
|
||||
// pass this on to our chat displays
|
||||
for (int i = 0; i < _displays.size(); i++) {
|
||||
ChatDisplay display = (ChatDisplay)_displays.get(i);
|
||||
display.displaySpeakMessage(speaker, message);
|
||||
}
|
||||
}
|
||||
|
||||
protected PartyContext _ctx;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: BodyObject.dobj,v 1.1 2001/07/20 20:07:37 mdb Exp $
|
||||
// $Id: BodyObject.dobj,v 1.2 2001/08/03 02:14:41 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.party.data;
|
||||
|
||||
@@ -7,4 +7,16 @@ import com.threerings.cocktail.cher.data.ClientObject;
|
||||
|
||||
public class BodyObject extends ClientObject
|
||||
{
|
||||
/** The field name of the <code>username</code> field. */
|
||||
public static final String USERNAME = "username";
|
||||
|
||||
/**
|
||||
* The username associated with this body object.
|
||||
*/
|
||||
public String username;
|
||||
|
||||
public void setUsername (String username)
|
||||
{
|
||||
requestAttributeChange(USERNAME, username);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
//
|
||||
// $Id: PlaceManager.java,v 1.5 2001/08/01 20:37:35 mdb Exp $
|
||||
// $Id: PlaceManager.java,v 1.6 2001/08/03 02:14:41 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.party.server;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.threerings.cocktail.cher.dobj.*;
|
||||
@@ -31,7 +32,7 @@ import com.threerings.cocktail.party.data.PlaceObject;
|
||||
* protected void didShutdown ()
|
||||
* </pre>
|
||||
*
|
||||
* as well as through additions to <code>handlEvent</code>.
|
||||
* as well as through additions to <code>handleEvent</code>.
|
||||
*/
|
||||
public class PlaceManager implements Subscriber
|
||||
{
|
||||
@@ -75,6 +76,23 @@ public class PlaceManager implements Subscriber
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a particular message handler instance to be used when
|
||||
* processing message events with the specified name.
|
||||
*
|
||||
* @param name the message name of the message events that should be
|
||||
* handled by this handler.
|
||||
* @param handler the handler to be registered.
|
||||
*/
|
||||
public void registerMessageHandler (String name, MessageHandler handler)
|
||||
{
|
||||
// create our handler map if necessary
|
||||
if (_msghandlers == null) {
|
||||
_msghandlers = new HashMap();
|
||||
}
|
||||
_msghandlers.put(name, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the place object managed by this place manager.
|
||||
*/
|
||||
@@ -99,9 +117,36 @@ public class PlaceManager implements Subscriber
|
||||
*/
|
||||
public boolean handleEvent (DEvent event, DObject target)
|
||||
{
|
||||
// if this is a message event, see if we have a handler for it
|
||||
if (event instanceof MessageEvent) {
|
||||
MessageEvent mevt = (MessageEvent)event;
|
||||
MessageHandler handler = (MessageHandler)
|
||||
_msghandlers.get(mevt.getName());
|
||||
if (handler != null) {
|
||||
handler.handleEvent(mevt, (PlaceObject)target);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* An interface used to allow the registration of standard message
|
||||
* handlers to be invoked by the place manager when particular types
|
||||
* of message events are received.
|
||||
*/
|
||||
protected static interface MessageHandler
|
||||
{
|
||||
/**
|
||||
* Invokes this message handler on the supplied event.
|
||||
*
|
||||
* @param event the message event received.
|
||||
* @param target the place object on which the message event was
|
||||
* received.
|
||||
*/
|
||||
public void handleEvent (MessageEvent event, PlaceObject target);
|
||||
}
|
||||
|
||||
/** A reference to the place object that we manage. */
|
||||
protected PlaceObject _plobj;
|
||||
|
||||
@@ -110,4 +155,7 @@ public class PlaceManager implements Subscriber
|
||||
|
||||
/** The configuration provided for this place manager. */
|
||||
protected Properties _config;
|
||||
|
||||
/** Message handlers are used to process message events. */
|
||||
protected HashMap _msghandlers;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user