-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer.hpp
107 lines (100 loc) · 4.17 KB
/
Server.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Server.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rchahban <rchahban@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/29 22:08:43 by rchahban #+# #+# */
/* Updated: 2024/07/23 04:52:21 by rchahban ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SERVER_HPP
# define SERVER_HPP
#include "./irc_serv.hpp"
#include "./Client.hpp"
#include "./Channel.hpp"
#define RED "\033[0;31m"
#define GREEN "\033[0;32m"
#define RESET "\033[0m"
#define YELLOW "\033[0;33m"
#define BLUE "\033[0;34m"
#define CYAN "\033[0;36m"
class Server {
private:
int port;
std::string password;
int fd;
static bool signal;
std::vector<Client *> clients;
std::vector<Channel *> channels;
std::vector<struct pollfd> fds;
public:
void displayChannels();
void displayInvitedChannels();
Server();
Server(int port, std::string& password);
Server(const Server& original);
Server& operator=(const Server& original);
~Server();
void init();
// GETTERS AND SETTERS
int getPort();
void setPort(int _port);
int getFd();
void setFd(int _fd);
std::string getPassword();
void setPassword(std::string _password);
std::vector<Client> getClients();
void setClients(std::vector<Client> _clients);
void AddToClients(Client& client);
void removeClient(int _fd);
void removeFd(int _fd);
Client *getClient(int _fd);
bool passwordsMatch(std::string _password);
void cmd_parser(std::string &msg, int fd);
Channel* getChannelByName(std::string name);
Client* getClientByName(std::string nick);
int getClientsNumberInChannel(std::string channelName);
bool clientAlreadyInChannel(int fd, std::string channelName);
bool clientIsInvited(int fd, Channel *channel);
static void handleSignal(int signum);
std::string getClientList(Channel *channel);
void removeClients();
void removeChannels();
void removePollFds();
void removeClientFromChannels(int _fd);
void displayClients();
//****** IRC COMMANDS ******//
void invite(std::string &msg, int fd);
void topic(std::string &msg, int fd);
void kick(std::string &msg, int fd);
void mode(std::string &msg, int fd);
void nick(std::string &msg, int fd);
void pass(std::string &msg, int fd);
void user(std::string &msg, int fd);
void join(std::string &msg, int fd);
void privmsg(std::string &msg, int fd);
Channel* inviteErreurHandler(std::vector<std::string> cmd, int fd);
Channel* topicErreurHandler(std::vector<std::string> cmd, int fd);
Channel* handlerkickcommand(std::vector<std::string> cmd, int fd);
Channel* handlermodecommand(std::vector<std::string> cmd, int fd);
bool handlerpasscommand(std::vector<std::string> cmd, int fd);
bool handlernickcommand(std::vector<std::string> cmd, int fd);
bool checkpass(std::string pass);
void handleNonExistingChannel(std::vector<std::pair<std::string, std::string> >&token, int i, int fd);
void createChannel(int fd, std::vector<std::pair<std::string, std::string> >&tokens, int x);
//****** utils funciton ******//
int splitJoinArgs(std::vector<std::pair<std::string, std::string> >& tokens, std::string msg, int fd);
void sendError(int code, std::string clientName, std::string channelName, int fd, std::string msg);
void sendError(int code, std::string clientname, int fd, std::string msg);
void sendResponse(std::string response, int fd);
int SearchForClients(std::string nickName);
void quit(std::string &msg, int fd);
// void handleSignal(int signum);
void sendMsg(int fd, std::string msg);
void handler_cmd_parser(std::string &msg, int fd);
Channel *senderreur(int fd, std::string msg);
void sendWelcome(int fd);
};
#endif