IRC (Internet Relay Chat) is a networking project at 42 School that challenges students to implement a functional IRC server from scratch. This text-based communication protocol, created in 1988, remains a fundamental example of client-server architecture and real-time messaging systems.
"This project is about creating your own IRC server. You will use an actual IRC client to connect to your server and test it. Internet is ruled by solid standards protocols that allow connected computers to interact with each other."
This project explores socket programming, client-server architecture, protocol implementation, and concurrent programming concepts.
- Implement a fully functional IRC server according to RFC specifications
- Handle multiple client connections simultaneously using non-blocking I/O
- Process and respond to standard IRC commands
- Manage channels, private messages, operators, and user privileges
- Implement proper error handling and client validation
- Create a robust and scalable server architecture
- Gain deep understanding of network protocols and socket programming
IRC is a text-based communication protocol that follows a client-server model, allowing real-time messaging between users in channels or privately:
Feature | Description | Implementation |
---|---|---|
Text-based | Simple ASCII commands and responses | Easy to parse and generate |
Client-Server | Centralized architecture | Single server handles multiple clients |
Channel-based | Group conversations in named channels | Managed as collections of users |
User Roles | Operators with special privileges | Access control implementation |
Stateful | Server maintains user/channel state | In-memory data structures |
Command | Description | Example |
---|---|---|
NICK | Set or change username | NICK john_doe |
USER | Set user identity details | USER john 0 * :John Doe |
JOIN | Enter a channel | JOIN #general |
PRIVMSG | Send a message | PRIVMSG #general :Hello everyone! |
PART | Leave a channel | PART #general |
KICK | Remove a user from channel | KICK #general jane_doe |
MODE | Change channel/user modes | MODE #general +o john_doe |
QUIT | Disconnect from server | QUIT :Gone to lunch |
βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ
β Server βββββββΊβ Client βββββββΊβ Channel β
βββββββββ¬ββββββββ βββββββββββββββββ βββββββββββββββββ
β β² β²
β β β
βΌ β β
βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ
β CommandHandlerβββββββΊβ Message βββββββΊβ Logger β
βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ
irc/
βββ inc/ # Header files
β βββ Server.hpp # Server class declaration
β βββ Client.hpp # Client class declaration
β βββ Channel.hpp # Channel class declaration
β βββ CommandHandler.hpp # Command parsing and execution
β βββ Message.hpp # IRC message representation
β βββ utils.hpp # Utility functions
β
βββ src/ # Implementation files
β βββ main.cpp # Entry point
β βββ Server.cpp # Server implementation
β βββ Client.cpp # Client implementation
β βββ Channel.cpp # Channel implementation
β βββ CommandHandler.cpp # Command handling logic
β βββ Message.cpp # Message parsing and formatting
β βββ utils.cpp # Utility function implementations
β
βββ Makefile # Build configuration
βββ README.md # Project documentation
Component | Purpose | Implementation Approach |
---|---|---|
Server | Manages connections and routes messages | Socket programming with non-blocking I/O using select() |
Client | Represents a connected user | State machine tracking authentication and activity |
Channel | Manages group conversations | Collection of members with permission levels |
CommandHandler | Processes IRC commands | Command pattern with function map dispatch |
Message | Parses and formats IRC messages | RFC-compliant formatting and validation |
Aspect | Implementation | Notes |
---|---|---|
Socket Type | TCP/IP | Reliable, ordered delivery |
I/O Model | Non-blocking with select() | Efficient handling of multiple clients |
Buffer Management | Input/output queues per client | Handles partial reads/writes |
Connection State | State tracking per client | Registration, authentication, channels |
My implementation focuses on correctness, performance, and maintainability:
- Event-driven model for high concurrency
- Non-blocking I/O for efficient resource usage
- Modular class design for maintainability
- Separation of concerns between components
- RFC 1459/2812 implementation
- Proper error codes and messages
- Complete command set support
- Input validation and sanitization
- Efficient data structures for user and channel lookup
- Minimal memory footprint per connection
- Optimized message parsing and generation
- Connection timeouts and resource limits
Category | Commands |
---|---|
Connection | NICK, USER, PASS, QUIT, PING, PONG |
Channel Operations | JOIN, PART, TOPIC, NAMES, LIST |
Messaging | PRIVMSG, NOTICE |
Channel Control | MODE, KICK, INVITE |
Server Information | MOTD, VERSION, INFO, TIME |
User Information | WHO, WHOIS, WHOWAS |
- Socket programming and network I/O
- Concurrent programming with non-blocking I/O
- Protocol design and implementation
- C++ design patterns and object-oriented programming
- Memory management and resource optimization
- Error handling and robust programming
- RFC specification interpretation and implementation
- Full RFC compliance with core IRC features
- Robust error handling with appropriate error codes
- Channel operations including modes and privileges
- User authentication and operator privileges
- Private messaging between users
- Efficient networking with non-blocking I/O
- Clean architecture with separation of concerns
Metric | Value |
---|---|
Final Score | 100/100 |
Lines of Code | ~3000 |
Classes | 5 core classes |
Commands Implemented | 5+ IRC commands |
Completion Time | 4 weeks |