OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
DialogModule.cs
Go to the documentation of this file.
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 
28 using System;
29 using System.Collections.Generic;
30 using System.Reflection;
31 using log4net;
32 using Nini.Config;
33 using OpenMetaverse;
34 using OpenSim.Framework;
35 using Mono.Addins;
36 
37 using OpenSim.Region.Framework.Interfaces;
38 using OpenSim.Region.Framework.Scenes;
39 using OpenSim.Services.Interfaces;
40 
41 namespace OpenSim.Region.CoreModules.Avatar.Dialog
42 {
43  [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "DialogModule")]
45  {
46  private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 
48  protected Scene m_scene;
49 
50  public void Initialise(IConfigSource source) { }
51 
52  public Type ReplaceableInterface { get { return null; } }
53 
54  public void AddRegion(Scene scene)
55  {
56  m_scene = scene;
57  m_scene.RegisterModuleInterface<IDialogModule>(this);
58  }
59 
60  public void RegionLoaded(Scene scene)
61  {
62  if (scene != m_scene)
63  return;
64 
65  m_scene.AddCommand(
66  "Users", this, "alert", "alert <message>",
67  "Send an alert to everyone",
68  HandleAlertConsoleCommand);
69 
70  m_scene.AddCommand(
71  "Users", this, "alert-user",
72  "alert-user <first> <last> <message>",
73  "Send an alert to a user",
74  HandleAlertConsoleCommand);
75  }
76 
77  public void RemoveRegion(Scene scene)
78  {
79  if (scene != m_scene)
80  return;
81 
82  m_scene.UnregisterModuleInterface<IDialogModule>(this);
83  }
84 
85  public void Close() { }
86  public string Name { get { return "Dialog Module"; } }
87 
88  public void SendAlertToUser(IClientAPI client, string message)
89  {
90  SendAlertToUser(client, message, false);
91  }
92 
93  public void SendAlertToUser(IClientAPI client, string message,
94  bool modal)
95  {
96  client.SendAgentAlertMessage(message, modal);
97  }
98 
99  public void SendAlertToUser(UUID agentID, string message)
100  {
101  SendAlertToUser(agentID, message, false);
102  }
103 
104  public void SendAlertToUser(UUID agentID, string message, bool modal)
105  {
106  ScenePresence sp = m_scene.GetScenePresence(agentID);
107 
108  if (sp != null)
109  sp.ControllingClient.SendAgentAlertMessage(message, modal);
110  }
111 
112  public void SendAlertToUser(string firstName, string lastName,
113  string message, bool modal)
114  {
115  ScenePresence presence = m_scene.GetScenePresence(firstName,
116  lastName);
117  if (presence != null)
118  {
119  presence.ControllingClient.SendAgentAlertMessage(message,
120  modal);
121  }
122  }
123 
124  public void SendGeneralAlert(string message)
125  {
126  m_scene.ForEachRootClient(delegate(IClientAPI client)
127  {
128  client.SendAlertMessage(message);
129  });
130  }
131 
132  public void SendDialogToUser(UUID avatarID, string objectName,
133  UUID objectID, UUID ownerID, string message, UUID textureID,
134  int ch, string[] buttonlabels)
135  {
136  string username = m_scene.UserManagementModule.GetUserName(ownerID);
137  string ownerFirstName, ownerLastName = String.Empty;
138  if (!String.IsNullOrEmpty(username))
139  {
140  string[] parts = username.Split(' ');
141  ownerFirstName = parts[0];
142  if (parts.Length > 1)
143  ownerLastName = username.Split(' ')[1];
144  }
145  else
146  {
147  ownerFirstName = "(unknown";
148  ownerLastName = "user)";
149  }
150 
151  ScenePresence sp = m_scene.GetScenePresence(avatarID);
152  if (sp != null)
153  {
154  sp.ControllingClient.SendDialog(objectName, objectID, ownerID,
155  ownerFirstName, ownerLastName, message, textureID, ch,
156  buttonlabels);
157  }
158  }
159 
160  public void SendUrlToUser(UUID avatarID, string objectName,
161  UUID objectID, UUID ownerID, bool groupOwned, string message,
162  string url)
163  {
164  ScenePresence sp = m_scene.GetScenePresence(avatarID);
165 
166  if (sp != null)
167  {
168  sp.ControllingClient.SendLoadURL(objectName, objectID,
169  ownerID, groupOwned, message, url);
170  }
171  }
172 
173  public void SendTextBoxToUser(UUID avatarid, string message,
174  int chatChannel, string name, UUID objectid, UUID ownerID)
175  {
176  string username = m_scene.UserManagementModule.GetUserName(ownerID);
177  string ownerFirstName, ownerLastName = String.Empty;
178  if (!String.IsNullOrEmpty(username))
179  {
180  string[] parts = username.Split(' ');
181  ownerFirstName = parts[0];
182  if (parts.Length > 1)
183  ownerLastName = username.Split(' ')[1];
184  }
185  else
186  {
187  ownerFirstName = "(unknown";
188  ownerLastName = "user)";
189  }
190 
191  ScenePresence sp = m_scene.GetScenePresence(avatarid);
192 
193  if (sp != null)
194  {
195  sp.ControllingClient.SendTextBoxRequest(message, chatChannel,
196  name, ownerID, ownerFirstName, ownerLastName,
197  objectid);
198  }
199  }
200 
201  public void SendNotificationToUsersInRegion(UUID fromAvatarID,
202  string fromAvatarName, string message)
203  {
204  m_scene.ForEachRootClient(delegate(IClientAPI client)
205  {
206  client.SendAgentAlertMessage(
207  message, false);
208  });
209  }
210 
216  public void HandleAlertConsoleCommand(string module,
217  string[] cmdparams)
218  {
219  if (m_scene.ConsoleScene() != null &&
220  m_scene.ConsoleScene() != m_scene)
221  {
222  return;
223  }
224 
225  string message = string.Empty;
226 
227  if (cmdparams[0].ToLower().Equals("alert"))
228  {
229  message = CombineParams(cmdparams, 1);
230  m_log.InfoFormat("[DIALOG]: Sending general alert in region {0} with message {1}",
231  m_scene.RegionInfo.RegionName, message);
232  SendGeneralAlert(message);
233  }
234  else if (cmdparams.Length > 3)
235  {
236  string firstName = cmdparams[1];
237  string lastName = cmdparams[2];
238  message = CombineParams(cmdparams, 3);
239  m_log.InfoFormat("[DIALOG]: Sending alert in region {0} to {1} {2} with message {3}",
240  m_scene.RegionInfo.RegionName, firstName, lastName,
241  message);
242  SendAlertToUser(firstName, lastName, message, false);
243  }
244  else
245  {
246  MainConsole.Instance.Output(
247  "Usage: alert <message> | alert-user <first> <last> <message>");
248  return;
249  }
250  }
251 
252  private string CombineParams(string[] commandParams, int pos)
253  {
254  string result = string.Empty;
255  for (int i = pos; i < commandParams.Length; i++)
256  {
257  result += commandParams[i] + " ";
258  }
259 
260  return result;
261  }
262  }
263 }
void SendAlertToUser(UUID agentID, string message)
Send a non-modal alert message to a particular user.
Definition: DialogModule.cs:99
void HandleAlertConsoleCommand(string module, string[] cmdparams)
Handle an alert command from the console.
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
Definition: DialogModule.cs:77
void SendDialogToUser(UUID avatarID, string objectName, UUID objectID, UUID ownerID, string message, UUID textureID, int ch, string[] buttonlabels)
Send a dialog box to a particular user.
void SendTextBoxToUser(UUID avatarid, string message, int chatChannel, string name, UUID objectid, UUID ownerID)
Send a textbox entry for the client to respond to
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
Definition: DialogModule.cs:85
void SendUrlToUser(UUID avatarID, string objectName, UUID objectID, UUID ownerID, bool groupOwned, string message, string url)
Send a url to a particular user.
void SendNotificationToUsersInRegion(UUID fromAvatarID, string fromAvatarName, string message)
Send a notification to all users in the scene. This notification should remain around until the user ...
void SendAlertToUser(IClientAPI client, string message, bool modal)
Send an alert message to a particular user.
Definition: DialogModule.cs:93
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
Definition: DialogModule.cs:60
void SendAlertToUser(IClientAPI client, string message)
Send a non-modal alert message to a particular user. This can disappear from the user's view after a ...
Definition: DialogModule.cs:88
void SendGeneralAlert(string message)
Send an alert message to all users in the scene.
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
Definition: DialogModule.cs:54
void SendAlertToUser(UUID agentID, string message, bool modal)
Send an alert message to a particular user.
void SendAlertToUser(string firstName, string lastName, string message, bool modal)
Send an alert message to a particular user.
Interactive OpenSim region server
Definition: OpenSim.cs:55
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
Definition: DialogModule.cs:50