-
Notifications
You must be signed in to change notification settings - Fork 0
/
eros.h
276 lines (209 loc) · 7.31 KB
/
eros.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
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#ifndef LIBEROS_EROS_H
#define LIBEROS_EROS_H
#include <QObject>
#include <QList>
#include <QTcpSocket>
#include <QTime>
#include <QMap>
#include <QAtomicInt>
#include <QBuffer>
#include "enums.h"
#include "user.h"
#include "localuser.h"
#include "character.h"
#include "chatroom.h"
#include "matchmakingmatch.h"
#include "division.h"
#include "map.h"
namespace google
{
namespace protobuf
{
class Message;
}
}
namespace protobufs
{
class HandshakeResponse;
class UserStats;
class Handshake;
};
#define UPLOAD_BUFFER_SIZE 4096
#define DEFAULT_PORT 12345
class Request;
class Eros : public QObject
{
Q_OBJECT
public:
Eros(QObject *parent);
~Eros();
ErosError lastError();
static const QString errorString(ErosError error);
const QString errorString() const;
ErosState state() const;
ErosMatchmakingState matchmakingState() const;
ErosLongProcessState longProcessState() const;
int regionSearchingUserCount(ErosRegion region) const;
int searchingUserCount() const;
int activeUserCount() const;
const QMap<int, Division*> &divisions() const;
const MatchmakingMatch *matchmakingMatch() const;
LocalUser *localUser();
User *getUser(const QString &username);
const QList<ChatRoom *> &chatRooms() const;
ChatRoom *getChatRoom(const QString &room);
const QList<ErosRegion> &activeRegions() const;
const QList<Map*> &mapPool() const;
Map *findMap(ErosRegion region, int battle_net_id);
int maxVetoes() const;
static const QString regionToString(ErosRegion region);
static const QString regionToLongString(ErosRegion region);
static const QString regionToLanguageString(ErosRegion region);
static const QString regionToDomainString(ErosRegion region);
public slots:
// Connectivity slots
void connectToEros(const QString server, const QString username, const QString password);
void disconnectFromEros();
// Matchmaking slots
void queueMatchmaking(ErosRegion region, int search_radius);
void queueMatchmaking(ErosRegionList regions, int search_radius);
void dequeueMatchmaking();
void forfeitMatchmaking();
// Chat slots
void sendMessage(ChatRoom *room, const QString message);
void sendMessage(User *user, const QString message);
void joinChatRoom(ChatRoom *room);
void joinChatRoom(ChatRoom *room, const QString password);
void leaveChatRoom(ChatRoom *room);
void refreshChatRooms();
// Character slots
void addCharacter(const QString battle_net_url);
void updateCharacter(Character *character, int new_character_code, const QString new_game_profile_link);
void removeCharacter(Character *character);
//Upload replay slots
void uploadReplay(const QString path);
void uploadReplay(QIODevice *device);
void requestDraw();
void requestNoShow();
// Are we agreeing with what the opponent is saying?
void acknowledgeLongProcess(bool response);
void toggleVeto(Map *map);
private:
QString server_hostname_;
quint16 server_port_;
QString username_;
QString password_;
QList<ChatRoom *> chatrooms_;
QList<User *> users_;
QMap<int, Request *> requests_;
QTcpSocket *socket_;
LocalUser *local_user_;
MatchmakingMatch *matchmaking_match_;
QMap<int, Division*> divisions_;
ErosError last_error_;
QAtomicInt transaction_id_base_;
int latency_;
ErosState state_;
ErosMatchmakingState matchmaking_state_;
ErosLongProcessState long_process_state_;
// I don't even know if this is necessary, but it's better safe than sorry
bool awaiting_data_;
QString awaiting_data_command_;
qint64 awaiting_data_size_;
qint64 awaiting_data_transaction_id_;
QBuffer *awaiting_data_buffer_;
// Server Stats
QMap<ErosRegion, int> eros_matchmaking_searching_regions_;
QList<ErosRegion> eros_active_regions_;
QList<Map*> map_pool_;
int max_vetoes_;
int eros_active_user_count_;
int eros_searching_user_count_;
void setState(ErosState);
void setStats(int active, int searching);
void setRegionStats(ErosRegion region, int searching);
void sendRequest(Request *request);
void handleCommand(const QString &command, const int &transaction_id, const QByteArray &data);
void handleServerCommand(const QString &command, const QByteArray &data);
void handleUserStats(const protobufs::UserStats &stats);
void setMatchmakingState(ErosMatchmakingState);
private slots:
void socketConnected();
void socketDisconnected();
void socketReadyRead();
void socketError(QAbstractSocket::SocketError );
void requestComplete(Request *);
void requestError(Request *, int);
void userUpdatedHandler(User *user);
void characterUpdatedHandler(Character *);
void handshakeRequestComplete(Request *);
void matchmakingRequestQueued(Request *);
void matchmakingRequestComplete(Request *);
void chatIndexRequestComplete(Request *);
void chatJoinRequestComplete(Request *);
void chatLeaveRequestComplete(Request *);
void chatMessageRequestComplete(Request *);
void characterRequestComplete(Request *);
void drawRequestComplete(Request *);
void noShowRequestComplete(Request *);
void longProcessResponseRequestComplete(Request *);
void replayRequestComplete(Request *);
void toggleVetoRequestComplete(Request *);
void ensureUserParent(User *);
void ensureChatParent(ChatRoom *);
signals:
// Low level connection signals.
void stateChanged(ErosState);
void connectionError(QAbstractSocket::SocketError, const QString);
// Basic operation signals
void connected();
void disconnected();
void authenticationFailed();
void alreadyLoggedIn();
void serverError(int);
void statsUpdated(int active, int searching);
void regionStatsUpdated(ErosRegion region, int searching);
void uploadProgress(qint64 written, qint64 total);
void broadcastAlert(const QString message, int predefined_hint);
// User signals
void userAdded(User *user);
void userUpdated(User *user);
void localUserUpdated(LocalUser *user);
void characterAdded(Character* character);
void characterUpdated(Character* character);
void characterRemoved(Character* character);
void addCharacterError(const QString battle_net_profile, ErosError error);
void updateCharacterError(Character* character, ErosError error);
void removeCharacterError(Character* character, ErosError error);
void vetoesUpdated();
void toggleVetoFailed(Map *map, ErosError error);
// Match signals
void matchmakingStateChanged(ErosMatchmakingState status);
void matchmakingMatchFound(MatchmakingMatch *match);
void replayUploaded();
void replayUploadError(ErosError error);
// Chat signals
void chatRoomJoinFailed(ChatRoom *room, ErosError code);
void chatRoomAdded(ChatRoom *room);
void chatRoomRemoved(ChatRoom *room);
void chatRoomJoined(ChatRoom *room);
void chatRoomLeft(ChatRoom *room);
void chatRoomUserJoined(ChatRoom *room, User *user);
void chatRoomUserLeft(ChatRoom *room, User *user);
void chatMessageReceieved(ChatRoom *room, User *user, const QString message);
void chatMessageReceieved(User *user, const QString message);
void chatMessageSent(ChatRoom *room, const QString message);
void chatMessageSent(User *user, const QString message);
void chatMessageFailed(ChatRoom *room, const QString message, ErosError code);
void chatMessageFailed(User *user, const QString message, ErosError code);
void longProcessStateChanged(ErosLongProcessState);
//Incoming
void noShowRequested();
void drawRequested();
//Outgoing
void noShowRequestFailed();
void drawRequestFailed();
void acknowledgeLongProcessFailed();
void acknowledgedLongProcess();
};
#endif // LIBEROS_EROS_H