This project has been created as part of the 42 curriculum by joolibar, mcullell, carlopez.
One poll() call. Every read, every write, every new connection — all of it, through the same one.
A real IRC server, and a subject that fails you outright for reaching for a second one.
📜 Context •
🧩 Modules •
📋 Commands •
🏗️ Architecture
🧪 Testing •
💻 Usage •
📚 Resources
"Only 1 poll() (or equivalent) can be used for handling all these operations (read, write, but also listen, and so forth)."
ft_irc is a real IRC server, built from raw sockets up, in C++98. Not a toy protocol — a real client (Irssi, HexChat, whatever gets picked as the reference) has to be able to connect, authenticate, join channels, message people, and have operators kick and invite, without knowing it's talking to something built from scratch for a school project.
No forking, no threads, and no blocking calls anywhere. Every client's read, every client's write, and the server's own listening socket all funnel through a single poll() loop — the subject is explicit that touching a file descriptor outside of it isn't a shortcut, it's a different, non-functional program.
Built as a team of three: joolibar, mcullell, and carlopez.
Two builds: the server itself, and a bot that talks to it like any other client would.
- The Server (Mandatory): Sockets, one
poll()loop, command parsing, channels, and operator privileges. - The Bot (Bonus): An independent IRC client, written to connect to the server and act as a channel assistant.
Click on each module below to view network architectures and protocol event loops.
🔌 Module I — The Server (Mandatory)
A command typed as
com, thenman, thend\n— three separate packets — has to arrive at the server as one command. That's the actual test.
- ✂️ Dynamic
POLLOUTRegistration: Sockets subscribe to write-readiness events (POLLOUT) strictly on-demand when client egress buffers contain queued frames, preventing 100% CPU busy-polling on idle sockets. - 🧵 Stream Assembly & Byte Ring Buffering: TCP packet fragmentation and coalescing are handled via dedicated per-client ring buffers, demarcating RFC commands strictly upon trailing
\r\nor\nline terminators. - 🔑 RFC 2812 Registration Handshake: Enforces a three-stage handshake pipeline (
PASS→NICK→USER), isolating unauthenticated sockets from accessing network broadcast channels. - 🏠 Dynamic Channel Allocation & Autonomous Chanopping: Instantiates channel entities on-demand via the first joining client, atomically granting channel operator privileges (
+o) to the creator. - 🔀 Vectorized Channel Routing: Supports comma-delimited multi-target
JOINvectors with aligned key lists (JOIN #chan1,#chan2 key1,key2), validating access keys and capacity limits in single-pass evaluation. - 👑 Privilege-Gated Administrative Primitives: Commands requiring channel ownership (
KICK,INVITE,TOPIC +t,MODE) enforce role-based access control, dispatching standard RFC numeric errors (ERR_CHANOPRIVSNEEDED) upon unauthorized invocation. - ⚙️ Compound Mode Mutation & Consolidated Broadcasts: Parses and validates composite channel modes (
+itklo) with variable parameters in single commands, consolidating state mutations into unified channel broadcast frames.
🤖 Module II — The Bot (Bonus)
"HelpBot" connects like any other client — same PASS, same NICK, same USER — because as far as the server's concerned, it is one.
- 🔐 Autonomous TCP Client Process: Operates as a completely decoupled network client via an independent POSIX socket and standard RFC registration handshake, without kernel hooks or server-side introspection.
- 🔁 Conflict-Resilient Nickname Arbitration: Handles numeric error
433(ERR_NICKNAMEINUSE) through exponential suffixing retry strategies, maintaining connection persistence during namespace collisions. - 👋 Event-Driven Channel Greetings: Intercepts incoming channel
JOINnotifications to dispatch contextual welcoming messages directing new arrivals to service dispatchers. - 📖 Interactive Command Dispatcher (
!help,!status): Provides realtime telemetry (server connection latency, process uptime, host machine timestamps) and responsive command documentation. - 💤 Graceful TCP Connection Teardown: Signal interceptors (
SIGINT,SIGQUIT) cleanly emit RFCQUITprotocol frames prior to socket shutdown, preventing orphaned half-open TCP connections on the server.
Sixteen commands, one file per command in src/commands/:
| Command | What it does |
|---|---|
PASS | Authenticates the connection with the server's password |
NICK | Sets or changes the client's nickname |
USER | Registers username, hostname, and real name |
CAP | Capability negotiation handshake with the client |
PING | Keeps the connection alive, expects a PONG back |
QUIT | Disconnects from the server |
JOIN | Joins one or more channels, creating them if they don't exist |
PART | Leaves one or more channels |
TOPIC | Views or changes a channel's topic |
INVITE | Invites a user to a channel (operators only, if invite-restricted) |
KICK | Removes a user from a channel (operators only) |
MODE | Changes channel modes: i, t, k, l, o (operators only) |
LIST | Lists visible channels |
WHOIS | Looks up information about a user |
PRIVMSG | Sends a message to a user or a channel |
NOTICE | Sends a message that never triggers an automatic reply |
One line in from a socket becomes one parsed command, dispatched to whichever handler owns it, and one or more lines of output queued back out — the same pipeline whether it's PASS or MODE.
Raw bytes → Per-client buffer → Full line extracted → Parser → Command handler → Output buffer → poll() sends it
ft_irc/
├── inc/
│ ├── commands/
│ │ ├── Commands.hpp
│ │ └── Parser.hpp
│ ├── core/
│ │ ├── Server.hpp
│ │ └── ServerConfig.hpp
│ ├── models/
│ │ ├── Channel.hpp # Membership, operators, modes, broadcasting
│ │ └── Client.hpp # Per-connection state, input/output buffers
│ ├── utils/
│ │ ├── Logger.hpp
│ │ ├── Replies.hpp # RFC numeric reply macros
│ │ └── Styles.hpp
│ └── Bot_bonus.hpp
├── src/
│ ├── commands/ # One .cpp per IRC command (16 total)
│ ├── core/
│ ├── models/
│ ├── utils/
│ └── main.cpp
├── src_bonus/
│ └── Bot_bonus.cpp
├── tests/
│ ├── test_mandatory.cpp
│ └── test_bonus.cpp
├── config/
├── ircserv.conf
└── Makefile
- Transparent CTCP & DCC Direct Client-to-Client File Streaming:
PRIVMSGforwards raw payloads transparently without protocol mutation, allowing clients to negotiate direct peer-to-peer DCC file transfers through standard CTCP wrapping without server-side payload overhead. - Zero-Blocking Reactor Event Loop: Every I/O operation on file descriptors is mediated by a single non-blocking
poll()multiplexer, enforcing strict zero-thread and zero-fork concurrency. - Resilient Process Suspension Management: Intercepts
SIGCONTto preserve operational telemetry without terminating the reactor loop when resuming from background pause states.
"Use ctrl+D to send the command in several parts: 'com', then 'man', then 'd\n'." The subject's own test for whether the buffering actually works.
Verification has been manual throughout, backed by the tests/ suite for repeatable checks, and run primarily against Irssi and netcat — with additional spot-checks against HexChat to confirm behavior held on a graphical client too, not just a terminal one. That exact fragmentation test gets run directly, confirming the per-client buffer reassembles the pieces correctly before dispatching. Beyond that, testing covers the full registration sequence, channel creation and joining (including the comma-separated multi-channel form), every operator-restricted command rejecting a non-operator, and each MODE flag individually and combined.
- Compiler Flags: compiled strictly with
-Wall -Wextra -Werror, verified to also compile clean under-std=c++98. - No linter: compiler warnings are the only automated check this project has.
Make sure you have a C++ compiler (c++ or clang++) and make installed, then clone the repository:
git clone https://github.com/joolibar/ft_irc.git
cd ft_ircmake # Compiles the server
make bonus # Compiles the botRun the server, then connect with a reference IRC client:
./ircserv 6667 my_passwordRun the bot against a live server:
./ircbot 6667 my_passwordBeyond the subject itself, these were the references we kept coming back to while building the protocol and networking layers:
- cppreference.com. (n.d.). C++ reference. https://en.cppreference.com/w/
- Hall, B. J. (2016). Beej's guide to network programming: Using Internet sockets. Jorgensen Publishing. https://beej.us/guide/bgnet/
- ircdocs. (n.d.). Modern IRC client protocol. https://modern.ircdocs.info/
- Kalt, C. (2000a). Internet Relay Chat: Channel management (RFC No. 2811). Internet Engineering Task Force. https://doi.org/10.17487/RFC2811
- Kalt, C. (2000b). Internet Relay Chat: Client protocol (RFC No. 2812). Internet Engineering Task Force. https://doi.org/10.17487/RFC2812
- Kerrisk, M. (n.d.). poll(2) — Linux manual page. Linux Man-Pages Project. https://man7.org/linux/man-pages/man2/poll.2.html
- Oikarinen, J., & Reed, D. (1993). Internet Relay Chat protocol (RFC No. 1459). Internet Engineering Task Force. https://doi.org/10.17487/RFC1459
AI was used deliberately and selectively — as a learning aid, not a substitute for understanding the code we shipped:
- Concept deepening: used as a reference to build a real understanding of ideas the team hadn't worked with before — non-blocking I/O,
poll(), and the IRC protocol itself — before writing any code around them. - Debugging: used to help track down and diagnose bugs once something didn't behave as expected, narrowing down where in the codebase an issue actually lived.
- Test design: used to help think through test cases while validating the server's behavior against the subject's requirements.
Every piece of core network logic — the event loop, the parser, the channel and client models — was written and understood by the team, not generated wholesale.
"Non-blocking I/O, a single event loop —
multiplexing real-time communication without a single thread." 📡💬
Crafted by joolibar, mcullell & carlopez
joolibar's 42 journey — this one, built together with two teammates
© 2026 joolibar • Graded by peers, not scripts 🧑🤝🧑, crafted by Humans 🧠.