DB4oGridData.cs 6.1 KB

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