nerd emoji

This commit is contained in:
2024-01-21 18:15:48 +01:00
parent 9ae6ad183b
commit 9f8fb8902a
7 changed files with 92 additions and 42 deletions

View File

@@ -1,18 +1,20 @@
/* ************************************************************************** */
/******************************************************************************/
/* */
/* ::: :::::::: */
/* server.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/21 09:31:17 by maldavid #+# #+# */
/* Updated: 2024/01/21 12:13:51 by maldavid ### ########.fr */
/* Updated: 2024/01/21 17:31:15 by vvaas ### ########.fr */
/* */
/* ************************************************************************** */
/******************************************************************************/
#include <server.hpp>
#include <client.hpp>
#include <channel.hpp>
#include <logs.hpp>
#include <cstring>
/** Commands to handle
* NICK
@@ -31,13 +33,41 @@
namespace irc
{
Server::Server(int port, const std::string& password) : _password(password), _port(port)
Server::Server(int port, const std::string& password) : _s_len(sizeof(_s_data)), _password(password), _port(port), _active(true)
{
(void)_port;
(void)_password;
(void)_socket;
(void)_channels;
std::memset(&_s_data, 0, sizeof(sockaddr));
init_socket();
wait();
}
void Server::init_socket(void)
{
_s_data.sin_family = AF_INET;
_s_data.sin_addr.s_addr = INADDR_ANY;
_s_data.sin_port = htons(_port);
_main_socket = socket(AF_INET, SOCK_STREAM, 0); // AF_INET == IPv4, SOCK_STREAM == TCP
if (_main_socket < 0)
irc::logs::report(irc::log_fatal_error, "socket error");
std::cout << "Socket creating succesful" << std::endl;
if (bind(_main_socket, (struct sockaddr *)&_s_data, sizeof(_s_data)) != 0)
irc::logs::report(irc::log_fatal_error, "bind error");
std::cout << "bind succesful, starting listen loop" << std::endl;
if (listen(_main_socket, MAX_USERS) != 0)
irc::logs::report(irc::log_fatal_error, "listen error");
std::cout << "listen queue created succesful" << std::endl;
}
Server::~Server() {}
void Server::wait(void)
{
while (_active)
{
FD_ZERO(&_fd_set);
FD_SET(_main_socket, &_fd_set);
}
}
Server::~Server()
{
if (_main_socket > 0)
close(_main_socket);
}
}