aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Avatar/Chat/IRCBridgeModule.cs
diff options
context:
space:
mode:
authorDr Scofield2009-05-22 11:37:26 +0000
committerDr Scofield2009-05-22 11:37:26 +0000
commit37726764be2beb71bfd6844482a26b7648b34435 (patch)
treeecb5a691c13eb993606bec53c8e6cb6277d95865 /OpenSim/Region/OptionalModules/Avatar/Chat/IRCBridgeModule.cs
parentadding RemoveXmlRpcHandler to IHttpServer (diff)
downloadopensim-SC_OLD-37726764be2beb71bfd6844482a26b7648b34435.zip
opensim-SC_OLD-37726764be2beb71bfd6844482a26b7648b34435.tar.gz
opensim-SC_OLD-37726764be2beb71bfd6844482a26b7648b34435.tar.bz2
opensim-SC_OLD-37726764be2beb71bfd6844482a26b7648b34435.tar.xz
changing IRCBridgeModule to new region module scheme
Diffstat (limited to 'OpenSim/Region/OptionalModules/Avatar/Chat/IRCBridgeModule.cs')
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/Chat/IRCBridgeModule.cs121
1 files changed, 47 insertions, 74 deletions
diff --git a/OpenSim/Region/OptionalModules/Avatar/Chat/IRCBridgeModule.cs b/OpenSim/Region/OptionalModules/Avatar/Chat/IRCBridgeModule.cs
index fdc2bd9..5ebbd7b 100644
--- a/OpenSim/Region/OptionalModules/Avatar/Chat/IRCBridgeModule.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/Chat/IRCBridgeModule.cs
@@ -38,87 +38,61 @@ using OpenSim.Region.Framework.Scenes;
38 38
39namespace OpenSim.Region.OptionalModules.Avatar.Chat 39namespace OpenSim.Region.OptionalModules.Avatar.Chat
40{ 40{
41 public class IRCBridgeModule : IRegionModule 41 public class IRCBridgeModule : INonSharedRegionModule
42 { 42 {
43 private static readonly ILog m_log = 43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45 44
46 internal static bool configured = false; 45 internal static bool m_pluginEnabled = false;
47 internal static bool enabled = false; 46 internal static IConfig m_config = null;
48 internal static IConfig m_config = null;
49 47
50 internal static List<ChannelState> m_channels = new List<ChannelState>(); 48 internal static List<ChannelState> m_channels = new List<ChannelState>();
51 internal static List<RegionState> m_regions = new List<RegionState>(); 49 internal static List<RegionState> m_regions = new List<RegionState>();
52 50
53 internal static string password = String.Empty; 51 internal static string m_password = String.Empty;
52 internal RegionState m_region = null;
54 53
55 internal RegionState region = null; 54 #region INonSharedRegionModule Members
56
57 #region IRegionModule Members
58 55
59 public string Name 56 public string Name
60 { 57 {
61 get { return "IRCBridgeModule"; } 58 get { return "IRCBridgeModule"; }
62 } 59 }
63 60
64 public bool IsSharedModule 61 public void Initialise(IConfigSource config)
65 { 62 {
66 get { return false; } 63 m_config = config.Configs["IRC"];
67 } 64 if (m_config == null)
68
69 public void Initialise(Scene scene, IConfigSource config)
70 {
71 // Do a once-only scan of the configuration file to make
72 // sure it's basically intact.
73
74 if (!configured)
75 { 65 {
76 configured = true; 66 m_log.InfoFormat("[IRC-Bridge] module not configured");
77 67 return;
78 try 68 }
79 {
80 if ((m_config = config.Configs["IRC"]) == null)
81 {
82 m_log.InfoFormat("[IRC-Bridge] module not configured");
83 return;
84 }
85
86 if (!m_config.GetBoolean("enabled", false))
87 {
88 m_log.InfoFormat("[IRC-Bridge] module disabled in configuration");
89 return;
90 }
91 }
92 catch (Exception e)
93 {
94 m_log.ErrorFormat("[IRC-Bridge] configuration failed : {0}", e.Message);
95 return;
96 }
97 69
98 enabled = true; 70 if (!m_config.GetBoolean("enabled", false))
71 {
72 m_log.InfoFormat("[IRC-Bridge] module disabled in configuration");
73 return;
74 }
99 75
100 if (config.Configs["RemoteAdmin"] != null) 76 if (config.Configs["RemoteAdmin"] != null)
101 { 77 {
102 password = config.Configs["RemoteAdmin"].GetString("access_password", password); 78 m_password = config.Configs["RemoteAdmin"].GetString("access_password", m_password);
103 scene.CommsManager.HttpServer.AddXmlRPCHandler("irc_admin", XmlRpcAdminMethod, false);
104 }
105 } 79 }
106 80
107 // Iff the IRC bridge is enabled, then each new region may be 81 m_pluginEnabled = true;
108 // connected to IRC. But it should NOT be obligatory (and it 82 }
109 // is not). 83
110 // We have to do ALL of the startup here because PostInitialize 84 public void AddRegion(Scene scene)
111 // is not called when a region gets created in-flight from the 85 {
112 // command line. 86 if (m_pluginEnabled)
113
114 if (enabled)
115 { 87 {
116 try 88 try
117 { 89 {
118 m_log.InfoFormat("[IRC-Bridge] Connecting region {0}", scene.RegionInfo.RegionName); 90 m_log.InfoFormat("[IRC-Bridge] Connecting region {0}", scene.RegionInfo.RegionName);
119 region = new RegionState(scene, m_config); 91 if (!String.IsNullOrEmpty(m_password))
120 lock (m_regions) m_regions.Add(region); 92 scene.CommsManager.HttpServer.AddXmlRPCHandler("irc_admin", XmlRpcAdminMethod, false);
121 region.Open(); 93 m_region = new RegionState(scene, m_config);
94 lock (m_regions) m_regions.Add(m_region);
95 m_region.Open();
122 } 96 }
123 catch (Exception e) 97 catch (Exception e)
124 { 98 {
@@ -132,34 +106,33 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
132 } 106 }
133 } 107 }
134 108
135 // This module can be called in-flight in which case PostInitialize
136 // is not called following Initialize. So no use is made of this
137 // call.
138 109
139 public void PostInitialise() 110 public void RegionLoaded(Scene scene)
140 { 111 {
141 } 112 }
142 113
143 // Called immediately before the region module is unloaded. Cleanup 114 public void RemoveRegion(Scene scene)
144 // the region.
145
146 public void Close()
147 { 115 {
148 if (!enabled) 116 if (!m_pluginEnabled)
149 return; 117 return;
150 118
151 if (region == null) 119 if (m_region == null)
152 return; 120 return;
153 121
154 region.Close(); 122 if (!String.IsNullOrEmpty(m_password))
123 scene.CommsManager.HttpServer.RemoveXmlRPCHandler("irc_admin");
124
125 m_region.Close();
155 126
156 if (m_regions.Contains(region)) 127 if (m_regions.Contains(m_region))
157 { 128 {
158 lock (m_regions) m_regions.Remove(region); 129 lock (m_regions) m_regions.Remove(m_region);
159 } 130 }
160
161 } 131 }
162 132
133 public void Close()
134 {
135 }
163 #endregion 136 #endregion
164 137
165 public static XmlRpcResponse XmlRpcAdminMethod(XmlRpcRequest request) 138 public static XmlRpcResponse XmlRpcAdminMethod(XmlRpcRequest request)
@@ -175,11 +148,11 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
175 bool found = false; 148 bool found = false;
176 string region = String.Empty; 149 string region = String.Empty;
177 150
178 if (password != String.Empty) 151 if (m_password != String.Empty)
179 { 152 {
180 if (!requestData.ContainsKey("password")) 153 if (!requestData.ContainsKey("password"))
181 throw new Exception("Invalid request"); 154 throw new Exception("Invalid request");
182 if ((string)requestData["password"] != password) 155 if ((string)requestData["password"] != m_password)
183 throw new Exception("Invalid request"); 156 throw new Exception("Invalid request");
184 } 157 }
185 158