-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminecontrol-client.h
More file actions
113 lines (99 loc) · 3.73 KB
/
minecontrol-client.h
File metadata and controls
113 lines (99 loc) · 3.73 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
// minecontrol-client.h
#ifndef MINECONTROL_CLIENT_H
#define MINECONTROL_CLIENT_H
#include <rlibrary/rdynarray.h>
#include "minecontrol-protocol.h"
#include "minecontrol-misc-types.h"
#include "socket.h" // gets io_device
#include "mutex.h" // gets pthread
namespace minecraft_controller
{
class controller_client_error { };
class controller_client
{
public:
// accepts a client connection on the specified socket;
// if the accept failed, then NULL is returned, else
// a pointer to a dynamically allocated `controller-client'
// object; this memory will be freed automatically once the
// client has disconnected
static controller_client* accept_client(socket&);
static void shutdown_clients();
static void close_client_sockets();
private:
controller_client(socket* acceptedSocket);
~controller_client();
static mutex clientsMutex; // protects 'clients'
static rtypes::dynamic_array<void*> clients; // rlibrary limitation: reduces coat-bloat
static void* client_thread(void*);
// command data
typedef bool (controller_client::* command_call)(rtypes::rstream&,rtypes::rstream&);
static rtypes::size_type CMD_COUNT_WITHOUT_LOGIN;
static rtypes::size_type CMD_COUNT_WITH_LOGIN;
static rtypes::size_type CMD_COUNT_WITH_PRIVILEGED_LOGIN;
static char const *const CMDNAME_WITHOUT_LOGIN[];
static command_call const CMDFUNC_WITHOUT_LOGIN[];
static char const *const CMDNAME_WITH_LOGIN[];
static command_call const CMDFUNC_WITH_LOGIN[];
static char const *const CMDNAME_WITH_PRIVILEGED_LOGIN[]; // root commands
static command_call const CMDFUNC_WITH_PRIVILEGED_LOGIN[];
// message handlers
bool message_loop();
bool command_login(rtypes::rstream&,rtypes::rstream&);
bool command_logout(rtypes::rstream&,rtypes::rstream&);
bool command_start(rtypes::rstream&,rtypes::rstream&);
bool command_status(rtypes::rstream&,rtypes::rstream&);
bool command_extend(rtypes::rstream&,rtypes::rstream&);
bool command_exec(rtypes::rstream&,rtypes::rstream&);
bool command_auth_ls(rtypes::rstream&,rtypes::rstream&);
bool command_server_ls(rtypes::rstream&,rtypes::rstream&);
bool command_profile_ls(rtypes::rstream&,rtypes::rstream&);
bool command_stop(rtypes::rstream&,rtypes::rstream&);
bool command_console(rtypes::rstream&,rtypes::rstream&);
bool command_shutdown(rtypes::rstream&,rtypes::rstream&);
// helpers
rtypes::rstream& client_log(rtypes::rstream& stream)
{
return stream << '{' << sock->get_accept_id() << "} ";
}
rtypes::rstream& prepare_message()
{
msgbuf.begin("MESSAGE");
msgbuf.enqueue_field_name("Payload");
return msgbuf;
}
rtypes::rstream& prepare_error()
{
msgbuf.begin("ERROR");
msgbuf.enqueue_field_name("Payload");
return msgbuf;
}
rtypes::rstream& prepare_list_message()
{
msgbuf.begin("LIST-MESSAGE");
msgbuf.repeat_field("Item");
return msgbuf;
}
rtypes::rstream& prepare_list_error()
{
msgbuf.begin("LIST-ERROR");
msgbuf.repeat_field("Item");
return msgbuf;
}
socket* sock;
socket_stream connection;
minecontrol_message_buffer msgbuf;
pthread_t threadID;
volatile bool threadCondition;
user_info userInfo;
rtypes::size_type referenceIndex;
};
}
#endif
/*
* Local Variables:
* mode:c++
* indent-tabs-mode:nil
* tab-width:4
* End:
*/