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,11 +61,23 @@ 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)
|
||||
{
|
||||
return -1;
|
||||
// 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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user