Thank you kindly Diva & KMeisthax for adding the beginnings

of search capability to OpenSim in the form of a configurable
module.
0.6.0-stable
Charles Krinke 2008-04-07 13:50:05 +00:00
parent 072b5faa34
commit 927003de33
8 changed files with 1111 additions and 1 deletions

View File

@ -0,0 +1,75 @@
/*
* 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 OpenSim 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.Collections;
using System.Text;
using System.Xml;
using OpenSim.Region.Environment.Scenes;
using OpenSim.Framework.Servers;
using OpenSim.Framework.Console;
namespace OpenSim.Region.DataSnapshot
{
public class DataRequestHandler
{
private Scene m_scene = null;
private DataSnapshotManager m_externalData = null;
private log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public DataRequestHandler(Scene scene, DataSnapshotManager externalData)
{
m_scene = scene;
m_externalData = externalData;
if (m_scene.AddHTTPHandler("collector", OnGetSnapshot))
{
m_log.Info("[DATASNAPSHOT]: Set up snapshot service");
}
//harbl
}
public Hashtable OnGetSnapshot(Hashtable keysvals)
{
m_log.Info("[DATASNAPSHOT] Received collection request");
Hashtable reply = new Hashtable();
int statuscode = 200;
string snapObj = (string)keysvals["region"];
XmlDocument response = m_externalData.GetSnapshot(snapObj);
reply["str_response_string"] = response.OuterXml;
reply["int_response_code"] = statuscode;
reply["content_type"] = "text/xml";
return reply;
}
}
}

View File

@ -0,0 +1,524 @@
/*
* 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 OpenSim 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 System.Xml;
using System.IO;
using System.Text;
using System.Timers;
using OpenSim.Framework;
using OpenSim.Framework.Communications;
using OpenSim.Region.Environment.Interfaces;
using OpenSim.Region.Environment.Scenes;
using Nini.Config;
using libsecondlife;
using libsecondlife.Packets;
namespace OpenSim.Region.DataSnapshot
{
public class DataSnapshotManager : IRegionModule
{
#region Class members
private List<Scene> m_scenes = new List<Scene>();
private log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private bool m_enabled = false;
private bool m_configLoaded = false;
internal object m_syncInit = new object();
private DataRequestHandler m_requests = null;
private Dictionary<Scene, List<IDataSnapshotProvider>> m_dataproviders = new Dictionary<Scene, List<IDataSnapshotProvider>>();
private Dictionary<String, String> m_gridinfo = new Dictionary<String, String>();
//private int m_oldestSnapshot = 0;
private int m_maxSnapshots = 500;
private int m_lastSnapshot = 0;
private string m_snapsDir = "DataSnapshot";
private string m_dataServices = "noservices";
private string m_listener_port = "9000"; //TODO: Set default port over 9000
private string m_hostname = "127.0.0.1";
private Timer m_periodic = null;
private int m_period = 60; // in seconds
private List<String> m_disabledModules = new List<String>();
#endregion
#region IRegionModule
public void Close()
{
}
public void Initialise(Scene scene, Nini.Config.IConfigSource config)
{
if (!m_scenes.Contains(scene))
m_scenes.Add(scene);
if (!m_configLoaded) {
m_configLoaded = true;
m_log.Info("[DATASNAPSHOT]: Loading configuration");
//Read from the config for options
lock (m_syncInit) {
try {
m_enabled = config.Configs["DataSnapshot"].GetBoolean("index_sims", m_enabled);
if (config.Configs["Startup"].GetBoolean("gridmode", true))
{
m_gridinfo.Add("gridserverURL", config.Configs["Network"].GetString("grid_server_url", "harbl"));
m_gridinfo.Add("userserverURL", config.Configs["Network"].GetString("user_server_url", "harbl"));
m_gridinfo.Add("assetserverURL", config.Configs["Network"].GetString("asset_server_url", "harbl"));
}
else
{
//Non gridmode stuff
}
m_gridinfo.Add("Name", config.Configs["DataSnapshot"].GetString("gridname", "harbl"));
m_maxSnapshots = config.Configs["DataSnapshot"].GetInt("max_snapshots", m_maxSnapshots);
m_period = config.Configs["DataSnapshot"].GetInt("default_snapshot_period", m_period);
m_snapsDir = config.Configs["DataSnapshot"].GetString("snapshot_cache_directory", m_snapsDir);
m_dataServices = config.Configs["DataSnapshot"].GetString("data_services", m_dataServices);
m_listener_port = config.Configs["Network"].GetString("http_listener_port", m_listener_port);
//BUG: Naming a search data module "DESUDESUDESU" will cause it to not get loaded by default.
//RESOLUTION: Wontfix, there are no Suiseiseki-loving developers
String[] annoying_string_array = config.Configs["DataSnapshot"].GetString("disable_modules", "DESUDESUDESU").Split(".".ToCharArray());
foreach (String bloody_wanker in annoying_string_array) {
m_disabledModules.Add(bloody_wanker);
}
} catch (Exception) {
m_log.Info("[DATASNAPSHOT]: Could not load configuration. DataSnapshot will be disabled.");
m_enabled = false;
return;
}
}
}
if (Directory.Exists(m_snapsDir))
{
m_log.Info("[DATASNAPSHOT] DataSnapshot directory already exists.");
}
else
{
// Try to create the directory.
m_log.Info("[DATASNAPSHOT] Creating " + m_snapsDir + " directory.");
try
{
Directory.CreateDirectory(m_snapsDir);
}
catch (Exception)
{
m_log.Error("[DATASNAPSHOT] Failed to create " + m_snapsDir + " directory.");
}
}
if (m_enabled)
{
m_log.Info("[DATASNAPSHOT]: Scene added to module.");
}
else
{
m_log.Warn("[DATASNAPSHOT]: Data snapshot disabled, not adding scene to module (or anything else).");
}
}
public bool IsSharedModule
{
get { return true; }
}
public string Name
{
get { return "External Data Generator"; }
}
public void PostInitialise()
{
if (m_enabled)
{
//Right now, only load ISearchData objects in the current assembly.
//Eventually allow it to load ISearchData objects from all assemblies.
Assembly currentasm = Assembly.GetExecutingAssembly();
//Stolen from ModuleLoader.cs
foreach (Type pluginType in currentasm.GetTypes())
{
if (pluginType.IsPublic)
{
if (!pluginType.IsAbstract)
{
if (pluginType.GetInterface("IDataSnapshotProvider") != null)
{
foreach (Scene scene in m_scenes)
{
IDataSnapshotProvider module = (IDataSnapshotProvider)Activator.CreateInstance(pluginType);
module.Initialize(scene, this);
//module.PrepareData();
List<IDataSnapshotProvider> providerlist = null;
m_dataproviders.TryGetValue(scene, out providerlist);
if (providerlist == null)
{
providerlist = new List<IDataSnapshotProvider>();
m_dataproviders.Add(scene, providerlist);
}
providerlist.Add(module);
}
m_log.Info("[DATASNAPSHOT]: Added new data provider type: " + pluginType.Name);
}
}
}
}
//Hand it the first scene, assuming that all scenes have the same BaseHTTPServer
m_requests = new DataRequestHandler(m_scenes[0], this);
//Create timer
m_periodic = new Timer();
m_periodic.Interval = m_period * 1000;
m_periodic.Elapsed += SnapshotTimerCallback;
m_periodic.Enabled = true;
m_hostname = m_scenes[0].RegionInfo.ExternalHostName;
MakeNewSnapshot(); //Make the initial snapshot
if (m_dataServices != "noservices")
NotifyDataServices(m_dataServices);
}
}
#endregion
#region Associated helper functions
string DataFileName(Scene scene)
{
return Path.Combine(m_snapsDir, Path.ChangeExtension(scene.RegionInfo.RegionName, "xml"));
//return (m_snapsDir + Path.DirectorySeparatorChar + scene.RegionInfo.RegionName + ".xml");
}
Scene SceneForName(string name)
{
foreach (Scene scene in m_scenes)
if (scene.RegionInfo.RegionName == name)
return scene;
return null;
}
#endregion
#region [Private] XML snapshot generator
private XmlDocument Snapshot(Scene scene)
{
XmlDocument basedoc = new XmlDocument();
XmlNode regionElement = MakeRegionNode(scene, basedoc);
regionElement.AppendChild(GetGridSnapshotData(basedoc));
XmlNode regionData = basedoc.CreateNode(XmlNodeType.Element, "data", "");
foreach (KeyValuePair<Scene, List<IDataSnapshotProvider>> dataprovider in m_dataproviders)
{
if (dataprovider.Key == scene)
{
foreach (IDataSnapshotProvider provider in dataprovider.Value)
{
XmlNode data = provider.RequestSnapshotData(basedoc);
regionData.AppendChild(data);
}
}
}
regionElement.AppendChild(regionData);
basedoc.AppendChild(regionElement);
return basedoc;
}
private XmlNode MakeRegionNode(Scene scene, XmlDocument basedoc)
{
XmlNode docElement = basedoc.CreateNode(XmlNodeType.Element, "region", "");
XmlAttribute attr = basedoc.CreateAttribute("category");
attr.Value = GetRegionCategory(scene);
docElement.Attributes.Append(attr);
attr = basedoc.CreateAttribute("entities");
attr.Value = scene.Entities.Count.ToString();
docElement.Attributes.Append(attr);
//attr = basedoc.CreateAttribute("parcels");
//attr.Value = scene.LandManager.landList.Count.ToString();
//docElement.Attributes.Append(attr);
XmlNode infoblock = basedoc.CreateNode(XmlNodeType.Element, "info", "");
XmlNode infopiece = basedoc.CreateNode(XmlNodeType.Element, "uuid", "");
infopiece.InnerText = scene.RegionInfo.RegionID.ToString();
infoblock.AppendChild(infopiece);
infopiece = basedoc.CreateNode(XmlNodeType.Element, "url", "");
infopiece.InnerText = "http://" + m_hostname + ":" + m_listener_port;
infoblock.AppendChild(infopiece);
infopiece = basedoc.CreateNode(XmlNodeType.Element, "name", "");
infopiece.InnerText = scene.RegionInfo.RegionName;
infoblock.AppendChild(infopiece);
docElement.AppendChild(infoblock);
return docElement;
}
private XmlNode GetGridSnapshotData(XmlDocument factory)
{
XmlNode griddata = factory.CreateNode(XmlNodeType.Element, "grid", "");
foreach (KeyValuePair<String, String> GridData in m_gridinfo)
{
//TODO: make it lowercase tag names for diva
XmlNode childnode = factory.CreateNode(XmlNodeType.Element, GridData.Key, "");
childnode.InnerText = GridData.Value;
griddata.AppendChild(childnode);
}
return griddata;
}
private String GetRegionCategory(Scene scene)
{
//Boolean choice between:
// "PG" - Mormontown
// "Mature" - Sodom and Gomorrah
// (Depreciated) "Patriotic Nigra Testing Sandbox" - Abandon Hope All Ye Who Enter Here
if ((scene.RegionInfo.EstateSettings.simAccess & Simulator.SimAccess.Mature) == Simulator.SimAccess.Mature)
{
return "Mature";
}
else if ((scene.RegionInfo.EstateSettings.simAccess & Simulator.SimAccess.PG) == Simulator.SimAccess.PG)
{
return "PG";
}
else
{
return "Unknown";
}
}
/* Code's closed due to AIDS, See EstateSnapshot.cs for CURE
private XmlNode GetEstateSnapshotData(Scene scene, XmlDocument factory)
{
//Estate data section - contains who owns a set of sims and the name of the set.
//In Opensim all the estate names are the same as the Master Avatar (owner of the sim)
XmlNode estatedata = factory.CreateNode(XmlNodeType.Element, "estate", "");
LLUUID ownerid = scene.RegionInfo.MasterAvatarAssignedUUID;
String firstname = scene.RegionInfo.MasterAvatarFirstName;
String lastname = scene.RegionInfo.MasterAvatarLastName;
String hostname = scene.RegionInfo.ExternalHostName;
XmlNode user = factory.CreateNode(XmlNodeType.Element, "owner", "");
XmlNode username = factory.CreateNode(XmlNodeType.Element, "name", "");
username.InnerText = firstname + " " + lastname;
user.AppendChild(username);
XmlNode useruuid = factory.CreateNode(XmlNodeType.Element, "uuid", "");
useruuid.InnerText = ownerid.ToString();
user.AppendChild(useruuid);
estatedata.AppendChild(user);
return estatedata;
} */
#endregion
#region [Public] Snapshot storage functions
public void MakeNewSnapshot()
{
foreach (Scene scene in m_scenes)
{
XmlDocument snapshot = Snapshot(scene);
string path = DataFileName(scene);
try
{
using (XmlTextWriter snapXWriter = new XmlTextWriter(path, Encoding.Default))
{
snapXWriter.Formatting = Formatting.Indented;
snapXWriter.WriteStartDocument();
snapshot.WriteTo(snapXWriter);
snapXWriter.WriteEndDocument();
m_lastSnapshot++;
}
}
catch (Exception e)
{
m_log.Warn("[DATASNAPSHOT]: Caught unknown exception while trying to save snapshot: " + path + "\n" + e.ToString());
}
m_log.Info("[DATASNAPSHOT]: Made external data snapshot " + path);
}
}
/**
* Reply to the http request
*/
public XmlDocument GetSnapshot(string regionName)
{
XmlDocument requestedSnap = new XmlDocument();
requestedSnap.AppendChild(requestedSnap.CreateXmlDeclaration("1.0", null, null));
requestedSnap.AppendChild(requestedSnap.CreateWhitespace("\r\n"));
XmlNode regiondata = requestedSnap.CreateNode(XmlNodeType.Element, "regiondata", "");
try
{
if (regionName == null || regionName == "")
{
foreach (Scene scene in m_scenes)
{
string path = DataFileName(scene);
XmlDocument regionSnap = new XmlDocument();
regionSnap.PreserveWhitespace = true;
regionSnap.Load(path);
XmlNode nodeOrig = regionSnap["region"];
XmlNode nodeDest = requestedSnap.ImportNode(nodeOrig, true);
//requestedSnap.AppendChild(nodeDest);
regiondata.AppendChild(requestedSnap.CreateWhitespace("\r\n"));
regiondata.AppendChild(nodeDest);
}
}
else
{
Scene scene = SceneForName(regionName);
requestedSnap.Load(DataFileName(scene));
}
// requestedSnap.InsertBefore(requestedSnap.CreateXmlDeclaration("1.0", null, null),
// requestedSnap.DocumentElement);
requestedSnap.AppendChild(regiondata);
regiondata.AppendChild(requestedSnap.CreateWhitespace("\r\n"));
}
catch (XmlException e)
{
m_log.Warn("[DATASNAPSHOT]: XmlException while trying to load snapshot: " + e.ToString());
requestedSnap = GetErrorMessage(regionName, e);
}
catch (Exception e)
{
m_log.Warn("[DATASNAPSHOT]: Caught unknown exception while trying to load snapshot: " + e.StackTrace);
requestedSnap = GetErrorMessage(regionName, e);
}
return requestedSnap;
}
private XmlDocument GetErrorMessage(string regionName, Exception e)
{
XmlDocument errorMessage = new XmlDocument();
XmlNode error = errorMessage.CreateNode(XmlNodeType.Element, "error", "");
XmlNode region = errorMessage.CreateNode(XmlNodeType.Element, "region", "");
region.InnerText = regionName;
XmlNode exception = errorMessage.CreateNode(XmlNodeType.Element, "exception", "");
exception.InnerText = e.ToString();
error.AppendChild(region);
error.AppendChild(exception);
errorMessage.AppendChild(error);
return errorMessage;
}
#endregion
#region Event callbacks
private void SnapshotTimerCallback(object timer, ElapsedEventArgs args)
{
MakeNewSnapshot();
//Add extra calls here
}
#endregion
#region External data services
private void NotifyDataServices(string servicesStr)
{
Stream reply = null;
string delimStr = ";";
char [] delimiter = delimStr.ToCharArray();
string[] services = servicesStr.Split(delimiter);
for (int i = 0; i < services.Length; i++)
{
string url = services[i].Trim();
RestClient cli = new RestClient(url);
cli.AddQueryParameter("host", m_hostname);
cli.AddQueryParameter("port", m_listener_port);
cli.RequestMethod = "GET";
try
{
reply = cli.Request();
}
catch (System.Net.WebException)
{
m_log.Warn("[DATASNAPSHOT] Unable to notify " + url);
}
catch (Exception e)
{
m_log.Warn("[DATASNAPSHOT] Ignoring unknown exception " + e.ToString());
}
byte[] response = new byte[1024];
int n = 0;
try
{
n = reply.Read(response, 0, 1024);
}
catch (Exception e)
{
m_log.Warn("[DATASNAPSHOT] Unable to decode reply from data service. Ignoring. " + e.StackTrace);
}
// This is not quite working, so...
string responseStr = System.Text.ASCIIEncoding.UTF8.GetString(response);
m_log.Info("[DATASNAPSHOT] data service notified: " + url);
}
}
#endregion
}
}

