예제 #1
0
/**
 * drops users from users.json by timeout
 * @param int $timeout
 * @return execute record to file
 *
 */
function dropUsersBySession($timeout)
{
    $users = getJsonFromFile('users.json');
    foreach ($users as $id => $user) {
        if ($id[0] == 'g') {
            if (time() - $user->visited > $timeout && $user->online == false) {
                dropUser($users, $id);
            }
        }
    }
    return setJsonToFile('users.json', $users);
}
예제 #2
0
function search()
{
    $users = getJsonFromFile('active_users.json');
    if (empty($users->count)) {
        return false;
    }
    foreach ($users as $id => $u) {
        if ($id[0] == 'g') {
            findOpponent($users, $id);
        }
    }
    setJsonToFile('active_users.json', $users);
    return true;
}
예제 #3
0
function showChat()
{
    $users = getJsonFromFile('users.json');
    if (isset($users->{$_SESSION}['user']->chat)) {
        $_SESSION['status'] = 2;
        $_SESSION['chat'] = $users->{$_SESSION}['user']->chat;
        return getChatHistory($_SESSION['chat']);
    }
    return false;
}
예제 #4
0
function searchResult()
{
    if (isset($_SESSION['chat'])) {
        return true;
    }
    $users = getJsonFromFile('users.json');
    if ($users->{$_SESSION}['user']->chat === null) {
        return false;
    }
    $_SESSION['chat'] = $users->{$_SESSION}['user']->chat;
    $_SESSION['status'] = 2;
    return true;
}
예제 #5
0
function counterUsersOnline()
{
    $obj = new stdClass();
    $users = getJsonFromFile('users.json');
    $ausers = getJsonFromFile('active_users.json');
    foreach ($users as $key => $value) {
        if ($key[0] == 'g') {
            if ($value->online) {
                $obj->total += 1;
            }
        }
    }
    $obj->total += $ausers->count;
    $obj->search = $ausers->count;
    return $obj;
}