Skip to content

Commit

Permalink
Merge pull request #35 from ygor-sena/7-b-implement-a-bot
Browse files Browse the repository at this point in the history
fix(JOIN): fix uninitialized variable bug and add code automation with .clang-format
  • Loading branch information
gialexan authored May 31, 2024
2 parents 1b0d4e9 + dfad667 commit 104729c
Show file tree
Hide file tree
Showing 37 changed files with 2,007 additions and 1,613 deletions.
31 changes: 31 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
Language: Cpp
BasedOnStyle: Google
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: true
BreakBeforeBraces: Allman
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 80
ConstructorInitializerAllOnOneLineOrOnePerLine: true
DerivePointerAlignment: false
IncludeBlocks: Preserve
IndentCaseLabels: false
IndentPPDirectives: None
UseTab: Always
IndentWidth: 4
TabWidth: 4
108 changes: 54 additions & 54 deletions include/Channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,73 +6,73 @@
/* By: yde-goes <yde-goes@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 08:24:04 by gilmar #+# #+# */
/* Updated: 2024/05/30 15:35:19 by yde-goes ### ########.fr */
/* Updated: 2024/05/30 22:54:51 by yde-goes ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef CHANNEL_HPP
# define CHANNEL_HPP
#define CHANNEL_HPP

# include "Client.hpp"
# include "Replies.hpp"
#include "Client.hpp"
#include "Replies.hpp"

class Channel
{
public:
Channel();
~Channel();
Channel(std::string name);
public:
Channel();
~Channel();
Channel(std::string name);

int get_clients_size(void) const;
std::string get_name(void) const;
std::string get_topic(void) const;
std::string get_channel_key(void) const;
std::string get_client_names(void) const;
std::vector<Client *> get_channel_clients(void);
std::vector<Client *> get_operator_clients(void);
bool get_topic_restriction(void) const;
int get_clients_size(void) const;
std::string get_name(void) const;
std::string get_topic(void) const;
std::string get_channel_key(void) const;
std::string get_client_names(void) const;
std::vector<Client*> get_channel_clients(void);
std::vector<Client*> get_operator_clients(void);
bool get_topic_restriction(void) const;

void set_limit(int limit);
void set_invite_only(void);
void set_topic_restriction(void);
void set_topic(std::string topic);
void set_key(std::string password);
void set_channel_operator(Client *client);
void set_limit(int limit);
void set_invite_only(void);
void set_topic_restriction(void);
void set_topic(std::string topic);
void set_key(std::string password);
void set_channel_operator(Client* client);

void remove_key(void);
void remove_limit(void);
void remove_invite_only(void);
void remove_topic_restriction(void);
void remove_channel_operator(Client *client);
void remove_channel_client(Client *client);

void join(Client *client);
void kick(Client *client);
void part(Client *client);
void invite(Client *client);
void broadcast(Client *sender, std::string target, std::string message);

bool has_key(void) const;
bool has_client(Client *client);
void remove_key(void);
void remove_limit(void);
void remove_invite_only(void);
void remove_topic_restriction(void);
void remove_channel_operator(Client* client);
void remove_channel_client(Client* client);

bool is_channel_full(void) const;
bool is_channel_operator(const int fd);
bool is_channel_invite_only(void) const;
bool is_channel_operator(std::string nickname);
bool is_client_in_channel(std::string nickname);
void join(Client* client);
void kick(Client* client);
void part(Client* client);
void invite(Client* client);
void broadcast(Client* sender, std::string target, std::string message);

private:
int _limit;
std::string _key;
std::string _name;
bool _invite_only;
std::string _topic;
bool _topic_restriction;
std::string _created_at;
bool has_key(void) const;
bool has_client(Client* client);

bool _has_key;
std::vector<Client *>_clients; // -> list of clients that are channel members
std::vector<Client *>_operator_clients; // -> list of channel operators
bool is_channel_full(void) const;
bool is_channel_operator(const int fd);
bool is_channel_invite_only(void) const;
bool is_channel_operator(std::string nickname);
bool is_client_in_channel(std::string nickname);

private:
int _limit;
bool _has_key;
bool _invite_only;
bool _topic_restriction;
std::string _key;
std::string _name;
std::string _topic;
std::string _created_at;
std::vector<Client*>
_clients; // -> list of clients that are channel members
std::vector<Client*> _operator_clients; // -> list of channel operators
};

#endif //CHANNEL_HPP
#endif // CHANNEL_HPP
116 changes: 58 additions & 58 deletions include/Client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,78 +6,78 @@
/* By: yde-goes <yde-goes@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/28 10:19:06 by gilmar #+# #+# */
/* Updated: 2024/05/30 13:11:52 by yde-goes ### ########.fr */
/* Updated: 2024/05/30 22:45:05 by yde-goes ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef CLIENT_HPP
# define CLIENT_HPP
#define CLIENT_HPP

# include <iostream>
# include <vector> //-> for vector
# include <sys/socket.h> //-> for socket()
# include <sys/types.h> //-> for socket()
# include <netinet/in.h> //-> for sockaddr_in
# include <fcntl.h> //-> for fcntl()
# include <unistd.h> //-> for close()
# include <arpa/inet.h> //-> for inet_ntoa()
# include <poll.h> //-> for poll()
# include <csignal> //-> for signal()
# include <string>
# include <algorithm>
# include "Replies.hpp"
#include <arpa/inet.h> //-> for inet_ntoa()
#include <fcntl.h> //-> for fcntl()
#include <netinet/in.h> //-> for sockaddr_in
#include <poll.h> //-> for poll()
#include <sys/socket.h> //-> for socket()
#include <sys/types.h> //-> for socket()
#include <unistd.h> //-> for close()
#include <algorithm>
#include <csignal> //-> for signal()
#include <iostream>
#include <string>
#include <vector> //-> for vector
#include "Replies.hpp"

//-------------------------------------------------------//
# define RED "\e[1;31m" //-> for red color
# define WHI "\e[0;37m" //-> for white color
# define GRE "\e[1;32m" //-> for green color
# define YEL "\e[1;33m" //-> for yellow color
#define RED "\e[1;31m" //-> for red color
#define WHI "\e[0;37m" //-> for white color
#define GRE "\e[1;32m" //-> for green color
#define YEL "\e[1;33m" //-> for yellow color
//-------------------------------------------------------//

class Client //-> class for client
class Client //-> class for client
{
public:
Client();
public:
Client();

int get_fd() const;
bool get_is_logged() const;
std::string get_buffer() const;
std::string get_nickname() const;
std::string get_username() const;
std::string get_password() const;
std::string get_hostname() const;
std::vector<std::string> get_channels_invited() const;
std::string get_ip_address() const;
bool get_is_authenticated() const;
bool get_is_operator() const;
int get_fd() const;
bool get_is_logged() const;
std::string get_buffer() const;
std::string get_nickname() const;
std::string get_username() const;
std::string get_password() const;
std::string get_hostname() const;
std::vector<std::string> get_channels_invited() const;
std::string get_ip_address() const;
bool get_is_authenticated() const;
bool get_is_operator() const;

void set_fd(const int fd);
void set_is_logged(bool is_logged);
void set_ip_add(const std::string &ipadd);
void set_buffer(const std::string &buffer);
void set_nickname(const std::string &nickname);
void set_username(const std::string &username);
void set_password(const std::string &password);
void set_is_authenticated(bool is_authenticated);
void set_is_operator(bool is_operator);
void set_fd(const int fd);
void set_is_logged(bool is_logged);
void set_ip_add(const std::string& ipadd);
void set_buffer(const std::string& buffer);
void set_nickname(const std::string& nickname);
void set_username(const std::string& username);
void set_password(const std::string& password);
void set_is_authenticated(bool is_authenticated);
void set_is_operator(bool is_operator);

bool is_channel_invited(const std::string &channel);
void add_channel_invited(const std::string &channel);
void remove_channel_invited(const std::string &channel);
bool is_channel_invited(const std::string& channel);
void add_channel_invited(const std::string& channel);
void remove_channel_invited(const std::string& channel);

void broadcast(Client *sender, std::string target, std::string message);
void broadcast(Client* sender, std::string target, std::string message);

private:
int _fd; //-> client file descriptor
bool _is_logged; //-> boolean for login
std::string _buffer; //-> client buffer
bool _is_authenticated; //-> boolean for authentication
bool _is_operator; //-> boolean for channel operator
std::string _ip_addr; //-> client ip address
std::string _nickname; //-> client nickname
std::string _username; //-> client username
std::string _password; //-> client password
std::vector<std::string> _channels_invited; //-> vector of channels invited
private:
int _fd; //-> client file descriptor
bool _is_logged; //-> boolean for login
bool _is_authenticated; //-> boolean for authentication
bool _is_operator; //-> boolean for channel operator
std::string _buffer; //-> client buffer
std::string _ip_addr; //-> client ip address
std::string _nickname; //-> client nickname
std::string _username; //-> client username
std::string _password; //-> client password
std::vector<std::string> _channels_invited; //-> vector of channels invited
};

#endif // CLIENT_HPP
#endif // CLIENT_HPP
85 changes: 46 additions & 39 deletions include/MarvinBot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,54 @@
/* ************************************************************************** */

