예제 #1
0
파일: CONFIG.php 프로젝트: piter65/spilldec
function get_player_data($group, $key, $timeout)
{
    $player_data_file_name = __PATH_PLAYER_DATA__ . 'player_data_' . $group . '.json';
    $player_data = array();
    if (file_exists($player_data_file_name)) {
        // Retrieve the messages
        $str_json = file_get_contents($player_data_file_name);
        $json = json_decode($str_json, true);
        if (isset($key)) {
            // Retrieve the specific player if it exists.
            if (isset($json[$key])) {
                $player_data = $json[$key];
            }
        } else {
            $player_data = $json;
            // Filter out those who exceed the timeout.
            $player_data = filter_player_data_by_timeout($player_data, $timeout);
        }
    }
    return $player_data;
}
예제 #2
0
require_once './data_store.php';
$result = array();
//$result['server_time'] = (new DateTime())->format(__DATE_FORMAT__);
$result['data'] = array();
$result['error'] = null;
try {
    $timeout = 0;
    if (isset($_REQUEST['timeout'])) {
        $timeout = (int) $_REQUEST['timeout'];
    }
    $group_data = array();
    // Retrieve the data
    $group_data = data_store_get_all('player_data_');
    // Loop backwards thru the groups and remove any players that exceen the timeout.
    for ($index_group = count($group_data) - 1; $index_group > -1; --$index_group) {
        $group = $group_data[$index_group];
        // Filter out the players that exceed the timeout.
        $players = filter_player_data_by_timeout($group['value'], $timeout);
        if (count($players) > 0) {
            $group['value'] = $players;
            $group_data[$index_group] = $group;
        } else {
            // Remove the group since it's now empty.
            array_splice($group_data, $index_group, 1);
        }
    }
    $result['data'] = $group_data;
} catch (Exception $e) {
    $result['error'] = $e->getMessage();
}
echo json_encode($result);
예제 #3
0
    $key = null;
    if (isset($_REQUEST['group'])) {
        $group = $_REQUEST['group'];
    } else {
        throw new Exception('ERROR NO GROUP SPECIFIED.');
    }
    if (isset($_REQUEST['timeout'])) {
        $timeout = (int) $_REQUEST['timeout'];
    }
    if (isset($_REQUEST['key'])) {
        $key = $_REQUEST['key'];
    }
    $data_key = 'player_data_' . $group;
    // Retrieve the data
    $data = data_store_get($data_key);
    $player_data = array();
    if (isset($key)) {
        // Retrieve the specific player if it exists.
        if (isset($data[$key])) {
            $player_data = $data[$key];
        }
    } else {
        $player_data = $data;
        // Filter out those who exceed the timeout.
        $player_data = filter_player_data_by_timeout($player_data, $timeout);
    }
    $result['data']['player_data'] = $player_data;
} catch (Exception $e) {
    $result['error'] = $e->getMessage();
}
echo json_encode($result);