diff options
author | Teravus Ovares | 2008-01-29 04:35:01 +0000 |
---|---|---|
committer | Teravus Ovares | 2008-01-29 04:35:01 +0000 |
commit | da0fa4253bc190390a92900833182737778bce23 (patch) | |
tree | 8ec60f118a7f13ba24509fe9484637b96c898df5 /OpenSim/Region/Environment/Modules | |
parent | * Commenting out the 'collision notifications' on BulletX, as there hasn't be... (diff) | |
download | opensim-SC_OLD-da0fa4253bc190390a92900833182737778bce23.zip opensim-SC_OLD-da0fa4253bc190390a92900833182737778bce23.tar.gz opensim-SC_OLD-da0fa4253bc190390a92900833182737778bce23.tar.bz2 opensim-SC_OLD-da0fa4253bc190390a92900833182737778bce23.tar.xz |
Thanks kinoc for your improved IRC Gateway patch as referenced in mantis issue 390.
Diffstat (limited to 'OpenSim/Region/Environment/Modules')
-rw-r--r-- | OpenSim/Region/Environment/Modules/ChatModule.cs | 103 |
1 files changed, 80 insertions, 23 deletions
diff --git a/OpenSim/Region/Environment/Modules/ChatModule.cs b/OpenSim/Region/Environment/Modules/ChatModule.cs index d6df978..9aea977 100644 --- a/OpenSim/Region/Environment/Modules/ChatModule.cs +++ b/OpenSim/Region/Environment/Modules/ChatModule.cs | |||
@@ -163,6 +163,12 @@ namespace OpenSim.Region.Environment.Modules | |||
163 | fromAgentID = e.Sender.AgentId; | 163 | fromAgentID = e.Sender.AgentId; |
164 | } | 164 | } |
165 | 165 | ||
166 | // Try to reconnect to server if not connected | ||
167 | if ((m_irc.Enabled)&&(!m_irc.Connected)) | ||
168 | { | ||
169 | m_irc.Connect(m_scenes); | ||
170 | } | ||
171 | |||
166 | if (e.Message.Length > 0) | 172 | if (e.Message.Length > 0) |
167 | { | 173 | { |
168 | if (m_irc.Connected && (avatar != null)) // this is to keep objects from talking to IRC | 174 | if (m_irc.Connected && (avatar != null)) // this is to keep objects from talking to IRC |
@@ -205,6 +211,7 @@ namespace OpenSim.Region.Environment.Modules | |||
205 | private bool m_connected = false; | 211 | private bool m_connected = false; |
206 | 212 | ||
207 | private List<Scene> m_scenes = null; | 213 | private List<Scene> m_scenes = null; |
214 | private List<Scene> m_last_scenes = null; | ||
208 | private LogBase m_log; | 215 | private LogBase m_log; |
209 | 216 | ||
210 | public IRCChatModule(IConfigSource config) | 217 | public IRCChatModule(IConfigSource config) |
@@ -214,6 +221,19 @@ namespace OpenSim.Region.Environment.Modules | |||
214 | m_writer = null; | 221 | m_writer = null; |
215 | m_reader = null; | 222 | m_reader = null; |
216 | 223 | ||
224 | // configuration in OpenSim.ini | ||
225 | // [IRC] | ||
226 | // server = chat.freenode.net | ||
227 | // nick = OSimBot_mysim | ||
228 | // ;username = OSimBot_mysim | ||
229 | // channel = #opensim-regions | ||
230 | // port = 6667 | ||
231 | // | ||
232 | // Traps I/O disconnects so it does not crash the sim | ||
233 | // Trys to reconnect if disconnected and someone says something | ||
234 | // Tells IRC server "QUIT" when doing a close (just to be nice) | ||
235 | // Default port back to 6667 | ||
236 | |||
217 | try | 237 | try |
218 | { | 238 | { |
219 | m_server = config.Configs["IRC"].GetString("server"); | 239 | m_server = config.Configs["IRC"].GetString("server"); |
@@ -238,7 +258,7 @@ namespace OpenSim.Region.Environment.Modules | |||
238 | try | 258 | try |
239 | { | 259 | { |
240 | m_scenes = scenes; | 260 | m_scenes = scenes; |
241 | 261 | m_last_scenes = scenes; | |
242 | m_tcp = new TcpClient(m_server, (int) m_port); | 262 | m_tcp = new TcpClient(m_server, (int) m_port); |
243 | m_log.Verbose("IRC", "Connecting..."); | 263 | m_log.Verbose("IRC", "Connecting..."); |
244 | m_stream = m_tcp.GetStream(); | 264 | m_stream = m_tcp.GetStream(); |
@@ -290,14 +310,20 @@ namespace OpenSim.Region.Environment.Modules | |||
290 | m_log.Error("IRC", "Disconnected from IRC server."); | 310 | m_log.Error("IRC", "Disconnected from IRC server."); |
291 | listener.Abort(); | 311 | listener.Abort(); |
292 | pingSender.Abort(); | 312 | pingSender.Abort(); |
313 | m_writer.Close(); | ||
314 | m_reader.Close(); | ||
315 | m_tcp.Close(); | ||
293 | m_connected = false; | 316 | m_connected = false; |
317 | if (m_enabled) { Connect(m_last_scenes); } | ||
294 | } | 318 | } |
295 | } | 319 | } |
296 | 320 | ||
297 | private Dictionary<string, string> ExtractMsg(string input) | 321 | private Dictionary<string, string> ExtractMsg(string input) |
298 | { | 322 | { |
323 | m_log.Verbose("IRC", "ExtractMsg: " + input); | ||
299 | Dictionary<string, string> result = null; | 324 | Dictionary<string, string> result = null; |
300 | string regex = @":(?<nick>\w*)!~(?<user>\S*) PRIVMSG (?<channel>\S+) :(?<msg>.*)"; | 325 | //string regex = @":(?<nick>\w*)!~(?<user>\S*) PRIVMSG (?<channel>\S+) :(?<msg>.*)"; |
326 | string regex = @":(?<nick>\w*)!(?<user>\S*) PRIVMSG (?<channel>\S+) :(?<msg>.*)"; | ||
301 | Regex RE = new Regex(regex, RegexOptions.Multiline); | 327 | Regex RE = new Regex(regex, RegexOptions.Multiline); |
302 | MatchCollection matches = RE.Matches(input); | 328 | MatchCollection matches = RE.Matches(input); |
303 | // Get some direct matches $1 $4 is a | 329 | // Get some direct matches $1 $4 is a |
@@ -324,10 +350,24 @@ namespace OpenSim.Region.Environment.Modules | |||
324 | { | 350 | { |
325 | while (true) | 351 | while (true) |
326 | { | 352 | { |
327 | m_writer.WriteLine("PING :" + m_server); | 353 | try |
328 | m_writer.Flush(); | 354 | { |
329 | Thread.Sleep(15000); | 355 | m_writer.WriteLine("PING :" + m_server); |
330 | } | 356 | m_writer.Flush(); |
357 | Thread.Sleep(15000); | ||
358 | } | ||
359 | catch (IOException) | ||
360 | { | ||
361 | m_log.Error("IRC", "Disconnected from IRC server."); | ||
362 | listener.Abort(); | ||
363 | pingSender.Abort(); | ||
364 | m_writer.Close(); | ||
365 | m_reader.Close(); | ||
366 | m_tcp.Close(); | ||
367 | m_connected = false; | ||
368 | if (m_enabled) { Connect(m_last_scenes); } | ||
369 | } | ||
370 | } | ||
331 | } | 371 | } |
332 | 372 | ||
333 | public void ListenerRun() | 373 | public void ListenerRun() |
@@ -336,36 +376,53 @@ namespace OpenSim.Region.Environment.Modules | |||
336 | LLVector3 pos = new LLVector3(128, 128, 20); | 376 | LLVector3 pos = new LLVector3(128, 128, 20); |
337 | while (true) | 377 | while (true) |
338 | { | 378 | { |
339 | while ((inputLine = m_reader.ReadLine()) != null) | 379 | try |
340 | { | 380 | { |
341 | // Console.WriteLine(inputLine); | 381 | while ((inputLine = m_reader.ReadLine()) != null) |
342 | if (inputLine.Contains(m_channel)) | ||
343 | { | 382 | { |
344 | Dictionary<string, string> data = ExtractMsg(inputLine); | 383 | // Console.WriteLine(inputLine); |
345 | if (data != null) | 384 | if (inputLine.Contains(m_channel)) |
346 | { | 385 | { |
347 | foreach (Scene m_scene in m_scenes) | 386 | Dictionary<string, string> data = ExtractMsg(inputLine); |
387 | if (data != null) | ||
348 | { | 388 | { |
349 | m_scene.ForEachScenePresence(delegate(ScenePresence avatar) | 389 | foreach (Scene m_scene in m_scenes) |
350 | { | 390 | { |
351 | if (!avatar.IsChildAgent) | 391 | m_scene.ForEachScenePresence(delegate(ScenePresence avatar) |
352 | { | 392 | { |
353 | avatar.ControllingClient.SendChatMessage( | 393 | if (!avatar.IsChildAgent) |
354 | Helpers.StringToField(data["msg"]), 255, | 394 | { |
355 | pos, data["nick"], | 395 | avatar.ControllingClient.SendChatMessage( |
356 | LLUUID.Zero); | 396 | Helpers.StringToField(data["msg"]), 255, |
357 | } | 397 | pos, data["nick"], |
358 | }); | 398 | LLUUID.Zero); |
399 | } | ||
400 | }); | ||
401 | } | ||
359 | } | 402 | } |
360 | } | 403 | } |
361 | } | 404 | } |
405 | Thread.Sleep(50); | ||
362 | } | 406 | } |
363 | Thread.Sleep(50); | 407 | catch (IOException) |
408 | { | ||
409 | m_log.Error("IRC", "Disconnected from IRC server."); | ||
410 | listener.Abort(); | ||
411 | pingSender.Abort(); | ||
412 | m_writer.Close(); | ||
413 | m_reader.Close(); | ||
414 | m_tcp.Close(); | ||
415 | m_connected = false; | ||
416 | if (m_enabled) { Connect(m_last_scenes); } | ||
417 | } | ||
418 | |||
364 | } | 419 | } |
365 | } | 420 | } |
366 | 421 | ||
367 | public void Close() | 422 | public void Close() |
368 | { | 423 | { |
424 | m_writer.WriteLine("QUIT :" + m_nick+" to "+m_channel+" wormhole with "+m_server+" closing"); | ||
425 | m_writer.Flush(); | ||
369 | listener.Abort(); | 426 | listener.Abort(); |
370 | pingSender.Abort(); | 427 | pingSender.Abort(); |
371 | m_writer.Close(); | 428 | m_writer.Close(); |
@@ -373,4 +430,4 @@ namespace OpenSim.Region.Environment.Modules | |||
373 | m_tcp.Close(); | 430 | m_tcp.Close(); |
374 | } | 431 | } |
375 | } | 432 | } |
376 | } \ No newline at end of file | 433 | } |