Skip to content

C++ implementation of RFC-compliant IRC server utilizing socket programming with non-blocking I/O via select(). Features client-server architecture supporting concurrent connections, channel operations, private messaging, user authentication, and operator privileges with full command parsing and execution.

License

Notifications You must be signed in to change notification settings

mbdanielcrespo/IRC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

28 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’¬ IRC Server

42 Badge Score Language Status

IRC Badge

πŸ“ Introduction

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.

🎯 Project Objectives

  • 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 Protocol: An Overview

IRC is a text-based communication protocol that follows a client-server model, allowing real-time messaging between users in channels or privately:

Key Protocol Features

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

Core IRC Commands

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

πŸ—οΈ Project Architecture

Class Structure

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     Server    │◄────►│     Client    │◄────►│    Channel    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚                      β–²                      β–²
        β”‚                      β”‚                      β”‚
        β–Ό                      β”‚                      β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ CommandHandler│◄────►│    Message    │─────►│    Logger     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Project Structure

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

πŸ› οΈ Implementation Details

Key Components

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

Networking Model

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

πŸ’‘ Technical Approach

My implementation focuses on correctness, performance, and maintainability:

1. Architecture Design

  • Event-driven model for high concurrency
  • Non-blocking I/O for efficient resource usage
  • Modular class design for maintainability
  • Separation of concerns between components

2. Protocol Compliance

  • RFC 1459/2812 implementation
  • Proper error codes and messages
  • Complete command set support
  • Input validation and sanitization

3. Performance Considerations

  • Efficient data structures for user and channel lookup
  • Minimal memory footprint per connection
  • Optimized message parsing and generation
  • Connection timeouts and resource limits

πŸ”§ Implemented Commands

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

πŸ’Ό Skills Developed

  • 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

πŸš€ Key Features

  • 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

πŸ“Š Project Stats

Metric Value
Final Score 100/100
Lines of Code ~3000
Classes 5 core classes
Commands Implemented 5+ IRC commands
Completion Time 4 weeks

C++ Socket TCP/IP 42

About

C++ implementation of RFC-compliant IRC server utilizing socket programming with non-blocking I/O via select(). Features client-server architecture supporting concurrent connections, channel operations, private messaging, user authentication, and operator privileges with full command parsing and execution.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •