IRCBridgeModule: optional agent-alertbox for IRC enabled Regions look in OpenSimDefaults.ini / section [IRC]

http://opensimulator.org/mantis/view.php?id=6470

idea: https://github.com/ssm2017/IrcBridgeAlert
user_profiles
PixelTomsen 2013-01-13 20:18:40 +01:00 committed by Justin Clark-Casey (justincc)
parent 41ae006e9b
commit 9c590e51b6
5 changed files with 317 additions and 274 deletions

View File

@ -55,35 +55,35 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
// These are the IRC Connector configurable parameters with hard-wired // These are the IRC Connector configurable parameters with hard-wired
// default values (retained for compatability). // default values (retained for compatability).
internal string Server = null; internal string Server = null;
internal string Password = null; internal string Password = null;
internal string IrcChannel = null; internal string IrcChannel = null;
internal string BaseNickname = "OSimBot"; internal string BaseNickname = "OSimBot";
internal uint Port = 6667; internal uint Port = 6667;
internal string User = null; internal string User = null;
internal bool ClientReporting = true; internal bool ClientReporting = true;
internal bool RelayChat = true; internal bool RelayChat = true;
internal bool RelayPrivateChannels = false; internal bool RelayPrivateChannels = false;
internal int RelayChannel = 1; internal int RelayChannel = 1;
internal List<int> ValidInWorldChannels = new List<int>(); internal List<int> ValidInWorldChannels = new List<int>();
// Connector agnostic parameters. These values are NOT shared with the // Connector agnostic parameters. These values are NOT shared with the
// connector and do not differentiate at an IRC level // connector and do not differentiate at an IRC level
internal string PrivateMessageFormat = "PRIVMSG {0} :<{2}> {1} {3}"; internal string PrivateMessageFormat = "PRIVMSG {0} :<{2}> {1} {3}";
internal string NoticeMessageFormat = "PRIVMSG {0} :<{2}> {3}"; internal string NoticeMessageFormat = "PRIVMSG {0} :<{2}> {3}";
internal int RelayChannelOut = -1; internal int RelayChannelOut = -1;
internal bool RandomizeNickname = true; internal bool RandomizeNickname = true;
internal bool CommandsEnabled = false; internal bool CommandsEnabled = false;
internal int CommandChannel = -1; internal int CommandChannel = -1;
internal int ConnectDelay = 10; internal int ConnectDelay = 10;
internal int PingDelay = 15; internal int PingDelay = 15;
internal string DefaultZone = "Sim"; internal string DefaultZone = "Sim";
internal string _accessPassword = String.Empty; internal string _accessPassword = String.Empty;
internal Regex AccessPasswordRegex = null; internal Regex AccessPasswordRegex = null;
internal List<string> ExcludeList = new List<string>(); internal List<string> ExcludeList = new List<string>();
internal string AccessPassword internal string AccessPassword
{ {
get { return _accessPassword; } get { return _accessPassword; }
@ -99,9 +99,9 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
// IRC connector reference // IRC connector reference
internal IRCConnector irc = null; internal IRCConnector irc = null;
internal int idn = _idk_++; internal int idn = _idk_++;
// List of regions dependent upon this connection // List of regions dependent upon this connection
@ -119,27 +119,27 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
internal ChannelState(ChannelState model) internal ChannelState(ChannelState model)
{ {
Server = model.Server; Server = model.Server;
Password = model.Password; Password = model.Password;
IrcChannel = model.IrcChannel; IrcChannel = model.IrcChannel;
Port = model.Port; Port = model.Port;
BaseNickname = model.BaseNickname; BaseNickname = model.BaseNickname;
RandomizeNickname = model.RandomizeNickname; RandomizeNickname = model.RandomizeNickname;
User = model.User; User = model.User;
CommandsEnabled = model.CommandsEnabled; CommandsEnabled = model.CommandsEnabled;
CommandChannel = model.CommandChannel; CommandChannel = model.CommandChannel;
RelayChat = model.RelayChat; RelayChat = model.RelayChat;
RelayPrivateChannels = model.RelayPrivateChannels; RelayPrivateChannels = model.RelayPrivateChannels;
RelayChannelOut = model.RelayChannelOut; RelayChannelOut = model.RelayChannelOut;
RelayChannel = model.RelayChannel; RelayChannel = model.RelayChannel;
ValidInWorldChannels = model.ValidInWorldChannels; ValidInWorldChannels = model.ValidInWorldChannels;
PrivateMessageFormat = model.PrivateMessageFormat; PrivateMessageFormat = model.PrivateMessageFormat;
NoticeMessageFormat = model.NoticeMessageFormat; NoticeMessageFormat = model.NoticeMessageFormat;
ClientReporting = model.ClientReporting; ClientReporting = model.ClientReporting;
AccessPassword = model.AccessPassword; AccessPassword = model.AccessPassword;
DefaultZone = model.DefaultZone; DefaultZone = model.DefaultZone;
ConnectDelay = model.ConnectDelay; ConnectDelay = model.ConnectDelay;
PingDelay = model.PingDelay; PingDelay = model.PingDelay;
} }
// Read the configuration file, performing variable substitution and any // Read the configuration file, performing variable substitution and any
@ -160,54 +160,54 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
m_log.DebugFormat("[IRC-Channel-{0}] Initial request by Region {1} to connect to IRC", cs.idn, rs.Region); m_log.DebugFormat("[IRC-Channel-{0}] Initial request by Region {1} to connect to IRC", cs.idn, rs.Region);
cs.Server = Substitute(rs, config.GetString("server", null)); cs.Server = Substitute(rs, config.GetString("server", null));
m_log.DebugFormat("[IRC-Channel-{0}] Server : <{1}>", cs.idn, cs.Server); m_log.DebugFormat("[IRC-Channel-{0}] Server : <{1}>", cs.idn, cs.Server);
cs.Password = Substitute(rs, config.GetString("password", null)); cs.Password = Substitute(rs, config.GetString("password", null));
// probably not a good idea to put a password in the log file // probably not a good idea to put a password in the log file
cs.User = Substitute(rs, config.GetString("user", null)); cs.User = Substitute(rs, config.GetString("user", null));
cs.IrcChannel = Substitute(rs, config.GetString("channel", null)); cs.IrcChannel = Substitute(rs, config.GetString("channel", null));
m_log.DebugFormat("[IRC-Channel-{0}] IrcChannel : <{1}>", cs.idn, cs.IrcChannel); m_log.DebugFormat("[IRC-Channel-{0}] IrcChannel : <{1}>", cs.idn, cs.IrcChannel);
cs.Port = Convert.ToUInt32(Substitute(rs, config.GetString("port", Convert.ToString(cs.Port)))); cs.Port = Convert.ToUInt32(Substitute(rs, config.GetString("port", Convert.ToString(cs.Port))));
m_log.DebugFormat("[IRC-Channel-{0}] Port : <{1}>", cs.idn, cs.Port); m_log.DebugFormat("[IRC-Channel-{0}] Port : <{1}>", cs.idn, cs.Port);
cs.BaseNickname = Substitute(rs, config.GetString("nick", cs.BaseNickname)); cs.BaseNickname = Substitute(rs, config.GetString("nick", cs.BaseNickname));
m_log.DebugFormat("[IRC-Channel-{0}] BaseNickname : <{1}>", cs.idn, cs.BaseNickname); m_log.DebugFormat("[IRC-Channel-{0}] BaseNickname : <{1}>", cs.idn, cs.BaseNickname);
cs.RandomizeNickname = Convert.ToBoolean(Substitute(rs, config.GetString("randomize_nick", Convert.ToString(cs.RandomizeNickname)))); cs.RandomizeNickname = Convert.ToBoolean(Substitute(rs, config.GetString("randomize_nick", Convert.ToString(cs.RandomizeNickname))));
m_log.DebugFormat("[IRC-Channel-{0}] RandomizeNickname : <{1}>", cs.idn, cs.RandomizeNickname); m_log.DebugFormat("[IRC-Channel-{0}] RandomizeNickname : <{1}>", cs.idn, cs.RandomizeNickname);
cs.RandomizeNickname = Convert.ToBoolean(Substitute(rs, config.GetString("nicknum", Convert.ToString(cs.RandomizeNickname)))); cs.RandomizeNickname = Convert.ToBoolean(Substitute(rs, config.GetString("nicknum", Convert.ToString(cs.RandomizeNickname))));
m_log.DebugFormat("[IRC-Channel-{0}] RandomizeNickname : <{1}>", cs.idn, cs.RandomizeNickname); m_log.DebugFormat("[IRC-Channel-{0}] RandomizeNickname : <{1}>", cs.idn, cs.RandomizeNickname);
cs.User = Substitute(rs, config.GetString("username", cs.User)); cs.User = Substitute(rs, config.GetString("username", cs.User));
m_log.DebugFormat("[IRC-Channel-{0}] User : <{1}>", cs.idn, cs.User); m_log.DebugFormat("[IRC-Channel-{0}] User : <{1}>", cs.idn, cs.User);
cs.CommandsEnabled = Convert.ToBoolean(Substitute(rs, config.GetString("commands_enabled", Convert.ToString(cs.CommandsEnabled)))); cs.CommandsEnabled = Convert.ToBoolean(Substitute(rs, config.GetString("commands_enabled", Convert.ToString(cs.CommandsEnabled))));
m_log.DebugFormat("[IRC-Channel-{0}] CommandsEnabled : <{1}>", cs.idn, cs.CommandsEnabled); m_log.DebugFormat("[IRC-Channel-{0}] CommandsEnabled : <{1}>", cs.idn, cs.CommandsEnabled);
cs.CommandChannel = Convert.ToInt32(Substitute(rs, config.GetString("commandchannel", Convert.ToString(cs.CommandChannel)))); cs.CommandChannel = Convert.ToInt32(Substitute(rs, config.GetString("commandchannel", Convert.ToString(cs.CommandChannel))));
m_log.DebugFormat("[IRC-Channel-{0}] CommandChannel : <{1}>", cs.idn, cs.CommandChannel); 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)))); 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); 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)))); 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); 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)))); 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); 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)))); cs.RelayPrivateChannels = Convert.ToBoolean(Substitute(rs, config.GetString("useworldcomm", Convert.ToString(cs.RelayPrivateChannels))));
m_log.DebugFormat("[IRC-Channel-{0}] RelayPrivateChannels : <{1}>", cs.idn, cs.RelayPrivateChannels); m_log.DebugFormat("[IRC-Channel-{0}] RelayPrivateChannels : <{1}>", cs.idn, cs.RelayPrivateChannels);
cs.RelayChannelOut = Convert.ToInt32(Substitute(rs, config.GetString("relay_private_channel_out", Convert.ToString(cs.RelayChannelOut)))); cs.RelayChannelOut = Convert.ToInt32(Substitute(rs, config.GetString("relay_private_channel_out", Convert.ToString(cs.RelayChannelOut))));
m_log.DebugFormat("[IRC-Channel-{0}] RelayChannelOut : <{1}>", cs.idn, cs.RelayChannelOut); m_log.DebugFormat("[IRC-Channel-{0}] RelayChannelOut : <{1}>", cs.idn, cs.RelayChannelOut);
cs.RelayChannel = Convert.ToInt32(Substitute(rs, config.GetString("relay_private_channel_in", Convert.ToString(cs.RelayChannel)))); cs.RelayChannel = Convert.ToInt32(Substitute(rs, config.GetString("relay_private_channel_in", Convert.ToString(cs.RelayChannel))));
m_log.DebugFormat("[IRC-Channel-{0}] RelayChannel : <{1}>", cs.idn, cs.RelayChannel); m_log.DebugFormat("[IRC-Channel-{0}] RelayChannel : <{1}>", cs.idn, cs.RelayChannel);
cs.RelayChannel = Convert.ToInt32(Substitute(rs, config.GetString("inchannel", Convert.ToString(cs.RelayChannel)))); cs.RelayChannel = Convert.ToInt32(Substitute(rs, config.GetString("inchannel", Convert.ToString(cs.RelayChannel))));
m_log.DebugFormat("[IRC-Channel-{0}] RelayChannel : <{1}>", cs.idn, cs.RelayChannel); m_log.DebugFormat("[IRC-Channel-{0}] RelayChannel : <{1}>", cs.idn, cs.RelayChannel);
cs.PrivateMessageFormat = Substitute(rs, config.GetString("msgformat", cs.PrivateMessageFormat)); cs.PrivateMessageFormat = Substitute(rs, config.GetString("msgformat", cs.PrivateMessageFormat));
m_log.DebugFormat("[IRC-Channel-{0}] PrivateMessageFormat : <{1}>", cs.idn, cs.PrivateMessageFormat); m_log.DebugFormat("[IRC-Channel-{0}] PrivateMessageFormat : <{1}>", cs.idn, cs.PrivateMessageFormat);
cs.NoticeMessageFormat = Substitute(rs, config.GetString("noticeformat", cs.NoticeMessageFormat)); cs.NoticeMessageFormat = Substitute(rs, config.GetString("noticeformat", cs.NoticeMessageFormat));
m_log.DebugFormat("[IRC-Channel-{0}] NoticeMessageFormat : <{1}>", cs.idn, cs.NoticeMessageFormat); m_log.DebugFormat("[IRC-Channel-{0}] NoticeMessageFormat : <{1}>", cs.idn, cs.NoticeMessageFormat);
cs.ClientReporting = Convert.ToInt32(Substitute(rs, config.GetString("verbosity", cs.ClientReporting?"1":"0"))) > 0; cs.ClientReporting = Convert.ToInt32(Substitute(rs, config.GetString("verbosity", cs.ClientReporting ? "1" : "0"))) > 0;
m_log.DebugFormat("[IRC-Channel-{0}] ClientReporting : <{1}>", cs.idn, cs.ClientReporting); 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)))); 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); m_log.DebugFormat("[IRC-Channel-{0}] ClientReporting : <{1}>", cs.idn, cs.ClientReporting);
cs.DefaultZone = Substitute(rs, config.GetString("fallback_region", cs.DefaultZone)); cs.DefaultZone = Substitute(rs, config.GetString("fallback_region", cs.DefaultZone));
m_log.DebugFormat("[IRC-Channel-{0}] DefaultZone : <{1}>", cs.idn, 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)))); 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); 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)))); 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); m_log.DebugFormat("[IRC-Channel-{0}] PingDelay : <{1}>", cs.idn, cs.PingDelay);
cs.AccessPassword = Substitute(rs, config.GetString("access_password", cs.AccessPassword)); cs.AccessPassword = Substitute(rs, config.GetString("access_password", cs.AccessPassword));
m_log.DebugFormat("[IRC-Channel-{0}] AccessPassword : <{1}>", cs.idn, cs.AccessPassword); m_log.DebugFormat("[IRC-Channel-{0}] AccessPassword : <{1}>", cs.idn, cs.AccessPassword);
@ -473,27 +473,27 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
{ {
string vvar = arg.Match(result).ToString(); string vvar = arg.Match(result).ToString();
string var = vvar.Substring(1,vvar.Length-2).Trim(); string var = vvar.Substring(1, vvar.Length - 2).Trim();
switch (var.ToLower()) switch (var.ToLower())
{ {
case "%region" : case "%region":
result = result.Replace(vvar, rs.Region); result = result.Replace(vvar, rs.Region);
break; break;
case "%host" : case "%host":
result = result.Replace(vvar, rs.Host); result = result.Replace(vvar, rs.Host);
break; break;
case "%locx" : case "%locx":
result = result.Replace(vvar, rs.LocX); result = result.Replace(vvar, rs.LocX);
break; break;
case "%locy" : case "%locy":
result = result.Replace(vvar, rs.LocY); result = result.Replace(vvar, rs.LocY);
break; break;
case "%k" : case "%k":
result = result.Replace(vvar, rs.IDK); result = result.Replace(vvar, rs.IDK);
break; break;
default : default:
result = result.Replace(vvar, rs.config.GetString(var,var)); result = result.Replace(vvar, rs.config.GetString(var, var));
break; break;
} }
// m_log.DebugFormat("[IRC-Channel] Parse[2]: {0}", result); // m_log.DebugFormat("[IRC-Channel] Parse[2]: {0}", result);

View File

@ -46,11 +46,11 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
internal static bool m_pluginEnabled = false; internal static bool Enabled = false;
internal static IConfig m_config = null; internal static IConfig m_config = null;
internal static List<ChannelState> m_channels = new List<ChannelState>(); internal static List<ChannelState> m_channels = new List<ChannelState>();
internal static List<RegionState> m_regions = new List<RegionState>(); internal static List<RegionState> m_regions = new List<RegionState>();
internal static string m_password = String.Empty; internal static string m_password = String.Empty;
internal RegionState m_region = null; internal RegionState m_region = null;
@ -72,13 +72,13 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
m_config = config.Configs["IRC"]; m_config = config.Configs["IRC"];
if (m_config == null) if (m_config == null)
{ {
// m_log.InfoFormat("[IRC-Bridge] module not configured"); // m_log.InfoFormat("[IRC-Bridge] module not configured");
return; return;
} }
if (!m_config.GetBoolean("enabled", false)) if (!m_config.GetBoolean("enabled", false))
{ {
// m_log.InfoFormat("[IRC-Bridge] module disabled in configuration"); // m_log.InfoFormat("[IRC-Bridge] module disabled in configuration");
return; return;
} }
@ -87,19 +87,22 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
m_password = config.Configs["RemoteAdmin"].GetString("access_password", m_password); m_password = config.Configs["RemoteAdmin"].GetString("access_password", m_password);
} }
m_pluginEnabled = true; Enabled = true;
m_log.InfoFormat("[IRC-Bridge]: Module enabled");
m_log.InfoFormat("[IRC-Bridge]: Module is enabled");
} }
public void AddRegion(Scene scene) public void AddRegion(Scene scene)
{ {
if (m_pluginEnabled) if (Enabled)
{ {
try try
{ {
m_log.InfoFormat("[IRC-Bridge] Connecting region {0}", scene.RegionInfo.RegionName); m_log.InfoFormat("[IRC-Bridge] Connecting region {0}", scene.RegionInfo.RegionName);
if (!String.IsNullOrEmpty(m_password)) if (!String.IsNullOrEmpty(m_password))
MainServer.Instance.AddXmlRPCHandler("irc_admin", XmlRpcAdminMethod, false); MainServer.Instance.AddXmlRPCHandler("irc_admin", XmlRpcAdminMethod, false);
m_region = new RegionState(scene, m_config); m_region = new RegionState(scene, m_config);
lock (m_regions) m_regions.Add(m_region); lock (m_regions) m_regions.Add(m_region);
m_region.Open(); m_region.Open();
@ -123,7 +126,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
public void RemoveRegion(Scene scene) public void RemoveRegion(Scene scene)
{ {
if (!m_pluginEnabled) if (!Enabled)
return; return;
if (m_region == null) if (m_region == null)
@ -150,12 +153,12 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
m_log.Debug("[IRC-Bridge]: XML RPC Admin Entry"); m_log.Debug("[IRC-Bridge]: XML RPC Admin Entry");
XmlRpcResponse response = new XmlRpcResponse(); XmlRpcResponse response = new XmlRpcResponse();
Hashtable responseData = new Hashtable(); Hashtable responseData = new Hashtable();
try try
{ {
Hashtable requestData = (Hashtable)request.Params[0]; Hashtable requestData = (Hashtable)request.Params[0];
bool found = false; bool found = false;
string region = String.Empty; string region = String.Empty;
if (m_password != String.Empty) if (m_password != String.Empty)
@ -174,13 +177,13 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
{ {
if (rs.Region == region) if (rs.Region == region)
{ {
responseData["server"] = rs.cs.Server; responseData["server"] = rs.cs.Server;
responseData["port"] = (int)rs.cs.Port; responseData["port"] = (int)rs.cs.Port;
responseData["user"] = rs.cs.User; responseData["user"] = rs.cs.User;
responseData["channel"] = rs.cs.IrcChannel; responseData["channel"] = rs.cs.IrcChannel;
responseData["enabled"] = rs.cs.irc.Enabled; responseData["enabled"] = rs.cs.irc.Enabled;
responseData["connected"] = rs.cs.irc.Connected; responseData["connected"] = rs.cs.irc.Connected;
responseData["nickname"] = rs.cs.irc.Nick; responseData["nickname"] = rs.cs.irc.Nick;
found = true; found = true;
break; break;
} }
@ -195,7 +198,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
m_log.ErrorFormat("[IRC-Bridge] XML RPC Admin request failed : {0}", e.Message); m_log.ErrorFormat("[IRC-Bridge] XML RPC Admin request failed : {0}", e.Message);
responseData["success"] = "false"; responseData["success"] = "false";
responseData["error"] = e.Message; responseData["error"] = e.Message;
} }
finally finally
{ {

View File

@ -53,16 +53,16 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
// Local constants // Local constants
private static readonly Vector3 CenterOfRegion = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 20); private static readonly Vector3 CenterOfRegion = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 20);
private static readonly char[] CS_SPACE = { ' ' }; private static readonly char[] CS_SPACE = { ' ' };
private const int WD_INTERVAL = 1000; // base watchdog interval private const int WD_INTERVAL = 1000; // base watchdog interval
private static int PING_PERIOD = 15; // WD intervals per PING private static int PING_PERIOD = 15; // WD intervals per PING
private static int ICCD_PERIOD = 10; // WD intervals between Connects private static int ICCD_PERIOD = 10; // WD intervals between Connects
private static int L_TIMEOUT = 25; // Login time out interval private static int L_TIMEOUT = 25; // Login time out interval
private static int _idk_ = 0; // core connector identifier private static int _idk_ = 0; // core connector identifier
private static int _pdk_ = 0; // ping interval counter private static int _pdk_ = 0; // ping interval counter
private static int _icc_ = ICCD_PERIOD; // IRC connect counter private static int _icc_ = ICCD_PERIOD; // IRC connect counter
// List of configured connectors // List of configured connectors
@ -113,7 +113,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
private Object msyncConnect = new Object(); private Object msyncConnect = new Object();
internal bool m_randomizeNick = true; // add random suffix internal bool m_randomizeNick = true; // add random suffix
internal string m_baseNick = null; // base name for randomizing internal string m_baseNick = null; // base name for randomizing
internal string m_nick = null; // effective nickname internal string m_nick = null; // effective nickname
@ -130,8 +130,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
} }
private bool m_connected = false; // connection status private bool m_connected = false; // connection status
private bool m_pending = false; // login disposition private bool m_pending = false; // login disposition
private int m_timeout = L_TIMEOUT; // login timeout counter private int m_timeout = L_TIMEOUT; // login timeout counter
public bool Connected public bool Connected
{ {
get { return m_connected; } get { return m_connected; }
@ -172,10 +172,10 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
// Network interface // Network interface
private TcpClient m_tcp; private TcpClient m_tcp;
private NetworkStream m_stream = null; private NetworkStream m_stream = null;
private StreamReader m_reader; private StreamReader m_reader;
private StreamWriter m_writer; private StreamWriter m_writer;
// Channel characteristic info (if available) // Channel characteristic info (if available)
@ -193,26 +193,26 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
// Prepare network interface // Prepare network interface
m_tcp = null; m_tcp = null;
m_writer = null; m_writer = null;
m_reader = null; m_reader = null;
// Setup IRC session parameters // Setup IRC session parameters
m_server = cs.Server; m_server = cs.Server;
m_password = cs.Password; m_password = cs.Password;
m_baseNick = cs.BaseNickname; m_baseNick = cs.BaseNickname;
m_randomizeNick = cs.RandomizeNickname; m_randomizeNick = cs.RandomizeNickname;
m_ircChannel = cs.IrcChannel; m_ircChannel = cs.IrcChannel;
m_port = cs.Port; m_port = cs.Port;
m_user = cs.User; m_user = cs.User;
if (m_watchdog == null) if (m_watchdog == null)
{ {
// Non-differentiating // Non-differentiating
ICCD_PERIOD = cs.ConnectDelay; ICCD_PERIOD = cs.ConnectDelay;
PING_PERIOD = cs.PingDelay; PING_PERIOD = cs.PingDelay;
// Smaller values are not reasonable // Smaller values are not reasonable
@ -295,15 +295,19 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
m_nick, m_ircChannel, m_server)); m_nick, m_ircChannel, m_server));
m_writer.Flush(); m_writer.Flush();
} }
catch (Exception) {} catch (Exception) { }
m_connected = false; m_connected = false;
try { m_writer.Close(); } catch (Exception) {} try { m_writer.Close(); }
try { m_reader.Close(); } catch (Exception) {} catch (Exception) { }
try { m_stream.Close(); } catch (Exception) {} try { m_reader.Close(); }
try { m_tcp.Close(); } catch (Exception) {} catch (Exception) { }
try { m_stream.Close(); }
catch (Exception) { }
try { m_tcp.Close(); }
catch (Exception) { }
} }
@ -347,10 +351,10 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
if (m_connected) return; if (m_connected) return;
m_connected = true; m_connected = true;
m_pending = true; m_pending = true;
m_timeout = L_TIMEOUT; m_timeout = L_TIMEOUT;
m_tcp = new TcpClient(m_server, (int)m_port); m_tcp = new TcpClient(m_server, (int)m_port);
m_stream = m_tcp.GetStream(); m_stream = m_tcp.GetStream();
m_reader = new StreamReader(m_stream); m_reader = new StreamReader(m_stream);
m_writer = new StreamWriter(m_stream); m_writer = new StreamWriter(m_stream);
@ -418,12 +422,15 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
// the socket and it will disappear of its own accord, once this // the socket and it will disappear of its own accord, once this
// processing is completed. // processing is completed.
try { m_writer.Close(); } catch (Exception) {} try { m_writer.Close(); }
try { m_reader.Close(); } catch (Exception) {} catch (Exception) { }
try { m_tcp.Close(); } catch (Exception) {} try { m_reader.Close(); }
catch (Exception) { }
try { m_tcp.Close(); }
catch (Exception) { }
m_connected = false; m_connected = false;
m_pending = false; m_pending = false;
m_resetk++; m_resetk++;
} }
@ -495,7 +502,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
{ {
string inputLine; string inputLine;
int resetk = m_resetk; int resetk = m_resetk;
try try
{ {
@ -617,8 +624,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
string[] commArgs; string[] commArgs;
string c_server = m_server; string c_server = m_server;
string pfx = String.Empty; string pfx = String.Empty;
string cmd = String.Empty; string cmd = String.Empty;
string parms = String.Empty; string parms = String.Empty;
// ":" indicates that a prefix is present // ":" indicates that a prefix is present
@ -627,15 +634,15 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
// ":" indicates that the remainder of the // ":" indicates that the remainder of the
// line is a single parameter value. // line is a single parameter value.
commArgs = command.Split(CS_SPACE,2); commArgs = command.Split(CS_SPACE, 2);
if (commArgs[0].StartsWith(":")) if (commArgs[0].StartsWith(":"))
{ {
pfx = commArgs[0].Substring(1); pfx = commArgs[0].Substring(1);
commArgs = commArgs[1].Split(CS_SPACE,2); commArgs = commArgs[1].Split(CS_SPACE, 2);
} }
cmd = commArgs[0]; cmd = commArgs[0];
parms = commArgs[1]; parms = commArgs[1];
// m_log.DebugFormat("[IRC-Connector-{0}] prefix = <{1}> cmd = <{2}>", idn, pfx, cmd); // m_log.DebugFormat("[IRC-Connector-{0}] prefix = <{1}> cmd = <{2}>", idn, pfx, cmd);
@ -646,44 +653,44 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
// Messages 001-004 are always sent // Messages 001-004 are always sent
// following signon. // following signon.
case "001" : // Welcome ... case "001": // Welcome ...
case "002" : // Server information case "002": // Server information
case "003" : // Welcome ... case "003": // Welcome ...
break; break;
case "004" : // Server information case "004": // Server information
m_log.DebugFormat("[IRC-Connector-{0}] [{1}] parms = <{2}>", idn, cmd, parms); m_log.DebugFormat("[IRC-Connector-{0}] [{1}] parms = <{2}>", idn, cmd, parms);
commArgs = parms.Split(CS_SPACE); commArgs = parms.Split(CS_SPACE);
c_server = commArgs[1]; c_server = commArgs[1];
m_server = c_server; m_server = c_server;
version = commArgs[2]; version = commArgs[2];
usermod = commArgs[3]; usermod = commArgs[3];
chanmod = commArgs[4]; chanmod = commArgs[4];
break; break;
case "005" : // Server information case "005": // Server information
break; break;
case "042" : case "042":
case "250" : case "250":
case "251" : case "251":
case "252" : case "252":
case "254" : case "254":
case "255" : case "255":
case "265" : case "265":
case "266" : case "266":
case "332" : // Subject case "332": // Subject
case "333" : // Subject owner (?) case "333": // Subject owner (?)
case "353" : // Name list case "353": // Name list
case "366" : // End-of-Name list marker case "366": // End-of-Name list marker
case "372" : // MOTD body case "372": // MOTD body
case "375" : // MOTD start case "375": // MOTD start
// m_log.InfoFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); // m_log.InfoFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]);
break; break;
case "376" : // MOTD end case "376": // MOTD end
// m_log.InfoFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); // m_log.InfoFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]);
motd = true; motd = true;
break; break;
case "451" : // Not registered case "451": // Not registered
break; break;
case "433" : // Nickname in use case "433": // Nickname in use
// Gen a new name // Gen a new name
m_nick = m_baseNick + Util.RandomClass.Next(1, 99); m_nick = m_baseNick + Util.RandomClass.Next(1, 99);
m_log.ErrorFormat("[IRC-Connector-{0}]: [{1}] IRC SERVER reports NicknameInUse, trying {2}", idn, cmd, m_nick); m_log.ErrorFormat("[IRC-Connector-{0}]: [{1}] IRC SERVER reports NicknameInUse, trying {2}", idn, cmd, m_nick);
@ -695,29 +702,29 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
m_writer.WriteLine(String.Format("JOIN {0}", m_ircChannel)); m_writer.WriteLine(String.Format("JOIN {0}", m_ircChannel));
m_writer.Flush(); m_writer.Flush();
break; break;
case "479" : // Bad channel name, etc. This will never work, so disable the connection case "479": // Bad channel name, etc. This will never work, so disable the connection
m_log.ErrorFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); m_log.ErrorFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE, 2)[1]);
m_log.ErrorFormat("[IRC-Connector-{0}] [{1}] Connector disabled", idn, cmd); m_log.ErrorFormat("[IRC-Connector-{0}] [{1}] Connector disabled", idn, cmd);
m_enabled = false; m_enabled = false;
m_connected = false; m_connected = false;
m_pending = false; m_pending = false;
break; break;
case "NOTICE" : case "NOTICE":
// m_log.WarnFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); // m_log.WarnFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]);
break; break;
case "ERROR" : case "ERROR":
m_log.ErrorFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE,2)[1]); m_log.ErrorFormat("[IRC-Connector-{0}] [{1}] {2}", idn, cmd, parms.Split(CS_SPACE, 2)[1]);
if (parms.Contains("reconnect too fast")) if (parms.Contains("reconnect too fast"))
ICCD_PERIOD++; ICCD_PERIOD++;
m_pending = false; m_pending = false;
Reconnect(); Reconnect();
break; break;
case "PING" : case "PING":
m_log.DebugFormat("[IRC-Connector-{0}] [{1}] parms = <{2}>", idn, cmd, parms); m_log.DebugFormat("[IRC-Connector-{0}] [{1}] parms = <{2}>", idn, cmd, parms);
m_writer.WriteLine(String.Format("PONG {0}", parms)); m_writer.WriteLine(String.Format("PONG {0}", parms));
m_writer.Flush(); m_writer.Flush();
break; break;
case "PONG" : case "PONG":
break; break;
case "JOIN": case "JOIN":
if (m_pending) if (m_pending)
@ -748,7 +755,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
m_log.DebugFormat("[IRC-Connector-{0}] [{1}] parms = <{2}>", idn, cmd, parms); m_log.DebugFormat("[IRC-Connector-{0}] [{1}] parms = <{2}>", idn, cmd, parms);
eventIrcQuit(pfx, cmd, parms); eventIrcQuit(pfx, cmd, parms);
break; break;
default : default:
m_log.DebugFormat("[IRC-Connector-{0}] Command '{1}' ignored, parms = {2}", idn, cmd, parms); m_log.DebugFormat("[IRC-Connector-{0}] Command '{1}' ignored, parms = {2}", idn, cmd, parms);
break; break;
} }
@ -759,8 +766,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
public void eventIrcJoin(string prefix, string command, string parms) public void eventIrcJoin(string prefix, string command, string parms)
{ {
string[] args = parms.Split(CS_SPACE,2); string[] args = parms.Split(CS_SPACE, 2);
string IrcUser = prefix.Split('!')[0]; string IrcUser = prefix.Split('!')[0];
string IrcChannel = args[0]; string IrcChannel = args[0];
if (IrcChannel.StartsWith(":")) if (IrcChannel.StartsWith(":"))
@ -772,8 +779,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
public void eventIrcPart(string prefix, string command, string parms) public void eventIrcPart(string prefix, string command, string parms)
{ {
string[] args = parms.Split(CS_SPACE,2); string[] args = parms.Split(CS_SPACE, 2);
string IrcUser = prefix.Split('!')[0]; string IrcUser = prefix.Split('!')[0];
string IrcChannel = args[0]; string IrcChannel = args[0];
m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCPart {1}:{2}", idn, m_server, m_ircChannel); m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCPart {1}:{2}", idn, m_server, m_ircChannel);
@ -782,7 +789,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
public void eventIrcMode(string prefix, string command, string parms) public void eventIrcMode(string prefix, string command, string parms)
{ {
string[] args = parms.Split(CS_SPACE,2); string[] args = parms.Split(CS_SPACE, 2);
string UserMode = args[1]; string UserMode = args[1];
m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCMode {1}:{2}", idn, m_server, m_ircChannel); m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCMode {1}:{2}", idn, m_server, m_ircChannel);
@ -794,7 +801,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
public void eventIrcNickChange(string prefix, string command, string parms) public void eventIrcNickChange(string prefix, string command, string parms)
{ {
string[] args = parms.Split(CS_SPACE,2); string[] args = parms.Split(CS_SPACE, 2);
string UserOldNick = prefix.Split('!')[0]; string UserOldNick = prefix.Split('!')[0];
string UserNewNick = args[0].Remove(0, 1); string UserNewNick = args[0].Remove(0, 1);
@ -804,10 +811,10 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
public void eventIrcKick(string prefix, string command, string parms) public void eventIrcKick(string prefix, string command, string parms)
{ {
string[] args = parms.Split(CS_SPACE,3); string[] args = parms.Split(CS_SPACE, 3);
string UserKicker = prefix.Split('!')[0]; string UserKicker = prefix.Split('!')[0];
string IrcChannel = args[0]; string IrcChannel = args[0];
string UserKicked = args[1]; string UserKicked = args[1];
string KickMessage = args[2]; string KickMessage = args[2];
m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCKick {1}:{2}", idn, m_server, m_ircChannel); m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCKick {1}:{2}", idn, m_server, m_ircChannel);
@ -822,7 +829,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
public void eventIrcQuit(string prefix, string command, string parms) public void eventIrcQuit(string prefix, string command, string parms)
{ {
string IrcUser = prefix.Split('!')[0]; string IrcUser = prefix.Split('!')[0];
string QuitMessage = parms; string QuitMessage = parms;
m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCQuit {1}:{2}", idn, m_server, m_ircChannel); m_log.DebugFormat("[IRC-Connector-{0}] Event: IRCQuit {1}:{2}", idn, m_server, m_ircChannel);
@ -842,65 +849,65 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
// m_log.InfoFormat("[IRC-Watchdog] Status scan, pdk = {0}, icc = {1}", _pdk_, _icc_); // m_log.InfoFormat("[IRC-Watchdog] Status scan, pdk = {0}, icc = {1}", _pdk_, _icc_);
_pdk_ = (_pdk_+1)%PING_PERIOD; // cycle the ping trigger _pdk_ = (_pdk_ + 1) % PING_PERIOD; // cycle the ping trigger
_icc_++; // increment the inter-consecutive-connect-delay counter _icc_++; // increment the inter-consecutive-connect-delay counter
lock (m_connectors) lock (m_connectors)
foreach (IRCConnector connector in m_connectors) foreach (IRCConnector connector in m_connectors)
{
// m_log.InfoFormat("[IRC-Watchdog] Scanning {0}", connector);
if (connector.Enabled)
{ {
if (!connector.Connected)
// m_log.InfoFormat("[IRC-Watchdog] Scanning {0}", connector);
if (connector.Enabled)
{ {
try if (!connector.Connected)
{
// m_log.DebugFormat("[IRC-Watchdog] Connecting {1}:{2}", connector.idn, connector.m_server, connector.m_ircChannel);
connector.Connect();
}
catch (Exception e)
{
m_log.ErrorFormat("[IRC-Watchdog] Exception on connector {0}: {1} ", connector.idn, e.Message);
}
}
else
{
if (connector.m_pending)
{
if (connector.m_timeout == 0)
{
m_log.ErrorFormat("[IRC-Watchdog] Login timed-out for connector {0}, reconnecting", connector.idn);
connector.Reconnect();
}
else
connector.m_timeout--;
}
// Being marked connected is not enough to ping. Socket establishment can sometimes take a long
// time, in which case the watch dog might try to ping the server before the socket has been
// set up, with nasty side-effects.
else if (_pdk_ == 0)
{ {
try try
{ {
connector.m_writer.WriteLine(String.Format("PING :{0}", connector.m_server)); // m_log.DebugFormat("[IRC-Watchdog] Connecting {1}:{2}", connector.idn, connector.m_server, connector.m_ircChannel);
connector.m_writer.Flush(); connector.Connect();
} }
catch (Exception e) catch (Exception e)
{ {
m_log.ErrorFormat("[IRC-PingRun] Exception on connector {0}: {1} ", connector.idn, e.Message); m_log.ErrorFormat("[IRC-Watchdog] Exception on connector {0}: {1} ", connector.idn, e.Message);
m_log.Debug(e);
connector.Reconnect();
} }
} }
else
{
if (connector.m_pending)
{
if (connector.m_timeout == 0)
{
m_log.ErrorFormat("[IRC-Watchdog] Login timed-out for connector {0}, reconnecting", connector.idn);
connector.Reconnect();
}
else
connector.m_timeout--;
}
// Being marked connected is not enough to ping. Socket establishment can sometimes take a long
// time, in which case the watch dog might try to ping the server before the socket has been
// set up, with nasty side-effects.
else if (_pdk_ == 0)
{
try
{
connector.m_writer.WriteLine(String.Format("PING :{0}", connector.m_server));
connector.m_writer.Flush();
}
catch (Exception e)
{
m_log.ErrorFormat("[IRC-PingRun] Exception on connector {0}: {1} ", connector.idn, e.Message);
m_log.Debug(e);
connector.Reconnect();
}
}
}
} }
} }
}
// m_log.InfoFormat("[IRC-Watchdog] Status scan completed"); // m_log.InfoFormat("[IRC-Watchdog] Status scan completed");

View File

@ -41,49 +41,71 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
internal class RegionState internal class RegionState
{ {
private static readonly ILog m_log = private static readonly ILog m_log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static readonly OpenMetaverse.Vector3 CenterOfRegion = new OpenMetaverse.Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 20); private static readonly OpenMetaverse.Vector3 CenterOfRegion = new OpenMetaverse.Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 20);
private const int DEBUG_CHANNEL = 2147483647; private const int DEBUG_CHANNEL = 2147483647;
private static int _idk_ = 0; private static int _idk_ = 0;
// Runtime variables; these values are assigned when the // Runtime variables; these values are assigned when the
// IrcState is created and remain constant thereafter. // IrcState is created and remain constant thereafter.
internal string Region = String.Empty; internal string Region = String.Empty;
internal string Host = String.Empty; internal string Host = String.Empty;
internal string LocX = String.Empty; internal string LocX = String.Empty;
internal string LocY = String.Empty; internal string LocY = String.Empty;
internal string IDK = String.Empty; internal string IDK = String.Empty;
// System values - used only be the IRC classes themselves // System values - used only be the IRC classes themselves
internal ChannelState cs = null; // associated IRC configuration internal ChannelState cs = null; // associated IRC configuration
internal Scene scene = null; // associated scene internal Scene scene = null; // associated scene
internal IConfig config = null; // configuration file reference internal IConfig config = null; // configuration file reference
internal bool enabled = true; internal bool enabled = true;
//AgentAlert
internal bool showAlert = false;
internal string alertMessage = String.Empty;
internal IDialogModule dialogModule = null;
// This list is used to keep track of who is here, and by // This list is used to keep track of who is here, and by
// implication, who is not. // implication, who is not.
internal List<IClientAPI> clients = new List<IClientAPI>(); internal List<IClientAPI> clients = new List<IClientAPI>();
// Setup runtime variable values // Setup runtime variable values
public RegionState(Scene p_scene, IConfig p_config) public RegionState(Scene p_scene, IConfig p_config)
{ {
scene = p_scene;
scene = p_scene;
config = p_config; config = p_config;
Region = scene.RegionInfo.RegionName; Region = scene.RegionInfo.RegionName;
Host = scene.RegionInfo.ExternalHostName; Host = scene.RegionInfo.ExternalHostName;
LocX = Convert.ToString(scene.RegionInfo.RegionLocX); LocX = Convert.ToString(scene.RegionInfo.RegionLocX);
LocY = Convert.ToString(scene.RegionInfo.RegionLocY); LocY = Convert.ToString(scene.RegionInfo.RegionLocY);
IDK = Convert.ToString(_idk_++); IDK = Convert.ToString(_idk_++);
showAlert = config.GetBoolean("alert_show", false);
string alertServerInfo = String.Empty;
if (showAlert)
{
bool showAlertServerInfo = config.GetBoolean("alert_show_serverinfo", true);
if (showAlertServerInfo)
alertServerInfo = String.Format("\nServer: {0}\nPort: {1}\nChannel: {2}\n\n",
config.GetString("server", ""), config.GetString("port", ""), config.GetString("channel", ""));
string alertPreMessage = config.GetString("alert_msg_pre", "This region is linked to Irc.");
string alertPostMessage = config.GetString("alert_msg_post", "Everything you say in public chat can be listened.");
alertMessage = String.Format("{0}\n{1}{2}", alertPreMessage, alertServerInfo, alertPostMessage);
dialogModule = scene.RequestModuleInterface<IDialogModule>();
}
// OpenChannel conditionally establishes a connection to the // OpenChannel conditionally establishes a connection to the
// IRC server. The request will either succeed, or it will // IRC server. The request will either succeed, or it will
@ -93,9 +115,9 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
// Connect channel to world events // Connect channel to world events
scene.EventManager.OnChatFromWorld += OnSimChat; scene.EventManager.OnChatFromWorld += OnSimChat;
scene.EventManager.OnChatFromClient += OnSimChat; scene.EventManager.OnChatFromClient += OnSimChat;
scene.EventManager.OnMakeRootAgent += OnMakeRootAgent; scene.EventManager.OnMakeRootAgent += OnMakeRootAgent;
scene.EventManager.OnMakeChildAgent += OnMakeChildAgent; scene.EventManager.OnMakeChildAgent += OnMakeChildAgent;
m_log.InfoFormat("[IRC-Region {0}] Initialization complete", Region); m_log.InfoFormat("[IRC-Region {0}] Initialization complete", Region);
@ -106,8 +128,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
~RegionState() ~RegionState()
{ {
if (cs != null) if (cs != null)
cs.RemoveRegion(this); cs.RemoveRegion(this);
} }
// Called by PostInitialize after all regions have been created // Called by PostInitialize after all regions have been created
@ -147,7 +169,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
cs.irc.PrivMsg(cs.NoticeMessageFormat, cs.irc.Nick, Region, String.Format("{0} has left", client.Name)); cs.irc.PrivMsg(cs.NoticeMessageFormat, cs.irc.Nick, Region, String.Format("{0} has left", client.Name));
} }
} }
client.OnLogout -= OnClientLoggedOut; client.OnLogout -= OnClientLoggedOut;
client.OnConnectionClosed -= OnClientLoggedOut; client.OnConnectionClosed -= OnClientLoggedOut;
clients.Remove(client); clients.Remove(client);
} }
@ -177,7 +199,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
m_log.DebugFormat("[IRC-Region {0}] {1} has left", Region, clientName); m_log.DebugFormat("[IRC-Region {0}] {1} has left", Region, clientName);
cs.irc.PrivMsg(cs.NoticeMessageFormat, cs.irc.Nick, Region, String.Format("{0} has left", clientName)); cs.irc.PrivMsg(cs.NoticeMessageFormat, cs.irc.Nick, Region, String.Format("{0} has left", clientName));
} }
client.OnLogout -= OnClientLoggedOut; client.OnLogout -= OnClientLoggedOut;
client.OnConnectionClosed -= OnClientLoggedOut; client.OnConnectionClosed -= OnClientLoggedOut;
clients.Remove(client); clients.Remove(client);
} }
@ -195,14 +217,13 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
private void OnMakeRootAgent(ScenePresence presence) private void OnMakeRootAgent(ScenePresence presence)
{ {
IClientAPI client = presence.ControllingClient; IClientAPI client = presence.ControllingClient;
try try
{ {
if (!clients.Contains(client)) if (!clients.Contains(client))
{ {
client.OnLogout += OnClientLoggedOut; client.OnLogout += OnClientLoggedOut;
client.OnConnectionClosed += OnClientLoggedOut; client.OnConnectionClosed += OnClientLoggedOut;
clients.Add(client); clients.Add(client);
if (enabled && (cs.irc.Enabled) && (cs.irc.Connected) && (cs.ClientReporting)) if (enabled && (cs.irc.Enabled) && (cs.irc.Connected) && (cs.ClientReporting))
@ -216,17 +237,18 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
} }
} }
} }
if (dialogModule != null && showAlert)
dialogModule.SendAlertToUser(client, alertMessage, true);
} }
catch (Exception ex) catch (Exception ex)
{ {
m_log.ErrorFormat("[IRC-Region {0}]: MakeRootAgent exception: {1}", Region, ex.Message); m_log.ErrorFormat("[IRC-Region {0}]: MakeRootAgent exception: {1}", Region, ex.Message);
m_log.Debug(ex); m_log.Debug(ex);
} }
} }
// This handler detects chat events int he virtual world. // This handler detects chat events int he virtual world.
public void OnSimChat(Object sender, OSChatMessage msg) public void OnSimChat(Object sender, OSChatMessage msg)
{ {

View File

@ -1109,6 +1109,17 @@
;exclude_list=User 1,User 2,User 3 ;exclude_list=User 1,User 2,User 3
;;Shows modal alertbox for entering agent on IRC enabled regions
;;
;; Enable Alert, default = false
;alert_show = false
;;
;; Show IRC serverinfo, default = true
;alert_show_serverinfo = true
;;
;alert_msg_pre = "This region is linked to Irc."
;alert_msg_post = "Everything you say in public chat can be listened."
; The following settings control the progression of daytime ; The following settings control the progression of daytime
; in the Sim. The defaults are the same as the commented out settings ; in the Sim. The defaults are the same as the commented out settings