Skip to content

Latest commit

History

28 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

💬 IRC Server

42 BadgeScoreLanguageStatus

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

FeatureDescriptionImplementation
Text-basedSimple ASCII commands and responsesEasy to parse and generate
Client-ServerCentralized architectureSingle server handles multiple clients
Channel-basedGroup conversations in named channelsManaged as collections of users
User RolesOperators with special privilegesAccess control implementation
StatefulServer maintains user/channel stateIn-memory data structures

Core IRC Commands

CommandDescriptionExample
NICKSet or change usernameNICK john_doe
USERSet user identity detailsUSER john 0 * :John Doe
JOINEnter a channelJOIN #general
PRIVMSGSend a messagePRIVMSG #general :Hello everyone!
PARTLeave a channelPART #general
KICKRemove a user from channelKICK #general jane_doe
MODEChange channel/user modesMODE #general +o john_doe
QUITDisconnect from serverQUIT :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

ComponentPurposeImplementation Approach
ServerManages connections and routes messagesSocket programming with non-blocking I/O using select()
ClientRepresents a connected userState machine tracking authentication and activity
ChannelManages group conversationsCollection of members with permission levels
CommandHandlerProcesses IRC commandsCommand pattern with function map dispatch
MessageParses and formats IRC messagesRFC-compliant formatting and validation

Networking Model

AspectImplementationNotes
Socket TypeTCP/IPReliable, ordered delivery
I/O ModelNon-blocking with select()Efficient handling of multiple clients
Buffer ManagementInput/output queues per clientHandles partial reads/writes
Connection StateState tracking per clientRegistration, 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

CategoryCommands
ConnectionNICK, USER, PASS, QUIT, PING, PONG
Channel OperationsJOIN, PART, TOPIC, NAMES, LIST
MessagingPRIVMSG, NOTICE
Channel ControlMODE, KICK, INVITE
Server InformationMOTD, VERSION, INFO, TIME
User InformationWHO, 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

MetricValue
Final Score100/100
Lines of Code~3000
Classes5 core classes
Commands Implemented5+ IRC commands
Completion Time4 weeks

C++SocketTCP/IP42

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

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages