This commit is contained in:
2024-01-30 17:34:39 +01:00
parent befdd7afbf
commit 64fb3e539d
2 changed files with 23 additions and 4 deletions

View File

@@ -6,7 +6,7 @@
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/30 01:54:56 by vvaas #+# #+# */
/* Updated: 2024/01/30 17:07:02 by vvaas ### ########.fr */
/* Updated: 2024/01/30 17:26:11 by vvaas ### ########.fr */
/* */
/******************************************************************************/
@@ -18,7 +18,8 @@
#include <fcntl.h>
#include <cstring>
bot::bot() {}
bot::bot() : _channel_created(false), _logged(false)
{}
bot::~bot() {}
@@ -27,6 +28,7 @@ void bot::init()
_connect_commands.push_back("PASS " PASSWORD "\r\n");
_connect_commands.push_back("NICK greg\r\n");
_connect_commands.push_back("USER greg_bot 0 * :botrealname\r\n");
_connect_commands.push_back("JOIN #greg\r\n");
_fd = socket(AF_INET, SOCK_STREAM, 0);
if (_fd == -1)
irc::logs::report(irc::log_fatal_error, "FD error");
@@ -41,7 +43,20 @@ void bot::init()
void bot::handle_response(std::string buffer)
{
if (buffer == ":yipirc 001 greg :Welcome to yipirc :), greg\r\n")
std::cout << buffer << std::flush;
if (!_logged && buffer == ":yipirc 001 greg :Welcome to yipirc :), greg\r\n")
{
_logged = true;
irc::logs::report(irc::log_message, "Logged in succesfully");
}
else if (!_logged)
return ;
if (!_channel_created && buffer == ":yipirc 353 greg @ #greg :@greg\r\n")
{
_channel_created = true;
irc::logs::report(irc::log_message, "Created the channel succesfully");
}
else if (!_channel_created)
return ;
}
@@ -52,6 +67,8 @@ void bot::connect_to_server()
{
if (send(_fd, (*it).c_str(), (*it).size(), 0) < 0)
irc::logs::report(irc::log_fatal_error, "send error");
if (recv(_fd, buffer, 1024, 0) > 0)
handle_response(buffer);
}
while (true)
{