Presence remote connector and handler. Presence HG Broker. Nothing tested, just compiles.
parent
b8dfccb227
commit
3ef513e863
|
@ -0,0 +1,256 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSimulator Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (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 OpenSim.Region.Framework.Interfaces;
|
||||
using OpenSim.Region.Framework.Scenes;
|
||||
using OpenSim.Server.Base;
|
||||
using OpenSim.Services.Interfaces;
|
||||
using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo;
|
||||
|
||||
using OpenMetaverse;
|
||||
using log4net;
|
||||
using Nini.Config;
|
||||
|
||||
namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence
|
||||
{
|
||||
public class HGPresenceBroker : ISharedRegionModule, IPresenceService
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
#region ISharedRegionModule
|
||||
|
||||
private bool m_Enabled = false;
|
||||
|
||||
private PresenceDetector m_PresenceDetector;
|
||||
private IPresenceService m_GridService;
|
||||
private IPresenceService m_HGService;
|
||||
|
||||
public Type ReplaceableInterface
|
||||
{
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "HGPresenceBroker"; }
|
||||
}
|
||||
|
||||
public void Initialise(IConfigSource source)
|
||||
{
|
||||
IConfig moduleConfig = source.Configs["Modules"];
|
||||
if (moduleConfig != null)
|
||||
{
|
||||
string name = moduleConfig.GetString("PresenceServices", "");
|
||||
if (name == Name)
|
||||
{
|
||||
//m_RemoteConnector = new InventoryServicesConnector(source);
|
||||
|
||||
m_Enabled = true;
|
||||
|
||||
m_PresenceDetector = new PresenceDetector(this);
|
||||
|
||||
|
||||
IConfig pConfig = source.Configs["PresenceService"];
|
||||
if (pConfig == null)
|
||||
{
|
||||
m_log.Error("[HG PRESENCE CONNECTOR]: PresenceService missing from OpenSim.ini");
|
||||
return;
|
||||
}
|
||||
|
||||
string localDll = pConfig.GetString("LocalGridPresenceService",
|
||||
String.Empty);
|
||||
string HGDll = pConfig.GetString("HypergridPresenceService",
|
||||
String.Empty);
|
||||
|
||||
if (localDll == String.Empty)
|
||||
{
|
||||
m_log.Error("[HG PRESENCE CONNECTOR]: No LocalGridPresenceService named in section PresenceService");
|
||||
//return;
|
||||
throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's");
|
||||
}
|
||||
|
||||
if (HGDll == String.Empty)
|
||||
{
|
||||
m_log.Error("[HG PRESENCE CONNECTOR]: No HypergridPresenceService named in section PresenceService");
|
||||
//return;
|
||||
throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's");
|
||||
}
|
||||
|
||||
Object[] args = new Object[] { source };
|
||||
m_GridService = ServerUtils.LoadPlugin<IPresenceService>(localDll, args);
|
||||
|
||||
m_HGService = ServerUtils.LoadPlugin<IPresenceService>(HGDll, args);
|
||||
// no. This will be:
|
||||
// m_HGService = new HGPresenceServiceConnector();
|
||||
|
||||
if (m_GridService == null)
|
||||
{
|
||||
m_log.Error("[HG PRESENCE CONNECTOR]: Can't load local presence service");
|
||||
return;
|
||||
}
|
||||
if (m_HGService == null)
|
||||
{
|
||||
m_log.Error("[HG PRESENCE CONNECTOR]: Can't load hypergrid presence service");
|
||||
return;
|
||||
}
|
||||
|
||||
m_log.Info("[HG PRESENCE CONNECTOR]: Hypergrid presence enabled");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public void AddRegion(Scene scene)
|
||||
{
|
||||
if (!m_Enabled)
|
||||
return;
|
||||
|
||||
scene.RegisterModuleInterface<IPresenceService>(this);
|
||||
m_PresenceDetector.AddRegion(scene);
|
||||
|
||||
m_log.InfoFormat("[HG PRESENCE CONNECTOR]: Enabled hypergrid presence for region {0}", scene.RegionInfo.RegionName);
|
||||
|
||||
}
|
||||
|
||||
public void RemoveRegion(Scene scene)
|
||||
{
|
||||
if (!m_Enabled)
|
||||
return;
|
||||
|
||||
m_PresenceDetector.RemoveRegion(scene);
|
||||
}
|
||||
|
||||
public void RegionLoaded(Scene scene)
|
||||
{
|
||||
if (!m_Enabled)
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IPresenceService
|
||||
|
||||
public bool LoginAgent(UUID principalID, UUID sessionID, UUID secureSessionID)
|
||||
{
|
||||
m_log.Warn("[HG PRESENCE CONNECTOR]: LoginAgent connector not implemented at the simulators");
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool LogoutAgent(UUID sessionID)
|
||||
{
|
||||
return m_GridService.LogoutAgent(sessionID);
|
||||
}
|
||||
|
||||
|
||||
public bool LogoutRegionAgents(UUID regionID)
|
||||
{
|
||||
return m_GridService.LogoutRegionAgents(regionID);
|
||||
}
|
||||
|
||||
public bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt)
|
||||
{
|
||||
return m_GridService.ReportAgent(sessionID, regionID, position, lookAt);
|
||||
}
|
||||
|
||||
public PresenceInfo GetAgent(UUID sessionID)
|
||||
{
|
||||
return m_GridService.GetAgent(sessionID);
|
||||
}
|
||||
|
||||
public PresenceInfo[] GetAgents(string[] principalIDs)
|
||||
{
|
||||
Dictionary<string, List<string>> triage = new Dictionary<string, List<string>>();
|
||||
List<PresenceInfo> presences = new List<PresenceInfo>();
|
||||
|
||||
foreach (string s in principalIDs)
|
||||
{
|
||||
string url = string.Empty;
|
||||
string uuid = UUID.Zero.ToString();
|
||||
StringToUrlAndUUID(s, out url, out uuid);
|
||||
if (triage.ContainsKey(url))
|
||||
triage[url].Add(uuid);
|
||||
else
|
||||
{
|
||||
List<string> list = new List<string>();
|
||||
list.Add(uuid);
|
||||
triage.Add(url, list);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (KeyValuePair<string, List<string>> kvp in triage)
|
||||
{
|
||||
if (kvp.Key == "local")
|
||||
{
|
||||
PresenceInfo[] pinfos = m_GridService.GetAgents(kvp.Value.ToArray());
|
||||
presences.AddRange(pinfos);
|
||||
}
|
||||
else
|
||||
{
|
||||
PresenceInfo[] pinfos = m_HGService.GetAgents(/*kvp.Key,*/ kvp.Value.ToArray());
|
||||
presences.AddRange(pinfos);
|
||||
}
|
||||
}
|
||||
|
||||
return presences.ToArray();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void StringToUrlAndUUID(string id, out string url, out string uuid)
|
||||
{
|
||||
url = String.Empty;
|
||||
uuid = String.Empty;
|
||||
|
||||
Uri uri;
|
||||
|
||||
if (Uri.TryCreate(id, UriKind.Absolute, out uri) &&
|
||||
uri.Scheme == Uri.UriSchemeHttp)
|
||||
{
|
||||
url = "http://" + uri.Authority;
|
||||
uuid = uri.LocalPath.Trim(new char[] { '/' });
|
||||
}
|
||||
else
|
||||
{
|
||||
url = "local";
|
||||
uuid = id;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -47,7 +47,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence
|
|||
#region ISharedRegionModule
|
||||
|
||||
private bool m_Enabled = false;
|
||||
private bool m_Initialized = false;
|
||||
|
||||
private PresenceDetector m_PresenceDetector;
|
||||
private IPresenceService m_PresenceService;
|
||||
|
|
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSimulator Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (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 OpenSim.Region.Framework.Interfaces;
|
||||
using OpenSim.Region.Framework.Scenes;
|
||||
using OpenSim.Server.Base;
|
||||
using OpenSim.Services.Interfaces;
|
||||
using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo;
|
||||
|
||||
using OpenMetaverse;
|
||||
using log4net;
|
||||
using Nini.Config;
|
||||
|
||||
namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence
|
||||
{
|
||||
public class RemotePresenceServiceConnector : ISharedRegionModule, IPresenceService
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
#region ISharedRegionModule
|
||||
|
||||
private bool m_Enabled = false;
|
||||
|
||||
private PresenceDetector m_PresenceDetector;
|
||||
private IPresenceService m_RemoteConnector;
|
||||
|
||||
public Type ReplaceableInterface
|
||||
{
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "RemotePresenceServiceConnector"; }
|
||||
}
|
||||
|
||||
public void Initialise(IConfigSource source)
|
||||
{
|
||||
IConfig moduleConfig = source.Configs["Modules"];
|
||||
if (moduleConfig != null)
|
||||
{
|
||||
string name = moduleConfig.GetString("PresenceServices", "");
|
||||
if (name == Name)
|
||||
{
|
||||
//m_RemoteConnector = new PresenceServicesConnector(source);
|
||||
|
||||
m_Enabled = true;
|
||||
|
||||
m_PresenceDetector = new PresenceDetector(this);
|
||||
|
||||
m_log.Info("[INVENTORY CONNECTOR]: Remote presence enabled");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public void AddRegion(Scene scene)
|
||||
{
|
||||
if (!m_Enabled)
|
||||
return;
|
||||
|
||||
scene.RegisterModuleInterface<IPresenceService>(this);
|
||||
m_PresenceDetector.AddRegion(scene);
|
||||
|
||||
m_log.InfoFormat("[REMOTE PRESENCE CONNECTOR]: Enabled remote presence for region {0}", scene.RegionInfo.RegionName);
|
||||
|
||||
}
|
||||
|
||||
public void RemoveRegion(Scene scene)
|
||||
{
|
||||
if (!m_Enabled)
|
||||
return;
|
||||
|
||||
m_PresenceDetector.RemoveRegion(scene);
|
||||
}
|
||||
|
||||
public void RegionLoaded(Scene scene)
|
||||
{
|
||||
if (!m_Enabled)
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IPresenceService
|
||||
|
||||
public bool LoginAgent(UUID principalID, UUID sessionID, UUID secureSessionID)
|
||||
{
|
||||
m_log.Warn("[REMOTE PRESENCE CONNECTOR]: LoginAgent connector not implemented at the simulators");
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool LogoutAgent(UUID sessionID)
|
||||
{
|
||||
return m_RemoteConnector.LogoutAgent(sessionID);
|
||||
}
|
||||
|
||||
|
||||
public bool LogoutRegionAgents(UUID regionID)
|
||||
{
|
||||
return m_RemoteConnector.LogoutRegionAgents(regionID);
|
||||
}
|
||||
|
||||
public bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt)
|
||||
{
|
||||
return m_RemoteConnector.ReportAgent(sessionID, regionID, position, lookAt);
|
||||
}
|
||||
|
||||
public PresenceInfo GetAgent(UUID sessionID)
|
||||
{
|
||||
return m_RemoteConnector.GetAgent(sessionID);
|
||||
}
|
||||
|
||||
public PresenceInfo[] GetAgents(string[] principalIDs)
|
||||
{
|
||||
return m_RemoteConnector.GetAgents(principalIDs);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
|
@ -78,8 +78,18 @@ namespace OpenSim.Server.Handlers.Presence
|
|||
|
||||
switch (method)
|
||||
{
|
||||
case "login":
|
||||
return LoginAgent(request);
|
||||
case "logout":
|
||||
return LogoutAgent(request);
|
||||
case "logoutregion":
|
||||
return LogoutRegionAgents(request);
|
||||
case "report":
|
||||
return Report(request);
|
||||
case "getagent":
|
||||
return GetAgent(request);
|
||||
case "getagents":
|
||||
return GetAgents(request);
|
||||
}
|
||||
m_log.DebugFormat("[PRESENCE HANDLER]: unknown method request: {0}", method);
|
||||
}
|
||||
|
@ -92,28 +102,154 @@ namespace OpenSim.Server.Handlers.Presence
|
|||
|
||||
}
|
||||
|
||||
byte[] Report(Dictionary<string, object> request)
|
||||
byte[] LoginAgent(Dictionary<string, object> request)
|
||||
{
|
||||
PresenceInfo info = new PresenceInfo();
|
||||
UUID principal = UUID.Zero;
|
||||
UUID session = UUID.Zero;
|
||||
UUID ssession = UUID.Zero;
|
||||
|
||||
if (!request.ContainsKey("PrincipalID") || !request.ContainsKey("RegionID"))
|
||||
if (!request.ContainsKey("PrincipalID") || !request.ContainsKey("SessionID"))
|
||||
return FailureResult();
|
||||
|
||||
if (!UUID.TryParse(request["PrincipalID"].ToString(),
|
||||
out info.PrincipalID))
|
||||
if (!UUID.TryParse(request["PrincipalID"].ToString(), out principal))
|
||||
return FailureResult();
|
||||
|
||||
if (!UUID.TryParse(request["RegionID"].ToString(),
|
||||
out info.RegionID))
|
||||
if (!UUID.TryParse(request["SessionID"].ToString(), out session))
|
||||
return FailureResult();
|
||||
|
||||
if (request.ContainsKey("SecureSessionID"))
|
||||
// If it's malformed, we go on with a Zero on it
|
||||
UUID.TryParse(request["SecureSessionID"].ToString(), out ssession);
|
||||
|
||||
// if (m_PresenceService.ReportAgent(info))
|
||||
// return SuccessResult();
|
||||
if (m_PresenceService.LoginAgent(principal, session, ssession))
|
||||
return SuccessResult();
|
||||
|
||||
return FailureResult();
|
||||
}
|
||||
|
||||
byte[] LogoutAgent(Dictionary<string, object> request)
|
||||
{
|
||||
UUID session = UUID.Zero;
|
||||
|
||||
if (!request.ContainsKey("SessionID"))
|
||||
return FailureResult();
|
||||
|
||||
if (!UUID.TryParse(request["SessionID"].ToString(), out session))
|
||||
return FailureResult();
|
||||
|
||||
if (m_PresenceService.LogoutAgent(session))
|
||||
return SuccessResult();
|
||||
|
||||
return FailureResult();
|
||||
}
|
||||
|
||||
byte[] LogoutRegionAgents(Dictionary<string, object> request)
|
||||
{
|
||||
UUID region = UUID.Zero;
|
||||
|
||||
if (!request.ContainsKey("RegionID"))
|
||||
return FailureResult();
|
||||
|
||||
if (!UUID.TryParse(request["RegionID"].ToString(), out region))
|
||||
return FailureResult();
|
||||
|
||||
if (m_PresenceService.LogoutRegionAgents(region))
|
||||
return SuccessResult();
|
||||
|
||||
return FailureResult();
|
||||
}
|
||||
|
||||
byte[] Report(Dictionary<string, object> request)
|
||||
{
|
||||
UUID session = UUID.Zero;
|
||||
UUID region = UUID.Zero;
|
||||
Vector3 position = new Vector3(128, 128, 70);
|
||||
Vector3 look = Vector3.Zero;
|
||||
|
||||
if (!request.ContainsKey("SessionID") || !request.ContainsKey("RegionID"))
|
||||
return FailureResult();
|
||||
|
||||
if (!UUID.TryParse(request["SessionID"].ToString(), out session))
|
||||
return FailureResult();
|
||||
|
||||
if (!UUID.TryParse(request["RegionID"].ToString(), out region))
|
||||
return FailureResult();
|
||||
|
||||
if (request.ContainsKey("position"))
|
||||
Vector3.TryParse(request["position"].ToString(), out position);
|
||||
|
||||
if (request.ContainsKey("lookAt"))
|
||||
Vector3.TryParse(request["lookAt"].ToString(), out look);
|
||||
|
||||
if (m_PresenceService.ReportAgent(session, region, position, look))
|
||||
return SuccessResult();
|
||||
|
||||
return FailureResult();
|
||||
}
|
||||
|
||||
byte[] GetAgent(Dictionary<string, object> request)
|
||||
{
|
||||
UUID session = UUID.Zero;
|
||||
|
||||
if (!request.ContainsKey("SessionID"))
|
||||
return FailureResult();
|
||||
|
||||
if (!UUID.TryParse(request["SessionID"].ToString(), out session))
|
||||
return FailureResult();
|
||||
|
||||
PresenceInfo pinfo = m_PresenceService.GetAgent(session);
|
||||
|
||||
Dictionary<string, object> result = new Dictionary<string, object>();
|
||||
if (pinfo == null)
|
||||
result["result"] = "null";
|
||||
else
|
||||
result["result"] = pinfo.ToKeyValuePairs();
|
||||
|
||||
string xmlString = ServerUtils.BuildXmlResponse(result);
|
||||
//m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
|
||||
UTF8Encoding encoding = new UTF8Encoding();
|
||||
return encoding.GetBytes(xmlString);
|
||||
}
|
||||
|
||||
byte[] GetAgents(Dictionary<string, object> request)
|
||||
{
|
||||
|
||||
string[] userIDs;
|
||||
|
||||
if (!request.ContainsKey("uuids"))
|
||||
return FailureResult();
|
||||
|
||||
if (!(request["uuids"] is List<string>))
|
||||
{
|
||||
m_log.DebugFormat("[PRESENCE HANDLER]: GetAgents input argument was of unexpected type {0}", request["uuids"].GetType().ToString());
|
||||
return FailureResult();
|
||||
}
|
||||
|
||||
userIDs = ((List<string>)request["uuids"]).ToArray();
|
||||
|
||||
PresenceInfo[] pinfos = m_PresenceService.GetAgents(userIDs);
|
||||
|
||||
Dictionary<string, object> result = new Dictionary<string, object>();
|
||||
if ((pinfos == null) || ((pinfos != null) && (pinfos.Length == 0)))
|
||||
result["result"] = "null";
|
||||
else
|
||||
{
|
||||
int i = 0;
|
||||
foreach (PresenceInfo pinfo in pinfos)
|
||||
{
|
||||
Dictionary<string, object> rinfoDict = pinfo.ToKeyValuePairs();
|
||||
result["presence" + i] = rinfoDict;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
string xmlString = ServerUtils.BuildXmlResponse(result);
|
||||
//m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
|
||||
UTF8Encoding encoding = new UTF8Encoding();
|
||||
return encoding.GetBytes(xmlString);
|
||||
}
|
||||
|
||||
|
||||
private byte[] SuccessResult()
|
||||
{
|
||||
XmlDocument doc = new XmlDocument();
|
||||
|
|
|
@ -0,0 +1,377 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSimulator Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (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 log4net;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Nini.Config;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Communications;
|
||||
using OpenSim.Framework.Servers.HttpServer;
|
||||
using OpenSim.Services.Interfaces;
|
||||
using GridRegion = OpenSim.Services.Interfaces.GridRegion;
|
||||
using OpenSim.Server.Base;
|
||||
using OpenMetaverse;
|
||||
|
||||
namespace OpenSim.Services.Connectors
|
||||
{
|
||||
public class PresenceServicesConnector : IPresenceService
|
||||
{
|
||||
private static readonly ILog m_log =
|
||||
LogManager.GetLogger(
|
||||
MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private string m_ServerURI = String.Empty;
|
||||
|
||||
public PresenceServicesConnector()
|
||||
{
|
||||
}
|
||||
|
||||
public PresenceServicesConnector(string serverURI)
|
||||
{
|
||||
m_ServerURI = serverURI.TrimEnd('/');
|
||||
}
|
||||
|
||||
public PresenceServicesConnector(IConfigSource source)
|
||||
{
|
||||
Initialise(source);
|
||||
}
|
||||
|
||||
public virtual void Initialise(IConfigSource source)
|
||||
{
|
||||
IConfig gridConfig = source.Configs["PresenceService"];
|
||||
if (gridConfig == null)
|
||||
{
|
||||
m_log.Error("[PRESENCE CONNECTOR]: PresenceService missing from OpenSim.ini");
|
||||
throw new Exception("Presence connector init error");
|
||||
}
|
||||
|
||||
string serviceURI = gridConfig.GetString("PresenceServerURI",
|
||||
String.Empty);
|
||||
|
||||
if (serviceURI == String.Empty)
|
||||
{
|
||||
m_log.Error("[PRESENCE CONNECTOR]: No Server URI named in section PresenceService");
|
||||
throw new Exception("Presence connector init error");
|
||||
}
|
||||
m_ServerURI = serviceURI;
|
||||
}
|
||||
|
||||
|
||||
#region IPresenceService
|
||||
|
||||
public bool LoginAgent(UUID principalID, UUID sessionID, UUID secureSessionID)
|
||||
{
|
||||
Dictionary<string, object> sendData = new Dictionary<string, object>();
|
||||
//sendData["SCOPEID"] = scopeID.ToString();
|
||||
sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
|
||||
sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
|
||||
sendData["METHOD"] = "login";
|
||||
|
||||
sendData["PrincipalID"] = principalID.ToString();
|
||||
sendData["SessionID"] = sessionID.ToString();
|
||||
sendData["SecureSessionID"] = secureSessionID.ToString();
|
||||
|
||||
string reqString = ServerUtils.BuildQueryString(sendData);
|
||||
// m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
|
||||
try
|
||||
{
|
||||
string reply = SynchronousRestFormsRequester.MakeRequest("POST",
|
||||
m_ServerURI + "/presence",
|
||||
reqString);
|
||||
if (reply != string.Empty)
|
||||
{
|
||||
Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
|
||||
|
||||
if (replyData.ContainsKey("Result"))
|
||||
{
|
||||
if (replyData["Result"].ToString().ToLower() == "success")
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
m_log.DebugFormat("[PRESENCE CONNECTOR]: LoginAgent reply data does not contain result field");
|
||||
|
||||
}
|
||||
else
|
||||
m_log.DebugFormat("[PRESENCE CONNECTOR]: LoginAgent received empty reply");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public bool LogoutAgent(UUID sessionID)
|
||||
{
|
||||
Dictionary<string, object> sendData = new Dictionary<string, object>();
|
||||
//sendData["SCOPEID"] = scopeID.ToString();
|
||||
sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
|
||||
sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
|
||||
sendData["METHOD"] = "logout";
|
||||
|
||||
sendData["SessionID"] = sessionID.ToString();
|
||||
|
||||
string reqString = ServerUtils.BuildQueryString(sendData);
|
||||
// m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
|
||||
try
|
||||
{
|
||||
string reply = SynchronousRestFormsRequester.MakeRequest("POST",
|
||||
m_ServerURI + "/presence",
|
||||
reqString);
|
||||
if (reply != string.Empty)
|
||||
{
|
||||
Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
|
||||
|
||||
if (replyData.ContainsKey("Result"))
|
||||
{
|
||||
if (replyData["Result"].ToString().ToLower() == "success")
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutAgent reply data does not contain result field");
|
||||
|
||||
}
|
||||
else
|
||||
m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutAgent received empty reply");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool LogoutRegionAgents(UUID regionID)
|
||||
{
|
||||
Dictionary<string, object> sendData = new Dictionary<string, object>();
|
||||
//sendData["SCOPEID"] = scopeID.ToString();
|
||||
sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
|
||||
sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
|
||||
sendData["METHOD"] = "logoutregion";
|
||||
|
||||
sendData["RegionID"] = regionID.ToString();
|
||||
|
||||
string reqString = ServerUtils.BuildQueryString(sendData);
|
||||
// m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
|
||||
try
|
||||
{
|
||||
string reply = SynchronousRestFormsRequester.MakeRequest("POST",
|
||||
m_ServerURI + "/presence",
|
||||
reqString);
|
||||
if (reply != string.Empty)
|
||||
{
|
||||
Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
|
||||
|
||||
if (replyData.ContainsKey("Result"))
|
||||
{
|
||||
if (replyData["Result"].ToString().ToLower() == "success")
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutRegionAgents reply data does not contain result field");
|
||||
|
||||
}
|
||||
else
|
||||
m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutRegionAgents received empty reply");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt)
|
||||
{
|
||||
Dictionary<string, object> sendData = new Dictionary<string, object>();
|
||||
//sendData["SCOPEID"] = scopeID.ToString();
|
||||
sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
|
||||
sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
|
||||
sendData["METHOD"] = "report";
|
||||
|
||||
sendData["SessionID"] = sessionID.ToString();
|
||||
sendData["RegionID"] = regionID.ToString();
|
||||
sendData["position"] = position.ToString();
|
||||
sendData["lookAt"] = lookAt.ToString();
|
||||
|
||||
string reqString = ServerUtils.BuildQueryString(sendData);
|
||||
// m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
|
||||
try
|
||||
{
|
||||
string reply = SynchronousRestFormsRequester.MakeRequest("POST",
|
||||
m_ServerURI + "/presence",
|
||||
reqString);
|
||||
if (reply != string.Empty)
|
||||
{
|
||||
Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
|
||||
|
||||
if (replyData.ContainsKey("Result"))
|
||||
{
|
||||
if (replyData["Result"].ToString().ToLower() == "success")
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
m_log.DebugFormat("[PRESENCE CONNECTOR]: ReportAgent reply data does not contain result field");
|
||||
|
||||
}
|
||||
else
|
||||
m_log.DebugFormat("[PRESENCE CONNECTOR]: ReportAgent received empty reply");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public PresenceInfo GetAgent(UUID sessionID)
|
||||
{
|
||||
Dictionary<string, object> sendData = new Dictionary<string, object>();
|
||||
//sendData["SCOPEID"] = scopeID.ToString();
|
||||
sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
|
||||
sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
|
||||
sendData["METHOD"] = "getagent";
|
||||
|
||||
sendData["SessionID"] = sessionID.ToString();
|
||||
|
||||
string reply = string.Empty;
|
||||
string reqString = ServerUtils.BuildQueryString(sendData);
|
||||
// m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
|
||||
try
|
||||
{
|
||||
reply = SynchronousRestFormsRequester.MakeRequest("POST",
|
||||
m_ServerURI + "/presence",
|
||||
reqString);
|
||||
if (reply == null || (reply != null && reply == string.Empty))
|
||||
{
|
||||
m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgent received null or empty reply");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message);
|
||||
}
|
||||
|
||||
Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
|
||||
PresenceInfo pinfo = null;
|
||||
|
||||
if ((replyData != null) && (replyData["result"] != null))
|
||||
{
|
||||
if (replyData["result"].ToString() == "null")
|
||||
return null;
|
||||
|
||||
if (replyData["result"] is Dictionary<string, object>)
|
||||
{
|
||||
pinfo = new PresenceInfo((Dictionary<string, object>)replyData["result"]);
|
||||
}
|
||||
}
|
||||
|
||||
return pinfo;
|
||||
}
|
||||
|
||||
public PresenceInfo[] GetAgents(string[] userIDs)
|
||||
{
|
||||
Dictionary<string, object> sendData = new Dictionary<string, object>();
|
||||
//sendData["SCOPEID"] = scopeID.ToString();
|
||||
sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
|
||||
sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
|
||||
sendData["METHOD"] = "getagents";
|
||||
|
||||
sendData["uuids"] = new List<string>(userIDs);
|
||||
|
||||
string reply = string.Empty;
|
||||
string reqString = ServerUtils.BuildQueryString(sendData);
|
||||
// m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
|
||||
try
|
||||
{
|
||||
reply = SynchronousRestFormsRequester.MakeRequest("POST",
|
||||
m_ServerURI + "/presence",
|
||||
reqString);
|
||||
if (reply == null || (reply != null && reply == string.Empty))
|
||||
{
|
||||
m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgent received null or empty reply");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message);
|
||||
}
|
||||
|
||||
List<PresenceInfo> rinfos = new List<PresenceInfo>();
|
||||
|
||||
Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
|
||||
|
||||
if (replyData != null)
|
||||
{
|
||||
if (replyData.ContainsKey("result") && replyData.ContainsKey("result").ToString() == "null")
|
||||
{
|
||||
return new PresenceInfo[0];
|
||||
}
|
||||
|
||||
Dictionary<string, object>.ValueCollection pinfosList = replyData.Values;
|
||||
//m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count);
|
||||
foreach (object presence in pinfosList)
|
||||
{
|
||||
if (presence is Dictionary<string, object>)
|
||||
{
|
||||
PresenceInfo pinfo = new PresenceInfo((Dictionary<string, object>)presence);
|
||||
rinfos.Add(pinfo);
|
||||
}
|
||||
else
|
||||
m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received invalid response type {0}",
|
||||
presence.GetType());
|
||||
}
|
||||
}
|
||||
else
|
||||
m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received null response");
|
||||
|
||||
return rinfos.ToArray();
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
|
@ -41,6 +41,43 @@ namespace OpenSim.Services.Interfaces
|
|||
public DateTime Logout;
|
||||
public Vector3 Position;
|
||||
public Vector3 LookAt;
|
||||
|
||||
public PresenceInfo()
|
||||
{
|
||||
}
|
||||
|
||||
public PresenceInfo(Dictionary<string, object> kvp)
|
||||
{
|
||||
if (kvp.ContainsKey("PrincipalID"))
|
||||
UUID.TryParse(kvp["PrincipalID"].ToString(), out PrincipalID);
|
||||
if (kvp.ContainsKey("RegionID"))
|
||||
UUID.TryParse(kvp["RegionID"].ToString(), out RegionID);
|
||||
if (kvp.ContainsKey("login"))
|
||||
DateTime.TryParse(kvp["login"].ToString(), out Login);
|
||||
if (kvp.ContainsKey("logout"))
|
||||
DateTime.TryParse(kvp["logout"].ToString(), out Logout);
|
||||
if (kvp.ContainsKey("lookAt"))
|
||||
Vector3.TryParse(kvp["lookAt"].ToString(), out LookAt);
|
||||
if (kvp.ContainsKey("online"))
|
||||
Boolean.TryParse(kvp["online"].ToString(), out Online);
|
||||
if (kvp.ContainsKey("position"))
|
||||
Vector3.TryParse(kvp["position"].ToString(), out Position);
|
||||
|
||||
}
|
||||
|
||||
public Dictionary<string, object> ToKeyValuePairs()
|
||||
{
|
||||
Dictionary<string, object> result = new Dictionary<string, object>();
|
||||
result["PrincipalID"] = PrincipalID.ToString();
|
||||
result["RegionID"] = RegionID.ToString();
|
||||
result["online"] = Online.ToString();
|
||||
result["login"] = Login.ToString();
|
||||
result["logout"] = Logout.ToString();
|
||||
result["position"] = Position.ToString();
|
||||
result["lookAt"] = LookAt.ToString();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IPresenceService
|
||||
|
@ -52,6 +89,6 @@ namespace OpenSim.Services.Interfaces
|
|||
bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt);
|
||||
|
||||
PresenceInfo GetAgent(UUID sessionID);
|
||||
PresenceInfo[] GetAgents(string[] principalIDs);
|
||||
PresenceInfo[] GetAgents(string[] userIDs);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue