aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Scenes/Scene.cs
diff options
context:
space:
mode:
authorMW2007-11-03 19:14:22 +0000
committerMW2007-11-03 19:14:22 +0000
commitdabbdec2cdf2c1056e4ebb8aec38302a1fa9eba4 (patch)
treeee886c072810521bd56b7124d53e093a8bc9cbf8 /OpenSim/Region/Environment/Scenes/Scene.cs
parenttiny commit to prepare for the first proper part of Scene.cs refactoring. (diff)
downloadopensim-SC_OLD-dabbdec2cdf2c1056e4ebb8aec38302a1fa9eba4.zip
opensim-SC_OLD-dabbdec2cdf2c1056e4ebb8aec38302a1fa9eba4.tar.gz
opensim-SC_OLD-dabbdec2cdf2c1056e4ebb8aec38302a1fa9eba4.tar.bz2
opensim-SC_OLD-dabbdec2cdf2c1056e4ebb8aec38302a1fa9eba4.tar.xz
First part of Scene refactoring:
Started the move of some of the methods from scene into a inner class (currently called InnerScene.cs), the idea being that the code related to the 3d scene (primitive/entities/Avatars etc) will be in this inner class, then what is now Scene.cs will be left as a kind of wrapper class around it. And once the spilt is complete can be renamed to something like RegionInstance (or any name that sounds good and ids it as the Region layer class that "has" a scene). Added SceneCommunicationService which at the moment is a kind of high level wrapper around commsManager. The idea being that it has a higher level API for the Region/Scene to send messages to the other regions on the grid. a Example of the API is that instead of having sendXmessage methods, it has more functional level method like PassAvatarToNeighbour. Hopefully this will allow more freedom to do changes in communications that doesn't break other things.
Diffstat (limited to 'OpenSim/Region/Environment/Scenes/Scene.cs')
-rw-r--r--OpenSim/Region/Environment/Scenes/Scene.cs583
1 files changed, 195 insertions, 388 deletions
diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs
index 9eb3a71..a956eb2 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.cs
@@ -51,13 +51,14 @@ using Timer=System.Timers.Timer;
51 51
52namespace OpenSim.Region.Environment.Scenes 52namespace OpenSim.Region.Environment.Scenes
53{ 53{
54 public delegate bool FilterAvatarList(ScenePresence avatar);
55
54 public partial class Scene : SceneBase 56 public partial class Scene : SceneBase
55 { 57 {
56 public delegate bool FilterAvatarList(ScenePresence avatar); 58 #region Fields
57
58 protected Timer m_heartbeatTimer = new Timer(); 59 protected Timer m_heartbeatTimer = new Timer();
59 protected Dictionary<LLUUID, ScenePresence> m_scenePresences; 60
60 protected Dictionary<LLUUID, SceneObjectGroup> m_sceneObjects; 61 public InnerScene m_innerScene;
61 62
62 private Random Rand = new Random(); 63 private Random Rand = new Random();
63 private uint _primCount = 702000; 64 private uint _primCount = 702000;
@@ -66,16 +67,14 @@ namespace OpenSim.Region.Environment.Scenes
66 private int m_timePhase = 24; 67 private int m_timePhase = 24;
67 private int m_timeUpdateCount; 68 private int m_timeUpdateCount;
68 69
69 public BasicQuadTreeNode QuadTree;
70
71 private readonly Mutex updateLock; 70 private readonly Mutex updateLock;
72 71
73 protected ModuleLoader m_moduleLoader; 72 protected ModuleLoader m_moduleLoader;
74 protected StorageManager storageManager; 73 protected StorageManager storageManager;
75 protected AgentCircuitManager authenticateHandler; 74 protected AgentCircuitManager authenticateHandler;
76 protected RegionCommsListener regionCommsHost;
77 public CommunicationsManager commsManager; 75 public CommunicationsManager commsManager;
78 // protected XferManager xferManager; 76 // protected XferManager xferManager;
77 protected SceneCommunicationService m_sceneGridService;
79 78
80 protected Dictionary<LLUUID, Caps> capsHandlers = new Dictionary<LLUUID, Caps>(); 79 protected Dictionary<LLUUID, Caps> capsHandlers = new Dictionary<LLUUID, Caps>();
81 protected BaseHttpServer httpListener; 80 protected BaseHttpServer httpListener;
@@ -111,6 +110,7 @@ namespace OpenSim.Region.Environment.Scenes
111 private int m_update_terrain = 50; 110 private int m_update_terrain = 50;
112 private int m_update_land = 1; 111 private int m_update_land = 1;
113 private int m_update_avatars = 1; 112 private int m_update_avatars = 1;
113 #endregion
114 114
115 #region Properties 115 #region Properties
116 116
@@ -128,12 +128,16 @@ namespace OpenSim.Region.Environment.Scenes
128 128
129 private readonly EstateManager m_estateManager; 129 private readonly EstateManager m_estateManager;
130 130
131 private PhysicsScene phyScene; 131 private PhysicsScene phyScene
132 {
133 set { m_innerScene.PhyScene = value; }
134 get { return (m_innerScene.PhyScene); }
135 }
132 136
133 public PhysicsScene PhysScene 137 public PhysicsScene PhysScene
134 { 138 {
135 set { phyScene = value; } 139 set { m_innerScene.PhyScene = value; }
136 get { return (phyScene); } 140 get { return (m_innerScene.PhyScene); }
137 } 141 }
138 142
139 public EstateManager EstateManager 143 public EstateManager EstateManager
@@ -148,29 +152,48 @@ namespace OpenSim.Region.Environment.Scenes
148 get { return m_permissionManager; } 152 get { return m_permissionManager; }
149 } 153 }
150 154
155 public int TimePhase
156 {
157 get { return m_timePhase; }
158 }
159
151 public Dictionary<LLUUID, SceneObjectGroup> Objects 160 public Dictionary<LLUUID, SceneObjectGroup> Objects
152 { 161 {
153 get { return m_sceneObjects; } 162 get { return m_innerScene.SceneObjects; }
154 } 163 }
155 164
156 public int TimePhase 165 protected Dictionary<LLUUID, ScenePresence> m_scenePresences
157 { 166 {
158 get { return m_timePhase; } 167 get { return m_innerScene.ScenePresences; }
168 set { m_innerScene.ScenePresences = value; }
169 }
170
171 protected Dictionary<LLUUID, SceneObjectGroup> m_sceneObjects
172 {
173 get { return m_innerScene.SceneObjects; }
174 set { m_innerScene.SceneObjects = value; }
175 }
176
177 public Dictionary<LLUUID, EntityBase> Entities
178 {
179 get { return m_innerScene.Entities; }
180 set { m_innerScene.Entities = value; }
159 } 181 }
160 182
161 #endregion 183 #endregion
162 184
163 #region Constructors 185 #region Constructors
164 186
165 public Scene(RegionInfo regInfo, AgentCircuitManager authen, CommunicationsManager commsMan, 187 public Scene(RegionInfo regInfo, AgentCircuitManager authen, CommunicationsManager commsMan, SceneCommunicationService sceneGridService,
166 AssetCache assetCach, StorageManager storeManager, BaseHttpServer httpServer, 188 AssetCache assetCach, StorageManager storeManager, BaseHttpServer httpServer,
167 ModuleLoader moduleLoader, bool dumpAssetsToFile) 189 ModuleLoader moduleLoader, bool dumpAssetsToFile)
168 { 190 {
169 updateLock = new Mutex(false); 191 updateLock = new Mutex(false);
170 192
171 m_moduleLoader = moduleLoader; 193 m_moduleLoader = moduleLoader;
172 authenticateHandler = authen; 194 authenticateHandler = authen;
173 commsManager = commsMan; 195 commsManager = commsMan;
196 m_sceneGridService = sceneGridService;
174 storageManager = storeManager; 197 storageManager = storeManager;
175 assetCache = assetCach; 198 assetCache = assetCach;
176 m_regInfo = regInfo; 199 m_regInfo = regInfo;
@@ -184,15 +207,13 @@ namespace OpenSim.Region.Environment.Scenes
184 m_eventManager = new EventManager(); 207 m_eventManager = new EventManager();
185 m_permissionManager = new PermissionManager(this); 208 m_permissionManager = new PermissionManager(this);
186 209
210 m_innerScene = new InnerScene(this, regInfo, m_permissionManager);
211
187 m_eventManager.OnParcelPrimCountAdd += 212 m_eventManager.OnParcelPrimCountAdd +=
188 m_LandManager.addPrimToLandPrimCounts; 213 m_LandManager.addPrimToLandPrimCounts;
189 214
190 m_eventManager.OnPermissionError += SendPermissionAlert; 215 m_eventManager.OnPermissionError += SendPermissionAlert;
191 216
192 QuadTree = new BasicQuadTreeNode(null, "/0/", 0, 0, 256, 256);
193 QuadTree.Subdivide();
194 QuadTree.Subdivide();
195
196 MainLog.Instance.Verbose("Creating new entitities instance"); 217 MainLog.Instance.Verbose("Creating new entitities instance");
197 Entities = new Dictionary<LLUUID, EntityBase>(); 218 Entities = new Dictionary<LLUUID, EntityBase>();
198 m_scenePresences = new Dictionary<LLUUID, ScenePresence>(); 219 m_scenePresences = new Dictionary<LLUUID, ScenePresence>();
@@ -209,34 +230,37 @@ namespace OpenSim.Region.Environment.Scenes
209 230
210 #endregion 231 #endregion
211 232
212 public void SetModuleInterfaces() 233 #region Startup / Close Methods
234 public override void Close()
213 { 235 {
214 m_simChatModule = RequestModuleInterface<ISimChat>(); 236 m_heartbeatTimer.Close();
215 m_httpRequestModule = RequestModuleInterface<IHttpRequests>(); 237 m_innerScene.Close();
216 m_xmlrpcModule = RequestModuleInterface<IXMLRPC>(); 238 m_sceneGridService.Close();
217 m_worldCommModule = RequestModuleInterface<IWorldComm>();
218 XferManager = RequestModuleInterface<IXfer>();
219 }
220
221 #region Script Handling Methods
222 239
223 public void SendCommandToPlugins(string[] args) 240 base.Close();
224 {
225 m_eventManager.TriggerOnPluginConsole(args);
226 } 241 }
227 242
228 #endregion
229
230 /// <summary> 243 /// <summary>
231 /// 244 ///
232 /// </summary> 245 /// </summary>
233 public void StartTimer() 246 public void StartTimer()
234 { 247 {
235 m_heartbeatTimer.Enabled = true; 248 m_heartbeatTimer.Enabled = true;
236 m_heartbeatTimer.Interval = (int) (m_timespan*1000); 249 m_heartbeatTimer.Interval = (int)(m_timespan * 1000);
237 m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat); 250 m_heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat);
238 } 251 }
239 252
253 public void SetModuleInterfaces()
254 {
255 m_simChatModule = RequestModuleInterface<ISimChat>();
256 m_httpRequestModule = RequestModuleInterface<IHttpRequests>();
257 m_xmlrpcModule = RequestModuleInterface<IXMLRPC>();
258 m_worldCommModule = RequestModuleInterface<IWorldComm>();
259 XferManager = RequestModuleInterface<IXfer>();
260 }
261
262 #endregion
263
240 #region Update Methods 264 #region Update Methods
241 265
242 /// <summary> 266 /// <summary>
@@ -597,38 +621,17 @@ namespace OpenSim.Region.Environment.Scenes
597 621
598 public void RemovePrim(uint localID, LLUUID avatar_deleter) 622 public void RemovePrim(uint localID, LLUUID avatar_deleter)
599 { 623 {
600 foreach (EntityBase obj in Entities.Values) 624 m_innerScene.RemovePrim(localID, avatar_deleter);
601 {
602 if (obj is SceneObjectGroup)
603 {
604 if (((SceneObjectGroup) obj).LocalId == localID)
605 {
606 RemoveEntity((SceneObjectGroup) obj);
607 return;
608 }
609 }
610 }
611 } 625 }
612 626
613 public void AddEntityFromStorage(SceneObjectGroup sceneObject) 627 public void AddEntityFromStorage(SceneObjectGroup sceneObject)
614 { 628 {
615 sceneObject.RegionHandle = m_regionHandle; 629 m_innerScene.AddEntityFromStorage(sceneObject);
616 sceneObject.SetScene(this);
617 foreach (SceneObjectPart part in sceneObject.Children.Values)
618 {
619 part.LocalID = PrimIDAllocate();
620 }
621 sceneObject.UpdateParentIDs();
622 AddEntity(sceneObject);
623 } 630 }
624 631
625 public void AddEntity(SceneObjectGroup sceneObject) 632 public void AddEntity(SceneObjectGroup sceneObject)
626 { 633 {
627 if (!Entities.ContainsKey(sceneObject.UUID)) 634 m_innerScene.AddEntity(sceneObject);
628 {
629 // QuadTree.AddObject(sceneObject);
630 Entities.Add(sceneObject.UUID, sceneObject);
631 }
632 } 635 }
633 636
634 public void RemoveEntity(SceneObjectGroup sceneObject) 637 public void RemoveEntity(SceneObjectGroup sceneObject)
@@ -797,31 +800,30 @@ namespace OpenSim.Region.Environment.Scenes
797 client.OnRegionHandShakeReply += SendLayerData; 800 client.OnRegionHandShakeReply += SendLayerData;
798 //remoteClient.OnRequestWearables += new GenericCall(this.GetInitialPrims); 801 //remoteClient.OnRequestWearables += new GenericCall(this.GetInitialPrims);
799 client.OnModifyTerrain += ModifyTerrain; 802 client.OnModifyTerrain += ModifyTerrain;
800 //client.OnChatFromViewer += SimChat; 803 // client.OnRequestWearables += InformClientOfNeighbours;
801 client.OnRequestWearables += InformClientOfNeighbours;
802 client.OnAddPrim += AddNewPrim; 804 client.OnAddPrim += AddNewPrim;
803 client.OnUpdatePrimGroupPosition += UpdatePrimPosition; 805 client.OnUpdatePrimGroupPosition += m_innerScene.UpdatePrimPosition;
804 client.OnUpdatePrimSinglePosition += UpdatePrimSinglePosition; 806 client.OnUpdatePrimSinglePosition += m_innerScene.UpdatePrimSinglePosition;
805 client.OnUpdatePrimGroupRotation += UpdatePrimRotation; 807 client.OnUpdatePrimGroupRotation += m_innerScene.UpdatePrimRotation;
806 client.OnUpdatePrimGroupMouseRotation += UpdatePrimRotation; 808 client.OnUpdatePrimGroupMouseRotation += m_innerScene.UpdatePrimRotation;
807 client.OnUpdatePrimSingleRotation += UpdatePrimSingleRotation; 809 client.OnUpdatePrimSingleRotation += m_innerScene.UpdatePrimSingleRotation;
808 client.OnUpdatePrimScale += UpdatePrimScale; 810 client.OnUpdatePrimScale += m_innerScene.UpdatePrimScale;
809 client.OnUpdateExtraParams += UpdateExtraParam; 811 client.OnUpdateExtraParams += m_innerScene.UpdateExtraParam;
810 client.OnUpdatePrimShape += UpdatePrimShape; 812 client.OnUpdatePrimShape += m_innerScene.UpdatePrimShape;
811 client.OnRequestMapBlocks += RequestMapBlocks; 813 client.OnRequestMapBlocks += RequestMapBlocks;
812 client.OnUpdatePrimTexture += UpdatePrimTexture; 814 client.OnUpdatePrimTexture += m_innerScene.UpdatePrimTexture;
813 client.OnTeleportLocationRequest += RequestTeleportLocation; 815 client.OnTeleportLocationRequest += RequestTeleportLocation;
814 client.OnObjectSelect += SelectPrim; 816 client.OnObjectSelect += SelectPrim;
815 client.OnObjectDeselect += DeselectPrim; 817 client.OnObjectDeselect += DeselectPrim;
816 client.OnGrabUpdate += MoveObject; 818 client.OnGrabUpdate += m_innerScene.MoveObject;
817 client.OnDeRezObject += DeRezObject; 819 client.OnDeRezObject += DeRezObject;
818 client.OnRezObject += RezObject; 820 client.OnRezObject += RezObject;
819 client.OnNameFromUUIDRequest += commsManager.HandleUUIDNameRequest; 821 client.OnNameFromUUIDRequest += commsManager.HandleUUIDNameRequest;
820 client.OnObjectDescription += PrimDescription; 822 client.OnObjectDescription += m_innerScene.PrimDescription;
821 client.OnObjectName += PrimName; 823 client.OnObjectName += m_innerScene.PrimName;
822 client.OnLinkObjects += LinkObjects; 824 client.OnLinkObjects += m_innerScene.LinkObjects;
823 client.OnObjectDuplicate += DuplicateObject; 825 client.OnObjectDuplicate += m_innerScene.DuplicateObject;
824 client.OnUpdatePrimFlags += UpdatePrimFlags; 826 client.OnUpdatePrimFlags += m_innerScene.UpdatePrimFlags;
825 827
826 client.OnParcelPropertiesRequest += new ParcelPropertiesRequest(m_LandManager.handleParcelPropertiesRequest); 828 client.OnParcelPropertiesRequest += new ParcelPropertiesRequest(m_LandManager.handleParcelPropertiesRequest);
827 client.OnParcelDivideRequest += new ParcelDivideRequest(m_LandManager.handleParcelDivideRequest); 829 client.OnParcelDivideRequest += new ParcelDivideRequest(m_LandManager.handleParcelDivideRequest);
@@ -845,8 +847,6 @@ namespace OpenSim.Region.Environment.Scenes
845 client.OnRezScript += RezScript; 847 client.OnRezScript += RezScript;
846 client.OnRemoveTaskItem += RemoveTaskInventory; 848 client.OnRemoveTaskItem += RemoveTaskInventory;
847 849
848 // client.OnRequestAvatarProperties += RequestAvatarProperty;
849
850 client.OnGrabObject += ProcessObjectGrab; 850 client.OnGrabObject += ProcessObjectGrab;
851 851
852 EventManager.TriggerOnNewClient(client); 852 EventManager.TriggerOnNewClient(client);
@@ -865,44 +865,11 @@ namespace OpenSim.Region.Environment.Scenes
865 AvatarFactoryModule.GetDefaultAvatarAppearance(out wearables, out visualParams); 865 AvatarFactoryModule.GetDefaultAvatarAppearance(out wearables, out visualParams);
866 } 866 }
867 867
868 newAvatar = new ScenePresence(client, this, m_regInfo, visualParams, wearables); 868 newAvatar = m_innerScene.CreateAndAddScenePresence(client, child, wearables, visualParams);
869 newAvatar.IsChildAgent = child;
870 869
871 if (child) 870 if (!newAvatar.IsChildAgent)
872 {
873 MainLog.Instance.Verbose("SCENE", RegionInfo.RegionName + ": Creating new child agent.");
874 }
875 else
876 { 871 {
877 newAvatar.OnSignificantClientMovement += m_LandManager.handleSignificantClientMovement; 872 newAvatar.OnSignificantClientMovement += m_LandManager.handleSignificantClientMovement;
878
879 MainLog.Instance.Verbose("SCENE", RegionInfo.RegionName + ": Creating new root agent.");
880 MainLog.Instance.Verbose("SCENE", RegionInfo.RegionName + ": Adding Physical agent.");
881
882 newAvatar.AddToPhysicalScene();
883 }
884
885 lock (Entities)
886 {
887 if (!Entities.ContainsKey(client.AgentId))
888 {
889 Entities.Add(client.AgentId, newAvatar);
890 }
891 else
892 {
893 Entities[client.AgentId] = newAvatar;
894 }
895 }
896 lock (m_scenePresences)
897 {
898 if (m_scenePresences.ContainsKey(client.AgentId))
899 {
900 m_scenePresences[client.AgentId] = newAvatar;
901 }
902 else
903 {
904 m_scenePresences.Add(client.AgentId, newAvatar);
905 }
906 } 873 }
907 874
908 return newAvatar; 875 return newAvatar;
@@ -942,87 +909,13 @@ namespace OpenSim.Region.Environment.Scenes
942 return; 909 return;
943 } 910 }
944 911
945 #endregion 912 public void NotifyMyCoarseLocationChange()
946
947 #region Request m_scenePresences List Methods
948
949 //The idea is to have a group of method that return a list of avatars meeting some requirement
950 // ie it could be all m_scenePresences within a certain range of the calling prim/avatar.
951
952 /// <summary>
953 /// Request a List of all m_scenePresences in this World
954 /// </summary>
955 /// <returns></returns>
956 public List<ScenePresence> GetScenePresences()
957 {
958 List<ScenePresence> result = new List<ScenePresence>(m_scenePresences.Values);
959
960 return result;
961 }
962
963 public List<ScenePresence> GetAvatars()
964 {
965 List<ScenePresence> result =
966 GetScenePresences(delegate(ScenePresence scenePresence) { return !scenePresence.IsChildAgent; });
967
968 return result;
969 }
970
971 /// <summary>
972 /// Request a filtered list of m_scenePresences in this World
973 /// </summary>
974 /// <returns></returns>
975 public List<ScenePresence> GetScenePresences(FilterAvatarList filter)
976 {
977 List<ScenePresence> result = new List<ScenePresence>();
978
979 foreach (ScenePresence avatar in m_scenePresences.Values)
980 {
981 if (filter(avatar))
982 {
983 result.Add(avatar);
984 }
985 }
986
987 return result;
988 }
989
990 /// <summary>
991 /// Request a Avatar by UUID
992 /// </summary>
993 /// <param name="avatarID"></param>
994 /// <returns></returns>
995 public ScenePresence GetScenePresence(LLUUID avatarID)
996 {
997 if (m_scenePresences.ContainsKey(avatarID))
998 {
999 return m_scenePresences[avatarID];
1000 }
1001 return null;
1002 }
1003
1004 /// <summary>
1005 ///
1006 /// </summary>
1007 /// <param name="action"></param>
1008 public void ForEachScenePresence(Action<ScenePresence> action)
1009 {
1010 foreach (ScenePresence presence in m_scenePresences.Values)
1011 {
1012 action(presence);
1013 }
1014 }
1015
1016 public void ForEachObject(Action<SceneObjectGroup> action)
1017 { 913 {
1018 foreach (SceneObjectGroup presence in m_sceneObjects.Values) 914 ForEachScenePresence(delegate(ScenePresence presence) { presence.CoarseLocationChange(); });
1019 {
1020 action(presence);
1021 }
1022 } 915 }
1023
1024 #endregion 916 #endregion
1025 917
918 #region Entities
1026 /// <summary> 919 /// <summary>
1027 /// 920 ///
1028 /// </summary> 921 /// </summary>
@@ -1044,36 +937,18 @@ namespace OpenSim.Region.Environment.Scenes
1044 Broadcast(delegate(IClientAPI client) { client.SendKillObject(m_regionHandle, localID); }); 937 Broadcast(delegate(IClientAPI client) { client.SendKillObject(m_regionHandle, localID); });
1045 } 938 }
1046 939
1047 public void NotifyMyCoarseLocationChange() 940 #endregion
1048 {
1049 ForEachScenePresence(delegate(ScenePresence presence) { presence.CoarseLocationChange(); });
1050 }
1051
1052 public void SendAllSceneObjectsToClient(ScenePresence presence)
1053 {
1054 foreach (EntityBase ent in Entities.Values)
1055 {
1056 if (ent is SceneObjectGroup)
1057 {
1058 // ((SceneObjectGroup)ent).SendFullUpdateToClient(client);
1059 ((SceneObjectGroup) ent).ScheduleFullUpdateToAvatar(presence);
1060 }
1061 }
1062 }
1063 941
1064 #region RegionCommsHost 942 #region RegionComms
1065 943
1066 /// <summary> 944 /// <summary>
1067 /// 945 ///
1068 /// </summary> 946 /// </summary>
1069 public void RegisterRegionWithComms() 947 public void RegisterRegionWithComms()
1070 { 948 {
1071 regionCommsHost = commsManager.GridService.RegisterRegion(m_regInfo); 949 m_sceneGridService.RegisterRegion(m_regInfo);
1072 if (regionCommsHost != null) 950 m_sceneGridService.OnExpectUser += NewUserConnection;
1073 { 951 m_sceneGridService.OnAvatarCrossingIntoRegion += AgentCrossing;
1074 regionCommsHost.OnExpectUser += NewUserConnection;
1075 regionCommsHost.OnAvatarCrossingIntoRegion += AgentCrossing;
1076 }
1077 } 952 }
1078 953
1079 /// <summary> 954 /// <summary>
@@ -1083,27 +958,23 @@ namespace OpenSim.Region.Environment.Scenes
1083 /// <param name="agent"></param> 958 /// <param name="agent"></param>
1084 public void NewUserConnection(ulong regionHandle, AgentCircuitData agent) 959 public void NewUserConnection(ulong regionHandle, AgentCircuitData agent)
1085 { 960 {
1086 // Console.WriteLine("Scene.cs - add new user connection");
1087 //should just check that its meant for this region
1088 if (regionHandle == m_regInfo.RegionHandle) 961 if (regionHandle == m_regInfo.RegionHandle)
1089 { 962 {
1090 if (agent.CapsPath != "") 963 if (agent.CapsPath != "")
1091 { 964 {
1092 //Console.WriteLine("new user, so creating caps handler for it");
1093 Caps cap = 965 Caps cap =
1094 new Caps(commsManager.AssetCache, httpListener, m_regInfo.ExternalHostName, httpListener.Port, 966 new Caps(commsManager.AssetCache, httpListener, m_regInfo.ExternalHostName, httpListener.Port,
1095 agent.CapsPath, agent.AgentID, m_dumpAssetsToFile); 967 agent.CapsPath, agent.AgentID, m_dumpAssetsToFile);
1096 968
1097 Util.SetCapsURL(agent.AgentID, 969 Util.SetCapsURL(agent.AgentID, "http://" + m_regInfo.ExternalHostName + ":" + httpListener.Port.ToString() +
1098 "http://" + m_regInfo.ExternalHostName + ":" + httpListener.Port.ToString() +
1099 "/CAPS/" + agent.CapsPath + "0000/"); 970 "/CAPS/" + agent.CapsPath + "0000/");
1100 cap.RegisterHandlers(); 971 cap.RegisterHandlers();
1101 cap.AddNewInventoryItem = AddInventoryItem; 972 cap.AddNewInventoryItem = AddInventoryItem;
1102 cap.ItemUpdatedCall = CapsUpdateInventoryItemAsset; 973 cap.ItemUpdatedCall = CapsUpdateInventoryItemAsset;
1103 if (capsHandlers.ContainsKey(agent.AgentID)) 974 if (capsHandlers.ContainsKey(agent.AgentID))
1104 { 975 {
1105 MainLog.Instance.Warn("client", "Adding duplicate CAPS entry for user " + 976 //MainLog.Instance.Warn("client", "Adding duplicate CAPS entry for user " +
1106 agent.AgentID.ToStringHyphenated()); 977 // agent.AgentID.ToStringHyphenated());
1107 capsHandlers[agent.AgentID] = cap; 978 capsHandlers[agent.AgentID] = cap;
1108 } 979 }
1109 else 980 else
@@ -1126,61 +997,13 @@ namespace OpenSim.Region.Environment.Scenes
1126 } 997 }
1127 } 998 }
1128 999
1129 private delegate void InformClientOfNeighbourDelegate( 1000
1130 IClientAPI remoteClient, AgentCircuitData a, ulong regionHandle, IPEndPoint endPoint);
1131
1132 private void InformClientOfNeighbourCompleted(IAsyncResult iar)
1133 {
1134 InformClientOfNeighbourDelegate icon = (InformClientOfNeighbourDelegate) iar.AsyncState;
1135
1136
1137 icon.EndInvoke(iar);
1138 }
1139
1140 /// <summary>
1141 /// Async compnent for informing client of which neighbours exists
1142 /// </summary>
1143 /// <remarks>
1144 /// This needs to run asynchronesously, as a network timeout may block the thread for a long while
1145 /// </remarks>
1146 /// <param name="remoteClient"></param>
1147 /// <param name="a"></param>
1148 /// <param name="regionHandle"></param>
1149 /// <param name="endPoint"></param>
1150 private void InformClientOfNeighbourAsync(IClientAPI remoteClient, AgentCircuitData a, ulong regionHandle,
1151 IPEndPoint endPoint)
1152 {
1153 MainLog.Instance.Notice("INTERGRID", "Starting to inform client about neighbours");
1154 bool regionAccepted = commsManager.InterRegion.InformRegionOfChildAgent(regionHandle, a);
1155
1156 if (regionAccepted)
1157 remoteClient.InformClientOfNeighbour(regionHandle, endPoint);
1158 MainLog.Instance.Notice("INTERGRID", "Completed inform client about neighbours");
1159 }
1160
1161 /// <summary> 1001 /// <summary>
1162 /// 1002 ///
1163 /// </summary> 1003 /// </summary>
1164 public void InformClientOfNeighbours(IClientAPI remoteClient) 1004 public void InformClientOfNeighbours(ScenePresence presence)
1165 { 1005 {
1166 List<SimpleRegionInfo> neighbours = 1006 m_sceneGridService.InformClientOfNeighbours(presence);
1167 commsManager.GridService.RequestNeighbours(m_regInfo.RegionLocX, m_regInfo.RegionLocY);
1168 if (neighbours != null)
1169 {
1170 for (int i = 0; i < neighbours.Count; i++)
1171 {
1172 AgentCircuitData agent = remoteClient.RequestClientInfo();
1173 agent.BaseFolder = LLUUID.Zero;
1174 agent.InventoryFolder = LLUUID.Zero;
1175 agent.startpos = new LLVector3(128, 128, 70);
1176 agent.child = true;
1177
1178 InformClientOfNeighbourDelegate d = InformClientOfNeighbourAsync;
1179 d.BeginInvoke(remoteClient, agent, neighbours[i].RegionHandle, neighbours[i].ExternalEndPoint,
1180 InformClientOfNeighbourCompleted,
1181 d);
1182 }
1183 }
1184 } 1007 }
1185 1008
1186 /// <summary> 1009 /// <summary>
@@ -1190,7 +1013,7 @@ namespace OpenSim.Region.Environment.Scenes
1190 /// <returns></returns> 1013 /// <returns></returns>
1191 public RegionInfo RequestNeighbouringRegionInfo(ulong regionHandle) 1014 public RegionInfo RequestNeighbouringRegionInfo(ulong regionHandle)
1192 { 1015 {
1193 return commsManager.GridService.RequestNeighbourInfo(regionHandle); 1016 return m_sceneGridService.RequestNeighbouringRegionInfo(regionHandle);
1194 } 1017 }
1195 1018
1196 /// <summary> 1019 /// <summary>
@@ -1202,9 +1025,7 @@ namespace OpenSim.Region.Environment.Scenes
1202 /// <param name="maxY"></param> 1025 /// <param name="maxY"></param>
1203 public void RequestMapBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY) 1026 public void RequestMapBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY)
1204 { 1027 {
1205 List<MapBlockData> mapBlocks; 1028 m_sceneGridService.RequestMapBlocks(remoteClient, minX, minY, maxX, maxX);
1206 mapBlocks = commsManager.GridService.RequestNeighbourMapBlocks(minX, minY, maxX, maxY);
1207 remoteClient.SendMapBlock(mapBlocks);
1208 } 1029 }
1209 1030
1210 /// <summary> 1031 /// <summary>
@@ -1218,34 +1039,9 @@ namespace OpenSim.Region.Environment.Scenes
1218 public void RequestTeleportLocation(IClientAPI remoteClient, ulong regionHandle, LLVector3 position, 1039 public void RequestTeleportLocation(IClientAPI remoteClient, ulong regionHandle, LLVector3 position,
1219 LLVector3 lookAt, uint flags) 1040 LLVector3 lookAt, uint flags)
1220 { 1041 {
1221 if (regionHandle == m_regionHandle) 1042 if (m_scenePresences.ContainsKey(remoteClient.AgentId))
1222 {
1223 if (m_scenePresences.ContainsKey(remoteClient.AgentId))
1224 {
1225 remoteClient.SendTeleportLocationStart();
1226 remoteClient.SendLocalTeleport(position, lookAt, flags);
1227 m_scenePresences[remoteClient.AgentId].Teleport(position);
1228 }
1229 }
1230 else
1231 { 1043 {
1232 RegionInfo reg = RequestNeighbouringRegionInfo(regionHandle); 1044 m_sceneGridService.RequestTeleportLocation(m_scenePresences[remoteClient.AgentId], regionHandle, position, lookAt, flags);
1233 if (reg != null)
1234 {
1235 remoteClient.SendTeleportLocationStart();
1236 AgentCircuitData agent = remoteClient.RequestClientInfo();
1237 agent.BaseFolder = LLUUID.Zero;
1238 agent.InventoryFolder = LLUUID.Zero;
1239 // agent.startpos = new LLVector3(128, 128, 70);
1240 agent.startpos = position;
1241 agent.child = true;
1242 m_scenePresences[remoteClient.AgentId].Close();
1243 commsManager.InterRegion.InformRegionOfChildAgent(regionHandle, agent);
1244 commsManager.InterRegion.ExpectAvatarCrossing(regionHandle, remoteClient.AgentId, position, false);
1245 AgentCircuitData circuitdata = remoteClient.RequestClientInfo();
1246 string capsPath = Util.GetCapsURL(remoteClient.AgentId);
1247 remoteClient.SendRegionTeleport(regionHandle, 13, reg.ExternalEndPoint, 4, (1 << 4), capsPath);
1248 }
1249 } 1045 }
1250 } 1046 }
1251 1047
@@ -1257,19 +1053,12 @@ namespace OpenSim.Region.Environment.Scenes
1257 /// <param name="position"></param> 1053 /// <param name="position"></param>
1258 public bool InformNeighbourOfCrossing(ulong regionhandle, LLUUID agentID, LLVector3 position, bool isFlying) 1054 public bool InformNeighbourOfCrossing(ulong regionhandle, LLUUID agentID, LLVector3 position, bool isFlying)
1259 { 1055 {
1260 return commsManager.InterRegion.ExpectAvatarCrossing(regionhandle, agentID, position, isFlying); 1056 return m_sceneGridService.InformNeighbourOfCrossing(regionhandle, agentID, position, isFlying);
1261 }
1262
1263 public void performParcelPrimCountUpdate()
1264 {
1265 m_LandManager.resetAllLandPrimCounts();
1266 m_eventManager.TriggerParcelPrimCountUpdate();
1267 m_LandManager.finalizeLandPrimCountUpdate();
1268 m_LandManager.landPrimCountTainted = false;
1269 } 1057 }
1270 1058
1271 #endregion 1059 #endregion
1272 1060
1061 #region Module Methods
1273 public void AddModule(string name, IRegionModule module) 1062 public void AddModule(string name, IRegionModule module)
1274 { 1063 {
1275 if (!Modules.ContainsKey(name)) 1064 if (!Modules.ContainsKey(name))
@@ -1297,7 +1086,9 @@ namespace OpenSim.Region.Environment.Scenes
1297 return default(T); 1086 return default(T);
1298 } 1087 }
1299 } 1088 }
1089 #endregion
1300 1090
1091 #region Other Methods
1301 public void SetTimePhase(int phase) 1092 public void SetTimePhase(int phase)
1302 { 1093 {
1303 m_timePhase = phase; 1094 m_timePhase = phase;
@@ -1313,6 +1104,26 @@ namespace OpenSim.Region.Environment.Scenes
1313 } 1104 }
1314 } 1105 }
1315 1106
1107 public LLUUID MakeHttpRequest(string url, string type, string body)
1108 {
1109 if (m_httpRequestModule != null)
1110 {
1111 return m_httpRequestModule.MakeHttpRequest(url, type, body);
1112 }
1113 return LLUUID.Zero;
1114 }
1115
1116 public void performParcelPrimCountUpdate()
1117 {
1118 m_LandManager.resetAllLandPrimCounts();
1119 m_eventManager.TriggerParcelPrimCountUpdate();
1120 m_LandManager.finalizeLandPrimCountUpdate();
1121 m_LandManager.landPrimCountTainted = false;
1122 }
1123
1124 #endregion
1125
1126 #region Console Commands
1316 #region Alert Methods 1127 #region Alert Methods
1317 1128
1318 private void SendPermissionAlert(LLUUID user, string reason) 1129 private void SendPermissionAlert(LLUUID user, string reason)
@@ -1444,15 +1255,17 @@ namespace OpenSim.Region.Environment.Scenes
1444 } 1255 }
1445 } 1256 }
1446 1257
1447 public LLUUID MakeHttpRequest(string url, string type, string body) 1258 #endregion
1259
1260 #region Script Handling Methods
1261
1262 public void SendCommandToPlugins(string[] args)
1448 { 1263 {
1449 if (m_httpRequestModule != null) 1264 m_eventManager.TriggerOnPluginConsole(args);
1450 {
1451 return m_httpRequestModule.MakeHttpRequest(url, type, body);
1452 }
1453 return LLUUID.Zero;
1454 } 1265 }
1455 1266
1267 #endregion
1268
1456 #region Script Engine 1269 #region Script Engine
1457 1270
1458 private List<ScriptEngineInterface> ScriptEngines = new List<ScriptEngineInterface>(); 1271 private List<ScriptEngineInterface> ScriptEngines = new List<ScriptEngineInterface>();
@@ -1467,106 +1280,100 @@ namespace OpenSim.Region.Environment.Scenes
1467 1280
1468 #endregion 1281 #endregion
1469 1282
1283 #region InnerScene wrapper methods
1284
1470 public LLUUID ConvertLocalIDToFullID(uint localID) 1285 public LLUUID ConvertLocalIDToFullID(uint localID)
1471 { 1286 {
1472 bool hasPrim = false; 1287 return m_innerScene.ConvertLocalIDToFullID(localID);
1473 foreach (EntityBase ent in Entities.Values)
1474 {
1475 if (ent is SceneObjectGroup)
1476 {
1477 hasPrim = ((SceneObjectGroup) ent).HasChildPrim(localID);
1478 if (hasPrim != false)
1479 {
1480 return ((SceneObjectGroup) ent).GetPartsFullID(localID);
1481 }
1482 }
1483 }
1484 return LLUUID.Zero;
1485 } 1288 }
1486 1289
1487 public SceneObjectPart GetSceneObjectPart(uint localID) 1290 public void SendAllSceneObjectsToClient(ScenePresence presence)
1488 { 1291 {
1489 bool hasPrim = false; 1292 m_innerScene.SendAllSceneObjectsToClient(presence);
1490 foreach (EntityBase ent in Entities.Values)
1491 {
1492 if (ent is SceneObjectGroup)
1493 {
1494 hasPrim = ((SceneObjectGroup) ent).HasChildPrim(localID);
1495 if (hasPrim != false)
1496 {
1497 return ((SceneObjectGroup) ent).GetChildPart(localID);
1498 }
1499 }
1500 }
1501 return null;
1502 } 1293 }
1503 1294
1504 public SceneObjectPart GetSceneObjectPart(LLUUID fullID) 1295 //The idea is to have a group of method that return a list of avatars meeting some requirement
1296 // ie it could be all m_scenePresences within a certain range of the calling prim/avatar.
1297
1298 public List<ScenePresence> GetAvatars()
1505 { 1299 {
1506 bool hasPrim = false; 1300 return m_innerScene.GetAvatars();
1507 foreach (EntityBase ent in Entities.Values) 1301 }
1302
1303 /// <summary>
1304 /// Request a List of all m_scenePresences in this World
1305 /// </summary>
1306 /// <returns></returns>
1307 public List<ScenePresence> GetScenePresences()
1308 {
1309 return m_innerScene.GetScenePresences();
1310 }
1311
1312 /// <summary>
1313 /// Request a filtered list of m_scenePresences in this World
1314 /// </summary>
1315 /// <returns></returns>
1316 public List<ScenePresence> GetScenePresences(FilterAvatarList filter)
1317 {
1318 return m_innerScene.GetScenePresences(filter);
1319 }
1320
1321 /// <summary>
1322 /// Request a Avatar by UUID
1323 /// </summary>
1324 /// <param name="avatarID"></param>
1325 /// <returns></returns>
1326 public ScenePresence GetScenePresence(LLUUID avatarID)
1327 {
1328 return m_innerScene.GetScenePresence(avatarID);
1329 }
1330
1331 /// <summary>
1332 ///
1333 /// </summary>
1334 /// <param name="action"></param>
1335 public void ForEachScenePresence(Action<ScenePresence> action)
1336 {
1337 foreach (ScenePresence presence in m_scenePresences.Values)
1508 { 1338 {
1509 if (ent is SceneObjectGroup) 1339 action(presence);
1510 {
1511 hasPrim = ((SceneObjectGroup) ent).HasChildPrim(fullID);
1512 if (hasPrim != false)
1513 {
1514 return ((SceneObjectGroup) ent).GetChildPart(fullID);
1515 }
1516 }
1517 } 1340 }
1518 return null;
1519 } 1341 }
1520 1342
1521 internal bool TryGetAvatar(LLUUID avatarId, out ScenePresence avatar) 1343 public void ForEachObject(Action<SceneObjectGroup> action)
1522 { 1344 {
1523 ScenePresence presence; 1345 foreach (SceneObjectGroup presence in m_sceneObjects.Values)
1524 if (m_scenePresences.TryGetValue(avatarId, out presence))
1525 { 1346 {
1526 if (!presence.IsChildAgent) 1347 action(presence);
1527 {
1528 avatar = presence;
1529 return true;
1530 }
1531 } 1348 }
1532
1533 avatar = null;
1534 return false;
1535 } 1349 }
1536 1350
1537 public override void Close() 1351 public SceneObjectPart GetSceneObjectPart(uint localID)
1538 { 1352 {
1539 m_heartbeatTimer.Close(); 1353 return m_innerScene.GetSceneObjectPart(localID);
1354 }
1540 1355
1541 base.Close(); 1356 public SceneObjectPart GetSceneObjectPart(LLUUID fullID)
1357 {
1358 return m_innerScene.GetSceneObjectPart(fullID);
1542 } 1359 }
1543 1360
1544 internal bool TryGetAvatarByName(string avatarName, out ScenePresence avatar) 1361 internal bool TryGetAvatar(LLUUID avatarId, out ScenePresence avatar)
1545 { 1362 {
1546 foreach (ScenePresence presence in m_scenePresences.Values) 1363 return m_innerScene.TryGetAvatar(avatarId, out avatar);
1547 { 1364 }
1548 if (!presence.IsChildAgent)
1549 {
1550 string name = presence.ControllingClient.FirstName + " " + presence.ControllingClient.LastName;
1551 1365
1552 if (String.Compare(avatarName, name, true) == 0)
1553 {
1554 avatar = presence;
1555 return true;
1556 }
1557 }
1558 }
1559 1366
1560 avatar = null; 1367 internal bool TryGetAvatarByName(string avatarName, out ScenePresence avatar)
1561 return false; 1368 {
1369 return m_innerScene.TryGetAvatarByName(avatarName, out avatar);
1562 } 1370 }
1563 1371
1564 internal void ForEachClient(Action<IClientAPI> action) 1372 internal void ForEachClient(Action<IClientAPI> action)
1565 { 1373 {
1566 foreach (ScenePresence presence in m_scenePresences.Values) 1374 m_innerScene.ForEachClient(action);
1567 {
1568 action(presence.ControllingClient);
1569 }
1570 } 1375 }
1376
1377 #endregion
1571 } 1378 }
1572} \ No newline at end of file 1379} \ No newline at end of file