Building an IRC Server 3

2021-04-28
2 min read

by Eudald

[storage, register, commands]

When the fun begins

Hi! Eudald to the talk now! I’m going to post news about our work as my team mates(and Docs too). So without further do, let’s introduce you to our third week of work.

So, in this we continued working on the essential commands and adding functionalities we didn’t really pay attention before.

Just like:

  • Accepting the order NICK - USER or USER - NICK.
  • Sending a PART message to all channels the user is when QUIT.
  • Nick change notification sent to all users.

We also added utility funcitons as things were progressing (i.e. vector of *Client in the second post). Like functions to send messages to all users in channel:

void	send_to_channel(const std::string &msg, const size_t &client_id, const MyServ &serv, const int &chan_id)
{
	std::string		full_msg = 	":" + <user_nickname> + "!" + <user_username> + "@" + <user_hostname> + " " + msg + "\r\n";
	for (size_t i = 0; i < g_vChannel[chan_id]._users.size(); i++)
	{
		if (g_vChannel[chan_id]._users[i] != g_aClient[client_idx].second)
			g_vChannel[chan_id]._users[i].send_reply(full_msg);
	}
}

Where “g_vChannel[chan_id]._users” is a vector of * Clients of the channel we are.

And like the one above many others. This was very useful as it simplified a lot (and shorten) the code, (e.g., for all the commands).

At the same time, we started WHO command, and improved MODE command step by step. One big upgrade we did in MODE was to handle the mode options in a “switch case”. In this situation we thought it was a great idea because it allows us to do something concrete with the character handled.

Take a quick look:

switch (c)
	{
		case 'k':
		{
			if (sign == '+' && !arg.empty())
				[curr_Channel].set_password(<pass>);
			else if (sign == '-')
				break;
			else
				return	false;
			break;
		}
		case 'l':
		{
			if (sign == '+' && !arg.empty())
				[curr_Channel].set_limit(ft_atoi(<limit>)); //We used our own atoi, i.e. 42_lbft or libft_42
			else if (sign == '-')
				break;
			else
				return	false;
			break;
		}
		default
			break;
	}

We then started KICK and OPER commands, which are not very tricky. And at this point we discovered aswe progressed that MODE is quite a hell but fun at the same time (a proper Doc about MODE will be added in the future), so don’t be discouraged about this command.

So here ends this post! See you in next ones and thanks for reading!
Eudald.