SceneBase.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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.Generic;
  29. using System.Reflection;
  30. using System.Threading;
  31. using OpenMetaverse;
  32. using log4net;
  33. using OpenSim.Framework;
  34. using OpenSim.Framework.Communications.Cache;
  35. using OpenSim.Region.Environment.Interfaces;
  36. namespace OpenSim.Region.Environment.Scenes
  37. {
  38. public abstract class SceneBase : IScene
  39. {
  40. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  41. #region Events
  42. public event restart OnRestart;
  43. #endregion
  44. #region Fields
  45. /// <summary>
  46. /// The last allocated local prim id. When a new local id is requested, the next number in the sequence is
  47. /// dispensed.
  48. /// </summary>
  49. protected uint m_lastAllocatedLocalId = 720000;
  50. private readonly Mutex _primAllocateMutex = new Mutex(false);
  51. private readonly ClientManager m_clientManager = new ClientManager();
  52. public ClientManager ClientManager
  53. {
  54. get { return m_clientManager; }
  55. }
  56. protected ulong m_regionHandle;
  57. protected string m_regionName;
  58. protected RegionInfo m_regInfo;
  59. //public TerrainEngine Terrain;
  60. public ITerrainChannel Heightmap;
  61. /// <value>
  62. /// Allows retrieval of land information for this scene.
  63. /// </value>
  64. public ILandChannel LandChannel;
  65. /// <value>
  66. /// Manage events that occur in this scene (avatar movement, script rez, etc.). Commonly used by region modules
  67. /// to subscribe to scene events.
  68. /// </value>
  69. public EventManager EventManager
  70. {
  71. get { return m_eventManager; }
  72. }
  73. protected EventManager m_eventManager;
  74. protected ScenePermissions m_permissions;
  75. public ScenePermissions Permissions
  76. {
  77. get { return m_permissions; }
  78. }
  79. protected string m_datastore;
  80. private AssetCache m_assetCache;
  81. public AssetCache AssetCache
  82. {
  83. get { return m_assetCache; }
  84. set { m_assetCache = value; }
  85. }
  86. protected RegionStatus m_regStatus;
  87. public RegionStatus Region_Status
  88. {
  89. get { return m_regStatus; }
  90. set { m_regStatus = value; }
  91. }
  92. #endregion
  93. #region Update Methods
  94. /// <summary>
  95. /// Normally called once every frame/tick to let the world preform anything required (like running the physics simulation)
  96. /// </summary>
  97. public abstract void Update();
  98. #endregion
  99. #region Terrain Methods
  100. /// <summary>
  101. /// Loads the World heightmap
  102. /// </summary>
  103. public abstract void LoadWorldMap();
  104. /// <summary>
  105. /// Send the region heightmap to the client
  106. /// </summary>
  107. /// <param name="RemoteClient">Client to send to</param>
  108. public virtual void SendLayerData(IClientAPI RemoteClient)
  109. {
  110. RemoteClient.SendLayerData(Heightmap.GetFloatsSerialised());
  111. }
  112. #endregion
  113. #region Add/Remove Agent/Avatar
  114. /// <summary>
  115. /// Register the new client with the scene. The client starts off as a child agent - the later agent crossing
  116. /// will promote it to a root agent during login.
  117. /// </summary>
  118. /// <param name="client"></param
  119. public abstract void AddNewClient(IClientAPI client);
  120. /// <summary>
  121. /// Remove a client from the scene
  122. /// </summary>
  123. /// <param name="agentID"></param>
  124. public abstract void RemoveClient(UUID agentID);
  125. public abstract void CloseAllAgents(uint circuitcode);
  126. #endregion
  127. /// <summary>
  128. ///
  129. /// </summary>
  130. /// <returns></returns>
  131. public virtual RegionInfo RegionInfo
  132. {
  133. get { return m_regInfo; }
  134. }
  135. #region admin stuff
  136. /// <summary>
  137. /// Region Restart - Seconds till restart.
  138. /// </summary>
  139. /// <param name="seconds"></param>
  140. public virtual void Restart(int seconds)
  141. {
  142. m_log.Error("[REGION]: passing Restart Message up the namespace");
  143. restart handlerPhysicsCrash = OnRestart;
  144. if (handlerPhysicsCrash != null)
  145. handlerPhysicsCrash(RegionInfo);
  146. }
  147. public virtual bool PresenceChildStatus(UUID avatarID)
  148. {
  149. return false;
  150. }
  151. public abstract bool OtherRegionUp(RegionInfo thisRegion);
  152. public virtual string GetSimulatorVersion()
  153. {
  154. return "OpenSimulator Server";
  155. }
  156. #endregion
  157. #region Shutdown
  158. /// <summary>
  159. /// Tidy before shutdown
  160. /// </summary>
  161. public virtual void Close()
  162. {
  163. try
  164. {
  165. EventManager.TriggerShutdown();
  166. }
  167. catch (Exception e)
  168. {
  169. m_log.Error("[SCENE]: SceneBase.cs: Close() - Failed with exception " + e.ToString());
  170. }
  171. }
  172. #endregion
  173. /// <summary>
  174. /// XXX These two methods are very temporary
  175. /// XXX Diva: this is really truly horrible; must...move...to...LL client...stack...
  176. /// </summary>
  177. protected Dictionary<UUID, string> capsPaths = new Dictionary<UUID, string>();
  178. protected Dictionary<UUID, Dictionary<ulong, string>> childrenSeeds = new Dictionary<UUID, Dictionary<ulong, string>>();
  179. public string GetCapsPath(UUID agentId)
  180. {
  181. if (capsPaths.ContainsKey(agentId))
  182. {
  183. return capsPaths[agentId];
  184. }
  185. return null;
  186. }
  187. public Dictionary<ulong, string> GetChildrenSeeds(UUID agentID)
  188. {
  189. Dictionary<ulong, string> seeds = null;
  190. if (childrenSeeds.TryGetValue(agentID, out seeds))
  191. return seeds;
  192. return new Dictionary<ulong, string>();
  193. }
  194. public void DropChildSeed(UUID agentID, ulong handle)
  195. {
  196. Dictionary<ulong, string> seeds;
  197. if (childrenSeeds.TryGetValue(agentID, out seeds))
  198. {
  199. seeds.Remove(handle);
  200. }
  201. }
  202. public string GetChildSeed(UUID agentID, ulong handle)
  203. {
  204. Dictionary<ulong, string> seeds;
  205. if (childrenSeeds.TryGetValue(agentID, out seeds))
  206. {
  207. return seeds[handle];
  208. }
  209. return null;
  210. }
  211. public void SetChildrenSeed(UUID agentID, Dictionary<ulong, string> value)
  212. {
  213. //Console.WriteLine(" !!! Setting child seeds in {0} to {1}", RegionInfo.RegionName, value.Count);
  214. childrenSeeds[agentID] = value;
  215. }
  216. public void DumpChildrenSeeds(UUID agentID)
  217. {
  218. Console.WriteLine("================ ChildrenSeed {0} ================", RegionInfo.RegionName);
  219. foreach (KeyValuePair<ulong, string> kvp in childrenSeeds[agentID])
  220. {
  221. uint x, y;
  222. Utils.LongToUInts(kvp.Key, out x, out y);
  223. x = x / Constants.RegionSize;
  224. y = y / Constants.RegionSize;
  225. Console.WriteLine(" >> {0}, {1}: {2}", x, y, kvp.Value);
  226. }
  227. }
  228. /// <summary>
  229. /// Returns a new unallocated local ID
  230. /// </summary>
  231. /// <returns>A brand new local ID</returns>
  232. protected internal uint AllocateLocalId()
  233. {
  234. uint myID;
  235. _primAllocateMutex.WaitOne();
  236. myID = ++m_lastAllocatedLocalId;
  237. _primAllocateMutex.ReleaseMutex();
  238. return myID;
  239. }
  240. public virtual T RequestModuleInterface<T>()
  241. {
  242. return default(T);
  243. }
  244. public virtual T[] RequestModuleInterfaces<T>()
  245. {
  246. return new T[] { default(T) };
  247. }
  248. }
  249. }