LocalBackEndServices.cs 19 KB

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