File size: 2,746 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
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
<?php

ob_start();
require_once 'PostgreSQL_funcs.php';
require 'PostgreSQL_config.php';
require 'PostgreSQL_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;
}

$path = htmlspecialchars($_REQUEST['marker']);
if ((!isset($path)) || strstr($path, "..")) {
    header('HTTP/1.0 500 Error');
    echo "<h1>500 Error</h1>";
    echo "Bad marker: " . $path;
    exit();
}

$parts = explode("/", $path);

if (($parts[0] != "faces") && ($parts[0] != "_markers_")) {
    header('HTTP/1.0 500 Error');
    echo "<h1>500 Error</h1>";
    echo "Bad marker: " . $path;
    exit();
}

initDbIfNeeded();

if ($parts[0] == "faces") {
    if (count($parts) != 3) {
        header('HTTP/1.0 500 Error');
        echo "<h1>500 Error</h1>";
        echo "Bad face: " . $path;
        cleanupDb();
        exit();
    }
    $ft = 0;
    if ($parts[1] == "8x8") {
        $ft = 0;
    } elseif ($parts[1] == '16x16') {
        $ft = 1;
    } elseif ($parts[1] == '32x32') {
        $ft = 2;
    } elseif ($parts[1] == 'body') {
        $ft = 3;
    }
    $pn = explode(".", $parts[2]);
    $stmt = $db->prepare('SELECT Image from ' . $dbprefix . 'Faces WHERE PlayerName=? AND TypeID=?');
    $res = $stmt->execute(array($pn[0], $ft));
    $timage = $stmt->fetch();
    if ($res && $timage) {
        header('Content-Type: image/png');
        echo stream_get_contents($timage[0]);
    } else {
        header('Location: ../images/blank.png');
    }
} else { // _markers_
    $in = explode(".", $parts[1]);
    $name = implode(".", array_slice($in, 0, count($in) - 1));
    $ext = $in[count($in) - 1];
    if (($ext == "json") && (strpos($name, "marker_") == 0)) {
        $world = substr($name, 7);
        $stmt = $db->prepare('SELECT Content from ' . $dbprefix . 'MarkerFiles WHERE FileName=?');
        $res = $stmt->execute(array($world));
        $timage = $stmt->fetch();
        header('Content-Type: application/json');
        if ($res && $timage) {
            echo stream_get_contents($timage[0]); //PDO returns arrays, even for single colums, and bytea is returned as stream.
        } else {
            echo "{ }";
        }
    } else {
        $stmt = $db->prepare('SELECT Image from ' . $dbprefix . 'MarkerIcons WHERE IconName=?');
        $res = $stmt->execute(array($name));
        $timage = $stmt->fetch();
        if ($res && $timage) {
            header('Content-Type: image/png');
            echo stream_get_contents($timage[0]);
        } else {
            header('Location: ../images/blank.png');
        }
    }
}

$stmt->closeCursor();

cleanupDb();

exit;