diff options
author | Dr Scofield | 2008-11-03 17:11:28 +0000 |
---|---|---|
committer | Dr Scofield | 2008-11-03 17:11:28 +0000 |
commit | 69ae33db1ad6a5111211d6ccc6c3b2ac2467f4d0 (patch) | |
tree | 1e14a6c9a6fae960cab80632d93708b19fa5503e /OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs | |
parent | * Use the UUID regex sitting in utils for detection of uuids embedded in scripts (diff) | |
download | opensim-SC-69ae33db1ad6a5111211d6ccc6c3b2ac2467f4d0.zip opensim-SC-69ae33db1ad6a5111211d6ccc6c3b2ac2467f4d0.tar.gz opensim-SC-69ae33db1ad6a5111211d6ccc6c3b2ac2467f4d0.tar.bz2 opensim-SC-69ae33db1ad6a5111211d6ccc6c3b2ac2467f4d0.tar.xz |
dropping old IRCBridgeModule.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs | 393 |
1 files changed, 0 insertions, 393 deletions
diff --git a/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs deleted file mode 100644 index 482f469..0000000 --- a/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs +++ /dev/null | |||
@@ -1,393 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Net.Sockets; | ||
32 | using System.Reflection; | ||
33 | using System.Text.RegularExpressions; | ||
34 | using System.Threading; | ||
35 | using OpenMetaverse; | ||
36 | using log4net; | ||
37 | using Nini.Config; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Region.Environment.Interfaces; | ||
40 | using OpenSim.Region.Environment.Scenes; | ||
41 | |||
42 | namespace OpenSim.Region.Environment.Modules.Avatar.Chat | ||
43 | { | ||
44 | public class IRCBridgeModule : IRegionModule | ||
45 | { | ||
46 | private static readonly ILog m_log = | ||
47 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | private const int DEBUG_CHANNEL = 2147483647; | ||
50 | |||
51 | |||
52 | private IRCConnector m_irc = null; | ||
53 | |||
54 | private string m_last_leaving_user = null; | ||
55 | private string m_last_new_user = null; | ||
56 | private List<Scene> m_scenes = new List<Scene>(); | ||
57 | private List<int> m_validInWorldChannels = new List<int>(); | ||
58 | |||
59 | internal object m_syncInit = new object(); | ||
60 | internal object m_syncLogout = new object(); | ||
61 | |||
62 | private IConfig m_config; | ||
63 | private string m_defaultzone = null; | ||
64 | private bool m_commandsEnabled = false; | ||
65 | private int m_commandChannel = -1; | ||
66 | private bool m_relayPrivateChannels = false; | ||
67 | private int m_relayChannelOut = -1; | ||
68 | private bool m_clientReporting = true; | ||
69 | private bool m_relayChat = true; | ||
70 | private Regex m_accessPasswordRe = null; | ||
71 | |||
72 | #region IRegionModule Members | ||
73 | |||
74 | public void Initialise(Scene scene, IConfigSource config) | ||
75 | { | ||
76 | try | ||
77 | { | ||
78 | if ((m_config = config.Configs["OIRC"]) == null) | ||
79 | { | ||
80 | m_log.InfoFormat("[IRC] module not configured"); | ||
81 | return; | ||
82 | } | ||
83 | |||
84 | if (!m_config.GetBoolean("enabled", false)) | ||
85 | { | ||
86 | m_log.InfoFormat("[IRC] module disabled in configuration"); | ||
87 | return; | ||
88 | } | ||
89 | } | ||
90 | catch (Exception) | ||
91 | { | ||
92 | m_log.Info("[IRC] module not configured"); | ||
93 | return; | ||
94 | } | ||
95 | |||
96 | m_commandsEnabled = m_config.GetBoolean("commands_enabled", m_commandsEnabled); | ||
97 | m_commandChannel = m_config.GetInt("commandchannel", m_commandChannel); // compat | ||
98 | m_commandChannel = m_config.GetInt("command_channel", m_commandChannel); | ||
99 | |||
100 | m_relayPrivateChannels = m_config.GetBoolean("relay_private_channels", m_relayPrivateChannels); | ||
101 | m_relayChannelOut = m_config.GetInt("relay_private_channel_out", m_relayChannelOut); | ||
102 | m_relayChat = m_config.GetBoolean("relay_chat", m_relayChat); | ||
103 | |||
104 | m_clientReporting = m_config.GetBoolean("report_clients", m_clientReporting); | ||
105 | |||
106 | if (m_accessPasswordRe == null) | ||
107 | { | ||
108 | string pass = config.Configs["IRC"].GetString("access_password", String.Empty); | ||
109 | m_accessPasswordRe = new Regex(String.Format(@"^{0},(?<avatar>[^,]+),(?<message>.+)$", pass), | ||
110 | RegexOptions.Compiled); | ||
111 | } | ||
112 | |||
113 | if (m_relayChat) | ||
114 | { | ||
115 | m_validInWorldChannels.Add(0); | ||
116 | m_validInWorldChannels.Add(DEBUG_CHANNEL); | ||
117 | } | ||
118 | |||
119 | if (m_relayPrivateChannels) | ||
120 | m_validInWorldChannels.Add(m_relayChannelOut); | ||
121 | |||
122 | |||
123 | lock (m_syncInit) | ||
124 | { | ||
125 | |||
126 | if (!m_scenes.Contains(scene)) | ||
127 | { | ||
128 | m_scenes.Add(scene); | ||
129 | scene.EventManager.OnNewClient += OnNewClient; | ||
130 | scene.EventManager.OnChatFromWorld += OnSimChat; | ||
131 | scene.EventManager.OnChatFromClient += OnSimChat; | ||
132 | scene.EventManager.OnMakeRootAgent += OnMakeRootAgent; | ||
133 | scene.EventManager.OnMakeChildAgent += OnMakeChildAgent; | ||
134 | } | ||
135 | |||
136 | try | ||
137 | { | ||
138 | m_defaultzone = config.Configs["IRC"].GetString("fallback_region", "Sim"); | ||
139 | } | ||
140 | catch (Exception) | ||
141 | { | ||
142 | } | ||
143 | |||
144 | // setup IRC Relay | ||
145 | if (m_irc == null) | ||
146 | { | ||
147 | m_irc = new IRCConnector(config); | ||
148 | } | ||
149 | m_irc.AddScene(scene); | ||
150 | |||
151 | m_log.InfoFormat("[IRC] initialized for {0}, nick: {1}, commands {2}, private channels {3}", | ||
152 | scene.RegionInfo.RegionName, m_defaultzone, | ||
153 | m_commandsEnabled ? "enabled" : "not enabled", | ||
154 | m_relayPrivateChannels ? "relayed" : "not relayed"); | ||
155 | } | ||
156 | } | ||
157 | |||
158 | public void PostInitialise() | ||
159 | { | ||
160 | if (null == m_irc || !m_irc.Enabled) return; | ||
161 | m_irc.Start(); | ||
162 | } | ||
163 | |||
164 | public void Close() | ||
165 | { | ||
166 | if (null != m_irc) | ||
167 | { | ||
168 | m_irc.Close(); | ||
169 | m_log.Info("[IRC] closed connection to IRC server"); | ||
170 | } | ||
171 | } | ||
172 | |||
173 | public string Name | ||
174 | { | ||
175 | get { return "IRCBridgeModule"; } | ||
176 | } | ||
177 | |||
178 | public bool IsSharedModule | ||
179 | { | ||
180 | get { return true; } | ||
181 | } | ||
182 | |||
183 | #endregion | ||
184 | |||
185 | #region ISimChat Members | ||
186 | |||
187 | public void OnSimChat(Object sender, OSChatMessage c) | ||
188 | { | ||
189 | // early return if nothing to forward | ||
190 | if (c.Message.Length == 0) return; | ||
191 | |||
192 | // early return if this comes from the IRC forwarder | ||
193 | if (m_irc.Equals(sender)) return; | ||
194 | |||
195 | m_log.DebugFormat("[IRC] heard on channel {0}: {1}", c.Channel, c.Message); | ||
196 | |||
197 | // check for commands coming from avatars or in-world | ||
198 | // object (if commands are enabled) | ||
199 | if (m_commandsEnabled && c.Channel == m_commandChannel) | ||
200 | { | ||
201 | string[] messages = c.Message.Split(' '); | ||
202 | string command = messages[0].ToLower(); | ||
203 | |||
204 | try | ||
205 | { | ||
206 | switch (command) | ||
207 | { | ||
208 | case "channel": | ||
209 | m_irc.IrcChannel = messages[1]; | ||
210 | break; | ||
211 | case "close": | ||
212 | m_irc.Close(); | ||
213 | break; | ||
214 | case "connect": | ||
215 | m_irc.Connect(); | ||
216 | break; | ||
217 | case "nick": | ||
218 | m_irc.Nick = messages[1]; | ||
219 | break; | ||
220 | case "port": | ||
221 | m_irc.Port = Convert.ToUInt32(messages[1]); | ||
222 | break; | ||
223 | case "reconnect": | ||
224 | m_irc.Reconnect(); | ||
225 | break; | ||
226 | case "server": | ||
227 | m_irc.Server = messages[1]; | ||
228 | break; | ||
229 | case "client-reporting": | ||
230 | m_irc.ClientReporting = Convert.ToBoolean(messages[1]); | ||
231 | |||
232 | break; | ||
233 | case "in-channel": | ||
234 | m_irc.RelayChannel = Convert.ToInt32(messages[1]); | ||
235 | break; | ||
236 | case "out-channel": | ||
237 | m_relayChannelOut = Convert.ToInt32(messages[1]); | ||
238 | break; | ||
239 | |||
240 | default: | ||
241 | m_irc.Send(c.Message); | ||
242 | break; | ||
243 | } | ||
244 | } | ||
245 | catch (Exception ex) | ||
246 | { | ||
247 | m_log.DebugFormat("[IRC] error processing in-world command channel input: {0}", ex); | ||
248 | } | ||
249 | } | ||
250 | |||
251 | // drop messages if their channel is not on the valid | ||
252 | // in-world channel list | ||
253 | if (!m_validInWorldChannels.Contains(c.Channel)) | ||
254 | { | ||
255 | m_log.DebugFormat("[IRC] dropping message {0} on channel {1}", c, c.Channel); | ||
256 | return; | ||
257 | } | ||
258 | |||
259 | ScenePresence avatar = null; | ||
260 | Scene scene = (Scene)c.Scene; | ||
261 | |||
262 | if (scene == null) | ||
263 | scene = m_scenes[0]; | ||
264 | |||
265 | string fromName = c.From; | ||
266 | |||
267 | if (c.Sender != null) | ||
268 | { | ||
269 | avatar = scene.GetScenePresence(c.Sender.AgentId); | ||
270 | if (avatar != null) fromName = avatar.Name; | ||
271 | } | ||
272 | |||
273 | if (!m_irc.Connected) | ||
274 | { | ||
275 | m_log.WarnFormat("[IRC] IRCConnector not connected: dropping message from {0}", fromName); | ||
276 | return; | ||
277 | } | ||
278 | |||
279 | if (null != avatar && m_relayChat) | ||
280 | { | ||
281 | string msg = c.Message; | ||
282 | if (msg.StartsWith("/me ")) | ||
283 | msg = String.Format("{0} {1}", fromName, c.Message.Substring(4)); | ||
284 | |||
285 | m_irc.PrivMsg(fromName, scene.RegionInfo.RegionName, msg); | ||
286 | return; | ||
287 | } | ||
288 | |||
289 | if (null == avatar && m_relayPrivateChannels) | ||
290 | { | ||
291 | Match m; | ||
292 | if (m_accessPasswordRe != null && | ||
293 | (m = m_accessPasswordRe.Match(c.Message)) != null) | ||
294 | { | ||
295 | m_log.DebugFormat("[IRC] relaying message from {0}: {1}", m.Groups["avatar"].ToString(), | ||
296 | m.Groups["message"].ToString()); | ||
297 | m_irc.PrivMsg(m.Groups["avatar"].ToString(), scene.RegionInfo.RegionName, | ||
298 | m.Groups["message"].ToString()); | ||
299 | } | ||
300 | return; | ||
301 | } | ||
302 | } | ||
303 | #endregion | ||
304 | |||
305 | public void OnNewClient(IClientAPI client) | ||
306 | { | ||
307 | try | ||
308 | { | ||
309 | client.OnLogout += OnClientLoggedOut; | ||
310 | client.OnConnectionClosed += OnClientLoggedOut; | ||
311 | |||
312 | if (client.Name != m_last_new_user) | ||
313 | { | ||
314 | if ((m_irc.Enabled) && (m_irc.Connected) && (m_clientReporting)) | ||
315 | { | ||
316 | m_log.DebugFormat("[IRC] {0} logging on", client.Name); | ||
317 | m_irc.PrivMsg(m_irc.Nick, "Sim", String.Format("notices {0} logging on", client.Name)); | ||
318 | } | ||
319 | m_last_new_user = client.Name; | ||
320 | } | ||
321 | } | ||
322 | catch (Exception ex) | ||
323 | { | ||
324 | m_log.Error("[IRC]: OnNewClient exception trap:" + ex.ToString()); | ||
325 | } | ||
326 | } | ||
327 | |||
328 | public void OnMakeRootAgent(ScenePresence presence) | ||
329 | { | ||
330 | try | ||
331 | { | ||
332 | if ((m_irc.Enabled) && (m_irc.Connected) && (m_clientReporting)) | ||
333 | { | ||
334 | string regionName = presence.Scene.RegionInfo.RegionName; | ||
335 | string clientName = String.Format("{0} {1}", presence.Firstname, presence.Lastname); | ||
336 | m_log.DebugFormat("[IRC] noticing {0} in {1}", clientName, regionName); | ||
337 | m_irc.PrivMsg(m_irc.Nick, "Sim", String.Format("notices {0} in {1}", clientName, regionName)); | ||
338 | } | ||
339 | } | ||
340 | catch (Exception) | ||
341 | { | ||
342 | } | ||
343 | } | ||
344 | |||
345 | public void OnMakeChildAgent(ScenePresence presence) | ||
346 | { | ||
347 | try | ||
348 | { | ||
349 | if ((m_irc.Enabled) && (m_irc.Connected) && (m_clientReporting)) | ||
350 | { | ||
351 | string regionName = presence.Scene.RegionInfo.RegionName; | ||
352 | string clientName = String.Format("{0} {1}", presence.Firstname, presence.Lastname); | ||
353 | m_log.DebugFormat("[IRC] noticing {0} in {1}", clientName, regionName); | ||
354 | m_irc.PrivMsg(m_irc.Nick, "Sim", String.Format("notices {0} left {1}", clientName, regionName)); | ||
355 | } | ||
356 | } | ||
357 | catch (Exception) | ||
358 | { | ||
359 | } | ||
360 | } | ||
361 | |||
362 | |||
363 | public void OnClientLoggedOut(IClientAPI client) | ||
364 | { | ||
365 | lock (m_syncLogout) | ||
366 | { | ||
367 | try | ||
368 | { | ||
369 | if ((m_irc.Enabled) && (m_irc.Connected) && (m_clientReporting)) | ||
370 | { | ||
371 | // handles simple case. May not work for | ||
372 | // hundred connecting in per second. and | ||
373 | // OnNewClients calle getting interleaved but | ||
374 | // filters out multiple reports | ||
375 | if (client.Name != m_last_leaving_user) | ||
376 | { | ||
377 | m_last_leaving_user = client.Name; | ||
378 | m_irc.PrivMsg(m_irc.Nick, "Sim", String.Format("notices {0} logging out", client.Name)); | ||
379 | m_log.InfoFormat("[IRC]: {0} logging out", client.Name); | ||
380 | } | ||
381 | |||
382 | if (m_last_new_user == client.Name) | ||
383 | m_last_new_user = null; | ||
384 | } | ||
385 | } | ||
386 | catch (Exception ex) | ||
387 | { | ||
388 | m_log.Error("[IRC]: ClientLoggedOut exception trap:" + ex.ToString()); | ||
389 | } | ||
390 | } | ||
391 | } | ||
392 | } | ||
393 | } | ||