replace lightshare early work

This commit is contained in:
UbitUmarov
2020-06-10 09:26:55 +01:00
parent 0d76635113
commit e2be90caaf
23 changed files with 1917 additions and 1457 deletions

View File

@@ -26,20 +26,25 @@
*/
using System;
using System.Collections.Generic;
using System.Net;
using System.Reflection;
using System.Text;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
using OpenSim.Framework;
using OpenSim.Framework.Capabilities;
using OpenSim.Framework.Servers.HttpServer;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Services.Interfaces;
using log4net;
using Nini.Config;
using Mono.Addins;
using Caps = OpenSim.Framework.Capabilities.Caps;
using OSDArray = OpenMetaverse.StructuredData.OSDArray;
using OSDMap = OpenMetaverse.StructuredData.OSDMap;
namespace OpenSim.Region.CoreModules.World.LightShare
{
@@ -52,6 +57,14 @@ namespace OpenSim.Region.CoreModules.World.LightShare
private Scene m_scene = null;
private UUID regionID = UUID.Zero;
private bool Enabled = false;
private IEstateModule m_estateModule;
private IEventQueue m_eventQueue;
private IAssetService m_assetService;
private static ViewerEnviroment m_DefaultEnv = null;
private static readonly string m_defaultDayAssetID = "5646d39e-d3d7-6aff-ed71-30fc87d64a91";
private int m_regionEnvVersion = -1;
#region INonSharedRegionModule
public void Initialise(IConfigSource source)
@@ -69,6 +82,7 @@ namespace OpenSim.Region.CoreModules.World.LightShare
Enabled = true;
m_log.InfoFormat("[{0}]: Module is enabled.", Name);
}
@@ -101,12 +115,80 @@ namespace OpenSim.Region.CoreModules.World.LightShare
if (!Enabled)
return;
m_estateModule = scene.RequestModuleInterface<IEstateModule>();
if (m_estateModule == null)
{
Enabled = false;
return;
}
m_eventQueue = m_scene.RequestModuleInterface<IEventQueue>();
if (m_eventQueue == null)
{
Enabled = false;
return;
}
m_assetService = m_scene.AssetService;
if (m_assetService == null)
{
Enabled = false;
return;
}
if(m_DefaultEnv == null)
{
AssetBase defEnv = m_assetService.Get(m_defaultDayAssetID);
if(defEnv != null)
{
byte[] envData = defEnv.Data;
try
{
OSD oenv = OSDParser.DeserializeLLSDXml(envData);
m_DefaultEnv = new ViewerEnviroment();
m_DefaultEnv.CycleFromOSD(oenv);
}
catch ( Exception e)
{
m_DefaultEnv = null;
m_log.WarnFormat("[Enviroment {0}]: failed to decode default enviroment asset: {1}", m_scene.Name, e.Message);
}
}
}
string senv = scene.SimulationDataService.LoadRegionEnvironmentSettings(scene.RegionInfo.RegionID);
if(!string.IsNullOrEmpty(senv))
{
try
{
OSD oenv = OSDParser.DeserializeLLSDXml(senv);
ViewerEnviroment VEnv = new ViewerEnviroment();
if(oenv is OSDArray)
VEnv.FromWLOSD(oenv);
else
VEnv.FromOSD(oenv);
scene.RegionEnviroment = VEnv;
m_regionEnvVersion = VEnv.version;
}
catch(Exception e)
{
m_log.ErrorFormat("[Enviroment {0}] failed to load initial enviroment {1}", m_scene.Name, e.Message);
scene.RegionEnviroment = null;
m_regionEnvVersion = -1;
}
}
else
{
scene.RegionEnviroment = null;
m_regionEnvVersion = -1;
}
scene.EventManager.OnRegisterCaps += OnRegisterCaps;
}
public void RemoveRegion(Scene scene)
{
if (Enabled)
if (!Enabled)
return;
scene.EventManager.OnRegisterCaps -= OnRegisterCaps;
@@ -120,57 +202,339 @@ namespace OpenSim.Region.CoreModules.World.LightShare
if (!Enabled)
return;
m_scene.SimulationDataService.RemoveRegionEnvironmentSettings(regionUUID);
StoreOnRegion(null);
WindlightRefresh(0);
}
public void WindlightRefresh(int interpolate)
{
List<byte[]> ls = null;
m_scene.ForEachClient(delegate (IClientAPI client)
{
if(!client.IsActive)
return;
uint vflags = client.GetViewerCaps();
if ((vflags & 0x8000) != 0)
m_estateModule.HandleRegionInfoRequest(client);
else if ((vflags & 0x4000) != 0)
m_eventQueue.WindlightRefreshEvent(interpolate, client.AgentId);
else
{
if(ls == null)
ls = MakeLightShareData();
SendLightShare(client, ls);
}
});
}
public void FromLightShare(RegionLightShareData ls)
{
if (!Enabled)
return;
ViewerEnviroment VEnv = new ViewerEnviroment();
VEnv.FromLightShare(ls);
StoreOnRegion(VEnv);
WindlightRefresh(0);
}
public RegionLightShareData ToLightShare()
{
if (!Enabled)
return new RegionLightShareData();
RegionLightShareData ls = null;
try
{
ViewerEnviroment VEnv = m_scene.RegionEnviroment;
if(VEnv == null)
return new RegionLightShareData();
ls = VEnv.ToLightShare();
}
catch (Exception e)
{
m_log.ErrorFormat("[{0}]: Unable to convert environment to lightShare, Exception: {1} - {2}",
Name, e.Message, e.StackTrace);
}
if(ls == null)
return new RegionLightShareData();
return ls;
}
#endregion
#region Events
private void OnRegisterCaps(UUID agentID, Caps caps)
{
// m_log.DebugFormat("[{0}]: Register capability for agentID {1} in region {2}",
// Name, agentID, caps.RegionName);
// m_log.DebugFormat("[{0}]: Register capability for agentID {1} in region {2}",
// Name, agentID, caps.RegionName);
string capsPath = "/CAPS/" + UUID.Random();
caps.RegisterSimpleHandler("EnvironmentSettings",
new SimpleStreamHandler("/" + UUID.Random(), delegate (IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
{
processEnv(httpRequest, httpResponse, agentID);
}));
// Get handler
caps.RegisterHandler(
"EnvironmentSettings",
new RestStreamHandler(
"GET",
capsPath,
(request, path, param, httpRequest, httpResponse)
=> GetEnvironmentSettings(request, path, param, agentID, caps),
"EnvironmentSettings",
agentID.ToString()));
// Set handler
caps.HttpListener.AddStreamHandler(
new RestStreamHandler(
"POST",
capsPath,
(request, path, param, httpRequest, httpResponse)
=> SetEnvironmentSettings(request, path, param, agentID, caps),
"EnvironmentSettings",
agentID.ToString()));
//Extended
caps.RegisterSimpleHandler("ExtEnvironment",
new SimpleStreamHandler("/" + UUID.Random(), delegate (IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
{
processExtEnv(httpRequest, httpResponse, agentID, caps);
}));
}
#endregion
private string GetEnvironmentSettings(string request, string path, string param,
UUID agentID, Caps caps)
private void processEnv(IOSHttpRequest request, IOSHttpResponse response, UUID agentID)
{
// m_log.DebugFormat("[{0}]: Environment GET handle for agentID {1} in region {2}",
// Name, agentID, caps.RegionName);
switch (request.HttpMethod)
{
case "POST":
SetEnvironmentSettings(request, response, agentID);
return;
case "GET":
GetEnvironmentSettings(response, agentID);
return;
default:
{
response.StatusCode = (int)HttpStatusCode.MethodNotAllowed;
return;
}
}
}
private void processExtEnv(IOSHttpRequest request, IOSHttpResponse response, UUID agentID, Caps caps)
{
switch(request.HttpMethod)
{
case "PUT":
case "POST":
SetExtEnvironmentSettings(request, response, agentID, caps);
return;
case "GET":
GetExtEnvironmentSettings(request, response, agentID);
return;
case "DELETE":
DeleteExtEnvironmentSettings(request, response, agentID);
return;
default:
{
response.StatusCode = (int)HttpStatusCode.MethodNotAllowed;
return;
}
}
}
private void DeleteExtEnvironmentSettings(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, UUID agentID)
{
int parcel = -1;
if (httpRequest.Query.Count > 0)
{
if (httpRequest.Query.ContainsKey("parcelid"))
{
Int32.TryParse((string)httpRequest.Query["parcelid"], out parcel);
}
}
if(parcel == -1)
StoreOnRegion(null);
WindlightRefresh(0);
StringBuilder sb = LLSDxmlEncode.Start();
LLSDxmlEncode.AddMap(sb);
LLSDxmlEncode.AddElem("messageID", UUID.Zero, sb);
LLSDxmlEncode.AddElem("regionID", regionID, sb);
LLSDxmlEncode.AddElem("success", true, sb);
LLSDxmlEncode.AddEndMap(sb);
httpResponse.RawBuffer = Util.UTF8.GetBytes(LLSDxmlEncode.End(sb));
httpResponse.StatusCode = (int)HttpStatusCode.OK;
}
private void GetExtEnvironmentSettings(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, UUID agentID)
{
if (httpRequest.Query.Count > 0)
{
int parcel = -1;
if (httpRequest.Query.ContainsKey("parcelid"))
{
Int32.TryParse((string)httpRequest.Query["parcelid"], out parcel);
}
OSD oenv = ViewerEnviroment.DefaultToOSD(regionID, parcel);
httpResponse.RawBuffer = Util.UTF8.GetBytes(OSDParser.SerializeLLSDXmlString(oenv));
httpResponse.StatusCode = (int)HttpStatusCode.OK;
}
ViewerEnviroment VEnv = m_scene.RegionEnviroment;
if (VEnv == null)
VEnv = m_DefaultEnv == null ? new ViewerEnviroment() : m_DefaultEnv;
OSDMap map = new OpenMetaverse.StructuredData.OSDMap();
map["environment"] = VEnv.ToOSD();
string env = OSDParser.SerializeLLSDXmlString(map);
// only the presence of enviroment seems to matter
if (String.IsNullOrEmpty(env))
{
StringBuilder sb = LLSDxmlEncode.Start();
LLSDxmlEncode.AddArray(sb);
LLSDxmlEncode.AddMap(sb);
LLSDxmlEncode.AddElem("messageID", UUID.Zero, sb);
LLSDxmlEncode.AddElem("regionID", regionID, sb);
LLSDxmlEncode.AddEndMap(sb);
LLSDxmlEncode.AddEndArray(sb);
env = LLSDxmlEncode.End(sb);
}
httpResponse.RawBuffer = Util.UTF8NBGetbytes(env);
httpResponse.StatusCode = (int)HttpStatusCode.OK;
}
private void SetExtEnvironmentSettings(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, UUID agentID, Caps caps)
{
bool success = false;
string message = "Could not process request";
int parcel = -1;
int track = -1;
StringBuilder sb = LLSDxmlEncode.Start();
if (httpRequest.Query.Count > 0)
{
if (httpRequest.Query.ContainsKey("parcelid"))
{
Int32.TryParse((string)httpRequest.Query["parcelid"], out parcel);
}
if (httpRequest.Query.ContainsKey("trackno"))
{
Int32.TryParse((string)httpRequest.Query["trackno"], out track);
}
message = "Parcel Enviroment not supported";
goto skiped;
}
if(parcel == -1)
{
if (!m_scene.Permissions.CanIssueEstateCommand(agentID, false))
{
message = "Insufficient estate permissions, settings has not been saved.";
goto skiped;
}
}
if(track == -1)
{
try
{
OSD req = OSDParser.DeserializeLLSDXml(httpRequest.InputStream);
if(req is OpenMetaverse.StructuredData.OSDMap)
{
OpenMetaverse.StructuredData.OSDMap map = req as OpenMetaverse.StructuredData.OSDMap;
if(map.TryGetValue("environment", out OSD env))
{
ViewerEnviroment VEnv = m_scene.RegionEnviroment;
if (VEnv == null)
VEnv = new ViewerEnviroment();
OSDMap evmap = (OSDMap)env;
if(evmap.TryGetValue("day_asset", out OSD tmp) && !evmap.ContainsKey("day_cycle"))
{
string id = tmp.AsString();
AssetBase asset = m_assetService.Get(id);
if(asset == null || asset.Data == null || asset.Data.Length == 0)
{
httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
return;
}
try
{
OSD oenv = OSDParser.DeserializeLLSDXml(asset.Data);
VEnv.CycleFromOSD(oenv);
}
catch (Exception e)
{
httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
return;
}
}
VEnv.FromOSD(env);
StoreOnRegion(VEnv);
WindlightRefresh(0);
success = true;
m_log.InfoFormat("[{0}]: ExtEnviromet settings saved from agentID {1} in region {2}",
Name, agentID, caps.RegionName);
}
}
else if (req is OSDArray)
{
ViewerEnviroment VEnv = m_scene.RegionEnviroment;
if (VEnv == null)
VEnv = new ViewerEnviroment();
VEnv.FromWLOSD(req);
StoreOnRegion(VEnv);
success = true;
WindlightRefresh(0);
m_log.InfoFormat("[{0}]: New Environment settings has been saved from agentID {1} in region {2}",
Name, agentID, caps.RegionName);
LLSDxmlEncode.AddMap(sb);
LLSDxmlEncode.AddElem("messageID", UUID.Zero, sb);
LLSDxmlEncode.AddElem("regionID", regionID, sb);
LLSDxmlEncode.AddElem("success", success, sb);
LLSDxmlEncode.AddEndMap(sb);
httpResponse.RawBuffer = Util.UTF8.GetBytes(LLSDxmlEncode.End(sb));
httpResponse.StatusCode = (int)HttpStatusCode.OK;
return;
}
}
catch (Exception e)
{
m_log.ErrorFormat("[{0}]: ExtEnvironment settings not saved for region {1}, Exception: {2} - {3}",
Name, caps.RegionName, e.Message, e.StackTrace);
success = false;
message = String.Format("ExtEnvironment Set for region {0} has failed, settings not saved.", caps.RegionName);
}
}
skiped:
string response;
LLSDxmlEncode.AddMap(sb);
LLSDxmlEncode.AddElem("success", success, sb);
if(!success)
LLSDxmlEncode.AddElem("message", message, sb);
LLSDxmlEncode.AddEndMap(sb);
response = LLSDxmlEncode.End(sb);
httpResponse.RawBuffer = Util.UTF8.GetBytes(response);
httpResponse.StatusCode = (int)HttpStatusCode.OK;
}
private void GetEnvironmentSettings(IOSHttpResponse response, UUID agentID)
{
// m_log.DebugFormat("[{0}]: Environment GET handle for agentID {1} in region {2}",
// Name, agentID, caps.RegionName);
string env = String.Empty;
ViewerEnviroment VEnv = m_scene.RegionEnviroment;
if (VEnv == null)
VEnv = m_DefaultEnv;
try
if (VEnv != null)
{
env = m_scene.SimulationDataService.LoadRegionEnvironmentSettings(regionID);
}
catch (Exception e)
{
m_log.ErrorFormat("[{0}]: Unable to load environment settings for region {1}, Exception: {2} - {3}",
Name, caps.RegionName, e.Message, e.StackTrace);
OSD d = VEnv.ToWLOSD(UUID.Zero, regionID);
env = OSDParser.SerializeLLSDXmlString(d);
}
if (String.IsNullOrEmpty(env))
@@ -185,15 +549,39 @@ namespace OpenSim.Region.CoreModules.World.LightShare
env = LLSDxmlEncode.End(sb);
}
return env;
response.RawBuffer = Util.UTF8.GetBytes(env);
response.StatusCode = (int)HttpStatusCode.OK;
}
private string SetEnvironmentSettings(string request, string path, string param,
UUID agentID, Caps caps)
private void StoreOnRegion(ViewerEnviroment VEnv)
{
try
{
if (VEnv == null)
{
m_scene.SimulationDataService.RemoveRegionEnvironmentSettings(regionID);
m_scene.RegionEnviroment = null;
m_regionEnvVersion = -1;
}
else
{
m_regionEnvVersion++;
VEnv.version = m_regionEnvVersion;
OSD env = VEnv.ToOSD();
m_scene.SimulationDataService.StoreRegionEnvironmentSettings(regionID, OSDParser.SerializeLLSDXmlString(env));
m_scene.RegionEnviroment = VEnv;
}
}
catch (Exception e)
{
m_log.ErrorFormat("[Enviroment {0}] failed to store enviroment {1}", m_scene.Name, e.Message);
}
}
// m_log.DebugFormat("[{0}]: Environment SET handle from agentID {1} in region {2}",
// Name, agentID, caps.RegionName);
private void SetEnvironmentSettings(IOSHttpRequest request, IOSHttpResponse response, UUID agentID)
{
// m_log.DebugFormat("[{0}]: Environment SET handle from agentID {1} in region {2}",
// Name, agentID, caps.RegionName);
bool success = false;
string fail_reason = "";
@@ -206,19 +594,24 @@ namespace OpenSim.Region.CoreModules.World.LightShare
{
try
{
m_scene.SimulationDataService.StoreRegionEnvironmentSettings(regionID, request);
ViewerEnviroment VEnv = new ViewerEnviroment();
OSD env = OSDParser.DeserializeLLSDXml(request.InputStream);
VEnv.FromWLOSD(env);
StoreOnRegion(VEnv);
success = true;
WindlightRefresh(0);
m_log.InfoFormat("[{0}]: New Environment settings has been saved from agentID {1} in region {2}",
Name, agentID, caps.RegionName);
Name, agentID, m_scene.Name);
}
catch (Exception e)
{
m_log.ErrorFormat("[{0}]: Environment settings has not been saved for region {1}, Exception: {2} - {3}",
Name, caps.RegionName, e.Message, e.StackTrace);
Name, m_scene.Name, e.Message, e.StackTrace);
success = false;
fail_reason = String.Format("Environment Set for region {0} has failed, settings not saved.", caps.RegionName);
fail_reason = String.Format("Environment Set for region {0} has failed, settings not saved.", m_scene.Name);
}
}
@@ -230,7 +623,111 @@ namespace OpenSim.Region.CoreModules.World.LightShare
if(!success)
LLSDxmlEncode.AddElem("fail_reason", fail_reason, sb);
LLSDxmlEncode.AddEndMap(sb);
return LLSDxmlEncode.End(sb);
response.RawBuffer = Util.UTF8.GetBytes(LLSDxmlEncode.End(sb));
response.StatusCode = (int)HttpStatusCode.OK;
}
public byte[] GetDefaultAssetData(int type)
{
OSD osddata;
switch(type)
{
case 0:
SkyData sky = new SkyData();
sky.Name = "DefaultSky";
osddata = sky.ToOSD();
break;
case 1:
WaterData water = new WaterData();
water.Name = "DefaultWater";
osddata = water.ToOSD();
break;
case 2:
DayCycle day = new DayCycle();
day.Name="New Daycycle";
DayCycle.TrackEntry te = new DayCycle.TrackEntry();
WaterData dwater = new WaterData();
dwater.Name = "DefaultWater";
day.waterframes["DefaultWater"] = dwater;
te.time = 0;
te.frameName = "DefaultWater";
day.waterTrack.Add(te);
SkyData dsky = new SkyData();
dsky.Name = "DefaultSky";
day.skyframes["DefaultSky"] = dsky;
te.time = 0;
te.frameName = "DefaultSky";
day.skyTrack0.Add(te);
osddata = day.ToOSD();
break;
default:
return null;
}
string sdata = OSDParser.SerializeLLSDXmlString(osddata);
return Util.UTF8NBGetbytes(sdata);
}
public List<byte[]> MakeLightShareData()
{
if(m_scene.RegionEnviroment == null)
return null;
RegionLightShareData wl = ToLightShare();
byte[] mBlock = new Byte[249];
int pos = 0;
wl.waterColor.ToBytes(mBlock, 0); pos += 12;
Utils.FloatToBytes(wl.waterFogDensityExponent).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.underwaterFogModifier).CopyTo(mBlock, pos); pos += 4;
wl.reflectionWaveletScale.ToBytes(mBlock, pos); pos += 12;
Utils.FloatToBytes(wl.fresnelScale).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.fresnelOffset).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.refractScaleAbove).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.refractScaleBelow).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.blurMultiplier).CopyTo(mBlock, pos); pos += 4;
wl.bigWaveDirection.ToBytes(mBlock, pos); pos += 8;
wl.littleWaveDirection.ToBytes(mBlock, pos); pos += 8;
wl.normalMapTexture.ToBytes(mBlock, pos); pos += 16;
wl.horizon.ToBytes(mBlock, pos); pos += 16;
Utils.FloatToBytes(wl.hazeHorizon).CopyTo(mBlock, pos); pos += 4;
wl.blueDensity.ToBytes(mBlock, pos); pos += 16;
Utils.FloatToBytes(wl.hazeDensity).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.densityMultiplier).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.distanceMultiplier).CopyTo(mBlock, pos); pos += 4;
wl.sunMoonColor.ToBytes(mBlock, pos); pos += 16;
Utils.FloatToBytes(wl.sunMoonPosition).CopyTo(mBlock, pos); pos += 4;
wl.ambient.ToBytes(mBlock, pos); pos += 16;
Utils.FloatToBytes(wl.eastAngle).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.sunGlowFocus).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.sunGlowSize).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.sceneGamma).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.starBrightness).CopyTo(mBlock, pos); pos += 4;
wl.cloudColor.ToBytes(mBlock, pos); pos += 16;
wl.cloudXYDensity.ToBytes(mBlock, pos); pos += 12;
Utils.FloatToBytes(wl.cloudCoverage).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.cloudScale).CopyTo(mBlock, pos); pos += 4;
wl.cloudDetailXYDensity.ToBytes(mBlock, pos); pos += 12;
Utils.FloatToBytes(wl.cloudScrollX).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.cloudScrollY).CopyTo(mBlock, pos); pos += 4;
Utils.UInt16ToBytes(wl.maxAltitude).CopyTo(mBlock, pos); pos += 2;
mBlock[pos] = Convert.ToByte(wl.cloudScrollXLock); pos++;
mBlock[pos] = Convert.ToByte(wl.cloudScrollYLock); pos++;
mBlock[pos] = Convert.ToByte(wl.drawClassicClouds); pos++;
List<byte[]> param = new List<byte[]>();
param.Add(mBlock);
return param;
}
public void SendLightShare(IClientAPI client, List<byte[]> param)
{
if(param == null || param.Count == 0)
client.SendGenericMessage("WindlightReset", UUID.Random(), new List<byte[]>());
else
client.SendGenericMessage("Windlight", UUID.Random(), param);
}
}
}

