Skip to content

Commit

Permalink
Merge pull request #45 from ygor-sena/test/client-irc-connection
Browse files Browse the repository at this point in the history
feat(main): add user and pwd to be passed as user args
  • Loading branch information
gialexan authored Jun 1, 2024
2 parents dd46c66 + 360bf40 commit 0ebb2de
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 20 deletions.
23 changes: 17 additions & 6 deletions include/Replies.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* Replies.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gilmar <gilmar@student.42.fr> +#+ +:+ +#+ */
/* By: yde-goes <yde-goes@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/11 18:18:57 by gilmar #+# #+# */
/* Updated: 2024/06/01 07:36:49 by gilmar ### ########.fr */
/* Updated: 2024/06/01 09:34:16 by yde-goes ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -17,6 +17,10 @@

// refer to https://datatracker.ietf.org/doc/html/rfc1459

/*
** ----------------------------- REPLY MESSAGES -------------------------------
*/

#define RPL_CONNECTED(serverhostname, nickname, targethostname) \
(":" + serverhostname + " 001 " + nickname + \
" :Welcome to the IRC server! " + nickname + "!" + targethostname + CRLF)
Expand Down Expand Up @@ -71,6 +75,10 @@
(":" + nickname + "!" + hostname + " PRIVMSG " + receiver + " " + text + \
CRLF)

/*
** ------------------------ MARVIN BOT REPLY MESSAGES -------------------------
*/

#define BOT_CMDMARVIN(nickname) \
(": 4242 marvin_bot " + nickname + \
" :Hello, I am Marvin, the paranoid robot." + CRLF)
Expand All @@ -84,14 +92,17 @@

#define BOT_CMDQUOTE(nickname, quote) \
(": 4242 marvin_bot " + nickname + " :" + quote + CRLF)

#define BOT_CLIENTNOTINCHANNEL(nickname) \
(": 2424 marvin_bot " + nickname + \
": Must be part of at least one channel to use marvin commands" + CRLF)

#define BOT_WHOISDOESNTEXIST(nickname) \
(": 4242 marvin_bot " + nickname + " :No such user" + CRLF)

///////// ERRORS /////////
/*
** --------------------------- ERROR REPLY MESSAGES ---------------------------
*/
#define ERR_NEEDMODEPARM(channelname, mode) \
(": 696 " + channelname + \
" * You must specify a parameter for the key mode. " + mode + CRLF)
Expand Down Expand Up @@ -133,9 +144,6 @@
#define ERR_NOTREGISTERED(nickname) \
(": 451 " + nickname + " :You have not registered!" + CRLF)

#define ERR_CMDNOTFOUND(nickname, command) \
(": 421 " + nickname + " " + command + " :Unknown command" + CRLF)

#define ERR_BADCHANNELKEY(nickname, channelname) \
(": 475 " + nickname + " " + channelname + \
" :Cannot join channel (incorrect key)" + CRLF)
Expand Down Expand Up @@ -175,4 +183,7 @@
(":" + server + " 476 " + nickname + " " + channel + \
" :Bad Channel Mask\r\n")

#define ERR_CMDNOTFOUND(command) \
(": 421 " + command + " :Unknown command" + CRLF)

#endif // REPLIES_HPP
1 change: 0 additions & 1 deletion include/Server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <string>
#include <utility>
#include <vector>
#include <csignal>

//-------------------------------------------------------//

Expand Down
9 changes: 7 additions & 2 deletions src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* Server.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gilmar <gilmar@student.42.fr> +#+ +:+ +#+ */
/* By: yde-goes <yde-goes@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/28 10:26:55 by gilmar #+# #+# */
/* Updated: 2024/06/01 00:10:57 by gilmar ### ########.fr */
/* Updated: 2024/06/01 09:22:38 by yde-goes ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -423,6 +423,8 @@ const Server::command_handler Server::_command_list[_command_list_size] = {
*/
void Server::_execute_command(const std::string buffer, const int fd)
{
bool cmd_executed = false;

if (buffer.empty())
return;
std::string clean_buffer = _cleanse_buffer(buffer, CRLF);
Expand All @@ -438,9 +440,12 @@ void Server::_execute_command(const std::string buffer, const int fd)
if (command == _command_list[i].command)
{
(this->*_command_list[i].handler)(parameters, fd);
cmd_executed = true;
break;
}
}
if (!cmd_executed)
_send_response(fd, ERR_CMDNOTFOUND(command));
}

/*
Expand Down
25 changes: 16 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,31 @@
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: user42 <user42@student.42.fr> +#+ +:+ +#+ */
/* By: yde-goes <yde-goes@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/28 10:47:49 by gilmar #+# #+# */
/* Updated: 2024/05/26 11:25:34 by user42 ### ########.fr */
/* Updated: 2024/06/01 09:27:16 by yde-goes ### ########.fr */
/* */
/* ************************************************************************** */

#include "Server.hpp"

/* Use this line if you want to test the server with the automated tests
created by Criterion framework
server.init("4444", "12345"); */
int main(int argc, char** argv)
{
(void)argc;
(void)argv;
Server server;
// if (argc != 3)
// {std::cout << "Usage: " << argv[0] << " <port number> <password>" <<
// std::endl; return 1;}
std::cout << GRE << "---- SERVER ----" << WHI << std::endl;
server.init("4444", "12345");

if (argc != 3)
{
std::cout << "Usage: " << argv[0] << " <port number> <password>"
<< std::endl;
return 1;
}
std::cout << GRE << "---- WELCOME TO OUR IRC SERVER! ----" << WHI
<< std::endl;
server.init(argv[1], argv[2]);

std::cout << RED << "The Server Closed!" << WHI << std::endl;
}
4 changes: 2 additions & 2 deletions tests/TestKick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Test(KickCommand, kick_successfully_no_comments)

server._channels.push_back(channel);
server._handler_client_kick("#world trollUser", 4);

cr_assert(eq(int, server._reply_code, 200));
cr_assert(eq(
int, server._get_channel(channel->get_name())->get_clients_size(), 1));
Expand All @@ -101,7 +101,7 @@ Test(KickCommand, kick_successfully_with_comments)

server._channels.push_back(channel);
server._handler_client_kick("#world trollUser trolou", 4);

cr_assert(eq(int, server._reply_code, 200));
cr_assert(eq(
int, server._get_channel(channel->get_name())->get_clients_size(), 1));
Expand Down

0 comments on commit 0ebb2de

Please sign in to comment.