opensim-development – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 eva 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")]
44 public class DialogModule : IDialogModule, INonSharedRegionModule
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 UserAccount account = m_scene.UserAccountService.GetUserAccount(
137 m_scene.RegionInfo.ScopeID, ownerID);
138 string ownerFirstName, ownerLastName;
139 if (account != null)
140 {
141 ownerFirstName = account.FirstName;
142 ownerLastName = account.LastName;
143 }
144 else
145 {
146 ownerFirstName = "(unknown";
147 ownerLastName = "user)";
148 }
149  
150 ScenePresence sp = m_scene.GetScenePresence(avatarID);
151 if (sp != null)
152 {
153 sp.ControllingClient.SendDialog(objectName, objectID, ownerID,
154 ownerFirstName, ownerLastName, message, textureID, ch,
155 buttonlabels);
156 }
157 }
158  
159 public void SendUrlToUser(UUID avatarID, string objectName,
160 UUID objectID, UUID ownerID, bool groupOwned, string message,
161 string url)
162 {
163 ScenePresence sp = m_scene.GetScenePresence(avatarID);
164  
165 if (sp != null)
166 {
167 sp.ControllingClient.SendLoadURL(objectName, objectID,
168 ownerID, groupOwned, message, url);
169 }
170 }
171  
172 public void SendTextBoxToUser(UUID avatarid, string message,
173 int chatChannel, string name, UUID objectid, UUID ownerid)
174 {
175 UserAccount account = m_scene.UserAccountService.GetUserAccount(
176 m_scene.RegionInfo.ScopeID, ownerid);
177 string ownerFirstName, ownerLastName;
178 UUID ownerID = UUID.Zero;
179 if (account != null)
180 {
181 ownerFirstName = account.FirstName;
182 ownerLastName = account.LastName;
183 ownerID = account.PrincipalID;
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.SendBlueBoxMessage(fromAvatarID, fromAvatarName,
207 message);
208 });
209 }
210  
211 /// <summary>
212 /// Handle an alert command from the console.
213 /// </summary>
214 /// <param name="module"></param>
215 /// <param name="cmdparams"></param>
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 }