diff options
author | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
commit | 134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch) | |
tree | 216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs | |
parent | More changing to production grid. Double oops. (diff) | |
download | opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2 opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz |
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs | 303 |
1 files changed, 152 insertions, 151 deletions
diff --git a/OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs b/OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs index a014798..6985371 100644 --- a/OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs +++ b/OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs | |||
@@ -52,17 +52,19 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
52 | 52 | ||
53 | // Local constants | 53 | // Local constants |
54 | 54 | ||
55 | // This computation is not the real region center if the region is larger than 256. | ||
56 | // This computation isn't fixed because there is not a handle back to the region. | ||
55 | private static readonly Vector3 CenterOfRegion = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 20); | 57 | private static readonly Vector3 CenterOfRegion = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 20); |
56 | private static readonly char[] CS_SPACE = { ' ' }; | 58 | private static readonly char[] CS_SPACE = { ' ' }; |
57 | 59 | ||
58 | private const int WD_INTERVAL = 1000; // base watchdog interval | 60 | private const int WD_INTERVAL = 1000; // base watchdog interval |
59 | private static int PING_PERIOD = 15; // WD intervals per PING | 61 | private static int PING_PERIOD = 15; // WD intervals per PING |
60 | private static int ICCD_PERIOD = 10; // WD intervals between Connects | 62 | private static int ICCD_PERIOD = 10; // WD intervals between Connects |
61 | private static int L_TIMEOUT = 25; // Login time out interval | 63 | private static int L_TIMEOUT = 25; // Login time out interval |
62 | 64 | ||
63 | private static int _idk_ = 0; // core connector identifier | 65 | private static int _idk_ = 0; // core connector identifier |
64 | private static int _pdk_ = 0; // ping interval counter | 66 | private static int _pdk_ = 0; // ping interval counter |
65 | private static int _icc_ = ICCD_PERIOD; // IRC connect counter | 67 | private static int _icc_ = ICCD_PERIOD; // IRC connect counter |
66 | 68 | ||
67 | // List of configured connectors | 69 | // List of configured connectors |
68 | 70 | ||
@@ -107,13 +109,9 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
107 | 109 | ||
108 | internal int m_resetk = 0; | 110 | internal int m_resetk = 0; |
109 | 111 | ||
110 | // Working threads | ||
111 | |||
112 | private Thread m_listener = null; | ||
113 | |||
114 | private Object msyncConnect = new Object(); | 112 | private Object msyncConnect = new Object(); |
115 | 113 | ||
116 | internal bool m_randomizeNick = true; // add random suffix | 114 | internal bool m_randomizeNick = true; // add random suffix |
117 | internal string m_baseNick = null; // base name for randomizing | 115 | internal string m_baseNick = null; // base name for randomizing |
118 | internal string m_nick = null; // effective nickname | 116 | internal string m_nick = null; // effective nickname |
119 | 117 | ||
@@ -122,7 +120,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
122 | get { return m_nick; } | 120 | get { return m_nick; } |
123 | set { m_nick = value; } | 121 | set { m_nick = value; } |
124 | } | 122 | } |
125 | 123 | ||
126 | private bool m_enabled = false; // connector enablement | 124 | private bool m_enabled = false; // connector enablement |
127 | public bool Enabled | 125 | public bool Enabled |
128 | { | 126 | { |
@@ -130,8 +128,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
130 | } | 128 | } |
131 | 129 | ||
132 | private bool m_connected = false; // connection status | 130 | private bool m_connected = false; // connection status |
133 | private bool m_pending = false; // login disposition | 131 | private bool m_pending = false; // login disposition |
134 | private int m_timeout = L_TIMEOUT; // login timeout counter | 132 | private int m_timeout = L_TIMEOUT; // login timeout counter |
135 | public bool Connected | 133 | public bool Connected |
136 | { | 134 | { |
137 | get { return m_connected; } | 135 | get { return m_connected; } |
@@ -143,9 +141,9 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
143 | get { return m_ircChannel; } | 141 | get { return m_ircChannel; } |
144 | set { m_ircChannel = value; } | 142 | set { m_ircChannel = value; } |
145 | } | 143 | } |
146 | 144 | ||
147 | private uint m_port = 6667; // session port | 145 | private uint m_port = 6667; // session port |
148 | public uint Port | 146 | public uint Port |
149 | { | 147 | { |
150 | get { return m_port; } | 148 | get { return m_port; } |
151 | set { m_port = value; } | 149 | set { m_port = value; } |
@@ -172,10 +170,10 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
172 | 170 | ||
173 | // Network interface | 171 | // Network interface |
174 | 172 | ||
175 | private TcpClient m_tcp; | 173 | private TcpClient m_tcp; |
176 | private NetworkStream m_stream = null; | 174 | private NetworkStream m_stream = null; |
177 | private StreamReader m_reader; | 175 | private StreamReader m_reader; |
178 | private StreamWriter m_writer; | 176 | private StreamWriter m_writer; |
179 | 177 | ||
180 | // Channel characteristic info (if available) | 178 | // Channel characteristic info (if available) |
181 | 179 | ||
@@ -193,26 +191,26 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
193 | 191 | ||
194 | // Prepare network interface | 192 | // Prepare network interface |
195 | 193 | ||
196 | m_tcp = null; | 194 | m_tcp = null; |
197 | m_writer = null; | 195 | m_writer = null; |
198 | m_reader = null; | 196 | m_reader = null; |
199 | 197 | ||
200 | // Setup IRC session parameters | 198 | // Setup IRC session parameters |
201 | 199 | ||
202 | m_server = cs.Server; | 200 | m_server = cs.Server; |
203 | m_password = cs.Password; | 201 | m_password = cs.Password; |
204 | m_baseNick = cs.BaseNickname; | 202 | m_baseNick = cs.BaseNickname; |
205 | m_randomizeNick = cs.RandomizeNickname; | 203 | m_randomizeNick = cs.RandomizeNickname; |
206 | m_ircChannel = cs.IrcChannel; | 204 | m_ircChannel = cs.IrcChannel; |
207 | m_port = cs.Port; | 205 | m_port = cs.Port; |
208 | m_user = cs.User; | 206 | m_user = cs.User; |
209 | 207 | ||
210 | if (m_watchdog == null) | 208 | if (m_watchdog == null) |
211 | { | 209 | { |
212 | // Non-differentiating | 210 | // Non-differentiating |
213 | 211 | ||
214 | ICCD_PERIOD = cs.ConnectDelay; | 212 | ICCD_PERIOD = cs.ConnectDelay; |
215 | PING_PERIOD = cs.PingDelay; | 213 | PING_PERIOD = cs.PingDelay; |
216 | 214 | ||
217 | // Smaller values are not reasonable | 215 | // Smaller values are not reasonable |
218 | 216 | ||
@@ -235,7 +233,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
235 | 233 | ||
236 | if (m_randomizeNick) | 234 | if (m_randomizeNick) |
237 | m_nick = m_baseNick + Util.RandomClass.Next(1, 99); | 235 | m_nick = m_baseNick + Util.RandomClass.Next(1, 99); |
238 | else | 236 | else |
239 | m_nick = m_baseNick; | 237 | m_nick = m_baseNick; |
240 | 238 | ||
241 | m_log.InfoFormat("[IRC-Connector-{0}]: Initialization complete", idn); | 239 | m_log.InfoFormat("[IRC-Connector-{0}]: Initialization complete", idn); |
@@ -295,18 +293,22 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
295 | m_nick, m_ircChannel, m_server)); | 293 | m_nick, m_ircChannel, m_server)); |
296 | m_writer.Flush(); | 294 | m_writer.Flush(); |
297 | } | 295 | } |
298 | catch (Exception) {} | 296 | catch (Exception) { } |
299 | 297 | ||
300 | 298 | ||
301 | m_connected = false; | 299 | m_connected = false; |
302 | 300 | ||
303 | try { m_writer.Close(); } catch (Exception) {} | 301 | try { m_writer.Close(); } |
304 | try { m_reader.Close(); } catch (Exception) {} | 302 | catch (Exception) { } |
305 | try { m_stream.Close(); } catch (Exception) {} | 303 | try { m_reader.Close(); } |
306 | try { m_tcp.Close(); } catch (Exception) {} | 304 | catch (Exception) { } |
305 | try { m_stream.Close(); } | ||
306 | catch (Exception) { } | ||
307 | try { m_tcp.Close(); } | ||
308 | catch (Exception) { } | ||
307 | 309 | ||
308 | } | 310 | } |
309 | 311 | ||
310 | lock (m_connectors) | 312 | lock (m_connectors) |
311 | m_connectors.Remove(this); | 313 | m_connectors.Remove(this); |
312 | 314 | ||
@@ -347,20 +349,17 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
347 | if (m_connected) return; | 349 | if (m_connected) return; |
348 | 350 | ||
349 | m_connected = true; | 351 | m_connected = true; |
350 | m_pending = true; | 352 | m_pending = true; |
351 | m_timeout = L_TIMEOUT; | 353 | m_timeout = L_TIMEOUT; |
352 | 354 | ||
353 | m_tcp = new TcpClient(m_server, (int)m_port); | 355 | m_tcp = new TcpClient(m_server, (int)m_port); |
354 | m_stream = m_tcp.GetStream(); | 356 | m_stream = m_tcp.GetStream(); |
355 | m_reader = new StreamReader(m_stream); | 357 | m_reader = new StreamReader(m_stream); |
356 | m_writer = new StreamWriter(m_stream); | 358 | m_writer = new StreamWriter(m_stream); |
357 | 359 | ||
358 | m_log.InfoFormat("[IRC-Connector-{0}]: Connected to {1}:{2}", idn, m_server, m_port); | 360 | m_log.InfoFormat("[IRC-Connector-{0}]: Connected to {1}:{2}", idn, m_server, m_port); |
359 | 361 | ||
360 | m_listener = new Thread(new ThreadStart(ListenerRun)); | 362 | WorkManager.StartThread(ListenerRun, "IRCConnectionListenerThread", ThreadPriority.Normal, true, false); |
361 | m_listener.Name = "IRCConnectorListenerThread"; | ||
362 | m_listener.IsBackground = true; | ||
363 | m_listener.Start(); | ||
364 | 363 | ||
365 | // This is the message order recommended by RFC 2812 | 364 | // This is the message order recommended by RFC 2812 |
366 | if (m_password != null) | 365 | if (m_password != null) |
@@ -418,12 +417,15 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
418 | // the socket and it will disappear of its own accord, once this | 417 | // the socket and it will disappear of its own accord, once this |
419 | // processing is completed. | 418 | // processing is completed. |
420 | 419 | ||
421 | try { m_writer.Close(); } catch (Exception) {} | 420 | try { m_writer.Close(); } |
422 | try { m_reader.Close(); } catch (Exception) {} | 421 | catch (Exception) { } |
423 | try { m_tcp.Close(); } catch (Exception) {} | 422 | try { m_reader.Close(); } |
423 | catch (Exception) { } | ||
424 | try { m_tcp.Close(); } | ||
425 | catch (Exception) { } | ||
424 | 426 | ||
425 | m_connected = false; | 427 | m_connected = false; |
426 | m_pending = false; | 428 | m_pending = false; |
427 | m_resetk++; | 429 | m_resetk++; |
428 | 430 | ||
429 | } | 431 | } |
@@ -495,27 +497,26 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
495 | { | 497 | { |
496 | 498 | ||
497 | string inputLine; | 499 | string inputLine; |
498 | int resetk = m_resetk; | 500 | int resetk = m_resetk; |
499 | 501 | ||
500 | try | 502 | try |
501 | { | 503 | { |
502 | while (m_enabled && m_connected) | 504 | while (m_enabled && m_connected) |
503 | { | 505 | { |
504 | |||
505 | if ((inputLine = m_reader.ReadLine()) == null) | 506 | if ((inputLine = m_reader.ReadLine()) == null) |
506 | throw new Exception("Listener input socket closed"); | 507 | throw new Exception("Listener input socket closed"); |
507 | 508 | ||
509 | Watchdog.UpdateThread(); | ||
510 | |||
508 | // m_log.Info("[IRCConnector]: " + inputLine); | 511 | // m_log.Info("[IRCConnector]: " + inputLine); |
509 | 512 | ||
510 | if (inputLine.Contains("PRIVMSG")) | 513 | if (inputLine.Contains("PRIVMSG")) |
511 | { | 514 | { |
512 | |||
513 | Dictionary<string, string> data = ExtractMsg(inputLine); | 515 | Dictionary<string, string> data = ExtractMsg(inputLine); |
514 | 516 | ||
515 | // Any chat ??? | 517 | // Any chat ??? |
516 | if (data != null) | 518 | if (data != null) |
517 | { | 519 | { |
518 | |||
519 | OSChatMessage c = new OSChatMessage(); | 520 | OSChatMessage c = new OSChatMessage(); |
520 | c.Message = data["msg"]; | 521 | c.Message = data["msg"]; |
521 | c.Type = ChatTypeEnum.Region; | 522 | c.Type = ChatTypeEnum.Region; |
@@ -531,9 +532,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
531 | c.Message = String.Format("/me {0}", c.Message.Substring(8, c.Message.Length - 9)); | 532 | c.Message = String.Format("/me {0}", c.Message.Substring(8, c.Message.Length - 9)); |
532 | 533 | ||
533 | ChannelState.OSChat(this, c, false); | 534 | ChannelState.OSChat(this, c, false); |
534 | |||
535 | } | 535 | } |
536 | |||
537 | } | 536 | } |
538 | else | 537 | else |
539 | { | 538 | { |
@@ -553,9 +552,11 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
553 | 552 | ||
554 | if (m_enabled && (m_resetk == resetk)) | 553 | if (m_enabled && (m_resetk == resetk)) |
555 | Reconnect(); | 554 | Reconnect(); |
555 | |||
556 | Watchdog.RemoveThread(); | ||
556 | } | 557 | } |
557 | 558 | ||
558 | private Regex RE = new Regex(@":(?<nick>[\w-]*)!(?<user>\S*) PRIVMSG (?<channel>\S+) :(?<msg>.*)", | 559 | private Regex RE = new Regex(@":(?<nick>[\w-]*)!(?<user>\S*) PRIVMSG (?<channel>\S+) :(?<msg>.*)", |
559 | RegexOptions.Multiline); | 560 | RegexOptions.Multiline); |
560 | 561 | ||
561 | private Dictionary<string, string> ExtractMsg(string input) | 562 | private Dictionary<string, string> ExtractMsg(string input) |
@@ -617,8 +618,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
617 | string[] commArgs; | 618 | string[] commArgs; |
618 | string c_server = m_server; | 619 | string c_server = m_server; |
619 | 620 | ||
620 | string pfx = String.Empty; | 621 | string pfx = String.Empty; |
621 | string cmd = String.Empty; | 622 | string cmd = String.Empty; |
622 | string parms = String.Empty; | 623 | string parms = String.Empty; |
623 | 624 | ||
624 | // ":" indicates that a prefix is present | 625 | // ":" indicates that a prefix is present |
@@ -627,15 +628,15 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
627 | // ":" indicates that the remainder of the | 628 | // ":" indicates that the remainder of the |
628 | // line is a single parameter value. | 629 | // line is a single parameter value. |
629 | 630 | ||
630 | commArgs = command.Split(CS_SPACE,2); | 631 | commArgs = command.Split(CS_SPACE, 2); |
631 | 632 | ||
632 | if (commArgs[0].StartsWith(":")) | 633 | if (commArgs[0].StartsWith(":")) |
633 | { | 634 | { |
634 | pfx = commArgs[0].Substring(1); | 635 | pfx = commArgs[0].Substring(1); |
635 | commArgs = commArgs[1].Split(CS_SPACE,2); | 636 | commArgs = commArgs[1].Split(CS_SPACE, 2); |
636 | } | 637 | } |
637 | 638 | ||
638 | cmd = commArgs[0]; | 639 | cmd = commArgs[0]; |
639 | parms = commArgs[1]; | 640 | parms = commArgs[1]; |
640 | 641 | ||
641 | // m_log.DebugFormat("[IRC-Connector-{0}] prefix = <{1}> cmd = <{2}>", idn, pfx, cmd); | 642 | // m_log.DebugFormat("[IRC-Connector-{0}] prefix = <{1}> cmd = <{2}>", idn, pfx, cmd); |
@@ -646,44 +647,44 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
646 | // Messages 001-004 are always sent | 647 | // Messages 001-004 are always sent |
647 | // following signon. | 648 | // following signon. |
648 | 649 | ||
649 | case "001" : // Welcome ... | 650 | case "001": // Welcome ... |
650 | case "002" : // Server information | 651 | case "002": // Server information |
651 | case "003" : // Welcome ... | 652 | case "003": // Welcome ... |
652 | break; | 653 | break; |
653 | case "004" : // Server information | 654 | case "004": // Server information |
654 | m_log.DebugFormat("[IRC-Connector-{0}] [{1}] parms = <{2}>", idn, cmd, parms); | 655 | m_log.DebugFormat("[IRC-Connector-{0}] [{1}] parms = <{2}>", idn, cmd, parms); |
655 | commArgs = parms.Split(CS_SPACE); | 656 | commArgs = parms.Split(CS_SPACE); |
656 | c_server = commArgs[1]; | 657 | c_server = commArgs[1]; |
657 | m_server = c_server; | 658 | m_server = c_server; |
658 | version = commArgs[2]; | 659 | version = commArgs[2]; |
659 | usermod = commArgs[3]; | 660 | usermod = commArgs[3]; |
660 | chanmod = commArgs[4]; | 661 | chanmod = commArgs[4]; |
661 | break; | 662 | break; |
662 | case "005" : // Server information | 663 | case "005": // Server information |
663 | break; | 664 | break; |
664 | case "042" : | 665 | case "042": |
665 | case "250" : | 666 | case "250": |
666 | case "251" : | 667 | case "251": |
667 | case "252" : | 668 | case "252": |
668 | case "254" : | 669 | case "254": |
669 | case "255" : | 670 | case "255": |
670 | case "265" : | 671 | case "265": |
671 | case "266" : | 672 | case "266": |
672 | case "332" : // Subject | 673 | case "332": // Subject |
673 | case "333" : // Subject owner (?) | 674 | case "333": // Subject owner (?) |
674 | case "353" : // Name list | 675 | case "353": // Name list |
675 | case "366" : // End-of-Name list marker | 676 | case "366": // End-of-Name list marker |
676 | case "372" : // MOTD body | 677 | case "372": // MOTD body |
677 | case "375" : // MOTD start | 678 | case "375": // MOTD start |
678 | // m_log.InfoFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); | 679 | // m_log.InfoFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); |
679 | break; | 680 | break; |
680 | case "376" : // MOTD end | 681 | case "376": // MOTD end |
681 | // m_log.InfoFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); | 682 | // m_log.InfoFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); |
682 | motd = true; | 683 | motd = true; |
683 | break; | 684 | break; |
684 | case "451" : // Not registered | 685 | case "451": // Not registered |
685 | break; | 686 | break; |
686 | case "433" : // Nickname in use | 687 | case "433": // Nickname in use |
687 | // Gen a new name | 688 | // Gen a new name |
688 | m_nick = m_baseNick + Util.RandomClass.Next(1, 99); | 689 | m_nick = m_baseNick + Util.RandomClass.Next(1, 99); |
689 | m_log.ErrorFormat("[IRC-Connector-{0}]: [{1}] IRC SERVER reports NicknameInUse, trying {2}", idn, cmd, m_nick); | 690 | m_log.ErrorFormat("[IRC-Connector-{0}]: [{1}] IRC SERVER reports NicknameInUse, trying {2}", idn, cmd, m_nick); |
@@ -695,29 +696,29 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
695 | m_writer.WriteLine(String.Format("JOIN {0}", m_ircChannel)); | 696 | m_writer.WriteLine(String.Format("JOIN {0}", m_ircChannel)); |
696 | m_writer.Flush(); | 697 | m_writer.Flush(); |
697 | break; | 698 | break; |
698 | case "479" : // Bad channel name, etc. This will never work, so disable the connection | 699 | case "479": // Bad channel name, etc. This will never work, so disable the connection |
699 | m_log.ErrorFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); | 700 | m_log.ErrorFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE, 2)[1]); |
700 | m_log.ErrorFormat("[IRC-Connector-{0}] [{1}] Connector disabled", idn, cmd); | 701 | m_log.ErrorFormat("[IRC-Connector-{0}] [{1}] Connector disabled", idn, cmd); |
701 | m_enabled = false; | 702 | m_enabled = false; |
702 | m_connected = false; | 703 | m_connected = false; |
703 | m_pending = false; | 704 | m_pending = false; |
704 | break; | 705 | break; |
705 | case "NOTICE" : | 706 | case "NOTICE": |
706 | // m_log.WarnFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); | 707 | // m_log.WarnFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); |
707 | break; | 708 | break; |
708 | case "ERROR" : | 709 | case "ERROR": |
709 | m_log.ErrorFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); | 710 | m_log.ErrorFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE, 2)[1]); |
710 | if (parms.Contains("reconnect too fast")) | 711 | if (parms.Contains("reconnect too fast")) |
711 | ICCD_PERIOD++; | 712 | ICCD_PERIOD++; |
712 | m_pending = false; | 713 | m_pending = false; |
713 | Reconnect(); | 714 | Reconnect(); |
714 | break; | 715 | break; |
715 | case "PING" : | 716 | case "PING": |
716 | m_log.DebugFormat("[IRC-Connector-{0}] [{1}] parms = <{2}>", idn, cmd, parms); | 717 | m_log.DebugFormat("[IRC-Connector-{0}] [{1}] parms = <{2}>", idn, cmd, parms); |
717 | m_writer.WriteLine(String.Format("PONG {0}", parms)); | 718 | m_writer.WriteLine(String.Format("PONG {0}", parms)); |
718 | m_writer.Flush(); | 719 | m_writer.Flush(); |
719 | break; | 720 | break; |
720 | case "PONG" : | 721 | case "PONG": |
721 | break; | 722 | break; |
722 | case "JOIN": | 723 | case "JOIN": |
723 | if (m_pending) | 724 | if (m_pending) |
@@ -748,19 +749,19 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
748 | m_log.DebugFormat("[IRC-Connector-{0}] [{1}] parms = <{2}>", idn, cmd, parms); | 749 | m_log.DebugFormat("[IRC-Connector-{0}] [{1}] parms = <{2}>", idn, cmd, parms); |
749 | eventIrcQuit(pfx, cmd, parms); | 750 | eventIrcQuit(pfx, cmd, parms); |
750 | break; | 751 | break; |
751 | default : | 752 | default: |
752 | m_log.DebugFormat("[IRC-Connector-{0}] Command '{1}' ignored, parms = {2}", idn, cmd, parms); | 753 | m_log.DebugFormat("[IRC-Connector-{0}] Command '{1}' ignored, parms = {2}", idn, cmd, parms); |
753 | break; | 754 | break; |
754 | } | 755 | } |
755 | 756 | ||
756 | // m_log.DebugFormat("[IRC-Connector-{0}] prefix = <{1}> cmd = <{2}> complete", idn, pfx, cmd); | 757 | // m_log.DebugFormat("[IRC-Connector-{0}] prefix = <{1}> cmd = <{2}> complete", idn, pfx, cmd); |
757 | 758 | ||
758 | } | 759 | } |
759 | 760 | ||
760 | public void eventIrcJoin(string prefix, string command, string parms) | 761 | public void eventIrcJoin(string prefix, string command, string parms) |
761 | { | 762 | { |
762 | string[] args = parms.Split(CS_SPACE,2); | 763 | string[] args = parms.Split(CS_SPACE, 2); |
763 | string IrcUser = prefix.Split('!')[0]; | 764 | string IrcUser = prefix.Split('!')[0]; |
764 | string IrcChannel = args[0]; | 765 | string IrcChannel = args[0]; |
765 | 766 | ||
766 | if (IrcChannel.StartsWith(":")) | 767 | if (IrcChannel.StartsWith(":")) |
@@ -772,8 +773,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
772 | 773 | ||
773 | public void eventIrcPart(string prefix, string command, string parms) | 774 | public void eventIrcPart(string prefix, string command, string parms) |
774 | { | 775 | { |
775 | string[] args = parms.Split(CS_SPACE,2); | 776 | string[] args = parms.Split(CS_SPACE, 2); |
776 | string IrcUser = prefix.Split('!')[0]; | 777 | string IrcUser = prefix.Split('!')[0]; |
777 | string IrcChannel = args[0]; | 778 | string IrcChannel = args[0]; |
778 | 779 | ||
779 | m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCPart {1}:{2}", idn, m_server, m_ircChannel); | 780 | m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCPart {1}:{2}", idn, m_server, m_ircChannel); |
@@ -782,7 +783,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
782 | 783 | ||
783 | public void eventIrcMode(string prefix, string command, string parms) | 784 | public void eventIrcMode(string prefix, string command, string parms) |
784 | { | 785 | { |
785 | string[] args = parms.Split(CS_SPACE,2); | 786 | string[] args = parms.Split(CS_SPACE, 2); |
786 | string UserMode = args[1]; | 787 | string UserMode = args[1]; |
787 | 788 | ||
788 | m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCMode {1}:{2}", idn, m_server, m_ircChannel); | 789 | m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCMode {1}:{2}", idn, m_server, m_ircChannel); |
@@ -794,7 +795,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
794 | 795 | ||
795 | public void eventIrcNickChange(string prefix, string command, string parms) | 796 | public void eventIrcNickChange(string prefix, string command, string parms) |
796 | { | 797 | { |
797 | string[] args = parms.Split(CS_SPACE,2); | 798 | string[] args = parms.Split(CS_SPACE, 2); |
798 | string UserOldNick = prefix.Split('!')[0]; | 799 | string UserOldNick = prefix.Split('!')[0]; |
799 | string UserNewNick = args[0].Remove(0, 1); | 800 | string UserNewNick = args[0].Remove(0, 1); |
800 | 801 | ||
@@ -804,11 +805,11 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
804 | 805 | ||
805 | public void eventIrcKick(string prefix, string command, string parms) | 806 | public void eventIrcKick(string prefix, string command, string parms) |
806 | { | 807 | { |
807 | string[] args = parms.Split(CS_SPACE,3); | 808 | string[] args = parms.Split(CS_SPACE, 3); |
808 | string UserKicker = prefix.Split('!')[0]; | 809 | string UserKicker = prefix.Split('!')[0]; |
809 | string IrcChannel = args[0]; | 810 | string IrcChannel = args[0]; |
810 | string UserKicked = args[1]; | 811 | string UserKicked = args[1]; |
811 | string KickMessage = args[2]; | 812 | string KickMessage = args[2]; |
812 | 813 | ||
813 | m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCKick {1}:{2}", idn, m_server, m_ircChannel); | 814 | m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCKick {1}:{2}", idn, m_server, m_ircChannel); |
814 | BroadcastSim(UserKicker, "/me kicks kicks {0} off {1} saying \"{2}\"", UserKicked, IrcChannel, KickMessage); | 815 | BroadcastSim(UserKicker, "/me kicks kicks {0} off {1} saying \"{2}\"", UserKicked, IrcChannel, KickMessage); |
@@ -822,7 +823,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
822 | 823 | ||
823 | public void eventIrcQuit(string prefix, string command, string parms) | 824 | public void eventIrcQuit(string prefix, string command, string parms) |
824 | { | 825 | { |
825 | string IrcUser = prefix.Split('!')[0]; | 826 | string IrcUser = prefix.Split('!')[0]; |
826 | string QuitMessage = parms; | 827 | string QuitMessage = parms; |
827 | 828 | ||
828 | m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCQuit {1}:{2}", idn, m_server, m_ircChannel); | 829 | m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCQuit {1}:{2}", idn, m_server, m_ircChannel); |
@@ -842,65 +843,65 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat | |||
842 | 843 | ||
843 | // m_log.InfoFormat("[IRC-Watchdog] Status scan, pdk = {0}, icc = {1}", _pdk_, _icc_); | 844 | // m_log.InfoFormat("[IRC-Watchdog] Status scan, pdk = {0}, icc = {1}", _pdk_, _icc_); |
844 | 845 | ||
845 | _pdk_ = (_pdk_+1)%PING_PERIOD; // cycle the ping trigger | 846 | _pdk_ = (_pdk_ + 1) % PING_PERIOD; // cycle the ping trigger |
846 | _icc_++; // increment the inter-consecutive-connect-delay counter | 847 | _icc_++; // increment the inter-consecutive-connect-delay counter |
847 | 848 | ||
848 | lock (m_connectors) | 849 | lock (m_connectors) |
849 | foreach (IRCConnector connector in m_connectors) | 850 | foreach (IRCConnector connector in m_connectors) |
850 | { | 851 | { |
851 | 852 | ||
852 | // m_log.InfoFormat("[IRC-Watchdog] Scanning {0}", connector); | 853 | // m_log.InfoFormat("[IRC-Watchdog] Scanning {0}", connector); |
853 | 854 | ||
854 | if (connector.Enabled) | 855 | if (connector.Enabled) |
855 | { | ||
856 | if (!connector.Connected) | ||
857 | { | 856 | { |
858 | try | 857 | if (!connector.Connected) |
859 | { | 858 | { |
860 | // m_log.DebugFormat("[IRC-Watchdog] Connecting {1}:{2}", connector.idn, connector.m_server, connector.m_ircChannel); | 859 | try |
861 | connector.Connect(); | 860 | { |
861 | // m_log.DebugFormat("[IRC-Watchdog] Connecting {1}:{2}", connector.idn, connector.m_server, connector.m_ircChannel); | ||
862 | connector.Connect(); | ||
863 | } | ||
864 | catch (Exception e) | ||
865 | { | ||
866 | m_log.ErrorFormat("[IRC-Watchdog] Exception on connector {0}: {1} ", connector.idn, e.Message); | ||
867 | } | ||
862 | } | 868 | } |
863 | catch (Exception e) | 869 | else |
864 | { | 870 | { |
865 | m_log.ErrorFormat("[IRC-Watchdog] Exception on connector {0}: {1} ", connector.idn, e.Message); | ||
866 | } | ||
867 | } | ||
868 | else | ||
869 | { | ||
870 | 871 | ||
871 | if (connector.m_pending) | 872 | if (connector.m_pending) |
872 | { | ||
873 | if (connector.m_timeout == 0) | ||
874 | { | 873 | { |
875 | m_log.ErrorFormat("[IRC-Watchdog] Login timed-out for connector {0}, reconnecting", connector.idn); | 874 | if (connector.m_timeout == 0) |
876 | connector.Reconnect(); | 875 | { |
876 | m_log.ErrorFormat("[IRC-Watchdog] Login timed-out for connector {0}, reconnecting", connector.idn); | ||
877 | connector.Reconnect(); | ||
878 | } | ||
879 | else | ||
880 | connector.m_timeout--; | ||
877 | } | 881 | } |
878 | else | ||
879 | connector.m_timeout--; | ||
880 | } | ||
881 | 882 | ||
882 | // Being marked connected is not enough to ping. Socket establishment can sometimes take a long | 883 | // Being marked connected is not enough to ping. Socket establishment can sometimes take a long |
883 | // time, in which case the watch dog might try to ping the server before the socket has been | 884 | // time, in which case the watch dog might try to ping the server before the socket has been |
884 | // set up, with nasty side-effects. | 885 | // set up, with nasty side-effects. |
885 | 886 | ||
886 | else if (_pdk_ == 0) | 887 | else if (_pdk_ == 0) |
887 | { | ||
888 | try | ||
889 | { | ||
890 | connector.m_writer.WriteLine(String.Format("PING :{0}", connector.m_server)); | ||
891 | connector.m_writer.Flush(); | ||
892 | } | ||
893 | catch (Exception e) | ||
894 | { | 888 | { |
895 | m_log.ErrorFormat("[IRC-PingRun] Exception on connector {0}: {1} ", connector.idn, e.Message); | 889 | try |
896 | m_log.Debug(e); | 890 | { |
897 | connector.Reconnect(); | 891 | connector.m_writer.WriteLine(String.Format("PING :{0}", connector.m_server)); |
892 | connector.m_writer.Flush(); | ||
893 | } | ||
894 | catch (Exception e) | ||
895 | { | ||
896 | m_log.ErrorFormat("[IRC-PingRun] Exception on connector {0}: {1} ", connector.idn, e.Message); | ||
897 | m_log.Debug(e); | ||
898 | connector.Reconnect(); | ||
899 | } | ||
898 | } | 900 | } |
899 | } | ||
900 | 901 | ||
902 | } | ||
901 | } | 903 | } |
902 | } | 904 | } |
903 | } | ||
904 | 905 | ||
905 | // m_log.InfoFormat("[IRC-Watchdog] Status scan completed"); | 906 | // m_log.InfoFormat("[IRC-Watchdog] Status scan completed"); |
906 | 907 | ||