Thanks kinoc for your improved IRC Gateway patch as referenced in mantis issue 390.

ThreadPoolClientBranch
Teravus Ovares 2008-01-29 04:35:01 +00:00
parent 47761a4a5e
commit da0fa4253b
2 changed files with 81 additions and 23 deletions

View File

@ -32,6 +32,7 @@ Patches
* BigFootAg
* CharlieO
* jhurliman (LLSD Login)
* kinoc
LSL Devs

View File

@ -163,6 +163,12 @@ namespace OpenSim.Region.Environment.Modules
fromAgentID = e.Sender.AgentId;
}
// Try to reconnect to server if not connected
if ((m_irc.Enabled)&&(!m_irc.Connected))
{
m_irc.Connect(m_scenes);
}
if (e.Message.Length > 0)
{
if (m_irc.Connected && (avatar != null)) // this is to keep objects from talking to IRC
@ -205,6 +211,7 @@ namespace OpenSim.Region.Environment.Modules
private bool m_connected = false;
private List<Scene> m_scenes = null;
private List<Scene> m_last_scenes = null;
private LogBase m_log;
public IRCChatModule(IConfigSource config)
@ -214,6 +221,19 @@ namespace OpenSim.Region.Environment.Modules
m_writer = null;
m_reader = null;
// configuration in OpenSim.ini
// [IRC]
// server = chat.freenode.net
// nick = OSimBot_mysim
// ;username = OSimBot_mysim
// channel = #opensim-regions
// port = 6667
//
// Traps I/O disconnects so it does not crash the sim
// Trys to reconnect if disconnected and someone says something
// Tells IRC server "QUIT" when doing a close (just to be nice)
// Default port back to 6667
try
{
m_server = config.Configs["IRC"].GetString("server");
@ -238,7 +258,7 @@ namespace OpenSim.Region.Environment.Modules
try
{
m_scenes = scenes;
m_last_scenes = scenes;
m_tcp = new TcpClient(m_server, (int) m_port);
m_log.Verbose("IRC", "Connecting...");
m_stream = m_tcp.GetStream();
@ -290,14 +310,20 @@ namespace OpenSim.Region.Environment.Modules
m_log.Error("IRC", "Disconnected from IRC server.");
listener.Abort();
pingSender.Abort();
m_writer.Close();
m_reader.Close();
m_tcp.Close();
m_connected = false;
if (m_enabled) { Connect(m_last_scenes); }
}
}
private Dictionary<string, string> ExtractMsg(string input)
{
m_log.Verbose("IRC", "ExtractMsg: " + input);
Dictionary<string, string> result = null;
string regex = @":(?<nick>\w*)!~(?<user>\S*) PRIVMSG (?<channel>\S+) :(?<msg>.*)";
//string regex = @":(?<nick>\w*)!~(?<user>\S*) PRIVMSG (?<channel>\S+) :(?<msg>.*)";
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
@ -323,11 +349,25 @@ namespace OpenSim.Region.Environment.Modules
public void PingRun()
{
while (true)
{
try
{
m_writer.WriteLine("PING :" + m_server);
m_writer.Flush();
Thread.Sleep(15000);
}
catch (IOException)
{
m_log.Error("IRC", "Disconnected from IRC server.");
listener.Abort();
pingSender.Abort();
m_writer.Close();
m_reader.Close();
m_tcp.Close();
m_connected = false;
if (m_enabled) { Connect(m_last_scenes); }
}
}
}
public void ListenerRun()
@ -335,6 +375,8 @@ namespace OpenSim.Region.Environment.Modules
string inputLine;
LLVector3 pos = new LLVector3(128, 128, 20);
while (true)
{
try
{
while ((inputLine = m_reader.ReadLine()) != null)
{
@ -362,10 +404,25 @@ namespace OpenSim.Region.Environment.Modules
}
Thread.Sleep(50);
}
catch (IOException)
{
m_log.Error("IRC", "Disconnected from IRC server.");
listener.Abort();
pingSender.Abort();
m_writer.Close();
m_reader.Close();
m_tcp.Close();
m_connected = false;
if (m_enabled) { Connect(m_last_scenes); }
}
}
}
public void Close()
{
m_writer.WriteLine("QUIT :" + m_nick+" to "+m_channel+" wormhole with "+m_server+" closing");
m_writer.Flush();
listener.Abort();
pingSender.Abort();
m_writer.Close();