Last Updated: 2025-04-05
- Introduction
- Project Overview
- Features
- Implementation Details
- Network Programming Concepts
- Project Constraints
- Building and Running
- Commands
- Architecture
- Future Improvements
- Credits
This project implements an IRC (Internet Relay Chat) server from scratch in C++. IRC is a text-based communication protocol that facilitates communication in the form of text messages between clients in a client-server networking model.
The server handles multiple clients simultaneously, manages channels, and implements the core IRC commands according to RFC standards.
IRC (Internet Relay Chat) is one of the first chat protocols on the internet, dating back to 1988. This implementation follows the core principles of IRC while focusing on a C++98 compliant codebase with robust socket programming and concurrent client handling.
The server is built to handle:
- Multiple simultaneous client connections
- Channel creation and management
- Private messaging between users
- Channel operator privileges
- Various IRC commands as specified in the RFC standards
- User Authentication: Password-protected server access
- Nickname Management: Unique nickname assignment and validation
- Channel Operations: Create, join, leave, and manage channels
- Private Messaging: Direct communication between users
- Channel Modes: Support for various channel modes including:
- Invite-only channels
- Topic restrictions
- Channel password protection
- User limits
- Operator privileges
- Network Communication: Robust socket programming with polling mechanisms
- Command Processing: Full parsing and execution of IRC commands
- Error Handling: RFC-compliant error responses
-
Server Class
- Manages the main server loop
- Handles client connections using poll()
- Processes incoming messages and dispatches commands
-
Client Class
- Represents a connected user
- Stores user information (nickname, username, etc.)
- Tracks authentication state
-
Channel Class
- Manages channel properties and members
- Handles channel modes and operator privileges
- Controls access to channels based on various restrictions
The server uses Berkeley sockets API for network communication:
- Socket creation and binding
- Setting up listening sockets
- Accepting new connections
- Non-blocking I/O with poll() for handling multiple clients
Commands are processed using a command dispatcher pattern:
- Each IRC command maps to a specific handler method
- Command arguments are parsed and validated
- Appropriate responses are generated according to RFC specifications
The server utilizes TCP/IP sockets to establish reliable, connection-oriented communication with clients. Key socket-related functions used include:
socket()
: Creates an endpoint for communicationbind()
: Assigns a local address to a socketlisten()
: Marks a socket as passive, ready to accept connectionsaccept()
: Accepts a connection on a socketsend()/recv()
: Transmits and receives data
Rather than creating a thread for each client (which would violate the project constraints), the server uses poll()
to multiplex I/O operations:
- Monitors multiple file descriptors simultaneously
- Efficiently handles many connections with a single thread
- Avoids blocking operations that would halt the entire server
This implementation adheres to strict project requirements:
- C++ Standard: Limited to C++98 standard
- External Libraries: No external libraries beyond standard C/C++ libraries and system calls
- Threading: No threads or fork (single process using poll() for concurrency)
- Memory Management: No memory leaks or undefined behaviors
- Error Handling: Robust error handling for all network operations
- RFC Compliance: Implementation follows RFC 1459 and related RFC documents for IRC protocol
- c++/g++ GCC/Clang compiler with C++98 support
- Linux/Unix environment (for socket APIs)
make
# IRC Server
## Running the Server
./ircserv <port> <password>
Where:
<port>
: The port number the server will listen on<password>
: Password required for clients to connect to the server
You can connect using any standard IRC client:
nc <server_ip> <port>
# Then authenticate with:
PASS <password>
NICK <your_nickname>
USER <username> 0 * :<realname>
The server supports the following IRC commands:
Command | Format | Description |
---|---|---|
PASS | PASS <password> |
Set connection password |
NICK | NICK <nickname> |
Set or change nickname |
USER | USER <username> <mode> <unused> :<realname> |
Set user information |
JOIN | JOIN <channel>{,<channel>} [<key>{,<key>}] |
Join channel(s) with optional key(s) |
PART | PART <channel>{,<channel>} [<message>] |
Leave channel(s) |
PRIVMSG | PRIVMSG <target> :<message> |
Send message to user or channel |
QUIT | QUIT [<message>] |
Disconnect from server |
KICK | KICK <channel> <user> [<comment>] |
Remove user from channel |
INVITE | INVITE <nickname> <channel> |
Invite user to channel |
TOPIC | TOPIC <channel> [:<topic>] |
Set or view channel topic |
MODE | MODE <target> <modes> [<mode-params>] |
Change channel or user mode |
PING | PING <server> |
Test connection to server |
PONG | PONG <server> |
Reply to PING message |
Mode | Parameter | Description |
---|---|---|
i | None | Set/remove Invite-only channel |
t | None | Set/remove restrictions of TOPIC command |
k | Key | Set/remove channel key (password) |
o | Nickname | Give/take channel operator privileges |
l | Limit | Set/remove user limit to channel |
┌────────────┐ ┌────────────┐
│ Server │◄─────►│ Client │
└────────────┘ └────────────┘
▲ ▲
│ │
│ │
▼ │
┌────────────┐ │
│ Channel │◄────────────┘
└────────────┘
- Server: Central class managing connections and dispatching commands
- Client: Represents a connected user with their state
- Channel: Handles channel operations and membership
- Client connects to server
- Server authenticates client (PASS, NICK, USER)
- Client joins channels or sends messages
- Server routes messages to appropriate clients
- Server handles administrative commands and channel operations
- File transfer capabilities
- SSL/TLS support for secure connections
- More extensive channel modes
- Bot support for automated operations
- Web interface for server administration
Developed by @saifeddineelhanoune @Da-ghost42
Project completed as part of advanced networking programming studies.
© 2025 - IRC Server Implementation - Version 1.0