merging changes from IRCBridgeModule in to XIRCBridgeModule; swapping

OpenSim.ini config tags in preparation for merge of IRCBridgeModule
and XIRCBridgeModule.
0.6.0-stable
Dr Scofield 2008-11-03 16:20:13 +00:00
parent d0c8d7a177
commit d6d2a38e76
6 changed files with 81 additions and 64 deletions

View File

@ -50,6 +50,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
private static Regex arg = new Regex(@"\[[^\[\]]*\]");
private static int _idk_ = 0;
private static int DEBUG_CHANNEL = 2147483647;
// These are the IRC Connector configurable parameters with hard-wired
// default values (retained for compatability).
@ -61,8 +62,10 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
internal string User = "USER OpenSimBot 8 * :I'm an OpenSim to IRC bot";
internal bool ClientReporting = true;
internal bool RelayChat = true;
internal bool RelayPrivateChannels = false;
internal int RelayChannel = 1;
internal List<int> ValidInWorldChannels = new List<int>();
// Connector agnostic parameters. These values are NOT shared with the
// connector and do not differentiate at an IRC level
@ -71,13 +74,27 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
internal string NoticeMessageFormat = "PRIVMSG {0} :<{2}> {3}";
internal int RelayChannelOut = -1;
internal bool RandomizeNickname = true;
internal string AccessPassword = "badkitty";
internal bool CommandsEnabled = false;
internal int CommandChannel = -1;
internal int ConnectDelay = 10;
internal int PingDelay = 15;
internal string DefaultZone = "Sim";
internal string _accessPassword = String.Empty;
internal Regex AccessPasswordRegex = null;
internal string AccessPassword
{
get { return _accessPassword; }
set
{
_accessPassword = value;
AccessPasswordRegex = new Regex(String.Format(@"^{0},\s*(?<avatar>[^,]+),\s*(?<message>.+)$", _accessPassword),
RegexOptions.Compiled);
}
}
// IRC connector reference
internal XIRCConnector irc = null;
@ -108,9 +125,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
User = model.User;
CommandsEnabled = model.CommandsEnabled;
CommandChannel = model.CommandChannel;
RelayChat = model.RelayChat;
RelayPrivateChannels = model.RelayPrivateChannels;
RelayChannelOut = model.RelayChannelOut;
RelayChannel = model.RelayChannel;
ValidInWorldChannels = model.ValidInWorldChannels;
PrivateMessageFormat = model.PrivateMessageFormat;
NoticeMessageFormat = model.NoticeMessageFormat;
ClientReporting = model.ClientReporting;
@ -158,6 +177,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
m_log.DebugFormat("[IRC-Channel-{0}] CommandChannel : <{1}>", cs.idn, cs.CommandChannel);
cs.CommandChannel = Convert.ToInt32(Substitute(rs, config.GetString("command_channel", Convert.ToString(cs.CommandChannel))));
m_log.DebugFormat("[IRC-Channel-{0}] CommandChannel : <{1}>", cs.idn, cs.CommandChannel);
cs.RelayChat = Convert.ToBoolean(Substitute(rs, config.GetString("relay_chat", Convert.ToString(cs.RelayChat))));
m_log.DebugFormat("[IRC-Channel-{0}] RelayChat : <{1}>", cs.idn, cs.RelayChat);
cs.RelayPrivateChannels = Convert.ToBoolean(Substitute(rs, config.GetString("relay_private_channels", Convert.ToString(cs.RelayPrivateChannels))));
m_log.DebugFormat("[IRC-Channel-{0}] RelayPrivateChannels : <{1}>", cs.idn, cs.RelayPrivateChannels);
cs.RelayPrivateChannels = Convert.ToBoolean(Substitute(rs, config.GetString("useworldcomm", Convert.ToString(cs.RelayPrivateChannels))));
@ -176,14 +197,15 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
m_log.DebugFormat("[IRC-Channel-{0}] ClientReporting : <{1}>", cs.idn, cs.ClientReporting);
cs.ClientReporting = Convert.ToBoolean(Substitute(rs, config.GetString("report_clients", Convert.ToString(cs.ClientReporting))));
m_log.DebugFormat("[IRC-Channel-{0}] ClientReporting : <{1}>", cs.idn, cs.ClientReporting);
cs.AccessPassword = Substitute(rs, config.GetString("access_password", cs.AccessPassword));
m_log.DebugFormat("[IRC-Channel-{0}] AccessPassword : <{1}>", cs.idn, cs.AccessPassword);
cs.DefaultZone = Substitute(rs, config.GetString("fallback_region", cs.DefaultZone));
m_log.DebugFormat("[IRC-Channel-{0}] DefaultZone : <{1}>", cs.idn, cs.DefaultZone);
cs.ConnectDelay = Convert.ToInt32(Substitute(rs, config.GetString("connect_delay", Convert.ToString(cs.ConnectDelay))));
m_log.DebugFormat("[IRC-Channel-{0}] ConnectDelay : <{1}>", cs.idn, cs.ConnectDelay);
cs.PingDelay = Convert.ToInt32(Substitute(rs, config.GetString("ping_delay", Convert.ToString(cs.PingDelay))));
m_log.DebugFormat("[IRC-Channel-{0}] PingDelay : <{1}>", cs.idn, cs.PingDelay);
cs.AccessPassword = Substitute(rs, config.GetString("access_password", cs.AccessPassword));
m_log.DebugFormat("[IRC-Channel-{0}] AccessPassword : <{1}>", cs.idn, cs.AccessPassword);
// Fail if fundamental information is still missing
@ -199,6 +221,15 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
// Set the channel state for this region
if (cs.RelayChat)
{
cs.ValidInWorldChannels.Add(0);
cs.ValidInWorldChannels.Add(DEBUG_CHANNEL);
}
if (cs.RelayPrivateChannels)
cs.ValidInWorldChannels.Add(cs.RelayChannelOut);
rs.cs = Integrate(rs, cs);
}
@ -377,18 +408,18 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
private bool IsAPerfectMatchFor(ChannelState cs)
{
return ( IsAConnectionMatchFor(cs) &&
RelayChannelOut == cs.RelayChannelOut &&
PrivateMessageFormat == cs.PrivateMessageFormat &&
NoticeMessageFormat == cs.NoticeMessageFormat &&
RandomizeNickname == cs.RandomizeNickname &&
AccessPassword == cs.AccessPassword &&
CommandsEnabled == cs.CommandsEnabled &&
CommandChannel == cs.CommandChannel &&
DefaultZone == cs.DefaultZone &&
RelayPrivateChannels == cs.RelayPrivateChannels &&
RelayChannel == cs.RelayChannel &&
ClientReporting == cs.ClientReporting
RelayChannelOut == cs.RelayChannelOut &&
PrivateMessageFormat == cs.PrivateMessageFormat &&
NoticeMessageFormat == cs.NoticeMessageFormat &&
RandomizeNickname == cs.RandomizeNickname &&
AccessPassword == cs.AccessPassword &&
CommandsEnabled == cs.CommandsEnabled &&
CommandChannel == cs.CommandChannel &&
DefaultZone == cs.DefaultZone &&
RelayPrivateChannels == cs.RelayPrivateChannels &&
RelayChannel == cs.RelayChannel &&
RelayChat == cs.RelayChat &&
ClientReporting == cs.ClientReporting
);
}

