* Avatar service connectors all in place, but untested.

* Fixed a typo in RemoteUserAccountServiceConnector module.
slimupdates
Diva Canto 2010-01-02 15:07:38 -08:00
parent e73eb55ad8
commit 28702f585f
7 changed files with 932 additions and 3 deletions

View File

@ -32,6 +32,8 @@
<!-- Service connectors OUT modules -->
<RegionModule id="LocalAssetServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset.LocalAssetServicesConnector" />
<RegionModule id="RemoteAssetServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset.RemoteAssetServicesConnector" />
<RegionModule id="LocalAvatarServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar.LocalAvatarServicesConnector" />
<RegionModule id="RemoteAvatarServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar.RemoteAvatarServicesConnector" />
<RegionModule id="LocalAuthenticationServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Authentication.LocalAuthenticationServicesConnector" />
<RegionModule id="RemoteAuthenticationServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Authentication.RemoteAuthenticationServicesConnector" />
<RegionModule id="LocalAuthorizationServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization.LocalAuthorizationServicesConnector" />

View File

@ -0,0 +1,168 @@
/*
* 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 log4net;
using Nini.Config;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Server.Base;
using OpenSim.Services.Interfaces;
using OpenMetaverse;
namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar
{
public class LocalAvatarServicesConnector : ISharedRegionModule, IAvatarService
{
private static readonly ILog m_log =
LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
private IAvatarService m_AvatarService;
private bool m_Enabled = false;
#region ISharedRegionModule
public Type ReplaceableInterface
{
get { return null; }
}
public string Name
{
get { return "LocalAvatarServicesConnector"; }
}
public void Initialise(IConfigSource source)
{
IConfig moduleConfig = source.Configs["Modules"];
if (moduleConfig != null)
{
string name = moduleConfig.GetString("AvatarServices", "");
if (name == Name)
{
IConfig userConfig = source.Configs["AvatarService"];
if (userConfig == null)
{
m_log.Error("[USER CONNECTOR]: AvatarService missing from OpenSim.ini");
return;
}
string serviceDll = userConfig.GetString("LocalServiceModule",
String.Empty);
if (serviceDll == String.Empty)
{
m_log.Error("[USER CONNECTOR]: No LocalServiceModule named in section AvatarService");
return;
}
Object[] args = new Object[] { source };
m_AvatarService =
ServerUtils.LoadPlugin<IAvatarService>(serviceDll,
args);
if (m_AvatarService == null)
{
m_log.Error("[USER CONNECTOR]: Can't load user account service");
return;
}
m_Enabled = true;
m_log.Info("[USER CONNECTOR]: Local avatar connector enabled");
}
}
}
public void PostInitialise()
{
if (!m_Enabled)
return;
}
public void Close()
{
if (!m_Enabled)
return;
}
public void AddRegion(Scene scene)
{
if (!m_Enabled)
return;
scene.RegisterModuleInterface<IAvatarService>(m_AvatarService);
}
public void RemoveRegion(Scene scene)
{
if (!m_Enabled)
return;
}
public void RegionLoaded(Scene scene)
{
if (!m_Enabled)
return;
}
#endregion
#region IAvatarService
public AvatarData GetAvatar(UUID userID)
{
return m_AvatarService.GetAvatar(userID);
}
public bool SetAvatar(UUID userID, AvatarData avatar)
{
return m_AvatarService.SetAvatar(userID, avatar);
}
public bool ResetAvatar(UUID userID)
{
return m_AvatarService.ResetAvatar(userID);
}
public bool SetItems(UUID userID, string[] names, string[] values)
{
return m_AvatarService.SetItems(userID, names, values);
}
public bool RemoveItems(UUID userID, string[] names)
{
return m_AvatarService.RemoveItems(userID, names);
}
#endregion
}
}

View File

@ -0,0 +1,114 @@
/*
* 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 Nini.Config;
using log4net;
using System.Reflection;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Services.Interfaces;
using OpenSim.Services.Connectors;
namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar
{
public class RemoteAvatarServicesConnector : AvatarServicesConnector,
ISharedRegionModule, IAvatarService
{
private static readonly ILog m_log =
LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
private bool m_Enabled = false;
public Type ReplaceableInterface
{
get { return null; }
}
public string Name
{
get { return "RemoteAvatarServicesConnector"; }
}
public override void Initialise(IConfigSource source)
{
IConfig moduleConfig = source.Configs["Modules"];
if (moduleConfig != null)
{
string name = moduleConfig.GetString("AvatarServices", "");
if (name == Name)
{
IConfig userConfig = source.Configs["AvatarService"];
if (userConfig == null)
{
m_log.Error("[AVATAR CONNECTOR]: AvatarService missing from OpanSim.ini");
return;
}
m_Enabled = true;
base.Initialise(source);
m_log.Info("[AVATAR CONNECTOR]: Remote avatars enabled");
}
}
}
public void PostInitialise()
{
if (!m_Enabled)
return;
}
public void Close()
{
if (!m_Enabled)
return;
}
public void AddRegion(Scene scene)
{
if (!m_Enabled)
return;
scene.RegisterModuleInterface<IAvatarService>(this);
}
public void RemoveRegion(Scene scene)
{
if (!m_Enabled)
return;
}
public void RegionLoaded(Scene scene)
{
if (!m_Enabled)
return;
}
}
}

View File

@ -60,13 +60,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
IConfig moduleConfig = source.Configs["Modules"];
if (moduleConfig != null)
{
string name = moduleConfig.GetString("UserServices", "");
string name = moduleConfig.GetString("UserAccountServices", "");
if (name == Name)
{
IConfig userConfig = source.Configs["UserService"];
IConfig userConfig = source.Configs["UserAccountService"];
if (userConfig == null)
{
m_log.Error("[USER CONNECTOR]: UserService missing from OpanSim.ini");
m_log.Error("[USER CONNECTOR]: UserAccountService missing from OpanSim.ini");
return;
}

View File

@ -0,0 +1,61 @@
/*
* 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 Nini.Config;
using OpenSim.Server.Base;
using OpenSim.Services.Interfaces;
using OpenSim.Framework.Servers.HttpServer;
using OpenSim.Server.Handlers.Base;
namespace OpenSim.Server.Handlers.Avatar
{
public class AvatarServiceConnector : ServiceConnector
{
private IAvatarService m_AvatarService;
private string m_ConfigName = "AvatarService";
public AvatarServiceConnector(IConfigSource config, IHttpServer server, string configName) :
base(config, server, configName)
{
IConfig serverConfig = config.Configs[m_ConfigName];
if (serverConfig == null)
throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
string avatarService = serverConfig.GetString("LocalServiceModule",
String.Empty);
if (avatarService == String.Empty)
throw new Exception("No LocalServiceModule in config file");
Object[] args = new Object[] { config };
m_AvatarService = ServerUtils.LoadPlugin<IAvatarService>(avatarService, args);
server.AddStreamHandler(new AvatarServerPostHandler(m_AvatarService));
}
}
}

View File

@ -0,0 +1,272 @@
/*
* 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 Nini.Config;
using log4net;
using System;
using System.Reflection;
using System.IO;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Serialization;
using System.Collections.Generic;
using OpenSim.Server.Base;
using OpenSim.Services.Interfaces;
using OpenSim.Framework;
using OpenSim.Framework.Servers.HttpServer;
using OpenMetaverse;
namespace OpenSim.Server.Handlers.Avatar
{
public class AvatarServerPostHandler : BaseStreamHandler
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private IAvatarService m_AvatarService;
public AvatarServerPostHandler(IAvatarService service) :
base("POST", "/avatar")
{
m_AvatarService = service;
}
public override byte[] Handle(string path, Stream requestData,
OSHttpRequest httpRequest, OSHttpResponse httpResponse)
{
StreamReader sr = new StreamReader(requestData);
string body = sr.ReadToEnd();
sr.Close();
body = body.Trim();
//m_log.DebugFormat("[XXX]: query String: {0}", body);
try
{
Dictionary<string, object> request =
ServerUtils.ParseQueryString(body);
if (!request.ContainsKey("METHOD"))
return FailureResult();
string method = request["METHOD"].ToString();
switch (method)
{
case "getavatar":
return GetAvatar(request);
case "setavatar":
return SetAvatar(request);
case "resetavatar":
return ResetAvatar(request);
case "setitems":
return SetItems(request);
case "removeitems":
return RemoveItems(request);
}
m_log.DebugFormat("[AVATAR HANDLER]: unknown method request: {0}", method);
}
catch (Exception e)
{
m_log.Debug("[AVATAR HANDLER]: Exception {0}" + e);
}
return FailureResult();
}
byte[] GetAvatar(Dictionary<string, object> request)
{
UUID user = UUID.Zero;
if (!request.ContainsKey("UserID"))
return FailureResult();
if (UUID.TryParse(request["UserID"].ToString(), out user))
{
AvatarData avatar = m_AvatarService.GetAvatar(user);
if (avatar == null)
return FailureResult();
Dictionary<string, object> result = new Dictionary<string, object>();
if (avatar == null)
result["result"] = "null";
else
result["result"] = avatar.ToKeyValuePairs();
string xmlString = ServerUtils.BuildXmlResponse(result);
UTF8Encoding encoding = new UTF8Encoding();
return encoding.GetBytes(xmlString);
}
return FailureResult();
}
byte[] SetAvatar(Dictionary<string, object> request)
{
UUID user = UUID.Zero;
if (!request.ContainsKey("UserID"))
return FailureResult();
if (!UUID.TryParse(request["UserID"].ToString(), out user))
return FailureResult();
if (request.ContainsKey("Avatar") && request["Avatar"] is Dictionary<string, object>)
{
AvatarData avatar = new AvatarData((Dictionary<string, object>)request["Avatar"]);
if (m_AvatarService.SetAvatar(user, avatar))
return SuccessResult();
}
return FailureResult();
}
byte[] ResetAvatar(Dictionary<string, object> request)
{
UUID user = UUID.Zero;
if (!request.ContainsKey("UserID"))
return FailureResult();
if (!UUID.TryParse(request["UserID"].ToString(), out user))
return FailureResult();
if (m_AvatarService.ResetAvatar(user))
return SuccessResult();
return FailureResult();
}
byte[] SetItems(Dictionary<string, object> request)
{
UUID user = UUID.Zero;
string[] names, values;
if (!request.ContainsKey("UserID") || !request.ContainsKey("Names") || !request.ContainsKey("Values"))
return FailureResult();
if (!UUID.TryParse(request["UserID"].ToString(), out user))
return FailureResult();
if (!(request["Names"] is List<string> || request["Values"] is List<string>))
return FailureResult();
List<string> _names = (List<string>)request["Names"];
names = _names.ToArray();
List<string> _values = (List<string>)request["Values"];
values = _values.ToArray();
if (m_AvatarService.SetItems(user, names, values))
return SuccessResult();
return FailureResult();
}
byte[] RemoveItems(Dictionary<string, object> request)
{
UUID user = UUID.Zero;
string[] names;
if (!request.ContainsKey("UserID") || !request.ContainsKey("Names"))
return FailureResult();
if (!UUID.TryParse(request["UserID"].ToString(), out user))
return FailureResult();
if (!(request["Names"] is List<string>))
return FailureResult();
List<string> _names = (List<string>)request["Names"];
names = _names.ToArray();
if (m_AvatarService.RemoveItems(user, names))
return SuccessResult();
return FailureResult();
}
private byte[] SuccessResult()
{
XmlDocument doc = new XmlDocument();
XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
"", "");
doc.AppendChild(xmlnode);
XmlElement rootElement = doc.CreateElement("", "ServerResponse",
"");
doc.AppendChild(rootElement);
XmlElement result = doc.CreateElement("", "result", "");
result.AppendChild(doc.CreateTextNode("Success"));
rootElement.AppendChild(result);
return DocToBytes(doc);
}
private byte[] FailureResult()
{
XmlDocument doc = new XmlDocument();
XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
"", "");
doc.AppendChild(xmlnode);
XmlElement rootElement = doc.CreateElement("", "ServerResponse",
"");
doc.AppendChild(rootElement);
XmlElement result = doc.CreateElement("", "result", "");
result.AppendChild(doc.CreateTextNode("Failure"));
rootElement.AppendChild(result);
return DocToBytes(doc);
}
private byte[] DocToBytes(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, null);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.ToArray();
}
}
}

View File

@ -0,0 +1,312 @@
/*
* 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 IAvatarService = OpenSim.Services.Interfaces.IAvatarService;
using OpenSim.Server.Base;
using OpenMetaverse;
namespace OpenSim.Services.Connectors
{
public class AvatarServicesConnector : IAvatarService
{
private static readonly ILog m_log =
LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
private string m_ServerURI = String.Empty;
public AvatarServicesConnector()
{
}
public AvatarServicesConnector(string serverURI)
{
m_ServerURI = serverURI.TrimEnd('/');
}
public AvatarServicesConnector(IConfigSource source)
{
Initialise(source);
}
public virtual void Initialise(IConfigSource source)
{
IConfig gridConfig = source.Configs["AvatarService"];
if (gridConfig == null)
{
m_log.Error("[AVATAR CONNECTOR]: AvatarService missing from OpenSim.ini");
throw new Exception("Avatar connector init error");
}
string serviceURI = gridConfig.GetString("AvatarServerURI",
String.Empty);
if (serviceURI == String.Empty)
{
m_log.Error("[AVATAR CONNECTOR]: No Server URI named in section AvatarService");
throw new Exception("Avatar connector init error");
}
m_ServerURI = serviceURI;
}
#region IAvatarService
public AvatarData GetAvatar(UUID userID)
{
Dictionary<string, object> sendData = new Dictionary<string, object>();
//sendData["SCOPEID"] = scopeID.ToString();
sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
sendData["METHOD"] = "getavatar";
sendData["UserID"] = userID;
string reply = string.Empty;
string reqString = ServerUtils.BuildQueryString(sendData);
// m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString);
try
{
reply = SynchronousRestFormsRequester.MakeRequest("POST",
m_ServerURI + "/avatar",
reqString);
if (reply == null || (reply != null && reply == string.Empty))
{
m_log.DebugFormat("[AVATAR CONNECTOR]: GetAgent received null or empty reply");
return null;
}
}
catch (Exception e)
{
m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting presence server: {0}", e.Message);
}
Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
AvatarData avatar = null;
if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null))
{
if (replyData["result"] is Dictionary<string, object>)
{
avatar = new AvatarData((Dictionary<string, object>)replyData["result"]);
}
}
return avatar;
}
public bool SetAvatar(UUID userID, AvatarData avatar)
{
Dictionary<string, object> sendData = new Dictionary<string, object>();
//sendData["SCOPEID"] = scopeID.ToString();
sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
sendData["METHOD"] = "setavatar";
sendData["UserID"] = userID.ToString();
sendData["Avatar"] = avatar.ToKeyValuePairs();
string reqString = ServerUtils.BuildQueryString(sendData);
// m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString);
try
{
string reply = SynchronousRestFormsRequester.MakeRequest("POST",
m_ServerURI + "/avatar",
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("[AVATAR CONNECTOR]: SetAvatar reply data does not contain result field");
}
else
m_log.DebugFormat("[AVATAR CONNECTOR]: SetAvatar received empty reply");
}
catch (Exception e)
{
m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting avatar server: {0}", e.Message);
}
return false;
}
public bool ResetAvatar(UUID userID)
{
Dictionary<string, object> sendData = new Dictionary<string, object>();
//sendData["SCOPEID"] = scopeID.ToString();
sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
sendData["METHOD"] = "resetavatar";
sendData["UserID"] = userID.ToString();
string reqString = ServerUtils.BuildQueryString(sendData);
// m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString);
try
{
string reply = SynchronousRestFormsRequester.MakeRequest("POST",
m_ServerURI + "/avatar",
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("[AVATAR CONNECTOR]: SetItems reply data does not contain result field");
}
else
m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems received empty reply");
}
catch (Exception e)
{
m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting avatar server: {0}", e.Message);
}
return false;
}
public bool SetItems(UUID userID, string[] names, string[] values)
{
Dictionary<string, object> sendData = new Dictionary<string, object>();
sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
sendData["METHOD"] = "setitems";
sendData["UserID"] = userID.ToString();
sendData["Names"] = new List<string>(names);
sendData["Values"] = new List<string>(values);
string reqString = ServerUtils.BuildQueryString(sendData);
// m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString);
try
{
string reply = SynchronousRestFormsRequester.MakeRequest("POST",
m_ServerURI + "/avatar",
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("[AVATAR CONNECTOR]: SetItems reply data does not contain result field");
}
else
m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems received empty reply");
}
catch (Exception e)
{
m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting avatar server: {0}", e.Message);
}
return false;
}
public bool RemoveItems(UUID userID, string[] names)
{
Dictionary<string, object> sendData = new Dictionary<string, object>();
//sendData["SCOPEID"] = scopeID.ToString();
sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
sendData["METHOD"] = "removeitems";
sendData["UserID"] = userID.ToString();
sendData["Names"] = new List<string>(names);
string reqString = ServerUtils.BuildQueryString(sendData);
// m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString);
try
{
string reply = SynchronousRestFormsRequester.MakeRequest("POST",
m_ServerURI + "/avatar",
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("[AVATAR CONNECTOR]: RemoveItems reply data does not contain result field");
}
else
m_log.DebugFormat("[AVATAR CONNECTOR]: RemoveItems received empty reply");
}
catch (Exception e)
{
m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting avatar server: {0}", e.Message);
}
return false;
}
#endregion
}
}