This project is read-only.

Toolbox.NETMF.NET.IRC_Client


Toolbox.NETMF.NET.IRC_Client(Socket, Nickname, Username, Fullname, Password)
  • Socket A reference for the socket to be used (see also: SimpleSocket)
  • Nickname The nickname
  • Username The username (optional)
  • Fullname The full name (optional)
  • Password Password to connect to the server (optional)

Static methods

  • SplitName(Name) Returns the username splitted (many IRCds send "[nickname]![username]@[hostname]")
  • SplitRawData(Data) Splits raw IRC data
  • Time() Returns the time in mIRC format

Methods

  • Connect() Connects to the IRC server
  • Disconnect() Disconnects from the IRC server
  • Dispose() Disposes the IRC Class object
  • Action(Recipient, Data) Sends an action
  • Notice(Recipient, Data) Sends a notice
  • Message(Recipient, Data) Sends a message
  • Join(Channels) Joins one or more channels (comma seperated)
  • Part(Channel, Reason) Leaves a channel
  • CtcpRequest(Recipient, Data) Sends a CTCP Request
  • CtcpResponse(Recipient, Data) Sends a CTCP Reply
  • SendRaw(Data) Sends raw data to the server

Properties

  • Nickname Sets or gets the current nickname on the IRC server
  • ClientVersion Returns the version of the IRC-client
  • Authenticated Returns true when we're connected and authenticated on the IRC server
  • ServerName Returns the name of the IRC server

Events

  • OnRawReceived(Unused, Unused, Data) Raw data received from the server
  • OnAuthenticated(Server, Nickname, WelcomeMessage) We're connected to Server with Nickname
  • OnNotice(Sender, Target, Data) Notice received from Sender to Target with text: Data
  • OnMessage(Sender, Target, Data) Message received from Sender to Target with text: Data
  • OnAction(Sender, Target, Data) Action received from Sender to Target with text: Data
  • OnCtcpRequest(Sender, Target, Data) CTCP Request received from Sender to Target with text: Data
  • OnCtcpReply(Sender, Target, Data) CTCP Reply received from Sender to Target with text: Data
  • OnJoin(Nickname, Channel, Unused) Nickname joined Channel
  • OnPart(Nickname, Channel, Reason) Nickname left Channel with a Reason
  • OnQuit(Nickname, Unused, Reason) Nickname left the IRC-server with a Reason

CTCP Note

If the code doesn't specify an OnCtcpRequest event, the client will respond by default to the following requests:
  • PING Just returns the timestamp
  • TIME Returns IRC_Client.Time
  • VERSION Returns IRC_Client.ClientVersion
As soon as OnCtcpRequest is defined, this behaviour will be disabled.

Sample code in C#

// Channel for our nice IRC-bot
public const string Channel = "#netduino";

// The IRC Client
public static IRC_Client Client;

// The onboard LED
public static OutputPort Led = new OutputPort(Pins.ONBOARD_LED, false);

// The onboard Switch
public static InterruptPort Button = new InterruptPort(Pins.ONBOARD_SW1, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);

// Main method, initiates all events and makes the connection
public static void Main()
{
    Button.OnInterrupt += new NativeEventHandler(Button_OnInterrupt);
    Client = new IRC_Client(new IntegratedSocket("irc.netmftoolbox.com", 6667), "Guest");
    Client.OnAuthenticated += new IRC_Client.OnStringReceived(Client_OnAuthenticated);
    Client.OnMessage += new IRC_Client.OnStringReceived(Client_OnMessage);
    Client.Connect();
}

// Button state changed
static void Button_OnInterrupt(uint PinId, uint Value, DateTime Time)
{
    if (!Client.Authenticated) return;
    if (Value == 1)
        Client.Message(Channel, "Oh thank goodness, the button is released.");
    else
        Client.Message(Channel, "Oh dear, someone pressed my button!");
}

