A custom IRC server implementation in C++98 that allows multiple clients to connect and communicate through channels and private messages.
- Overview
- Features
- Requirements
- Installation
- Usage
- Supported IRC Commands
- Channel Modes
- Testing
- Project Structure
- Team Members
This project implements an IRC (Internet Relay Chat) server following the IRC protocol specifications. The server can handle multiple simultaneous client connections without blocking, using non-blocking I/O operations and epoll for efficient event handling. Additionally, the project includes an IRC bot that connects to the server and can interact with users.
The implementation follows the C++98 standard and includes all mandatory IRC features plus bonus functionalities.
- ✅ Multi-client support - Handle multiple simultaneous connections
- ✅ Non-blocking I/O - Uses epoll for efficient event handling
- ✅ User authentication - Password-protected server access
- ✅ Channel management - Create, join, and manage channels
- ✅ Private messaging - Direct client-to-client communication
- ✅ Operator privileges - Channel operator system with special commands
- ✅ Channel creation - Automatic channel creation on first join
- ✅ Channel modes - Support for invite-only, topic restrictions, keys, and user limits
- ✅ Operator commands - KICK, INVITE, TOPIC, MODE
- ✅ Message broadcasting - Messages sent to all channel members
- ✅ Channel member management - Track and manage channel members and operators
- ✅ Channel topic system - View and modify channel topics with operator restrictions
- ✅ Channel invitation system - Invite-only channels with waitlist management
- ✅ Password protection - Server-wide password authentication
- ✅ Error handling - Comprehensive error responses following IRC standards
- ✅ Memory management - No memory leaks, proper resource cleanup
- ✅ Partial message handling - Handles TCP packet fragmentation
- ✅ Logging system - Comprehensive logging for debugging and monitoring
- ✅ Input validation - Strict nickname and command parameter validation
- Compiler: c++ with C++98 standard support
- Operating System: Unix-like systems (Linux, macOS)
- Dependencies: Standard C++ libraries only (no external libraries)
- IRC Client: Any standard IRC client (HexChat, irssi, WeeChat, etc.)
-
Clone the repository:
git clone https://github.com/mchouikr/ft_irc.git cd ft_irc -
Compile the project:
make
This builds both the server (
ircserv) and the bot (ircbot). -
Clean build files (optional):
make clean # Remove object files make fclean # Remove object files and executable make re # Clean rebuild
./ircserv <port> <password>Parameters:
<port>: The port number for the IRC server (e.g., 6667)<password>: Connection password required by clients
Example:
./ircserv 6667 password./ircbot <port> <password> <nickname>Parameters:
<port>: The port number for the IRC server (e.g., 6667)<password>: Connection password required by clients<nickname>: The nickname for the bot (must be 1-9 chars, start with a letter or special char)
Example:
./ircbot 6667 password bot- Auto-connect and Authentication: The bot automatically connects to the server and authenticates using the provided password.
- Channel Interaction: The bot can join channels and respond to commands.
- Commands:
!help: Displays available commands.!say <message>: Repeats the message in the channel or private message.
- PING/PONG: The bot responds to server PING messages to maintain the connection.
- Logging: Comprehensive logging for debugging and monitoring.
PASS <password>- Authenticate with server passwordNICK <nickname>- Set or change nickname (must be 1-9 chars, start with letter or special char)USER <username> <hostname> <servername> <realname>- Set user informationCAP- Handle client capabilities negotiation
JOIN <channel> [key]- Join a channel (creates if doesn't exist)- Requires channel key if channel is password protected
- Cannot join if channel is invite-only without invitation
- Cannot join if channel is full (user limit reached)
PART <channel> [reason]- Leave a channelPRIVMSG <target> <message>- Send message to channel or userMSG <target> <message>- Alias for PRIVMSGNOTICE <target> <message>- Send notice to channel or userTOPIC <channel> [topic]- View or set channel topicNAMES <channel>- List users in a channel
KICK <channel> <user> [reason]- Remove user from channel (channel operator only)INVITE <user> <channel>- Invite user to channel (channel operator only)MODE <channel> <mode> [parameters]- Change channel modes (channel operator only)
PING <server>- Server ping (keep-alive)PONG <server>- Server pong responseDCC <type> <target> [params]- DCC message relay (forwards DCC messages between clients)
The server supports the following channel modes:
| Mode | Description | Usage |
|---|---|---|
+i |
Invite-only | MODE #channel +i |
+t |
Topic operator-only | MODE #channel +t |
+k |
Channel key (password) | MODE #channel +k password |
+o |
Operator privilege | MODE #channel +o username |
+l |
User limit | MODE #channel +l 10 |
Examples:
MODE #channel +i # Make channel invite-only
MODE #channel +k secretkey # Set channel password
MODE #channel +l 50 # Limit channel to 50 users
MODE #channel +o alice # Give operator status to alice
MODE #channel -i # Remove invite-only mode
# Terminal 1: Start server
./ircserv 6667 password
# Terminal 2: Connect client 1
nc -C localhost 6667
PASS password
NICK alice
USER alice 0 * :Alice User
JOIN #test
# Terminal 3: Connect client 2
nc -C localhost 6667
PASS password
NICK bob
USER bob 0 * :Bob User
JOIN #test
PRIVMSG #test :Hello everyone!nc -C localhost 6667
com^Dman^DdUse Ctrl+D to send the command in parts: 'com', then 'man', then 'd\n'.
- HexChat (GUI, user-friendly)
- irssi (terminal-based)
- WeeChat (terminal-based)
- IRCCloud (web-based)
ft_irc/
├── Makefile # Build configuration
├── server/ # Server component
│ ├── includes/ # Header files
│ │ ├── Server.hpp # Server class definition
│ │ ├── Client.hpp # Client class definition
│ │ ├── Channel.hpp # Channel class definition
│ │ ├── MessageHandler.hpp # Command processing
│ │ ├── ErrorsAndReplies.hpp # IRC response codes
│ │ └── Logger.hpp # Logging system
│ └── srcs/ # Source files
│ ├── main.cpp # Entry point
│ ├── Server.cpp # Server implementation
│ ├── Client.cpp # Client implementation
│ ├── Channel.cpp # Channel implementation
│ ├── MessageHandler.cpp # Command processing logic
│ └── Logger.cpp # Logging implementation
├── bot/ # Bot component
│ ├── includes/ # Header files
│ │ ├── Bot.hpp # Bot class definition
│ │ ├── ErrorsAndRepliesBot.hpp # Bot response codes
│ │ ├── Logger.hpp # Logging system
│ │ └── MessageHandler.hpp # Bot command processing
│ └── srcs/ # Source files
│ ├── main.cpp # Entry point
│ ├── Bot.cpp # Bot implementation
│ ├── MessageHandler.cpp # Bot command processing logic
│ └── Logger.cpp # Logging implementation
└── README.md # Project documentation
- IRC RFC 1459 - Original IRC Protocol
- IRC RFC 2812 - Internet Relay Chat: Client Protocol
- IRC Numeric Replies - Complete list of IRC response codes
This project was developed as part of the 42 School curriculum.