Skip to content
2cat1vimPublic

About

A custom IRC server written in C++98, implementing the core of the IRC protocol (RFC 1459/2812-style) over raw TCP sockets with a single-threaded, poll()-based event loop. Includes a Python weather bot as an example IRC client/bot integration.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

63 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

ircserv

A custom IRC server written in C++98, implementing the core of the IRC protocol (RFC 1459/2812-style) over raw TCP sockets with a single-threaded, poll()-based event loop. Includes a Python weather bot as an example IRC client/bot integration.

Features

  • Single-threaded, non-blocking server using poll() to multiplex the listening socket and all connected clients
  • Full client registration flow: PASS → NICK → USER
  • Channel management: creation, joining, parting, and automatic cleanup of empty channels
  • Channel operator system with promotion of a new operator when the current one leaves
  • Channel modes: +i (invite-only), +t (topic lock), +k (password), +l (user limit), +o (operator)
  • Messaging: PRIVMSG and NOTICE to both users and channels
  • TOPIC, KICK, INVITE, MODE, QUIT command support
  • PING / PONG keepalive handling
  • Numeric reply codes matching standard IRC clients' expectations (e.g. 001, 331/332, 353/366, 401–475)
  • Example Python bot (WeatherBot.py) demonstrating a working IRC client integration using wttr.in

Requirements

  • A C++98-compatible compiler (c++/g++/clang++)
  • POSIX sockets (Linux/macOS)
  • Python 3 (only needed to run WeatherBot.py)

Build

make          # builds the ircserv binary
make clean    # removes object files
make fclean   # removes object files and the binary
make re       # fclean + all

Usage

./ircserv <port> <password>
  • port — must be 1–5 digits (e.g. 6667)
  • password — required to authenticate clients via the IRC PASS command

Example:

./ircserv 6667 1234

Connect with any standard IRC client (e.g. irssi, WeeChat, HexChat) pointed at localhost:6667, using 1234 as the server password.

Architecture

.
├── Makefile
├── WeatherBot.py             # example bot client (Python)
└── src/
    ├── main.cpp               # entry point, argument parsing, server bootstrap
    ├── Server.cpp/.hpp        # socket setup, poll() event loop, command dispatch
    ├── Client.cpp/.hpp        # per-connection state (nick, user, auth, buffer)
    ├── Message.cpp/.hpp       # raw IRC line parser (prefix/command/params/trailing)
    ├── Channel/
    │   └── Channel.cpp/.hpp   # channel state: members, operators, modes, invites
    ├── Commands/
    │   └── Commands.cpp/.hpp  # handlers for PASS, NICK, USER, JOIN, PRIVMSG, etc.
    └── Utils/
        ├── Parser.cpp/.hpp    # CLI argument validation (port/password)
        └── Exceptions.hpp     # custom exception types for startup/socket failures

How it works

  1. Parser validates the port and password command-line arguments at startup.
  2. Server creates a listening TCP socket, binds, and listens.
  3. The main loop uses poll() over the listening socket plus every connected client socket.
  4. On a new connection, a Client object is created and added to the poll set.
  5. On incoming data, bytes are appended to the client's internal buffer and split on \r\n into individual Message objects.
  6. Each Message is dispatched by command name (Server::dispatch) to the matching handler in Commands.cpp, which validates state (registration, permissions, channel membership) and sends the appropriate numeric or command reply.
  7. Channel tracks membership, operator status, invite lists, and modes, and provides broadcast() to relay messages to all members.

WeatherBot.py

A minimal example IRC bot that connects to the server, joins #general, and responds to !weather <city> by querying wttr.in for current conditions.

python3 WeatherBot.py

Make sure ircserv is already running on localhost:6667 with password 1234 (or update the constants at the top of the script to match your server).

Notes

  • This is a C++98 project (per the Makefile's -std=c++98 flag), so it deliberately avoids C++11+ features (e.g. nullptr, range-based for, auto).
  • Compiled with -Wall -Wextra -Werror, so the codebase is warning-clean by design.

About

A custom IRC server written in C++98, implementing the core of the IRC protocol (RFC 1459/2812-style) over raw TCP sockets with a single-threaded, poll()-based event loop. Includes a Python weather bot as an example IRC client/bot integration.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages