DialogModule.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. using System;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using log4net;
  31. using Nini.Config;
  32. using OpenMetaverse;
  33. using OpenSim.Framework;
  34. using Mono.Addins;
  35. using OpenSim.Region.Framework.Interfaces;
  36. using OpenSim.Region.Framework.Scenes;
  37. using OpenSim.Services.Interfaces;
  38. namespace OpenSim.Region.CoreModules.Avatar.Dialog
  39. {
  40. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "DialogModule")]
  41. public class DialogModule : IDialogModule, INonSharedRegionModule
  42. {
  43. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  44. protected Scene m_scene;
  45. public void Initialise(IConfigSource source) { }
  46. public Type ReplaceableInterface { get { return null; } }
  47. public void AddRegion(Scene scene)
  48. {
  49. m_scene = scene;
  50. m_scene.RegisterModuleInterface<IDialogModule>(this);
  51. }
  52. public void RegionLoaded(Scene scene)
  53. {
  54. if (scene != m_scene)
  55. return;
  56. m_scene.AddCommand(
  57. "Users", this, "alert", "alert <message>",
  58. "Send an alert to everyone",
  59. HandleAlertConsoleCommand);
  60. m_scene.AddCommand(
  61. "Users", this, "alert-user",
  62. "alert-user <first> <last> <message>",
  63. "Send an alert to a user",
  64. HandleAlertConsoleCommand);
  65. }
  66. public void RemoveRegion(Scene scene)
  67. {
  68. if (scene != m_scene)
  69. return;
  70. m_scene.UnregisterModuleInterface<IDialogModule>(this);
  71. }
  72. public void Close() { }
  73. public string Name { get { return "Dialog Module"; } }
  74. public void SendAlertToUser(IClientAPI client, string message)
  75. {
  76. client?.SendAgentAlertMessage(message, false);
  77. }
  78. public void SendAlertToUser(IClientAPI client, string message, bool modal)
  79. {
  80. client?.SendAgentAlertMessage(message, modal);
  81. }
  82. public void SendAlertToUser(UUID agentID, string message)
  83. {
  84. ScenePresence sp = m_scene.GetScenePresence(agentID);
  85. sp?.ControllingClient.SendAgentAlertMessage(message, false);
  86. }
  87. public void SendAlertToUser(UUID agentID, string message, bool modal)
  88. {
  89. ScenePresence sp = m_scene.GetScenePresence(agentID);
  90. sp?.ControllingClient.SendAgentAlertMessage(message, modal);
  91. }
  92. public void SendAlertToUser(string firstName, string lastName, string message, bool modal)
  93. {
  94. ScenePresence sp= m_scene.GetScenePresence(firstName, lastName);
  95. sp?.ControllingClient.SendAgentAlertMessage(message, modal);
  96. }
  97. public void SendGeneralAlert(string message)
  98. {
  99. m_scene.ForEachRootClient(delegate(IClientAPI client)
  100. {
  101. client.SendAlertMessage(message);
  102. });
  103. }
  104. private bool GetOwnerName(UUID partID, out string ownerFirstName, out string ownerLastName)
  105. {
  106. SceneObjectPart sop = m_scene.GetSceneObjectPart(partID);
  107. if(sop != null)
  108. return sop.GetOwnerName(out ownerFirstName, out ownerLastName);
  109. ownerFirstName = string.Empty;
  110. ownerLastName = string.Empty;
  111. return false;
  112. }
  113. // legacy
  114. public void SendDialogToUser(UUID avatarID, string objectName,
  115. UUID objectID, UUID ownerID, string message, UUID textureID,
  116. int ch, string[] buttonlabels)
  117. {
  118. ScenePresence sp = m_scene.GetScenePresence(avatarID);
  119. if (sp != null)
  120. {
  121. if(GetOwnerName(objectID, out string ownerFirstName, out string ownerLastName))
  122. {
  123. sp.ControllingClient.SendDialog(objectName, objectID, ownerID,
  124. ownerFirstName, ownerLastName, message, textureID, ch, buttonlabels);
  125. }
  126. }
  127. }
  128. public void SendDialogToUser(UUID avatarID, string objectName,
  129. UUID objectID, UUID ownerID, string ownerFirstName, string ownerLastName,string message, UUID textureID,
  130. int ch, string[] buttonlabels)
  131. {
  132. ScenePresence sp = m_scene.GetScenePresence(avatarID);
  133. sp?.ControllingClient.SendDialog(objectName, objectID, ownerID,
  134. ownerFirstName, ownerLastName, message, textureID, ch, buttonlabels);
  135. }
  136. public void SendUrlToUser(UUID avatarID, string objectName,
  137. UUID objectID, UUID ownerID, bool groupOwned, string message,
  138. string url)
  139. {
  140. ScenePresence sp = m_scene.GetScenePresence(avatarID);
  141. sp?.ControllingClient.SendLoadURL(objectName, objectID,
  142. ownerID, groupOwned, message, url);
  143. }
  144. // legacy
  145. public void SendTextBoxToUser(UUID avatarid, string message,
  146. int chatChannel, string name, UUID objectid, UUID ownerID)
  147. {
  148. ScenePresence sp = m_scene.GetScenePresence(avatarid);
  149. if (sp != null)
  150. {
  151. if (GetOwnerName(objectid, out string ownerFirstName, out string ownerLastName))
  152. {
  153. sp.ControllingClient.SendTextBoxRequest(message, chatChannel,
  154. name, ownerID, ownerFirstName, ownerLastName, objectid);
  155. }
  156. }
  157. }
  158. public void SendTextBoxToUser(UUID avatarid, string message,
  159. int chatChannel, string name, UUID objectid, string ownerFirstName, string ownerLastName, UUID ownerID)
  160. {
  161. ScenePresence sp = m_scene.GetScenePresence(avatarid);
  162. sp?.ControllingClient.SendTextBoxRequest(message, chatChannel,
  163. name, ownerID, ownerFirstName, ownerLastName,
  164. objectid);
  165. }
  166. public void SendNotificationToUsersInRegion(UUID fromAvatarID, string fromAvatarName, string message)
  167. {
  168. m_scene.ForEachRootClient(delegate(IClientAPI client)
  169. {
  170. client.SendAgentAlertMessage(message, false);
  171. });
  172. }
  173. /// <summary>
  174. /// Handle an alert command from the console.
  175. /// </summary>
  176. /// <param name="module"></param>
  177. /// <param name="cmdparams"></param>
  178. public void HandleAlertConsoleCommand(string module, string[] cmdparams)
  179. {
  180. if (m_scene.ConsoleScene() != null && m_scene.ConsoleScene() != m_scene)
  181. {
  182. return;
  183. }
  184. string message = string.Empty;
  185. if (cmdparams[0].ToLower().Equals("alert"))
  186. {
  187. message = CombineParams(cmdparams, 1);
  188. m_log.InfoFormat("[DIALOG]: Sending general alert in region {0} with message {1}",
  189. m_scene.RegionInfo.RegionName, message);
  190. SendGeneralAlert(message);
  191. }
  192. else if (cmdparams.Length > 3)
  193. {
  194. string firstName = cmdparams[1];
  195. string lastName = cmdparams[2];
  196. message = CombineParams(cmdparams, 3);
  197. m_log.InfoFormat("[DIALOG]: Sending alert in region {0} to {1} {2} with message {3}",
  198. m_scene.RegionInfo.RegionName, firstName, lastName,
  199. message);
  200. SendAlertToUser(firstName, lastName, message, false);
  201. }
  202. else
  203. {
  204. MainConsole.Instance.Output(
  205. "Usage: alert <message> | alert-user <first> <last> <message>");
  206. return;
  207. }
  208. }
  209. private string CombineParams(string[] commandParams, int pos)
  210. {
  211. string result = string.Empty;
  212. for (int i = pos; i < commandParams.Length; i++)
  213. {
  214. result += commandParams[i] + " ";
  215. }
  216. return result;
  217. }
  218. }
  219. }