A fully functional IRC Server implementation in C++98 following the IRC protocol standards
Features • Installation • Usage • Commands • Bot • Architecture
- 🎯 Project Overview
- ✨ Features
- 🚀 Installation
- 💻 Usage
- 🎮 IRC Commands
- 🤖 IRC Bot
- 🏗️ Architecture
- 📁 Project Structure
- 🧪 Testing
- 🔧 Troubleshooting
- 📚 Resources
ft_irc is a robust IRC (Internet Relay Chat) server implementation built from scratch in C++98. This project creates a multi-client chat server that follows the IRC protocol standards, allowing users to connect with standard IRC clients and enjoy real-time communication through channels and private messages.
- ✅ Implement a fully functional IRC server
- ✅ Support multiple simultaneous clients
- ✅ Handle channel management with operators
- ✅ Process IRC commands according to RFC standards
- ✅ Maintain stability and performance under load
- Multi-client Support: Handle unlimited simultaneous connections
- Non-blocking I/O: Efficient event-driven architecture using
poll() - Password Authentication: Secure server access
- Channel Management: Create, join, and manage chat channels
- User Roles: Regular users and channel operators
- Private Messaging: Direct user-to-user communication
- Channel Creation: Automatic channel creation on first join
- Operator System: First user becomes channel operator
- Channel Modes:
+i- Invite-only channel+t- Topic restriction to operators+k- Channel password protection+l- User limit+o- Operator privileges
| Command | Description | Usage |
|---|---|---|
PASS |
Server authentication | PASS <password> |
NICK |
Set nickname | NICK <nickname> |
USER |
Set user information | USER <username> 0 * :<realname> |
JOIN |
Join channel | JOIN #<channel> [password] |
PART |
Leave channel | PART #<channel> |
PRIVMSG |
Send message | PRIVMSG <target> :<message> |
KICK |
Remove user | KICK #<channel> <user> [reason] |
INVITE |
Invite user | INVITE <user> #<channel> |
TOPIC |
Set/view topic | TOPIC #<channel> [new topic] |
MODE |
Change modes | MODE #<channel> <+/-><mode> [params] |
NAMES |
List users | NAMES #<channel> |
- IRC Bot: Automated bot with jokes and commands
- File Transfer: DCC SEND support (bonus)
- Signal Handling: Graceful shutdown on SIGINT/SIGTERM
# Required
- C++ compiler with C++98 support
- Make
- Unix-like system (Linux/macOS)
# Optional (for testing)
- IRC client (irssi, HexChat, WeeChat, etc.)
- netcat (nc) for basic testing-
Clone the repository
git clone <repository-url> cd ft_irc
-
Compile the server
make
-
Compile the bot (bonus)
make bonus # or cd bot && make
make # Build server only
make bonus # Build server + bot
make clean # Remove object files
make fclean # Remove all built files
make re # Rebuild everything./ircserv <port> <password>Parameters:
port: Port number (1024-65535)password: Connection password for clients
Example:
./ircserv 6667 mypassword123./ircbot <port> <password>The bot will automatically connect to 127.0.0.1 and join the #bot channel.
irssi
/connect localhost 6667 mypassword123
/nick YourNickname
/join #general- Add new network:
localhost/6667 - Set password:
mypassword123 - Connect and join channels
nc localhost 6667
PASS mypassword123
NICK testnick
USER testuser 0 * :Test User
JOIN #test
PRIVMSG #test :Hello World!PASS <password>
Must be sent before NICK and USER commands.
NICK <nickname>
Sets your nickname. Must be unique on the server.
USER <username> <hostname> <servername> :<realname>
Completes the registration process.
JOIN #<channel> [password]
- Creates channel if it doesn't exist
- First user becomes operator
- Password required if channel has
+kmode
PART #<channel>
Leaves the specified channel.
TOPIC #<channel> # View current topic
TOPIC #<channel> :New topic # Set new topic (operators only if +t)
PRIVMSG #<channel> :Hello everyone! # Channel message
PRIVMSG <nickname> :Private message # Private message
KICK #<channel> <nickname> :Reason for kick
Removes a user from the channel (operators only).
INVITE <nickname> #<channel>
Invites a user to the channel.
MODE #<channel> +i # Set invite-only
MODE #<channel> -i # Remove invite-only
MODE #<channel> +t # Topic restricted to operators
MODE #<channel> +k password # Set channel password
MODE #<channel> +l 50 # Set user limit to 50
MODE #<channel> +o nickname # Give operator status
MODE #<channel> -o nickname # Remove operator status
NAMES #<channel>
Shows all users in the channel. Operators are prefixed with @.
The IRC bot is an automated client that connects to your server and provides interactive commands.
- Automatic Connection: Connects to server on startup
- Command Processing: Responds to
!prefixed commands - Joke Database: Built-in programming jokes
- Channel Management: Automatically joins
#botchannel
| Command | Description | Example |
|---|---|---|
!help |
Show available commands | !help |
!ping |
Responds with "Pong!" | !ping |
!pong |
Responds with "Ping!" | !pong |
!hi |
Greets the user | !hi |
!joke |
Tells a random programming joke | !joke |
<YourNick> !hi
<ircbot> Hello YourNick! How are you doing?
<YourNick> !joke
<ircbot> Why don't programmers like nature? It has too many bugs!
<YourNick> !help
<ircbot> Available commands: !help, !ping, !pong, !hi, !joke
The bot connects to 127.0.0.1 by default. To modify:
- Edit
bot/src/main.cpp - Change the server address in the Bot constructor
- Recompile with
make bonus
- Purpose: Main server management and client handling
- Key Features:
- Socket creation and binding
- Client connection acceptance
- Command parsing and routing
- Signal handling for graceful shutdown
- Purpose: Individual client connection management
- Key Features:
- Connection state tracking
- Authentication status
- Input/output buffering
- User information storage
- Purpose: Chat channel management
- Key Features:
- Member list management
- Operator privileges
- Channel modes and settings
- Topic management
graph TD
A[Client Connection] --> B[Authentication]
B --> C[Command Processing]
C --> D{Command Type}
D -->|Channel| E[Channel Operations]
D -->|Private| F[Direct Messaging]
D -->|Server| G[Server Management]
E --> H[Broadcast to Channel]
F --> I[Send to Target]
G --> J[Server Response]
- Server Socket: Listens for incoming connections
- Poll Loop: Monitors all file descriptors for activity
- Event Processing: Handles read/write events
- Command Router: Dispatches commands to handlers
- Response System: Sends replies back to clients
ft_irc/
├── 📄 Makefile # Build configuration
├── 📄 README.md # This file
├── 📁 include/ # Header files
│ ├── 📄 Server.hpp # Server class definition
│ ├── 📄 Client.hpp # Client class definition
│ ├── 📄 Channel.hpp # Channel class definition
│ └── 📄 Bot.hpp # Bot class definition
├── 📁 src/ # Source files
│ ├── 📄 main.cpp # Server entry point
│ ├── 📄 Server.cpp # Server implementation
│ ├── 📁 classes/ # Class implementations
│ │ ├── 📄 Client.cpp # Client implementation
│ │ └── 📄 Channel.cpp # Channel implementation
│ ├── 📁 commands/ # IRC command handlers
│ │ ├── 📄 CommandParser.cpp # Command parsing
│ │ ├── 📁 authentication/ # Auth commands
│ │ │ ├── 📄 Pass.cpp # PASS command
│ │ │ ├── 📄 Nick.cpp # NICK command
│ │ │ ├── 📄 User.cpp # USER command
│ │ │ └── 📄 Quit.cpp # QUIT command
│ │ ├── 📁 channel/ # Channel commands
│ │ │ ├── 📄 Join.cpp # JOIN command
│ │ │ ├── 📄 Part.cpp # PART command
│ │ │ ├── 📄 Topic.cpp # TOPIC command
│ │ │ ├── 📄 Names.cpp # NAMES command
│ │ │ ├── 📄 Kick.cpp # KICK command
│ │ │ ├── 📄 Invite.cpp # INVITE command
│ │ │ └── 📄 Mode.cpp # MODE command
│ │ └── 📁 messaging/ # Message commands
│ │ └── 📄 Privmsg.cpp # PRIVMSG command
└── 📁 bot/ # IRC Bot (bonus)
├── 📄 Makefile # Bot build config
├── 📁 include/ # Bot headers
│ └── 📄 Bot.hpp # Bot class definition
└── 📁 src/ # Bot source files
├── 📄 main.cpp # Bot entry point
└── 📄 Bot.cpp # Bot implementation
./ircserv 6667 testpass
# Should start without errors and listen on port 6667# Terminal 1: Start server
./ircserv 6667 testpass
# Terminal 2: Connect with netcat
nc localhost 6667
PASS testpass
NICK testuser
USER testuser 0 * :Test User
# Should receive welcome messages# After connecting:
JOIN #test
PRIVMSG #test :Hello World!
NAMES #test
TOPIC #test :Test Channel Topic
# Test all commands systematically# Terminal 1: Start server
./ircserv 6667 testpass
# Terminal 2: Start bot
./ircbot 6667 testpass
# Terminal 3: Connect as user and test bot
nc localhost 6667
PASS testpass
NICK testuser
USER testuser 0 * :Test User
JOIN #bot
PRIVMSG #bot :!help
PRIVMSG #bot :!joke# Use this script to test multiple connections
for i in {1..10}; do
(echo -e "PASS testpass\nNICK user$i\nUSER user$i 0 * :User $i\nJOIN #stress\nPRIVMSG #stress :Hello from user $i\nQUIT" | nc localhost 6667) &
done# Test handling of partial messages (as per subject requirements)
nc -C localhost 6667
# Send: com^D (Ctrl+D)
# Send: man^D
# Send: d^D
# Should handle partial command properly# Problem: Port is still bound from previous run
# Solution: Wait or kill existing process
lsof -ti:6667 | xargs kill -9
# Or use a different port
./ircserv 6668 testpass# Check if server is running
ps aux | grep ircserv
# Check if port is open
netstat -tlnp | grep 6667
# Ensure firewall allows connections
sudo ufw allow 6667# Ensure server is running first
./ircserv 6667 testpass
# Check bot connection
./ircbot 6667 testpass
# Bot should show "Connected to server" message# Ensure you're not trying to bind to privileged ports (<1024) without sudo
# Use ports >= 1024
./ircserv 8080 testpassEnable debug output by uncommenting debug statements in the source code:
// In CommandParser.cpp
std::cout << "Parse Command : " << message << std::endl;# Compile with debug flags
make CFLAGS="-g -fsanitize=address"
# Run with valgrind
valgrind --leak-check=full ./ircserv 6667 testpass- RFC 1459 - Internet Relay Chat Protocol
- RFC 2812 - Internet Relay Chat: Client Protocol
- IRC Numeric Replies
- IRC Client Testing - HexChat IRC Client
- Command Reference - Modern IRC Documentation
- Protocol Testing - IRCv3 Test Networks
Made with ❤️ by [Haithem (0xk4g3) & zabdirak & raouf]
This project demonstrates advanced C++ programming, network protocols, and system programming concepts.
- ✅ C++98 Standard: All code follows C++98 specifications
- ✅ No External Libraries: Only standard C++98 and allowed system calls
- ✅ Non-blocking I/O: Uses poll() for efficient event handling
- ✅ Multi-client Support: Handles multiple simultaneous connections
- ✅ IRC Protocol: Implements required IRC commands and responses
- ✅ Memory Management: Proper cleanup and leak prevention
- ✅ Error Handling: Robust error checking and graceful failure
-
✅ IRC Bot: Interactive bot with command system
-
✅ File Transfer: Basic DCC SEND support
-
✅ Signal Handling: Graceful shutdown capabilities
-
✅ Extended Commands: Additional IRC command support
-
Performance monitoring and metrics
*Happy Coding! �