opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 eva 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 OpenSimulator 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;
30 using System.Collections.Generic;
31 using System.Net;
32 using System.Reflection;
33 using log4net;
34 using Mono.Addins;
35 using Nini.Config;
36 using Nwc.XmlRpc;
37 using OpenSim.Framework;
38 using OpenSim.Framework.Servers;
39 using OpenSim.Region.Framework.Interfaces;
40 using OpenSim.Region.Framework.Scenes;
41  
42 namespace OpenSim.Region.OptionalModules.Avatar.Chat
43 {
44 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "IRCBridgeModule")]
45 public class IRCBridgeModule : INonSharedRegionModule
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48  
49 internal static bool Enabled = false;
50 internal static IConfig m_config = null;
51  
52 internal static List<ChannelState> m_channels = new List<ChannelState>();
53 internal static List<RegionState> m_regions = new List<RegionState>();
54  
55 internal static string m_password = String.Empty;
56 internal RegionState m_region = null;
57  
58 #region INonSharedRegionModule Members
59  
60 public Type ReplaceableInterface
61 {
62 get { return null; }
63 }
64  
65 public string Name
66 {
67 get { return "IRCBridgeModule"; }
68 }
69  
70 public void Initialise(IConfigSource config)
71 {
72 m_config = config.Configs["IRC"];
73 if (m_config == null)
74 {
75 // m_log.InfoFormat("[IRC-Bridge] module not configured");
76 return;
77 }
78  
79 if (!m_config.GetBoolean("enabled", false))
80 {
81 // m_log.InfoFormat("[IRC-Bridge] module disabled in configuration");
82 return;
83 }
84  
85 if (config.Configs["RemoteAdmin"] != null)
86 {
87 m_password = config.Configs["RemoteAdmin"].GetString("access_password", m_password);
88 }
89  
90 Enabled = true;
91  
92 m_log.InfoFormat("[IRC-Bridge]: Module is enabled");
93 }
94  
95 public void AddRegion(Scene scene)
96 {
97 if (Enabled)
98 {
99 try
100 {
101 m_log.InfoFormat("[IRC-Bridge] Connecting region {0}", scene.RegionInfo.RegionName);
102  
103 if (!String.IsNullOrEmpty(m_password))
104 MainServer.Instance.AddXmlRPCHandler("irc_admin", XmlRpcAdminMethod, false);
105  
106 m_region = new RegionState(scene, m_config);
107 lock (m_regions) m_regions.Add(m_region);
108 m_region.Open();
109 }
110 catch (Exception e)
111 {
112 m_log.WarnFormat("[IRC-Bridge] Region {0} not connected to IRC : {1}", scene.RegionInfo.RegionName, e.Message);
113 m_log.Debug(e);
114 }
115 }
116 else
117 {
118 //m_log.DebugFormat("[IRC-Bridge] Not enabled. Connect for region {0} ignored", scene.RegionInfo.RegionName);
119 }
120 }
121  
122  
123 public void RegionLoaded(Scene scene)
124 {
125 }
126  
127 public void RemoveRegion(Scene scene)
128 {
129 if (!Enabled)
130 return;
131  
132 if (m_region == null)
133 return;
134  
135 if (!String.IsNullOrEmpty(m_password))
136 MainServer.Instance.RemoveXmlRPCHandler("irc_admin");
137  
138 m_region.Close();
139  
140 if (m_regions.Contains(m_region))
141 {
142 lock (m_regions) m_regions.Remove(m_region);
143 }
144 }
145  
146 public void Close()
147 {
148 }
149 #endregion
150  
151 public static XmlRpcResponse XmlRpcAdminMethod(XmlRpcRequest request, IPEndPoint remoteClient)
152 {
153 m_log.Debug("[IRC-Bridge]: XML RPC Admin Entry");
154  
155 XmlRpcResponse response = new XmlRpcResponse();
156 Hashtable responseData = new Hashtable();
157  
158 try
159 {
160 Hashtable requestData = (Hashtable)request.Params[0];
161 bool found = false;
162 string region = String.Empty;
163  
164 if (m_password != String.Empty)
165 {
166 if (!requestData.ContainsKey("password"))
167 throw new Exception("Invalid request");
168 if ((string)requestData["password"] != m_password)
169 throw new Exception("Invalid request");
170 }
171  
172 if (!requestData.ContainsKey("region"))
173 throw new Exception("No region name specified");
174 region = (string)requestData["region"];
175  
176 foreach (RegionState rs in m_regions)
177 {
178 if (rs.Region == region)
179 {
180 responseData["server"] = rs.cs.Server;
181 responseData["port"] = (int)rs.cs.Port;
182 responseData["user"] = rs.cs.User;
183 responseData["channel"] = rs.cs.IrcChannel;
184 responseData["enabled"] = rs.cs.irc.Enabled;
185 responseData["connected"] = rs.cs.irc.Connected;
186 responseData["nickname"] = rs.cs.irc.Nick;
187 found = true;
188 break;
189 }
190 }
191  
192 if (!found) throw new Exception(String.Format("Region <{0}> not found", region));
193  
194 responseData["success"] = true;
195 }
196 catch (Exception e)
197 {
198 m_log.ErrorFormat("[IRC-Bridge] XML RPC Admin request failed : {0}", e.Message);
199  
200 responseData["success"] = "false";
201 responseData["error"] = e.Message;
202 }
203 finally
204 {
205 response.Value = responseData;
206 }
207  
208 m_log.Debug("[IRC-Bridge]: XML RPC Admin Exit");
209  
210 return response;
211 }
212 }
213 }