From 8e424a41623cb20fc22572ef19da65fd5b80e7fc Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Mon, 22 Oct 2007 16:35:39 +0000 Subject: make for nicer IRC messages. No promiss that this works yet, but it is a first attempt. Will tune shortly. --- OpenSim/Region/Environment/Modules/ChatModule.cs | 29 ++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'OpenSim/Region/Environment/Modules/ChatModule.cs') diff --git a/OpenSim/Region/Environment/Modules/ChatModule.cs b/OpenSim/Region/Environment/Modules/ChatModule.cs index 54f32f6..5a31e0b 100644 --- a/OpenSim/Region/Environment/Modules/ChatModule.cs +++ b/OpenSim/Region/Environment/Modules/ChatModule.cs @@ -31,6 +31,7 @@ using System.IO; using System.Net.Sockets; using System.Threading; using System.Collections.Generic; +using System.Text.RegularExpressions; using libsecondlife; using OpenSim.Framework.Interfaces; using OpenSim.Framework.Utilities; @@ -319,6 +320,23 @@ namespace OpenSim.Region.Environment.Modules } } + private Dictionary ExtractMsg(string input) { + Dictionary result = null; + string regex = @":(?\w*)!~(?\S*) PRIVMSG (?\S+) :(?.*)"; + Regex RE = new Regex(regex, RegexOptions.Multiline); + MatchCollection matches = RE.Matches(input); + // Get some direct matches $1 $4 is a + if (matches.Count == 4) { + result = new Dictionary(); + result.Add("nick", matches[0].Value); + result.Add("user", matches[1].Value); + result.Add("channel", matches[2].Value); + result.Add("msg", matches[3].Value); + } else { + m_log.Verbose("IRC", "Number of matches: " + matches.Count); + } + return result; + } public void PingRun() { @@ -341,18 +359,21 @@ namespace OpenSim.Region.Environment.Modules Console.WriteLine(inputLine); if (inputLine.Contains(m_channel)) { - string mess = inputLine.Substring(inputLine.IndexOf(m_channel)); - foreach (Scene m_scene in m_scenes) + Dictionary data = ExtractMsg(inputLine); + if (data != null ) { - m_scene.ForEachScenePresence(delegate(ScenePresence avatar) + foreach (Scene m_scene in m_scenes) + { + m_scene.ForEachScenePresence(delegate(ScenePresence avatar) { if (!avatar.IsChildAgent) { avatar.ControllingClient.SendChatMessage( - Helpers.StringToField(inputLine), 255, pos, "IRC:", + Helpers.StringToField(data["msg"]), 255, pos, data["nick"], LLUUID.Zero); } }); + } } } } -- cgit v1.1