-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGDServer.h
163 lines (130 loc) · 6.26 KB
/
GDServer.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
/**
* LevelAPI - Geometry Dash level cacher with search functionality and more.
Copyright (C) 2023 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/>.
*/
#pragma once
#include "ModuleEnabled.h"
#include "curl_backend.h"
#include <optional>
#include "LevelRangeList.h"
// search recent levels
#define GDSEARCH_RECENT "4"
namespace LevelAPI {
class Account19;
namespace DatabaseController {
class Level;
}
namespace Backend {
// current status of this gdserver
enum GDServerStatus {
// server works properly
GSS_ONLINE = 0,
// server is down
GSS_OFFLINE = 1,
// server's cloudflare banned ip that tried to make a request to this server
GSS_PERMANENT_BAN = 2
};
class GDServerUploadResult {
public:
// is uploading was successful
bool successful;
// level id
int id;
};
class GDServer : public ModuleEnabled {
protected:
// base url for this gdserver
std::string m_sEndpointURL;
// player username
std::string m_sUsername;
// player password
std::string m_sPassword;
// gjp encrypted password
std::string m_sGJPPassword;
// gjp2 encrypted password
std::string m_sGJP2Password;
// account for logged in user
Account19 *m_pAccount;
LevelRangeList _ranges;
// run this server in debug mode
bool m_bDebug;
// get endpint for login action
virtual std::string _getDownloadLevelEndpointName();
// get endpoint for downloading level directly
virtual std::string _getLevelListEndpointName();
// get endpoint for downloading a list of levels
virtual std::string _getLoginAccountEndpointName();
// get common secret value used in the gd endpoints
virtual std::string _getSecretValueStandard();
// get extra secret value used in the gd endpoints
// should be redone to be more specific
virtual std::string _getSecretValueExtra();
// get a list of cloudflare errors which tells user that their ip has been bannned
virtual std::vector<std::string> _getCloudflareBans();
// create curl connection for this request
virtual CURLConnection *_setupCURL(std::optional<CurlProxy> proxy, std::string secret);
public:
GDServer();
// create gdserver with a list of level ranges
GDServer(std::vector<LevelRange> list);
// create gdserver with a single level range
GDServer(LevelRangeList list);
~GDServer();
// current status of this server
GDServerStatus m_eStatus;
// how much user should wait for a next request
int _rateLimitLength;
// emab;e or disable debug mode
virtual void setDebug(bool d);
// get debug mode flag
virtual bool getDebug();
// get level metadata by id
virtual LevelAPI::DatabaseController::Level *getLevelMetaByID(int id, std::optional<CurlProxy> proxy = std::nullopt);
// download level by id
virtual LevelAPI::DatabaseController::Level *downloadLevel(int id, std::optional<CurlProxy> proxy = std::nullopt);
// returns self
virtual LevelAPI::DatabaseController::Level *resolveLevelData(LevelAPI::DatabaseController::Level *level, std::optional<CurlProxy> proxy = std::nullopt);
// get a list of levels with type and standard parameters
virtual std::vector<LevelAPI::DatabaseController::Level *> getLevelsBySearchType(int type, std::optional<CurlProxy> proxy = std::nullopt);
// implements basic search functionality
// it doesn't allow searching requests that use gjp password
virtual std::vector<LevelAPI::DatabaseController::Level *> getLevelsBySearchType(int type, std::string str, int page, std::optional<CurlProxy> proxy = std::nullopt);
// get a list of levels based on the server response
virtual std::vector<LevelAPI::DatabaseController::Level *> getLevelsFromResponse(std::string &response);
// set credentials for this account
virtual void setCredentials(std::string u, std::string p);
// login into an acccount
// NOT IMPLEMENTED
virtual bool login(std::optional<CurlProxy> proxy = std::nullopt);
// get max size of level page (in levels)
virtual int getMaxLevelPageSize();
// get max size of max pack page (in levels)
virtual int getMaxMapPackPageSize();
// get gameversion for this server
virtual int getGameVersion();
// get server name
virtual std::string getServerName();
// get server identifier
virtual std::string getServerIdentifier();
// this function uses level ranges to detect in which version this level has been released
virtual std::string determineGVFromID(int id);
// try to upload a level
// NOT IMPLEMENTED
virtual GDServerUploadResult *uploadLevel(DatabaseController::Level *level, std::optional<CurlProxy> proxy = std::nullopt);
// unload level array
static void destroyLevelVector(std::vector<LevelAPI::DatabaseController::Level *> v);
// returns true if curl or cloudflare returned error
bool processCURLAnswer(CURLResult *res);
};
}
}