forked from codewhite7777/ft_irc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer.hpp
123 lines (96 loc) · 3.51 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Server.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mgo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/12 11:20:30 by mgo #+# #+# */
/* Updated: 2022/10/12 11:20:31 by mgo ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SERVER_HPP
# define SERVER_HPP
# include "Chatbot.hpp" // todo: organize
# include <list>
# include <map>
# include <netinet/in.h>
# include <string>
typedef int SOCKET;
typedef enum e_buf
{
BUFFER_MAX = 1024 << 4
} t_buf;
class Command;
class Protocol;
class Client;
class Channel;
class Server
{
public:
Server(int argc, char *argv[]);
~Server(void);
bool getStatus(void) const;
void Run(void);
void equipCommandAndProtocol(\
Command* cmd, Protocol* proto);
Command* getCommand() const;
Protocol* getProtocol() const;
const std::string& getName(void) const;
std::string getNamePrefix() const;
const std::string& getVersion() const;
const std::string& getPwd(void) const;
std::string getCreatedDateAsString() const;
bool isOverlapNickName(std::string& search_nick);
Channel* findChannel(std::string chann_name);
void assignNewChannel(Channel* new_chann);
Client* findClient(std::string clnt_nickname);
std::list<Client*>* makeOtherClntListInSameChanns(Client* clnt);
void requestAllChannsToEraseOneUser(Client* clnt);
void requestAllChannsToReplaceKeyNickOfUser(Client* clnt, \
std::string nick_to_key);
bool isOperName(std::string name);
bool isOperPassword(std::string password);
bool isOperHost(std::string hostname);
const std::string& getOperType() const;
void requestAllClientsToDisconnect();
void sendErrorClosingLinkProtoToAllClientsWithMsg(\
std::string msg);
void setStatusOff();
private:
bool configPort(std::string port);
bool configPwd(std::string pwd);
void networkInit(void);
void networkClose(void);
int getMaxSD(void);
void networkProcess(void);
void acceptClient(SOCKET listen_sock);
void recvMsgEachClnt(SOCKET sd, Client* clnt);
void sendMsgEachClnt(SOCKET sd, Client* clnt);
void processClientMessages(void);
void clientDisconnect(void);
void requestAllChannsToQuitClntUnexpectdly(Client* clnt);
bool status_;
std::string raw_port_;
std::string raw_pwd_;
Command* cmd_;
Protocol* proto_;
std::string name_;
const std::string version_;
const time_t created_time_;
SOCKET listen_sock_;
struct sockaddr_in s_addr_in_;
unsigned short s_port_;
std::string s_ip_;
unsigned int sock_count_;
const std::string oper_name_;
const std::string oper_pwd_;
const std::string oper_host_;
const std::string oper_type_;
std::map<SOCKET, Client*> client_map_;
fd_set read_set_;
fd_set write_set_;
std::map<std::string, Channel*> chann_map_;
ChatBot night_bot;
};
#endif