aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Avatar
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Avatar')
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/AvatarFactory/AvatarFactoryModule.cs676
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs1734
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/Currency/SampleMoney/SampleMoneyModule.cs2938
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs1000
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/Groups/GroupsModule.cs544
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs314
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/Inventory/InventoryModule.cs438
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/Profiles/AvatarProfilesModule.cs264
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/Voice/AsterixVoice/AsteriskVoiceModule.cs578
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/Voice/SIPVoice/SIPVoiceModule.cs398
10 files changed, 4442 insertions, 4442 deletions
diff --git a/OpenSim/Region/Environment/Modules/Avatar/AvatarFactory/AvatarFactoryModule.cs b/OpenSim/Region/Environment/Modules/Avatar/AvatarFactory/AvatarFactoryModule.cs
index 3614686..cb94021 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/AvatarFactory/AvatarFactoryModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/AvatarFactory/AvatarFactoryModule.cs
@@ -1,338 +1,338 @@
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 OpenSim Project nor the 12 * * Neither the name of the OpenSim 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/* 28/*
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Threading; 31using System.Threading;
32using libsecondlife; 32using libsecondlife;
33using Nini.Config; 33using Nini.Config;
34using OpenSim.Framework; 34using OpenSim.Framework;
35using OpenSim.Framework.Communications.Cache; 35using OpenSim.Framework.Communications.Cache;
36using OpenSim.Data.MySQLMapper; 36using OpenSim.Data.MySQLMapper;
37using OpenSim.Region.Environment.Interfaces; 37using OpenSim.Region.Environment.Interfaces;
38using OpenSim.Region.Environment.Scenes; 38using OpenSim.Region.Environment.Scenes;
39using OpenSim.Data.Base; 39using OpenSim.Data.Base;
40 40
41namespace OpenSim.Region.Environment.Modules 41namespace OpenSim.Region.Environment.Modules
42{ 42{
43 public class AvatarFactoryModule : IAvatarFactory 43 public class AvatarFactoryModule : IAvatarFactory
44 { 44 {
45 private Scene m_scene = null; 45 private Scene m_scene = null;
46 private readonly Dictionary<LLUUID, AvatarAppearance> m_avatarsAppearance = new Dictionary<LLUUID, AvatarAppearance>(); 46 private readonly Dictionary<LLUUID, AvatarAppearance> m_avatarsAppearance = new Dictionary<LLUUID, AvatarAppearance>();
47 47
48 private bool m_enablePersist = false; 48 private bool m_enablePersist = false;
49 private string m_connectionString; 49 private string m_connectionString;
50 private bool m_configured = false; 50 private bool m_configured = false;
51 private BaseDatabaseConnector m_databaseMapper; 51 private BaseDatabaseConnector m_databaseMapper;
52 private AppearanceTableMapper m_appearanceMapper; 52 private AppearanceTableMapper m_appearanceMapper;
53 53
54 private Dictionary<LLUUID, EventWaitHandle> m_fetchesInProgress = new Dictionary<LLUUID, EventWaitHandle>(); 54 private Dictionary<LLUUID, EventWaitHandle> m_fetchesInProgress = new Dictionary<LLUUID, EventWaitHandle>();
55 private object m_syncLock = new object(); 55 private object m_syncLock = new object();
56 56
57 public bool TryGetAvatarAppearance(LLUUID avatarId, out AvatarAppearance appearance) 57 public bool TryGetAvatarAppearance(LLUUID avatarId, out AvatarAppearance appearance)
58 { 58 {
59 59
60 //should only let one thread at a time do this part 60 //should only let one thread at a time do this part
61 EventWaitHandle waitHandle = null; 61 EventWaitHandle waitHandle = null;
62 bool fetchInProgress = false; 62 bool fetchInProgress = false;
63 lock (m_syncLock) 63 lock (m_syncLock)
64 { 64 {
65 appearance = CheckCache(avatarId); 65 appearance = CheckCache(avatarId);
66 if (appearance != null) 66 if (appearance != null)
67 { 67 {
68 return true; 68 return true;
69 } 69 }
70 70
71 //not in cache so check to see if another thread is already fetching it 71 //not in cache so check to see if another thread is already fetching it
72 if (m_fetchesInProgress.TryGetValue(avatarId, out waitHandle)) 72 if (m_fetchesInProgress.TryGetValue(avatarId, out waitHandle))
73 { 73 {
74 fetchInProgress = true; 74 fetchInProgress = true;
75 } 75 }
76 else 76 else
77 { 77 {
78 fetchInProgress = false; 78 fetchInProgress = false;
79 79
80 //no thread already fetching this appearance, so add a wait handle to list 80 //no thread already fetching this appearance, so add a wait handle to list
81 //for any following threads that want the same appearance 81 //for any following threads that want the same appearance
82 waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset); 82 waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
83 m_fetchesInProgress.Add(avatarId, waitHandle); 83 m_fetchesInProgress.Add(avatarId, waitHandle);
84 } 84 }
85 } 85 }
86 86
87 if (fetchInProgress) 87 if (fetchInProgress)
88 { 88 {
89 waitHandle.WaitOne(); 89 waitHandle.WaitOne();
90 appearance = CheckCache(avatarId); 90 appearance = CheckCache(avatarId);
91 if (appearance != null) 91 if (appearance != null)
92 { 92 {
93 waitHandle = null; 93 waitHandle = null;
94 return true; 94 return true;
95 } 95 }
96 else 96 else
97 { 97 {
98 waitHandle = null; 98 waitHandle = null;
99 return false; 99 return false;
100 } 100 }
101 } 101 }
102 else 102 else
103 { 103 {
104 Thread.Sleep(5000); 104 Thread.Sleep(5000);
105 105
106 //this is the first thread to request this appearance 106 //this is the first thread to request this appearance
107 //so let it check the db and if not found then create a default appearance 107 //so let it check the db and if not found then create a default appearance
108 //and add that to the cache 108 //and add that to the cache
109 appearance = CheckDatabase(avatarId); 109 appearance = CheckDatabase(avatarId);
110 if (appearance != null) 110 if (appearance != null)
111 { 111 {
112 //appearance has now been added to cache so lets pulse any waiting threads 112 //appearance has now been added to cache so lets pulse any waiting threads
113 lock (m_syncLock) 113 lock (m_syncLock)
114 { 114 {
115 m_fetchesInProgress.Remove(avatarId); 115 m_fetchesInProgress.Remove(avatarId);
116 waitHandle.Set(); 116 waitHandle.Set();
117 } 117 }
118 // waitHandle.Close(); 118 // waitHandle.Close();
119 waitHandle = null; 119 waitHandle = null;
120 return true; 120 return true;
121 } 121 }
122 122
123 //not found a appearance for the user, so create a new default one 123 //not found a appearance for the user, so create a new default one
124 appearance = CreateDefault(avatarId); 124 appearance = CreateDefault(avatarId);
125 if (appearance != null) 125 if (appearance != null)
126 { 126 {
127 //update database 127 //update database
128 if (m_enablePersist) 128 if (m_enablePersist)
129 { 129 {
130 m_appearanceMapper.Add(avatarId.UUID, appearance); 130 m_appearanceMapper.Add(avatarId.UUID, appearance);
131 } 131 }
132 132
133 //add appearance to dictionary cache 133 //add appearance to dictionary cache
134 lock (m_avatarsAppearance) 134 lock (m_avatarsAppearance)
135 { 135 {
136 m_avatarsAppearance[avatarId] = appearance; 136 m_avatarsAppearance[avatarId] = appearance;
137 } 137 }
138 138
139 //appearance has now been added to cache so lets pulse any waiting threads 139 //appearance has now been added to cache so lets pulse any waiting threads
140 lock (m_syncLock) 140 lock (m_syncLock)
141 { 141 {
142 m_fetchesInProgress.Remove(avatarId); 142 m_fetchesInProgress.Remove(avatarId);
143 waitHandle.Set(); 143 waitHandle.Set();
144 } 144 }
145 // waitHandle.Close(); 145 // waitHandle.Close();
146 waitHandle = null; 146 waitHandle = null;
147 return true; 147 return true;
148 } 148 }
149 else 149 else
150 { 150 {
151 //something went wrong, so release the wait handle and remove it 151 //something went wrong, so release the wait handle and remove it
152 //all waiting threads will fail to find cached appearance 152 //all waiting threads will fail to find cached appearance
153 //but its better for them to fail than wait for ever 153 //but its better for them to fail than wait for ever
154 lock (m_syncLock) 154 lock (m_syncLock)
155 { 155 {
156 m_fetchesInProgress.Remove(avatarId); 156 m_fetchesInProgress.Remove(avatarId);
157 waitHandle.Set(); 157 waitHandle.Set();
158 } 158 }
159 //waitHandle.Close(); 159 //waitHandle.Close();
160 waitHandle = null; 160 waitHandle = null;
161 return false; 161 return false;
162 } 162 }
163 } 163 }
164 } 164 }
165 165
166 private AvatarAppearance CreateDefault(LLUUID avatarId) 166 private AvatarAppearance CreateDefault(LLUUID avatarId)
167 { 167 {
168 AvatarAppearance appearance = null; 168 AvatarAppearance appearance = null;
169 AvatarWearable[] wearables; 169 AvatarWearable[] wearables;
170 byte[] visualParams; 170 byte[] visualParams;
171 GetDefaultAvatarAppearance(out wearables, out visualParams); 171 GetDefaultAvatarAppearance(out wearables, out visualParams);
172 appearance = new AvatarAppearance(avatarId, wearables, visualParams); 172 appearance = new AvatarAppearance(avatarId, wearables, visualParams);
173 173
174 return appearance; 174 return appearance;
175 } 175 }
176 176
177 private AvatarAppearance CheckDatabase(LLUUID avatarId) 177 private AvatarAppearance CheckDatabase(LLUUID avatarId)
178 { 178 {
179 AvatarAppearance appearance = null; 179 AvatarAppearance appearance = null;
180 if (m_enablePersist) 180 if (m_enablePersist)
181 { 181 {
182 if (m_appearanceMapper.TryGetValue(avatarId.UUID, out appearance)) 182 if (m_appearanceMapper.TryGetValue(avatarId.UUID, out appearance))
183 { 183 {
184 appearance.VisualParams = GetDefaultVisualParams(); 184 appearance.VisualParams = GetDefaultVisualParams();
185 appearance.TextureEntry = AvatarAppearance.GetDefaultTextureEntry(); 185 appearance.TextureEntry = AvatarAppearance.GetDefaultTextureEntry();
186 lock (m_avatarsAppearance) 186 lock (m_avatarsAppearance)
187 { 187 {
188 m_avatarsAppearance[avatarId] = appearance; 188 m_avatarsAppearance[avatarId] = appearance;
189 } 189 }
190 } 190 }
191 } 191 }
192 return appearance; 192 return appearance;
193 } 193 }
194 194
195 private AvatarAppearance CheckCache(LLUUID avatarId) 195 private AvatarAppearance CheckCache(LLUUID avatarId)
196 { 196 {
197 AvatarAppearance appearance = null; 197 AvatarAppearance appearance = null;
198 lock (m_avatarsAppearance) 198 lock (m_avatarsAppearance)
199 { 199 {
200 if (m_avatarsAppearance.ContainsKey(avatarId)) 200 if (m_avatarsAppearance.ContainsKey(avatarId))
201 { 201 {
202 appearance = m_avatarsAppearance[avatarId]; 202 appearance = m_avatarsAppearance[avatarId];
203 } 203 }
204 } 204 }
205 return appearance; 205 return appearance;
206 } 206 }
207 207
208 public void Initialise(Scene scene, IConfigSource source) 208 public void Initialise(Scene scene, IConfigSource source)
209 { 209 {
210 scene.RegisterModuleInterface<IAvatarFactory>(this); 210 scene.RegisterModuleInterface<IAvatarFactory>(this);
211 scene.EventManager.OnNewClient += NewClient; 211 scene.EventManager.OnNewClient += NewClient;
212 212
213 if (m_scene == null) 213 if (m_scene == null)
214 { 214 {
215 m_scene = scene; 215 m_scene = scene;
216 } 216 }
217 217
218 if (!m_configured) 218 if (!m_configured)
219 { 219 {
220 m_configured = true; 220 m_configured = true;
221 try 221 try
222 { 222 {
223 m_enablePersist = source.Configs["Startup"].GetBoolean("appearance_persist", false); 223 m_enablePersist = source.Configs["Startup"].GetBoolean("appearance_persist", false);
224 m_connectionString = source.Configs["Startup"].GetString("appearance_connection_string", ""); 224 m_connectionString = source.Configs["Startup"].GetString("appearance_connection_string", "");
225 } 225 }
226 catch (Exception) 226 catch (Exception)
227 { 227 {
228 } 228 }
229 if (m_enablePersist) 229 if (m_enablePersist)
230 { 230 {
231 m_databaseMapper = new MySQLDatabaseMapper(m_connectionString); 231 m_databaseMapper = new MySQLDatabaseMapper(m_connectionString);
232 m_appearanceMapper = new AppearanceTableMapper(m_databaseMapper, "AvatarAppearance"); 232 m_appearanceMapper = new AppearanceTableMapper(m_databaseMapper, "AvatarAppearance");
233 } 233 }
234 } 234 }
235 } 235 }
236 236
237 public void PostInitialise() 237 public void PostInitialise()
238 { 238 {
239 } 239 }
240 240
241 public void Close() 241 public void Close()
242 { 242 {
243 } 243 }
244 244
245 public string Name 245 public string Name
246 { 246 {
247 get { return "Default Avatar Factory"; } 247 get { return "Default Avatar Factory"; }
248 } 248 }
249 249
250 public bool IsSharedModule 250 public bool IsSharedModule
251 { 251 {
252 get { return true; } 252 get { return true; }
253 } 253 }
254 254
255 public void NewClient(IClientAPI client) 255 public void NewClient(IClientAPI client)
256 { 256 {
257 client.OnAvatarNowWearing += AvatarIsWearing; 257 client.OnAvatarNowWearing += AvatarIsWearing;
258 } 258 }
259 259
260 public void RemoveClient(IClientAPI client) 260 public void RemoveClient(IClientAPI client)
261 { 261 {
262 // client.OnAvatarNowWearing -= AvatarIsWearing; 262 // client.OnAvatarNowWearing -= AvatarIsWearing;
263 } 263 }
264 264
265 public void AvatarIsWearing(Object sender, AvatarWearingArgs e) 265 public void AvatarIsWearing(Object sender, AvatarWearingArgs e)
266 { 266 {
267 IClientAPI clientView = (IClientAPI)sender; 267 IClientAPI clientView = (IClientAPI)sender;
268 CachedUserInfo profile = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(clientView.AgentId); 268 CachedUserInfo profile = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(clientView.AgentId);
269 if (profile != null) 269 if (profile != null)
270 { 270 {
271 if (profile.RootFolder != null) 271 if (profile.RootFolder != null)
272 { 272 {
273 if (m_avatarsAppearance.ContainsKey(clientView.AgentId)) 273 if (m_avatarsAppearance.ContainsKey(clientView.AgentId))
274 { 274 {
275 AvatarAppearance avatAppearance = null; 275 AvatarAppearance avatAppearance = null;
276 lock (m_avatarsAppearance) 276 lock (m_avatarsAppearance)
277 { 277 {
278 avatAppearance = m_avatarsAppearance[clientView.AgentId]; 278 avatAppearance = m_avatarsAppearance[clientView.AgentId];
279 } 279 }
280 280
281 foreach (AvatarWearingArgs.Wearable wear in e.NowWearing) 281 foreach (AvatarWearingArgs.Wearable wear in e.NowWearing)
282 { 282 {
283 if (wear.Type < 13) 283 if (wear.Type < 13)
284 { 284 {
285 if (wear.ItemID == LLUUID.Zero) 285 if (wear.ItemID == LLUUID.Zero)
286 { 286 {
287 avatAppearance.Wearables[wear.Type].ItemID = LLUUID.Zero; 287 avatAppearance.Wearables[wear.Type].ItemID = LLUUID.Zero;
288 avatAppearance.Wearables[wear.Type].AssetID = LLUUID.Zero; 288 avatAppearance.Wearables[wear.Type].AssetID = LLUUID.Zero;
289 289
290 UpdateDatabase(clientView.AgentId, avatAppearance); 290 UpdateDatabase(clientView.AgentId, avatAppearance);
291 } 291 }
292 else 292 else
293 { 293 {
294 LLUUID assetId; 294 LLUUID assetId;
295 295
296 InventoryItemBase baseItem = profile.RootFolder.HasItem(wear.ItemID); 296 InventoryItemBase baseItem = profile.RootFolder.HasItem(wear.ItemID);
297 if (baseItem != null) 297 if (baseItem != null)
298 { 298 {
299 assetId = baseItem.assetID; 299 assetId = baseItem.assetID;
300 avatAppearance.Wearables[wear.Type].AssetID = assetId; 300 avatAppearance.Wearables[wear.Type].AssetID = assetId;
301 avatAppearance.Wearables[wear.Type].ItemID = wear.ItemID; 301 avatAppearance.Wearables[wear.Type].ItemID = wear.ItemID;
302 302
303 UpdateDatabase(clientView.AgentId, avatAppearance); 303 UpdateDatabase(clientView.AgentId, avatAppearance);
304 } 304 }
305 } 305 }
306 } 306 }
307 } 307 }
308 } 308 }
309 } 309 }
310 } 310 }
311 } 311 }
312 312
313 public void UpdateDatabase(LLUUID userID, AvatarAppearance avatAppearance) 313 public void UpdateDatabase(LLUUID userID, AvatarAppearance avatAppearance)
314 { 314 {
315 if (m_enablePersist) 315 if (m_enablePersist)
316 { 316 {
317 m_appearanceMapper.Update(userID.UUID, avatAppearance); 317 m_appearanceMapper.Update(userID.UUID, avatAppearance);
318 } 318 }
319 } 319 }
320 320
321 public static void GetDefaultAvatarAppearance(out AvatarWearable[] wearables, out byte[] visualParams) 321 public static void GetDefaultAvatarAppearance(out AvatarWearable[] wearables, out byte[] visualParams)
322 { 322 {
323 visualParams = GetDefaultVisualParams(); 323 visualParams = GetDefaultVisualParams();
324 wearables = AvatarWearable.DefaultWearables; 324 wearables = AvatarWearable.DefaultWearables;
325 } 325 }
326 326
327 private static byte[] GetDefaultVisualParams() 327 private static byte[] GetDefaultVisualParams()
328 { 328 {
329 byte[] visualParams; 329 byte[] visualParams;
330 visualParams = new byte[218]; 330 visualParams = new byte[218];
331 for (int i = 0; i < 218; i++) 331 for (int i = 0; i < 218; i++)
332 { 332 {
333 visualParams[i] = 100; 333 visualParams[i] = 100;
334 } 334 }
335 return visualParams; 335 return visualParams;
336 } 336 }
337 } 337 }
338}*/ 338}*/
diff --git a/OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs
index 966f5f3..15720fc 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs
@@ -1,868 +1,868 @@
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 OpenSim Project nor the 12 * * Neither the name of the OpenSim 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
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.IO; 30using System.IO;
31using System.Net.Sockets; 31using System.Net.Sockets;
32using System.Reflection; 32using System.Reflection;
33using System.Text.RegularExpressions; 33using System.Text.RegularExpressions;
34using System.Threading; 34using System.Threading;
35using libsecondlife; 35using libsecondlife;
36using log4net; 36using log4net;
37using Nini.Config; 37using Nini.Config;
38using OpenSim.Framework; 38using OpenSim.Framework;
39using OpenSim.Region.Environment.Interfaces; 39using OpenSim.Region.Environment.Interfaces;
40using OpenSim.Region.Environment.Scenes; 40using OpenSim.Region.Environment.Scenes;
41 41
42namespace OpenSim.Region.Environment.Modules.Avatar.Chat 42namespace OpenSim.Region.Environment.Modules.Avatar.Chat
43{ 43{
44 public class ChatModule : IRegionModule, ISimChat 44 public class ChatModule : IRegionModule, ISimChat
45 { 45 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 private string m_defaultzone = null; 47 private string m_defaultzone = null;
48 48
49 private IRCChatModule m_irc = null; 49 private IRCChatModule m_irc = null;
50 private Thread m_irc_connector = null; 50 private Thread m_irc_connector = null;
51 51
52 private string m_last_leaving_user = null; 52 private string m_last_leaving_user = null;
53 private string m_last_new_user = null; 53 private string m_last_new_user = null;
54 private int m_saydistance = 30; 54 private int m_saydistance = 30;
55 private List<Scene> m_scenes = new List<Scene>(); 55 private List<Scene> m_scenes = new List<Scene>();
56 private int m_shoutdistance = 100; 56 private int m_shoutdistance = 100;
57 internal object m_syncInit = new object(); 57 internal object m_syncInit = new object();
58 internal object m_syncLogout = new object(); 58 internal object m_syncLogout = new object();
59 private int m_whisperdistance = 10; 59 private int m_whisperdistance = 10;
60 60
61 #region IRegionModule Members 61 #region IRegionModule Members
62 62
63 public void Initialise(Scene scene, IConfigSource config) 63 public void Initialise(Scene scene, IConfigSource config)
64 { 64 {
65 lock (m_syncInit) 65 lock (m_syncInit)
66 { 66 {
67 if (!m_scenes.Contains(scene)) 67 if (!m_scenes.Contains(scene))
68 { 68 {
69 m_scenes.Add(scene); 69 m_scenes.Add(scene);
70 scene.EventManager.OnNewClient += NewClient; 70 scene.EventManager.OnNewClient += NewClient;
71 scene.RegisterModuleInterface<ISimChat>(this); 71 scene.RegisterModuleInterface<ISimChat>(this);
72 } 72 }
73 73
74 // wrap this in a try block so that defaults will work if 74 // wrap this in a try block so that defaults will work if
75 // the config file doesn't specify otherwise. 75 // the config file doesn't specify otherwise.
76 try 76 try
77 { 77 {
78 m_whisperdistance = config.Configs["Chat"].GetInt("whisper_distance", m_whisperdistance); 78 m_whisperdistance = config.Configs["Chat"].GetInt("whisper_distance", m_whisperdistance);
79 m_saydistance = config.Configs["Chat"].GetInt("say_distance", m_saydistance); 79 m_saydistance = config.Configs["Chat"].GetInt("say_distance", m_saydistance);
80 m_shoutdistance = config.Configs["Chat"].GetInt("shout_distance", m_shoutdistance); 80 m_shoutdistance = config.Configs["Chat"].GetInt("shout_distance", m_shoutdistance);
81 } 81 }
82 catch (Exception) 82 catch (Exception)
83 { 83 {
84 } 84 }
85 85
86 try 86 try
87 { 87 {
88 m_defaultzone = config.Configs["IRC"].GetString("nick", "Sim"); 88 m_defaultzone = config.Configs["IRC"].GetString("nick", "Sim");
89 } 89 }
90 catch (Exception) 90 catch (Exception)
91 { 91 {
92 } 92 }
93 93
94 // setup IRC Relay 94 // setup IRC Relay
95 if (m_irc == null) 95 if (m_irc == null)
96 { 96 {
97 m_irc = new IRCChatModule(config); 97 m_irc = new IRCChatModule(config);
98 } 98 }
99 if (m_irc_connector == null) 99 if (m_irc_connector == null)
100 { 100 {
101 m_irc_connector = new Thread(IRCConnectRun); 101 m_irc_connector = new Thread(IRCConnectRun);
102 m_irc_connector.Name = "IRCConnectorThread"; 102 m_irc_connector.Name = "IRCConnectorThread";
103 m_irc_connector.IsBackground = true; 103 m_irc_connector.IsBackground = true;
104 } 104 }
105 } 105 }
106 } 106 }
107 107
108 public void PostInitialise() 108 public void PostInitialise()
109 { 109 {
110 if (m_irc.Enabled) 110 if (m_irc.Enabled)
111 { 111 {
112 try 112 try
113 { 113 {
114 //m_irc.Connect(m_scenes); 114 //m_irc.Connect(m_scenes);
115 if (m_irc_connector == null) 115 if (m_irc_connector == null)
116 { 116 {
117 m_irc_connector = new Thread(IRCConnectRun); 117 m_irc_connector = new Thread(IRCConnectRun);
118 m_irc_connector.Name = "IRCConnectorThread"; 118 m_irc_connector.Name = "IRCConnectorThread";
119 m_irc_connector.IsBackground = true; 119 m_irc_connector.IsBackground = true;
120 } 120 }
121 if (!m_irc_connector.IsAlive) 121 if (!m_irc_connector.IsAlive)
122 { 122 {
123 m_irc_connector.Start(); 123 m_irc_connector.Start();
124 ThreadTracker.Add(m_irc_connector); 124 ThreadTracker.Add(m_irc_connector);
125 } 125 }
126 } 126 }
127 catch (Exception) 127 catch (Exception)
128 { 128 {
129 } 129 }
130 } 130 }
131 } 131 }
132 132
133 public void Close() 133 public void Close()
134 { 134 {
135 m_irc.Close(); 135 m_irc.Close();
136 } 136 }
137 137
138 public string Name 138 public string Name
139 { 139 {
140 get { return "ChatModule"; } 140 get { return "ChatModule"; }
141 } 141 }
142 142
143 public bool IsSharedModule 143 public bool IsSharedModule
144 { 144 {
145 get { return true; } 145 get { return true; }
146 } 146 }
147 147
148 #endregion 148 #endregion
149 149
150 #region ISimChat Members 150 #region ISimChat Members
151 151
152 public void SimChat(Object sender, ChatFromViewerArgs e) 152 public void SimChat(Object sender, ChatFromViewerArgs e)
153 { 153 {
154 // FROM: Sim TO: IRC 154 // FROM: Sim TO: IRC
155 155
156 ScenePresence avatar = null; 156 ScenePresence avatar = null;
157 157
158 //TODO: Move ForEachScenePresence and others into IScene. 158 //TODO: Move ForEachScenePresence and others into IScene.
159 Scene scene = (Scene) e.Scene; 159 Scene scene = (Scene) e.Scene;
160 160
161 //TODO: Remove the need for this check 161 //TODO: Remove the need for this check
162 if (scene == null) 162 if (scene == null)
163 scene = m_scenes[0]; 163 scene = m_scenes[0];
164 164
165 // Filled in since it's easier than rewriting right now. 165 // Filled in since it's easier than rewriting right now.
166 LLVector3 fromPos = e.Position; 166 LLVector3 fromPos = e.Position;
167 LLVector3 regionPos = new LLVector3(scene.RegionInfo.RegionLocX * Constants.RegionSize, scene.RegionInfo.RegionLocY * Constants.RegionSize, 0); 167 LLVector3 regionPos = new LLVector3(scene.RegionInfo.RegionLocX * Constants.RegionSize, scene.RegionInfo.RegionLocY * Constants.RegionSize, 0);
168 168
169 string fromName = e.From; 169 string fromName = e.From;
170 string message = e.Message; 170 string message = e.Message;
171 LLUUID fromAgentID = LLUUID.Zero; 171 LLUUID fromAgentID = LLUUID.Zero;
172 172
173 if (e.Sender != null) 173 if (e.Sender != null)
174 { 174 {
175 avatar = scene.GetScenePresence(e.Sender.AgentId); 175 avatar = scene.GetScenePresence(e.Sender.AgentId);
176 } 176 }
177 177
178 if (avatar != null) 178 if (avatar != null)
179 { 179 {
180 fromPos = avatar.AbsolutePosition; 180 fromPos = avatar.AbsolutePosition;
181 regionPos = new LLVector3(scene.RegionInfo.RegionLocX * Constants.RegionSize, scene.RegionInfo.RegionLocY * Constants.RegionSize, 0); 181 regionPos = new LLVector3(scene.RegionInfo.RegionLocX * Constants.RegionSize, scene.RegionInfo.RegionLocY * Constants.RegionSize, 0);
182 fromName = avatar.Firstname + " " + avatar.Lastname; 182 fromName = avatar.Firstname + " " + avatar.Lastname;
183 fromAgentID = e.Sender.AgentId; 183 fromAgentID = e.Sender.AgentId;
184 } 184 }
185 185
186 // Try to reconnect to server if not connected 186 // Try to reconnect to server if not connected
187 if (m_irc.Enabled && !m_irc.Connected) 187 if (m_irc.Enabled && !m_irc.Connected)
188 { 188 {
189 // In a non-blocking way. Eventually the connector will get it started 189 // In a non-blocking way. Eventually the connector will get it started
190 try 190 try
191 { 191 {
192 if (m_irc_connector == null) 192 if (m_irc_connector == null)
193 { 193 {
194 m_irc_connector = new Thread(IRCConnectRun); 194 m_irc_connector = new Thread(IRCConnectRun);
195 m_irc_connector.Name = "IRCConnectorThread"; 195 m_irc_connector.Name = "IRCConnectorThread";
196 m_irc_connector.IsBackground = true; 196 m_irc_connector.IsBackground = true;
197 } 197 }
198 if (!m_irc_connector.IsAlive) 198 if (!m_irc_connector.IsAlive)
199 { 199 {
200 m_irc_connector.Start(); 200 m_irc_connector.Start();
201 ThreadTracker.Add(m_irc_connector); 201 ThreadTracker.Add(m_irc_connector);
202 } 202 }
203 } 203 }
204 catch (Exception) 204 catch (Exception)
205 { 205 {
206 } 206 }
207 } 207 }
208 208
209 209
210 // We only want to relay stuff on channel 0 210 // We only want to relay stuff on channel 0
211 if (e.Channel == 0) 211 if (e.Channel == 0)
212 { 212 {
213 // IRC stuff 213 // IRC stuff
214 if (e.Message.Length > 0) 214 if (e.Message.Length > 0)
215 { 215 {
216 if (m_irc.Connected && (avatar != null)) // this is to keep objects from talking to IRC 216 if (m_irc.Connected && (avatar != null)) // this is to keep objects from talking to IRC
217 { 217 {
218 m_irc.PrivMsg(fromName, scene.RegionInfo.RegionName, e.Message); 218 m_irc.PrivMsg(fromName, scene.RegionInfo.RegionName, e.Message);
219 } 219 }
220 } 220 }
221 221
222 foreach (Scene s in m_scenes) 222 foreach (Scene s in m_scenes)
223 { 223 {
224 s.ForEachScenePresence(delegate(ScenePresence presence) 224 s.ForEachScenePresence(delegate(ScenePresence presence)
225 { 225 {
226 TrySendChatMessage(presence, fromPos, regionPos, 226 TrySendChatMessage(presence, fromPos, regionPos,
227 fromAgentID, fromName, e.Type, message); 227 fromAgentID, fromName, e.Type, message);
228 }); 228 });
229 } 229 }
230 } 230 }
231 } 231 }
232 232
233 #endregion 233 #endregion
234 234
235 public void NewClient(IClientAPI client) 235 public void NewClient(IClientAPI client)
236 { 236 {
237 try 237 try
238 { 238 {
239 client.OnChatFromViewer += SimChat; 239 client.OnChatFromViewer += SimChat;
240 240
241 if ((m_irc.Enabled) && (m_irc.Connected)) 241 if ((m_irc.Enabled) && (m_irc.Connected))
242 { 242 {
243 string clientName = client.FirstName + " " + client.LastName; 243 string clientName = client.FirstName + " " + client.LastName;
244 // handles simple case. May not work for hundred connecting in per second. 244 // handles simple case. May not work for hundred connecting in per second.
245 // and the NewClients calles getting interleved 245 // and the NewClients calles getting interleved
246 // but filters out multiple reports 246 // but filters out multiple reports
247 if (clientName != m_last_new_user) 247 if (clientName != m_last_new_user)
248 { 248 {
249 m_last_new_user = clientName; 249 m_last_new_user = clientName;
250 string clientRegion = FindClientRegion(client.FirstName, client.LastName); 250 string clientRegion = FindClientRegion(client.FirstName, client.LastName);
251 m_irc.PrivMsg(m_irc.Nick, "Sim", "notices " + clientName + " in " + clientRegion); 251 m_irc.PrivMsg(m_irc.Nick, "Sim", "notices " + clientName + " in " + clientRegion);
252 } 252 }
253 } 253 }
254 client.OnLogout += ClientLoggedOut; 254 client.OnLogout += ClientLoggedOut;
255 client.OnConnectionClosed += ClientLoggedOut; 255 client.OnConnectionClosed += ClientLoggedOut;
256 client.OnLogout += ClientLoggedOut; 256 client.OnLogout += ClientLoggedOut;
257 } 257 }
258 catch (Exception ex) 258 catch (Exception ex)
259 { 259 {
260 m_log.Error("[IRC]: NewClient exception trap:" + ex.ToString()); 260 m_log.Error("[IRC]: NewClient exception trap:" + ex.ToString());
261 } 261 }
262 } 262 }
263 263
264 public void ClientLoggedOut(IClientAPI client) 264 public void ClientLoggedOut(IClientAPI client)
265 { 265 {
266 lock (m_syncLogout) 266 lock (m_syncLogout)
267 { 267 {
268 try 268 try
269 { 269 {
270 if ((m_irc.Enabled) && (m_irc.Connected)) 270 if ((m_irc.Enabled) && (m_irc.Connected))
271 { 271 {
272 string clientName = client.FirstName + " " + client.LastName; 272 string clientName = client.FirstName + " " + client.LastName;
273 string clientRegion = FindClientRegion(client.FirstName, client.LastName); 273 string clientRegion = FindClientRegion(client.FirstName, client.LastName);
274 // handles simple case. May not work for hundred connecting in per second. 274 // handles simple case. May not work for hundred connecting in per second.
275 // and the NewClients calles getting interleved 275 // and the NewClients calles getting interleved
276 // but filters out multiple reports 276 // but filters out multiple reports
277 if (clientName != m_last_leaving_user) 277 if (clientName != m_last_leaving_user)
278 { 278 {
279 m_last_leaving_user = clientName; 279 m_last_leaving_user = clientName;
280 m_irc.PrivMsg(m_irc.Nick, "Sim", "notices " + clientName + " left " + clientRegion); 280 m_irc.PrivMsg(m_irc.Nick, "Sim", "notices " + clientName + " left " + clientRegion);
281 m_log.Info("[IRC]: IRC watcher notices " + clientName + " left " + clientRegion); 281 m_log.Info("[IRC]: IRC watcher notices " + clientName + " left " + clientRegion);
282 } 282 }
283 } 283 }
284 } 284 }
285 catch (Exception ex) 285 catch (Exception ex)
286 { 286 {
287 m_log.Error("[IRC]: ClientLoggedOut exception trap:" + ex.ToString()); 287 m_log.Error("[IRC]: ClientLoggedOut exception trap:" + ex.ToString());
288 } 288 }
289 } 289 }
290 } 290 }
291 291
292 private void TrySendChatMessage(ScenePresence presence, LLVector3 fromPos, LLVector3 regionPos, 292 private void TrySendChatMessage(ScenePresence presence, LLVector3 fromPos, LLVector3 regionPos,
293 LLUUID fromAgentID, string fromName, ChatTypeEnum type, string message) 293 LLUUID fromAgentID, string fromName, ChatTypeEnum type, string message)
294 { 294 {
295 if (!presence.IsChildAgent) 295 if (!presence.IsChildAgent)
296 { 296 {
297 LLVector3 fromRegionPos = fromPos + regionPos; 297 LLVector3 fromRegionPos = fromPos + regionPos;
298 LLVector3 toRegionPos = presence.AbsolutePosition + regionPos; 298 LLVector3 toRegionPos = presence.AbsolutePosition + regionPos;
299 int dis = Math.Abs((int) Util.GetDistanceTo(toRegionPos, fromRegionPos)); 299 int dis = Math.Abs((int) Util.GetDistanceTo(toRegionPos, fromRegionPos));
300 300
301 if (type == ChatTypeEnum.Whisper && dis > m_whisperdistance || 301 if (type == ChatTypeEnum.Whisper && dis > m_whisperdistance ||
302 type == ChatTypeEnum.Say && dis > m_saydistance || 302 type == ChatTypeEnum.Say && dis > m_saydistance ||
303 type == ChatTypeEnum.Shout && dis > m_shoutdistance) 303 type == ChatTypeEnum.Shout && dis > m_shoutdistance)
304 { 304 {
305 return; 305 return;
306 } 306 }
307 307
308 // TODO: should change so the message is sent through the avatar rather than direct to the ClientView 308 // TODO: should change so the message is sent through the avatar rather than direct to the ClientView
309 presence.ControllingClient.SendChatMessage(message, (byte) type, fromPos, fromName, fromAgentID); 309 presence.ControllingClient.SendChatMessage(message, (byte) type, fromPos, fromName, fromAgentID);
310 } 310 }
311 } 311 }
312 312
313 // if IRC is enabled then just keep trying using a monitor thread 313 // if IRC is enabled then just keep trying using a monitor thread
314 public void IRCConnectRun() 314 public void IRCConnectRun()
315 { 315 {
316 while (true) 316 while (true)
317 { 317 {
318 if ((m_irc.Enabled) && (!m_irc.Connected)) 318 if ((m_irc.Enabled) && (!m_irc.Connected))
319 { 319 {
320 m_irc.Connect(m_scenes); 320 m_irc.Connect(m_scenes);
321 } 321 }
322 Thread.Sleep(15000); 322 Thread.Sleep(15000);
323 } 323 }
324 } 324 }
325 325
326 public string FindClientRegion(string client_FirstName, string client_LastName) 326 public string FindClientRegion(string client_FirstName, string client_LastName)
327 { 327 {
328 string sourceRegion = null; 328 string sourceRegion = null;
329 foreach (Scene s in m_scenes) 329 foreach (Scene s in m_scenes)
330 { 330 {
331 s.ForEachScenePresence(delegate(ScenePresence presence) 331 s.ForEachScenePresence(delegate(ScenePresence presence)
332 { 332 {
333 if ((presence.IsChildAgent == false) 333 if ((presence.IsChildAgent == false)
334 && (presence.Firstname == client_FirstName) 334 && (presence.Firstname == client_FirstName)
335 && (presence.Lastname == client_LastName)) 335 && (presence.Lastname == client_LastName))
336 { 336 {
337 sourceRegion = presence.Scene.RegionInfo.RegionName; 337 sourceRegion = presence.Scene.RegionInfo.RegionName;
338 //sourceRegion= s.RegionInfo.RegionName; 338 //sourceRegion= s.RegionInfo.RegionName;
339 } 339 }
340 }); 340 });
341 if (sourceRegion != null) return sourceRegion; 341 if (sourceRegion != null) return sourceRegion;
342 } 342 }
343 if (m_defaultzone == null) 343 if (m_defaultzone == null)
344 { 344 {
345 m_defaultzone = "Sim"; 345 m_defaultzone = "Sim";
346 } 346 }
347 return m_defaultzone; 347 return m_defaultzone;
348 } 348 }
349 } 349 }
350 350
351 internal class IRCChatModule 351 internal class IRCChatModule
352 { 352 {
353 #region ErrorReplies enum 353 #region ErrorReplies enum
354 354
355 public enum ErrorReplies 355 public enum ErrorReplies
356 { 356 {
357 NotRegistered = 451, // ":You have not registered" 357 NotRegistered = 451, // ":You have not registered"
358 NicknameInUse = 433 // "<nick> :Nickname is already in use" 358 NicknameInUse = 433 // "<nick> :Nickname is already in use"
359 } 359 }
360 360
361 #endregion 361 #endregion
362 362
363 #region Replies enum 363 #region Replies enum
364 364
365 public enum Replies 365 public enum Replies
366 { 366 {
367 MotdStart = 375, // ":- <server> Message of the day - " 367 MotdStart = 375, // ":- <server> Message of the day - "
368 Motd = 372, // ":- <text>" 368 Motd = 372, // ":- <text>"
369 EndOfMotd = 376 // ":End of /MOTD command" 369 EndOfMotd = 376 // ":End of /MOTD command"
370 } 370 }
371 371
372 #endregion 372 #endregion
373 373
374 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 374 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
375 private Thread listener; 375 private Thread listener;
376 376
377 private string m_basenick = null; 377 private string m_basenick = null;
378 private string m_channel = null; 378 private string m_channel = null;
379 private bool m_connected = false; 379 private bool m_connected = false;
380 private bool m_enabled = false; 380 private bool m_enabled = false;
381 private List<Scene> m_last_scenes = null; 381 private List<Scene> m_last_scenes = null;
382 private string m_nick = null; 382 private string m_nick = null;
383 private uint m_port = 6668; 383 private uint m_port = 6668;
384 private string m_privmsgformat = "PRIVMSG {0} :<{1} in {2}>: {3}"; 384 private string m_privmsgformat = "PRIVMSG {0} :<{1} in {2}>: {3}";
385 private StreamReader m_reader; 385 private StreamReader m_reader;
386 private List<Scene> m_scenes = null; 386 private List<Scene> m_scenes = null;
387 private string m_server = null; 387 private string m_server = null;
388 388
389 private NetworkStream m_stream; 389 private NetworkStream m_stream;
390 internal object m_syncConnect = new object(); 390 internal object m_syncConnect = new object();
391 private TcpClient m_tcp; 391 private TcpClient m_tcp;
392 private string m_user = "USER OpenSimBot 8 * :I'm a OpenSim to irc bot"; 392 private string m_user = "USER OpenSimBot 8 * :I'm a OpenSim to irc bot";
393 private StreamWriter m_writer; 393 private StreamWriter m_writer;
394 394
395 private Thread pingSender; 395 private Thread pingSender;
396 396
397 public IRCChatModule(IConfigSource config) 397 public IRCChatModule(IConfigSource config)
398 { 398 {
399 m_nick = "OSimBot" + Util.RandomClass.Next(1, 99); 399 m_nick = "OSimBot" + Util.RandomClass.Next(1, 99);
400 m_tcp = null; 400 m_tcp = null;
401 m_writer = null; 401 m_writer = null;
402 m_reader = null; 402 m_reader = null;
403 403
404 // configuration in OpenSim.ini 404 // configuration in OpenSim.ini
405 // [IRC] 405 // [IRC]
406 // server = chat.freenode.net 406 // server = chat.freenode.net
407 // nick = OSimBot_mysim 407 // nick = OSimBot_mysim
408 // ;username = USER OpenSimBot 8 * :I'm a OpenSim to irc bot 408 // ;username = USER OpenSimBot 8 * :I'm a OpenSim to irc bot
409 // ; username is the IRC command line sent 409 // ; username is the IRC command line sent
410 // ; USER <irc_user> <visible=8,invisible=0> * : <IRC_realname> 410 // ; USER <irc_user> <visible=8,invisible=0> * : <IRC_realname>
411 // channel = #opensim-regions 411 // channel = #opensim-regions
412 // port = 6667 412 // port = 6667
413 // ;MSGformat fields : 0=botnick, 1=user, 2=region, 3=message 413 // ;MSGformat fields : 0=botnick, 1=user, 2=region, 3=message
414 // ;for <bot>:<user in region> :<message> 414 // ;for <bot>:<user in region> :<message>
415 // ;msgformat = "PRIVMSG {0} :<{1} in {2}>: {3}" 415 // ;msgformat = "PRIVMSG {0} :<{1} in {2}>: {3}"
416 // ;for <bot>:<message> - <user of region> : 416 // ;for <bot>:<message> - <user of region> :
417 // ;msgformat = "PRIVMSG {0} : {3} - {1} of {2}" 417 // ;msgformat = "PRIVMSG {0} : {3} - {1} of {2}"
418 // ;for <bot>:<message> - from <user> : 418 // ;for <bot>:<message> - from <user> :
419 // ;msgformat = "PRIVMSG {0} : {3} - from {1}" 419 // ;msgformat = "PRIVMSG {0} : {3} - from {1}"
420 // Traps I/O disconnects so it does not crash the sim 420 // Traps I/O disconnects so it does not crash the sim
421 // Trys to reconnect if disconnected and someone says something 421 // Trys to reconnect if disconnected and someone says something
422 // Tells IRC server "QUIT" when doing a close (just to be nice) 422 // Tells IRC server "QUIT" when doing a close (just to be nice)
423 // Default port back to 6667 423 // Default port back to 6667
424 424
425 try 425 try
426 { 426 {
427 m_server = config.Configs["IRC"].GetString("server"); 427 m_server = config.Configs["IRC"].GetString("server");
428 m_nick = config.Configs["IRC"].GetString("nick"); 428 m_nick = config.Configs["IRC"].GetString("nick");
429 m_basenick = m_nick; 429 m_basenick = m_nick;
430 m_channel = config.Configs["IRC"].GetString("channel"); 430 m_channel = config.Configs["IRC"].GetString("channel");
431 m_port = (uint) config.Configs["IRC"].GetInt("port", (int) m_port); 431 m_port = (uint) config.Configs["IRC"].GetInt("port", (int) m_port);
432 m_user = config.Configs["IRC"].GetString("username", m_user); 432 m_user = config.Configs["IRC"].GetString("username", m_user);
433 m_privmsgformat = config.Configs["IRC"].GetString("msgformat", m_privmsgformat); 433 m_privmsgformat = config.Configs["IRC"].GetString("msgformat", m_privmsgformat);
434 if (m_server != null && m_nick != null && m_channel != null) 434 if (m_server != null && m_nick != null && m_channel != null)
435 { 435 {
436 m_nick = m_nick + Util.RandomClass.Next(1, 99); 436 m_nick = m_nick + Util.RandomClass.Next(1, 99);
437 m_enabled = true; 437 m_enabled = true;
438 } 438 }
439 } 439 }
440 catch (Exception) 440 catch (Exception)
441 { 441 {
442 m_log.Info("[CHAT]: No IRC config information, skipping IRC bridge configuration"); 442 m_log.Info("[CHAT]: No IRC config information, skipping IRC bridge configuration");
443 } 443 }
444 } 444 }
445 445
446 public bool Enabled 446 public bool Enabled
447 { 447 {
448 get { return m_enabled; } 448 get { return m_enabled; }
449 } 449 }
450 450
451 public bool Connected 451 public bool Connected
452 { 452 {
453 get { return m_connected; } 453 get { return m_connected; }
454 } 454 }
455 455
456 public string Nick 456 public string Nick
457 { 457 {
458 get { return m_nick; } 458 get { return m_nick; }
459 } 459 }
460 460
461 public bool Connect(List<Scene> scenes) 461 public bool Connect(List<Scene> scenes)
462 { 462 {
463 lock (m_syncConnect) 463 lock (m_syncConnect)
464 { 464 {
465 try 465 try
466 { 466 {
467 if (m_connected) return true; 467 if (m_connected) return true;
468 m_scenes = scenes; 468 m_scenes = scenes;
469 if (m_last_scenes == null) 469 if (m_last_scenes == null)
470 { 470 {
471 m_last_scenes = scenes; 471 m_last_scenes = scenes;
472 } 472 }
473 473
474 m_tcp = new TcpClient(m_server, (int) m_port); 474 m_tcp = new TcpClient(m_server, (int) m_port);
475 m_log.Info("[IRC]: Connecting..."); 475 m_log.Info("[IRC]: Connecting...");
476 m_stream = m_tcp.GetStream(); 476 m_stream = m_tcp.GetStream();
477 m_log.Info("[IRC]: Connected to " + m_server); 477 m_log.Info("[IRC]: Connected to " + m_server);
478 m_reader = new StreamReader(m_stream); 478 m_reader = new StreamReader(m_stream);
479 m_writer = new StreamWriter(m_stream); 479 m_writer = new StreamWriter(m_stream);
480 480
481 pingSender = new Thread(new ThreadStart(PingRun)); 481 pingSender = new Thread(new ThreadStart(PingRun));
482 pingSender.Name = "PingSenderThread"; 482 pingSender.Name = "PingSenderThread";
483 pingSender.IsBackground = true; 483 pingSender.IsBackground = true;
484 pingSender.Start(); 484 pingSender.Start();
485 ThreadTracker.Add(pingSender); 485 ThreadTracker.Add(pingSender);
486 486
487 listener = new Thread(new ThreadStart(ListenerRun)); 487 listener = new Thread(new ThreadStart(ListenerRun));
488 listener.Name = "IRCChatModuleListenerThread"; 488 listener.Name = "IRCChatModuleListenerThread";
489 listener.IsBackground = true; 489 listener.IsBackground = true;
490 listener.Start(); 490 listener.Start();
491 ThreadTracker.Add(listener); 491 ThreadTracker.Add(listener);
492 492
493 m_writer.WriteLine(m_user); 493 m_writer.WriteLine(m_user);
494 m_writer.Flush(); 494 m_writer.Flush();
495 m_writer.WriteLine("NICK " + m_nick); 495 m_writer.WriteLine("NICK " + m_nick);
496 m_writer.Flush(); 496 m_writer.Flush();
497 m_writer.WriteLine("JOIN " + m_channel); 497 m_writer.WriteLine("JOIN " + m_channel);
498 m_writer.Flush(); 498 m_writer.Flush();
499 m_log.Info("[IRC]: Connection fully established"); 499 m_log.Info("[IRC]: Connection fully established");
500 m_connected = true; 500 m_connected = true;
501 } 501 }
502 catch (Exception e) 502 catch (Exception e)
503 { 503 {
504 Console.WriteLine(e.ToString()); 504 Console.WriteLine(e.ToString());
505 } 505 }
506 return m_connected; 506 return m_connected;
507 } 507 }
508 } 508 }
509 509
510 public void Reconnect() 510 public void Reconnect()
511 { 511 {
512 m_connected = false; 512 m_connected = false;
513 listener.Abort(); 513 listener.Abort();
514 pingSender.Abort(); 514 pingSender.Abort();
515 m_writer.Close(); 515 m_writer.Close();
516 m_reader.Close(); 516 m_reader.Close();
517 m_tcp.Close(); 517 m_tcp.Close();
518 if (m_enabled) 518 if (m_enabled)
519 { 519 {
520 Connect(m_last_scenes); 520 Connect(m_last_scenes);
521 } 521 }
522 } 522 }
523 523
524 public void PrivMsg(string from, string region, string msg) 524 public void PrivMsg(string from, string region, string msg)
525 { 525 {
526 // One message to the IRC server 526 // One message to the IRC server
527 527
528 try 528 try
529 { 529 {
530 if (m_privmsgformat == null) 530 if (m_privmsgformat == null)
531 { 531 {
532 m_writer.WriteLine("PRIVMSG {0} :<{1} in {2}>: {3}", m_channel, from, region, msg); 532 m_writer.WriteLine("PRIVMSG {0} :<{1} in {2}>: {3}", m_channel, from, region, msg);
533 } 533 }
534 else 534 else
535 { 535 {
536 m_writer.WriteLine(m_privmsgformat, m_channel, from, region, msg); 536 m_writer.WriteLine(m_privmsgformat, m_channel, from, region, msg);
537 } 537 }
538 m_writer.Flush(); 538 m_writer.Flush();
539 m_log.Info("[IRC]: PrivMsg " + from + " in " + region + " :" + msg); 539 m_log.Info("[IRC]: PrivMsg " + from + " in " + region + " :" + msg);
540 } 540 }
541 catch (IOException) 541 catch (IOException)
542 { 542 {
543 m_log.Error("[IRC]: Disconnected from IRC server.(PrivMsg)"); 543 m_log.Error("[IRC]: Disconnected from IRC server.(PrivMsg)");
544 Reconnect(); 544 Reconnect();
545 } 545 }
546 catch (Exception ex) 546 catch (Exception ex)
547 { 547 {
548 m_log.Error("[IRC]: PrivMsg exception trap:" + ex.ToString()); 548 m_log.Error("[IRC]: PrivMsg exception trap:" + ex.ToString());
549 } 549 }
550 } 550 }
551 551
552 private Dictionary<string, string> ExtractMsg(string input) 552 private Dictionary<string, string> ExtractMsg(string input)
553 { 553 {
554 //examines IRC commands and extracts any private messages 554 //examines IRC commands and extracts any private messages
555 // which will then be reboadcast in the Sim 555 // which will then be reboadcast in the Sim
556 556
557 m_log.Info("[IRC]: ExtractMsg: " + input); 557 m_log.Info("[IRC]: ExtractMsg: " + input);
558 Dictionary<string, string> result = null; 558 Dictionary<string, string> result = null;
559 //string regex = @":(?<nick>\w*)!~(?<user>\S*) PRIVMSG (?<channel>\S+) :(?<msg>.*)"; 559 //string regex = @":(?<nick>\w*)!~(?<user>\S*) PRIVMSG (?<channel>\S+) :(?<msg>.*)";
560 string regex = @":(?<nick>\w*)!(?<user>\S*) PRIVMSG (?<channel>\S+) :(?<msg>.*)"; 560 string regex = @":(?<nick>\w*)!(?<user>\S*) PRIVMSG (?<channel>\S+) :(?<msg>.*)";
561 Regex RE = new Regex(regex, RegexOptions.Multiline); 561 Regex RE = new Regex(regex, RegexOptions.Multiline);
562 MatchCollection matches = RE.Matches(input); 562 MatchCollection matches = RE.Matches(input);
563 // Get some direct matches $1 $4 is a 563 // Get some direct matches $1 $4 is a
564 if ((matches.Count == 1) && (matches[0].Groups.Count == 5)) 564 if ((matches.Count == 1) && (matches[0].Groups.Count == 5))
565 { 565 {
566 result = new Dictionary<string, string>(); 566 result = new Dictionary<string, string>();
567 result.Add("nick", matches[0].Groups[1].Value); 567 result.Add("nick", matches[0].Groups[1].Value);
568 result.Add("user", matches[0].Groups[2].Value); 568 result.Add("user", matches[0].Groups[2].Value);
569 result.Add("channel", matches[0].Groups[3].Value); 569 result.Add("channel", matches[0].Groups[3].Value);
570 result.Add("msg", matches[0].Groups[4].Value); 570 result.Add("msg", matches[0].Groups[4].Value);
571 } 571 }
572 else 572 else
573 { 573 {
574 m_log.Info("[IRC]: Number of matches: " + matches.Count); 574 m_log.Info("[IRC]: Number of matches: " + matches.Count);
575 if (matches.Count > 0) 575 if (matches.Count > 0)
576 { 576 {
577 m_log.Info("[IRC]: Number of groups: " + matches[0].Groups.Count); 577 m_log.Info("[IRC]: Number of groups: " + matches[0].Groups.Count);
578 } 578 }
579 } 579 }
580 return result; 580 return result;
581 } 581 }
582 582
583 public void PingRun() 583 public void PingRun()
584 { 584 {
585 // IRC keep alive thread 585 // IRC keep alive thread
586 // send PING ever 15 seconds 586 // send PING ever 15 seconds
587 while (true) 587 while (true)
588 { 588 {
589 try 589 try
590 { 590 {
591 if (m_connected == true) 591 if (m_connected == true)
592 { 592 {
593 m_writer.WriteLine("PING :" + m_server); 593 m_writer.WriteLine("PING :" + m_server);
594 m_writer.Flush(); 594 m_writer.Flush();
595 Thread.Sleep(15000); 595 Thread.Sleep(15000);
596 } 596 }
597 } 597 }
598 catch (IOException) 598 catch (IOException)
599 { 599 {
600 m_log.Error("[IRC]: Disconnected from IRC server.(PingRun)"); 600 m_log.Error("[IRC]: Disconnected from IRC server.(PingRun)");
601 Reconnect(); 601 Reconnect();
602 } 602 }
603 catch (Exception ex) 603 catch (Exception ex)
604 { 604 {
605 m_log.Error("[IRC]: PingRun exception trap:" + ex.ToString() + "\n" + ex.StackTrace); 605 m_log.Error("[IRC]: PingRun exception trap:" + ex.ToString() + "\n" + ex.StackTrace);
606 } 606 }
607 } 607 }
608 } 608 }
609 609
610 public void ListenerRun() 610 public void ListenerRun()
611 { 611 {
612 string inputLine; 612 string inputLine;
613 LLVector3 pos = new LLVector3(128, 128, 20); 613 LLVector3 pos = new LLVector3(128, 128, 20);
614 while (true) 614 while (true)
615 { 615 {
616 try 616 try
617 { 617 {
618 while ((m_connected == true) && ((inputLine = m_reader.ReadLine()) != null)) 618 while ((m_connected == true) && ((inputLine = m_reader.ReadLine()) != null))
619 { 619 {
620 // Console.WriteLine(inputLine); 620 // Console.WriteLine(inputLine);
621 if (inputLine.Contains(m_channel)) 621 if (inputLine.Contains(m_channel))
622 { 622 {
623 Dictionary<string, string> data = ExtractMsg(inputLine); 623 Dictionary<string, string> data = ExtractMsg(inputLine);
624 // Any chat ??? 624 // Any chat ???
625 if (data != null) 625 if (data != null)
626 { 626 {
627 foreach (Scene m_scene in m_scenes) 627 foreach (Scene m_scene in m_scenes)
628 { 628 {
629 m_scene.ForEachScenePresence(delegate(ScenePresence avatar) 629 m_scene.ForEachScenePresence(delegate(ScenePresence avatar)
630 { 630 {
631 if (!avatar.IsChildAgent) 631 if (!avatar.IsChildAgent)
632 { 632 {
633 avatar.ControllingClient.SendChatMessage( 633 avatar.ControllingClient.SendChatMessage(
634 Helpers.StringToField(data["msg"]), 255, 634 Helpers.StringToField(data["msg"]), 255,
635 pos, data["nick"], 635 pos, data["nick"],
636 LLUUID.Zero); 636 LLUUID.Zero);
637 } 637 }
638 }); 638 });
639 } 639 }
640 } 640 }
641 else 641 else
642 { 642 {
643 // Was an command from the IRC server 643 // Was an command from the IRC server
644 ProcessIRCCommand(inputLine); 644 ProcessIRCCommand(inputLine);
645 } 645 }
646 } 646 }
647 else 647 else
648 { 648 {
649 // Was an command from the IRC server 649 // Was an command from the IRC server
650 ProcessIRCCommand(inputLine); 650 ProcessIRCCommand(inputLine);
651 } 651 }
652 Thread.Sleep(150); 652 Thread.Sleep(150);
653 } 653 }
654 } 654 }
655 catch (IOException) 655 catch (IOException)
656 { 656 {
657 m_log.Error("[IRC]: ListenerRun IOException. Disconnected from IRC server ??? (ListenerRun)"); 657 m_log.Error("[IRC]: ListenerRun IOException. Disconnected from IRC server ??? (ListenerRun)");
658 Reconnect(); 658 Reconnect();
659 } 659 }
660 catch (Exception ex) 660 catch (Exception ex)
661 { 661 {
662 m_log.Error("[IRC]: ListenerRun exception trap:" + ex.ToString() + "\n" + ex.StackTrace); 662 m_log.Error("[IRC]: ListenerRun exception trap:" + ex.ToString() + "\n" + ex.StackTrace);
663 } 663 }
664 } 664 }
665 } 665 }
666 666
667 public void BroadcastSim(string message, string sender) 667 public void BroadcastSim(string message, string sender)
668 { 668 {
669 LLVector3 pos = new LLVector3(128, 128, 20); 669 LLVector3 pos = new LLVector3(128, 128, 20);
670 try 670 try
671 { 671 {
672 foreach (Scene m_scene in m_scenes) 672 foreach (Scene m_scene in m_scenes)
673 { 673 {
674 m_scene.ForEachScenePresence(delegate(ScenePresence avatar) 674 m_scene.ForEachScenePresence(delegate(ScenePresence avatar)
675 { 675 {
676 if (!avatar.IsChildAgent) 676 if (!avatar.IsChildAgent)
677 { 677 {
678 avatar.ControllingClient.SendChatMessage( 678 avatar.ControllingClient.SendChatMessage(
679 Helpers.StringToField(message), 255, 679 Helpers.StringToField(message), 255,
680 pos, sender, 680 pos, sender,
681 LLUUID.Zero); 681 LLUUID.Zero);
682 } 682 }
683 }); 683 });
684 } 684 }
685 } 685 }
686 catch (Exception ex) // IRC gate should not crash Sim 686 catch (Exception ex) // IRC gate should not crash Sim
687 { 687 {
688 m_log.Error("[IRC]: BroadcastSim Exception Trap:" + ex.ToString() + "\n" + ex.StackTrace); 688 m_log.Error("[IRC]: BroadcastSim Exception Trap:" + ex.ToString() + "\n" + ex.StackTrace);
689 } 689 }
690 } 690 }
691 691
692 public void ProcessIRCCommand(string command) 692 public void ProcessIRCCommand(string command)
693 { 693 {
694 //m_log.Info("[IRC]: ProcessIRCCommand:" + command); 694 //m_log.Info("[IRC]: ProcessIRCCommand:" + command);
695 695
696 string[] commArgs = new string[command.Split(' ').Length]; 696 string[] commArgs = new string[command.Split(' ').Length];
697 string c_server = m_server; 697 string c_server = m_server;
698 698
699 commArgs = command.Split(' '); 699 commArgs = command.Split(' ');
700 if (commArgs[0].Substring(0, 1) == ":") 700 if (commArgs[0].Substring(0, 1) == ":")
701 { 701 {
702 commArgs[0] = commArgs[0].Remove(0, 1); 702 commArgs[0] = commArgs[0].Remove(0, 1);
703 } 703 }
704 704
705 if (commArgs[1] == "002") 705 if (commArgs[1] == "002")
706 { 706 {
707 // fetch the correct servername 707 // fetch the correct servername
708 // ex: irc.freenode.net -> brown.freenode.net/kornbluth.freenode.net/... 708 // ex: irc.freenode.net -> brown.freenode.net/kornbluth.freenode.net/...
709 // irc.bluewin.ch -> irc1.bluewin.ch/irc2.bluewin.ch 709 // irc.bluewin.ch -> irc1.bluewin.ch/irc2.bluewin.ch
710 710
711 c_server = (commArgs[6].Split('['))[0]; 711 c_server = (commArgs[6].Split('['))[0];
712 m_server = c_server; 712 m_server = c_server;
713 } 713 }
714 714
715 if (commArgs[0] == "ERROR") 715 if (commArgs[0] == "ERROR")
716 { 716 {
717 m_log.Error("[IRC]: IRC SERVER ERROR:" + command); 717 m_log.Error("[IRC]: IRC SERVER ERROR:" + command);
718 } 718 }
719 719
720 if (commArgs[0] == "PING") 720 if (commArgs[0] == "PING")
721 { 721 {
722 string p_reply = ""; 722 string p_reply = "";
723 723
724 for (int i = 1; i < commArgs.Length; i++) 724 for (int i = 1; i < commArgs.Length; i++)
725 { 725 {
726 p_reply += commArgs[i] + " "; 726 p_reply += commArgs[i] + " ";
727 } 727 }
728 728
729 m_writer.WriteLine("PONG " + p_reply); 729 m_writer.WriteLine("PONG " + p_reply);
730 m_writer.Flush(); 730 m_writer.Flush();
731 } 731 }
732 else if (commArgs[0] == c_server) 732 else if (commArgs[0] == c_server)
733 { 733 {
734 // server message 734 // server message
735 try 735 try
736 { 736 {
737 Int32 commandCode = Int32.Parse(commArgs[1]); 737 Int32 commandCode = Int32.Parse(commArgs[1]);
738 switch (commandCode) 738 switch (commandCode)
739 { 739 {
740 case (int) ErrorReplies.NicknameInUse: 740 case (int) ErrorReplies.NicknameInUse:
741 // Gen a new name 741 // Gen a new name
742 m_nick = m_basenick + Util.RandomClass.Next(1, 99); 742 m_nick = m_basenick + Util.RandomClass.Next(1, 99);
743 m_log.Error("[IRC]: IRC SERVER reports NicknameInUse, trying " + m_nick); 743 m_log.Error("[IRC]: IRC SERVER reports NicknameInUse, trying " + m_nick);
744 // Retry 744 // Retry
745 m_writer.WriteLine("NICK " + m_nick); 745 m_writer.WriteLine("NICK " + m_nick);
746 m_writer.Flush(); 746 m_writer.Flush();
747 m_writer.WriteLine("JOIN " + m_channel); 747 m_writer.WriteLine("JOIN " + m_channel);
748 m_writer.Flush(); 748 m_writer.Flush();
749 break; 749 break;
750 case (int) ErrorReplies.NotRegistered: 750 case (int) ErrorReplies.NotRegistered:
751 break; 751 break;
752 case (int) Replies.EndOfMotd: 752 case (int) Replies.EndOfMotd:
753 break; 753 break;
754 } 754 }
755 } 755 }
756 catch (Exception) 756 catch (Exception)
757 { 757 {
758 } 758 }
759 } 759 }
760 else 760 else
761 { 761 {
762 // Normal message 762 // Normal message
763 string commAct = commArgs[1]; 763 string commAct = commArgs[1];
764 switch (commAct) 764 switch (commAct)
765 { 765 {
766 case "JOIN": 766 case "JOIN":
767 eventIrcJoin(commArgs); 767 eventIrcJoin(commArgs);
768 break; 768 break;
769 case "PART": 769 case "PART":
770 eventIrcPart(commArgs); 770 eventIrcPart(commArgs);
771 break; 771 break;
772 case "MODE": 772 case "MODE":
773 eventIrcMode(commArgs); 773 eventIrcMode(commArgs);
774 break; 774 break;
775 case "NICK": 775 case "NICK":
776 eventIrcNickChange(commArgs); 776 eventIrcNickChange(commArgs);
777 break; 777 break;
778 case "KICK": 778 case "KICK":
779 eventIrcKick(commArgs); 779 eventIrcKick(commArgs);
780 break; 780 break;
781 case "QUIT": 781 case "QUIT":
782 eventIrcQuit(commArgs); 782 eventIrcQuit(commArgs);
783 break; 783 break;
784 case "PONG": 784 case "PONG":
785 break; // that's nice 785 break; // that's nice
786 } 786 }
787 } 787 }
788 } 788 }
789 789
790 public void eventIrcJoin(string[] commArgs) 790 public void eventIrcJoin(string[] commArgs)
791 { 791 {
792 string IrcChannel = commArgs[2]; 792 string IrcChannel = commArgs[2];
793 string IrcUser = commArgs[0].Split('!')[0]; 793 string IrcUser = commArgs[0].Split('!')[0];
794 BroadcastSim(IrcUser + " is joining " + IrcChannel, m_nick); 794 BroadcastSim(IrcUser + " is joining " + IrcChannel, m_nick);
795 } 795 }
796 796
797 public void eventIrcPart(string[] commArgs) 797 public void eventIrcPart(string[] commArgs)
798 { 798 {
799 string IrcChannel = commArgs[2]; 799 string IrcChannel = commArgs[2];
800 string IrcUser = commArgs[0].Split('!')[0]; 800 string IrcUser = commArgs[0].Split('!')[0];
801 BroadcastSim(IrcUser + " is parting " + IrcChannel, m_nick); 801 BroadcastSim(IrcUser + " is parting " + IrcChannel, m_nick);
802 } 802 }
803 803
804 public void eventIrcMode(string[] commArgs) 804 public void eventIrcMode(string[] commArgs)
805 { 805 {
806 string IrcChannel = commArgs[2]; 806 string IrcChannel = commArgs[2];
807 string IrcUser = commArgs[0].Split('!')[0]; 807 string IrcUser = commArgs[0].Split('!')[0];
808 string UserMode = ""; 808 string UserMode = "";
809 for (int i = 3; i < commArgs.Length; i++) 809 for (int i = 3; i < commArgs.Length; i++)
810 { 810 {
811 UserMode += commArgs[i] + " "; 811 UserMode += commArgs[i] + " ";
812 } 812 }
813 813
814 if (UserMode.Substring(0, 1) == ":") 814 if (UserMode.Substring(0, 1) == ":")
815 { 815 {
816 UserMode = UserMode.Remove(0, 1); 816 UserMode = UserMode.Remove(0, 1);
817 } 817 }
818 } 818 }
819 819
820 public void eventIrcNickChange(string[] commArgs) 820 public void eventIrcNickChange(string[] commArgs)
821 { 821 {
822 string UserOldNick = commArgs[0].Split('!')[0]; 822 string UserOldNick = commArgs[0].Split('!')[0];
823 string UserNewNick = commArgs[2].Remove(0, 1); 823 string UserNewNick = commArgs[2].Remove(0, 1);
824 BroadcastSim(UserOldNick + " changed their nick to " + UserNewNick, m_nick); 824 BroadcastSim(UserOldNick + " changed their nick to " + UserNewNick, m_nick);
825 } 825 }
826 826
827 public void eventIrcKick(string[] commArgs) 827 public void eventIrcKick(string[] commArgs)
828 { 828 {
829 string UserKicker = commArgs[0].Split('!')[0]; 829 string UserKicker = commArgs[0].Split('!')[0];
830 string UserKicked = commArgs[3]; 830 string UserKicked = commArgs[3];
831 string IrcChannel = commArgs[2]; 831 string IrcChannel = commArgs[2];
832 string KickMessage = ""; 832 string KickMessage = "";
833 for (int i = 4; i < commArgs.Length; i++) 833 for (int i = 4; i < commArgs.Length; i++)
834 { 834 {
835 KickMessage += commArgs[i] + " "; 835 KickMessage += commArgs[i] + " ";
836 } 836 }
837 BroadcastSim(UserKicker + " kicked " + UserKicked + " on " + IrcChannel + " saying " + KickMessage, m_nick); 837 BroadcastSim(UserKicker + " kicked " + UserKicked + " on " + IrcChannel + " saying " + KickMessage, m_nick);
838 if (UserKicked == m_nick) 838 if (UserKicked == m_nick)
839 { 839 {
840 BroadcastSim("Hey, that was me!!!", m_nick); 840 BroadcastSim("Hey, that was me!!!", m_nick);
841 } 841 }
842 } 842 }
843 843
844 public void eventIrcQuit(string[] commArgs) 844 public void eventIrcQuit(string[] commArgs)
845 { 845 {
846 string IrcUser = commArgs[0].Split('!')[0]; 846 string IrcUser = commArgs[0].Split('!')[0];
847 string QuitMessage = ""; 847 string QuitMessage = "";
848 848
849 for (int i = 2; i < commArgs.Length; i++) 849 for (int i = 2; i < commArgs.Length; i++)
850 { 850 {
851 QuitMessage += commArgs[i] + " "; 851 QuitMessage += commArgs[i] + " ";
852 } 852 }
853 BroadcastSim(IrcUser + " quits saying " + QuitMessage, m_nick); 853 BroadcastSim(IrcUser + " quits saying " + QuitMessage, m_nick);
854 } 854 }
855 855
856 public void Close() 856 public void Close()
857 { 857 {
858 m_connected = false; 858 m_connected = false;
859 m_writer.WriteLine("QUIT :" + m_nick + " to " + m_channel + " wormhole with " + m_server + " closing"); 859 m_writer.WriteLine("QUIT :" + m_nick + " to " + m_channel + " wormhole with " + m_server + " closing");
860 m_writer.Flush(); 860 m_writer.Flush();
861 listener.Abort(); 861 listener.Abort();
862 pingSender.Abort(); 862 pingSender.Abort();
863 m_writer.Close(); 863 m_writer.Close();
864 m_reader.Close(); 864 m_reader.Close();
865 m_tcp.Close(); 865 m_tcp.Close();
866 } 866 }
867 } 867 }
868} \ No newline at end of file 868} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Avatar/Currency/SampleMoney/SampleMoneyModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Currency/SampleMoney/SampleMoneyModule.cs
index 181984e..966c5e2 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/Currency/SampleMoney/SampleMoneyModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/Currency/SampleMoney/SampleMoneyModule.cs
@@ -1,1470 +1,1470 @@
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 OpenSim Project nor the 12 * * Neither the name of the OpenSim 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
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Net; 31using System.Net;
32using System.Net.Sockets; 32using System.Net.Sockets;
33using System.Reflection; 33using System.Reflection;
34using System.Xml; 34using System.Xml;
35using libsecondlife; 35using libsecondlife;
36using log4net; 36using log4net;
37using Nini.Config; 37using Nini.Config;
38using Nwc.XmlRpc; 38using Nwc.XmlRpc;
39using OpenSim.Framework; 39using OpenSim.Framework;
40using OpenSim.Region.Environment.Interfaces; 40using OpenSim.Region.Environment.Interfaces;
41using OpenSim.Region.Environment.Scenes; 41using OpenSim.Region.Environment.Scenes;
42 42
43namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney 43namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
44{ 44{
45 /// <summary> 45 /// <summary>
46 /// Demo Economy/Money Module. This is not a production quality money/economy module! 46 /// Demo Economy/Money Module. This is not a production quality money/economy module!
47 /// This is a demo for you to use when making one that works for you. 47 /// This is a demo for you to use when making one that works for you.
48 /// // To use the following you need to add: 48 /// // To use the following you need to add:
49 /// -helperuri <ADDRESS TO HERE OR grid MONEY SERVER> 49 /// -helperuri <ADDRESS TO HERE OR grid MONEY SERVER>
50 /// to the command line parameters you use to start up your client 50 /// to the command line parameters you use to start up your client
51 /// This commonly looks like -helperuri http://127.0.0.1:9000/ 51 /// This commonly looks like -helperuri http://127.0.0.1:9000/
52 /// 52 ///
53 /// Centralized grid structure example using OpenSimWi Redux revision 9+ 53 /// Centralized grid structure example using OpenSimWi Redux revision 9+
54 /// svn co https://opensimwiredux.svn.sourceforge.net/svnroot/opensimwiredux 54 /// svn co https://opensimwiredux.svn.sourceforge.net/svnroot/opensimwiredux
55 /// </summary> 55 /// </summary>
56 public delegate void ObjectPaid(LLUUID objectID, LLUUID agentID, int amount); 56 public delegate void ObjectPaid(LLUUID objectID, LLUUID agentID, int amount);
57 57
58 public interface IMoneyModule : IRegionModule 58 public interface IMoneyModule : IRegionModule
59 { 59 {
60 bool ObjectGiveMoney(LLUUID objectID, LLUUID fromID, LLUUID toID, int amount); 60 bool ObjectGiveMoney(LLUUID objectID, LLUUID fromID, LLUUID toID, int amount);
61 61
62 event ObjectPaid OnObjectPaid; 62 event ObjectPaid OnObjectPaid;
63 } 63 }
64 64
65 public class SampleMoneyModule : IMoneyModule 65 public class SampleMoneyModule : IMoneyModule
66 { 66 {
67 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 67 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
68 68
69 /// <summary> 69 /// <summary>
70 /// Where Stipends come from and Fees go to. 70 /// Where Stipends come from and Fees go to.
71 /// </summary> 71 /// </summary>
72 private LLUUID EconomyBaseAccount = LLUUID.Zero; 72 private LLUUID EconomyBaseAccount = LLUUID.Zero;
73 73
74 private float EnergyEfficiency = 0f; 74 private float EnergyEfficiency = 0f;
75 private bool gridmode = false; 75 private bool gridmode = false;
76 private ObjectPaid handerOnObjectPaid; 76 private ObjectPaid handerOnObjectPaid;
77 private bool m_enabled = true; 77 private bool m_enabled = true;
78 78
79 private IConfigSource m_gConfig; 79 private IConfigSource m_gConfig;
80 80
81 private bool m_keepMoneyAcrossLogins = true; 81 private bool m_keepMoneyAcrossLogins = true;
82 private Dictionary<LLUUID, int> m_KnownClientFunds = new Dictionary<LLUUID, int>(); 82 private Dictionary<LLUUID, int> m_KnownClientFunds = new Dictionary<LLUUID, int>();
83 private string m_LandAddress = String.Empty; 83 private string m_LandAddress = String.Empty;
84 84
85 private int m_minFundsBeforeRefresh = 100; 85 private int m_minFundsBeforeRefresh = 100;
86 private string m_MoneyAddress = String.Empty; 86 private string m_MoneyAddress = String.Empty;
87 87
88 /// <summary> 88 /// <summary>
89 /// Region UUIDS indexed by AgentID 89 /// Region UUIDS indexed by AgentID
90 /// </summary> 90 /// </summary>
91 private Dictionary<LLUUID, LLUUID> m_rootAgents = new Dictionary<LLUUID, LLUUID>(); 91 private Dictionary<LLUUID, LLUUID> m_rootAgents = new Dictionary<LLUUID, LLUUID>();
92 92
93 /// <summary> 93 /// <summary>
94 /// Scenes by Region Handle 94 /// Scenes by Region Handle
95 /// </summary> 95 /// </summary>
96 private Dictionary<ulong, Scene> m_scenel = new Dictionary<ulong, Scene>(); 96 private Dictionary<ulong, Scene> m_scenel = new Dictionary<ulong, Scene>();
97 97
98 private int m_stipend = 1000; 98 private int m_stipend = 1000;
99 99
100 private int ObjectCapacity = 45000; 100 private int ObjectCapacity = 45000;
101 private int ObjectCount = 0; 101 private int ObjectCount = 0;
102 private int PriceEnergyUnit = 0; 102 private int PriceEnergyUnit = 0;
103 private int PriceGroupCreate = 0; 103 private int PriceGroupCreate = 0;
104 private int PriceObjectClaim = 0; 104 private int PriceObjectClaim = 0;
105 private float PriceObjectRent = 0f; 105 private float PriceObjectRent = 0f;
106 private float PriceObjectScaleFactor = 0f; 106 private float PriceObjectScaleFactor = 0f;
107 private int PriceParcelClaim = 0; 107 private int PriceParcelClaim = 0;
108 private float PriceParcelClaimFactor = 0f; 108 private float PriceParcelClaimFactor = 0f;
109 private int PriceParcelRent = 0; 109 private int PriceParcelRent = 0;
110 private int PricePublicObjectDecay = 0; 110 private int PricePublicObjectDecay = 0;
111 private int PricePublicObjectDelete = 0; 111 private int PricePublicObjectDelete = 0;
112 private int PriceRentLight = 0; 112 private int PriceRentLight = 0;
113 private int PriceUpload = 0; 113 private int PriceUpload = 0;
114 private int TeleportMinPrice = 0; 114 private int TeleportMinPrice = 0;
115 115
116 private float TeleportPriceExponent = 0f; 116 private float TeleportPriceExponent = 0f;
117 private int UserLevelPaysFees = 2; 117 private int UserLevelPaysFees = 2;
118 private Scene XMLRPCHandler; 118 private Scene XMLRPCHandler;
119 119
120 #region IMoneyModule Members 120 #region IMoneyModule Members
121 121
122 public event ObjectPaid OnObjectPaid; 122 public event ObjectPaid OnObjectPaid;
123 123
124 /// <summary> 124 /// <summary>
125 /// Startup 125 /// Startup
126 /// </summary> 126 /// </summary>
127 /// <param name="scene"></param> 127 /// <param name="scene"></param>
128 /// <param name="config"></param> 128 /// <param name="config"></param>
129 public void Initialise(Scene scene, IConfigSource config) 129 public void Initialise(Scene scene, IConfigSource config)
130 { 130 {
131 m_gConfig = config; 131 m_gConfig = config;
132 132
133 IConfig startupConfig = m_gConfig.Configs["Startup"]; 133 IConfig startupConfig = m_gConfig.Configs["Startup"];
134 IConfig economyConfig = m_gConfig.Configs["Economy"]; 134 IConfig economyConfig = m_gConfig.Configs["Economy"];
135 135
136 scene.RegisterModuleInterface<IMoneyModule>(this); 136 scene.RegisterModuleInterface<IMoneyModule>(this);
137 137
138 ReadConfigAndPopulate(scene, startupConfig, "Startup"); 138 ReadConfigAndPopulate(scene, startupConfig, "Startup");
139 ReadConfigAndPopulate(scene, economyConfig, "Economy"); 139 ReadConfigAndPopulate(scene, economyConfig, "Economy");
140 140
141 if (m_enabled) 141 if (m_enabled)
142 { 142 {
143 lock (m_scenel) 143 lock (m_scenel)
144 { 144 {
145 if (m_scenel.Count == 0) 145 if (m_scenel.Count == 0)
146 { 146 {
147 XMLRPCHandler = scene; 147 XMLRPCHandler = scene;
148 148
149 // To use the following you need to add: 149 // To use the following you need to add:
150 // -helperuri <ADDRESS TO HERE OR grid MONEY SERVER> 150 // -helperuri <ADDRESS TO HERE OR grid MONEY SERVER>
151 // to the command line parameters you use to start up your client 151 // to the command line parameters you use to start up your client
152 // This commonly looks like -helperuri http://127.0.0.1:9000/ 152 // This commonly looks like -helperuri http://127.0.0.1:9000/
153 153
154 if (m_MoneyAddress.Length > 0) 154 if (m_MoneyAddress.Length > 0)
155 { 155 {
156 // Centralized grid structure using OpenSimWi Redux revision 9+ 156 // Centralized grid structure using OpenSimWi Redux revision 9+
157 // https://opensimwiredux.svn.sourceforge.net/svnroot/opensimwiredux 157 // https://opensimwiredux.svn.sourceforge.net/svnroot/opensimwiredux
158 scene.AddXmlRPCHandler("balanceUpdateRequest", GridMoneyUpdate); 158 scene.AddXmlRPCHandler("balanceUpdateRequest", GridMoneyUpdate);
159 scene.AddXmlRPCHandler("userAlert", UserAlert); 159 scene.AddXmlRPCHandler("userAlert", UserAlert);
160 } 160 }
161 else 161 else
162 { 162 {
163 // Local Server.. enables functionality only. 163 // Local Server.. enables functionality only.
164 scene.AddXmlRPCHandler("getCurrencyQuote", quote_func); 164 scene.AddXmlRPCHandler("getCurrencyQuote", quote_func);
165 scene.AddXmlRPCHandler("buyCurrency", buy_func); 165 scene.AddXmlRPCHandler("buyCurrency", buy_func);
166 scene.AddXmlRPCHandler("preflightBuyLandPrep", preflightBuyLandPrep_func); 166 scene.AddXmlRPCHandler("preflightBuyLandPrep", preflightBuyLandPrep_func);
167 scene.AddXmlRPCHandler("buyLandPrep", landBuy_func); 167 scene.AddXmlRPCHandler("buyLandPrep", landBuy_func);
168 } 168 }
169 } 169 }
170 170
171 if (m_scenel.ContainsKey(scene.RegionInfo.RegionHandle)) 171 if (m_scenel.ContainsKey(scene.RegionInfo.RegionHandle))
172 { 172 {
173 m_scenel[scene.RegionInfo.RegionHandle] = scene; 173 m_scenel[scene.RegionInfo.RegionHandle] = scene;
174 } 174 }
175 else 175 else
176 { 176 {
177 m_scenel.Add(scene.RegionInfo.RegionHandle, scene); 177 m_scenel.Add(scene.RegionInfo.RegionHandle, scene);
178 } 178 }
179 } 179 }
180 180
181 scene.EventManager.OnNewClient += OnNewClient; 181 scene.EventManager.OnNewClient += OnNewClient;
182 scene.EventManager.OnMoneyTransfer += MoneyTransferAction; 182 scene.EventManager.OnMoneyTransfer += MoneyTransferAction;
183 scene.EventManager.OnClientClosed += ClientClosed; 183 scene.EventManager.OnClientClosed += ClientClosed;
184 scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel; 184 scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel;
185 scene.EventManager.OnMakeChildAgent += MakeChildAgent; 185 scene.EventManager.OnMakeChildAgent += MakeChildAgent;
186 scene.EventManager.OnClientClosed += ClientLoggedOut; 186 scene.EventManager.OnClientClosed += ClientLoggedOut;
187 scene.EventManager.OnValidateLandBuy += ValidateLandBuy; 187 scene.EventManager.OnValidateLandBuy += ValidateLandBuy;
188 scene.EventManager.OnLandBuy += processLandBuy; 188 scene.EventManager.OnLandBuy += processLandBuy;
189 } 189 }
190 } 190 }
191 191
192 public bool ObjectGiveMoney(LLUUID objectID, LLUUID fromID, LLUUID toID, int amount) 192 public bool ObjectGiveMoney(LLUUID objectID, LLUUID fromID, LLUUID toID, int amount)
193 { 193 {
194 string description = String.Format("Object {0} pays {1}", resolveObjectName(objectID), resolveAgentName(toID)); 194 string description = String.Format("Object {0} pays {1}", resolveObjectName(objectID), resolveAgentName(toID));
195 195
196 bool give_result = doMoneyTransfer(fromID, toID, amount, 2, description); 196 bool give_result = doMoneyTransfer(fromID, toID, amount, 2, description);
197 197
198 if (m_MoneyAddress.Length == 0) 198 if (m_MoneyAddress.Length == 0)
199 BalanceUpdate(fromID, toID, give_result, description); 199 BalanceUpdate(fromID, toID, give_result, description);
200 200
201 return give_result; 201 return give_result;
202 } 202 }
203 203
204 public void PostInitialise() 204 public void PostInitialise()
205 { 205 {
206 } 206 }
207 207
208 public void Close() 208 public void Close()
209 { 209 {
210 } 210 }
211 211
212 public string Name 212 public string Name
213 { 213 {
214 get { return "BetaGridLikeMoneyModule"; } 214 get { return "BetaGridLikeMoneyModule"; }
215 } 215 }
216 216
217 public bool IsSharedModule 217 public bool IsSharedModule
218 { 218 {
219 get { return true; } 219 get { return true; }
220 } 220 }
221 221
222 #endregion 222 #endregion
223 223
224 /// <summary> 224 /// <summary>
225 /// Parse Configuration 225 /// Parse Configuration
226 /// </summary> 226 /// </summary>
227 /// <param name="scene"></param> 227 /// <param name="scene"></param>
228 /// <param name="startupConfig"></param> 228 /// <param name="startupConfig"></param>
229 /// <param name="config"></param> 229 /// <param name="config"></param>
230 private void ReadConfigAndPopulate(Scene scene, IConfig startupConfig, string config) 230 private void ReadConfigAndPopulate(Scene scene, IConfig startupConfig, string config)
231 { 231 {
232 if (config == "Startup" && startupConfig != null) 232 if (config == "Startup" && startupConfig != null)
233 { 233 {
234 gridmode = startupConfig.GetBoolean("gridmode", false); 234 gridmode = startupConfig.GetBoolean("gridmode", false);
235 m_enabled = (startupConfig.GetString("economymodule", "BetaGridLikeMoneyModule") == "BetaGridLikeMoneyModule"); 235 m_enabled = (startupConfig.GetString("economymodule", "BetaGridLikeMoneyModule") == "BetaGridLikeMoneyModule");
236 } 236 }
237 237
238 if (config == "Economy" && startupConfig != null) 238 if (config == "Economy" && startupConfig != null)
239 { 239 {
240 ObjectCapacity = startupConfig.GetInt("ObjectCapacity", 45000); 240 ObjectCapacity = startupConfig.GetInt("ObjectCapacity", 45000);
241 PriceEnergyUnit = startupConfig.GetInt("PriceEnergyUnit", 100); 241 PriceEnergyUnit = startupConfig.GetInt("PriceEnergyUnit", 100);
242 PriceObjectClaim = startupConfig.GetInt("PriceObjectClaim", 10); 242 PriceObjectClaim = startupConfig.GetInt("PriceObjectClaim", 10);
243 PricePublicObjectDecay = startupConfig.GetInt("PricePublicObjectDecay", 4); 243 PricePublicObjectDecay = startupConfig.GetInt("PricePublicObjectDecay", 4);
244 PricePublicObjectDelete = startupConfig.GetInt("PricePublicObjectDelete", 4); 244 PricePublicObjectDelete = startupConfig.GetInt("PricePublicObjectDelete", 4);
245 PriceParcelClaim = startupConfig.GetInt("PriceParcelClaim", 1); 245 PriceParcelClaim = startupConfig.GetInt("PriceParcelClaim", 1);
246 PriceParcelClaimFactor = startupConfig.GetFloat("PriceParcelClaimFactor", 1f); 246 PriceParcelClaimFactor = startupConfig.GetFloat("PriceParcelClaimFactor", 1f);
247 PriceUpload = startupConfig.GetInt("PriceUpload", 0); 247 PriceUpload = startupConfig.GetInt("PriceUpload", 0);
248 PriceRentLight = startupConfig.GetInt("PriceRentLight", 5); 248 PriceRentLight = startupConfig.GetInt("PriceRentLight", 5);
249 TeleportMinPrice = startupConfig.GetInt("TeleportMinPrice", 2); 249 TeleportMinPrice = startupConfig.GetInt("TeleportMinPrice", 2);
250 TeleportPriceExponent = startupConfig.GetFloat("TeleportPriceExponent", 2f); 250 TeleportPriceExponent = startupConfig.GetFloat("TeleportPriceExponent", 2f);
251 EnergyEfficiency = startupConfig.GetFloat("EnergyEfficiency", 1); 251 EnergyEfficiency = startupConfig.GetFloat("EnergyEfficiency", 1);
252 PriceObjectRent = startupConfig.GetFloat("PriceObjectRent", 1); 252 PriceObjectRent = startupConfig.GetFloat("PriceObjectRent", 1);
253 PriceObjectScaleFactor = startupConfig.GetFloat("PriceObjectScaleFactor", 10); 253 PriceObjectScaleFactor = startupConfig.GetFloat("PriceObjectScaleFactor", 10);
254 PriceParcelRent = startupConfig.GetInt("PriceParcelRent", 1); 254 PriceParcelRent = startupConfig.GetInt("PriceParcelRent", 1);
255 PriceGroupCreate = startupConfig.GetInt("PriceGroupCreate", -1); 255 PriceGroupCreate = startupConfig.GetInt("PriceGroupCreate", -1);
256 string EBA = startupConfig.GetString("EconomyBaseAccount", LLUUID.Zero.ToString()); 256 string EBA = startupConfig.GetString("EconomyBaseAccount", LLUUID.Zero.ToString());
257 Helpers.TryParse(EBA, out EconomyBaseAccount); 257 Helpers.TryParse(EBA, out EconomyBaseAccount);
258 258
259 UserLevelPaysFees = startupConfig.GetInt("UserLevelPaysFees", -1); 259 UserLevelPaysFees = startupConfig.GetInt("UserLevelPaysFees", -1);
260 m_stipend = startupConfig.GetInt("UserStipend", 500); 260 m_stipend = startupConfig.GetInt("UserStipend", 500);
261 m_minFundsBeforeRefresh = startupConfig.GetInt("IssueStipendWhenClientIsBelowAmount", 10); 261 m_minFundsBeforeRefresh = startupConfig.GetInt("IssueStipendWhenClientIsBelowAmount", 10);
262 m_keepMoneyAcrossLogins = startupConfig.GetBoolean("KeepMoneyAcrossLogins", true); 262 m_keepMoneyAcrossLogins = startupConfig.GetBoolean("KeepMoneyAcrossLogins", true);
263 m_MoneyAddress = startupConfig.GetString("CurrencyServer", String.Empty); 263 m_MoneyAddress = startupConfig.GetString("CurrencyServer", String.Empty);
264 m_LandAddress = startupConfig.GetString("LandServer", String.Empty); 264 m_LandAddress = startupConfig.GetString("LandServer", String.Empty);
265 } 265 }
266 266
267 // Send ObjectCapacity to Scene.. Which sends it to the SimStatsReporter. 267 // Send ObjectCapacity to Scene.. Which sends it to the SimStatsReporter.
268 scene.SetObjectCapacity(ObjectCapacity); 268 scene.SetObjectCapacity(ObjectCapacity);
269 } 269 }
270 270
271 /// <summary> 271 /// <summary>
272 /// New Client Event Handler 272 /// New Client Event Handler
273 /// </summary> 273 /// </summary>
274 /// <param name="client"></param> 274 /// <param name="client"></param>
275 private void OnNewClient(IClientAPI client) 275 private void OnNewClient(IClientAPI client)
276 { 276 {
277 // Here we check if we're in grid mode 277 // Here we check if we're in grid mode
278 // I imagine that the 'check balance' 278 // I imagine that the 'check balance'
279 // function for the client should be here or shortly after 279 // function for the client should be here or shortly after
280 280
281 if (gridmode) 281 if (gridmode)
282 { 282 {
283 if (m_MoneyAddress.Length == 0) 283 if (m_MoneyAddress.Length == 0)
284 { 284 {
285 CheckExistAndRefreshFunds(client.AgentId); 285 CheckExistAndRefreshFunds(client.AgentId);
286 } 286 }
287 else 287 else
288 { 288 {
289 bool childYN = true; 289 bool childYN = true;
290 ScenePresence agent = null; 290 ScenePresence agent = null;
291 //client.SecureSessionId; 291 //client.SecureSessionId;
292 Scene s = LocateSceneClientIn(client.AgentId); 292 Scene s = LocateSceneClientIn(client.AgentId);
293 if (s != null) 293 if (s != null)
294 { 294 {
295 agent = s.GetScenePresence(client.AgentId); 295 agent = s.GetScenePresence(client.AgentId);
296 if (agent != null) 296 if (agent != null)
297 childYN = agent.IsChildAgent; 297 childYN = agent.IsChildAgent;
298 } 298 }
299 if (s != null && agent != null && childYN == false) 299 if (s != null && agent != null && childYN == false)
300 { 300 {
301 //s.RegionInfo.RegionHandle; 301 //s.RegionInfo.RegionHandle;
302 LLUUID agentID = LLUUID.Zero; 302 LLUUID agentID = LLUUID.Zero;
303 int funds = 0; 303 int funds = 0;
304 304
305 Hashtable hbinfo = 305 Hashtable hbinfo =
306 GetBalanceForUserFromMoneyServer(client.AgentId, client.SecureSessionId, s.RegionInfo.originRegionID.ToString(), 306 GetBalanceForUserFromMoneyServer(client.AgentId, client.SecureSessionId, s.RegionInfo.originRegionID.ToString(),
307 s.RegionInfo.regionSecret); 307 s.RegionInfo.regionSecret);
308 if ((bool) hbinfo["success"] == true) 308 if ((bool) hbinfo["success"] == true)
309 { 309 {
310 Helpers.TryParse((string) hbinfo["agentId"], out agentID); 310 Helpers.TryParse((string) hbinfo["agentId"], out agentID);
311 try 311 try
312 { 312 {
313 funds = (Int32) hbinfo["funds"]; 313 funds = (Int32) hbinfo["funds"];
314 } 314 }
315 catch (ArgumentException) 315 catch (ArgumentException)
316 { 316 {
317 } 317 }
318 catch (FormatException) 318 catch (FormatException)
319 { 319 {
320 } 320 }
321 catch (OverflowException) 321 catch (OverflowException)
322 { 322 {
323 m_log.ErrorFormat("[MONEY]: While getting the Currency for user {0}, the return funds overflowed.", agentID); 323 m_log.ErrorFormat("[MONEY]: While getting the Currency for user {0}, the return funds overflowed.", agentID);
324 client.SendAlertMessage("Unable to get your money balance, money operations will be unavailable"); 324 client.SendAlertMessage("Unable to get your money balance, money operations will be unavailable");
325 } 325 }
326 catch (InvalidCastException) 326 catch (InvalidCastException)
327 { 327 {
328 funds = 0; 328 funds = 0;
329 } 329 }
330 330
331 m_KnownClientFunds[agentID] = funds; 331 m_KnownClientFunds[agentID] = funds;
332 } 332 }
333 else 333 else
334 { 334 {
335 m_log.WarnFormat("[MONEY]: Getting Money for user {0} failed with the following message:{1}", agentID, 335 m_log.WarnFormat("[MONEY]: Getting Money for user {0} failed with the following message:{1}", agentID,
336 (string) hbinfo["errorMessage"]); 336 (string) hbinfo["errorMessage"]);
337 client.SendAlertMessage((string) hbinfo["errorMessage"]); 337 client.SendAlertMessage((string) hbinfo["errorMessage"]);
338 } 338 }
339 SendMoneyBalance(client, agentID, client.SessionId, LLUUID.Zero); 339 SendMoneyBalance(client, agentID, client.SessionId, LLUUID.Zero);
340 } 340 }
341 } 341 }
342 } 342 }
343 else 343 else
344 { 344 {
345 CheckExistAndRefreshFunds(client.AgentId); 345 CheckExistAndRefreshFunds(client.AgentId);
346 } 346 }
347 347
348 // Subscribe to Money messages 348 // Subscribe to Money messages
349 client.OnEconomyDataRequest += EconomyDataRequestHandler; 349 client.OnEconomyDataRequest += EconomyDataRequestHandler;
350 client.OnMoneyBalanceRequest += SendMoneyBalance; 350 client.OnMoneyBalanceRequest += SendMoneyBalance;
351 client.OnRequestPayPrice += requestPayPrice; 351 client.OnRequestPayPrice += requestPayPrice;
352 client.OnLogout += ClientClosed; 352 client.OnLogout += ClientClosed;
353 } 353 }
354 354
355 /// <summary> 355 /// <summary>
356 /// Transfer money 356 /// Transfer money
357 /// </summary> 357 /// </summary>
358 /// <param name="Sender"></param> 358 /// <param name="Sender"></param>
359 /// <param name="Receiver"></param> 359 /// <param name="Receiver"></param>
360 /// <param name="amount"></param> 360 /// <param name="amount"></param>
361 /// <returns></returns> 361 /// <returns></returns>
362 private bool doMoneyTransfer(LLUUID Sender, LLUUID Receiver, int amount, int transactiontype, string description) 362 private bool doMoneyTransfer(LLUUID Sender, LLUUID Receiver, int amount, int transactiontype, string description)
363 { 363 {
364 bool result = false; 364 bool result = false;
365 if (amount >= 0) 365 if (amount >= 0)
366 { 366 {
367 lock (m_KnownClientFunds) 367 lock (m_KnownClientFunds)
368 { 368 {
369 // If we don't know about the sender, then the sender can't 369 // If we don't know about the sender, then the sender can't
370 // actually be here and therefore this is likely fraud or outdated. 370 // actually be here and therefore this is likely fraud or outdated.
371 if (m_MoneyAddress.Length == 0) 371 if (m_MoneyAddress.Length == 0)
372 { 372 {
373 if (m_KnownClientFunds.ContainsKey(Sender)) 373 if (m_KnownClientFunds.ContainsKey(Sender))
374 { 374 {
375 // Does the sender have enough funds to give? 375 // Does the sender have enough funds to give?
376 if (m_KnownClientFunds[Sender] >= amount) 376 if (m_KnownClientFunds[Sender] >= amount)
377 { 377 {
378 // Subtract the funds from the senders account 378 // Subtract the funds from the senders account
379 m_KnownClientFunds[Sender] -= amount; 379 m_KnownClientFunds[Sender] -= amount;
380 380
381 // do we know about the receiver? 381 // do we know about the receiver?
382 if (!m_KnownClientFunds.ContainsKey(Receiver)) 382 if (!m_KnownClientFunds.ContainsKey(Receiver))
383 { 383 {
384 // Make a record for them so they get the updated balance when they login 384 // Make a record for them so they get the updated balance when they login
385 CheckExistAndRefreshFunds(Receiver); 385 CheckExistAndRefreshFunds(Receiver);
386 } 386 }
387 if (m_enabled) 387 if (m_enabled)
388 { 388 {
389 //Add the amount to the Receiver's funds 389 //Add the amount to the Receiver's funds
390 m_KnownClientFunds[Receiver] += amount; 390 m_KnownClientFunds[Receiver] += amount;
391 result = true; 391 result = true;
392 } 392 }
393 } 393 }
394 else 394 else
395 { 395 {
396 // These below are redundant to make this clearer to read 396 // These below are redundant to make this clearer to read
397 result = false; 397 result = false;
398 } 398 }
399 } 399 }
400 else 400 else
401 { 401 {
402 result = false; 402 result = false;
403 } 403 }
404 } 404 }
405 else 405 else
406 { 406 {
407 result = TransferMoneyonMoneyServer(Sender, Receiver, amount, transactiontype, description); 407 result = TransferMoneyonMoneyServer(Sender, Receiver, amount, transactiontype, description);
408 } 408 }
409 } 409 }
410 } 410 }
411 return result; 411 return result;
412 } 412 }
413 413
414 414
415 /// <summary> 415 /// <summary>
416 /// Sends the the stored money balance to the client 416 /// Sends the the stored money balance to the client
417 /// </summary> 417 /// </summary>
418 /// <param name="client"></param> 418 /// <param name="client"></param>
419 /// <param name="agentID"></param> 419 /// <param name="agentID"></param>
420 /// <param name="SessionID"></param> 420 /// <param name="SessionID"></param>
421 /// <param name="TransactionID"></param> 421 /// <param name="TransactionID"></param>
422 public void SendMoneyBalance(IClientAPI client, LLUUID agentID, LLUUID SessionID, LLUUID TransactionID) 422 public void SendMoneyBalance(IClientAPI client, LLUUID agentID, LLUUID SessionID, LLUUID TransactionID)
423 { 423 {
424 if (client.AgentId == agentID && client.SessionId == SessionID) 424 if (client.AgentId == agentID && client.SessionId == SessionID)
425 { 425 {
426 int returnfunds = 0; 426 int returnfunds = 0;
427 427
428 try 428 try
429 { 429 {
430 returnfunds = GetFundsForAgentID(agentID); 430 returnfunds = GetFundsForAgentID(agentID);
431 } 431 }
432 catch (Exception e) 432 catch (Exception e)
433 { 433 {
434 client.SendAlertMessage(e.Message + " "); 434 client.SendAlertMessage(e.Message + " ");
435 } 435 }
436 436
437 client.SendMoneyBalance(TransactionID, true, new byte[0], returnfunds); 437 client.SendMoneyBalance(TransactionID, true, new byte[0], returnfunds);
438 } 438 }
439 else 439 else
440 { 440 {
441 client.SendAlertMessage("Unable to send your money balance to you!"); 441 client.SendAlertMessage("Unable to send your money balance to you!");
442 } 442 }
443 } 443 }
444 444
445 /// <summary> 445 /// <summary>
446 /// Gets the current balance for the user from the Grid Money Server 446 /// Gets the current balance for the user from the Grid Money Server
447 /// </summary> 447 /// </summary>
448 /// <param name="agentId"></param> 448 /// <param name="agentId"></param>
449 /// <param name="secureSessionID"></param> 449 /// <param name="secureSessionID"></param>
450 /// <param name="regionId"></param> 450 /// <param name="regionId"></param>
451 /// <param name="regionSecret"></param> 451 /// <param name="regionSecret"></param>
452 /// <returns></returns> 452 /// <returns></returns>
453 public Hashtable GetBalanceForUserFromMoneyServer(LLUUID agentId, LLUUID secureSessionID, LLUUID regionId, string regionSecret) 453 public Hashtable GetBalanceForUserFromMoneyServer(LLUUID agentId, LLUUID secureSessionID, LLUUID regionId, string regionSecret)
454 { 454 {
455 Hashtable MoneyBalanceRequestParams = new Hashtable(); 455 Hashtable MoneyBalanceRequestParams = new Hashtable();
456 MoneyBalanceRequestParams["agentId"] = agentId.ToString(); 456 MoneyBalanceRequestParams["agentId"] = agentId.ToString();
457 MoneyBalanceRequestParams["secureSessionId"] = secureSessionID.ToString(); 457 MoneyBalanceRequestParams["secureSessionId"] = secureSessionID.ToString();
458 MoneyBalanceRequestParams["regionId"] = regionId.ToString(); 458 MoneyBalanceRequestParams["regionId"] = regionId.ToString();
459 MoneyBalanceRequestParams["secret"] = regionSecret; 459 MoneyBalanceRequestParams["secret"] = regionSecret;
460 MoneyBalanceRequestParams["currencySecret"] = ""; // per - region/user currency secret gotten from the money system 460 MoneyBalanceRequestParams["currencySecret"] = ""; // per - region/user currency secret gotten from the money system
461 461
462 Hashtable MoneyRespData = genericCurrencyXMLRPCRequest(MoneyBalanceRequestParams, "simulatorUserBalanceRequest"); 462 Hashtable MoneyRespData = genericCurrencyXMLRPCRequest(MoneyBalanceRequestParams, "simulatorUserBalanceRequest");
463 463
464 return MoneyRespData; 464 return MoneyRespData;
465 } 465 }
466 466
467 467
468 /// <summary> 468 /// <summary>
469 /// Generic XMLRPC client abstraction 469 /// Generic XMLRPC client abstraction
470 /// </summary> 470 /// </summary>
471 /// <param name="ReqParams">Hashtable containing parameters to the method</param> 471 /// <param name="ReqParams">Hashtable containing parameters to the method</param>
472 /// <param name="method">Method to invoke</param> 472 /// <param name="method">Method to invoke</param>
473 /// <returns>Hashtable with success=>bool and other values</returns> 473 /// <returns>Hashtable with success=>bool and other values</returns>
474 public Hashtable genericCurrencyXMLRPCRequest(Hashtable ReqParams, string method) 474 public Hashtable genericCurrencyXMLRPCRequest(Hashtable ReqParams, string method)
475 { 475 {
476 ArrayList SendParams = new ArrayList(); 476 ArrayList SendParams = new ArrayList();
477 SendParams.Add(ReqParams); 477 SendParams.Add(ReqParams);
478 // Send Request 478 // Send Request
479 XmlRpcResponse MoneyResp; 479 XmlRpcResponse MoneyResp;
480 try 480 try
481 { 481 {
482 XmlRpcRequest BalanceRequestReq = new XmlRpcRequest(method, SendParams); 482 XmlRpcRequest BalanceRequestReq = new XmlRpcRequest(method, SendParams);
483 MoneyResp = BalanceRequestReq.Send(m_MoneyAddress, 30000); 483 MoneyResp = BalanceRequestReq.Send(m_MoneyAddress, 30000);
484 } 484 }
485 catch (WebException ex) 485 catch (WebException ex)
486 { 486 {
487 m_log.ErrorFormat( 487 m_log.ErrorFormat(
488 "[MONEY]: Unable to connect to Money Server {0}. Exception {1}", 488 "[MONEY]: Unable to connect to Money Server {0}. Exception {1}",
489 m_MoneyAddress, ex); 489 m_MoneyAddress, ex);
490 490
491 Hashtable ErrorHash = new Hashtable(); 491 Hashtable ErrorHash = new Hashtable();
492 ErrorHash["success"] = false; 492 ErrorHash["success"] = false;
493 ErrorHash["errorMessage"] = "Unable to manage your money at this time. Purchases may be unavailable"; 493 ErrorHash["errorMessage"] = "Unable to manage your money at this time. Purchases may be unavailable";
494 ErrorHash["errorURI"] = ""; 494 ErrorHash["errorURI"] = "";
495 495
496 return ErrorHash; 496 return ErrorHash;
497 //throw (ex); 497 //throw (ex);
498 } 498 }
499 catch (SocketException ex) 499 catch (SocketException ex)
500 { 500 {
501 m_log.ErrorFormat( 501 m_log.ErrorFormat(
502 "[MONEY]: Unable to connect to Money Server {0}. Exception {1}", 502 "[MONEY]: Unable to connect to Money Server {0}. Exception {1}",
503 m_MoneyAddress, ex); 503 m_MoneyAddress, ex);
504 504
505 Hashtable ErrorHash = new Hashtable(); 505 Hashtable ErrorHash = new Hashtable();
506 ErrorHash["success"] = false; 506 ErrorHash["success"] = false;
507 ErrorHash["errorMessage"] = "Unable to manage your money at this time. Purchases may be unavailable"; 507 ErrorHash["errorMessage"] = "Unable to manage your money at this time. Purchases may be unavailable";
508 ErrorHash["errorURI"] = ""; 508 ErrorHash["errorURI"] = "";
509 509
510 return ErrorHash; 510 return ErrorHash;
511 //throw (ex); 511 //throw (ex);
512 } 512 }
513 catch (XmlException ex) 513 catch (XmlException ex)
514 { 514 {
515 m_log.ErrorFormat( 515 m_log.ErrorFormat(
516 "[MONEY]: Unable to connect to Money Server {0}. Exception {1}", 516 "[MONEY]: Unable to connect to Money Server {0}. Exception {1}",
517 m_MoneyAddress, ex); 517 m_MoneyAddress, ex);
518 518
519 Hashtable ErrorHash = new Hashtable(); 519 Hashtable ErrorHash = new Hashtable();
520 ErrorHash["success"] = false; 520 ErrorHash["success"] = false;
521 ErrorHash["errorMessage"] = "Unable to manage your money at this time. Purchases may be unavailable"; 521 ErrorHash["errorMessage"] = "Unable to manage your money at this time. Purchases may be unavailable";
522 ErrorHash["errorURI"] = ""; 522 ErrorHash["errorURI"] = "";
523 523
524 return ErrorHash; 524 return ErrorHash;
525 } 525 }
526 if (MoneyResp.IsFault) 526 if (MoneyResp.IsFault)
527 { 527 {
528 Hashtable ErrorHash = new Hashtable(); 528 Hashtable ErrorHash = new Hashtable();
529 ErrorHash["success"] = false; 529 ErrorHash["success"] = false;
530 ErrorHash["errorMessage"] = "Unable to manage your money at this time. Purchases may be unavailable"; 530 ErrorHash["errorMessage"] = "Unable to manage your money at this time. Purchases may be unavailable";
531 ErrorHash["errorURI"] = ""; 531 ErrorHash["errorURI"] = "";
532 532
533 return ErrorHash; 533 return ErrorHash;
534 } 534 }
535 Hashtable MoneyRespData = (Hashtable) MoneyResp.Value; 535 Hashtable MoneyRespData = (Hashtable) MoneyResp.Value;
536 536
537 return MoneyRespData; 537 return MoneyRespData;
538 } 538 }
539 539
540 /// <summary> 540 /// <summary>
541 /// This informs the Money Grid Server that the avatar is in this simulator 541 /// This informs the Money Grid Server that the avatar is in this simulator
542 /// </summary> 542 /// </summary>
543 /// <param name="agentId"></param> 543 /// <param name="agentId"></param>
544 /// <param name="secureSessionID"></param> 544 /// <param name="secureSessionID"></param>
545 /// <param name="regionId"></param> 545 /// <param name="regionId"></param>
546 /// <param name="regionSecret"></param> 546 /// <param name="regionSecret"></param>
547 /// <returns></returns> 547 /// <returns></returns>
548 public Hashtable claim_user(LLUUID agentId, LLUUID secureSessionID, LLUUID regionId, string regionSecret) 548 public Hashtable claim_user(LLUUID agentId, LLUUID secureSessionID, LLUUID regionId, string regionSecret)
549 { 549 {
550 Hashtable MoneyBalanceRequestParams = new Hashtable(); 550 Hashtable MoneyBalanceRequestParams = new Hashtable();
551 MoneyBalanceRequestParams["agentId"] = agentId.ToString(); 551 MoneyBalanceRequestParams["agentId"] = agentId.ToString();
552 MoneyBalanceRequestParams["secureSessionId"] = secureSessionID.ToString(); 552 MoneyBalanceRequestParams["secureSessionId"] = secureSessionID.ToString();
553 MoneyBalanceRequestParams["regionId"] = regionId.ToString(); 553 MoneyBalanceRequestParams["regionId"] = regionId.ToString();
554 MoneyBalanceRequestParams["secret"] = regionSecret; 554 MoneyBalanceRequestParams["secret"] = regionSecret;
555 555
556 Hashtable MoneyRespData = genericCurrencyXMLRPCRequest(MoneyBalanceRequestParams, "simulatorClaimUserRequest"); 556 Hashtable MoneyRespData = genericCurrencyXMLRPCRequest(MoneyBalanceRequestParams, "simulatorClaimUserRequest");
557 IClientAPI sendMoneyBal = LocateClientObject(agentId); 557 IClientAPI sendMoneyBal = LocateClientObject(agentId);
558 if (sendMoneyBal != null) 558 if (sendMoneyBal != null)
559 { 559 {
560 SendMoneyBalance(sendMoneyBal, agentId, sendMoneyBal.SessionId, LLUUID.Zero); 560 SendMoneyBalance(sendMoneyBal, agentId, sendMoneyBal.SessionId, LLUUID.Zero);
561 } 561 }
562 return MoneyRespData; 562 return MoneyRespData;
563 } 563 }
564 564
565 private SceneObjectPart findPrim(LLUUID objectID) 565 private SceneObjectPart findPrim(LLUUID objectID)
566 { 566 {
567 lock (m_scenel) 567 lock (m_scenel)
568 { 568 {
569 foreach (Scene s in m_scenel.Values) 569 foreach (Scene s in m_scenel.Values)
570 { 570 {
571 SceneObjectPart part = s.GetSceneObjectPart(objectID); 571 SceneObjectPart part = s.GetSceneObjectPart(objectID);
572 if (part != null) 572 if (part != null)
573 { 573 {
574 return part; 574 return part;
575 } 575 }
576 } 576 }
577 } 577 }
578 return null; 578 return null;
579 } 579 }
580 580
581 private string resolveObjectName(LLUUID objectID) 581 private string resolveObjectName(LLUUID objectID)
582 { 582 {
583 SceneObjectPart part = findPrim(objectID); 583 SceneObjectPart part = findPrim(objectID);
584 if (part != null) 584 if (part != null)
585 { 585 {
586 return part.Name; 586 return part.Name;
587 } 587 }
588 return String.Empty; 588 return String.Empty;
589 } 589 }
590 590
591 private string resolveAgentName(LLUUID agentID) 591 private string resolveAgentName(LLUUID agentID)
592 { 592 {
593 // try avatar username surname 593 // try avatar username surname
594 Scene scene = GetRandomScene(); 594 Scene scene = GetRandomScene();
595 UserProfileData profile = scene.CommsManager.UserService.GetUserProfile(agentID); 595 UserProfileData profile = scene.CommsManager.UserService.GetUserProfile(agentID);
596 if (profile != null) 596 if (profile != null)
597 { 597 {
598 string avatarname = profile.FirstName + " " + profile.SurName; 598 string avatarname = profile.FirstName + " " + profile.SurName;
599 return avatarname; 599 return avatarname;
600 } 600 }
601 return String.Empty; 601 return String.Empty;
602 } 602 }
603 603
604 private void BalanceUpdate(LLUUID senderID, LLUUID receiverID, bool transactionresult, string description) 604 private void BalanceUpdate(LLUUID senderID, LLUUID receiverID, bool transactionresult, string description)
605 { 605 {
606 IClientAPI sender = LocateClientObject(senderID); 606 IClientAPI sender = LocateClientObject(senderID);
607 IClientAPI receiver = LocateClientObject(receiverID); 607 IClientAPI receiver = LocateClientObject(receiverID);
608 608
609 if (senderID != receiverID) 609 if (senderID != receiverID)
610 { 610 {
611 if (sender != null) 611 if (sender != null)
612 { 612 {
613 sender.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(description), GetFundsForAgentID(senderID)); 613 sender.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(description), GetFundsForAgentID(senderID));
614 } 614 }
615 615
616 if (receiver != null) 616 if (receiver != null)
617 { 617 {
618 receiver.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(description), GetFundsForAgentID(receiverID)); 618 receiver.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(description), GetFundsForAgentID(receiverID));
619 } 619 }
620 } 620 }
621 } 621 }
622 622
623 /// <summary> 623 /// <summary>
624 /// Informs the Money Grid Server of a transfer. 624 /// Informs the Money Grid Server of a transfer.
625 /// </summary> 625 /// </summary>
626 /// <param name="sourceId"></param> 626 /// <param name="sourceId"></param>
627 /// <param name="destId"></param> 627 /// <param name="destId"></param>
628 /// <param name="amount"></param> 628 /// <param name="amount"></param>
629 /// <returns></returns> 629 /// <returns></returns>
630 public bool TransferMoneyonMoneyServer(LLUUID sourceId, LLUUID destId, int amount, int transactiontype, string description) 630 public bool TransferMoneyonMoneyServer(LLUUID sourceId, LLUUID destId, int amount, int transactiontype, string description)
631 { 631 {
632 int aggregatePermInventory = 0; 632 int aggregatePermInventory = 0;
633 int aggregatePermNextOwner = 0; 633 int aggregatePermNextOwner = 0;
634 int flags = 0; 634 int flags = 0;
635 bool rvalue = false; 635 bool rvalue = false;
636 636
637 IClientAPI cli = LocateClientObject(sourceId); 637 IClientAPI cli = LocateClientObject(sourceId);
638 if (cli != null) 638 if (cli != null)
639 { 639 {
640 Scene userScene = null; 640 Scene userScene = null;
641 lock (m_rootAgents) 641 lock (m_rootAgents)
642 { 642 {
643 userScene = GetSceneByUUID(m_rootAgents[sourceId]); 643 userScene = GetSceneByUUID(m_rootAgents[sourceId]);
644 } 644 }
645 if (userScene != null) 645 if (userScene != null)
646 { 646 {
647 Hashtable ht = new Hashtable(); 647 Hashtable ht = new Hashtable();
648 ht["agentId"] = sourceId.ToString(); 648 ht["agentId"] = sourceId.ToString();
649 ht["secureSessionId"] = cli.SecureSessionId.ToString(); 649 ht["secureSessionId"] = cli.SecureSessionId.ToString();
650 ht["regionId"] = userScene.RegionInfo.originRegionID.ToString(); 650 ht["regionId"] = userScene.RegionInfo.originRegionID.ToString();
651 ht["secret"] = userScene.RegionInfo.regionSecret; 651 ht["secret"] = userScene.RegionInfo.regionSecret;
652 ht["currencySecret"] = " "; 652 ht["currencySecret"] = " ";
653 ht["destId"] = destId.ToString(); 653 ht["destId"] = destId.ToString();
654 ht["cash"] = amount; 654 ht["cash"] = amount;
655 ht["aggregatePermInventory"] = aggregatePermInventory; 655 ht["aggregatePermInventory"] = aggregatePermInventory;
656 ht["aggregatePermNextOwner"] = aggregatePermNextOwner; 656 ht["aggregatePermNextOwner"] = aggregatePermNextOwner;
657 ht["flags"] = flags; 657 ht["flags"] = flags;
658 ht["transactionType"] = transactiontype; 658 ht["transactionType"] = transactiontype;
659 ht["description"] = description; 659 ht["description"] = description;
660 660
661 Hashtable hresult = genericCurrencyXMLRPCRequest(ht, "regionMoveMoney"); 661 Hashtable hresult = genericCurrencyXMLRPCRequest(ht, "regionMoveMoney");
662 662
663 if ((bool) hresult["success"] == true) 663 if ((bool) hresult["success"] == true)
664 { 664 {
665 int funds1 = 0; 665 int funds1 = 0;
666 int funds2 = 0; 666 int funds2 = 0;
667 try 667 try
668 { 668 {
669 funds1 = (Int32) hresult["funds"]; 669 funds1 = (Int32) hresult["funds"];
670 } 670 }
671 catch (InvalidCastException) 671 catch (InvalidCastException)
672 { 672 {
673 funds1 = 0; 673 funds1 = 0;
674 } 674 }
675 SetLocalFundsForAgentID(sourceId, funds1); 675 SetLocalFundsForAgentID(sourceId, funds1);
676 if (m_KnownClientFunds.ContainsKey(destId)) 676 if (m_KnownClientFunds.ContainsKey(destId))
677 { 677 {
678 try 678 try
679 { 679 {
680 funds2 = (Int32) hresult["funds2"]; 680 funds2 = (Int32) hresult["funds2"];
681 } 681 }
682 catch (InvalidCastException) 682 catch (InvalidCastException)
683 { 683 {
684 funds2 = 0; 684 funds2 = 0;
685 } 685 }
686 SetLocalFundsForAgentID(destId, funds2); 686 SetLocalFundsForAgentID(destId, funds2);
687 } 687 }
688 688
689 689
690 rvalue = true; 690 rvalue = true;
691 } 691 }
692 else 692 else
693 { 693 {
694 cli.SendAgentAlertMessage((string) hresult["errorMessage"], true); 694 cli.SendAgentAlertMessage((string) hresult["errorMessage"], true);
695 } 695 }
696 } 696 }
697 } 697 }
698 else 698 else
699 { 699 {
700 m_log.ErrorFormat("[MONEY]: Client {0} not found", sourceId.ToString()); 700 m_log.ErrorFormat("[MONEY]: Client {0} not found", sourceId.ToString());
701 } 701 }
702 702
703 return rvalue; 703 return rvalue;
704 } 704 }
705 705
706 public int GetRemoteBalance(LLUUID agentId) 706 public int GetRemoteBalance(LLUUID agentId)
707 { 707 {
708 int funds = 0; 708 int funds = 0;
709 709
710 IClientAPI aClient = LocateClientObject(agentId); 710 IClientAPI aClient = LocateClientObject(agentId);
711 if (aClient != null) 711 if (aClient != null)
712 { 712 {
713 Scene s = LocateSceneClientIn(agentId); 713 Scene s = LocateSceneClientIn(agentId);
714 if (s != null) 714 if (s != null)
715 { 715 {
716 if (m_MoneyAddress.Length > 0) 716 if (m_MoneyAddress.Length > 0)
717 { 717 {
718 Hashtable hbinfo = 718 Hashtable hbinfo =
719 GetBalanceForUserFromMoneyServer(aClient.AgentId, aClient.SecureSessionId, s.RegionInfo.originRegionID.ToString(), 719 GetBalanceForUserFromMoneyServer(aClient.AgentId, aClient.SecureSessionId, s.RegionInfo.originRegionID.ToString(),
720 s.RegionInfo.regionSecret); 720 s.RegionInfo.regionSecret);
721 if ((bool) hbinfo["success"] == true) 721 if ((bool) hbinfo["success"] == true)
722 { 722 {
723 try 723 try
724 { 724 {
725 funds = (Int32) hbinfo["funds"]; 725 funds = (Int32) hbinfo["funds"];
726 } 726 }
727 catch (ArgumentException) 727 catch (ArgumentException)
728 { 728 {
729 } 729 }
730 catch (FormatException) 730 catch (FormatException)
731 { 731 {
732 } 732 }
733 catch (OverflowException) 733 catch (OverflowException)
734 { 734 {
735 m_log.ErrorFormat("[MONEY]: While getting the Currency for user {0}, the return funds overflowed.", agentId); 735 m_log.ErrorFormat("[MONEY]: While getting the Currency for user {0}, the return funds overflowed.", agentId);
736 aClient.SendAlertMessage("Unable to get your money balance, money operations will be unavailable"); 736 aClient.SendAlertMessage("Unable to get your money balance, money operations will be unavailable");
737 } 737 }
738 catch (InvalidCastException) 738 catch (InvalidCastException)
739 { 739 {
740 funds = 0; 740 funds = 0;
741 } 741 }
742 } 742 }
743 else 743 else
744 { 744 {
745 m_log.WarnFormat("[MONEY]: Getting Money for user {0} failed with the following message:{1}", agentId, 745 m_log.WarnFormat("[MONEY]: Getting Money for user {0} failed with the following message:{1}", agentId,
746 (string) hbinfo["errorMessage"]); 746 (string) hbinfo["errorMessage"]);
747 aClient.SendAlertMessage((string) hbinfo["errorMessage"]); 747 aClient.SendAlertMessage((string) hbinfo["errorMessage"]);
748 } 748 }
749 } 749 }
750 750
751 SetLocalFundsForAgentID(agentId, funds); 751 SetLocalFundsForAgentID(agentId, funds);
752 SendMoneyBalance(aClient, agentId, aClient.SessionId, LLUUID.Zero); 752 SendMoneyBalance(aClient, agentId, aClient.SessionId, LLUUID.Zero);
753 } 753 }
754 else 754 else
755 { 755 {
756 m_log.Debug("[MONEY]: Got balance request update for agent that is here, but couldn't find which scene."); 756 m_log.Debug("[MONEY]: Got balance request update for agent that is here, but couldn't find which scene.");
757 } 757 }
758 } 758 }
759 else 759 else
760 { 760 {
761 m_log.Debug("[MONEY]: Got balance request update for agent that isn't here."); 761 m_log.Debug("[MONEY]: Got balance request update for agent that isn't here.");
762 } 762 }
763 return funds; 763 return funds;
764 } 764 }
765 765
766 public XmlRpcResponse GridMoneyUpdate(XmlRpcRequest request) 766 public XmlRpcResponse GridMoneyUpdate(XmlRpcRequest request)
767 { 767 {
768 m_log.Debug("[MONEY]: Dynamic balance update called."); 768 m_log.Debug("[MONEY]: Dynamic balance update called.");
769 Hashtable requestData = (Hashtable) request.Params[0]; 769 Hashtable requestData = (Hashtable) request.Params[0];
770 770
771 if (requestData.ContainsKey("agentId")) 771 if (requestData.ContainsKey("agentId"))
772 { 772 {
773 LLUUID agentId = LLUUID.Zero; 773 LLUUID agentId = LLUUID.Zero;
774 774
775 Helpers.TryParse((string) requestData["agentId"], out agentId); 775 Helpers.TryParse((string) requestData["agentId"], out agentId);
776 if (agentId != LLUUID.Zero) 776 if (agentId != LLUUID.Zero)
777 { 777 {
778 GetRemoteBalance(agentId); 778 GetRemoteBalance(agentId);
779 } 779 }
780 else 780 else
781 { 781 {
782 m_log.Debug("[MONEY]: invalid agentId specified, dropping."); 782 m_log.Debug("[MONEY]: invalid agentId specified, dropping.");
783 } 783 }
784 } 784 }
785 else 785 else
786 { 786 {
787 m_log.Debug("[MONEY]: no agentId specified, dropping."); 787 m_log.Debug("[MONEY]: no agentId specified, dropping.");
788 } 788 }
789 XmlRpcResponse r = new XmlRpcResponse(); 789 XmlRpcResponse r = new XmlRpcResponse();
790 Hashtable rparms = new Hashtable(); 790 Hashtable rparms = new Hashtable();
791 rparms["success"] = true; 791 rparms["success"] = true;
792 792
793 r.Value = rparms; 793 r.Value = rparms;
794 return r; 794 return r;
795 } 795 }
796 796
797 /// <summary> 797 /// <summary>
798 /// XMLRPC handler to send alert message and sound to client 798 /// XMLRPC handler to send alert message and sound to client
799 /// </summary> 799 /// </summary>
800 public XmlRpcResponse UserAlert(XmlRpcRequest request) 800 public XmlRpcResponse UserAlert(XmlRpcRequest request)
801 { 801 {
802 XmlRpcResponse ret = new XmlRpcResponse(); 802 XmlRpcResponse ret = new XmlRpcResponse();
803 Hashtable retparam = new Hashtable(); 803 Hashtable retparam = new Hashtable();
804 Hashtable requestData = (Hashtable) request.Params[0]; 804 Hashtable requestData = (Hashtable) request.Params[0];
805 805
806 LLUUID agentId = LLUUID.Zero; 806 LLUUID agentId = LLUUID.Zero;
807 LLUUID soundId = LLUUID.Zero; 807 LLUUID soundId = LLUUID.Zero;
808 808
809 Helpers.TryParse((string) requestData["agentId"], out agentId); 809 Helpers.TryParse((string) requestData["agentId"], out agentId);
810 Helpers.TryParse((string) requestData["soundId"], out soundId); 810 Helpers.TryParse((string) requestData["soundId"], out soundId);
811 string text = (string) requestData["text"]; 811 string text = (string) requestData["text"];
812 string secret = (string) requestData["secret"]; 812 string secret = (string) requestData["secret"];
813 813
814 Scene userScene = GetRandomScene(); 814 Scene userScene = GetRandomScene();
815 if (userScene.RegionInfo.regionSecret.ToString() == secret) 815 if (userScene.RegionInfo.regionSecret.ToString() == secret)
816 { 816 {
817 IClientAPI client = LocateClientObject(agentId); 817 IClientAPI client = LocateClientObject(agentId);
818 818
819 if (client != null) 819 if (client != null)
820 { 820 {
821 if (soundId != LLUUID.Zero) 821 if (soundId != LLUUID.Zero)
822 client.SendPlayAttachedSound(soundId, LLUUID.Zero, LLUUID.Zero, 1.0f, 0); 822 client.SendPlayAttachedSound(soundId, LLUUID.Zero, LLUUID.Zero, 1.0f, 0);
823 client.SendBlueBoxMessage(LLUUID.Zero, LLUUID.Zero, "", text); 823 client.SendBlueBoxMessage(LLUUID.Zero, LLUUID.Zero, "", text);
824 retparam.Add("success", true); 824 retparam.Add("success", true);
825 } 825 }
826 else 826 else
827 { 827 {
828 retparam.Add("success", false); 828 retparam.Add("success", false);
829 } 829 }
830 } 830 }
831 else 831 else
832 { 832 {
833 retparam.Add("success", false); 833 retparam.Add("success", false);
834 } 834 }
835 ret.Value = retparam; 835 ret.Value = retparam;
836 836
837 return ret; 837 return ret;
838 } 838 }
839 839
840 # region Standalone box enablers only 840 # region Standalone box enablers only
841 841
842 public XmlRpcResponse quote_func(XmlRpcRequest request) 842 public XmlRpcResponse quote_func(XmlRpcRequest request)
843 { 843 {
844 Hashtable requestData = (Hashtable) request.Params[0]; 844 Hashtable requestData = (Hashtable) request.Params[0];
845 LLUUID agentId = LLUUID.Zero; 845 LLUUID agentId = LLUUID.Zero;
846 int amount = 0; 846 int amount = 0;
847 Hashtable quoteResponse = new Hashtable(); 847 Hashtable quoteResponse = new Hashtable();
848 XmlRpcResponse returnval = new XmlRpcResponse(); 848 XmlRpcResponse returnval = new XmlRpcResponse();
849 849
850 if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy")) 850 if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy"))
851 { 851 {
852 Helpers.TryParse((string) requestData["agentId"], out agentId); 852 Helpers.TryParse((string) requestData["agentId"], out agentId);
853 try 853 try
854 { 854 {
855 amount = (Int32) requestData["currencyBuy"]; 855 amount = (Int32) requestData["currencyBuy"];
856 } 856 }
857 catch (InvalidCastException) 857 catch (InvalidCastException)
858 { 858 {
859 } 859 }
860 Hashtable currencyResponse = new Hashtable(); 860 Hashtable currencyResponse = new Hashtable();
861 currencyResponse.Add("estimatedCost", 0); 861 currencyResponse.Add("estimatedCost", 0);
862 currencyResponse.Add("currencyBuy", amount); 862 currencyResponse.Add("currencyBuy", amount);
863 863
864 quoteResponse.Add("success", true); 864 quoteResponse.Add("success", true);
865 quoteResponse.Add("currency", currencyResponse); 865 quoteResponse.Add("currency", currencyResponse);
866 quoteResponse.Add("confirm", "asdfad9fj39ma9fj"); 866 quoteResponse.Add("confirm", "asdfad9fj39ma9fj");
867 867
868 returnval.Value = quoteResponse; 868 returnval.Value = quoteResponse;
869 return returnval; 869 return returnval;
870 } 870 }
871 871
872 872
873 quoteResponse.Add("success", false); 873 quoteResponse.Add("success", false);
874 quoteResponse.Add("errorMessage", "Invalid parameters passed to the quote box"); 874 quoteResponse.Add("errorMessage", "Invalid parameters passed to the quote box");
875 quoteResponse.Add("errorURI", "http://www.opensimulator.org/wiki"); 875 quoteResponse.Add("errorURI", "http://www.opensimulator.org/wiki");
876 returnval.Value = quoteResponse; 876 returnval.Value = quoteResponse;
877 return returnval; 877 return returnval;
878 } 878 }
879 879
880 public XmlRpcResponse buy_func(XmlRpcRequest request) 880 public XmlRpcResponse buy_func(XmlRpcRequest request)
881 { 881 {
882 Hashtable requestData = (Hashtable) request.Params[0]; 882 Hashtable requestData = (Hashtable) request.Params[0];
883 LLUUID agentId = LLUUID.Zero; 883 LLUUID agentId = LLUUID.Zero;
884 int amount = 0; 884 int amount = 0;
885 if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy")) 885 if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy"))
886 { 886 {
887 Helpers.TryParse((string) requestData["agentId"], out agentId); 887 Helpers.TryParse((string) requestData["agentId"], out agentId);
888 try 888 try
889 { 889 {
890 amount = (Int32) requestData["currencyBuy"]; 890 amount = (Int32) requestData["currencyBuy"];
891 } 891 }
892 catch (InvalidCastException) 892 catch (InvalidCastException)
893 { 893 {
894 } 894 }
895 if (agentId != LLUUID.Zero) 895 if (agentId != LLUUID.Zero)
896 { 896 {
897 lock (m_KnownClientFunds) 897 lock (m_KnownClientFunds)
898 { 898 {
899 if (m_KnownClientFunds.ContainsKey(agentId)) 899 if (m_KnownClientFunds.ContainsKey(agentId))
900 { 900 {
901 m_KnownClientFunds[agentId] += amount; 901 m_KnownClientFunds[agentId] += amount;
902 } 902 }
903 else 903 else
904 { 904 {
905 m_KnownClientFunds.Add(agentId, amount); 905 m_KnownClientFunds.Add(agentId, amount);
906 } 906 }
907 } 907 }
908 IClientAPI client = LocateClientObject(agentId); 908 IClientAPI client = LocateClientObject(agentId);
909 if (client != null) 909 if (client != null)
910 { 910 {
911 SendMoneyBalance(client, agentId, client.SessionId, LLUUID.Zero); 911 SendMoneyBalance(client, agentId, client.SessionId, LLUUID.Zero);
912 } 912 }
913 } 913 }
914 } 914 }
915 XmlRpcResponse returnval = new XmlRpcResponse(); 915 XmlRpcResponse returnval = new XmlRpcResponse();
916 Hashtable returnresp = new Hashtable(); 916 Hashtable returnresp = new Hashtable();
917 returnresp.Add("success", true); 917 returnresp.Add("success", true);
918 returnval.Value = returnresp; 918 returnval.Value = returnresp;
919 return returnval; 919 return returnval;
920 } 920 }
921 921
922 public XmlRpcResponse preflightBuyLandPrep_func(XmlRpcRequest request) 922 public XmlRpcResponse preflightBuyLandPrep_func(XmlRpcRequest request)
923 { 923 {
924 XmlRpcResponse ret = new XmlRpcResponse(); 924 XmlRpcResponse ret = new XmlRpcResponse();
925 Hashtable retparam = new Hashtable(); 925 Hashtable retparam = new Hashtable();
926 Hashtable membershiplevels = new Hashtable(); 926 Hashtable membershiplevels = new Hashtable();
927 ArrayList levels = new ArrayList(); 927 ArrayList levels = new ArrayList();
928 Hashtable level = new Hashtable(); 928 Hashtable level = new Hashtable();
929 level.Add("id", "00000000-0000-0000-0000-000000000000"); 929 level.Add("id", "00000000-0000-0000-0000-000000000000");
930 level.Add("description", "some level"); 930 level.Add("description", "some level");
931 levels.Add(level); 931 levels.Add(level);
932 //membershiplevels.Add("levels",levels); 932 //membershiplevels.Add("levels",levels);
933 933
934 Hashtable landuse = new Hashtable(); 934 Hashtable landuse = new Hashtable();
935 landuse.Add("upgrade", false); 935 landuse.Add("upgrade", false);
936 landuse.Add("action", "http://invaliddomaininvalid.com/"); 936 landuse.Add("action", "http://invaliddomaininvalid.com/");
937 937
938 Hashtable currency = new Hashtable(); 938 Hashtable currency = new Hashtable();
939 currency.Add("estimatedCost", 0); 939 currency.Add("estimatedCost", 0);
940 940
941 Hashtable membership = new Hashtable(); 941 Hashtable membership = new Hashtable();
942 membershiplevels.Add("upgrade", false); 942 membershiplevels.Add("upgrade", false);
943 membershiplevels.Add("action", "http://invaliddomaininvalid.com/"); 943 membershiplevels.Add("action", "http://invaliddomaininvalid.com/");
944 membershiplevels.Add("levels", membershiplevels); 944 membershiplevels.Add("levels", membershiplevels);
945 945
946 retparam.Add("success", true); 946 retparam.Add("success", true);
947 retparam.Add("currency", currency); 947 retparam.Add("currency", currency);
948 retparam.Add("membership", membership); 948 retparam.Add("membership", membership);
949 retparam.Add("landuse", landuse); 949 retparam.Add("landuse", landuse);
950 retparam.Add("confirm", "asdfajsdkfjasdkfjalsdfjasdf"); 950 retparam.Add("confirm", "asdfajsdkfjasdkfjalsdfjasdf");
951 951
952 ret.Value = retparam; 952 ret.Value = retparam;
953 953
954 return ret; 954 return ret;
955 } 955 }
956 956
957 public XmlRpcResponse landBuy_func(XmlRpcRequest request) 957 public XmlRpcResponse landBuy_func(XmlRpcRequest request)
958 { 958 {
959 XmlRpcResponse ret = new XmlRpcResponse(); 959 XmlRpcResponse ret = new XmlRpcResponse();
960 Hashtable retparam = new Hashtable(); 960 Hashtable retparam = new Hashtable();
961 Hashtable requestData = (Hashtable) request.Params[0]; 961 Hashtable requestData = (Hashtable) request.Params[0];
962 962
963 LLUUID agentId = LLUUID.Zero; 963 LLUUID agentId = LLUUID.Zero;
964 int amount = 0; 964 int amount = 0;
965 if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy")) 965 if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy"))
966 { 966 {
967 Helpers.TryParse((string) requestData["agentId"], out agentId); 967 Helpers.TryParse((string) requestData["agentId"], out agentId);
968 try 968 try
969 { 969 {
970 amount = (Int32) requestData["currencyBuy"]; 970 amount = (Int32) requestData["currencyBuy"];
971 } 971 }
972 catch (InvalidCastException) 972 catch (InvalidCastException)
973 { 973 {
974 } 974 }
975 if (agentId != LLUUID.Zero) 975 if (agentId != LLUUID.Zero)
976 { 976 {
977 lock (m_KnownClientFunds) 977 lock (m_KnownClientFunds)
978 { 978 {
979 if (m_KnownClientFunds.ContainsKey(agentId)) 979 if (m_KnownClientFunds.ContainsKey(agentId))
980 { 980 {
981 m_KnownClientFunds[agentId] += amount; 981 m_KnownClientFunds[agentId] += amount;
982 } 982 }
983 else 983 else
984 { 984 {
985 m_KnownClientFunds.Add(agentId, amount); 985 m_KnownClientFunds.Add(agentId, amount);
986 } 986 }
987 } 987 }
988 IClientAPI client = LocateClientObject(agentId); 988 IClientAPI client = LocateClientObject(agentId);
989 if (client != null) 989 if (client != null)
990 { 990 {
991 SendMoneyBalance(client, agentId, client.SessionId, LLUUID.Zero); 991 SendMoneyBalance(client, agentId, client.SessionId, LLUUID.Zero);
992 } 992 }
993 } 993 }
994 } 994 }
995 retparam.Add("success", true); 995 retparam.Add("success", true);
996 ret.Value = retparam; 996 ret.Value = retparam;
997 997
998 return ret; 998 return ret;
999 } 999 }
1000 1000
1001 #endregion 1001 #endregion
1002 1002
1003 #region local Fund Management 1003 #region local Fund Management
1004 1004
1005 /// <summary> 1005 /// <summary>
1006 /// Ensures that the agent accounting data is set up in this instance. 1006 /// Ensures that the agent accounting data is set up in this instance.
1007 /// </summary> 1007 /// </summary>
1008 /// <param name="agentID"></param> 1008 /// <param name="agentID"></param>
1009 private void CheckExistAndRefreshFunds(LLUUID agentID) 1009 private void CheckExistAndRefreshFunds(LLUUID agentID)
1010 { 1010 {
1011 lock (m_KnownClientFunds) 1011 lock (m_KnownClientFunds)
1012 { 1012 {
1013 if (!m_KnownClientFunds.ContainsKey(agentID)) 1013 if (!m_KnownClientFunds.ContainsKey(agentID))
1014 { 1014 {
1015 m_KnownClientFunds.Add(agentID, m_stipend); 1015 m_KnownClientFunds.Add(agentID, m_stipend);
1016 } 1016 }
1017 else 1017 else
1018 { 1018 {
1019 if (m_KnownClientFunds[agentID] <= m_minFundsBeforeRefresh) 1019 if (m_KnownClientFunds[agentID] <= m_minFundsBeforeRefresh)
1020 { 1020 {
1021 m_KnownClientFunds[agentID] = m_stipend; 1021 m_KnownClientFunds[agentID] = m_stipend;
1022 } 1022 }
1023 } 1023 }
1024 } 1024 }
1025 } 1025 }
1026 1026
1027 /// <summary> 1027 /// <summary>
1028 /// Gets the amount of Funds for an agent 1028 /// Gets the amount of Funds for an agent
1029 /// </summary> 1029 /// </summary>
1030 /// <param name="AgentID"></param> 1030 /// <param name="AgentID"></param>
1031 /// <returns></returns> 1031 /// <returns></returns>
1032 private int GetFundsForAgentID(LLUUID AgentID) 1032 private int GetFundsForAgentID(LLUUID AgentID)
1033 { 1033 {
1034 int returnfunds = 0; 1034 int returnfunds = 0;
1035 lock (m_KnownClientFunds) 1035 lock (m_KnownClientFunds)
1036 { 1036 {
1037 if (m_KnownClientFunds.ContainsKey(AgentID)) 1037 if (m_KnownClientFunds.ContainsKey(AgentID))
1038 { 1038 {
1039 returnfunds = m_KnownClientFunds[AgentID]; 1039 returnfunds = m_KnownClientFunds[AgentID];
1040 } 1040 }
1041 else 1041 else
1042 { 1042 {
1043 //throw new Exception("Unable to get funds."); 1043 //throw new Exception("Unable to get funds.");
1044 } 1044 }
1045 } 1045 }
1046 return returnfunds; 1046 return returnfunds;
1047 } 1047 }
1048 1048
1049 private void SetLocalFundsForAgentID(LLUUID AgentID, int amount) 1049 private void SetLocalFundsForAgentID(LLUUID AgentID, int amount)
1050 { 1050 {
1051 lock (m_KnownClientFunds) 1051 lock (m_KnownClientFunds)
1052 { 1052 {
1053 if (m_KnownClientFunds.ContainsKey(AgentID)) 1053 if (m_KnownClientFunds.ContainsKey(AgentID))
1054 { 1054 {
1055 m_KnownClientFunds[AgentID] = amount; 1055 m_KnownClientFunds[AgentID] = amount;
1056 } 1056 }
1057 else 1057 else
1058 { 1058 {
1059 m_KnownClientFunds.Add(AgentID, amount); 1059 m_KnownClientFunds.Add(AgentID, amount);
1060 } 1060 }
1061 } 1061 }
1062 } 1062 }
1063 1063
1064 #endregion 1064 #endregion
1065 1065
1066 #region Utility Helpers 1066 #region Utility Helpers
1067 1067
1068 /// <summary> 1068 /// <summary>
1069 /// Locates a IClientAPI for the client specified 1069 /// Locates a IClientAPI for the client specified
1070 /// </summary> 1070 /// </summary>
1071 /// <param name="AgentID"></param> 1071 /// <param name="AgentID"></param>
1072 /// <returns></returns> 1072 /// <returns></returns>
1073 private IClientAPI LocateClientObject(LLUUID AgentID) 1073 private IClientAPI LocateClientObject(LLUUID AgentID)
1074 { 1074 {
1075 ScenePresence tPresence = null; 1075 ScenePresence tPresence = null;
1076 IClientAPI rclient = null; 1076 IClientAPI rclient = null;
1077 1077
1078 lock (m_scenel) 1078 lock (m_scenel)
1079 { 1079 {
1080 foreach (Scene _scene in m_scenel.Values) 1080 foreach (Scene _scene in m_scenel.Values)
1081 { 1081 {
1082 tPresence = _scene.GetScenePresence(AgentID); 1082 tPresence = _scene.GetScenePresence(AgentID);
1083 if (tPresence != null) 1083 if (tPresence != null)
1084 { 1084 {
1085 if (!tPresence.IsChildAgent) 1085 if (!tPresence.IsChildAgent)
1086 { 1086 {
1087 rclient = tPresence.ControllingClient; 1087 rclient = tPresence.ControllingClient;
1088 } 1088 }
1089 } 1089 }
1090 if (rclient != null) 1090 if (rclient != null)
1091 { 1091 {
1092 return rclient; 1092 return rclient;
1093 } 1093 }
1094 } 1094 }
1095 } 1095 }
1096 return null; 1096 return null;
1097 } 1097 }
1098 1098
1099 private Scene LocateSceneClientIn(LLUUID AgentId) 1099 private Scene LocateSceneClientIn(LLUUID AgentId)
1100 { 1100 {
1101 lock (m_scenel) 1101 lock (m_scenel)
1102 { 1102 {
1103 foreach (Scene _scene in m_scenel.Values) 1103 foreach (Scene _scene in m_scenel.Values)
1104 { 1104 {
1105 ScenePresence tPresence = _scene.GetScenePresence(AgentId); 1105 ScenePresence tPresence = _scene.GetScenePresence(AgentId);
1106 if (tPresence != null) 1106 if (tPresence != null)
1107 { 1107 {
1108 if (!tPresence.IsChildAgent) 1108 if (!tPresence.IsChildAgent)
1109 { 1109 {
1110 return _scene; 1110 return _scene;
1111 } 1111 }
1112 } 1112 }
1113 } 1113 }
1114 } 1114 }
1115 return null; 1115 return null;
1116 } 1116 }
1117 1117
1118 /// <summary> 1118 /// <summary>
1119 /// Utility function Gets a Random scene in the instance. For when which scene exactly you're doing something with doesn't matter 1119 /// Utility function Gets a Random scene in the instance. For when which scene exactly you're doing something with doesn't matter
1120 /// </summary> 1120 /// </summary>
1121 /// <returns></returns> 1121 /// <returns></returns>
1122 public Scene GetRandomScene() 1122 public Scene GetRandomScene()
1123 { 1123 {
1124 lock (m_scenel) 1124 lock (m_scenel)
1125 { 1125 {
1126 foreach (Scene rs in m_scenel.Values) 1126 foreach (Scene rs in m_scenel.Values)
1127 return rs; 1127 return rs;
1128 } 1128 }
1129 return null; 1129 return null;
1130 } 1130 }
1131 1131
1132 /// <summary> 1132 /// <summary>
1133 /// Utility function to get a Scene by RegionID in a module 1133 /// Utility function to get a Scene by RegionID in a module
1134 /// </summary> 1134 /// </summary>
1135 /// <param name="RegionID"></param> 1135 /// <param name="RegionID"></param>
1136 /// <returns></returns> 1136 /// <returns></returns>
1137 public Scene GetSceneByUUID(LLUUID RegionID) 1137 public Scene GetSceneByUUID(LLUUID RegionID)
1138 { 1138 {
1139 lock (m_scenel) 1139 lock (m_scenel)
1140 { 1140 {
1141 foreach (Scene rs in m_scenel.Values) 1141 foreach (Scene rs in m_scenel.Values)
1142 { 1142 {
1143 if (rs.RegionInfo.originRegionID == RegionID) 1143 if (rs.RegionInfo.originRegionID == RegionID)
1144 { 1144 {
1145 return rs; 1145 return rs;
1146 } 1146 }
1147 } 1147 }
1148 } 1148 }
1149 return null; 1149 return null;
1150 } 1150 }
1151 1151
1152 #endregion 1152 #endregion
1153 1153
1154 #region event Handlers 1154 #region event Handlers
1155 1155
1156 public void requestPayPrice(IClientAPI client, LLUUID objectID) 1156 public void requestPayPrice(IClientAPI client, LLUUID objectID)
1157 { 1157 {
1158 Scene scene = LocateSceneClientIn(client.AgentId); 1158 Scene scene = LocateSceneClientIn(client.AgentId);
1159 if (scene == null) 1159 if (scene == null)
1160 return; 1160 return;
1161 1161
1162 SceneObjectPart task = scene.GetSceneObjectPart(objectID); 1162 SceneObjectPart task = scene.GetSceneObjectPart(objectID);
1163 if (task == null) 1163 if (task == null)
1164 return; 1164 return;
1165 SceneObjectGroup group = task.ParentGroup; 1165 SceneObjectGroup group = task.ParentGroup;
1166 SceneObjectPart root = group.RootPart; 1166 SceneObjectPart root = group.RootPart;
1167 1167
1168 client.SendPayPrice(objectID, root.PayPrice); 1168 client.SendPayPrice(objectID, root.PayPrice);
1169 } 1169 }
1170 1170
1171 /// <summary> 1171 /// <summary>
1172 /// When the client closes the connection we remove their accounting info from memory to free up resources. 1172 /// When the client closes the connection we remove their accounting info from memory to free up resources.
1173 /// </summary> 1173 /// </summary>
1174 /// <param name="AgentID"></param> 1174 /// <param name="AgentID"></param>
1175 public void ClientClosed(LLUUID AgentID) 1175 public void ClientClosed(LLUUID AgentID)
1176 { 1176 {
1177 lock (m_KnownClientFunds) 1177 lock (m_KnownClientFunds)
1178 { 1178 {
1179 if (m_keepMoneyAcrossLogins && m_MoneyAddress.Length == 0) 1179 if (m_keepMoneyAcrossLogins && m_MoneyAddress.Length == 0)
1180 { 1180 {
1181 } 1181 }
1182 else 1182 else
1183 { 1183 {
1184 m_KnownClientFunds.Remove(AgentID); 1184 m_KnownClientFunds.Remove(AgentID);
1185 } 1185 }
1186 } 1186 }
1187 } 1187 }
1188 1188
1189 /// <summary> 1189 /// <summary>
1190 /// Event called Economy Data Request handler. 1190 /// Event called Economy Data Request handler.
1191 /// </summary> 1191 /// </summary>
1192 /// <param name="agentId"></param> 1192 /// <param name="agentId"></param>
1193 public void EconomyDataRequestHandler(LLUUID agentId) 1193 public void EconomyDataRequestHandler(LLUUID agentId)
1194 { 1194 {
1195 IClientAPI user = LocateClientObject(agentId); 1195 IClientAPI user = LocateClientObject(agentId);
1196 1196
1197 if (user != null) 1197 if (user != null)
1198 { 1198 {
1199 user.SendEconomyData(EnergyEfficiency, ObjectCapacity, ObjectCount, PriceEnergyUnit, PriceGroupCreate, 1199 user.SendEconomyData(EnergyEfficiency, ObjectCapacity, ObjectCount, PriceEnergyUnit, PriceGroupCreate,
1200 PriceObjectClaim, PriceObjectRent, PriceObjectScaleFactor, PriceParcelClaim, PriceParcelClaimFactor, 1200 PriceObjectClaim, PriceObjectRent, PriceObjectScaleFactor, PriceParcelClaim, PriceParcelClaimFactor,
1201 PriceParcelRent, PricePublicObjectDecay, PricePublicObjectDelete, PriceRentLight, PriceUpload, 1201 PriceParcelRent, PricePublicObjectDecay, PricePublicObjectDelete, PriceRentLight, PriceUpload,
1202 TeleportMinPrice, TeleportPriceExponent); 1202 TeleportMinPrice, TeleportPriceExponent);
1203 } 1203 }
1204 } 1204 }
1205 1205
1206 private void ValidateLandBuy(Object osender, EventManager.LandBuyArgs e) 1206 private void ValidateLandBuy(Object osender, EventManager.LandBuyArgs e)
1207 { 1207 {
1208 if (m_MoneyAddress.Length == 0) 1208 if (m_MoneyAddress.Length == 0)
1209 { 1209 {
1210 lock (m_KnownClientFunds) 1210 lock (m_KnownClientFunds)
1211 { 1211 {
1212 if (m_KnownClientFunds.ContainsKey(e.agentId)) 1212 if (m_KnownClientFunds.ContainsKey(e.agentId))
1213 { 1213 {
1214 // Does the sender have enough funds to give? 1214 // Does the sender have enough funds to give?
1215 if (m_KnownClientFunds[e.agentId] >= e.parcelPrice) 1215 if (m_KnownClientFunds[e.agentId] >= e.parcelPrice)
1216 { 1216 {
1217 lock (e) 1217 lock (e)
1218 { 1218 {
1219 e.economyValidated = true; 1219 e.economyValidated = true;
1220 } 1220 }
1221 } 1221 }
1222 } 1222 }
1223 } 1223 }
1224 } 1224 }
1225 else 1225 else
1226 { 1226 {
1227 if (GetRemoteBalance(e.agentId) >= e.parcelPrice) 1227 if (GetRemoteBalance(e.agentId) >= e.parcelPrice)
1228 { 1228 {
1229 lock (e) 1229 lock (e)
1230 { 1230 {
1231 e.economyValidated = true; 1231 e.economyValidated = true;
1232 } 1232 }
1233 } 1233 }
1234 } 1234 }
1235 } 1235 }
1236 1236
1237 private void processLandBuy(Object osender, EventManager.LandBuyArgs e) 1237 private void processLandBuy(Object osender, EventManager.LandBuyArgs e)
1238 { 1238 {
1239 lock (e) 1239 lock (e)
1240 { 1240 {
1241 if (e.economyValidated == true && e.transactionID == 0) 1241 if (e.economyValidated == true && e.transactionID == 0)
1242 { 1242 {
1243 e.transactionID = Util.UnixTimeSinceEpoch(); 1243 e.transactionID = Util.UnixTimeSinceEpoch();
1244 1244
1245 if (doMoneyTransfer(e.agentId, e.parcelOwnerID, e.parcelPrice, 0, "Land purchase")) 1245 if (doMoneyTransfer(e.agentId, e.parcelOwnerID, e.parcelPrice, 0, "Land purchase"))
1246 { 1246 {
1247 lock (e) 1247 lock (e)
1248 { 1248 {
1249 e.amountDebited = e.parcelPrice; 1249 e.amountDebited = e.parcelPrice;
1250 } 1250 }
1251 } 1251 }
1252 } 1252 }
1253 } 1253 }
1254 } 1254 }
1255 1255
1256 /// <summary> 1256 /// <summary>
1257 /// THis method gets called when someone pays someone else as a gift. 1257 /// THis method gets called when someone pays someone else as a gift.
1258 /// </summary> 1258 /// </summary>
1259 /// <param name="osender"></param> 1259 /// <param name="osender"></param>
1260 /// <param name="e"></param> 1260 /// <param name="e"></param>
1261 private void MoneyTransferAction(Object osender, EventManager.MoneyTransferArgs e) 1261 private void MoneyTransferAction(Object osender, EventManager.MoneyTransferArgs e)
1262 { 1262 {
1263 IClientAPI sender = null; 1263 IClientAPI sender = null;
1264 IClientAPI receiver = null; 1264 IClientAPI receiver = null;
1265 1265
1266 if (m_MoneyAddress.Length > 0) // Handled on server 1266 if (m_MoneyAddress.Length > 0) // Handled on server
1267 e.description = String.Empty; 1267 e.description = String.Empty;
1268 1268
1269 if (e.transactiontype == 5008) // Object gets paid 1269 if (e.transactiontype == 5008) // Object gets paid
1270 { 1270 {
1271 sender = LocateClientObject(e.sender); 1271 sender = LocateClientObject(e.sender);
1272 if (sender != null) 1272 if (sender != null)
1273 { 1273 {
1274 SceneObjectPart part = findPrim(e.receiver); 1274 SceneObjectPart part = findPrim(e.receiver);
1275 if (part == null) 1275 if (part == null)
1276 return; 1276 return;
1277 1277
1278 string name = resolveAgentName(part.OwnerID); 1278 string name = resolveAgentName(part.OwnerID);
1279 if (name == String.Empty) 1279 if (name == String.Empty)
1280 name = "(hippos)"; 1280 name = "(hippos)";
1281 1281
1282 receiver = LocateClientObject(part.OwnerID); 1282 receiver = LocateClientObject(part.OwnerID);
1283 1283
1284 string description = String.Format("Paid {0} via object {1}", name, e.description); 1284 string description = String.Format("Paid {0} via object {1}", name, e.description);
1285 bool transactionresult = doMoneyTransfer(e.sender, part.OwnerID, e.amount, e.transactiontype, description); 1285 bool transactionresult = doMoneyTransfer(e.sender, part.OwnerID, e.amount, e.transactiontype, description);
1286 1286
1287 if (transactionresult) 1287 if (transactionresult)
1288 { 1288 {
1289 ObjectPaid handlerOnObjectPaid = OnObjectPaid; 1289 ObjectPaid handlerOnObjectPaid = OnObjectPaid;
1290 if (handlerOnObjectPaid != null) 1290 if (handlerOnObjectPaid != null)
1291 { 1291 {
1292 handlerOnObjectPaid(e.receiver, e.sender, e.amount); 1292 handlerOnObjectPaid(e.receiver, e.sender, e.amount);
1293 } 1293 }
1294 } 1294 }
1295 1295
1296 if (e.sender != e.receiver) 1296 if (e.sender != e.receiver)
1297 { 1297 {
1298 sender.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.sender)); 1298 sender.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.sender));
1299 } 1299 }
1300 if (receiver != null) 1300 if (receiver != null)
1301 { 1301 {
1302 receiver.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(part.OwnerID)); 1302 receiver.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(part.OwnerID));
1303 } 1303 }
1304 } 1304 }
1305 return; 1305 return;
1306 } 1306 }
1307 1307
1308 sender = LocateClientObject(e.sender); 1308 sender = LocateClientObject(e.sender);
1309 if (sender != null) 1309 if (sender != null)
1310 { 1310 {
1311 receiver = LocateClientObject(e.receiver); 1311 receiver = LocateClientObject(e.receiver);
1312 1312
1313 bool transactionresult = doMoneyTransfer(e.sender, e.receiver, e.amount, e.transactiontype, e.description); 1313 bool transactionresult = doMoneyTransfer(e.sender, e.receiver, e.amount, e.transactiontype, e.description);
1314 1314
1315 if (e.sender != e.receiver) 1315 if (e.sender != e.receiver)
1316 { 1316 {
1317 if (sender != null) 1317 if (sender != null)
1318 { 1318 {
1319 sender.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.sender)); 1319 sender.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.sender));
1320 } 1320 }
1321 } 1321 }
1322 1322
1323 if (receiver != null) 1323 if (receiver != null)
1324 { 1324 {
1325 receiver.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.receiver)); 1325 receiver.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.receiver));
1326 } 1326 }
1327 } 1327 }
1328 else 1328 else
1329 { 1329 {
1330 m_log.Warn("[MONEY]: Potential Fraud Warning, got money transfer request for avatar that isn't in this simulator - Details; Sender:" + 1330 m_log.Warn("[MONEY]: Potential Fraud Warning, got money transfer request for avatar that isn't in this simulator - Details; Sender:" +
1331 e.sender.ToString() + " Receiver: " + e.receiver.ToString() + " Amount: " + e.amount.ToString()); 1331 e.sender.ToString() + " Receiver: " + e.receiver.ToString() + " Amount: " + e.amount.ToString());
1332 } 1332 }
1333 } 1333 }
1334 1334
1335 /// <summary> 1335 /// <summary>
1336 /// Event Handler for when a root agent becomes a child agent 1336 /// Event Handler for when a root agent becomes a child agent
1337 /// </summary> 1337 /// </summary>
1338 /// <param name="avatar"></param> 1338 /// <param name="avatar"></param>
1339 private void MakeChildAgent(ScenePresence avatar) 1339 private void MakeChildAgent(ScenePresence avatar)
1340 { 1340 {
1341 lock (m_rootAgents) 1341 lock (m_rootAgents)
1342 { 1342 {
1343 if (m_rootAgents.ContainsKey(avatar.UUID)) 1343 if (m_rootAgents.ContainsKey(avatar.UUID))
1344 { 1344 {
1345 if (m_rootAgents[avatar.UUID] == avatar.Scene.RegionInfo.originRegionID) 1345 if (m_rootAgents[avatar.UUID] == avatar.Scene.RegionInfo.originRegionID)
1346 { 1346 {
1347 m_rootAgents.Remove(avatar.UUID); 1347 m_rootAgents.Remove(avatar.UUID);
1348 m_log.Info("[MONEY]: Removing " + avatar.Firstname + " " + avatar.Lastname + " as a root agent"); 1348 m_log.Info("[MONEY]: Removing " + avatar.Firstname + " " + avatar.Lastname + " as a root agent");
1349 } 1349 }
1350 } 1350 }
1351 } 1351 }
1352 } 1352 }
1353 1353
1354 /// <summary> 1354 /// <summary>
1355 /// Event Handler for when the client logs out. 1355 /// Event Handler for when the client logs out.
1356 /// </summary> 1356 /// </summary>
1357 /// <param name="AgentId"></param> 1357 /// <param name="AgentId"></param>
1358 private void ClientLoggedOut(LLUUID AgentId) 1358 private void ClientLoggedOut(LLUUID AgentId)
1359 { 1359 {
1360 lock (m_rootAgents) 1360 lock (m_rootAgents)
1361 { 1361 {
1362 if (m_rootAgents.ContainsKey(AgentId)) 1362 if (m_rootAgents.ContainsKey(AgentId))
1363 { 1363 {
1364 m_rootAgents.Remove(AgentId); 1364 m_rootAgents.Remove(AgentId);
1365 //m_log.Info("[MONEY]: Removing " + AgentId + ". Agent logged out."); 1365 //m_log.Info("[MONEY]: Removing " + AgentId + ". Agent logged out.");
1366 } 1366 }
1367 } 1367 }
1368 } 1368 }
1369 1369
1370 /// <summary> 1370 /// <summary>
1371 /// Call this when the client disconnects. 1371 /// Call this when the client disconnects.
1372 /// </summary> 1372 /// </summary>
1373 /// <param name="client"></param> 1373 /// <param name="client"></param>
1374 public void ClientClosed(IClientAPI client) 1374 public void ClientClosed(IClientAPI client)
1375 { 1375 {
1376 ClientClosed(client.AgentId); 1376 ClientClosed(client.AgentId);
1377 } 1377 }
1378 1378
1379 /// <summary> 1379 /// <summary>
1380 /// Event Handler for when an Avatar enters one of the parcels in the simulator. 1380 /// Event Handler for when an Avatar enters one of the parcels in the simulator.
1381 /// </summary> 1381 /// </summary>
1382 /// <param name="avatar"></param> 1382 /// <param name="avatar"></param>
1383 /// <param name="localLandID"></param> 1383 /// <param name="localLandID"></param>
1384 /// <param name="regionID"></param> 1384 /// <param name="regionID"></param>
1385 private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, LLUUID regionID) 1385 private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, LLUUID regionID)
1386 { 1386 {
1387 lock (m_rootAgents) 1387 lock (m_rootAgents)
1388 { 1388 {
1389 if (m_rootAgents.ContainsKey(avatar.UUID)) 1389 if (m_rootAgents.ContainsKey(avatar.UUID))
1390 { 1390 {
1391 if (avatar.Scene.RegionInfo.originRegionID != m_rootAgents[avatar.UUID]) 1391 if (avatar.Scene.RegionInfo.originRegionID != m_rootAgents[avatar.UUID])
1392 { 1392 {
1393 m_rootAgents[avatar.UUID] = avatar.Scene.RegionInfo.originRegionID; 1393 m_rootAgents[avatar.UUID] = avatar.Scene.RegionInfo.originRegionID;
1394 //m_log.Info("[MONEY]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + "."); 1394 //m_log.Info("[MONEY]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + ".");
1395 // Claim User! my user! Mine mine mine! 1395 // Claim User! my user! Mine mine mine!
1396 if (m_MoneyAddress.Length > 0) 1396 if (m_MoneyAddress.Length > 0)
1397 { 1397 {
1398 Scene RegionItem = GetSceneByUUID(regionID); 1398 Scene RegionItem = GetSceneByUUID(regionID);
1399 if (RegionItem != null) 1399 if (RegionItem != null)
1400 { 1400 {
1401 Hashtable hresult = 1401 Hashtable hresult =
1402 claim_user(avatar.UUID, avatar.ControllingClient.SecureSessionId, regionID, RegionItem.RegionInfo.regionSecret); 1402 claim_user(avatar.UUID, avatar.ControllingClient.SecureSessionId, regionID, RegionItem.RegionInfo.regionSecret);
1403 if ((bool) hresult["success"] == true) 1403 if ((bool) hresult["success"] == true)
1404 { 1404 {
1405 int funds = 0; 1405 int funds = 0;
1406 try 1406 try
1407 { 1407 {
1408 funds = (Int32) hresult["funds"]; 1408 funds = (Int32) hresult["funds"];
1409 } 1409 }
1410 catch (InvalidCastException) 1410 catch (InvalidCastException)
1411 { 1411 {
1412 } 1412 }
1413 SetLocalFundsForAgentID(avatar.UUID, funds); 1413 SetLocalFundsForAgentID(avatar.UUID, funds);
1414 } 1414 }
1415 else 1415 else
1416 { 1416 {
1417 avatar.ControllingClient.SendAgentAlertMessage((string) hresult["errorMessage"], true); 1417 avatar.ControllingClient.SendAgentAlertMessage((string) hresult["errorMessage"], true);
1418 } 1418 }
1419 } 1419 }
1420 } 1420 }
1421 } 1421 }
1422 } 1422 }
1423 else 1423 else
1424 { 1424 {
1425 lock (m_rootAgents) 1425 lock (m_rootAgents)
1426 { 1426 {
1427 m_rootAgents.Add(avatar.UUID, avatar.Scene.RegionInfo.originRegionID); 1427 m_rootAgents.Add(avatar.UUID, avatar.Scene.RegionInfo.originRegionID);
1428 } 1428 }
1429 if (m_MoneyAddress.Length > 0) 1429 if (m_MoneyAddress.Length > 0)
1430 { 1430 {
1431 Scene RegionItem = GetSceneByUUID(regionID); 1431 Scene RegionItem = GetSceneByUUID(regionID);
1432 if (RegionItem != null) 1432 if (RegionItem != null)
1433 { 1433 {
1434 Hashtable hresult = claim_user(avatar.UUID, avatar.ControllingClient.SecureSessionId, regionID, RegionItem.RegionInfo.regionSecret); 1434 Hashtable hresult = claim_user(avatar.UUID, avatar.ControllingClient.SecureSessionId, regionID, RegionItem.RegionInfo.regionSecret);
1435 if ((bool) hresult["success"] == true) 1435 if ((bool) hresult["success"] == true)
1436 { 1436 {
1437 int funds = 0; 1437 int funds = 0;
1438 try 1438 try
1439 { 1439 {
1440 funds = (Int32) hresult["funds"]; 1440 funds = (Int32) hresult["funds"];
1441 } 1441 }
1442 catch (InvalidCastException) 1442 catch (InvalidCastException)
1443 { 1443 {
1444 } 1444 }
1445 SetLocalFundsForAgentID(avatar.UUID, funds); 1445 SetLocalFundsForAgentID(avatar.UUID, funds);
1446 } 1446 }
1447 else 1447 else
1448 { 1448 {
1449 avatar.ControllingClient.SendAgentAlertMessage((string) hresult["errorMessage"], true); 1449 avatar.ControllingClient.SendAgentAlertMessage((string) hresult["errorMessage"], true);
1450 } 1450 }
1451 } 1451 }
1452 } 1452 }
1453 1453
1454 //m_log.Info("[MONEY]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + "."); 1454 //m_log.Info("[MONEY]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + ".");
1455 } 1455 }
1456 } 1456 }
1457 //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString()); 1457 //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString());
1458 } 1458 }
1459 1459
1460 #endregion 1460 #endregion
1461 } 1461 }
1462 1462
1463 public enum TransactionType : int 1463 public enum TransactionType : int
1464 { 1464 {
1465 SystemGenerated = 0, 1465 SystemGenerated = 0,
1466 RegionMoneyRequest = 1, 1466 RegionMoneyRequest = 1,
1467 Gift = 2, 1467 Gift = 2,
1468 Purchase = 3 1468 Purchase = 3
1469 } 1469 }
1470} \ No newline at end of file 1470} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs
index db38d87..dd6a92e 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs
@@ -1,501 +1,501 @@
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 OpenSim Project nor the 12 * * Neither the name of the OpenSim 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 */
27using System; 27using System;
28using System.Collections.Generic; 28using System.Collections.Generic;
29using System.Reflection; 29using System.Reflection;
30using libsecondlife; 30using libsecondlife;
31using libsecondlife.Packets; 31using libsecondlife.Packets;
32using log4net; 32using log4net;
33using Nini.Config; 33using Nini.Config;
34using Nwc.XmlRpc; 34using Nwc.XmlRpc;
35using OpenSim.Framework; 35using OpenSim.Framework;
36using OpenSim.Region.Environment.Interfaces; 36using OpenSim.Region.Environment.Interfaces;
37using OpenSim.Region.Environment.Scenes; 37using OpenSim.Region.Environment.Scenes;
38 38
39namespace OpenSim.Region.Environment.Modules.Avatar.Friends 39namespace OpenSim.Region.Environment.Modules.Avatar.Friends
40{ 40{
41 public class FriendsModule : IRegionModule 41 public class FriendsModule : IRegionModule
42 { 42 {
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44 44
45 private Dictionary<LLUUID, List<FriendListItem>> FriendLists = new Dictionary<LLUUID, List<FriendListItem>>(); 45 private Dictionary<LLUUID, List<FriendListItem>> FriendLists = new Dictionary<LLUUID, List<FriendListItem>>();
46 private Dictionary<LLUUID, LLUUID> m_pendingFriendRequests = new Dictionary<LLUUID, LLUUID>(); 46 private Dictionary<LLUUID, LLUUID> m_pendingFriendRequests = new Dictionary<LLUUID, LLUUID>();
47 private Dictionary<LLUUID, ulong> m_rootAgents = new Dictionary<LLUUID, ulong>(); 47 private Dictionary<LLUUID, ulong> m_rootAgents = new Dictionary<LLUUID, ulong>();
48 private List<Scene> m_scene = new List<Scene>(); 48 private List<Scene> m_scene = new List<Scene>();
49 49
50 #region IRegionModule Members 50 #region IRegionModule Members
51 51
52 public void Initialise(Scene scene, IConfigSource config) 52 public void Initialise(Scene scene, IConfigSource config)
53 { 53 {
54 lock (m_scene) 54 lock (m_scene)
55 { 55 {
56 if (m_scene.Count == 0) 56 if (m_scene.Count == 0)
57 { 57 {
58 scene.AddXmlRPCHandler("presence_update", processPresenceUpdate); 58 scene.AddXmlRPCHandler("presence_update", processPresenceUpdate);
59 } 59 }
60 60
61 if (!m_scene.Contains(scene)) 61 if (!m_scene.Contains(scene))
62 m_scene.Add(scene); 62 m_scene.Add(scene);
63 } 63 }
64 scene.EventManager.OnNewClient += OnNewClient; 64 scene.EventManager.OnNewClient += OnNewClient;
65 scene.EventManager.OnGridInstantMessageToFriendsModule += OnGridInstantMessage; 65 scene.EventManager.OnGridInstantMessageToFriendsModule += OnGridInstantMessage;
66 scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel; 66 scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel;
67 scene.EventManager.OnMakeChildAgent += MakeChildAgent; 67 scene.EventManager.OnMakeChildAgent += MakeChildAgent;
68 scene.EventManager.OnClientClosed += ClientLoggedOut; 68 scene.EventManager.OnClientClosed += ClientLoggedOut;
69 } 69 }
70 70
71 public void PostInitialise() 71 public void PostInitialise()
72 { 72 {
73 } 73 }
74 74
75 public void Close() 75 public void Close()
76 { 76 {
77 } 77 }
78 78
79 public string Name 79 public string Name
80 { 80 {
81 get { return "FriendsModule"; } 81 get { return "FriendsModule"; }
82 } 82 }
83 83
84 public bool IsSharedModule 84 public bool IsSharedModule
85 { 85 {
86 get { return true; } 86 get { return true; }
87 } 87 }
88 88
89 #endregion 89 #endregion
90 90
91 public XmlRpcResponse processPresenceUpdate(XmlRpcRequest req) 91 public XmlRpcResponse processPresenceUpdate(XmlRpcRequest req)
92 { 92 {
93 m_log.Info("[FRIENDS]: Got Notification about a user! OMG"); 93 m_log.Info("[FRIENDS]: Got Notification about a user! OMG");
94 return new XmlRpcResponse(); 94 return new XmlRpcResponse();
95 } 95 }
96 96
97 private void OnNewClient(IClientAPI client) 97 private void OnNewClient(IClientAPI client)
98 { 98 {
99 // All friends establishment protocol goes over instant message 99 // All friends establishment protocol goes over instant message
100 // There's no way to send a message from the sim 100 // There's no way to send a message from the sim
101 // to a user to 'add a friend' without causing dialog box spam 101 // to a user to 'add a friend' without causing dialog box spam
102 // 102 //
103 // The base set of friends are added when the user signs on in their XMLRPC response 103 // The base set of friends are added when the user signs on in their XMLRPC response
104 // Generated by LoginService. The friends are retreived from the database by the UserManager 104 // Generated by LoginService. The friends are retreived from the database by the UserManager
105 105
106 // Subscribe to instant messages 106 // Subscribe to instant messages
107 107
108 client.OnInstantMessage += OnInstantMessage; 108 client.OnInstantMessage += OnInstantMessage;
109 client.OnApproveFriendRequest += OnApprovedFriendRequest; 109 client.OnApproveFriendRequest += OnApprovedFriendRequest;
110 client.OnDenyFriendRequest += OnDenyFriendRequest; 110 client.OnDenyFriendRequest += OnDenyFriendRequest;
111 client.OnTerminateFriendship += OnTerminateFriendship; 111 client.OnTerminateFriendship += OnTerminateFriendship;
112 112
113 List<FriendListItem> fl = new List<FriendListItem>(); 113 List<FriendListItem> fl = new List<FriendListItem>();
114 114
115 //bool addFLback = false; 115 //bool addFLback = false;
116 116
117 lock (FriendLists) 117 lock (FriendLists)
118 { 118 {
119 if (FriendLists.ContainsKey(client.AgentId)) 119 if (FriendLists.ContainsKey(client.AgentId))
120 { 120 {
121 fl = FriendLists[client.AgentId]; 121 fl = FriendLists[client.AgentId];
122 } 122 }
123 else 123 else
124 { 124 {
125 fl = m_scene[0].GetFriendList(client.AgentId); 125 fl = m_scene[0].GetFriendList(client.AgentId);
126 126
127 //lock (FriendLists) 127 //lock (FriendLists)
128 //{ 128 //{
129 if (!FriendLists.ContainsKey(client.AgentId)) 129 if (!FriendLists.ContainsKey(client.AgentId))
130 FriendLists.Add(client.AgentId, fl); 130 FriendLists.Add(client.AgentId, fl);
131 //} 131 //}
132 } 132 }
133 } 133 }
134 134
135 List<LLUUID> UpdateUsers = new List<LLUUID>(); 135 List<LLUUID> UpdateUsers = new List<LLUUID>();
136 136
137 foreach (FriendListItem f in fl) 137 foreach (FriendListItem f in fl)
138 { 138 {
139 if (m_rootAgents.ContainsKey(f.Friend)) 139 if (m_rootAgents.ContainsKey(f.Friend))
140 { 140 {
141 if (f.onlinestatus == false) 141 if (f.onlinestatus == false)
142 { 142 {
143 UpdateUsers.Add(f.Friend); 143 UpdateUsers.Add(f.Friend);
144 f.onlinestatus = true; 144 f.onlinestatus = true;
145 } 145 }
146 } 146 }
147 } 147 }
148 foreach (LLUUID user in UpdateUsers) 148 foreach (LLUUID user in UpdateUsers)
149 { 149 {
150 ScenePresence av = GetPresenceFromAgentID(user); 150 ScenePresence av = GetPresenceFromAgentID(user);
151 if (av != null) 151 if (av != null)
152 { 152 {
153 List<FriendListItem> usrfl = new List<FriendListItem>(); 153 List<FriendListItem> usrfl = new List<FriendListItem>();
154 154
155 lock (FriendLists) 155 lock (FriendLists)
156 { 156 {
157 usrfl = FriendLists[user]; 157 usrfl = FriendLists[user];
158 } 158 }
159 159
160 lock (usrfl) 160 lock (usrfl)
161 { 161 {
162 foreach (FriendListItem fli in usrfl) 162 foreach (FriendListItem fli in usrfl)
163 { 163 {
164 if (fli.Friend == client.AgentId) 164 if (fli.Friend == client.AgentId)
165 { 165 {
166 fli.onlinestatus = true; 166 fli.onlinestatus = true;
167 OnlineNotificationPacket onp = new OnlineNotificationPacket(); 167 OnlineNotificationPacket onp = new OnlineNotificationPacket();
168 OnlineNotificationPacket.AgentBlockBlock[] onpb = new OnlineNotificationPacket.AgentBlockBlock[1]; 168 OnlineNotificationPacket.AgentBlockBlock[] onpb = new OnlineNotificationPacket.AgentBlockBlock[1];
169 OnlineNotificationPacket.AgentBlockBlock onpbl = new OnlineNotificationPacket.AgentBlockBlock(); 169 OnlineNotificationPacket.AgentBlockBlock onpbl = new OnlineNotificationPacket.AgentBlockBlock();
170 onpbl.AgentID = client.AgentId; 170 onpbl.AgentID = client.AgentId;
171 onpb[0] = onpbl; 171 onpb[0] = onpbl;
172 onp.AgentBlock = onpb; 172 onp.AgentBlock = onpb;
173 av.ControllingClient.OutPacket(onp, ThrottleOutPacketType.Task); 173 av.ControllingClient.OutPacket(onp, ThrottleOutPacketType.Task);
174 } 174 }
175 } 175 }
176 } 176 }
177 } 177 }
178 } 178 }
179 179
180 if (UpdateUsers.Count > 0) 180 if (UpdateUsers.Count > 0)
181 { 181 {
182 OnlineNotificationPacket onp = new OnlineNotificationPacket(); 182 OnlineNotificationPacket onp = new OnlineNotificationPacket();
183 OnlineNotificationPacket.AgentBlockBlock[] onpb = new OnlineNotificationPacket.AgentBlockBlock[UpdateUsers.Count]; 183 OnlineNotificationPacket.AgentBlockBlock[] onpb = new OnlineNotificationPacket.AgentBlockBlock[UpdateUsers.Count];
184 for (int i = 0; i < UpdateUsers.Count; i++) 184 for (int i = 0; i < UpdateUsers.Count; i++)
185 { 185 {
186 OnlineNotificationPacket.AgentBlockBlock onpbl = new OnlineNotificationPacket.AgentBlockBlock(); 186 OnlineNotificationPacket.AgentBlockBlock onpbl = new OnlineNotificationPacket.AgentBlockBlock();
187 onpbl.AgentID = UpdateUsers[i]; 187 onpbl.AgentID = UpdateUsers[i];
188 onpb[i] = onpbl; 188 onpb[i] = onpbl;
189 } 189 }
190 onp.AgentBlock = onpb; 190 onp.AgentBlock = onpb;
191 client.OutPacket(onp, ThrottleOutPacketType.Task); 191 client.OutPacket(onp, ThrottleOutPacketType.Task);
192 } 192 }
193 } 193 }
194 194
195 private void ClientLoggedOut(LLUUID AgentId) 195 private void ClientLoggedOut(LLUUID AgentId)
196 { 196 {
197 lock (m_rootAgents) 197 lock (m_rootAgents)
198 { 198 {
199 if (m_rootAgents.ContainsKey(AgentId)) 199 if (m_rootAgents.ContainsKey(AgentId))
200 { 200 {
201 m_rootAgents.Remove(AgentId); 201 m_rootAgents.Remove(AgentId);
202 m_log.Info("[FRIEND]: Removing " + AgentId + ". Agent logged out."); 202 m_log.Info("[FRIEND]: Removing " + AgentId + ". Agent logged out.");
203 } 203 }
204 } 204 }
205 List<FriendListItem> lfli = new List<FriendListItem>(); 205 List<FriendListItem> lfli = new List<FriendListItem>();
206 lock (FriendLists) 206 lock (FriendLists)
207 { 207 {
208 if (FriendLists.ContainsKey(AgentId)) 208 if (FriendLists.ContainsKey(AgentId))
209 { 209 {
210 lfli = FriendLists[AgentId]; 210 lfli = FriendLists[AgentId];
211 } 211 }
212 } 212 }
213 List<LLUUID> updateUsers = new List<LLUUID>(); 213 List<LLUUID> updateUsers = new List<LLUUID>();
214 foreach (FriendListItem fli in lfli) 214 foreach (FriendListItem fli in lfli)
215 { 215 {
216 if (fli.onlinestatus == true) 216 if (fli.onlinestatus == true)
217 { 217 {
218 updateUsers.Add(fli.Friend); 218 updateUsers.Add(fli.Friend);
219 } 219 }
220 } 220 }
221 lock (updateUsers) 221 lock (updateUsers)
222 { 222 {
223 for (int i = 0; i < updateUsers.Count; i++) 223 for (int i = 0; i < updateUsers.Count; i++)
224 { 224 {
225 List<FriendListItem> flfli = new List<FriendListItem>(); 225 List<FriendListItem> flfli = new List<FriendListItem>();
226 try 226 try
227 { 227 {
228 lock (FriendLists) 228 lock (FriendLists)
229 { 229 {
230 if (FriendLists.ContainsKey(updateUsers[i])) 230 if (FriendLists.ContainsKey(updateUsers[i]))
231 flfli = FriendLists[updateUsers[i]]; 231 flfli = FriendLists[updateUsers[i]];
232 } 232 }
233 } 233 }
234 catch (IndexOutOfRangeException) 234 catch (IndexOutOfRangeException)
235 { 235 {
236 // Ignore the index out of range exception. 236 // Ignore the index out of range exception.
237 // This causes friend lists to get out of sync slightly.. however 237 // This causes friend lists to get out of sync slightly.. however
238 // prevents a sim crash. 238 // prevents a sim crash.
239 m_log.Info("[FRIEND]: Unable to enumerate last friendlist user. User logged off"); 239 m_log.Info("[FRIEND]: Unable to enumerate last friendlist user. User logged off");
240 } 240 }
241 241
242 for (int j = 0; j < flfli.Count; j++) 242 for (int j = 0; j < flfli.Count; j++)
243 { 243 {
244 try 244 try
245 { 245 {
246 if (flfli[i].Friend == AgentId) 246 if (flfli[i].Friend == AgentId)
247 { 247 {
248 flfli[i].onlinestatus = false; 248 flfli[i].onlinestatus = false;
249 } 249 }
250 } 250 }
251 251
252 catch (IndexOutOfRangeException) 252 catch (IndexOutOfRangeException)
253 { 253 {
254 // Ignore the index out of range exception. 254 // Ignore the index out of range exception.
255 // This causes friend lists to get out of sync slightly.. however 255 // This causes friend lists to get out of sync slightly.. however
256 // prevents a sim crash. 256 // prevents a sim crash.
257 m_log.Info("[FRIEND]: Unable to enumerate last friendlist user. User logged off"); 257 m_log.Info("[FRIEND]: Unable to enumerate last friendlist user. User logged off");
258 } 258 }
259 } 259 }
260 } 260 }
261 261
262 for (int i = 0; i < updateUsers.Count; i++) 262 for (int i = 0; i < updateUsers.Count; i++)
263 { 263 {
264 ScenePresence av = GetPresenceFromAgentID(updateUsers[i]); 264 ScenePresence av = GetPresenceFromAgentID(updateUsers[i]);
265 if (av != null) 265 if (av != null)
266 { 266 {
267 OfflineNotificationPacket onp = new OfflineNotificationPacket(); 267 OfflineNotificationPacket onp = new OfflineNotificationPacket();
268 OfflineNotificationPacket.AgentBlockBlock[] onpb = new OfflineNotificationPacket.AgentBlockBlock[1]; 268 OfflineNotificationPacket.AgentBlockBlock[] onpb = new OfflineNotificationPacket.AgentBlockBlock[1];
269 OfflineNotificationPacket.AgentBlockBlock onpbl = new OfflineNotificationPacket.AgentBlockBlock(); 269 OfflineNotificationPacket.AgentBlockBlock onpbl = new OfflineNotificationPacket.AgentBlockBlock();
270 onpbl.AgentID = AgentId; 270 onpbl.AgentID = AgentId;
271 onpb[0] = onpbl; 271 onpb[0] = onpbl;
272 onp.AgentBlock = onpb; 272 onp.AgentBlock = onpb;
273 av.ControllingClient.OutPacket(onp, ThrottleOutPacketType.Task); 273 av.ControllingClient.OutPacket(onp, ThrottleOutPacketType.Task);
274 } 274 }
275 } 275 }
276 } 276 }
277 lock (FriendLists) 277 lock (FriendLists)
278 { 278 {
279 FriendLists.Remove(AgentId); 279 FriendLists.Remove(AgentId);
280 } 280 }
281 } 281 }
282 282
283 private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, LLUUID regionID) 283 private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, LLUUID regionID)
284 { 284 {
285 lock (m_rootAgents) 285 lock (m_rootAgents)
286 { 286 {
287 if (m_rootAgents.ContainsKey(avatar.UUID)) 287 if (m_rootAgents.ContainsKey(avatar.UUID))
288 { 288 {
289 if (avatar.RegionHandle != m_rootAgents[avatar.UUID]) 289 if (avatar.RegionHandle != m_rootAgents[avatar.UUID])
290 { 290 {
291 m_rootAgents[avatar.UUID] = avatar.RegionHandle; 291 m_rootAgents[avatar.UUID] = avatar.RegionHandle;
292 m_log.Info("[FRIEND]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + "."); 292 m_log.Info("[FRIEND]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + ".");
293 if (avatar.JID.Length > 0) 293 if (avatar.JID.Length > 0)
294 { 294 {
295 JId avatarID = new JId(avatar.JID); 295 JId avatarID = new JId(avatar.JID);
296 // REST Post XMPP Stanzas! 296 // REST Post XMPP Stanzas!
297 } 297 }
298 // Claim User! my user! Mine mine mine! 298 // Claim User! my user! Mine mine mine!
299 } 299 }
300 } 300 }
301 else 301 else
302 { 302 {
303 m_rootAgents.Add(avatar.UUID, avatar.RegionHandle); 303 m_rootAgents.Add(avatar.UUID, avatar.RegionHandle);
304 m_log.Info("[FRIEND]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + "."); 304 m_log.Info("[FRIEND]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + ".");
305 } 305 }
306 } 306 }
307 //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString()); 307 //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString());
308 } 308 }
309 309
310 private void MakeChildAgent(ScenePresence avatar) 310 private void MakeChildAgent(ScenePresence avatar)
311 { 311 {
312 lock (m_rootAgents) 312 lock (m_rootAgents)
313 { 313 {
314 if (m_rootAgents.ContainsKey(avatar.UUID)) 314 if (m_rootAgents.ContainsKey(avatar.UUID))
315 { 315 {
316 if (m_rootAgents[avatar.UUID] == avatar.RegionHandle) 316 if (m_rootAgents[avatar.UUID] == avatar.RegionHandle)
317 { 317 {
318 m_rootAgents.Remove(avatar.UUID); 318 m_rootAgents.Remove(avatar.UUID);
319 m_log.Info("[FRIEND]: Removing " + avatar.Firstname + " " + avatar.Lastname + " as a root agent"); 319 m_log.Info("[FRIEND]: Removing " + avatar.Firstname + " " + avatar.Lastname + " as a root agent");
320 } 320 }
321 } 321 }
322 } 322 }
323 } 323 }
324 324
325 private ScenePresence GetPresenceFromAgentID(LLUUID AgentID) 325 private ScenePresence GetPresenceFromAgentID(LLUUID AgentID)
326 { 326 {
327 ScenePresence returnAgent = null; 327 ScenePresence returnAgent = null;
328 lock (m_scene) 328 lock (m_scene)
329 { 329 {
330 ScenePresence queryagent = null; 330 ScenePresence queryagent = null;
331 for (int i = 0; i < m_scene.Count; i++) 331 for (int i = 0; i < m_scene.Count; i++)
332 { 332 {
333 queryagent = m_scene[i].GetScenePresence(AgentID); 333 queryagent = m_scene[i].GetScenePresence(AgentID);
334 if (queryagent != null) 334 if (queryagent != null)
335 { 335 {
336 if (!queryagent.IsChildAgent) 336 if (!queryagent.IsChildAgent)
337 { 337 {
338 returnAgent = queryagent; 338 returnAgent = queryagent;
339 break; 339 break;
340 } 340 }
341 } 341 }
342 } 342 }
343 } 343 }
344 return returnAgent; 344 return returnAgent;
345 } 345 }
346 346
347 #region FriendRequestHandling 347 #region FriendRequestHandling
348 348
349 private void OnInstantMessage(IClientAPI client, LLUUID fromAgentID, 349 private void OnInstantMessage(IClientAPI client, LLUUID fromAgentID,
350 LLUUID fromAgentSession, LLUUID toAgentID, 350 LLUUID fromAgentSession, LLUUID toAgentID,
351 LLUUID imSessionID, uint timestamp, string fromAgentName, 351 LLUUID imSessionID, uint timestamp, string fromAgentName,
352 string message, byte dialog, bool fromGroup, byte offline, 352 string message, byte dialog, bool fromGroup, byte offline,
353 uint ParentEstateID, LLVector3 Position, LLUUID RegionID, 353 uint ParentEstateID, LLVector3 Position, LLUUID RegionID,
354 byte[] binaryBucket) 354 byte[] binaryBucket)
355 { 355 {
356 // Friend Requests go by Instant Message.. using the dialog param 356 // Friend Requests go by Instant Message.. using the dialog param
357 // https://wiki.secondlife.com/wiki/ImprovedInstantMessage 357 // https://wiki.secondlife.com/wiki/ImprovedInstantMessage
358 358
359 // 38 == Offer friendship 359 // 38 == Offer friendship
360 if (dialog == (byte) 38) 360 if (dialog == (byte) 38)
361 { 361 {
362 LLUUID friendTransactionID = LLUUID.Random(); 362 LLUUID friendTransactionID = LLUUID.Random();
363 363
364 m_pendingFriendRequests.Add(friendTransactionID, fromAgentID); 364 m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
365 365
366 m_log.Info("[FRIEND]: 38 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + 366 m_log.Info("[FRIEND]: 38 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" +
367 message); 367 message);
368 GridInstantMessage msg = new GridInstantMessage(); 368 GridInstantMessage msg = new GridInstantMessage();
369 msg.fromAgentID = fromAgentID.UUID; 369 msg.fromAgentID = fromAgentID.UUID;
370 msg.fromAgentSession = fromAgentSession.UUID; 370 msg.fromAgentSession = fromAgentSession.UUID;
371 msg.toAgentID = toAgentID.UUID; 371 msg.toAgentID = toAgentID.UUID;
372 msg.imSessionID = friendTransactionID.UUID; // This is the item we're mucking with here 372 msg.imSessionID = friendTransactionID.UUID; // This is the item we're mucking with here
373 m_log.Info("[FRIEND]: Filling Session: " + msg.imSessionID.ToString()); 373 m_log.Info("[FRIEND]: Filling Session: " + msg.imSessionID.ToString());
374 msg.timestamp = timestamp; 374 msg.timestamp = timestamp;
375 if (client != null) 375 if (client != null)
376 { 376 {
377 msg.fromAgentName = client.FirstName + " " + client.LastName; // fromAgentName; 377 msg.fromAgentName = client.FirstName + " " + client.LastName; // fromAgentName;
378 } 378 }
379 else 379 else
380 { 380 {
381 msg.fromAgentName = "(hippos)"; // Added for posterity. This means that we can't figure out who sent it 381 msg.fromAgentName = "(hippos)"; // Added for posterity. This means that we can't figure out who sent it
382 } 382 }
383 msg.message = message; 383 msg.message = message;
384 msg.dialog = dialog; 384 msg.dialog = dialog;
385 msg.fromGroup = fromGroup; 385 msg.fromGroup = fromGroup;
386 msg.offline = offline; 386 msg.offline = offline;
387 msg.ParentEstateID = ParentEstateID; 387 msg.ParentEstateID = ParentEstateID;
388 msg.Position = new sLLVector3(Position); 388 msg.Position = new sLLVector3(Position);
389 msg.RegionID = RegionID.UUID; 389 msg.RegionID = RegionID.UUID;
390 msg.binaryBucket = binaryBucket; 390 msg.binaryBucket = binaryBucket;
391 // We don't really care which scene we pipe it through. 391 // We don't really care which scene we pipe it through.
392 m_scene[0].TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); 392 m_scene[0].TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule);
393 } 393 }
394 394
395 // 39 == Accept Friendship 395 // 39 == Accept Friendship
396 if (dialog == (byte) 39) 396 if (dialog == (byte) 39)
397 { 397 {
398 m_log.Info("[FRIEND]: 39 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + 398 m_log.Info("[FRIEND]: 39 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" +
399 message); 399 message);
400 } 400 }
401 401
402 // 40 == Decline Friendship 402 // 40 == Decline Friendship
403 if (dialog == (byte) 40) 403 if (dialog == (byte) 40)
404 { 404 {
405 m_log.Info("[FRIEND]: 40 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + 405 m_log.Info("[FRIEND]: 40 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" +
406 message); 406 message);
407 } 407 }
408 } 408 }
409 409
410 private void OnApprovedFriendRequest(IClientAPI client, LLUUID agentID, LLUUID transactionID, List<LLUUID> callingCardFolders) 410 private void OnApprovedFriendRequest(IClientAPI client, LLUUID agentID, LLUUID transactionID, List<LLUUID> callingCardFolders)
411 { 411 {
412 if (m_pendingFriendRequests.ContainsKey(transactionID)) 412 if (m_pendingFriendRequests.ContainsKey(transactionID))
413 { 413 {
414 // Found Pending Friend Request with that Transaction.. 414 // Found Pending Friend Request with that Transaction..
415 Scene SceneAgentIn = m_scene[0]; 415 Scene SceneAgentIn = m_scene[0];
416 416
417 // Found Pending Friend Request with that Transaction.. 417 // Found Pending Friend Request with that Transaction..
418 ScenePresence agentpresence = GetPresenceFromAgentID(agentID); 418 ScenePresence agentpresence = GetPresenceFromAgentID(agentID);
419 if (agentpresence != null) 419 if (agentpresence != null)
420 { 420 {
421 SceneAgentIn = agentpresence.Scene; 421 SceneAgentIn = agentpresence.Scene;
422 } 422 }
423 423
424 // Compose response to other agent. 424 // Compose response to other agent.
425 GridInstantMessage msg = new GridInstantMessage(); 425 GridInstantMessage msg = new GridInstantMessage();
426 msg.toAgentID = m_pendingFriendRequests[transactionID].UUID; 426 msg.toAgentID = m_pendingFriendRequests[transactionID].UUID;
427 msg.fromAgentID = agentID.UUID; 427 msg.fromAgentID = agentID.UUID;
428 msg.fromAgentName = client.FirstName + " " + client.LastName; 428 msg.fromAgentName = client.FirstName + " " + client.LastName;
429 msg.fromAgentSession = client.SessionId.UUID; 429 msg.fromAgentSession = client.SessionId.UUID;
430 msg.fromGroup = false; 430 msg.fromGroup = false;
431 msg.imSessionID = transactionID.UUID; 431 msg.imSessionID = transactionID.UUID;
432 msg.message = agentID.UUID.ToString(); 432 msg.message = agentID.UUID.ToString();
433 msg.ParentEstateID = 0; 433 msg.ParentEstateID = 0;
434 msg.timestamp = (uint) Util.UnixTimeSinceEpoch(); 434 msg.timestamp = (uint) Util.UnixTimeSinceEpoch();
435 msg.RegionID = SceneAgentIn.RegionInfo.RegionID.UUID; 435 msg.RegionID = SceneAgentIn.RegionInfo.RegionID.UUID;
436 msg.dialog = (byte) 39; // Approved friend request 436 msg.dialog = (byte) 39; // Approved friend request
437 msg.Position = new sLLVector3(); 437 msg.Position = new sLLVector3();
438 msg.offline = (byte) 0; 438 msg.offline = (byte) 0;
439 msg.binaryBucket = new byte[0]; 439 msg.binaryBucket = new byte[0];
440 // We don't really care which scene we pipe it through, it goes to the shared IM Module and/or the database 440 // We don't really care which scene we pipe it through, it goes to the shared IM Module and/or the database
441 441
442 SceneAgentIn.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); 442 SceneAgentIn.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule);
443 SceneAgentIn.StoreAddFriendship(m_pendingFriendRequests[transactionID], agentID, (uint) 1); 443 SceneAgentIn.StoreAddFriendship(m_pendingFriendRequests[transactionID], agentID, (uint) 1);
444 m_pendingFriendRequests.Remove(transactionID); 444 m_pendingFriendRequests.Remove(transactionID);
445 445
446 // TODO: Inform agent that the friend is online 446 // TODO: Inform agent that the friend is online
447 } 447 }
448 } 448 }
449 449
450 private void OnDenyFriendRequest(IClientAPI client, LLUUID agentID, LLUUID transactionID, List<LLUUID> callingCardFolders) 450 private void OnDenyFriendRequest(IClientAPI client, LLUUID agentID, LLUUID transactionID, List<LLUUID> callingCardFolders)
451 { 451 {
452 if (m_pendingFriendRequests.ContainsKey(transactionID)) 452 if (m_pendingFriendRequests.ContainsKey(transactionID))
453 { 453 {
454 Scene SceneAgentIn = m_scene[0]; 454 Scene SceneAgentIn = m_scene[0];
455 455
456 // Found Pending Friend Request with that Transaction.. 456 // Found Pending Friend Request with that Transaction..
457 ScenePresence agentpresence = GetPresenceFromAgentID(agentID); 457 ScenePresence agentpresence = GetPresenceFromAgentID(agentID);
458 if (agentpresence != null) 458 if (agentpresence != null)
459 { 459 {
460 SceneAgentIn = agentpresence.Scene; 460 SceneAgentIn = agentpresence.Scene;
461 } 461 }
462 // Compose response to other agent. 462 // Compose response to other agent.
463 GridInstantMessage msg = new GridInstantMessage(); 463 GridInstantMessage msg = new GridInstantMessage();
464 msg.toAgentID = m_pendingFriendRequests[transactionID].UUID; 464 msg.toAgentID = m_pendingFriendRequests[transactionID].UUID;
465 msg.fromAgentID = agentID.UUID; 465 msg.fromAgentID = agentID.UUID;
466 msg.fromAgentName = client.FirstName + " " + client.LastName; 466 msg.fromAgentName = client.FirstName + " " + client.LastName;
467 msg.fromAgentSession = client.SessionId.UUID; 467 msg.fromAgentSession = client.SessionId.UUID;
468 msg.fromGroup = false; 468 msg.fromGroup = false;
469 msg.imSessionID = transactionID.UUID; 469 msg.imSessionID = transactionID.UUID;
470 msg.message = agentID.UUID.ToString(); 470 msg.message = agentID.UUID.ToString();
471 msg.ParentEstateID = 0; 471 msg.ParentEstateID = 0;
472 msg.timestamp = (uint) Util.UnixTimeSinceEpoch(); 472 msg.timestamp = (uint) Util.UnixTimeSinceEpoch();
473 msg.RegionID = SceneAgentIn.RegionInfo.RegionID.UUID; 473 msg.RegionID = SceneAgentIn.RegionInfo.RegionID.UUID;
474 msg.dialog = (byte) 40; // Deny friend request 474 msg.dialog = (byte) 40; // Deny friend request
475 msg.Position = new sLLVector3(); 475 msg.Position = new sLLVector3();
476 msg.offline = (byte) 0; 476 msg.offline = (byte) 0;
477 msg.binaryBucket = new byte[0]; 477 msg.binaryBucket = new byte[0];
478 SceneAgentIn.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); 478 SceneAgentIn.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule);
479 m_pendingFriendRequests.Remove(transactionID); 479 m_pendingFriendRequests.Remove(transactionID);
480 } 480 }
481 } 481 }
482 482
483 private void OnTerminateFriendship(IClientAPI client, LLUUID agent, LLUUID exfriendID) 483 private void OnTerminateFriendship(IClientAPI client, LLUUID agent, LLUUID exfriendID)
484 { 484 {
485 m_scene[0].StoreRemoveFriendship(agent, exfriendID); 485 m_scene[0].StoreRemoveFriendship(agent, exfriendID);
486 // TODO: Inform the client that the ExFriend is offline 486 // TODO: Inform the client that the ExFriend is offline
487 } 487 }
488 488
489 private void OnGridInstantMessage(GridInstantMessage msg) 489 private void OnGridInstantMessage(GridInstantMessage msg)
490 { 490 {
491 // Trigger the above event handler 491 // Trigger the above event handler
492 OnInstantMessage(null, new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession), 492 OnInstantMessage(null, new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession),
493 new LLUUID(msg.toAgentID), new LLUUID(msg.imSessionID), msg.timestamp, msg.fromAgentName, 493 new LLUUID(msg.toAgentID), new LLUUID(msg.imSessionID), msg.timestamp, msg.fromAgentName,
494 msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID, 494 msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID,
495 new LLVector3(msg.Position.x, msg.Position.y, msg.Position.z), new LLUUID(msg.RegionID), 495 new LLVector3(msg.Position.x, msg.Position.y, msg.Position.z), new LLUUID(msg.RegionID),
496 msg.binaryBucket); 496 msg.binaryBucket);
497 } 497 }
498 498
499 #endregion 499 #endregion
500 } 500 }
501} \ No newline at end of file 501} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Avatar/Groups/GroupsModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Groups/GroupsModule.cs
index c4906d2..6edc44d 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/Groups/GroupsModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/Groups/GroupsModule.cs
@@ -1,273 +1,273 @@
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 OpenSim Project nor the 12 * * Neither the name of the OpenSim 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
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Reflection; 30using System.Reflection;
31using libsecondlife; 31using libsecondlife;
32using log4net; 32using log4net;
33using Nini.Config; 33using Nini.Config;
34using OpenSim.Framework; 34using OpenSim.Framework;
35using OpenSim.Region.Environment.Interfaces; 35using OpenSim.Region.Environment.Interfaces;
36using OpenSim.Region.Environment.Scenes; 36using OpenSim.Region.Environment.Scenes;
37 37
38namespace OpenSim.Region.Environment.Modules.Avatar.Groups 38namespace OpenSim.Region.Environment.Modules.Avatar.Groups
39{ 39{
40 public class GroupsModule : IRegionModule 40 public class GroupsModule : IRegionModule
41 { 41 {
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43 43
44 private Dictionary<LLUUID, GroupList> m_grouplistmap = new Dictionary<LLUUID, GroupList>(); 44 private Dictionary<LLUUID, GroupList> m_grouplistmap = new Dictionary<LLUUID, GroupList>();
45 private Dictionary<LLUUID, GroupData> m_groupmap = new Dictionary<LLUUID, GroupData>(); 45 private Dictionary<LLUUID, GroupData> m_groupmap = new Dictionary<LLUUID, GroupData>();
46 private Dictionary<LLUUID, IClientAPI> m_iclientmap = new Dictionary<LLUUID, IClientAPI>(); 46 private Dictionary<LLUUID, IClientAPI> m_iclientmap = new Dictionary<LLUUID, IClientAPI>();
47 private List<Scene> m_scene = new List<Scene>(); 47 private List<Scene> m_scene = new List<Scene>();
48 48
49 #region IRegionModule Members 49 #region IRegionModule Members
50 50
51 public void Initialise(Scene scene, IConfigSource config) 51 public void Initialise(Scene scene, IConfigSource config)
52 { 52 {
53 lock (m_scene) 53 lock (m_scene)
54 { 54 {
55 m_scene.Add(scene); 55 m_scene.Add(scene);
56 } 56 }
57 scene.EventManager.OnNewClient += OnNewClient; 57 scene.EventManager.OnNewClient += OnNewClient;
58 scene.EventManager.OnClientClosed += OnClientClosed; 58 scene.EventManager.OnClientClosed += OnClientClosed;
59 scene.EventManager.OnGridInstantMessageToGroupsModule += OnGridInstantMessage; 59 scene.EventManager.OnGridInstantMessageToGroupsModule += OnGridInstantMessage;
60 //scene.EventManager. 60 //scene.EventManager.
61 } 61 }
62 62
63 public void PostInitialise() 63 public void PostInitialise()
64 { 64 {
65 } 65 }
66 66
67 public void Close() 67 public void Close()
68 { 68 {
69 m_log.Info("[GROUP]: Shutting down group module."); 69 m_log.Info("[GROUP]: Shutting down group module.");
70 lock (m_iclientmap) 70 lock (m_iclientmap)
71 { 71 {
72 m_iclientmap.Clear(); 72 m_iclientmap.Clear();
73 } 73 }
74 74
75 lock (m_groupmap) 75 lock (m_groupmap)
76 { 76 {
77 m_groupmap.Clear(); 77 m_groupmap.Clear();
78 } 78 }
79 79
80 lock (m_grouplistmap) 80 lock (m_grouplistmap)
81 { 81 {
82 m_grouplistmap.Clear(); 82 m_grouplistmap.Clear();
83 } 83 }
84 GC.Collect(); 84 GC.Collect();
85 } 85 }
86 86
87 public string Name 87 public string Name
88 { 88 {
89 get { return "GroupsModule"; } 89 get { return "GroupsModule"; }
90 } 90 }
91 91
92 public bool IsSharedModule 92 public bool IsSharedModule
93 { 93 {
94 get { return true; } 94 get { return true; }
95 } 95 }
96 96
97 #endregion 97 #endregion
98 98
99 private void OnNewClient(IClientAPI client) 99 private void OnNewClient(IClientAPI client)
100 { 100 {
101 // All friends establishment protocol goes over instant message 101 // All friends establishment protocol goes over instant message
102 // There's no way to send a message from the sim 102 // There's no way to send a message from the sim
103 // to a user to 'add a friend' without causing dialog box spam 103 // to a user to 'add a friend' without causing dialog box spam
104 // 104 //
105 // The base set of friends are added when the user signs on in their XMLRPC response 105 // The base set of friends are added when the user signs on in their XMLRPC response
106 // Generated by LoginService. The friends are retreived from the database by the UserManager 106 // Generated by LoginService. The friends are retreived from the database by the UserManager
107 107
108 // Subscribe to instant messages 108 // Subscribe to instant messages
109 client.OnInstantMessage += OnInstantMessage; 109 client.OnInstantMessage += OnInstantMessage;
110 client.OnAgentDataUpdateRequest += OnAgentDataUpdateRequest; 110 client.OnAgentDataUpdateRequest += OnAgentDataUpdateRequest;
111 lock (m_iclientmap) 111 lock (m_iclientmap)
112 { 112 {
113 if (!m_iclientmap.ContainsKey(client.AgentId)) 113 if (!m_iclientmap.ContainsKey(client.AgentId))
114 { 114 {
115 m_iclientmap.Add(client.AgentId, client); 115 m_iclientmap.Add(client.AgentId, client);
116 } 116 }
117 } 117 }
118 GroupData OpenSimulatorGroup = new GroupData(); 118 GroupData OpenSimulatorGroup = new GroupData();
119 OpenSimulatorGroup.ActiveGroupTitle = "OpenSimulator Tester"; 119 OpenSimulatorGroup.ActiveGroupTitle = "OpenSimulator Tester";
120 OpenSimulatorGroup.GroupID = new LLUUID("00000000-68f9-1111-024e-222222111120"); 120 OpenSimulatorGroup.GroupID = new LLUUID("00000000-68f9-1111-024e-222222111120");
121 OpenSimulatorGroup.GroupMembers.Add(client.AgentId); 121 OpenSimulatorGroup.GroupMembers.Add(client.AgentId);
122 OpenSimulatorGroup.groupName = "OpenSimulator Testing"; 122 OpenSimulatorGroup.groupName = "OpenSimulator Testing";
123 OpenSimulatorGroup.ActiveGroupPowers = GroupPowers.LandAllowSetHome; 123 OpenSimulatorGroup.ActiveGroupPowers = GroupPowers.LandAllowSetHome;
124 OpenSimulatorGroup.GroupTitles.Add("OpenSimulator Tester"); 124 OpenSimulatorGroup.GroupTitles.Add("OpenSimulator Tester");
125 lock (m_groupmap) 125 lock (m_groupmap)
126 { 126 {
127 if (!m_groupmap.ContainsKey(client.AgentId)) 127 if (!m_groupmap.ContainsKey(client.AgentId))
128 { 128 {
129 m_groupmap.Add(client.AgentId, OpenSimulatorGroup); 129 m_groupmap.Add(client.AgentId, OpenSimulatorGroup);
130 } 130 }
131 } 131 }
132 GroupList testGroupList = new GroupList(); 132 GroupList testGroupList = new GroupList();
133 testGroupList.m_GroupList.Add(new LLUUID("00000000-68f9-1111-024e-222222111120")); 133 testGroupList.m_GroupList.Add(new LLUUID("00000000-68f9-1111-024e-222222111120"));
134 134
135 lock (m_grouplistmap) 135 lock (m_grouplistmap)
136 { 136 {
137 if (!m_grouplistmap.ContainsKey(client.AgentId)) 137 if (!m_grouplistmap.ContainsKey(client.AgentId))
138 { 138 {
139 m_grouplistmap.Add(client.AgentId, testGroupList); 139 m_grouplistmap.Add(client.AgentId, testGroupList);
140 } 140 }
141 } 141 }
142 m_log.Info("[GROUP]: Adding " + client.FirstName + " " + client.LastName + " to OpenSimulator Tester group"); 142 m_log.Info("[GROUP]: Adding " + client.FirstName + " " + client.LastName + " to OpenSimulator Tester group");
143 } 143 }
144 144
145 private void OnAgentDataUpdateRequest(IClientAPI remoteClient, LLUUID AgentID, LLUUID SessionID) 145 private void OnAgentDataUpdateRequest(IClientAPI remoteClient, LLUUID AgentID, LLUUID SessionID)
146 { 146 {
147 string firstname = remoteClient.FirstName; 147 string firstname = remoteClient.FirstName;
148 string lastname = remoteClient.LastName; 148 string lastname = remoteClient.LastName;
149 149
150 LLUUID ActiveGroupID = LLUUID.Zero; 150 LLUUID ActiveGroupID = LLUUID.Zero;
151 uint ActiveGroupPowers = 0; 151 uint ActiveGroupPowers = 0;
152 string ActiveGroupName = ""; 152 string ActiveGroupName = "";
153 string ActiveGroupTitle = ""; 153 string ActiveGroupTitle = "";
154 154
155 bool foundUser = false; 155 bool foundUser = false;
156 156
157 lock (m_iclientmap) 157 lock (m_iclientmap)
158 { 158 {
159 if (m_iclientmap.ContainsKey(remoteClient.AgentId)) 159 if (m_iclientmap.ContainsKey(remoteClient.AgentId))
160 { 160 {
161 foundUser = true; 161 foundUser = true;
162 } 162 }
163 } 163 }
164 if (foundUser) 164 if (foundUser)
165 { 165 {
166 lock (m_groupmap) 166 lock (m_groupmap)
167 { 167 {
168 if (m_groupmap.ContainsKey(remoteClient.AgentId)) 168 if (m_groupmap.ContainsKey(remoteClient.AgentId))
169 { 169 {
170 GroupData grp = m_groupmap[remoteClient.AgentId]; 170 GroupData grp = m_groupmap[remoteClient.AgentId];
171 if (grp != null) 171 if (grp != null)
172 { 172 {
173 ActiveGroupID = grp.GroupID; 173 ActiveGroupID = grp.GroupID;
174 ActiveGroupName = grp.groupName; 174 ActiveGroupName = grp.groupName;
175 ActiveGroupPowers = grp.groupPowers; 175 ActiveGroupPowers = grp.groupPowers;
176 ActiveGroupTitle = grp.ActiveGroupTitle; 176 ActiveGroupTitle = grp.ActiveGroupTitle;
177 } 177 }
178 178
179 //remoteClient.SendAgentDataUpdate(AgentID, ActiveGroupID, firstname, lastname, ActiveGroupPowers, ActiveGroupName, ActiveGroupTitle); 179 //remoteClient.SendAgentDataUpdate(AgentID, ActiveGroupID, firstname, lastname, ActiveGroupPowers, ActiveGroupName, ActiveGroupTitle);
180 } 180 }
181 } 181 }
182 } 182 }
183 } 183 }
184 184
185 private void OnInstantMessage(IClientAPI client, LLUUID fromAgentID, 185 private void OnInstantMessage(IClientAPI client, LLUUID fromAgentID,
186 LLUUID fromAgentSession, LLUUID toAgentID, 186 LLUUID fromAgentSession, LLUUID toAgentID,
187 LLUUID imSessionID, uint timestamp, string fromAgentName, 187 LLUUID imSessionID, uint timestamp, string fromAgentName,
188 string message, byte dialog, bool fromGroup, byte offline, 188 string message, byte dialog, bool fromGroup, byte offline,
189 uint ParentEstateID, LLVector3 Position, LLUUID RegionID, 189 uint ParentEstateID, LLVector3 Position, LLUUID RegionID,
190 byte[] binaryBucket) 190 byte[] binaryBucket)
191 { 191 {
192 } 192 }
193 193
194 private void OnGridInstantMessage(GridInstantMessage msg) 194 private void OnGridInstantMessage(GridInstantMessage msg)
195 { 195 {
196 // Trigger the above event handler 196 // Trigger the above event handler
197 OnInstantMessage(null, new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession), 197 OnInstantMessage(null, new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession),
198 new LLUUID(msg.toAgentID), new LLUUID(msg.imSessionID), msg.timestamp, msg.fromAgentName, 198 new LLUUID(msg.toAgentID), new LLUUID(msg.imSessionID), msg.timestamp, msg.fromAgentName,
199 msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID, 199 msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID,
200 new LLVector3(msg.Position.x, msg.Position.y, msg.Position.z), new LLUUID(msg.RegionID), 200 new LLVector3(msg.Position.x, msg.Position.y, msg.Position.z), new LLUUID(msg.RegionID),
201 msg.binaryBucket); 201 msg.binaryBucket);
202 } 202 }
203 203
204 private void OnClientClosed(LLUUID agentID) 204 private void OnClientClosed(LLUUID agentID)
205 { 205 {
206 lock (m_iclientmap) 206 lock (m_iclientmap)
207 { 207 {
208 if (m_iclientmap.ContainsKey(agentID)) 208 if (m_iclientmap.ContainsKey(agentID))
209 { 209 {
210 IClientAPI cli = m_iclientmap[agentID]; 210 IClientAPI cli = m_iclientmap[agentID];
211 if (cli != null) 211 if (cli != null)
212 { 212 {
213 m_log.Info("[GROUP]: Removing all reference to groups for " + cli.FirstName + " " + cli.LastName); 213 m_log.Info("[GROUP]: Removing all reference to groups for " + cli.FirstName + " " + cli.LastName);
214 } 214 }
215 else 215 else
216 { 216 {
217 m_log.Info("[GROUP]: Removing all reference to groups for " + agentID.ToString()); 217 m_log.Info("[GROUP]: Removing all reference to groups for " + agentID.ToString());
218 } 218 }
219 m_iclientmap.Remove(agentID); 219 m_iclientmap.Remove(agentID);
220 } 220 }
221 } 221 }
222 222
223 lock (m_groupmap) 223 lock (m_groupmap)
224 { 224 {
225 if (m_groupmap.ContainsKey(agentID)) 225 if (m_groupmap.ContainsKey(agentID))
226 { 226 {
227 m_groupmap.Remove(agentID); 227 m_groupmap.Remove(agentID);
228 } 228 }
229 } 229 }
230 230
231 lock (m_grouplistmap) 231 lock (m_grouplistmap)
232 { 232 {
233 if (m_grouplistmap.ContainsKey(agentID)) 233 if (m_grouplistmap.ContainsKey(agentID))
234 { 234 {
235 m_grouplistmap.Remove(agentID); 235 m_grouplistmap.Remove(agentID);
236 } 236 }
237 } 237 }
238 GC.Collect(); 238 GC.Collect();
239 } 239 }
240 } 240 }
241 241
242 public class GroupData 242 public class GroupData
243 { 243 {
244 public string ActiveGroupTitle; 244 public string ActiveGroupTitle;
245 public LLUUID GroupID; 245 public LLUUID GroupID;
246 public List<LLUUID> GroupMembers; 246 public List<LLUUID> GroupMembers;
247 public string groupName; 247 public string groupName;
248 public uint groupPowers = (uint) (GroupPowers.LandAllowLandmark | GroupPowers.LandAllowSetHome); 248 public uint groupPowers = (uint) (GroupPowers.LandAllowLandmark | GroupPowers.LandAllowSetHome);
249 public List<string> GroupTitles; 249 public List<string> GroupTitles;
250 250
251 public GroupData() 251 public GroupData()
252 { 252 {
253 GroupTitles = new List<string>(); 253 GroupTitles = new List<string>();
254 GroupMembers = new List<LLUUID>(); 254 GroupMembers = new List<LLUUID>();
255 } 255 }
256 256
257 public GroupPowers ActiveGroupPowers 257 public GroupPowers ActiveGroupPowers
258 { 258 {
259 set { groupPowers = (uint) value; } 259 set { groupPowers = (uint) value; }
260 get { return (GroupPowers) groupPowers; } 260 get { return (GroupPowers) groupPowers; }
261 } 261 }
262 } 262 }
263 263
264 public class GroupList 264 public class GroupList
265 { 265 {
266 public List<LLUUID> m_GroupList; 266 public List<LLUUID> m_GroupList;
267 267
268 public GroupList() 268 public GroupList()
269 { 269 {
270 m_GroupList = new List<LLUUID>(); 270 m_GroupList = new List<LLUUID>();
271 } 271 }
272 } 272 }
273} \ No newline at end of file 273} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs b/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs
index cb58b4c..26586a5 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs
@@ -1,158 +1,158 @@
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 OpenSim Project nor the 12 * * Neither the name of the OpenSim 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
28using System.Collections.Generic; 28using System.Collections.Generic;
29using libsecondlife; 29using libsecondlife;
30using Nini.Config; 30using Nini.Config;
31using OpenSim.Framework; 31using OpenSim.Framework;
32using OpenSim.Region.Environment.Interfaces; 32using OpenSim.Region.Environment.Interfaces;
33using OpenSim.Region.Environment.Scenes; 33using OpenSim.Region.Environment.Scenes;
34 34
35namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage 35namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
36{ 36{
37 public class InstantMessageModule : IRegionModule 37 public class InstantMessageModule : IRegionModule
38 { 38 {
39 private readonly List<Scene> m_scenes = new List<Scene>(); 39 private readonly List<Scene> m_scenes = new List<Scene>();
40 40
41 #region IRegionModule Members 41 #region IRegionModule Members
42 42
43 public void Initialise(Scene scene, IConfigSource config) 43 public void Initialise(Scene scene, IConfigSource config)
44 { 44 {
45 lock (m_scenes) 45 lock (m_scenes)
46 { 46 {
47 if (m_scenes.Count == 0) 47 if (m_scenes.Count == 0)
48 { 48 {
49 //scene.AddXmlRPCHandler("avatar_location_update", processPresenceUpdate); 49 //scene.AddXmlRPCHandler("avatar_location_update", processPresenceUpdate);
50 } 50 }
51 51
52 if (!m_scenes.Contains(scene)) 52 if (!m_scenes.Contains(scene))
53 { 53 {
54 m_scenes.Add(scene); 54 m_scenes.Add(scene);
55 scene.EventManager.OnNewClient += OnNewClient; 55 scene.EventManager.OnNewClient += OnNewClient;
56 scene.EventManager.OnGridInstantMessageToIMModule += OnGridInstantMessage; 56 scene.EventManager.OnGridInstantMessageToIMModule += OnGridInstantMessage;
57 } 57 }
58 } 58 }
59 } 59 }
60 60
61 public void PostInitialise() 61 public void PostInitialise()
62 { 62 {
63 } 63 }
64 64
65 public void Close() 65 public void Close()
66 { 66 {
67 } 67 }
68 68
69 public string Name 69 public string Name
70 { 70 {
71 get { return "InstantMessageModule"; } 71 get { return "InstantMessageModule"; }
72 } 72 }
73 73
74 public bool IsSharedModule 74 public bool IsSharedModule
75 { 75 {
76 get { return true; } 76 get { return true; }
77 } 77 }
78 78
79 #endregion 79 #endregion
80 80
81 private void OnNewClient(IClientAPI client) 81 private void OnNewClient(IClientAPI client)
82 { 82 {
83 client.OnInstantMessage += OnInstantMessage; 83 client.OnInstantMessage += OnInstantMessage;
84 } 84 }
85 85
86 private void OnInstantMessage(IClientAPI client, LLUUID fromAgentID, 86 private void OnInstantMessage(IClientAPI client, LLUUID fromAgentID,
87 LLUUID fromAgentSession, LLUUID toAgentID, 87 LLUUID fromAgentSession, LLUUID toAgentID,
88 LLUUID imSessionID, uint timestamp, string fromAgentName, 88 LLUUID imSessionID, uint timestamp, string fromAgentName,
89 string message, byte dialog, bool fromGroup, byte offline, 89 string message, byte dialog, bool fromGroup, byte offline,
90 uint ParentEstateID, LLVector3 Position, LLUUID RegionID, 90 uint ParentEstateID, LLVector3 Position, LLUUID RegionID,
91 byte[] binaryBucket) 91 byte[] binaryBucket)
92 { 92 {
93 bool dialogHandledElsewhere 93 bool dialogHandledElsewhere
94 = ((dialog == 38) || (dialog == 39) || (dialog == 40) 94 = ((dialog == 38) || (dialog == 39) || (dialog == 40)
95 || dialog == (byte) InstantMessageDialog.InventoryOffered 95 || dialog == (byte) InstantMessageDialog.InventoryOffered
96 || dialog == (byte) InstantMessageDialog.InventoryAccepted 96 || dialog == (byte) InstantMessageDialog.InventoryAccepted
97 || dialog == (byte) InstantMessageDialog.InventoryDeclined); 97 || dialog == (byte) InstantMessageDialog.InventoryDeclined);
98 98
99 // IM dialogs need to be pre-processed and have their sessionID filled by the server 99 // IM dialogs need to be pre-processed and have their sessionID filled by the server
100 // so the sim can match the transaction on the return packet. 100 // so the sim can match the transaction on the return packet.
101 101
102 // Don't send a Friend Dialog IM with a LLUUID.Zero session. 102 // Don't send a Friend Dialog IM with a LLUUID.Zero session.
103 if (!(dialogHandledElsewhere && imSessionID == LLUUID.Zero)) 103 if (!(dialogHandledElsewhere && imSessionID == LLUUID.Zero))
104 { 104 {
105 // Try root avatar only first 105 // Try root avatar only first
106 foreach (Scene scene in m_scenes) 106 foreach (Scene scene in m_scenes)
107 { 107 {
108 if (scene.Entities.ContainsKey(toAgentID) && scene.Entities[toAgentID] is ScenePresence) 108 if (scene.Entities.ContainsKey(toAgentID) && scene.Entities[toAgentID] is ScenePresence)
109 { 109 {
110 // Local message 110 // Local message
111 ScenePresence user = (ScenePresence) scene.Entities[toAgentID]; 111 ScenePresence user = (ScenePresence) scene.Entities[toAgentID];
112 if (!user.IsChildAgent) 112 if (!user.IsChildAgent)
113 { 113 {
114 user.ControllingClient.SendInstantMessage(fromAgentID, fromAgentSession, message, 114 user.ControllingClient.SendInstantMessage(fromAgentID, fromAgentSession, message,
115 toAgentID, imSessionID, fromAgentName, dialog, 115 toAgentID, imSessionID, fromAgentName, dialog,
116 timestamp); 116 timestamp);
117 // Message sent 117 // Message sent
118 return; 118 return;
119 } 119 }
120 } 120 }
121 } 121 }
122 122
123 // try child avatar second 123 // try child avatar second
124 foreach (Scene scene in m_scenes) 124 foreach (Scene scene in m_scenes)
125 { 125 {
126 if (scene.Entities.ContainsKey(toAgentID) && scene.Entities[toAgentID] is ScenePresence) 126 if (scene.Entities.ContainsKey(toAgentID) && scene.Entities[toAgentID] is ScenePresence)
127 { 127 {
128 // Local message 128 // Local message
129 ScenePresence user = (ScenePresence) scene.Entities[toAgentID]; 129 ScenePresence user = (ScenePresence) scene.Entities[toAgentID];
130 130
131 user.ControllingClient.SendInstantMessage(fromAgentID, fromAgentSession, message, 131 user.ControllingClient.SendInstantMessage(fromAgentID, fromAgentSession, message,
132 toAgentID, imSessionID, fromAgentName, dialog, 132 toAgentID, imSessionID, fromAgentName, dialog,
133 timestamp); 133 timestamp);
134 // Message sent 134 // Message sent
135 return; 135 return;
136 } 136 }
137 } 137 }
138 } 138 }
139 139
140 140
141 // Still here, try send via Grid 141 // Still here, try send via Grid
142 // TODO 142 // TODO
143 } 143 }
144 144
145 // Trusty OSG1 called method. This method also gets called from the FriendsModule 145 // Trusty OSG1 called method. This method also gets called from the FriendsModule
146 // Turns out the sim has to send an instant message to the user to get it to show an accepted friend. 146 // Turns out the sim has to send an instant message to the user to get it to show an accepted friend.
147 147
148 private void OnGridInstantMessage(GridInstantMessage msg) 148 private void OnGridInstantMessage(GridInstantMessage msg)
149 { 149 {
150 // Trigger the above event handler 150 // Trigger the above event handler
151 OnInstantMessage(null, new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession), 151 OnInstantMessage(null, new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession),
152 new LLUUID(msg.toAgentID), new LLUUID(msg.imSessionID), msg.timestamp, msg.fromAgentName, 152 new LLUUID(msg.toAgentID), new LLUUID(msg.imSessionID), msg.timestamp, msg.fromAgentName,
153 msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID, 153 msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID,
154 new LLVector3(msg.Position.x, msg.Position.y, msg.Position.z), new LLUUID(msg.RegionID), 154 new LLVector3(msg.Position.x, msg.Position.y, msg.Position.z), new LLUUID(msg.RegionID),
155 msg.binaryBucket); 155 msg.binaryBucket);
156 } 156 }
157 } 157 }
158} \ No newline at end of file 158} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Avatar/Inventory/InventoryModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Inventory/InventoryModule.cs
index 2844450..624f307 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/Inventory/InventoryModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/Inventory/InventoryModule.cs
@@ -1,220 +1,220 @@
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 OpenSim Project nor the 12 * * Neither the name of the OpenSim 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
28using System.Collections.Generic; 28using System.Collections.Generic;
29using System.Reflection; 29using System.Reflection;
30using libsecondlife; 30using libsecondlife;
31using log4net; 31using log4net;
32using Nini.Config; 32using Nini.Config;
33using OpenSim.Framework; 33using OpenSim.Framework;
34using OpenSim.Region.Environment.Interfaces; 34using OpenSim.Region.Environment.Interfaces;
35using OpenSim.Region.Environment.Scenes; 35using OpenSim.Region.Environment.Scenes;
36 36
37namespace OpenSim.Region.Environment.Modules.Avatar.Inventory 37namespace OpenSim.Region.Environment.Modules.Avatar.Inventory
38{ 38{
39 public class InventoryModule : IRegionModule 39 public class InventoryModule : IRegionModule
40 { 40 {
41 private static readonly ILog m_log 41 private static readonly ILog m_log
42 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 42 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43 43
44 /// <summary> 44 /// <summary>
45 /// We need to keep track of the pending item offers between clients since the itemId offered only 45 /// We need to keep track of the pending item offers between clients since the itemId offered only
46 /// occurs in the initial offer message, not the accept message. So this dictionary links 46 /// occurs in the initial offer message, not the accept message. So this dictionary links
47 /// IM Session Ids to ItemIds 47 /// IM Session Ids to ItemIds
48 /// </summary> 48 /// </summary>
49 private IDictionary<LLUUID, LLUUID> m_pendingOffers = new Dictionary<LLUUID, LLUUID>(); 49 private IDictionary<LLUUID, LLUUID> m_pendingOffers = new Dictionary<LLUUID, LLUUID>();
50 50
51 private Scene m_scene; 51 private Scene m_scene;
52 52
53 #region IRegionModule Members 53 #region IRegionModule Members
54 54
55 public void Initialise(Scene scene, IConfigSource config) 55 public void Initialise(Scene scene, IConfigSource config)
56 { 56 {
57 m_scene = scene; 57 m_scene = scene;
58 scene.EventManager.OnNewClient += OnNewClient; 58 scene.EventManager.OnNewClient += OnNewClient;
59 } 59 }
60 60
61 public void PostInitialise() 61 public void PostInitialise()
62 { 62 {
63 } 63 }
64 64
65 public void Close() 65 public void Close()
66 { 66 {
67 } 67 }
68 68
69 public string Name 69 public string Name
70 { 70 {
71 get { return "InventoryModule"; } 71 get { return "InventoryModule"; }
72 } 72 }
73 73
74 public bool IsSharedModule 74 public bool IsSharedModule
75 { 75 {
76 get { return false; } 76 get { return false; }
77 } 77 }
78 78
79 #endregion 79 #endregion
80 80
81 private void OnNewClient(IClientAPI client) 81 private void OnNewClient(IClientAPI client)
82 { 82 {
83 // Inventory giving is conducted via instant message 83 // Inventory giving is conducted via instant message
84 client.OnInstantMessage += OnInstantMessage; 84 client.OnInstantMessage += OnInstantMessage;
85 } 85 }
86 86
87 private void OnInstantMessage(IClientAPI client, LLUUID fromAgentID, 87 private void OnInstantMessage(IClientAPI client, LLUUID fromAgentID,
88 LLUUID fromAgentSession, LLUUID toAgentID, 88 LLUUID fromAgentSession, LLUUID toAgentID,
89 LLUUID imSessionID, uint timestamp, string fromAgentName, 89 LLUUID imSessionID, uint timestamp, string fromAgentName,
90 string message, byte dialog, bool fromGroup, byte offline, 90 string message, byte dialog, bool fromGroup, byte offline,
91 uint ParentEstateID, LLVector3 Position, LLUUID RegionID, 91 uint ParentEstateID, LLVector3 Position, LLUUID RegionID,
92 byte[] binaryBucket) 92 byte[] binaryBucket)
93 { 93 {
94 if (dialog == (byte) InstantMessageDialog.InventoryOffered) 94 if (dialog == (byte) InstantMessageDialog.InventoryOffered)
95 { 95 {
96 m_log.DebugFormat( 96 m_log.DebugFormat(
97 "[AGENT INVENTORY]: Routing inventory offering message from {0}, {1} to {2}", 97 "[AGENT INVENTORY]: Routing inventory offering message from {0}, {1} to {2}",
98 client.AgentId, client.Name, toAgentID); 98 client.AgentId, client.Name, toAgentID);
99 99
100 if (m_scene.Entities.ContainsKey(toAgentID) && m_scene.Entities[toAgentID] is ScenePresence) 100 if (m_scene.Entities.ContainsKey(toAgentID) && m_scene.Entities[toAgentID] is ScenePresence)
101 { 101 {
102 ScenePresence user = (ScenePresence) m_scene.Entities[toAgentID]; 102 ScenePresence user = (ScenePresence) m_scene.Entities[toAgentID];
103 103
104 if (!user.IsChildAgent) 104 if (!user.IsChildAgent)
105 { 105 {
106 //byte[] rawId = new byte[16]; 106 //byte[] rawId = new byte[16];
107 107
108 // First byte of the array is probably the item type 108 // First byte of the array is probably the item type
109 // Next 16 bytes are the UUID 109 // Next 16 bytes are the UUID
110 //Array.Copy(binaryBucket, 1, rawId, 0, 16); 110 //Array.Copy(binaryBucket, 1, rawId, 0, 16);
111 111
112 //LLUUID itemId = new LLUUID(new Guid(rawId)); 112 //LLUUID itemId = new LLUUID(new Guid(rawId));
113 LLUUID itemId = new LLUUID(binaryBucket, 1); 113 LLUUID itemId = new LLUUID(binaryBucket, 1);
114 114
115 m_log.DebugFormat( 115 m_log.DebugFormat(
116 "[AGENT INVENTORY]: ItemId for giving is {0}", itemId); 116 "[AGENT INVENTORY]: ItemId for giving is {0}", itemId);
117 117
118 m_pendingOffers[imSessionID] = itemId; 118 m_pendingOffers[imSessionID] = itemId;
119 119
120 user.ControllingClient.SendInstantMessage( 120 user.ControllingClient.SendInstantMessage(
121 fromAgentID, fromAgentSession, message, toAgentID, imSessionID, fromAgentName, 121 fromAgentID, fromAgentSession, message, toAgentID, imSessionID, fromAgentName,
122 dialog, timestamp, binaryBucket); 122 dialog, timestamp, binaryBucket);
123 123
124 return; 124 return;
125 } 125 }
126 else 126 else
127 { 127 {
128 m_log.WarnFormat( 128 m_log.WarnFormat(
129 "[AGENT INVENTORY]: Agent {0} targeted for inventory give by {1}, {2} of {3} was a child agent!", 129 "[AGENT INVENTORY]: Agent {0} targeted for inventory give by {1}, {2} of {3} was a child agent!",
130 toAgentID, client.AgentId, client.Name, message); 130 toAgentID, client.AgentId, client.Name, message);
131 } 131 }
132 } 132 }
133 else 133 else
134 { 134 {
135 m_log.WarnFormat( 135 m_log.WarnFormat(
136 "[AGENT INVENTORY]: Could not find agent {0} for user {1}, {2} to give {3}", 136 "[AGENT INVENTORY]: Could not find agent {0} for user {1}, {2} to give {3}",
137 toAgentID, client.AgentId, client.Name, message); 137 toAgentID, client.AgentId, client.Name, message);
138 } 138 }
139 } 139 }
140 else if (dialog == (byte) InstantMessageDialog.InventoryAccepted) 140 else if (dialog == (byte) InstantMessageDialog.InventoryAccepted)
141 { 141 {
142 m_log.DebugFormat( 142 m_log.DebugFormat(
143 "[AGENT INVENTORY]: Routing inventory accepted message from {0}, {1} to {2}", 143 "[AGENT INVENTORY]: Routing inventory accepted message from {0}, {1} to {2}",
144 client.AgentId, client.Name, toAgentID); 144 client.AgentId, client.Name, toAgentID);
145 145
146 if (m_scene.Entities.ContainsKey(toAgentID) && m_scene.Entities[toAgentID] is ScenePresence) 146 if (m_scene.Entities.ContainsKey(toAgentID) && m_scene.Entities[toAgentID] is ScenePresence)
147 { 147 {
148 ScenePresence user = (ScenePresence) m_scene.Entities[toAgentID]; 148 ScenePresence user = (ScenePresence) m_scene.Entities[toAgentID];
149 149
150 if (!user.IsChildAgent) 150 if (!user.IsChildAgent)
151 { 151 {
152 user.ControllingClient.SendInstantMessage( 152 user.ControllingClient.SendInstantMessage(
153 fromAgentID, fromAgentSession, message, toAgentID, imSessionID, fromAgentName, 153 fromAgentID, fromAgentSession, message, toAgentID, imSessionID, fromAgentName,
154 dialog, timestamp, binaryBucket); 154 dialog, timestamp, binaryBucket);
155 155
156 if (m_pendingOffers.ContainsKey(imSessionID)) 156 if (m_pendingOffers.ContainsKey(imSessionID))
157 { 157 {
158 m_log.DebugFormat( 158 m_log.DebugFormat(
159 "[AGENT INVENTORY]: Accepted item id {0}", m_pendingOffers[imSessionID]); 159 "[AGENT INVENTORY]: Accepted item id {0}", m_pendingOffers[imSessionID]);
160 160
161 // Since the message originates from the accepting client, the toAgentID is 161 // Since the message originates from the accepting client, the toAgentID is
162 // the agent giving the item. 162 // the agent giving the item.
163 m_scene.GiveInventoryItem(client, toAgentID, m_pendingOffers[imSessionID]); 163 m_scene.GiveInventoryItem(client, toAgentID, m_pendingOffers[imSessionID]);
164 164
165 m_pendingOffers.Remove(imSessionID); 165 m_pendingOffers.Remove(imSessionID);
166 } 166 }
167 else 167 else
168 { 168 {
169 m_log.ErrorFormat( 169 m_log.ErrorFormat(
170 "[AGENT INVENTORY]: Could not find an item associated with session id {0} to accept", 170 "[AGENT INVENTORY]: Could not find an item associated with session id {0} to accept",
171 imSessionID); 171 imSessionID);
172 } 172 }
173 173
174 return; 174 return;
175 } 175 }
176 else 176 else
177 { 177 {
178 m_log.WarnFormat( 178 m_log.WarnFormat(
179 "[AGENT INVENTORY]: Agent {0} targeted for inventory give by {1}, {2} of {3} was a child agent!", 179 "[AGENT INVENTORY]: Agent {0} targeted for inventory give by {1}, {2} of {3} was a child agent!",
180 toAgentID, client.AgentId, client.Name, message); 180 toAgentID, client.AgentId, client.Name, message);
181 } 181 }
182 } 182 }
183 else 183 else
184 { 184 {
185 m_log.WarnFormat( 185 m_log.WarnFormat(
186 "[AGENT INVENTORY]: Could not find agent {0} for user {1}, {2} to give {3}", 186 "[AGENT INVENTORY]: Could not find agent {0} for user {1}, {2} to give {3}",
187 toAgentID, client.AgentId, client.Name, message); 187 toAgentID, client.AgentId, client.Name, message);
188 } 188 }
189 } 189 }
190 else if (dialog == (byte) InstantMessageDialog.InventoryDeclined) 190 else if (dialog == (byte) InstantMessageDialog.InventoryDeclined)
191 { 191 {
192 if (m_scene.Entities.ContainsKey(toAgentID) && m_scene.Entities[toAgentID] is ScenePresence) 192 if (m_scene.Entities.ContainsKey(toAgentID) && m_scene.Entities[toAgentID] is ScenePresence)
193 { 193 {
194 ScenePresence user = (ScenePresence) m_scene.Entities[toAgentID]; 194 ScenePresence user = (ScenePresence) m_scene.Entities[toAgentID];
195 195
196 if (!user.IsChildAgent) 196 if (!user.IsChildAgent)
197 { 197 {
198 user.ControllingClient.SendInstantMessage( 198 user.ControllingClient.SendInstantMessage(
199 fromAgentID, fromAgentSession, message, toAgentID, imSessionID, fromAgentName, 199 fromAgentID, fromAgentSession, message, toAgentID, imSessionID, fromAgentName,
200 dialog, timestamp, binaryBucket); 200 dialog, timestamp, binaryBucket);
201 201
202 if (m_pendingOffers.ContainsKey(imSessionID)) 202 if (m_pendingOffers.ContainsKey(imSessionID))
203 { 203 {
204 m_log.DebugFormat( 204 m_log.DebugFormat(
205 "[AGENT INVENTORY]: Declined item id {0}", m_pendingOffers[imSessionID]); 205 "[AGENT INVENTORY]: Declined item id {0}", m_pendingOffers[imSessionID]);
206 206
207 m_pendingOffers.Remove(imSessionID); 207 m_pendingOffers.Remove(imSessionID);
208 } 208 }
209 else 209 else
210 { 210 {
211 m_log.ErrorFormat( 211 m_log.ErrorFormat(
212 "[AGENT INVENTORY]: Could not find an item associated with session id {0} to decline", 212 "[AGENT INVENTORY]: Could not find an item associated with session id {0} to decline",
213 imSessionID); 213 imSessionID);
214 } 214 }
215 } 215 }
216 } 216 }
217 } 217 }
218 } 218 }
219 } 219 }
220} \ No newline at end of file 220} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Avatar/Profiles/AvatarProfilesModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Profiles/AvatarProfilesModule.cs
index 1955d2a..15825b6 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/Profiles/AvatarProfilesModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/Profiles/AvatarProfilesModule.cs
@@ -1,133 +1,133 @@
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 OpenSim Project nor the 12 * * Neither the name of the OpenSim 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
28using System; 28using System;
29using System.Reflection; 29using System.Reflection;
30using libsecondlife; 30using libsecondlife;
31using log4net; 31using log4net;
32using Nini.Config; 32using Nini.Config;
33using OpenSim.Framework; 33using OpenSim.Framework;
34using OpenSim.Region.Environment.Interfaces; 34using OpenSim.Region.Environment.Interfaces;
35using OpenSim.Region.Environment.Scenes; 35using OpenSim.Region.Environment.Scenes;
36 36
37namespace OpenSim.Region.Environment.Modules.Avatar.Profiles 37namespace OpenSim.Region.Environment.Modules.Avatar.Profiles
38{ 38{
39 public class AvatarProfilesModule : IRegionModule 39 public class AvatarProfilesModule : IRegionModule
40 { 40 {
41 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 41 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
42 private Scene m_scene; 42 private Scene m_scene;
43 43
44 public AvatarProfilesModule() 44 public AvatarProfilesModule()
45 { 45 {
46 } 46 }
47 47
48 #region IRegionModule Members 48 #region IRegionModule Members
49 49
50 public void Initialise(Scene scene, IConfigSource config) 50 public void Initialise(Scene scene, IConfigSource config)
51 { 51 {
52 m_scene = scene; 52 m_scene = scene;
53 m_scene.EventManager.OnNewClient += NewClient; 53 m_scene.EventManager.OnNewClient += NewClient;
54 } 54 }
55 55
56 public void PostInitialise() 56 public void PostInitialise()
57 { 57 {
58 } 58 }
59 59
60 public void Close() 60 public void Close()
61 { 61 {
62 } 62 }
63 63
64 public string Name 64 public string Name
65 { 65 {
66 get { return "AvatarProfilesModule"; } 66 get { return "AvatarProfilesModule"; }
67 } 67 }
68 68
69 public bool IsSharedModule 69 public bool IsSharedModule
70 { 70 {
71 get { return false; } 71 get { return false; }
72 } 72 }
73 73
74 #endregion 74 #endregion
75 75
76 public void NewClient(IClientAPI client) 76 public void NewClient(IClientAPI client)
77 { 77 {
78 client.OnRequestAvatarProperties += RequestAvatarProperty; 78 client.OnRequestAvatarProperties += RequestAvatarProperty;
79 client.OnUpdateAvatarProperties += UpdateAvatarProperties; 79 client.OnUpdateAvatarProperties += UpdateAvatarProperties;
80 } 80 }
81 81
82 public void RemoveClient(IClientAPI client) 82 public void RemoveClient(IClientAPI client)
83 { 83 {
84 client.OnRequestAvatarProperties -= RequestAvatarProperty; 84 client.OnRequestAvatarProperties -= RequestAvatarProperty;
85 client.OnUpdateAvatarProperties -= UpdateAvatarProperties; 85 client.OnUpdateAvatarProperties -= UpdateAvatarProperties;
86 } 86 }
87 87
88 /// <summary> 88 /// <summary>
89 /// 89 ///
90 /// </summary> 90 /// </summary>
91 /// <param name="remoteClient"></param> 91 /// <param name="remoteClient"></param>
92 /// <param name="avatarID"></param> 92 /// <param name="avatarID"></param>
93 public void RequestAvatarProperty(IClientAPI remoteClient, LLUUID avatarID) 93 public void RequestAvatarProperty(IClientAPI remoteClient, LLUUID avatarID)
94 { 94 {
95 // FIXME: finish adding fields such as url, masking, etc. 95 // FIXME: finish adding fields such as url, masking, etc.
96 LLUUID partner = new LLUUID("11111111-1111-0000-0000-000100bba000"); 96 LLUUID partner = new LLUUID("11111111-1111-0000-0000-000100bba000");
97 UserProfileData profile = m_scene.CommsManager.UserService.GetUserProfile(avatarID); 97 UserProfileData profile = m_scene.CommsManager.UserService.GetUserProfile(avatarID);
98 if (null != profile) 98 if (null != profile)
99 { 99 {
100 remoteClient.SendAvatarProperties(profile.ID, profile.AboutText, 100 remoteClient.SendAvatarProperties(profile.ID, profile.AboutText,
101 Util.ToDateTime(profile.Created).ToString(), 101 Util.ToDateTime(profile.Created).ToString(),
102 String.Empty, profile.FirstLifeAboutText, profile.CanDoMask, 102 String.Empty, profile.FirstLifeAboutText, profile.CanDoMask,
103 profile.FirstLifeImage, profile.Image, String.Empty, partner); 103 profile.FirstLifeImage, profile.Image, String.Empty, partner);
104 } 104 }
105 else 105 else
106 { 106 {
107 m_log.Debug("[AvatarProfilesModule]: Got null for profile for " + avatarID.ToString()); 107 m_log.Debug("[AvatarProfilesModule]: Got null for profile for " + avatarID.ToString());
108 } 108 }
109 } 109 }
110 110
111 public void UpdateAvatarProperties(IClientAPI remoteClient, UserProfileData newProfile) 111 public void UpdateAvatarProperties(IClientAPI remoteClient, UserProfileData newProfile)
112 { 112 {
113 UserProfileData Profile = m_scene.CommsManager.UserService.GetUserProfile(newProfile.ID); 113 UserProfileData Profile = m_scene.CommsManager.UserService.GetUserProfile(newProfile.ID);
114 114
115 // if it's the profile of the user requesting the update, then we change only a few things. 115 // if it's the profile of the user requesting the update, then we change only a few things.
116 if (remoteClient.AgentId.CompareTo(Profile.ID) == 0) 116 if (remoteClient.AgentId.CompareTo(Profile.ID) == 0)
117 { 117 {
118 Profile.Image = newProfile.Image; 118 Profile.Image = newProfile.Image;
119 Profile.FirstLifeImage = newProfile.FirstLifeImage; 119 Profile.FirstLifeImage = newProfile.FirstLifeImage;
120 Profile.AboutText = newProfile.AboutText; 120 Profile.AboutText = newProfile.AboutText;
121 Profile.FirstLifeAboutText = newProfile.FirstLifeAboutText; 121 Profile.FirstLifeAboutText = newProfile.FirstLifeAboutText;
122 } 122 }
123 else 123 else
124 { 124 {
125 return; 125 return;
126 } 126 }
127 if (m_scene.CommsManager.UserService.UpdateUserProfileProperties(Profile)) 127 if (m_scene.CommsManager.UserService.UpdateUserProfileProperties(Profile))
128 { 128 {
129 RequestAvatarProperty(remoteClient, newProfile.ID); 129 RequestAvatarProperty(remoteClient, newProfile.ID);
130 } 130 }
131 } 131 }
132 } 132 }
133} \ No newline at end of file 133} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Avatar/Voice/AsterixVoice/AsteriskVoiceModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Voice/AsterixVoice/AsteriskVoiceModule.cs
index 44d67e6..f8f6ec2 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/Voice/AsterixVoice/AsteriskVoiceModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/Voice/AsterixVoice/AsteriskVoiceModule.cs
@@ -1,290 +1,290 @@
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 OpenSim Project nor the 12 * * Neither the name of the OpenSim 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
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Reflection; 30using System.Reflection;
31using libsecondlife; 31using libsecondlife;
32using log4net; 32using log4net;
33using Nini.Config; 33using Nini.Config;
34using Nwc.XmlRpc; 34using Nwc.XmlRpc;
35using OpenSim.Framework; 35using OpenSim.Framework;
36using OpenSim.Framework.Communications.Cache; 36using OpenSim.Framework.Communications.Cache;
37using OpenSim.Framework.Servers; 37using OpenSim.Framework.Servers;
38using OpenSim.Region.Capabilities; 38using OpenSim.Region.Capabilities;
39using OpenSim.Region.Environment.Interfaces; 39using OpenSim.Region.Environment.Interfaces;
40using OpenSim.Region.Environment.Scenes; 40using OpenSim.Region.Environment.Scenes;
41using Caps=OpenSim.Region.Capabilities.Caps; 41using Caps=OpenSim.Region.Capabilities.Caps;
42 42
43namespace OpenSim.Region.Environment.Modules.Avatar.Voice.AsterixVoice 43namespace OpenSim.Region.Environment.Modules.Avatar.Voice.AsterixVoice
44{ 44{
45 public class AsteriskVoiceModule : IRegionModule 45 public class AsteriskVoiceModule : IRegionModule
46 { 46 {
47 private static readonly ILog m_log = 47 private static readonly ILog m_log =
48 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 48 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49 49
50 private static readonly string m_parcelVoiceInfoRequestPath = "0007/"; 50 private static readonly string m_parcelVoiceInfoRequestPath = "0007/";
51 private static readonly string m_provisionVoiceAccountRequestPath = "0008/"; 51 private static readonly string m_provisionVoiceAccountRequestPath = "0008/";
52 52
53 private string m_asterisk; 53 private string m_asterisk;
54 private string m_asterisk_password; 54 private string m_asterisk_password;
55 private string m_asterisk_salt; 55 private string m_asterisk_salt;
56 private int m_asterisk_timeout; 56 private int m_asterisk_timeout;
57 private string m_confDomain; 57 private string m_confDomain;
58 private IConfig m_config; 58 private IConfig m_config;
59 private Scene m_scene; 59 private Scene m_scene;
60 private string m_sipDomain; 60 private string m_sipDomain;
61 61
62 #region IRegionModule Members 62 #region IRegionModule Members
63 63
64 public void Initialise(Scene scene, IConfigSource config) 64 public void Initialise(Scene scene, IConfigSource config)
65 { 65 {
66 m_scene = scene; 66 m_scene = scene;
67 m_config = config.Configs["AsteriskVoice"]; 67 m_config = config.Configs["AsteriskVoice"];
68 68
69 if (null == m_config) 69 if (null == m_config)
70 { 70 {
71 m_log.Info("[ASTERISKVOICE] no config found, plugin disabled"); 71 m_log.Info("[ASTERISKVOICE] no config found, plugin disabled");
72 return; 72 return;
73 } 73 }
74 74
75 if (!m_config.GetBoolean("enabled", false)) 75 if (!m_config.GetBoolean("enabled", false))
76 { 76 {
77 m_log.Info("[ASTERISKVOICE] plugin disabled by configuration"); 77 m_log.Info("[ASTERISKVOICE] plugin disabled by configuration");
78 return; 78 return;
79 } 79 }
80 m_log.Info("[ASTERISKVOICE] plugin enabled"); 80 m_log.Info("[ASTERISKVOICE] plugin enabled");
81 81
82 try 82 try
83 { 83 {
84 m_sipDomain = m_config.GetString("sip_domain", String.Empty); 84 m_sipDomain = m_config.GetString("sip_domain", String.Empty);
85 m_log.InfoFormat("[ASTERISKVOICE] using SIP domain {0}", m_sipDomain); 85 m_log.InfoFormat("[ASTERISKVOICE] using SIP domain {0}", m_sipDomain);
86 86
87 m_confDomain = m_config.GetString("conf_domain", String.Empty); 87 m_confDomain = m_config.GetString("conf_domain", String.Empty);
88 m_log.InfoFormat("[ASTERISKVOICE] using conf domain {0}", m_confDomain); 88 m_log.InfoFormat("[ASTERISKVOICE] using conf domain {0}", m_confDomain);
89 89
90 m_asterisk = m_config.GetString("asterisk_frontend", String.Empty); 90 m_asterisk = m_config.GetString("asterisk_frontend", String.Empty);
91 m_asterisk_password = m_config.GetString("asterisk_password", String.Empty); 91 m_asterisk_password = m_config.GetString("asterisk_password", String.Empty);
92 m_asterisk_timeout = m_config.GetInt("asterisk_timeout", 3000); 92 m_asterisk_timeout = m_config.GetInt("asterisk_timeout", 3000);
93 m_asterisk_salt = m_config.GetString("asterisk_salt", "Wuffwuff"); 93 m_asterisk_salt = m_config.GetString("asterisk_salt", "Wuffwuff");
94 if (String.IsNullOrEmpty(m_asterisk)) throw new Exception("missing asterisk_frontend config parameter"); 94 if (String.IsNullOrEmpty(m_asterisk)) throw new Exception("missing asterisk_frontend config parameter");
95 if (String.IsNullOrEmpty(m_asterisk_password)) throw new Exception("missing asterisk_password config parameter"); 95 if (String.IsNullOrEmpty(m_asterisk_password)) throw new Exception("missing asterisk_password config parameter");
96 m_log.InfoFormat("[ASTERISKVOICE] using asterisk front end {0}", m_asterisk); 96 m_log.InfoFormat("[ASTERISKVOICE] using asterisk front end {0}", m_asterisk);
97 97
98 scene.EventManager.OnRegisterCaps += OnRegisterCaps; 98 scene.EventManager.OnRegisterCaps += OnRegisterCaps;
99 } 99 }
100 catch (Exception e) 100 catch (Exception e)
101 { 101 {
102 m_log.ErrorFormat("[ASTERISKVOICE] plugin initialization failed: {0}", e.Message); 102 m_log.ErrorFormat("[ASTERISKVOICE] plugin initialization failed: {0}", e.Message);
103 m_log.DebugFormat("[ASTERISKVOICE] plugin initialization failed: {0}", e.ToString()); 103 m_log.DebugFormat("[ASTERISKVOICE] plugin initialization failed: {0}", e.ToString());
104 return; 104 return;
105 } 105 }
106 } 106 }
107 107
108 public void PostInitialise() 108 public void PostInitialise()
109 { 109 {
110 } 110 }
111 111
112 public void Close() 112 public void Close()
113 { 113 {
114 } 114 }
115 115
116 public string Name 116 public string Name
117 { 117 {
118 get { return "AsteriskVoiceModule"; } 118 get { return "AsteriskVoiceModule"; }
119 } 119 }
120 120
121 public bool IsSharedModule 121 public bool IsSharedModule
122 { 122 {
123 get { return false; } 123 get { return false; }
124 } 124 }
125 125
126 #endregion 126 #endregion
127 127
128 public void OnRegisterCaps(LLUUID agentID, Caps caps) 128 public void OnRegisterCaps(LLUUID agentID, Caps caps)
129 { 129 {
130 m_log.DebugFormat("[ASTERISKVOICE] OnRegisterCaps: agentID {0} caps {1}", agentID, caps); 130 m_log.DebugFormat("[ASTERISKVOICE] OnRegisterCaps: agentID {0} caps {1}", agentID, caps);
131 string capsBase = "/CAPS/" + caps.CapsObjectPath; 131 string capsBase = "/CAPS/" + caps.CapsObjectPath;
132 caps.RegisterHandler("ParcelVoiceInfoRequest", 132 caps.RegisterHandler("ParcelVoiceInfoRequest",
133 new RestStreamHandler("POST", capsBase + m_parcelVoiceInfoRequestPath, 133 new RestStreamHandler("POST", capsBase + m_parcelVoiceInfoRequestPath,
134 delegate(string request, string path, string param) 134 delegate(string request, string path, string param)
135 { 135 {
136 return ParcelVoiceInfoRequest(request, path, param, 136 return ParcelVoiceInfoRequest(request, path, param,
137 agentID, caps); 137 agentID, caps);
138 })); 138 }));
139 caps.RegisterHandler("ProvisionVoiceAccountRequest", 139 caps.RegisterHandler("ProvisionVoiceAccountRequest",
140 new RestStreamHandler("POST", capsBase + m_provisionVoiceAccountRequestPath, 140 new RestStreamHandler("POST", capsBase + m_provisionVoiceAccountRequestPath,
141 delegate(string request, string path, string param) 141 delegate(string request, string path, string param)
142 { 142 {
143 return ProvisionVoiceAccountRequest(request, path, param, 143 return ProvisionVoiceAccountRequest(request, path, param,
144 agentID, caps); 144 agentID, caps);
145 })); 145 }));
146 } 146 }
147 147
148 /// <summary> 148 /// <summary>
149 /// Callback for a client request for ParcelVoiceInfo 149 /// Callback for a client request for ParcelVoiceInfo
150 /// </summary> 150 /// </summary>
151 /// <param name="request"></param> 151 /// <param name="request"></param>
152 /// <param name="path"></param> 152 /// <param name="path"></param>
153 /// <param name="param"></param> 153 /// <param name="param"></param>
154 /// <param name="agentID"></param> 154 /// <param name="agentID"></param>
155 /// <param name="caps"></param> 155 /// <param name="caps"></param>
156 /// <returns></returns> 156 /// <returns></returns>
157 public string ParcelVoiceInfoRequest(string request, string path, string param, 157 public string ParcelVoiceInfoRequest(string request, string path, string param,
158 LLUUID agentID, Caps caps) 158 LLUUID agentID, Caps caps)
159 { 159 {
160 // we need to do: 160 // we need to do:
161 // - send channel_uri: as "sip:regionID@m_sipDomain" 161 // - send channel_uri: as "sip:regionID@m_sipDomain"
162 try 162 try
163 { 163 {
164 m_log.DebugFormat("[ASTERISKVOICE][PARCELVOICE]: request: {0}, path: {1}, param: {2}", 164 m_log.DebugFormat("[ASTERISKVOICE][PARCELVOICE]: request: {0}, path: {1}, param: {2}",
165 request, path, param); 165 request, path, param);
166 166
167 167
168 // setup response to client 168 // setup response to client
169 Hashtable creds = new Hashtable(); 169 Hashtable creds = new Hashtable();
170 creds["channel_uri"] = String.Format("sip:{0}@{1}", 170 creds["channel_uri"] = String.Format("sip:{0}@{1}",
171 m_scene.RegionInfo.RegionID, m_sipDomain); 171 m_scene.RegionInfo.RegionID, m_sipDomain);
172 172
173 string regionName = m_scene.RegionInfo.RegionName; 173 string regionName = m_scene.RegionInfo.RegionName;
174 ScenePresence avatar = m_scene.GetScenePresence(agentID); 174 ScenePresence avatar = m_scene.GetScenePresence(agentID);
175 if (null == m_scene.LandChannel) throw new Exception("land data not yet available"); 175 if (null == m_scene.LandChannel) throw new Exception("land data not yet available");
176 LandData land = m_scene.GetLandData(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); 176 LandData land = m_scene.GetLandData(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
177 177
178 LLSDParcelVoiceInfoResponse parcelVoiceInfo = 178 LLSDParcelVoiceInfoResponse parcelVoiceInfo =
179 new LLSDParcelVoiceInfoResponse(regionName, land.localID, creds); 179 new LLSDParcelVoiceInfoResponse(regionName, land.localID, creds);
180 180
181 string r = LLSDHelpers.SerialiseLLSDReply(parcelVoiceInfo); 181 string r = LLSDHelpers.SerialiseLLSDReply(parcelVoiceInfo);
182 182
183 183
184 // update region on asterisk-opensim frontend 184 // update region on asterisk-opensim frontend
185 Hashtable requestData = new Hashtable(); 185 Hashtable requestData = new Hashtable();
186 requestData["admin_password"] = m_asterisk_password; 186 requestData["admin_password"] = m_asterisk_password;
187 requestData["region"] = m_scene.RegionInfo.RegionID.ToString(); 187 requestData["region"] = m_scene.RegionInfo.RegionID.ToString();
188 if (!String.IsNullOrEmpty(m_confDomain)) 188 if (!String.IsNullOrEmpty(m_confDomain))
189 { 189 {
190 requestData["region"] += String.Format("@{0}", m_confDomain); 190 requestData["region"] += String.Format("@{0}", m_confDomain);
191 } 191 }
192 192
193 ArrayList SendParams = new ArrayList(); 193 ArrayList SendParams = new ArrayList();
194 SendParams.Add(requestData); 194 SendParams.Add(requestData);
195 XmlRpcRequest updateAccountRequest = new XmlRpcRequest("region_update", SendParams); 195 XmlRpcRequest updateAccountRequest = new XmlRpcRequest("region_update", SendParams);
196 XmlRpcResponse updateAccountResponse = updateAccountRequest.Send(m_asterisk, m_asterisk_timeout); 196 XmlRpcResponse updateAccountResponse = updateAccountRequest.Send(m_asterisk, m_asterisk_timeout);
197 Hashtable responseData = (Hashtable) updateAccountResponse.Value; 197 Hashtable responseData = (Hashtable) updateAccountResponse.Value;
198 198
199 if (!responseData.ContainsKey("success")) throw new Exception("region_update call failed"); 199 if (!responseData.ContainsKey("success")) throw new Exception("region_update call failed");
200 200
201 bool success = Convert.ToBoolean((string) responseData["success"]); 201 bool success = Convert.ToBoolean((string) responseData["success"]);
202 if (!success) throw new Exception("region_update failed"); 202 if (!success) throw new Exception("region_update failed");
203 203
204 204
205 m_log.DebugFormat("[ASTERISKVOICE][PARCELVOICE]: {0}", r); 205 m_log.DebugFormat("[ASTERISKVOICE][PARCELVOICE]: {0}", r);
206 return r; 206 return r;
207 } 207 }
208 catch (Exception e) 208 catch (Exception e)
209 { 209 {
210 m_log.ErrorFormat("[ASTERISKVOICE][CAPS][PARCELVOICE]: {0}, retry later", e.Message); 210 m_log.ErrorFormat("[ASTERISKVOICE][CAPS][PARCELVOICE]: {0}, retry later", e.Message);
211 m_log.DebugFormat("[ASTERISKVOICE][CAPS][PARCELVOICE]: {0} failed", e.ToString()); 211 m_log.DebugFormat("[ASTERISKVOICE][CAPS][PARCELVOICE]: {0} failed", e.ToString());
212 212
213 return "<llsd>undef</llsd>"; 213 return "<llsd>undef</llsd>";
214 } 214 }
215 } 215 }
216 216
217 /// <summary> 217 /// <summary>
218 /// Callback for a client request for Voice Account Details 218 /// Callback for a client request for Voice Account Details
219 /// </summary> 219 /// </summary>
220 /// <param name="request"></param> 220 /// <param name="request"></param>
221 /// <param name="path"></param> 221 /// <param name="path"></param>
222 /// <param name="param"></param> 222 /// <param name="param"></param>
223 /// <param name="agentID"></param> 223 /// <param name="agentID"></param>
224 /// <param name="caps"></param> 224 /// <param name="caps"></param>
225 /// <returns></returns> 225 /// <returns></returns>
226 public string ProvisionVoiceAccountRequest(string request, string path, string param, 226 public string ProvisionVoiceAccountRequest(string request, string path, string param,
227 LLUUID agentID, Caps caps) 227 LLUUID agentID, Caps caps)
228 { 228 {
229 // we need to 229 // we need to
230 // - get user data from UserProfileCacheService 230 // - get user data from UserProfileCacheService
231 // - generate nonce for user voice account password 231 // - generate nonce for user voice account password
232 // - issue XmlRpc request to asterisk opensim front end: 232 // - issue XmlRpc request to asterisk opensim front end:
233 // + user: base 64 encoded user name (otherwise SL 233 // + user: base 64 encoded user name (otherwise SL
234 // client is unhappy) 234 // client is unhappy)
235 // + password: nonce 235 // + password: nonce
236 // - the XmlRpc call to asteris-opensim was successful: 236 // - the XmlRpc call to asteris-opensim was successful:
237 // send account details back to client 237 // send account details back to client
238 try 238 try
239 { 239 {
240 m_log.DebugFormat("[ASTERISKVOICE][PROVISIONVOICE]: request: {0}, path: {1}, param: {2}", 240 m_log.DebugFormat("[ASTERISKVOICE][PROVISIONVOICE]: request: {0}, path: {1}, param: {2}",
241 request, path, param); 241 request, path, param);
242 242
243 // get user data & prepare voice account response 243 // get user data & prepare voice account response
244 string voiceUser = "x" + Convert.ToBase64String(agentID.GetBytes()); 244 string voiceUser = "x" + Convert.ToBase64String(agentID.GetBytes());
245 voiceUser = voiceUser.Replace('+', '-').Replace('/', '_'); 245 voiceUser = voiceUser.Replace('+', '-').Replace('/', '_');
246 246
247 CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(agentID); 247 CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(agentID);
248 if (null == userInfo) throw new Exception("cannot get user details"); 248 if (null == userInfo) throw new Exception("cannot get user details");
249 249
250 // we generate a nonce everytime 250 // we generate a nonce everytime
251 string voicePassword = "$1$" + Util.Md5Hash(DateTime.UtcNow.ToLongTimeString() + m_asterisk_salt); 251 string voicePassword = "$1$" + Util.Md5Hash(DateTime.UtcNow.ToLongTimeString() + m_asterisk_salt);
252 LLSDVoiceAccountResponse voiceAccountResponse = 252 LLSDVoiceAccountResponse voiceAccountResponse =
253 new LLSDVoiceAccountResponse(voiceUser, voicePassword); 253 new LLSDVoiceAccountResponse(voiceUser, voicePassword);
254 string r = LLSDHelpers.SerialiseLLSDReply(voiceAccountResponse); 254 string r = LLSDHelpers.SerialiseLLSDReply(voiceAccountResponse);
255 m_log.DebugFormat("[CAPS][PROVISIONVOICE]: {0}", r); 255 m_log.DebugFormat("[CAPS][PROVISIONVOICE]: {0}", r);
256 256
257 257
258 // update user account on asterisk frontend 258 // update user account on asterisk frontend
259 Hashtable requestData = new Hashtable(); 259 Hashtable requestData = new Hashtable();
260 requestData["admin_password"] = m_asterisk_password; 260 requestData["admin_password"] = m_asterisk_password;
261 requestData["username"] = voiceUser; 261 requestData["username"] = voiceUser;
262 if (!String.IsNullOrEmpty(m_sipDomain)) 262 if (!String.IsNullOrEmpty(m_sipDomain))
263 { 263 {
264 requestData["username"] += String.Format("@{0}", m_sipDomain); 264 requestData["username"] += String.Format("@{0}", m_sipDomain);
265 } 265 }
266 requestData["password"] = voicePassword; 266 requestData["password"] = voicePassword;
267 267
268 ArrayList SendParams = new ArrayList(); 268 ArrayList SendParams = new ArrayList();
269 SendParams.Add(requestData); 269 SendParams.Add(requestData);
270 XmlRpcRequest updateAccountRequest = new XmlRpcRequest("account_update", SendParams); 270 XmlRpcRequest updateAccountRequest = new XmlRpcRequest("account_update", SendParams);
271 XmlRpcResponse updateAccountResponse = updateAccountRequest.Send(m_asterisk, m_asterisk_timeout); 271 XmlRpcResponse updateAccountResponse = updateAccountRequest.Send(m_asterisk, m_asterisk_timeout);
272 Hashtable responseData = (Hashtable) updateAccountResponse.Value; 272 Hashtable responseData = (Hashtable) updateAccountResponse.Value;
273 273
274 if (!responseData.ContainsKey("success")) throw new Exception("account_update call failed"); 274 if (!responseData.ContainsKey("success")) throw new Exception("account_update call failed");
275 275
276 bool success = Convert.ToBoolean((string) responseData["success"]); 276 bool success = Convert.ToBoolean((string) responseData["success"]);
277 if (!success) throw new Exception("account_update failed"); 277 if (!success) throw new Exception("account_update failed");
278 278
279 return r; 279 return r;
280 } 280 }
281 catch (Exception e) 281 catch (Exception e)
282 { 282 {
283 m_log.ErrorFormat("[ASTERISKVOICE][CAPS][PROVISIONVOICE]: {0}, retry later", e.Message); 283 m_log.ErrorFormat("[ASTERISKVOICE][CAPS][PROVISIONVOICE]: {0}, retry later", e.Message);
284 m_log.DebugFormat("[ASTERISKVOICE][CAPS][PROVISIONVOICE]: {0} failed", e.ToString()); 284 m_log.DebugFormat("[ASTERISKVOICE][CAPS][PROVISIONVOICE]: {0} failed", e.ToString());
285 285
286 return "<llsd>undef</llsd>"; 286 return "<llsd>undef</llsd>";
287 } 287 }
288 } 288 }
289 } 289 }
290} \ No newline at end of file 290} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Avatar/Voice/SIPVoice/SIPVoiceModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Voice/SIPVoice/SIPVoiceModule.cs
index 8d9ba6f..1527f1e 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/Voice/SIPVoice/SIPVoiceModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/Voice/SIPVoice/SIPVoiceModule.cs
@@ -1,200 +1,200 @@
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 OpenSim Project nor the 12 * * Neither the name of the OpenSim 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
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Reflection; 30using System.Reflection;
31using libsecondlife; 31using libsecondlife;
32using log4net; 32using log4net;
33using Nini.Config; 33using Nini.Config;
34using OpenSim.Framework; 34using OpenSim.Framework;
35using OpenSim.Framework.Communications.Cache; 35using OpenSim.Framework.Communications.Cache;
36using OpenSim.Framework.Servers; 36using OpenSim.Framework.Servers;
37using OpenSim.Region.Capabilities; 37using OpenSim.Region.Capabilities;
38using OpenSim.Region.Environment.Interfaces; 38using OpenSim.Region.Environment.Interfaces;
39using OpenSim.Region.Environment.Scenes; 39using OpenSim.Region.Environment.Scenes;
40using Caps=OpenSim.Region.Capabilities.Caps; 40using Caps=OpenSim.Region.Capabilities.Caps;
41 41
42namespace OpenSim.Region.Environment.Modules.Avatar.Voice.SIPVoice 42namespace OpenSim.Region.Environment.Modules.Avatar.Voice.SIPVoice
43{ 43{
44 public class SIPVoiceModule : IRegionModule 44 public class SIPVoiceModule : IRegionModule
45 { 45 {
46 private static readonly ILog m_log = 46 private static readonly ILog m_log =
47 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 47 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48 48
49 private static readonly string m_parcelVoiceInfoRequestPath = "0007/"; 49 private static readonly string m_parcelVoiceInfoRequestPath = "0007/";
50 private static readonly string m_provisionVoiceAccountRequestPath = "0008/"; 50 private static readonly string m_provisionVoiceAccountRequestPath = "0008/";
51 private IConfig m_config; 51 private IConfig m_config;
52 private Scene m_scene; 52 private Scene m_scene;
53 private string m_sipDomain; 53 private string m_sipDomain;
54 54
55 #region IRegionModule Members 55 #region IRegionModule Members
56 56
57 public void Initialise(Scene scene, IConfigSource config) 57 public void Initialise(Scene scene, IConfigSource config)
58 { 58 {
59 m_scene = scene; 59 m_scene = scene;
60 m_config = config.Configs["Voice"]; 60 m_config = config.Configs["Voice"];
61 61
62 if (null == m_config || !m_config.GetBoolean("enabled", false)) 62 if (null == m_config || !m_config.GetBoolean("enabled", false))
63 { 63 {
64 m_log.Info("[VOICE] plugin disabled"); 64 m_log.Info("[VOICE] plugin disabled");
65 return; 65 return;
66 } 66 }
67 m_log.Info("[VOICE] plugin enabled"); 67 m_log.Info("[VOICE] plugin enabled");
68 68
69 m_sipDomain = m_config.GetString("sip_domain", String.Empty); 69 m_sipDomain = m_config.GetString("sip_domain", String.Empty);
70 if (String.IsNullOrEmpty(m_sipDomain)) 70 if (String.IsNullOrEmpty(m_sipDomain))
71 { 71 {
72 m_log.Error("[VOICE] plugin mis-configured: missing sip_domain configuration"); 72 m_log.Error("[VOICE] plugin mis-configured: missing sip_domain configuration");
73 m_log.Info("[VOICE] plugin disabled"); 73 m_log.Info("[VOICE] plugin disabled");
74 return; 74 return;
75 } 75 }
76 m_log.InfoFormat("[VOICE] using SIP domain {0}", m_sipDomain); 76 m_log.InfoFormat("[VOICE] using SIP domain {0}", m_sipDomain);
77 77
78 scene.EventManager.OnRegisterCaps += OnRegisterCaps; 78 scene.EventManager.OnRegisterCaps += OnRegisterCaps;
79 } 79 }
80 80
81 public void PostInitialise() 81 public void PostInitialise()
82 { 82 {
83 } 83 }
84 84
85 public void Close() 85 public void Close()
86 { 86 {
87 } 87 }
88 88
89 public string Name 89 public string Name
90 { 90 {
91 get { return "VoiceModule"; } 91 get { return "VoiceModule"; }
92 } 92 }
93 93
94 public bool IsSharedModule 94 public bool IsSharedModule
95 { 95 {
96 get { return false; } 96 get { return false; }
97 } 97 }
98 98
99 #endregion 99 #endregion
100 100
101 public void OnRegisterCaps(LLUUID agentID, Caps caps) 101 public void OnRegisterCaps(LLUUID agentID, Caps caps)
102 { 102 {
103 m_log.DebugFormat("[VOICE] OnRegisterCaps: agentID {0} caps {1}", agentID, caps); 103 m_log.DebugFormat("[VOICE] OnRegisterCaps: agentID {0} caps {1}", agentID, caps);
104 string capsBase = "/CAPS/" + caps.CapsObjectPath; 104 string capsBase = "/CAPS/" + caps.CapsObjectPath;
105 caps.RegisterHandler("ParcelVoiceInfoRequest", 105 caps.RegisterHandler("ParcelVoiceInfoRequest",
106 new RestStreamHandler("POST", capsBase + m_parcelVoiceInfoRequestPath, 106 new RestStreamHandler("POST", capsBase + m_parcelVoiceInfoRequestPath,
107 delegate(string request, string path, string param) 107 delegate(string request, string path, string param)
108 { 108 {
109 return ParcelVoiceInfoRequest(request, path, param, 109 return ParcelVoiceInfoRequest(request, path, param,
110 agentID, caps); 110 agentID, caps);
111 })); 111 }));
112 caps.RegisterHandler("ProvisionVoiceAccountRequest", 112 caps.RegisterHandler("ProvisionVoiceAccountRequest",
113 new RestStreamHandler("POST", capsBase + m_provisionVoiceAccountRequestPath, 113 new RestStreamHandler("POST", capsBase + m_provisionVoiceAccountRequestPath,
114 delegate(string request, string path, string param) 114 delegate(string request, string path, string param)
115 { 115 {
116 return ProvisionVoiceAccountRequest(request, path, param, 116 return ProvisionVoiceAccountRequest(request, path, param,
117 agentID, caps); 117 agentID, caps);
118 })); 118 }));
119 } 119 }
120 120
121 /// <summary> 121 /// <summary>
122 /// Callback for a client request for ParcelVoiceInfo 122 /// Callback for a client request for ParcelVoiceInfo
123 /// </summary> 123 /// </summary>
124 /// <param name="request"></param> 124 /// <param name="request"></param>
125 /// <param name="path"></param> 125 /// <param name="path"></param>
126 /// <param name="param"></param> 126 /// <param name="param"></param>
127 /// <param name="agentID"></param> 127 /// <param name="agentID"></param>
128 /// <param name="caps"></param> 128 /// <param name="caps"></param>
129 /// <returns></returns> 129 /// <returns></returns>
130 public string ParcelVoiceInfoRequest(string request, string path, string param, 130 public string ParcelVoiceInfoRequest(string request, string path, string param,
131 LLUUID agentID, Caps caps) 131 LLUUID agentID, Caps caps)
132 { 132 {
133 try 133 try
134 { 134 {
135 m_log.DebugFormat("[VOICE][PARCELVOICE]: request: {0}, path: {1}, param: {2}", request, path, param); 135 m_log.DebugFormat("[VOICE][PARCELVOICE]: request: {0}, path: {1}, param: {2}", request, path, param);
136 136
137 // FIXME: get the creds from region file or from config 137 // FIXME: get the creds from region file or from config
138 Hashtable creds = new Hashtable(); 138 Hashtable creds = new Hashtable();
139 139
140 creds["channel_uri"] = String.Format("sip:{0}@{1}", agentID, m_sipDomain); 140 creds["channel_uri"] = String.Format("sip:{0}@{1}", agentID, m_sipDomain);
141 141
142 string regionName = m_scene.RegionInfo.RegionName; 142 string regionName = m_scene.RegionInfo.RegionName;
143 ScenePresence avatar = m_scene.GetScenePresence(agentID); 143 ScenePresence avatar = m_scene.GetScenePresence(agentID);
144 if (null == m_scene.LandChannel) throw new Exception("land data not yet available"); 144 if (null == m_scene.LandChannel) throw new Exception("land data not yet available");
145 LandData land = m_scene.GetLandData(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); 145 LandData land = m_scene.GetLandData(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
146 146
147 LLSDParcelVoiceInfoResponse parcelVoiceInfo = 147 LLSDParcelVoiceInfoResponse parcelVoiceInfo =
148 new LLSDParcelVoiceInfoResponse(regionName, land.localID, creds); 148 new LLSDParcelVoiceInfoResponse(regionName, land.localID, creds);
149 149
150 string r = LLSDHelpers.SerialiseLLSDReply(parcelVoiceInfo); 150 string r = LLSDHelpers.SerialiseLLSDReply(parcelVoiceInfo);
151 m_log.DebugFormat("[VOICE][PARCELVOICE]: {0}", r); 151 m_log.DebugFormat("[VOICE][PARCELVOICE]: {0}", r);
152 152
153 return r; 153 return r;
154 } 154 }
155 catch (Exception e) 155 catch (Exception e)
156 { 156 {
157 m_log.ErrorFormat("[CAPS]: {0}, try again later", e.ToString()); 157 m_log.ErrorFormat("[CAPS]: {0}, try again later", e.ToString());
158 } 158 }
159 159
160 return null; 160 return null;
161 } 161 }
162 162
163 /// <summary> 163 /// <summary>
164 /// Callback for a client request for Voice Account Details 164 /// Callback for a client request for Voice Account Details
165 /// </summary> 165 /// </summary>
166 /// <param name="request"></param> 166 /// <param name="request"></param>
167 /// <param name="path"></param> 167 /// <param name="path"></param>
168 /// <param name="param"></param> 168 /// <param name="param"></param>
169 /// <param name="agentID"></param> 169 /// <param name="agentID"></param>
170 /// <param name="caps"></param> 170 /// <param name="caps"></param>
171 /// <returns></returns> 171 /// <returns></returns>
172 public string ProvisionVoiceAccountRequest(string request, string path, string param, 172 public string ProvisionVoiceAccountRequest(string request, string path, string param,
173 LLUUID agentID, Caps caps) 173 LLUUID agentID, Caps caps)
174 { 174 {
175 try 175 try
176 { 176 {
177 m_log.DebugFormat("[VOICE][PROVISIONVOICE]: request: {0}, path: {1}, param: {2}", 177 m_log.DebugFormat("[VOICE][PROVISIONVOICE]: request: {0}, path: {1}, param: {2}",
178 request, path, param); 178 request, path, param);
179 179
180 string voiceUser = "x" + Convert.ToBase64String(agentID.GetBytes()); 180 string voiceUser = "x" + Convert.ToBase64String(agentID.GetBytes());
181 voiceUser = voiceUser.Replace('+', '-').Replace('/', '_'); 181 voiceUser = voiceUser.Replace('+', '-').Replace('/', '_');
182 182
183 CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(agentID); 183 CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(agentID);
184 if (null == userInfo) throw new Exception("cannot get user details"); 184 if (null == userInfo) throw new Exception("cannot get user details");
185 185
186 LLSDVoiceAccountResponse voiceAccountResponse = 186 LLSDVoiceAccountResponse voiceAccountResponse =
187 new LLSDVoiceAccountResponse(voiceUser, "$1$" + userInfo.UserProfile.PasswordHash); 187 new LLSDVoiceAccountResponse(voiceUser, "$1$" + userInfo.UserProfile.PasswordHash);
188 string r = LLSDHelpers.SerialiseLLSDReply(voiceAccountResponse); 188 string r = LLSDHelpers.SerialiseLLSDReply(voiceAccountResponse);
189 m_log.DebugFormat("[CAPS][PROVISIONVOICE]: {0}", r); 189 m_log.DebugFormat("[CAPS][PROVISIONVOICE]: {0}", r);
190 return r; 190 return r;
191 } 191 }
192 catch (Exception e) 192 catch (Exception e)
193 { 193 {
194 m_log.ErrorFormat("[CAPS][PROVISIONVOICE]: {0}, retry later", e.Message); 194 m_log.ErrorFormat("[CAPS][PROVISIONVOICE]: {0}, retry later", e.Message);
195 } 195 }
196 196
197 return null; 197 return null;
198 } 198 }
199 } 199 }
200} \ No newline at end of file 200} \ No newline at end of file