#ifndef MARVINBOT_HPP
# define MARVINBOT_HPP

# include "Server.hpp"
# include "Replies.hpp"

# define SOCRATES_KNOWLEDGE "I know that I know nothing. - Socrates"
# define DESCARTES_EXISTENCE "I think, therefore I am. - René Descartes"
# define KANT_CATEGORICAL_IMPERATIVE "Act only according to that maxim whereby you can, at the same time, will that it should become a universal law. - Immanuel Kant"
# define NIETZSCHE_GOD "God is dead! - Friedrich Nietzsche"
# define PLATO_FORMS "The Forms are eternal and changeless. - Plato"
# define MARX_RELIGION "Religion is the opium of the people. - Karl Marx"
# define CONFUCIUS_WISDOM "Real knowledge is to know the extent of one's ignorance. - Confucius"
# define HUME_SCIENCE "A wise man proportions his belief to the evidence. - David Hume"
# define HEIDEGGER_BEING "Being is time, and time is finite. - Martin Heidegger"
# define ROUSSEAU_FREEDOM "Man is born free, and everywhere he is in chains. - Jean-Jacques Rousseau"
#define MARVINBOT_HPP

#include "Replies.hpp"
#include "Server.hpp"

#define SOCRATES_KNOWLEDGE "I know that I know nothing. - Socrates"
#define DESCARTES_EXISTENCE "I think, therefore I am. - René Descartes"
#define KANT_CATEGORICAL_IMPERATIVE \
"Act only according to that maxim whereby you can, at the same time, " \
"will that it should become a universal law. - Immanuel Kant"
#define NIETZSCHE_GOD "God is dead! - Friedrich Nietzsche"
#define PLATO_FORMS "The Forms are eternal and changeless. - Plato"
#define MARX_RELIGION "Religion is the opium of the people. - Karl Marx"
#define CONFUCIUS_WISDOM \
"Real knowledge is to know the extent of one's ignorance. - Confucius"
#define HUME_SCIENCE \
"A wise man proportions his belief to the evidence. - David Hume"
#define HEIDEGGER_BEING "Being is time, and time is finite. - Martin Heidegger"
#define ROUSSEAU_FREEDOM \
"Man is born free, and everywhere he is in chains. - Jean-Jacques " \
"Rousseau"

