Files
narya/src/java/com/threerings/crowd/peer/server/CrowdPeerManager.java
T
Michael Bayne c69630b7e0 PresentsClient -> PresentsSession (Jamie's suggestion) and associated changes
on down the client.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5508 542714f4-19e9-0310-aa3c-eee0fc999fb1
2008-11-06 18:04:42 +00:00

156 lines
5.4 KiB
Java

//
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2007 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.crowd.peer.server;
import com.google.inject.Inject;
import com.threerings.util.Name;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.peer.data.ClientInfo;
import com.threerings.presents.peer.data.NodeObject;
import com.threerings.presents.peer.server.PeerManager;
import com.threerings.presents.peer.server.PeerNode;
import com.threerings.presents.server.InvocationException;
import com.threerings.presents.server.InvocationManager;
import com.threerings.presents.server.PresentsSession;
import com.threerings.presents.server.ShutdownManager;
import com.threerings.crowd.chat.client.ChatService;
import com.threerings.crowd.chat.data.UserMessage;
import com.threerings.crowd.chat.server.ChatProvider;
import com.threerings.crowd.data.BodyObject;
import com.threerings.crowd.peer.data.CrowdClientInfo;
import com.threerings.crowd.peer.data.CrowdNodeObject;
/**
* Extends the standard peer manager and bridges certain Crowd services.
*/
public class CrowdPeerManager extends PeerManager
implements CrowdPeerProvider, ChatProvider.ChatForwarder
{
/**
* Creates an uninitialized peer manager.
*/
@Inject public CrowdPeerManager (ShutdownManager shutmgr)
{
super(shutmgr);
}
// from interface CrowdPeerProvider
public void deliverTell (ClientObject caller, UserMessage message,
Name target, ChatService.TellListener listener)
throws InvocationException
{
// we just forward the message as if it originated on this server
_chatprov.deliverTell(message, target, listener);
}
// from interface CrowdPeerProvider
public void deliverBroadcast (ClientObject caller, Name from, String bundle, String msg,
boolean attention)
{
// deliver the broadcast locally on this server
_chatprov.broadcast(from, bundle, msg, attention, false);
}
// from interface ChatProvider.ChatForwarder
public boolean forwardTell (UserMessage message, Name target,
ChatService.TellListener listener)
{
// 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) {
continue;
}
CrowdClientInfo cinfo = (CrowdClientInfo)cnobj.clients.get(target);
if (cinfo != null) {
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 ()
{
super.shutdown();
// unregister our invocation service
if (_nodeobj != null) {
_invmgr.clearDispatcher(((CrowdNodeObject)_nodeobj).crowdPeerService);
}
// clear our chat forwarder registration
_chatprov.setChatForwarder(null);
}
@Override // documentation inherited
protected NodeObject createNodeObject ()
{
return new CrowdNodeObject();
}
@Override // documentation inherited
protected ClientInfo createClientInfo ()
{
return new CrowdClientInfo();
}
@Override // documentation inherited
protected void initClientInfo (PresentsSession client, ClientInfo info)
{
super.initClientInfo(client, info);
((CrowdClientInfo)info).visibleName =
((BodyObject)client.getClientObject()).getVisibleName();
}
@Override // documentation inherited
protected void didInit ()
{
super.didInit();
// register and initialize our invocation service
CrowdNodeObject cnobj = (CrowdNodeObject)_nodeobj;
cnobj.setCrowdPeerService(_invmgr.registerDispatcher(new CrowdPeerDispatcher(this)));
// register ourselves as a chat forwarder
_chatprov.setChatForwarder(this);
}
@Inject protected InvocationManager _invmgr;
@Inject protected ChatProvider _chatprov;
}