* This update enables grid wide presence updates.

* You'll need to start-up the MessageingServer and set it up.   It sets up like any of the other grid servers.
* All user presence data is kept in memory for speed, while the agent is online.   That means if you shutdown the messaging server or the messaging server crashes, it forgets who's online/offline.
* Occasionally the region-cache will get stale if regions move around a lot. if it gets stale, run clear-cache on the messaging server console to clear the region cache.
0.6.0-stable
Teravus Ovares 2008-06-02 16:16:07 +00:00
parent 89fa5fd67e
commit 3991908db5
9 changed files with 374 additions and 44 deletions

View File

@ -38,6 +38,7 @@ namespace OpenSim.Framework
public static bool DefaultHttpSSL = false; public static bool DefaultHttpSSL = false;
private ConfigurationMember configMember; private ConfigurationMember configMember;
public string DatabaseProvider = String.Empty; public string DatabaseProvider = String.Empty;
public string DatabaseConnect = String.Empty;
public string DefaultStartupMsg = String.Empty; public string DefaultStartupMsg = String.Empty;
public string GridCommsProvider = String.Empty; public string GridCommsProvider = String.Empty;
public string GridRecvKey = String.Empty; public string GridRecvKey = String.Empty;
@ -76,6 +77,11 @@ namespace OpenSim.Framework
configMember.addConfigurationOption("grid_recv_key", ConfigurationOption.ConfigurationTypes.TYPE_STRING, configMember.addConfigurationOption("grid_recv_key", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
"Key to expect from user server", "null", false); "Key to expect from user server", "null", false);
configMember.addConfigurationOption("database_connect", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
"Connection String for Database", "", false);
configMember.addConfigurationOption("database_provider", ConfigurationOption.ConfigurationTypes.TYPE_STRING, configMember.addConfigurationOption("database_provider", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
"DLL for database provider", "OpenSim.Data.MySQL.dll", false); "DLL for database provider", "OpenSim.Data.MySQL.dll", false);
@ -115,6 +121,9 @@ namespace OpenSim.Framework
case "database_provider": case "database_provider":
DatabaseProvider = (string) configuration_result; DatabaseProvider = (string) configuration_result;
break; break;
case "database_connect":
DatabaseConnect = (string)configuration_result;
break;
case "http_port": case "http_port":
HttpPort = (uint) configuration_result; HttpPort = (uint) configuration_result;
break; break;

View File

