nerd emoji
This commit is contained in:
15
Makefile
15
Makefile
@@ -1,14 +1,14 @@
|
||||
# **************************************************************************** #
|
||||
#******************************************************************************#
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: vavaas <vvaas@student.42.fr> +#+ +:+ +#+ #
|
||||
# By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/08/09 15:08:49 by vavaas #+# #+# #
|
||||
# Updated: 2024/01/21 12:04:28 by maldavid ### ########.fr #
|
||||
# Updated: 2024/01/21 17:23:26 by vvaas ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
#******************************************************************************#
|
||||
|
||||
NAME = ircserv
|
||||
|
||||
@@ -24,7 +24,12 @@ OBJ_DIR = objs
|
||||
OBJS = $(addprefix $(OBJ_DIR)/, $(SRCS:.cpp=.o))
|
||||
|
||||
CXX = c++
|
||||
CXXFLAGS = -std=c++98 -Wall -Wextra -Werror -I includes
|
||||
FLAGS ?= true
|
||||
CXXFLAGS = -std=c++98 -I includes
|
||||
ifeq ($(FLAGS), true)
|
||||
CXXFLAGS += -Wall -Wextra -Werror
|
||||
endif
|
||||
|
||||
|
||||
DEBUG ?= false
|
||||
MODE = "release"
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* client.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/21 10:33:17 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/21 10:34:13 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/01/21 16:32:05 by vvaas ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
|
||||
#ifndef __CLIENT__
|
||||
#define __CLIENT__
|
||||
@@ -18,11 +18,12 @@ namespace irc
|
||||
class Client
|
||||
{
|
||||
public:
|
||||
Client();
|
||||
Client(int fd);
|
||||
|
||||
~Client();
|
||||
|
||||
private:
|
||||
int _fd;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* irc.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: vvaas <vvaas@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/29 13:24:01 by vvaas #+# #+# */
|
||||
/* Updated: 2023/11/29 16:32:34 by vvaas ### ########.fr */
|
||||
/* Updated: 2024/01/21 14:20:31 by vvaas ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
|
||||
#ifndef IRC_H
|
||||
# define IRC_H
|
||||
@@ -20,5 +20,5 @@
|
||||
# include <unistd.h>
|
||||
# include <cstdlib>
|
||||
# include <sys/socket.h>
|
||||
|
||||
# include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
@@ -1,21 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* server.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/21 09:12:28 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/21 10:37:58 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/01/21 17:18:17 by vvaas ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
|
||||
#ifndef __SERVER_IRC__
|
||||
#define __SERVER_IRC__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <irc.hpp>
|
||||
#include <unstd/shared_ptr.hpp>
|
||||
|
||||
#define MAX_USERS 20
|
||||
namespace irc
|
||||
{
|
||||
class Server
|
||||
@@ -24,12 +27,24 @@ namespace irc
|
||||
Server(int port, const std::string& password);
|
||||
|
||||
~Server();
|
||||
inline unsigned long get_port(void) { return (htons(_port)); }
|
||||
|
||||
private:
|
||||
void init_socket(void);
|
||||
void wait(void);
|
||||
|
||||
private:
|
||||
sockaddr_in _s_data;
|
||||
socklen_t _s_len;
|
||||
fd_set _fd_set;
|
||||
|
||||
std::vector<class Channel> _channels;
|
||||
std::vector<unstd::SharedPtr<class Client> > _client;
|
||||
const std::string _password;
|
||||
const std::string _ip;
|
||||
const int _port;
|
||||
int _socket;
|
||||
int _main_socket;
|
||||
bool _active;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* client.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/21 10:35:52 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/21 10:36:20 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/01/21 16:32:12 by vvaas ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
|
||||
#include <client.hpp>
|
||||
|
||||
namespace irc
|
||||
{
|
||||
Client::Client()
|
||||
Client::Client(int fd) : _fd(fd)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/20 09:27:04 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/21 12:16:41 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/01/21 16:14:07 by vvaas ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
|
||||
#include <logs.hpp>
|
||||
#include <cstdlib>
|
||||
@@ -24,13 +24,12 @@ int main(int ac, char** av)
|
||||
irc::logs::report(irc::log_message, "usage './ircserv <port> <password>', try again dumbass");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(av[1] == NULL || av[2] == NULL)
|
||||
irc::logs::report(irc::log_fatal_error, "invalid argv, argv[1] or argv[2] is NULL (wtf)");
|
||||
|
||||
char* end;
|
||||
long port = std::strtol(av[1], &end, 10);
|
||||
if(errno == ERANGE || *end != 0 || port < 0 || port > 0xffff)
|
||||
int port = std::strtol(av[1], &end, 10);
|
||||
if(errno == ERANGE || *end != 0 || port < 0 || port > 0xFFFF || std::strlen(av[1]) == 0)
|
||||
irc::logs::report(irc::log_fatal_error, "invalid port");
|
||||
|
||||
irc::Server server(port, av[2]);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Server::~Server() {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user