View File

@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using OpenSim.Region.Environment.Scenes;
using OpenSim.Region.Environment.Modules.LandManagement;
using OpenSim.Framework;
using OpenSim.Framework.Console;
using OpenSim.Framework.Communications;
using libsecondlife;
using libsecondlife.Packets;
namespace OpenSim.Region.DataSnapshot
{
public class EstateSnapshot : IDataSnapshotProvider
{
private Scene m_scene = null;
private DataSnapshotManager m_parent = null;
#region IDataSnapshotProvider Members
public XmlNode RequestSnapshotData(XmlDocument factory)
{
//Estate data section - contains who owns a set of sims and the name of the set.
//In Opensim all the estate names are the same as the Master Avatar (owner of the sim)
//Now in DataSnapshotProvider module form!
XmlNode estatedata = factory.CreateNode(XmlNodeType.Element, "estate", "");
LLUUID ownerid = m_scene.RegionInfo.MasterAvatarAssignedUUID;
//TODO: Change to query userserver about the master avatar UUID ?
String firstname = m_scene.RegionInfo.MasterAvatarFirstName;
String lastname = m_scene.RegionInfo.MasterAvatarLastName;
//TODO: Fix the marshalling system to have less copypasta gruntwork
XmlNode user = factory.CreateNode(XmlNodeType.Element, "user", "");
XmlAttribute type = (XmlAttribute)factory.CreateNode(XmlNodeType.Attribute, "type", "");
type.Value = "owner";
user.Attributes.Append(type);
//TODO: Create more TODOs
XmlNode username = factory.CreateNode(XmlNodeType.Element, "name", "");
username.InnerText = firstname + " " + lastname;
user.AppendChild(username);
XmlNode useruuid = factory.CreateNode(XmlNodeType.Element, "uuid", "");
useruuid.InnerText = ownerid.ToString();
user.AppendChild(useruuid);
estatedata.AppendChild(user);
return estatedata;
}
public void Initialize(Scene scene, DataSnapshotManager parent)
{
m_scene = scene;
m_parent = parent;
}
public Scene GetParentScene
{
get { return m_scene; }
}
#endregion
}
}

