Esempio n. 1
0
 $except = NULL;
 if (socket_select($read, $write, $except, NULL) < 1) {
     continue;
 }
 if (in_array($sock, $read)) {
     $newsock = socket_accept($sock);
     connect($newsock);
     $key = array_search($sock, $read);
     unset($read[$key]);
 }
 foreach ($read as $socket) {
     $bytes = @socket_recv($socket, $buffer, 2048, 0);
     if ($bytes == 0) {
         disconnect($socket);
     } else {
         $user = getuserbysocket($socket);
         if (!$user->handshake) {
             dohandshake($user, $buffer);
             console("User " . $user->id . " Connected!");
             send($user->socket, "You are connected. ID = " . $user->id . "<br/>");
             #global_msg("[GLOBAL MESSAGE] User ".$user->id." logged in!<br/>");
         } else {
             #console("\nprocess -> id: " . $user->id);
             #process($socket,$buffer);
             $val = json_decode(unmask($buffer), true);
             #console(var_dump(mysql_real_escape_string($val['message'])));
             //disconnect user!!!!!!!!!!!!!!!!!!!!!!! anti double login
             if (isset($val['uname'])) {
                 foreach ($users as $u) {
                     if ($val['uname'] == $u->name) {
                         if ($u->id != $user->id) {
Esempio n. 2
0
function send($client, $msg)
{
    say("> " . $client . ": \n   " . $msg);
    $msg = wrap($msg);
    $client = getuserbysocket($client);
    //$sent =
    socket_write($client->socket, $msg);
}