LocalBackEndServices.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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.Collections;
  28. using System.Collections.Generic;
  29. using libsecondlife;
  30. using OpenSim.Framework;
  31. using OpenSim.Framework.Communications;
  32. using OpenSim.Framework.Console;
  33. namespace OpenSim.Region.Communications.Local
  34. {
  35. public class LocalBackEndServices : IGridServices, IInterRegionCommunications
  36. {
  37. private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  38. protected Dictionary<ulong, RegionInfo> m_regions = new Dictionary<ulong, RegionInfo>();
  39. protected Dictionary<ulong, RegionCommsListener> m_regionListeners =
  40. new Dictionary<ulong, RegionCommsListener>();
  41. private Dictionary<ulong, RegionInfo> m_remoteRegionInfoCache = new Dictionary<ulong, RegionInfo>();
  42. private Dictionary<string, string> m_queuedGridSettings = new Dictionary<string, string>();
  43. public string _gdebugRegionName = System.String.Empty;
  44. bool m_bAvailable=true;
  45. public void CheckRegion(string address, uint port)
  46. {
  47. m_bAvailable = true;
  48. }
  49. public bool Available
  50. {
  51. get { return m_bAvailable; }
  52. }
  53. public string gdebugRegionName
  54. {
  55. get { return _gdebugRegionName; }
  56. set { _gdebugRegionName = value; }
  57. }
  58. public string _rdebugRegionName = System.String.Empty;
  59. public string rdebugRegionName
  60. {
  61. get { return _rdebugRegionName; }
  62. set { _rdebugRegionName = value; }
  63. }
  64. public LocalBackEndServices()
  65. {
  66. }
  67. /// <summary>
  68. /// Register a region method with the BackEnd Services.
  69. /// </summary>
  70. /// <param name="regionInfo"></param>
  71. /// <returns></returns>
  72. public RegionCommsListener RegisterRegion(RegionInfo regionInfo)
  73. {
  74. //Console.WriteLine("CommsManager - Region " + regionInfo.RegionHandle + " , " + regionInfo.RegionLocX + " , "+ regionInfo.RegionLocY +" is registering");
  75. if (!m_regions.ContainsKey(regionInfo.RegionHandle))
  76. {
  77. //Console.WriteLine("CommsManager - Adding Region " + regionInfo.RegionHandle );
  78. m_regions.Add(regionInfo.RegionHandle, regionInfo);
  79. RegionCommsListener regionHost = new RegionCommsListener();
  80. if (m_regionListeners.ContainsKey(regionInfo.RegionHandle))
  81. {
  82. m_log.Error("[INTERREGION STANDALONE]: " +
  83. "Error:Region registered twice as an Events listener for Interregion Communications but not as a listed region. " +
  84. "In Standalone mode this will cause BIG issues. In grid mode, it means a region went down and came back up.");
  85. m_regionListeners.Remove(regionInfo.RegionHandle);
  86. }
  87. m_regionListeners.Add(regionInfo.RegionHandle, regionHost);
  88. return regionHost;
  89. }
  90. else
  91. {
  92. // Already in our list, so the region went dead and restarted.
  93. m_regions.Remove(regionInfo.RegionHandle);
  94. m_log.Warn("[INTERREGION STANDALONE]: Region registered twice. Region went down and came back up.");
  95. RegionCommsListener regionHost = new RegionCommsListener();
  96. if (m_regionListeners.ContainsKey(regionInfo.RegionHandle))
  97. {
  98. m_regionListeners.Remove(regionInfo.RegionHandle);
  99. }
  100. m_regionListeners.Add(regionInfo.RegionHandle, regionHost);
  101. return regionHost;
  102. }
  103. }
  104. public bool DeregisterRegion(RegionInfo regionInfo)
  105. {
  106. if (m_regions.ContainsKey(regionInfo.RegionHandle))
  107. {
  108. m_regions.Remove(regionInfo.RegionHandle);
  109. if (m_regionListeners.ContainsKey(regionInfo.RegionHandle))
  110. {
  111. m_regionListeners.Remove(regionInfo.RegionHandle);
  112. }
  113. return true;
  114. }
  115. return false;
  116. }
  117. /// <summary>
  118. /// </summary>
  119. /// <param name="regionInfo"></param>
  120. /// <returns></returns>
  121. public List<SimpleRegionInfo> RequestNeighbours(uint x, uint y)
  122. {
  123. // Console.WriteLine("Finding Neighbours to " + regionInfo.RegionHandle);
  124. List<SimpleRegionInfo> neighbours = new List<SimpleRegionInfo>();
  125. foreach (RegionInfo reg in m_regions.Values)
  126. {
  127. // Console.WriteLine("CommsManager- RequestNeighbours() checking region " + reg.RegionLocX + " , "+ reg.RegionLocY);
  128. if (reg.RegionLocX != x || reg.RegionLocY != y)
  129. {
  130. //Console.WriteLine("CommsManager- RequestNeighbours() - found a different region in list, checking location");
  131. if ((reg.RegionLocX > (x - 2)) && (reg.RegionLocX < (x + 2)))
  132. {
  133. if ((reg.RegionLocY > (y - 2)) && (reg.RegionLocY < (y + 2)))
  134. {
  135. neighbours.Add(reg);
  136. }
  137. }
  138. }
  139. }
  140. return neighbours;
  141. }
  142. /// <summary>
  143. ///
  144. /// </summary>
  145. /// <param name="regionHandle"></param>
  146. /// <returns></returns>
  147. public RegionInfo RequestNeighbourInfo(ulong regionHandle)
  148. {
  149. if (m_regions.ContainsKey(regionHandle))
  150. {
  151. return m_regions[regionHandle];
  152. }
  153. return null;
  154. }
  155. public RegionInfo RequestClosestRegion(string regionName)
  156. {
  157. // Don't use this method. It's only for SLURLS and Logins
  158. return null;
  159. }
  160. /// <summary>
  161. ///
  162. /// </summary>
  163. /// <param name="minX"></param>
  164. /// <param name="minY"></param>
  165. /// <param name="maxX"></param>
  166. /// <param name="maxY"></param>
  167. /// <returns></returns>
  168. public List<MapBlockData> RequestNeighbourMapBlocks(int minX, int minY, int maxX, int maxY)
  169. {
  170. List<MapBlockData> mapBlocks = new List<MapBlockData>();
  171. foreach (RegionInfo regInfo in m_regions.Values)
  172. {
  173. if (((regInfo.RegionLocX >= minX) && (regInfo.RegionLocX <= maxX)) &&
  174. ((regInfo.RegionLocY >= minY) && (regInfo.RegionLocY <= maxY)))
  175. {
  176. MapBlockData map = new MapBlockData();
  177. map.Name = regInfo.RegionName;
  178. map.X = (ushort) regInfo.RegionLocX;
  179. map.Y = (ushort) regInfo.RegionLocY;
  180. map.WaterHeight = (byte) regInfo.EstateSettings.waterHeight;
  181. map.MapImageId = regInfo.EstateSettings.terrainImageID;
  182. map.Agents = 1;
  183. map.RegionFlags = 72458694;
  184. map.Access = 13;
  185. mapBlocks.Add(map);
  186. }
  187. }
  188. return mapBlocks;
  189. }
  190. public bool TellRegionToCloseChildConnection(ulong regionHandle, LLUUID agentID)
  191. {
  192. if (m_regionListeners.ContainsKey(regionHandle))
  193. {
  194. return m_regionListeners[regionHandle].TriggerTellRegionToCloseChildConnection(regionHandle, agentID);
  195. }
  196. return false;
  197. }
  198. public virtual bool RegionUp(SearializableRegionInfo sregion, ulong regionhandle)
  199. {
  200. RegionInfo region = new RegionInfo(sregion);
  201. //region.RegionLocX = sregion.X;
  202. //region.RegionLocY = sregion.Y;
  203. //region.SetEndPoint(sregion.IPADDR, sregion.PORT);
  204. //sregion);
  205. if (m_regionListeners.ContainsKey(regionhandle))
  206. {
  207. return m_regionListeners[regionhandle].TriggerRegionUp(region);
  208. }
  209. return false;
  210. }
  211. public virtual bool ChildAgentUpdate(ulong regionHandle, ChildAgentDataUpdate cAgentData)
  212. {
  213. if (m_regionListeners.ContainsKey(regionHandle))
  214. {
  215. // Console.WriteLine("CommsManager- Informing a region to expect child agent");
  216. m_regionListeners[regionHandle].TriggerChildAgentUpdate(regionHandle, cAgentData);
  217. //m_log.Info("[INTER]: " + rdebugRegionName + ":Local BackEnd: Got Listener trigginering local event: " + agentData.firstname + " " + agentData.lastname);
  218. return true;
  219. }
  220. return false;
  221. }
  222. // This function is only here to keep this class in line with the Grid Interface.
  223. // It never gets called.
  224. public virtual Dictionary<string, string> GetGridSettings()
  225. {
  226. Dictionary<string, string> returnGridSettings = new Dictionary<string, string>();
  227. lock (m_queuedGridSettings)
  228. {
  229. returnGridSettings = m_queuedGridSettings;
  230. m_queuedGridSettings.Clear();
  231. }
  232. return returnGridSettings;
  233. }
  234. public virtual void SetForcefulBanlistsDisallowed(ulong regionHandle)
  235. {
  236. m_queuedGridSettings.Add("allow_forceful_banlines", "FALSE");
  237. }
  238. public bool TriggerRegionUp(RegionInfo region, ulong regionhandle)
  239. {
  240. if (m_regionListeners.ContainsKey(regionhandle))
  241. {
  242. return m_regionListeners[regionhandle].TriggerRegionUp(region);
  243. }
  244. return false;
  245. }
  246. public bool TriggerChildAgentUpdate(ulong regionHandle, ChildAgentDataUpdate cAgentData)
  247. {
  248. if (m_regionListeners.ContainsKey(regionHandle))
  249. {
  250. return m_regionListeners[regionHandle].TriggerChildAgentUpdate(regionHandle, cAgentData);
  251. }
  252. return false;
  253. }
  254. public bool TriggerTellRegionToCloseChildConnection(ulong regionHandle, LLUUID agentID)
  255. {
  256. if (m_regionListeners.ContainsKey(regionHandle))
  257. {
  258. return m_regionListeners[regionHandle].TriggerTellRegionToCloseChildConnection(regionHandle, agentID);
  259. }
  260. return false;
  261. }
  262. /// <summary>
  263. ///
  264. /// </summary>
  265. /// <param name="regionHandle"></param>
  266. /// <param name="agentData"></param>
  267. /// <returns></returns>
  268. public bool InformRegionOfChildAgent(ulong regionHandle, AgentCircuitData agentData)
  269. // TODO: should change from agentCircuitData
  270. {
  271. //Console.WriteLine("CommsManager- Trying to Inform a region to expect child agent");
  272. //m_log.Info("[INTER]: " + rdebugRegionName + ":Local BackEnd: Trying to inform region of child agent: " + agentData.firstname + " " + agentData.lastname);
  273. if (m_regionListeners.ContainsKey(regionHandle))
  274. {
  275. // Console.WriteLine("CommsManager- Informing a region to expect child agent");
  276. m_regionListeners[regionHandle].TriggerExpectUser(regionHandle, agentData);
  277. //m_log.Info("[INTER]: " + rdebugRegionName + ":Local BackEnd: Got Listener trigginering local event: " + agentData.firstname + " " + agentData.lastname);
  278. return true;
  279. }
  280. return false;
  281. }
  282. public bool InformRegionOfPrimCrossing(ulong regionHandle, LLUUID primID, string objData, int XMLMethod)
  283. {
  284. if (m_regionListeners.ContainsKey(regionHandle))
  285. {
  286. m_regionListeners[regionHandle].TriggerExpectPrim(regionHandle, primID, objData, XMLMethod);
  287. return true;
  288. }
  289. return false;
  290. }
  291. /// <summary>
  292. ///
  293. /// </summary>
  294. /// <param name="regionHandle"></param>
  295. /// <param name="agentID"></param>
  296. /// <param name="position"></param>
  297. /// <returns></returns>
  298. public bool ExpectAvatarCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position, bool isFlying)
  299. {
  300. if (m_regionListeners.ContainsKey(regionHandle))
  301. {
  302. // Console.WriteLine("CommsManager- Informing a region to expect avatar crossing");
  303. m_regionListeners[regionHandle].TriggerExpectAvatarCrossing(regionHandle, agentID, position, isFlying);
  304. return true;
  305. }
  306. return false;
  307. }
  308. public bool ExpectPrimCrossing(ulong regionHandle, LLUUID primID, LLVector3 position, bool isPhysical)
  309. {
  310. if (m_regionListeners.ContainsKey(regionHandle))
  311. {
  312. m_regionListeners[regionHandle].TriggerExpectPrimCrossing(regionHandle, primID, position, isPhysical);
  313. return true;
  314. }
  315. return false;
  316. }
  317. public bool AcknowledgeAgentCrossed(ulong regionHandle, LLUUID agentId)
  318. {
  319. if (m_regionListeners.ContainsKey(regionHandle))
  320. {
  321. return true;
  322. }
  323. return false;
  324. }
  325. public bool AcknowledgePrimCrossed(ulong regionHandle, LLUUID primID)
  326. {
  327. if (m_regionListeners.ContainsKey(regionHandle))
  328. {
  329. return true;
  330. }
  331. return false;
  332. }
  333. /// <summary>
  334. /// Is a Sandbox mode method, used by the local Login server to inform a region of a connection user/session
  335. /// </summary>
  336. /// <param name="regionHandle"></param>
  337. /// <param name="loginData"></param>
  338. /// <returns></returns>
  339. public void AddNewSession(ulong regionHandle, Login loginData)
  340. {
  341. AgentCircuitData agent = new AgentCircuitData();
  342. agent.AgentID = loginData.Agent;
  343. agent.firstname = loginData.First;
  344. agent.lastname = loginData.Last;
  345. agent.SessionID = loginData.Session;
  346. agent.SecureSessionID = loginData.SecureSession;
  347. agent.circuitcode = loginData.CircuitCode;
  348. agent.BaseFolder = loginData.BaseFolder;
  349. agent.InventoryFolder = loginData.InventoryFolder;
  350. agent.startpos = loginData.StartPos;
  351. agent.CapsPath = loginData.CapsPath;
  352. TriggerExpectUser(regionHandle, agent);
  353. }
  354. public void TriggerExpectUser(ulong regionHandle, AgentCircuitData agent)
  355. {
  356. //m_log.Info("[INTER]: " + rdebugRegionName + ":Local BackEnd: Other region is sending child agent our way: " + agent.firstname + " " + agent.lastname);
  357. if (m_regionListeners.ContainsKey(regionHandle))
  358. {
  359. //m_log.Info("[INTER]: " + rdebugRegionName + ":Local BackEnd: FoundLocalRegion To send it to: " + agent.firstname + " " + agent.lastname);
  360. m_regionListeners[regionHandle].TriggerExpectUser(regionHandle, agent);
  361. }
  362. }
  363. public void TriggerExpectPrim(ulong regionHandle, LLUUID primID, string objData, int XMLMethod)
  364. {
  365. if (m_regionListeners.ContainsKey(regionHandle))
  366. {
  367. m_regionListeners[regionHandle].TriggerExpectPrim(regionHandle, primID, objData, XMLMethod);
  368. }
  369. }
  370. public void PingCheckReply(Hashtable respData)
  371. {
  372. foreach (ulong region in m_regions.Keys)
  373. {
  374. Hashtable regData = new Hashtable();
  375. RegionInfo reg = m_regions[region];
  376. regData["status"] = "active";
  377. regData["handle"] = region.ToString();
  378. respData[reg.RegionID.ToString()] = regData;
  379. }
  380. }
  381. public bool TriggerExpectAvatarCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position, bool isFlying)
  382. {
  383. if (m_regionListeners.ContainsKey(regionHandle))
  384. {
  385. return m_regionListeners[regionHandle].TriggerExpectAvatarCrossing(regionHandle, agentID, position,
  386. isFlying);
  387. }
  388. return false;
  389. }
  390. public bool TriggerExpectPrimCrossing(ulong regionHandle, LLUUID primID, LLVector3 position, bool isPhysical)
  391. {
  392. if (m_regionListeners.ContainsKey(regionHandle))
  393. {
  394. return
  395. m_regionListeners[regionHandle].TriggerExpectPrimCrossing(regionHandle, primID, position, isPhysical);
  396. }
  397. return false;
  398. }
  399. public bool IncomingChildAgent(ulong regionHandle, AgentCircuitData agentData)
  400. {
  401. // m_log.Info("[INTER]: " + rdebugRegionName + ":Local BackEnd: Other local region is sending child agent our way: " + agentData.firstname + " " + agentData.lastname);
  402. if (m_regionListeners.ContainsKey(regionHandle))
  403. {
  404. //m_log.Info("[INTER]: " + rdebugRegionName + ":Local BackEnd: found local region to trigger event on: " + agentData.firstname + " " + agentData.lastname);
  405. TriggerExpectUser(regionHandle, agentData);
  406. return true;
  407. }
  408. return false;
  409. }
  410. }
  411. }