View File

@ -0,0 +1,48 @@
/*
* 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 OpenSim 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.Text;
using System.Xml;
using OpenSim.Region.Environment.Scenes;
using libsecondlife;
namespace OpenSim.Region.DataSnapshot
{
public interface IDataSnapshotProvider
{
XmlNode RequestSnapshotData(XmlDocument document);
//void PrepareData();
void Initialize(Scene scene, DataSnapshotManager parent);
Scene GetParentScene { get; }
}
}

View File

@ -0,0 +1,267 @@
/*
* 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 OpenSim 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.Text;
using System.Xml;
using System.Reflection;
using OpenSim.Region.Environment.Scenes;
using OpenSim.Region.Environment.Modules.LandManagement;
using OpenSim.Region.Environment.Interfaces;
using OpenSim.Framework;
using OpenSim.Framework.Console;
using OpenSim.Framework.Communications;
using libsecondlife;
using libsecondlife.Packets;
namespace OpenSim.Region.DataSnapshot
{
public class LandSnapshot : IDataSnapshotProvider
{
private Scene m_scene = null;
private DataSnapshotManager m_parent = null;
//private Dictionary<int, Land> m_landIndexed = new Dictionary<int, Land>();
private log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#region Dead code
/*
* David, I don't think we need this at all. When we do the snapshot, we can
* simply look into the parcels that are marked for ShowDirectory -- see
* conditional in RequestSnapshotData
*
//Revise this, look for more direct way of checking for change in land
#region Client hooks
public void OnNewClient(IClientAPI client)
{
//Land hooks
client.OnParcelDivideRequest += ParcelSplitHook;
client.OnParcelJoinRequest += ParcelSplitHook;
client.OnParcelPropertiesUpdateRequest += ParcelPropsHook;
}
public void ParcelSplitHook(int west, int south, int east, int north, IClientAPI remote_client)
{
PrepareData();
}
public void ParcelPropsHook(ParcelPropertiesUpdatePacket packet, IClientAPI remote_client)
{
PrepareData();
}
#endregion
public void PrepareData()
{
m_log.Info("[EXTERNALDATA]: Generating land data.");
m_landIndexed.Clear();
//Index sim land
foreach (KeyValuePair<int, Land> curLand in m_scene.LandManager.landList)
{
//if ((curLand.Value.landData.landFlags & (uint)Parcel.ParcelFlags.ShowDirectory) == (uint)Parcel.ParcelFlags.ShowDirectory)
//{
m_landIndexed.Add(curLand.Key, curLand.Value.Copy());
//}
}
}
public Dictionary<int,Land> IndexedLand {
get { return m_landIndexed; }
}
*/
#endregion
#region IDataSnapshotProvider members
public void Initialize(Scene scene, DataSnapshotManager parent)
{
m_scene = scene;
m_parent = parent;
//m_scene.EventManager.OnNewClient += OnNewClient;
}
public Scene GetParentScene
{
get { return m_scene; }
}
public XmlNode RequestSnapshotData(XmlDocument nodeFactory)
{
ILandChannel landChannel = (LandChannel)m_scene.LandChannel;
Dictionary<int, ILandObject> landList = null;
try
{
Type landChannelType = typeof(LandChannel);
FieldInfo landListField = landChannelType.GetField("landList", BindingFlags.NonPublic | BindingFlags.Instance);
if (landListField != null)
{
landList = (Dictionary<int, ILandObject>)landListField.GetValue(landChannel);
}
}
catch (Exception e)
{
Console.WriteLine("[DATASNAPSHOT] couldn't access field reflectively\n" + e.ToString());
}
XmlNode parent = nodeFactory.CreateNode(XmlNodeType.Element, "parceldata", "");
if (landList != null)
{
//foreach (KeyValuePair<int, Land> curParcel in m_landIndexed)
foreach (LandObject land in landList.Values)
{
LandData parcel = land.landData;
if ((parcel.landFlags & (uint)Parcel.ParcelFlags.ShowDirectory) == (uint)Parcel.ParcelFlags.ShowDirectory)
{
//TODO: make better method of marshalling data from LandData to XmlNode
XmlNode xmlparcel = nodeFactory.CreateNode(XmlNodeType.Element, "parcel", "");
// Attributes of the parcel node
XmlAttribute scripts_attr = nodeFactory.CreateAttribute("scripts");
scripts_attr.Value = GetScriptsPermissions(parcel);
XmlAttribute category_attr = nodeFactory.CreateAttribute("category");
category_attr.Value = parcel.category.ToString();
//XmlAttribute entities_attr = nodeFactory.CreateAttribute("entities");
//entities_attr.Value = land.primsOverMe.Count.ToString();
xmlparcel.Attributes.Append(scripts_attr);
xmlparcel.Attributes.Append(category_attr);
//xmlparcel.Attributes.Append(entities_attr);
//name, description, area, and UUID
XmlNode name = nodeFactory.CreateNode(XmlNodeType.Element, "name", "");
name.InnerText = parcel.landName;
xmlparcel.AppendChild(name);
XmlNode desc = nodeFactory.CreateNode(XmlNodeType.Element, "description", "");
desc.InnerText = parcel.landDesc;
xmlparcel.AppendChild(desc);
XmlNode uuid = nodeFactory.CreateNode(XmlNodeType.Element, "uuid", "");
uuid.InnerText = parcel.globalID.ToString();
xmlparcel.AppendChild(uuid);
XmlNode area = nodeFactory.CreateNode(XmlNodeType.Element, "area", "");
area.InnerText = parcel.area.ToString();
xmlparcel.AppendChild(area);
//default location
XmlNode tpLocation = nodeFactory.CreateNode(XmlNodeType.Element, "location", "");
LLVector3 loc = parcel.userLocation;
if (loc.Equals(LLVector3.Zero)) // This test is mute at this point: the location is wrong by default
loc = new LLVector3((parcel.AABBMax.X - parcel.AABBMin.X) / 2, (parcel.AABBMax.Y - parcel.AABBMin.Y) / 2, (parcel.AABBMax.Y - parcel.AABBMin.Y) / 2);
tpLocation.InnerText = loc.X.ToString() + "/" + loc.Y.ToString() + "/" + loc.Z.ToString();
xmlparcel.AppendChild(tpLocation);
//TODO: figure how to figure out teleport system landData.landingType
//land texture snapshot uuid
if (parcel.snapshotID != LLUUID.Zero)
{
XmlNode textureuuid = nodeFactory.CreateNode(XmlNodeType.Element, "image", "");
textureuuid.InnerText = parcel.snapshotID.ToString();
xmlparcel.AppendChild(textureuuid);
}
//attached user and group
if (parcel.groupID != LLUUID.Zero)
{
XmlNode groupblock = nodeFactory.CreateNode(XmlNodeType.Element, "group", "");
XmlNode groupuuid = nodeFactory.CreateNode(XmlNodeType.Element, "uuid", "");
groupuuid.InnerText = parcel.groupID.ToString();
groupblock.AppendChild(groupuuid);
//No name yet, there's no way to get a group name since they don't exist yet.
//TODO: When groups are supported, add the group handling code.
xmlparcel.AppendChild(groupblock);
}
if (!parcel.isGroupOwned)
{
XmlNode userblock = nodeFactory.CreateNode(XmlNodeType.Element, "owner", "");
LLUUID userOwnerUUID = parcel.ownerID;
XmlNode useruuid = nodeFactory.CreateNode(XmlNodeType.Element, "uuid", "");
useruuid.InnerText = userOwnerUUID.ToString();
userblock.AppendChild(useruuid);
try
{
XmlNode username = nodeFactory.CreateNode(XmlNodeType.Element, "name", "");
UserProfileData userProfile = m_scene.CommsManager.UserService.GetUserProfile(userOwnerUUID);
username.InnerText = userProfile.username + " " + userProfile.surname;
userblock.AppendChild(username);
}
catch (Exception)
{
m_log.Info("[DATASNAPSHOT]: Cannot find owner name; ignoring this parcel");
}
xmlparcel.AppendChild(userblock);
}
//else
//{
// XmlAttribute type = (XmlAttribute)nodeFactory.CreateNode(XmlNodeType.Attribute, "type", "");
// type.InnerText = "owner";
// groupblock.Attributes.Append(type);
//}
parent.AppendChild(xmlparcel);
}
}
//snap.AppendChild(parent);
}
return parent;
}
#endregion
#region Helper functions
private string GetScriptsPermissions(LandData parcel)
{
if ((parcel.landFlags & (uint)Parcel.ParcelFlags.AllowOtherScripts) == (uint)Parcel.ParcelFlags.AllowOtherScripts)
return "yes";
else
return "no";
}
#endregion
}
}

