All 42 projects

42 Project brief

ft_irc

An IRC server in C++98 that real IRC clients can connect to, built in a team of three. I wrote the command layer: parsing, the channel and message commands, error replies and the bonus bot.

My role
Commands, channels, bot
Team
3 developers
Timeline
Feb — Mar 2023
Workload
175 h

The project

ft_irc is the 42 networking project: write an IRC server in C++98, with no external libraries, that a real IRC client can use. One process serves every connection with non-blocking sockets and a single poll() loop.

Users register with the server password, pick a nickname, join channels, talk in channels or in private, and channel operators can set the topic, change modes and kick people.

The team’s stack

  • C++98
  • TCP sockets
  • poll()
  • IRC protocol
  • Make
  • Valgrind
  • LimeChat
  • netcat

My part

I made about 110 of the 232 commits, the most on the team. My two teammates built the socket and poll() core and the code that receives data.

01

Startup & registration

The first things a client meets.

  • Checks ./ircserv <port> <password>: the port must be numeric, and reserved ports 0 to 1023 are refused
  • PASS and USER registration, with error 464 when the password is wrong
02

Command parsing

Turning raw lines from the socket into commands.

  • Splits each line into a command and its parameters, including the trailing text after the colon, even when it contains more colons
  • Answers with the IRC numeric errors: not enough parameters, bad channel name, not on channel, operator rights needed
  • Tested against a real client, LimeChat, and raw netcat sessions
03

Channels & messages

The commands people use all the time.

  • JOIN with several channels at once and per-channel passwords, like JOIN #a,#b key1,key2
  • PART, QUIT with a goodbye message, PRIVMSG and NOTICE to users or channels, and LIST of every channel
04

Operators & the bonus bot

Moderation, and a small bot built into the server.

  • TOPIC and KICK, restricted to channel operators; KICK finds its target in a map of users indexed by nickname
  • YIRC_BoT: a help menu with example commands, the number of open channels, and joining a random channel
  • Segfaults and memory leaks tracked down with Valgrind, and C++11 features removed to stay within C++98

What happens on JOIN

  1. 1

    Read

    The poll() loop hands the parser a line such as JOIN #a,#b key1,key2.

  2. 2

    Split

    The channel list and the key list are split on commas and paired up.

  3. 3

    Validate

    Every name must start with #, otherwise the client gets error 476, bad channel mask.

  4. 4

    Join or create

    An existing channel checks its password before adding the user; a new one is created with that key.

  5. 5

    Reply

    The user gets the join confirmation and the list of members.

Code