DialogModule.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 OpenSim.Region.Framework.Interfaces;
  35. using OpenSim.Region.Framework.Scenes;
  36. using OpenSim.Services.Interfaces;
  37. namespace OpenSim.Region.CoreModules.Avatar.Dialog
  38. {
  39. public class DialogModule : IRegionModule, IDialogModule
  40. {
  41. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  42. protected Scene m_scene;
  43. public void Initialise(Scene scene, IConfigSource source)
  44. {
  45. m_scene = scene;
  46. m_scene.RegisterModuleInterface<IDialogModule>(this);
  47. m_scene.AddCommand(
  48. this, "alert", "alert <message>",
  49. "Send an alert to everyone",
  50. HandleAlertConsoleCommand);
  51. m_scene.AddCommand(
  52. this, "alert-user", "alert-user <first> <last> <message>",
  53. "Send an alert to a user",
  54. HandleAlertConsoleCommand);
  55. }
  56. public void PostInitialise() {}
  57. public void Close() {}
  58. public string Name { get { return "Dialog Module"; } }
  59. public bool IsSharedModule { get { return false; } }
  60. public void SendAlertToUser(IClientAPI client, string message)
  61. {
  62. SendAlertToUser(client, message, false);
  63. }
  64. public void SendAlertToUser(IClientAPI client, string message, bool modal)
  65. {
  66. client.SendAgentAlertMessage(message, modal);
  67. }
  68. public void SendAlertToUser(UUID agentID, string message)
  69. {
  70. SendAlertToUser(agentID, message, false);
  71. }
  72. public void SendAlertToUser(UUID agentID, string message, bool modal)
  73. {
  74. ScenePresence sp = m_scene.GetScenePresence(agentID);
  75. if (sp != null)
  76. sp.ControllingClient.SendAgentAlertMessage(message, modal);
  77. }
  78. public void SendAlertToUser(string firstName, string lastName, string message, bool modal)
  79. {
  80. ScenePresence presence = m_scene.GetScenePresence(firstName, lastName);
  81. if (presence != null)
  82. presence.ControllingClient.SendAgentAlertMessage(message, modal);
  83. }
  84. public void SendGeneralAlert(string message)
  85. {
  86. m_scene.ForEachRootClient(delegate(IClientAPI client)
  87. {
  88. client.SendAlertMessage(message);
  89. });
  90. }
  91. public void SendDialogToUser(
  92. UUID avatarID, string objectName, UUID objectID, UUID ownerID,
  93. string message, UUID textureID, int ch, string[] buttonlabels)
  94. {
  95. UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, ownerID);
  96. string ownerFirstName, ownerLastName;
  97. if (account != null)
  98. {
  99. ownerFirstName = account.FirstName;
  100. ownerLastName = account.LastName;
  101. }
  102. else
  103. {
  104. ownerFirstName = "(unknown";
  105. ownerLastName = "user)";
  106. }
  107. ScenePresence sp = m_scene.GetScenePresence(avatarID);
  108. if (sp != null)
  109. sp.ControllingClient.SendDialog(
  110. objectName, objectID, ownerID, ownerFirstName, ownerLastName, message, textureID, ch, buttonlabels);
  111. }
  112. public void SendUrlToUser(
  113. UUID avatarID, string objectName, UUID objectID, UUID ownerID, bool groupOwned, string message, string url)
  114. {
  115. ScenePresence sp = m_scene.GetScenePresence(avatarID);
  116. if (sp != null)
  117. sp.ControllingClient.SendLoadURL(objectName, objectID, ownerID, groupOwned, message, url);
  118. }
  119. public void SendTextBoxToUser(UUID avatarid, string message, int chatChannel, string name, UUID objectid, UUID ownerid)
  120. {
  121. UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, ownerid);
  122. string ownerFirstName, ownerLastName;
  123. UUID ownerID = UUID.Zero;
  124. if (account != null)
  125. {
  126. ownerFirstName = account.FirstName;
  127. ownerLastName = account.LastName;
  128. ownerID = account.PrincipalID;
  129. }
  130. else
  131. {
  132. ownerFirstName = "(unknown";
  133. ownerLastName = "user)";
  134. }
  135. ScenePresence sp = m_scene.GetScenePresence(avatarid);
  136. if (sp != null)
  137. sp.ControllingClient.SendTextBoxRequest(message, chatChannel, name, ownerID, ownerFirstName, ownerLastName, objectid);
  138. }
  139. public void SendNotificationToUsersInRegion(
  140. UUID fromAvatarID, string fromAvatarName, string message)
  141. {
  142. m_scene.ForEachRootClient(delegate(IClientAPI client)
  143. {
  144. client.SendBlueBoxMessage(fromAvatarID, fromAvatarName, message);
  145. });
  146. }
  147. /// <summary>
  148. /// Handle an alert command from the console.
  149. /// </summary>
  150. /// <param name="module"></param>
  151. /// <param name="cmdparams"></param>
  152. public void HandleAlertConsoleCommand(string module, string[] cmdparams)
  153. {
  154. if (m_scene.ConsoleScene() != null && m_scene.ConsoleScene() != m_scene)
  155. return;
  156. string message = string.Empty;
  157. if (cmdparams[0].ToLower().Equals("alert"))
  158. {
  159. message = CombineParams(cmdparams, 1);
  160. m_log.InfoFormat("[DIALOG]: Sending general alert in region {0} with message {1}",
  161. m_scene.RegionInfo.RegionName, message);
  162. SendGeneralAlert(message);
  163. }
  164. else if (cmdparams.Length > 3)
  165. {
  166. string firstName = cmdparams[1];
  167. string lastName = cmdparams[2];
  168. message = CombineParams(cmdparams, 3);
  169. m_log.InfoFormat(
  170. "[DIALOG]: Sending alert in region {0} to {1} {2} with message {3}",
  171. m_scene.RegionInfo.RegionName, firstName, lastName, message);
  172. SendAlertToUser(firstName, lastName, message, false);
  173. }
  174. else
  175. {
  176. MainConsole.Instance.Output(
  177. "Usage: alert <message> | alert-user <first> <last> <message>");
  178. return;
  179. }
  180. }
  181. private string CombineParams(string[] commandParams, int pos)
  182. {
  183. string result = string.Empty;
  184. for (int i = pos; i < commandParams.Length; i++)
  185. {
  186. result += commandParams[i] + " ";
  187. }
  188. return result;
  189. }
  190. }
  191. }