A lightweight IRC server implementation in C++98 using non-blocking sockets and poll().
This project was written to support testing and usage with the irssi IRC client.
- Non-blocking TCP server loop with
poll() - Multi-client handling with per-client input/output buffers
- Registration flow with password protection (
PASS,NICK,USER) - Channel support with membership, operators, invites, topic, key, and user limit
- User and channel messaging (
PRIVMSG,NOTICE) - Operator/channel management (
KICK,MODE,TOPIC,INVITE) - Numeric replies for common IRC success/error cases
- Graceful shutdown on
SIGINT/SIGTERM
Requirements:
c++compiler with C++98 supportmake
Build commands:
make
make clean
make fclean
make reOutput binary:
./ircserv
./ircserv <port> <password>Constraints enforced by the server:
portmust be numeric and in range1024..65535passwordcannot be empty or only spaces
Example:
./ircserv 6667 supersecretirssi quick connect example:
irssi -c 127.0.0.1 -p 6667 -w supersecret -n aliceIn one terminal:
./ircserv 6667 supersecretIn another terminal:
nc 127.0.0.1 6667Then send (each line ends with Enter):
PASS supersecret
NICK alice
USER alice 0 * :Alice Example
JOIN #test
PRIVMSG #test :hello
Clients must complete:
PASS <password>NICK <nickname>USER <username> <mode> <unused> :<realname>
Notes:
- Before registration, most commands return
451(ERR_NOTREGISTERED). - Wrong
PASSreturns464and connection is closed. - Nicknames are compared case-insensitively (IRC-style casefolding).
- Client connects to server via TCP
- Client completes registration (PASS, NICK, USER)
- Server stores client state and assigns nickname
- Client joins a channel (#test)
- Messages (PRIVMSG) are broadcast to all channel members
Client → Server → Channel/User state → Broadcast
Implemented command handlers:
- Connection/session:
CAP(LS,END),PING,QUIT - Registration:
PASS,NICK,USER - Channels:
JOIN,PART - Messaging:
PRIVMSG,NOTICE - Moderation/admin:
KICK,MODE,TOPIC,INVITE
Supported channel modes:
+i/-i: invite-only channel+t/-t: topic change restricted to operators+k <key>/-k: channel key+o <nick>/-o <nick>: grant/revoke operator+l <limit>/-l: user limit
Examples of handled replies/errors:
- Welcome/topic/names:
001,331,332,353,366 - Common errors:
401,403,404,411,412,421,431,432,433 - Channel/operator errors:
441,442,443,461,471,472,473,475,476,482 - Registration/auth errors:
451,462,464
See include/NumericReplies.hpp for the complete list used by the server.
Main components:
Server: socket setup, poll loop, dispatch, cleanup, channel/client registriesClient: per-connection identity + registration flags + I/O buffersChannel: members, operators, invites, topic, and mode stateCommand: parsed command name and parametersUtils: validation and helper functions (nick/channel checks, casefolding, etc.)
Code layout:
src/Authentication.cpp- registration and nick/user/pass validationsrc/ChannelCommands.cpp- join/part/names/topic listing logicsrc/MessagingCommands.cpp- user/channel messagingsrc/OperatorCommands.cpp- mode/topic/invite/kick handlingsrc/ServerCommands.cpp- dispatch, numeric replies, CAP/PING/QUIT, broadcastsrc/Server.cpp- event loop, connection handling, parser, teardown
- Client disconnect cleanup removes membership/invite state before erasing client data.
- Broadcast/name-list paths guard against stale member entries.
- Server ignores
SIGPIPEto avoid process termination on broken sockets.
This project intentionally focuses on core IRC behavior and does not aim to be a full production IRC daemon.
Potential limitations may include:
- No TLS
- No server-to-server networking
- No persistence
- Limited subset of IRC commands/capabilities compared to full RFC implementations
This project was developed as part of a team collaboration.
The original repository is private and not publicly accessible.
- Implemented the core IRC command handling (JOIN, PRIVMSG, MODE, etc.)
- Developed server-side logic for command parsing, validation, and execution
- Contributed to overall server architecture and behavior
My teammate focused on:
- Establishing network connections
- Managing incoming client connections and low-level I/O