diff options
Diffstat (limited to 'OpenSim.RegionServer/world/World.cs')
-rw-r--r-- | OpenSim.RegionServer/world/World.cs | 646 |
1 files changed, 0 insertions, 646 deletions
diff --git a/OpenSim.RegionServer/world/World.cs b/OpenSim.RegionServer/world/World.cs deleted file mode 100644 index 99fb8e0..0000000 --- a/OpenSim.RegionServer/world/World.cs +++ /dev/null | |||
@@ -1,646 +0,0 @@ | |||
1 | using System; | ||
2 | using libsecondlife; | ||
3 | using libsecondlife.Packets; | ||
4 | using System.Collections.Generic; | ||
5 | using System.Text; | ||
6 | using System.Reflection; | ||
7 | using System.IO; | ||
8 | using System.Threading; | ||
9 | using OpenSim.Physics.Manager; | ||
10 | using OpenSim.Framework.Interfaces; | ||
11 | using OpenSim.Framework.Types; | ||
12 | using OpenSim.Framework.Terrain; | ||
13 | using OpenSim.Framework.Inventory; | ||
14 | using OpenSim.Assets; | ||
15 | //using OpenSim.world.scripting; | ||
16 | using OpenSim.RegionServer.world.scripting; | ||
17 | using OpenSim.Terrain; | ||
18 | |||
19 | namespace OpenSim.world | ||
20 | { | ||
21 | public partial class World : WorldBase, ILocalStorageReceiver, IScriptAPI | ||
22 | { | ||
23 | public object LockPhysicsEngine = new object(); | ||
24 | public Dictionary<libsecondlife.LLUUID, Avatar> Avatars; | ||
25 | public Dictionary<libsecondlife.LLUUID, Primitive> Prims; | ||
26 | //public ScriptEngine Scripts; | ||
27 | public uint _localNumber = 0; | ||
28 | private PhysicsScene phyScene; | ||
29 | private float timeStep = 0.1f; | ||
30 | public ILocalStorage localStorage; | ||
31 | private Random Rand = new Random(); | ||
32 | private uint _primCount = 702000; | ||
33 | private int storageCount; | ||
34 | private Dictionary<LLUUID, ScriptHandler> m_scriptHandlers; | ||
35 | private Dictionary<string, ScriptFactory> m_scripts; | ||
36 | private Mutex updateLock; | ||
37 | public string m_datastore; | ||
38 | |||
39 | #region Properties | ||
40 | public PhysicsScene PhysScene | ||
41 | { | ||
42 | set | ||
43 | { | ||
44 | this.phyScene = value; | ||
45 | } | ||
46 | get | ||
47 | { | ||
48 | return (this.phyScene); | ||
49 | } | ||
50 | } | ||
51 | #endregion | ||
52 | |||
53 | #region Constructors | ||
54 | /// <summary> | ||
55 | /// Creates a new World class, and a region to go with it. | ||
56 | /// </summary> | ||
57 | /// <param name="clientThreads">Dictionary to contain client threads</param> | ||
58 | /// <param name="regionHandle">Region Handle for this region</param> | ||
59 | /// <param name="regionName">Region Name for this region</param> | ||
60 | public World(Dictionary<uint, ClientView> clientThreads, RegionInfo regInfo, ulong regionHandle, string regionName) | ||
61 | { | ||
62 | try | ||
63 | { | ||
64 | updateLock = new Mutex(false); | ||
65 | m_clientThreads = clientThreads; | ||
66 | m_regionHandle = regionHandle; | ||
67 | m_regionName = regionName; | ||
68 | m_regInfo = regInfo; | ||
69 | |||
70 | m_scriptHandlers = new Dictionary<LLUUID, ScriptHandler>(); | ||
71 | m_scripts = new Dictionary<string, ScriptFactory>(); | ||
72 | |||
73 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs - creating new entitities instance"); | ||
74 | Entities = new Dictionary<libsecondlife.LLUUID, Entity>(); | ||
75 | Avatars = new Dictionary<LLUUID, Avatar>(); | ||
76 | Prims = new Dictionary<LLUUID, Primitive>(); | ||
77 | |||
78 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs - creating LandMap"); | ||
79 | TerrainManager = new TerrainManager(new SecondLife()); | ||
80 | Terrain = new TerrainEngine(); | ||
81 | Avatar.SetupTemplate("avatar-texture.dat"); | ||
82 | // MainConsole.Instance.WriteLine("World.cs - Creating script engine instance"); | ||
83 | // Initialise this only after the world has loaded | ||
84 | // Scripts = new ScriptEngine(this); | ||
85 | Avatar.LoadAnims(); | ||
86 | this.SetDefaultScripts(); | ||
87 | this.LoadScriptEngines(); | ||
88 | } | ||
89 | catch (Exception e) | ||
90 | { | ||
91 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.CRITICAL, "World.cs: Constructor failed with exception " + e.ToString()); | ||
92 | } | ||
93 | } | ||
94 | #endregion | ||
95 | |||
96 | #region Script Methods | ||
97 | /// <summary> | ||
98 | /// Loads a new script into the specified entity | ||
99 | /// </summary> | ||
100 | /// <param name="entity">Entity to be scripted</param> | ||
101 | /// <param name="script">The script to load</param> | ||
102 | public void AddScript(Entity entity, Script script) | ||
103 | { | ||
104 | try | ||
105 | { | ||
106 | ScriptHandler scriptHandler = new ScriptHandler(script, entity, this); | ||
107 | m_scriptHandlers.Add(scriptHandler.ScriptId, scriptHandler); | ||
108 | } | ||
109 | catch (Exception e) | ||
110 | { | ||
111 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: AddScript() - Failed with exception " + e.ToString()); | ||
112 | } | ||
113 | } | ||
114 | |||
115 | /// <summary> | ||
116 | /// Loads a new script into the specified entity, using a script loaded from a string. | ||
117 | /// </summary> | ||
118 | /// <param name="entity">The entity to be scripted</param> | ||
119 | /// <param name="scriptData">The string containing the script</param> | ||
120 | public void AddScript(Entity entity, string scriptData) | ||
121 | { | ||
122 | try | ||
123 | { | ||
124 | int scriptstart = 0; | ||
125 | int scriptend = 0; | ||
126 | string substring; | ||
127 | scriptstart = scriptData.LastIndexOf("<Script>"); | ||
128 | scriptend = scriptData.LastIndexOf("</Script>"); | ||
129 | substring = scriptData.Substring(scriptstart + 8, scriptend - scriptstart - 8); | ||
130 | substring = substring.Trim(); | ||
131 | //Console.WriteLine("searching for script to add: " + substring); | ||
132 | |||
133 | ScriptFactory scriptFactory; | ||
134 | //Console.WriteLine("script string is " + substring); | ||
135 | if (substring.StartsWith("<ScriptEngine:")) | ||
136 | { | ||
137 | string substring1 = ""; | ||
138 | string script = ""; | ||
139 | // Console.WriteLine("searching for script engine"); | ||
140 | substring1 = substring.Remove(0, 14); | ||
141 | int dev = substring1.IndexOf(','); | ||
142 | string sEngine = substring1.Substring(0, dev); | ||
143 | substring1 = substring1.Remove(0, dev + 1); | ||
144 | int end = substring1.IndexOf('>'); | ||
145 | string sName = substring1.Substring(0, end); | ||
146 | //Console.WriteLine(" script info : " + sEngine + " , " + sName); | ||
147 | int startscript = substring.IndexOf('>'); | ||
148 | script = substring.Remove(0, startscript + 1); | ||
149 | // Console.WriteLine("script data is " + script); | ||
150 | if (this.scriptEngines.ContainsKey(sEngine)) | ||
151 | { | ||
152 | this.scriptEngines[sEngine].LoadScript(script, sName, entity.localid); | ||
153 | } | ||
154 | } | ||
155 | else if (this.m_scripts.TryGetValue(substring, out scriptFactory)) | ||
156 | { | ||
157 | //Console.WriteLine("added script"); | ||
158 | this.AddScript(entity, scriptFactory()); | ||
159 | } | ||
160 | } | ||
161 | catch (Exception e) | ||
162 | { | ||
163 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: AddScript() - Failed with exception " + e.ToString()); | ||
164 | } | ||
165 | } | ||
166 | |||
167 | #endregion | ||
168 | |||
169 | #region Update Methods | ||
170 | /// <summary> | ||
171 | /// Performs per-frame updates on the world, this should be the central world loop | ||
172 | /// </summary> | ||
173 | public override void Update() | ||
174 | { | ||
175 | updateLock.WaitOne(); | ||
176 | try | ||
177 | { | ||
178 | if (this.phyScene.IsThreaded) | ||
179 | { | ||
180 | this.phyScene.GetResults(); | ||
181 | |||
182 | } | ||
183 | |||
184 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
185 | { | ||
186 | Entities[UUID].addForces(); | ||
187 | } | ||
188 | |||
189 | lock (this.LockPhysicsEngine) | ||
190 | { | ||
191 | this.phyScene.Simulate(timeStep); | ||
192 | } | ||
193 | |||
194 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
195 | { | ||
196 | Entities[UUID].update(); | ||
197 | } | ||
198 | |||
199 | foreach (ScriptHandler scriptHandler in m_scriptHandlers.Values) | ||
200 | { | ||
201 | scriptHandler.OnFrame(); | ||
202 | } | ||
203 | foreach (IScriptEngine scripteng in this.scriptEngines.Values) | ||
204 | { | ||
205 | scripteng.OnFrame(); | ||
206 | } | ||
207 | //backup world data | ||
208 | this.storageCount++; | ||
209 | if (storageCount > 1200) //set to how often you want to backup | ||
210 | { | ||
211 | this.Backup(); | ||
212 | storageCount = 0; | ||
213 | } | ||
214 | } | ||
215 | catch (Exception e) | ||
216 | { | ||
217 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: Update() - Failed with exception " + e.ToString()); | ||
218 | } | ||
219 | updateLock.ReleaseMutex(); | ||
220 | } | ||
221 | |||
222 | public bool Backup() | ||
223 | { | ||
224 | try | ||
225 | { | ||
226 | // Terrain backup routines | ||
227 | if (Terrain.tainted > 0) | ||
228 | { | ||
229 | Terrain.tainted = 0; | ||
230 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs: Backup() - Terrain tainted, saving."); | ||
231 | localStorage.SaveMap(Terrain.getHeights1D()); | ||
232 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs: Backup() - Terrain saved, informing Physics."); | ||
233 | phyScene.SetTerrain(Terrain.getHeights1D()); | ||
234 | } | ||
235 | |||
236 | // Primitive backup routines | ||
237 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs: Backup() - Backing up Primitives"); | ||
238 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
239 | { | ||
240 | Entities[UUID].BackUp(); | ||
241 | } | ||
242 | |||
243 | // Backup successful | ||
244 | return true; | ||
245 | } | ||
246 | catch (Exception e) | ||
247 | { | ||
248 | // Backup failed | ||
249 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, "World.cs: Backup() - Backup Failed with exception " + e.ToString()); | ||
250 | return false; | ||
251 | } | ||
252 | } | ||
253 | #endregion | ||
254 | |||
255 | #region Setup Methods | ||
256 | /// <summary> | ||
257 | /// Loads a new storage subsystem from a named library | ||
258 | /// </summary> | ||
259 | /// <param name="dllName">Storage Library</param> | ||
260 | /// <returns>Successful or not</returns> | ||
261 | public bool LoadStorageDLL(string dllName) | ||
262 | { | ||
263 | try | ||
264 | { | ||
265 | Assembly pluginAssembly = Assembly.LoadFrom(dllName); | ||
266 | ILocalStorage store = null; | ||
267 | |||
268 | foreach (Type pluginType in pluginAssembly.GetTypes()) | ||
269 | { | ||
270 | if (pluginType.IsPublic) | ||
271 | { | ||
272 | if (!pluginType.IsAbstract) | ||
273 | { | ||
274 | Type typeInterface = pluginType.GetInterface("ILocalStorage", true); | ||
275 | |||
276 | if (typeInterface != null) | ||
277 | { | ||
278 | ILocalStorage plug = (ILocalStorage)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); | ||
279 | store = plug; | ||
280 | |||
281 | store.Initialise(this.m_datastore); | ||
282 | break; | ||
283 | } | ||
284 | |||
285 | typeInterface = null; | ||
286 | } | ||
287 | } | ||
288 | } | ||
289 | pluginAssembly = null; | ||
290 | this.localStorage = store; | ||
291 | return (store == null); | ||
292 | } | ||
293 | catch (Exception e) | ||
294 | { | ||
295 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: LoadStorageDLL() - Failed with exception " + e.ToString()); | ||
296 | return false; | ||
297 | } | ||
298 | } | ||
299 | |||
300 | public void SetDefaultScripts() | ||
301 | { | ||
302 | this.m_scripts.Add("FollowRandomAvatar", delegate() | ||
303 | { | ||
304 | return new OpenSim.RegionServer.world.scripting.FollowRandomAvatar(); | ||
305 | }); | ||
306 | } | ||
307 | |||
308 | #endregion | ||
309 | |||
310 | #region Regenerate Terrain | ||
311 | |||
312 | /// <summary> | ||
313 | /// Rebuilds the terrain using a procedural algorithm | ||
314 | /// </summary> | ||
315 | public void RegenerateTerrain() | ||
316 | { | ||
317 | try | ||
318 | { | ||
319 | Terrain.hills(); | ||
320 | |||
321 | lock (this.LockPhysicsEngine) | ||
322 | { | ||
323 | this.phyScene.SetTerrain(Terrain.getHeights1D()); | ||
324 | } | ||
325 | this.localStorage.SaveMap(this.Terrain.getHeights1D()); | ||
326 | |||
327 | foreach (ClientView client in m_clientThreads.Values) | ||
328 | { | ||
329 | this.SendLayerData(client); | ||
330 | } | ||
331 | |||
332 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
333 | { | ||
334 | Entities[UUID].LandRenegerated(); | ||
335 | } | ||
336 | } | ||
337 | catch (Exception e) | ||
338 | { | ||
339 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: RegenerateTerrain() - Failed with exception " + e.ToString()); | ||
340 | } | ||
341 | } | ||
342 | |||
343 | /// <summary> | ||
344 | /// Rebuilds the terrain using a 2D float array | ||
345 | /// </summary> | ||
346 | /// <param name="newMap">256,256 float array containing heights</param> | ||
347 | public void RegenerateTerrain(float[,] newMap) | ||
348 | { | ||
349 | try | ||
350 | { | ||
351 | this.Terrain.setHeights2D(newMap); | ||
352 | lock (this.LockPhysicsEngine) | ||
353 | { | ||
354 | this.phyScene.SetTerrain(this.Terrain.getHeights1D()); | ||
355 | } | ||
356 | this.localStorage.SaveMap(this.Terrain.getHeights1D()); | ||
357 | |||
358 | foreach (ClientView client in m_clientThreads.Values) | ||
359 | { | ||
360 | this.SendLayerData(client); | ||
361 | } | ||
362 | |||
363 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
364 | { | ||
365 | Entities[UUID].LandRenegerated(); | ||
366 | } | ||
367 | } | ||
368 | catch (Exception e) | ||
369 | { | ||
370 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: RegenerateTerrain() - Failed with exception " + e.ToString()); | ||
371 | } | ||
372 | } | ||
373 | |||
374 | /// <summary> | ||
375 | /// Rebuilds the terrain assuming changes occured at a specified point[?] | ||
376 | /// </summary> | ||
377 | /// <param name="changes">???</param> | ||
378 | /// <param name="pointx">???</param> | ||
379 | /// <param name="pointy">???</param> | ||
380 | public void RegenerateTerrain(bool changes, int pointx, int pointy) | ||
381 | { | ||
382 | try | ||
383 | { | ||
384 | if (changes) | ||
385 | { | ||
386 | lock (this.LockPhysicsEngine) | ||
387 | { | ||
388 | this.phyScene.SetTerrain(this.Terrain.getHeights1D()); | ||
389 | } | ||
390 | this.localStorage.SaveMap(this.Terrain.getHeights1D()); | ||
391 | |||
392 | foreach (ClientView client in m_clientThreads.Values) | ||
393 | { | ||
394 | this.SendLayerData(pointx, pointy, client); | ||
395 | } | ||
396 | } | ||
397 | } | ||
398 | catch (Exception e) | ||
399 | { | ||
400 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: RegenerateTerrain() - Failed with exception " + e.ToString()); | ||
401 | } | ||
402 | } | ||
403 | |||
404 | #endregion | ||
405 | |||
406 | #region Load Terrain | ||
407 | /// <summary> | ||
408 | /// Loads the World heightmap | ||
409 | /// </summary> | ||
410 | public override void LoadWorldMap() | ||
411 | { | ||
412 | try | ||
413 | { | ||
414 | float[] map = this.localStorage.LoadWorld(); | ||
415 | if (map == null) | ||
416 | { | ||
417 | Console.WriteLine("creating new terrain"); | ||
418 | this.Terrain.hills(); | ||
419 | |||
420 | this.localStorage.SaveMap(this.Terrain.getHeights1D()); | ||
421 | } | ||
422 | else | ||
423 | { | ||
424 | this.Terrain.setHeights1D(map); | ||
425 | } | ||
426 | } | ||
427 | catch (Exception e) | ||
428 | { | ||
429 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: LoadWorldMap() - Failed with exception " + e.ToString()); | ||
430 | } | ||
431 | } | ||
432 | #endregion | ||
433 | |||
434 | #region Primitives Methods | ||
435 | |||
436 | /// <summary> | ||
437 | /// Sends prims to a client | ||
438 | /// </summary> | ||
439 | /// <param name="RemoteClient">Client to send to</param> | ||
440 | public void GetInitialPrims(ClientView RemoteClient) | ||
441 | { | ||
442 | try | ||
443 | { | ||
444 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
445 | { | ||
446 | if (Entities[UUID] is Primitive) | ||
447 | { | ||
448 | Primitive primitive = Entities[UUID] as Primitive; | ||
449 | primitive.UpdateClient(RemoteClient); | ||
450 | } | ||
451 | } | ||
452 | } | ||
453 | catch (Exception e) | ||
454 | { | ||
455 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: GetInitialPrims() - Failed with exception " + e.ToString()); | ||
456 | } | ||
457 | } | ||
458 | |||
459 | /// <summary> | ||
460 | /// Loads the World's objects | ||
461 | /// </summary> | ||
462 | public void LoadPrimsFromStorage() | ||
463 | { | ||
464 | try | ||
465 | { | ||
466 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs: LoadPrimsFromStorage() - Loading primitives"); | ||
467 | this.localStorage.LoadPrimitives(this); | ||
468 | } | ||
469 | catch (Exception e) | ||
470 | { | ||
471 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: LoadPrimsFromStorage() - Failed with exception " + e.ToString()); | ||
472 | } | ||
473 | } | ||
474 | |||
475 | /// <summary> | ||
476 | /// Loads a specific object from storage | ||
477 | /// </summary> | ||
478 | /// <param name="prim">The object to load</param> | ||
479 | public void PrimFromStorage(PrimData prim) | ||
480 | { | ||
481 | try | ||
482 | { | ||
483 | if (prim.LocalID >= this._primCount) | ||
484 | { | ||
485 | _primCount = prim.LocalID + 1; | ||
486 | } | ||
487 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs: PrimFromStorage() - Reloading prim (localId " + prim.LocalID + " ) from storage"); | ||
488 | Primitive nPrim = new Primitive(m_clientThreads, m_regionHandle, this); | ||
489 | nPrim.CreateFromStorage(prim); | ||
490 | this.Entities.Add(nPrim.uuid, nPrim); | ||
491 | } | ||
492 | catch (Exception e) | ||
493 | { | ||
494 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: PrimFromStorage() - Failed with exception " + e.ToString()); | ||
495 | } | ||
496 | } | ||
497 | |||
498 | public void AddNewPrim(ObjectAddPacket addPacket, ClientView AgentClient) | ||
499 | { | ||
500 | AddNewPrim(addPacket, AgentClient.AgentID); | ||
501 | } | ||
502 | |||
503 | public void AddNewPrim(ObjectAddPacket addPacket, LLUUID ownerID) | ||
504 | { | ||
505 | try | ||
506 | { | ||
507 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs: AddNewPrim() - Creating new prim"); | ||
508 | Primitive prim = new Primitive(m_clientThreads, m_regionHandle, this); | ||
509 | prim.CreateFromPacket(addPacket, ownerID, this._primCount); | ||
510 | PhysicsVector pVec = new PhysicsVector(prim.Pos.X, prim.Pos.Y, prim.Pos.Z); | ||
511 | PhysicsVector pSize = new PhysicsVector(0.255f, 0.255f, 0.255f); | ||
512 | if (OpenSim.world.Avatar.PhysicsEngineFlying) | ||
513 | { | ||
514 | lock (this.LockPhysicsEngine) | ||
515 | { | ||
516 | prim.PhysActor = this.phyScene.AddPrim(pVec, pSize); | ||
517 | } | ||
518 | } | ||
519 | |||
520 | this.Entities.Add(prim.uuid, prim); | ||
521 | this._primCount++; | ||
522 | } | ||
523 | catch (Exception e) | ||
524 | { | ||
525 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: AddNewPrim() - Failed with exception " + e.ToString()); | ||
526 | } | ||
527 | } | ||
528 | |||
529 | #endregion | ||
530 | |||
531 | #region Add/Remove Avatar Methods | ||
532 | |||
533 | public override void AddViewerAgent(ClientView agentClient) | ||
534 | { | ||
535 | //register for events | ||
536 | agentClient.OnChatFromViewer += new ClientView.ChatFromViewer(this.SimChat); | ||
537 | agentClient.OnRezObject += new ClientView.RezObject(this.RezObject); | ||
538 | agentClient.OnModifyTerrain += new ClientView.ModifyTerrain(this.ModifyTerrain); | ||
539 | agentClient.OnRegionHandShakeReply += new ClientView.GenericCall(this.SendLayerData); | ||
540 | agentClient.OnRequestWearables += new ClientView.GenericCall(this.GetInitialPrims); | ||
541 | agentClient.OnRequestAvatarsData += new ClientView.GenericCall(this.SendAvatarsToClient); | ||
542 | |||
543 | try | ||
544 | { | ||
545 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs:AddViewerAgent() - Creating new avatar for remote viewer agent"); | ||
546 | Avatar newAvatar = new Avatar(agentClient, this, m_regionName, m_clientThreads, m_regionHandle, true, 20); | ||
547 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs:AddViewerAgent() - Adding new avatar to world"); | ||
548 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs:AddViewerAgent() - Starting RegionHandshake "); | ||
549 | newAvatar.SendRegionHandshake(this); | ||
550 | if (!agentClient.m_child) | ||
551 | { | ||
552 | PhysicsVector pVec = new PhysicsVector(newAvatar.Pos.X, newAvatar.Pos.Y, newAvatar.Pos.Z); | ||
553 | lock (this.LockPhysicsEngine) | ||
554 | { | ||
555 | newAvatar.PhysActor = this.phyScene.AddAvatar(pVec); | ||
556 | } | ||
557 | } | ||
558 | lock (Entities) | ||
559 | { | ||
560 | if (!Entities.ContainsKey(agentClient.AgentID)) | ||
561 | { | ||
562 | this.Entities.Add(agentClient.AgentID, newAvatar); | ||
563 | } | ||
564 | else | ||
565 | { | ||
566 | Entities[agentClient.AgentID] = newAvatar; | ||
567 | } | ||
568 | } | ||
569 | lock (Avatars) | ||
570 | { | ||
571 | if (Avatars.ContainsKey(agentClient.AgentID)) | ||
572 | { | ||
573 | Avatars[agentClient.AgentID] = newAvatar; | ||
574 | } | ||
575 | else | ||
576 | { | ||
577 | this.Avatars.Add(agentClient.AgentID, newAvatar); | ||
578 | } | ||
579 | } | ||
580 | } | ||
581 | catch (Exception e) | ||
582 | { | ||
583 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: AddViewerAgent() - Failed with exception " + e.ToString()); | ||
584 | } | ||
585 | } | ||
586 | |||
587 | public override void RemoveViewerAgent(ClientView agentClient) | ||
588 | { | ||
589 | try | ||
590 | { | ||
591 | lock (Entities) | ||
592 | { | ||
593 | Entities.Remove(agentClient.AgentID); | ||
594 | } | ||
595 | lock (Avatars) | ||
596 | { | ||
597 | Avatars.Remove(agentClient.AgentID); | ||
598 | } | ||
599 | if (agentClient.ClientAvatar.PhysActor != null) | ||
600 | { | ||
601 | //this.phyScene.RemoveAvatar(agentClient.ClientAvatar.PhysActor); | ||
602 | } | ||
603 | } | ||
604 | catch (Exception e) | ||
605 | { | ||
606 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: RemoveViewerAgent() - Failed with exception " + e.ToString()); | ||
607 | } | ||
608 | } | ||
609 | #endregion | ||
610 | |||
611 | #region Request Avatars List Methods | ||
612 | //The idea is to have a group of method that return a list of avatars meeting some requirement | ||
613 | // ie it could be all Avatars within a certain range of the calling prim/avatar. | ||
614 | |||
615 | public List<Avatar> RequestAvatarList() | ||
616 | { | ||
617 | List<Avatar> result = new List<Avatar>(); | ||
618 | |||
619 | foreach (Avatar avatar in Avatars.Values) | ||
620 | { | ||
621 | result.Add(avatar); | ||
622 | } | ||
623 | |||
624 | return result; | ||
625 | } | ||
626 | #endregion | ||
627 | |||
628 | #region ShutDown | ||
629 | /// <summary> | ||
630 | /// Tidy before shutdown | ||
631 | /// </summary> | ||
632 | public override void Close() | ||
633 | { | ||
634 | try | ||
635 | { | ||
636 | this.localStorage.ShutDown(); | ||
637 | } | ||
638 | catch (Exception e) | ||
639 | { | ||
640 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, "World.cs: Close() - Failed with exception " + e.ToString()); | ||
641 | } | ||
642 | } | ||
643 | #endregion | ||
644 | |||
645 | } | ||
646 | } | ||