Merge branch 'master' into careminster-presence-refactor

This brings careminster on the level of master. To be tested
This commit is contained in:
Melanie
2010-03-03 02:07:03 +00:00
501 changed files with 26121 additions and 46964 deletions

View File

@@ -24,6 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Reflection;
using log4net;
@@ -36,9 +37,10 @@ using OpenSim.Region.Framework.Scenes;
namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
{
public class InstantMessageModule : IRegionModule
public class InstantMessageModule : ISharedRegionModule
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static readonly ILog m_log = LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
/// <value>
/// Is this module enabled?
@@ -51,7 +53,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
private IMessageTransferModule m_TransferModule = null;
public void Initialise(Scene scene, IConfigSource config)
public void Initialise(IConfigSource config)
{
if (config.Configs["Messaging"] != null)
{
@@ -62,6 +64,12 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
}
m_enabled = true;
}
public void AddRegion(Scene scene)
{
if (!m_enabled)
return;
lock (m_scenes)
{
@@ -74,6 +82,39 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
}
}
public void RegionLoaded(Scene scene)
{
if (!m_enabled)
return;
if (m_TransferModule == null)
{
m_TransferModule =
scene.RequestModuleInterface<IMessageTransferModule>();
if (m_TransferModule == null)
{
m_log.Error("[INSTANT MESSAGE]: No message transfer module, IM will not work!");
scene.EventManager.OnClientConnect -= OnClientConnect;
scene.EventManager.OnIncomingInstantMessage -= OnGridInstantMessage;
m_scenes.Clear();
m_enabled = false;
}
}
}
public void RemoveRegion(Scene scene)
{
if (!m_enabled)
return;
lock (m_scenes)
{
m_scenes.Remove(scene);
}
}
void OnClientConnect(IClientCore client)
{
IClientIM clientIM;
@@ -85,15 +126,6 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
public void PostInitialise()
{
if (!m_enabled)
return;
m_TransferModule =
m_scenes[0].RequestModuleInterface<IMessageTransferModule>();
if (m_TransferModule == null)
m_log.Error("[INSTANT MESSAGE]: No message transfer module, "+
"IM will not work!");
}
public void Close()
@@ -105,9 +137,9 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
get { return "InstantMessageModule"; }
}
public bool IsSharedModule
public Type ReplaceableInterface
{
get { return true; }
get { return null; }
}
#endregion

View File

@@ -37,21 +37,33 @@ using OpenSim.Framework;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using GridRegion = OpenSim.Services.Interfaces.GridRegion;
using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo;
using OpenSim.Services.Interfaces;
namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
{
public class MessageTransferModule : IRegionModule, IMessageTransferModule
public class MessageTransferModule : ISharedRegionModule, IMessageTransferModule
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
// private bool m_Enabled = false;
protected bool m_Gridmode = false;
private bool m_Enabled = false;
protected List<Scene> m_Scenes = new List<Scene>();
protected Dictionary<UUID, ulong> m_UserRegionMap = new Dictionary<UUID, ulong>();
protected Dictionary<UUID, UUID> m_UserRegionMap = new Dictionary<UUID, UUID>();
public event UndeliveredMessage OnUndeliveredMessage;
public virtual void Initialise(Scene scene, IConfigSource config)
private IPresenceService m_PresenceService;
protected IPresenceService PresenceService
{
get
{
if (m_PresenceService == null)
m_PresenceService = m_Scenes[0].RequestModuleInterface<IPresenceService>();
return m_PresenceService;
}
}
public virtual void Initialise(IConfigSource config)
{
IConfig cnf = config.Configs["Messaging"];
if (cnf != null && cnf.GetString(
@@ -62,20 +74,16 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
return;
}
cnf = config.Configs["Startup"];
if (cnf != null)
m_Gridmode = cnf.GetBoolean("gridmode", false);
m_Enabled = true;
}
// m_Enabled = true;
public virtual void AddRegion(Scene scene)
{
if (!m_Enabled)
return;
lock (m_Scenes)
{
if (m_Scenes.Count == 0)
{
MainServer.Instance.AddXmlRPCHandler(
"grid_instant_message", processXMLRPCGridInstantMessage);
}
m_log.Debug("[MESSAGE TRANSFER]: Message transfer module active");
scene.RegisterModuleInterface<IMessageTransferModule>(this);
m_Scenes.Add(scene);
@@ -84,6 +92,26 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
public virtual void PostInitialise()
{
if (!m_Enabled)
return;
MainServer.Instance.AddXmlRPCHandler(
"grid_instant_message", processXMLRPCGridInstantMessage);
}
public virtual void RegionLoaded(Scene scene)
{
}
public virtual void RemoveRegion(Scene scene)
{
if (!m_Enabled)
return;
lock(m_Scenes)
{
m_Scenes.Remove(scene);
}
}
public virtual void Close()
@@ -95,9 +123,9 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
get { return "MessageTransferModule"; }
}
public virtual bool IsSharedModule
public virtual Type ReplaceableInterface
{
get { return true; }
get { return null; }
}
public virtual void SendInstantMessage(GridInstantMessage im, MessageResultNotification result)
@@ -148,15 +176,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
}
}
if (m_Gridmode)
{
//m_log.DebugFormat("[INSTANT MESSAGE]: Delivering via grid");
// Still here, try send via Grid
SendGridInstantMessageViaXMLRPC(im, result);
return;
}
HandleUndeliveredMessage(im, result);
SendGridInstantMessageViaXMLRPC(im, result);
return;
}
@@ -409,7 +429,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
/// <summary>
/// delegate for sending a grid instant message asynchronously
/// </summary>
public delegate void GridInstantMessageDelegate(GridInstantMessage im, MessageResultNotification result, ulong prevRegionHandle);
public delegate void GridInstantMessageDelegate(GridInstantMessage im, MessageResultNotification result, UUID prevRegionID);
protected virtual void GridInstantMessageCompleted(IAsyncResult iar)
{
@@ -423,7 +443,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
{
GridInstantMessageDelegate d = SendGridInstantMessageViaXMLRPCAsync;
d.BeginInvoke(im, result, 0, GridInstantMessageCompleted, d);
d.BeginInvoke(im, result, UUID.Zero, GridInstantMessageCompleted, d);
}
/// <summary>
@@ -438,11 +458,11 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
/// Pass in 0 the first time this method is called. It will be called recursively with the last
/// regionhandle tried
/// </param>
protected virtual void SendGridInstantMessageViaXMLRPCAsync(GridInstantMessage im, MessageResultNotification result, ulong prevRegionHandle)
protected virtual void SendGridInstantMessageViaXMLRPCAsync(GridInstantMessage im, MessageResultNotification result, UUID prevRegionID)
{
UUID toAgentID = new UUID(im.toAgentID);
UserAgentData upd = null;
PresenceInfo upd = null;
bool lookupAgent = false;
@@ -450,13 +470,13 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
{
if (m_UserRegionMap.ContainsKey(toAgentID))
{
upd = new UserAgentData();
upd.AgentOnline = true;
upd.Handle = m_UserRegionMap[toAgentID];
upd = new PresenceInfo();
upd.Online = true;
upd.RegionID = m_UserRegionMap[toAgentID];
// We need to compare the current regionhandle with the previous region handle
// or the recursive loop will never end because it will never try to lookup the agent again
if (prevRegionHandle == upd.Handle)
if (prevRegionID == upd.RegionID)
{
lookupAgent = true;
}
@@ -472,14 +492,23 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
if (lookupAgent)
{
// Non-cached user agent lookup.
upd = m_Scenes[0].CommsManager.UserService.GetAgentByUUID(toAgentID);
PresenceInfo[] presences = PresenceService.GetAgents(new string[] { toAgentID.ToString() });
if (presences != null)
{
foreach (PresenceInfo p in presences)
if (p.Online)
{
upd = presences[0];
break;
}
}
if (upd != null)
{
// check if we've tried this before..
// This is one way to end the recursive loop
//
if (upd.Handle == prevRegionHandle)
if (upd.RegionID == prevRegionID)
{
m_log.Error("[GRID INSTANT MESSAGE]: Unable to deliver an instant message");
HandleUndeliveredMessage(im, result);
@@ -496,12 +525,10 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
if (upd != null)
{
if (upd.AgentOnline)
if (upd.Online)
{
uint x = 0, y = 0;
Utils.LongToUInts(upd.Handle, out x, out y);
GridRegion reginfo = m_Scenes[0].GridService.GetRegionByPosition(m_Scenes[0].RegionInfo.ScopeID,
(int)x, (int)y);
GridRegion reginfo = m_Scenes[0].GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID,
upd.RegionID);
if (reginfo != null)
{
Hashtable msgdata = ConvertGridInstantMessageToXMLRPC(im);
@@ -517,11 +544,11 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
{
if (m_UserRegionMap.ContainsKey(toAgentID))
{
m_UserRegionMap[toAgentID] = upd.Handle;
m_UserRegionMap[toAgentID] = upd.RegionID;
}
else
{
m_UserRegionMap.Add(toAgentID, upd.Handle);
m_UserRegionMap.Add(toAgentID, upd.RegionID);
}
}
result(true);
@@ -536,12 +563,12 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
// This is recursive!!!!!
SendGridInstantMessageViaXMLRPCAsync(im, result,
upd.Handle);
upd.RegionID);
}
}
else
{
m_log.WarnFormat("[GRID INSTANT MESSAGE]: Unable to find region {0}", upd.Handle);
m_log.WarnFormat("[GRID INSTANT MESSAGE]: Unable to find region {0}", upd.RegionID);
HandleUndeliveredMessage(im, result);
}
}

View File

@@ -37,9 +37,9 @@ using OpenSim.Framework.Client;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
namespace OpenSim.Region.CoreModules.Avatar.MuteList
namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
{
public class MuteListModule : IRegionModule
public class MuteListModule : ISharedRegionModule
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@@ -47,11 +47,8 @@ namespace OpenSim.Region.CoreModules.Avatar.MuteList
private List<Scene> m_SceneList = new List<Scene>();
private string m_RestURL = String.Empty;
public void Initialise(Scene scene, IConfigSource config)
public void Initialise(IConfigSource config)
{
if (!enabled)
return;
IConfig cnf = config.Configs["Messaging"];
if (cnf == null)
{
@@ -59,41 +56,55 @@ namespace OpenSim.Region.CoreModules.Avatar.MuteList
return;
}
if (cnf != null && cnf.GetString(
"MuteListModule", "None") !=
if (cnf != null && cnf.GetString("MuteListModule", "None") !=
"MuteListModule")
{
enabled = false;
return;
}
m_RestURL = cnf.GetString("MuteListURL", "");
if (m_RestURL == "")
{
m_log.Error("[MUTE LIST] Module was enabled, but no URL is given, disabling");
enabled = false;
return;
}
}
public void AddRegion(Scene scene)
{
if (!enabled)
return;
lock (m_SceneList)
{
if (m_SceneList.Count == 0)
{
m_RestURL = cnf.GetString("MuteListURL", "");
if (m_RestURL == "")
{
m_log.Error("[MUTE LIST] Module was enabled, but no URL is given, disabling");
enabled = false;
return;
}
}
if (!m_SceneList.Contains(scene))
m_SceneList.Add(scene);
m_SceneList.Add(scene);
scene.EventManager.OnNewClient += OnNewClient;
}
}
public void RegionLoaded(Scene scene)
{
}
public void RemoveRegion(Scene scene)
{
if (!enabled)
return;
lock (m_SceneList)
{
m_SceneList.Remove(scene);
}
}
public void PostInitialise()
{
if (!enabled)
return;
if (m_SceneList.Count == 0)
return;
m_log.Debug("[MUTE LIST] Mute list enabled");
}
@@ -102,26 +113,15 @@ namespace OpenSim.Region.CoreModules.Avatar.MuteList
get { return "MuteListModule"; }
}
public bool IsSharedModule
public Type ReplaceableInterface
{
get { return true; }
get { return null; }
}
public void Close()
{
}
// private IClientAPI FindClient(UUID agentID)
// {
// foreach (Scene s in m_SceneList)
// {
// ScenePresence presence = s.GetScenePresence(agentID);
// if (presence != null && !presence.IsChildAgent)
// return presence.ControllingClient;
// }
// return null;
// }
private void OnNewClient(IClientAPI client)
{
client.OnMuteListRequest += OnMuteListRequest;

View File

@@ -40,83 +40,92 @@ using OpenSim.Region.Framework.Scenes;
namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
{
public class OfflineMessageModule : IRegionModule
public class OfflineMessageModule : ISharedRegionModule
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private bool enabled = true;
private List<Scene> m_SceneList = new List<Scene>();
private string m_RestURL = String.Empty;
IMessageTransferModule m_TransferModule = null;
private bool m_ForwardOfflineGroupMessages = true;
public void Initialise(Scene scene, IConfigSource config)
public void Initialise(IConfigSource config)
{
if (!enabled)
return;
IConfig cnf = config.Configs["Messaging"];
if (cnf == null)
{
enabled = false;
return;
}
if (cnf != null && cnf.GetString(
"OfflineMessageModule", "None") !=
if (cnf != null && cnf.GetString("OfflineMessageModule", "None") !=
"OfflineMessageModule")
{
enabled = false;
return;
}
if (cnf != null)
m_ForwardOfflineGroupMessages = cnf.GetBoolean("ForwardOfflineGroupMessages", m_ForwardOfflineGroupMessages);
m_RestURL = cnf.GetString("OfflineMessageURL", "");
if (m_RestURL == "")
{
m_log.Error("[OFFLINE MESSAGING] Module was enabled, but no URL is given, disabling");
enabled = false;
return;
}
m_ForwardOfflineGroupMessages = cnf.GetBoolean("ForwardOfflineGroupMessages", m_ForwardOfflineGroupMessages);
}
public void AddRegion(Scene scene)
{
if (!enabled)
return;
lock (m_SceneList)
{
if (m_SceneList.Count == 0)
{
m_RestURL = cnf.GetString("OfflineMessageURL", "");
if (m_RestURL == "")
{
m_log.Error("[OFFLINE MESSAGING] Module was enabled, but no URL is given, disabling");
enabled = false;
return;
}
}
if (!m_SceneList.Contains(scene))
m_SceneList.Add(scene);
m_SceneList.Add(scene);
scene.EventManager.OnNewClient += OnNewClient;
}
}
public void RegionLoaded(Scene scene)
{
if (!enabled)
return;
if (m_TransferModule == null)
{
m_TransferModule = scene.RequestModuleInterface<IMessageTransferModule>();
if (m_TransferModule == null)
{
scene.EventManager.OnNewClient -= OnNewClient;
enabled = false;
m_SceneList.Clear();
m_log.Error("[OFFLINE MESSAGING] No message transfer module is enabled. Diabling offline messages");
}
m_TransferModule.OnUndeliveredMessage += UndeliveredMessage;
}
}
public void RemoveRegion(Scene scene)
{
if (!enabled)
return;
lock (m_SceneList)
{
m_SceneList.Remove(scene);
}
}
public void PostInitialise()
{
if (!enabled)
return;
if (m_SceneList.Count == 0)
return;
IMessageTransferModule trans = m_SceneList[0].RequestModuleInterface<IMessageTransferModule>();
if (trans == null)
{
enabled = false;
lock (m_SceneList)
{
foreach (Scene s in m_SceneList)
s.EventManager.OnNewClient -= OnNewClient;
m_SceneList.Clear();
}
m_log.Error("[OFFLINE MESSAGING] No message transfer module is enabled. Diabling offline messages");
return;
}
trans.OnUndeliveredMessage += UndeliveredMessage;
m_log.Debug("[OFFLINE MESSAGING] Offline messages enabled");
}
@@ -125,9 +134,9 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
get { return "OfflineMessageModule"; }
}
public bool IsSharedModule
public Type ReplaceableInterface
{
get { return true; }
get { return null; }
}
public void Close()

View File

@@ -24,6 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
@@ -35,64 +36,58 @@ using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Services.Interfaces;
using GridRegion = OpenSim.Services.Interfaces.GridRegion;
using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo;
namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
{
public class PresenceModule : IRegionModule, IPresenceModule
public class PresenceModule : ISharedRegionModule, IPresenceModule
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private bool m_Enabled = false;
private bool m_Gridmode = false;
// some default scene for doing things that aren't connected to a specific scene. Avoids locking.
private Scene m_initialScene;
private List<Scene> m_Scenes = new List<Scene>();
// we currently are only interested in root-agents. If the root isn't here, we don't know the region the
// user is in, so we have to ask the messaging server anyway.
private Dictionary<UUID, Scene> m_RootAgents =
new Dictionary<UUID, Scene>();
private static readonly ILog m_log = LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
public event PresenceChange OnPresenceChange;
public event BulkPresenceData OnBulkPresenceData;
public void Initialise(Scene scene, IConfigSource config)
protected List<Scene> m_Scenes = new List<Scene>();
protected IPresenceService m_PresenceService = null;
protected IPresenceService PresenceService
{
lock (m_Scenes)
get
{
// This is a shared module; Initialise will be called for every region on this server.
// Only check config once for the first region.
if (m_Scenes.Count == 0)
if (m_PresenceService == null)
{
IConfig cnf = config.Configs["Messaging"];
if (cnf != null && cnf.GetString(
"PresenceModule", "PresenceModule") !=
"PresenceModule")
return;
cnf = config.Configs["Startup"];
if (cnf != null)
m_Gridmode = cnf.GetBoolean("gridmode", false);
m_Enabled = true;
m_initialScene = scene;
if (m_Scenes.Count > 0)
m_PresenceService = m_Scenes[0].RequestModuleInterface<IPresenceService>();
}
if (m_Gridmode)
NotifyMessageServerOfStartup(scene);
m_Scenes.Add(scene);
return m_PresenceService;
}
}
scene.RegisterModuleInterface<IPresenceModule>(this);
public void Initialise(IConfigSource config)
{
}
public void AddRegion(Scene scene)
{
m_Scenes.Add(scene);
scene.EventManager.OnNewClient += OnNewClient;
scene.EventManager.OnSetRootAgentScene += OnSetRootAgentScene;
scene.EventManager.OnMakeChildAgent += OnMakeChildAgent;
scene.RegisterModuleInterface<IPresenceModule>(this);
}
public void RegionLoaded(Scene scene)
{
}
public void RemoveRegion(Scene scene)
{
m_Scenes.Remove(scene);
}
public void PostInitialise()
@@ -101,26 +96,6 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
public void Close()
{
if (!m_Gridmode || !m_Enabled)
return;
if (OnPresenceChange != null)
{
lock (m_RootAgents)
{
// on shutdown, users are kicked, too
foreach (KeyValuePair<UUID, Scene> pair in m_RootAgents)
{
OnPresenceChange(new PresenceInfo(pair.Key, UUID.Zero));
}
}
}
lock (m_Scenes)
{
foreach (Scene scene in m_Scenes)
NotifyMessageServerOfShutdown(scene);
}
}
public string Name
@@ -128,315 +103,56 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
get { return "PresenceModule"; }
}
public bool IsSharedModule
public Type ReplaceableInterface
{
get { return true; }
get { return null; }
}
public void RequestBulkPresenceData(UUID[] users)
{
if (OnBulkPresenceData != null)
{
PresenceInfo[] result = new PresenceInfo[users.Length];
if (m_Gridmode)
{
// first check the local information
List<UUID> uuids = new List<UUID>(); // the uuids to check remotely
List<int> indices = new List<int>(); // just for performance.
lock (m_RootAgents)
{
for (int i = 0; i < uuids.Count; ++i)
{
Scene scene;
if (m_RootAgents.TryGetValue(users[i], out scene))
{
result[i] = new PresenceInfo(users[i], scene.RegionInfo.RegionID);
}
else
{
uuids.Add(users[i]);
indices.Add(i);
}
}
}
}
// now we have filtered out all the local root agents. The rest we have to request info about
Dictionary<UUID, FriendRegionInfo> infos = m_initialScene.GetFriendRegionInfos(uuids);
for (int i = 0; i < uuids.Count; ++i)
public void OnNewClient(IClientAPI client)
{
client.AddGenericPacketHandler("requestonlinenotification", OnRequestOnlineNotification);
}
public void OnRequestOnlineNotification(Object sender, string method, List<String> args)
{
if (!(sender is IClientAPI))
return;
IClientAPI client = (IClientAPI)sender;
m_log.DebugFormat("[PRESENCE MODULE]: OnlineNotification requested by {0}", client.Name);
PresenceInfo[] status = PresenceService.GetAgents(args.ToArray());
List<UUID> online = new List<UUID>();
List<UUID> offline = new List<UUID>();
foreach (PresenceInfo pi in status)
{
UUID uuid = new UUID(pi.UserID);
if (pi.Online)
{
if (!online.Contains(uuid))
{
FriendRegionInfo info;
if (infos.TryGetValue(uuids[i], out info) && info.isOnline)
{
UUID regionID = info.regionID;
if (regionID == UUID.Zero)
{
// TODO this is the old messaging-server protocol; only the regionHandle is available.
// Fetch region-info to get the id
uint x = 0, y = 0;
Utils.LongToUInts(info.regionHandle, out x, out y);
GridRegion regionInfo = m_initialScene.GridService.GetRegionByPosition(m_initialScene.RegionInfo.ScopeID,
(int)x, (int)y);
regionID = regionInfo.RegionID;
}
result[indices[i]] = new PresenceInfo(uuids[i], regionID);
}
else result[indices[i]] = new PresenceInfo(uuids[i], UUID.Zero);
online.Add(uuid);
if (offline.Contains(uuid))
offline.Remove(uuid);
}
}
else
{
// in standalone mode, we have all the info locally available.
lock (m_RootAgents)
{
for (int i = 0; i < users.Length; ++i)
{
Scene scene;
if (m_RootAgents.TryGetValue(users[i], out scene))
{
result[i] = new PresenceInfo(users[i], scene.RegionInfo.RegionID);
}
else
{
result[i] = new PresenceInfo(users[i], UUID.Zero);
}
}
}
}
// tell everyone
OnBulkPresenceData(result);
}
}
// new client doesn't mean necessarily that user logged in, it just means it entered one of the
// the regions on this server
public void OnNewClient(IClientAPI client)
{
client.OnConnectionClosed += OnConnectionClosed;
client.OnLogout += OnLogout;
// KLUDGE: See handler for details.
client.OnEconomyDataRequest += OnEconomyDataRequest;
}
// connection closed just means *one* client connection has been closed. It doesn't mean that the
// user has logged off; it might have just TPed away.
public void OnConnectionClosed(IClientAPI client)
{
// TODO: Have to think what we have to do here...
// Should we just remove the root from the list (if scene matches)?
if (!(client.Scene is Scene))
return;
Scene scene = (Scene)client.Scene;
lock (m_RootAgents)
{
Scene rootScene;
if (!(m_RootAgents.TryGetValue(client.AgentId, out rootScene)) || scene != rootScene)
return;
m_RootAgents.Remove(client.AgentId);
}
// Should it have logged off, we'll do the logout part in OnLogout, even if no root is stored
// anymore. It logged off, after all...
}
// Triggered when the user logs off.
public void OnLogout(IClientAPI client)
{
if (!(client.Scene is Scene))
return;
Scene scene = (Scene)client.Scene;
// On logout, we really remove the client from rootAgents, even if the scene doesn't match
lock (m_RootAgents)
{
if (m_RootAgents.ContainsKey(client.AgentId)) m_RootAgents.Remove(client.AgentId);
}
// now inform the messaging server and anyone who is interested
NotifyMessageServerOfAgentLeaving(client.AgentId, scene.RegionInfo.RegionID, scene.RegionInfo.RegionHandle);
if (OnPresenceChange != null) OnPresenceChange(new PresenceInfo(client.AgentId, UUID.Zero));
}
public void OnSetRootAgentScene(UUID agentID, Scene scene)
{
// OnSetRootAgentScene can be called from several threads at once (with different agentID).
// Concurrent access to m_RootAgents is prone to failure on multi-core/-processor systems without
// correct locking).
lock (m_RootAgents)
{
Scene rootScene;
if (m_RootAgents.TryGetValue(agentID, out rootScene) && scene == rootScene)
{
return;
}
m_RootAgents[agentID] = scene;
}
// inform messaging server that agent changed the region
Util.FireAndForget(
delegate(object o)
{
NotifyMessageServerOfAgentLocation(agentID, scene.RegionInfo.RegionID, scene.RegionInfo.RegionHandle);
}
);
}
private void OnEconomyDataRequest(UUID agentID)
{
// KLUDGE: This is the only way I found to get a message (only) after login was completed and the
// client is connected enough to receive UDP packets.
// This packet seems to be sent only once, just after connection was established to the first
// region after login.
// We use it here to trigger a presence update; the old update-on-login was never be heard by
// the freshly logged in viewer, as it wasn't connected to the region at that time.
// TODO: Feel free to replace this by a better solution if you find one.
// get the agent. This should work every time, as we just got a packet from it
ScenePresence agent = null;
lock (m_Scenes)
{
foreach (Scene scene in m_Scenes)
{
agent = scene.GetScenePresence(agentID);
if (agent != null) break;
if (!online.Contains(uuid) && !offline.Contains(uuid))
offline.Add(uuid);
}
}
// just to be paranoid...
if (agent == null)
{
m_log.ErrorFormat("[PRESENCE]: Got a packet from agent {0} who can't be found anymore!?", agentID);
return;
}
// we are a bit premature here, but the next packet will switch this child agent to root.
if (OnPresenceChange != null) OnPresenceChange(new PresenceInfo(agentID, agent.Scene.RegionInfo.RegionID));
}
public void OnMakeChildAgent(ScenePresence agent)
{
// OnMakeChildAgent can be called from several threads at once (with different agent).
// Concurrent access to m_RootAgents is prone to failure on multi-core/-processor systems without
// correct locking).
lock (m_RootAgents)
{
Scene rootScene;
if (m_RootAgents.TryGetValue(agent.UUID, out rootScene) && agent.Scene == rootScene)
{
m_RootAgents.Remove(agent.UUID);
}
}
// don't notify the messaging-server; either this agent just had been downgraded and another one will be upgraded
// to root momentarily (which will notify the messaging-server), or possibly it will be closed in a moment,
// which will update the messaging-server, too.
}
private void NotifyMessageServerOfStartup(Scene scene)
{
Hashtable xmlrpcdata = new Hashtable();
xmlrpcdata["RegionUUID"] = scene.RegionInfo.RegionID.ToString();
ArrayList SendParams = new ArrayList();
SendParams.Add(xmlrpcdata);
try
{
XmlRpcRequest UpRequest = new XmlRpcRequest("region_startup", SendParams);
XmlRpcResponse resp = UpRequest.Send(scene.CommsManager.NetworkServersInfo.MessagingURL, 5000);
Hashtable responseData = (Hashtable)resp.Value;
if (responseData == null || (!responseData.ContainsKey("success")) || (string)responseData["success"] != "TRUE")
{
m_log.ErrorFormat("[PRESENCE]: Failed to notify message server of region startup for region {0}", scene.RegionInfo.RegionName);
}
}
catch (WebException)
{
m_log.ErrorFormat("[PRESENCE]: Failed to notify message server of region startup for region {0}", scene.RegionInfo.RegionName);
}
}
private void NotifyMessageServerOfShutdown(Scene scene)
{
if (m_Scenes[0].CommsManager.NetworkServersInfo.MessagingURL == string.Empty)
return;
Hashtable xmlrpcdata = new Hashtable();
xmlrpcdata["RegionUUID"] = scene.RegionInfo.RegionID.ToString();
ArrayList SendParams = new ArrayList();
SendParams.Add(xmlrpcdata);
try
{
XmlRpcRequest DownRequest = new XmlRpcRequest("region_shutdown", SendParams);
XmlRpcResponse resp = DownRequest.Send(scene.CommsManager.NetworkServersInfo.MessagingURL, 5000);
Hashtable responseData = (Hashtable)resp.Value;
if ((!responseData.ContainsKey("success")) || (string)responseData["success"] != "TRUE")
{
m_log.ErrorFormat("[PRESENCE]: Failed to notify message server of region shutdown for region {0}", scene.RegionInfo.RegionName);
}
}
catch (WebException)
{
m_log.ErrorFormat("[PRESENCE]: Failed to notify message server of region shutdown for region {0}", scene.RegionInfo.RegionName);
}
}
private void NotifyMessageServerOfAgentLocation(UUID agentID, UUID region, ulong regionHandle)
{
if (m_Scenes[0].CommsManager.NetworkServersInfo.MessagingURL == string.Empty)
return;
Hashtable xmlrpcdata = new Hashtable();
xmlrpcdata["AgentID"] = agentID.ToString();
xmlrpcdata["RegionUUID"] = region.ToString();
xmlrpcdata["RegionHandle"] = regionHandle.ToString();
ArrayList SendParams = new ArrayList();
SendParams.Add(xmlrpcdata);
try
{
XmlRpcRequest LocationRequest = new XmlRpcRequest("agent_location", SendParams);
XmlRpcResponse resp = LocationRequest.Send(m_Scenes[0].CommsManager.NetworkServersInfo.MessagingURL, 5000);
Hashtable responseData = (Hashtable)resp.Value;
if ((!responseData.ContainsKey("success")) || (string)responseData["success"] != "TRUE")
{
m_log.ErrorFormat("[PRESENCE]: Failed to notify message server of agent location for {0}", agentID.ToString());
}
}
catch (WebException)
{
m_log.ErrorFormat("[PRESENCE]: Failed to notify message server of agent location for {0}", agentID.ToString());
}
}
private void NotifyMessageServerOfAgentLeaving(UUID agentID, UUID region, ulong regionHandle)
{
if (m_Scenes[0].CommsManager.NetworkServersInfo.MessagingURL == string.Empty)
return;
Hashtable xmlrpcdata = new Hashtable();
xmlrpcdata["AgentID"] = agentID.ToString();
xmlrpcdata["RegionUUID"] = region.ToString();
xmlrpcdata["RegionHandle"] = regionHandle.ToString();
ArrayList SendParams = new ArrayList();
SendParams.Add(xmlrpcdata);
try
{
XmlRpcRequest LeavingRequest = new XmlRpcRequest("agent_leaving", SendParams);
XmlRpcResponse resp = LeavingRequest.Send(m_Scenes[0].CommsManager.NetworkServersInfo.MessagingURL, 5000);
Hashtable responseData = (Hashtable)resp.Value;
if ((!responseData.ContainsKey("success")) || (string)responseData["success"] != "TRUE")
{
m_log.ErrorFormat("[PRESENCE]: Failed to notify message server of agent leaving for {0}", agentID.ToString());
}
}
catch (WebException)
{
m_log.ErrorFormat("[PRESENCE]: Failed to notify message server of agent leaving for {0}", agentID.ToString());
}
if (online.Count > 0)
client.SendAgentOnline(online.ToArray());
if (offline.Count > 0)
client.SendAgentOffline(offline.ToArray());
}
}
}