3 * Return user data with dynamic username that has been saved during login
5 * @author Christian Weiske <cweiske@cweiske.de>
8 $dbFile = __DIR__ . '/../../../../data/usernames.sqlite3';
9 $cfgFile = __DIR__ . '/../../../../config.php';
10 if (file_exists($cfgFile)) {
15 $ip = $_SERVER['REMOTE_ADDR'];
18 header('X-Fail-Reason: empty ip address');
19 header('Content-type: application/json');
20 echo file_get_contents('me.json');
25 $db = new SQLite3($dbFile, SQLITE3_OPEN_READONLY);
26 } catch (Exception $e) {
28 header('X-Fail-Reason: database file not found');
29 header('Content-type: application/json');
30 echo file_get_contents('me.json');
34 $stmt = $db->prepare('SELECT * FROM usernames WHERE ip = :ip');
35 $stmt->bindValue(':ip', $ip);
36 $res = $stmt->execute();
37 $row = $res->fetchArray(SQLITE3_ASSOC);
41 header('Content-type: application/json');
42 echo file_get_contents('me.json');
46 $data = json_decode(file_get_contents('me.json'));
47 $data->gamer->username = $row['username'];
48 $data->gamer->nickname = $row['username'];
50 switch (strtolower($row['username'])) {
52 $data->gamer->founder = true;
53 $data->gamer->avatar = $GLOBALS['baseUrl'] . 'avatars/cweiske.png';
56 $data->gamer->founder = true;
60 header('Content-type: application/json');
61 echo json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n";