-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.h
70 lines (58 loc) · 1.51 KB
/
server.h
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
#ifndef __SERVER__
#define __SERVER__
//#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <poll.h>
#include <thread>
#include <string>
#include <vector>
#include <unordered_map>
#include <mutex>
#include <memory>
#include <algorithm>
#include <nlohmann/json.hpp>
#include "util.h"
#include "room.h"
#define MAX_CLIENTS 10
using json = nlohmann::json;
class Server
{
private:
/* data */
int lis_sockfd;
int *cli_sockfd;
std::vector<int> list_client;
std::unordered_map<std::string, std::unique_ptr<Room>> list_room;
std::vector<std::string> closed_rooms;
std::mutex mtx_client;
std::mutex mtx_fds;
struct pollfd fds[MAX_CLIENTS];
int nfds, value_read;
char buffer[BUFFER_SIZE] = {0};
std::thread * hilo;
bool listen_data;
public:
Server(int port);
~Server();
bool send_message(const int &cli_sockfd, json msg);
bool choose_room(const std::string &, const int &);
void start();
bool set_up_connection();
void set_listen();
json read_data(int);
void add_client(int, bool = true);
void manage_data(json, const int &);
bool autenticar(const int &, const int &);
void reinsertar(const int &, const int &);
bool create_room(const std::string &, const int &);
std::vector<std::string> get_room_list();
void close_room(const int &, const int &, std::string &);
void clear_rooms();
};
#endif