DialogModule.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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.ForEachScenePresence(delegate(ScenePresence presence)
  87. {
  88. if (!presence.IsChildAgent)
  89. presence.ControllingClient.SendAlertMessage(message);
  90. });
  91. }
  92. public void SendDialogToUser(
  93. UUID avatarID, string objectName, UUID objectID, UUID ownerID,
  94. string message, UUID textureID, int ch, string[] buttonlabels)
  95. {
  96. UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, ownerID);
  97. string ownerFirstName, ownerLastName;
  98. if (account != null)
  99. {
  100. ownerFirstName = account.FirstName;
  101. ownerLastName = account.LastName;
  102. }
  103. else
  104. {
  105. ownerFirstName = "(unknown";
  106. ownerLastName = "user)";
  107. }
  108. ScenePresence sp = m_scene.GetScenePresence(avatarID);
  109. if (sp != null)
  110. sp.ControllingClient.SendDialog(
  111. objectName, objectID, ownerID, ownerFirstName, ownerLastName, message, textureID, ch, buttonlabels);
  112. }
  113. public void SendUrlToUser(
  114. UUID avatarID, string objectName, UUID objectID, UUID ownerID, bool groupOwned, string message, string url)
  115. {
  116. ScenePresence sp = m_scene.GetScenePresence(avatarID);
  117. if (sp != null)
  118. sp.ControllingClient.SendLoadURL(objectName, objectID, ownerID, groupOwned, message, url);
  119. }
  120. public void SendTextBoxToUser(UUID avatarid, string message, int chatChannel, string name, UUID objectid, UUID ownerid)
  121. {
  122. UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, ownerid);
  123. string ownerFirstName, ownerLastName;
  124. UUID ownerID = UUID.Zero;
  125. if (account != null)
  126. {
  127. ownerFirstName = account.FirstName;
  128. ownerLastName = account.LastName;
  129. ownerID = account.PrincipalID;
  130. }
  131. else
  132. {
  133. ownerFirstName = "(unknown";
  134. ownerLastName = "user)";
  135. }
  136. ScenePresence sp = m_scene.GetScenePresence(avatarid);
  137. if (sp != null)
  138. sp.ControllingClient.SendTextBoxRequest(message, chatChannel, name, ownerID, ownerFirstName, ownerLastName, objectid);
  139. }
  140. public void SendNotificationToUsersInRegion(
  141. UUID fromAvatarID, string fromAvatarName, string message)
  142. {
  143. m_scene.ForEachScenePresence(delegate(ScenePresence presence)
  144. {
  145. if (!presence.IsChildAgent)
  146. presence.ControllingClient.SendBlueBoxMessage(fromAvatarID, fromAvatarName, message);
  147. });
  148. }
  149. /// <summary>
  150. /// Handle an alert command from the console.
  151. /// </summary>
  152. /// <param name="module"></param>
  153. /// <param name="cmdparams"></param>
  154. public void HandleAlertConsoleCommand(string module, string[] cmdparams)
  155. {
  156. if (m_scene.ConsoleScene() != null && m_scene.ConsoleScene() != m_scene)
  157. return;
  158. string message = string.Empty;
  159. if (cmdparams[0].ToLower().Equals("alert"))
  160. {
  161. message = CombineParams(cmdparams, 1);
  162. m_log.InfoFormat("[DIALOG]: Sending general alert in region {0} with message {1}",
  163. m_scene.RegionInfo.RegionName, message);
  164. SendGeneralAlert(message);
  165. }
  166. else if (cmdparams.Length > 3)
  167. {
  168. string firstName = cmdparams[1];
  169. string lastName = cmdparams[2];
  170. message = CombineParams(cmdparams, 3);
  171. m_log.InfoFormat(
  172. "[DIALOG]: Sending alert in region {0} to {1} {2} with message {3}",
  173. m_scene.RegionInfo.RegionName, firstName, lastName, message);
  174. SendAlertToUser(firstName, lastName, message, false);
  175. }
  176. else
  177. {
  178. OpenSim.Framework.Console.MainConsole.Instance.Output(
  179. "Usage: alert <message> | alert-user <first> <last> <message>");
  180. return;
  181. }
  182. }
  183. private string CombineParams(string[] commandParams, int pos)
  184. {
  185. string result = string.Empty;
  186. for (int i = pos; i < commandParams.Length; i++)
  187. {
  188. result += commandParams[i] + " ";
  189. }
  190. return result;
  191. }
  192. }
  193. }