Crowd peer services now forward broadcasts as well as tells. We must get the
word to the people, all the people. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4816 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -64,8 +64,8 @@ public class ChatProvider
|
||||
public void sentTell (BodyObject teller, BodyObject tellee, String message);
|
||||
}
|
||||
|
||||
/** Used to forward tells between servers in a multi-server setup. */
|
||||
public static interface TellForwarder
|
||||
/** Used to forward certain types of chat messages between servers in a multi-server setup. */
|
||||
public static interface ChatForwarder
|
||||
{
|
||||
/**
|
||||
* Requests that the supplied tell message be delivered to the appropriate destination.
|
||||
@@ -73,6 +73,11 @@ public class ChatProvider
|
||||
* @return true if the tell was delivered, false otherwise.
|
||||
*/
|
||||
public boolean forwardTell (UserMessage message, Name target, TellListener listener);
|
||||
|
||||
/**
|
||||
* Requests that the supplied broadcast message be delivered on other servers.
|
||||
*/
|
||||
public void forwardBroadcast (Name from, String bundle, String msg, boolean attention);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,12 +104,12 @@ public class ChatProvider
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the tell forwarded for the chat provider. This is used by the Crowd peer services
|
||||
* to forward tells between servers in a multi-server cluster.
|
||||
* Configures the chat forwarder. This is used by the Crowd peer services to forward messages
|
||||
* between servers in a multi-server cluster.
|
||||
*/
|
||||
public void setTellForwarder (TellForwarder forwarder)
|
||||
public void setChatForwarder (ChatForwarder forwarder)
|
||||
{
|
||||
_tellForwarder = forwarder;
|
||||
_chatForwarder = forwarder;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,7 +156,7 @@ public class ChatProvider
|
||||
if (errmsg != null) {
|
||||
throw new InvocationException(errmsg);
|
||||
}
|
||||
broadcast(body.getVisibleName(), null, message, false);
|
||||
broadcast(body.getVisibleName(), null, message, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,16 +171,17 @@ public class ChatProvider
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast the specified message to all places in the game.
|
||||
* Broadcasts the specified message to all place objects in the system.
|
||||
*
|
||||
* @param from the user the broadcast is from, or null to send the message as a system message.
|
||||
* @param bundle the bundle, or null if the message needs no translation.
|
||||
* @param msg the content of the message to broadcast.
|
||||
* @param attention if true, the message is sent as ATTENTION level, otherwise as INFO. Ignored
|
||||
* if from is non-null.
|
||||
* @param forward if true, forward this broadcast on to any registered chat forwarder, if
|
||||
* false, deliver it only locally on this server.
|
||||
*/
|
||||
public void broadcast (Name from, String bundle, String msg,
|
||||
boolean attention)
|
||||
public void broadcast (Name from, String bundle, String msg, boolean attention, boolean forward)
|
||||
{
|
||||
if (_broadcastObject != null) {
|
||||
broadcastTo(_broadcastObject, from, bundle, msg, attention);
|
||||
@@ -189,6 +195,10 @@ public class ChatProvider
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (forward && _chatForwarder != null) {
|
||||
_chatForwarder.forwardBroadcast(from, bundle, msg, attention);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,8 +212,7 @@ public class ChatProvider
|
||||
BodyObject tobj = CrowdServer.lookupBody(target);
|
||||
if (tobj == null) {
|
||||
// if we have a forwarder configured, try forwarding the tell
|
||||
if (_tellForwarder != null &&
|
||||
_tellForwarder.forwardTell(message, target, listener)) {
|
||||
if (_chatForwarder != null && _chatForwarder.forwardTell(message, target, listener)) {
|
||||
return;
|
||||
}
|
||||
throw new InvocationException(USER_NOT_ONLINE);
|
||||
@@ -273,8 +282,8 @@ public class ChatProvider
|
||||
/** Generates auto-responses to tells. May be null. */
|
||||
protected TellAutoResponder _autoRespond;
|
||||
|
||||
/** Forwards tells between servers. May be null. */
|
||||
protected TellForwarder _tellForwarder;
|
||||
/** Forwards chat between servers. May be null. */
|
||||
protected ChatForwarder _chatForwarder;
|
||||
|
||||
/** An alternative object to which broadcasts should be sent. */
|
||||
protected DObject _broadcastObject;
|
||||
|
||||
@@ -35,9 +35,15 @@ import com.threerings.crowd.chat.data.UserMessage;
|
||||
public interface CrowdPeerService extends InvocationService
|
||||
{
|
||||
/**
|
||||
* Used to forward a tell request to the server on which the destination
|
||||
* user actually occupies.
|
||||
* Used to forward a tell request to the server on which the destination user actually
|
||||
* occupies.
|
||||
*/
|
||||
public void deliverTell (Client client, UserMessage message, Name target,
|
||||
ChatService.TellListener listener);
|
||||
|
||||
/**
|
||||
* Dispatches a broadcast message on this peer.
|
||||
*/
|
||||
public void deliverBroadcast (
|
||||
Client client, Name from, String bundle, String msg, boolean attention);
|
||||
}
|
||||
|
||||
@@ -40,8 +40,19 @@ import com.threerings.util.Name;
|
||||
public class CrowdPeerMarshaller extends InvocationMarshaller
|
||||
implements CrowdPeerService
|
||||
{
|
||||
/** The method id used to dispatch {@link #deliverBroadcast} requests. */
|
||||
public static final int DELIVER_BROADCAST = 1;
|
||||
|
||||
// from interface CrowdPeerService
|
||||
public void deliverBroadcast (Client arg1, Name arg2, String arg3, String arg4, boolean arg5)
|
||||
{
|
||||
sendRequest(arg1, DELIVER_BROADCAST, new Object[] {
|
||||
arg2, arg3, arg4, Boolean.valueOf(arg5)
|
||||
});
|
||||
}
|
||||
|
||||
/** The method id used to dispatch {@link #deliverTell} requests. */
|
||||
public static final int DELIVER_TELL = 1;
|
||||
public static final int DELIVER_TELL = 2;
|
||||
|
||||
// from interface CrowdPeerService
|
||||
public void deliverTell (Client arg1, UserMessage arg2, Name arg3, ChatService.TellListener arg4)
|
||||
|
||||
@@ -59,6 +59,13 @@ public class CrowdPeerDispatcher extends InvocationDispatcher
|
||||
throws InvocationException
|
||||
{
|
||||
switch (methodId) {
|
||||
case CrowdPeerMarshaller.DELIVER_BROADCAST:
|
||||
((CrowdPeerProvider)provider).deliverBroadcast(
|
||||
source,
|
||||
(Name)args[0], (String)args[1], (String)args[2], ((Boolean)args[3]).booleanValue()
|
||||
);
|
||||
return;
|
||||
|
||||
case CrowdPeerMarshaller.DELIVER_TELL:
|
||||
((CrowdPeerProvider)provider).deliverTell(
|
||||
source,
|
||||
|
||||
@@ -47,9 +47,9 @@ import com.threerings.crowd.peer.data.CrowdPeerMarshaller;
|
||||
* Extends the standard peer manager and bridges certain Crowd services.
|
||||
*/
|
||||
public class CrowdPeerManager extends PeerManager
|
||||
implements CrowdPeerProvider, ChatProvider.TellForwarder
|
||||
implements CrowdPeerProvider, ChatProvider.ChatForwarder
|
||||
{
|
||||
// documentation inherited from interface CrowdPeerProvider
|
||||
// from interface CrowdPeerProvider
|
||||
public void deliverTell (ClientObject caller, UserMessage message,
|
||||
Name target, ChatService.TellListener listener)
|
||||
throws InvocationException
|
||||
@@ -58,12 +58,19 @@ public class CrowdPeerManager extends PeerManager
|
||||
CrowdServer.chatprov.deliverTell(message, target, listener);
|
||||
}
|
||||
|
||||
// documentation inherited from interface ChatProvider.TellForwarder
|
||||
// from interface CrowdPeerProvider
|
||||
public void deliverBroadcast (ClientObject caller, Name from, String bundle, String msg,
|
||||
boolean attention)
|
||||
{
|
||||
// deliver the broadcast locally on this server
|
||||
CrowdServer.chatprov.broadcast(from, bundle, msg, attention, false);
|
||||
}
|
||||
|
||||
// from interface ChatProvider.ChatForwarder
|
||||
public boolean forwardTell (UserMessage message, Name target,
|
||||
ChatService.TellListener listener)
|
||||
{
|
||||
// look through our peer objects to see if the target user is online on
|
||||
// one of the other servers
|
||||
// look through our peers to see if the target user is online on one of them
|
||||
for (PeerNode peer : _peers.values()) {
|
||||
CrowdNodeObject cnobj = (CrowdNodeObject)peer.nodeobj;
|
||||
if (cnobj == null) {
|
||||
@@ -71,14 +78,24 @@ public class CrowdPeerManager extends PeerManager
|
||||
}
|
||||
CrowdClientInfo cinfo = (CrowdClientInfo)cnobj.clients.get(target);
|
||||
if (cinfo != null) {
|
||||
cnobj.crowdPeerService.deliverTell(
|
||||
peer.getClient(), message, target, listener);
|
||||
cnobj.crowdPeerService.deliverTell(peer.getClient(), message, target, listener);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// from interface ChatProvider.ChatForwarder
|
||||
public void forwardBroadcast (Name from, String bundle, String msg, boolean attention)
|
||||
{
|
||||
for (PeerNode peer : _peers.values()) {
|
||||
if (peer.nodeobj != null) {
|
||||
((CrowdNodeObject)peer.nodeobj).crowdPeerService.deliverBroadcast(
|
||||
peer.getClient(), from, bundle, msg, attention);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override // documentation inherited
|
||||
public void shutdown ()
|
||||
{
|
||||
@@ -89,8 +106,8 @@ public class CrowdPeerManager extends PeerManager
|
||||
CrowdServer.invmgr.clearDispatcher(((CrowdNodeObject)_nodeobj).crowdPeerService);
|
||||
}
|
||||
|
||||
// clear our tell forwarder registration
|
||||
CrowdServer.chatprov.setTellForwarder(null);
|
||||
// clear our chat forwarder registration
|
||||
CrowdServer.chatprov.setChatForwarder(null);
|
||||
}
|
||||
|
||||
@Override // documentation inherited
|
||||
@@ -124,7 +141,7 @@ public class CrowdPeerManager extends PeerManager
|
||||
(CrowdPeerMarshaller)CrowdServer.invmgr.registerDispatcher(
|
||||
new CrowdPeerDispatcher(this)));
|
||||
|
||||
// register ourselves as a tell forwarder
|
||||
CrowdServer.chatprov.setTellForwarder(this);
|
||||
// register ourselves as a chat forwarder
|
||||
CrowdServer.chatprov.setChatForwarder(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,11 @@ import com.threerings.util.Name;
|
||||
*/
|
||||
public interface CrowdPeerProvider extends InvocationProvider
|
||||
{
|
||||
/**
|
||||
* Handles a {@link CrowdPeerService#deliverBroadcast} request.
|
||||
*/
|
||||
public void deliverBroadcast (ClientObject caller, Name arg1, String arg2, String arg3, boolean arg4);
|
||||
|
||||
/**
|
||||
* Handles a {@link CrowdPeerService#deliverTell} request.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user