CMController.cs 30 KB

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