View File

@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Reflection;
using OpenSim.Region.Environment.Scenes;
using OpenSim.Framework;
using libsecondlife;
namespace OpenSim.Region.DataSnapshot
{
public class ObjectSnapshot : IDataSnapshotProvider
{
private Scene m_scene = null;
private DataSnapshotManager m_parent = null;
private log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public void Initialize(Scene scene, DataSnapshotManager parent)
{
m_scene = scene;
m_parent = parent;
}
public Scene GetParentScene
{
get { return m_scene; }
}
public XmlNode RequestSnapshotData(XmlDocument nodeFactory)
{
XmlNode parent = nodeFactory.CreateNode(XmlNodeType.Element, "objectdata", "");
XmlNode node;
#if LIBSL_IS_FIXED
foreach (EntityBase entity in m_scene.Entities.Values)
{
// only objects, not avatars
if (entity is SceneObjectGroup)
{
SceneObjectGroup obj = (SceneObjectGroup)entity;
XmlNode xmlobject = nodeFactory.CreateNode(XmlNodeType.Element, "object", "");
node = nodeFactory.CreateNode(XmlNodeType.Element, "uuid", "");
node.InnerText = obj.UUID.ToString();
xmlobject.AppendChild(node);
SceneObjectPart m_rootPart = null;
try
{
Type sog = typeof(SceneObjectGroup);
FieldInfo rootField = sog.GetField("m_rootPart", BindingFlags.NonPublic | BindingFlags.Instance);
if (rootField != null)
{
m_rootPart = (SceneObjectPart)rootField.GetValue(obj);
}
}
catch (Exception e)
{
Console.WriteLine("[DATASNAPSHOT] couldn't access field reflectively\n" + e.ToString());
}
if (m_rootPart != null)
{
node = nodeFactory.CreateNode(XmlNodeType.Element, "title", "");
node.InnerText = m_rootPart.Name;
xmlobject.AppendChild(node);
node = nodeFactory.CreateNode(XmlNodeType.Element, "description", "");
node.InnerText = m_rootPart.Description;
xmlobject.AppendChild(node);
node = nodeFactory.CreateNode(XmlNodeType.Element, "flags", "");
node.InnerText = String.Format("{0:x}", m_rootPart.ObjectFlags);
xmlobject.AppendChild(node);
}
parent.AppendChild(xmlobject);
}
}
#endif
return parent;
}
}
}

