Repository navigation
Expand file tree
/
Copy pathServer.hpp
More file actions
60 lines (50 loc) · 1.43 KB
/
Copy pathServer.hpp
File metadata and controls
60 lines (50 loc) · 1.43 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
#ifndef SERVER_HPP
#define SERVER_HPP
#include <string>
#include <map>
#include "User.hpp"
#include "Channel.hpp"
#include <signal.h>
#include <iostream>
#include <cstdlib>
#include <unistd.h>
#include <cctype>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <algorithm>
#include <errno.h>
#include <sys/select.h>
class Server {
private:
int server_fd;
int port;
std::string password;
std::map<int, User*> users;
std::map<std::string, Channel> channels;
void setupServer();
void handleNewConnection();
void handleClientData(int client_fd);
bool checkClientConnection(int client_fd);
public:
Server(int port, const std::string& password);
~Server();
void run(volatile sig_atomic_t& shutdown_requested);
void disconnectUser(int fd);
void handleWrite(int fd);
void broadcast(const std::string& channel_name, const std::string& message);
int getServerFd() const;
const std::string& getPassword() const;
const std::map<int, User*>& getUsers() const;
const std::map<std::string, Channel>& getChannels() const;
void addUser(int fd);
void removeUser(int fd);
User* getUser(int fd);
Channel* getChannel(const std::string& name);
const Channel* getChannel(const std::string& name) const;
void createChannel(const std::string& name);
void removeChannel(const std::string& name);
};
#endif