-
Notifications
You must be signed in to change notification settings - Fork 0
/
xdm.json-server.php
51 lines (41 loc) · 1.1 KB
/
xdm.json-server.php
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
<?php
require_once('xdm.lib.php');
$sets = SetFactory::allSets();
if(!empty($_REQUEST['q'])){
if($_REQUEST['q'] === 'save'){
$collection = json_decode(file_get_contents('php://input'));
print abstractJSON($collection);
}
if($_REQUEST['q'] === 'load'){
$collection = file_get_contents('php://input');
$json = json_encode(clarifyJSON(trim($collection,'"')));
print $json;
}
if($_REQUEST['q'] === 'all'){
$string = '[';
foreach($sets as $set){
$string .= $set->json(true).',';
}
$string = trim($string,',').']';
print $string;
}
if($_REQUEST['q'] === 'draft'){
$col = json_decode(file_get_contents('php://input'));
if(empty($col)){
print "Unable to read collection";
}else{
/* $rules =
[
team size: default 6,
number of teams: default 1,
balance cost?: default false,
balance rarities?: default false (recursive call: array(rarities))
*/
$request = json_decode(file_get_contents('php://input'));
$draft = new Draft($request->cards,$request->rules);
$result = json_encode($draft->result());
print $result;
}
}
}
?>