SparkleShare/SparkleLib/SparkleListener.cs

97 lines
2.1 KiB
C#
Raw Normal View History

2010-09-11 16:03:28 +00:00
// SparkleShare, an instant update workflow to Git.
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using Meebey.SmartIrc4net;
using System;
using System.Collections.Generic;
using System.Text;
2010-09-11 18:11:34 +00:00
using System.Threading;
2010-09-11 16:03:28 +00:00
namespace SparkleLib {
2010-09-11 18:11:34 +00:00
public class SparkleListener
2010-09-11 16:03:28 +00:00
{
public IrcClient Client;
2010-09-12 17:46:00 +00:00
public Thread Thread;
public string Server;
public string Channel;
public string Nick;
public int Port;
2010-09-11 18:11:34 +00:00
public SparkleListener (string server, string channel, string nick)
{
2010-09-11 18:11:34 +00:00
Server = server;
Channel = channel;
Nick = nick.Replace ("@", "_at_").Replace (".", "_dot_");
Port = 6667;
2010-09-11 18:11:34 +00:00
if (Nick.Length > 9)
Nick = Nick.Substring (0, 9);
// TODO: Remove these hardcoded values
Channel = "#sparkletest";
Server = "irc.gnome.org";
2010-09-11 18:11:34 +00:00
Client = new IrcClient ();
2010-09-11 18:11:34 +00:00
Client.AutoRejoin = true;
Client.AutoRetry = true;
Client.AutoRelogin = true;
2010-09-11 18:11:34 +00:00
}
2010-09-11 18:11:34 +00:00
// Starts a new thread and listens to the channel
public void Listen ()
{
2010-09-11 18:11:34 +00:00
try {
2010-09-11 18:11:34 +00:00
2010-09-12 17:46:00 +00:00
Thread = new Thread (
new ThreadStart (delegate {
2010-09-11 18:11:34 +00:00
// Connect to the server
Client.Connect (new string [] {Server}, Port);
2010-09-11 18:11:34 +00:00
// Login to the server
Client.Login (Nick, Nick);
// Join the channel
Client.RfcJoin (Channel);
2010-09-11 18:11:34 +00:00
Client.Listen ();
Client.Disconnect ();
})
);
2010-09-11 18:11:34 +00:00
2010-09-12 17:46:00 +00:00
Thread.Start ();
2010-09-11 18:11:34 +00:00
} catch (Exception e) {
2010-09-11 16:03:28 +00:00
Console.WriteLine ("Could not connect: " + e.Message);
2010-09-11 16:50:30 +00:00
}
2010-09-11 16:50:30 +00:00
}
2010-09-11 16:03:28 +00:00
}
}