Skip to content

Latest commit

History

78 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

ft_irc

An IRC server written in C++98 using TCP sockets and poll(2) (42 school project).

This repository contains:

  • mandatory/ — the IRC server (ircserv)
  • bonus/ — a simple IRC bot (Bot) that can reply with quotes

Features (high-level)

  • Multiple clients handled with a single-threaded event loop (poll)
  • Basic IRC registration flow (PASS, NICK, USER)
  • Channels and messaging (JOIN, PRIVMSG)
  • Channel moderation & management (KICK, TOPIC, MODE, INVITE)
  • Graceful shutdown handling (SIGINT / SIGTERM)
  • Bonus: bot that connects to the server and responds to !quote

Prerequisites

  • c++ compiler with C++98 support
  • make
  • An IRC client (recommended): irssi, weechat, hexchat
  • Or nc / telnet for quick manual testing

Build

Server (mandatory)

cd mandatory
make

Binary output:

  • mandatory/ircserv

Bonus bot

cd bonus
make

Binary output:

  • bonus/Bot

Run

Start the server

From mandatory/:

./ircserv <port><password>

Example:

./ircserv 6667 secret

Notes:

  • Port must be between 1 and 65535.
  • Password must be non-empty.

Connect with an IRC client

Using irssi (example):

/connect 127.0.0.1 6667 secret
/nick mynick
/user myuser 0 * :Real Name
/join #general

Quick connectivity test:

nc 127.0.0.1 6667

Supported commands

The server reads commands line-by-line and accepts both \r\n and \n as line endings.

Recognized commands:

  • PASS
  • NICK
  • USER
  • JOIN
  • PRIVMSG
  • KICK
  • TOPIC
  • MODE
  • INVITE

Unknown commands return: 421 <nick> <command> :Unknown command.

Registration (required)

Clients must authenticate first, then register.

PASS <password>

Authenticate using the server password (the one passed to ./ircserv <port> <password>).

  • Must be called before registration.
  • If the password is wrong, authentication fails.

Example:

PASS secret

NICK <nickname>

Set (or change) your nickname.

Rules implemented:

  • Requires authentication (PASS) first; otherwise you get ERR_NOTREGISTERED.
  • Nickname cannot start with: #, :, space, or a digit.
  • Nickname must be unique.

Example:

NICK aragragu

If you change nick after being registered, the nick change is broadcast.

USER <username> <hostname> <servername> :<realname>

Set your username and real name and complete registration.

Rules implemented:

  • Requires authentication (PASS) first.
  • Refused if already registered.
  • Realname can contain spaces when prefixed by :.

Example:

USER aragragu 0 * :Anas Rag

Channels & messaging

JOIN #chan1,#chan2 [pass1,pass2]

Join one or more channels. Channels are comma-separated; passwords (if needed) can also be comma-separated.

Checks implemented:

  • You must be registered.
  • Channel name must start with # and not be just #.
  • If channel is invite-only (+i), you must have been invited.
  • If channel has a key (+k), you must provide the correct password.
  • If channel has a user limit (+l), you cannot join if it is full.

Examples:

JOIN #general
JOIN #private mykey
JOIN #chan1,#chan2 pass1,pass2

When you join, the server sends JOIN + topic info (or “No topic is set”) and a names-style list (operators are prefixed with @ in that listing).

PRIVMSG <nick|#channel> :<message>

Send a private message to a user or a channel.

Rules implemented:

  • You must be registered.
  • You must provide a target and a message.
  • If target is a channel, you must be a member of that channel; otherwise you get ERR_CANNOTSENDTOCHAN.

Examples:

PRIVMSG aragragu :hello!
PRIVMSG #general :hi everyone

Moderation & channel management

KICK #channel user1[,user2...] [:reason]

Kick one or multiple users from a channel.

Rules implemented:

  • You must be registered.
  • You must be in the channel.
  • You must be a channel operator to kick.
  • The target user(s) must exist and be in the channel.

Examples:

KICK #general bob
KICK #general bob :spamming
KICK #general bob,alice :cleanup

If the channel becomes empty after removals, it is deleted.

TOPIC #channel (get) / TOPIC #channel :<new topic> (set)

Get or set the topic of a channel.

Rules implemented:

  • Getting the topic:
    TOPIC #general
    
  • Setting the topic:
    • requires you to be registered
    • requires you to be in the channel
    • if the channel has +t enabled, only channel operators can change the topic

Examples:

TOPIC #general :Welcome to #general
TOPIC #general

INVITE <nick> <#channel>

Invite a user to a channel.

Rules implemented:

  • You must be registered.
  • The target nick must exist.
  • The channel must exist.
  • You must be a member of the channel.
  • If the channel is invite-only (+i), you must be a channel operator to invite.
  • You cannot invite a user already in the channel.

Example:

INVITE bob #private

MODE #channel (query) / MODE #channel <modes> [params...] (set)

Query or set channel modes.

Query current modes
MODE #general

The server replies with a 324 numeric containing a mode string like:

  • +i invite-only
  • +t topic restricted to operators
  • +k key/password set
  • +l user limit set
Set modes (operator only)

Only channel operators can change modes.

Supported flags (as implemented):

  • +i / -i — invite-only
  • +t / -t — only operators can change topic
  • +k <key> / -k — set/unset channel key
    • +k requires a parameter
    • if a key is already set, it returns an error
  • +l <limit> / -l — set/unset user limit
    • +l requires a numeric limit > 0
  • +o <nick> / -o <nick> — give/remove operator
    • target must exist and be in the channel

Examples:

MODE #general +i
MODE #general +t
MODE #general +k supersecret
MODE #general -k
MODE #general +l 10
MODE #general -l
MODE #general +o bob
MODE #general -o bob

When a mode change is applied, the server broadcasts:

:<setterNick> MODE #channel <modes> [params...]

to all channel members.


Bonus: Quote bot

The bot connects to the server, registers, and joins #general automatically.

Build:

cd bonus && make

Run:

./Bot <server_ip><port><password>

Example:

./Bot 127.0.0.1 6667 secret

In #general, type:

  • !quote
  • !quote programming
  • !quote music
  • !quote adventure
  • !quote life

Project structure

.
├── mandatory/
│ ├── Makefile
│ ├── main.cpp
│ ├── Server.*
│ ├── Client.*
│ ├── channel.*
│ └── (handlers: Join/Pass/Nick/User/Privmsg/Kick/Topic/Mode/Invite/...)
└── bonus/
├── Makefile
└── Bot.*

Common Makefile targets

Both mandatory/Makefile and bonus/Makefile provide:

make
make clean
make fclean
make re

License

No license file is included in this repository.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages