Skip to content

Univers42/ft_irc

Repository files navigation

This project has been created as part of the 42 curriculum by dlesieur.

ft_irc

Description

ft_irc is an IRC (Internet Relay Chat) server implemented in C++98. It follows the IRC protocol (RFC 2812) and is designed to work with HexChat as the reference client. The server handles multiple simultaneous clients using non-blocking I/O with epoll(), supports authentication, channel management, private messaging, and operator commands.

Features

  • Authentication: Password-protected server with PASS/NICK/USER registration
  • Channels: Create, join, and manage IRC channels with # prefix
  • Private messaging: PRIVMSG and NOTICE between users
  • Channel operators: KICK, INVITE, TOPIC, and MODE commands
  • Channel modes: +i (invite-only), +t (topic restricted), +k (key/password), +o (operator), +l (user limit)
  • Bonus: Bot — Built-in ircbot that responds to !help, !time, !info, !joke
  • Bonus: File transfer — DCC handshake relay and an original server-mediated FILE protocol (base64 relay with validation, flow control and timeouts)
  • Partial message reassembly: Handles fragmented TCP data correctly
  • Ping/Pong keepalive: Automatic timeout detection
  • Hardened: ascii casemapping, CR/LF/NUL line-injection sanitizer, SENDQ + connection caps, bounded MODE/TOPIC/KEY parameters, timing-safe password check

Instructions

Compilation — build tiers

make mandatory  # strictly the subject's mandatory part (pure RFC kernel)
make bonus      # mandatory + subject bonus (bot, FILE transfer)
make            # full (default): bonus + optional platform extras
make clean      # Remove object files
make fclean     # Remove object files and binary
make re         # Full rebuild (full tier)
make test       # Build & run the test suite (Google Test, 138 assertions)

All three tiers produce the same ircserv binary name from the same kernel sources; they differ only in which extensions are linked (per-tier object dirs, one registerExtensions() translation unit each — see src/tiers/). Evaluation note: the default make includes the extras, but they are dead code without the FT_IRC_CONFIG environment variable — a scripted session transcript is byte-identical across all three binaries. Use make mandatory to demonstrate the strict subject build.

Running

./ircserv <port> <password>
  • port: The TCP port to listen on (e.g., 6667)
  • password: Connection password required by clients

Running with Docker

The whole stack — the C++ server plus the Claude-backed AI companion — runs with one command. Docker and Compose v2 required.

cp .env.example .env          # then set ANTHROPIC_API_KEY (and a password)
docker compose up --build

This starts ircserv (published on ${IRC_PORT:-6667}) and the ai-assistant companion, which connects to the server over the compose network, joins $IRC_CHANNELS, and answers when addressed (!ai …, assistant: …, or a direct message). Secrets live only in the gitignored .env.

Server only, no companion:

docker build -t ircserv .
docker run --rm -p 6667:6667 ircserv 6667 mypassword

Run the test suite in a clean container:

docker build --target test -t ircserv-test .

The ai-assistant is a separate process (see companions/ai-assistant/), not part of the C++98 server or its 42 build — the server stays subject-clean and is unaware the companion is AI. See that directory's README for how it works.

Optional real-time / web tier

docker compose --profile platform up --build

Adds two more services: realtime-agnostic (a Rust WebSocket pub/sub fan-out engine with database change-capture, pinned to an immutable digest and published on the host at ${REALTIME_PORT:-4455} → container 4000) and realtime-bridge — a companion that mirrors IRC and realtime in both directions. IRC channel messages are published to realtime (so browser / WebSocket clients and DB-CDC consumers see live IRC), and realtime chat events (browser publishes under irc-in/<channel>) are injected back into IRC, each web user appearing under its own IRC nick via a short-lived puppet connection; pg/** / mongo/** CDC events inject via the rtbridge service. Both directions are verified end-to-end. The default docker compose up is unchanged; this tier is purely additive and outside the 42 build. See companions/realtime-bridge/.

Connecting with HexChat

  1. Open HexChat → Add a new network
  2. Set server address to 127.0.0.1/6667
  3. Set the server password to the password you used when starting ircserv
  4. Connect — you should see the welcome message

Testing with netcat

nc -C 127.0.0.1 6667
PASS mypassword
NICK mynick
USER myuser 0 * :My Real Name
JOIN #test
PRIVMSG #test :Hello!
QUIT :bye

Resources

AI Usage

AI (GitHub Copilot with Claude) was used as a programming assistant for:

  • Planning the project architecture and identifying required IRC numerics for HexChat compatibility
  • Generating boilerplate code for class declarations and socket setup
  • Implementing IRC command handlers based on RFC 2812 specifications
  • Debugging protocol compliance issues during testing

About

IRC from (internet relay chat) is text-based protocol communication in the internet. It offers real-time messaging that can be either public or pivate. Users can excange message and direct messages and join group channels

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors