-
Notifications
You must be signed in to change notification settings - Fork 0
/
TriviaServer.h
82 lines (60 loc) · 1.71 KB
/
TriviaServer.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
71
72
73
74
75
76
77
78
79
80
81
82
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include <WS2tcpip.h>
#include<WinSock2.h>
#include<Windows.h>
#include <queue>
#include <map>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <iostream>
#include "Helper.h"
#include "RecievedMessage.h"
#include "Protocol.h"
#pragma comment(lib, "ws2_32.lib")
using namespace std;
#define MAX_LENGTH 1024
/***********/
class TriviaServer
{
public:
TriviaServer();
~TriviaServer();
void server();
private:
void bindAndListen();
void accept();
void clientHandler(SOCKET s);
void safeDeleteUser(RecievedMessage* m);
User* handleSignin(RecievedMessage* m);
bool handleSignup(RecievedMessage* m);
void handleSignout(RecievedMessage* m);
void handleLeaveGame(RecievedMessage* m);
void handleStartGame(RecievedMessage* m);
void handlePlayerAnswer(RecievedMessage* m);
bool handleCreateRoom(RecievedMessage* m);
bool handleCloseRoom(RecievedMessage* m);
bool handleJoinRoom(RecievedMessage* m);
bool handleLeaveRoom(RecievedMessage* m);
void handleGetUsersInRoom(RecievedMessage* m);
void handleGetRooms(RecievedMessage* m);
void handleGetBestScores(RecievedMessage* m);
void handleGetPersonalStatus(RecievedMessage* m);
void handleRecievedMessages();
void addRecievedMessage(RecievedMessage* m);
RecievedMessage* buildRecieveMessage(SOCKET s, int num);
User* getUserByName(string name);
User* getUserBySocket(SOCKET s);
Room* getRoomById(int id);
/********Local Variables**********/
SOCKET _socket;
map<SOCKET, User*> _connectedUsers;
map<int, Room*> _roomsList;
//DataBase _db;
queue<RecievedMessage*> _queRcvMessages;
mutex _mtxRecievedMessages;
condition_variable _cv;
static int _roomIdSequence;
};