DB4oGridData.cs 6.8 KB

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