@ -49,6 +49,10 @@ namespace OpenSim.Framework
public bool HttpSSL = DefaultHttpSSL; public bool HttpSSL = DefaultHttpSSL;
public string InventoryUrl = String.Empty; public string InventoryUrl = String.Empty;
public UserConfig()
{
// weird, but UserManagerBase needs this.
}
public UserConfig(string description, string filename) public UserConfig(string description, string filename)
{ {
configMember = configMember =

View File

@ -31,7 +31,9 @@ using System.Reflection;
using libsecondlife; using libsecondlife;
using log4net; using log4net;
using log4net.Config; using log4net.Config;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Framework.Communications.Cache;
using OpenSim.Framework.Console; using OpenSim.Framework.Console;
using OpenSim.Framework.Servers; using OpenSim.Framework.Servers;
@ -88,6 +90,8 @@ namespace OpenSim.Grid.MessagingServer
m_log.Info("[REGION]: Starting HTTP process"); m_log.Info("[REGION]: Starting HTTP process");
m_httpServer = new BaseHttpServer(Cfg.HttpPort); m_httpServer = new BaseHttpServer(Cfg.HttpPort);
msgsvc = new MessageService(Cfg); msgsvc = new MessageService(Cfg);
if (msgsvc.registerWithUserServer()) if (msgsvc.registerWithUserServer())
@ -144,6 +148,24 @@ namespace OpenSim.Grid.MessagingServer
} }
} }
public override void RunCmd(string cmd, string[] cmdparams)
{
base.RunCmd(cmd, cmdparams);
switch (cmd)
{
case "help":
m_console.Notice("clear-cache - Clears region cache. Should be done when regions change position. The region cache gets stale after a while.");
break;
case "clear-cache":
int entries = msgsvc.ClearRegionCache();
m_console.Notice("Region cache cleared! Cleared " + entries.ToString() + " entries");
break;
}
}
public override void Shutdown() public override void Shutdown()
{ {
msgsvc.deregisterWithUserServer(); msgsvc.deregisterWithUserServer();

View File

@ -46,6 +46,7 @@ namespace OpenSim.Grid.MessagingServer
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private MessageServerConfig m_cfg; private MessageServerConfig m_cfg;
private UserManager m_userManager;
//A hashtable of all current presences this server knows about //A hashtable of all current presences this server knows about
private Hashtable m_presences = new Hashtable(); private Hashtable m_presences = new Hashtable();
@ -62,11 +63,16 @@ namespace OpenSim.Grid.MessagingServer
public MessageService(MessageServerConfig cfg) public MessageService(MessageServerConfig cfg)
{ {
m_cfg = cfg; m_cfg = cfg;
m_userManager = new UserManager();
UserConfig uc = new UserConfig();
uc.DatabaseConnect = cfg.DatabaseConnect;
uc.DatabaseProvider = cfg.DatabaseProvider;
m_userManager._config = uc;
m_userManager.AddPlugin(cfg.DatabaseProvider, cfg.DatabaseConnect);
} }
#region RegionComms Methods
#endregion
#region FriendList Methods #region FriendList Methods
@ -123,11 +129,27 @@ namespace OpenSim.Grid.MessagingServer
{ {
// we need to send out online status update, but the user is already subscribed // we need to send out online status update, but the user is already subscribed
} }
PresenceInformer friendlistupdater = new PresenceInformer(); UserAgentData p2Handle = m_userManager.GetUserAgentData(userpresence.agentData.AgentID);
friendlistupdater.presence1 = friendpresence; if (p2Handle != null)
friendlistupdater.presence2 = userpresence; {
WaitCallback cb = new WaitCallback(friendlistupdater.go);
ThreadPool.QueueUserWorkItem(cb); userpresence.regionData.regionHandle = p2Handle.Handle;
PresenceInformer friendlistupdater = new PresenceInformer();
friendlistupdater.presence1 = friendpresence;
//friendlistupdater.gridserverurl = m_cfg.GridServerURL;
//friendlistupdater.gridserversendkey = m_cfg.GridSendKey;
//friendlistupdater.gridserverrecvkey = m_cfg.GridRecvKey;
friendlistupdater.presence2 = userpresence;
friendlistupdater.OnGetRegionData += GetRegionInfo;
friendlistupdater.OnDone += PresenceUpdateDone;
WaitCallback cb = new WaitCallback(friendlistupdater.go);
ThreadPool.QueueUserWorkItem(cb);
}
else
{
// Skip because we can't find any data on the user
}
//SendRegionPresenceUpdate(friendpresence, userpresence); //SendRegionPresenceUpdate(friendpresence, userpresence);
} }
@ -143,12 +165,30 @@ namespace OpenSim.Grid.MessagingServer
{ {
// we need to send out online status update, but the user is already subscribed // we need to send out online status update, but the user is already subscribed
} }
PresenceInformer friendlistupdater = new PresenceInformer();
friendlistupdater.presence1 = userpresence; UserAgentData p2Handle = m_userManager.GetUserAgentData(friendpresence.agentData.AgentID);
friendlistupdater.presence2 = friendpresence;
WaitCallback cb2 = new WaitCallback(friendlistupdater.go); if (p2Handle != null)
ThreadPool.QueueUserWorkItem(cb2); {
friendpresence.regionData.regionHandle = p2Handle.Handle;
PresenceInformer friendlistupdater = new PresenceInformer();
friendlistupdater.presence1 = userpresence;
friendlistupdater.presence2 = friendpresence;
//friendlistupdater.gridserverurl = m_cfg.GridServerURL;
//friendlistupdater.gridserversendkey = m_cfg.GridSendKey;
//friendlistupdater.gridserverrecvkey = m_cfg.GridRecvKey;
friendlistupdater.OnGetRegionData += GetRegionInfo;
friendlistupdater.OnDone += PresenceUpdateDone;
WaitCallback cb2 = new WaitCallback(friendlistupdater.go);
ThreadPool.QueueUserWorkItem(cb2);
}
else
{
// skip, agent doesn't appear to exist anymore
}
//SendRegionPresenceUpdate(userpresence, friendpresence); //SendRegionPresenceUpdate(userpresence, friendpresence);
} }
@ -209,6 +249,7 @@ namespace OpenSim.Grid.MessagingServer
/// <param name="AgentID"></param> /// <param name="AgentID"></param>
private void ProcessLogOff(LLUUID AgentID) private void ProcessLogOff(LLUUID AgentID)
{ {
m_log.Info("[LOGOFF]: Processing Logoff");
UserPresenceData AgentData = null; UserPresenceData AgentData = null;
List<LLUUID> AgentsNeedingNotification = new List<LLUUID>(); List<LLUUID> AgentsNeedingNotification = new List<LLUUID>();
UserPresenceData friendd = null; UserPresenceData friendd = null;
@ -223,6 +264,7 @@ namespace OpenSim.Grid.MessagingServer
if (AgentData != null) if (AgentData != null)
{ {
AgentsNeedingNotification = AgentData.subscriptionData; AgentsNeedingNotification = AgentData.subscriptionData;
AgentData.OnlineYN = false;
//lock (m_presence_BackReferences) //lock (m_presence_BackReferences)
//{ //{
//if (m_presence_BackReferences.Contains(AgentID)) //if (m_presence_BackReferences.Contains(AgentID))
@ -262,13 +304,33 @@ namespace OpenSim.Grid.MessagingServer
m_presences[AgentsNeedingNotification[i]] = friendd; m_presences[AgentsNeedingNotification[i]] = friendd;
} }
PresenceInformer friendlistupdater = new PresenceInformer(); UserAgentData p2Handle = m_userManager.GetUserAgentData(friendd.agentData.AgentID);
friendlistupdater.presence1 = AgentData; if (p2Handle != null)
friendlistupdater.presence2 = friendd; {
friendd.regionData.regionHandle = p2Handle.Handle;
PresenceInformer friendlistupdater = new PresenceInformer();
friendlistupdater.presence1 = AgentData;
friendlistupdater.presence2 = friendd;
WaitCallback cb3 = new WaitCallback(friendlistupdater.go); //friendlistupdater.gridserverurl = m_cfg.GridServerURL;
ThreadPool.QueueUserWorkItem(cb3); //friendlistupdater.gridserversendkey = m_cfg.GridSendKey;
//friendlistupdater.gridserverrecvkey = m_cfg.GridRecvKey;
friendlistupdater.OnGetRegionData += GetRegionInfo;
friendlistupdater.OnDone += PresenceUpdateDone;
WaitCallback cb3 = new WaitCallback(friendlistupdater.go);
ThreadPool.QueueUserWorkItem(cb3);
}
else
{
// skip, agent can't be found
}
//SendRegionPresenceUpdate(AgentData, friendd); //SendRegionPresenceUpdate(AgentData, friendd);
//removeBackReference(AgentID, AgentsNeedingNotification[i]); //removeBackReference(AgentID, AgentsNeedingNotification[i]);
@ -279,6 +341,12 @@ namespace OpenSim.Grid.MessagingServer
#endregion #endregion
public void PresenceUpdateDone(PresenceInformer obj)
{
obj.OnGetRegionData -= GetRegionInfo;
obj.OnDone -= PresenceUpdateDone;
}
#region UserServer Comms #region UserServer Comms
/// <summary> /// <summary>
@ -393,7 +461,7 @@ namespace OpenSim.Grid.MessagingServer
up.friendData = flData; up.friendData = flData;
RegionProfileData riData = GetRegionInfo(regionHandle); RegionProfileData riData = GetRegionInfo(regionHandle);
up.regionData = riData; up.regionData = riData;
up.OnlineYN = true;
ProcessFriendListSubscriptions(up); ProcessFriendListSubscriptions(up);
return new XmlRpcResponse(); return new XmlRpcResponse();
@ -407,6 +475,7 @@ namespace OpenSim.Grid.MessagingServer
/// <returns></returns> /// <returns></returns>
public XmlRpcResponse UserLoggedOff(XmlRpcRequest request) public XmlRpcResponse UserLoggedOff(XmlRpcRequest request)
{ {
m_log.Info("[USERLOGOFF]: User logged off called");
Hashtable requestData = (Hashtable)request.Params[0]; Hashtable requestData = (Hashtable)request.Params[0];
LLUUID AgentID = new LLUUID((string)requestData["agentid"]); LLUUID AgentID = new LLUUID((string)requestData["agentid"]);
@ -423,23 +492,64 @@ namespace OpenSim.Grid.MessagingServer
/// <summary> /// <summary>
/// Gets and caches a RegionInfo object from the gridserver based on regionhandle /// Gets and caches a RegionInfo object from the gridserver based on regionhandle
/// if the regionhandle is already cached, use the cached values /// if the regionhandle is already cached, use the cached values
/// Gets called by lots of threads!!!!!
/// </summary> /// </summary>
/// <param name="regionhandle">handle to the XY of the region we're looking for</param> /// <param name="regionhandle">handle to the XY of the region we're looking for</param>
/// <returns>A RegionInfo object to stick in the presence info</returns> /// <returns>A RegionInfo object to stick in the presence info</returns>
public RegionProfileData GetRegionInfo(ulong regionhandle) public RegionProfileData GetRegionInfo(ulong regionhandle)
{ {
RegionProfileData regionInfo = null; RegionProfileData regionInfo = null;
if (m_regionInfoCache.Contains(regionhandle)) bool lookup = false;
lock (m_regionInfoCache)
{ {
regionInfo = (RegionProfileData)m_regionInfoCache[regionhandle]; if (m_regionInfoCache.Contains(regionhandle))
{
regionInfo = (RegionProfileData)m_regionInfoCache[regionhandle];
}
else
{
// Don't lock the cache while we're looking up the region!
lookup = true;
}
} }
else
if (lookup)
{ {
regionInfo = RequestRegionInfo(regionhandle); regionInfo = RequestRegionInfo(regionhandle);
if (regionInfo != null)
{
lock (m_regionInfoCache)
{
if (m_regionInfoCache.Contains(regionhandle))
{
m_regionInfoCache[regionhandle] = regionInfo;
}
else
{
m_regionInfoCache.Add(regionhandle, regionInfo);
}
}
}
} }
return regionInfo; return regionInfo;
} }
public int ClearRegionCache()
{
int cachecount = 0;
lock (m_regionInfoCache)
{
cachecount = m_regionInfoCache.Count;
m_regionInfoCache.Clear();
}
return cachecount;
}
/// <summary> /// <summary>
/// Get RegionProfileData from the GridServer /// Get RegionProfileData from the GridServer
/// We'll Cache this information and use it for presence updates /// We'll Cache this information and use it for presence updates
@ -541,6 +651,7 @@ namespace OpenSim.Grid.MessagingServer
// Process Response // Process Response
if (GridRespData.ContainsKey("responsestring")) if (GridRespData.ContainsKey("responsestring"))
{ {
return true; return true;
} }
else else

View File

@ -27,16 +27,31 @@
using System.Collections; using System.Collections;
using System.Reflection; using System.Reflection;
using System.Net;
using log4net; using log4net;
using Nwc.XmlRpc; using Nwc.XmlRpc;
using OpenSim.Data; using OpenSim.Data;
namespace OpenSim.Grid.MessagingServer namespace OpenSim.Grid.MessagingServer
{ {
public delegate RegionProfileData GetRegionData(ulong region_handle);
public delegate void Done(PresenceInformer obj);
public class PresenceInformer public class PresenceInformer
{ {
public event GetRegionData OnGetRegionData;
public event Done OnDone;
private GetRegionData handlerGetRegionData = null;
private Done handlerDone = null;
public UserPresenceData presence1 = null; public UserPresenceData presence1 = null;
public UserPresenceData presence2 = null; public UserPresenceData presence2 = null;
public string gridserverurl, gridserversendkey, gridserverrecvkey;
public bool lookupRegion = true;
//public methodGroup
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public PresenceInformer() public PresenceInformer()
@ -60,18 +75,68 @@ namespace OpenSim.Grid.MessagingServer
public void SendRegionPresenceUpdate(UserPresenceData TalkingAbout, UserPresenceData UserToUpdate) public void SendRegionPresenceUpdate(UserPresenceData TalkingAbout, UserPresenceData UserToUpdate)
{ {
// TODO: Fill in pertenant Presence Data from 'TalkingAbout' // TODO: Fill in pertenant Presence Data from 'TalkingAbout'
RegionProfileData whichRegion = new RegionProfileData();
if (lookupRegion)
{
handlerGetRegionData = OnGetRegionData;
if (handlerGetRegionData != null)
{
whichRegion = handlerGetRegionData(UserToUpdate.regionData.regionHandle);
}
//RegionProfileData rp = RegionProfileData.RequestSimProfileData(UserToUpdate.regionData.regionHandle, gridserverurl, gridserversendkey, gridserverrecvkey);
RegionProfileData whichRegion = UserToUpdate.regionData; //whichRegion = rp;
}
else
{
whichRegion = UserToUpdate.regionData;
}
//whichRegion.httpServerURI //whichRegion.httpServerURI
Hashtable PresenceParams = new Hashtable(); if (whichRegion != null)
ArrayList SendParams = new ArrayList(); {
SendParams.Add(PresenceParams);
Hashtable PresenceParams = new Hashtable();
PresenceParams.Add("agent_id",TalkingAbout.agentData.AgentID.ToString());
PresenceParams.Add("notify_id",UserToUpdate.agentData.AgentID.ToString());
if (TalkingAbout.OnlineYN)
PresenceParams.Add("status","TRUE");
else
PresenceParams.Add("status","FALSE");
ArrayList SendParams = new ArrayList();
SendParams.Add(PresenceParams);
m_log.Info("[PRESENCE]: Informing " + whichRegion.regionName + " at " + whichRegion.httpServerURI);
// Send
XmlRpcRequest RegionReq = new XmlRpcRequest("presence_update", SendParams);
try
{
XmlRpcResponse RegionResp = RegionReq.Send(whichRegion.httpServerURI, 6000);
}
catch (WebException)
{
m_log.WarnFormat("[INFORM]: failed notifying region {0} containing user {1} about {2}", whichRegion.regionName, UserToUpdate.agentData.firstname + " " + UserToUpdate.agentData.lastname, TalkingAbout.agentData.firstname + " " + TalkingAbout.agentData.lastname);
}
}
else
{
m_log.Info("[PRESENCEUPDATER]: Region data was null skipping");
}
handlerDone = OnDone;
if (handlerDone != null)
{
handlerDone(this);
}
m_log.Info("[PRESENCE]: Informing " + whichRegion.regionName + " at " + whichRegion.httpServerURI);
// Send
XmlRpcRequest RegionReq = new XmlRpcRequest("presence_update", SendParams);
XmlRpcResponse RegionResp = RegionReq.Send(whichRegion.httpServerURI, 6000);
} }
} }
} }

View File

@ -40,6 +40,7 @@ namespace OpenSim.Grid.MessagingServer
public string httpURI = String.Empty; public string httpURI = String.Empty;
public List<FriendListItem> friendData = new List<FriendListItem> (); public List<FriendListItem> friendData = new List<FriendListItem> ();
public List<LLUUID> subscriptionData = new List<LLUUID>(); public List<LLUUID> subscriptionData = new List<LLUUID>();
public bool OnlineYN = false;
public UserPresenceData() public UserPresenceData()
{ {

View File

@ -185,12 +185,12 @@ namespace OpenSim.Grid.UserServer
{ {
if (MessageServers.Count > 0) if (MessageServers.Count > 0)
{ {
m_log.Info("[MSGCONNECTOR]: Sending login notice to registered message servers"); m_log.Info("[MSGCONNECTOR]: Sending logoff notice to registered message servers");
} }
else else
// { {
// m_log.Debug("[MSGCONNECTOR]: No Message Servers registered, ignoring"); // m_log.Debug("[MSGCONNECTOR]: No Message Servers registered, ignoring");
// } }
foreach (MessageServerInfo serv in MessageServers.Values) foreach (MessageServerInfo serv in MessageServers.Values)
{ {
NotifyMessageServerAboutUserLogoff(serv,agentID); NotifyMessageServerAboutUserLogoff(serv,agentID);

View File

@ -382,7 +382,13 @@ namespace OpenSim.Region.Communications.OGS1
regionInfo.RegionID = new LLUUID((string) responseData["region_UUID"]); regionInfo.RegionID = new LLUUID((string) responseData["region_UUID"]);
regionInfo.RegionName = (string) responseData["region_name"]; regionInfo.RegionName = (string) responseData["region_name"];
m_remoteRegionInfoCache.Add(regionHandle, regionInfo); lock (m_remoteRegionInfoCache)
{
if (!m_remoteRegionInfoCache.ContainsKey(regionHandle))
{
m_remoteRegionInfoCache.Add(regionHandle, regionInfo);
}
}
} }
catch (WebException) catch (WebException)
{ {

View File

@ -25,6 +25,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using libsecondlife; using libsecondlife;
@ -45,6 +46,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
private Dictionary<LLUUID, List<FriendListItem>> FriendLists = new Dictionary<LLUUID, List<FriendListItem>>(); private Dictionary<LLUUID, List<FriendListItem>> FriendLists = new Dictionary<LLUUID, List<FriendListItem>>();
private Dictionary<LLUUID, LLUUID> m_pendingFriendRequests = new Dictionary<LLUUID, LLUUID>(); private Dictionary<LLUUID, LLUUID> m_pendingFriendRequests = new Dictionary<LLUUID, LLUUID>();
private Dictionary<LLUUID, ulong> m_rootAgents = new Dictionary<LLUUID, ulong>(); private Dictionary<LLUUID, ulong> m_rootAgents = new Dictionary<LLUUID, ulong>();
private Dictionary<LLUUID, List<StoredFriendListUpdate>> StoredFriendListUpdates = new Dictionary<LLUUID, List<StoredFriendListUpdate>>();
private List<Scene> m_scene = new List<Scene>(); private List<Scene> m_scene = new List<Scene>();
#region IRegionModule Members #region IRegionModule Members
@ -91,6 +94,73 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
public XmlRpcResponse processPresenceUpdate(XmlRpcRequest req) public XmlRpcResponse processPresenceUpdate(XmlRpcRequest req)
{ {
m_log.Info("[FRIENDS]: Got Notification about a user! OMG"); m_log.Info("[FRIENDS]: Got Notification about a user! OMG");
Hashtable requestData = (Hashtable)req.Params[0];
if (requestData.ContainsKey("agent_id") && requestData.ContainsKey("notify_id") && requestData.ContainsKey("status"))
{
LLUUID notifyAgentId = LLUUID.Zero;
LLUUID notifyAboutAgentId = LLUUID.Zero;
bool notifyOnlineStatus = false;
if ((string)requestData["status"] == "TRUE")
notifyOnlineStatus = true;
Helpers.TryParse((string)requestData["notify_id"], out notifyAgentId);
Helpers.TryParse((string)requestData["agent_id"], out notifyAboutAgentId);
ScenePresence avatar = GetPresenceFromAgentID(notifyAgentId);
if (avatar != null)
{
if (avatar.IsChildAgent)
{
StoredFriendListUpdate sob = new StoredFriendListUpdate();
sob.OnlineYN = notifyOnlineStatus;
sob.storedAbout = notifyAboutAgentId;
sob.storedFor = notifyAgentId;
lock (StoredFriendListUpdates)
{
if (StoredFriendListUpdates.ContainsKey(notifyAgentId))
{
StoredFriendListUpdates[notifyAgentId].Add(sob);
}
else
{
List<StoredFriendListUpdate> newitem = new List<StoredFriendListUpdate>();
newitem.Add(sob);
StoredFriendListUpdates.Add(notifyAgentId, newitem);
}
}
}
else
{
if (notifyOnlineStatus)
doFriendListUpdateOnline(notifyAboutAgentId);
else
ClientLoggedOut(notifyAboutAgentId);
}
}
else
{
StoredFriendListUpdate sob = new StoredFriendListUpdate();
sob.OnlineYN = notifyOnlineStatus;
sob.storedAbout = notifyAboutAgentId;
sob.storedFor = notifyAgentId;
lock (StoredFriendListUpdates)
{
if (StoredFriendListUpdates.ContainsKey(notifyAgentId))
{
StoredFriendListUpdates[notifyAgentId].Add(sob);
}
else
{
List<StoredFriendListUpdate> newitem = new List<StoredFriendListUpdate>();
newitem.Add(sob);
StoredFriendListUpdates.Add(notifyAgentId, newitem);
}
}
}
}
return new XmlRpcResponse(); return new XmlRpcResponse();
} }
@ -110,24 +180,30 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
client.OnDenyFriendRequest += OnDenyFriendRequest; client.OnDenyFriendRequest += OnDenyFriendRequest;
client.OnTerminateFriendship += OnTerminateFriendship; client.OnTerminateFriendship += OnTerminateFriendship;
doFriendListUpdateOnline(client.AgentId);
}
private void doFriendListUpdateOnline(LLUUID AgentId)
{
List<FriendListItem> fl = new List<FriendListItem>(); List<FriendListItem> fl = new List<FriendListItem>();
//bool addFLback = false; //bool addFLback = false;
lock (FriendLists) lock (FriendLists)
{ {
if (FriendLists.ContainsKey(client.AgentId)) if (FriendLists.ContainsKey(AgentId))
{ {
fl = FriendLists[client.AgentId]; fl = FriendLists[AgentId];
} }
else else
{ {
fl = m_scene[0].GetFriendList(client.AgentId); fl = m_scene[0].GetFriendList(AgentId);
//lock (FriendLists) //lock (FriendLists)
//{ //{
if (!FriendLists.ContainsKey(client.AgentId)) if (!FriendLists.ContainsKey(AgentId))
FriendLists.Add(client.AgentId, fl); FriendLists.Add(AgentId, fl);
//} //}
} }
} }
@ -161,11 +237,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
{ {
foreach (FriendListItem fli in usrfl) foreach (FriendListItem fli in usrfl)
{ {
if (fli.Friend == client.AgentId) if (fli.Friend == AgentId)
{ {
fli.onlinestatus = true; fli.onlinestatus = true;
LLUUID[] Agents = new LLUUID[1]; LLUUID[] Agents = new LLUUID[1];
Agents[0] = client.AgentId; Agents[0] = AgentId;
av.ControllingClient.SendAgentOnline(Agents); av.ControllingClient.SendAgentOnline(Agents);
} }
@ -176,8 +252,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
if (UpdateUsers.Count > 0) if (UpdateUsers.Count > 0)
{ {
ScenePresence avatar = GetPresenceFromAgentID(AgentId);
client.SendAgentOnline(UpdateUsers.ToArray()); if (avatar != null)
{
avatar.ControllingClient.SendAgentOnline(UpdateUsers.ToArray());
}
} }
} }
@ -302,6 +381,27 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
{ {
m_rootAgents.Add(avatar.UUID, avatar.RegionHandle); m_rootAgents.Add(avatar.UUID, avatar.RegionHandle);
m_log.Info("[FRIEND]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + "."); m_log.Info("[FRIEND]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + ".");
List<StoredFriendListUpdate> updateme = new List<StoredFriendListUpdate>();
lock (StoredFriendListUpdates)
{
if (StoredFriendListUpdates.ContainsKey(avatar.UUID))
{
updateme = StoredFriendListUpdates[avatar.UUID];
StoredFriendListUpdates.Remove(avatar.UUID);
}
}
if (updateme.Count > 0)
{
foreach (StoredFriendListUpdate u in updateme)
{
if (u.OnlineYN)
doFriendListUpdateOnline(u.storedAbout);
else
ClientLoggedOut(u.storedAbout);
}
}
} }
} }
//m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString()); //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString());
@ -441,8 +541,13 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
SceneAgentIn.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); SceneAgentIn.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule);
SceneAgentIn.StoreAddFriendship(m_pendingFriendRequests[transactionID], agentID, (uint) 1); SceneAgentIn.StoreAddFriendship(m_pendingFriendRequests[transactionID], agentID, (uint) 1);
m_pendingFriendRequests.Remove(transactionID);
//LLUUID[] Agents = new LLUUID[1];
//Agents[0] = msg.toAgentID;
//av.ControllingClient.SendAgentOnline(Agents);
m_pendingFriendRequests.Remove(transactionID);
// TODO: Inform agent that the friend is online // TODO: Inform agent that the friend is online
} }
} }
@ -498,4 +603,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
#endregion #endregion
} }
public struct StoredFriendListUpdate
{
public LLUUID storedFor;
public LLUUID storedAbout;
public bool OnlineYN;
}
} }