Click here to Skip to main content
15,886,919 members
Articles / Programming Languages / XML

SmartIrc4net - The C# IRC Library

Rate me:
Please Sign up or sign in to vote.
4.92/5 (18 votes)
19 Sep 20042 min read 139.8K   1.6K   56   32
IRC library for .NET

Introduction

I wrote SmartIrc4net for having a high-level IRC API for .NET/C#. I started a long time ago with IRC programming for PHP, I wrote Net_SmartIRC. Net_SmartIRC is a PEAR class. Later, I was disappointed that the OO features of PHP are so limited. I was starting to port the project to C++, after a few weeks I stopped, so many things are missing and have to be written (even simple things like string manipulation). Then I found C#. And I ported SmartIRC in about 1-2 weeks! After that, the API got better and better, it's just great what it is now... so here we are SmartIrc4net.

Object Design

This library has a 3 layered API, allows developers to pick the layer/features they need. You could use any layer for writing IRC applications, the question is how much IRC abstraction and features you need. You have the choice!

Layer 1: IrcConnection

This layer is a low-level API and manages the messagebuffer (for reading and writing). Also, the ping/pong and connection handling is done.

Layer 2: IrcCommands (extends IrcConnection)

This layer is a middle-level API. It contains all IRC RFC commands plus some useful and easy to use IRC methods (like Op, Deop, Ban, Unban, etc.).

Layer 3: IrcClient (extends IrcCommands)

This layer is a high-level API with all features you could need for IRC programming, like channel syncing (keeping track of channels in objects with modes/topic/users), user syncing (for nicks, indents, hosts, realnames, servers, and hopcounts). This layer is fully event driven, all received data is parsed into different events with special arguments for each event (this makes it very easy to use the received IRC data without checking the RFC each time!)

How to Use SmartIrc4net

Here is an example of how to use the library using the high-level API:

C#
using System;
using System.Collections;
using Meebey.SmartIrc4net;
using Meebey.SmartIrc4net.Delegates;

public class Test
{
    public static IrcClient irc = new IrcClient();

    public static void OnQueryMessage(Data ircdata)
    {
        switch (ircdata.MessageEx[0]) {
            case "join":
                irc.Join(ircdata.MessageEx[1]);
            break;
            case "part":
                irc.Part(ircdata.MessageEx[1]);
            break;
            case "say":
                irc.Message(SendType.Message, MessageEx[1], MessageEx[2]);
            break;
        }
    }

    public static void Main(string[] args)
    {
        irc.SendDelay = 200;
        irc.AutoRetry = true;
        irc.ChannelSyncing = true;
        irc.OnQueryMessage += new MessageEventHandler(OnQueryMessage);

        string[] serverlist;
        serverlist = new string[] {"irc.ircnet.net"};

        int    port   = 6667;
        if(irc.Connect(serverlist, port) == true) {
            irc.Login("SmartIRC", "Stupid Bot");
            irc.Join("#smartirc");
            irc.Message(SendType.Message, "#smartirc", "test message");
            irc.Message(SendType.Action, "#smartirc", " thinks this is cool");
            irc.Message(SendType.Notice, "#smartirc", "SmartIrc4net rocks!");
            }
            irc.Listen();
            irc.Disconnect();
        } else {
            System.Console.WriteLine("couldn't connect!");
        }
    }
}

Connect to your favorite IRC server, set the IRC server in the source. Join the #smartirc channel. Compile the source, spawn the bot. The bot should come and say three messages, after that, send him a private message: "/msg smartirc say #smartirc hello!".

Official Project Page

SmartIrc4net is an own project which you can find here. There you get the current versions, can report bugs or post help requests on the forum. Comments, suggestions and criticism are welcome!

Have Fun

There you go, have fun with bot coding! ;)

License

This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.

A list of licenses authors might use can be found here.


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generalbugs in the example Pin
meebey26-Sep-04 10:21
meebey26-Sep-04 10:21 
GeneralRe: bugs in the example Pin
meebey20-Nov-04 3:17
meebey20-Nov-04 3:17 
GeneralNo Source Pin
Rev_Fry19-Sep-04 7:40
Rev_Fry19-Sep-04 7:40 
GeneralRe: No Source Pin
Rev_Fry19-Sep-04 7:41
Rev_Fry19-Sep-04 7:41 
GeneralRe: No Source Pin
Uwe Keim19-Sep-04 18:41
sitebuilderUwe Keim19-Sep-04 18:41 
GeneralRe: No Source Pin
meebey20-Sep-04 8:35
meebey20-Sep-04 8:35 
GeneralRe: No Source Pin
meebey20-Sep-04 8:34
meebey20-Sep-04 8:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.