-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.h
93 lines (79 loc) · 2.68 KB
/
client.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
83
84
85
86
87
88
89
90
91
92
#ifndef NETWORKCLIENT_H
#define NETWORKCLIENT_H
#include "base.h"
namespace ser {
class serializer_API client : public network_base
{
public:
explicit client(const ser::string& alias, const std::string& host, uint16 port, uint16 connection_timeout = DEFAULT_CONNECTION_TIMEOUT);
virtual ~client();
client(const client&) = delete;
client& operator=(const client&) = delete;
void status();
void disconnect();
virtual void on_package(RakNet::Packet* packet) override;
template <typename ... Args>
void one(const ser::string& to_guid, int port, int version, Args&& ... data) const
{
if(this->convert_to_guid(_server_guid) == to_guid)
{
up(port, version, std::forward<Args>(data)...);
}
else
{
RakNet::BitStream pipe;
write_header(pipe, NET_MESSAGE_FORWARD);
ser::serialize(pipe, this->get_guid(), to_guid, port, version, std::forward<Args>(data)...);
_peer->Send(&pipe, MEDIUM_PRIORITY, RELIABLE, 0, _server_guid, false);
}
}
template <typename ... Args>
void all(int port, int version, Args&& ... data) const
{
RakNet::BitStream pipe;
write_header(pipe, NET_MESSAGE_BROADCAST);
ser::serialize(pipe, this->get_guid(), port, version, std::forward<Args>(data)...);
_peer->Send(&pipe, MEDIUM_PRIORITY, RELIABLE, 0, _server_guid, false);
}
template <typename ... Args>
void topic(const ser::string& room, int version, Args&& ... data) const
{
RakNet::BitStream pipe;
write_header(pipe, NET_MESSAGE_ROOM_FORWARD);
ser::serialize(pipe, this->get_guid(), room, version, std::forward<Args>(data)...);
_peer->Send(&pipe, MEDIUM_PRIORITY, RELIABLE, 0, _server_guid, false);
}
template <typename ... Args>
void up(int port, int version, Args&& ... data) const
{
RakNet::BitStream pipe;
write_header(pipe, NET_MESSAGE_DATA);
ser::serialize(pipe, this->get_guid(), port, version, std::forward<Args>(data)...);
_peer->Send(&pipe, MEDIUM_PRIORITY, RELIABLE, 0, _server_guid, false);
}
void subscribe(const ser::string& room)
{
RakNet::BitStream pipe;
write_header(pipe, NET_MESSAGE_ROOM_SUBSCRIBE);
ser::serialize(pipe, this->get_guid(), room);
_peer->Send(&pipe, MEDIUM_PRIORITY, RELIABLE, 0, _server_guid, false);
}
void unsubscribe(const ser::string& room)
{
RakNet::BitStream pipe;
write_header(pipe, NET_MESSAGE_ROOM_UNSUBSCRIBE);
ser::serialize(pipe, this->get_guid(), room);
_peer->Send(&pipe, MEDIUM_PRIORITY, RELIABLE, 0, _server_guid, false);
}
protected:
virtual void notify_alias(const ser::string& guid, const ser::string& alias) override;
public:
fes::bind<ser::string> on_disconnect_server;
protected:
std::string _host;
uint16 _port;
uint16 _connection_timeout;
RakNet::SystemAddress _server_guid;
};
} // end namespace Dune
#endif