CMController.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  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 OpenSim 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. #region Header
  28. // CMController.cs
  29. // User: bongiojp
  30. //
  31. #endregion Header
  32. using System;
  33. using System.Collections;
  34. using System.Collections.Generic;
  35. using System.Diagnostics;
  36. using System.Threading;
  37. using OpenMetaverse;
  38. using OpenSim;
  39. using OpenSim.Framework;
  40. using OpenSim.Region.Environment.Interfaces;
  41. using OpenSim.Region.Environment.Scenes;
  42. using OpenSim.Region.Physics.Manager;
  43. using log4net;
  44. namespace OpenSim.Region.Environment.Modules.ContentManagement
  45. {
  46. /// <summary>
  47. /// 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,
  48. /// 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.
  49. /// </summary>
  50. public class CMController
  51. {
  52. #region Static Fields
  53. private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  54. /// <value>
  55. /// The queue that keeps track of which actions have happened. The MainLoop thread eats through this queue.
  56. /// </value>
  57. private static OpenSim.Framework.BlockingQueue<Work> m_WorkQueue = new OpenSim.Framework.BlockingQueue<Work>();
  58. #endregion Static Fields
  59. #region Fields
  60. //bool init = false;
  61. int m_channel = -1;
  62. /// <value>
  63. /// The estate module is used to identify which clients are estateManagers. Presently, the controller only pays attention to estate managers.
  64. /// </value>
  65. IEstateModule m_estateModule = null;
  66. //These have to be global variables, threading doesn't allow for passing parameters. (Used in MainLoop)
  67. CMModel m_model = null;
  68. /// <value>
  69. /// A list of all the scenes that should be revisioned. Controller is the only class that keeps track of all scenes in the region.
  70. /// </value>
  71. Hashtable m_sceneList = Hashtable.Synchronized(new Hashtable());
  72. State m_state = State.NONE;
  73. Thread m_thread = null;
  74. CMView m_view = null;
  75. #endregion Fields
  76. #region Constructors
  77. /// <summary>
  78. /// Initializes a work thread with an initial scene. Additional scenes should be added through the RegisterNewRegion method.
  79. /// </summary>
  80. /// <param name="model">
  81. /// <see cref="CMModel"/>
  82. /// </param>
  83. /// <param name="view">
  84. /// <see cref="CMView"/>
  85. /// </param>
  86. /// <param name="scene">
  87. /// The first scene to keep track of. <see cref="Scene"/>
  88. /// </param>
  89. /// <param name="channel">
  90. /// The simchat channel number to listen to for instructions <see cref="System.Int32"/>
  91. /// </param>
  92. public CMController(CMModel model, CMView view, Scene scene, int channel)
  93. {
  94. m_model = model; m_view = view; m_channel = channel;
  95. RegisterNewRegion(scene);
  96. Initialize(model, view, scene, channel);
  97. }
  98. #endregion Constructors
  99. #region Private Methods
  100. //------------------------------------------------ EVENTS ----------------------------------------------------//
  101. // private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, LLUUID regionID)
  102. // {
  103. // }
  104. /// <summary>
  105. /// 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.
  106. /// </summary>
  107. private SceneObjectGroup GetGroupByPrim(uint localID)
  108. {
  109. foreach (Object currScene in m_sceneList.Values)
  110. {
  111. foreach (EntityBase ent in ((Scene)currScene).GetEntities())
  112. {
  113. if (ent is SceneObjectGroup)
  114. {
  115. if (((SceneObjectGroup)ent).HasChildPrim(localID))
  116. return (SceneObjectGroup)ent;
  117. }
  118. }
  119. }
  120. return null;
  121. }
  122. private void Initialize(CMModel model, CMView view, Scene scene, int channel)
  123. {
  124. lock (this)
  125. {
  126. m_estateModule = scene.RequestModuleInterface<IEstateModule>();
  127. m_thread = new Thread(MainLoop);
  128. m_thread.Name = "Content Management";
  129. m_thread.IsBackground = true;
  130. m_thread.Start();
  131. ThreadTracker.Add(m_thread);
  132. m_state = State.NONE;
  133. }
  134. }
  135. /// <summary>
  136. /// 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.
  137. /// </summary>
  138. private void MainLoop()
  139. {
  140. try
  141. {
  142. CMModel model = m_model; CMView view = m_view; int channel = m_channel;
  143. Work currentJob = new Work();
  144. while (true)
  145. {
  146. currentJob = m_WorkQueue.Dequeue();
  147. m_log.Debug("[CONTENT MANAGEMENT] MAIN LOOP -- DeQueued a request");
  148. m_log.Debug("[CONTENT MANAGEMENT] MAIN LOOP -- Work type: " + currentJob.Type);
  149. switch (currentJob.Type)
  150. {
  151. case WorkType.NONE:
  152. break;
  153. case WorkType.OBJECTATTRIBUTECHANGE:
  154. ObjectAttributeChanged(model, view, currentJob.LocalId);
  155. break;
  156. case WorkType.PRIMITIVEADDED:
  157. PrimitiveAdded(model, view, currentJob);
  158. break;
  159. case WorkType.OBJECTDUPLICATED:
  160. ObjectDuplicated(model, view, currentJob.LocalId);
  161. break;
  162. case WorkType.OBJECTKILLED:
  163. ObjectKilled(model, view, (SceneObjectGroup) currentJob.Data1);
  164. break;
  165. case WorkType.UNDODID:
  166. UndoDid(model, view, currentJob.UUID);
  167. break;
  168. case WorkType.NEWCLIENT:
  169. NewClient(view, (IClientAPI) currentJob.Data1);
  170. break;
  171. case WorkType.SIMCHAT:
  172. m_log.Debug("[CONTENT MANAGEMENT] MAIN LOOP -- Message received: " + ((OSChatMessage) currentJob.Data1).Message);
  173. SimChat(model, view, (OSChatMessage) currentJob.Data1, channel);
  174. break;
  175. default:
  176. m_log.Debug("[CONTENT MANAGEMENT] MAIN LOOP -- uuuuuuuuuh, what?");
  177. break;
  178. }
  179. }
  180. }
  181. catch (Exception e)
  182. {
  183. // TODO: Let users in the sim and those entering it and possibly an external watchdog know what has happened
  184. m_log.ErrorFormat(
  185. "[CONTENT MANAGEMENT]: Content management thread terminating with exception. PLEASE REBOOT YOUR SIM - CONTENT MANAGEMENT WILL NOT BE AVAILABLE UNTIL YOU DO. Exception is {0}",
  186. e);
  187. }
  188. }
  189. /// <summary>
  190. /// Only called by the MainLoop. Updates the view of a new client with metaentities if diff-mode is currently enabled.
  191. /// </summary>
  192. private void NewClient(CMView view, IClientAPI client)
  193. {
  194. if ((m_state & State.SHOWING_CHANGES) > 0)
  195. view.SendMetaEntitiesToNewClient(client);
  196. }
  197. /// <summary>
  198. /// Only called by the MainLoop.
  199. /// </summary>
  200. private void ObjectAttributeChanged(CMModel model, CMView view, uint LocalId)
  201. {
  202. SceneObjectGroup group = null;
  203. if ((m_state & State.SHOWING_CHANGES) > 0)
  204. {
  205. group = GetGroupByPrim(LocalId);
  206. if (group != null)
  207. {
  208. view.DisplayAuras(model.UpdateNormalEntityEffects(group)); //Might be a normal entity (green aura)
  209. m_view.DisplayMetaEntity(group.UUID); //Might be a meta entity (blue aura)
  210. }
  211. }
  212. }
  213. /// <summary>
  214. /// Only called by the MainLoop. Displays new green auras over the newly created part when a part is shift copied.
  215. /// </summary>
  216. private void ObjectDuplicated(CMModel model, CMView view, uint localId)
  217. {
  218. if ((m_state & State.SHOWING_CHANGES) > 0)
  219. view.DisplayAuras(model.CheckForNewEntitiesMissingAuras(GetGroupByPrim(localId).Scene));
  220. }
  221. /// <summary>
  222. /// Only called by the MainLoop.
  223. /// </summary>
  224. private void ObjectKilled(CMModel model, CMView view, SceneObjectGroup group)
  225. {
  226. if ((m_state & State.SHOWING_CHANGES) > 0)
  227. {
  228. view.RemoveOrUpdateDeletedEntity(group);
  229. model.RemoveOrUpdateDeletedEntity(group);
  230. }
  231. }
  232. /// <summary>
  233. /// Only called by the MainLoop.
  234. /// </summary>
  235. private void PrimitiveAdded(CMModel model, CMView view, Work currentJob)
  236. {
  237. if ((m_state & State.SHOWING_CHANGES) > 0)
  238. {
  239. foreach (Object scene in m_sceneList.Values)
  240. m_view.DisplayAuras(model.CheckForNewEntitiesMissingAuras((Scene) scene));
  241. }
  242. }
  243. /// <summary>
  244. /// Only called by the MainLoop.
  245. /// </summary>
  246. private void UndoDid(CMModel model, CMView view, UUID uuid)
  247. {
  248. if ((m_state & State.SHOWING_CHANGES) > 0)
  249. {
  250. ContentManagementEntity ent = model.FindMetaEntityAffectedByUndo(uuid);
  251. if (ent != null)
  252. view.DisplayEntity(ent);
  253. }
  254. }
  255. #endregion Private Methods
  256. #region Protected Methods
  257. protected void GroupBeingDeleted(SceneObjectGroup group)
  258. {
  259. m_log.Debug("[CONTENT MANAGEMENT] Something was deleted!!!");
  260. Work moreWork = new Work();
  261. moreWork.Type = WorkType.OBJECTKILLED;
  262. moreWork.Data1 = group.Copy();
  263. m_WorkQueue.Enqueue(moreWork);
  264. }
  265. protected void ObjectDuplicated(uint localID, Vector3 offset, uint dupeFlags, UUID AgentID, UUID GroupID)
  266. {
  267. Work moreWork = new Work();
  268. moreWork.Type = WorkType.OBJECTDUPLICATED;
  269. moreWork.LocalId = localID;
  270. m_WorkQueue.Enqueue(moreWork);
  271. m_log.Debug("[CONTENT MANAGEMENT] dup queue");
  272. }
  273. protected void ObjectDuplicatedOnRay(uint localID, uint dupeFlags, UUID AgentID, UUID GroupID,
  274. UUID RayTargetObj, Vector3 RayEnd, Vector3 RayStart,
  275. bool BypassRaycast, bool RayEndIsIntersection, bool CopyCenters, bool CopyRotates)
  276. {
  277. Work moreWork = new Work();
  278. moreWork.Type = WorkType.OBJECTDUPLICATED;
  279. moreWork.LocalId = localID;
  280. m_WorkQueue.Enqueue(moreWork);
  281. m_log.Debug("[CONTENT MANAGEMENT] dup queue");
  282. }
  283. protected void OnNewClient(IClientAPI client)
  284. {
  285. Work moreWork = new Work();
  286. moreWork.Type = WorkType.NEWCLIENT;
  287. moreWork.Data1 = client;
  288. m_WorkQueue.Enqueue(moreWork);
  289. m_log.Debug("[CONTENT MANAGEMENT] new client");
  290. }
  291. protected void OnUnDid(IClientAPI remoteClient, UUID primId)
  292. {
  293. Work moreWork = new Work();
  294. moreWork.Type = WorkType.UNDODID;
  295. moreWork.UUID = primId;
  296. m_WorkQueue.Enqueue(moreWork);
  297. m_log.Debug("[CONTENT MANAGEMENT] undid");
  298. }
  299. /// <summary>
  300. /// Takes a list of scenes and forms a new orderd list according to the proximity of scenes to the second argument.
  301. /// </summary>
  302. protected static System.Collections.Generic.List<Scene> ScenesInOrderOfProximity(Hashtable sceneList, Scene scene)
  303. {
  304. int somethingAddedToList = 1;
  305. System.Collections.Generic.List<Scene> newList = new List<Scene>();
  306. newList.Add(scene);
  307. if (!sceneList.ContainsValue(scene))
  308. {
  309. foreach (Object sceneObj in sceneList)
  310. newList.Add((Scene) sceneObj);
  311. return newList;
  312. }
  313. while (somethingAddedToList > 0)
  314. {
  315. somethingAddedToList = 0;
  316. for (int i = 0; i < newList.Count; i++)
  317. {
  318. foreach (Object sceneObj in sceneList.Values)
  319. {
  320. if (newList[i].CheckNeighborRegion(((Scene)sceneObj).RegionInfo) && (!newList.Contains((Scene)sceneObj)))
  321. {
  322. newList.Add((Scene)sceneObj);
  323. somethingAddedToList++;
  324. }
  325. }
  326. }
  327. }
  328. foreach (Object sceneObj in sceneList.Values)
  329. if (!newList.Contains((Scene)sceneObj))
  330. newList.Add((Scene)sceneObj);
  331. return newList;
  332. }
  333. //This is stupid, the same information is contained in the first and second argument
  334. protected void SimChatSent(Object x, OSChatMessage e)
  335. {
  336. m_log.Debug("[CONTENT MANAGEMENT] SIMCHAT SENT !!!!!!!");
  337. m_log.Debug("[CONTENT MANAGEMENT] message was: " + e.Message);
  338. Work moreWork = new Work();
  339. moreWork.Type = WorkType.SIMCHAT;
  340. moreWork.Data1 = e;
  341. m_WorkQueue.Enqueue(moreWork);
  342. }
  343. /// <summary>
  344. /// Adds extra handlers to a number of events so that the controller can produce work based on the client's actions.
  345. /// </summary>
  346. protected void StartManaging(IClientAPI client)
  347. {
  348. m_log.Debug("[CONTENT MANAGEMENT] Registering channel with chat services.");
  349. // client.OnChatFromClient += SimChatSent;
  350. //init = true;
  351. OnNewClient(client);
  352. m_log.Debug("[CONTENT MANAGEMENT] Adding handlers to client.");
  353. client.OnUpdatePrimScale += UpdateSingleScale;
  354. client.OnUpdatePrimGroupScale += UpdateMultipleScale;
  355. client.OnUpdatePrimGroupPosition += UpdateMultiplePosition;
  356. client.OnUpdatePrimSinglePosition += UpdateSinglePosition;
  357. client.OnUpdatePrimGroupRotation += UpdateMultipleRotation;
  358. client.OnUpdatePrimSingleRotation += UpdateSingleRotation;
  359. client.OnAddPrim += UpdateNewParts;
  360. client.OnObjectDuplicate += ObjectDuplicated;
  361. client.OnObjectDuplicateOnRay += ObjectDuplicatedOnRay;
  362. client.OnUndo += OnUnDid;
  363. //client.OnUpdatePrimGroupMouseRotation += m_innerScene.UpdatePrimRotation;
  364. }
  365. /// <summary>
  366. ///
  367. /// </summary>
  368. protected void StopManaging(UUID clientUUID)
  369. {
  370. foreach (Object sceneobj in m_sceneList.Values)
  371. {
  372. ScenePresence presence = ((Scene)sceneobj).GetScenePresence(clientUUID);
  373. if (presence != null)
  374. {
  375. IClientAPI client = presence.ControllingClient;
  376. m_log.Debug("[CONTENT MANAGEMENT] Unregistering channel with chat services.");
  377. // client.OnChatFromViewer -= SimChatSent;
  378. m_log.Debug("[CONTENT MANAGEMENT] Removing handlers to client");
  379. client.OnUpdatePrimScale -= UpdateSingleScale;
  380. client.OnUpdatePrimGroupScale -= UpdateMultipleScale;
  381. client.OnUpdatePrimGroupPosition -= UpdateMultiplePosition;
  382. client.OnUpdatePrimSinglePosition -= UpdateSinglePosition;
  383. client.OnUpdatePrimGroupRotation -= UpdateMultipleRotation;
  384. client.OnUpdatePrimSingleRotation -= UpdateSingleRotation;
  385. client.OnAddPrim -= UpdateNewParts;
  386. client.OnObjectDuplicate -= ObjectDuplicated;
  387. client.OnObjectDuplicateOnRay -= ObjectDuplicatedOnRay;
  388. client.OnUndo -= OnUnDid;
  389. //client.OnUpdatePrimGroupMouseRotation += m_innerScene.UpdatePrimRotation;
  390. return;
  391. }
  392. }
  393. }
  394. protected void UpdateMultiplePosition(uint localID, Vector3 pos, IClientAPI remoteClient)
  395. {
  396. Work moreWork = new Work();
  397. moreWork.Type = WorkType.OBJECTATTRIBUTECHANGE;
  398. moreWork.LocalId = localID;
  399. m_WorkQueue.Enqueue(moreWork);
  400. m_log.Debug("[CONTENT MANAGEMENT] pos");
  401. }
  402. protected void UpdateMultipleRotation(uint localID, Quaternion rot, IClientAPI remoteClient)
  403. {
  404. Work moreWork = new Work();
  405. moreWork.Type = WorkType.OBJECTATTRIBUTECHANGE;
  406. moreWork.LocalId = localID;
  407. m_WorkQueue.Enqueue(moreWork);
  408. m_log.Debug("[CONTENT MANAGEMENT] rot");
  409. }
  410. protected void UpdateMultipleScale(uint localID, Vector3 scale, IClientAPI remoteClient)
  411. {
  412. Work moreWork = new Work();
  413. moreWork.Type = WorkType.OBJECTATTRIBUTECHANGE;
  414. moreWork.LocalId = localID;
  415. m_WorkQueue.Enqueue(moreWork);
  416. m_log.Debug("[CONTENT MANAGEMENT]scale");
  417. }
  418. protected void UpdateNewParts(UUID ownerID, UUID groupID, Vector3 RayEnd, Quaternion rot, PrimitiveBaseShape shape,
  419. byte bypassRaycast, Vector3 RayStart, UUID RayTargetID,
  420. byte RayEndIsIntersection)
  421. {
  422. Work moreWork = new Work();
  423. moreWork.Type = WorkType.PRIMITIVEADDED;
  424. moreWork.UUID = ownerID;
  425. m_WorkQueue.Enqueue(moreWork);
  426. m_log.Debug("[CONTENT MANAGEMENT] new parts");
  427. }
  428. protected void UpdateSinglePosition(uint localID, Vector3 pos, IClientAPI remoteClient)
  429. {
  430. Work moreWork = new Work();
  431. moreWork.Type = WorkType.OBJECTATTRIBUTECHANGE;
  432. moreWork.LocalId = localID;
  433. m_WorkQueue.Enqueue(moreWork);
  434. m_log.Debug("[CONTENT MANAGEMENT] move");
  435. }
  436. /// <summary>
  437. ///
  438. /// </summary>
  439. protected void UpdateSingleRotation(uint localID, Quaternion rot, IClientAPI remoteClient)
  440. {
  441. Work moreWork = new Work();
  442. moreWork.Type = WorkType.OBJECTATTRIBUTECHANGE;
  443. moreWork.LocalId = localID;
  444. m_WorkQueue.Enqueue(moreWork);
  445. m_log.Debug("[CONTENT MANAGEMENT] rot");
  446. }
  447. protected void UpdateSingleScale(uint localID, Vector3 scale, IClientAPI remoteClient)
  448. {
  449. Work moreWork = new Work();
  450. moreWork.Type = WorkType.OBJECTATTRIBUTECHANGE;
  451. moreWork.LocalId = localID;
  452. m_WorkQueue.Enqueue(moreWork);
  453. m_log.Debug("[CONTENT MANAGEMENT] scale");
  454. }
  455. /// <summary>
  456. /// Only called from within the SimChat method.
  457. /// </summary>
  458. protected void commit(string message, Scene scene, CMModel model, CMView view)
  459. {
  460. System.Collections.Generic.List<Scene> proximitySceneList = ScenesInOrderOfProximity(m_sceneList, scene);
  461. string[] args = message.Split(new char[] {' '});
  462. char[] logMessage = {' '};
  463. if (args.Length > 1)
  464. {
  465. logMessage = new char[message.Length - (args[0].Length)];
  466. message.CopyTo(args[0].Length, logMessage, 0, message.Length - (args[0].Length));
  467. }
  468. m_log.Debug("[CONTENT MANAGEMENT] Saving terrain and objects of region.");
  469. foreach (Scene currScene in proximitySceneList)
  470. {
  471. model.CommitRegion(currScene, new String(logMessage));
  472. view.SendSimChatMessage(scene, "Region Saved Successfully: " + currScene.RegionInfo.RegionName);
  473. }
  474. view.SendSimChatMessage(scene, "Successfully saved all regions.");
  475. m_state |= State.DIRTY;
  476. if ((m_state & State.SHOWING_CHANGES) > 0) //DISPLAY NEW CHANGES INSTEAD OF OLD CHANGES
  477. {
  478. view.SendSimChatMessage(scene, "Updating differences between new revision and current environment.");
  479. //Hide objects from users and Forget about them
  480. view.HideAllMetaEntities();
  481. view.HideAllAuras();
  482. model.DeleteAllMetaObjects();
  483. //Recreate them from backend files
  484. foreach (Scene currScene in proximitySceneList)
  485. {
  486. model.UpdateCMEntities(currScene);
  487. view.SendSimChatMessage(scene, "Finished updating differences between current scene and last revision: " + currScene.RegionInfo.RegionName);
  488. }
  489. //Display new objects to users1
  490. view.DisplayRecentChanges();
  491. view.SendSimChatMessage(scene, "Finished updating for DIFF-MODE.");
  492. m_state &= ~(State.DIRTY);
  493. m_state |= State.SHOWING_CHANGES;
  494. }
  495. }
  496. /// <summary>
  497. /// Only called from within the SimChat method.
  498. /// </summary>
  499. protected void diffmode(Scene scene, CMModel model, CMView view)
  500. {
  501. System.Collections.Generic.List<Scene> proximitySceneList = ScenesInOrderOfProximity(m_sceneList, scene);
  502. if ((m_state & State.SHOWING_CHANGES) > 0) // TURN OFF
  503. {
  504. view.SendSimChatMessage(scene, "Hiding all meta objects.");
  505. view.HideAllMetaEntities();
  506. view.HideAllAuras();
  507. view.SendSimChatMessage(scene, "Diff-mode = OFF");
  508. m_state &= ~State.SHOWING_CHANGES;
  509. return;
  510. }
  511. else // TURN ON
  512. {
  513. if ((m_state & State.DIRTY) != 0 || m_state == State.NONE)
  514. {
  515. view.SendSimChatMessage(scene, "Hiding meta objects and replacing with latest revision");
  516. //Hide objects from users and Forget about them
  517. view.HideAllMetaEntities();
  518. view.HideAllAuras();
  519. model.DeleteAllMetaObjects();
  520. //Recreate them from backend files
  521. foreach (Object currScene in m_sceneList.Values)
  522. model.UpdateCMEntities((Scene) currScene);
  523. }
  524. else if ((m_state & State.DIRTY) != 0) {
  525. view.SendSimChatMessage(scene, "Forming list of meta entities with latest revision");
  526. foreach (Scene currScene in proximitySceneList)
  527. model.UpdateCMEntities(currScene);
  528. }
  529. view.SendSimChatMessage(scene, "Displaying differences between last revision and current environment");
  530. foreach (Scene currScene in proximitySceneList)
  531. model.CheckForNewEntitiesMissingAuras(currScene);
  532. view.DisplayRecentChanges();
  533. view.SendSimChatMessage(scene, "Diff-mode = ON");
  534. m_state |= State.SHOWING_CHANGES;
  535. m_state &= ~State.DIRTY;
  536. }
  537. }
  538. /// <summary>
  539. /// Only called from within the SimChat method. Hides all auras and meta entities,
  540. /// retrieves the current scene object list with the most recent revision retrieved from the model for each scene,
  541. /// then lets the view update the clients of the new objects.
  542. /// </summary>
  543. protected void rollback(Scene scene, CMModel model, CMView view)
  544. {
  545. if ((m_state & State.SHOWING_CHANGES) > 0)
  546. {
  547. view.HideAllAuras();
  548. view.HideAllMetaEntities();
  549. }
  550. System.Collections.Generic.List<Scene> proximitySceneList = ScenesInOrderOfProximity(m_sceneList, scene);
  551. foreach (Scene currScene in proximitySceneList)
  552. model.RollbackRegion(currScene);
  553. if ((m_state & State.DIRTY) != 0)
  554. {
  555. model.DeleteAllMetaObjects();
  556. foreach (Scene currScene in proximitySceneList)
  557. model.UpdateCMEntities(currScene);
  558. }
  559. if ((m_state & State.SHOWING_CHANGES) > 0)
  560. view.DisplayRecentChanges();
  561. }
  562. #endregion Protected Methods
  563. #region Public Methods
  564. /// <summary>
  565. /// Register a new scene object to keep track of for revisioning. Starts the controller monitoring actions of clients within the given scene.
  566. /// </summary>
  567. /// <param name="scene">
  568. /// A <see cref="Scene"/>
  569. /// </param>
  570. public void RegisterNewRegion(Scene scene)
  571. {
  572. m_sceneList.Add(scene.RegionInfo.RegionID, scene);
  573. m_log.Debug("[CONTENT MANAGEMENT] Registering new region: " + scene.RegionInfo.RegionID);
  574. m_log.Debug("[CONTENT MANAGEMENT] Initializing Content Management System.");
  575. scene.EventManager.OnNewClient += StartManaging;
  576. scene.EventManager.OnChatFromClient += SimChatSent;
  577. scene.EventManager.OnRemovePresence += StopManaging;
  578. // scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel;
  579. scene.EventManager.OnObjectBeingRemovedFromScene += GroupBeingDeleted;
  580. }
  581. /// <summary>
  582. /// Only called by the MainLoop. Takes the message from a user sent to the channel and executes the proper command.
  583. /// </summary>
  584. public void SimChat(CMModel model, CMView view, OSChatMessage e, int channel)
  585. {
  586. if (e.Channel != channel)
  587. return;
  588. if (e.Sender == null)
  589. return;
  590. m_log.Debug("[CONTENT MANAGEMENT] Message received: " + e.Message);
  591. IClientAPI client = e.Sender;
  592. Scene scene = (Scene) e.Scene;
  593. string message = e.Message;
  594. string[] args = e.Message.Split(new char[] {' '});
  595. ScenePresence avatar = scene.GetScenePresence(client.AgentId);
  596. if (!(m_estateModule.IsManager(avatar.UUID)))
  597. {
  598. m_log.Debug("[CONTENT MANAGEMENT] Message sent from non Estate Manager ... ignoring.");
  599. view.SendSimChatMessage(scene, "You must be an estate manager to perform that action.");
  600. return;
  601. }
  602. switch (args[0])
  603. {
  604. case "ci":
  605. case "commit":
  606. commit(message, scene, model, view);
  607. break;
  608. case "dm":
  609. case "diff-mode":
  610. diffmode(scene, model, view);
  611. break;
  612. case "rb":
  613. case "rollback":
  614. rollback(scene, model, view);
  615. break;
  616. case "help":
  617. m_view.DisplayHelpMenu(scene);
  618. break;
  619. default:
  620. view.SendSimChatMessage(scene, "Command not found: " + args[0]);
  621. break;
  622. }
  623. }
  624. #endregion Public Methods
  625. #region Other
  626. /// <value>
  627. /// 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.
  628. /// </value>
  629. [Flags]
  630. private enum State
  631. {
  632. NONE = 0,
  633. DIRTY = 1, // The meta entities may not correctly represent the last revision.
  634. SHOWING_CHANGES = 1<<1 // The meta entities are being shown to user.
  635. }
  636. /// <value>
  637. /// The structure that defines the basic unit of work which is produced when a user sends commands to the ContentMangaementSystem.
  638. /// </value>
  639. private struct Work
  640. {
  641. #region Fields
  642. public Object Data1; //Just space for holding data.
  643. public Object Data2; //Just more space for holding data.
  644. public uint LocalId; //Convenient
  645. public WorkType Type;
  646. public UUID UUID; //Convenient
  647. #endregion Fields
  648. }
  649. /// <value>
  650. /// Identifies what the data in struct Work should be used for.
  651. /// </value>
  652. private enum WorkType
  653. {
  654. NONE,
  655. OBJECTATTRIBUTECHANGE,
  656. PRIMITIVEADDED,
  657. OBJECTDUPLICATED,
  658. OBJECTKILLED,
  659. UNDODID,
  660. NEWCLIENT,
  661. SIMCHAT
  662. }
  663. #endregion Other
  664. }
  665. }