blob: a476621ec20397c1ddc77984260b08470a5748ec (
plain)
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
|
#ifndef MESSAGES_H
#define MESSAGES_H
#include <boost/asio.hpp>
namespace message {
enum MessageType {
MSG_TYPE_NONE = 0,
MSG_TYPE_HELLO,
MSG_TYPE_POS,
MSG_TYPE_CHUNK,
MSG_TYPE_MSG
};
class MessageBase {
protected:
uint8_t type;
boost::asio::streambuf b;
public:
MessageBase();
virtual ~MessageBase() {};
void send(boost::asio::ip::tcp::socket& socket);
virtual std::size_t payload_size();
virtual void read(boost::asio::ip::tcp::socket& socket);
static uint8_t read_type(boost::asio::ip::tcp::socket& socket);
};
class Hello : public MessageBase {
public:
Hello();
Hello(uint8_t version);
virtual std::size_t payload_size();
uint8_t read_version();
};
class Pos : public MessageBase {
public:
Pos();
Pos(float x, float y, float z);
virtual std::size_t payload_size();
void get_pos(float& x, float& y, float& z);
};
class Chunk : public MessageBase {
protected:
bool got_coords;
public:
Chunk();
Chunk(int64_t x, int64_t y);
virtual std::size_t payload_size();
void set_data(float *data);
float* get_data();
void get_coords(int64_t& x, int64_t& y);
};
class Message : public MessageBase {
protected:
uint16_t str_len;
bool got_len;
public:
Message();
Message(std::string msg);
virtual std::size_t payload_size();
uint16_t get_len();
std::string get_str();
};
}
#endif
|