forked from challenge-project/challenge-sandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeb.Script.txt
More file actions
406 lines (336 loc) · 10.4 KB
/
Copy pathWeb.Script.txt
File metadata and controls
406 lines (336 loc) · 10.4 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
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
/*
// Web.Script.txt
// by BigBang1112
// part of Universe Library Set
// Wrapper for implicit ManiaPlanet Web Services API access.
// This library does depend on more libraries from the Universe Library Set:
// - Http.Script.txt
// - RegexFix.Script.txt
// You only need to use the libraries above, although it's recommended to use the whole set.
*/
/*
// Compatible contexts:
// - CManiaApp
// - CMode
// - CServerPlugin
*/
/*
// SPlayer Me(Text _Token)
// STitle[] MeTitlesCreated(Text _Token)
// SDedicatedAccount[] MeDedicated(Text _Token)
// SMap[] MeMaps(Text _Token)
// Text MeEmail(Text _Token)
// SMap Map(Text _Uid)
// SZone[] Zones()
// STitle[] Titles(Text[] _Filters, Text _OrderBy, Integer _Offset, Integer Length)
// STitle[] Titles(Text[] _Filters, Text _OrderBy, Integer _Offset)
// STitle[] Titles(Text[] _Filters, Text _OrderBy)
// STitle[] Titles(Text[] _Filters)
// STitle[] Titles()
// STitle Title(Text _Uid)
// STitleScript[] TitleScripts(Text _Uid)
// SOnlineServer[] Servers(SServerFilter _Filter)
// SOnlineServer[] Servers()
// SFlashPost[] Flashes(Text _LiveUid, Integer _Offset, Integer _Length)
// SFlashPost[] Flashes(Text _LiveUid, Integer _Offset)
// SFlashPost[] Flashes(Text _LiveUid)
*/
#Include "TextLib" as TextLib
#Include "Libs/BigBang1112/Http.Script.txt" as Http
#Include "Libs/BigBang1112/RegexFix.Script.txt" as RegexFix
#Struct SPlayer {
Text Login;
Text Nickname;
Text Path;
}
#Struct STitle {
Text Uid;
Integer Cost;
Text Name;
Text Description;
Text Punchline;
Text CardUrl;
Text DownloadUrl;
Text BackgroundUrl;
Text LogoUrl;
Text TitleMakerUid;
Boolean Public;
}
#Struct SDedicatedAccount {
Text Login;
Integer LastUsedDate;
}
#Struct SMap {
Text Uid;
Text Name;
Text AuthorLogin;
Text DownloadUrl;
Boolean Private;
Text ThumbnailUrl;
}
#Struct SZone {
Text Path;
}
#Struct STitleScript {
Text FileName;
Text MatchSettings;
}
#Struct SOnlineServer {
Text Name;
Text Description;
Text Login;
Text Title;
Integer LadderLimitMin;
Integer LadderLimitMax;
Integer AverageLadderPoints;
Integer PlayerCount;
Integer PlayerMax;
Integer SpectatorCount;
Text Zone;
Boolean IsPrivate;
Boolean IsSpectatorPrivate;
Boolean IsLobby;
Integer LevelClass1;
Integer LevelClass2;
Integer LevelClass3;
Integer LevelClass4;
Integer LevelClass5;
Text ScriptName;
Integer Gamemode;
Text RelayOf;
Text Environment;
}
#Struct SFlashPost {
Integer Id;
Text Headline;
Text Body;
Text MediaUrl;
Text DateDiff;
Text PostDate;
Text Location;
Text LocationManialink;
Text LocationType;
Text LocationId;
Text LocationFrom;
Text LocationFromManialink;
Integer RepostCount;
}
#Struct SServerFilter {
Text OrderBy;
Integer PlayerCount;
Text[] TitleUids;
Text[] Environments;
Text ScriptName;
Text Search;
Text Zone;
Boolean OnlyPublic;
Boolean OnlyPrivate;
Boolean OnlyLobby;
Boolean ExcludeLobby;
Integer Offset;
Integer Length;
}
Text Private_ToCleanerJson(Text _Json) {
declare Final = _Json;
declare AllKeys = TextLib::RegexFind("\"(.*?)\":(.*?)(,|})",_Json,"g");
foreach(Key,AllKeys) {
declare PatternPrecise = "\"([a-z])(.*?)\":(.*?)(,|})";
declare MatchFirstLetter = TextLib::RegexMatch(PatternPrecise,Key,"");
declare FirstLetter = TextLib::ToUpperCase(MatchFirstLetter[1]);
declare FixedRest = MatchFirstLetter[2];
declare FindInnerFirstLetters = TextLib::RegexFind("_([a-z])(.*?)",FixedRest,"g");
foreach(InnerFirstLetter, FindInnerFirstLetters) {
declare MatchInnerFirstLetters = TextLib::RegexMatch("_([a-z])(.*?)",InnerFirstLetter,"");
declare FirstInnerLetter = TextLib::ToUpperCase(MatchInnerFirstLetters[1]);
FixedRest = TextLib::Replace(FixedRest, InnerFirstLetter, RegexFix::RegexReplace("_([a-z])(.*?)", InnerFirstLetter, "g", FirstInnerLetter^"\\2"));
}
declare Fixed = RegexFix::RegexReplace(PatternPrecise, Key, "g", "\"" ^ FirstLetter ^ FixedRest ^ "\":\\3\\4");
Final = TextLib::Replace(Final,Key,Fixed);
}
return Final;
}
SPlayer Me(Text _Token) {
declare Result = Http::SyncGET_Result("https://maniaplanet.com/webservices/me", False, "Authorization: Bearer "^_Token);
declare SPlayer Player;
declare JsonSuccess = Player.fromjson(Private_ToCleanerJson(Result));
return Player;
}
STitle[] MeTitlesCreated(Text _Token) {
declare Result = Http::SyncGET_Result("https://maniaplanet.com/webservices/me/titles/created", False, "Authorization: Bearer "^_Token);
declare STitle[] Titles;
declare JsonSuccess = Titles.fromjson(Private_ToCleanerJson(Result));
return Titles;
}
SDedicatedAccount[] MeDedicated(Text _Token) {
declare Result = Http::SyncGET_Result("https://maniaplanet.com/webservices/me/titles/dedicated", False, "Authorization: Bearer "^_Token);
declare SDedicatedAccount[] Accounts;
declare JsonSuccess = Accounts.fromjson(Private_ToCleanerJson(Result));
return Accounts;
}
SMap[] MeMaps(Text _Token) {
declare Result = Http::SyncGET_Result("https://maniaplanet.com/webservices/me/maps", False, "Authorization: Bearer "^_Token);
declare SMap[] Maps;
declare JsonSuccess = Maps.fromjson(Private_ToCleanerJson(Result));
return Maps;
}
//tested, not working
Text MeEmail(Text _Token) {
return Http::SyncGET_Result("https://maniaplanet.com/webservices/me/email", False, "Authorization: Bearer "^_Token);
}
SMap Map(Text _Uid) {
declare Result = Http::SyncGET_Result("https://maniaplanet.com/webservices/maps/"^_Uid);
declare SMap Map;
declare JsonSuccess = Map.fromjson(Private_ToCleanerJson(Result));
return Map;
}
SZone[] Zones() {
declare Result = Http::SyncGET_Result("https://maniaplanet.com/webservices/zones");
declare SZone[] Zones;
declare JsonSuccess = Zones.fromjson(Private_ToCleanerJson(Result));
return Zones;
}
STitle[] Titles(Text[] _Filters, Text _OrderBy, Integer _Offset, Integer Length) {
return [];
}
STitle[] Titles(Text[] _Filters, Text _OrderBy, Integer _Offset) {
return Titles(_Filters, _OrderBy, _Offset, 10);
}
STitle[] Titles(Text[] _Filters, Text _OrderBy) {
return Titles(_Filters, _OrderBy, 0);
}
STitle[] Titles(Text[] _Filters) {
return Titles(_Filters, "onlinePlayers");
}
STitle[] Titles() {
return Titles([]);
}
STitle Title(Text _Uid) {
declare Result = Http::SyncGET_Result("https://maniaplanet.com/webservices/titles/"^_Uid);
declare STitle Title;
declare JsonSuccess = Title.fromjson(Private_ToCleanerJson(Result));
return Title;
}
STitleScript[] TitleScripts(Text _Uid) {
declare Result = Http::SyncGET_Result("https://maniaplanet.com/webservices/titles/"^_Uid^"/scripts");
declare STitleScript[] Scripts;
declare JsonSuccess = Scripts.fromjson(Private_ToCleanerJson(Result));
return Scripts;
}
SOnlineServer[] Servers(SServerFilter _Filter) {
return [];
}
SOnlineServer[] Servers() {
declare SServerFilter Filter;
return Servers(Filter);
}
SFlashPost[] Flashes(Text _LiveUid, Integer _Offset, Integer _Length) {
declare Result = Http::SyncGET_Result("""https://maniaplanet.com/webservices/flashes/post/{{{_LiveUid}}}?offset={{{_Offset}}}&length={{{_Length}}}""");
declare SFlashPost[] Flashes;
declare JsonSuccess = Flashes.fromjson(Private_ToCleanerJson(Result));
return Flashes;
}
SFlashPost[] Flashes(Text _LiveUid, Integer _Offset) {
return Flashes(_LiveUid, _Offset, 10);
}
SFlashPost[] Flashes(Text _LiveUid) {
return Flashes(_LiveUid, 0);
}
/*
// CHttpRequest AsyncGet(Text _Name)
// Gets asynchonous request, completed or pending.
// Text _Name - Identification name
// Returns request that can or cannot be in the progress
*/
CHttpRequest AsyncGet(Text _Name) {
return Http::Get(_Name);
}
/*
// Void AsyncDestroy(Text _Name)
// Destroys an aynchonous request.
// Text _Name - Identification name
*/
Void AsyncDestroy(Text _Name) {
Http::Destroy(_Name);
}
/*
// Boolean AsyncIsCompleted(Text _Name, Boolean _NoLog)
// Checks if the asynchronous request was completed.
// Text _Name - Identification name
// Boolean _NoLog - If to not inform to the console
// Returns True if the request is completed but not destroyed.
*/
Boolean AsyncIsCompleted(Text _Name, Boolean _NoLog) {
return Http::IsCompleted(_Name, _NoLog);
}
/*
// Boolean AsyncIsCompleted(Text _Name)
// Checks if the asynchronous request was completed.
// Text _Name - Identification name
// Returns True if the request is completed but not destroyed.
*/
Boolean AsyncIsCompleted(Text _Name) {
return AsyncIsCompleted(_Name, False);
}
/*
// Boolean AsyncIsSuccessful(Text _Name)
// Checks if the asynchonous request was completed successfully.
// Text _Name - Identification name
// Returns True if the request is completed with a positive response (between 200 inclusively and 300 exclusively HTTP code).
*/
Boolean AsyncIsSuccessful(Text _Name) {
return Http::IsSuccessful(_Name);
}
/*
// Integer AsyncGetStatusCode(Text _Name, Boolean _NoLog)
// Gets status code of the asynchronous request.
// Text _Name - Identification name
// Boolean _NoLog - If to not inform to the console
// Returns status code number of a completed request, or 0 if the request is not completed or does not exist.
*/
Integer AsyncGetStatusCode(Text _Name, Boolean _NoLog) {
return Http::GetStatusCode(_Name, _NoLog);
}
/*
// Integer AsyncGetStatusCode(Text _Name)
// Gets status code of the asynchronous request.
// Text _Name - Identification name
// Returns status code number of a completed request, or 0 if the request is not completed or does not exist.
*/
Integer AsyncGetStatusCode(Text _Name) {
return AsyncGetStatusCode(_Name, False);
}
/*
// Text AsyncGetResult(Text _Name)
// Gets result of the asynchronous request.
// Text _Name - Identification name
// Returns result of a completed request, or empty string if the request is not completed or does not exist.
*/
Text AsyncGetResult(Text _Name) {
return Http::GetResult(_Name);
}
Boolean AsyncMeMaps(Text _Name, Text _Token) {
return Http::AsyncGET(_Name, "https://maniaplanet.com/webservices/me/maps", False, "Authorization: Bearer "^_Token);
}
SMap[] GetAsyncMeMapsResult(Text _Name) {
declare SMap[] Result;
if(AsyncIsCompleted(_Name, True)) {
if(AsyncIsSuccessful(_Name)) {
declare JsonSuccess = Result.fromjson(Private_ToCleanerJson(AsyncGetResult(_Name)));
}
AsyncDestroy(_Name);
}
return Result;
}
Boolean AsyncMap(Text _Name, Text _Uid) {
return Http::AsyncGET(_Name, "https://maniaplanet.com/webservices/maps/"^_Uid);
}
SMap GetAsyncMapResult(Text _Name) {
declare SMap Result;
if(AsyncIsCompleted(_Name, True)) {
if(AsyncIsSuccessful(_Name)) {
declare JsonSuccess = Result.fromjson(Private_ToCleanerJson(AsyncGetResult(_Name)));
}
AsyncDestroy(_Name);
}
return Result;
}