1
0

LocalBackEndServices.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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.Collections.Generic;
  29. using libsecondlife;
  30. using OpenSim.Framework;
  31. using OpenSim.Framework.Communications;
  32. using OpenSim.Framework.Types;
  33. namespace OpenSim.Region.Communications.Local
  34. {
  35. public class LocalBackEndServices : IGridServices, IInterRegionCommunications
  36. {
  37. protected Dictionary<ulong, RegionInfo> regions = new Dictionary<ulong, RegionInfo>();
  38. protected Dictionary<ulong, RegionCommsListener> regionHosts = new Dictionary<ulong, RegionCommsListener>();
  39. public LocalBackEndServices()
  40. {
  41. }
  42. /// <summary>
  43. /// Register a region method with the BackEnd Services.
  44. /// </summary>
  45. /// <param name="regionInfo"></param>
  46. /// <returns></returns>
  47. public RegionCommsListener RegisterRegion(RegionInfo regionInfo)
  48. {
  49. //Console.WriteLine("CommsManager - Region " + regionInfo.RegionHandle + " , " + regionInfo.RegionLocX + " , "+ regionInfo.RegionLocY +" is registering");
  50. if (!this.regions.ContainsKey((uint)regionInfo.RegionHandle))
  51. {
  52. //Console.WriteLine("CommsManager - Adding Region " + regionInfo.RegionHandle );
  53. this.regions.Add(regionInfo.RegionHandle, regionInfo);
  54. RegionCommsListener regionHost = new RegionCommsListener();
  55. this.regionHosts.Add(regionInfo.RegionHandle, regionHost);
  56. return regionHost;
  57. }
  58. //already in our list of regions so for now lets return null
  59. return null;
  60. }
  61. /// <summary>
  62. /// </summary>
  63. /// <param name="regionInfo"></param>
  64. /// <returns></returns>
  65. public List<RegionInfo> RequestNeighbours(RegionInfo regionInfo)
  66. {
  67. // Console.WriteLine("Finding Neighbours to " + regionInfo.RegionHandle);
  68. List<RegionInfo> neighbours = new List<RegionInfo>();
  69. foreach (RegionInfo reg in this.regions.Values)
  70. {
  71. // Console.WriteLine("CommsManager- RequestNeighbours() checking region " + reg.RegionLocX + " , "+ reg.RegionLocY);
  72. if (reg.RegionHandle != regionInfo.RegionHandle)
  73. {
  74. //Console.WriteLine("CommsManager- RequestNeighbours() - found a different region in list, checking location");
  75. if ((reg.RegionLocX > (regionInfo.RegionLocX - 2)) && (reg.RegionLocX < (regionInfo.RegionLocX + 2)))
  76. {
  77. if ((reg.RegionLocY > (regionInfo.RegionLocY - 2)) && (reg.RegionLocY < (regionInfo.RegionLocY + 2)))
  78. {
  79. neighbours.Add(reg);
  80. }
  81. }
  82. }
  83. }
  84. return neighbours;
  85. }
  86. /// <summary>
  87. ///
  88. /// </summary>
  89. /// <param name="regionHandle"></param>
  90. /// <returns></returns>
  91. public RegionInfo RequestNeighbourInfo(ulong regionHandle)
  92. {
  93. if (this.regions.ContainsKey(regionHandle))
  94. {
  95. return this.regions[regionHandle];
  96. }
  97. return null;
  98. }
  99. /// <summary>
  100. ///
  101. /// </summary>
  102. /// <param name="minX"></param>
  103. /// <param name="minY"></param>
  104. /// <param name="maxX"></param>
  105. /// <param name="maxY"></param>
  106. /// <returns></returns>
  107. public List<MapBlockData> RequestNeighbourMapBlocks(int minX, int minY, int maxX, int maxY)
  108. {
  109. List<MapBlockData> mapBlocks = new List<MapBlockData>();
  110. foreach(RegionInfo regInfo in this.regions.Values)
  111. {
  112. if (((regInfo.RegionLocX >= minX) && (regInfo.RegionLocX <= maxX)) && ((regInfo.RegionLocY >= minY) && (regInfo.RegionLocY <= maxY)))
  113. {
  114. MapBlockData map = new MapBlockData();
  115. map.Name = regInfo.RegionName;
  116. map.X = (ushort)regInfo.RegionLocX;
  117. map.Y = (ushort)regInfo.RegionLocY;
  118. map.WaterHeight =(byte) regInfo.estateSettings.waterHeight;
  119. map.MapImageId = regInfo.estateSettings.terrainImageID; //new LLUUID("00000000-0000-0000-9999-000000000007");
  120. map.Agents = 1;
  121. map.RegionFlags = 72458694;
  122. map.Access = 13;
  123. mapBlocks.Add(map);
  124. }
  125. }
  126. return mapBlocks;
  127. }
  128. /// <summary>
  129. /// </summary>
  130. /// <param name="regionHandle"></param>
  131. /// <param name="agentData"></param>
  132. /// <returns></returns>
  133. public bool InformRegionOfChildAgent(ulong regionHandle, AgentCircuitData agentData) //should change from agentCircuitData
  134. {
  135. //Console.WriteLine("CommsManager- Trying to Inform a region to expect child agent");
  136. if (this.regionHosts.ContainsKey(regionHandle))
  137. {
  138. // Console.WriteLine("CommsManager- Informing a region to expect child agent");
  139. this.regionHosts[regionHandle].TriggerExpectUser(regionHandle, agentData);
  140. return true;
  141. }
  142. return false;
  143. }
  144. /// <summary>
  145. ///
  146. /// </summary>
  147. /// <param name="regionHandle"></param>
  148. /// <param name="agentID"></param>
  149. /// <param name="position"></param>
  150. /// <returns></returns>
  151. public bool ExpectAvatarCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position)
  152. {
  153. if (this.regionHosts.ContainsKey(regionHandle))
  154. {
  155. // Console.WriteLine("CommsManager- Informing a region to expect avatar crossing");
  156. this.regionHosts[regionHandle].TriggerExpectAvatarCrossing(regionHandle, agentID, position);
  157. return true;
  158. }
  159. return false;
  160. }
  161. /// <summary>
  162. /// Is a Sandbox mode method, used by the local Login server to inform a region of a connection user/session
  163. /// </summary>
  164. /// <param name="regionHandle"></param>
  165. /// <param name="loginData"></param>
  166. /// <returns></returns>
  167. public bool AddNewSession(ulong regionHandle, Login loginData)
  168. {
  169. AgentCircuitData agent = new AgentCircuitData();
  170. agent.AgentID = loginData.Agent;
  171. agent.firstname = loginData.First;
  172. agent.lastname = loginData.Last;
  173. agent.SessionID = loginData.Session;
  174. agent.SecureSessionID = loginData.SecureSession;
  175. agent.circuitcode = loginData.CircuitCode;
  176. agent.BaseFolder = loginData.BaseFolder;
  177. agent.InventoryFolder = loginData.InventoryFolder;
  178. agent.startpos = new LLVector3(128, 128, 70);
  179. agent.CapsPath = loginData.CapsPath;
  180. if (this.regionHosts.ContainsKey(regionHandle))
  181. {
  182. this.regionHosts[regionHandle].TriggerExpectUser(regionHandle, agent);
  183. return true;
  184. }
  185. // region not found
  186. return false;
  187. }
  188. }
  189. }