class MarvinBot
{
public:
MarvinBot();
~MarvinBot();

// Enum for quotes
enum EnumMarvinBotQuotes {
QUOTE_SOCRATES_KNOWLEDGE,
QUOTE_DESCARTES_EXISTENCE,
QUOTE_KANT_CATEGORICAL_IMPERATIVE,
QUOTE_NIETZSCHE_GOD,
QUOTE_PLATO_FORMS,
QUOTE_MARX_RELIGION,
QUOTE_CONFUCIUS_WISDOM,
QUOTE_HUME_SCIENCE,
QUOTE_HEIDEGGER_BEING,
QUOTE_ROUSSEAU_FREEDOM,
QUOTES_COUNT // To keep track of the number of quotes
};

const char* marvin_bot_quotes[QUOTES_COUNT];

private:
std::string _return_quote();
public:
MarvinBot();
~MarvinBot();

// Enum for quotes
enum EnumMarvinBotQuotes
{
QUOTE_SOCRATES_KNOWLEDGE,
QUOTE_DESCARTES_EXISTENCE,
QUOTE_KANT_CATEGORICAL_IMPERATIVE,
QUOTE_NIETZSCHE_GOD,
QUOTE_PLATO_FORMS,
QUOTE_MARX_RELIGION,
QUOTE_CONFUCIUS_WISDOM,
QUOTE_HUME_SCIENCE,
QUOTE_HEIDEGGER_BEING,
QUOTE_ROUSSEAU_FREEDOM,
QUOTES_COUNT // To keep track of the number of quotes
};

const char* marvin_bot_quotes[QUOTES_COUNT];

private:
std::string _return_quote();
};

#endif // MARVINBOT_HPP
#endif // MARVINBOT_HPP
Loading

0 comments on commit 104729c

Please sign in to comment.