aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Avatar
diff options
context:
space:
mode:
authorAdam Frisby2008-04-30 21:43:47 +0000
committerAdam Frisby2008-04-30 21:43:47 +0000
commitbe20f41637b6c06ce3ab16bc25851b6e43468e12 (patch)
treec41081329891f4c24de704fc760fb9012954ac9d /OpenSim/Region/Environment/Modules/Avatar
parent* Sometimes you know, you do something really stupid. (diff)
downloadopensim-SC_OLD-be20f41637b6c06ce3ab16bc25851b6e43468e12.zip
opensim-SC_OLD-be20f41637b6c06ce3ab16bc25851b6e43468e12.tar.gz
opensim-SC_OLD-be20f41637b6c06ce3ab16bc25851b6e43468e12.tar.bz2
opensim-SC_OLD-be20f41637b6c06ce3ab16bc25851b6e43468e12.tar.xz
* Cruft removal step #1. Cleaning Modules directory.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Avatar')
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs349
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/Currency/SampleMoney/SampleMoneyModule.cs1171
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs165
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/Groups/GroupsModule.cs111
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs75
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/Inventory/InventoryModule.cs104
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/Profiles/AvatarProfilesModule.cs6
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/Voice/AsterixVoice/AsteriskVoiceModule.cs81
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/Voice/SIPVoice/SIPVoiceModule.cs47
9 files changed, 1067 insertions, 1042 deletions
diff --git a/OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs
index 1281873..966f5f3 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/Chat/ChatModule.cs
@@ -44,21 +44,21 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
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 47 private string m_defaultzone = null;
48 private List<Scene> m_scenes = new List<Scene>();
49
50 private int m_whisperdistance = 10;
51 private int m_saydistance = 30;
52 private int m_shoutdistance = 100;
53 48
54 private IRCChatModule m_irc = null; 49 private IRCChatModule m_irc = null;
50 private Thread m_irc_connector = null;
55 51
56 private string m_last_new_user = null;
57 private string m_last_leaving_user = null; 52 private string m_last_leaving_user = null;
58 private string m_defaultzone = null; 53 private string m_last_new_user = null;
54 private int m_saydistance = 30;
55 private List<Scene> m_scenes = new List<Scene>();
56 private int m_shoutdistance = 100;
59 internal object m_syncInit = new object(); 57 internal object m_syncInit = new object();
60 internal object m_syncLogout = new object(); 58 internal object m_syncLogout = new object();
61 private Thread m_irc_connector=null; 59 private int m_whisperdistance = 10;
60
61 #region IRegionModule Members
62 62
63 public void Initialise(Scene scene, IConfigSource config) 63 public void Initialise(Scene scene, IConfigSource config)
64 { 64 {
@@ -85,14 +85,17 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
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) { m_irc = new IRCChatModule(config); } 95 if (m_irc == null)
96 {
97 m_irc = new IRCChatModule(config);
98 }
96 if (m_irc_connector == null) 99 if (m_irc_connector == null)
97 { 100 {
98 m_irc_connector = new Thread(IRCConnectRun); 101 m_irc_connector = new Thread(IRCConnectRun);
@@ -142,83 +145,9 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
142 get { return true; } 145 get { return true; }
143 } 146 }
144 147
145 public void NewClient(IClientAPI client) 148 #endregion
146 {
147 try
148 {
149 client.OnChatFromViewer += SimChat;
150 149
151 if ((m_irc.Enabled) && (m_irc.Connected)) 150 #region ISimChat Members
152 {
153 string clientName = client.FirstName + " " + client.LastName;
154 // handles simple case. May not work for hundred connecting in per second.
155 // and the NewClients calles getting interleved
156 // but filters out multiple reports
157 if (clientName != m_last_new_user)
158 {
159 m_last_new_user = clientName;
160 string clientRegion = FindClientRegion(client.FirstName, client.LastName);
161 m_irc.PrivMsg(m_irc.Nick, "Sim", "notices " + clientName + " in "+clientRegion);
162 }
163 }
164 client.OnLogout += ClientLoggedOut;
165 client.OnConnectionClosed += ClientLoggedOut;
166 client.OnLogout += ClientLoggedOut;
167 }
168 catch (Exception ex)
169 {
170 m_log.Error("[IRC]: NewClient exception trap:" + ex.ToString());
171 }
172 }
173
174 public void ClientLoggedOut(IClientAPI client)
175 {
176 lock (m_syncLogout)
177 {
178 try
179 {
180 if ((m_irc.Enabled) && (m_irc.Connected))
181 {
182 string clientName = client.FirstName + " " + client.LastName;
183 string clientRegion = FindClientRegion(client.FirstName, client.LastName);
184 // handles simple case. May not work for hundred connecting in per second.
185 // and the NewClients calles getting interleved
186 // but filters out multiple reports
187 if (clientName != m_last_leaving_user)
188 {
189 m_last_leaving_user = clientName;
190 m_irc.PrivMsg(m_irc.Nick, "Sim", "notices " + clientName + " left " + clientRegion);
191 m_log.Info("[IRC]: IRC watcher notices " + clientName + " left " + clientRegion);
192 }
193 }
194 }
195 catch (Exception ex)
196 {
197 m_log.Error("[IRC]: ClientLoggedOut exception trap:" + ex.ToString());
198 }
199 }
200 }
201
202 private void TrySendChatMessage(ScenePresence presence, LLVector3 fromPos, LLVector3 regionPos,
203 LLUUID fromAgentID, string fromName, ChatTypeEnum type, string message)
204 {
205 if (!presence.IsChildAgent)
206 {
207 LLVector3 fromRegionPos = fromPos + regionPos;
208 LLVector3 toRegionPos = presence.AbsolutePosition + regionPos;
209 int dis = Math.Abs((int) Util.GetDistanceTo(toRegionPos, fromRegionPos));
210
211 if (type == ChatTypeEnum.Whisper && dis > m_whisperdistance ||
212 type == ChatTypeEnum.Say && dis > m_saydistance ||
213 type == ChatTypeEnum.Shout && dis > m_shoutdistance)
214 {
215 return;
216 }
217
218 // TODO: should change so the message is sent through the avatar rather than direct to the ClientView
219 presence.ControllingClient.SendChatMessage(message, (byte) type, fromPos, fromName, fromAgentID);
220 }
221 }
222 151
223 public void SimChat(Object sender, ChatFromViewerArgs e) 152 public void SimChat(Object sender, ChatFromViewerArgs e)
224 { 153 {
@@ -289,7 +218,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
289 m_irc.PrivMsg(fromName, scene.RegionInfo.RegionName, e.Message); 218 m_irc.PrivMsg(fromName, scene.RegionInfo.RegionName, e.Message);
290 } 219 }
291 } 220 }
292 221
293 foreach (Scene s in m_scenes) 222 foreach (Scene s in m_scenes)
294 { 223 {
295 s.ForEachScenePresence(delegate(ScenePresence presence) 224 s.ForEachScenePresence(delegate(ScenePresence presence)
@@ -301,12 +230,92 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
301 } 230 }
302 } 231 }
303 232
233 #endregion
234
235 public void NewClient(IClientAPI client)
236 {
237 try
238 {
239 client.OnChatFromViewer += SimChat;
240
241 if ((m_irc.Enabled) && (m_irc.Connected))
242 {
243 string clientName = client.FirstName + " " + client.LastName;
244 // handles simple case. May not work for hundred connecting in per second.
245 // and the NewClients calles getting interleved
246 // but filters out multiple reports
247 if (clientName != m_last_new_user)
248 {
249 m_last_new_user = clientName;
250 string clientRegion = FindClientRegion(client.FirstName, client.LastName);
251 m_irc.PrivMsg(m_irc.Nick, "Sim", "notices " + clientName + " in " + clientRegion);
252 }
253 }
254 client.OnLogout += ClientLoggedOut;
255 client.OnConnectionClosed += ClientLoggedOut;
256 client.OnLogout += ClientLoggedOut;
257 }
258 catch (Exception ex)
259 {
260 m_log.Error("[IRC]: NewClient exception trap:" + ex.ToString());
261 }
262 }
263
264 public void ClientLoggedOut(IClientAPI client)
265 {
266 lock (m_syncLogout)
267 {
268 try
269 {
270 if ((m_irc.Enabled) && (m_irc.Connected))
271 {
272 string clientName = 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.
275 // and the NewClients calles getting interleved
276 // but filters out multiple reports
277 if (clientName != m_last_leaving_user)
278 {
279 m_last_leaving_user = clientName;
280 m_irc.PrivMsg(m_irc.Nick, "Sim", "notices " + clientName + " left " + clientRegion);
281 m_log.Info("[IRC]: IRC watcher notices " + clientName + " left " + clientRegion);
282 }
283 }
284 }
285 catch (Exception ex)
286 {
287 m_log.Error("[IRC]: ClientLoggedOut exception trap:" + ex.ToString());
288 }
289 }
290 }
291
292 private void TrySendChatMessage(ScenePresence presence, LLVector3 fromPos, LLVector3 regionPos,
293 LLUUID fromAgentID, string fromName, ChatTypeEnum type, string message)
294 {
295 if (!presence.IsChildAgent)
296 {
297 LLVector3 fromRegionPos = fromPos + regionPos;
298 LLVector3 toRegionPos = presence.AbsolutePosition + regionPos;
299 int dis = Math.Abs((int) Util.GetDistanceTo(toRegionPos, fromRegionPos));
300
301 if (type == ChatTypeEnum.Whisper && dis > m_whisperdistance ||
302 type == ChatTypeEnum.Say && dis > m_saydistance ||
303 type == ChatTypeEnum.Shout && dis > m_shoutdistance)
304 {
305 return;
306 }
307
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);
310 }
311 }
312
304 // 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
305 public void IRCConnectRun() 314 public void IRCConnectRun()
306 { 315 {
307 while(true) 316 while (true)
308 { 317 {
309 if ((m_irc.Enabled)&&(!m_irc.Connected)) 318 if ((m_irc.Enabled) && (!m_irc.Connected))
310 { 319 {
311 m_irc.Connect(m_scenes); 320 m_irc.Connect(m_scenes);
312 } 321 }
@@ -314,54 +323,76 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
314 } 323 }
315 } 324 }
316 325
317 public string FindClientRegion(string client_FirstName,string client_LastName) 326 public string FindClientRegion(string client_FirstName, string client_LastName)
318 { 327 {
319 string sourceRegion = null; 328 string sourceRegion = null;
320 foreach (Scene s in m_scenes) 329 foreach (Scene s in m_scenes)
321 { 330 {
322 s.ForEachScenePresence(delegate(ScenePresence presence) 331 s.ForEachScenePresence(delegate(ScenePresence presence)
323 { 332 {
324 if ((presence.IsChildAgent==false) 333 if ((presence.IsChildAgent == false)
325 &&(presence.Firstname==client_FirstName) 334 && (presence.Firstname == client_FirstName)
326 &&(presence.Lastname==client_LastName)) 335 && (presence.Lastname == client_LastName))
327 { 336 {
328 sourceRegion = presence.Scene.RegionInfo.RegionName; 337 sourceRegion = presence.Scene.RegionInfo.RegionName;
329 //sourceRegion= s.RegionInfo.RegionName; 338 //sourceRegion= s.RegionInfo.RegionName;
330 } 339 }
331 }); 340 });
332 if (sourceRegion != null) return sourceRegion; 341 if (sourceRegion != null) return sourceRegion;
342 }
343 if (m_defaultzone == null)
344 {
345 m_defaultzone = "Sim";
333 } 346 }
334 if (m_defaultzone == null) { m_defaultzone = "Sim"; }
335 return m_defaultzone; 347 return m_defaultzone;
336 } 348 }
337 } 349 }
338 350
339 internal class IRCChatModule 351 internal class IRCChatModule
340 { 352 {
353 #region ErrorReplies enum
354
355 public enum ErrorReplies
356 {
357 NotRegistered = 451, // ":You have not registered"
358 NicknameInUse = 433 // "<nick> :Nickname is already in use"
359 }
360
361 #endregion
362
363 #region Replies enum
364
365 public enum Replies
366 {
367 MotdStart = 375, // ":- <server> Message of the day - "
368 Motd = 372, // ":- <text>"
369 EndOfMotd = 376 // ":End of /MOTD command"
370 }
371
372 #endregion
373
341 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;
342 376
343 private string m_server = null;
344 private uint m_port = 6668;
345 private string m_user = "USER OpenSimBot 8 * :I'm a OpenSim to irc bot";
346 private string m_nick = null;
347 private string m_basenick = null; 377 private string m_basenick = null;
348 private string m_channel = null; 378 private string m_channel = null;
379 private bool m_connected = false;
380 private bool m_enabled = false;
381 private List<Scene> m_last_scenes = null;
382 private string m_nick = null;
383 private uint m_port = 6668;
349 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;
386 private List<Scene> m_scenes = null;
387 private string m_server = null;
350 388
351 private NetworkStream m_stream; 389 private NetworkStream m_stream;
390 internal object m_syncConnect = new object();
352 private TcpClient m_tcp; 391 private TcpClient m_tcp;
392 private string m_user = "USER OpenSimBot 8 * :I'm a OpenSim to irc bot";
353 private StreamWriter m_writer; 393 private StreamWriter m_writer;
354 private StreamReader m_reader;
355 394
356 private Thread pingSender; 395 private Thread pingSender;
357 private Thread listener;
358 internal object m_syncConnect = new object();
359
360 private bool m_enabled = false;
361 private bool m_connected = false;
362
363 private List<Scene> m_scenes = null;
364 private List<Scene> m_last_scenes = null;
365 396
366 public IRCChatModule(IConfigSource config) 397 public IRCChatModule(IConfigSource config)
367 { 398 {
@@ -412,6 +443,21 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
412 } 443 }
413 } 444 }
414 445
446 public bool Enabled
447 {
448 get { return m_enabled; }
449 }
450
451 public bool Connected
452 {
453 get { return m_connected; }
454 }
455
456 public string Nick
457 {
458 get { return m_nick; }
459 }
460
415 public bool Connect(List<Scene> scenes) 461 public bool Connect(List<Scene> scenes)
416 { 462 {
417 lock (m_syncConnect) 463 lock (m_syncConnect)
@@ -420,9 +466,12 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
420 { 466 {
421 if (m_connected) return true; 467 if (m_connected) return true;
422 m_scenes = scenes; 468 m_scenes = scenes;
423 if (m_last_scenes == null) { m_last_scenes = scenes; } 469 if (m_last_scenes == null)
470 {
471 m_last_scenes = scenes;
472 }
424 473
425 m_tcp = new TcpClient(m_server, (int)m_port); 474 m_tcp = new TcpClient(m_server, (int) m_port);
426 m_log.Info("[IRC]: Connecting..."); 475 m_log.Info("[IRC]: Connecting...");
427 m_stream = m_tcp.GetStream(); 476 m_stream = m_tcp.GetStream();
428 m_log.Info("[IRC]: Connected to " + m_server); 477 m_log.Info("[IRC]: Connected to " + m_server);
@@ -458,21 +507,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
458 } 507 }
459 } 508 }
460 509
461 public bool Enabled
462 {
463 get { return m_enabled; }
464 }
465
466 public bool Connected
467 {
468 get { return m_connected; }
469 }
470
471 public string Nick
472 {
473 get { return m_nick; }
474 }
475
476 public void Reconnect() 510 public void Reconnect()
477 { 511 {
478 m_connected = false; 512 m_connected = false;
@@ -481,7 +515,10 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
481 m_writer.Close(); 515 m_writer.Close();
482 m_reader.Close(); 516 m_reader.Close();
483 m_tcp.Close(); 517 m_tcp.Close();
484 if (m_enabled) { Connect(m_last_scenes); } 518 if (m_enabled)
519 {
520 Connect(m_last_scenes);
521 }
485 } 522 }
486 523
487 public void PrivMsg(string from, string region, string msg) 524 public void PrivMsg(string from, string region, string msg)
@@ -627,7 +664,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
627 } 664 }
628 } 665 }
629 666
630 public void BroadcastSim(string message,string sender) 667 public void BroadcastSim(string message, string sender)
631 { 668 {
632 LLVector3 pos = new LLVector3(128, 128, 20); 669 LLVector3 pos = new LLVector3(128, 128, 20);
633 try 670 try
@@ -652,23 +689,10 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
652 } 689 }
653 } 690 }
654 691
655 public enum ErrorReplies
656 {
657 NotRegistered = 451, // ":You have not registered"
658 NicknameInUse = 433 // "<nick> :Nickname is already in use"
659 }
660
661 public enum Replies
662 {
663 MotdStart = 375, // ":- <server> Message of the day - "
664 Motd = 372, // ":- <text>"
665 EndOfMotd = 376 // ":End of /MOTD command"
666 }
667
668 public void ProcessIRCCommand(string command) 692 public void ProcessIRCCommand(string command)
669 { 693 {
670 //m_log.Info("[IRC]: ProcessIRCCommand:" + command); 694 //m_log.Info("[IRC]: ProcessIRCCommand:" + command);
671 695
672 string[] commArgs = new string[command.Split(' ').Length]; 696 string[] commArgs = new string[command.Split(' ').Length];
673 string c_server = m_server; 697 string c_server = m_server;
674 698
@@ -690,7 +714,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
690 714
691 if (commArgs[0] == "ERROR") 715 if (commArgs[0] == "ERROR")
692 { 716 {
693 m_log.Error("[IRC]: IRC SERVER ERROR:" + command); 717 m_log.Error("[IRC]: IRC SERVER ERROR:" + command);
694 } 718 }
695 719
696 if (commArgs[0] == "PING") 720 if (commArgs[0] == "PING")
@@ -713,7 +737,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
713 Int32 commandCode = Int32.Parse(commArgs[1]); 737 Int32 commandCode = Int32.Parse(commArgs[1]);
714 switch (commandCode) 738 switch (commandCode)
715 { 739 {
716 case (int)ErrorReplies.NicknameInUse: 740 case (int) ErrorReplies.NicknameInUse:
717 // Gen a new name 741 // Gen a new name
718 m_nick = m_basenick + Util.RandomClass.Next(1, 99); 742 m_nick = m_basenick + Util.RandomClass.Next(1, 99);
719 m_log.Error("[IRC]: IRC SERVER reports NicknameInUse, trying " + m_nick); 743 m_log.Error("[IRC]: IRC SERVER reports NicknameInUse, trying " + m_nick);
@@ -723,9 +747,9 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
723 m_writer.WriteLine("JOIN " + m_channel); 747 m_writer.WriteLine("JOIN " + m_channel);
724 m_writer.Flush(); 748 m_writer.Flush();
725 break; 749 break;
726 case (int)ErrorReplies.NotRegistered: 750 case (int) ErrorReplies.NotRegistered:
727 break; 751 break;
728 case (int)Replies.EndOfMotd: 752 case (int) Replies.EndOfMotd:
729 break; 753 break;
730 } 754 }
731 } 755 }
@@ -733,19 +757,32 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
733 { 757 {
734 } 758 }
735 } 759 }
736 else 760 else
737 { 761 {
738 // Normal message 762 // Normal message
739 string commAct = commArgs[1]; 763 string commAct = commArgs[1];
740 switch (commAct) 764 switch (commAct)
741 { 765 {
742 case "JOIN": eventIrcJoin(commArgs); break; 766 case "JOIN":
743 case "PART": eventIrcPart(commArgs); break; 767 eventIrcJoin(commArgs);
744 case "MODE": eventIrcMode(commArgs); break; 768 break;
745 case "NICK": eventIrcNickChange(commArgs); break; 769 case "PART":
746 case "KICK": eventIrcKick(commArgs); break; 770 eventIrcPart(commArgs);
747 case "QUIT": eventIrcQuit(commArgs); break; 771 break;
748 case "PONG": break; // that's nice 772 case "MODE":
773 eventIrcMode(commArgs);
774 break;
775 case "NICK":
776 eventIrcNickChange(commArgs);
777 break;
778 case "KICK":
779 eventIrcKick(commArgs);
780 break;
781 case "QUIT":
782 eventIrcQuit(commArgs);
783 break;
784 case "PONG":
785 break; // that's nice
749 } 786 }
750 } 787 }
751 } 788 }
@@ -797,7 +834,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
797 { 834 {
798 KickMessage += commArgs[i] + " "; 835 KickMessage += commArgs[i] + " ";
799 } 836 }
800 BroadcastSim(UserKicker + " kicked " + UserKicked +" on "+IrcChannel+" saying "+KickMessage, m_nick); 837 BroadcastSim(UserKicker + " kicked " + UserKicked + " on " + IrcChannel + " saying " + KickMessage, m_nick);
801 if (UserKicked == m_nick) 838 if (UserKicked == m_nick)
802 { 839 {
803 BroadcastSim("Hey, that was me!!!", m_nick); 840 BroadcastSim("Hey, that was me!!!", m_nick);
diff --git a/OpenSim/Region/Environment/Modules/Avatar/Currency/SampleMoney/SampleMoneyModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Currency/SampleMoney/SampleMoneyModule.cs
index 0e058ec..181984e 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/Currency/SampleMoney/SampleMoneyModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/Currency/SampleMoney/SampleMoneyModule.cs
@@ -53,7 +53,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
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
57 public delegate void ObjectPaid(LLUUID objectID, LLUUID agentID, int amount); 56 public delegate void ObjectPaid(LLUUID objectID, LLUUID agentID, int amount);
58 57
59 public interface IMoneyModule : IRegionModule 58 public interface IMoneyModule : IRegionModule
@@ -65,37 +64,39 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
65 64
66 public class SampleMoneyModule : IMoneyModule 65 public class SampleMoneyModule : IMoneyModule
67 { 66 {
68 public event ObjectPaid OnObjectPaid;
69
70 private ObjectPaid handerOnObjectPaid;
71
72 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 67 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
73 68
74 /// <summary>
75 /// Region UUIDS indexed by AgentID
76 /// </summary>
77 Dictionary<LLUUID, LLUUID> m_rootAgents = new Dictionary<LLUUID, LLUUID>();
78
79 /// <summary> 69 /// <summary>
80 /// Scenes by Region Handle 70 /// Where Stipends come from and Fees go to.
81 /// </summary> 71 /// </summary>
82 private Dictionary<ulong,Scene> m_scenel = new Dictionary<ulong,Scene>(); 72 private LLUUID EconomyBaseAccount = LLUUID.Zero;
73
74 private float EnergyEfficiency = 0f;
75 private bool gridmode = false;
76 private ObjectPaid handerOnObjectPaid;
77 private bool m_enabled = true;
83 78
84 private IConfigSource m_gConfig; 79 private IConfigSource m_gConfig;
85 80
86 private bool m_keepMoneyAcrossLogins = true; 81 private bool m_keepMoneyAcrossLogins = true;
82 private Dictionary<LLUUID, int> m_KnownClientFunds = new Dictionary<LLUUID, int>();
83 private string m_LandAddress = String.Empty;
87 84
88 private int m_minFundsBeforeRefresh = 100; 85 private int m_minFundsBeforeRefresh = 100;
86 private string m_MoneyAddress = String.Empty;
89 87
90 private int m_stipend = 1000; 88 /// <summary>
89 /// Region UUIDS indexed by AgentID
90 /// </summary>
91 private Dictionary<LLUUID, LLUUID> m_rootAgents = new Dictionary<LLUUID, LLUUID>();
91 92
92 private bool m_enabled = true; 93 /// <summary>
94 /// Scenes by Region Handle
95 /// </summary>
96 private Dictionary<ulong, Scene> m_scenel = new Dictionary<ulong, Scene>();
93 97
94 private Dictionary<LLUUID, int> m_KnownClientFunds = new Dictionary<LLUUID, int>(); 98 private int m_stipend = 1000;
95 99
96 private bool gridmode = false;
97 private Scene XMLRPCHandler;
98 private float EnergyEfficiency = 0f;
99 private int ObjectCapacity = 45000; 100 private int ObjectCapacity = 45000;
100 private int ObjectCount = 0; 101 private int ObjectCount = 0;
101 private int PriceEnergyUnit = 0; 102 private int PriceEnergyUnit = 0;
@@ -111,16 +112,14 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
111 private int PriceRentLight = 0; 112 private int PriceRentLight = 0;
112 private int PriceUpload = 0; 113 private int PriceUpload = 0;
113 private int TeleportMinPrice = 0; 114 private int TeleportMinPrice = 0;
115
116 private float TeleportPriceExponent = 0f;
114 private int UserLevelPaysFees = 2; 117 private int UserLevelPaysFees = 2;
115 private string m_MoneyAddress = String.Empty; 118 private Scene XMLRPCHandler;
116 private string m_LandAddress = String.Empty;
117 119
118 float TeleportPriceExponent = 0f; 120 #region IMoneyModule Members
119 121
120 /// <summary> 122 public event ObjectPaid OnObjectPaid;
121 /// Where Stipends come from and Fees go to.
122 /// </summary>
123 LLUUID EconomyBaseAccount = LLUUID.Zero;
124 123
125 /// <summary> 124 /// <summary>
126 /// Startup 125 /// Startup
@@ -130,12 +129,12 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
130 public void Initialise(Scene scene, IConfigSource config) 129 public void Initialise(Scene scene, IConfigSource config)
131 { 130 {
132 m_gConfig = config; 131 m_gConfig = config;
133 132
134 IConfig startupConfig = m_gConfig.Configs["Startup"]; 133 IConfig startupConfig = m_gConfig.Configs["Startup"];
135 IConfig economyConfig = m_gConfig.Configs["Economy"]; 134 IConfig economyConfig = m_gConfig.Configs["Economy"];
136 135
137 scene.RegisterModuleInterface<IMoneyModule>(this); 136 scene.RegisterModuleInterface<IMoneyModule>(this);
138 137
139 ReadConfigAndPopulate(scene, startupConfig, "Startup"); 138 ReadConfigAndPopulate(scene, startupConfig, "Startup");
140 ReadConfigAndPopulate(scene, economyConfig, "Economy"); 139 ReadConfigAndPopulate(scene, economyConfig, "Economy");
141 140
@@ -167,8 +166,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
167 scene.AddXmlRPCHandler("preflightBuyLandPrep", preflightBuyLandPrep_func); 166 scene.AddXmlRPCHandler("preflightBuyLandPrep", preflightBuyLandPrep_func);
168 scene.AddXmlRPCHandler("buyLandPrep", landBuy_func); 167 scene.AddXmlRPCHandler("buyLandPrep", landBuy_func);
169 } 168 }
170
171
172 } 169 }
173 170
174 if (m_scenel.ContainsKey(scene.RegionInfo.RegionHandle)) 171 if (m_scenel.ContainsKey(scene.RegionInfo.RegionHandle))
@@ -180,7 +177,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
180 m_scenel.Add(scene.RegionInfo.RegionHandle, scene); 177 m_scenel.Add(scene.RegionInfo.RegionHandle, scene);
181 } 178 }
182 } 179 }
183 180
184 scene.EventManager.OnNewClient += OnNewClient; 181 scene.EventManager.OnNewClient += OnNewClient;
185 scene.EventManager.OnMoneyTransfer += MoneyTransferAction; 182 scene.EventManager.OnMoneyTransfer += MoneyTransferAction;
186 scene.EventManager.OnClientClosed += ClientClosed; 183 scene.EventManager.OnClientClosed += ClientClosed;
@@ -189,9 +186,41 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
189 scene.EventManager.OnClientClosed += ClientLoggedOut; 186 scene.EventManager.OnClientClosed += ClientLoggedOut;
190 scene.EventManager.OnValidateLandBuy += ValidateLandBuy; 187 scene.EventManager.OnValidateLandBuy += ValidateLandBuy;
191 scene.EventManager.OnLandBuy += processLandBuy; 188 scene.EventManager.OnLandBuy += processLandBuy;
192
193 } 189 }
194 } 190 }
191
192 public bool ObjectGiveMoney(LLUUID objectID, LLUUID fromID, LLUUID toID, int amount)
193 {
194 string description = String.Format("Object {0} pays {1}", resolveObjectName(objectID), resolveAgentName(toID));
195
196 bool give_result = doMoneyTransfer(fromID, toID, amount, 2, description);
197
198 if (m_MoneyAddress.Length == 0)
199 BalanceUpdate(fromID, toID, give_result, description);
200
201 return give_result;
202 }
203
204 public void PostInitialise()
205 {
206 }
207
208 public void Close()
209 {
210 }
211
212 public string Name
213 {
214 get { return "BetaGridLikeMoneyModule"; }
215 }
216
217 public bool IsSharedModule
218 {
219 get { return true; }
220 }
221
222 #endregion
223
195 /// <summary> 224 /// <summary>
196 /// Parse Configuration 225 /// Parse Configuration
197 /// </summary> 226 /// </summary>
@@ -207,7 +236,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
207 } 236 }
208 237
209 if (config == "Economy" && startupConfig != null) 238 if (config == "Economy" && startupConfig != null)
210 { 239 {
211 ObjectCapacity = startupConfig.GetInt("ObjectCapacity", 45000); 240 ObjectCapacity = startupConfig.GetInt("ObjectCapacity", 45000);
212 PriceEnergyUnit = startupConfig.GetInt("PriceEnergyUnit", 100); 241 PriceEnergyUnit = startupConfig.GetInt("PriceEnergyUnit", 100);
213 PriceObjectClaim = startupConfig.GetInt("PriceObjectClaim", 10); 242 PriceObjectClaim = startupConfig.GetInt("PriceObjectClaim", 10);
@@ -225,7 +254,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
225 PriceParcelRent = startupConfig.GetInt("PriceParcelRent", 1); 254 PriceParcelRent = startupConfig.GetInt("PriceParcelRent", 1);
226 PriceGroupCreate = startupConfig.GetInt("PriceGroupCreate", -1); 255 PriceGroupCreate = startupConfig.GetInt("PriceGroupCreate", -1);
227 string EBA = startupConfig.GetString("EconomyBaseAccount", LLUUID.Zero.ToString()); 256 string EBA = startupConfig.GetString("EconomyBaseAccount", LLUUID.Zero.ToString());
228 Helpers.TryParse(EBA,out EconomyBaseAccount); 257 Helpers.TryParse(EBA, out EconomyBaseAccount);
229 258
230 UserLevelPaysFees = startupConfig.GetInt("UserLevelPaysFees", -1); 259 UserLevelPaysFees = startupConfig.GetInt("UserLevelPaysFees", -1);
231 m_stipend = startupConfig.GetInt("UserStipend", 500); 260 m_stipend = startupConfig.GetInt("UserStipend", 500);
@@ -234,7 +263,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
234 m_MoneyAddress = startupConfig.GetString("CurrencyServer", String.Empty); 263 m_MoneyAddress = startupConfig.GetString("CurrencyServer", String.Empty);
235 m_LandAddress = startupConfig.GetString("LandServer", String.Empty); 264 m_LandAddress = startupConfig.GetString("LandServer", String.Empty);
236 } 265 }
237 266
238 // Send ObjectCapacity to Scene.. Which sends it to the SimStatsReporter. 267 // Send ObjectCapacity to Scene.. Which sends it to the SimStatsReporter.
239 scene.SetObjectCapacity(ObjectCapacity); 268 scene.SetObjectCapacity(ObjectCapacity);
240 } 269 }
@@ -253,7 +282,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
253 { 282 {
254 if (m_MoneyAddress.Length == 0) 283 if (m_MoneyAddress.Length == 0)
255 { 284 {
256
257 CheckExistAndRefreshFunds(client.AgentId); 285 CheckExistAndRefreshFunds(client.AgentId);
258 } 286 }
259 else 287 else
@@ -273,15 +301,16 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
273 //s.RegionInfo.RegionHandle; 301 //s.RegionInfo.RegionHandle;
274 LLUUID agentID = LLUUID.Zero; 302 LLUUID agentID = LLUUID.Zero;
275 int funds = 0; 303 int funds = 0;
276
277 Hashtable hbinfo = GetBalanceForUserFromMoneyServer(client.AgentId, client.SecureSessionId, s.RegionInfo.originRegionID.ToString(), s.RegionInfo.regionSecret);
278 if ((bool)hbinfo["success"] == true)
279 {
280 304
281 Helpers.TryParse((string)hbinfo["agentId"], out agentID); 305 Hashtable hbinfo =
306 GetBalanceForUserFromMoneyServer(client.AgentId, client.SecureSessionId, s.RegionInfo.originRegionID.ToString(),
307 s.RegionInfo.regionSecret);
308 if ((bool) hbinfo["success"] == true)
309 {
310 Helpers.TryParse((string) hbinfo["agentId"], out agentID);
282 try 311 try
283 { 312 {
284 funds = (Int32)hbinfo["funds"]; 313 funds = (Int32) hbinfo["funds"];
285 } 314 }
286 catch (ArgumentException) 315 catch (ArgumentException)
287 { 316 {
@@ -303,340 +332,27 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
303 } 332 }
304 else 333 else
305 { 334 {
306 m_log.WarnFormat("[MONEY]: Getting Money for user {0} failed with the following message:{1}", agentID, (string)hbinfo["errorMessage"]); 335 m_log.WarnFormat("[MONEY]: Getting Money for user {0} failed with the following message:{1}", agentID,
307 client.SendAlertMessage((string)hbinfo["errorMessage"]); 336 (string) hbinfo["errorMessage"]);
337 client.SendAlertMessage((string) hbinfo["errorMessage"]);
308 } 338 }
309 SendMoneyBalance(client, agentID, client.SessionId, LLUUID.Zero); 339 SendMoneyBalance(client, agentID, client.SessionId, LLUUID.Zero);
310
311 } 340 }
312 } 341 }
313
314 } 342 }
315 else 343 else
316 { 344 {
317 CheckExistAndRefreshFunds(client.AgentId); 345 CheckExistAndRefreshFunds(client.AgentId);
318 } 346 }
319 347
320 // Subscribe to Money messages 348 // Subscribe to Money messages
321 client.OnEconomyDataRequest += EconomyDataRequestHandler; 349 client.OnEconomyDataRequest += EconomyDataRequestHandler;
322 client.OnMoneyBalanceRequest += SendMoneyBalance; 350 client.OnMoneyBalanceRequest += SendMoneyBalance;
323 client.OnRequestPayPrice += requestPayPrice; 351 client.OnRequestPayPrice += requestPayPrice;
324 client.OnLogout += ClientClosed; 352 client.OnLogout += ClientClosed;
325
326
327 }
328
329 #region event Handlers
330
331 public void requestPayPrice(IClientAPI client, LLUUID objectID)
332 {
333 Scene scene=LocateSceneClientIn(client.AgentId);
334 if(scene == null)
335 return;
336
337 SceneObjectPart task=scene.GetSceneObjectPart(objectID);
338 if(task == null)
339 return;
340 SceneObjectGroup group=task.ParentGroup;
341 SceneObjectPart root=group.RootPart;
342
343 client.SendPayPrice(objectID, root.PayPrice);
344 }
345
346 /// <summary>
347 /// When the client closes the connection we remove their accounting info from memory to free up resources.
348 /// </summary>
349 /// <param name="AgentID"></param>
350 public void ClientClosed(LLUUID AgentID)
351 {
352 lock (m_KnownClientFunds)
353 {
354 if (m_keepMoneyAcrossLogins && m_MoneyAddress.Length == 0)
355 {
356 }
357 else
358 {
359 m_KnownClientFunds.Remove(AgentID);
360 }
361 }
362 }
363
364 /// <summary>
365 /// Event called Economy Data Request handler.
366 /// </summary>
367 /// <param name="agentId"></param>
368 public void EconomyDataRequestHandler(LLUUID agentId)
369 {
370 IClientAPI user = LocateClientObject(agentId);
371
372 if (user != null)
373 {
374 user.SendEconomyData(EnergyEfficiency, ObjectCapacity, ObjectCount, PriceEnergyUnit, PriceGroupCreate,
375 PriceObjectClaim, PriceObjectRent, PriceObjectScaleFactor, PriceParcelClaim, PriceParcelClaimFactor,
376 PriceParcelRent, PricePublicObjectDecay, PricePublicObjectDelete, PriceRentLight, PriceUpload,
377 TeleportMinPrice, TeleportPriceExponent);
378 }
379 }
380
381 private void ValidateLandBuy (Object osender, EventManager.LandBuyArgs e)
382 {
383 if (m_MoneyAddress.Length == 0)
384 {
385 lock (m_KnownClientFunds)
386 {
387 if (m_KnownClientFunds.ContainsKey(e.agentId))
388 {
389 // Does the sender have enough funds to give?
390 if (m_KnownClientFunds[e.agentId] >= e.parcelPrice)
391 {
392 lock(e)
393 {
394 e.economyValidated=true;
395 }
396 }
397 }
398 }
399 }
400 else
401 {
402 if(GetRemoteBalance(e.agentId) >= e.parcelPrice)
403 {
404 lock(e)
405 {
406 e.economyValidated=true;
407 }
408 }
409 }
410 }
411
412 private void processLandBuy(Object osender, EventManager.LandBuyArgs e)
413 {
414 lock(e)
415 {
416 if(e.economyValidated == true && e.transactionID == 0)
417 {
418 e.transactionID=Util.UnixTimeSinceEpoch();
419
420 if(doMoneyTransfer(e.agentId, e.parcelOwnerID, e.parcelPrice, 0, "Land purchase"))
421 {
422 lock (e)
423 {
424 e.amountDebited = e.parcelPrice;
425 }
426 }
427 }
428 }
429 } 353 }
430 354
431 /// <summary> 355 /// <summary>
432 /// THis method gets called when someone pays someone else as a gift.
433 /// </summary>
434 /// <param name="osender"></param>
435 /// <param name="e"></param>
436 private void MoneyTransferAction (Object osender, EventManager.MoneyTransferArgs e)
437 {
438 IClientAPI sender = null;
439 IClientAPI receiver = null;
440
441 if(m_MoneyAddress.Length > 0) // Handled on server
442 e.description=String.Empty;
443
444 if(e.transactiontype == 5008) // Object gets paid
445 {
446 sender = LocateClientObject(e.sender);
447 if (sender != null)
448 {
449 SceneObjectPart part=findPrim(e.receiver);
450 if(part == null)
451 return;
452
453 string name=resolveAgentName(part.OwnerID);
454 if(name == String.Empty)
455 name="(hippos)";
456
457 receiver = LocateClientObject(part.OwnerID);
458
459 string description=String.Format("Paid {0} via object {1}", name, e.description);
460 bool transactionresult = doMoneyTransfer(e.sender, part.OwnerID, e.amount, e.transactiontype, description);
461
462 if(transactionresult)
463 {
464 ObjectPaid handlerOnObjectPaid = OnObjectPaid;
465 if(handlerOnObjectPaid != null)
466 {
467 handlerOnObjectPaid(e.receiver, e.sender, e.amount);
468 }
469 }
470
471 if (e.sender != e.receiver)
472 {
473 sender.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.sender));
474 }
475 if(receiver != null)
476 {
477 receiver.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(part.OwnerID));
478 }
479 }
480 return;
481 }
482
483 sender = LocateClientObject(e.sender);
484 if (sender != null)
485 {
486 receiver = LocateClientObject(e.receiver);
487
488 bool transactionresult = doMoneyTransfer(e.sender, e.receiver, e.amount, e.transactiontype, e.description);
489
490 if (e.sender != e.receiver)
491 {
492 if (sender != null)
493 {
494 sender.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.sender));
495 }
496 }
497
498 if (receiver != null)
499 {
500 receiver.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.receiver));
501 }
502 }
503 else
504 {
505 m_log.Warn("[MONEY]: Potential Fraud Warning, got money transfer request for avatar that isn't in this simulator - Details; Sender:" + e.sender.ToString() + " Receiver: " + e.receiver.ToString() + " Amount: " + e.amount.ToString());
506 }
507 }
508
509 /// <summary>
510 /// Event Handler for when a root agent becomes a child agent
511 /// </summary>
512 /// <param name="avatar"></param>
513 private void MakeChildAgent(ScenePresence avatar)
514 {
515 lock (m_rootAgents)
516 {
517 if (m_rootAgents.ContainsKey(avatar.UUID))
518 {
519 if (m_rootAgents[avatar.UUID] == avatar.Scene.RegionInfo.originRegionID)
520 {
521 m_rootAgents.Remove(avatar.UUID);
522 m_log.Info("[MONEY]: Removing " + avatar.Firstname + " " + avatar.Lastname + " as a root agent");
523 }
524
525 }
526 }
527
528 }
529
530 /// <summary>
531 /// Event Handler for when the client logs out.
532 /// </summary>
533 /// <param name="AgentId"></param>
534 private void ClientLoggedOut(LLUUID AgentId)
535 {
536 lock (m_rootAgents)
537 {
538 if (m_rootAgents.ContainsKey(AgentId))
539 {
540 m_rootAgents.Remove(AgentId);
541 //m_log.Info("[MONEY]: Removing " + AgentId + ". Agent logged out.");
542 }
543 }
544 }
545
546 /// <summary>
547 /// Call this when the client disconnects.
548 /// </summary>
549 /// <param name="client"></param>
550 public void ClientClosed(IClientAPI client)
551 {
552 ClientClosed(client.AgentId);
553 }
554
555 /// <summary>
556 /// Event Handler for when an Avatar enters one of the parcels in the simulator.
557 /// </summary>
558 /// <param name="avatar"></param>
559 /// <param name="localLandID"></param>
560 /// <param name="regionID"></param>
561 private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, LLUUID regionID)
562 {
563 lock (m_rootAgents)
564 {
565 if (m_rootAgents.ContainsKey(avatar.UUID))
566 {
567 if (avatar.Scene.RegionInfo.originRegionID != m_rootAgents[avatar.UUID])
568 {
569 m_rootAgents[avatar.UUID] = avatar.Scene.RegionInfo.originRegionID;
570 //m_log.Info("[MONEY]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + ".");
571 // Claim User! my user! Mine mine mine!
572 if (m_MoneyAddress.Length > 0)
573 {
574 Scene RegionItem = GetSceneByUUID(regionID);
575 if (RegionItem != null)
576 {
577 Hashtable hresult = claim_user(avatar.UUID, avatar.ControllingClient.SecureSessionId, regionID, RegionItem.RegionInfo.regionSecret);
578 if ((bool)hresult["success"] == true)
579 {
580 int funds = 0;
581 try
582 {
583 funds = (Int32)hresult["funds"];
584 }
585 catch (InvalidCastException)
586 {
587
588 }
589 SetLocalFundsForAgentID(avatar.UUID, funds);
590 }
591 else
592 {
593 avatar.ControllingClient.SendAgentAlertMessage((string)hresult["errorMessage"], true);
594 }
595 }
596 }
597 }
598 }
599 else
600 {
601 lock (m_rootAgents)
602 {
603 m_rootAgents.Add(avatar.UUID, avatar.Scene.RegionInfo.originRegionID);
604 }
605 if (m_MoneyAddress.Length > 0)
606 {
607 Scene RegionItem = GetSceneByUUID(regionID);
608 if (RegionItem != null)
609 {
610 Hashtable hresult = claim_user(avatar.UUID, avatar.ControllingClient.SecureSessionId, regionID, RegionItem.RegionInfo.regionSecret);
611 if ((bool)hresult["success"] == true)
612 {
613 int funds = 0;
614 try
615 {
616 funds = (Int32)hresult["funds"];
617 }
618 catch (InvalidCastException)
619 {
620
621 }
622 SetLocalFundsForAgentID(avatar.UUID, funds);
623 }
624 else
625 {
626 avatar.ControllingClient.SendAgentAlertMessage((string)hresult["errorMessage"], true);
627 }
628 }
629 }
630
631 //m_log.Info("[MONEY]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + ".");
632 }
633 }
634 //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString());
635 }
636
637 #endregion
638
639 /// <summary>
640 /// Transfer money 356 /// Transfer money
641 /// </summary> 357 /// </summary>
642 /// <param name="Sender"></param> 358 /// <param name="Sender"></param>
@@ -695,96 +411,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
695 return result; 411 return result;
696 } 412 }
697 413
698 #region Utility Helpers
699 /// <summary>
700 /// Locates a IClientAPI for the client specified
701 /// </summary>
702 /// <param name="AgentID"></param>
703 /// <returns></returns>
704 private IClientAPI LocateClientObject(LLUUID AgentID)
705 {
706 ScenePresence tPresence = null;
707 IClientAPI rclient = null;
708
709 lock (m_scenel)
710 {
711 foreach (Scene _scene in m_scenel.Values)
712 {
713 tPresence = _scene.GetScenePresence(AgentID);
714 if (tPresence != null)
715 {
716 if (!tPresence.IsChildAgent)
717 {
718 rclient = tPresence.ControllingClient;
719 }
720 }
721 if (rclient != null)
722 {
723 return rclient;
724 }
725 }
726
727 }
728 return null;
729 }
730
731 private Scene LocateSceneClientIn(LLUUID AgentId)
732 {
733 lock (m_scenel)
734 {
735 foreach (Scene _scene in m_scenel.Values)
736 {
737 ScenePresence tPresence = _scene.GetScenePresence(AgentId);
738 if (tPresence != null)
739 {
740 if (!tPresence.IsChildAgent)
741 {
742 return _scene;
743 }
744 }
745
746 }
747
748 }
749 return null;
750 }
751
752 /// <summary>
753 /// Utility function Gets a Random scene in the instance. For when which scene exactly you're doing something with doesn't matter
754 /// </summary>
755 /// <returns></returns>
756 public Scene GetRandomScene()
757 {
758 lock (m_scenel)
759 {
760 foreach (Scene rs in m_scenel.Values)
761 return rs;
762 }
763 return null;
764
765 }
766 /// <summary>
767 /// Utility function to get a Scene by RegionID in a module
768 /// </summary>
769 /// <param name="RegionID"></param>
770 /// <returns></returns>
771 public Scene GetSceneByUUID(LLUUID RegionID)
772 {
773 lock (m_scenel)
774 {
775 foreach (Scene rs in m_scenel.Values)
776 {
777 if (rs.RegionInfo.originRegionID == RegionID)
778 {
779 return rs;
780 }
781 }
782 }
783 return null;
784 }
785 #endregion
786
787
788 414
789 /// <summary> 415 /// <summary>
790 /// Sends the the stored money balance to the client 416 /// Sends the the stored money balance to the client
@@ -798,7 +424,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
798 if (client.AgentId == agentID && client.SessionId == SessionID) 424 if (client.AgentId == agentID && client.SessionId == SessionID)
799 { 425 {
800 int returnfunds = 0; 426 int returnfunds = 0;
801 427
802 try 428 try
803 { 429 {
804 returnfunds = GetFundsForAgentID(agentID); 430 returnfunds = GetFundsForAgentID(agentID);
@@ -807,7 +433,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
807 { 433 {
808 client.SendAlertMessage(e.Message + " "); 434 client.SendAlertMessage(e.Message + " ");
809 } 435 }
810 436
811 client.SendMoneyBalance(TransactionID, true, new byte[0], returnfunds); 437 client.SendMoneyBalance(TransactionID, true, new byte[0], returnfunds);
812 } 438 }
813 else 439 else
@@ -816,67 +442,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
816 } 442 }
817 } 443 }
818 444
819 #region local Fund Management
820 /// <summary>
821 /// Ensures that the agent accounting data is set up in this instance.
822 /// </summary>
823 /// <param name="agentID"></param>
824 private void CheckExistAndRefreshFunds(LLUUID agentID)
825 {
826 lock (m_KnownClientFunds)
827 {
828 if (!m_KnownClientFunds.ContainsKey(agentID))
829 {
830 m_KnownClientFunds.Add(agentID, m_stipend);
831 }
832 else
833 {
834 if (m_KnownClientFunds[agentID] <= m_minFundsBeforeRefresh)
835 {
836 m_KnownClientFunds[agentID] = m_stipend;
837 }
838 }
839 }
840 }
841 /// <summary>
842 /// Gets the amount of Funds for an agent
843 /// </summary>
844 /// <param name="AgentID"></param>
845 /// <returns></returns>
846 private int GetFundsForAgentID(LLUUID AgentID)
847 {
848 int returnfunds = 0;
849 lock (m_KnownClientFunds)
850 {
851 if (m_KnownClientFunds.ContainsKey(AgentID))
852 {
853 returnfunds = m_KnownClientFunds[AgentID];
854 }
855 else
856 {
857 //throw new Exception("Unable to get funds.");
858 }
859 }
860 return returnfunds;
861 }
862 private void SetLocalFundsForAgentID(LLUUID AgentID, int amount)
863 {
864 lock (m_KnownClientFunds)
865 {
866 if (m_KnownClientFunds.ContainsKey(AgentID))
867 {
868 m_KnownClientFunds[AgentID] = amount;
869 }
870 else
871 {
872 m_KnownClientFunds.Add(AgentID, amount);
873 }
874 }
875
876 }
877
878 #endregion
879
880 /// <summary> 445 /// <summary>
881 /// 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
882 /// </summary> 447 /// </summary>
@@ -887,7 +452,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
887 /// <returns></returns> 452 /// <returns></returns>
888 public Hashtable GetBalanceForUserFromMoneyServer(LLUUID agentId, LLUUID secureSessionID, LLUUID regionId, string regionSecret) 453 public Hashtable GetBalanceForUserFromMoneyServer(LLUUID agentId, LLUUID secureSessionID, LLUUID regionId, string regionSecret)
889 { 454 {
890
891 Hashtable MoneyBalanceRequestParams = new Hashtable(); 455 Hashtable MoneyBalanceRequestParams = new Hashtable();
892 MoneyBalanceRequestParams["agentId"] = agentId.ToString(); 456 MoneyBalanceRequestParams["agentId"] = agentId.ToString();
893 MoneyBalanceRequestParams["secureSessionId"] = secureSessionID.ToString(); 457 MoneyBalanceRequestParams["secureSessionId"] = secureSessionID.ToString();
@@ -899,8 +463,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
899 463
900 return MoneyRespData; 464 return MoneyRespData;
901 } 465 }
902 466
903
904 467
905 /// <summary> 468 /// <summary>
906 /// Generic XMLRPC client abstraction 469 /// Generic XMLRPC client abstraction
@@ -921,7 +484,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
921 } 484 }
922 catch (WebException ex) 485 catch (WebException ex)
923 { 486 {
924
925 m_log.ErrorFormat( 487 m_log.ErrorFormat(
926 "[MONEY]: Unable to connect to Money Server {0}. Exception {1}", 488 "[MONEY]: Unable to connect to Money Server {0}. Exception {1}",
927 m_MoneyAddress, ex); 489 m_MoneyAddress, ex);
@@ -936,7 +498,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
936 } 498 }
937 catch (SocketException ex) 499 catch (SocketException ex)
938 { 500 {
939
940 m_log.ErrorFormat( 501 m_log.ErrorFormat(
941 "[MONEY]: Unable to connect to Money Server {0}. Exception {1}", 502 "[MONEY]: Unable to connect to Money Server {0}. Exception {1}",
942 m_MoneyAddress, ex); 503 m_MoneyAddress, ex);
@@ -961,7 +522,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
961 ErrorHash["errorURI"] = ""; 522 ErrorHash["errorURI"] = "";
962 523
963 return ErrorHash; 524 return ErrorHash;
964
965 } 525 }
966 if (MoneyResp.IsFault) 526 if (MoneyResp.IsFault)
967 { 527 {
@@ -971,12 +531,12 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
971 ErrorHash["errorURI"] = ""; 531 ErrorHash["errorURI"] = "";
972 532
973 return ErrorHash; 533 return ErrorHash;
974
975 } 534 }
976 Hashtable MoneyRespData = (Hashtable)MoneyResp.Value; 535 Hashtable MoneyRespData = (Hashtable) MoneyResp.Value;
977 536
978 return MoneyRespData; 537 return MoneyRespData;
979 } 538 }
539
980 /// <summary> 540 /// <summary>
981 /// 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
982 /// </summary> 542 /// </summary>
@@ -987,7 +547,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
987 /// <returns></returns> 547 /// <returns></returns>
988 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)
989 { 549 {
990
991 Hashtable MoneyBalanceRequestParams = new Hashtable(); 550 Hashtable MoneyBalanceRequestParams = new Hashtable();
992 MoneyBalanceRequestParams["agentId"] = agentId.ToString(); 551 MoneyBalanceRequestParams["agentId"] = agentId.ToString();
993 MoneyBalanceRequestParams["secureSessionId"] = secureSessionID.ToString(); 552 MoneyBalanceRequestParams["secureSessionId"] = secureSessionID.ToString();
@@ -1009,8 +568,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1009 { 568 {
1010 foreach (Scene s in m_scenel.Values) 569 foreach (Scene s in m_scenel.Values)
1011 { 570 {
1012 SceneObjectPart part=s.GetSceneObjectPart(objectID); 571 SceneObjectPart part = s.GetSceneObjectPart(objectID);
1013 if(part != null) 572 if (part != null)
1014 { 573 {
1015 return part; 574 return part;
1016 } 575 }
@@ -1021,8 +580,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1021 580
1022 private string resolveObjectName(LLUUID objectID) 581 private string resolveObjectName(LLUUID objectID)
1023 { 582 {
1024 SceneObjectPart part=findPrim(objectID); 583 SceneObjectPart part = findPrim(objectID);
1025 if(part != null) 584 if (part != null)
1026 { 585 {
1027 return part.Name; 586 return part.Name;
1028 } 587 }
@@ -1032,7 +591,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1032 private string resolveAgentName(LLUUID agentID) 591 private string resolveAgentName(LLUUID agentID)
1033 { 592 {
1034 // try avatar username surname 593 // try avatar username surname
1035 Scene scene=GetRandomScene(); 594 Scene scene = GetRandomScene();
1036 UserProfileData profile = scene.CommsManager.UserService.GetUserProfile(agentID); 595 UserProfileData profile = scene.CommsManager.UserService.GetUserProfile(agentID);
1037 if (profile != null) 596 if (profile != null)
1038 { 597 {
@@ -1042,19 +601,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1042 return String.Empty; 601 return String.Empty;
1043 } 602 }
1044 603
1045 public bool ObjectGiveMoney(LLUUID objectID, LLUUID fromID, LLUUID toID, int amount)
1046 {
1047 string description=String.Format("Object {0} pays {1}", resolveObjectName(objectID), resolveAgentName(toID));
1048
1049 bool give_result = doMoneyTransfer(fromID, toID, amount, 2, description);
1050
1051 if (m_MoneyAddress.Length == 0)
1052 BalanceUpdate(fromID, toID, give_result, description);
1053
1054 return give_result;
1055
1056
1057 }
1058 private void BalanceUpdate(LLUUID senderID, LLUUID receiverID, bool transactionresult, string description) 604 private void BalanceUpdate(LLUUID senderID, LLUUID receiverID, bool transactionresult, string description)
1059 { 605 {
1060 IClientAPI sender = LocateClientObject(senderID); 606 IClientAPI sender = LocateClientObject(senderID);
@@ -1091,7 +637,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1091 IClientAPI cli = LocateClientObject(sourceId); 637 IClientAPI cli = LocateClientObject(sourceId);
1092 if (cli != null) 638 if (cli != null)
1093 { 639 {
1094
1095 Scene userScene = null; 640 Scene userScene = null;
1096 lock (m_rootAgents) 641 lock (m_rootAgents)
1097 { 642 {
@@ -1112,18 +657,18 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1112 ht["flags"] = flags; 657 ht["flags"] = flags;
1113 ht["transactionType"] = transactiontype; 658 ht["transactionType"] = transactiontype;
1114 ht["description"] = description; 659 ht["description"] = description;
1115 660
1116 Hashtable hresult = genericCurrencyXMLRPCRequest(ht, "regionMoveMoney"); 661 Hashtable hresult = genericCurrencyXMLRPCRequest(ht, "regionMoveMoney");
1117 662
1118 if ((bool)hresult["success"] == true) 663 if ((bool) hresult["success"] == true)
1119 { 664 {
1120 int funds1 = 0; 665 int funds1 = 0;
1121 int funds2 = 0; 666 int funds2 = 0;
1122 try 667 try
1123 { 668 {
1124 funds1 = (Int32)hresult["funds"]; 669 funds1 = (Int32) hresult["funds"];
1125 } 670 }
1126 catch(InvalidCastException) 671 catch (InvalidCastException)
1127 { 672 {
1128 funds1 = 0; 673 funds1 = 0;
1129 } 674 }
@@ -1132,7 +677,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1132 { 677 {
1133 try 678 try
1134 { 679 {
1135 funds2 = (Int32)hresult["funds2"]; 680 funds2 = (Int32) hresult["funds2"];
1136 } 681 }
1137 catch (InvalidCastException) 682 catch (InvalidCastException)
1138 { 683 {
@@ -1146,9 +691,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1146 } 691 }
1147 else 692 else
1148 { 693 {
1149 cli.SendAgentAlertMessage((string)hresult["errorMessage"], true); 694 cli.SendAgentAlertMessage((string) hresult["errorMessage"], true);
1150 } 695 }
1151
1152 } 696 }
1153 } 697 }
1154 else 698 else
@@ -1157,7 +701,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1157 } 701 }
1158 702
1159 return rvalue; 703 return rvalue;
1160
1161 } 704 }
1162 705
1163 public int GetRemoteBalance(LLUUID agentId) 706 public int GetRemoteBalance(LLUUID agentId)
@@ -1172,12 +715,14 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1172 { 715 {
1173 if (m_MoneyAddress.Length > 0) 716 if (m_MoneyAddress.Length > 0)
1174 { 717 {
1175 Hashtable hbinfo = GetBalanceForUserFromMoneyServer(aClient.AgentId, aClient.SecureSessionId, s.RegionInfo.originRegionID.ToString(), s.RegionInfo.regionSecret); 718 Hashtable hbinfo =
1176 if ((bool)hbinfo["success"] == true) 719 GetBalanceForUserFromMoneyServer(aClient.AgentId, aClient.SecureSessionId, s.RegionInfo.originRegionID.ToString(),
720 s.RegionInfo.regionSecret);
721 if ((bool) hbinfo["success"] == true)
1177 { 722 {
1178 try 723 try
1179 { 724 {
1180 funds = (Int32)hbinfo["funds"]; 725 funds = (Int32) hbinfo["funds"];
1181 } 726 }
1182 catch (ArgumentException) 727 catch (ArgumentException)
1183 { 728 {
@@ -1194,12 +739,12 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1194 { 739 {
1195 funds = 0; 740 funds = 0;
1196 } 741 }
1197
1198 } 742 }
1199 else 743 else
1200 { 744 {
1201 m_log.WarnFormat("[MONEY]: Getting Money for user {0} failed with the following message:{1}", agentId, (string)hbinfo["errorMessage"]); 745 m_log.WarnFormat("[MONEY]: Getting Money for user {0} failed with the following message:{1}", agentId,
1202 aClient.SendAlertMessage((string)hbinfo["errorMessage"]); 746 (string) hbinfo["errorMessage"]);
747 aClient.SendAlertMessage((string) hbinfo["errorMessage"]);
1203 } 748 }
1204 } 749 }
1205 750
@@ -1221,17 +766,16 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1221 public XmlRpcResponse GridMoneyUpdate(XmlRpcRequest request) 766 public XmlRpcResponse GridMoneyUpdate(XmlRpcRequest request)
1222 { 767 {
1223 m_log.Debug("[MONEY]: Dynamic balance update called."); 768 m_log.Debug("[MONEY]: Dynamic balance update called.");
1224 Hashtable requestData = (Hashtable)request.Params[0]; 769 Hashtable requestData = (Hashtable) request.Params[0];
1225 770
1226 if (requestData.ContainsKey("agentId")) 771 if (requestData.ContainsKey("agentId"))
1227 { 772 {
1228 LLUUID agentId = LLUUID.Zero; 773 LLUUID agentId = LLUUID.Zero;
1229 774
1230 Helpers.TryParse((string)requestData["agentId"], out agentId); 775 Helpers.TryParse((string) requestData["agentId"], out agentId);
1231 if (agentId != LLUUID.Zero) 776 if (agentId != LLUUID.Zero)
1232 { 777 {
1233 GetRemoteBalance(agentId); 778 GetRemoteBalance(agentId);
1234
1235 } 779 }
1236 else 780 else
1237 { 781 {
@@ -1245,7 +789,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1245 XmlRpcResponse r = new XmlRpcResponse(); 789 XmlRpcResponse r = new XmlRpcResponse();
1246 Hashtable rparms = new Hashtable(); 790 Hashtable rparms = new Hashtable();
1247 rparms["success"] = true; 791 rparms["success"] = true;
1248 792
1249 r.Value = rparms; 793 r.Value = rparms;
1250 return r; 794 return r;
1251 } 795 }
@@ -1257,24 +801,24 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1257 { 801 {
1258 XmlRpcResponse ret = new XmlRpcResponse(); 802 XmlRpcResponse ret = new XmlRpcResponse();
1259 Hashtable retparam = new Hashtable(); 803 Hashtable retparam = new Hashtable();
1260 Hashtable requestData = (Hashtable)request.Params[0]; 804 Hashtable requestData = (Hashtable) request.Params[0];
1261 805
1262 LLUUID agentId = LLUUID.Zero; 806 LLUUID agentId = LLUUID.Zero;
1263 LLUUID soundId = LLUUID.Zero; 807 LLUUID soundId = LLUUID.Zero;
1264 808
1265 Helpers.TryParse((string)requestData["agentId"], out agentId); 809 Helpers.TryParse((string) requestData["agentId"], out agentId);
1266 Helpers.TryParse((string)requestData["soundId"], out soundId); 810 Helpers.TryParse((string) requestData["soundId"], out soundId);
1267 string text=(string)requestData["text"]; 811 string text = (string) requestData["text"];
1268 string secret=(string)requestData["secret"]; 812 string secret = (string) requestData["secret"];
1269 813
1270 Scene userScene = GetRandomScene(); 814 Scene userScene = GetRandomScene();
1271 if(userScene.RegionInfo.regionSecret.ToString() == secret) 815 if (userScene.RegionInfo.regionSecret.ToString() == secret)
1272 { 816 {
1273 IClientAPI client = LocateClientObject(agentId); 817 IClientAPI client = LocateClientObject(agentId);
1274 818
1275 if (client != null) 819 if (client != null)
1276 { 820 {
1277 if(soundId != LLUUID.Zero) 821 if (soundId != LLUUID.Zero)
1278 client.SendPlayAttachedSound(soundId, LLUUID.Zero, LLUUID.Zero, 1.0f, 0); 822 client.SendPlayAttachedSound(soundId, LLUUID.Zero, LLUUID.Zero, 1.0f, 0);
1279 client.SendBlueBoxMessage(LLUUID.Zero, LLUUID.Zero, "", text); 823 client.SendBlueBoxMessage(LLUUID.Zero, LLUUID.Zero, "", text);
1280 retparam.Add("success", true); 824 retparam.Add("success", true);
@@ -1293,12 +837,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1293 return ret; 837 return ret;
1294 } 838 }
1295 839
1296
1297 # region Standalone box enablers only 840 # region Standalone box enablers only
1298 841
1299 public XmlRpcResponse quote_func(XmlRpcRequest request) 842 public XmlRpcResponse quote_func(XmlRpcRequest request)
1300 { 843 {
1301 Hashtable requestData = (Hashtable)request.Params[0]; 844 Hashtable requestData = (Hashtable) request.Params[0];
1302 LLUUID agentId = LLUUID.Zero; 845 LLUUID agentId = LLUUID.Zero;
1303 int amount = 0; 846 int amount = 0;
1304 Hashtable quoteResponse = new Hashtable(); 847 Hashtable quoteResponse = new Hashtable();
@@ -1306,51 +849,48 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1306 849
1307 if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy")) 850 if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy"))
1308 { 851 {
1309 Helpers.TryParse((string)requestData["agentId"], out agentId); 852 Helpers.TryParse((string) requestData["agentId"], out agentId);
1310 try 853 try
1311 { 854 {
1312 amount = (Int32)requestData["currencyBuy"]; 855 amount = (Int32) requestData["currencyBuy"];
1313 } 856 }
1314 catch (InvalidCastException) 857 catch (InvalidCastException)
1315 { 858 {
1316
1317 } 859 }
1318 Hashtable currencyResponse = new Hashtable(); 860 Hashtable currencyResponse = new Hashtable();
1319 currencyResponse.Add("estimatedCost", 0); 861 currencyResponse.Add("estimatedCost", 0);
1320 currencyResponse.Add("currencyBuy", amount); 862 currencyResponse.Add("currencyBuy", amount);
1321 863
1322 quoteResponse.Add("success", true); 864 quoteResponse.Add("success", true);
1323 quoteResponse.Add("currency", currencyResponse); 865 quoteResponse.Add("currency", currencyResponse);
1324 quoteResponse.Add("confirm", "asdfad9fj39ma9fj"); 866 quoteResponse.Add("confirm", "asdfad9fj39ma9fj");
1325 867
1326 returnval.Value = quoteResponse; 868 returnval.Value = quoteResponse;
1327 return returnval; 869 return returnval;
1328 } 870 }
1329 871
1330 872
1331
1332 quoteResponse.Add("success", false); 873 quoteResponse.Add("success", false);
1333 quoteResponse.Add("errorMessage", "Invalid parameters passed to the quote box"); 874 quoteResponse.Add("errorMessage", "Invalid parameters passed to the quote box");
1334 quoteResponse.Add("errorURI", "http://www.opensimulator.org/wiki"); 875 quoteResponse.Add("errorURI", "http://www.opensimulator.org/wiki");
1335 returnval.Value = quoteResponse; 876 returnval.Value = quoteResponse;
1336 return returnval; 877 return returnval;
1337 } 878 }
879
1338 public XmlRpcResponse buy_func(XmlRpcRequest request) 880 public XmlRpcResponse buy_func(XmlRpcRequest request)
1339 { 881 {
1340 882 Hashtable requestData = (Hashtable) request.Params[0];
1341 Hashtable requestData = (Hashtable)request.Params[0];
1342 LLUUID agentId = LLUUID.Zero; 883 LLUUID agentId = LLUUID.Zero;
1343 int amount = 0; 884 int amount = 0;
1344 if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy")) 885 if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy"))
1345 { 886 {
1346 Helpers.TryParse((string)requestData["agentId"], out agentId); 887 Helpers.TryParse((string) requestData["agentId"], out agentId);
1347 try 888 try
1348 { 889 {
1349 amount = (Int32)requestData["currencyBuy"]; 890 amount = (Int32) requestData["currencyBuy"];
1350 } 891 }
1351 catch (InvalidCastException) 892 catch (InvalidCastException)
1352 { 893 {
1353
1354 } 894 }
1355 if (agentId != LLUUID.Zero) 895 if (agentId != LLUUID.Zero)
1356 { 896 {
@@ -1412,26 +952,25 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1412 ret.Value = retparam; 952 ret.Value = retparam;
1413 953
1414 return ret; 954 return ret;
1415
1416 } 955 }
956
1417 public XmlRpcResponse landBuy_func(XmlRpcRequest request) 957 public XmlRpcResponse landBuy_func(XmlRpcRequest request)
1418 { 958 {
1419 XmlRpcResponse ret = new XmlRpcResponse(); 959 XmlRpcResponse ret = new XmlRpcResponse();
1420 Hashtable retparam = new Hashtable(); 960 Hashtable retparam = new Hashtable();
1421 Hashtable requestData = (Hashtable)request.Params[0]; 961 Hashtable requestData = (Hashtable) request.Params[0];
1422 962
1423 LLUUID agentId = LLUUID.Zero; 963 LLUUID agentId = LLUUID.Zero;
1424 int amount = 0; 964 int amount = 0;
1425 if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy")) 965 if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy"))
1426 { 966 {
1427 Helpers.TryParse((string)requestData["agentId"], out agentId); 967 Helpers.TryParse((string) requestData["agentId"], out agentId);
1428 try 968 try
1429 { 969 {
1430 amount = (Int32)requestData["currencyBuy"]; 970 amount = (Int32) requestData["currencyBuy"];
1431 } 971 }
1432 catch (InvalidCastException) 972 catch (InvalidCastException)
1433 { 973 {
1434
1435 } 974 }
1436 if (agentId != LLUUID.Zero) 975 if (agentId != LLUUID.Zero)
1437 { 976 {
@@ -1457,35 +996,475 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1457 ret.Value = retparam; 996 ret.Value = retparam;
1458 997
1459 return ret; 998 return ret;
999 }
1000
1001 #endregion
1002
1003 #region local Fund Management
1004
1005 /// <summary>
1006 /// Ensures that the agent accounting data is set up in this instance.
1007 /// </summary>
1008 /// <param name="agentID"></param>
1009 private void CheckExistAndRefreshFunds(LLUUID agentID)
1010 {
1011 lock (m_KnownClientFunds)
1012 {
1013 if (!m_KnownClientFunds.ContainsKey(agentID))
1014 {
1015 m_KnownClientFunds.Add(agentID, m_stipend);
1016 }
1017 else
1018 {
1019 if (m_KnownClientFunds[agentID] <= m_minFundsBeforeRefresh)
1020 {
1021 m_KnownClientFunds[agentID] = m_stipend;
1022 }
1023 }
1024 }
1025 }
1460 1026
1027 /// <summary>
1028 /// Gets the amount of Funds for an agent
1029 /// </summary>
1030 /// <param name="AgentID"></param>
1031 /// <returns></returns>
1032 private int GetFundsForAgentID(LLUUID AgentID)
1033 {
1034 int returnfunds = 0;
1035 lock (m_KnownClientFunds)
1036 {
1037 if (m_KnownClientFunds.ContainsKey(AgentID))
1038 {
1039 returnfunds = m_KnownClientFunds[AgentID];
1040 }
1041 else
1042 {
1043 //throw new Exception("Unable to get funds.");
1044 }
1045 }
1046 return returnfunds;
1461 } 1047 }
1048
1049 private void SetLocalFundsForAgentID(LLUUID AgentID, int amount)
1050 {
1051 lock (m_KnownClientFunds)
1052 {
1053 if (m_KnownClientFunds.ContainsKey(AgentID))
1054 {
1055 m_KnownClientFunds[AgentID] = amount;
1056 }
1057 else
1058 {
1059 m_KnownClientFunds.Add(AgentID, amount);
1060 }
1061 }
1062 }
1063
1462 #endregion 1064 #endregion
1463 1065
1464 public void PostInitialise() 1066 #region Utility Helpers
1067
1068 /// <summary>
1069 /// Locates a IClientAPI for the client specified
1070 /// </summary>
1071 /// <param name="AgentID"></param>
1072 /// <returns></returns>
1073 private IClientAPI LocateClientObject(LLUUID AgentID)
1465 { 1074 {
1075 ScenePresence tPresence = null;
1076 IClientAPI rclient = null;
1077
1078 lock (m_scenel)
1079 {
1080 foreach (Scene _scene in m_scenel.Values)
1081 {
1082 tPresence = _scene.GetScenePresence(AgentID);
1083 if (tPresence != null)
1084 {
1085 if (!tPresence.IsChildAgent)
1086 {
1087 rclient = tPresence.ControllingClient;
1088 }
1089 }
1090 if (rclient != null)
1091 {
1092 return rclient;
1093 }
1094 }
1095 }
1096 return null;
1466 } 1097 }
1467 1098
1468 public void Close() 1099 private Scene LocateSceneClientIn(LLUUID AgentId)
1469 { 1100 {
1101 lock (m_scenel)
1102 {
1103 foreach (Scene _scene in m_scenel.Values)
1104 {
1105 ScenePresence tPresence = _scene.GetScenePresence(AgentId);
1106 if (tPresence != null)
1107 {
1108 if (!tPresence.IsChildAgent)
1109 {
1110 return _scene;
1111 }
1112 }
1113 }
1114 }
1115 return null;
1470 } 1116 }
1471 1117
1472 public string Name 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
1120 /// </summary>
1121 /// <returns></returns>
1122 public Scene GetRandomScene()
1473 { 1123 {
1474 get { return "BetaGridLikeMoneyModule"; } 1124 lock (m_scenel)
1125 {
1126 foreach (Scene rs in m_scenel.Values)
1127 return rs;
1128 }
1129 return null;
1475 } 1130 }
1476 1131
1477 public bool IsSharedModule 1132 /// <summary>
1133 /// Utility function to get a Scene by RegionID in a module
1134 /// </summary>
1135 /// <param name="RegionID"></param>
1136 /// <returns></returns>
1137 public Scene GetSceneByUUID(LLUUID RegionID)
1478 { 1138 {
1479 get { return true; } 1139 lock (m_scenel)
1140 {
1141 foreach (Scene rs in m_scenel.Values)
1142 {
1143 if (rs.RegionInfo.originRegionID == RegionID)
1144 {
1145 return rs;
1146 }
1147 }
1148 }
1149 return null;
1150 }
1151
1152 #endregion
1153
1154 #region event Handlers
1155
1156 public void requestPayPrice(IClientAPI client, LLUUID objectID)
1157 {
1158 Scene scene = LocateSceneClientIn(client.AgentId);
1159 if (scene == null)
1160 return;
1161
1162 SceneObjectPart task = scene.GetSceneObjectPart(objectID);
1163 if (task == null)
1164 return;
1165 SceneObjectGroup group = task.ParentGroup;
1166 SceneObjectPart root = group.RootPart;
1167
1168 client.SendPayPrice(objectID, root.PayPrice);
1169 }
1170
1171 /// <summary>
1172 /// When the client closes the connection we remove their accounting info from memory to free up resources.
1173 /// </summary>
1174 /// <param name="AgentID"></param>
1175 public void ClientClosed(LLUUID AgentID)
1176 {
1177 lock (m_KnownClientFunds)
1178 {
1179 if (m_keepMoneyAcrossLogins && m_MoneyAddress.Length == 0)
1180 {
1181 }
1182 else
1183 {
1184 m_KnownClientFunds.Remove(AgentID);
1185 }
1186 }
1480 } 1187 }
1188
1189 /// <summary>
1190 /// Event called Economy Data Request handler.
1191 /// </summary>
1192 /// <param name="agentId"></param>
1193 public void EconomyDataRequestHandler(LLUUID agentId)
1194 {
1195 IClientAPI user = LocateClientObject(agentId);
1196
1197 if (user != null)
1198 {
1199 user.SendEconomyData(EnergyEfficiency, ObjectCapacity, ObjectCount, PriceEnergyUnit, PriceGroupCreate,
1200 PriceObjectClaim, PriceObjectRent, PriceObjectScaleFactor, PriceParcelClaim, PriceParcelClaimFactor,
1201 PriceParcelRent, PricePublicObjectDecay, PricePublicObjectDelete, PriceRentLight, PriceUpload,
1202 TeleportMinPrice, TeleportPriceExponent);
1203 }
1204 }
1205
1206 private void ValidateLandBuy(Object osender, EventManager.LandBuyArgs e)
1207 {
1208 if (m_MoneyAddress.Length == 0)
1209 {
1210 lock (m_KnownClientFunds)
1211 {
1212 if (m_KnownClientFunds.ContainsKey(e.agentId))
1213 {
1214 // Does the sender have enough funds to give?
1215 if (m_KnownClientFunds[e.agentId] >= e.parcelPrice)
1216 {
1217 lock (e)
1218 {
1219 e.economyValidated = true;
1220 }
1221 }
1222 }
1223 }
1224 }
1225 else
1226 {
1227 if (GetRemoteBalance(e.agentId) >= e.parcelPrice)
1228 {
1229 lock (e)
1230 {
1231 e.economyValidated = true;
1232 }
1233 }
1234 }
1235 }
1236
1237 private void processLandBuy(Object osender, EventManager.LandBuyArgs e)
1238 {
1239 lock (e)
1240 {
1241 if (e.economyValidated == true && e.transactionID == 0)
1242 {
1243 e.transactionID = Util.UnixTimeSinceEpoch();
1244
1245 if (doMoneyTransfer(e.agentId, e.parcelOwnerID, e.parcelPrice, 0, "Land purchase"))
1246 {
1247 lock (e)
1248 {
1249 e.amountDebited = e.parcelPrice;
1250 }
1251 }
1252 }
1253 }
1254 }
1255
1256 /// <summary>
1257 /// THis method gets called when someone pays someone else as a gift.
1258 /// </summary>
1259 /// <param name="osender"></param>
1260 /// <param name="e"></param>
1261 private void MoneyTransferAction(Object osender, EventManager.MoneyTransferArgs e)
1262 {
1263 IClientAPI sender = null;
1264 IClientAPI receiver = null;
1265
1266 if (m_MoneyAddress.Length > 0) // Handled on server
1267 e.description = String.Empty;
1268
1269 if (e.transactiontype == 5008) // Object gets paid
1270 {
1271 sender = LocateClientObject(e.sender);
1272 if (sender != null)
1273 {
1274 SceneObjectPart part = findPrim(e.receiver);
1275 if (part == null)
1276 return;
1277
1278 string name = resolveAgentName(part.OwnerID);
1279 if (name == String.Empty)
1280 name = "(hippos)";
1281
1282 receiver = LocateClientObject(part.OwnerID);
1283
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);
1286
1287 if (transactionresult)
1288 {
1289 ObjectPaid handlerOnObjectPaid = OnObjectPaid;
1290 if (handlerOnObjectPaid != null)
1291 {
1292 handlerOnObjectPaid(e.receiver, e.sender, e.amount);
1293 }
1294 }
1295
1296 if (e.sender != e.receiver)
1297 {
1298 sender.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.sender));
1299 }
1300 if (receiver != null)
1301 {
1302 receiver.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(part.OwnerID));
1303 }
1304 }
1305 return;
1306 }
1307
1308 sender = LocateClientObject(e.sender);
1309 if (sender != null)
1310 {
1311 receiver = LocateClientObject(e.receiver);
1312
1313 bool transactionresult = doMoneyTransfer(e.sender, e.receiver, e.amount, e.transactiontype, e.description);
1314
1315 if (e.sender != e.receiver)
1316 {
1317 if (sender != null)
1318 {
1319 sender.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.sender));
1320 }
1321 }
1322
1323 if (receiver != null)
1324 {
1325 receiver.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.receiver));
1326 }
1327 }
1328 else
1329 {
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());
1332 }
1333 }
1334
1335 /// <summary>
1336 /// Event Handler for when a root agent becomes a child agent
1337 /// </summary>
1338 /// <param name="avatar"></param>
1339 private void MakeChildAgent(ScenePresence avatar)
1340 {
1341 lock (m_rootAgents)
1342 {
1343 if (m_rootAgents.ContainsKey(avatar.UUID))
1344 {
1345 if (m_rootAgents[avatar.UUID] == avatar.Scene.RegionInfo.originRegionID)
1346 {
1347 m_rootAgents.Remove(avatar.UUID);
1348 m_log.Info("[MONEY]: Removing " + avatar.Firstname + " " + avatar.Lastname + " as a root agent");
1349 }
1350 }
1351 }
1352 }
1353
1354 /// <summary>
1355 /// Event Handler for when the client logs out.
1356 /// </summary>
1357 /// <param name="AgentId"></param>
1358 private void ClientLoggedOut(LLUUID AgentId)
1359 {
1360 lock (m_rootAgents)
1361 {
1362 if (m_rootAgents.ContainsKey(AgentId))
1363 {
1364 m_rootAgents.Remove(AgentId);
1365 //m_log.Info("[MONEY]: Removing " + AgentId + ". Agent logged out.");
1366 }
1367 }
1368 }
1369
1370 /// <summary>
1371 /// Call this when the client disconnects.
1372 /// </summary>
1373 /// <param name="client"></param>
1374 public void ClientClosed(IClientAPI client)
1375 {
1376 ClientClosed(client.AgentId);
1377 }
1378
1379 /// <summary>
1380 /// Event Handler for when an Avatar enters one of the parcels in the simulator.
1381 /// </summary>
1382 /// <param name="avatar"></param>
1383 /// <param name="localLandID"></param>
1384 /// <param name="regionID"></param>
1385 private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, LLUUID regionID)
1386 {
1387 lock (m_rootAgents)
1388 {
1389 if (m_rootAgents.ContainsKey(avatar.UUID))
1390 {
1391 if (avatar.Scene.RegionInfo.originRegionID != m_rootAgents[avatar.UUID])
1392 {
1393 m_rootAgents[avatar.UUID] = avatar.Scene.RegionInfo.originRegionID;
1394 //m_log.Info("[MONEY]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + ".");
1395 // Claim User! my user! Mine mine mine!
1396 if (m_MoneyAddress.Length > 0)
1397 {
1398 Scene RegionItem = GetSceneByUUID(regionID);
1399 if (RegionItem != null)
1400 {
1401 Hashtable hresult =
1402 claim_user(avatar.UUID, avatar.ControllingClient.SecureSessionId, regionID, RegionItem.RegionInfo.regionSecret);
1403 if ((bool) hresult["success"] == true)
1404 {
1405 int funds = 0;
1406 try
1407 {
1408 funds = (Int32) hresult["funds"];
1409 }
1410 catch (InvalidCastException)
1411 {
1412 }
1413 SetLocalFundsForAgentID(avatar.UUID, funds);
1414 }
1415 else
1416 {
1417 avatar.ControllingClient.SendAgentAlertMessage((string) hresult["errorMessage"], true);
1418 }
1419 }
1420 }
1421 }
1422 }
1423 else
1424 {
1425 lock (m_rootAgents)
1426 {
1427 m_rootAgents.Add(avatar.UUID, avatar.Scene.RegionInfo.originRegionID);
1428 }
1429 if (m_MoneyAddress.Length > 0)
1430 {
1431 Scene RegionItem = GetSceneByUUID(regionID);
1432 if (RegionItem != null)
1433 {
1434 Hashtable hresult = claim_user(avatar.UUID, avatar.ControllingClient.SecureSessionId, regionID, RegionItem.RegionInfo.regionSecret);
1435 if ((bool) hresult["success"] == true)
1436 {
1437 int funds = 0;
1438 try
1439 {
1440 funds = (Int32) hresult["funds"];
1441 }
1442 catch (InvalidCastException)
1443 {
1444 }
1445 SetLocalFundsForAgentID(avatar.UUID, funds);
1446 }
1447 else
1448 {
1449 avatar.ControllingClient.SendAgentAlertMessage((string) hresult["errorMessage"], true);
1450 }
1451 }
1452 }
1453
1454 //m_log.Info("[MONEY]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + ".");
1455 }
1456 }
1457 //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString());
1458 }
1459
1460 #endregion
1481 } 1461 }
1482 1462
1483 public enum TransactionType : int 1463 public enum TransactionType : int
1484 { 1464 {
1485 SystemGenerated=0, 1465 SystemGenerated = 0,
1486 RegionMoneyRequest=1, 1466 RegionMoneyRequest = 1,
1487 Gift=2, 1467 Gift = 2,
1488 Purchase=3 1468 Purchase = 3
1489
1490 } 1469 }
1491} \ 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 3b0cc4c..db38d87 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs
@@ -42,13 +42,12 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
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>>();
46 private Dictionary<LLUUID, LLUUID> m_pendingFriendRequests = new Dictionary<LLUUID, LLUUID>();
47 private Dictionary<LLUUID, ulong> m_rootAgents = new Dictionary<LLUUID, ulong>();
45 private List<Scene> m_scene = new List<Scene>(); 48 private List<Scene> m_scene = new List<Scene>();
46 49
47 Dictionary<LLUUID, ulong> m_rootAgents = new Dictionary<LLUUID, ulong>(); 50 #region IRegionModule Members
48
49 Dictionary<LLUUID, LLUUID> m_pendingFriendRequests = new Dictionary<LLUUID, LLUUID>();
50
51 Dictionary<LLUUID, List<FriendListItem>> FriendLists = new Dictionary<LLUUID, List<FriendListItem>>();
52 51
53 public void Initialise(Scene scene, IConfigSource config) 52 public void Initialise(Scene scene, IConfigSource config)
54 { 53 {
@@ -68,11 +67,33 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
68 scene.EventManager.OnMakeChildAgent += MakeChildAgent; 67 scene.EventManager.OnMakeChildAgent += MakeChildAgent;
69 scene.EventManager.OnClientClosed += ClientLoggedOut; 68 scene.EventManager.OnClientClosed += ClientLoggedOut;
70 } 69 }
70
71 public void PostInitialise()
72 {
73 }
74
75 public void Close()
76 {
77 }
78
79 public string Name
80 {
81 get { return "FriendsModule"; }
82 }
83
84 public bool IsSharedModule
85 {
86 get { return true; }
87 }
88
89 #endregion
90
71 public XmlRpcResponse processPresenceUpdate(XmlRpcRequest req) 91 public XmlRpcResponse processPresenceUpdate(XmlRpcRequest req)
72 { 92 {
73 m_log.Info("[FRIENDS]: Got Notification about a user! OMG"); 93 m_log.Info("[FRIENDS]: Got Notification about a user! OMG");
74 return new XmlRpcResponse(); 94 return new XmlRpcResponse();
75 } 95 }
96
76 private void OnNewClient(IClientAPI client) 97 private void OnNewClient(IClientAPI client)
77 { 98 {
78 // All friends establishment protocol goes over instant message 99 // All friends establishment protocol goes over instant message
@@ -83,7 +104,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
83 // 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
84 105
85 // Subscribe to instant messages 106 // Subscribe to instant messages
86 107
87 client.OnInstantMessage += OnInstantMessage; 108 client.OnInstantMessage += OnInstantMessage;
88 client.OnApproveFriendRequest += OnApprovedFriendRequest; 109 client.OnApproveFriendRequest += OnApprovedFriendRequest;
89 client.OnDenyFriendRequest += OnDenyFriendRequest; 110 client.OnDenyFriendRequest += OnDenyFriendRequest;
@@ -99,10 +120,10 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
99 { 120 {
100 fl = FriendLists[client.AgentId]; 121 fl = FriendLists[client.AgentId];
101 } 122 }
102 else 123 else
103 { 124 {
104 fl = m_scene[0].GetFriendList(client.AgentId); 125 fl = m_scene[0].GetFriendList(client.AgentId);
105 126
106 //lock (FriendLists) 127 //lock (FriendLists)
107 //{ 128 //{
108 if (!FriendLists.ContainsKey(client.AgentId)) 129 if (!FriendLists.ContainsKey(client.AgentId))
@@ -110,11 +131,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
110 //} 131 //}
111 } 132 }
112 } 133 }
113 134
114 List<LLUUID> UpdateUsers = new List<LLUUID>(); 135 List<LLUUID> UpdateUsers = new List<LLUUID>();
115 136
116 foreach (FriendListItem f in fl) 137 foreach (FriendListItem f in fl)
117 { 138 {
118 if (m_rootAgents.ContainsKey(f.Friend)) 139 if (m_rootAgents.ContainsKey(f.Friend))
119 { 140 {
120 if (f.onlinestatus == false) 141 if (f.onlinestatus == false)
@@ -169,10 +190,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
169 onp.AgentBlock = onpb; 190 onp.AgentBlock = onpb;
170 client.OutPacket(onp, ThrottleOutPacketType.Task); 191 client.OutPacket(onp, ThrottleOutPacketType.Task);
171 } 192 }
172
173
174
175
176 } 193 }
177 194
178 private void ClientLoggedOut(LLUUID AgentId) 195 private void ClientLoggedOut(LLUUID AgentId)
@@ -182,7 +199,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
182 if (m_rootAgents.ContainsKey(AgentId)) 199 if (m_rootAgents.ContainsKey(AgentId))
183 { 200 {
184 m_rootAgents.Remove(AgentId); 201 m_rootAgents.Remove(AgentId);
185 m_log.Info("[FRIEND]: Removing " + AgentId + ". Agent logged out."); 202 m_log.Info("[FRIEND]: Removing " + AgentId + ". Agent logged out.");
186 } 203 }
187 } 204 }
188 List<FriendListItem> lfli = new List<FriendListItem>(); 205 List<FriendListItem> lfli = new List<FriendListItem>();
@@ -208,7 +225,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
208 List<FriendListItem> flfli = new List<FriendListItem>(); 225 List<FriendListItem> flfli = new List<FriendListItem>();
209 try 226 try
210 { 227 {
211
212 lock (FriendLists) 228 lock (FriendLists)
213 { 229 {
214 if (FriendLists.ContainsKey(updateUsers[i])) 230 if (FriendLists.ContainsKey(updateUsers[i]))
@@ -231,9 +247,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
231 { 247 {
232 flfli[i].onlinestatus = false; 248 flfli[i].onlinestatus = false;
233 } 249 }
234
235 } 250 }
236 251
237 catch (IndexOutOfRangeException) 252 catch (IndexOutOfRangeException)
238 { 253 {
239 // Ignore the index out of range exception. 254 // Ignore the index out of range exception.
@@ -242,15 +257,13 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
242 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");
243 } 258 }
244 } 259 }
245
246 } 260 }
247 261
248 for (int i = 0; i < updateUsers.Count; i++) 262 for (int i = 0; i < updateUsers.Count; i++)
249 { 263 {
250 ScenePresence av = GetPresenceFromAgentID(updateUsers[i]); 264 ScenePresence av = GetPresenceFromAgentID(updateUsers[i]);
251 if (av != null) 265 if (av != null)
252 { 266 {
253
254 OfflineNotificationPacket onp = new OfflineNotificationPacket(); 267 OfflineNotificationPacket onp = new OfflineNotificationPacket();
255 OfflineNotificationPacket.AgentBlockBlock[] onpb = new OfflineNotificationPacket.AgentBlockBlock[1]; 268 OfflineNotificationPacket.AgentBlockBlock[] onpb = new OfflineNotificationPacket.AgentBlockBlock[1];
256 OfflineNotificationPacket.AgentBlockBlock onpbl = new OfflineNotificationPacket.AgentBlockBlock(); 269 OfflineNotificationPacket.AgentBlockBlock onpbl = new OfflineNotificationPacket.AgentBlockBlock();
@@ -265,7 +278,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
265 { 278 {
266 FriendLists.Remove(AgentId); 279 FriendLists.Remove(AgentId);
267 } 280 }
268
269 } 281 }
270 282
271 private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, LLUUID regionID) 283 private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, LLUUID regionID)
@@ -282,7 +294,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
282 { 294 {
283 JId avatarID = new JId(avatar.JID); 295 JId avatarID = new JId(avatar.JID);
284 // REST Post XMPP Stanzas! 296 // REST Post XMPP Stanzas!
285
286 } 297 }
287 // Claim User! my user! Mine mine mine! 298 // Claim User! my user! Mine mine mine!
288 } 299 }
@@ -295,9 +306,9 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
295 } 306 }
296 //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString()); 307 //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString());
297 } 308 }
309
298 private void MakeChildAgent(ScenePresence avatar) 310 private void MakeChildAgent(ScenePresence avatar)
299 { 311 {
300
301 lock (m_rootAgents) 312 lock (m_rootAgents)
302 { 313 {
303 if (m_rootAgents.ContainsKey(avatar.UUID)) 314 if (m_rootAgents.ContainsKey(avatar.UUID))
@@ -307,30 +318,53 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
307 m_rootAgents.Remove(avatar.UUID); 318 m_rootAgents.Remove(avatar.UUID);
308 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");
309 } 320 }
310
311 } 321 }
312 } 322 }
323 }
313 324
325 private ScenePresence GetPresenceFromAgentID(LLUUID AgentID)
326 {
327 ScenePresence returnAgent = null;
328 lock (m_scene)
329 {
330 ScenePresence queryagent = null;
331 for (int i = 0; i < m_scene.Count; i++)
332 {
333 queryagent = m_scene[i].GetScenePresence(AgentID);
334 if (queryagent != null)
335 {
336 if (!queryagent.IsChildAgent)
337 {
338 returnAgent = queryagent;
339 break;
340 }
341 }
342 }
343 }
344 return returnAgent;
314 } 345 }
346
315 #region FriendRequestHandling 347 #region FriendRequestHandling
316 private void OnInstantMessage(IClientAPI client,LLUUID fromAgentID, 348
349 private void OnInstantMessage(IClientAPI client, LLUUID fromAgentID,
317 LLUUID fromAgentSession, LLUUID toAgentID, 350 LLUUID fromAgentSession, LLUUID toAgentID,
318 LLUUID imSessionID, uint timestamp, string fromAgentName, 351 LLUUID imSessionID, uint timestamp, string fromAgentName,
319 string message, byte dialog, bool fromGroup, byte offline, 352 string message, byte dialog, bool fromGroup, byte offline,
320 uint ParentEstateID, LLVector3 Position, LLUUID RegionID, 353 uint ParentEstateID, LLVector3 Position, LLUUID RegionID,
321 byte[] binaryBucket) 354 byte[] binaryBucket)
322 { 355 {
323 // Friend Requests go by Instant Message.. using the dialog param 356 // Friend Requests go by Instant Message.. using the dialog param
324 // https://wiki.secondlife.com/wiki/ImprovedInstantMessage 357 // https://wiki.secondlife.com/wiki/ImprovedInstantMessage
325 358
326 // 38 == Offer friendship 359 // 38 == Offer friendship
327 if (dialog == (byte)38) 360 if (dialog == (byte) 38)
328 { 361 {
329 LLUUID friendTransactionID = LLUUID.Random(); 362 LLUUID friendTransactionID = LLUUID.Random();
330 363
331 m_pendingFriendRequests.Add(friendTransactionID, fromAgentID); 364 m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
332 365
333 m_log.Info("[FRIEND]: 38 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message); 366 m_log.Info("[FRIEND]: 38 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" +
367 message);
334 GridInstantMessage msg = new GridInstantMessage(); 368 GridInstantMessage msg = new GridInstantMessage();
335 msg.fromAgentID = fromAgentID.UUID; 369 msg.fromAgentID = fromAgentID.UUID;
336 msg.fromAgentSession = fromAgentSession.UUID; 370 msg.fromAgentSession = fromAgentSession.UUID;
@@ -340,11 +374,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
340 msg.timestamp = timestamp; 374 msg.timestamp = timestamp;
341 if (client != null) 375 if (client != null)
342 { 376 {
343 msg.fromAgentName = client.FirstName + " " + client.LastName;// fromAgentName; 377 msg.fromAgentName = client.FirstName + " " + client.LastName; // fromAgentName;
344 } 378 }
345 else 379 else
346 { 380 {
347 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
348 } 382 }
349 msg.message = message; 383 msg.message = message;
350 msg.dialog = dialog; 384 msg.dialog = dialog;
@@ -359,15 +393,17 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
359 } 393 }
360 394
361 // 39 == Accept Friendship 395 // 39 == Accept Friendship
362 if (dialog == (byte)39) 396 if (dialog == (byte) 39)
363 { 397 {
364 m_log.Info("[FRIEND]: 39 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message); 398 m_log.Info("[FRIEND]: 39 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" +
399 message);
365 } 400 }
366 401
367 // 40 == Decline Friendship 402 // 40 == Decline Friendship
368 if (dialog == (byte)40) 403 if (dialog == (byte) 40)
369 { 404 {
370 m_log.Info("[FRIEND]: 40 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message); 405 m_log.Info("[FRIEND]: 40 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" +
406 message);
371 } 407 }
372 } 408 }
373 409
@@ -395,16 +431,16 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
395 msg.imSessionID = transactionID.UUID; 431 msg.imSessionID = transactionID.UUID;
396 msg.message = agentID.UUID.ToString(); 432 msg.message = agentID.UUID.ToString();
397 msg.ParentEstateID = 0; 433 msg.ParentEstateID = 0;
398 msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); 434 msg.timestamp = (uint) Util.UnixTimeSinceEpoch();
399 msg.RegionID = SceneAgentIn.RegionInfo.RegionID.UUID; 435 msg.RegionID = SceneAgentIn.RegionInfo.RegionID.UUID;
400 msg.dialog = (byte)39;// Approved friend request 436 msg.dialog = (byte) 39; // Approved friend request
401 msg.Position = new sLLVector3(); 437 msg.Position = new sLLVector3();
402 msg.offline = (byte)0; 438 msg.offline = (byte) 0;
403 msg.binaryBucket = new byte[0]; 439 msg.binaryBucket = new byte[0];
404 // 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
405 441
406 SceneAgentIn.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); 442 SceneAgentIn.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule);
407 SceneAgentIn.StoreAddFriendship(m_pendingFriendRequests[transactionID], agentID, (uint)1); 443 SceneAgentIn.StoreAddFriendship(m_pendingFriendRequests[transactionID], agentID, (uint) 1);
408 m_pendingFriendRequests.Remove(transactionID); 444 m_pendingFriendRequests.Remove(transactionID);
409 445
410 // TODO: Inform agent that the friend is online 446 // TODO: Inform agent that the friend is online
@@ -433,11 +469,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
433 msg.imSessionID = transactionID.UUID; 469 msg.imSessionID = transactionID.UUID;
434 msg.message = agentID.UUID.ToString(); 470 msg.message = agentID.UUID.ToString();
435 msg.ParentEstateID = 0; 471 msg.ParentEstateID = 0;
436 msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); 472 msg.timestamp = (uint) Util.UnixTimeSinceEpoch();
437 msg.RegionID = SceneAgentIn.RegionInfo.RegionID.UUID; 473 msg.RegionID = SceneAgentIn.RegionInfo.RegionID.UUID;
438 msg.dialog = (byte)40;// Deny friend request 474 msg.dialog = (byte) 40; // Deny friend request
439 msg.Position = new sLLVector3(); 475 msg.Position = new sLLVector3();
440 msg.offline = (byte)0; 476 msg.offline = (byte) 0;
441 msg.binaryBucket = new byte[0]; 477 msg.binaryBucket = new byte[0];
442 SceneAgentIn.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); 478 SceneAgentIn.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule);
443 m_pendingFriendRequests.Remove(transactionID); 479 m_pendingFriendRequests.Remove(transactionID);
@@ -453,52 +489,13 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
453 private void OnGridInstantMessage(GridInstantMessage msg) 489 private void OnGridInstantMessage(GridInstantMessage msg)
454 { 490 {
455 // Trigger the above event handler 491 // Trigger the above event handler
456 OnInstantMessage(null,new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession), 492 OnInstantMessage(null, new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession),
457 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,
458 msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID, 494 msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID,
459 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),
460 msg.binaryBucket); 496 msg.binaryBucket);
461 } 497 }
462 #endregion
463 private ScenePresence GetPresenceFromAgentID(LLUUID AgentID)
464 {
465 ScenePresence returnAgent = null;
466 lock (m_scene)
467 {
468 ScenePresence queryagent = null;
469 for (int i = 0; i < m_scene.Count; i++)
470 {
471 queryagent = m_scene[i].GetScenePresence(AgentID);
472 if (queryagent != null)
473 {
474 if (!queryagent.IsChildAgent)
475 {
476 returnAgent = queryagent;
477 break;
478 }
479 }
480 }
481 }
482 return returnAgent;
483
484 }
485
486 public void PostInitialise()
487 {
488 }
489
490 public void Close()
491 {
492 }
493 498
494 public string Name 499 #endregion
495 {
496 get { return "FriendsModule"; }
497 }
498
499 public bool IsSharedModule
500 {
501 get { return true; }
502 }
503 } 500 }
504} \ 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 4b28ad7..c4906d2 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/Groups/GroupsModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/Groups/GroupsModule.cs
@@ -41,10 +41,12 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Groups
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 List<Scene> m_scene = new List<Scene>();
45 private Dictionary<LLUUID, IClientAPI> m_iclientmap = new Dictionary<LLUUID, IClientAPI>();
46 private Dictionary<LLUUID, GroupData> m_groupmap = new Dictionary<LLUUID, GroupData>();
47 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>();
46 private Dictionary<LLUUID, IClientAPI> m_iclientmap = new Dictionary<LLUUID, IClientAPI>();
47 private List<Scene> m_scene = new List<Scene>();
48
49 #region IRegionModule Members
48 50
49 public void Initialise(Scene scene, IConfigSource config) 51 public void Initialise(Scene scene, IConfigSource config)
50 { 52 {
@@ -58,6 +60,42 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Groups
58 //scene.EventManager. 60 //scene.EventManager.
59 } 61 }
60 62
63 public void PostInitialise()
64 {
65 }
66
67 public void Close()
68 {
69 m_log.Info("[GROUP]: Shutting down group module.");
70 lock (m_iclientmap)
71 {
72 m_iclientmap.Clear();
73 }
74
75 lock (m_groupmap)
76 {
77 m_groupmap.Clear();
78 }
79
80 lock (m_grouplistmap)
81 {
82 m_grouplistmap.Clear();
83 }
84 GC.Collect();
85 }
86
87 public string Name
88 {
89 get { return "GroupsModule"; }
90 }
91
92 public bool IsSharedModule
93 {
94 get { return true; }
95 }
96
97 #endregion
98
61 private void OnNewClient(IClientAPI client) 99 private void OnNewClient(IClientAPI client)
62 { 100 {
63 // All friends establishment protocol goes over instant message 101 // All friends establishment protocol goes over instant message
@@ -115,7 +153,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Groups
115 string ActiveGroupTitle = ""; 153 string ActiveGroupTitle = "";
116 154
117 bool foundUser = false; 155 bool foundUser = false;
118 156
119 lock (m_iclientmap) 157 lock (m_iclientmap)
120 { 158 {
121 if (m_iclientmap.ContainsKey(remoteClient.AgentId)) 159 if (m_iclientmap.ContainsKey(remoteClient.AgentId))
@@ -139,11 +177,9 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Groups
139 } 177 }
140 178
141 //remoteClient.SendAgentDataUpdate(AgentID, ActiveGroupID, firstname, lastname, ActiveGroupPowers, ActiveGroupName, ActiveGroupTitle); 179 //remoteClient.SendAgentDataUpdate(AgentID, ActiveGroupID, firstname, lastname, ActiveGroupPowers, ActiveGroupName, ActiveGroupTitle);
142
143 } 180 }
144 } 181 }
145 } 182 }
146
147 } 183 }
148 184
149 private void OnInstantMessage(IClientAPI client, LLUUID fromAgentID, 185 private void OnInstantMessage(IClientAPI client, LLUUID fromAgentID,
@@ -183,7 +219,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Groups
183 m_iclientmap.Remove(agentID); 219 m_iclientmap.Remove(agentID);
184 } 220 }
185 } 221 }
186 222
187 lock (m_groupmap) 223 lock (m_groupmap)
188 { 224 {
189 if (m_groupmap.ContainsKey(agentID)) 225 if (m_groupmap.ContainsKey(agentID))
@@ -191,7 +227,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Groups
191 m_groupmap.Remove(agentID); 227 m_groupmap.Remove(agentID);
192 } 228 }
193 } 229 }
194 230
195 lock (m_grouplistmap) 231 lock (m_grouplistmap)
196 { 232 {
197 if (m_grouplistmap.ContainsKey(agentID)) 233 if (m_grouplistmap.ContainsKey(agentID))
@@ -201,63 +237,16 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Groups
201 } 237 }
202 GC.Collect(); 238 GC.Collect();
203 } 239 }
204
205 public void PostInitialise()
206 {
207 }
208
209 public void Close()
210 {
211 m_log.Info("[GROUP]: Shutting down group module.");
212 lock (m_iclientmap)
213 {
214 m_iclientmap.Clear();
215 }
216
217 lock (m_groupmap)
218 {
219 m_groupmap.Clear();
220 }
221
222 lock (m_grouplistmap)
223 {
224 m_grouplistmap.Clear();
225 }
226 GC.Collect();
227 }
228
229 public string Name
230 {
231 get { return "GroupsModule"; }
232 }
233
234 public bool IsSharedModule
235 {
236 get { return true; }
237 }
238
239 } 240 }
240 241
241 public class GroupData 242 public class GroupData
242 { 243 {
244 public string ActiveGroupTitle;
243 public LLUUID GroupID; 245 public LLUUID GroupID;
246 public List<LLUUID> GroupMembers;
244 public string groupName; 247 public string groupName;
245 public string ActiveGroupTitle; 248 public uint groupPowers = (uint) (GroupPowers.LandAllowLandmark | GroupPowers.LandAllowSetHome);
246 public List<string> GroupTitles; 249 public List<string> GroupTitles;
247 public List<LLUUID> GroupMembers;
248 public uint groupPowers = (uint)(GroupPowers.LandAllowLandmark | GroupPowers.LandAllowSetHome);
249
250 public GroupPowers ActiveGroupPowers
251 {
252 set
253 {
254 groupPowers = (uint) value;
255 }
256 get
257 {
258 return (GroupPowers)groupPowers;
259 }
260 }
261 250
262 public GroupData() 251 public GroupData()
263 { 252 {
@@ -265,11 +254,17 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Groups
265 GroupMembers = new List<LLUUID>(); 254 GroupMembers = new List<LLUUID>();
266 } 255 }
267 256
257 public GroupPowers ActiveGroupPowers
258 {
259 set { groupPowers = (uint) value; }
260 get { return (GroupPowers) groupPowers; }
261 }
268 } 262 }
269 263
270 public class GroupList 264 public class GroupList
271 { 265 {
272 public List<LLUUID> m_GroupList; 266 public List<LLUUID> m_GroupList;
267
273 public GroupList() 268 public GroupList()
274 { 269 {
275 m_GroupList = new List<LLUUID>(); 270 m_GroupList = new List<LLUUID>();
diff --git a/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs b/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs
index 1b82837..cb58b4c 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs
@@ -38,6 +38,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
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
42
41 public void Initialise(Scene scene, IConfigSource config) 43 public void Initialise(Scene scene, IConfigSource config)
42 { 44 {
43 lock (m_scenes) 45 lock (m_scenes)
@@ -56,27 +58,47 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
56 } 58 }
57 } 59 }
58 60
61 public void PostInitialise()
62 {
63 }
64
65 public void Close()
66 {
67 }
68
69 public string Name
70 {
71 get { return "InstantMessageModule"; }
72 }
73
74 public bool IsSharedModule
75 {
76 get { return true; }
77 }
78
79 #endregion
80
59 private void OnNewClient(IClientAPI client) 81 private void OnNewClient(IClientAPI client)
60 { 82 {
61 client.OnInstantMessage += OnInstantMessage; 83 client.OnInstantMessage += OnInstantMessage;
62 } 84 }
63 85
64 private void OnInstantMessage(IClientAPI client,LLUUID fromAgentID, 86 private void OnInstantMessage(IClientAPI client, LLUUID fromAgentID,
65 LLUUID fromAgentSession, LLUUID toAgentID, 87 LLUUID fromAgentSession, LLUUID toAgentID,
66 LLUUID imSessionID, uint timestamp, string fromAgentName, 88 LLUUID imSessionID, uint timestamp, string fromAgentName,
67 string message, byte dialog, bool fromGroup, byte offline, 89 string message, byte dialog, bool fromGroup, byte offline,
68 uint ParentEstateID, LLVector3 Position, LLUUID RegionID, 90 uint ParentEstateID, LLVector3 Position, LLUUID RegionID,
69 byte[] binaryBucket) 91 byte[] binaryBucket)
70 { 92 {
71 bool dialogHandledElsewhere 93 bool dialogHandledElsewhere
72 = ((dialog == 38) || (dialog == 39) || (dialog == 40) 94 = ((dialog == 38) || (dialog == 39) || (dialog == 40)
73 || dialog == (byte)InstantMessageDialog.InventoryOffered 95 || dialog == (byte) InstantMessageDialog.InventoryOffered
74 || dialog == (byte)InstantMessageDialog.InventoryAccepted 96 || dialog == (byte) InstantMessageDialog.InventoryAccepted
75 || dialog == (byte)InstantMessageDialog.InventoryDeclined); 97 || dialog == (byte) InstantMessageDialog.InventoryDeclined);
76 98
77 // 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
78 // so the sim can match the transaction on the return packet. 100 // so the sim can match the transaction on the return packet.
79 101
80 // 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.
81 if (!(dialogHandledElsewhere && imSessionID == LLUUID.Zero)) 103 if (!(dialogHandledElsewhere && imSessionID == LLUUID.Zero))
82 { 104 {
@@ -86,7 +108,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
86 if (scene.Entities.ContainsKey(toAgentID) && scene.Entities[toAgentID] is ScenePresence) 108 if (scene.Entities.ContainsKey(toAgentID) && scene.Entities[toAgentID] is ScenePresence)
87 { 109 {
88 // Local message 110 // Local message
89 ScenePresence user = (ScenePresence)scene.Entities[toAgentID]; 111 ScenePresence user = (ScenePresence) scene.Entities[toAgentID];
90 if (!user.IsChildAgent) 112 if (!user.IsChildAgent)
91 { 113 {
92 user.ControllingClient.SendInstantMessage(fromAgentID, fromAgentSession, message, 114 user.ControllingClient.SendInstantMessage(fromAgentID, fromAgentSession, message,
@@ -104,54 +126,33 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage
104 if (scene.Entities.ContainsKey(toAgentID) && scene.Entities[toAgentID] is ScenePresence) 126 if (scene.Entities.ContainsKey(toAgentID) && scene.Entities[toAgentID] is ScenePresence)
105 { 127 {
106 // Local message 128 // Local message
107 ScenePresence user = (ScenePresence)scene.Entities[toAgentID]; 129 ScenePresence user = (ScenePresence) scene.Entities[toAgentID];
108 130
109 user.ControllingClient.SendInstantMessage(fromAgentID, fromAgentSession, message, 131 user.ControllingClient.SendInstantMessage(fromAgentID, fromAgentSession, message,
110 toAgentID, imSessionID, fromAgentName, dialog, 132 toAgentID, imSessionID, fromAgentName, dialog,
111 timestamp); 133 timestamp);
112 // Message sent 134 // Message sent
113 return; 135 return;
114
115 } 136 }
116 } 137 }
117
118 } 138 }
119 139
120 140
121 // Still here, try send via Grid 141 // Still here, try send via Grid
122 // TODO 142 // TODO
123 } 143 }
124 144
125 // 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
126 // 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.
127 147
128 private void OnGridInstantMessage(GridInstantMessage msg) 148 private void OnGridInstantMessage(GridInstantMessage msg)
129 { 149 {
130 // Trigger the above event handler 150 // Trigger the above event handler
131 OnInstantMessage(null,new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession), 151 OnInstantMessage(null, new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession),
132 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,
133 msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID, 153 msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID,
134 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),
135 msg.binaryBucket); 155 msg.binaryBucket);
136
137 }
138
139 public void PostInitialise()
140 {
141 }
142
143 public void Close()
144 {
145 }
146
147 public string Name
148 {
149 get { return "InstantMessageModule"; }
150 }
151
152 public bool IsSharedModule
153 {
154 get { return true; }
155 } 156 }
156 } 157 }
157} \ 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 42c6238..2844450 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/Inventory/InventoryModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/Inventory/InventoryModule.cs
@@ -38,11 +38,9 @@ namespace 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 private Scene m_scene;
45
46 /// <summary> 44 /// <summary>
47 /// 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
48 /// 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
@@ -50,10 +48,14 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Inventory
50 /// </summary> 48 /// </summary>
51 private IDictionary<LLUUID, LLUUID> m_pendingOffers = new Dictionary<LLUUID, LLUUID>(); 49 private IDictionary<LLUUID, LLUUID> m_pendingOffers = new Dictionary<LLUUID, LLUUID>();
52 50
51 private Scene m_scene;
52
53 #region IRegionModule Members
54
53 public void Initialise(Scene scene, IConfigSource config) 55 public void Initialise(Scene scene, IConfigSource config)
54 { 56 {
55 m_scene = scene; 57 m_scene = scene;
56 scene.EventManager.OnNewClient += OnNewClient; 58 scene.EventManager.OnNewClient += OnNewClient;
57 } 59 }
58 60
59 public void PostInitialise() 61 public void PostInitialise()
@@ -73,59 +75,61 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Inventory
73 { 75 {
74 get { return false; } 76 get { return false; }
75 } 77 }
76 78
79 #endregion
80
77 private void OnNewClient(IClientAPI client) 81 private void OnNewClient(IClientAPI client)
78 { 82 {
79 // Inventory giving is conducted via instant message 83 // Inventory giving is conducted via instant message
80 client.OnInstantMessage += OnInstantMessage; 84 client.OnInstantMessage += OnInstantMessage;
81 } 85 }
82 86
83 private void OnInstantMessage(IClientAPI client, LLUUID fromAgentID, 87 private void OnInstantMessage(IClientAPI client, LLUUID fromAgentID,
84 LLUUID fromAgentSession, LLUUID toAgentID, 88 LLUUID fromAgentSession, LLUUID toAgentID,
85 LLUUID imSessionID, uint timestamp, string fromAgentName, 89 LLUUID imSessionID, uint timestamp, string fromAgentName,
86 string message, byte dialog, bool fromGroup, byte offline, 90 string message, byte dialog, bool fromGroup, byte offline,
87 uint ParentEstateID, LLVector3 Position, LLUUID RegionID, 91 uint ParentEstateID, LLVector3 Position, LLUUID RegionID,
88 byte[] binaryBucket) 92 byte[] binaryBucket)
89 { 93 {
90 if (dialog == (byte)InstantMessageDialog.InventoryOffered) 94 if (dialog == (byte) InstantMessageDialog.InventoryOffered)
91 { 95 {
92 m_log.DebugFormat( 96 m_log.DebugFormat(
93 "[AGENT INVENTORY]: Routing inventory offering message from {0}, {1} to {2}", 97 "[AGENT INVENTORY]: Routing inventory offering message from {0}, {1} to {2}",
94 client.AgentId, client.Name, toAgentID); 98 client.AgentId, client.Name, toAgentID);
95 99
96 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)
97 { 101 {
98 ScenePresence user = (ScenePresence)m_scene.Entities[toAgentID]; 102 ScenePresence user = (ScenePresence) m_scene.Entities[toAgentID];
99 103
100 if (!user.IsChildAgent) 104 if (!user.IsChildAgent)
101 { 105 {
102 //byte[] rawId = new byte[16]; 106 //byte[] rawId = new byte[16];
103 107
104 // First byte of the array is probably the item type 108 // First byte of the array is probably the item type
105 // Next 16 bytes are the UUID 109 // Next 16 bytes are the UUID
106 //Array.Copy(binaryBucket, 1, rawId, 0, 16); 110 //Array.Copy(binaryBucket, 1, rawId, 0, 16);
107 111
108 //LLUUID itemId = new LLUUID(new Guid(rawId)); 112 //LLUUID itemId = new LLUUID(new Guid(rawId));
109 LLUUID itemId = new LLUUID(binaryBucket, 1); 113 LLUUID itemId = new LLUUID(binaryBucket, 1);
110 114
111 m_log.DebugFormat( 115 m_log.DebugFormat(
112 "[AGENT INVENTORY]: ItemId for giving is {0}", itemId); 116 "[AGENT INVENTORY]: ItemId for giving is {0}", itemId);
113 117
114 m_pendingOffers[imSessionID] = itemId; 118 m_pendingOffers[imSessionID] = itemId;
115 119
116 user.ControllingClient.SendInstantMessage( 120 user.ControllingClient.SendInstantMessage(
117 fromAgentID, fromAgentSession, message, toAgentID, imSessionID, fromAgentName, 121 fromAgentID, fromAgentSession, message, toAgentID, imSessionID, fromAgentName,
118 dialog, timestamp, binaryBucket); 122 dialog, timestamp, binaryBucket);
119 123
120 return; 124 return;
121 } 125 }
122 else 126 else
123 { 127 {
124 m_log.WarnFormat( 128 m_log.WarnFormat(
125 "[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!",
126 toAgentID, client.AgentId, client.Name, message); 130 toAgentID, client.AgentId, client.Name, message);
127 } 131 }
128 } 132 }
129 else 133 else
130 { 134 {
131 m_log.WarnFormat( 135 m_log.WarnFormat(
@@ -133,84 +137,84 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Inventory
133 toAgentID, client.AgentId, client.Name, message); 137 toAgentID, client.AgentId, client.Name, message);
134 } 138 }
135 } 139 }
136 else if (dialog == (byte)InstantMessageDialog.InventoryAccepted) 140 else if (dialog == (byte) InstantMessageDialog.InventoryAccepted)
137 { 141 {
138 m_log.DebugFormat( 142 m_log.DebugFormat(
139 "[AGENT INVENTORY]: Routing inventory accepted message from {0}, {1} to {2}", 143 "[AGENT INVENTORY]: Routing inventory accepted message from {0}, {1} to {2}",
140 client.AgentId, client.Name, toAgentID); 144 client.AgentId, client.Name, toAgentID);
141 145
142 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)
143 { 147 {
144 ScenePresence user = (ScenePresence)m_scene.Entities[toAgentID]; 148 ScenePresence user = (ScenePresence) m_scene.Entities[toAgentID];
145 149
146 if (!user.IsChildAgent) 150 if (!user.IsChildAgent)
147 { 151 {
148 user.ControllingClient.SendInstantMessage( 152 user.ControllingClient.SendInstantMessage(
149 fromAgentID, fromAgentSession, message, toAgentID, imSessionID, fromAgentName, 153 fromAgentID, fromAgentSession, message, toAgentID, imSessionID, fromAgentName,
150 dialog, timestamp, binaryBucket); 154 dialog, timestamp, binaryBucket);
151 155
152 if (m_pendingOffers.ContainsKey(imSessionID)) 156 if (m_pendingOffers.ContainsKey(imSessionID))
153 { 157 {
154 m_log.DebugFormat( 158 m_log.DebugFormat(
155 "[AGENT INVENTORY]: Accepted item id {0}", m_pendingOffers[imSessionID]); 159 "[AGENT INVENTORY]: Accepted item id {0}", m_pendingOffers[imSessionID]);
156 160
157 // Since the message originates from the accepting client, the toAgentID is 161 // Since the message originates from the accepting client, the toAgentID is
158 // the agent giving the item. 162 // the agent giving the item.
159 m_scene.GiveInventoryItem(client, toAgentID, m_pendingOffers[imSessionID]); 163 m_scene.GiveInventoryItem(client, toAgentID, m_pendingOffers[imSessionID]);
160 164
161 m_pendingOffers.Remove(imSessionID); 165 m_pendingOffers.Remove(imSessionID);
162 } 166 }
163 else 167 else
164 { 168 {
165 m_log.ErrorFormat( 169 m_log.ErrorFormat(
166 "[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",
167 imSessionID); 171 imSessionID);
168 } 172 }
169 173
170 return; 174 return;
171 } 175 }
172 else 176 else
173 { 177 {
174 m_log.WarnFormat( 178 m_log.WarnFormat(
175 "[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!",
176 toAgentID, client.AgentId, client.Name, message); 180 toAgentID, client.AgentId, client.Name, message);
177 } 181 }
178 } 182 }
179 else 183 else
180 { 184 {
181 m_log.WarnFormat( 185 m_log.WarnFormat(
182 "[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}",
183 toAgentID, client.AgentId, client.Name, message); 187 toAgentID, client.AgentId, client.Name, message);
184 } 188 }
185 } 189 }
186 else if (dialog == (byte)InstantMessageDialog.InventoryDeclined) 190 else if (dialog == (byte) InstantMessageDialog.InventoryDeclined)
187 { 191 {
188 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)
189 { 193 {
190 ScenePresence user = (ScenePresence)m_scene.Entities[toAgentID]; 194 ScenePresence user = (ScenePresence) m_scene.Entities[toAgentID];
191 195
192 if (!user.IsChildAgent) 196 if (!user.IsChildAgent)
193 { 197 {
194 user.ControllingClient.SendInstantMessage( 198 user.ControllingClient.SendInstantMessage(
195 fromAgentID, fromAgentSession, message, toAgentID, imSessionID, fromAgentName, 199 fromAgentID, fromAgentSession, message, toAgentID, imSessionID, fromAgentName,
196 dialog, timestamp, binaryBucket); 200 dialog, timestamp, binaryBucket);
197 201
198 if (m_pendingOffers.ContainsKey(imSessionID)) 202 if (m_pendingOffers.ContainsKey(imSessionID))
199 { 203 {
200 m_log.DebugFormat( 204 m_log.DebugFormat(
201 "[AGENT INVENTORY]: Declined item id {0}", m_pendingOffers[imSessionID]); 205 "[AGENT INVENTORY]: Declined item id {0}", m_pendingOffers[imSessionID]);
202 206
203 m_pendingOffers.Remove(imSessionID); 207 m_pendingOffers.Remove(imSessionID);
204 } 208 }
205 else 209 else
206 { 210 {
207 m_log.ErrorFormat( 211 m_log.ErrorFormat(
208 "[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",
209 imSessionID); 213 imSessionID);
210 } 214 }
211 } 215 }
212 } 216 }
213 } 217 }
214 } 218 }
215 } 219 }
216} \ 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 f8b14d3..1955d2a 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/Profiles/AvatarProfilesModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/Profiles/AvatarProfilesModule.cs
@@ -45,6 +45,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Profiles
45 { 45 {
46 } 46 }
47 47
48 #region IRegionModule Members
49
48 public void Initialise(Scene scene, IConfigSource config) 50 public void Initialise(Scene scene, IConfigSource config)
49 { 51 {
50 m_scene = scene; 52 m_scene = scene;
@@ -69,6 +71,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Profiles
69 get { return false; } 71 get { return false; }
70 } 72 }
71 73
74 #endregion
75
72 public void NewClient(IClientAPI client) 76 public void NewClient(IClientAPI client)
73 { 77 {
74 client.OnRequestAvatarProperties += RequestAvatarProperty; 78 client.OnRequestAvatarProperties += RequestAvatarProperty;
@@ -107,7 +111,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Profiles
107 public void UpdateAvatarProperties(IClientAPI remoteClient, UserProfileData newProfile) 111 public void UpdateAvatarProperties(IClientAPI remoteClient, UserProfileData newProfile)
108 { 112 {
109 UserProfileData Profile = m_scene.CommsManager.UserService.GetUserProfile(newProfile.ID); 113 UserProfileData Profile = m_scene.CommsManager.UserService.GetUserProfile(newProfile.ID);
110 114
111 // 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.
112 if (remoteClient.AgentId.CompareTo(Profile.ID) == 0) 116 if (remoteClient.AgentId.CompareTo(Profile.ID) == 0)
113 { 117 {
diff --git a/OpenSim/Region/Environment/Modules/Avatar/Voice/AsterixVoice/AsteriskVoiceModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Voice/AsterixVoice/AsteriskVoiceModule.cs
index 0d7de78..44d67e6 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/Voice/AsterixVoice/AsteriskVoiceModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/Voice/AsterixVoice/AsteriskVoiceModule.cs
@@ -44,40 +44,43 @@ namespace 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 Scene m_scene; 50 private static readonly string m_parcelVoiceInfoRequestPath = "0007/";
51 private IConfig m_config; 51 private static readonly string m_provisionVoiceAccountRequestPath = "0008/";
52
52 private string m_asterisk; 53 private string m_asterisk;
53 private string m_asterisk_password; 54 private string m_asterisk_password;
54 private string m_asterisk_salt; 55 private string m_asterisk_salt;
55 private int m_asterisk_timeout; 56 private int m_asterisk_timeout;
56 private string m_sipDomain;
57 private string m_confDomain; 57 private string m_confDomain;
58 private IConfig m_config;
59 private Scene m_scene;
60 private string m_sipDomain;
58 61
59 private static readonly string m_parcelVoiceInfoRequestPath = "0007/"; 62 #region IRegionModule Members
60 private static readonly string m_provisionVoiceAccountRequestPath = "0008/";
61 63
62 public void Initialise(Scene scene, IConfigSource config) 64 public void Initialise(Scene scene, IConfigSource config)
63 { 65 {
64 m_scene = scene; 66 m_scene = scene;
65 m_config = config.Configs["AsteriskVoice"]; 67 m_config = config.Configs["AsteriskVoice"];
66 68
67 if (null == m_config) 69 if (null == m_config)
68 { 70 {
69 m_log.Info("[ASTERISKVOICE] no config found, plugin disabled"); 71 m_log.Info("[ASTERISKVOICE] no config found, plugin disabled");
70 return; 72 return;
71 } 73 }
72 74
73 if (!m_config.GetBoolean("enabled", false)) 75 if (!m_config.GetBoolean("enabled", false))
74 { 76 {
75 m_log.Info("[ASTERISKVOICE] plugin disabled by configuration"); 77 m_log.Info("[ASTERISKVOICE] plugin disabled by configuration");
76 return; 78 return;
77 } 79 }
78 m_log.Info("[ASTERISKVOICE] plugin enabled"); 80 m_log.Info("[ASTERISKVOICE] plugin enabled");
79 81
80 try { 82 try
83 {
81 m_sipDomain = m_config.GetString("sip_domain", String.Empty); 84 m_sipDomain = m_config.GetString("sip_domain", String.Empty);
82 m_log.InfoFormat("[ASTERISKVOICE] using SIP domain {0}", m_sipDomain); 85 m_log.InfoFormat("[ASTERISKVOICE] using SIP domain {0}", m_sipDomain);
83 86
@@ -91,17 +94,17 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.AsterixVoice
91 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");
92 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");
93 m_log.InfoFormat("[ASTERISKVOICE] using asterisk front end {0}", m_asterisk); 96 m_log.InfoFormat("[ASTERISKVOICE] using asterisk front end {0}", m_asterisk);
94 97
95 scene.EventManager.OnRegisterCaps += OnRegisterCaps; 98 scene.EventManager.OnRegisterCaps += OnRegisterCaps;
96 } 99 }
97 catch (Exception e) 100 catch (Exception e)
98 { 101 {
99 m_log.ErrorFormat("[ASTERISKVOICE] plugin initialization failed: {0}", e.Message); 102 m_log.ErrorFormat("[ASTERISKVOICE] plugin initialization failed: {0}", e.Message);
100 m_log.DebugFormat("[ASTERISKVOICE] plugin initialization failed: {0}", e.ToString()); 103 m_log.DebugFormat("[ASTERISKVOICE] plugin initialization failed: {0}", e.ToString());
101 return; 104 return;
102 } 105 }
103 } 106 }
104 107
105 public void PostInitialise() 108 public void PostInitialise()
106 { 109 {
107 } 110 }
@@ -120,15 +123,17 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.AsterixVoice
120 get { return false; } 123 get { return false; }
121 } 124 }
122 125
123 public void OnRegisterCaps(LLUUID agentID, Caps caps) 126 #endregion
127
128 public void OnRegisterCaps(LLUUID agentID, Caps caps)
124 { 129 {
125 m_log.DebugFormat("[ASTERISKVOICE] OnRegisterCaps: agentID {0} caps {1}", agentID, caps); 130 m_log.DebugFormat("[ASTERISKVOICE] OnRegisterCaps: agentID {0} caps {1}", agentID, caps);
126 string capsBase = "/CAPS/" + caps.CapsObjectPath; 131 string capsBase = "/CAPS/" + caps.CapsObjectPath;
127 caps.RegisterHandler("ParcelVoiceInfoRequest", 132 caps.RegisterHandler("ParcelVoiceInfoRequest",
128 new RestStreamHandler("POST", capsBase + m_parcelVoiceInfoRequestPath, 133 new RestStreamHandler("POST", capsBase + m_parcelVoiceInfoRequestPath,
129 delegate(string request, string path, string param) 134 delegate(string request, string path, string param)
130 { 135 {
131 return ParcelVoiceInfoRequest(request, path, param, 136 return ParcelVoiceInfoRequest(request, path, param,
132 agentID, caps); 137 agentID, caps);
133 })); 138 }));
134 caps.RegisterHandler("ProvisionVoiceAccountRequest", 139 caps.RegisterHandler("ProvisionVoiceAccountRequest",
@@ -139,7 +144,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.AsterixVoice
139 agentID, caps); 144 agentID, caps);
140 })); 145 }));
141 } 146 }
142 147
143 /// <summary> 148 /// <summary>
144 /// Callback for a client request for ParcelVoiceInfo 149 /// Callback for a client request for ParcelVoiceInfo
145 /// </summary> 150 /// </summary>
@@ -149,30 +154,30 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.AsterixVoice
149 /// <param name="agentID"></param> 154 /// <param name="agentID"></param>
150 /// <param name="caps"></param> 155 /// <param name="caps"></param>
151 /// <returns></returns> 156 /// <returns></returns>
152 public string ParcelVoiceInfoRequest(string request, string path, string param, 157 public string ParcelVoiceInfoRequest(string request, string path, string param,
153 LLUUID agentID, Caps caps) 158 LLUUID agentID, Caps caps)
154 { 159 {
155 // we need to do: 160 // we need to do:
156 // - send channel_uri: as "sip:regionID@m_sipDomain" 161 // - send channel_uri: as "sip:regionID@m_sipDomain"
157 try 162 try
158 { 163 {
159 m_log.DebugFormat("[ASTERISKVOICE][PARCELVOICE]: request: {0}, path: {1}, param: {2}", 164 m_log.DebugFormat("[ASTERISKVOICE][PARCELVOICE]: request: {0}, path: {1}, param: {2}",
160 request, path, param); 165 request, path, param);
161 166
162 167
163 // setup response to client 168 // setup response to client
164 Hashtable creds = new Hashtable(); 169 Hashtable creds = new Hashtable();
165 creds["channel_uri"] = String.Format("sip:{0}@{1}", 170 creds["channel_uri"] = String.Format("sip:{0}@{1}",
166 m_scene.RegionInfo.RegionID, m_sipDomain); 171 m_scene.RegionInfo.RegionID, m_sipDomain);
167 172
168 string regionName = m_scene.RegionInfo.RegionName; 173 string regionName = m_scene.RegionInfo.RegionName;
169 ScenePresence avatar = m_scene.GetScenePresence(agentID); 174 ScenePresence avatar = m_scene.GetScenePresence(agentID);
170 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");
171 LandData land = m_scene.GetLandData(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); 176 LandData land = m_scene.GetLandData(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
172 177
173 LLSDParcelVoiceInfoResponse parcelVoiceInfo = 178 LLSDParcelVoiceInfoResponse parcelVoiceInfo =
174 new LLSDParcelVoiceInfoResponse(regionName, land.localID, creds); 179 new LLSDParcelVoiceInfoResponse(regionName, land.localID, creds);
175 180
176 string r = LLSDHelpers.SerialiseLLSDReply(parcelVoiceInfo); 181 string r = LLSDHelpers.SerialiseLLSDReply(parcelVoiceInfo);
177 182
178 183
@@ -183,17 +188,17 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.AsterixVoice
183 if (!String.IsNullOrEmpty(m_confDomain)) 188 if (!String.IsNullOrEmpty(m_confDomain))
184 { 189 {
185 requestData["region"] += String.Format("@{0}", m_confDomain); 190 requestData["region"] += String.Format("@{0}", m_confDomain);
186 } 191 }
187 192
188 ArrayList SendParams = new ArrayList(); 193 ArrayList SendParams = new ArrayList();
189 SendParams.Add(requestData); 194 SendParams.Add(requestData);
190 XmlRpcRequest updateAccountRequest = new XmlRpcRequest("region_update", SendParams); 195 XmlRpcRequest updateAccountRequest = new XmlRpcRequest("region_update", SendParams);
191 XmlRpcResponse updateAccountResponse = updateAccountRequest.Send(m_asterisk, m_asterisk_timeout); 196 XmlRpcResponse updateAccountResponse = updateAccountRequest.Send(m_asterisk, m_asterisk_timeout);
192 Hashtable responseData = (Hashtable)updateAccountResponse.Value; 197 Hashtable responseData = (Hashtable) updateAccountResponse.Value;
193 198
194 if (!responseData.ContainsKey("success")) throw new Exception("region_update call failed"); 199 if (!responseData.ContainsKey("success")) throw new Exception("region_update call failed");
195 200
196 bool success = Convert.ToBoolean((string)responseData["success"]); 201 bool success = Convert.ToBoolean((string) responseData["success"]);
197 if (!success) throw new Exception("region_update failed"); 202 if (!success) throw new Exception("region_update failed");
198 203
199 204
@@ -218,8 +223,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.AsterixVoice
218 /// <param name="agentID"></param> 223 /// <param name="agentID"></param>
219 /// <param name="caps"></param> 224 /// <param name="caps"></param>
220 /// <returns></returns> 225 /// <returns></returns>
221 public string ProvisionVoiceAccountRequest(string request, string path, string param, 226 public string ProvisionVoiceAccountRequest(string request, string path, string param,
222 LLUUID agentID, Caps caps) 227 LLUUID agentID, Caps caps)
223 { 228 {
224 // we need to 229 // we need to
225 // - get user data from UserProfileCacheService 230 // - get user data from UserProfileCacheService
@@ -232,7 +237,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.AsterixVoice
232 // send account details back to client 237 // send account details back to client
233 try 238 try
234 { 239 {
235 m_log.DebugFormat("[ASTERISKVOICE][PROVISIONVOICE]: request: {0}, path: {1}, param: {2}", 240 m_log.DebugFormat("[ASTERISKVOICE][PROVISIONVOICE]: request: {0}, path: {1}, param: {2}",
236 request, path, param); 241 request, path, param);
237 242
238 // get user data & prepare voice account response 243 // get user data & prepare voice account response
@@ -244,7 +249,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.AsterixVoice
244 249
245 // we generate a nonce everytime 250 // we generate a nonce everytime
246 string voicePassword = "$1$" + Util.Md5Hash(DateTime.UtcNow.ToLongTimeString() + m_asterisk_salt); 251 string voicePassword = "$1$" + Util.Md5Hash(DateTime.UtcNow.ToLongTimeString() + m_asterisk_salt);
247 LLSDVoiceAccountResponse voiceAccountResponse = 252 LLSDVoiceAccountResponse voiceAccountResponse =
248 new LLSDVoiceAccountResponse(voiceUser, voicePassword); 253 new LLSDVoiceAccountResponse(voiceUser, voicePassword);
249 string r = LLSDHelpers.SerialiseLLSDReply(voiceAccountResponse); 254 string r = LLSDHelpers.SerialiseLLSDReply(voiceAccountResponse);
250 m_log.DebugFormat("[CAPS][PROVISIONVOICE]: {0}", r); 255 m_log.DebugFormat("[CAPS][PROVISIONVOICE]: {0}", r);
@@ -257,18 +262,18 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.AsterixVoice
257 if (!String.IsNullOrEmpty(m_sipDomain)) 262 if (!String.IsNullOrEmpty(m_sipDomain))
258 { 263 {
259 requestData["username"] += String.Format("@{0}", m_sipDomain); 264 requestData["username"] += String.Format("@{0}", m_sipDomain);
260 } 265 }
261 requestData["password"] = voicePassword; 266 requestData["password"] = voicePassword;
262 267
263 ArrayList SendParams = new ArrayList(); 268 ArrayList SendParams = new ArrayList();
264 SendParams.Add(requestData); 269 SendParams.Add(requestData);
265 XmlRpcRequest updateAccountRequest = new XmlRpcRequest("account_update", SendParams); 270 XmlRpcRequest updateAccountRequest = new XmlRpcRequest("account_update", SendParams);
266 XmlRpcResponse updateAccountResponse = updateAccountRequest.Send(m_asterisk, m_asterisk_timeout); 271 XmlRpcResponse updateAccountResponse = updateAccountRequest.Send(m_asterisk, m_asterisk_timeout);
267 Hashtable responseData = (Hashtable)updateAccountResponse.Value; 272 Hashtable responseData = (Hashtable) updateAccountResponse.Value;
268 273
269 if (!responseData.ContainsKey("success")) throw new Exception("account_update call failed"); 274 if (!responseData.ContainsKey("success")) throw new Exception("account_update call failed");
270 275
271 bool success = Convert.ToBoolean((string)responseData["success"]); 276 bool success = Convert.ToBoolean((string) responseData["success"]);
272 if (!success) throw new Exception("account_update failed"); 277 if (!success) throw new Exception("account_update failed");
273 278
274 return r; 279 return r;
diff --git a/OpenSim/Region/Environment/Modules/Avatar/Voice/SIPVoice/SIPVoiceModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Voice/SIPVoice/SIPVoiceModule.cs
index 8b7c3d0..8d9ba6f 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/Voice/SIPVoice/SIPVoiceModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/Voice/SIPVoice/SIPVoiceModule.cs
@@ -43,22 +43,23 @@ namespace 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 Scene m_scene; 49 private static readonly string m_parcelVoiceInfoRequestPath = "0007/";
50 private static readonly string m_provisionVoiceAccountRequestPath = "0008/";
50 private IConfig m_config; 51 private IConfig m_config;
52 private Scene m_scene;
51 private string m_sipDomain; 53 private string m_sipDomain;
52 54
53 private static readonly string m_parcelVoiceInfoRequestPath = "0007/"; 55 #region IRegionModule Members
54 private static readonly string m_provisionVoiceAccountRequestPath = "0008/";
55 56
56 public void Initialise(Scene scene, IConfigSource config) 57 public void Initialise(Scene scene, IConfigSource config)
57 { 58 {
58 m_scene = scene; 59 m_scene = scene;
59 m_config = config.Configs["Voice"]; 60 m_config = config.Configs["Voice"];
60 61
61 if (null == m_config || !m_config.GetBoolean("enabled", false)) 62 if (null == m_config || !m_config.GetBoolean("enabled", false))
62 { 63 {
63 m_log.Info("[VOICE] plugin disabled"); 64 m_log.Info("[VOICE] plugin disabled");
64 return; 65 return;
@@ -95,15 +96,17 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.SIPVoice
95 get { return false; } 96 get { return false; }
96 } 97 }
97 98
98 public void OnRegisterCaps(LLUUID agentID, Caps caps) 99 #endregion
100
101 public void OnRegisterCaps(LLUUID agentID, Caps caps)
99 { 102 {
100 m_log.DebugFormat("[VOICE] OnRegisterCaps: agentID {0} caps {1}", agentID, caps); 103 m_log.DebugFormat("[VOICE] OnRegisterCaps: agentID {0} caps {1}", agentID, caps);
101 string capsBase = "/CAPS/" + caps.CapsObjectPath; 104 string capsBase = "/CAPS/" + caps.CapsObjectPath;
102 caps.RegisterHandler("ParcelVoiceInfoRequest", 105 caps.RegisterHandler("ParcelVoiceInfoRequest",
103 new RestStreamHandler("POST", capsBase + m_parcelVoiceInfoRequestPath, 106 new RestStreamHandler("POST", capsBase + m_parcelVoiceInfoRequestPath,
104 delegate(string request, string path, string param) 107 delegate(string request, string path, string param)
105 { 108 {
106 return ParcelVoiceInfoRequest(request, path, param, 109 return ParcelVoiceInfoRequest(request, path, param,
107 agentID, caps); 110 agentID, caps);
108 })); 111 }));
109 caps.RegisterHandler("ProvisionVoiceAccountRequest", 112 caps.RegisterHandler("ProvisionVoiceAccountRequest",
@@ -114,7 +117,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.SIPVoice
114 agentID, caps); 117 agentID, caps);
115 })); 118 }));
116 } 119 }
117 120
118 /// <summary> 121 /// <summary>
119 /// Callback for a client request for ParcelVoiceInfo 122 /// Callback for a client request for ParcelVoiceInfo
120 /// </summary> 123 /// </summary>
@@ -124,8 +127,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.SIPVoice
124 /// <param name="agentID"></param> 127 /// <param name="agentID"></param>
125 /// <param name="caps"></param> 128 /// <param name="caps"></param>
126 /// <returns></returns> 129 /// <returns></returns>
127 public string ParcelVoiceInfoRequest(string request, string path, string param, 130 public string ParcelVoiceInfoRequest(string request, string path, string param,
128 LLUUID agentID, Caps caps) 131 LLUUID agentID, Caps caps)
129 { 132 {
130 try 133 try
131 { 134 {
@@ -135,15 +138,15 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.SIPVoice
135 Hashtable creds = new Hashtable(); 138 Hashtable creds = new Hashtable();
136 139
137 creds["channel_uri"] = String.Format("sip:{0}@{1}", agentID, m_sipDomain); 140 creds["channel_uri"] = String.Format("sip:{0}@{1}", agentID, m_sipDomain);
138 141
139 string regionName = m_scene.RegionInfo.RegionName; 142 string regionName = m_scene.RegionInfo.RegionName;
140 ScenePresence avatar = m_scene.GetScenePresence(agentID); 143 ScenePresence avatar = m_scene.GetScenePresence(agentID);
141 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");
142 LandData land = m_scene.GetLandData(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); 145 LandData land = m_scene.GetLandData(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
143 146
144 LLSDParcelVoiceInfoResponse parcelVoiceInfo = 147 LLSDParcelVoiceInfoResponse parcelVoiceInfo =
145 new LLSDParcelVoiceInfoResponse(regionName, land.localID, creds); 148 new LLSDParcelVoiceInfoResponse(regionName, land.localID, creds);
146 149
147 string r = LLSDHelpers.SerialiseLLSDReply(parcelVoiceInfo); 150 string r = LLSDHelpers.SerialiseLLSDReply(parcelVoiceInfo);
148 m_log.DebugFormat("[VOICE][PARCELVOICE]: {0}", r); 151 m_log.DebugFormat("[VOICE][PARCELVOICE]: {0}", r);
149 152
@@ -153,7 +156,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.SIPVoice
153 { 156 {
154 m_log.ErrorFormat("[CAPS]: {0}, try again later", e.ToString()); 157 m_log.ErrorFormat("[CAPS]: {0}, try again later", e.ToString());
155 } 158 }
156 159
157 return null; 160 return null;
158 } 161 }
159 162
@@ -166,12 +169,12 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.SIPVoice
166 /// <param name="agentID"></param> 169 /// <param name="agentID"></param>
167 /// <param name="caps"></param> 170 /// <param name="caps"></param>
168 /// <returns></returns> 171 /// <returns></returns>
169 public string ProvisionVoiceAccountRequest(string request, string path, string param, 172 public string ProvisionVoiceAccountRequest(string request, string path, string param,
170 LLUUID agentID, Caps caps) 173 LLUUID agentID, Caps caps)
171 { 174 {
172 try 175 try
173 { 176 {
174 m_log.DebugFormat("[VOICE][PROVISIONVOICE]: request: {0}, path: {1}, param: {2}", 177 m_log.DebugFormat("[VOICE][PROVISIONVOICE]: request: {0}, path: {1}, param: {2}",
175 request, path, param); 178 request, path, param);
176 179
177 string voiceUser = "x" + Convert.ToBase64String(agentID.GetBytes()); 180 string voiceUser = "x" + Convert.ToBase64String(agentID.GetBytes());
@@ -180,7 +183,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.SIPVoice
180 CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(agentID); 183 CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(agentID);
181 if (null == userInfo) throw new Exception("cannot get user details"); 184 if (null == userInfo) throw new Exception("cannot get user details");
182 185
183 LLSDVoiceAccountResponse voiceAccountResponse = 186 LLSDVoiceAccountResponse voiceAccountResponse =
184 new LLSDVoiceAccountResponse(voiceUser, "$1$" + userInfo.UserProfile.PasswordHash); 187 new LLSDVoiceAccountResponse(voiceUser, "$1$" + userInfo.UserProfile.PasswordHash);
185 string r = LLSDHelpers.SerialiseLLSDReply(voiceAccountResponse); 188 string r = LLSDHelpers.SerialiseLLSDReply(voiceAccountResponse);
186 m_log.DebugFormat("[CAPS][PROVISIONVOICE]: {0}", r); 189 m_log.DebugFormat("[CAPS][PROVISIONVOICE]: {0}", r);