aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/ContentManagementSystem/CMController.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/OptionalModules/ContentManagementSystem/CMController.cs')
-rw-r--r--OpenSim/Region/OptionalModules/ContentManagementSystem/CMController.cs756
1 files changed, 0 insertions, 756 deletions
diff --git a/OpenSim/Region/OptionalModules/ContentManagementSystem/CMController.cs b/OpenSim/Region/OptionalModules/ContentManagementSystem/CMController.cs
deleted file mode 100644
index 8d6c41d..0000000
--- a/OpenSim/Region/OptionalModules/ContentManagementSystem/CMController.cs
+++ /dev/null
@@ -1,756 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#region Header
29
30// CMController.cs
31// User: bongiojp
32//
33
34#endregion Header
35
36using System;
37using System.Collections;
38using System.Collections.Generic;
39using System.Diagnostics;
40using System.Threading;
41
42using OpenMetaverse;
43
44using OpenSim;
45using OpenSim.Framework;
46using OpenSim.Region.Framework.Interfaces;
47using OpenSim.Region.Framework.Scenes;
48using OpenSim.Region.Physics.Manager;
49
50using log4net;
51
52namespace OpenSim.Region.OptionalModules.ContentManagement
53{
54 /// <summary>
55 /// The controller in a Model-View-Controller framework. This controller catches actions by the avatars, creates work packets, loops through these work packets in a separate thread,
56 /// then dictates to the model how the data should change and dictates to the view which data should be displayed. The main mechanism for interaction is through the simchat system.
57 /// </summary>
58 public class CMController
59 {
60 #region Static Fields
61
62 private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
63
64 /// <value>
65 /// The queue that keeps track of which actions have happened. The MainLoop thread eats through this queue.
66 /// </value>
67 private static OpenSim.Framework.BlockingQueue<Work> m_WorkQueue = new OpenSim.Framework.BlockingQueue<Work>();
68
69 #endregion Static Fields
70
71 #region Fields
72
73 //bool init = false;
74 int m_channel = -1;
75
76 /// <value>
77 /// The estate module is used to identify which clients are estateManagers. Presently, the controller only pays attention to estate managers.
78 /// </value>
79 IEstateModule m_estateModule = null;
80
81 //These have to be global variables, threading doesn't allow for passing parameters. (Used in MainLoop)
82 CMModel m_model = null;
83
84 /// <value>
85 /// A list of all the scenes that should be revisioned. Controller is the only class that keeps track of all scenes in the region.
86 /// </value>
87 Hashtable m_sceneList = Hashtable.Synchronized(new Hashtable());
88 State m_state = State.NONE;
89 CMView m_view = null;
90
91 #endregion Fields
92
93 #region Constructors
94
95 /// <summary>
96 /// Initializes a work thread with an initial scene. Additional scenes should be added through the RegisterNewRegion method.
97 /// </summary>
98 /// <param name="model">
99 /// <see cref="CMModel"/>
100 /// </param>
101 /// <param name="view">
102 /// <see cref="CMView"/>
103 /// </param>
104 /// <param name="scene">
105 /// The first scene to keep track of. <see cref="Scene"/>
106 /// </param>
107 /// <param name="channel">
108 /// The simchat channel number to listen to for instructions <see cref="System.Int32"/>
109 /// </param>
110 public CMController(CMModel model, CMView view, Scene scene, int channel)
111 {
112 m_model = model; m_view = view; m_channel = channel;
113 RegisterNewRegion(scene);
114 Initialize(model, view, scene, channel);
115 }
116
117 #endregion Constructors
118
119 #region Private Methods
120
121 //------------------------------------------------ EVENTS ----------------------------------------------------//
122// private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, LLUUID regionID)
123// {
124// }
125
126 /// <summary>
127 /// Searches in all scenes for a SceneObjectGroup that contains a part with a specific localID. If found, the object is returned. Else null is returned.
128 /// </summary>
129 private SceneObjectGroup GetGroupByPrim(uint localID)
130 {
131 foreach (Object currScene in m_sceneList.Values)
132 {
133 foreach (EntityBase ent in ((Scene)currScene).GetEntities())
134 {
135 if (ent is SceneObjectGroup)
136 {
137 if (((SceneObjectGroup)ent).HasChildPrim(localID))
138 return (SceneObjectGroup)ent;
139 }
140 }
141 }
142 return null;
143 }
144
145 private void Initialize(CMModel model, CMView view, Scene scene, int channel)
146 {
147 lock (this)
148 {
149 m_estateModule = scene.RequestModuleInterface<IEstateModule>();
150 Watchdog.StartThread(MainLoop, "Content Management", ThreadPriority.Normal, true);
151 m_state = State.NONE;
152 }
153 }
154
155 /// <summary>
156 /// Run in a thread of its own. A endless loop that consumes (or blocks on) and work queue. Thw work queue is filled through client actions.
157 /// </summary>
158 private void MainLoop()
159 {
160 try
161 {
162 CMModel model = m_model; CMView view = m_view; int channel = m_channel;
163 Work currentJob = new Work();
164 while (true)
165 {
166 currentJob = m_WorkQueue.Dequeue();
167 m_log.Debug("[CONTENT MANAGEMENT] MAIN LOOP -- DeQueued a request");
168 m_log.Debug("[CONTENT MANAGEMENT] MAIN LOOP -- Work type: " + currentJob.Type);
169 switch (currentJob.Type)
170 {
171 case WorkType.NONE:
172 break;
173 case WorkType.OBJECTATTRIBUTECHANGE:
174 ObjectAttributeChanged(model, view, currentJob.LocalId);
175 break;
176 case WorkType.PRIMITIVEADDED:
177 PrimitiveAdded(model, view, currentJob);
178 break;
179 case WorkType.OBJECTDUPLICATED:
180 ObjectDuplicated(model, view, currentJob.LocalId);
181 break;
182 case WorkType.OBJECTKILLED:
183 ObjectKilled(model, view, (SceneObjectGroup) currentJob.Data1);
184 break;
185 case WorkType.UNDODID:
186 UndoDid(model, view, currentJob.UUID);
187 break;
188 case WorkType.NEWCLIENT:
189 NewClient(view, (IClientAPI) currentJob.Data1);
190 break;
191 case WorkType.SIMCHAT:
192 m_log.Debug("[CONTENT MANAGEMENT] MAIN LOOP -- Message received: " + ((OSChatMessage) currentJob.Data1).Message);
193 SimChat(model, view, (OSChatMessage) currentJob.Data1, channel);
194 break;
195 default:
196 m_log.Debug("[CONTENT MANAGEMENT] MAIN LOOP -- uuuuuuuuuh, what?");
197 break;
198 }
199
200 Watchdog.UpdateThread();
201 }
202 }
203 catch (Exception e)
204 {
205 // TODO: Let users in the sim and those entering it and possibly an external watchdog know what has happened
206 m_log.ErrorFormat(
207 "[CONTENT MANAGEMENT]: Content management thread terminating with exception. PLEASE REBOOT YOUR SIM - CONTENT MANAGEMENT WILL NOT BE AVAILABLE UNTIL YOU DO. Exception is {0}",
208 e);
209 }
210
211 Watchdog.RemoveThread();
212 }
213
214 /// <summary>
215 /// Only called by the MainLoop. Updates the view of a new client with metaentities if diff-mode is currently enabled.
216 /// </summary>
217 private void NewClient(CMView view, IClientAPI client)
218 {
219 if ((m_state & State.SHOWING_CHANGES) > 0)
220 view.SendMetaEntitiesToNewClient(client);
221 }
222
223 /// <summary>
224 /// Only called by the MainLoop.
225 /// </summary>
226 private void ObjectAttributeChanged(CMModel model, CMView view, uint LocalId)
227 {
228 SceneObjectGroup group = null;
229 if ((m_state & State.SHOWING_CHANGES) > 0)
230 {
231 group = GetGroupByPrim(LocalId);
232 if (group != null)
233 {
234 view.DisplayAuras(model.UpdateNormalEntityEffects(group)); //Might be a normal entity (green aura)
235 m_view.DisplayMetaEntity(group.UUID); //Might be a meta entity (blue aura)
236 }
237 }
238 }
239
240 /// <summary>
241 /// Only called by the MainLoop. Displays new green auras over the newly created part when a part is shift copied.
242 /// </summary>
243 private void ObjectDuplicated(CMModel model, CMView view, uint localId)
244 {
245 if ((m_state & State.SHOWING_CHANGES) > 0)
246 view.DisplayAuras(model.CheckForNewEntitiesMissingAuras(GetGroupByPrim(localId).Scene));
247 }
248
249 /// <summary>
250 /// Only called by the MainLoop.
251 /// </summary>
252 private void ObjectKilled(CMModel model, CMView view, SceneObjectGroup group)
253 {
254 if ((m_state & State.SHOWING_CHANGES) > 0)
255 {
256 view.RemoveOrUpdateDeletedEntity(group);
257 model.RemoveOrUpdateDeletedEntity(group);
258 }
259 }
260
261 /// <summary>
262 /// Only called by the MainLoop.
263 /// </summary>
264 private void PrimitiveAdded(CMModel model, CMView view, Work currentJob)
265 {
266 if ((m_state & State.SHOWING_CHANGES) > 0)
267 {
268 foreach (Object scene in m_sceneList.Values)
269 m_view.DisplayAuras(model.CheckForNewEntitiesMissingAuras((Scene) scene));
270 }
271 }
272
273 /// <summary>
274 /// Only called by the MainLoop.
275 /// </summary>
276 private void UndoDid(CMModel model, CMView view, UUID uuid)
277 {
278 if ((m_state & State.SHOWING_CHANGES) > 0)
279 {
280 ContentManagementEntity ent = model.FindMetaEntityAffectedByUndo(uuid);
281 if (ent != null)
282 view.DisplayEntity(ent);
283 }
284 }
285
286 #endregion Private Methods
287
288 #region Protected Methods
289
290 protected void GroupBeingDeleted(SceneObjectGroup group)
291 {
292 m_log.Debug("[CONTENT MANAGEMENT] Something was deleted!!!");
293 Work moreWork = new Work();
294 moreWork.Type = WorkType.OBJECTKILLED;
295 moreWork.Data1 = group.Copy();
296 m_WorkQueue.Enqueue(moreWork);
297 }
298
299 protected void ObjectDuplicated(uint localID, Vector3 offset, uint dupeFlags, UUID AgentID, UUID GroupID)
300 {
301 Work moreWork = new Work();
302 moreWork.Type = WorkType.OBJECTDUPLICATED;
303 moreWork.LocalId = localID;
304 m_WorkQueue.Enqueue(moreWork);
305 m_log.Debug("[CONTENT MANAGEMENT] dup queue");
306 }
307
308 protected void ObjectDuplicatedOnRay(uint localID, uint dupeFlags, UUID AgentID, UUID GroupID,
309 UUID RayTargetObj, Vector3 RayEnd, Vector3 RayStart,
310 bool BypassRaycast, bool RayEndIsIntersection, bool CopyCenters, bool CopyRotates)
311 {
312 Work moreWork = new Work();
313 moreWork.Type = WorkType.OBJECTDUPLICATED;
314 moreWork.LocalId = localID;
315 m_WorkQueue.Enqueue(moreWork);
316 m_log.Debug("[CONTENT MANAGEMENT] dup queue");
317 }
318
319 protected void OnNewClient(IClientAPI client)
320 {
321 Work moreWork = new Work();
322 moreWork.Type = WorkType.NEWCLIENT;
323 moreWork.Data1 = client;
324 m_WorkQueue.Enqueue(moreWork);
325 m_log.Debug("[CONTENT MANAGEMENT] new client");
326 }
327
328 protected void OnUnDid(IClientAPI remoteClient, UUID primId)
329 {
330 Work moreWork = new Work();
331 moreWork.Type = WorkType.UNDODID;
332 moreWork.UUID = primId;
333 m_WorkQueue.Enqueue(moreWork);
334 m_log.Debug("[CONTENT MANAGEMENT] undid");
335 }
336
337 /// <summary>
338 /// Takes a list of scenes and forms a new orderd list according to the proximity of scenes to the second argument.
339 /// </summary>
340 protected static System.Collections.Generic.List<Scene> ScenesInOrderOfProximity(Hashtable sceneList, Scene scene)
341 {
342 int somethingAddedToList = 1;
343 System.Collections.Generic.List<Scene> newList = new List<Scene>();
344 newList.Add(scene);
345
346 if (!sceneList.ContainsValue(scene))
347 {
348 foreach (Object sceneObj in sceneList)
349 newList.Add((Scene) sceneObj);
350 return newList;
351 }
352
353 while (somethingAddedToList > 0)
354 {
355 somethingAddedToList = 0;
356 for (int i = 0; i < newList.Count; i++)
357 {
358 foreach (Object sceneObj in sceneList.Values)
359 {
360 if (newList[i].CheckNeighborRegion(((Scene)sceneObj).RegionInfo) && (!newList.Contains((Scene)sceneObj)))
361 {
362 newList.Add((Scene)sceneObj);
363 somethingAddedToList++;
364 }
365 }
366 }
367 }
368
369 foreach (Object sceneObj in sceneList.Values)
370 if (!newList.Contains((Scene)sceneObj))
371 newList.Add((Scene)sceneObj);
372
373 return newList;
374 }
375
376 //This is stupid, the same information is contained in the first and second argument
377 protected void SimChatSent(Object x, OSChatMessage e)
378 {
379 m_log.Debug("[CONTENT MANAGEMENT] SIMCHAT SENT !!!!!!!");
380 m_log.Debug("[CONTENT MANAGEMENT] message was: " + e.Message);
381 Work moreWork = new Work();
382 moreWork.Type = WorkType.SIMCHAT;
383 moreWork.Data1 = e;
384 m_WorkQueue.Enqueue(moreWork);
385 }
386
387 /// <summary>
388 /// Adds extra handlers to a number of events so that the controller can produce work based on the client's actions.
389 /// </summary>
390 protected void StartManaging(IClientAPI client)
391 {
392 m_log.Debug("[CONTENT MANAGEMENT] Registering channel with chat services.");
393 // client.OnChatFromClient += SimChatSent;
394 //init = true;
395
396 OnNewClient(client);
397
398 m_log.Debug("[CONTENT MANAGEMENT] Adding handlers to client.");
399 client.OnUpdatePrimScale += UpdateSingleScale;
400 client.OnUpdatePrimGroupScale += UpdateMultipleScale;
401 client.OnUpdatePrimGroupPosition += UpdateMultiplePosition;
402 client.OnUpdatePrimSinglePosition += UpdateSinglePosition;
403 client.OnUpdatePrimGroupRotation += UpdateMultipleRotation;
404 client.OnUpdatePrimSingleRotation += UpdateSingleRotation;
405 client.OnAddPrim += UpdateNewParts;
406 client.OnObjectDuplicate += ObjectDuplicated;
407 client.OnObjectDuplicateOnRay += ObjectDuplicatedOnRay;
408 client.OnUndo += OnUnDid;
409 //client.OnUpdatePrimGroupMouseRotation += m_innerScene.UpdatePrimRotation;
410 }
411
412 /// <summary>
413 ///
414 /// </summary>
415 protected void StopManaging(UUID clientUUID)
416 {
417 foreach (Object sceneobj in m_sceneList.Values)
418 {
419 ScenePresence presence = ((Scene)sceneobj).GetScenePresence(clientUUID);
420 if (presence != null)
421 {
422 IClientAPI client = presence.ControllingClient;
423 m_log.Debug("[CONTENT MANAGEMENT] Unregistering channel with chat services.");
424 // client.OnChatFromViewer -= SimChatSent;
425
426 m_log.Debug("[CONTENT MANAGEMENT] Removing handlers to client");
427 client.OnUpdatePrimScale -= UpdateSingleScale;
428 client.OnUpdatePrimGroupScale -= UpdateMultipleScale;
429 client.OnUpdatePrimGroupPosition -= UpdateMultiplePosition;
430 client.OnUpdatePrimSinglePosition -= UpdateSinglePosition;
431 client.OnUpdatePrimGroupRotation -= UpdateMultipleRotation;
432 client.OnUpdatePrimSingleRotation -= UpdateSingleRotation;
433 client.OnAddPrim -= UpdateNewParts;
434 client.OnObjectDuplicate -= ObjectDuplicated;
435 client.OnObjectDuplicateOnRay -= ObjectDuplicatedOnRay;
436 client.OnUndo -= OnUnDid;
437 //client.OnUpdatePrimGroupMouseRotation += m_innerScene.UpdatePrimRotation;
438 return;
439 }
440 }
441 }
442
443 protected void UpdateMultiplePosition(uint localID, Vector3 pos, IClientAPI remoteClient)
444 {
445 Work moreWork = new Work();
446 moreWork.Type = WorkType.OBJECTATTRIBUTECHANGE;
447 moreWork.LocalId = localID;
448 m_WorkQueue.Enqueue(moreWork);
449 m_log.Debug("[CONTENT MANAGEMENT] pos");
450 }
451
452 protected void UpdateMultipleRotation(uint localID, Quaternion rot, IClientAPI remoteClient)
453 {
454 Work moreWork = new Work();
455 moreWork.Type = WorkType.OBJECTATTRIBUTECHANGE;
456 moreWork.LocalId = localID;
457 m_WorkQueue.Enqueue(moreWork);
458 m_log.Debug("[CONTENT MANAGEMENT] rot");
459 }
460
461 protected void UpdateMultipleScale(uint localID, Vector3 scale, IClientAPI remoteClient)
462 {
463 Work moreWork = new Work();
464 moreWork.Type = WorkType.OBJECTATTRIBUTECHANGE;
465 moreWork.LocalId = localID;
466 m_WorkQueue.Enqueue(moreWork);
467 m_log.Debug("[CONTENT MANAGEMENT]scale");
468 }
469
470 protected void UpdateNewParts(UUID ownerID, UUID groupID, Vector3 RayEnd, Quaternion rot, PrimitiveBaseShape shape,
471 byte bypassRaycast, Vector3 RayStart, UUID RayTargetID,
472 byte RayEndIsIntersection)
473 {
474 Work moreWork = new Work();
475 moreWork.Type = WorkType.PRIMITIVEADDED;
476 moreWork.UUID = ownerID;
477 m_WorkQueue.Enqueue(moreWork);
478 m_log.Debug("[CONTENT MANAGEMENT] new parts");
479 }
480
481 protected void UpdateSinglePosition(uint localID, Vector3 pos, IClientAPI remoteClient)
482 {
483 Work moreWork = new Work();
484 moreWork.Type = WorkType.OBJECTATTRIBUTECHANGE;
485 moreWork.LocalId = localID;
486 m_WorkQueue.Enqueue(moreWork);
487 m_log.Debug("[CONTENT MANAGEMENT] move");
488 }
489
490 /// <summary>
491 ///
492 /// </summary>
493 protected void UpdateSingleRotation(uint localID, Quaternion rot, IClientAPI remoteClient)
494 {
495 Work moreWork = new Work();
496 moreWork.Type = WorkType.OBJECTATTRIBUTECHANGE;
497 moreWork.LocalId = localID;
498 m_WorkQueue.Enqueue(moreWork);
499 m_log.Debug("[CONTENT MANAGEMENT] rot");
500 }
501
502 protected void UpdateSingleScale(uint localID, Vector3 scale, IClientAPI remoteClient)
503 {
504 Work moreWork = new Work();
505 moreWork.Type = WorkType.OBJECTATTRIBUTECHANGE;
506 moreWork.LocalId = localID;
507 m_WorkQueue.Enqueue(moreWork);
508 m_log.Debug("[CONTENT MANAGEMENT] scale");
509 }
510
511 /// <summary>
512 /// Only called from within the SimChat method.
513 /// </summary>
514 protected void commit(string message, Scene scene, CMModel model, CMView view)
515 {
516 System.Collections.Generic.List<Scene> proximitySceneList = ScenesInOrderOfProximity(m_sceneList, scene);
517
518 string[] args = message.Split(new char[] {' '});
519
520 char[] logMessage = {' '};
521 if (args.Length > 1)
522 {
523 logMessage = new char[message.Length - (args[0].Length)];
524 message.CopyTo(args[0].Length, logMessage, 0, message.Length - (args[0].Length));
525 }
526
527 m_log.Debug("[CONTENT MANAGEMENT] Saving terrain and objects of region.");
528 foreach (Scene currScene in proximitySceneList)
529 {
530 model.CommitRegion(currScene, new String(logMessage));
531 view.SendSimChatMessage(scene, "Region Saved Successfully: " + currScene.RegionInfo.RegionName);
532 }
533
534 view.SendSimChatMessage(scene, "Successfully saved all regions.");
535 m_state |= State.DIRTY;
536
537 if ((m_state & State.SHOWING_CHANGES) > 0) //DISPLAY NEW CHANGES INSTEAD OF OLD CHANGES
538 {
539 view.SendSimChatMessage(scene, "Updating differences between new revision and current environment.");
540 //Hide objects from users and Forget about them
541 view.HideAllMetaEntities();
542 view.HideAllAuras();
543 model.DeleteAllMetaObjects();
544
545 //Recreate them from backend files
546 foreach (Scene currScene in proximitySceneList)
547 {
548 model.UpdateCMEntities(currScene);
549 view.SendSimChatMessage(scene, "Finished updating differences between current scene and last revision: " + currScene.RegionInfo.RegionName);
550 }
551
552 //Display new objects to users1
553 view.DisplayRecentChanges();
554 view.SendSimChatMessage(scene, "Finished updating for DIFF-MODE.");
555 m_state &= ~(State.DIRTY);
556 m_state |= State.SHOWING_CHANGES;
557 }
558 }
559
560 /// <summary>
561 /// Only called from within the SimChat method.
562 /// </summary>
563 protected void diffmode(Scene scene, CMModel model, CMView view)
564 {
565 System.Collections.Generic.List<Scene> proximitySceneList = ScenesInOrderOfProximity(m_sceneList, scene);
566
567 if ((m_state & State.SHOWING_CHANGES) > 0) // TURN OFF
568 {
569 view.SendSimChatMessage(scene, "Hiding all meta objects.");
570 view.HideAllMetaEntities();
571 view.HideAllAuras();
572 view.SendSimChatMessage(scene, "Diff-mode = OFF");
573
574 m_state &= ~State.SHOWING_CHANGES;
575 return;
576 }
577 else // TURN ON
578 {
579 if ((m_state & State.DIRTY) != 0 || m_state == State.NONE)
580 {
581 view.SendSimChatMessage(scene, "Hiding meta objects and replacing with latest revision");
582 //Hide objects from users and Forget about them
583 view.HideAllMetaEntities();
584 view.HideAllAuras();
585 model.DeleteAllMetaObjects();
586 //Recreate them from backend files
587 foreach (Object currScene in m_sceneList.Values)
588 model.UpdateCMEntities((Scene) currScene);
589 }
590 else if ((m_state & State.DIRTY) != 0) {
591 view.SendSimChatMessage(scene, "Forming list of meta entities with latest revision");
592 foreach (Scene currScene in proximitySceneList)
593 model.UpdateCMEntities(currScene);
594 }
595
596 view.SendSimChatMessage(scene, "Displaying differences between last revision and current environment");
597 foreach (Scene currScene in proximitySceneList)
598 model.CheckForNewEntitiesMissingAuras(currScene);
599 view.DisplayRecentChanges();
600
601 view.SendSimChatMessage(scene, "Diff-mode = ON");
602 m_state |= State.SHOWING_CHANGES;
603 m_state &= ~State.DIRTY;
604 }
605 }
606
607 /// <summary>
608 /// Only called from within the SimChat method. Hides all auras and meta entities,
609 /// retrieves the current scene object list with the most recent revision retrieved from the model for each scene,
610 /// then lets the view update the clients of the new objects.
611 /// </summary>
612 protected void rollback(Scene scene, CMModel model, CMView view)
613 {
614 if ((m_state & State.SHOWING_CHANGES) > 0)
615 {
616 view.HideAllAuras();
617 view.HideAllMetaEntities();
618 }
619
620 System.Collections.Generic.List<Scene> proximitySceneList = ScenesInOrderOfProximity(m_sceneList, scene);
621 foreach (Scene currScene in proximitySceneList)
622 model.RollbackRegion(currScene);
623
624 if ((m_state & State.DIRTY) != 0)
625 {
626 model.DeleteAllMetaObjects();
627 foreach (Scene currScene in proximitySceneList)
628 model.UpdateCMEntities(currScene);
629 }
630
631 if ((m_state & State.SHOWING_CHANGES) > 0)
632 view.DisplayRecentChanges();
633 }
634
635 #endregion Protected Methods
636
637 #region Public Methods
638
639 /// <summary>
640 /// Register a new scene object to keep track of for revisioning. Starts the controller monitoring actions of clients within the given scene.
641 /// </summary>
642 /// <param name="scene">
643 /// A <see cref="Scene"/>
644 /// </param>
645 public void RegisterNewRegion(Scene scene)
646 {
647 m_sceneList.Add(scene.RegionInfo.RegionID, scene);
648
649 m_log.Debug("[CONTENT MANAGEMENT] Registering new region: " + scene.RegionInfo.RegionID);
650 m_log.Debug("[CONTENT MANAGEMENT] Initializing Content Management System.");
651
652 scene.EventManager.OnNewClient += StartManaging;
653 scene.EventManager.OnChatFromClient += SimChatSent;
654 scene.EventManager.OnRemovePresence += StopManaging;
655 // scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel;
656 scene.EventManager.OnObjectBeingRemovedFromScene += GroupBeingDeleted;
657 }
658
659 /// <summary>
660 /// Only called by the MainLoop. Takes the message from a user sent to the channel and executes the proper command.
661 /// </summary>
662 public void SimChat(CMModel model, CMView view, OSChatMessage e, int channel)
663 {
664 if (e.Channel != channel)
665 return;
666 if (e.Sender == null)
667 return;
668
669 m_log.Debug("[CONTENT MANAGEMENT] Message received: " + e.Message);
670
671 IClientAPI client = e.Sender;
672 Scene scene = (Scene) e.Scene;
673 string message = e.Message;
674 string[] args = e.Message.Split(new char[] {' '});
675
676 ScenePresence avatar = scene.GetScenePresence(client.AgentId);
677
678 if (!(m_estateModule.IsManager(avatar.UUID)))
679 {
680 m_log.Debug("[CONTENT MANAGEMENT] Message sent from non Estate Manager ... ignoring.");
681 view.SendSimChatMessage(scene, "You must be an estate manager to perform that action.");
682 return;
683 }
684
685 switch (args[0])
686 {
687 case "ci":
688 case "commit":
689 commit(message, scene, model, view);
690 break;
691 case "dm":
692 case "diff-mode":
693 diffmode(scene, model, view);
694 break;
695 case "rb":
696 case "rollback":
697 rollback(scene, model, view);
698 break;
699 case "help":
700 m_view.DisplayHelpMenu(scene);
701 break;
702 default:
703 view.SendSimChatMessage(scene, "Command not found: " + args[0]);
704 break;
705 }
706 }
707
708 #endregion Public Methods
709
710 #region Other
711
712 /// <value>
713 /// Used to keep track of whether a list has been produced yet and whether that list is up-to-date compard to latest revision on disk.
714 /// </value>
715 [Flags]
716 private enum State
717 {
718 NONE = 0,
719 DIRTY = 1, // The meta entities may not correctly represent the last revision.
720 SHOWING_CHANGES = 1<<1 // The meta entities are being shown to user.
721 }
722
723 /// <value>
724 /// The structure that defines the basic unit of work which is produced when a user sends commands to the ContentMangaementSystem.
725 /// </value>
726 private struct Work
727 {
728 #region Fields
729
730 public Object Data1; //Just space for holding data.
731 public Object Data2; //Just more space for holding data.
732 public uint LocalId; //Convenient
733 public WorkType Type;
734 public UUID UUID; //Convenient
735
736 #endregion Fields
737 }
738
739 /// <value>
740 /// Identifies what the data in struct Work should be used for.
741 /// </value>
742 private enum WorkType
743 {
744 NONE,
745 OBJECTATTRIBUTECHANGE,
746 PRIMITIVEADDED,
747 OBJECTDUPLICATED,
748 OBJECTKILLED,
749 UNDODID,
750 NEWCLIENT,
751 SIMCHAT
752 }
753
754 #endregion Other
755 }
756}