123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using OpenMetaverse;
- using OpenSim.Framework;
- using OpenSim.Data;
- using System.Reflection;
- using log4net;
- using RegionFlags = OpenSim.Framework.RegionFlags;
- namespace OpenSim.Data.Null
- {
- public class NullRegionData : IRegionData
- {
- private static NullRegionData Instance = null;
-
-
-
- private bool m_useStaticInstance = true;
- Dictionary<UUID, RegionData> m_regionData = new Dictionary<UUID, RegionData>();
- public NullRegionData(string connectionString, string realm)
- {
-
-
-
-
-
- if (connectionString == "!static")
- m_useStaticInstance = false;
- else if (Instance == null)
- Instance = this;
- }
- private delegate bool Matcher(string value);
- public List<RegionData> Get(string regionName, UUID scopeID)
- {
- if (m_useStaticInstance && Instance != this)
- return Instance.Get(regionName, scopeID);
- string cleanName = regionName.ToLower();
-
- const string wildcard = "%";
- bool wildcardPrefix = false;
- bool wildcardSuffix = false;
- if (cleanName.Equals(wildcard))
- {
- wildcardPrefix = wildcardSuffix = true;
- cleanName = string.Empty;
- }
- else
- {
- if (cleanName.StartsWith(wildcard))
- {
- wildcardPrefix = true;
- cleanName = cleanName.Substring(1);
- }
- if (regionName.EndsWith(wildcard))
- {
- wildcardSuffix = true;
- cleanName = cleanName.Remove(cleanName.Length - 1);
- }
- }
- Matcher queryMatch;
- if (wildcardPrefix && wildcardSuffix)
- queryMatch = delegate(string s) { return s.Contains(cleanName); };
- else if (wildcardSuffix)
- queryMatch = delegate(string s) { return s.StartsWith(cleanName); };
- else if (wildcardPrefix)
- queryMatch = delegate(string s) { return s.EndsWith(cleanName); };
- else
- queryMatch = delegate(string s) { return s.Equals(cleanName); };
-
- List<RegionData> ret = new List<RegionData>();
- lock (m_regionData)
- {
- foreach (RegionData r in m_regionData.Values)
- {
-
- if (queryMatch(r.RegionName.ToLower()))
- ret.Add(r);
- }
- }
- if (ret.Count > 0)
- return ret;
- return null;
- }
- public RegionData Get(int posX, int posY, UUID scopeID)
- {
- if (m_useStaticInstance && Instance != this)
- return Instance.Get(posX, posY, scopeID);
- List<RegionData> ret = new List<RegionData>();
- lock (m_regionData)
- {
- foreach (RegionData r in m_regionData.Values)
- {
- if (r.posX == posX && r.posY == posY)
- ret.Add(r);
- }
- }
- if (ret.Count > 0)
- return ret[0];
- return null;
- }
- public RegionData Get(UUID regionID, UUID scopeID)
- {
- if (m_useStaticInstance && Instance != this)
- return Instance.Get(regionID, scopeID);
- lock (m_regionData)
- {
- if (m_regionData.ContainsKey(regionID))
- return m_regionData[regionID];
- }
- return null;
- }
- public List<RegionData> Get(int startX, int startY, int endX, int endY, UUID scopeID)
- {
- if (m_useStaticInstance && Instance != this)
- return Instance.Get(startX, startY, endX, endY, scopeID);
- List<RegionData> ret = new List<RegionData>();
- lock (m_regionData)
- {
- foreach (RegionData r in m_regionData.Values)
- {
- if (r.posX >= startX && r.posX <= endX && r.posY >= startY && r.posY <= endY)
- ret.Add(r);
- }
- }
- return ret;
- }
- public bool Store(RegionData data)
- {
- if (m_useStaticInstance && Instance != this)
- return Instance.Store(data);
- lock (m_regionData)
- {
- m_regionData[data.RegionID] = data;
- }
- return true;
- }
- public bool SetDataItem(UUID regionID, string item, string value)
- {
- if (m_useStaticInstance && Instance != this)
- return Instance.SetDataItem(regionID, item, value);
- lock (m_regionData)
- {
- if (!m_regionData.ContainsKey(regionID))
- return false;
- m_regionData[regionID].Data[item] = value;
- }
- return true;
- }
- public bool Delete(UUID regionID)
- {
- if (m_useStaticInstance && Instance != this)
- return Instance.Delete(regionID);
- lock (m_regionData)
- {
- if (!m_regionData.ContainsKey(regionID))
- return false;
- m_regionData.Remove(regionID);
- }
- return true;
- }
- public List<RegionData> GetDefaultRegions(UUID scopeID)
- {
- return Get((int)RegionFlags.DefaultRegion, scopeID);
- }
- public List<RegionData> GetDefaultHypergridRegions(UUID scopeID)
- {
- return Get((int)RegionFlags.DefaultHGRegion, scopeID);
- }
- public List<RegionData> GetFallbackRegions(UUID scopeID, int x, int y)
- {
- List<RegionData> regions = Get((int)RegionFlags.FallbackRegion, scopeID);
- RegionDataDistanceCompare distanceComparer = new RegionDataDistanceCompare(x, y);
- regions.Sort(distanceComparer);
- return regions;
- }
- public List<RegionData> GetHyperlinks(UUID scopeID)
- {
- return Get((int)RegionFlags.Hyperlink, scopeID);
- }
- private List<RegionData> Get(int regionFlags, UUID scopeID)
- {
- if (Instance != this)
- return Instance.Get(regionFlags, scopeID);
- List<RegionData> ret = new List<RegionData>();
- lock (m_regionData)
- {
- foreach (RegionData r in m_regionData.Values)
- {
- if ((Convert.ToInt32(r.Data["flags"]) & regionFlags) != 0)
- ret.Add(r);
- }
- }
- return ret;
- }
- }
- }
|