diff options
author | Dahlia Trimble | 2008-10-01 08:24:44 +0000 |
---|---|---|
committer | Dahlia Trimble | 2008-10-01 08:24:44 +0000 |
commit | dabe61f283c15b0aee3dd5f0a8bfa60197bd68e5 (patch) | |
tree | 4d78fd523bcd30632109f1abf3e03d5e828bb1e3 /OpenSim/Region | |
parent | Added functions to find prims by name (diff) | |
download | opensim-SC_OLD-dabe61f283c15b0aee3dd5f0a8bfa60197bd68e5.zip opensim-SC_OLD-dabe61f283c15b0aee3dd5f0a8bfa60197bd68e5.tar.gz opensim-SC_OLD-dabe61f283c15b0aee3dd5f0a8bfa60197bd68e5.tar.bz2 opensim-SC_OLD-dabe61f283c15b0aee3dd5f0a8bfa60197bd68e5.tar.xz |
a little (incomplete) hackery in the IRC module to allow run-time connection changes
Diffstat (limited to 'OpenSim/Region')
-rw-r--r-- | OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs | 85 |
1 files changed, 74 insertions, 11 deletions
diff --git a/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs index 215c8d9..eba65a9 100644 --- a/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs +++ b/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs | |||
@@ -61,7 +61,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat | |||
61 | internal object m_syncLogout = new object(); | 61 | internal object m_syncLogout = new object(); |
62 | 62 | ||
63 | private IConfig m_config; | 63 | private IConfig m_config; |
64 | |||
65 | #region IRegionModule Members | 64 | #region IRegionModule Members |
66 | 65 | ||
67 | public void Initialise(Scene scene, IConfigSource config) | 66 | public void Initialise(Scene scene, IConfigSource config) |
@@ -174,6 +173,47 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat | |||
174 | public void OnSimChat(Object sender, OSChatMessage e) | 173 | public void OnSimChat(Object sender, OSChatMessage e) |
175 | { | 174 | { |
176 | // We only want to relay stuff on channel 0 | 175 | // We only want to relay stuff on channel 0 |
176 | if (e.Channel == m_irc.m_commandChannel) | ||
177 | { | ||
178 | string[] messages = e.Message.Split(' '); | ||
179 | string command = messages[0].ToLower(); | ||
180 | |||
181 | m_log.Debug("IRC: Got command on channel: " + e.Channel.ToString() + " message: " + e.Message); | ||
182 | |||
183 | try | ||
184 | { | ||
185 | switch (command) | ||
186 | { | ||
187 | case "channel": | ||
188 | m_irc.m_channel = messages[1]; | ||
189 | break; | ||
190 | case "close": | ||
191 | m_irc.Close(); | ||
192 | break; | ||
193 | case "connect": | ||
194 | m_irc.Connect(m_scenes); | ||
195 | break; | ||
196 | case "nick": | ||
197 | m_irc.m_nick = messages[1]; | ||
198 | break; | ||
199 | case "port": | ||
200 | m_irc.m_port = Convert.ToUInt32(messages[1]); | ||
201 | break; | ||
202 | case "reconnect": | ||
203 | m_irc.Reconnect(); | ||
204 | break; | ||
205 | case "server": | ||
206 | m_irc.m_server = messages[1]; | ||
207 | break; | ||
208 | |||
209 | default: | ||
210 | m_irc.Send(e.Message); | ||
211 | break; | ||
212 | } | ||
213 | } | ||
214 | catch | ||
215 | { } | ||
216 | } | ||
177 | if (e.Channel != 0) return; | 217 | if (e.Channel != 0) return; |
178 | if (e.Message.Length == 0) return; | 218 | if (e.Message.Length == 0) return; |
179 | 219 | ||
@@ -369,19 +409,20 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat | |||
369 | private Thread listener; | 409 | private Thread listener; |
370 | 410 | ||
371 | private string m_basenick = null; | 411 | private string m_basenick = null; |
372 | private string m_channel = null; | 412 | public string m_channel = null; |
373 | private bool m_nrnick = false; | 413 | private bool m_nrnick = false; |
374 | private bool m_connected = false; | 414 | private bool m_connected = false; |
375 | private bool m_enabled = false; | 415 | private bool m_enabled = false; |
376 | private List<Scene> m_last_scenes = null; | 416 | public int m_commandChannel = -1; |
377 | private string m_nick = null; | 417 | public List<Scene> m_last_scenes = null; |
378 | private uint m_port = 6668; | 418 | public string m_nick = null; |
419 | public uint m_port = 6668; | ||
379 | private string m_privmsgformat = "PRIVMSG {0} :<{1} in {2}>: {3}"; | 420 | private string m_privmsgformat = "PRIVMSG {0} :<{1} in {2}>: {3}"; |
380 | private StreamReader m_reader; | 421 | private StreamReader m_reader; |
381 | private List<Scene> m_scenes = null; | 422 | private List<Scene> m_scenes = null; |
382 | private string m_server = null; | 423 | public string m_server = null; |
383 | 424 | ||
384 | private NetworkStream m_stream; | 425 | private NetworkStream m_stream = null; |
385 | internal object m_syncConnect = new object(); | 426 | internal object m_syncConnect = new object(); |
386 | private TcpClient m_tcp; | 427 | private TcpClient m_tcp; |
387 | private string m_user = "USER OpenSimBot 8 * :I'm an OpenSim to IRC bot"; | 428 | private string m_user = "USER OpenSimBot 8 * :I'm an OpenSim to IRC bot"; |
@@ -429,6 +470,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat | |||
429 | m_port = (uint)config.Configs["IRC"].GetInt("port", (int)m_port); | 470 | m_port = (uint)config.Configs["IRC"].GetInt("port", (int)m_port); |
430 | m_user = config.Configs["IRC"].GetString("username", m_user); | 471 | m_user = config.Configs["IRC"].GetString("username", m_user); |
431 | m_privmsgformat = config.Configs["IRC"].GetString("msgformat", m_privmsgformat); | 472 | m_privmsgformat = config.Configs["IRC"].GetString("msgformat", m_privmsgformat); |
473 | m_commandChannel = config.Configs["IRC"].GetInt("commandchannel", m_commandChannel); | ||
432 | if (m_server != null && m_nick != null && m_channel != null) | 474 | if (m_server != null && m_nick != null && m_channel != null) |
433 | { | 475 | { |
434 | if (m_nrnick == true) | 476 | if (m_nrnick == true) |
@@ -552,6 +594,27 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat | |||
552 | } | 594 | } |
553 | } | 595 | } |
554 | 596 | ||
597 | public void Send(string msg) | ||
598 | { | ||
599 | try | ||
600 | { | ||
601 | m_writer.WriteLine(msg); | ||
602 | m_writer.Flush(); | ||
603 | m_log.Info("IRC: Sent command string: " + msg); | ||
604 | } | ||
605 | catch (IOException) | ||
606 | { | ||
607 | m_log.Error("[IRC]: Disconnected from IRC server.(PrivMsg)"); | ||
608 | Reconnect(); | ||
609 | } | ||
610 | catch (Exception ex) | ||
611 | { | ||
612 | m_log.ErrorFormat("[IRC]: PrivMsg exception trap: {0}", ex.ToString()); | ||
613 | } | ||
614 | |||
615 | } | ||
616 | |||
617 | |||
555 | private Dictionary<string, string> ExtractMsg(string input) | 618 | private Dictionary<string, string> ExtractMsg(string input) |
556 | { | 619 | { |
557 | //examines IRC commands and extracts any private messages | 620 | //examines IRC commands and extracts any private messages |
@@ -625,7 +688,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat | |||
625 | { | 688 | { |
626 | while ((m_connected == true) && ((inputLine = m_reader.ReadLine()) != null)) | 689 | while ((m_connected == true) && ((inputLine = m_reader.ReadLine()) != null)) |
627 | { | 690 | { |
628 | // Console.WriteLine(inputLine); | 691 | //Console.WriteLine("IRC: " + inputLine); |
629 | if (inputLine.Contains(m_channel)) | 692 | if (inputLine.Contains(m_channel)) |
630 | { | 693 | { |
631 | Dictionary<string, string> data = ExtractMsg(inputLine); | 694 | Dictionary<string, string> data = ExtractMsg(inputLine); |
@@ -874,12 +937,12 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat | |||
874 | m_connected = false; | 937 | m_connected = false; |
875 | m_enabled = false; | 938 | m_enabled = false; |
876 | 939 | ||
877 | // listener.Abort(); | 940 | listener.Abort(); |
878 | // pingSender.Abort(); | 941 | pingSender.Abort(); |
879 | 942 | ||
880 | m_writer.Close(); | 943 | m_writer.Close(); |
881 | m_reader.Close(); | 944 | m_reader.Close(); |
882 | 945 | m_stream.Close(); | |
883 | m_tcp.Close(); | 946 | m_tcp.Close(); |
884 | } | 947 | } |
885 | } | 948 | } |