AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH

This commit is contained in:
Kbz-8
2024-01-22 14:54:39 +01:00
parent 6728b47953
commit be35fc2616
12 changed files with 360 additions and 98 deletions

View File

@@ -6,23 +6,28 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/21 10:34:25 by maldavid #+# #+# */
/* Updated: 2024/01/21 11:41:51 by maldavid ### ########.fr */
/* Updated: 2024/01/22 14:41:25 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __CHANNEL__
#define __CHANNEL__
#include <string>
namespace irc
{
class Channel
{
public:
Channel();
Channel(const std::string& name);
inline const std::string& getName() const { return _name; }
~Channel();
private:
const std::string _name;
};
}

View File

@@ -6,28 +6,51 @@
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/21 10:33:17 by maldavid #+# #+# */
/* Updated: 2024/01/22 01:29:55 by vvaas ### ########.fr */
/* Updated: 2024/01/22 13:03:37 by maldavid ### ########.fr */
/* */
/******************************************************************************/
#ifndef __CLIENT__
#define __CLIENT__
#include <irc.hpp>
#include <string>
#include <sstream>
namespace irc
{
class Client
{
public:
Client(int fd, sockaddr_in sock, int id);
inline int get_fd(void) { return (_fd); }
inline void set_fd(int new_fd) { _fd = new_fd; }
inline sockaddr_in get_sockaddr(void) { return (_s_data); }
inline std::string get_string_id(void) { std::stringstream out; out << _id; return (out.str()); }
inline void newMsgInFlight(const std::string& msg) { _msg_in_flight = msg; }
inline int getFD() const { return _fd; }
inline int getID() const { return _id; }
inline sockaddr_in getSockAddr() const { return _s_data; }
inline const std::string& getMsgInFlight() const { return _msg_in_flight; }
std::string getNextMsg();
inline void setNewNickName(const std::string& name) { _nickname = name; }
inline void setNewUserName(const std::string& name) { _username = name; }
inline void setNewRealName(const std::string& name) { _realname = name; }
inline const std::string& getNickName() const { return _nickname; }
inline const std::string& getUserName() const { return _username; }
inline const std::string& getRealName() const { return _realname; }
void printUserHeader() const;
inline void setFd(int new_fd) { _fd = new_fd; }
~Client();
private:
std::string _nickname;
std::string _username;
std::string _realname;
std::string _msg_in_flight;
sockaddr_in _s_data;
int _fd;
int _id;

19
includes/config.hpp Normal file
View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* config.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/22 09:45:10 by maldavid #+# #+# */
/* Updated: 2024/01/22 09:46:42 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __CONFIG__
#define __CONFIG__
#define INPUT_SIZE 1024
#define LOGS_BUFFER_SIZE 4096
#endif

View File

@@ -3,22 +3,23 @@
/* ::: :::::::: */
/* irc.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: vavaas <vavaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/29 13:24:01 by vvaas #+# #+# */
/* Updated: 2024/01/21 14:20:31 by vvaas ### ########.fr */
/* Created: 2023/11/29 13:24:01 by vavaas #+# #+# */
/* Updated: 2024/01/22 09:46:18 by maldavid ### ########.fr */
/* */
/******************************************************************************/
#ifndef IRC_H
# define IRC_H
#ifndef __IRC__
#define __IRC__
#include <iostream>
#include <string>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <cstdlib>
#include <sys/socket.h>
#include <arpa/inet.h>
# include <iostream>
# include <string>
# include <sys/socket.h>
# include <netinet/in.h>
# include <unistd.h>
# include <cstdlib>
# include <sys/socket.h>
# include <arpa/inet.h>
#endif

View File

@@ -6,13 +6,14 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/21 11:35:21 by maldavid #+# #+# */
/* Updated: 2024/01/21 12:04:43 by maldavid ### ########.fr */
/* Updated: 2024/01/22 11:51:25 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MESSAGE__
#define __MESSAGE__
#include <vector>
#include <string>
#include <unstd/shared_ptr.hpp>
@@ -26,10 +27,12 @@ namespace irc
inline unstd::SharedPtr<class Client> getClient() const { return _client; }
inline const std::string& getRawMsg() const { return _raw_msg; }
inline const std::string& getCmd() const { return _command; }
inline const std::vector<std::string>& getTokens() const { return _tokens; }
~Message();
private:
std::vector<std::string> _tokens;
const std::string _raw_msg;
std::string _command;
unstd::SharedPtr<class Client> _client;

View File

@@ -6,7 +6,7 @@
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/21 09:12:28 by maldavid #+# #+# */
/* Updated: 2024/01/22 01:14:42 by vvaas ### ########.fr */
/* Updated: 2024/01/22 12:16:31 by maldavid ### ########.fr */
/* */
/******************************************************************************/
@@ -20,31 +20,45 @@
#include <csignal>
#define MAX_USERS 20
namespace irc
{
class Server
{
public:
Server(int port, const std::string& password);
void wait();
~Server();
inline unsigned long get_port(void) { return (htons(_port)); }
private:
void init_socket(void);
void init_socket_data(void);
void init_signal(void);
void initSocket();
void initSocketData();
void initSignal();
void wait(void);
void add_client(int fd);
bool handleMessage(unstd::SharedPtr<class Client> client);
void handleInput();
// ugly as f*ck
void handleNick(unstd::SharedPtr<class Client> client, const class Message& msg);
void handleUser(unstd::SharedPtr<class Client> client, const class Message& msg);
void handleQuit(unstd::SharedPtr<class Client> client, const class Message& msg);
void handlePart(unstd::SharedPtr<class Client> client, const class Message& msg);
void handleJoin(unstd::SharedPtr<class Client> client, const class Message& msg);
void handlePrivMsg(unstd::SharedPtr<class Client> client, const class Message& msg);
void handleNotice(unstd::SharedPtr<class Client> client, const class Message& msg);
void handleKick(unstd::SharedPtr<class Client> client, const class Message& msg);
void handleMotD(unstd::SharedPtr<class Client> client, const class Message& msg);
void handleTopic(unstd::SharedPtr<class Client> client, const class Message& msg);
void handlePing(unstd::SharedPtr<class Client> client, const class Message& msg);
void handleMode(unstd::SharedPtr<class Client> client, const class Message& msg);
void handle_input(void);
private:
sockaddr_in _s_data;
socklen_t _s_len;
fd_set _fd_set;
std::vector<class Channel> _channels;
std::vector<class Client> _client;
std::vector<unstd::SharedPtr<class Client> > _client;
sockaddr_in _s_data;
socklen_t _s_len;
fd_set _fd_set;
const std::string _password;
const std::string _ip;
const int _port;