aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs280
1 files changed, 280 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs
new file mode 100644
index 0000000..e413290
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs
@@ -0,0 +1,280 @@
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
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Reflection;
32using log4net;
33using Nini.Config;
34using Nwc.XmlRpc;
35using OpenSim.Framework;
36using OpenSim.Region.Environment.Interfaces;
37using OpenSim.Region.Environment.Scenes;
38
39namespace OpenSim.Region.Environment.Modules.Avatar.Chat
40{
41
42 public class IRCBridgeModule : IRegionModule
43 {
44
45 private static readonly ILog m_log =
46 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47
48 internal static bool configured = false;
49 internal static bool enabled = false;
50 internal static IConfig m_config = null;
51
52 internal static List<RegionState> m_regions = new List<RegionState>();
53 internal static List<ChannelState> m_channels = new List<ChannelState>();
54
55 internal static string password = String.Empty;
56
57 #region IRegionModule Members
58
59 public string Name
60 {
61 get { return "IRCBridgeModule"; }
62 }
63
64 public bool IsSharedModule
65 {
66 get { return true; }
67 }
68
69 public void Initialise(Scene scene, IConfigSource config)
70 {
71
72 // Do a once-only scan of the configuration file to make
73 // sure it's basically intact.
74
75 if (!configured)
76 {
77
78 configured = true;
79
80 try
81 {
82 if ((m_config = config.Configs["IRC"]) == null)
83 {
84 m_log.InfoFormat("[IRC-Bridge] module not configured");
85 return;
86 }
87
88 if (!m_config.GetBoolean("enabled", false))
89 {
90 m_log.InfoFormat("[IRC-Bridge] module disabled in configuration");
91 return;
92 }
93 }
94 catch (Exception e)
95 {
96 m_log.ErrorFormat("[IRC-Bridge] configuration failed : {0}", e.Message);
97 return;
98 }
99
100 enabled = true;
101
102 if (config.Configs["RemoteAdmin"] != null)
103 {
104 password = config.Configs["RemoteAdmin"].GetString("access_password", password);
105 scene.CommsManager.HttpServer.AddXmlRPCHandler("irc_admin", XmlRpcAdminMethod, false);
106 }
107
108 }
109
110 // Iff the IRC bridge is enabled, then each new region may be
111 // connected to IRC. But it should NOT be obligatory (and it
112 // is not).
113
114 if (enabled)
115 {
116 try
117 {
118 m_log.InfoFormat("[IRC-Bridge] Connecting region {0}", scene.RegionInfo.RegionName);
119 m_regions.Add(new RegionState(scene, m_config));
120 }
121 catch (Exception e)
122 {
123 m_log.WarnFormat("[IRC-Bridge] Region {0} not connected to IRC : {1}", scene.RegionInfo.RegionName, e.Message);
124 m_log.Debug(e);
125 }
126 }
127 else
128 {
129 m_log.WarnFormat("[IRC-Bridge] Not enabled. Connect for region {0} ignored", scene.RegionInfo.RegionName);
130 }
131
132 }
133
134 // Called after all region modules have been loaded.
135 // Iff the IRC bridge is enabled, then start all of the
136 // configured channels. The set of channels is a side
137 // effect of RegionState creation.
138
139 public void PostInitialise()
140 {
141
142 if (!enabled)
143 return;
144
145 foreach (RegionState region in m_regions)
146 {
147 m_log.InfoFormat("[IRC-Bridge] Opening connection for {0}:{1} on IRC server {2}:{3}",
148 region.Region, region.cs.BaseNickname, region.cs.Server, region.cs.IrcChannel);
149 try
150 {
151 region.Open();
152 }
153 catch (Exception e)
154 {
155 m_log.ErrorFormat("[IRC-Bridge] Open failed for {0}:{1} on IRC server {2}:{3} : {4}",
156 region.Region, region.cs.BaseNickname, region.cs.Server, region.cs.IrcChannel,
157 e.Message);
158 }
159 }
160
161 }
162
163 // Called immediately before the region module is unloaded. Close all
164 // associated channels.
165
166 public void Close()
167 {
168
169 if (!enabled)
170 return;
171
172 // Stop each of the region sessions
173
174 foreach (RegionState region in m_regions)
175 {
176 m_log.InfoFormat("[IRC-Bridge] Closing connection for {0}:{1} on IRC server {2}:{3}",
177 region.Region, region.cs.BaseNickname, region.cs.Server, region.cs.IrcChannel);
178 try
179 {
180 region.Close();
181 }
182 catch (Exception e)
183 {
184 m_log.ErrorFormat("[IRC-Bridge] Close failed for {0}:{1} on IRC server {2}:{3} : {4}",
185 region.Region, region.cs.BaseNickname, region.cs.Server, region.cs.IrcChannel,
186 e.Message);
187 }
188 }
189
190 // Perform final cleanup of the channels (they now have no active clients)
191
192 foreach (ChannelState channel in m_channels)
193 {
194 m_log.InfoFormat("[IRC-Bridge] Closing connection for {0} on IRC server {1}:{2}",
195 channel.BaseNickname, channel.Server, channel.IrcChannel);
196 try
197 {
198 channel.Close();
199 }
200 catch (Exception e)
201 {
202 m_log.ErrorFormat("[IRC-Bridge] Close failed for {0} on IRC server {1}:{2} : {3}",
203 channel.BaseNickname, channel.Server, channel.IrcChannel,
204 e.Message);
205 }
206 }
207
208 }
209
210 #endregion
211
212 public XmlRpcResponse XmlRpcAdminMethod(XmlRpcRequest request)
213 {
214
215 m_log.Info("[IRC-Bridge]: XML RPC Admin Entry");
216
217 XmlRpcResponse response = new XmlRpcResponse();
218 Hashtable responseData = new Hashtable();
219
220 try
221 {
222
223 Hashtable requestData = (Hashtable)request.Params[0];
224 bool found = false;
225 string region = String.Empty;
226
227 if (password != String.Empty)
228 {
229 if (!requestData.ContainsKey("password"))
230 throw new Exception("Invalid request");
231 if ((string)requestData["password"] != password)
232 throw new Exception("Invalid request");
233 }
234
235 if (!requestData.ContainsKey("region"))
236 throw new Exception("No region name specified");
237
238 foreach (RegionState rs in m_regions)
239 {
240 if (rs.Region == region)
241 {
242 responseData["server"] = rs.cs.Server;
243 responseData["port"] = rs.cs.Port;
244 responseData["user"] = rs.cs.User;
245 responseData["channel"] = rs.cs.IrcChannel;
246 responseData["enabled"] = rs.cs.irc.Enabled;
247 responseData["connected"] = rs.cs.irc.Connected;
248 responseData["nickname"] = rs.cs.irc.Nick;
249 found = true;
250 break;
251 }
252 }
253
254 if (!found) throw new Exception(String.Format("Region <{0}> not found", region));
255
256 responseData["success"] = true;
257
258 }
259 catch (Exception e)
260 {
261 m_log.InfoFormat("[IRC-Bridge] XML RPC Admin request failed : {0}", e.Message);
262
263 responseData["success"] = "false";
264 responseData["error"] = e.Message;
265
266 }
267 finally
268 {
269 response.Value = responseData;
270 }
271
272 m_log.Debug("[IRC-Bridge]: XML RPC Admin Exit");
273
274 return response;
275
276 }
277
278 }
279
280}