Skip to content
This repository was archived by the owner on Apr 2, 2025. It is now read-only.

ltorkia/ircserv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

128 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

IRC Server 42 Group Project - SUBJECT

This project involves developing an IRC server in C++ 98, designed to handle multiple clients simultaneously while respecting the IRC protocol standards. The goal is to implement a lightweight, efficient, and modular server with robust error handling and non-blocking operations.


Project Overview πŸ“š

Objectives 🎯:

  • Develop an IRC server running on TCP/IP.
  • Support multiple simultaneous clients without blocking.
  • Provide essential IRC functionalities, such as authentication, private messaging, and channel management.
  • Ensure compliance with a reference IRC client (irssi here)

Execution :

./ircserv <port> <password>
  • port : Port number for incoming connections.
  • password : Password required for user authentication.

Technical Requirements πŸ”§

Constraints βš™οΈ:

  • C++ 98 standard only (no C++11 or later features).
  • Non-blocking I/O operations.
  • Only one call to poll() or equivalent (select() here).
  • No forking or multi-threading.

Allowed External Functions πŸ§‘β€πŸ’»:

  • socket, close, setsockopt, bind, connect, listen, accept...
  • Full list here.

Core Features ⚑

Basic Functionalities :

  • Client Authentication using a password.
  • Handling Multiple Clients concurrently.
  • Message Parsing and Routing compliant with the IRC protocol.
  • Proper Error Handling to avoid crashes and connection failures.

IRC Commands ⌨️:

  • Connection Commands: PASS, NICK, USER
  • Messaging: PRIVMSG
  • Channel Management: JOIN, PART, TOPIC, MODE, INVITE, KICK
  • Operator Commands: Assigning and managing user privileges.

Channel Modes (MODE) Implementation πŸ”:

  • +i (Invite-only channels)
  • +t (Only operators can change the topic)
  • +k (Password-protected channels)
  • +o (Grant/revoke operator status)
  • +l (User limit in a channel)

Network Handling 🌐

  • Efficient message broadcasting using a select-based non-blocking event loop.
  • Packet fragmentation handling to support broken or delayed messages.

Project Structure πŸ—‚οΈ

File Organization :


β”œβ”€β”€ assets
β”‚   └── quotes.txt
β”œβ”€β”€ incs
β”‚   └── bot
β”‚   β”‚   └── Bot.hpp
β”‚   β”œβ”€β”€ config
β”‚   β”‚   β”œβ”€β”€ bot_config.hpp
β”‚   β”‚   β”œβ”€β”€ colors.hpp
β”‚   β”‚   β”œβ”€β”€ commands.hpp
β”‚   β”‚   β”œβ”€β”€ irc_config.hpp
β”‚   β”‚   β”œβ”€β”€ irc_replies.hpp
β”‚   β”‚   β”œβ”€β”€ server_libs.hpp
β”‚   β”‚   └── server_messages.hpp
β”‚   β”œβ”€β”€ server
β”‚   β”‚   β”œβ”€β”€ Channel.hpp
β”‚   β”‚   β”œβ”€β”€ Client.hpp
β”‚   β”‚   β”œβ”€β”€ Command.hpp
β”‚   β”‚   β”œβ”€β”€ FileData.hpp
β”‚   β”‚   └── Server.hpp
β”‚   └── utils
β”‚       β”œβ”€β”€ IrcHelper.hpp
β”‚       β”œβ”€β”€ MessageBuilder.hpp
β”‚       └── Utils.hpp
└── srcs
β”‚   β”œβ”€β”€ bot
β”‚   β”‚   β”œβ”€β”€ Bot_Command.cpp
β”‚   β”‚   β”œβ”€β”€ Bot_Message.cpp
β”‚   β”‚   β”œβ”€β”€ Bot_Parser.cpp
β”‚   β”‚   β”œβ”€β”€ Bot_Register.cpp
β”‚   β”‚   β”œβ”€β”€ Bot.cpp
β”‚   β”‚   └── BotMain.cpp
β”‚   β”œβ”€β”€ server
β”‚   β”‚   β”œβ”€β”€ channels
β”‚   β”‚   β”‚   β”œβ”€β”€ Channel_Actions.cpp
β”‚   β”‚   β”‚   β”œβ”€β”€ Channel_Attributes.cpp
β”‚   β”‚   β”‚   └── Channel.cpp
β”‚   β”‚   β”œβ”€β”€ clients
β”‚   β”‚   β”‚   β”œβ”€β”€ Client_Actions.cpp
β”‚   β”‚   β”‚   β”œβ”€β”€ Client_Attributes.cpp
β”‚   β”‚   β”‚   └── Client.cpp
β”‚   β”‚   β”œβ”€β”€ commands
β”‚   β”‚   β”‚   β”œβ”€β”€ Command_Channel.cpp
β”‚   β”‚   β”‚   β”œβ”€β”€ Command_File.cpp
β”‚   β”‚   β”‚   β”œβ”€β”€ Command_Log.cpp
β”‚   β”‚   β”‚   β”œβ”€β”€ Command_Message.cpp
β”‚   β”‚   β”‚   β”œβ”€β”€ Command_Mode.cpp
β”‚   β”‚   β”‚   β”œβ”€β”€ Command_Register.cpp
β”‚   β”‚   β”‚   └── Command.cpp
β”‚   β”‚   β”œβ”€β”€ core
β”‚   β”‚   β”‚   β”œβ”€β”€ Server_Clients.cpp
β”‚   β”‚   β”‚   β”œβ”€β”€ Server_Infos.cpp
β”‚   β”‚   β”‚   β”œβ”€β”€ Server_Loop.cpp
β”‚   β”‚   β”‚   └── Server.cpp
β”‚   β”‚   └── ServerMain.cpp
β”‚   └── utils
β”‚       β”œβ”€β”€ IrcHelper.cpp
β”‚       β”œβ”€β”€ MessageBuilder.cpp
β”‚       └── Utils.cpp
β”œβ”€β”€ Makefile
└── README.md


