Created fooCodes interfaces to go along with invocation service
packages. These contain all the message codes as well as error response codes that are used by a particular invocation service. Also changed client.LocationManager to client.LocationDirector and chat.ChatManager to chat.ChatDirector to go along with the new philosophy of naming the client-side managing entity for an invocation service a director. Also elimitated cocktail.util.Codes since it's no longer used as a central repository for codes (instead they are in InvocationCodes and its derivatives). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@368 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ChatDirector.java,v 1.6 2001/08/22 00:08:39 mdb Exp $
|
||||
// $Id: ChatDirector.java,v 1.7 2001/10/01 22:14:55 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.party.chat;
|
||||
|
||||
@@ -7,7 +7,6 @@ import java.util.ArrayList;
|
||||
|
||||
import com.threerings.cocktail.cher.client.*;
|
||||
import com.threerings.cocktail.cher.dobj.*;
|
||||
import com.threerings.cocktail.cher.util.Codes;
|
||||
|
||||
import com.threerings.cocktail.party.Log;
|
||||
import com.threerings.cocktail.party.client.LocationObserver;
|
||||
@@ -15,20 +14,20 @@ import com.threerings.cocktail.party.data.PlaceObject;
|
||||
import com.threerings.cocktail.party.util.PartyContext;
|
||||
|
||||
/**
|
||||
* The chat manager is the client side coordinator of all chat related
|
||||
* The chat director is the client side coordinator of all chat related
|
||||
* services. It handles both place constrainted chat as well as direct
|
||||
* messaging.
|
||||
*/
|
||||
public class ChatManager
|
||||
implements LocationObserver, Subscriber, InvocationReceiver
|
||||
public class ChatDirector
|
||||
implements LocationObserver, Subscriber, InvocationReceiver, ChatCodes
|
||||
{
|
||||
/**
|
||||
* Creates a chat manager and initializes it with the supplied
|
||||
* context. The chat manager will register itself as a location
|
||||
* Creates a chat director and initializes it with the supplied
|
||||
* context. The chat director will register itself as a location
|
||||
* observer so that it can automatically process place constrained
|
||||
* chat.
|
||||
*/
|
||||
public ChatManager (PartyContext ctx)
|
||||
public ChatDirector (PartyContext ctx)
|
||||
{
|
||||
// keep the context around
|
||||
_ctx = ctx;
|
||||
@@ -39,12 +38,12 @@ public class ChatManager
|
||||
public void clientDidLogon (Client client)
|
||||
{
|
||||
client.getInvocationManager().registerReceiver(
|
||||
ChatService.MODULE, ChatManager.this);
|
||||
MODULE_NAME, ChatDirector.this);
|
||||
}
|
||||
});
|
||||
|
||||
// register ourselves as a location observer
|
||||
_ctx.getLocationManager().addLocationObserver(this);
|
||||
_ctx.getLocationDirector().addLocationObserver(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,7 +182,7 @@ public class ChatManager
|
||||
// pass this on to our chat displays
|
||||
for (int i = 0; i < _displays.size(); i++) {
|
||||
ChatDisplay display = (ChatDisplay)_displays.get(i);
|
||||
display.handleResponse(invid, Codes.SUCCESS);
|
||||
display.handleResponse(invid, SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ChatDisplay.java,v 1.1 2001/08/02 23:46:47 mdb Exp $
|
||||
// $Id: ChatDisplay.java,v 1.2 2001/10/01 22:14:55 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.party.chat;
|
||||
|
||||
@@ -36,10 +36,9 @@ public interface ChatDisplay
|
||||
* Called in response to a chat request (either speak or tell) that
|
||||
* originated on this client. The request id supplied will match the
|
||||
* one returned when the request was generated and the status will
|
||||
* either indicate success (by being equal to
|
||||
* <code>Codes.SUCCESS</code>) or failure (in which case it will
|
||||
* contain a message failure code which can be converted into a
|
||||
* displayable string).
|
||||
* either indicate success (by being equal to <code>SUCCESS</code>) or
|
||||
* failure (in which case it will contain a message failure code which
|
||||
* can be converted into a displayable string).
|
||||
*
|
||||
* <p> A chat display should track outstanding chat requests so that
|
||||
* it can properly handle the response when it arrives.
|
||||
@@ -49,8 +48,8 @@ public interface ChatDisplay
|
||||
* @param status the message code indicating whether the chat request
|
||||
* was successful or not.
|
||||
*
|
||||
* @see ChatManager#requestSpeak
|
||||
* @see ChatManager#requestTell
|
||||
* @see ChatDirector#requestSpeak
|
||||
* @see ChatDirector#requestTell
|
||||
*/
|
||||
public void handleResponse (int reqid, String status);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ChatService.java,v 1.3 2001/08/04 02:54:28 mdb Exp $
|
||||
// $Id: ChatService.java,v 1.4 2001/10/01 22:14:55 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.party.chat;
|
||||
|
||||
@@ -11,27 +11,12 @@ 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
|
||||
* object or directly to a particular client. These services should not be
|
||||
* used directly, but instead should be accessed via the chat manager.
|
||||
* used directly, but instead should be accessed via the chat director.
|
||||
*
|
||||
* @see ChatManager
|
||||
* @see ChatDirector
|
||||
*/
|
||||
public class ChatService
|
||||
public class ChatService implements ChatCodes
|
||||
{
|
||||
/** The module name for the chat services. */
|
||||
public static final String MODULE = "chat";
|
||||
|
||||
/** The message identifier for a speak request message. */
|
||||
public static final String SPEAK_REQUEST = "spkreq";
|
||||
|
||||
/** 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>.
|
||||
@@ -40,18 +25,18 @@ public class ChatService
|
||||
* @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
|
||||
* @param rsptarget the chat director 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)
|
||||
ChatDirector 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);
|
||||
return invmgr.invoke(MODULE_NAME, TELL_REQUEST, args, rsptarget);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// $Id: ChatCodes.java,v 1.1 2001/10/01 22:14:55 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.party.chat;
|
||||
|
||||
import com.threerings.cocktail.cher.client.InvocationCodes;
|
||||
|
||||
/**
|
||||
* Contains codes used by the chat invocation services.
|
||||
*/
|
||||
public interface ChatCodes extends InvocationCodes
|
||||
{
|
||||
/** The module name for the chat services. */
|
||||
public static final String MODULE_NAME = "chat";
|
||||
|
||||
/** The message identifier for a speak request message. */
|
||||
public static final String SPEAK_REQUEST = "spkreq";
|
||||
|
||||
/** 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 response identifier for a successful tell request. This is
|
||||
* mapped by the invocation services to a call to {@link
|
||||
* ChatDirector#handleTellSucceded}. */
|
||||
public static final String TELL_SUCCEEDED_RESPONSE = "TellSucceeded";
|
||||
|
||||
/** The response identifier for a failed tell request. This is mapped
|
||||
* by the invocation services to a call to {@link
|
||||
* ChatDirector#handleTellFailed}. */
|
||||
public static final String TELL_FAILED_RESPONSE = "TellFailed";
|
||||
|
||||
/** The message identifier for a tell notification. */
|
||||
public static final String TELL_NOTIFICATION = "Tell";
|
||||
|
||||
/** An error code delivered when the user targeted for a tell
|
||||
* notification is not online. */
|
||||
public static final String USER_NOT_ONLINE = "m.user_not_online";
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ChatProvider.java,v 1.3 2001/08/11 00:05:58 mdb Exp $
|
||||
// $Id: ChatProvider.java,v 1.4 2001/10/01 22:14:55 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.party.chat;
|
||||
|
||||
@@ -7,7 +7,12 @@ 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
|
||||
/**
|
||||
* The chat provider handles the server side of the chat-related
|
||||
* invocation services.
|
||||
*/
|
||||
public class ChatProvider
|
||||
extends InvocationProvider implements ChatCodes
|
||||
{
|
||||
/**
|
||||
* Processes a request from a client to deliver a tell message to
|
||||
@@ -19,15 +24,15 @@ public class ChatProvider extends InvocationProvider
|
||||
// look up the target body object
|
||||
BodyObject tobj = PartyServer.lookupBody(target);
|
||||
if (tobj == null) {
|
||||
sendResponse(source, invid, "TellFailed", "m.player_not_online");
|
||||
sendResponse(source, invid, TELL_FAILED_RESPONSE,
|
||||
USER_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);
|
||||
tobj.getOid(), MODULE_NAME, TELL_NOTIFICATION, args);
|
||||
|
||||
sendResponse(source, invid, "TellSucceeded");
|
||||
sendResponse(source, invid, TELL_SUCCEEDED_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user