An IRC server built from scratch in C++98, fully compatible with standard IRC clients like irssi. This project implements the core of the IRC protocol (inspired by RFC 2812), handling real-time multi-client communication through non-blocking I/O and the poll() system call.
A 42 School project.
Authors: Ayoub Diri · Mohammed Akarkaou · Youssef El Bouzidi
- Capability Handshake —
CAP LSsupport for modern IRC client negotiation - User Registration —
PASS,NICK,USERauthentication flow - Channel Management —
JOIN,PART,KICK,INVITE,TOPIC - Messaging —
PRIVMSGfor both channels and private DMs - Operator Privileges —
MODEwith support for+i,+t,+k,+o,+l - Connection Handling —
PING/PONGkeepalive,QUIT
- Non-blocking sockets with
poll()multiplexing - Buffered, event-driven I/O (
POLLIN/POLLOUT) - Handles partial reads and multi-command buffers
- Compatible with both
\r\n(IRC standard) and\n(netcat)
CalcBot 🤖 — A built-in channel bot that evaluates math expressions:
<user> !calc 42 + 13 - 5
<CalcBot> user, the answer to 42 + 13 - 5 is 50
DCC File Transfer — The server transparently relays CTCP/DCC messages between clients, enabling peer-to-peer file transfers through IRC clients like irssi.
- A C++98-compatible compiler (e.g.
g++,clang++) make- An IRC client (
irssirecommended) ornetcat
make
./ircserv <port> <password>Where:
portmust be between1024and65535passwordmust be1..128chars, without spaces/newlines
Example:
./ircserv 6667 mypasswordirssi -c 127.0.0.1 -p 6667 -w mypasswordnc localhost 6667
PASS mypassword
NICK mynick
USER mynick 0 * :My Name
JOIN #general
PRIVMSG #general :Hello, world!ft_irc/
├── includes/ # Header files
│ ├── Server.hpp # Server class with poll() event loop
│ ├── Client.hpp # Client state and buffered I/O
│ ├── Channel.hpp # Channel membership and modes
│ ├── Bot.hpp # CalcBot
│ ├── Parser.hpp # IRC message parser
│ ├── Commands.hpp # Command handler declarations
│ ├── Reply.hpp # IRC numeric reply formatting
│ └── Utils.hpp # String utilities
├── srcs/
│ ├── Server.cpp # Socket setup, poll loop, client management
│ ├── Client.cpp # Command routing and execution
│ ├── Channel.cpp # Channel operations and broadcasting
│ ├── Bot.cpp # Calculator bot logic
│ ├── Parser.cpp # RFC-compliant message parsing
│ ├── Reply.cpp # Reply/error code formatting
│ ├── Utils.cpp # Helper functions
│ ├── main.cpp # Entry point
│ └── Command/ # Individual command implementations
│ ├── Pass.cpp, Nick.cpp, User.cpp
│ ├── Join.cpp, Part.cpp, Kick.cpp
│ ├── Privmgs.cpp, Mode.cpp
│ ├── Ping.cpp, Quit.cpp
│ ├── invite.cpp, topic.cpp
│ └── Unknown.cpp
└── Makefile
| Command | Description |
|---|---|
CAP |
Capability negotiation (CAP LS implemented) |
PASS |
Set connection password |
NICK |
Set or change nickname |
USER |
Complete registration |
JOIN |
Join a channel |
PART |
Leave a channel |
KICK |
Remove a user from a channel |
INVITE |
Invite a user to a channel |
TOPIC |
View or set channel topic |
MODE |
Set channel/user modes (+i, +t, +k, +o, +l) |
PRIVMSG |
Send a message to a channel or user |
PING |
Connection keepalive |
QUIT |
Disconnect from the server |
- Registration requirement: clients must authenticate with
PASSbeforeNICK/USERare accepted. - Connection is fully registered only after both valid
NICKandUSERare set. - Nickname validation: max length
16, must start with a letter, then letters/digits/-/_. - Channel creation: first
JOIN #channelcreates the channel and makes that user channel operator. JOINrestrictions enforced:- invite-only (
+i) - user limit (
+l) - key-protected channel (
+k) viaJOIN #chan <key>
- invite-only (
TOPICwith+t: only channel operators can change topic.MODE #channelwith no extra args returns active channel modes.- Unknown commands return standard IRC
ERR_UNKNOWNCOMMAND. - Line handling: both
\r\n(IRC standard) and\nare accepted.
+i/-i— invite-only channel+t/-t— only operators may set topic+k <key>/-k— channel key+o <nick>/-o <nick>— give/remove channel operator+l <limit>/-l— user limit
- Built-in bot runs as
CalcBotand responds to!calcin channels. - CTCP/DCC payloads are relayed transparently through
PRIVMSG, enabling client-side DCC workflows.
- irssi v1.4.5
- netcat (
nc) - Verified on Linux (Ubuntu/Debian)