diff options
author | Melanie | 2010-03-03 02:07:03 +0000 |
---|---|---|
committer | Melanie | 2010-03-03 02:07:03 +0000 |
commit | 028a87fe37002e7a0611f66babf1deee46c83804 (patch) | |
tree | 387aec499fd60c2012bed8148e6a2ddc847c3d95 /OpenSim/Data/MySQL/MySQLGridData.cs | |
parent | Revert "test" (diff) | |
parent | Fixes Region.Framework tests. Although these tests don't fail, they need to b... (diff) | |
download | opensim-SC_OLD-028a87fe37002e7a0611f66babf1deee46c83804.zip opensim-SC_OLD-028a87fe37002e7a0611f66babf1deee46c83804.tar.gz opensim-SC_OLD-028a87fe37002e7a0611f66babf1deee46c83804.tar.bz2 opensim-SC_OLD-028a87fe37002e7a0611f66babf1deee46c83804.tar.xz |
Merge branch 'master' into careminster-presence-refactor
This brings careminster on the level of master. To be tested
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLGridData.cs')
-rw-r--r-- | OpenSim/Data/MySQL/MySQLGridData.cs | 422 |
1 files changed, 0 insertions, 422 deletions
diff --git a/OpenSim/Data/MySQL/MySQLGridData.cs b/OpenSim/Data/MySQL/MySQLGridData.cs deleted file mode 100644 index f4e7b85..0000000 --- a/OpenSim/Data/MySQL/MySQLGridData.cs +++ /dev/null | |||
@@ -1,422 +0,0 @@ | |||
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.Generic; | ||
30 | using System.Data; | ||
31 | using System.Reflection; | ||
32 | using System.Threading; | ||
33 | using log4net; | ||
34 | using MySql.Data.MySqlClient; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Framework; | ||
37 | |||
38 | namespace OpenSim.Data.MySQL | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// A MySQL Interface for the Grid Server | ||
42 | /// </summary> | ||
43 | public class MySQLGridData : GridDataBase | ||
44 | { | ||
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | private MySQLManager m_database; | ||
48 | private object m_dbLock = new object(); | ||
49 | private string m_connectionString; | ||
50 | |||
51 | override public void Initialise() | ||
52 | { | ||
53 | m_log.Info("[MySQLGridData]: " + Name + " cannot be default-initialized!"); | ||
54 | throw new PluginNotInitialisedException (Name); | ||
55 | } | ||
56 | |||
57 | /// <summary> | ||
58 | /// <para>Initialises Grid interface</para> | ||
59 | /// <para> | ||
60 | /// <list type="bullet"> | ||
61 | /// <item>Loads and initialises the MySQL storage plugin</item> | ||
62 | /// <item>Warns and uses the obsolete mysql_connection.ini if connect string is empty.</item> | ||
63 | /// <item>Check for migration</item> | ||
64 | /// </list> | ||
65 | /// </para> | ||
66 | /// </summary> | ||
67 | /// <param name="connect">connect string.</param> | ||
68 | override public void Initialise(string connect) | ||
69 | { | ||
70 | m_connectionString = connect; | ||
71 | m_database = new MySQLManager(connect); | ||
72 | |||
73 | // This actually does the roll forward assembly stuff | ||
74 | Assembly assem = GetType().Assembly; | ||
75 | |||
76 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
77 | { | ||
78 | Migration m = new Migration(dbcon, assem, "GridStore"); | ||
79 | m.Update(); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | /// <summary> | ||
84 | /// Shuts down the grid interface | ||
85 | /// </summary> | ||
86 | override public void Dispose() | ||
87 | { | ||
88 | } | ||
89 | |||
90 | /// <summary> | ||
91 | /// Returns the plugin name | ||
92 | /// </summary> | ||
93 | /// <returns>Plugin name</returns> | ||
94 | override public string Name | ||
95 | { | ||
96 | get { return "MySql OpenGridData"; } | ||
97 | } | ||
98 | |||
99 | /// <summary> | ||
100 | /// Returns the plugin version | ||
101 | /// </summary> | ||
102 | /// <returns>Plugin version</returns> | ||
103 | override public string Version | ||
104 | { | ||
105 | get { return "0.1"; } | ||
106 | } | ||
107 | |||
108 | /// <summary> | ||
109 | /// Returns all the specified region profiles within coordates -- coordinates are inclusive | ||
110 | /// </summary> | ||
111 | /// <param name="xmin">Minimum X coordinate</param> | ||
112 | /// <param name="ymin">Minimum Y coordinate</param> | ||
113 | /// <param name="xmax">Maximum X coordinate</param> | ||
114 | /// <param name="ymax">Maximum Y coordinate</param> | ||
115 | /// <returns>Array of sim profiles</returns> | ||
116 | override public RegionProfileData[] GetProfilesInRange(uint xmin, uint ymin, uint xmax, uint ymax) | ||
117 | { | ||
118 | try | ||
119 | { | ||
120 | Dictionary<string, object> param = new Dictionary<string, object>(); | ||
121 | param["?xmin"] = xmin.ToString(); | ||
122 | param["?ymin"] = ymin.ToString(); | ||
123 | param["?xmax"] = xmax.ToString(); | ||
124 | param["?ymax"] = ymax.ToString(); | ||
125 | |||
126 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
127 | { | ||
128 | dbcon.Open(); | ||
129 | |||
130 | using (IDbCommand result = m_database.Query(dbcon, | ||
131 | "SELECT * FROM regions WHERE locX >= ?xmin AND locX <= ?xmax AND locY >= ?ymin AND locY <= ?ymax", | ||
132 | param)) | ||
133 | { | ||
134 | using (IDataReader reader = result.ExecuteReader()) | ||
135 | { | ||
136 | RegionProfileData row; | ||
137 | |||
138 | List<RegionProfileData> rows = new List<RegionProfileData>(); | ||
139 | |||
140 | while ((row = m_database.readSimRow(reader)) != null) | ||
141 | rows.Add(row); | ||
142 | |||
143 | return rows.ToArray(); | ||
144 | } | ||
145 | } | ||
146 | } | ||
147 | } | ||
148 | catch (Exception e) | ||
149 | { | ||
150 | m_log.Error(e.Message, e); | ||
151 | return null; | ||
152 | } | ||
153 | } | ||
154 | |||
155 | /// <summary> | ||
156 | /// Returns up to maxNum profiles of regions that have a name starting with namePrefix | ||
157 | /// </summary> | ||
158 | /// <param name="name">The name to match against</param> | ||
159 | /// <param name="maxNum">Maximum number of profiles to return</param> | ||
160 | /// <returns>A list of sim profiles</returns> | ||
161 | override public List<RegionProfileData> GetRegionsByName(string namePrefix, uint maxNum) | ||
162 | { | ||
163 | try | ||
164 | { | ||
165 | Dictionary<string, object> param = new Dictionary<string, object>(); | ||
166 | param["?name"] = namePrefix + "%"; | ||
167 | |||
168 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
169 | { | ||
170 | dbcon.Open(); | ||
171 | |||
172 | using (IDbCommand result = m_database.Query(dbcon, | ||
173 | "SELECT * FROM regions WHERE regionName LIKE ?name", | ||
174 | param)) | ||
175 | { | ||
176 | using (IDataReader reader = result.ExecuteReader()) | ||
177 | { | ||
178 | RegionProfileData row; | ||
179 | |||
180 | List<RegionProfileData> rows = new List<RegionProfileData>(); | ||
181 | |||
182 | while (rows.Count < maxNum && (row = m_database.readSimRow(reader)) != null) | ||
183 | rows.Add(row); | ||
184 | |||
185 | return rows; | ||
186 | } | ||
187 | } | ||
188 | } | ||
189 | } | ||
190 | catch (Exception e) | ||
191 | { | ||
192 | m_log.Error(e.Message, e); | ||
193 | return null; | ||
194 | } | ||
195 | } | ||
196 | |||
197 | /// <summary> | ||
198 | /// Returns a sim profile from it's location | ||
199 | /// </summary> | ||
200 | /// <param name="handle">Region location handle</param> | ||
201 | /// <returns>Sim profile</returns> | ||
202 | override public RegionProfileData GetProfileByHandle(ulong handle) | ||
203 | { | ||
204 | try | ||
205 | { | ||
206 | Dictionary<string, object> param = new Dictionary<string, object>(); | ||
207 | param["?handle"] = handle.ToString(); | ||
208 | |||
209 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
210 | { | ||
211 | dbcon.Open(); | ||
212 | |||
213 | using (IDbCommand result = m_database.Query(dbcon, "SELECT * FROM regions WHERE regionHandle = ?handle", param)) | ||
214 | { | ||
215 | using (IDataReader reader = result.ExecuteReader()) | ||
216 | { | ||
217 | RegionProfileData row = m_database.readSimRow(reader); | ||
218 | return row; | ||
219 | } | ||
220 | } | ||
221 | } | ||
222 | } | ||
223 | catch (Exception e) | ||
224 | { | ||
225 | m_log.Error(e.Message, e); | ||
226 | return null; | ||
227 | } | ||
228 | } | ||
229 | |||
230 | /// <summary> | ||
231 | /// Returns a sim profile from it's UUID | ||
232 | /// </summary> | ||
233 | /// <param name="uuid">The region UUID</param> | ||
234 | /// <returns>The sim profile</returns> | ||
235 | override public RegionProfileData GetProfileByUUID(UUID uuid) | ||
236 | { | ||
237 | try | ||
238 | { | ||
239 | Dictionary<string, object> param = new Dictionary<string, object>(); | ||
240 | param["?uuid"] = uuid.ToString(); | ||
241 | |||
242 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
243 | { | ||
244 | dbcon.Open(); | ||
245 | |||
246 | using (IDbCommand result = m_database.Query(dbcon, "SELECT * FROM regions WHERE uuid = ?uuid", param)) | ||
247 | { | ||
248 | using (IDataReader reader = result.ExecuteReader()) | ||
249 | { | ||
250 | RegionProfileData row = m_database.readSimRow(reader); | ||
251 | return row; | ||
252 | } | ||
253 | } | ||
254 | } | ||
255 | } | ||
256 | catch (Exception e) | ||
257 | { | ||
258 | m_log.Error(e.Message, e); | ||
259 | return null; | ||
260 | } | ||
261 | } | ||
262 | |||
263 | /// <summary> | ||
264 | /// Returns a sim profile from it's Region name string | ||
265 | /// </summary> | ||
266 | /// <returns>The sim profile</returns> | ||
267 | override public RegionProfileData GetProfileByString(string regionName) | ||
268 | { | ||
269 | if (regionName.Length > 2) | ||
270 | { | ||
271 | try | ||
272 | { | ||
273 | Dictionary<string, object> param = new Dictionary<string, object>(); | ||
274 | // Add % because this is a like query. | ||
275 | param["?regionName"] = regionName + "%"; | ||
276 | |||
277 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
278 | { | ||
279 | dbcon.Open(); | ||
280 | |||
281 | // Order by statement will return shorter matches first. Only returns one record or no record. | ||
282 | using (IDbCommand result = m_database.Query(dbcon, | ||
283 | "SELECT * FROM regions WHERE regionName like ?regionName order by LENGTH(regionName) asc LIMIT 1", | ||
284 | param)) | ||
285 | { | ||
286 | using (IDataReader reader = result.ExecuteReader()) | ||
287 | { | ||
288 | RegionProfileData row = m_database.readSimRow(reader); | ||
289 | return row; | ||
290 | } | ||
291 | } | ||
292 | } | ||
293 | } | ||
294 | catch (Exception e) | ||
295 | { | ||
296 | m_log.Error(e.Message, e); | ||
297 | return null; | ||
298 | } | ||
299 | } | ||
300 | |||
301 | m_log.Error("[GRID DB]: Searched for a Region Name shorter then 3 characters"); | ||
302 | return null; | ||
303 | } | ||
304 | |||
305 | /// <summary> | ||
306 | /// Adds a new profile to the database | ||
307 | /// </summary> | ||
308 | /// <param name="profile">The profile to add</param> | ||
309 | /// <returns>Successful?</returns> | ||
310 | override public DataResponse StoreProfile(RegionProfileData profile) | ||
311 | { | ||
312 | try | ||
313 | { | ||
314 | if (m_database.insertRegion(profile)) | ||
315 | return DataResponse.RESPONSE_OK; | ||
316 | else | ||
317 | return DataResponse.RESPONSE_ERROR; | ||
318 | } | ||
319 | catch | ||
320 | { | ||
321 | return DataResponse.RESPONSE_ERROR; | ||
322 | } | ||
323 | } | ||
324 | |||
325 | /// <summary> | ||
326 | /// Deletes a sim profile from the database | ||
327 | /// </summary> | ||
328 | /// <param name="uuid">the sim UUID</param> | ||
329 | /// <returns>Successful?</returns> | ||
330 | //public DataResponse DeleteProfile(RegionProfileData profile) | ||
331 | override public DataResponse DeleteProfile(string uuid) | ||
332 | { | ||
333 | try | ||
334 | { | ||
335 | if (m_database.deleteRegion(uuid)) | ||
336 | return DataResponse.RESPONSE_OK; | ||
337 | else | ||
338 | return DataResponse.RESPONSE_ERROR; | ||
339 | } | ||
340 | catch | ||
341 | { | ||
342 | return DataResponse.RESPONSE_ERROR; | ||
343 | } | ||
344 | } | ||
345 | |||
346 | /// <summary> | ||
347 | /// DEPRECATED. Attempts to authenticate a region by comparing a shared secret. | ||
348 | /// </summary> | ||
349 | /// <param name="uuid">The UUID of the challenger</param> | ||
350 | /// <param name="handle">The attempted regionHandle of the challenger</param> | ||
351 | /// <param name="authkey">The secret</param> | ||
352 | /// <returns>Whether the secret and regionhandle match the database entry for UUID</returns> | ||
353 | override public bool AuthenticateSim(UUID uuid, ulong handle, string authkey) | ||
354 | { | ||
355 | bool throwHissyFit = false; // Should be true by 1.0 | ||
356 | |||
357 | if (throwHissyFit) | ||
358 | throw new Exception("CRYPTOWEAK AUTHENTICATE: Refusing to authenticate due to replay potential."); | ||
359 | |||
360 | RegionProfileData data = GetProfileByUUID(uuid); | ||
361 | |||
362 | return (handle == data.regionHandle && authkey == data.regionSecret); | ||
363 | } | ||
364 | |||
365 | /// <summary> | ||
366 | /// NOT YET FUNCTIONAL. Provides a cryptographic authentication of a region | ||
367 | /// </summary> | ||
368 | /// <remarks>This requires a security audit.</remarks> | ||
369 | /// <param name="uuid"></param> | ||
370 | /// <param name="handle"></param> | ||
371 | /// <param name="authhash"></param> | ||
372 | /// <param name="challenge"></param> | ||
373 | /// <returns></returns> | ||
374 | public bool AuthenticateSim(UUID uuid, ulong handle, string authhash, string challenge) | ||
375 | { | ||
376 | // SHA512Managed HashProvider = new SHA512Managed(); | ||
377 | // Encoding TextProvider = new UTF8Encoding(); | ||
378 | |||
379 | // byte[] stream = TextProvider.GetBytes(uuid.ToString() + ":" + handle.ToString() + ":" + challenge); | ||
380 | // byte[] hash = HashProvider.ComputeHash(stream); | ||
381 | |||
382 | return false; | ||
383 | } | ||
384 | |||
385 | /// <summary> | ||
386 | /// Adds a location reservation | ||
387 | /// </summary> | ||
388 | /// <param name="x">x coordinate</param> | ||
389 | /// <param name="y">y coordinate</param> | ||
390 | /// <returns></returns> | ||
391 | override public ReservationData GetReservationAtPoint(uint x, uint y) | ||
392 | { | ||
393 | try | ||
394 | { | ||
395 | Dictionary<string, object> param = new Dictionary<string, object>(); | ||
396 | param["?x"] = x.ToString(); | ||
397 | param["?y"] = y.ToString(); | ||
398 | |||
399 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
400 | { | ||
401 | dbcon.Open(); | ||
402 | |||
403 | using (IDbCommand result = m_database.Query(dbcon, | ||
404 | "SELECT * FROM reservations WHERE resXMin <= ?x AND resXMax >= ?x AND resYMin <= ?y AND resYMax >= ?y", | ||
405 | param)) | ||
406 | { | ||
407 | using (IDataReader reader = result.ExecuteReader()) | ||
408 | { | ||
409 | ReservationData row = m_database.readReservationRow(reader); | ||
410 | return row; | ||
411 | } | ||
412 | } | ||
413 | } | ||
414 | } | ||
415 | catch (Exception e) | ||
416 | { | ||
417 | m_log.Error(e.Message, e); | ||
418 | return null; | ||
419 | } | ||
420 | } | ||
421 | } | ||
422 | } | ||