Advertisement
Guest User

report.cs

a guest
Jun 28th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.54 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Reflection;
  5. using log4net;
  6. using Nini.Config;
  7. using Mono.Addins;
  8. using OpenMetaverse;
  9. using OpenMetaverse.StructuredData;
  10. using OpenSim.Framework;
  11. using OpenSim.Data;
  12. using OpenSim.Framework.Servers.HttpServer;
  13. using OpenSim.Region.Framework.Interfaces;
  14. using OpenSim.Region.Framework.Scenes;
  15. using Caps = OpenSim.Framework.Capabilities.Caps;
  16.  
  17.  
  18. namespace Quill.Framework
  19. {
  20. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
  21.  
  22. public class AbuseReports : ISharedRegionModule
  23. {
  24. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  25.  
  26. private bool m_enabled = true;
  27. private List<Scene> m_SceneList = new List<Scene>();
  28.  
  29. public void Initialise(IConfigSource source)
  30. {
  31. IConfig cnf = source.Configs["AbuseReports"];
  32. if (cnf != null)
  33. m_enabled = cnf.GetBoolean("Enabled", true);
  34. }
  35.  
  36. public void AddRegion(Scene scene)
  37. {
  38. if (!m_enabled)
  39. return;
  40.  
  41. lock (m_SceneList)
  42. {
  43. if (!m_SceneList.Contains(scene))
  44. m_SceneList.Add(scene);
  45. }
  46. //scene.EventManager.OnMakeRootAgent += OnMakeRootAgent;
  47. //scene.EventManager.OnMakeChildAgent += OnMakeChildAgent;
  48. scene.EventManager.OnNewClient += OnNewClient;
  49. scene.EventManager.OnRegisterCaps += RegisterCaps;
  50. //scene.EventManager.OnClosingClient += OnClosingClient;
  51. }
  52.  
  53. private void OnClosingClient(IClientAPI client)
  54. {
  55. client.OnUserReport -= UserReport;
  56. }
  57. public void RemoveRegion(Scene scene)
  58. {
  59. if (!m_enabled)
  60. return;
  61.  
  62. lock (m_SceneList)
  63. {
  64. if (m_SceneList.Contains(scene))
  65. m_SceneList.Remove(scene);
  66. }
  67. scene.EventManager.OnNewClient -= OnNewClient;
  68.  
  69. }
  70. public void RegionLoaded(Scene scene)
  71. {
  72. }
  73.  
  74. public void PostInitialise()
  75. {
  76. }
  77.  
  78. public Type ReplaceableInterface
  79. {
  80. get { return null; }
  81. }
  82.  
  83. public string Name
  84. {
  85. get { return "AbuseReports"; }
  86. }
  87. public void Close()
  88. {
  89. }
  90. public bool IsSharedModule
  91. {
  92. get { return true; }
  93. }
  94.  
  95. private void OnNewClient(IClientAPI client)
  96. {
  97. client.OnUserReport += UserReport;
  98. }
  99.  
  100. private void UserReport(IClientAPI client, string regionName, UUID abuserID, byte catagory, byte checkflags, string details, UUID objectID, Vector3 position, byte reportType, UUID screenshotID, string summery, UUID reporter)
  101. {
  102. AbuseReport report = new AbuseReport();
  103. report.ObjectUUID = objectID;
  104. report.ObjectPosition = position.ToString();
  105. report.Active = true;
  106. report.Checked = false;
  107. report.Notes = "";
  108. report.AssignedTo = "No One";
  109. report.ScreenshotID = screenshotID;
  110. if (objectID != UUID.Zero)
  111. {
  112. SceneObjectPart Object = ((Scene)client.Scene).GetSceneObjectPart(objectID);
  113. report.ObjectName = Object.Name;
  114. }
  115. else
  116. report.ObjectName = "";
  117.  
  118. string[] detailssplit = details.Split('\n');
  119.  
  120. string AbuseDetails = detailssplit[detailssplit.Length - 1];
  121.  
  122. report.AbuseDetails = AbuseDetails;
  123.  
  124. report.ReporterName = client.Name;
  125.  
  126. string[] findRegion = summery.Split('|');
  127. report.RegionName = findRegion[1];
  128.  
  129. string[] findLocation = summery.Split('(');
  130. string[] findLocationend = findLocation[1].Split(')');
  131. report.AbuseLocation = findLocationend[0];
  132.  
  133. string[] findCategory = summery.Split('[');
  134. string[] findCategoryend = findCategory[1].Split(']');
  135. report.Category = findCategoryend[0];
  136.  
  137. string[] findAbuserName = summery.Split('{');
  138. string[] findAbuserNameend = findAbuserName[1].Split('}');
  139. report.AbuserName = findAbuserNameend[0];
  140.  
  141. string[] findSummary = summery.Split('\"');
  142.  
  143. string abuseSummary = findSummary[1];
  144. if (findSummary.Length != 0)
  145. {
  146. abuseSummary = findSummary[1];
  147. }
  148. report.Number = (-1);
  149. report.AbuseSummary = abuseSummary;
  150. m_log.Info(UUID.Zero +"qlittlefeather@gmail.com" + "Abuse Report" + "This abuse report was submitted by " +
  151. report.ReporterName + " against " + report.AbuserName + " at " + report.AbuseLocation + " in your region " + report.RegionName +
  152. ". Summary: " + report.AbuseSummary + ". Details: " + report.AbuseDetails + ".");
  153.  
  154.  
  155.  
  156. EstateSettings ES = client.Scene.RegionInfo.EstateSettings;
  157. //If the abuse email is set up and the email module is available, send the email
  158.  
  159. IEmailModule Email = m_SceneList[0].RequestModuleInterface<IEmailModule>();
  160.  
  161. Email.SendEmail(UUID.Zero, "qlittlefeather@gmail.com", "Abuse Report", "This abuse report was submitted by " +
  162. report.ReporterName + " against " + report.AbuserName + " at " + report.AbuseLocation + " in your region " + report.RegionName +
  163. ". Summary: " + report.AbuseSummary + ". Details: " + report.AbuseDetails + ".");
  164.  
  165.  
  166. }
  167.  
  168. private void RegisterCaps(UUID agentID, Caps caps)
  169. {
  170. UUID capuuid = UUID.Random();
  171.  
  172. IRequestHandler SendUserReportWithScreenshot
  173. = new RestHTTPHandler(
  174. "POST", "/CAPS/" + capuuid + "/",
  175. delegate(Hashtable m_dhttpMethod)
  176. {
  177. return ProcessSendUserReportWithScreenshot(m_dhttpMethod, capuuid, agentID);
  178. });
  179.  
  180.  
  181.  
  182. caps.RegisterHandler("SendUserReportWithScreenshot", SendUserReportWithScreenshot);
  183.  
  184.  
  185.  
  186. }
  187. private Hashtable ProcessSendUserReportWithScreenshot(Hashtable m_dhttpMethod, UUID capuuid, UUID agentID)
  188. {
  189. ScenePresence SP = findScenePresence(agentID);
  190. string RegionName = (string)m_dhttpMethod["abuse-region-name"];
  191. UUID AbuserID = UUID.Parse((string)m_dhttpMethod["abuser-id"]);
  192. byte Category = byte.Parse((string)m_dhttpMethod["category"]);
  193. byte CheckFlags = byte.Parse((string)m_dhttpMethod["check-flags"]);
  194. string details = (string)m_dhttpMethod["details"];
  195. UUID objectID = UUID.Parse((string)m_dhttpMethod["object-id"]);
  196. Vector3 position = Vector3.Zero;
  197.  
  198. byte ReportType = byte.Parse((string)m_dhttpMethod["report-type"]);
  199. UUID ScreenShotID = UUID.Parse((string)m_dhttpMethod["screenshot-id"]);
  200. string summary = (string)m_dhttpMethod["summary"];
  201. UserReport(SP.ControllingClient, RegionName, AbuserID, Category, CheckFlags,
  202. details, objectID, position, ReportType, ScreenShotID, summary, SP.UUID);
  203.  
  204. return new Hashtable();
  205. }
  206. #region Helpers
  207.  
  208. public ScenePresence findScenePresence(UUID agentID)
  209. {
  210. ScenePresence SP = null;
  211. foreach (Scene scene in m_SceneList)
  212. {
  213. SP = scene.GetScenePresence(agentID);
  214. if (SP != null)
  215. {
  216. return SP;
  217. }
  218. }
  219. return null;
  220. }
  221.  
  222. #endregion
  223. }
  224. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement