예제 #1
0
파일: server.php 프로젝트: Silxik/webgl
    $names = [];
    foreach ($users as $data) {
        $names[] = $data->name;
    }
    wsSend($clientID, 'U ' . implode(' ', $names));
    $users[$clientID] = (object) ['queue' => [], 'name' => $name, 'ang' => 0, 'pos' => [0, 0], 'vel' => [0, 0]];
    echo "({$clientID}){$name} joined.\n";
}
function removeUser($clientID)
{
    global $users;
    $name = $users[$clientID]->name;
    unset($users[$clientID]);
    foreach ($users as $userID => $data) {
        wsSend($userID, 'Q ' . $name);
        unset($users[$userID]->queue[$clientID]);
    }
    echo "({$clientID}){$name} left.\n";
}
function nameTaken($name)
{
    global $users;
    foreach ($users as $data) {
        if ($name === $data->name) {
            return true;
        }
    }
    return false;
}
wsStartServer(SERVER_BIND_HOST, SERVER_BIND_PORT);
예제 #2
0
    // checks if the username is being used by any client
    global $users;
    foreach ($users as $username2) {
        if ($username === $username2) {
            return true;
        }
    }
    return false;
}
function getUsernames()
{
    // returns an array of usernames
    global $users;
    $usernames = array();
    foreach ($users as $username) {
        $usernames[] = $username;
    }
    return $usernames;
}
// chat functions
function sendChat($username, $text)
{
    // sends chat text to all clients
    global $users;
    foreach ($users as $clientID => $user) {
        wsSend($clientID, 'ONTEXT ' . $username . ' ' . $text);
    }
}
// start the server
wsStartServer(CB_SERVER_BIND_HOST, CB_SERVER_BIND_PORT);