using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Net.Sockets;
namespace
IRC
{
class IRCClient : Component
{
const short MESSAGE_BUFFERSIZE = 512;
private TcpClient tcpClient = new TcpClient();
public string Hostname
{
get { return Hostname; }
set { Hostname = value; }
}
public short Port
{
get { return Port; }
set { Port = value; }
}
public delegate void ConnectEventHandler(object sender, EventArgs e);
public event ConnectEventHandler OnConnect;
public void Connect()
{
tcpClient.Connect(Hostname, Port);
}
public void Disconnect()
{
tcpClient.Close();
}
public void Raw(string Message)
{
if (tcpClient != null)
{
byte[] buf = new byte[MESSAGE_BUFFERSIZE];
Message += "\r\n";
buf = System.Text.Encoding.UTF8.GetBytes(Message.ToCharArray());
tcpClient.GetStream().Write(buf, 0, buf.Length);
}
}
public void Message(string Target, string Message)
{
Raw(String.Format("PRIVMSG {0} :{1}", Target, Message));
}
public void Notice(string Target, string Message)
{
Raw(String.Format("NOTICE {0} :{1}", Target, Message));
}
public void Join(string Channel)
{
Raw(String.Format("JOIN {0}", Channel));
}
public void Join(string Channel, string Password)
{
Raw(String.Format("JOIN {0} {1}", Channel, Password));
}
public void Part(string Channel)
{
Raw(String.Format("PART {0}", Channel));
}
public void Part(string Channel, string Message)
{
Raw(String.Format("PART {0} :{1}", Channel, Message));
}
public void Quit()
{
Raw("QUIT");
}
public void Quit(string Message)
{
Raw(String.Format("QUIT :{0}", Message));
}
public void Invite(string Nickname, string Channel)
{
Raw(String.Format("INVITE {0} {1}", Nickname, Channel));
}
public void Nick(string Nickname)
{
Raw(String.Format("NICK :{0}", Nickname));
}
}
}