-
Notifications
You must be signed in to change notification settings - Fork 1
/
mcquery.hpp
157 lines (131 loc) · 4.13 KB
/
mcquery.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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include <boost/asio.hpp>
#include <array>
#include <sstream>
/*******************************
* mcData declarations *
*******************************/
struct mcData {
bool success = false;
std::string error; // contains the .what() string if an exception was thrown
std::string motd;
int numplayers;
int maxplayers;
};
struct mcDataSimple : mcData {
std::string version;
};
struct mcDataBasic : mcData {
std::string gametype;
std::string map;
unsigned short hostport = 0;
std::string hostip;
};
struct mcDataFull : mcDataBasic {
std::string& hostname = motd; // same thing different name
std::string game_id;
std::string version;
std::vector<std::string> plugins; // only used by bukkit
std::vector<std::string> playernames; // a name is max 16 chars, so a fixed-length string type would be more appropriate
};
struct mcDataSnoop {
int difficulty; // data types tbd
int modlist;
int uptime;
int worlborder;
int tps;
};
struct mcDataPlayer {
char name[17];
int gamemode;
int capabilities;
int armor;
int xp;
int group;
int health;
int food;
int ping;
int money;
int pos;
};
struct mcDataInv {
char name[17];
int head;
int chest;
int legs;
int feet;
int inv;
};
/*******************************
* mcQuery declarations *
*******************************/
struct mcQuery {
mcQuery(const char* host = "localhost", // move arguments away from constructor?
const char* port = "25565",
const int timeoutsecs = 5);
mcDataBasic getBasic();
mcDataFull getFull();
private: // functions
void challengeReceiver(const boost::system::error_code& error, size_t nBytes);
void dataReceiver(const boost::system::error_code& error, size_t nBytes);
void connect();
void extract();
void extractBasic();
void extractFull();
void extractKey(const char* expected);
private: // data
boost::asio::io_service ioService;
boost::asio::deadline_timer t;
boost::asio::ip::udp::resolver Resolver;
boost::asio::ip::udp::resolver::query Query;
boost::asio::ip::udp::endpoint Endpoint;
boost::asio::ip::udp::socket Socket;
std::istringstream iss;
boost::posix_time::time_duration timeout;
bool fullreq;
std::array<unsigned char,5000> recvBuffer; // should look into making the buffer size variable, have to look at boost documentation
mcDataFull data;
};
/********************************
* mcQuerySimple declarations *
********************************/
struct mcQuerySimple {
mcQuerySimple(const char* host = "localhost",
const char* port = "25565",
const int timeoutsecs = 5);
mcDataSimple get();
private:
void connector(const boost::system::error_code& error);
void sender(const boost::system::error_code& e, std::size_t numBytes);
void receiver(const boost::system::error_code& e, std::size_t numBytes);
private:
boost::asio::io_service ioService;
boost::asio::deadline_timer t;
boost::asio::ip::tcp::resolver Resolver;
boost::asio::ip::tcp::resolver::query Query;
boost::asio::ip::tcp::endpoint Endpoint;
boost::asio::ip::tcp::socket Socket;
boost::posix_time::time_duration timeout;
std::array<unsigned char,100> recvBuffer;
mcDataSimple data;
};
/********************************
* mcSnooper declarations *
********************************/
// not implemented yet --> waiting on upstream fixes
struct mcSnooper {
mcSnooper(const char* host = "localhost",
const char* port = "25566", // default is one port higher than minecraft host
const int timeoutsecs = 5);
mcDataSnoop get();
mcDataPlayer getPlayer(const char* name);
mcDataInv getInventory(const char* name);
private:
private:
boost::asio::io_service ioService;
boost::asio::deadline_timer t;
boost::asio::ip::tcp::resolver Resolver;
boost::asio::ip::tcp::resolver::query Query;
boost::asio::ip::tcp::endpoint Endpoint;
boost::asio::ip::tcp::socket Socket;
boost::posix_time::time_duration timeout;
};