-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathServerClass.hpp
More file actions
124 lines (107 loc) · 3.66 KB
/
ServerClass.hpp
File metadata and controls
124 lines (107 loc) · 3.66 KB
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
124
#ifndef SERVER_CLASS_HPP
#define SERVER_CLASS_HPP
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <iostream>
#include <sys/select.h>
#include <netdb.h>
#include <string>
#include <unistd.h>
#include <map>
#include <list>
#include <queue>
#include <sstream>
#include <cstring>
#include "MsgIRC.hpp"
#include "UserIRC.hpp"
#include "socket.hpp"
#include "debug.hpp"
#include "Channel.hpp"
// #include "replies.hpp"
// #include "server.hpp"
#ifdef __linux__
#define exit _exit; //linux
#endif
struct MsgIRC;
class Channel;
using namespace std;
# define SERVER_NAME "EpikEkipEkolegram"
# define SERVER_VERSION "42.69"
class Server {
public:
Server();
Server(const int& port, const string& pwd = "password");
~Server();
void launch();
const string& name() const;
void sendMessage(UserIRC* receiver, PayloadIRC payload);
void sendMessage(UserIRC* sender, UserIRC* receiver, PayloadIRC payload);
UserList _users;
queue<MsgIRC> _msgQueue;
map<string, Channel> _channels;
list<UserIRC> _usersHistory;
const string _startTime;
const string _hostName;
const string _version;
const string _password;
private:
void bindEndpoint();
int createEndpoint(void);
void serverLoop(int &endpoint);
void initializeMap();
const int _port;
int _endpoint;
map<string, int(*)(MsgIRC&, Server&)> _handlerFunction;
static const int DEFAULT_PORT = 6667;
static const int BUFFER_SIZE = 1024;
};
std::string randomPwd(const int len);
string getDateTime();
//send a message to all users that are on the same channel that input user
void sendToAllChan(PayloadIRC& payload, UserIRC *user, Server &server);
//same but without the exeption on the user
void sendToAllChan2(PayloadIRC& payload, UserIRC *user, Server &server);
void sendToAllChanInfo(PayloadIRC& payload, UserIRC *user, Server &server);
//remove the user from all channels it was connected
void removeUsersFromAllChans(UserIRC *user, Server &server);
bool chanExist(const string& channel, Server &server);
/*
-------handlerFunction--------
please put your functions here using the template [int function(MsgIRC&, ServerClass&)]
and in initializeMap() for the referencement
all functions here may broke msg so don't use it afterward
*/
int funCap(MsgIRC& msg, Server& server);
int NICKParser(MsgIRC& msg, Server& server);
int USERParser(MsgIRC& msg, Server& server);
int QUITParser(MsgIRC& msg, Server& server);
int JOINParser(MsgIRC& msg, Server& server);
int MODEParser(MsgIRC& msg, Server& server);
int PRIVMSGParser(MsgIRC& msg, Server& server);
int WHOParser(MsgIRC& msg, Server& server);
int NAMESParser(MsgIRC& msg, Server& server);
int MOTD(MsgIRC& msg, Server& server);
int INFOParser(MsgIRC& msg, Server& server);
int AWAY(MsgIRC& msg, Server& server);
int TIME(MsgIRC& msg, Server& server);
int USERHOSTParser(MsgIRC& msg, Server& server);
int IsonParser(MsgIRC& msg, Server& server);
int PINGParser(MsgIRC& msg, Server& server);
int PONGParser(MsgIRC& msg, Server& server);
int PARTParser(MsgIRC& msg, Server& server);
int TOPICParser(MsgIRC& msg, Server& server);
int LISTParser(MsgIRC& msg, Server& server);
int KICKParser(MsgIRC& msg, Server& server);
int KILLParser(MsgIRC& msg, Server& server);
int MODEUser(MsgIRC& msg, Server& server, string& target);
int MODEChannel(MsgIRC& msg, Server& server, string& target);
int INVITEParser(MsgIRC& msg, Server& server);
int WHOISParser(MsgIRC& msg, Server& server);
int WHOWASParser(MsgIRC& msg, Server& server);
int ADMINParser(MsgIRC& msg, Server& server);
int LUSERSParser(MsgIRC& msg, Server& server);
int OPERATORParser(MsgIRC& msg, Server& server);
int PASSParser(MsgIRC& msg, Server& server);
int NOTICEParser(MsgIRC& msg, Server& server);
#endif