Project Approach πŸ’‘

1. Object-Oriented Design πŸ’Ό

  • Server Class: Manages network connections and client sessions.
  • Client Class: Represents an IRC user with its state and actions.
  • Channel Class: Handles channel-specific logic and member management.
  • Command Class: Parses and executes IRC commands.
  • Bot Class (Bonus): Implements additional interactive features.

2. Non-Blocking Event Handling πŸ”„

  • File descriptor management using select() for handling multiple clients concurrently.
  • Setting sockets to non-blocking mode with fcntl():
fcntl(fd, F_SETFL, O_NONBLOCK);

3. Error Handling & Debugging ⚠️

  • Try-catch blocks to prevent crashes.

Bonus Features πŸŽ‰

IRC Bot πŸ€–:

Bot execution :

./ircbot

The bot operates independently from the server and is treated like a standard IRC client. Upon execution, it automatically connects to the server by retrieving necessary information from the .env file, such as the server password. This ensures that the bot connects seamlessly to the server without needing manual configuration each time.

Interactive commands available both in channels and private messages with the bot:

  • !funfact: Returns a random tech-related fun fact.
  • !age <YYYY-MM-DD>: Calculates and displays the user's exact age in years, months, and days.
  • !time: Displays the current time.

File Transfer Support (DCC Protocol) πŸ“:

  • Direct peer-to-peer file sharing between users is implemented correctly for irssi, as required by the assignment, using the DCC SEND protocol.
  • For Netcat, we opted for a local file transfer approach using environment variables instead of a full DCC implementation. This allows basic file transmission but does not strictly follow the DCC protocol as defined for IRC clients.

Advanced Logging System πŸ“‘:

  • Detailed event logs for debugging and server management.
  • Real-time monitoring of connections and messages.

Installation & Compilation πŸ› οΈ

Compiling the Server and the Bot :

To compile both ircserv and ircbot, simply run:

make
  • The compilation process first builds the shared library containing common utilities before linking it to each executable.

You can also compile the server and bot separately using:

make server  
make bot  

To speed up compilation on multi-core systems, you can use:

make -j

For debugging purposes, use:

make debug
  • This compiles the project with -g3 -DDEBUG flags for enhanced debugging capabilities.

Cleaning the Project :

make clean    # Removes object files
make fclean   # Removes binaries and object files
make re       # Cleans and recompiles everything

Testing & Usage πŸ§ͺ

If you have any issues, refer to irc.connect.help.md

Running server πŸš€:

./ircserv 6667 "my_password"

Connecting with nc 🌐:

nc 127.0.0.1 6667
  • Authentication commands πŸ›‚:
PASS pass_server
NICK test_user
USER test_user 0 * :Real Name
  • Packet framentation test with CTRL+D:
com^Dman^Dd

Connecting with irssi πŸ’»:

irssi -c 127.0.0.1 -p 6667 -w "my_password"
  • Test commands like:
/join #channel
/msg user Hello!
/msg #channel Hello!
/kick user

About

42 school / group project - An IRC (Internet Relay Chat) server designed to provide a real-time communication platform. It allows multiple users to connect, chat live, and manage chat rooms. This project includes basic features for authentication, channel management, and client communication.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors