diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs | 465 |
1 files changed, 242 insertions, 223 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs b/OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs index 1498dba..a514a83 100644 --- a/OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs | |||
@@ -1,223 +1,242 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSimulator Project nor the | 12 | * * Neither the name of the OpenSimulator Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Reflection; | 30 | using System.Reflection; |
31 | using log4net; | 31 | using log4net; |
32 | using Nini.Config; | 32 | using Nini.Config; |
33 | using OpenMetaverse; | 33 | using OpenMetaverse; |
34 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
35 | 35 | ||
36 | using OpenSim.Region.Framework.Interfaces; | 36 | using OpenSim.Region.Framework.Interfaces; |
37 | using OpenSim.Region.Framework.Scenes; | 37 | using OpenSim.Region.Framework.Scenes; |
38 | using OpenSim.Services.Interfaces; | 38 | using OpenSim.Services.Interfaces; |
39 | 39 | ||
40 | namespace OpenSim.Region.CoreModules.Avatar.Dialog | 40 | namespace OpenSim.Region.CoreModules.Avatar.Dialog |
41 | { | 41 | { |
42 | public class DialogModule : IRegionModule, IDialogModule | 42 | public class DialogModule : IRegionModule, IDialogModule |
43 | { | 43 | { |
44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
45 | 45 | ||
46 | protected Scene m_scene; | 46 | protected Scene m_scene; |
47 | 47 | ||
48 | public void Initialise(Scene scene, IConfigSource source) | 48 | public void Initialise(Scene scene, IConfigSource source) |
49 | { | 49 | { |
50 | m_scene = scene; | 50 | m_scene = scene; |
51 | m_scene.RegisterModuleInterface<IDialogModule>(this); | 51 | m_scene.RegisterModuleInterface<IDialogModule>(this); |
52 | 52 | ||
53 | m_scene.AddCommand( | 53 | m_scene.AddCommand( |
54 | this, "alert", "alert <first> <last> <message>", "Send an alert to a user", HandleAlertConsoleCommand); | 54 | this, "alert", "alert <first> <last> <message>", |
55 | 55 | "Send an alert to a user", | |
56 | m_scene.AddCommand( | 56 | HandleAlertConsoleCommand); |
57 | this, "alert general", "alert general <message>", "Send an alert to everyone", HandleAlertConsoleCommand); | 57 | |
58 | 58 | m_scene.AddCommand( | |
59 | m_scene.AddCommand( | 59 | this, "alert general", "alert [general] <message>", |
60 | this, "alert dialog", "alert dialog <message>", "Send a dialog alert to everyone", HandleAlertConsoleCommand); | 60 | "Send an alert to everyone", |
61 | 61 | "If keyword 'general' is omitted, then <message> must be surrounded by quotation marks.", | |
62 | 62 | HandleAlertConsoleCommand); | |
63 | } | 63 | } |
64 | 64 | ||
65 | public void PostInitialise() {} | 65 | public void PostInitialise() {} |
66 | public void Close() {} | 66 | public void Close() {} |
67 | public string Name { get { return "Dialog Module"; } } | 67 | public string Name { get { return "Dialog Module"; } } |
68 | public bool IsSharedModule { get { return false; } } | 68 | public bool IsSharedModule { get { return false; } } |
69 | 69 | ||
70 | public void SendAlertToUser(IClientAPI client, string message) | 70 | public void SendAlertToUser(IClientAPI client, string message) |
71 | { | 71 | { |
72 | SendAlertToUser(client, message, false); | 72 | SendAlertToUser(client, message, false); |
73 | } | 73 | } |
74 | 74 | ||
75 | public void SendAlertToUser(IClientAPI client, string message, bool modal) | 75 | public void SendAlertToUser(IClientAPI client, string message, bool modal) |
76 | { | 76 | { |
77 | client.SendAgentAlertMessage(message, modal); | 77 | client.SendAgentAlertMessage(message, modal); |
78 | } | 78 | } |
79 | 79 | ||
80 | public void SendAlertToUser(UUID agentID, string message) | 80 | public void SendAlertToUser(UUID agentID, string message) |
81 | { | 81 | { |
82 | SendAlertToUser(agentID, message, false); | 82 | SendAlertToUser(agentID, message, false); |
83 | } | 83 | } |
84 | 84 | ||
85 | public void SendAlertToUser(UUID agentID, string message, bool modal) | 85 | public void SendAlertToUser(UUID agentID, string message, bool modal) |
86 | { | 86 | { |
87 | ScenePresence sp = m_scene.GetScenePresence(agentID); | 87 | ScenePresence sp = m_scene.GetScenePresence(agentID); |
88 | 88 | ||
89 | if (sp != null) | 89 | if (sp != null) |
90 | sp.ControllingClient.SendAgentAlertMessage(message, modal); | 90 | sp.ControllingClient.SendAgentAlertMessage(message, modal); |
91 | } | 91 | } |
92 | 92 | ||
93 | public void SendAlertToUser(string firstName, string lastName, string message, bool modal) | 93 | public void SendAlertToUser(string firstName, string lastName, string message, bool modal) |
94 | { | 94 | { |
95 | ScenePresence presence = m_scene.GetScenePresence(firstName, lastName); | 95 | ScenePresence presence = m_scene.GetScenePresence(firstName, lastName); |
96 | if (presence != null) | 96 | if (presence != null) |
97 | presence.ControllingClient.SendAgentAlertMessage(message, modal); | 97 | presence.ControllingClient.SendAgentAlertMessage(message, modal); |
98 | } | 98 | } |
99 | 99 | ||
100 | public void SendGeneralAlert(string message) | 100 | public void SendGeneralAlert(string message) |
101 | { | 101 | { |
102 | m_scene.ForEachScenePresence(delegate(ScenePresence presence) | 102 | m_scene.ForEachScenePresence(delegate(ScenePresence presence) |
103 | { | 103 | { |
104 | if (!presence.IsChildAgent) | 104 | if (!presence.IsChildAgent) |
105 | { | 105 | presence.ControllingClient.SendAlertMessage(message); |
106 | presence.ControllingClient.SendAlertMessage(message); | 106 | }); |
107 | } | 107 | } |
108 | }); | 108 | |
109 | } | 109 | public void SendDialogToUser( |
110 | 110 | UUID avatarID, string objectName, UUID objectID, UUID ownerID, | |
111 | public void SendDialogToUser( | 111 | string message, UUID textureID, int ch, string[] buttonlabels) |
112 | UUID avatarID, string objectName, UUID objectID, UUID ownerID, | 112 | { |
113 | string message, UUID textureID, int ch, string[] buttonlabels) | 113 | UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, ownerID); |
114 | { | 114 | string ownerFirstName, ownerLastName; |
115 | UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, ownerID); | 115 | if (account != null) |
116 | string ownerFirstName, ownerLastName; | 116 | { |
117 | if (account != null) | 117 | ownerFirstName = account.FirstName; |
118 | { | 118 | ownerLastName = account.LastName; |
119 | ownerFirstName = account.FirstName; | 119 | } |
120 | ownerLastName = account.LastName; | 120 | else |
121 | } | 121 | { |
122 | else | 122 | ownerFirstName = "(unknown"; |
123 | { | 123 | ownerLastName = "user)"; |
124 | ownerFirstName = "(unknown"; | 124 | } |
125 | ownerLastName = "user)"; | 125 | |
126 | } | 126 | ScenePresence sp = m_scene.GetScenePresence(avatarID); |
127 | 127 | if (sp != null) | |
128 | ScenePresence sp = m_scene.GetScenePresence(avatarID); | 128 | sp.ControllingClient.SendDialog(objectName, objectID, ownerFirstName, ownerLastName, message, textureID, ch, buttonlabels); |
129 | if (sp != null) | 129 | } |
130 | sp.ControllingClient.SendDialog(objectName, objectID, ownerFirstName, ownerLastName, message, textureID, ch, buttonlabels); | 130 | |
131 | } | 131 | public void SendUrlToUser( |
132 | 132 | UUID avatarID, string objectName, UUID objectID, UUID ownerID, bool groupOwned, string message, string url) | |
133 | public void SendUrlToUser( | 133 | { |
134 | UUID avatarID, string objectName, UUID objectID, UUID ownerID, bool groupOwned, string message, string url) | 134 | ScenePresence sp = m_scene.GetScenePresence(avatarID); |
135 | { | 135 | |
136 | ScenePresence sp = m_scene.GetScenePresence(avatarID); | 136 | if (sp != null) |
137 | 137 | sp.ControllingClient.SendLoadURL(objectName, objectID, ownerID, groupOwned, message, url); | |
138 | if (sp != null) | 138 | } |
139 | sp.ControllingClient.SendLoadURL(objectName, objectID, ownerID, groupOwned, message, url); | 139 | |
140 | } | 140 | public void SendTextBoxToUser(UUID avatarid, string message, int chatChannel, string name, UUID objectid, UUID ownerid) |
141 | 141 | { | |
142 | public void SendTextBoxToUser(UUID avatarid, string message, int chatChannel, string name, UUID objectid, UUID ownerid) | 142 | UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, ownerid); |
143 | { | 143 | string ownerFirstName, ownerLastName; |
144 | UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, ownerid); | 144 | if (account != null) |
145 | string ownerFirstName, ownerLastName; | 145 | { |
146 | if (account != null) | 146 | ownerFirstName = account.FirstName; |
147 | { | 147 | ownerLastName = account.LastName; |
148 | ownerFirstName = account.FirstName; | 148 | } |
149 | ownerLastName = account.LastName; | 149 | else |
150 | } | 150 | { |
151 | else | 151 | ownerFirstName = "(unknown"; |
152 | { | 152 | ownerLastName = "user)"; |
153 | ownerFirstName = "(unknown"; | 153 | } |
154 | ownerLastName = "user)"; | 154 | |
155 | } | 155 | ScenePresence sp = m_scene.GetScenePresence(avatarid); |
156 | 156 | ||
157 | ScenePresence sp = m_scene.GetScenePresence(avatarid); | 157 | if (sp != null) |
158 | 158 | sp.ControllingClient.SendTextBoxRequest(message, chatChannel, name, ownerFirstName, ownerLastName, objectid); | |
159 | if (sp != null) | 159 | } |
160 | sp.ControllingClient.SendTextBoxRequest(message, chatChannel, name, ownerFirstName, ownerLastName, objectid); | 160 | |
161 | } | 161 | public void SendNotificationToUsersInRegion( |
162 | 162 | UUID fromAvatarID, string fromAvatarName, string message) | |
163 | public void SendNotificationToUsersInRegion( | 163 | { |
164 | UUID fromAvatarID, string fromAvatarName, string message) | 164 | m_scene.ForEachScenePresence(delegate(ScenePresence presence) |
165 | { | 165 | { |
166 | m_scene.ForEachScenePresence(delegate(ScenePresence presence) | 166 | if (!presence.IsChildAgent) |
167 | { | 167 | presence.ControllingClient.SendBlueBoxMessage(fromAvatarID, fromAvatarName, message); |
168 | if (!presence.IsChildAgent) | 168 | }); |
169 | presence.ControllingClient.SendBlueBoxMessage(fromAvatarID, fromAvatarName, message); | 169 | } |
170 | }); | 170 | |
171 | } | 171 | /// <summary> |
172 | 172 | /// Handle an alert command from the console. | |
173 | /// <summary> | 173 | /// </summary> |
174 | /// Handle an alert command from the console. | 174 | /// <param name="module"></param> |
175 | /// </summary> | 175 | /// <param name="cmdparams"></param> |
176 | /// <param name="module"></param> | 176 | public void HandleAlertConsoleCommand(string module, string[] cmdparams) |
177 | /// <param name="cmdparams"></param> | 177 | { |
178 | public void HandleAlertConsoleCommand(string module, string[] cmdparams) | 178 | if (m_scene.ConsoleScene() != null && m_scene.ConsoleScene() != m_scene) |
179 | { | 179 | return; |
180 | if (m_scene.ConsoleScene() != null && m_scene.ConsoleScene() != m_scene) | 180 | |
181 | return; | 181 | bool isGeneral = false; |
182 | 182 | string firstName = string.Empty; | |
183 | if (cmdparams[1] == "general") | 183 | string lastName = string.Empty; |
184 | { | 184 | string message = string.Empty; |
185 | string message = CombineParams(cmdparams, 2); | 185 | |
186 | 186 | if (cmdparams.Length > 1) | |
187 | m_log.InfoFormat( | 187 | { |
188 | "[DIALOG]: Sending general alert in region {0} with message {1}", m_scene.RegionInfo.RegionName, message); | 188 | firstName = cmdparams[1]; |
189 | SendGeneralAlert(message); | 189 | isGeneral = firstName.ToLower().Equals("general"); |
190 | } | 190 | } |
191 | else if (cmdparams[1] == "dialog") | 191 | if (cmdparams.Length == 2 && !isGeneral) |
192 | { | 192 | { |
193 | string message = CombineParams(cmdparams, 2); | 193 | // alert "message" |
194 | 194 | message = cmdparams[1]; | |
195 | m_log.InfoFormat( | 195 | isGeneral = true; |
196 | "[DIALOG]: Sending dialog alert in region {0} with message {1}", m_scene.RegionInfo.RegionName, message); | 196 | } |
197 | SendNotificationToUsersInRegion(UUID.Zero, "System", message); | 197 | else if (cmdparams.Length > 2 && isGeneral) |
198 | } | 198 | { |
199 | else | 199 | // alert general <message> |
200 | { | 200 | message = CombineParams(cmdparams, 2); |
201 | string firstName = cmdparams[1]; | 201 | } |
202 | string lastName = cmdparams[2]; | 202 | else if (cmdparams.Length > 3) |
203 | string message = CombineParams(cmdparams, 3); | 203 | { |
204 | 204 | // alert <first> <last> <message> | |
205 | m_log.InfoFormat( | 205 | lastName = cmdparams[2]; |
206 | "[DIALOG]: Sending alert in region {0} to {1} {2} with message {3}", | 206 | message = CombineParams(cmdparams, 3); |
207 | m_scene.RegionInfo.RegionName, firstName, lastName, message); | 207 | } |
208 | SendAlertToUser(firstName, lastName, message, false); | 208 | else |
209 | } | 209 | { |
210 | } | 210 | OpenSim.Framework.Console.MainConsole.Instance.Output( |
211 | 211 | "Usage: alert \"message\" | alert general <message> | alert <first> <last> <message>"); | |
212 | private string CombineParams(string[] commandParams, int pos) | 212 | return; |
213 | { | 213 | } |
214 | string result = string.Empty; | 214 | |
215 | for (int i = pos; i < commandParams.Length; i++) | 215 | if (isGeneral) |
216 | { | 216 | { |
217 | result += commandParams[i] + " "; | 217 | m_log.InfoFormat( |
218 | } | 218 | "[DIALOG]: Sending general alert in region {0} with message {1}", |
219 | 219 | m_scene.RegionInfo.RegionName, message); | |
220 | return result; | 220 | SendGeneralAlert(message); |
221 | } | 221 | } |
222 | } | 222 | else |
223 | } | 223 | { |
224 | m_log.InfoFormat( | ||
225 | "[DIALOG]: Sending alert in region {0} to {1} {2} with message {3}", | ||
226 | m_scene.RegionInfo.RegionName, firstName, lastName, message); | ||
227 | SendAlertToUser(firstName, lastName, message, false); | ||
228 | } | ||
229 | } | ||
230 | |||
231 | private string CombineParams(string[] commandParams, int pos) | ||
232 | { | ||
233 | string result = string.Empty; | ||
234 | for (int i = pos; i < commandParams.Length; i++) | ||
235 | { | ||
236 | result += commandParams[i] + " "; | ||
237 | } | ||
238 | |||
239 | return result; | ||
240 | } | ||
241 | } | ||
242 | } | ||