DialogModule.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. SendAlertToUser(client, message, false);
  77. }
  78. public void SendAlertToUser(IClientAPI client, string message,
  79. bool modal)
  80. {
  81. client.SendAgentAlertMessage(message, modal);
  82. }
  83. public void SendAlertToUser(UUID agentID, string message)
  84. {
  85. SendAlertToUser(agentID, message, false);
  86. }
  87. public void SendAlertToUser(UUID agentID, string message, bool modal)
  88. {
  89. ScenePresence sp = m_scene.GetScenePresence(agentID);
  90. if (sp != null)
  91. sp.ControllingClient.SendAgentAlertMessage(message, modal);
  92. }
  93. public void SendAlertToUser(string firstName, string lastName,
  94. string message, bool modal)
  95. {
  96. ScenePresence presence = m_scene.GetScenePresence(firstName,
  97. lastName);
  98. if (presence != null)
  99. {
  100. presence.ControllingClient.SendAgentAlertMessage(message,
  101. modal);
  102. }
  103. }
  104. public void SendGeneralAlert(string message)
  105. {
  106. m_scene.ForEachRootClient(delegate(IClientAPI client)
  107. {
  108. client.SendAlertMessage(message);
  109. });
  110. }
  111. public void SendDialogToUser(UUID avatarID, string objectName,
  112. UUID objectID, UUID ownerID, string message, UUID textureID,
  113. int ch, string[] buttonlabels)
  114. {
  115. string username = m_scene.UserManagementModule.GetUserName(ownerID);
  116. string ownerFirstName, ownerLastName = String.Empty;
  117. if (!String.IsNullOrEmpty(username))
  118. {
  119. string[] parts = username.Split(' ');
  120. ownerFirstName = parts[0];
  121. if (parts.Length > 1)
  122. ownerLastName = username.Split(' ')[1];
  123. }
  124. else
  125. {
  126. ownerFirstName = "(unknown";
  127. ownerLastName = "user)";
  128. }
  129. ScenePresence sp = m_scene.GetScenePresence(avatarID);
  130. if (sp != null)
  131. {
  132. sp.ControllingClient.SendDialog(objectName, objectID, ownerID,
  133. ownerFirstName, ownerLastName, message, textureID, ch,
  134. buttonlabels);
  135. }
  136. }
  137. public void SendUrlToUser(UUID avatarID, string objectName,
  138. UUID objectID, UUID ownerID, bool groupOwned, string message,
  139. string url)
  140. {
  141. ScenePresence sp = m_scene.GetScenePresence(avatarID);
  142. if (sp != null)
  143. {
  144. sp.ControllingClient.SendLoadURL(objectName, objectID,
  145. ownerID, groupOwned, message, url);
  146. }
  147. }
  148. public void SendTextBoxToUser(UUID avatarid, string message,
  149. int chatChannel, string name, UUID objectid, UUID ownerID)
  150. {
  151. string username = m_scene.UserManagementModule.GetUserName(ownerID);
  152. string ownerFirstName, ownerLastName = String.Empty;
  153. if (!String.IsNullOrEmpty(username))
  154. {
  155. string[] parts = username.Split(' ');
  156. ownerFirstName = parts[0];
  157. if (parts.Length > 1)
  158. ownerLastName = username.Split(' ')[1];
  159. }
  160. else
  161. {
  162. ownerFirstName = "(unknown";
  163. ownerLastName = "user)";
  164. }
  165. ScenePresence sp = m_scene.GetScenePresence(avatarid);
  166. if (sp != null)
  167. {
  168. sp.ControllingClient.SendTextBoxRequest(message, chatChannel,
  169. name, ownerID, ownerFirstName, ownerLastName,
  170. objectid);
  171. }
  172. }
  173. public void SendNotificationToUsersInRegion(UUID fromAvatarID,
  174. string fromAvatarName, string message)
  175. {
  176. m_scene.ForEachRootClient(delegate(IClientAPI client)
  177. {
  178. client.SendBlueBoxMessage(fromAvatarID, fromAvatarName,
  179. message);
  180. });
  181. }
  182. /// <summary>
  183. /// Handle an alert command from the console.
  184. /// </summary>
  185. /// <param name="module"></param>
  186. /// <param name="cmdparams"></param>
  187. public void HandleAlertConsoleCommand(string module,
  188. string[] cmdparams)
  189. {
  190. if (m_scene.ConsoleScene() != null &&
  191. m_scene.ConsoleScene() != m_scene)
  192. {
  193. return;
  194. }
  195. string message = string.Empty;
  196. if (cmdparams[0].ToLower().Equals("alert"))
  197. {
  198. message = CombineParams(cmdparams, 1);
  199. m_log.InfoFormat("[DIALOG]: Sending general alert in region {0} with message {1}",
  200. m_scene.RegionInfo.RegionName, message);
  201. SendGeneralAlert(message);
  202. }
  203. else if (cmdparams.Length > 3)
  204. {
  205. string firstName = cmdparams[1];
  206. string lastName = cmdparams[2];
  207. message = CombineParams(cmdparams, 3);
  208. m_log.InfoFormat("[DIALOG]: Sending alert in region {0} to {1} {2} with message {3}",
  209. m_scene.RegionInfo.RegionName, firstName, lastName,
  210. message);
  211. SendAlertToUser(firstName, lastName, message, false);
  212. }
  213. else
  214. {
  215. MainConsole.Instance.Output(
  216. "Usage: alert <message> | alert-user <first> <last> <message>");
  217. return;
  218. }
  219. }
  220. private string CombineParams(string[] commandParams, int pos)
  221. {
  222. string result = string.Empty;
  223. for (int i = pos; i < commandParams.Length; i++)
  224. {
  225. result += commandParams[i] + " ";
  226. }
  227. return result;
  228. }
  229. }
  230. }