-
Notifications
You must be signed in to change notification settings - Fork 0
/
CTFd.hx
37 lines (34 loc) · 1.15 KB
/
CTFd.hx
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
import haxe.Json;
class CTFd {
public static function run(api:String, cookie:String):CTF {
function req(endpoint:String):Dynamic {
var url = '$api/$endpoint';
var cacheId = "cache/" + endpoint.split("/").join("-") + ".json";
var parsed:haxe.DynamicAccess<Dynamic> = Json.parse(url.requestString(cacheId));
if (!parsed.exists("success") || !(parsed.get("success"):Bool) || !parsed.exists("data"))
throw 'cannot retrieve ${url} (not CTFd?)';
return parsed.get("data");
}
var rawList:Array<{id:Int}> = req("challenges");
var solved:Array<Int> = (req("teams/me/solves"):Array<{challenge_id:Int}>).map(c -> c.challenge_id);
return {
challenges: rawList.map(c -> {
var chall:CTFdChallenge = req('challenges/${c.id}');
chall.solved = solved.indexOf(chall.id) != -1;
chall;
})
};
}
}
typedef CTFdCTF = {
challenges:Array<CTFdChallenge>
};
typedef CTFdChallenge = CTF.CTFChallenge & {
id:Int
,state:String
,type:String
,max_attempts:Int
,tags:Array<{value:String}>
,hints:Array<{content:String, cost:Int, id:Int}>
,solves:Int
};