View File

@ -7,7 +7,7 @@ gridmode = false
; *** Prim Storage - only leave one storage_plugin uncommented ***
; --- The NullStorage stores nothing - effectively disabling persistence:
storage_plugin = "OpenSim.Data.Null.dll"
storage_plugin = "OpenSim.DataStore.NullStorage.dll"
; --- To use sqlite as region storage:
;storage_plugin = "OpenSim.Data.SQLite.dll"
@ -285,3 +285,19 @@ CleanUpOldScriptsOnStartup=true
[LL-Functions]
; Set the following to true to allow administrator owned scripts to execute console commands
AllowosConsoleCommand=false
[DataSnapshot]
; The following set of configs pertains to search.
; Set index_sims to true to enable search engines to index your searchable data
; If false, no data will be exposed, DataSnapshot module will be off, and you can ignore the rest of these search-related configs
index_sims = false
; If search is on, change this to your grid name; will be ignored for standalones
gridname = "OSGrid"
; Period between data snapshots, in seconds. 20 minutes, for starters, so that you see the initial changes fast.
; Later, you may want to increase this to 3600 (1 hour) or more
default_snapshot_period = 1200
; This will be created in bin, if it doesn't exist already. It will hold the data snapshots.
snapshot_cache_directory = "DataSnapshot"
; This semicolon-separated string serves to notify specific data services
; about the existence of this sim.
data_services="http://metaverseink.com/cgi-bin/register.py"