// We're connected, lets initialize our client further
static void Client_OnAuthenticated(string Sender, string Target, string Data)
{
    Debug.Print("Successfully connected to " + Sender + " as " + Target);
    Debug.Print(Data);
    Client.Join(Channel);
    Client.Message(Channel, "Hello, it's me, running " + Client.ClientVersion);
    Client.Message(Channel, "Type \"LED [ON/OFF/STATUS]\" to play with my led :-)");
}

// We got a message. If it's a channel message, we're going to respond to it
static void Client_OnMessage(string Sender, string Target, string Data)
{
    if (Target.ToLower() == Channel)
    {
        Debug.Print(IRC_Client.SplitName(Sender)[0] + ": " + Data);

        string[] Commandline = Data.ToUpper().Split(new char[] { ' ' }, 2);
        if (Commandline[0] == "LED" && Commandline[1] == "ON")
        {
            Led.Write(true);
            Client.Message(Channel, "LED just turned ON");
        }
        else if (Commandline[0] == "LED" && Commandline[1] == "OFF")
        {
            Led.Write(false);
            Client.Message(Channel, "LED just turned OFF");
        }
        else if (Commandline[0] == "LED" && Commandline[1] == "STATUS")
        {
            Client.Message(Channel, "The LED is currently " + (Led.Read() ? "ON" : "OFF"));
        }
    }
}

Sample code in VB

' Channel for our nice IRC-bot
Public Const Channel As String = "#netduino"

' The IRC Client
Public WithEvents Client As IRC_Client

' The onboard LED
Public Led As OutputPort = New OutputPort(Pins.ONBOARD_LED, False)

' The onboard Switch
Public WithEvents Button As InterruptPort = New InterruptPort(Pins.ONBOARD_SW1, True, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth)

' Main method, makes the connection
Sub Main()
    Client = New IRC_Client(New IntegratedSocket("irc.netmftoolbox.com", 6667), "Guest")
    Client.Connect()
End Sub

' Button state changed
Private Sub Button_OnInterrupt(PinId As UInteger, Value As UInteger, Time As Date) Handles Button.OnInterrupt
    If Not Client.Authenticated Then Exit Sub
    If Value = 1 Then
        Client.Message(Channel, "Oh thank goodness, the button is released.")
    Else
        Client.Message(Channel, "Oh dear, someone pressed my button!")
    End If
End Sub

' We're connected, lets initialize our client further
Private Sub Client_OnAuthenticated(Sender As String, Target As String, Data As String) Handles Client.OnAuthenticated
    Debug.Print("Successfully connected to " + Sender + " as " + Target)
    Debug.Print(Data)
    Client.Join(Channel)
    Client.Message(Channel, "Hello, it's me, running " + Client.ClientVersion)
    Client.Message(Channel, "Type ""LED [ON/OFF/STATUS]"" to play with my led :-)")
End Sub

' We got a message. If it's a channel message, we're going to respond to it
Private Sub Client_OnMessage(Sender As String, Target As String, Data As String) Handles Client.OnMessage
    If Target.ToLower() = Channel Then
        Debug.Print(IRC_Client.SplitName(Sender)(0) + ": " + Data)

        Dim Commandline() As String = Data.ToUpper().Split(" ".ToCharArray(), 2)
        If Commandline(0) = "LED" And Commandline(1) = "ON" Then
            Led.Write(True)
            Client.Message(Channel, "LED just turned ON")
        ElseIf Commandline(0) = "LED" And Commandline(1) = "OFF" Then
            Led.Write(False)
            Client.Message(Channel, "LED just turned OFF")
        ElseIf Commandline(0) = "LED" And Commandline(1) = "STATUS" Then
            If Led.Read() Then
                Client.Message(Channel, "The LED is currently ON")
            Else
                Client.Message(Channel, "The LED is currently OFF")
            End If
        End If

    End If
End Sub

Last edited Feb 26, 2012 at 12:17 PM by Garrcomm, version 1