HG Friends: pulled sim-bound notification code to HGStatusNotifier, so that we can better manage this traffic.

0.7.4.1
Diva Canto 2012-03-21 09:14:17 -07:00
parent 8ad426f329
commit d8bcb78b10
3 changed files with 58 additions and 20 deletions

View File

@ -212,7 +212,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
scene.EventManager.OnClientLogin += OnClientLogin; scene.EventManager.OnClientLogin += OnClientLogin;
} }
public void RegionLoaded(Scene scene) public virtual void RegionLoaded(Scene scene)
{ {
} }

View File

@ -62,6 +62,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
} }
protected HGFriendsServicesConnector m_HGFriendsConnector = new HGFriendsServicesConnector(); protected HGFriendsServicesConnector m_HGFriendsConnector = new HGFriendsServicesConnector();
protected HGStatusNotifier m_StatusNotifier;
#region ISharedRegionModule #region ISharedRegionModule
public override string Name public override string Name
@ -78,6 +79,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
scene.RegisterModuleInterface<IFriendsSimConnector>(this); scene.RegisterModuleInterface<IFriendsSimConnector>(this);
} }
public override void RegionLoaded(Scene scene)
{
if (!m_Enabled)
return;
if (m_StatusNotifier == null)
m_StatusNotifier = new HGStatusNotifier(this);
}
#endregion #endregion
#region IFriendsSimConnector #region IFriendsSimConnector
@ -230,25 +239,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
if (friendsPerDomain.ContainsKey("local")) if (friendsPerDomain.ContainsKey("local"))
base.StatusNotify(friendsPerDomain["local"], userID, online); base.StatusNotify(friendsPerDomain["local"], userID, online);
foreach (KeyValuePair<string, List<FriendInfo>> kvp in friendsPerDomain) m_StatusNotifier.Notify(userID, friendsPerDomain, online);
{
if (kvp.Key != "local")
{
// For the others, call the user agent service
List<string> ids = new List<string>();
foreach (FriendInfo f in kvp.Value)
ids.Add(f.Friend);
UserAgentServiceConnector uConn = new UserAgentServiceConnector(kvp.Key);
List<UUID> friendsOnline = uConn.StatusNotification(ids, userID, online);
if (online && friendsOnline.Count > 0)
{
IClientAPI client = LocateClientObject(userID);
if (client != null)
client.SendAgentOnline(friendsOnline.ToArray());
}
}
}
// m_log.DebugFormat("[HGFRIENDS MODULE]: Exiting StatusNotify for {0}", userID); // m_log.DebugFormat("[HGFRIENDS MODULE]: Exiting StatusNotify for {0}", userID);
} }

View File

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenSim.Framework;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Services.Interfaces;
using OpenSim.Services.Connectors.Hypergrid;
using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
using OpenMetaverse;
namespace OpenSim.Region.CoreModules.Avatar.Friends
{
public class HGStatusNotifier
{
private HGFriendsModule m_FriendsModule;
public HGStatusNotifier(HGFriendsModule friendsModule)
{
m_FriendsModule = friendsModule;
}
public void Notify(UUID userID, Dictionary<string, List<FriendInfo>> friendsPerDomain, bool online)
{
foreach (KeyValuePair<string, List<FriendInfo>> kvp in friendsPerDomain)
{
if (kvp.Key != "local")
{
// For the others, call the user agent service
List<string> ids = new List<string>();
foreach (FriendInfo f in kvp.Value)
ids.Add(f.Friend);
UserAgentServiceConnector uConn = new UserAgentServiceConnector(kvp.Key);
List<UUID> friendsOnline = uConn.StatusNotification(ids, userID, online);
if (online && friendsOnline.Count > 0)
{
IClientAPI client = m_FriendsModule.LocateClientObject(userID);
if (client != null)
client.SendAgentOnline(friendsOnline.ToArray());
}
}
}
}
}
}