-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirectoryServer.h
66 lines (57 loc) · 1.77 KB
/
directoryServer.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
#ifndef DIRECTORYSERVER_H
#define DIRECTORYSERVER_H
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <vector>
#include <string>
#include <mutex>
#include "UDPSocket.h"
#include "Message.h"
#include "rapidcsv.h"
#define TIMEOUT 30;
//#define MAX_SAMPLES 10;
using namespace std;
class directoryServer
{
private:
string usersFile = "./users.csv";
mutex mtx,mtxStatus;
UDPSocket udpObj;
thread* listen_thread = nullptr;
thread* status_thread = nullptr;
//everything here is stored in users.csv + username
struct data
{
string password;
int online = 0; //bool causes issues
string ip = "";
unsigned int port;
string token;
int imageCount;
vector <string> imageName;
vector <string> image64;
};
unordered_map<string, data> usersDict;
unordered_map<string, int> statusDict;
void login(string&, string&, Message* , directoryServer*);
void logout(string&, Message*, directoryServer*);
void signup(string&, string&, Message* , directoryServer*);
void uploadimage(string&, string&, string&, Message* , directoryServer*);
string getPortnIP(string&, string&, Message*, directoryServer*);//string of "port,ip"
string getAllImages(string&, Message*, directoryServer*);//string of username,imagename,image(base64),...
bool authenticate(string&, string&);
bool usernameExists(string&);
void updateStatus(string& , directoryServer*);
void removeImage(string&, string&, Message*, directoryServer*);
string getOnlineUsers(string&, Message*, directoryServer*);
bool checkOnline(string&);
void decrementStatus();
void clearUsers();
public:
directoryServer(unsigned int);
~directoryServer();
void listen();
void doOperation(Message *request);
};
#endif