From: Roland Häder Date: Sun, 15 Feb 2009 15:23:22 +0000 (+0000) Subject: Just moved X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e185f1b9f5fc8716afd8787afeffddf4dee84958;p=hub.git Just moved --- diff --git a/.gitattributes b/.gitattributes index 9d4d1ecd8..a4e5913d2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -14,7 +14,6 @@ application/hub/loader.php -text application/hub/main/.htaccess -text application/hub/middleware/.htaccess -text application/hub/starter.php -text -/chat-server.php -text /clear-cache.sh -text db/.htaccess -text docs/COPYING -text @@ -27,6 +26,3 @@ docs/THANKS -text /package.sh -text /pdepend.sh -text /rebuild_doc.sh -text -/udp-client.php -text -/udp-inc.php -text -/udp-server.php -text diff --git a/chat-server.php b/chat-server.php deleted file mode 100644 index 388d8039e..000000000 --- a/chat-server.php +++ /dev/null @@ -1,168 +0,0 @@ - 0) { - // create a copy, so $clients doesn't get modified by socket_select() - $read = $clients; - - // get a list of all the clients that have data to be read from - // if there are no clients with data, go to next iteration - $left = @socket_select($read, $write = null, $except = null, 0, 150); - if ($left < 1) { - continue; - } - - // check if there is a client trying to connect - if (in_array($main_sock, $read)) { - // accept the client, and add him to the $clients array - $new_sock = socket_accept($main_sock); - $clients[] = $new_sock; - - // send the client a welcome message - socket_write($new_sock, "no noobs, but ill make an exception :)\n". - "There are ".(count($clients) - 1)." client(s) connected to the server\n"); - - socket_getpeername($new_sock, $ip); - out(__FILE__, __LINE__, "[".date("m/d/Y:H:i:s", time())."]:New client connected: {$ip}"); - - // Notify all chatter - if (count($clients) > 2) { - foreach ($clients as $send_sock) { - if ($send_sock != $main_sock && $send_sock != $new_sock) { - socket_write($send_sock, "Server: Chatter has joined from {$ip}. There are now ".(count($clients) - 1)." clients.\n"); - } - } - } - - // remove the listening socket from the clients-with-data array - $key = array_search($main_sock, $read); - unset($read[$key]); - } - - // loop through all the clients that have data to read from - foreach ($read as $read_sock) { - // Get client data - socket_getpeername($read_sock, $ip); - - // read until newline or 1024 bytes - // socket_read while show errors when the client is disconnected, so silence the error messages - $data = @socket_read($read_sock, 1024, PHP_NORMAL_READ); - - // check if the client is disconnected - if (($data === false) || (in_array(strtolower(trim($data)), $leaving))) { - - // remove client for $clients array - $key = array_search($read_sock, $clients); - unset($clients[$key]); - out(__FILE__, __LINE__, "[".date("m/d/Y:H:i:s", time())."]:Client from {$ip} disconnected. Left: ".(count($clients) - 1).""); - - // Notify all chatter - if (count($clients) > 1) { - foreach ($clients as $send_sock) { - if ($send_sock != $main_sock) { - socket_write($send_sock, "Server: Chatter from {$ip} has logged out. ".(count($clients) - 1)." left.\n"); - } - } - } - - // continue to the next client to read from, if any - socket_write($read_sock, "Server: Good bye.\n"); - socket_shutdown($read_sock, 2); - socket_close($read_sock); - continue; - } elseif (in_array(trim($data), $shutdown)) { - // Is he allowed to shutdown? - if (!in_array($ip, $masters)) { - out(__FILE__, __LINE__, "[".date("m/d/Y:H:i:s", time())."]:Client $ip has tried to shutdown the server!"); - socket_write($read_sock, "Server: You are not allowed to shutdown the server!\n"); - $data = ""; - continue; - } - - // Close all connections a leave here - foreach ($clients as $client) { - // Send message to client - if ($client !== $main_sock && $client != $read_sock) { - socket_write($client, "Server: Shutting down! Thank you for joining us.\n"); - } - - // Quit him - socket_shutdown($client, 2); - socket_close($client); - } // end foreach - - // Leave the loop - $data = ""; - $clients = array(); - continue; - } - - // trim off the trailing/beginning white spaces - $data = trim($data); - - // Test for HTML codes - $tags = strip_tags($data); - - // check if there is any data after trimming off the spaces - if (!empty($data) && $tags == $data && count($clients) > 2) { - // send this to all the clients in the $clients array (except the first one, which is a listening socket) - foreach ($clients as $send_sock) { - - // if its the listening sock or the client that we got the message from, go to the next one in the list - if ($send_sock == $main_sock || $send_sock == $read_sock) - continue; - - // write the message to the client -- add a newline character to the end of the message - socket_write($send_sock, "{$ip}:{$data}\n"); - - } // end of broadcast foreach - - // Send confirmation to "chatter" - socket_write($read_sock, "\nServer: Message accepted.\n"); - } elseif ($tags != $data) { - // HTML codes are not allowed - out(__FILE__, __LINE__, "[".date("m/d/Y:H:i:s", time())."]:Client $ip has entered HTML code!"); - socket_write($read_sock, "Server: HTML is forbidden!\n"); - } elseif ((count($clients) == 2) && ($read_sock != $main_sock)) { - // No one else will hear the "chatter" - out(__FILE__, __LINE__, "[".date("m/d/Y:H:i:s", time())."]:Client $ip speaks with himself."); - socket_write($read_sock, "Server: No one will hear you!\n"); - } - } // end of reading foreach -} - -// close the listening socket -socket_close($main_sock); - -?> - \ No newline at end of file diff --git a/udp-client.php b/udp-client.php deleted file mode 100644 index d06663ee9..000000000 --- a/udp-client.php +++ /dev/null @@ -1,124 +0,0 @@ - 0)) { - echo "ERROR: $errno - $errstr\n"; - exit; -} - -if (!stream_set_blocking($client, 0)) { - echo "ERROR: Cannot set non-blocking mode!\n"; - exit; -} - -out(__FILE__, __LINE__, "Starting test..."); -while (!feof($client)) { - //out(__FILE__, __LINE__, "Sending ping..."); - fwrite($client, "PING"); - - //out(__FILE__, __LINE__, "Reading reply..."); - $read = trim(fread($client, 50)); - if (empty($read)) { - $failed++; - out(__FILE__, __LINE__, "Empty line received. Is the server there?"); - } elseif ($read == "INVALID") { - $failed++; - out(__FILE__, __LINE__, "Server has not accepted our message."); - } else { - $failed = 0; - //out(__FILE__, __LINE__, "Response ${read} received."); - } - - if ($failed == constant('MAX_FAILURES')) { - out(__FILE__, __LINE__, "Too many failures! (failed=${failed})"); - break; - } elseif ($failed < constant('MAX_FAILURES')) { - continue; - } - - $rec = explode(":", $read); - - $time = $rec[0]; - $right = explode("=", $rec[1]); - $hash = $right[1]; - $hasher = $right[0]; - - if (validate($time) != $hash) { - out(__FILE__, __LINE__, "Invalid: ${read}/{$hash}"); - $invalid++; - continue; - } - - if (!isset($data[$rec[0]])) { - if (count($data) > 0) { - echo $data[$rec[0]-1]."\n"; - $cnt++; - if ($cnt > constant('ROUNDS')) break; - } - $data[$rec[0]] = 0; - } - $data[$rec[0]]++; -} - -array_shift($data); - -stream_socket_shutdown($client, STREAM_SHUT_RDWR); - -$avg = 0; -$min = 0; -$max = 0; - -foreach ($data as $cnt) { - if ($cnt > $max) { - $max = $cnt; - } - if (($cnt < $min) || ($min == 0)) { - $min = $cnt; - } - $avg += $cnt; -} - -if (count($data) > 0) { - $avg = round($avg / count($data)); -} - -out(__FILE__, __LINE__, "MIN/AVG/MAX=${min}/${avg}/${max}"); -out(__FILE__, __LINE__, "INVALID=${invalid}"); - -?> diff --git a/udp-inc.php b/udp-inc.php deleted file mode 100644 index b92a35c07..000000000 --- a/udp-inc.php +++ /dev/null @@ -1,13 +0,0 @@ - diff --git a/udp-server.php b/udp-server.php deleted file mode 100644 index b52609264..000000000 --- a/udp-server.php +++ /dev/null @@ -1,30 +0,0 @@ - 0)) { - die("$errstr ($errno)\n"); -} - -$pkt = ""; - -out(__FILE__, __LINE__, "Waiting for clients..."); - -do { - $pkt = stream_socket_recvfrom($socket, 50, 0, $peer); - //out(__FILE__, __LINE__, "Received packet ${pkt} from peer ${peer}."); - - if (trim($pkt) == "PING") { - //out(__FILE__, __LINE__, "Sending data to peer ${peer}."); - stream_socket_sendto($socket, (time().":md5=".md5(time())), 0, $peer); - } else { - out(__FILE__, __LINE__, "Invalid packet ${pkt} from peer ${peer}."); - stream_socket_sendto($socket, "INVALID", 0, $peer); - } -} while ($pkt !== false); - -?>