Virtual Developer Workshop: Containerized Development with Docker
Click here for larger image
Environment: eg VC6, WIN32
This article describes a C++ class library to help programmers implement their own IRC client (like the famous mIRC). The protocols supported by this class library are :
- Maintaining a TCP/IP connection to a remote IRC server in a secondary thread.
- Identification server (optional. see CIrcSessionInfo).
- Full IRC messages two-way parsing.
- IRC notifications are posted back to the thread that created the monitor object.
- Efficient mechaism of mapping IRC commands to their associated user-defined member functions. This mechanism resembles the way MFC maps Windows(tm) messages to response functions.
- Even though the demo project was written using MFC, the library itself was written using only plain C++, STL and WIN32 API.
IIrcSessionMonitor (irc.h,irc.cpp) - Base interface for IRC session monitors.
CIrcSession (irc.h,irc.cpp) - IRC session manager. Maintains a connection to the remote IRC server in a secondary thread, and distributes parsed IRC messages to registered monitors.
CIrcSessionInfo (irc.h,irc.cpp) - IRC connection specs holder.
CIrcMonitor (irc.h,irc.cpp) - Basic session monitor object (derived from IIrcSessionMonitor). This class implements a mechanism that maps IRC commands to user-defined member functions, same as what MFC does with Windows(tm) messages. All notifications are posted outside the context of the connection thread(!)
CIrcDefaultMonitor (irc.h,irc.cpp) - Provides some automatic responses the IRC server requires. (Derived from CIrcMonitor).
CIrcIdentServer (irc.h,irc.cpp) - Identification server. This class is used by the CIrcSession class.
DEFINE_IRC_MAP() (irc.h) - Must be defined inside your CIrcMonitor derived class's definition (.H file).
DECLARE_IRC_MAP(this_class_name, base_class_name) (irc.h) - Must be defined in your CIrcMonitor derived class's implementation file (.CPP).
IRC_MAP_ENTRY(class_name, command, member) (irc.h) - Add entries like this in your class's constructor for each IRC command you'd like to respond to.
WinsockInit (socket.h,socket.cpp) - Provides automatic winsock initialization. All address resolving code is contained by this class.
Socket (socket.h,socket.cpp) - WIN32 socket's wrapper class.
InetAddr (socket.h,socket.cpp) - Internet address helper class.
CCrossThreadsMessagingDevice (CrossThreadsMessagingDevice.h,CrossThreadsMessagingDevice.cpp) - Used by CIrcMonitor to post IRC notifications back to the thread that the monitor was created in.
- The library comes in the form of source-code only (sorry, no DLL yet, although it would certainly make sense to create one), so you just have to add all those source files to your C++ project.
- Somewhere inside your project, create an instance of CIrcSession. no derivation needed. This object is your actual connection to the remote IRC server.
- To receive notification from the server, you'll have to create a 'monitor' object. This monitor can be any class that is derived from the IIrcSessionMonitor, directory or indirectly. My personal recommendation is to derive from CIrcDefaultMonitor, because it also provides some automatic responses the IRC server requires. (The demo project i provided here is a multiple-document MFC project so there i decided to make the document object as my monitor).
- Add the notification handler functions to your monitor object as needed.
DownloadsDownload demo project - 34 Kb
Download source - 9 Kb
Yet to be done
Things I haven't implemented in the current version :
- DCC connections (both char and file-transfer).
- DLL version.
- Unicode support.