Skip to content
joolibarPublic

About

A C++98 IRC server built on a single poll() loop with fully non-blocking I/O — authentication, channels, operators (KICK, INVITE, TOPIC, MODE), and private messaging over TCP/IP, tested against a real IRC client. Bonus: an autonomous bot. Team project.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

50 Commits

Folders and files

Repository files navigation

This project has been created as part of the 42 curriculum by joolibar, mcullell, carlopez.

ft_irc - One poll(), Every Client

​

Language Bonus Team

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


📜 The Context

"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.

🧩 The Modules

Two builds: the server itself, and a bot that talks to it like any other client would.

  1. The Server (Mandatory): Sockets, one poll() loop, command parsing, channels, and operator privileges.
  2. 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, then man, then d\n — three separate packets — has to arrive at the server as one command. That's the actual test.

  • ✂️ Dynamic POLLOUT Registration: 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\n or \n line 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 JOIN vectors 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 JOIN notifications 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 RFC QUIT protocol frames prior to socket shutdown, preventing orphaned half-open TCP connections on the server.

📋 Command Reference

Sixteen commands, one file per command in src/commands/:

Command What it does
PASSAuthenticates the connection with the server's password
NICKSets or changes the client's nickname
USERRegisters username, hostname, and real name
CAPCapability negotiation handshake with the client
PINGKeeps the connection alive, expects a PONG back
QUITDisconnects from the server
JOINJoins one or more channels, creating them if they don't exist
PARTLeaves one or more channels
TOPICViews or changes a channel's topic
INVITEInvites a user to a channel (operators only, if invite-restricted)
KICKRemoves a user from a channel (operators only)
MODEChanges channel modes: i, t, k, l, o (operators only)
LISTLists visible channels
WHOISLooks up information about a user
PRIVMSGSends a message to a user or a channel
NOTICESends a message that never triggers an automatic reply

🏗️ System Architecture

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.

🔄 The Pipeline

Raw bytes → Per-client buffer → Full line extracted → Parser → Command handler → Output buffer → poll() sends it

📂 Project Structure

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

🔩 Design Decisions

  • Transparent CTCP & DCC Direct Client-to-Client File Streaming: PRIVMSG forwards 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 SIGCONT to preserve operational telemetry without terminating the reactor loop when resuming from background pause states.

🧪 Testing & Validation

"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.

💻 Compilation & Usage

⚡ Installation

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_irc

🛠️ Usage

make          # Compiles the server
make bonus    # Compiles the bot

Run the server, then connect with a reference IRC client:

./ircserv 6667 my_password

Run the bot against a live server:

./ircbot 6667 my_password

📚 Resources

Beyond the subject itself, these were the references we kept coming back to while building the protocol and networking layers:

AI Usage Declaration

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."
 📡💬


Capybara
Crafted by joolibar, mcullell & carlopez
joolibar's 42 journey — this one, built together with two teammates

joolibar GitHub LinkedIn mcullell GitHub carlopez GitHub Return

© 2026 joolibar  •  Graded by peers, not scripts 🧑‍🤝‍🧑, crafted by Humans 🧠.


42 ft_irc Footer

About

A C++98 IRC server built on a single poll() loop with fully non-blocking I/O — authentication, channels, operators (KICK, INVITE, TOPIC, MODE), and private messaging over TCP/IP, tested against a real IRC client. Bonus: an autonomous bot. Team project.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages