DialogModule.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 <first> <last> <message>", "Send an alert to a user", HandleAlertConsoleCommand);
  49. m_scene.AddCommand(
  50. this, "alert general", "alert general <message>", "Send an alert to everyone", HandleAlertConsoleCommand);
  51. }
  52. public void PostInitialise() {}
  53. public void Close() {}
  54. public string Name { get { return "Dialog Module"; } }
  55. public bool IsSharedModule { get { return false; } }
  56. public void SendAlertToUser(IClientAPI client, string message)
  57. {
  58. SendAlertToUser(client, message, false);
  59. }
  60. public void SendAlertToUser(IClientAPI client, string message, bool modal)
  61. {
  62. client.SendAgentAlertMessage(message, modal);
  63. }
  64. public void SendAlertToUser(UUID agentID, string message)
  65. {
  66. SendAlertToUser(agentID, message, false);
  67. }
  68. public void SendAlertToUser(UUID agentID, string message, bool modal)
  69. {
  70. ScenePresence sp = m_scene.GetScenePresence(agentID);
  71. if (sp != null)
  72. sp.ControllingClient.SendAgentAlertMessage(message, modal);
  73. }
  74. public void SendAlertToUser(string firstName, string lastName, string message, bool modal)
  75. {
  76. ScenePresence presence = m_scene.GetScenePresence(firstName, lastName);
  77. if (presence != null)
  78. presence.ControllingClient.SendAgentAlertMessage(message, modal);
  79. }
  80. public void SendGeneralAlert(string message)
  81. {
  82. m_scene.ForEachScenePresence(delegate(ScenePresence presence)
  83. {
  84. if (!presence.IsChildAgent)
  85. presence.ControllingClient.SendAlertMessage(message);
  86. });
  87. }
  88. public void SendDialogToUser(
  89. UUID avatarID, string objectName, UUID objectID, UUID ownerID,
  90. string message, UUID textureID, int ch, string[] buttonlabels)
  91. {
  92. UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, ownerID);
  93. string ownerFirstName, ownerLastName;
  94. if (account != null)
  95. {
  96. ownerFirstName = account.FirstName;
  97. ownerLastName = account.LastName;
  98. }
  99. else
  100. {
  101. ownerFirstName = "(unknown";
  102. ownerLastName = "user)";
  103. }
  104. ScenePresence sp = m_scene.GetScenePresence(avatarID);
  105. if (sp != null)
  106. sp.ControllingClient.SendDialog(objectName, objectID, ownerFirstName, ownerLastName, message, textureID, ch, buttonlabels);
  107. }
  108. public void SendUrlToUser(
  109. UUID avatarID, string objectName, UUID objectID, UUID ownerID, bool groupOwned, string message, string url)
  110. {
  111. ScenePresence sp = m_scene.GetScenePresence(avatarID);
  112. if (sp != null)
  113. sp.ControllingClient.SendLoadURL(objectName, objectID, ownerID, groupOwned, message, url);
  114. }
  115. public void SendTextBoxToUser(UUID avatarid, string message, int chatChannel, string name, UUID objectid, UUID ownerid)
  116. {
  117. UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, ownerid);
  118. string ownerFirstName, ownerLastName;
  119. if (account != null)
  120. {
  121. ownerFirstName = account.FirstName;
  122. ownerLastName = account.LastName;
  123. }
  124. else
  125. {
  126. ownerFirstName = "(unknown";
  127. ownerLastName = "user)";
  128. }
  129. ScenePresence sp = m_scene.GetScenePresence(avatarid);
  130. if (sp != null)
  131. sp.ControllingClient.SendTextBoxRequest(message, chatChannel, name, ownerFirstName, ownerLastName, objectid);
  132. }
  133. public void SendNotificationToUsersInRegion(
  134. UUID fromAvatarID, string fromAvatarName, string message)
  135. {
  136. m_scene.ForEachScenePresence(delegate(ScenePresence presence)
  137. {
  138. if (!presence.IsChildAgent)
  139. presence.ControllingClient.SendBlueBoxMessage(fromAvatarID, fromAvatarName, message);
  140. });
  141. }
  142. /// <summary>
  143. /// Handle an alert command from the console.
  144. /// </summary>
  145. /// <param name="module"></param>
  146. /// <param name="cmdparams"></param>
  147. public void HandleAlertConsoleCommand(string module, string[] cmdparams)
  148. {
  149. if (m_scene.ConsoleScene() != null && m_scene.ConsoleScene() != m_scene)
  150. return;
  151. if (cmdparams[1] == "general")
  152. {
  153. string message = CombineParams(cmdparams, 2);
  154. m_log.InfoFormat(
  155. "[DIALOG]: Sending general alert in region {0} with message {1}", m_scene.RegionInfo.RegionName, message);
  156. SendGeneralAlert(message);
  157. }
  158. else
  159. {
  160. string firstName = cmdparams[1];
  161. string lastName = cmdparams[2];
  162. string message = CombineParams(cmdparams, 3);
  163. m_log.InfoFormat(
  164. "[DIALOG]: Sending alert in region {0} to {1} {2} with message {3}",
  165. m_scene.RegionInfo.RegionName, firstName, lastName, message);
  166. SendAlertToUser(firstName, lastName, message, false);
  167. }
  168. }
  169. private string CombineParams(string[] commandParams, int pos)
  170. {
  171. string result = string.Empty;
  172. for (int i = pos; i < commandParams.Length; i++)
  173. {
  174. result += commandParams[i] + " ";
  175. }
  176. return result;
  177. }
  178. }
  179. }