View File

@ -75,7 +75,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
{
try
{
if ((m_config = config.Configs["IRC"]) == null)
if ((m_config = config.Configs["OIRC"]) == null)
{
m_log.InfoFormat("[IRC] module not configured");
return;

View File

@ -177,23 +177,23 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
try
{
m_server = config.Configs["IRC"].GetString("server");
m_baseNick = config.Configs["IRC"].GetString("nick", "OSimBot");
m_server = config.Configs["OIRC"].GetString("server");
m_baseNick = config.Configs["OIRC"].GetString("nick", "OSimBot");
m_randomizeNick = config.Configs["IRC"].GetBoolean("randomize_nick", m_randomizeNick);
m_randomizeNick = config.Configs["IRC"].GetBoolean("nicknum", m_randomizeNick); // compat
m_ircChannel = config.Configs["IRC"].GetString("channel");
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_randomizeNick = config.Configs["OIRC"].GetBoolean("randomize_nick", m_randomizeNick);
m_randomizeNick = config.Configs["OIRC"].GetBoolean("nicknum", m_randomizeNick); // compat
m_ircChannel = config.Configs["OIRC"].GetString("channel");
m_port = (uint)config.Configs["OIRC"].GetInt("port", (int)m_port);
m_user = config.Configs["OIRC"].GetString("username", m_user);
m_privmsgformat = config.Configs["OIRC"].GetString("msgformat", m_privmsgformat);
m_clientReporting = config.Configs["IRC"].GetInt("verbosity", 2) > 0;
m_clientReporting = config.Configs["IRC"].GetBoolean("report_clients", m_clientReporting);
m_clientReporting = config.Configs["OIRC"].GetInt("verbosity", 2) > 0;
m_clientReporting = config.Configs["OIRC"].GetBoolean("report_clients", m_clientReporting);
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_relayPrivateChannels = config.Configs["OIRC"].GetBoolean("relay_private_channels", m_relayPrivateChannels);
m_relayPrivateChannels = config.Configs["OIRC"].GetBoolean("useworldcomm", m_relayPrivateChannels); //compat
m_relayChannel = config.Configs["OIRC"].GetInt("relay_private_channel_in", m_relayChannel);
m_relayChannel = config.Configs["OIRC"].GetInt("inchannel", m_relayChannel);
if (m_server != null && m_baseNick != null && m_ircChannel != null)
{

View File

@ -28,6 +28,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text.RegularExpressions;
using log4net;
using Nini.Config;
using OpenSim.Framework;
@ -331,27 +332,16 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
if (!enabled)
return;
// 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
// drop messages unless they are on a valid in-world
// channel as configured in the ChannelState
if (cs.RelayPrivateChannels)
{
if (msg.Channel != 0 && msg.Channel != DEBUG_CHANNEL && msg.Channel != cs.RelayChannelOut)
{
m_log.DebugFormat("[IRC-Region {0}] dropping message {1} on channel {2}", Region, msg, msg.Channel);
return;
}
}
else if (msg.Channel != 0 && msg.Channel != DEBUG_CHANNEL)
if (!cs.ValidInWorldChannels.Contains(msg.Channel))
{
m_log.DebugFormat("[IRC-Region {0}] dropping message {1} on channel {2}", Region, msg, msg.Channel);
return;
}
}
ScenePresence avatar = null;
string fromName = msg.From;
if (msg.Sender != null)
@ -368,31 +358,26 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
m_log.DebugFormat("[IRC-Region {0}] heard on channel {1} : {2}", Region, msg.Channel, msg.Message);
if (null != avatar)
if (null != avatar && cs.RelayChat && (msg.Channel == 0 || msg.Channel == DEBUG_CHANNEL))
{
string txt = msg.Message;
if (txt.StartsWith("/me "))
txt = String.Format("{0} {1}", fromName, msg.Message.Substring(4));
cs.irc.PrivMsg(cs.PrivateMessageFormat, fromName, Region, txt);
return;
}
else
{
//Message came from an object
char[] splits = { ',' };
string[] tokens = msg.Message.Split(splits,3); // This is certainly wrong
if (tokens.Length == 3)
if (null == avatar && cs.RelayPrivateChannels && null != cs.AccessPassword &&
msg.Channel == cs.RelayChannelOut)
{
Match m = cs.AccessPasswordRegex.Match(msg.Message);
if (null != m)
{
if (tokens[0] == cs.AccessPassword) // This is my really simple check
{
m_log.DebugFormat("[IRC-Region {0}] message from object {1}, {2}", Region, tokens[0], tokens[1]);
cs.irc.PrivMsg(cs.PrivateMessageFormat, tokens[1], scene.RegionInfo.RegionName, tokens[2]);
}
else
{
m_log.WarnFormat("[IRC-Region {0}] prim security key mismatch <{1}> not <{2}>", Region, tokens[0], cs.AccessPassword);
}
m_log.DebugFormat("[IRC] relaying message from {0}: {1}", m.Groups["avatar"].ToString(),
m.Groups["message"].ToString());
cs.irc.PrivMsg(cs.PrivateMessageFormat, m.Groups["avatar"].ToString(),
scene.RegionInfo.RegionName, m.Groups["message"].ToString());
}
}
}

View File

@ -79,7 +79,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
try
{
if ((m_config = config.Configs["XIRC"]) == null)
if ((m_config = config.Configs["IRC"]) == null)
{
m_log.InfoFormat("[XIRC-Bridge] module not configured");
return;

View File

@ -521,6 +521,9 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
}
private Regex RE = new Regex(@":(?<nick>[\w-]*)!(?<user>\S*) PRIVMSG (?<channel>\S+) :(?<msg>.*)",
RegexOptions.Multiline);
private Dictionary<string, string> ExtractMsg(string input)
{
//examines IRC commands and extracts any private messages
@ -529,8 +532,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat
// m_log.InfoFormat("[IRC-Connector-{0}]: ExtractMsg: {1}", idn, input);
Dictionary<string, string> result = null;
string regex = @":(?<nick>[\w-]*)!(?<user>\S*) PRIVMSG (?<channel>\S+) :(?<msg>.*)";
Regex RE = new Regex(regex, RegexOptions.Multiline);
MatchCollection matches = RE.Matches(input);
// Get some direct matches $1 $4 is a