-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.cpp
More file actions
129 lines (96 loc) · 1.64 KB
/
User.cpp
File metadata and controls
129 lines (96 loc) · 1.64 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <iostream>
#include "Game.h"
#include <string>
#include "Helper.h"
#include "Room.h"
#include "User.h"
User::User(string username, SOCKET sock)
{
this->_username = username;
this->_sock = sock;
_currRoom = NULL;
}
void User::setUserName(string newUsername)
{
this->_username = newUsername;
}
void User::send(string message)
{
Helper::sendData(this->_sock, message);
}
SOCKET User::getSocket()
{
return this->_sock;
}
Room* User::getRoom()
{
return this->_currRoom;
}
Game* User::getGame()
{
return _currGame;
}
string User::getUsername()
{
return _username;
}
void User::setGame(Game* gm)
{
this->_currGame = gm;
this->_currRoom = NULL;
}
bool User::createRoom(int roomId, string roomName, int maxUsers, int questionsNo, int questionTime)
{
if (this->_currRoom == NULL)
{
this->_currRoom = new Room(roomId, this, roomName, maxUsers, questionsNo, questionTime);
this->send("1140");
return true;
}
this->send("1141");
return false;
}
bool User::joinRoom(Room* newRoom)
{
if ((this->_currRoom == NULL) && (newRoom != NULL))
{
this->_currRoom = newRoom;
return true;
}
return false;
}
void User::leaveRoom()
{
if (this->_currRoom != NULL)
{
this->_currRoom = NULL;
}
}
int User::closeRoom()
{
int roomNum = -1;
if (this->_currRoom != NULL)
{
roomNum = this->_currRoom->getId();
free(this->_currRoom);
this->_currRoom = NULL;
}
return roomNum;
}
void User::clearRoom()
{
this->_currRoom = NULL;
}
bool User::leaveGamePrimal()
{
if (this->_currGame != NULL)
{
this->_currGame = NULL;
return true;
}
return false;
}
void User::clearGame()
{
this->_currGame = NULL;
}