-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.hpp
123 lines (106 loc) · 3.37 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
#pragma once
#include <iostream>
#include <ctime>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/poll.h>
#include <map>
#include <vector>
#include <string>
#include <sstream>
#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include "errors.hpp"
#include "Channel.hpp"
#include "Command.hpp"
#include "User.hpp"
#include "socket.hpp"
using std::string;
using std::map;
using std::vector;
class Server
{
public:
Server(int argc, char **argv);
~Server();
// CONNECTION
void setupPoll(int);
int addConnection(int);
int removeConnection(int);
void executeCommand(User &, Command&);
void processCommands(User &);
void receiveInput(int);
void acceptUser();
void disconnectUser(User &u);
void run(void);
// SEND
void sendResponseServer(string, string, User&);
void sendResponse(string, User&);
void sendResponseRaw(string, User&);
void sendToChannel(string, Channel, User);
// COMMANDS
void pass(User&, Command&);
void nick(User&, Command&);
void user(User&, Command&);
void ping(User&, Command&);
void cap(User&, Command&);
void oper(User&, Command&);
void quit(User&, Command&);
void join(User&, Command&);
void part(User&, Command&);
void topic(User&, Command&);
void list(User&, Command&);
void kick(User&, Command&);
void registrate(User&);
void removeChannel(vector<Channel>::iterator);
void applyUserModes(User&, Command&);
void sendApply(Channel &chan, User &user, Command& c, string &modestring);
void changeUserMode(Channel &, User&, Command&);
string getUserModes(void);
// string getChannelModes(string);
void userMode(string, User&, Command&);
void channelMode(string, User&, Command&);
void mode(User&, Command&);
string getRPL_list(User&, bool letUserSeeThemselves = false);
string getRPL_namelist(std::vector<Channel>::iterator, User&);
void privmsg(User&, Command&);
void notice(User&, Command&);
void who(User&, Command&);
bool alreadyInUse(string, string);
map<string, string> parseChannels(User&, string);
map<string, string> parseChannels(User&, string, string);
vector<string> parseUsers(string);
string getUsersIn(vector<Channel>::iterator);
void addUser(vector<Channel>::iterator, User&);
void joinChannel(map<string, string>::iterator, User&);
bool notInChannelNames(string);
bool inChannelNames(string);
void cleanupUser(int);
vector<Channel>::iterator getChannel(string);
User& getUser(string);
map<int, User>::iterator getUserFD(int);
bool isUserIn(User&, string);
bool isUserRegistered(string);
string getChannelNames(User&, bool letUserSeeThemselves = false);
vector<string> parseChannelPRIVMSG(User&, string);
private:
int _port;
string _password;
string _operpass;
pollfd _userPoll[SOMAXCONN];
nfds_t _activeUsers;
int _activePoll;
bool _stop;
bool _is_first;
int _listeningSocket;
map<int, User> _users;
vector<Channel> _channels;
void loop();
};
string parsePassword(string);
bool isChannelValid(string);
bool contains(string&, string const &);
void to_upper(string&);
void printsvec(vector<string>);
vector<string> split(string, char);