View File

@ -1073,6 +1073,35 @@
<!-- Scene Server API Example Apps -->
<Project name="OpenSim.Region.DataSnapshot" path="OpenSim/Region/DataSnapshot" type="Library">
<Configuration name="Debug">
<Options>
<OutputPath>../../../bin/</OutputPath>
</Options>
</Configuration>
<Configuration name="Release">
<Options>
<OutputPath>../../../bin/</OutputPath>
</Options>
</Configuration>
<ReferencePath>../../../bin/</ReferencePath>
<Reference name="System" localCopy="false"/>
<Reference name="System.Xml"/>
<Reference name="System.Data"/>
<Reference name="OpenSim.Framework"/>
<Reference name="OpenSim.Framework.Communications"/>
<Reference name="OpenSim.Framework.Console"/>
<Reference name="OpenSim.Framework.Servers"/>
<Reference name="OpenSim.Region.Environment"/>
<Reference name="libsecondlife.dll"/>
<Reference name="Nini.dll" />
<Reference name="log4net.dll" />
<Files>
<Match pattern="*.cs" recurse="true"/>
</Files>
</Project>
<Project name="OpenSim.Region.Examples.SimpleModule" path="OpenSim/Region/Examples/SimpleModule" type="Library">
<Configuration name="Debug">
<Options>