Skip to content

pquline/ft_irc

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ft_irc - Internet Relay Chat Server

A custom IRC server implementation in C++98 that allows multiple clients to connect and communicate through channels and private messages.

📋 Table of Contents

🌟 Overview

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.

✨ Features

Core IRC Functionality

  • 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 Features

  • 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

Security & Reliability

  • 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

🔧 Requirements

  • 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.)

🚀 Installation

  1. Clone the repository:

    git clone https://github.com/mchouikr/ft_irc.git
    cd ft_irc
  2. Compile the project:

    make

    This builds both the server (ircserv) and the bot (ircbot).

  3. Clean build files (optional):

    make clean    # Remove object files
    make fclean   # Remove object files and executable
    make re       # Clean rebuild

💻 Usage

Starting the Server

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

Starting the Bot

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

Bot Features

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

🎮 Supported IRC Commands

Authentication Commands

  • PASS <password> - Authenticate with server password
  • NICK <nickname> - Set or change nickname (must be 1-9 chars, start with letter or special char)
  • USER <username> <hostname> <servername> <realname> - Set user information
  • CAP - Handle client capabilities negotiation

Channel Commands

  • 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 channel
  • PRIVMSG <target> <message> - Send message to channel or user
  • MSG <target> <message> - Alias for PRIVMSG
  • NOTICE <target> <message> - Send notice to channel or user
  • TOPIC <channel> [topic] - View or set channel topic
  • NAMES <channel> - List users in a channel

Operator Commands

  • 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)

Utility Commands

  • PING <server> - Server ping (keep-alive)
  • PONG <server> - Server pong response
  • DCC <type> <target> [params] - DCC message relay (forwards DCC messages between clients)

⚙️ Channel Modes

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

🧪 Testing

Basic Functionality Test

# 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!

Partial Data Test

nc -C localhost 6667
com^Dman^Dd

Use Ctrl+D to send the command in parts: 'com', then 'man', then 'd\n'.

Recommended IRC Clients for Testing

  • HexChat (GUI, user-friendly)
  • irssi (terminal-based)
  • WeeChat (terminal-based)
  • IRCCloud (web-based)

📁 Project Structure

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

📚 Additional Resources

👥 Team Members

This project was developed as part of the 42 School curriculum.

About

A lightweight IRC server in C++, fully compatible with IRSSI.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 94.7%
  • Makefile 5.3%