From dbd8e1edb5b2ce0e686b23200ff297fc3d004b5b Mon Sep 17 00:00:00 2001 From: Dr Scofield Date: Thu, 23 Oct 2008 09:58:12 +0000 Subject: [PATCH] cleaning up commented lines in IRCConnector; changing access_password logic to use a regexp. --- .../Modules/Avatar/Chat/IRCBridgeModule.cs | 64 +++++++++++-------- .../Modules/Avatar/Chat/IRCConnector.cs | 8 --- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs index 05718d87e6..ba993a06b9 100644 --- a/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs +++ b/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs @@ -54,6 +54,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat private string m_last_leaving_user = null; private string m_last_new_user = null; private List m_scenes = new List(); + private List m_validInWorldChannels = new List(); internal object m_syncInit = new object(); internal object m_syncLogout = new object(); @@ -65,6 +66,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat private bool m_relayPrivateChannels = false; private int m_relayChannelOut = -1; private bool m_clientReporting = true; + private bool m_relayChat = true; + private Regex m_accessPasswordRe = null; #region IRegionModule Members @@ -96,9 +99,27 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat m_relayPrivateChannels = m_config.GetBoolean("relay_private_channels", m_relayPrivateChannels); m_relayChannelOut = m_config.GetInt("relay_private_channel_out", m_relayChannelOut); + m_relayChat = m_config.GetBoolean("relay_chat", m_relayChat); m_clientReporting = m_config.GetBoolean("report_clients", m_clientReporting); + if (m_accessPasswordRe == null) + { + string pass = config.Configs["IRC"].GetString("access_password", String.Empty); + m_accessPasswordRe = new Regex(String.Format(@"^{0},(?[^,]+),(?.+)$", pass), + RegexOptions.Compiled); + } + + if (m_relayChat) + { + m_validInWorldChannels.Add(0); + m_validInWorldChannels.Add(DEBUG_CHANNEL); + } + + if (m_relayPrivateChannels) + m_validInWorldChannels.Add(m_relayChannelOut); + + lock (m_syncInit) { @@ -227,19 +248,9 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat } } - // drop all messages coming in on a private channel, - // except if we are relaying private channels, in which - // case we drop if the private channel is not the - // configured m_relayChannelOut - if (m_relayPrivateChannels) - { - if (c.Channel != 0 && c.Channel != DEBUG_CHANNEL && c.Channel != m_relayChannelOut) - { - m_log.DebugFormat("[IRC] dropping message {0} on channel {1}", c, c.Channel); - return; - } - } - else if (c.Channel != 0 && c.Channel != DEBUG_CHANNEL) + // drop messages if their channel is not on the valid + // in-world channel list + if (!m_validInWorldChannels.Contains(c.Channel)) { m_log.DebugFormat("[IRC] dropping message {0} on channel {1}", c, c.Channel); return; @@ -265,31 +276,28 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat return; } - if (null != avatar) + if (null != avatar && m_relayChat) { string msg = c.Message; if (msg.StartsWith("/me ")) msg = String.Format("{0} {1}", fromName, c.Message.Substring(4)); m_irc.PrivMsg(fromName, scene.RegionInfo.RegionName, msg); + return; } - else + + if (null == avatar && m_relayPrivateChannels) { - //Message came from an object - char[] splits = { ',' }; - string[] tokens = c.Message.Split(splits,3); // This is certainly wrong - if (tokens.Length == 3) + Match m; + if (m_accessPasswordRe != null && + (m = m_accessPasswordRe.Match(c.Message)) != null) { - if (tokens[0] == m_irc.m_accessPassword) // This is my really simple check - { - m_log.DebugFormat("[IRC] message from object {0}, {1}", tokens[0], tokens[1]); - m_irc.PrivMsg(tokens[1], scene.RegionInfo.RegionName, tokens[2]); - } - else - { - m_log.WarnFormat("[IRC] prim security key mismatch <{0}> not <{1}>", tokens[0], m_irc.m_accessPassword); - } + m_log.DebugFormat("[IRC] relaying message from {0}: {1}", m.Groups["avatar"].ToString(), + m.Groups["message"].ToString()); + m_irc.PrivMsg(m.Groups["avatar"].ToString(), scene.RegionInfo.RegionName, + m.Groups["message"].ToString()); } + return; } } #endregion diff --git a/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCConnector.cs b/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCConnector.cs index 9ad467ee51..ddf6601e89 100644 --- a/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCConnector.cs +++ b/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCConnector.cs @@ -135,8 +135,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat set { m_server = value; } } - public string m_accessPassword = "badkitty"; - private string m_privmsgformat = "PRIVMSG {0} :<{1} in {2}>: {3}"; private StreamReader m_reader; private List m_scenes = new List(); @@ -188,20 +186,14 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat m_port = (uint)config.Configs["IRC"].GetInt("port", (int)m_port); m_user = config.Configs["IRC"].GetString("username", m_user); m_privmsgformat = config.Configs["IRC"].GetString("msgformat", m_privmsgformat); - // m_commandChannel = config.Configs["IRC"].GetInt("commandchannel", m_commandChannel); - // m_verbosity = config.Configs["IRC"].GetInt("verbosity", m_verbosity); m_clientReporting = config.Configs["IRC"].GetInt("verbosity", 2) > 0; m_clientReporting = config.Configs["IRC"].GetBoolean("report_clients", m_clientReporting); - // m_messageOutChannel = config.Configs["IRC"].GetInt("outchannel", m_messageOutChannel); - // m_messageInChannel = config.Configs["IRC"].GetInt("inchannel", m_messageInChannel); m_relayPrivateChannels = config.Configs["IRC"].GetBoolean("relay_private_channels", m_relayPrivateChannels); m_relayPrivateChannels = config.Configs["IRC"].GetBoolean("useworldcomm", m_relayPrivateChannels); //compat m_relayChannel = config.Configs["IRC"].GetInt("relay_private_channel_in", m_relayChannel); m_relayChannel = config.Configs["IRC"].GetInt("inchannel", m_relayChannel); - m_accessPassword = config.Configs["IRC"].GetString("access_password",m_accessPassword); - // m_useWorldComm = config.Configs["IRC"].GetBoolean("useworldcomm", m_useWorldComm); if (m_server != null && m_baseNick != null && m_ircChannel != null) {