File size: 1,711 Bytes
36ddefa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<?php

ob_start();
require_once 'MySQL_funcs.php';
require 'MySQL_config.php';
require 'MySQL_access.php';
ob_end_clean();

session_start();

if (isset($_SESSION['userid'])) {
    $userid = $_SESSION['userid'];
} else {
    $userid = '-guest-';
}

$loggedin = false;
if (strcmp($userid, '-guest-')) {
    $loggedin = true;
}

$content = getStandaloneFile('dynmap_config.json');

header('Content-type: application/json; charset=utf-8');

$json = json_decode($content);

if (!$loginenabled) {
    echo $content;
} elseif ($json->loginrequired && !$loggedin) {
    echo "{ \"error\": \"login-required\" }";
} else {
    $uid = '[' . strtolower($userid) . ']';
    $json->loggedin = $loggedin;
    $wcnt = count($json->worlds);
    $newworlds = array();
    for ($i = 0; $i < $wcnt; $i++) {
        $w = $json->worlds[$i];
        if ($w->protected) {
            $ss = stristr($worldaccess[$w->name], $uid);
            if ($ss !== false) {
                $newworlds[] = $w;
            } else {
                $w = null;
            }
        } else {
            $newworlds[] = $w;
        }
        if ($w != null) {
            $mcnt = count($w->maps);
            $newmaps = array();
            for ($j = 0; $j < $mcnt; $j++) {
                $m = $w->maps[$j];
                if ($m->protected) {
                    $ss = stristr($mapaccess[$w->name . '.' . $m->prefix], $uid);
                    if ($ss !== false) {
                        $newmaps[] = $m;
                    }
                } else {
                    $newmaps[] = $m;
                }
            }
            $w->maps = $newmaps;
        }
    }
    $json->worlds = $newworlds;

    echo json_encode($json);
}
cleanupDb();