-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.hpp
78 lines (57 loc) · 1.57 KB
/
client.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
#ifndef CLIENT_H_
#define CLIENT_H_
#include "client_fwd.hpp"
#include "packet.hpp"
#include "server_fwd.hpp"
#include "rooms_fwd.hpp"
using namespace std;
class Client {
private:
ConnectionPtr connection;
Server *server;
set<RoomPtr> rooms;
weak_ptr<Client> self;
string name;
uint uid;
bool _isGirl;
string color;
string lastClientIP;
string token;
public:
time_t lastPacketTime;
time_t lastMessageTime;
int messageCounter;
Client(Server *srv, string token);
~Client();
void setSelfPtr(weak_ptr<Client> wptr) { self = wptr; }
ClientPtr getSelfPtr() { return self.lock(); }
bool isGirl() { return _isGirl; }
void setGirl(bool g) { _isGirl = g; }
string getColor() { return color; }
void setColor(string clr) { color = clr; }
string getName() { return name; }
void setName(const string &nm) { name = nm; }
string getLastIP() { return lastClientIP; }
string getToken() { return token; }
uint getID() { return uid; }
void setID(int id) { uid = id; }
Server *getServer() { return server; }
void setConnection(ConnectionPtr conn);
ConnectionPtr getConnection() { return connection; }
void onPacket(string pack);
void onRevive();
void onDisconnect();
void onRemove();
void onKick(RoomPtr room);
MemberPtr joinRoom(RoomPtr room);
void leaveRoom(RoomPtr room);
RoomPtr getRoomByName(const string &name);
inline const set<RoomPtr> &getConnectedRooms() { return rooms; }
void sendPacket(const Packet &);
void sendRawData(const string &data);
inline bool isAdmin() {
return uid == 1 || uid == 2;
}
inline bool isGuest() { return uid <= 0; }
};
#endif