-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.hpp
208 lines (157 loc) · 6.49 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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#ifndef client_hpp
#define client_hpp
namespace dfterm
{
class Client;
};
#include "types.hpp"
#include "interface_termemu.hpp"
#include "termemu.h"
#include "sockets.hpp"
#include "telnet.hpp"
#include "logger.hpp"
#include "slot.hpp"
#include "configuration_interface.hpp"
#include "configuration_primitives.hpp"
#include "state.hpp"
#include "id.hpp"
namespace dfterm
{
class Client;
/* Required by TelnetSession */
class ClientTelnetSession : public trankesbel::TelnetSession
{
private:
WP<Client> client;
public:
ClientTelnetSession();
~ClientTelnetSession();
bool readRawData(void* data, size_t* size);
bool writeRawData(const void* data, size_t* size);
void setClient(WP<Client> client);
};
class Client
{
private:
ID id;
ClientTelnetSession ts;
SP<trankesbel::Socket> client_socket;
SP<trankesbel::InterfaceTermemu> interface;
Terminal buffer_terminal;
Terminal last_client_terminal;
boost::recursive_mutex cycle_mutex;
bool slot_active_in_last_cycle;
/* Slot for game. */
WP<Slot> slot;
/* Database access. */
WP<ConfigurationDatabase> configuration;
/* In the identifying window, track the index numbers for password fields. */
int password1_index, password2_index, message_index;
/* Last time a password was entered. Used for limiting how fast passwords
* can be tried. */
uint64_t password_enter_time;
/* Nickname and whether the client has identified itself. */
UnicodeString nickname;
bool identified;
/* This method handles what happens when client identified.
(Creates windows etc.) */
void clientIdentified();
trankesbel::ui32 chat_window_input_index;
/* Maximum number of lines in chat history. */
trankesbel::ui32 max_chat_history;
SP<Logger> global_chat;
SP<LoggerReader> global_chat_reader;
SP<Logger> private_chat;
SP<LoggerReader> private_chat_reader;
void cycleChat();
/* Configuring dfterm2 is complex enough to warrant
* dedicated classes and files. Here's a class handle to them. */
SP<ConfigurationInterface> config_interface;
/* User handle. */
SP<User> user;
/* Nicks go in this window */
SP<trankesbel::InterfaceElementWindow> nicklist_window;
/* And chat to this window */
SP<trankesbel::InterfaceElementWindow> chat_window;
/* And the game screen to this one */
SP<trankesbel::Interface2DWindow> game_window;
/* Configuration window */
SP<trankesbel::InterfaceElementWindow> config_window;
/* Identify window. Exists only at start. */
SP<trankesbel::InterfaceElementWindow> identify_window;
/* Used to keep nick list up to date. */
std::vector<WP<Client> > clients;
void updateNicklistWindow();
/* This one calls updateNicklistWindow for all clients in that vector. */
void updateNicklistWindowForAll();
bool do_full_redraw;
bool packet_pending;
trankesbel::ui32 packet_pending_index;
std::string deltas;
/* These are used to control how many times
client can have its windows refreshed per second. */
trankesbel::ui64 refresh_per_second;
trankesbel::ui64 last_refresh;
WP<Client> self;
WP<State> state;
/* No copies */
Client(const Client &c) { };
Client& operator=(const Client &c) { return (*this); };
/* No default constructor */
Client() { };
/* Create a client and associate a socket with it. */
Client(SP<trankesbel::Socket> client_socket);
void setSelf(WP<Client> c) { self = c; ts.setClient(self); };
/* Callback functions. */
bool chatRestrictFunction(trankesbel::ui32* keycode, trankesbel::ui32* cursor);
bool chatSelectFunction(trankesbel::ui32 index);
bool identifySelectFunction(trankesbel::ui32 index);
void gameInputFunction(const trankesbel::KeyPress &kp);
void gameResizeFunction(trankesbel::ui32 w, trankesbel::ui32 h);
/* Checks if normal cycle can be done. */
bool cycleCheck();
/* Refreshes interface and screen. */
void doCycleRefresh();
public:
static SP<Client> createClient(SP<trankesbel::Socket> client_socket);
/* Destructor */
~Client();
/* Set the configuration database to use. Clients will use a weak reference to the database.
* You should set it before you put the client into use. */
void setConfigurationDatabase(SP<ConfigurationDatabase> configuration_database)
{ setConfigurationDatabase(WP<ConfigurationDatabase>(configuration_database)); };
void setConfigurationDatabase(WP<ConfigurationDatabase> configuration_database);
/* Returns the configuration database this client is using. */
WP<ConfigurationDatabase> getConfigurationDatabase() const;
/* Returns the socket the client is using */
SP<trankesbel::Socket> getSocket() { return client_socket; };
/* Returns true if client connection is active. */
bool isActive() const;
/* Returns the user object associated with the client. */
SP<User> getUser() { return user; };
/* Sets the state for the client. */
void setState(WP<State> state);
void setState(SP<State> state) { setState(WP<State>(state)); };
/* Sets a slot for this client. */
void setSlot(SP<Slot> slot);
/* Gets the slot this client is seeing. */
WP<Slot> getSlot() const { return slot; };
/* Sets the global chat. */
void setGlobalChatLogger(SP<Logger> global_chat);
SP<Logger> getGlobalChatLogger() const;
/* Sends a private chat message to the client.
The message will appear in its chat window. */
void sendPrivateChatMessage(const UnicodeString &us);
void sendPrivateChatMessageUTF8(const std::string &s)
{ sendPrivateChatMessage(TO_UNICODESTRING(s)); };
void updateClientNicklist(std::vector<SP<Client> >* clients);
/* Returns true if the entire server should close. */
bool shouldShutdown() const;
/* Cycle the client connection */
void cycle();
void setID(const ID& i) { id = i; };
ID getID() const { return id; };
const ID& getIDRef() const { return id; };
};
}
#endif