-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheader.hpp
78 lines (69 loc) · 2.55 KB
/
header.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
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define MAX_CLIENTS 1005
// #define DEBUG 1
#ifndef _HEADER_HPP_
#define _HEADER_HPP_
struct User {
std::string username;
std::string password;
std::string status = "offline"; // default status is offline
};
struct ChatRecord {
std::string username;
std::string message;
};
class ChatRoom {
public:
std::string owner;
std::vector<int> clients;
std::vector<ChatRecord> history;
std::pair<std::string, std::string> pinned_message; // username and message
std::vector<std::string> filter_list;
ChatRoom();
ChatRoom(const std::string &owner);
};
class Server {
private:
std::map<int, User *> clients;
std::vector<User *> registerd_user;
std::map<int, ChatRoom> chatRooms;
std::set<std::string> loggedInUsers;
std::map<int, int> client_in_chat_room;
fd_set master_set;
public:
Server();
fd_set getMasterSet();
void addSocket(int socket);
void removeSocket(int socket);
std::string registerUser(std::vector<std::string> tokens);
std::string loginUser(std::vector<std::string> tokens, int client_socket);
std::string logoutUser(std::vector<std::string> tokens, int client_socket);
std::string exitUser(std::vector<std::string> tokens, int client_socket, int client_socket_list[]);
std::string getwhoami(std::vector<std::string> tokens, int client_socket);
std::string setClientStatus(std::vector<std::string> tokens, int client_socket);
std::string listUser(std::vector<std::string> tokens, int client_socket);
std::string enterChatRoom(std::vector<std::string> tokens, int client_socket);
std::string listChatRoom(std::vector<std::string> tokens, int client_socket);
std::string closeChatRoom(std::vector<std::string> tokens, int client_socket);
std::string setPinMessage(std::vector<std::string> tokens, int client_socket);
std::string deletePinMessage(std::vector<std::string> tokens, int client_socket);
std::string exitChatRoom(std::vector<std::string> tokens, int client_socket);
std::string listUserinChatRoom(std::vector<std::string> tokens, int client_socket);
std::string sendMessage(std::vector<std::string> tokens, int client_socket);
void handleCommand(int client_socket, std::string command, int client_socket_list[]);
};
int setupServer(int port);
#endif