Saphirac / ft_irc

MIT License
1 stars 1 forks source link

Implement the IRC commands #12

Open JonathanDUFOUR opened 5 months ago

JonathanDUFOUR commented 5 months ago

Now that our documentation is ready, we should start implementing the IRC commands. There is a list of the commands that we must implement:

To be able to make a map of these commands, and jump to the correct one when the server receives a message from a client, we should have the same prototype for every command. I suggest the following one:

bool irc_command(Client &sender, std::string const &parameters);
Saphirac commented 4 months ago

I'd prefer to use

int irc_command(Client &sender, std::string const &parameters); 

Instead of bool because it would allow us to send detailed error codes via the return of the function.

JonathanDUFOUR commented 4 months ago

We can do that, then I suggest also adding an enum to list every different return code for our internal functions, like:

enum StatusCode
{
  Success,
  ErrorFormatReply,
  ErrorClientSendMessage,
  /* ... */
};
Saphirac commented 4 months ago

I suggest that we use this format to implement command instead :

StatusCode    cmd(Client &sender, std::vector<std::string> const &parameters);

Using a vector of parameters is simpler than using a string as they are already separated. Do you agree ?

JonathanDUFOUR commented 3 months ago

After thinking about the nature of the errors that can occur and would return a StatusCode different from Success, it seems that they are all triggered by a critical internal error, with different possible origins. Thus, we decided to throw exceptions for these kinds of errors, instead of returning a StatusCode, and the new prototype is now:

void irc_command(Client &sender, std::vector<std::string> const &parameters);
JonathanDUFOUR commented 3 months ago

Closing this issue was a mistake.