A custom IRC server written in C++98, implementing the core of the IRC protocol (RFC 1459/2812-style) over raw TCP sockets with a single-threaded, poll()-based event loop. Includes a Python weather bot as an example IRC client/bot integration.
- Single-threaded, non-blocking server using
poll()to multiplex the listening socket and all connected clients - Full client registration flow:
PASS→NICK→USER - Channel management: creation, joining, parting, and automatic cleanup of empty channels
- Channel operator system with promotion of a new operator when the current one leaves
- Channel modes:
+i(invite-only),+t(topic lock),+k(password),+l(user limit),+o(operator) - Messaging:
PRIVMSGandNOTICEto both users and channels TOPIC,KICK,INVITE,MODE,QUITcommand supportPING/PONGkeepalive handling- Numeric reply codes matching standard IRC clients' expectations (e.g. 001, 331/332, 353/366, 401–475)
- Example Python bot (
WeatherBot.py) demonstrating a working IRC client integration using wttr.in
- A C++98-compatible compiler (
c++/g++/clang++) - POSIX sockets (Linux/macOS)
- Python 3 (only needed to run
WeatherBot.py)
make # builds the ircserv binary
make clean # removes object files
make fclean # removes object files and the binary
make re # fclean + all./ircserv <port> <password>port— must be 1–5 digits (e.g.6667)password— required to authenticate clients via the IRCPASScommand
Example:
./ircserv 6667 1234Connect with any standard IRC client (e.g. irssi, WeeChat, HexChat) pointed at localhost:6667, using 1234 as the server password.
.
├── Makefile
├── WeatherBot.py # example bot client (Python)
└── src/
├── main.cpp # entry point, argument parsing, server bootstrap
├── Server.cpp/.hpp # socket setup, poll() event loop, command dispatch
├── Client.cpp/.hpp # per-connection state (nick, user, auth, buffer)
├── Message.cpp/.hpp # raw IRC line parser (prefix/command/params/trailing)
├── Channel/
│ └── Channel.cpp/.hpp # channel state: members, operators, modes, invites
├── Commands/
│ └── Commands.cpp/.hpp # handlers for PASS, NICK, USER, JOIN, PRIVMSG, etc.
└── Utils/
├── Parser.cpp/.hpp # CLI argument validation (port/password)
└── Exceptions.hpp # custom exception types for startup/socket failures
Parservalidates theportandpasswordcommand-line arguments at startup.Servercreates a listening TCP socket, binds, and listens.- The main loop uses
poll()over the listening socket plus every connected client socket. - On a new connection, a
Clientobject is created and added to the poll set. - On incoming data, bytes are appended to the client's internal buffer and split on
\r\ninto individualMessageobjects. - Each
Messageis dispatched by command name (Server::dispatch) to the matching handler inCommands.cpp, which validates state (registration, permissions, channel membership) and sends the appropriate numeric or command reply. Channeltracks membership, operator status, invite lists, and modes, and providesbroadcast()to relay messages to all members.
A minimal example IRC bot that connects to the server, joins #general, and responds to !weather <city> by querying wttr.in for current conditions.
python3 WeatherBot.pyMake sure ircserv is already running on localhost:6667 with password 1234 (or update the constants at the top of the script to match your server).
- This is a C++98 project (per the Makefile's
-std=c++98flag), so it deliberately avoids C++11+ features (e.g.nullptr, range-based for,auto). - Compiled with
-Wall -Wextra -Werror, so the codebase is warning-clean by design.