How hek3er/irc-serv works
Project Type and Purpose
• FT_IRC is a standalone C++ server application implementing the IRC protocol (RFC 2812).
• It provides a non‐blocking, event‐driven chat server that handles multiple concurrent clients, channels, and basic IRC commands (JOIN, PRIVMSG, KICK, INVITE, TOPIC, MODE, PASS, USER, NICK), plus DCC file transfers.
File Structure Analysis
• Top‐level source files grouped by responsibility:
• Channel.cpp/.hpp – channel state and management
• Client.cpp/.hpp – per‐connection client state
• Server.cpp/.hpp – listens on socket, accepts new connections, drives the event loop
• invite.cpp, join.cpp, kick.cpp, mode.cpp, topic.cpp – one module per IRC command/response logic
• replies.hpp – constant definitions for numeric reply codes
• main.cpp – parses CLI args (port, password), instantiates Server and starts it
• Build artifacts: Makefile; no external libraries beyond the C++ standard library and POSIX sockets.
Key Architectural Insights from README
• Non‐blocking I/O / Reactor pattern: single threaded event loop (select/poll)
• In‐memory data stores: containers mapping client fds → Client objects and channel names → Channel objects
• Modular command handlers invoked by a central dispatcher
• RFC compliance drives error codes and protocol parsing
Main Components
a. Network Layer (Server)
• Listener socket
• Event loop / Reactor (select, poll, or epoll)
b. Connection Manager (Client Manager)
• Accept new connections, track active client fds, client state (nick, user, modes)
c. Parser & Dispatcher
• Reads raw TCP data, parses IRC messages, routes to the appropriate command handler
d. Command Handlers
• JOIN, PRIVMSG, KICK, INVITE, TOPIC, MODE, PASS, USER, NICK, DCC module
e. Channel Manager
• Creates/tracks Channel objects, operator lists, topics, mode settings, password protection
f. Message Routing & Broadcast
• Delivers messages to single clients or all channel members
g. In‐Memory Data Stores
• <socket_fd, Client>
• <channel_name, Channel>
h. External Interfaces
• Reference IRC client (e.g., LimeChat or netcat)
• DCC file‐transfer peer‐to‐peer data channel
Relationships and Data Flows
• Listener → accept() → Connection Manager → register fd in Reactor
• Reactor signals “readable” → Server reads raw bytes → Parser → Dispatcher
• Dispatcher invokes specific Command Handler → Handler updates Client or Channel state → may generate outgoing messages
• Router sends replies via socket fds back to clients or broadcasts to channel members
Architectural Patterns & Design Principles
• Reactor Pattern for non‐blocking I/O
• Single Responsibility: each .cpp module handles one IRC command
• Inversion of Control: central dispatcher calls handlers based on command type
• Encapsulation of state: Client and Channel classes hold protocol state
Technologies & Frameworks
• C++98, STL containers (std::map, std::string)
• POSIX sockets API (socket, bind, listen, accept, fcntl, select/poll)
• Makefile build system