LocalBackEndServices.cs 8.9 KB

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