enable IRC bridge via runtime configuration

afrisby
Sean Dague 2007-10-19 21:36:58 +00:00
parent d4bb430f78
commit 9a17bc58a6
2 changed files with 56 additions and 36 deletions

View File

@ -43,21 +43,21 @@ namespace OpenSim.Region.Environment.Modules
{ {
private Scene m_scene; private Scene m_scene;
private string m_server = "irc2.choopa.net"; private string m_server = null;
private int m_port = 6668;
private string m_user = "USER OpenSimBot 8 * :I'm a OpenSim to irc bot";
private string m_nick = null;
private string m_channel = null;
// private int m_port = 6668; private NetworkStream m_stream;
//private string m_user = "USER OpenSimBot 8 * :I'm a OpenSim to irc bot";
private string m_nick = "OSimBot";
private string m_channel = "#opensim";
// private NetworkStream m_stream;
private TcpClient m_irc; private TcpClient m_irc;
private StreamWriter m_ircWriter; private StreamWriter m_ircWriter;
private StreamReader m_ircReader; private StreamReader m_ircReader;
private Thread pingSender;
private Thread listener;
// private Thread pingSender; private bool m_enable_irc = false;
// private Thread listener;
private bool connected = false; private bool connected = false;
public ChatModule() public ChatModule()
@ -70,6 +70,19 @@ namespace OpenSim.Region.Environment.Modules
public void Initialise(Scene scene, IConfigSource config) public void Initialise(Scene scene, IConfigSource config)
{ {
try {
m_server = config.Configs["IRC"].GetString("server");
m_nick = config.Configs["IRC"].GetString("nick");
m_channel = config.Configs["IRC"].GetString("channel");
m_port = config.Configs["IRC"].GetInt("port", m_port);
m_user = config.Configs["IRC"].GetString("username", m_user);
if (m_server != null && m_nick != null && m_channel != null) {
m_enable_irc = true;
}
} catch (Exception e) {
Console.WriteLine("No IRC config information, skipping IRC bridge configuration");
}
m_scene = scene; m_scene = scene;
m_scene.EventManager.OnNewClient += NewClient; m_scene.EventManager.OnNewClient += NewClient;
@ -78,33 +91,33 @@ namespace OpenSim.Region.Environment.Modules
public void PostInitialise() public void PostInitialise()
{ {
/* if( m_enable_irc ) {
try try
{ {
m_irc = new TcpClient(m_server, m_port); m_irc = new TcpClient(m_server, m_port);
m_stream = m_irc.GetStream(); m_stream = m_irc.GetStream();
m_ircReader = new StreamReader(m_stream); m_ircReader = new StreamReader(m_stream);
m_ircWriter = new StreamWriter(m_stream); m_ircWriter = new StreamWriter(m_stream);
pingSender = new Thread(new ThreadStart(this.PingRun)); pingSender = new Thread(new ThreadStart(this.PingRun));
pingSender.Start(); pingSender.Start();
listener = new Thread(new ThreadStart(this.ListenerRun)); listener = new Thread(new ThreadStart(this.ListenerRun));
listener.Start(); listener.Start();
m_ircWriter.WriteLine(m_user); m_ircWriter.WriteLine(m_user);
m_ircWriter.Flush(); m_ircWriter.Flush();
m_ircWriter.WriteLine("NICK " + m_nick); m_ircWriter.WriteLine("NICK " + m_nick);
m_ircWriter.Flush(); m_ircWriter.Flush();
m_ircWriter.WriteLine("JOIN " + m_channel); m_ircWriter.WriteLine("JOIN " + m_channel);
m_ircWriter.Flush(); m_ircWriter.Flush();
connected = true; connected = true;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
} }
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
*/
} }
public void Close() public void Close()

View File

@ -39,4 +39,11 @@ user_recv_key = "null"
asset_server_url = "http://127.0.0.1:8003" asset_server_url = "http://127.0.0.1:8003"
; Uncomment the following for IRC bridge
; experimental, so if it breaks... keep both parts... yada yada
; also, not good error detection when it fails
;[IRC]
;server = name.of.irc.server.on.the.net
;nick = OpenSimBotNameProbablyMakeThisShorter
;channel = #the_irc_channel_you_want_to_connect_to