aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/ChatModule.cs
diff options
context:
space:
mode:
authorJeff Ames2008-02-05 19:44:27 +0000
committerJeff Ames2008-02-05 19:44:27 +0000
commit6ed5283bc06a62f38eb517e67b975832b603bf61 (patch)
treee5f635018789b73a99ddeca0883a68368fa5eece /OpenSim/Region/Environment/Modules/ChatModule.cs
parentCut down on the number of packets sent during terraforming. Terraforming shou... (diff)
downloadopensim-SC_OLD-6ed5283bc06a62f38eb517e67b975832b603bf61.zip
opensim-SC_OLD-6ed5283bc06a62f38eb517e67b975832b603bf61.tar.gz
opensim-SC_OLD-6ed5283bc06a62f38eb517e67b975832b603bf61.tar.bz2
opensim-SC_OLD-6ed5283bc06a62f38eb517e67b975832b603bf61.tar.xz
Converted logging to use log4net.
Changed LogBase to ConsoleBase, which handles console I/O. This is mostly an in-place conversion, so lots of refactoring can still be done.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/ChatModule.cs103
1 files changed, 50 insertions, 53 deletions
diff --git a/OpenSim/Region/Environment/Modules/ChatModule.cs b/OpenSim/Region/Environment/Modules/ChatModule.cs
index 749a923..82bd2ec 100644
--- a/OpenSim/Region/Environment/Modules/ChatModule.cs
+++ b/OpenSim/Region/Environment/Modules/ChatModule.cs
@@ -43,8 +43,9 @@ namespace OpenSim.Region.Environment.Modules
43{ 43{
44 public class ChatModule : IRegionModule, ISimChat 44 public class ChatModule : IRegionModule, ISimChat
45 { 45 {
46 private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
47
46 private List<Scene> m_scenes = new List<Scene>(); 48 private List<Scene> m_scenes = new List<Scene>();
47 private LogBase m_log;
48 49
49 private int m_whisperdistance = 10; 50 private int m_whisperdistance = 10;
50 private int m_saydistance = 30; 51 private int m_saydistance = 30;
@@ -59,11 +60,6 @@ namespace OpenSim.Region.Environment.Modules
59 internal object m_syncLogout = new object(); 60 internal object m_syncLogout = new object();
60 private Thread m_irc_connector=null; 61 private Thread m_irc_connector=null;
61 62
62 public ChatModule()
63 {
64 m_log = MainLog.Instance;
65 }
66
67 public void Initialise(Scene scene, IConfigSource config) 63 public void Initialise(Scene scene, IConfigSource config)
68 { 64 {
69 lock (m_syncInit) 65 lock (m_syncInit)
@@ -159,7 +155,7 @@ namespace OpenSim.Region.Environment.Modules
159 } 155 }
160 catch (Exception ex) 156 catch (Exception ex)
161 { 157 {
162 m_log.Error("IRC", "NewClient exception trap:" + ex.ToString()); 158 m_log.Error("[IRC]: NewClient exception trap:" + ex.ToString());
163 } 159 }
164 } 160 }
165 161
@@ -180,13 +176,13 @@ namespace OpenSim.Region.Environment.Modules
180 { 176 {
181 m_last_leaving_user = clientName; 177 m_last_leaving_user = clientName;
182 m_irc.PrivMsg(m_irc.Nick, "Sim", "notices " + clientName + " left " + clientRegion); 178 m_irc.PrivMsg(m_irc.Nick, "Sim", "notices " + clientName + " left " + clientRegion);
183 m_log.Verbose("IRC", "IRC watcher notices " + clientName + " left " + clientRegion); 179 m_log.Info("[IRC]: IRC watcher notices " + clientName + " left " + clientRegion);
184 } 180 }
185 } 181 }
186 } 182 }
187 catch (Exception ex) 183 catch (Exception ex)
188 { 184 {
189 m_log.Error("IRC", "ClientLoggedOut exception trap:" + ex.ToString()); 185 m_log.Error("[IRC]: ClientLoggedOut exception trap:" + ex.ToString());
190 } 186 }
191 } 187 }
192 188
@@ -319,6 +315,8 @@ namespace OpenSim.Region.Environment.Modules
319 315
320 internal class IRCChatModule 316 internal class IRCChatModule
321 { 317 {
318 private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
319
322 private string m_server = null; 320 private string m_server = null;
323 private uint m_port = 6668; 321 private uint m_port = 6668;
324 private string m_user = "USER OpenSimBot 8 * :I'm a OpenSim to irc bot"; 322 private string m_user = "USER OpenSimBot 8 * :I'm a OpenSim to irc bot";
@@ -341,7 +339,6 @@ namespace OpenSim.Region.Environment.Modules
341 339
342 private List<Scene> m_scenes = null; 340 private List<Scene> m_scenes = null;
343 private List<Scene> m_last_scenes = null; 341 private List<Scene> m_last_scenes = null;
344 private LogBase m_log;
345 342
346 public IRCChatModule(IConfigSource config) 343 public IRCChatModule(IConfigSource config)
347 { 344 {
@@ -388,9 +385,8 @@ namespace OpenSim.Region.Environment.Modules
388 } 385 }
389 catch (Exception) 386 catch (Exception)
390 { 387 {
391 MainLog.Instance.Verbose("CHAT", "No IRC config information, skipping IRC bridge configuration"); 388 m_log.Info("[CHAT]: No IRC config information, skipping IRC bridge configuration");
392 } 389 }
393 m_log = MainLog.Instance;
394 } 390 }
395 391
396 public bool Connect(List<Scene> scenes) 392 public bool Connect(List<Scene> scenes)
@@ -404,9 +400,9 @@ namespace OpenSim.Region.Environment.Modules
404 if (m_last_scenes == null) { m_last_scenes = scenes; } 400 if (m_last_scenes == null) { m_last_scenes = scenes; }
405 401
406 m_tcp = new TcpClient(m_server, (int)m_port); 402 m_tcp = new TcpClient(m_server, (int)m_port);
407 m_log.Verbose("IRC", "Connecting..."); 403 m_log.Info("[IRC]: Connecting...");
408 m_stream = m_tcp.GetStream(); 404 m_stream = m_tcp.GetStream();
409 m_log.Verbose("IRC", "Connected to " + m_server); 405 m_log.Info("[IRC]: Connected to " + m_server);
410 m_reader = new StreamReader(m_stream); 406 m_reader = new StreamReader(m_stream);
411 m_writer = new StreamWriter(m_stream); 407 m_writer = new StreamWriter(m_stream);
412 408
@@ -422,7 +418,7 @@ namespace OpenSim.Region.Environment.Modules
422 m_writer.Flush(); 418 m_writer.Flush();
423 m_writer.WriteLine("JOIN " + m_channel); 419 m_writer.WriteLine("JOIN " + m_channel);
424 m_writer.Flush(); 420 m_writer.Flush();
425 m_log.Verbose("IRC", "Connection fully established"); 421 m_log.Info("[IRC]: Connection fully established");
426 m_connected = true; 422 m_connected = true;
427 } 423 }
428 catch (Exception e) 424 catch (Exception e)
@@ -475,16 +471,16 @@ namespace OpenSim.Region.Environment.Modules
475 m_writer.WriteLine(m_privmsgformat, m_channel, from, region, msg); 471 m_writer.WriteLine(m_privmsgformat, m_channel, from, region, msg);
476 } 472 }
477 m_writer.Flush(); 473 m_writer.Flush();
478 m_log.Verbose("IRC", "PrivMsg " + from + " in " + region + " :" + msg); 474 m_log.Info("[IRC]: PrivMsg " + from + " in " + region + " :" + msg);
479 } 475 }
480 catch (IOException) 476 catch (IOException)
481 { 477 {
482 m_log.Error("IRC", "Disconnected from IRC server.(PrivMsg)"); 478 m_log.Error("[IRC]: Disconnected from IRC server.(PrivMsg)");
483 Reconnect(); 479 Reconnect();
484 } 480 }
485 catch (Exception ex) 481 catch (Exception ex)
486 { 482 {
487 m_log.Error("IRC", "PrivMsg exception trap:" + ex.ToString()); 483 m_log.Error("[IRC]: PrivMsg exception trap:" + ex.ToString());
488 } 484 }
489 } 485 }
490 486
@@ -493,7 +489,7 @@ namespace OpenSim.Region.Environment.Modules
493 //examines IRC commands and extracts any private messages 489 //examines IRC commands and extracts any private messages
494 // which will then be reboadcast in the Sim 490 // which will then be reboadcast in the Sim
495 491
496 m_log.Verbose("IRC", "ExtractMsg: " + input); 492 m_log.Info("[IRC]: ExtractMsg: " + input);
497 Dictionary<string, string> result = null; 493 Dictionary<string, string> result = null;
498 //string regex = @":(?<nick>\w*)!~(?<user>\S*) PRIVMSG (?<channel>\S+) :(?<msg>.*)"; 494 //string regex = @":(?<nick>\w*)!~(?<user>\S*) PRIVMSG (?<channel>\S+) :(?<msg>.*)";
499 string regex = @":(?<nick>\w*)!(?<user>\S*) PRIVMSG (?<channel>\S+) :(?<msg>.*)"; 495 string regex = @":(?<nick>\w*)!(?<user>\S*) PRIVMSG (?<channel>\S+) :(?<msg>.*)";
@@ -510,10 +506,10 @@ namespace OpenSim.Region.Environment.Modules
510 } 506 }
511 else 507 else
512 { 508 {
513 m_log.Verbose("IRC", "Number of matches: " + matches.Count); 509 m_log.Info("[IRC]: Number of matches: " + matches.Count);
514 if (matches.Count > 0) 510 if (matches.Count > 0)
515 { 511 {
516 m_log.Verbose("IRC", "Number of groups: " + matches[0].Groups.Count); 512 m_log.Info("[IRC]: Number of groups: " + matches[0].Groups.Count);
517 } 513 }
518 } 514 }
519 return result; 515 return result;
@@ -536,12 +532,12 @@ namespace OpenSim.Region.Environment.Modules
536 } 532 }
537 catch (IOException) 533 catch (IOException)
538 { 534 {
539 m_log.Error("IRC", "Disconnected from IRC server.(PingRun)"); 535 m_log.Error("[IRC]: Disconnected from IRC server.(PingRun)");
540 Reconnect(); 536 Reconnect();
541 } 537 }
542 catch (Exception ex) 538 catch (Exception ex)
543 { 539 {
544 m_log.Error("IRC", "PingRun exception trap:" + ex.ToString() + "\n" + ex.StackTrace); 540 m_log.Error("[IRC]: PingRun exception trap:" + ex.ToString() + "\n" + ex.StackTrace);
545 } 541 }
546 } 542 }
547 } 543 }
@@ -552,29 +548,29 @@ namespace OpenSim.Region.Environment.Modules
552 LLVector3 pos = new LLVector3(128, 128, 20); 548 LLVector3 pos = new LLVector3(128, 128, 20);
553 while (true) 549 while (true)
554 { 550 {
555 try 551 try
556 {
557 while ((m_connected == true) && ((inputLine = m_reader.ReadLine()) != null))
558 { 552 {
553 while ((m_connected == true) && ((inputLine = m_reader.ReadLine()) != null))
554 {
559 // Console.WriteLine(inputLine); 555 // Console.WriteLine(inputLine);
560 if (inputLine.Contains(m_channel)) 556 if (inputLine.Contains(m_channel))
561 { 557 {
562 Dictionary<string, string> data = ExtractMsg(inputLine); 558 Dictionary<string, string> data = ExtractMsg(inputLine);
563 // Any chat ??? 559 // Any chat ???
564 if (data != null) 560 if (data != null)
565 { 561 {
566 foreach (Scene m_scene in m_scenes) 562 foreach (Scene m_scene in m_scenes)
567 { 563 {
568 m_scene.ForEachScenePresence(delegate(ScenePresence avatar) 564 m_scene.ForEachScenePresence(delegate(ScenePresence avatar)
565 {
566 if (!avatar.IsChildAgent)
569 { 567 {
570 if (!avatar.IsChildAgent) 568 avatar.ControllingClient.SendChatMessage(
571 { 569 Helpers.StringToField(data["msg"]), 255,
572 avatar.ControllingClient.SendChatMessage( 570 pos, data["nick"],
573 Helpers.StringToField(data["msg"]), 255, 571 LLUUID.Zero);
574 pos, data["nick"], 572 }
575 LLUUID.Zero); 573 });
576 }
577 });
578 } 574 }
579 575
580 576
@@ -584,24 +580,24 @@ namespace OpenSim.Region.Environment.Modules
584 // Was an command from the IRC server 580 // Was an command from the IRC server
585 ProcessIRCCommand(inputLine); 581 ProcessIRCCommand(inputLine);
586 } 582 }
587 } 583 }
588 else 584 else
589 { 585 {
590 // Was an command from the IRC server 586 // Was an command from the IRC server
591 ProcessIRCCommand(inputLine); 587 ProcessIRCCommand(inputLine);
592 } 588 }
593 Thread.Sleep(150); 589 Thread.Sleep(150);
594 }
595 }
596 catch (IOException)
597 {
598 m_log.Error("IRC", "ListenerRun IOException. Disconnected from IRC server ??? (ListenerRun)");
599 Reconnect();
600 }
601 catch (Exception ex)
602 {
603 m_log.Error("IRC", "ListenerRun exception trap:" + ex.ToString()+"\n"+ex.StackTrace);
604 } 590 }
591 }
592 catch (IOException)
593 {
594 m_log.Error("[IRC]: ListenerRun IOException. Disconnected from IRC server ??? (ListenerRun)");
595 Reconnect();
596 }
597 catch (Exception ex)
598 {
599 m_log.Error("[IRC]: ListenerRun exception trap:" + ex.ToString() + "\n" + ex.StackTrace);
600 }
605 } 601 }
606 } 602 }
607 603
@@ -626,27 +622,27 @@ namespace OpenSim.Region.Environment.Modules
626 } 622 }
627 catch (Exception ex) // IRC gate should not crash Sim 623 catch (Exception ex) // IRC gate should not crash Sim
628 { 624 {
629 m_log.Error("IRC", "BroadcastSim Exception Trap:" + ex.ToString() + "\n" + ex.StackTrace); 625 m_log.Error("[IRC]: BroadcastSim Exception Trap:" + ex.ToString() + "\n" + ex.StackTrace);
630 626
631 } 627 }
632
633
634 } 628 }
629
635 public enum ErrorReplies 630 public enum ErrorReplies
636 { 631 {
637 NotRegistered = 451, // ":You have not registered" 632 NotRegistered = 451, // ":You have not registered"
638 NicknameInUse = 433 // "<nick> :Nickname is already in use" 633 NicknameInUse = 433 // "<nick> :Nickname is already in use"
639 } 634 }
635
640 public enum Replies 636 public enum Replies
641 { 637 {
642 MotdStart = 375, // ":- <server> Message of the day - " 638 MotdStart = 375, // ":- <server> Message of the day - "
643 Motd = 372, // ":- <text>" 639 Motd = 372, // ":- <text>"
644 EndOfMotd = 376 // ":End of /MOTD command" 640 EndOfMotd = 376 // ":End of /MOTD command"
645
646 } 641 }
642
647 public void ProcessIRCCommand(string command) 643 public void ProcessIRCCommand(string command)
648 { 644 {
649 //m_log.Verbose("IRC", "ProcessIRCCommand:"+command); 645 //m_log.Info("[IRC]: ProcessIRCCommand:" + command);
650 646
651 string[] commArgs = new string[command.Split(' ').Length]; 647 string[] commArgs = new string[command.Split(' ').Length];
652 string c_server = m_server; 648 string c_server = m_server;
@@ -656,6 +652,7 @@ namespace OpenSim.Region.Environment.Modules
656 { 652 {
657 commArgs[0] = commArgs[0].Remove(0, 1); 653 commArgs[0] = commArgs[0].Remove(0, 1);
658 } 654 }
655
659 if (commArgs[1] == "002") 656 if (commArgs[1] == "002")
660 { 657 {
661 // fetch the correct servername 658 // fetch the correct servername
@@ -668,7 +665,7 @@ namespace OpenSim.Region.Environment.Modules
668 665
669 if (commArgs[0] == "ERROR") 666 if (commArgs[0] == "ERROR")
670 { 667 {
671 m_log.Error("IRC", "IRC SERVER ERROR:" + command); 668 m_log.Error("[IRC]: IRC SERVER ERROR:" + command);
672 } 669 }
673 670
674 if (commArgs[0] == "PING") 671 if (commArgs[0] == "PING")
@@ -695,7 +692,7 @@ namespace OpenSim.Region.Environment.Modules
695 case (int)ErrorReplies.NicknameInUse: 692 case (int)ErrorReplies.NicknameInUse:
696 // Gen a new name 693 // Gen a new name
697 m_nick = m_basenick + Util.RandomClass.Next(1, 99); 694 m_nick = m_basenick + Util.RandomClass.Next(1, 99);
698 m_log.Error("IRC", "IRC SERVER reports NicknameInUse, trying " + m_nick); 695 m_log.Error("[IRC]: IRC SERVER reports NicknameInUse, trying " + m_nick);
699 // Retry 696 // Retry
700 m_writer.WriteLine("NICK " + m_nick); 697 m_writer.WriteLine("NICK " + m_nick);
701 m_writer.Flush(); 698 m_writer.Flush();