DB4oGridData.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 OpenSim 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. using System;
  28. using System.Collections.Generic;
  29. using libsecondlife;
  30. using OpenSim.Framework;
  31. namespace OpenSim.Data.DB4o
  32. {
  33. /// <summary>
  34. /// A grid server storage mechanism employing the DB4o database system
  35. /// </summary>
  36. internal class DB4oGridData : GridDataBase
  37. {
  38. /// <summary>
  39. /// The database manager object
  40. /// </summary>
  41. private DB4oGridManager manager;
  42. /// <summary>
  43. /// Called when the plugin is first loaded (as constructors are not called)
  44. /// </summary>
  45. override public void Initialise()
  46. {
  47. manager = new DB4oGridManager("gridserver.yap");
  48. }
  49. /// <summary>
  50. /// Returns a list of regions within the specified ranges
  51. /// </summary>
  52. /// <param name="a">minimum X coordinate</param>
  53. /// <param name="b">minimum Y coordinate</param>
  54. /// <param name="c">maximum X coordinate</param>
  55. /// <param name="d">maximum Y coordinate</param>
  56. /// <returns>An array of region profiles</returns>
  57. override public RegionProfileData[] GetProfilesInRange(uint a, uint b, uint c, uint d)
  58. {
  59. return null;
  60. }
  61. /// <summary>
  62. /// Returns a region located at the specified regionHandle (warning multiple regions may occupy the one spot, first found is returned)
  63. /// </summary>
  64. /// <param name="handle">The handle to search for</param>
  65. /// <returns>A region profile</returns>
  66. override public RegionProfileData GetProfileByHandle(ulong handle)
  67. {
  68. lock (manager.simProfiles)
  69. {
  70. foreach (LLUUID UUID in manager.simProfiles.Keys)
  71. {
  72. if (manager.simProfiles[UUID].regionHandle == handle)
  73. {
  74. return manager.simProfiles[UUID];
  75. }
  76. }
  77. }
  78. throw new Exception("Unable to find profile with handle (" + handle.ToString() + ")");
  79. }
  80. /// <summary>
  81. /// Returns a specific region
  82. /// </summary>
  83. /// <param name="uuid">The region ID code</param>
  84. /// <returns>A region profile</returns>
  85. override public RegionProfileData GetProfileByLLUUID(LLUUID uuid)
  86. {
  87. lock (manager.simProfiles)
  88. {
  89. if (manager.simProfiles.ContainsKey(uuid))
  90. return manager.simProfiles[uuid];
  91. }
  92. throw new Exception("Unable to find profile with UUID (" + uuid.ToString() +
  93. "). Total Registered Regions: " + manager.simProfiles.Count);
  94. }
  95. override public RegionProfileData GetProfileByString(string regionName)
  96. {
  97. throw new Exception("GetProfileByString Not supported in DB4oGridData");
  98. //return null;
  99. }
  100. /// <summary>
  101. /// Adds a new specified region to the database
  102. /// </summary>
  103. /// <param name="profile">The profile to add</param>
  104. /// <returns>A dataresponse enum indicating success</returns>
  105. override public DataResponse AddProfile(RegionProfileData profile)
  106. {
  107. lock (manager.simProfiles)
  108. {
  109. if (manager.AddRow(profile))
  110. {
  111. return DataResponse.RESPONSE_OK;
  112. }
  113. else
  114. {
  115. return DataResponse.RESPONSE_ERROR;
  116. }
  117. }
  118. }
  119. override public DataResponse UpdateProfile(RegionProfileData profile)
  120. {
  121. return AddProfile(profile);
  122. }
  123. /// <summary>
  124. /// Authenticates a new region using the shared secrets. NOT SECURE.
  125. /// </summary>
  126. /// <param name="uuid">The UUID the region is authenticating with</param>
  127. /// <param name="handle">The location the region is logging into (unused in Db4o)</param>
  128. /// <param name="key">The shared secret</param>
  129. /// <returns>Authenticated?</returns>
  130. override public bool AuthenticateSim(LLUUID uuid, ulong handle, string key)
  131. {
  132. if (manager.simProfiles[uuid].regionRecvKey == key)
  133. return true;
  134. return false;
  135. }
  136. /// <summary>
  137. /// Shuts down the database
  138. /// </summary>
  139. override public void Close()
  140. {
  141. manager = null;
  142. }
  143. /// <summary>
  144. /// // Returns a list of avatar and UUIDs that match the query
  145. /// </summary>
  146. public List<AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query)
  147. {
  148. //Do nothing yet
  149. List<AvatarPickerAvatar> returnlist = new List<AvatarPickerAvatar>();
  150. return returnlist;
  151. }
  152. /// <summary>
  153. /// Returns the providers name
  154. /// </summary>
  155. /// <returns>The name of the storage system</returns>
  156. override public string getName()
  157. {
  158. return "DB4o Grid Provider";
  159. }
  160. /// <summary>
  161. /// Returns the providers version
  162. /// </summary>
  163. /// <returns>The version of the storage system</returns>
  164. override public string getVersion()
  165. {
  166. return "0.1";
  167. }
  168. override public ReservationData GetReservationAtPoint(uint x, uint y)
  169. {
  170. return null;
  171. }
  172. }
  173. }