aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Scenes/Scene.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Scenes/Scene.cs1838
1 files changed, 919 insertions, 919 deletions
diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs
index 1e69c9e..a06d74d 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.cs
@@ -1,919 +1,919 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Threading; 30using System.Threading;
31using System.Timers; 31using System.Timers;
32using libsecondlife; 32using libsecondlife;
33using libsecondlife.Packets; 33using libsecondlife.Packets;
34using OpenSim.Framework; 34using OpenSim.Framework;
35using OpenSim.Framework.Communications; 35using OpenSim.Framework.Communications;
36using OpenSim.Framework.Console; 36using OpenSim.Framework.Console;
37using OpenSim.Framework.Interfaces; 37using OpenSim.Framework.Interfaces;
38using OpenSim.Framework.Servers; 38using OpenSim.Framework.Servers;
39using OpenSim.Framework.Types; 39using OpenSim.Framework.Types;
40using OpenSim.Physics.Manager; 40using OpenSim.Physics.Manager;
41using OpenSim.Region.Caches; 41using OpenSim.Region.Caches;
42using OpenSim.Region.Interfaces; 42using OpenSim.Region.Interfaces;
43using OpenSim.Region.Scripting; 43using OpenSim.Region.Scripting;
44using OpenSim.Region.Terrain; 44using OpenSim.Region.Terrain;
45using Caps = OpenSim.Region.Capabilities.Caps; 45using Caps = OpenSim.Region.Capabilities.Caps;
46using Timer = System.Timers.Timer; 46using Timer = System.Timers.Timer;
47 47
48namespace OpenSim.Region.Environment.Scenes 48namespace OpenSim.Region.Environment.Scenes
49{ 49{
50 public delegate bool FilterAvatarList(ScenePresence avatar); 50 public delegate bool FilterAvatarList(ScenePresence avatar);
51 public delegate void ForEachScenePresenceDelegate(ScenePresence presence); 51 public delegate void ForEachScenePresenceDelegate(ScenePresence presence);
52 52
53 public partial class Scene : SceneBase, ILocalStorageReceiver 53 public partial class Scene : SceneBase, ILocalStorageReceiver
54 { 54 {
55 protected Timer m_heartbeatTimer = new Timer(); 55 protected Timer m_heartbeatTimer = new Timer();
56 protected Dictionary<LLUUID, ScenePresence> Avatars; 56 protected Dictionary<LLUUID, ScenePresence> Avatars;
57 protected Dictionary<LLUUID, SceneObject> Prims; 57 protected Dictionary<LLUUID, SceneObject> Prims;
58 protected PhysicsScene phyScene; 58 protected PhysicsScene phyScene;
59 protected float timeStep = 0.1f; 59 protected float timeStep = 0.1f;
60 private Random Rand = new Random(); 60 private Random Rand = new Random();
61 private uint _primCount = 702000; 61 private uint _primCount = 702000;
62 private System.Threading.Mutex _primAllocateMutex = new Mutex(false); 62 private System.Threading.Mutex _primAllocateMutex = new Mutex(false);
63 private int storageCount; 63 private int storageCount;
64 private int parcelPrimCheckCount; 64 private int parcelPrimCheckCount;
65 private Mutex updateLock; 65 private Mutex updateLock;
66 66
67 protected AuthenticateSessionsBase authenticateHandler; 67 protected AuthenticateSessionsBase authenticateHandler;
68 protected RegionCommsListener regionCommsHost; 68 protected RegionCommsListener regionCommsHost;
69 protected CommunicationsManager commsManager; 69 protected CommunicationsManager commsManager;
70 protected StorageManager storageManager; 70 protected StorageManager storageManager;
71 71
72 protected Dictionary<LLUUID, Caps> capsHandlers = new Dictionary<LLUUID, Caps>(); 72 protected Dictionary<LLUUID, Caps> capsHandlers = new Dictionary<LLUUID, Caps>();
73 protected BaseHttpServer httpListener; 73 protected BaseHttpServer httpListener;
74 74
75 #region Properties 75 #region Properties
76 /// <summary> 76 /// <summary>
77 /// 77 ///
78 /// </summary> 78 /// </summary>
79 public PhysicsScene PhysScene 79 public PhysicsScene PhysScene
80 { 80 {
81 set 81 set
82 { 82 {
83 this.phyScene = value; 83 this.phyScene = value;
84 } 84 }
85 get 85 get
86 { 86 {
87 return (this.phyScene); 87 return (this.phyScene);
88 } 88 }
89 } 89 }
90 90
91 private ParcelManager m_parcelManager; 91 private ParcelManager m_parcelManager;
92 public ParcelManager ParcelManager 92 public ParcelManager ParcelManager
93 { 93 {
94 get { return m_parcelManager; } 94 get { return m_parcelManager; }
95 } 95 }
96 96
97 private EstateManager m_estateManager; 97 private EstateManager m_estateManager;
98 public EstateManager EstateManager 98 public EstateManager EstateManager
99 { 99 {
100 get { return m_estateManager; } 100 get { return m_estateManager; }
101 } 101 }
102 102
103 private EventManager m_eventManager; 103 private EventManager m_eventManager;
104 public EventManager EventManager 104 public EventManager EventManager
105 { 105 {
106 get { return m_eventManager; } 106 get { return m_eventManager; }
107 } 107 }
108 108
109 private ScriptManager m_scriptManager; 109 private ScriptManager m_scriptManager;
110 public ScriptManager ScriptManager 110 public ScriptManager ScriptManager
111 { 111 {
112 get { return m_scriptManager; } 112 get { return m_scriptManager; }
113 } 113 }
114 114
115 public Dictionary<LLUUID, SceneObject> Objects 115 public Dictionary<LLUUID, SceneObject> Objects
116 { 116 {
117 get { return Prims; } 117 get { return Prims; }
118 } 118 }
119 119
120 #endregion 120 #endregion
121 121
122 #region Constructors 122 #region Constructors
123 /// <summary> 123 /// <summary>
124 /// Creates a new World class, and a region to go with it. 124 /// Creates a new World class, and a region to go with it.
125 /// </summary> 125 /// </summary>
126 /// <param name="clientThreads">Dictionary to contain client threads</param> 126 /// <param name="clientThreads">Dictionary to contain client threads</param>
127 /// <param name="regionHandle">Region Handle for this region</param> 127 /// <param name="regionHandle">Region Handle for this region</param>
128 /// <param name="regionName">Region Name for this region</param> 128 /// <param name="regionName">Region Name for this region</param>
129 public Scene(RegionInfo regInfo, AuthenticateSessionsBase authen, CommunicationsManager commsMan, AssetCache assetCach, StorageManager storeManager, BaseHttpServer httpServer) 129 public Scene(RegionInfo regInfo, AuthenticateSessionsBase authen, CommunicationsManager commsMan, AssetCache assetCach, StorageManager storeManager, BaseHttpServer httpServer)
130 { 130 {
131 updateLock = new Mutex(false); 131 updateLock = new Mutex(false);
132 this.authenticateHandler = authen; 132 this.authenticateHandler = authen;
133 this.commsManager = commsMan; 133 this.commsManager = commsMan;
134 this.storageManager = storeManager; 134 this.storageManager = storeManager;
135 this.assetCache = assetCach; 135 this.assetCache = assetCach;
136 m_regInfo = regInfo; 136 m_regInfo = regInfo;
137 m_regionHandle = m_regInfo.RegionHandle; 137 m_regionHandle = m_regInfo.RegionHandle;
138 m_regionName = m_regInfo.RegionName; 138 m_regionName = m_regInfo.RegionName;
139 this.m_datastore = m_regInfo.DataStore; 139 this.m_datastore = m_regInfo.DataStore;
140 this.RegisterRegionWithComms(); 140 this.RegisterRegionWithComms();
141 141
142 m_parcelManager = new ParcelManager(this, this.m_regInfo); 142 m_parcelManager = new ParcelManager(this, this.m_regInfo);
143 m_estateManager = new EstateManager(this, this.m_regInfo); 143 m_estateManager = new EstateManager(this, this.m_regInfo);
144 m_scriptManager = new ScriptManager(this); 144 m_scriptManager = new ScriptManager(this);
145 m_eventManager = new EventManager(); 145 m_eventManager = new EventManager();
146 146
147 m_eventManager.OnParcelPrimCountAdd += new EventManager.OnParcelPrimCountAddDelegate(m_parcelManager.addPrimToParcelCounts); 147 m_eventManager.OnParcelPrimCountAdd += new EventManager.OnParcelPrimCountAddDelegate(m_parcelManager.addPrimToParcelCounts);
148 148
149 MainLog.Instance.Verbose("World.cs - creating new entitities instance"); 149 MainLog.Instance.Verbose("World.cs - creating new entitities instance");
150 Entities = new Dictionary<LLUUID, EntityBase>(); 150 Entities = new Dictionary<LLUUID, EntityBase>();
151 Avatars = new Dictionary<LLUUID, ScenePresence>(); 151 Avatars = new Dictionary<LLUUID, ScenePresence>();
152 Prims = new Dictionary<LLUUID, SceneObject>(); 152 Prims = new Dictionary<LLUUID, SceneObject>();
153 153
154 MainLog.Instance.Verbose("World.cs - loading objects from datastore"); 154 MainLog.Instance.Verbose("World.cs - loading objects from datastore");
155 List<SceneObject> PrimsFromDB = storageManager.DataStore.LoadObjects(); 155 List<SceneObject> PrimsFromDB = storageManager.DataStore.LoadObjects();
156 foreach (SceneObject prim in PrimsFromDB) 156 foreach (SceneObject prim in PrimsFromDB)
157 { 157 {
158 AddEntity(prim); 158 AddEntity(prim);
159 } 159 }
160 MainLog.Instance.Verbose("World.cs - loaded " + PrimsFromDB.Count.ToString() + " object(s)"); 160 MainLog.Instance.Verbose("World.cs - loaded " + PrimsFromDB.Count.ToString() + " object(s)");
161 161
162 162
163 MainLog.Instance.Verbose("World.cs - creating LandMap"); 163 MainLog.Instance.Verbose("World.cs - creating LandMap");
164 Terrain = new TerrainEngine(); 164 Terrain = new TerrainEngine();
165 165
166 ScenePresence.LoadAnims(); 166 ScenePresence.LoadAnims();
167 167
168 this.httpListener = httpServer; 168 this.httpListener = httpServer;
169 } 169 }
170 #endregion 170 #endregion
171 171
172 #region Script Handling Methods 172 #region Script Handling Methods
173 173
174 public void SendCommandToScripts(string[] args) 174 public void SendCommandToScripts(string[] args)
175 { 175 {
176 m_eventManager.TriggerOnScriptConsole(args); 176 m_eventManager.TriggerOnScriptConsole(args);
177 } 177 }
178 178
179 #endregion 179 #endregion
180 180
181 /// <summary> 181 /// <summary>
182 /// 182 ///
183 /// </summary> 183 /// </summary>
184 public void StartTimer() 184 public void StartTimer()
185 { 185 {
186 m_heartbeatTimer.Enabled = true; 186 m_heartbeatTimer.Enabled = true;
187 m_heartbeatTimer.Interval = 100; 187 m_heartbeatTimer.Interval = 100;
188 m_heartbeatTimer.Elapsed += new ElapsedEventHandler(this.Heartbeat); 188 m_heartbeatTimer.Elapsed += new ElapsedEventHandler(this.Heartbeat);
189 } 189 }
190 190
191 191
192 #region Update Methods 192 #region Update Methods
193 193
194 194
195 /// <summary> 195 /// <summary>
196 /// Performs per-frame updates regularly 196 /// Performs per-frame updates regularly
197 /// </summary> 197 /// </summary>
198 /// <param name="sender"></param> 198 /// <param name="sender"></param>
199 /// <param name="e"></param> 199 /// <param name="e"></param>
200 void Heartbeat(object sender, EventArgs e) 200 void Heartbeat(object sender, EventArgs e)
201 { 201 {
202 this.Update(); 202 this.Update();
203 } 203 }
204 204
205 /// <summary> 205 /// <summary>
206 /// Performs per-frame updates on the world, this should be the central world loop 206 /// Performs per-frame updates on the world, this should be the central world loop
207 /// </summary> 207 /// </summary>
208 public override void Update() 208 public override void Update()
209 { 209 {
210 updateLock.WaitOne(); 210 updateLock.WaitOne();
211 try 211 try
212 { 212 {
213 if (this.phyScene.IsThreaded) 213 if (this.phyScene.IsThreaded)
214 { 214 {
215 this.phyScene.GetResults(); 215 this.phyScene.GetResults();
216 216
217 } 217 }
218 218
219 foreach (LLUUID UUID in Entities.Keys) 219 foreach (LLUUID UUID in Entities.Keys)
220 { 220 {
221 Entities[UUID].updateMovement(); 221 Entities[UUID].updateMovement();
222 } 222 }
223 223
224 lock (this.m_syncRoot) 224 lock (this.m_syncRoot)
225 { 225 {
226 this.phyScene.Simulate(timeStep); 226 this.phyScene.Simulate(timeStep);
227 } 227 }
228 228
229 foreach (LLUUID UUID in Entities.Keys) 229 foreach (LLUUID UUID in Entities.Keys)
230 { 230 {
231 Entities[UUID].update(); 231 Entities[UUID].update();
232 } 232 }
233 233
234 // General purpose event manager 234 // General purpose event manager
235 m_eventManager.TriggerOnFrame(); 235 m_eventManager.TriggerOnFrame();
236 236
237 //backup world data 237 //backup world data
238 this.storageCount++; 238 this.storageCount++;
239 if (storageCount > 1200) //set to how often you want to backup 239 if (storageCount > 1200) //set to how often you want to backup
240 { 240 {
241 this.Backup(); 241 this.Backup();
242 storageCount = 0; 242 storageCount = 0;
243 } 243 }
244 244
245 this.parcelPrimCheckCount++; 245 this.parcelPrimCheckCount++;
246 if (this.parcelPrimCheckCount > 50) //check every 5 seconds for tainted prims 246 if (this.parcelPrimCheckCount > 50) //check every 5 seconds for tainted prims
247 { 247 {
248 if (m_parcelManager.parcelPrimCountTainted) 248 if (m_parcelManager.parcelPrimCountTainted)
249 { 249 {
250 //Perform parcel update of prim count 250 //Perform parcel update of prim count
251 performParcelPrimCountUpdate(); 251 performParcelPrimCountUpdate();
252 this.parcelPrimCheckCount = 0; 252 this.parcelPrimCheckCount = 0;
253 } 253 }
254 } 254 }
255 255
256 } 256 }
257 catch (Exception e) 257 catch (Exception e)
258 { 258 {
259 MainLog.Instance.Warn("World.cs: Update() - Failed with exception " + e.ToString()); 259 MainLog.Instance.Warn("World.cs: Update() - Failed with exception " + e.ToString());
260 } 260 }
261 updateLock.ReleaseMutex(); 261 updateLock.ReleaseMutex();
262 262
263 } 263 }
264 264
265 /// <summary> 265 /// <summary>
266 /// 266 ///
267 /// </summary> 267 /// </summary>
268 /// <returns></returns> 268 /// <returns></returns>
269 public bool Backup() 269 public bool Backup()
270 { 270 {
271 EventManager.TriggerOnBackup(this.storageManager.DataStore); 271 EventManager.TriggerOnBackup(this.storageManager.DataStore);
272 return true; 272 return true;
273 } 273 }
274 #endregion 274 #endregion
275 275
276 #region Regenerate Terrain 276 #region Regenerate Terrain
277 277
278 /// <summary> 278 /// <summary>
279 /// Rebuilds the terrain using a procedural algorithm 279 /// Rebuilds the terrain using a procedural algorithm
280 /// </summary> 280 /// </summary>
281 public void RegenerateTerrain() 281 public void RegenerateTerrain()
282 { 282 {
283 try 283 try
284 { 284 {
285 Terrain.hills(); 285 Terrain.hills();
286 286
287 lock (this.m_syncRoot) 287 lock (this.m_syncRoot)
288 { 288 {
289 this.phyScene.SetTerrain(Terrain.getHeights1D()); 289 this.phyScene.SetTerrain(Terrain.getHeights1D());
290 } 290 }
291 291
292 this.storageManager.DataStore.StoreTerrain(Terrain.getHeights2DD()); 292 this.storageManager.DataStore.StoreTerrain(Terrain.getHeights2DD());
293 293
294 this.ForEachScenePresence(delegate(ScenePresence presence) 294 this.ForEachScenePresence(delegate(ScenePresence presence)
295 { 295 {
296 this.SendLayerData(presence.ControllingClient); 296 this.SendLayerData(presence.ControllingClient);
297 }); 297 });
298 298
299 foreach (LLUUID UUID in Entities.Keys) 299 foreach (LLUUID UUID in Entities.Keys)
300 { 300 {
301 Entities[UUID].LandRenegerated(); 301 Entities[UUID].LandRenegerated();
302 } 302 }
303 } 303 }
304 catch (Exception e) 304 catch (Exception e)
305 { 305 {
306 MainLog.Instance.Warn("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString()); 306 MainLog.Instance.Warn("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString());
307 } 307 }
308 } 308 }
309 309
310 /// <summary> 310 /// <summary>
311 /// Rebuilds the terrain using a 2D float array 311 /// Rebuilds the terrain using a 2D float array
312 /// </summary> 312 /// </summary>
313 /// <param name="newMap">256,256 float array containing heights</param> 313 /// <param name="newMap">256,256 float array containing heights</param>
314 public void RegenerateTerrain(float[,] newMap) 314 public void RegenerateTerrain(float[,] newMap)
315 { 315 {
316 try 316 try
317 { 317 {
318 this.Terrain.setHeights2D(newMap); 318 this.Terrain.setHeights2D(newMap);
319 lock (this.m_syncRoot) 319 lock (this.m_syncRoot)
320 { 320 {
321 this.phyScene.SetTerrain(this.Terrain.getHeights1D()); 321 this.phyScene.SetTerrain(this.Terrain.getHeights1D());
322 } 322 }
323 this.storageManager.DataStore.StoreTerrain(Terrain.getHeights2DD()); 323 this.storageManager.DataStore.StoreTerrain(Terrain.getHeights2DD());
324 324
325 this.ForEachScenePresence(delegate(ScenePresence presence) 325 this.ForEachScenePresence(delegate(ScenePresence presence)
326 { 326 {
327 this.SendLayerData(presence.ControllingClient); 327 this.SendLayerData(presence.ControllingClient);
328 }); 328 });
329 329
330 foreach (LLUUID UUID in Entities.Keys) 330 foreach (LLUUID UUID in Entities.Keys)
331 { 331 {
332 Entities[UUID].LandRenegerated(); 332 Entities[UUID].LandRenegerated();
333 } 333 }
334 } 334 }
335 catch (Exception e) 335 catch (Exception e)
336 { 336 {
337 MainLog.Instance.Warn("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString()); 337 MainLog.Instance.Warn("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString());
338 } 338 }
339 } 339 }
340 340
341 /// <summary> 341 /// <summary>
342 /// Rebuilds the terrain assuming changes occured at a specified point[?] 342 /// Rebuilds the terrain assuming changes occured at a specified point[?]
343 /// </summary> 343 /// </summary>
344 /// <param name="changes">???</param> 344 /// <param name="changes">???</param>
345 /// <param name="pointx">???</param> 345 /// <param name="pointx">???</param>
346 /// <param name="pointy">???</param> 346 /// <param name="pointy">???</param>
347 public void RegenerateTerrain(bool changes, int pointx, int pointy) 347 public void RegenerateTerrain(bool changes, int pointx, int pointy)
348 { 348 {
349 try 349 try
350 { 350 {
351 if (changes) 351 if (changes)
352 { 352 {
353 /* Dont save here, rely on tainting system instead */ 353 /* Dont save here, rely on tainting system instead */
354 354
355 this.ForEachScenePresence(delegate(ScenePresence presence) 355 this.ForEachScenePresence(delegate(ScenePresence presence)
356 { 356 {
357 this.SendLayerData(pointx, pointy, presence.ControllingClient); 357 this.SendLayerData(pointx, pointy, presence.ControllingClient);
358 }); 358 });
359 } 359 }
360 } 360 }
361 catch (Exception e) 361 catch (Exception e)
362 { 362 {
363 MainLog.Instance.Warn("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString()); 363 MainLog.Instance.Warn("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString());
364 } 364 }
365 } 365 }
366 366
367 #endregion 367 #endregion
368 368
369 #region Load Terrain 369 #region Load Terrain
370 /// <summary> 370 /// <summary>
371 /// Loads the World heightmap 371 /// Loads the World heightmap
372 /// </summary> 372 /// </summary>
373 /// 373 ///
374 public override void LoadWorldMap() 374 public override void LoadWorldMap()
375 { 375 {
376 try 376 try
377 { 377 {
378 double[,] map = this.storageManager.DataStore.LoadTerrain(); 378 double[,] map = this.storageManager.DataStore.LoadTerrain();
379 if (map == null) 379 if (map == null)
380 { 380 {
381 if (string.IsNullOrEmpty(this.m_regInfo.estateSettings.terrainFile)) 381 if (string.IsNullOrEmpty(this.m_regInfo.estateSettings.terrainFile))
382 { 382 {
383 Console.WriteLine("No default terrain, procedurally generating..."); 383 Console.WriteLine("No default terrain, procedurally generating...");
384 this.Terrain.hills(); 384 this.Terrain.hills();
385 385
386 this.storageManager.DataStore.StoreTerrain(this.Terrain.getHeights2DD()); 386 this.storageManager.DataStore.StoreTerrain(this.Terrain.getHeights2DD());
387 } 387 }
388 else 388 else
389 { 389 {
390 try 390 try
391 { 391 {
392 this.Terrain.loadFromFileF32(this.m_regInfo.estateSettings.terrainFile); 392 this.Terrain.loadFromFileF32(this.m_regInfo.estateSettings.terrainFile);
393 this.Terrain *= this.m_regInfo.estateSettings.terrainMultiplier; 393 this.Terrain *= this.m_regInfo.estateSettings.terrainMultiplier;
394 } 394 }
395 catch 395 catch
396 { 396 {
397 Console.WriteLine("Unable to load default terrain, procedurally generating instead..."); 397 Console.WriteLine("Unable to load default terrain, procedurally generating instead...");
398 Terrain.hills(); 398 Terrain.hills();
399 } 399 }
400 this.storageManager.DataStore.StoreTerrain(this.Terrain.getHeights2DD()); 400 this.storageManager.DataStore.StoreTerrain(this.Terrain.getHeights2DD());
401 } 401 }
402 } 402 }
403 else 403 else
404 { 404 {
405 this.Terrain.setHeights2D(map); 405 this.Terrain.setHeights2D(map);
406 } 406 }
407 407
408 CreateTerrainTexture(); 408 CreateTerrainTexture();
409 409
410 } 410 }
411 catch (Exception e) 411 catch (Exception e)
412 { 412 {
413 MainLog.Instance.Warn("World.cs: LoadWorldMap() - Failed with exception " + e.ToString()); 413 MainLog.Instance.Warn("World.cs: LoadWorldMap() - Failed with exception " + e.ToString());
414 } 414 }
415 } 415 }
416 416
417 /// <summary> 417 /// <summary>
418 /// 418 ///
419 /// </summary> 419 /// </summary>
420 public void CreateTerrainTexture() 420 public void CreateTerrainTexture()
421 { 421 {
422 //create a texture asset of the terrain 422 //create a texture asset of the terrain
423 byte[] data = this.Terrain.exportJpegImage("defaultstripe.png"); 423 byte[] data = this.Terrain.exportJpegImage("defaultstripe.png");
424 this.m_regInfo.estateSettings.terrainImageID = LLUUID.Random(); 424 this.m_regInfo.estateSettings.terrainImageID = LLUUID.Random();
425 AssetBase asset = new AssetBase(); 425 AssetBase asset = new AssetBase();
426 asset.FullID = this.m_regInfo.estateSettings.terrainImageID; 426 asset.FullID = this.m_regInfo.estateSettings.terrainImageID;
427 asset.Data = data; 427 asset.Data = data;
428 asset.Name = "terrainImage"; 428 asset.Name = "terrainImage";
429 asset.Type = 0; 429 asset.Type = 0;
430 this.assetCache.AddAsset(asset); 430 this.assetCache.AddAsset(asset);
431 } 431 }
432 #endregion 432 #endregion
433 433
434 #region Primitives Methods 434 #region Primitives Methods
435 435
436 436
437 /// <summary> 437 /// <summary>
438 /// Loads the World's objects 438 /// Loads the World's objects
439 /// </summary> 439 /// </summary>
440 public void LoadPrimsFromStorage() 440 public void LoadPrimsFromStorage()
441 { 441 {
442 try 442 try
443 { 443 {
444 MainLog.Instance.Verbose("World.cs: LoadPrimsFromStorage() - Loading primitives"); 444 MainLog.Instance.Verbose("World.cs: LoadPrimsFromStorage() - Loading primitives");
445 this.localStorage.LoadPrimitives(this); 445 this.localStorage.LoadPrimitives(this);
446 } 446 }
447 catch (Exception e) 447 catch (Exception e)
448 { 448 {
449 MainLog.Instance.Warn("World.cs: LoadPrimsFromStorage() - Failed with exception " + e.ToString()); 449 MainLog.Instance.Warn("World.cs: LoadPrimsFromStorage() - Failed with exception " + e.ToString());
450 } 450 }
451 } 451 }
452 452
453 /// <summary> 453 /// <summary>
454 /// Loads a specific object from storage 454 /// Loads a specific object from storage
455 /// </summary> 455 /// </summary>
456 /// <param name="prim">The object to load</param> 456 /// <param name="prim">The object to load</param>
457 public void PrimFromStorage(PrimData prim) 457 public void PrimFromStorage(PrimData prim)
458 { 458 {
459 } 459 }
460 460
461 /// <summary> 461 /// <summary>
462 /// Returns a new unallocated primitive ID 462 /// Returns a new unallocated primitive ID
463 /// </summary> 463 /// </summary>
464 /// <returns>A brand new primitive ID</returns> 464 /// <returns>A brand new primitive ID</returns>
465 public uint PrimIDAllocate() 465 public uint PrimIDAllocate()
466 { 466 {
467 uint myID; 467 uint myID;
468 468
469 _primAllocateMutex.WaitOne(); 469 _primAllocateMutex.WaitOne();
470 ++_primCount; 470 ++_primCount;
471 myID = _primCount; 471 myID = _primCount;
472 _primAllocateMutex.ReleaseMutex(); 472 _primAllocateMutex.ReleaseMutex();
473 473
474 return myID; 474 return myID;
475 } 475 }
476 476
477 /// <summary> 477 /// <summary>
478 /// 478 ///
479 /// </summary> 479 /// </summary>
480 /// <param name="addPacket"></param> 480 /// <param name="addPacket"></param>
481 /// <param name="ownerID"></param> 481 /// <param name="ownerID"></param>
482 public void AddNewPrim(LLUUID ownerID, LLVector3 pos, PrimitiveBaseShape shape) 482 public void AddNewPrim(LLUUID ownerID, LLVector3 pos, PrimitiveBaseShape shape)
483 { 483 {
484 484
485 SceneObject sceneOb = new SceneObject(this, m_eventManager, ownerID, this.PrimIDAllocate(), pos, shape); 485 SceneObject sceneOb = new SceneObject(this, m_eventManager, ownerID, this.PrimIDAllocate(), pos, shape);
486 AddEntity(sceneOb); 486 AddEntity(sceneOb);
487 } 487 }
488 488
489 public void RemovePrim(uint localID, LLUUID avatar_deleter) 489 public void RemovePrim(uint localID, LLUUID avatar_deleter)
490 { 490 {
491 foreach (EntityBase obj in Entities.Values) 491 foreach (EntityBase obj in Entities.Values)
492 { 492 {
493 if (obj is SceneObject) 493 if (obj is SceneObject)
494 { 494 {
495 if (((SceneObject)obj).LocalId == localID) 495 if (((SceneObject)obj).LocalId == localID)
496 { 496 {
497 RemoveEntity((SceneObject)obj); 497 RemoveEntity((SceneObject)obj);
498 return; 498 return;
499 } 499 }
500 } 500 }
501 } 501 }
502 502
503 } 503 }
504 504
505 public void AddEntity(SceneObject sceneObject) 505 public void AddEntity(SceneObject sceneObject)
506 { 506 {
507 this.Entities.Add(sceneObject.rootUUID, sceneObject); 507 this.Entities.Add(sceneObject.rootUUID, sceneObject);
508 } 508 }
509 509
510 public void RemoveEntity(SceneObject sceneObject) 510 public void RemoveEntity(SceneObject sceneObject)
511 { 511 {
512 if (this.Entities.ContainsKey(sceneObject.rootUUID)) 512 if (this.Entities.ContainsKey(sceneObject.rootUUID))
513 { 513 {
514 m_parcelManager.removePrimFromParcelCounts(sceneObject); 514 m_parcelManager.removePrimFromParcelCounts(sceneObject);
515 this.Entities.Remove(sceneObject.rootUUID); 515 this.Entities.Remove(sceneObject.rootUUID);
516 m_parcelManager.setPrimsTainted(); 516 m_parcelManager.setPrimsTainted();
517 } 517 }
518 } 518 }
519 519
520 /// <summary> 520 /// <summary>
521 /// Called by a prim when it has been created/cloned, so that its events can be subscribed to 521 /// Called by a prim when it has been created/cloned, so that its events can be subscribed to
522 /// </summary> 522 /// </summary>
523 /// <param name="prim"></param> 523 /// <param name="prim"></param>
524 public void AcknowledgeNewPrim(Primitive prim) 524 public void AcknowledgeNewPrim(Primitive prim)
525 { 525 {
526 prim.OnPrimCountTainted += m_parcelManager.setPrimsTainted; 526 prim.OnPrimCountTainted += m_parcelManager.setPrimsTainted;
527 } 527 }
528 #endregion 528 #endregion
529 529
530 #region Add/Remove Avatar Methods 530 #region Add/Remove Avatar Methods
531 531
532 /// <summary> 532 /// <summary>
533 /// 533 ///
534 /// </summary> 534 /// </summary>
535 /// <param name="remoteClient"></param 535 /// <param name="remoteClient"></param
536 /// <param name="agentID"></param> 536 /// <param name="agentID"></param>
537 /// <param name="child"></param> 537 /// <param name="child"></param>
538 public override void AddNewClient(IClientAPI client, bool child) 538 public override void AddNewClient(IClientAPI client, bool child)
539 { 539 {
540 SubscribeToClientEvents(client); 540 SubscribeToClientEvents(client);
541 this.m_estateManager.sendRegionHandshake(client); 541 this.m_estateManager.sendRegionHandshake(client);
542 CreateAndAddScenePresence(client); 542 CreateAndAddScenePresence(client);
543 this.m_parcelManager.sendParcelOverlay(client); 543 this.m_parcelManager.sendParcelOverlay(client);
544 544
545 } 545 }
546 546
547 protected virtual void SubscribeToClientEvents(IClientAPI client) 547 protected virtual void SubscribeToClientEvents(IClientAPI client)
548 { 548 {
549 client.OnRegionHandShakeReply += this.SendLayerData; 549 client.OnRegionHandShakeReply += this.SendLayerData;
550 //remoteClient.OnRequestWearables += new GenericCall(this.GetInitialPrims); 550 //remoteClient.OnRequestWearables += new GenericCall(this.GetInitialPrims);
551 client.OnChatFromViewer += this.SimChat; 551 client.OnChatFromViewer += this.SimChat;
552 client.OnInstantMessage += this.InstantMessage; 552 client.OnInstantMessage += this.InstantMessage;
553 client.OnRequestWearables += this.InformClientOfNeighbours; 553 client.OnRequestWearables += this.InformClientOfNeighbours;
554 client.OnAddPrim += this.AddNewPrim; 554 client.OnAddPrim += this.AddNewPrim;
555 client.OnUpdatePrimGroupPosition += this.UpdatePrimPosition; 555 client.OnUpdatePrimGroupPosition += this.UpdatePrimPosition;
556 client.OnUpdatePrimSinglePosition += this.UpdatePrimSinglePosition; 556 client.OnUpdatePrimSinglePosition += this.UpdatePrimSinglePosition;
557 client.OnUpdatePrimGroupRotation += this.UpdatePrimRotation; 557 client.OnUpdatePrimGroupRotation += this.UpdatePrimRotation;
558 client.OnUpdatePrimGroupMouseRotation += this.UpdatePrimRotation; 558 client.OnUpdatePrimGroupMouseRotation += this.UpdatePrimRotation;
559 client.OnUpdatePrimSingleRotation += this.UpdatePrimSingleRotation; 559 client.OnUpdatePrimSingleRotation += this.UpdatePrimSingleRotation;
560 client.OnUpdatePrimScale += this.UpdatePrimScale; 560 client.OnUpdatePrimScale += this.UpdatePrimScale;
561 client.OnUpdatePrimShape += this.UpdatePrimShape; 561 client.OnUpdatePrimShape += this.UpdatePrimShape;
562 client.OnRequestMapBlocks += this.RequestMapBlocks; 562 client.OnRequestMapBlocks += this.RequestMapBlocks;
563 client.OnUpdatePrimTexture += this.UpdatePrimTexture; 563 client.OnUpdatePrimTexture += this.UpdatePrimTexture;
564 client.OnTeleportLocationRequest += this.RequestTeleportLocation; 564 client.OnTeleportLocationRequest += this.RequestTeleportLocation;
565 client.OnObjectSelect += this.SelectPrim; 565 client.OnObjectSelect += this.SelectPrim;
566 client.OnObjectDeselect += this.DeselectPrim; 566 client.OnObjectDeselect += this.DeselectPrim;
567 client.OnGrapUpdate += this.MoveObject; 567 client.OnGrapUpdate += this.MoveObject;
568 client.OnNameFromUUIDRequest += this.commsManager.HandleUUIDNameRequest; 568 client.OnNameFromUUIDRequest += this.commsManager.HandleUUIDNameRequest;
569 client.OnObjectDescription += this.PrimDescription; 569 client.OnObjectDescription += this.PrimDescription;
570 client.OnObjectName += this.PrimName; 570 client.OnObjectName += this.PrimName;
571 client.OnLinkObjects += this.LinkObjects; 571 client.OnLinkObjects += this.LinkObjects;
572 client.OnObjectDuplicate += this.DuplicateObject; 572 client.OnObjectDuplicate += this.DuplicateObject;
573 573
574 client.OnParcelPropertiesRequest += new ParcelPropertiesRequest(m_parcelManager.handleParcelPropertiesRequest); 574 client.OnParcelPropertiesRequest += new ParcelPropertiesRequest(m_parcelManager.handleParcelPropertiesRequest);
575 client.OnParcelDivideRequest += new ParcelDivideRequest(m_parcelManager.handleParcelDivideRequest); 575 client.OnParcelDivideRequest += new ParcelDivideRequest(m_parcelManager.handleParcelDivideRequest);
576 client.OnParcelJoinRequest += new ParcelJoinRequest(m_parcelManager.handleParcelJoinRequest); 576 client.OnParcelJoinRequest += new ParcelJoinRequest(m_parcelManager.handleParcelJoinRequest);
577 client.OnParcelPropertiesUpdateRequest += new ParcelPropertiesUpdateRequest(m_parcelManager.handleParcelPropertiesUpdateRequest); 577 client.OnParcelPropertiesUpdateRequest += new ParcelPropertiesUpdateRequest(m_parcelManager.handleParcelPropertiesUpdateRequest);
578 client.OnParcelSelectObjects += new ParcelSelectObjects(m_parcelManager.handleParcelSelectObjectsRequest); 578 client.OnParcelSelectObjects += new ParcelSelectObjects(m_parcelManager.handleParcelSelectObjectsRequest);
579 client.OnParcelObjectOwnerRequest += new ParcelObjectOwnerRequest(m_parcelManager.handleParcelObjectOwnersRequest); 579 client.OnParcelObjectOwnerRequest += new ParcelObjectOwnerRequest(m_parcelManager.handleParcelObjectOwnersRequest);
580 580
581 client.OnEstateOwnerMessage += new EstateOwnerMessageRequest(m_estateManager.handleEstateOwnerMessage); 581 client.OnEstateOwnerMessage += new EstateOwnerMessageRequest(m_estateManager.handleEstateOwnerMessage);
582 582
583 } 583 }
584 584
585 protected ScenePresence CreateAndAddScenePresence(IClientAPI client) 585 protected ScenePresence CreateAndAddScenePresence(IClientAPI client)
586 { 586 {
587 ScenePresence newAvatar = null; 587 ScenePresence newAvatar = null;
588 588
589 MainLog.Instance.Verbose("World.cs:AddViewerAgent() - Creating new avatar for remote viewer agent"); 589 MainLog.Instance.Verbose("World.cs:AddViewerAgent() - Creating new avatar for remote viewer agent");
590 newAvatar = new ScenePresence(client, this, this.m_regInfo); 590 newAvatar = new ScenePresence(client, this, this.m_regInfo);
591 MainLog.Instance.Verbose("World.cs:AddViewerAgent() - Adding new avatar to world"); 591 MainLog.Instance.Verbose("World.cs:AddViewerAgent() - Adding new avatar to world");
592 MainLog.Instance.Verbose("World.cs:AddViewerAgent() - Starting RegionHandshake "); 592 MainLog.Instance.Verbose("World.cs:AddViewerAgent() - Starting RegionHandshake ");
593 593
594 PhysicsVector pVec = new PhysicsVector(newAvatar.Pos.X, newAvatar.Pos.Y, newAvatar.Pos.Z); 594 PhysicsVector pVec = new PhysicsVector(newAvatar.Pos.X, newAvatar.Pos.Y, newAvatar.Pos.Z);
595 lock (this.m_syncRoot) 595 lock (this.m_syncRoot)
596 { 596 {
597 newAvatar.PhysActor = this.phyScene.AddAvatar(pVec); 597 newAvatar.PhysActor = this.phyScene.AddAvatar(pVec);
598 } 598 }
599 599
600 lock (Entities) 600 lock (Entities)
601 { 601 {
602 if (!Entities.ContainsKey(client.AgentId)) 602 if (!Entities.ContainsKey(client.AgentId))
603 { 603 {
604 this.Entities.Add(client.AgentId, newAvatar); 604 this.Entities.Add(client.AgentId, newAvatar);
605 } 605 }
606 else 606 else
607 { 607 {
608 Entities[client.AgentId] = newAvatar; 608 Entities[client.AgentId] = newAvatar;
609 } 609 }
610 } 610 }
611 lock (Avatars) 611 lock (Avatars)
612 { 612 {
613 if (Avatars.ContainsKey(client.AgentId)) 613 if (Avatars.ContainsKey(client.AgentId))
614 { 614 {
615 Avatars[client.AgentId] = newAvatar; 615 Avatars[client.AgentId] = newAvatar;
616 } 616 }
617 else 617 else
618 { 618 {
619 this.Avatars.Add(client.AgentId, newAvatar); 619 this.Avatars.Add(client.AgentId, newAvatar);
620 } 620 }
621 } 621 }
622 newAvatar.OnSignificantClientMovement += m_parcelManager.handleSignificantClientMovement; 622 newAvatar.OnSignificantClientMovement += m_parcelManager.handleSignificantClientMovement;
623 return newAvatar; 623 return newAvatar;
624 } 624 }
625 625
626 626
627 /// <summary> 627 /// <summary>
628 /// 628 ///
629 /// </summary> 629 /// </summary>
630 /// <param name="agentID"></param> 630 /// <param name="agentID"></param>
631 public override void RemoveClient(LLUUID agentID) 631 public override void RemoveClient(LLUUID agentID)
632 { 632 {
633 m_eventManager.TriggerOnRemovePresence(agentID); 633 m_eventManager.TriggerOnRemovePresence(agentID);
634 634
635 ScenePresence avatar = this.RequestAvatar(agentID); 635 ScenePresence avatar = this.RequestAvatar(agentID);
636 636
637 this.ForEachScenePresence( 637 this.ForEachScenePresence(
638 delegate(ScenePresence presence) 638 delegate(ScenePresence presence)
639 { 639 {
640 presence.ControllingClient.SendKillObject(avatar.RegionHandle, avatar.LocalId); 640 presence.ControllingClient.SendKillObject(avatar.RegionHandle, avatar.LocalId);
641 }); 641 });
642 642
643 lock (Avatars) 643 lock (Avatars)
644 { 644 {
645 if (Avatars.ContainsKey(agentID)) 645 if (Avatars.ContainsKey(agentID))
646 { 646 {
647 Avatars.Remove(agentID); 647 Avatars.Remove(agentID);
648 } 648 }
649 } 649 }
650 lock (Entities) 650 lock (Entities)
651 { 651 {
652 if (Entities.ContainsKey(agentID)) 652 if (Entities.ContainsKey(agentID))
653 { 653 {
654 Entities.Remove(agentID); 654 Entities.Remove(agentID);
655 } 655 }
656 } 656 }
657 // TODO: Add the removal from physics ? 657 // TODO: Add the removal from physics ?
658 658
659 659
660 660
661 return; 661 return;
662 } 662 }
663 #endregion 663 #endregion
664 664
665 #region Request Avatars List Methods 665 #region Request Avatars List Methods
666 //The idea is to have a group of method that return a list of avatars meeting some requirement 666 //The idea is to have a group of method that return a list of avatars meeting some requirement
667 // ie it could be all Avatars within a certain range of the calling prim/avatar. 667 // ie it could be all Avatars within a certain range of the calling prim/avatar.
668 668
669 /// <summary> 669 /// <summary>
670 /// Request a List of all Avatars in this World 670 /// Request a List of all Avatars in this World
671 /// </summary> 671 /// </summary>
672 /// <returns></returns> 672 /// <returns></returns>
673 public List<ScenePresence> RequestAvatarList() 673 public List<ScenePresence> RequestAvatarList()
674 { 674 {
675 List<ScenePresence> result = new List<ScenePresence>(); 675 List<ScenePresence> result = new List<ScenePresence>();
676 676
677 foreach (ScenePresence avatar in Avatars.Values) 677 foreach (ScenePresence avatar in Avatars.Values)
678 { 678 {
679 result.Add(avatar); 679 result.Add(avatar);
680 } 680 }
681 681
682 return result; 682 return result;
683 } 683 }
684 684
685 /// <summary> 685 /// <summary>
686 /// Request a filtered list of Avatars in this World 686 /// Request a filtered list of Avatars in this World
687 /// </summary> 687 /// </summary>
688 /// <returns></returns> 688 /// <returns></returns>
689 public List<ScenePresence> RequestAvatarList(FilterAvatarList filter) 689 public List<ScenePresence> RequestAvatarList(FilterAvatarList filter)
690 { 690 {
691 List<ScenePresence> result = new List<ScenePresence>(); 691 List<ScenePresence> result = new List<ScenePresence>();
692 692
693 foreach (ScenePresence avatar in Avatars.Values) 693 foreach (ScenePresence avatar in Avatars.Values)
694 { 694 {
695 if (filter(avatar)) 695 if (filter(avatar))
696 { 696 {
697 result.Add(avatar); 697 result.Add(avatar);
698 } 698 }
699 } 699 }
700 700
701 return result; 701 return result;
702 } 702 }
703 703
704 /// <summary> 704 /// <summary>
705 /// Request a Avatar by UUID 705 /// Request a Avatar by UUID
706 /// </summary> 706 /// </summary>
707 /// <param name="avatarID"></param> 707 /// <param name="avatarID"></param>
708 /// <returns></returns> 708 /// <returns></returns>
709 public ScenePresence RequestAvatar(LLUUID avatarID) 709 public ScenePresence RequestAvatar(LLUUID avatarID)
710 { 710 {
711 if (this.Avatars.ContainsKey(avatarID)) 711 if (this.Avatars.ContainsKey(avatarID))
712 { 712 {
713 return Avatars[avatarID]; 713 return Avatars[avatarID];
714 } 714 }
715 return null; 715 return null;
716 } 716 }
717 717
718 public void ForEachScenePresence(ForEachScenePresenceDelegate whatToDo) 718 public void ForEachScenePresence(ForEachScenePresenceDelegate whatToDo)
719 { 719 {
720 foreach (ScenePresence presence in this.Avatars.Values) 720 foreach (ScenePresence presence in this.Avatars.Values)
721 { 721 {
722 whatToDo(presence); 722 whatToDo(presence);
723 } 723 }
724 } 724 }
725 #endregion 725 #endregion
726 726
727 727
728 /// <summary> 728 /// <summary>
729 /// 729 ///
730 /// </summary> 730 /// </summary>
731 /// <param name="entID"></param> 731 /// <param name="entID"></param>
732 /// <returns></returns> 732 /// <returns></returns>
733 public bool DeleteEntity(LLUUID entID) 733 public bool DeleteEntity(LLUUID entID)
734 { 734 {
735 if (this.Entities.ContainsKey(entID)) 735 if (this.Entities.ContainsKey(entID))
736 { 736 {
737 this.Entities.Remove(entID); 737 this.Entities.Remove(entID);
738 return true; 738 return true;
739 } 739 }
740 return false; 740 return false;
741 } 741 }
742 742
743 public void SendAllSceneObjectsToClient(IClientAPI client) 743 public void SendAllSceneObjectsToClient(IClientAPI client)
744 { 744 {
745 foreach (EntityBase ent in Entities.Values) 745 foreach (EntityBase ent in Entities.Values)
746 { 746 {
747 if (ent is SceneObject) 747 if (ent is SceneObject)
748 { 748 {
749 ((SceneObject)ent).SendAllChildPrimsToClient(client); 749 ((SceneObject)ent).SendAllChildPrimsToClient(client);
750 } 750 }
751 } 751 }
752 } 752 }
753 753
754 #region RegionCommsHost 754 #region RegionCommsHost
755 755
756 /// <summary> 756 /// <summary>
757 /// 757 ///
758 /// </summary> 758 /// </summary>
759 public void RegisterRegionWithComms() 759 public void RegisterRegionWithComms()
760 { 760 {
761 761
762 this.regionCommsHost = this.commsManager.GridServer.RegisterRegion(this.m_regInfo); 762 this.regionCommsHost = this.commsManager.GridServer.RegisterRegion(this.m_regInfo);
763 if (this.regionCommsHost != null) 763 if (this.regionCommsHost != null)
764 { 764 {
765 this.regionCommsHost.OnExpectUser += this.NewUserConnection; 765 this.regionCommsHost.OnExpectUser += this.NewUserConnection;
766 this.regionCommsHost.OnAvatarCrossingIntoRegion += this.AgentCrossing; 766 this.regionCommsHost.OnAvatarCrossingIntoRegion += this.AgentCrossing;
767 } 767 }
768 } 768 }
769 769
770 /// <summary> 770 /// <summary>
771 /// 771 ///
772 /// </summary> 772 /// </summary>
773 /// <param name="regionHandle"></param> 773 /// <param name="regionHandle"></param>
774 /// <param name="agent"></param> 774 /// <param name="agent"></param>
775 public void NewUserConnection(ulong regionHandle, AgentCircuitData agent) 775 public void NewUserConnection(ulong regionHandle, AgentCircuitData agent)
776 { 776 {
777 // Console.WriteLine("World.cs - add new user connection"); 777 // Console.WriteLine("World.cs - add new user connection");
778 //should just check that its meant for this region 778 //should just check that its meant for this region
779 if (regionHandle == this.m_regInfo.RegionHandle) 779 if (regionHandle == this.m_regInfo.RegionHandle)
780 { 780 {
781 if (agent.CapsPath != "") 781 if (agent.CapsPath != "")
782 { 782 {
783 //Console.WriteLine("new user, so creating caps handler for it"); 783 //Console.WriteLine("new user, so creating caps handler for it");
784 Caps cap = new Caps(this.assetCache, httpListener, this.m_regInfo.ExternalHostName, this.m_regInfo.ExternalEndPoint.Port, agent.CapsPath, agent.AgentID); 784 Caps cap = new Caps(this.assetCache, httpListener, this.m_regInfo.ExternalHostName, this.m_regInfo.ExternalEndPoint.Port, agent.CapsPath, agent.AgentID);
785 cap.RegisterHandlers(); 785 cap.RegisterHandlers();
786 if (capsHandlers.ContainsKey(agent.AgentID)) 786 if (capsHandlers.ContainsKey(agent.AgentID))
787 { 787 {
788 OpenSim.Framework.Console.MainLog.Instance.Warn("Adding duplicate CAPS entry for user " + agent.AgentID.ToStringHyphenated()); 788 OpenSim.Framework.Console.MainLog.Instance.Warn("Adding duplicate CAPS entry for user " + agent.AgentID.ToStringHyphenated());
789 this.capsHandlers[agent.AgentID] = cap; 789 this.capsHandlers[agent.AgentID] = cap;
790 } 790 }
791 else 791 else
792 { 792 {
793 this.capsHandlers.Add(agent.AgentID, cap); 793 this.capsHandlers.Add(agent.AgentID, cap);
794 } 794 }
795 795
796 } 796 }
797 this.authenticateHandler.AddNewCircuit(agent.circuitcode, agent); 797 this.authenticateHandler.AddNewCircuit(agent.circuitcode, agent);
798 } 798 }
799 } 799 }
800 800
801 public void AgentCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position) 801 public void AgentCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position)
802 { 802 {
803 if (regionHandle == this.m_regInfo.RegionHandle) 803 if (regionHandle == this.m_regInfo.RegionHandle)
804 { 804 {
805 if (this.Avatars.ContainsKey(agentID)) 805 if (this.Avatars.ContainsKey(agentID))
806 { 806 {
807 this.Avatars[agentID].MakeAvatar(position); 807 this.Avatars[agentID].MakeAvatar(position);
808 } 808 }
809 } 809 }
810 } 810 }
811 811
812 /// <summary> 812 /// <summary>
813 /// 813 ///
814 /// </summary> 814 /// </summary>
815 public void InformClientOfNeighbours(IClientAPI remoteClient) 815 public void InformClientOfNeighbours(IClientAPI remoteClient)
816 { 816 {
817 List<RegionInfo> neighbours = this.commsManager.GridServer.RequestNeighbours(this.m_regInfo); 817 List<RegionInfo> neighbours = this.commsManager.GridServer.RequestNeighbours(this.m_regInfo);
818 818
819 if (neighbours != null) 819 if (neighbours != null)
820 { 820 {
821 for (int i = 0; i < neighbours.Count; i++) 821 for (int i = 0; i < neighbours.Count; i++)
822 { 822 {
823 AgentCircuitData agent = remoteClient.RequestClientInfo(); 823 AgentCircuitData agent = remoteClient.RequestClientInfo();
824 agent.BaseFolder = LLUUID.Zero; 824 agent.BaseFolder = LLUUID.Zero;
825 agent.InventoryFolder = LLUUID.Zero; 825 agent.InventoryFolder = LLUUID.Zero;
826 agent.startpos = new LLVector3(128, 128, 70); 826 agent.startpos = new LLVector3(128, 128, 70);
827 agent.child = true; 827 agent.child = true;
828 this.commsManager.InterRegion.InformRegionOfChildAgent(neighbours[i].RegionHandle, agent); 828 this.commsManager.InterRegion.InformRegionOfChildAgent(neighbours[i].RegionHandle, agent);
829 remoteClient.InformClientOfNeighbour(neighbours[i].RegionHandle, neighbours[i].ExternalEndPoint); 829 remoteClient.InformClientOfNeighbour(neighbours[i].RegionHandle, neighbours[i].ExternalEndPoint);
830 //this.capsHandlers[remoteClient.AgentId].CreateEstablishAgentComms("", System.Net.IPAddress.Parse(neighbours[i].CommsIPListenAddr) + ":" + neighbours[i].CommsIPListenPort); 830 //this.capsHandlers[remoteClient.AgentId].CreateEstablishAgentComms("", System.Net.IPAddress.Parse(neighbours[i].CommsIPListenAddr) + ":" + neighbours[i].CommsIPListenPort);
831 } 831 }
832 } 832 }
833 } 833 }
834 834
835 /// <summary> 835 /// <summary>
836 /// 836 ///
837 /// </summary> 837 /// </summary>
838 /// <param name="regionHandle"></param> 838 /// <param name="regionHandle"></param>
839 /// <returns></returns> 839 /// <returns></returns>
840 public RegionInfo RequestNeighbouringRegionInfo(ulong regionHandle) 840 public RegionInfo RequestNeighbouringRegionInfo(ulong regionHandle)
841 { 841 {
842 return this.commsManager.GridServer.RequestNeighbourInfo(regionHandle); 842 return this.commsManager.GridServer.RequestNeighbourInfo(regionHandle);
843 } 843 }
844 844
845 /// <summary> 845 /// <summary>
846 /// 846 ///
847 /// </summary> 847 /// </summary>
848 /// <param name="minX"></param> 848 /// <param name="minX"></param>
849 /// <param name="minY"></param> 849 /// <param name="minY"></param>
850 /// <param name="maxX"></param> 850 /// <param name="maxX"></param>
851 /// <param name="maxY"></param> 851 /// <param name="maxY"></param>
852 public void RequestMapBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY) 852 public void RequestMapBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY)
853 { 853 {
854 List<MapBlockData> mapBlocks; 854 List<MapBlockData> mapBlocks;
855 mapBlocks = this.commsManager.GridServer.RequestNeighbourMapBlocks(minX, minY, maxX, maxY); 855 mapBlocks = this.commsManager.GridServer.RequestNeighbourMapBlocks(minX, minY, maxX, maxY);
856 remoteClient.SendMapBlock(mapBlocks); 856 remoteClient.SendMapBlock(mapBlocks);
857 } 857 }
858 858
859 /// <summary> 859 /// <summary>
860 /// 860 ///
861 /// </summary> 861 /// </summary>
862 /// <param name="remoteClient"></param> 862 /// <param name="remoteClient"></param>
863 /// <param name="RegionHandle"></param> 863 /// <param name="RegionHandle"></param>
864 /// <param name="position"></param> 864 /// <param name="position"></param>
865 /// <param name="lookAt"></param> 865 /// <param name="lookAt"></param>
866 /// <param name="flags"></param> 866 /// <param name="flags"></param>
867 public void RequestTeleportLocation(IClientAPI remoteClient, ulong regionHandle, LLVector3 position, LLVector3 lookAt, uint flags) 867 public void RequestTeleportLocation(IClientAPI remoteClient, ulong regionHandle, LLVector3 position, LLVector3 lookAt, uint flags)
868 { 868 {
869 if (regionHandle == this.m_regionHandle) 869 if (regionHandle == this.m_regionHandle)
870 { 870 {
871 if (this.Avatars.ContainsKey(remoteClient.AgentId)) 871 if (this.Avatars.ContainsKey(remoteClient.AgentId))
872 { 872 {
873 remoteClient.SendTeleportLocationStart(); 873 remoteClient.SendTeleportLocationStart();
874 remoteClient.SendLocalTeleport(position, lookAt, flags); 874 remoteClient.SendLocalTeleport(position, lookAt, flags);
875 this.Avatars[remoteClient.AgentId].Teleport(position); 875 this.Avatars[remoteClient.AgentId].Teleport(position);
876 } 876 }
877 } 877 }
878 else 878 else
879 { 879 {
880 RegionInfo reg = this.RequestNeighbouringRegionInfo(regionHandle); 880 RegionInfo reg = this.RequestNeighbouringRegionInfo(regionHandle);
881 if (reg != null) 881 if (reg != null)
882 { 882 {
883 remoteClient.SendTeleportLocationStart(); 883 remoteClient.SendTeleportLocationStart();
884 AgentCircuitData agent = remoteClient.RequestClientInfo(); 884 AgentCircuitData agent = remoteClient.RequestClientInfo();
885 agent.BaseFolder = LLUUID.Zero; 885 agent.BaseFolder = LLUUID.Zero;
886 agent.InventoryFolder = LLUUID.Zero; 886 agent.InventoryFolder = LLUUID.Zero;
887 agent.startpos = new LLVector3(128, 128, 70); 887 agent.startpos = new LLVector3(128, 128, 70);
888 agent.child = true; 888 agent.child = true;
889 this.commsManager.InterRegion.InformRegionOfChildAgent(regionHandle, agent); 889 this.commsManager.InterRegion.InformRegionOfChildAgent(regionHandle, agent);
890 this.commsManager.InterRegion.ExpectAvatarCrossing(regionHandle, remoteClient.AgentId, position); 890 this.commsManager.InterRegion.ExpectAvatarCrossing(regionHandle, remoteClient.AgentId, position);
891 891
892 remoteClient.SendRegionTeleport(regionHandle, 13, reg.ExternalEndPoint, 4, (1 << 4)); 892 remoteClient.SendRegionTeleport(regionHandle, 13, reg.ExternalEndPoint, 4, (1 << 4));
893 893
894 } 894 }
895 } 895 }
896 } 896 }
897 897
898 /// <summary> 898 /// <summary>
899 /// 899 ///
900 /// </summary> 900 /// </summary>
901 /// <param name="regionhandle"></param> 901 /// <param name="regionhandle"></param>
902 /// <param name="agentID"></param> 902 /// <param name="agentID"></param>
903 /// <param name="position"></param> 903 /// <param name="position"></param>
904 public bool InformNeighbourOfCrossing(ulong regionhandle, LLUUID agentID, LLVector3 position) 904 public bool InformNeighbourOfCrossing(ulong regionhandle, LLUUID agentID, LLVector3 position)
905 { 905 {
906 return this.commsManager.InterRegion.ExpectAvatarCrossing(regionhandle, agentID, position); 906 return this.commsManager.InterRegion.ExpectAvatarCrossing(regionhandle, agentID, position);
907 } 907 }
908 908
909 public void performParcelPrimCountUpdate() 909 public void performParcelPrimCountUpdate()
910 { 910 {
911 m_parcelManager.resetAllParcelPrimCounts(); 911 m_parcelManager.resetAllParcelPrimCounts();
912 m_eventManager.TriggerParcelPrimCountUpdate(); 912 m_eventManager.TriggerParcelPrimCountUpdate();
913 m_parcelManager.finalizeParcelPrimCountUpdate(); 913 m_parcelManager.finalizeParcelPrimCountUpdate();
914 m_parcelManager.parcelPrimCountTainted = false; 914 m_parcelManager.parcelPrimCountTainted = false;
915 } 915 }
916 #endregion 916 #endregion
917 917
918 } 918 }
919} 919}