Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project has been created as part of the 42 curriculum by luciama2, kde-la-c and ldel-val

Description

This project is a single-threaded IRC (Internet Relay Chat) server for Linux developed in C++.

The server lets clients connect over a network to chat in channels or one-to-one communication complying with the IRC protocol.

Instructions

Instalation instructions

To compile the program from its source you can clone it from the github repository or vogsphere during evaluations, compilation has been tested for GNU Make 4.3 and gcc version 10.5.0.

Once you have cloned the repository, run make in the root directory.

git clone https://github.com/luna7111/IRCServer.git
cd ft_irc
make

Running

Once compiled, run the binary using the following command in the project source:

./ircserver <port> <password>

Important

The password policy requires a 8 character long password with at least a number, an upper case letter, and a lower case letter.

Make sure the port isn't already being used and is ready to use.

Connecting a client to the server

The server has been tested both with netcat (writing packages manually) and HexChat, but it should work with any IRC client.

Connect using netcat

Connecting to the server using netcat is specially useful to debug the server and have a better understanding of the text-based comunication between server and client. Netcat lets you write and read arbitrary packages across network connections, so keep in mind you will have to manually write the packages complying with the IRC protocol.

For example if the server is running locally on port 8080 you can run:

nc localhost 8080

From then on you can type and send packages according to the protocol, here is a basic example of a client connecting to the server and sending a message to a channel:

PASS Password123
NICK Robi        
USER Robi 0 * Robin
JOIN #GeneralChannel
PRIVMSG #GeneralChannel :Hey there! My name is Robin, im new here :)

Connect using HexChat

HexChat is an open-source IRC client with a GUI with a user experience that is more aligned with modern chat services.

To connect to a server running locally on port 8080 first fill the Nick fields with your nick choice and click "Add" in the network section. Edit the new network and in the "Servers" section add the server address and port, for example localhost/8080. Set the login method to Server password (/PASS password) and fill the "Password" field with the server password and close the window. Now you can click "Connect" and use the server normally.

Important

If the server doesn't have a valid SSL certificate (which is the case for our example), uncheck the "Use SSL for all the servers on this network" box.

Only do this if you trust the server you are connecting to.

Resources

RFC1459 is the original memo defining the protocol and RFC7194 is the most updated version.

IRCdocs is an archive with useful and present information about the protocol.

LLMs such as ChatGPT and Gemini were used to debug some parts of the code.

Technical choices

The server was developed in C++98 in a single thread, using no external libraries or Boost libraries. These restrictions were imposed by the subject requirements of the 42 curriculum project ft_irc.

The program relies on the following system calls to operate:

  • socket() creates the the server endpoint used to receive connections from clients.
  • bind() assigns the server address to the server socket.
  • listen() marks the server socket as a passive socket which, instead of being used to write or send information to other endpoints will be used to accept incoming connections from clients using accept().
  • accept() creates a socket connected to the first pending connection in the queue of the passive server socket, this socket is active and is used to send and receive information to the client.
  • The epoll API (epoll_create1(), epoll_ctl(), epoll_wait()...) is used to monitor all the file descriptors (socket) for incomming connections and information packages.

The program main loop waits for an event in any file descriptor tracked by the epoll instance. When epoll_wait() returns a file descriptor the server checks whether its a client socket that neads to be read or the server's passive socket with a connection waiting to be accepted.

About

This project is about creating your own IRC server. You will use an actual IRC client to connect to your server and test it. The Internet is governed by solid standard protocols that allow connected computers to interact with each other. It’s always beneficial to understand these protocols.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages