Skip to content

RFC 2812-compliant IRC server in C++98. Handles 100+ concurrent clients with non-blocking I/O using poll(). Features 26 IRC commands, advanced security with rate limiting, and channel mode support.

License

Notifications You must be signed in to change notification settings

TheValiant/viberc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

viberc

A high-performance, RFC 2812-compliant IRC server written in C++98 with advanced security features and non-blocking I/O.

Overview

viberc is a fully-featured Internet Relay Chat (IRC) server implementation built from scratch as part of the 42 School curriculum. The server handles multiple concurrent client connections using efficient poll-based I/O multiplexing, implements the complete IRC protocol specification, and includes comprehensive security measures such as rate limiting and input validation.

This project demonstrates expertise in network programming, concurrent connection handling, and protocol implementation. The architecture follows a single-threaded, event-driven model that efficiently manages hundreds of simultaneous connections without the complexity of multi-threading.

Features

  • RFC 2812 Protocol Compliance: Full implementation of the IRC protocol specification with proper numeric reply codes
  • Non-blocking I/O: Event-driven architecture using poll() for efficient handling of 100+ concurrent connections
  • 26 IRC Commands: Complete command set including registration, messaging, channel operations, and user management
  • Advanced Security: Rate limiting, flood protection, input sanitization, and ban mask pattern matching
  • Channel Modes: Support for +i (invite-only), +t (topic restriction), +k (channel key), +l (user limit), +o (operator), +b (ban)
  • RAII Resource Management: Automatic cleanup of sockets and memory with modern C++ patterns in C++98
  • Comprehensive Logging: Configurable logging levels with color-coded output and file rotation support
  • Client Compatibility: Tested with irssi, WeeChat, LimeChat, and nc/netcat

Technical Highlights

  • Networking: Non-blocking socket I/O with poll-based multiplexing, buffered partial send/receive handling
  • Protocol Implementation: Strict RFC 2812 message parsing with proper prefix, command, and parameter extraction
  • Security: Multi-layer protection including message rate limiting, command throttling, join flood prevention, and wildcard ban pattern matching
  • Performance: Optimized ban pattern compilation, efficient client lookup using STL containers, minimal memory footprint

Architecture

┌─────────────────────────────────────────────────────────────────┐
│                         IRC Clients                              │
│                 (irssi, WeeChat, LimeChat, etc.)                │
└─────────────────────────────────────────────────────────────────┘
                                │
                                ▼
┌─────────────────────────────────────────────────────────────────┐
│                    Socket Layer (poll())                         │
│          Non-blocking I/O multiplexing for all clients          │
└─────────────────────────────────────────────────────────────────┘
                                │
                                ▼
┌─────────────────────────────────────────────────────────────────┐
│                    Message Processing                            │
│     Buffer management → Message parsing → Command dispatch       │
└─────────────────────────────────────────────────────────────────┘
                                │
                                ▼
┌─────────────────────────────────────────────────────────────────┐
│                    Command Handlers                              │
│  ┌──────────┐  ┌──────────┐  ┌──────────┐  ┌──────────────┐    │
│  │Essential │  │ Channel  │  │ Operator │  │   Advanced   │    │
│  │NICK,USER │  │JOIN,PART │  │KICK,MODE │  │ AWAY,WHOIS   │    │
│  │PASS,QUIT │  │PRIVMSG   │  │TOPIC,BAN │  │ WHO,LIST     │    │
│  └──────────┘  └──────────┘  └──────────┘  └──────────────┘    │
└─────────────────────────────────────────────────────────────────┘
                                │
                                ▼
┌─────────────────────────────────────────────────────────────────┐
│                    Data Management                               │
│  ┌────────────────┐  ┌────────────────┐  ┌────────────────┐    │
│  │    Clients     │  │    Channels    │  │    Security    │    │
│  │ State, Buffers │  │ Members, Modes │  │ Rate Limiting  │    │
│  └────────────────┘  └────────────────┘  └────────────────┘    │
└─────────────────────────────────────────────────────────────────┘

Implemented Commands

Registration Commands

Command Description
CAP Capability negotiation for modern IRC clients
PASS Server password authentication
NICK Set or change nickname
USER Complete user registration
QUIT Disconnect from server

Messaging Commands

Command Description
PRIVMSG Send private messages to users or channels
NOTICE Send notices (no automatic replies)

Channel Commands

Command Description
JOIN Join one or more channels
PART Leave one or more channels
TOPIC View or set channel topic
NAMES List users in channel
LIST List available channels
MODE Set channel or user modes
KICK Remove user from channel
INVITE Invite user to channel

Query Commands

Command Description
WHO Query user information
WHOIS Detailed user information
ISON Check if users are online
USERHOST Get user host information

Utility Commands

Command Description
PING Connection keepalive request
PONG Connection keepalive response
AWAY Set away status and message
MOTD Display message of the day
TIME Server time query
VERSION Server version information
HELP Command help

Requirements

  • Operating System: Linux, macOS
  • Compiler: GCC 9+ or Clang 12+ with C++98 support
  • Build Tools: GNU Make

Optional (for development)

  • clang-tidy (static analysis)
  • clang-format (code formatting)
  • cppcheck (additional static analysis)
  • Valgrind (memory debugging)

Installation and Usage

Building

git clone https://github.com/TheValiant/viberc.git
cd viberc
make

Build Variants

make            # Standard build
make debug      # Debug build with AddressSanitizer and UBSan
make release    # Optimized release build
make tidy-build # Build with integrated clang-tidy checks

Running the Server

./ircserv <port> <password> [options]

Arguments:

  • port: TCP port to listen on (1024-65535)
  • password: Server connection password

Options:

  • --verbose: Enable verbose logging
  • --max-clients=N: Set maximum client limit (default: 100)
  • --no-rate-limit: Disable rate limiting (for testing)
  • --no-security: Disable security checks (for testing)
  • --allow-weak-passwords: Skip password strength validation

Example Usage

# Start server on port 6667 with password "mypassword"
./ircserv 6667 mypassword

# Start with verbose logging and higher client limit
./ircserv 6667 mypassword --verbose --max-clients=200

# Connect with irssi
irssi -c localhost -p 6667 -w mypassword

# Connect with netcat (for testing)
nc localhost 6667
PASS mypassword
NICK testuser
USER testuser 0 * :Test User

Testing

The project includes comprehensive test scripts:

# Quick functionality test
./quick_comprehensive_test.sh

# Run with Valgrind for memory leak detection
valgrind --leak-check=full --show-leak-kinds=all ./ircserv 6667 password

Static Analysis

make tidy         # Run clang-tidy analysis
make cppcheck     # Run cppcheck analysis
make analyze-all  # Run all static analyzers
make format       # Format code with clang-format

Client Compatibility

Tested and compatible with:

  • irssi - Terminal-based IRC client
  • WeeChat - Extensible chat client
  • LimeChat - macOS IRC client
  • HexChat - Cross-platform graphical client
  • netcat - For protocol-level testing

Security Features

  • Rate Limiting: Configurable message and command rate limits
  • Flood Protection: Prevention of join flooding and message spam
  • Input Validation: Strict parameter validation for all commands
  • Buffer Overflow Protection: Size limits on all input buffers
  • Ban Pattern Matching: Wildcard support for host-based banning
  • Password Security: Optional weak password rejection

Learning Outcomes

This project provided deep experience in:

  • POSIX socket programming and network I/O
  • Event-driven architecture design with poll/select
  • Protocol implementation from RFC specifications
  • Security-conscious systems programming
  • Memory management in constrained C++98 environment
  • Static analysis and code quality tooling

Acknowledgments

  • 42 School for the project specifications and learning environment
  • RFC 2812 authors for the IRC protocol specification
  • The irssi and WeeChat projects for reference implementations

License

This project is available under the MIT License. See LICENSE for details.


Note: This project was completed as part of the 42 School curriculum, which emphasizes peer-to-peer learning and project-based education in software engineering.

About

RFC 2812-compliant IRC server in C++98. Handles 100+ concurrent clients with non-blocking I/O using poll(). Features 26 IRC commands, advanced security with rate limiting, and channel mode support.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published