-
Notifications
You must be signed in to change notification settings - Fork 1
/
GDServer_BoomlingsLike19.cpp
354 lines (268 loc) · 10.6 KB
/
GDServer_BoomlingsLike19.cpp
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
/**
* LevelAPI - Geometry Dash level cacher with search functionality and more.
Copyright (C) 2024 Sergei Baigerov
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "GDServer_BoomlingsLike19.h"
// #include "RobTopStringContainer.hpp"
#include "LevelRange.h"
#include "UUID.h"
#include "curl_backend.h"
#include "ThreadSafeLevelParser.h"
#include "Account19.h"
#include "StringSplit.h"
#include "Translation.h"
#include "UUID.h"
#include "Level.h"
#include "LevelRelease.h"
#include <cstdint>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace LevelAPI::Backend;
GDServer_BoomlingsLike19::GDServer_BoomlingsLike19(std::string endpoint) : GDServer() {
m_sEndpointURL = endpoint;
}
GDServer_BoomlingsLike19::GDServer_BoomlingsLike19(std::string endpoint, std::vector<LevelRange> list) : GDServer(list) {
m_sEndpointURL = endpoint;
}
GDServer_BoomlingsLike19::GDServer_BoomlingsLike19(std::string endpoint, LevelRangeList list) : GDServer(list) {
m_sEndpointURL = endpoint;
}
std::string GDServer_BoomlingsLike19::_getLoginAccountEndpointName() {
return "loginGJAccount.php";
}
std::string GDServer_BoomlingsLike19::_getDownloadLevelEndpointName() {
return "downloadGJLevel19.php";
}
std::string GDServer_BoomlingsLike19::_getLevelListEndpointName() {
return "getGJLevels19.php";
}
int GDServer_BoomlingsLike19::getMaxLevelPageSize() {
return 10;
}
int GDServer_BoomlingsLike19::getMaxMapPackPageSize() {
return 5;
};
bool GDServer_BoomlingsLike19::login(std::optional<CurlProxy> proxy) {
// create curl instance
auto m_pLinkedCURL = _setupCURL(proxy, _getSecretValueExtra());
// add parameters
m_pLinkedCURL->addData({
new CURLParameter("udid", ConnectionCrypt::createUUID()),
new CURLParameter("password", m_sPassword),
new CURLParameter("username", m_sUsername)
});
// set url
std::string url = m_sEndpointURL + "/accounts/" + _getLoginAccountEndpointName();
// create request to the server
CURLResult *res = m_pLinkedCURL->access_page(url.c_str(), "POST");
printf("response login: %s\n", res->data);
printf("%d %d %d\n", res->http_status, res->result, res->retry_after);
if (!processCURLAnswer(res)) {
delete m_pLinkedCURL; m_pLinkedCURL = nullptr;
free((char *)res->data);
delete res; res = nullptr;
return false;
}
delete m_pLinkedCURL; m_pLinkedCURL = nullptr;
delete res; res = nullptr;
return true;
}
LevelAPI::DatabaseController::Level *GDServer_BoomlingsLike19::downloadLevel(int id, std::optional<CurlProxy> proxy) {
// create curl instance
auto m_pLinkedCURL = _setupCURL(proxy, _getSecretValueStandard());
// add parameters
m_pLinkedCURL->addData({
new CURLParameter("levelID", id)
});
// create url
std::string url = m_sEndpointURL + "/" + _getDownloadLevelEndpointName();
// send request to the server
CURLResult *res = m_pLinkedCURL->access_page(url.c_str(), "POST");
if (!processCURLAnswer(res)) {
free((char *)res->data);
delete res; res = nullptr;
delete m_pLinkedCURL; m_pLinkedCURL = nullptr;
return nullptr;
}
// check if level doesn't exist
std::string strtest = res->data;
if(!strtest.compare("-1")) {
free((char *)res->data);
delete res; res = nullptr;
delete m_pLinkedCURL; m_pLinkedCURL = nullptr;
return nullptr;
}
// parse level
auto lvl = LevelParser::parseFromResponse(res->data);
// set values
lvl->m_uRelease->m_nGameVersion = lvl->m_nGameVersion;
lvl->m_uRelease->m_fActualVersion = determineGVFromID(lvl->m_nLevelID);
free((char *)res->data);
delete res; res = nullptr;
delete m_pLinkedCURL; m_pLinkedCURL = nullptr;
return lvl;
}
std::vector<CURLParameter *> GDServer_BoomlingsLike19::_setupGJLevelsArgs(int type, std::string str, int page) {
std::string _str = str;
if (str.empty()) _str = "-";
return {
new CURLParameter("type", type),
new CURLParameter("page", page),
new CURLParameter("str", _str),
new CURLParameter("total", getMaxLevelPageSize())
};
}
std::vector<LevelAPI::DatabaseController::Level *> GDServer_BoomlingsLike19::getLevelsBySearchType(int type, std::string str, int page, std::optional<CurlProxy> proxy) {
// create curl instance
auto m_pLinkedCURL = _setupCURL(proxy, _getSecretValueStandard());
// add parameters
m_pLinkedCURL->addData(_setupGJLevelsArgs(type, str, page));
// printf("str=%s\n", str.c_str());
// create url
std::string url = m_sEndpointURL + "/" + _getLevelListEndpointName();
// send request to the server
CURLResult *res = m_pLinkedCURL->access_page(url.c_str(), "POST");
if (!processCURLAnswer(res)) {
free((char *)res->data);
delete res; res = nullptr;
delete m_pLinkedCURL; m_pLinkedCURL = nullptr;
return {};
}
if(res->data[0] == '-') {
free((char *)res->data);
delete res; res = nullptr;
delete m_pLinkedCURL; m_pLinkedCURL = nullptr;
return {};
}
// create level array
std::vector<LevelAPI::DatabaseController::Level *> vec1;
// split array into level array and player array
std::vector<std::string> vec2 = splitString(res->data, '#');
// get player list
std::string plList = vec2[1];
// get level list
std::string lvlList = vec2[0];
// create player map
std::map<int, Account19 *> playerMap;
// split player list into individual players
std::vector<std::string> vec4array = splitString(plList.c_str(), '|');
// split level list into individual levels
std::vector<std::string> vec5levels = splitString(lvlList.c_str(), '|');
int i = 0;
std::vector<Account19 *> accounts;
for (auto player_string : vec4array) {
// split robtop array
std::vector<std::string> player_data = splitString(player_string.c_str(), ':');
if (player_data.size() >= 3) {
// get strings for each array element;
std::string userID_string = player_data[0];
std::string accountID_string = player_data[2];
std::string username = player_data[1];
// parse userID
int userID = atoi(userID_string.c_str());
// parse accountID
int accountID = atoi(accountID_string.c_str());
Account19 *account = new Account19();
account->accountID = accountID;
account->userID = userID;
account->username = username;
playerMap.insert(std::pair<int, Account19 *>(userID, account));
accounts.push_back(account);
}
}
for (auto level_string : vec5levels) {
// parse level
LevelAPI::DatabaseController::Level *lvl = LevelParser::parseFromResponse(level_string);
// get account by user id
Account19 *account = playerMap[lvl->m_nPlayerID];
// set account values if it was found
if (account != nullptr) {
lvl->m_nAccountID = account->accountID;
lvl->m_sUsername = account->username;
}
// set level release values
lvl->m_uRelease->m_nGameVersion = lvl->m_nGameVersion;
lvl->m_uRelease->m_fActualVersion = determineGVFromID(lvl->m_nLevelID);
vec1.push_back(lvl);
}
// delete accounts
for (auto account : accounts) delete account;
free((char *)res->data);
delete res; res = nullptr;
delete m_pLinkedCURL; m_pLinkedCURL = nullptr;
// reserse array to make first level to be the latest one
std::reverse(vec1.begin(), vec1.end());
return vec1;
};
std::string GDServer_BoomlingsLike19::_getSecretValueStandard() {
return "Wmfd2893gb7";
}
std::string GDServer_BoomlingsLike19::_getSecretValueExtra() {
return "Wmfv3899gc9";
}
LevelAPI::DatabaseController::Level *GDServer_BoomlingsLike19::resolveLevelData(LevelAPI::DatabaseController::Level *level, std::optional<CurlProxy> proxy) {
// create curl instance
auto m_pLinkedCURL = _setupCURL(proxy, _getSecretValueStandard());
// add level id parameter
m_pLinkedCURL->setData({
new CURLParameter("levelID", level->m_nLevelID)
});
// generate url
std::string url = m_sEndpointURL + "/" +_getDownloadLevelEndpointName();
// create request to the server
CURLResult *res = m_pLinkedCURL->access_page(url.c_str(), "POST");
if (!processCURLAnswer(res)) {
free((char *)res->data);
delete res; res = nullptr;
delete m_pLinkedCURL; m_pLinkedCURL = nullptr;
return level;
}
// check if level doesn't exist
std::string strtest = res->data;
if(!strtest.compare("-1")) {
free((char *)res->data);
delete res; res = nullptr;
delete m_pLinkedCURL; m_pLinkedCURL = nullptr;
return level;
}
// parse level
LevelAPI::DatabaseController::Level *lvl = LevelParser::parseFromResponse(res->data);
// set values
level->m_sLevelString = lvl->m_sLevelString;
level->m_nMusicID = lvl->m_nMusicID;
level->m_nSongID = lvl->m_nSongID;
level->m_uRelease->m_nGameVersion = lvl->m_nGameVersion;
level->m_uRelease->m_fActualVersion = determineGVFromID(lvl->m_nLevelID);
free((char *)res->data);
delete res; res = nullptr;
delete m_pLinkedCURL; m_pLinkedCURL = nullptr;
delete lvl; lvl = nullptr;
return level;
}
int GDServer_BoomlingsLike19::getGameVersion() {
return 19;
}
std::string GDServer_BoomlingsLike19::getServerName() {
return Frontend::Translation::getByKey("lapi.gdserver_boomlingslike19.name");
}
std::string GDServer_BoomlingsLike19::getServerIdentifier() {
return "gdserver_boomlingslike19";
}
GDServerUploadResult *GDServer_BoomlingsLike19::uploadLevel(DatabaseController::Level *level, std::optional<CurlProxy> proxy) {
return nullptr;
}
std::vector<LevelAPI::DatabaseController::Level *> GDServer_BoomlingsLike19::getLevelsFromResponse(std::string &response) {
// TODO: implement this
return {};
}