TestLocalCommsManager.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using libsecondlife;
  6. using OpenSim.Framework;
  7. using OpenSim.Framework.Interfaces;
  8. using OpenSim.Framework.Types;
  9. namespace OpenGrid.Framework.Communications
  10. {
  11. public class TestLocalCommsManager : RegionServerCommsManager
  12. {
  13. protected Dictionary<ulong, RegionInfo> regions = new Dictionary<ulong,RegionInfo>();
  14. protected Dictionary<ulong, RegionCommsHostBase> regionHosts = new Dictionary<ulong, RegionCommsHostBase>();
  15. public TestLocalCommsManager()
  16. {
  17. }
  18. /// <summary>
  19. ///
  20. /// </summary>
  21. /// <param name="regionInfo"></param>
  22. /// <returns></returns>
  23. public override RegionCommsHostBase RegisterRegion(RegionInfo regionInfo)
  24. {
  25. //Console.WriteLine("CommsManager - Region " + regionInfo.RegionHandle + " , " + regionInfo.RegionLocX + " , "+ regionInfo.RegionLocY +" is registering");
  26. if (!this.regions.ContainsKey((uint)regionInfo.RegionHandle))
  27. {
  28. //Console.WriteLine("CommsManager - Adding Region " + regionInfo.RegionHandle );
  29. this.regions.Add(regionInfo.RegionHandle, regionInfo);
  30. RegionCommsHostBase regionHost = new RegionCommsHostBase();
  31. this.regionHosts.Add(regionInfo.RegionHandle, regionHost);
  32. return regionHost;
  33. }
  34. //already in our list of regions so for now lets return null
  35. return null;
  36. }
  37. /// <summary>
  38. ///
  39. /// </summary>
  40. /// <param name="regionInfo"></param>
  41. /// <returns></returns>
  42. public override List<RegionInfo> RequestNeighbours(RegionInfo regionInfo)
  43. {
  44. // Console.WriteLine("Finding Neighbours to " + regionInfo.RegionHandle);
  45. List<RegionInfo> neighbours = new List<RegionInfo>();
  46. foreach (RegionInfo reg in this.regions.Values)
  47. {
  48. // Console.WriteLine("CommsManager- RequestNeighbours() checking region " + reg.RegionLocX + " , "+ reg.RegionLocY);
  49. if (reg.RegionHandle != regionInfo.RegionHandle)
  50. {
  51. //Console.WriteLine("CommsManager- RequestNeighbours() - found a different region in list, checking location");
  52. if ((reg.RegionLocX > (regionInfo.RegionLocX - 2)) && (reg.RegionLocX < (regionInfo.RegionLocX + 2)))
  53. {
  54. if ((reg.RegionLocY > (regionInfo.RegionLocY - 2)) && (reg.RegionLocY < (regionInfo.RegionLocY + 2)))
  55. {
  56. neighbours.Add(reg);
  57. }
  58. }
  59. }
  60. }
  61. return neighbours;
  62. }
  63. /// <summary>
  64. ///
  65. /// </summary>
  66. /// <returns></returns>
  67. public override bool InformNeighbourOfChildAgent(ulong regionHandle, AgentCircuitData agentData) //should change from agentCircuitData
  68. {
  69. //Console.WriteLine("CommsManager- Trying to Inform a region to expect child agent");
  70. if (this.regionHosts.ContainsKey(regionHandle))
  71. {
  72. // Console.WriteLine("CommsManager- Informing a region to expect child agent");
  73. this.regionHosts[regionHandle].TriggerExpectUser(regionHandle, agentData);
  74. return true;
  75. }
  76. return false;
  77. }
  78. /// <summary>
  79. /// Is a Sandbox mode method, used by the local Login server to inform a region of a connection user/session
  80. /// </summary>
  81. /// <param name="regionHandle"></param>
  82. /// <param name="loginData"></param>
  83. /// <returns></returns>
  84. public bool AddNewSession(ulong regionHandle, Login loginData)
  85. {
  86. //Console.WriteLine(" comms manager been told to expect new user");
  87. AgentCircuitData agent = new AgentCircuitData();
  88. agent.AgentID = loginData.Agent;
  89. agent.firstname = loginData.First;
  90. agent.lastname = loginData.Last;
  91. agent.SessionID = loginData.Session;
  92. agent.SecureSessionID = loginData.SecureSession;
  93. agent.circuitcode = loginData.CircuitCode;
  94. agent.BaseFolder = loginData.BaseFolder;
  95. agent.InventoryFolder = loginData.InventoryFolder;
  96. agent.startpos = new LLVector3(128, 128, 70);
  97. if (this.regionHosts.ContainsKey(regionHandle))
  98. {
  99. this.regionHosts[regionHandle].TriggerExpectUser(regionHandle, agent);
  100. return true;
  101. }
  102. // region not found
  103. return false;
  104. }
  105. }
  106. }