C++98 · TCP · poll() · 42 Common Core · team of two
ft_irc
An IRC server written from scratch in C++98 that real chat clients like irssi can connect to.
The problem
The problem
Serve many clients at once on one thread, speak the IRC protocol correctly, and manage channels with their modes and operators, without any IRC library.
What I built
- Non-blocking sockets driven by a single poll() loop.
- Registration with PASS, NICK and USER, private and channel messages with PRIVMSG.
- Channels with JOIN, PART, KICK, INVITE and TOPIC, and the modes i, t, k, o and l.
- Relaying of the DCC handshake so two clients can send each other files directly.
- Bonus: TimeBot, a bot that connects like any client and answers !time.
Technical decisions
- One poll() call for every connection instead of a thread per client.
- Works with a standard client (irssi) and with raw TCP (netcat), which makes the protocol easy to test by hand.
- For file transfer the server only relays the handshake; the clients connect to each other.
What makes it hard
- TCP delivers a stream, not messages: commands can arrive split or several at once and must be buffered per client.
- Keeping channel state right when people join, leave, get kicked or disconnect mid-command.
What I can do because of it
- Write a network server that handles many connections with non-blocking I/O.
- Implement a text protocol from its specification.
- Build it with a teammate: split the work and agree on interfaces.