View File

@@ -1,301 +0,0 @@
/*
* 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 OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Region.CoreModules.Framework.InterfaceCommander;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using log4net;
using Nini.Config;
using Mono.Addins;
namespace OpenSim.Region.CoreModules.World.LightShare
{
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LightShareModule")]
public class LightShareModule : INonSharedRegionModule, ILightShareModule, ICommandableModule
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private readonly Commander m_commander = new Commander("windlight");
private Scene m_scene;
private static bool m_enableWindlight;
#region ICommandableModule Members
public ICommander CommandInterface
{
get { return m_commander; }
}
#endregion
#region INonSharedRegionModule Members
public void Initialise(IConfigSource config)
{
try
{
m_enableWindlight = config.Configs["LightShare"].GetBoolean("enable_windlight", false);
}
catch (Exception)
{
m_log.Debug("[WINDLIGHT]: ini failure for enable_windlight - using default");
}
m_log.DebugFormat("[WINDLIGHT]: windlight module {0}", (m_enableWindlight ? "enabled" : "disabled"));
}
public void AddRegion(Scene scene)
{
if (!m_enableWindlight)
return;
m_scene = scene;
m_scene.RegisterModuleInterface<ILightShareModule>(this);
m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
m_scene.EventManager.OnMakeRootAgent += EventManager_OnMakeRootAgent;
m_scene.EventManager.OnSaveNewWindlightProfile += EventManager_OnSaveNewWindlightProfile;
m_scene.EventManager.OnSendNewWindlightProfileTargeted += EventManager_OnSendNewWindlightProfileTargeted;
m_scene.LoadWindlightProfile();
InstallCommands();
}
public void RemoveRegion(Scene scene)
{
if (!m_enableWindlight)
return;
m_scene.EventManager.OnPluginConsole -= EventManager_OnPluginConsole;
m_scene.EventManager.OnMakeRootAgent -= EventManager_OnMakeRootAgent;
m_scene.EventManager.OnSaveNewWindlightProfile -= EventManager_OnSaveNewWindlightProfile;
m_scene.EventManager.OnSendNewWindlightProfileTargeted -= EventManager_OnSendNewWindlightProfileTargeted;
m_scene = null;
}
public void Close()
{
}
public string Name
{
get { return "LightShareModule"; }
}
public void RegionLoaded(Scene scene)
{
}
public Type ReplaceableInterface
{
get { return null; }
}
#endregion
public static bool EnableWindlight
{
get
{
return m_enableWindlight;
}
set
{
}
}
#region events
private List<byte[]> compileWindlightSettings(RegionLightShareData wl)
{
byte[] mBlock = new Byte[249];
int pos = 0;
wl.waterColor.ToBytes(mBlock, 0); pos += 12;
Utils.FloatToBytes(wl.waterFogDensityExponent).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.underwaterFogModifier).CopyTo(mBlock, pos); pos += 4;
wl.reflectionWaveletScale.ToBytes(mBlock, pos); pos += 12;
Utils.FloatToBytes(wl.fresnelScale).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.fresnelOffset).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.refractScaleAbove).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.refractScaleBelow).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.blurMultiplier).CopyTo(mBlock, pos); pos += 4;
wl.bigWaveDirection.ToBytes(mBlock, pos); pos += 8;
wl.littleWaveDirection.ToBytes(mBlock, pos); pos += 8;
wl.normalMapTexture.ToBytes(mBlock, pos); pos += 16;
wl.horizon.ToBytes(mBlock, pos); pos += 16;
Utils.FloatToBytes(wl.hazeHorizon).CopyTo(mBlock, pos); pos += 4;
wl.blueDensity.ToBytes(mBlock, pos); pos += 16;
Utils.FloatToBytes(wl.hazeDensity).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.densityMultiplier).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.distanceMultiplier).CopyTo(mBlock, pos); pos += 4;
wl.sunMoonColor.ToBytes(mBlock, pos); pos += 16;
Utils.FloatToBytes(wl.sunMoonPosition).CopyTo(mBlock, pos); pos += 4;
wl.ambient.ToBytes(mBlock, pos); pos += 16;
Utils.FloatToBytes(wl.eastAngle).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.sunGlowFocus).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.sunGlowSize).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.sceneGamma).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.starBrightness).CopyTo(mBlock, pos); pos += 4;
wl.cloudColor.ToBytes(mBlock, pos); pos += 16;
wl.cloudXYDensity.ToBytes(mBlock, pos); pos += 12;
Utils.FloatToBytes(wl.cloudCoverage).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.cloudScale).CopyTo(mBlock, pos); pos += 4;
wl.cloudDetailXYDensity.ToBytes(mBlock, pos); pos += 12;
Utils.FloatToBytes(wl.cloudScrollX).CopyTo(mBlock, pos); pos += 4;
Utils.FloatToBytes(wl.cloudScrollY).CopyTo(mBlock, pos); pos += 4;
Utils.UInt16ToBytes(wl.maxAltitude).CopyTo(mBlock, pos); pos += 2;
mBlock[pos] = Convert.ToByte(wl.cloudScrollXLock); pos++;
mBlock[pos] = Convert.ToByte(wl.cloudScrollYLock); pos++;
mBlock[pos] = Convert.ToByte(wl.drawClassicClouds); pos++;
List<byte[]> param = new List<byte[]>();
param.Add(mBlock);
return param;
}
public void SendProfileToClient(IClientAPI client)
{
SendProfileToClient(client, m_scene.RegionInfo.WindlightSettings);
}
public void SendProfileToClient(IClientAPI client, RegionLightShareData wl)
{
if (client == null)
return;
if (m_enableWindlight)
{
if (m_scene.RegionInfo.WindlightSettings.valid)
{
List<byte[]> param = compileWindlightSettings(wl);
client.SendGenericMessage("Windlight", UUID.Random(), param);
}
else
{
List<byte[]> param = new List<byte[]>();
client.SendGenericMessage("WindlightReset", UUID.Random(), param);
}
}
}
private void EventManager_OnMakeRootAgent(ScenePresence presence)
{
if (m_enableWindlight && m_scene.RegionInfo.WindlightSettings.valid)
m_log.Debug("[WINDLIGHT]: Sending windlight scene to new client");
SendProfileToClient(presence.ControllingClient);
}
private void EventManager_OnSendNewWindlightProfileTargeted(RegionLightShareData wl, UUID pUUID)
{
IClientAPI client;
m_scene.TryGetClient(pUUID, out client);
SendProfileToClient(client, wl);
}
private void EventManager_OnSaveNewWindlightProfile()
{
m_scene.ForEachRootClient(SendProfileToClient);
}
#endregion
#region ICommandableModule Members
private void InstallCommands()
{
Command wlload = new Command("load", CommandIntentions.COMMAND_NON_HAZARDOUS, HandleLoad, "Load windlight profile from the database and broadcast");
Command wlenable = new Command("enable", CommandIntentions.COMMAND_NON_HAZARDOUS, HandleEnable, "Enable the windlight plugin");
Command wldisable = new Command("disable", CommandIntentions.COMMAND_NON_HAZARDOUS, HandleDisable, "Disable the windlight plugin");
m_commander.RegisterCommand("load", wlload);
m_commander.RegisterCommand("enable", wlenable);
m_commander.RegisterCommand("disable", wldisable);
m_scene.RegisterModuleCommander(m_commander);
}
private void HandleLoad(Object[] args)
{
if (!m_enableWindlight)
{
m_log.InfoFormat("[WINDLIGHT]: Cannot load windlight profile, module disabled. Use 'windlight enable' first.");
}
else
{
m_log.InfoFormat("[WINDLIGHT]: Loading Windlight profile from database");
m_scene.LoadWindlightProfile();
m_log.InfoFormat("[WINDLIGHT]: Load complete");
}
}
private void HandleDisable(Object[] args)
{
m_log.InfoFormat("[WINDLIGHT]: Plugin now disabled");
m_enableWindlight = false;
}
private void HandleEnable(Object[] args)
{
m_log.InfoFormat("[WINDLIGHT]: Plugin now enabled");
m_enableWindlight = true;
}
/// <summary>
/// Processes commandline input. Do not call directly.
/// </summary>
/// <param name="args">Commandline arguments</param>
private void EventManager_OnPluginConsole(string[] args)
{
if (args[0] == "windlight")
{
if (args.Length == 1)
{
m_commander.ProcessConsoleCommand("add", new string[0]);
return;
}
string[] tmpArgs = new string[args.Length - 2];
int i;
for (i = 2; i < args.Length; i++)
{
tmpArgs[i - 2] = args[i];
}
m_commander.ProcessConsoleCommand(args[1], tmpArgs);
}
}
#endregion
}
}

View File

@@ -33,8 +33,8 @@ namespace OpenSim.Region.Framework.Interfaces
public interface IEnvironmentModule
{
void ResetEnvironmentSettings(UUID regionUUID);
//void FromLightShare(RegionLightShareData wl);
//RegionLightShareData ToLightShare();
//byte[] GetDefaultAssetData(string name);
void FromLightShare(RegionLightShareData wl);
RegionLightShareData ToLightShare();
byte[] GetDefaultAssetData(int type);
}
}

View File

@@ -109,9 +109,6 @@ namespace OpenSim.Region.Framework.Interfaces
void StoreRegionSettings(RegionSettings rs);
RegionSettings LoadRegionSettings(UUID regionUUID);
RegionLightShareData LoadRegionWindlightSettings(UUID regionUUID);
void StoreRegionWindlightSettings(RegionLightShareData wl);
void RemoveRegionWindlightSettings(UUID regionID);
/// <summary>
/// Load Environment settings from region storage

View File

@@ -121,9 +121,7 @@ namespace OpenSim.Region.Framework.Interfaces
void StoreRegionSettings(RegionSettings rs);
RegionSettings LoadRegionSettings(UUID regionUUID);
RegionLightShareData LoadRegionWindlightSettings(UUID regionUUID);
void StoreRegionWindlightSettings(RegionLightShareData wl);
void RemoveRegionWindlightSettings(UUID regionID);
UUID[] GetObjectIDs(UUID regionID);
/// <summary>

View File

@@ -720,9 +720,6 @@ namespace OpenSim.Region.Framework.Scenes
/// </remarks>
public event OnMakeChildAgentDelegate OnMakeChildAgent;
public delegate void OnSaveNewWindlightProfileDelegate();
public delegate void OnSendNewWindlightProfileTargetedDelegate(RegionLightShareData wl, UUID user);
/// <summary>
/// Triggered after the grunt work for adding a root agent to a
/// scene has been performed (resuming attachment scripts, physics,
@@ -739,9 +736,6 @@ namespace OpenSim.Region.Framework.Scenes
/// </remarks>
public event Action<ScenePresence> OnMakeRootAgent;
public event OnSendNewWindlightProfileTargetedDelegate OnSendNewWindlightProfileTargeted;
public event OnSaveNewWindlightProfileDelegate OnSaveNewWindlightProfile;
/// <summary>
/// Triggered when an object or attachment enters a scene
/// </summary>
@@ -2160,24 +2154,6 @@ namespace OpenSim.Region.Framework.Scenes
}
}
public void TriggerOnSendNewWindlightProfileTargeted(RegionLightShareData wl, UUID user)
{
OnSendNewWindlightProfileTargetedDelegate handlerSendNewWindlightProfileTargeted = OnSendNewWindlightProfileTargeted;
if (handlerSendNewWindlightProfileTargeted != null)
{
handlerSendNewWindlightProfileTargeted(wl, user);
}
}
public void TriggerOnSaveNewWindlightProfile()
{
OnSaveNewWindlightProfileDelegate handlerSaveNewWindlightProfile = OnSaveNewWindlightProfile;
if (handlerSaveNewWindlightProfile != null)
{
handlerSaveNewWindlightProfile();
}
}
public void TriggerOnMakeRootAgent(ScenePresence presence)
{
Action<ScenePresence> handlerMakeRootAgent = OnMakeRootAgent;

View File

@@ -2123,17 +2123,17 @@ namespace OpenSim.Region.Framework.Scenes
SimulationDataService.StoreBakedTerrain(Bakedmap.GetTerrainData(), RegionInfo.RegionID);
}
public void StoreWindlightProfile(RegionLightShareData wl)
private ViewerEnviroment m_regionEnviroment;
public ViewerEnviroment RegionEnviroment
{
RegionInfo.WindlightSettings = wl;
SimulationDataService.StoreRegionWindlightSettings(wl);
m_eventManager.TriggerOnSaveNewWindlightProfile();
}
public void LoadWindlightProfile()
{
RegionInfo.WindlightSettings = SimulationDataService.LoadRegionWindlightSettings(RegionInfo.RegionID);
m_eventManager.TriggerOnSaveNewWindlightProfile();
get
{
return m_regionEnviroment;
}
set
{
m_regionEnviroment = value;
}
}
/// <summary>

View File

@@ -62,9 +62,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
internal bool m_LSFunctionsEnabled = false;
internal IScriptModuleComms m_comms = null;
internal IConfig m_osslconfig;
internal IEnvironmentModule m_enviroment = null;
public void Initialize(
IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item)
public void Initialize(IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item)
{
m_ScriptEngine = scriptEngine;
m_host = host;
@@ -79,6 +79,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
m_comms = m_ScriptEngine.World.RequestModuleInterface<IScriptModuleComms>();
if (m_comms == null)
m_LSFunctionsEnabled = false;
m_enviroment = m_ScriptEngine.World.RequestModuleInterface<IEnvironmentModule>();
}
public override Object InitializeLifetimeService()
@@ -88,8 +90,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
if (lease.CurrentState == LeaseState.Initial)
{
lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
// lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
// lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
//lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
//lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
}
return lease;
}
@@ -120,13 +122,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
/// <returns>List of windlight parameters</returns>
public LSL_List lsGetWindlightScene(LSL_List rules)
{
if (!m_LSFunctionsEnabled)
if (!m_LSFunctionsEnabled || m_enviroment == null)
{
LSShoutError("LightShare functions are not enabled.");
return new LSL_List();
}
m_host.AddScriptLPS(1);
RegionLightShareData wl = m_host.ParentGroup.Scene.RegionInfo.WindlightSettings;
RegionLightShareData wl = m_enviroment.ToLightShare();
LSL_List values = new LSL_List();
int idx = 0;
@@ -264,9 +268,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
private RegionLightShareData getWindlightProfileFromRules(LSL_List rules)
{
RegionLightShareData wl = (RegionLightShareData)m_host.ParentGroup.Scene.RegionInfo.WindlightSettings.Clone();
RegionLightShareData wl = m_enviroment.ToLightShare();
// LSL_List values = new LSL_List();
int idx = 0;
while (idx < rules.Length)
{
@@ -716,12 +719,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
/// <returns>success: true or false</returns>
public int lsSetWindlightScene(LSL_List rules)
{
if (!m_LSFunctionsEnabled)
if (!m_LSFunctionsEnabled || m_enviroment == null)
{
LSShoutError("LightShare functions are not enabled.");
return 0;
}
m_host.AddScriptLPS(1);
if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID))
{
ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
@@ -733,42 +738,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
}
int success = 0;
m_host.AddScriptLPS(1);
if (LightShareModule.EnableWindlight)
try
{
RegionLightShareData wl;
try
{
wl = getWindlightProfileFromRules(rules);
}
catch(InvalidCastException e)
{
LSShoutError(e.Message);
return 0;
}
wl.valid = true;
m_host.ParentGroup.Scene.StoreWindlightProfile(wl);
success = 1;
RegionLightShareData wl = getWindlightProfileFromRules(rules);
m_enviroment.FromLightShare(wl);
}
else
catch(InvalidCastException e)
{
LSShoutError("Windlight module is disabled");
LSShoutError(e.Message);
return 0;
}
return success;
return 1;
}
public void lsClearWindlightScene()
{
if (!m_LSFunctionsEnabled)
if (!m_LSFunctionsEnabled || m_enviroment == null)
{
LSShoutError("LightShare functions are not enabled.");
return;
}
m_host.AddScriptLPS(1);
if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID))
{
ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
@@ -780,11 +773,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
}
m_host.ParentGroup.Scene.RegionInfo.WindlightSettings.valid = false;
if (m_host.ParentGroup.Scene.SimulationDataService != null)
m_host.ParentGroup.Scene.SimulationDataService.RemoveRegionWindlightSettings(m_host.ParentGroup.Scene.RegionInfo.RegionID);
m_host.ParentGroup.Scene.EventManager.TriggerOnSaveNewWindlightProfile();
m_enviroment.ResetEnvironmentSettings(m_host.ParentGroup.Scene.RegionInfo.RegionID);
}
/// <summary>
@@ -794,6 +783,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
/// <returns>success: true or false</returns>
public int lsSetWindlightSceneTargeted(LSL_List rules, LSL_Key target)
{
LSShoutError("Function temporary not supported");
return 0;
/* disabled code until we add force a WL into a single user
if (!m_LSFunctionsEnabled)
{
LSShoutError("LightShare functions are not enabled.");
@@ -814,7 +807,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
int success = 0;
m_host.AddScriptLPS(1);
if (LightShareModule.EnableWindlight)
if (m_enviroment != null)
{
RegionLightShareData wl;
try
@@ -836,6 +829,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
return success;
*/
}
}
}