#!/usr/local/bin/php $value) { if (get_resource_type($value)=='Unknown') { unset($tabSocket[$key]); } } // On bloque en attendant une connexion $pret = socket_select($tabSocket, $null = null, $null = null, null); // Si on detecte une nouvelle connexion if (in_array($socketHandler, $tabSocket)) { for ($i=0; $i < MAXCONCURRENT; $i++) { if ($client[$i]==null) { // On se met à l'écoute $client[$i] = socket_accept($socketHandler); socket_setopt($client[$i], SOL_SOCKET, SO_REUSEADDR, 1); socket_getpeername($client[$i], $remote_host[$i], $remote_port[$i]); // On fait une liaison à l'ircd $todisconnect = false; $irc[$i] = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if(!$irc[$i]) { $todisconnect = true; } else { $test = socket_connect($irc[$i], IRC_ADDR, IRC_PORT); if(!$test) { $todisconnect = true; } } if ($todisconnect) { // Y'a eut un probleme de connexion irc, on deconnecte le client socket_shutdown($client[$i]); socket_close($client[$i]); $client[$i] = null; unset($remote_host[$i]); unset($remote_port[$i]); } break; } if ($i == MAXCONCURRENT - 1) { echo 'Trop de clients'."\n"; } } if ($i>$maxi) { $maxi = $i; } if (--$pret<=0) { continue; } } // On balaye les clients pour voir si un client a parlé for ($i = 0; $i <= $maxi; $i++) { if ($client[$i]==null) { continue; } if (in_array($client[$i], $tabSocket)) { $buff = trim(socket_read($client[$i], MAXLINE)); if (!$buff) { // On ferme la connexion flash socket_shutdown($client[$i]); socket_close($client[$i]); $client[$i] = null; unset($remote_host[$i]); unset($remote_port[$i]); // On ferme la connexion ircd socket_shutdown($irc[$i]); socket_close($irc[$i]); $irc[$i] = null; } else { // On modifie les < pour que ca passe bien $buff = str_replace('<','<', $buff); // On envoie du flash vers le irc socket_write($irc[$i], $buff."\n"); } } } // On balaye connexionx irc pour voir si un irc a parlé for ($i = 0; $i <= $maxi; $i++) { if ($irc[$i]==null) { continue; } if (in_array($irc[$i], $tabSocket)) { $buff = trim(socket_read($irc[$i], MAXLINE)); if (!$buff) { // On ferme la connexion flash socket_shutdown($client[$i]); socket_close($client[$i]); $client[$i] = null; unset($remote_host[$i]); unset($remote_port[$i]); // On ferme la connexion ircd socket_shutdown($irc[$i]); socket_close($irc[$i]); $irc[$i] = null; } else { // On decode si c'est en utf8 $buff = smart_utf8_decode($buff); // On modifie les < en < $buff = str_replace('<', '<', $buff); // On envoie de irc vers flash $tabout = explode("\r\n", $buff); foreach($tabout as $value) { socket_write($client[$i], $value."\0"); } } } } } // Fermeture du serveur socket_close($socketHandler); ?>