opensim-development – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | eva | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ |
||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
||
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions are met: |
||
7 | * * Redistributions of source code must retain the above copyright |
||
8 | * notice, this list of conditions and the following disclaimer. |
||
9 | * * Redistributions in binary form must reproduce the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer in the |
||
11 | * documentation and/or other materials provided with the distribution. |
||
12 | * * Neither the name of the OpenSimulator Project nor the |
||
13 | * names of its contributors may be used to endorse or promote products |
||
14 | * derived from this software without specific prior written permission. |
||
15 | * |
||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
26 | */ |
||
27 | |||
28 | using System; |
||
29 | using System.Collections; |
||
30 | using System.Collections.Generic; |
||
31 | using OpenMetaverse; |
||
32 | using OpenSim.Framework; |
||
33 | using OpenSim.Data; |
||
34 | using System.Reflection; |
||
35 | using log4net; |
||
36 | using RegionFlags = OpenSim.Framework.RegionFlags; |
||
37 | |||
38 | namespace OpenSim.Data.Null |
||
39 | { |
||
40 | public class NullRegionData : IRegionData |
||
41 | { |
||
42 | private static NullRegionData Instance = null; |
||
43 | |||
44 | /// <summary> |
||
45 | /// Should we use the static instance for all invocations? |
||
46 | /// </summary> |
||
47 | private bool m_useStaticInstance = true; |
||
48 | |||
49 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
||
50 | |||
51 | Dictionary<UUID, RegionData> m_regionData = new Dictionary<UUID, RegionData>(); |
||
52 | |||
53 | public NullRegionData(string connectionString, string realm) |
||
54 | { |
||
55 | // m_log.DebugFormat( |
||
56 | // "[NULL REGION DATA]: Constructor got connectionString {0}, realm {1}", connectionString, realm); |
||
57 | |||
58 | // The !static connection string is a hack so that regression tests can use this module without a high degree of fragility |
||
59 | // in having to deal with the static reference in the once-loaded NullRegionData class. |
||
60 | // |
||
61 | // In standalone operation, we have to use only one instance of this class since the login service and |
||
62 | // simulator have no other way of using a common data store. |
||
63 | if (connectionString == "!static") |
||
64 | m_useStaticInstance = false; |
||
65 | else if (Instance == null) |
||
66 | Instance = this; |
||
67 | } |
||
68 | |||
69 | private delegate bool Matcher(string value); |
||
70 | |||
71 | public List<RegionData> Get(string regionName, UUID scopeID) |
||
72 | { |
||
73 | if (m_useStaticInstance && Instance != this) |
||
74 | return Instance.Get(regionName, scopeID); |
||
75 | |||
76 | // m_log.DebugFormat("[NULL REGION DATA]: Getting region {0}, scope {1}", regionName, scopeID); |
||
77 | |||
78 | string cleanName = regionName.ToLower(); |
||
79 | |||
80 | // Handle SQL wildcards |
||
81 | const string wildcard = "%"; |
||
82 | bool wildcardPrefix = false; |
||
83 | bool wildcardSuffix = false; |
||
84 | if (cleanName.Equals(wildcard)) |
||
85 | { |
||
86 | wildcardPrefix = wildcardSuffix = true; |
||
87 | cleanName = string.Empty; |
||
88 | } |
||
89 | else |
||
90 | { |
||
91 | if (cleanName.StartsWith(wildcard)) |
||
92 | { |
||
93 | wildcardPrefix = true; |
||
94 | cleanName = cleanName.Substring(1); |
||
95 | } |
||
96 | if (regionName.EndsWith(wildcard)) |
||
97 | { |
||
98 | wildcardSuffix = true; |
||
99 | cleanName = cleanName.Remove(cleanName.Length - 1); |
||
100 | } |
||
101 | } |
||
102 | |||
103 | Matcher queryMatch; |
||
104 | if (wildcardPrefix && wildcardSuffix) |
||
105 | queryMatch = delegate(string s) { return s.Contains(cleanName); }; |
||
106 | else if (wildcardSuffix) |
||
107 | queryMatch = delegate(string s) { return s.StartsWith(cleanName); }; |
||
108 | else if (wildcardPrefix) |
||
109 | queryMatch = delegate(string s) { return s.EndsWith(cleanName); }; |
||
110 | else |
||
111 | queryMatch = delegate(string s) { return s.Equals(cleanName); }; |
||
112 | |||
113 | // Find region data |
||
114 | List<RegionData> ret = new List<RegionData>(); |
||
115 | |||
116 | lock (m_regionData) |
||
117 | { |
||
118 | foreach (RegionData r in m_regionData.Values) |
||
119 | { |
||
120 | // m_log.DebugFormat("[NULL REGION DATA]: comparing {0} to {1}", cleanName, r.RegionName.ToLower()); |
||
121 | if (queryMatch(r.RegionName.ToLower())) |
||
122 | ret.Add(r); |
||
123 | } |
||
124 | } |
||
125 | |||
126 | if (ret.Count > 0) |
||
127 | return ret; |
||
128 | |||
129 | return null; |
||
130 | } |
||
131 | |||
132 | public RegionData Get(int posX, int posY, UUID scopeID) |
||
133 | { |
||
134 | if (m_useStaticInstance && Instance != this) |
||
135 | return Instance.Get(posX, posY, scopeID); |
||
136 | |||
137 | List<RegionData> ret = new List<RegionData>(); |
||
138 | |||
139 | lock (m_regionData) |
||
140 | { |
||
141 | foreach (RegionData r in m_regionData.Values) |
||
142 | { |
||
143 | if (r.posX == posX && r.posY == posY) |
||
144 | ret.Add(r); |
||
145 | } |
||
146 | } |
||
147 | |||
148 | if (ret.Count > 0) |
||
149 | return ret[0]; |
||
150 | |||
151 | return null; |
||
152 | } |
||
153 | |||
154 | public RegionData Get(UUID regionID, UUID scopeID) |
||
155 | { |
||
156 | if (m_useStaticInstance && Instance != this) |
||
157 | return Instance.Get(regionID, scopeID); |
||
158 | |||
159 | lock (m_regionData) |
||
160 | { |
||
161 | if (m_regionData.ContainsKey(regionID)) |
||
162 | return m_regionData[regionID]; |
||
163 | } |
||
164 | |||
165 | return null; |
||
166 | } |
||
167 | |||
168 | public List<RegionData> Get(int startX, int startY, int endX, int endY, UUID scopeID) |
||
169 | { |
||
170 | if (m_useStaticInstance && Instance != this) |
||
171 | return Instance.Get(startX, startY, endX, endY, scopeID); |
||
172 | |||
173 | List<RegionData> ret = new List<RegionData>(); |
||
174 | |||
175 | lock (m_regionData) |
||
176 | { |
||
177 | foreach (RegionData r in m_regionData.Values) |
||
178 | { |
||
179 | if (r.posX >= startX && r.posX <= endX && r.posY >= startY && r.posY <= endY) |
||
180 | ret.Add(r); |
||
181 | } |
||
182 | } |
||
183 | |||
184 | return ret; |
||
185 | } |
||
186 | |||
187 | public bool Store(RegionData data) |
||
188 | { |
||
189 | if (m_useStaticInstance && Instance != this) |
||
190 | return Instance.Store(data); |
||
191 | |||
192 | // m_log.DebugFormat( |
||
193 | // "[NULL REGION DATA]: Storing region {0} {1}, scope {2}", data.RegionName, data.RegionID, data.ScopeID); |
||
194 | |||
195 | lock (m_regionData) |
||
196 | { |
||
197 | m_regionData[data.RegionID] = data; |
||
198 | } |
||
199 | |||
200 | return true; |
||
201 | } |
||
202 | |||
203 | public bool SetDataItem(UUID regionID, string item, string value) |
||
204 | { |
||
205 | if (m_useStaticInstance && Instance != this) |
||
206 | return Instance.SetDataItem(regionID, item, value); |
||
207 | |||
208 | lock (m_regionData) |
||
209 | { |
||
210 | if (!m_regionData.ContainsKey(regionID)) |
||
211 | return false; |
||
212 | |||
213 | m_regionData[regionID].Data[item] = value; |
||
214 | } |
||
215 | |||
216 | return true; |
||
217 | } |
||
218 | |||
219 | public bool Delete(UUID regionID) |
||
220 | { |
||
221 | if (m_useStaticInstance && Instance != this) |
||
222 | return Instance.Delete(regionID); |
||
223 | |||
224 | // m_log.DebugFormat("[NULL REGION DATA]: Deleting region {0}", regionID); |
||
225 | |||
226 | lock (m_regionData) |
||
227 | { |
||
228 | if (!m_regionData.ContainsKey(regionID)) |
||
229 | return false; |
||
230 | |||
231 | m_regionData.Remove(regionID); |
||
232 | } |
||
233 | |||
234 | return true; |
||
235 | } |
||
236 | |||
237 | public List<RegionData> GetDefaultRegions(UUID scopeID) |
||
238 | { |
||
239 | return Get((int)RegionFlags.DefaultRegion, scopeID); |
||
240 | } |
||
241 | |||
242 | public List<RegionData> GetDefaultHypergridRegions(UUID scopeID) |
||
243 | { |
||
244 | return Get((int)RegionFlags.DefaultHGRegion, scopeID); |
||
245 | } |
||
246 | |||
247 | public List<RegionData> GetFallbackRegions(UUID scopeID, int x, int y) |
||
248 | { |
||
249 | List<RegionData> regions = Get((int)RegionFlags.FallbackRegion, scopeID); |
||
250 | RegionDataDistanceCompare distanceComparer = new RegionDataDistanceCompare(x, y); |
||
251 | regions.Sort(distanceComparer); |
||
252 | return regions; |
||
253 | } |
||
254 | |||
255 | public List<RegionData> GetHyperlinks(UUID scopeID) |
||
256 | { |
||
257 | return Get((int)RegionFlags.Hyperlink, scopeID); |
||
258 | } |
||
259 | |||
260 | private List<RegionData> Get(int regionFlags, UUID scopeID) |
||
261 | { |
||
262 | if (Instance != this) |
||
263 | return Instance.Get(regionFlags, scopeID); |
||
264 | |||
265 | List<RegionData> ret = new List<RegionData>(); |
||
266 | |||
267 | lock (m_regionData) |
||
268 | { |
||
269 | foreach (RegionData r in m_regionData.Values) |
||
270 | { |
||
271 | if ((Convert.ToInt32(r.Data["flags"]) & regionFlags) != 0) |
||
272 | ret.Add(r); |
||
273 | } |
||
274 | } |
||
275 | |||
276 | return ret; |
||
277 | } |
||
278 | } |
||
279 | } |