Beginnings of the tell (client to client messaging) implementation.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@181 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ChatDirector.java,v 1.3 2001/08/03 02:14:41 mdb Exp $
|
||||
// $Id: ChatDirector.java,v 1.4 2001/08/04 02:54:28 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.party.chat;
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.threerings.cocktail.cher.dobj.*;
|
||||
|
||||
import com.threerings.cocktail.party.Log;
|
||||
import com.threerings.cocktail.party.client.LocationObserver;
|
||||
import com.threerings.cocktail.cher.client.InvocationReceiver;
|
||||
import com.threerings.cocktail.party.data.PlaceObject;
|
||||
import com.threerings.cocktail.party.util.PartyContext;
|
||||
|
||||
@@ -17,7 +18,7 @@ import com.threerings.cocktail.party.util.PartyContext;
|
||||
* messaging.
|
||||
*/
|
||||
public class ChatManager
|
||||
implements LocationObserver, Subscriber
|
||||
implements LocationObserver, Subscriber, InvocationReceiver
|
||||
{
|
||||
/**
|
||||
* Creates a chat manager and initializes it with the supplied
|
||||
@@ -30,6 +31,10 @@ public class ChatManager
|
||||
// keep the context around
|
||||
_ctx = ctx;
|
||||
|
||||
// register ourselves as the chat receiver
|
||||
_ctx.getClient().getInvocationManager().registerReceiver(
|
||||
ChatService.MODULE, this);
|
||||
|
||||
// register ourselves as a location observer
|
||||
_ctx.getLocationManager().addLocationObserver(this);
|
||||
}
|
||||
@@ -94,7 +99,7 @@ public class ChatManager
|
||||
*/
|
||||
public int requestTell (String target, String message)
|
||||
{
|
||||
return -1;
|
||||
return ChatService.tell(_ctx.getClient(), target, message, this);
|
||||
}
|
||||
|
||||
public boolean locationMayChange (int placeId)
|
||||
@@ -147,6 +152,38 @@ public class ChatManager
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the invocation manager when another client has requested
|
||||
* a tell message be delivered to this client.
|
||||
*/
|
||||
public void handleTellNotification (String source, String message)
|
||||
{
|
||||
Log.info("Tell notification [src=" + source +
|
||||
", msg=" + message + "].");
|
||||
}
|
||||
|
||||
/**
|
||||
* Called in response to a tell request that succeeded.
|
||||
*
|
||||
* @param invid the invocation id of the tell request.
|
||||
*/
|
||||
public void handleTellSuccess (int invid)
|
||||
{
|
||||
Log.info("Tell succeeded [invid=" + invid + "].");
|
||||
}
|
||||
|
||||
/**
|
||||
* Called in response to a tell request that failed.
|
||||
*
|
||||
* @param invid the invocation id of the tell request.
|
||||
* @param reason the code that describes the reason for failure.
|
||||
*/
|
||||
public void handleTellFailed (int invid, String reason)
|
||||
{
|
||||
Log.info("Tell failed [invid=" + invid +
|
||||
", reason=" + reason + "].");
|
||||
}
|
||||
|
||||
protected void handleSpeakMessage (Object[] args)
|
||||
{
|
||||
String speaker = (String)args[0];
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
//
|
||||
// $Id: ChatReceiver.java,v 1.1 2001/07/20 20:07:37 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.party.chat;
|
||||
|
||||
import com.threerings.cocktail.cher.client.InvocationReceiver;
|
||||
|
||||
public class ChatReceiver extends InvocationReceiver
|
||||
{
|
||||
}
|
||||
@@ -1,8 +1,12 @@
|
||||
//
|
||||
// $Id: ChatService.java,v 1.2 2001/08/02 23:46:47 mdb Exp $
|
||||
// $Id: ChatService.java,v 1.3 2001/08/04 02:54:28 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.party.chat;
|
||||
|
||||
import com.threerings.cocktail.cher.client.Client;
|
||||
import com.threerings.cocktail.cher.client.InvocationManager;
|
||||
import com.threerings.cocktail.party.Log;
|
||||
|
||||
/**
|
||||
* The chat services provide a mechanism by which the client can broadcast
|
||||
* chat messages to all clients that are subscribed to a particular place
|
||||
@@ -21,4 +25,33 @@ public class ChatService
|
||||
|
||||
/** The message identifier for a speak notification message. */
|
||||
public static final String SPEAK_NOTIFICATION = "spknot";
|
||||
|
||||
/** The message identifier for a tell request. */
|
||||
public static final String TELL_REQUEST = "Tell";
|
||||
|
||||
/** The message identifier for a tell notification. */
|
||||
public static final String TELL_NOTIFICATION = "Tell";
|
||||
|
||||
/**
|
||||
* Requests that a tell message be delivered to the user with username
|
||||
* equal to <code>target</code>.
|
||||
*
|
||||
* @param client a connected, operational client instance.
|
||||
* @param target the username of the user to which the tell message
|
||||
* should be delivered.
|
||||
* @param message the contents of the message.
|
||||
* @param rsptarget the chat manager reference that will receive the
|
||||
* tell response.
|
||||
*
|
||||
* @return the invocation request id of the generated tell request.
|
||||
*/
|
||||
public static int tell (Client client, String target, String message,
|
||||
ChatManager rsptarget)
|
||||
{
|
||||
InvocationManager invmgr = client.getInvocationManager();
|
||||
Object[] args = new Object[] { target, message };
|
||||
Log.info("Sending tell request [tgt=" + target +
|
||||
", msg=" + message + "].");
|
||||
return invmgr.invoke(MODULE, TELL_REQUEST, args, rsptarget);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,33 @@
|
||||
//
|
||||
// $Id: ChatProvider.java,v 1.1 2001/07/20 20:07:37 mdb Exp $
|
||||
// $Id: ChatProvider.java,v 1.2 2001/08/04 02:54:28 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.party.chat;
|
||||
|
||||
import com.threerings.cocktail.cher.server.InvocationProvider;
|
||||
import com.threerings.cocktail.party.data.BodyObject;
|
||||
import com.threerings.cocktail.party.server.PartyServer;
|
||||
|
||||
public class ChatProvider extends InvocationProvider
|
||||
{
|
||||
/**
|
||||
* Processes a request from a client to deliver a tell message to
|
||||
* another client.
|
||||
*/
|
||||
public Object[] handleTellRequest (
|
||||
BodyObject source, String target, String message)
|
||||
{
|
||||
// look up the target body object
|
||||
BodyObject tobj = PartyServer.lookupBody(target);
|
||||
if (tobj == null) {
|
||||
return createResponse("TellFailed", "m.player_not_online");
|
||||
}
|
||||
|
||||
// deliver a tell notification to the target player
|
||||
Object[] args = new Object[] { source.username, message };
|
||||
PartyServer.invmgr.sendNotification(
|
||||
tobj.getOid(), ChatService.MODULE, ChatService.TELL_NOTIFICATION,
|
||||
args);
|
||||
|
||||
return createResponse("TellSucceeded");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user