aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/SceneBase.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/SceneBase.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneBase.cs603
1 files changed, 1 insertions, 602 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneBase.cs b/OpenSim/Region/Framework/Scenes/SceneBase.cs
index c4671f0..f420f69 100644
--- a/OpenSim/Region/Framework/Scenes/SceneBase.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneBase.cs
@@ -1,4 +1,3 @@
1<<<<<<< HEAD
2/* 1/*
3 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
4 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
@@ -201,7 +200,7 @@ namespace OpenSim.Region.Framework.Scenes
201 /// If -1 then updates until shutdown. 200 /// If -1 then updates until shutdown.
202 /// </param> 201 /// </param>
203 /// <returns>true if update completed within minimum frame time, false otherwise.</returns> 202 /// <returns>true if update completed within minimum frame time, false otherwise.</returns>
204 public abstract bool Update(int frames); 203 public abstract void Update(int frames);
205 204
206 #endregion 205 #endregion
207 206
@@ -635,603 +634,3 @@ namespace OpenSim.Region.Framework.Scenes
635 public abstract bool CheckClient(UUID agentID, System.Net.IPEndPoint ep); 634 public abstract bool CheckClient(UUID agentID, System.Net.IPEndPoint ep);
636 } 635 }
637} 636}
638=======
639/*
640 * Copyright (c) Contributors, http://opensimulator.org/
641 * See CONTRIBUTORS.TXT for a full list of copyright holders.
642 *
643 * Redistribution and use in source and binary forms, with or without
644 * modification, are permitted provided that the following conditions are met:
645 * * Redistributions of source code must retain the above copyright
646 * notice, this list of conditions and the following disclaimer.
647 * * Redistributions in binary form must reproduce the above copyright
648 * notice, this list of conditions and the following disclaimer in the
649 * documentation and/or other materials provided with the distribution.
650 * * Neither the name of the OpenSimulator Project nor the
651 * names of its contributors may be used to endorse or promote products
652 * derived from this software without specific prior written permission.
653 *
654 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
655 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
656 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
657 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
658 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
659 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
660 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
661 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
662 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
663 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
664 */
665
666using System;
667using System.Collections.Generic;
668using System.Reflection;
669using System.Threading;
670using OpenMetaverse;
671using log4net;
672using Nini.Config;
673using OpenSim.Framework;
674using OpenSim.Framework.Console;
675
676using OpenSim.Region.Framework.Interfaces;
677using GridRegion = OpenSim.Services.Interfaces.GridRegion;
678
679namespace OpenSim.Region.Framework.Scenes
680{
681 public abstract class SceneBase : IScene
682 {
683 protected static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
684 protected static readonly string LogHeader = "[SCENE]";
685
686 #region Events
687
688 public event restart OnRestart;
689
690 #endregion
691
692 #region Fields
693
694 public string Name { get { return RegionInfo.RegionName; } }
695
696 public IConfigSource Config
697 {
698 get { return GetConfig(); }
699 }
700
701 protected virtual IConfigSource GetConfig()
702 {
703 return null;
704 }
705
706 /// <value>
707 /// All the region modules attached to this scene.
708 /// </value>
709 public Dictionary<string, IRegionModuleBase> RegionModules
710 {
711 get { return m_regionModules; }
712 }
713 private Dictionary<string, IRegionModuleBase> m_regionModules = new Dictionary<string, IRegionModuleBase>();
714
715 /// <value>
716 /// The module interfaces available from this scene.
717 /// </value>
718 protected Dictionary<Type, List<object>> ModuleInterfaces = new Dictionary<Type, List<object>>();
719
720 protected Dictionary<string, object> ModuleAPIMethods = new Dictionary<string, object>();
721
722 /// <value>
723 /// The module commanders available from this scene
724 /// </value>
725 protected Dictionary<string, ICommander> m_moduleCommanders = new Dictionary<string, ICommander>();
726
727 /// <value>
728 /// Registered classes that are capable of creating entities.
729 /// </value>
730 protected Dictionary<PCode, IEntityCreator> m_entityCreators = new Dictionary<PCode, IEntityCreator>();
731
732 /// <summary>
733 /// The last allocated local prim id. When a new local id is requested, the next number in the sequence is
734 /// dispensed.
735 /// </summary>
736 protected uint m_lastAllocatedLocalId = 720000;
737
738 private readonly Mutex _primAllocateMutex = new Mutex(false);
739
740 protected readonly ClientManager m_clientManager = new ClientManager();
741
742 public bool LoginsEnabled
743 {
744 get
745 {
746 return m_loginsEnabled;
747 }
748
749 set
750 {
751 if (m_loginsEnabled != value)
752 {
753 m_loginsEnabled = value;
754 EventManager.TriggerRegionLoginsStatusChange(this);
755 }
756 }
757 }
758 private bool m_loginsEnabled;
759
760 public bool Ready
761 {
762 get
763 {
764 return m_ready;
765 }
766
767 set
768 {
769 if (m_ready != value)
770 {
771 m_ready = value;
772 EventManager.TriggerRegionReadyStatusChange(this);
773 }
774 }
775 }
776 private bool m_ready;
777
778 public float TimeDilation
779 {
780 get { return 1.0f; }
781 }
782
783 protected ulong m_regionHandle;
784 protected string m_regionName;
785
786 public ITerrainChannel Heightmap;
787
788 /// <value>
789 /// Allows retrieval of land information for this scene.
790 /// </value>
791 public ILandChannel LandChannel;
792
793 /// <value>
794 /// Manage events that occur in this scene (avatar movement, script rez, etc.). Commonly used by region modules
795 /// to subscribe to scene events.
796 /// </value>
797 public EventManager EventManager
798 {
799 get { return m_eventManager; }
800 }
801 protected EventManager m_eventManager;
802
803 protected ScenePermissions m_permissions;
804 public ScenePermissions Permissions
805 {
806 get { return m_permissions; }
807 }
808
809 protected string m_datastore;
810
811 /* Used by the loadbalancer plugin on GForge */
812 protected RegionStatus m_regStatus;
813 public RegionStatus RegionStatus
814 {
815 get { return m_regStatus; }
816 set { m_regStatus = value; }
817 }
818
819 #endregion
820
821 public SceneBase(RegionInfo regInfo)
822 {
823 RegionInfo = regInfo;
824 }
825
826 #region Update Methods
827
828 /// <summary>
829 /// Called to update the scene loop by a number of frames and until shutdown.
830 /// </summary>
831 /// <param name="frames">
832 /// Number of frames to update. Exits on shutdown even if there are frames remaining.
833 /// If -1 then updates until shutdown.
834 /// </param>
835 public abstract void Update(int frames);
836
837 #endregion
838
839 #region Terrain Methods
840
841 /// <summary>
842 /// Loads the World heightmap
843 /// </summary>
844 public abstract void LoadWorldMap();
845
846 /// <summary>
847 /// Send the region heightmap to the client
848 /// </summary>
849 /// <param name="RemoteClient">Client to send to</param>
850 public virtual void SendLayerData(IClientAPI RemoteClient)
851 {
852// RemoteClient.SendLayerData(Heightmap.GetFloatsSerialised());
853 ITerrainModule terrModule = RequestModuleInterface<ITerrainModule>();
854 if (terrModule != null)
855 {
856 terrModule.PushTerrain(RemoteClient);
857 }
858 }
859
860 #endregion
861
862 #region Add/Remove Agent/Avatar
863
864 public abstract ISceneAgent AddNewAgent(IClientAPI client, PresenceType type);
865
866 public abstract bool CloseAgent(UUID agentID, bool force);
867
868 public bool TryGetScenePresence(UUID agentID, out object scenePresence)
869 {
870 scenePresence = null;
871 ScenePresence sp = null;
872 if (TryGetScenePresence(agentID, out sp))
873 {
874 scenePresence = sp;
875 return true;
876 }
877
878 return false;
879 }
880
881 /// <summary>
882 /// Try to get a scene presence from the scene
883 /// </summary>
884 /// <param name="agentID"></param>
885 /// <param name="scenePresence">null if there is no scene presence with the given agent id</param>
886 /// <returns>true if there was a scene presence with the given id, false otherwise.</returns>
887 public abstract bool TryGetScenePresence(UUID agentID, out ScenePresence scenePresence);
888
889 #endregion
890
891 /// <summary>
892 ///
893 /// </summary>
894 /// <returns></returns>
895 public virtual RegionInfo RegionInfo { get; private set; }
896
897 #region admin stuff
898
899 public abstract void OtherRegionUp(GridRegion otherRegion);
900
901 public virtual string GetSimulatorVersion()
902 {
903 return "OpenSimulator Server";
904 }
905
906 #endregion
907
908 #region Shutdown
909
910 /// <summary>
911 /// Tidy before shutdown
912 /// </summary>
913 public virtual void Close()
914 {
915 try
916 {
917 EventManager.TriggerShutdown();
918 }
919 catch (Exception e)
920 {
921 m_log.Error(string.Format("[SCENE]: SceneBase.cs: Close() - Failed with exception ", e));
922 }
923 }
924
925 #endregion
926
927 /// <summary>
928 /// Returns a new unallocated local ID
929 /// </summary>
930 /// <returns>A brand new local ID</returns>
931 public uint AllocateLocalId()
932 {
933 uint myID;
934
935 _primAllocateMutex.WaitOne();
936 myID = ++m_lastAllocatedLocalId;
937 _primAllocateMutex.ReleaseMutex();
938
939 return myID;
940 }
941
942 public uint AllocatePresenceLocalId()
943 {
944 uint myID;
945
946 _primAllocateMutex.WaitOne();
947 myID = ++m_lastAllocatedLocalId;
948 ++m_lastAllocatedLocalId;
949 _primAllocateMutex.ReleaseMutex();
950
951 return myID;
952 }
953
954 #region Module Methods
955
956 /// <summary>
957 /// Add a region-module to this scene. TODO: This will replace AddModule in the future.
958 /// </summary>
959 /// <param name="name"></param>
960 /// <param name="module"></param>
961 public void AddRegionModule(string name, IRegionModuleBase module)
962 {
963 if (!RegionModules.ContainsKey(name))
964 {
965 RegionModules.Add(name, module);
966 }
967 }
968
969 public void RemoveRegionModule(string name)
970 {
971 RegionModules.Remove(name);
972 }
973
974 /// <summary>
975 /// Register a module commander.
976 /// </summary>
977 /// <param name="commander"></param>
978 public void RegisterModuleCommander(ICommander commander)
979 {
980 lock (m_moduleCommanders)
981 {
982 m_moduleCommanders.Add(commander.Name, commander);
983 }
984 }
985
986 /// <summary>
987 /// Unregister a module commander and all its commands
988 /// </summary>
989 /// <param name="name"></param>
990 public void UnregisterModuleCommander(string name)
991 {
992 lock (m_moduleCommanders)
993 {
994 ICommander commander;
995 if (m_moduleCommanders.TryGetValue(name, out commander))
996 m_moduleCommanders.Remove(name);
997 }
998 }
999
1000 /// <summary>
1001 /// Get a module commander
1002 /// </summary>
1003 /// <param name="name"></param>
1004 /// <returns>The module commander, null if no module commander with that name was found</returns>
1005 public ICommander GetCommander(string name)
1006 {
1007 lock (m_moduleCommanders)
1008 {
1009 if (m_moduleCommanders.ContainsKey(name))
1010 return m_moduleCommanders[name];
1011 }
1012
1013 return null;
1014 }
1015
1016 public Dictionary<string, ICommander> GetCommanders()
1017 {
1018 return m_moduleCommanders;
1019 }
1020
1021 /// <summary>
1022 /// Register an interface to a region module. This allows module methods to be called directly as
1023 /// well as via events. If there is already a module registered for this interface, it is not replaced
1024 /// (is this the best behaviour?)
1025 /// </summary>
1026 /// <param name="mod"></param>
1027 public void RegisterModuleInterface<M>(M mod)
1028 {
1029// m_log.DebugFormat("[SCENE BASE]: Registering interface {0}", typeof(M));
1030
1031 List<Object> l = null;
1032 if (!ModuleInterfaces.TryGetValue(typeof(M), out l))
1033 {
1034 l = new List<Object>();
1035 ModuleInterfaces.Add(typeof(M), l);
1036 }
1037
1038 if (l.Count > 0)
1039 return;
1040
1041 l.Add(mod);
1042
1043 if (mod is IEntityCreator)
1044 {
1045 IEntityCreator entityCreator = (IEntityCreator)mod;
1046 foreach (PCode pcode in entityCreator.CreationCapabilities)
1047 {
1048 m_entityCreators[pcode] = entityCreator;
1049 }
1050 }
1051 }
1052
1053 public void UnregisterModuleInterface<M>(M mod)
1054 {
1055 List<Object> l;
1056 if (ModuleInterfaces.TryGetValue(typeof(M), out l))
1057 {
1058 if (l.Remove(mod))
1059 {
1060 if (mod is IEntityCreator)
1061 {
1062 IEntityCreator entityCreator = (IEntityCreator)mod;
1063 foreach (PCode pcode in entityCreator.CreationCapabilities)
1064 {
1065 m_entityCreators[pcode] = null;
1066 }
1067 }
1068 }
1069 }
1070 }
1071
1072 public void StackModuleInterface<M>(M mod)
1073 {
1074 List<Object> l;
1075 if (ModuleInterfaces.ContainsKey(typeof(M)))
1076 l = ModuleInterfaces[typeof(M)];
1077 else
1078 l = new List<Object>();
1079
1080 if (l.Contains(mod))
1081 return;
1082
1083 l.Add(mod);
1084
1085 if (mod is IEntityCreator)
1086 {
1087 IEntityCreator entityCreator = (IEntityCreator)mod;
1088 foreach (PCode pcode in entityCreator.CreationCapabilities)
1089 {
1090 m_entityCreators[pcode] = entityCreator;
1091 }
1092 }
1093
1094 ModuleInterfaces[typeof(M)] = l;
1095 }
1096
1097 /// <summary>
1098 /// For the given interface, retrieve the region module which implements it.
1099 /// </summary>
1100 /// <returns>null if there is no registered module implementing that interface</returns>
1101 public T RequestModuleInterface<T>()
1102 {
1103 if (ModuleInterfaces.ContainsKey(typeof(T)) &&
1104 (ModuleInterfaces[typeof(T)].Count > 0))
1105 return (T)ModuleInterfaces[typeof(T)][0];
1106 else
1107 return default(T);
1108 }
1109
1110 /// <summary>
1111 /// For the given interface, retrieve an array of region modules that implement it.
1112 /// </summary>
1113 /// <returns>an empty array if there are no registered modules implementing that interface</returns>
1114 public T[] RequestModuleInterfaces<T>()
1115 {
1116 if (ModuleInterfaces.ContainsKey(typeof(T)))
1117 {
1118 List<T> ret = new List<T>();
1119
1120 foreach (Object o in ModuleInterfaces[typeof(T)])
1121 ret.Add((T)o);
1122 return ret.ToArray();
1123 }
1124 else
1125 {
1126 return new T[] {};
1127 }
1128 }
1129
1130 #endregion
1131
1132 /// <summary>
1133 /// Call this from a region module to add a command to the OpenSim console.
1134 /// </summary>
1135 /// <param name="mod"></param>
1136 /// <param name="command"></param>
1137 /// <param name="shorthelp"></param>
1138 /// <param name="longhelp"></param>
1139 /// <param name="callback"></param>
1140 public void AddCommand(IRegionModuleBase module, string command, string shorthelp, string longhelp, CommandDelegate callback)
1141 {
1142 AddCommand(module, command, shorthelp, longhelp, string.Empty, callback);
1143 }
1144
1145 /// <summary>
1146 /// Call this from a region module to add a command to the OpenSim console.
1147 /// </summary>
1148 /// <param name="mod">
1149 /// The use of IRegionModuleBase is a cheap trick to get a different method signature,
1150 /// though all new modules should be using interfaces descended from IRegionModuleBase anyway.
1151 /// </param>
1152 /// <param name="category">
1153 /// Category of the command. This is the section under which it will appear when the user asks for help
1154 /// </param>
1155 /// <param name="command"></param>
1156 /// <param name="shorthelp"></param>
1157 /// <param name="longhelp"></param>
1158 /// <param name="callback"></param>
1159 public void AddCommand(
1160 string category, IRegionModuleBase module, string command, string shorthelp, string longhelp, CommandDelegate callback)
1161 {
1162 AddCommand(category, module, command, shorthelp, longhelp, string.Empty, callback);
1163 }
1164
1165 /// <summary>
1166 /// Call this from a region module to add a command to the OpenSim console.
1167 /// </summary>
1168 /// <param name="mod"></param>
1169 /// <param name="command"></param>
1170 /// <param name="shorthelp"></param>
1171 /// <param name="longhelp"></param>
1172 /// <param name="descriptivehelp"></param>
1173 /// <param name="callback"></param>
1174 public void AddCommand(IRegionModuleBase module, string command, string shorthelp, string longhelp, string descriptivehelp, CommandDelegate callback)
1175 {
1176 string moduleName = "";
1177
1178 if (module != null)
1179 moduleName = module.Name;
1180
1181 AddCommand(moduleName, module, command, shorthelp, longhelp, descriptivehelp, callback);
1182 }
1183
1184 /// <summary>
1185 /// Call this from a region module to add a command to the OpenSim console.
1186 /// </summary>
1187 /// <param name="category">
1188 /// Category of the command. This is the section under which it will appear when the user asks for help
1189 /// </param>
1190 /// <param name="mod"></param>
1191 /// <param name="command"></param>
1192 /// <param name="shorthelp"></param>
1193 /// <param name="longhelp"></param>
1194 /// <param name="descriptivehelp"></param>
1195 /// <param name="callback"></param>
1196 public void AddCommand(
1197 string category, IRegionModuleBase module, string command,
1198 string shorthelp, string longhelp, string descriptivehelp, CommandDelegate callback)
1199 {
1200 if (MainConsole.Instance == null)
1201 return;
1202
1203 bool shared = false;
1204
1205 if (module != null)
1206 shared = module is ISharedRegionModule;
1207
1208 MainConsole.Instance.Commands.AddCommand(
1209 category, shared, command, shorthelp, longhelp, descriptivehelp, callback);
1210 }
1211
1212 public virtual ISceneObject DeserializeObject(string representation)
1213 {
1214 return null;
1215 }
1216
1217 public virtual bool AllowScriptCrossings
1218 {
1219 get { return false; }
1220 }
1221
1222 public virtual void Start()
1223 {
1224 }
1225
1226 public void Restart()
1227 {
1228 // This has to be here to fire the event
1229 restart handlerPhysicsCrash = OnRestart;
1230 if (handlerPhysicsCrash != null)
1231 handlerPhysicsCrash(RegionInfo);
1232 }
1233
1234 public abstract bool CheckClient(UUID agentID, System.Net.IPEndPoint ep);
1235 }
1236}
1237>>>>>>> avn/ubitvar