Simulator Extra Features Service

Provide a means for regions to fetch extra features supported by modern viewers from a central location
.
This commit is contained in:
BlueWall
2014-07-30 11:19:34 -04:00
parent a4107cb6c7
commit e0d8f42e6b
7 changed files with 415 additions and 9 deletions

View File

@@ -56,13 +56,15 @@ namespace OpenSim.Region.ClientStack.Linden
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "SimulatorFeaturesModule")]
public class SimulatorFeaturesModule : ISharedRegionModule, ISimulatorFeaturesModule
{
// private static readonly ILog m_log =
// LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static readonly ILog m_log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public event SimulatorFeaturesRequestDelegate OnSimulatorFeaturesRequest;
private Scene m_scene;
bool m_AllowOverride = true;
/// <summary>
/// Simulator features
/// </summary>
@@ -75,8 +77,15 @@ namespace OpenSim.Region.ClientStack.Linden
public void Initialise(IConfigSource source)
{
IConfig config = source.Configs["SimulatorFeatures"];
if (config != null)
IConfig config = source.Configs ["SimulatorFeatures"];
string featuresURI = config.GetString ("ExtraFeaturesServiceURI", string.Empty);
if (string.IsNullOrEmpty (featuresURI)) {
m_log.Info ("ExtraFeaturesServiceURI is undefined. The grid's ExtraFeatures will not be available to regions in this instnace.");
} else {
GetGridExtraFeatures(featuresURI);
}
if (config != null && m_AllowOverride == true)
{
m_SearchURL = config.GetString("SearchServerURI", string.Empty);
@@ -126,6 +135,7 @@ namespace OpenSim.Region.ClientStack.Linden
/// </remarks>
private void AddDefaultFeatures()
{
lock (m_features)
{
m_features["MeshRezEnabled"] = true;
@@ -141,15 +151,21 @@ namespace OpenSim.Region.ClientStack.Linden
// Extra information for viewers that want to use it
// TODO: Take these out of here into their respective modules, like map-server-url
OSDMap extrasMap = new OSDMap();
if (m_SearchURL != string.Empty)
OSDMap extrasMap;
if(m_features.ContainsKey("OpenSimExtras"))
{
extrasMap = (OSDMap)m_features["OpenSimExtras"];
}
else
extrasMap = new OSDMap();
if (m_SearchURL != string.Empty && m_AllowOverride == true)
extrasMap["search-server-url"] = m_SearchURL;
if (m_ExportSupported)
if (m_ExportSupported && m_AllowOverride == true)
extrasMap["ExportSupported"] = true;
if (extrasMap.Count > 0)
m_features["OpenSimExtras"] = extrasMap;
}
}
@@ -204,7 +220,10 @@ namespace OpenSim.Region.ClientStack.Linden
OSDMap copy = DeepCopy();
SimulatorFeaturesRequestDelegate handlerOnSimulatorFeaturesRequest = OnSimulatorFeaturesRequest;
if (handlerOnSimulatorFeaturesRequest != null)
// We will not trigger the event if m_AllowOverride == False
// See Robust.ini/Robust.HG.ini [GridExtraFeatures] - AllowRegionOverride
if (handlerOnSimulatorFeaturesRequest != null && m_AllowOverride == true)
handlerOnSimulatorFeaturesRequest(agentID, ref copy);
//Send back data
@@ -217,5 +236,42 @@ namespace OpenSim.Region.ClientStack.Linden
return responsedata;
}
/// <summary>
/// Gets the grid extra features.
/// </summary>
/// <param name='featuresURI'>
/// The URI Robust uses to handle the get_extra_features request
/// </param>
private void GetGridExtraFeatures(string featuresURI)
{
JsonRpcRequestManager rpc = new JsonRpcRequestManager ();
OSDMap parameters = new OSDMap ();
OSD Params = (OSD)parameters;
if (!rpc.JsonRpcRequest (ref Params, "get_extra_features", featuresURI, UUID.Random ().ToString ()))
{
m_log.Error("[SIMFEATURES]: Could not retrieve extra features from grid. Please check configuration.");
return;
}
parameters = (OSDMap)Params;
OSDMap features = (OSDMap)parameters ["result"];
if(features.ContainsKey("region_override"))
m_AllowOverride = features ["region_override"].AsBoolean () ;
else
m_AllowOverride = true;
OSDMap test = (OSDMap)features ["extra_features"];
lock (m_features)
{
OSDMap extrasMap = new OSDMap();
foreach (string key in test.Keys)
{
extrasMap[key] = test[key];
}
m_features["OpenSimExtras"] = extrasMap;
}
}
}
}

View File

@@ -0,0 +1,129 @@
/*
* 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.Reflection;
using System.Collections.Generic;
using log4net;
using Mono.Addins;
using Nini.Config;
using OpenSim.Framework;
using OpenSim.Framework.Servers;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Server.Base;
using OpenSim.Server.Handlers.Base;
using OpenSim.Server.Handlers.Grid;
using OpenSim.Services.Interfaces;
using OpenSim.Framework.Servers.HttpServer;
namespace OpenSim.Region.CoreModules.ServiceConnectorsIn.Grid
{
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LocalGridFeaturesServiceInConnector")]
public class LocalGridExtraFeaturesServiceInConnector : ISharedRegionModule
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static bool m_Enabled = false;
private IConfigSource m_Config;
bool m_Registered = false;
#region Region Module interface
public void Initialise(IConfigSource config)
{
m_Config = config;
IConfig moduleConfig = config.Configs["Modules"];
if (moduleConfig != null)
{
string name = moduleConfig.GetString("GridExtraFeaturesServiceInConnector", "");
if (name == Name)
{
m_log.Info("[GridExtraFeatures]: GridExtraFeatures Service In Connector enabled");
InitializeService(config);
}
}
}
public void InitializeService(IConfigSource config)
{
GridExtraFeaturesHandlers handler = new GridExtraFeaturesHandlers(config);
IHttpServer Server = MainServer.Instance;
Server.AddJsonRPCHandler("get_extra_features", handler.JsonGetGridFeaturesMethod);
}
public void PostInitialise()
{
}
public void Close()
{
}
public Type ReplaceableInterface
{
get { return null; }
}
public string Name
{
get { return "LocalGridExtraFeaturesServiceInConnector"; }
}
public void AddRegion(Scene scene)
{
if (!m_Enabled)
return;
}
public void RemoveRegion(Scene scene)
{
if (!m_Enabled)
return;
}
public void RegionLoaded(Scene scene)
{
if (!m_Enabled)
return;
if (!m_Registered)
{
m_Registered = true;
m_log.Info("[GRID EXTRA FEATURES]: Starting...");
new GridExtraFeaturesServerInConnector(m_Config, MainServer.Instance, "GridExtraFeaturesService");
}
}
#endregion
}
}