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
@ -324,10 +350,24 @@ namespace OpenSim.Region.Environment.Modules
{
while (true)
{
m_writer.WriteLine("PING :" + m_server);
m_writer.Flush();
Thread.Sleep(15000);
}
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()
@ -336,36 +376,53 @@ namespace OpenSim.Region.Environment.Modules
LLVector3 pos = new LLVector3(128, 128, 20);
while (true)
{
while ((inputLine = m_reader.ReadLine()) != null)
try
{
// Console.WriteLine(inputLine);
if (inputLine.Contains(m_channel))
while ((inputLine = m_reader.ReadLine()) != null)
{
Dictionary<string, string> data = ExtractMsg(inputLine);
if (data != null)
// Console.WriteLine(inputLine);
if (inputLine.Contains(m_channel))
{
foreach (Scene m_scene in m_scenes)
Dictionary<string, string> data = ExtractMsg(inputLine);
if (data != null)
{
m_scene.ForEachScenePresence(delegate(ScenePresence avatar)
{
if (!avatar.IsChildAgent)
foreach (Scene m_scene in m_scenes)
{
m_scene.ForEachScenePresence(delegate(ScenePresence avatar)
{
avatar.ControllingClient.SendChatMessage(
Helpers.StringToField(data["msg"]), 255,
pos, data["nick"],
LLUUID.Zero);
}
});
if (!avatar.IsChildAgent)
{
avatar.ControllingClient.SendChatMessage(
Helpers.StringToField(data["msg"]), 255,
pos, data["nick"],
LLUUID.Zero);
}
});
}
}
}
}
Thread.Sleep(50);
}
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();
@ -373,4 +430,4 @@ namespace OpenSim.Region.Environment.Modules
m_tcp.Close();
}
}
}
}