diff --git a/AutoLoader.php b/AutoLoader.php index 487f531..ab8072f 100644 --- a/AutoLoader.php +++ b/AutoLoader.php @@ -7,7 +7,7 @@ * @return void */ function __autoload($className) { - $file = "Classes/" . str_replace("_", "/", $className) . ".php"; + $file = "Classes" . DIRECTORY_SEPARATOR . str_replace("_", DIRECTORY_SEPARATOR, $className) . ".php"; if(file_exists($file) === TRUE) { require_once($file); } else { diff --git a/Classes/Socket/SocketHandler.php b/Classes/Socket/SocketHandler.php index 6dcb160..6df559b 100644 --- a/Classes/Socket/SocketHandler.php +++ b/Classes/Socket/SocketHandler.php @@ -91,7 +91,7 @@ class Socket_SocketHandler { public function connect($address, $port) { if($this->isConnected === TRUE) throw new Exception_SocketException("Socket is already connected!", 1289663170); $result = socket_connect($this->socket, $address, $port); - if($result === FALSE) $this->error(); + if($result === FALSE) $this->handleSocketError(); $this->isConnected = TRUE; } @@ -105,9 +105,9 @@ class Socket_SocketHandler { public function bind($address, $port) { if($this->isBound === TRUE) throw new Exception_SocketException("Socket is already bound!", 1289663212); $result = socket_set_option($this->socket, SOL_SOCKET, SO_REUSEADDR, 1); - if($result === FALSE) $this->error(); + if($result === FALSE) $this->handleSocketError(); $result = socket_bind($this->socket, $address, $port); - if($result === FALSE) $this->error(); + if($result === FALSE) $this->handleSocketError(); $this->isBound = TRUE; } @@ -119,7 +119,7 @@ class Socket_SocketHandler { public function listen() { if($this->isBound === FALSE) throw new Exception_SocketException("Cannot listen on unbound socket!", 1289663220); $result = socket_listen($this->socket); - if($result === FALSE) $this->error(); + if($result === FALSE) $this->handleSocketError(); $this->isListening = TRUE; } @@ -141,7 +141,7 @@ class Socket_SocketHandler { if($this->isBound === FALSE) throw new Exception_SocketException("Cannot accept connections from unbound socket!", 1289663239); if($this->isListening === FALSE) throw new Exception_SocketException("Cannot accept connections from socket that is not listening!", 1289663241); $accept = socket_accept($this->socket); - if($accept === FALSE) $this->error(); + if($accept === FALSE) $this->handleSocketError(); return $accept; } @@ -153,7 +153,7 @@ class Socket_SocketHandler { public function getRemoteName() { if($this->isConnected === FALSE) throw new Exception_SocketException("Socket not connected, cannot retrieve remote name!", 1289928192); $result = socket_getpeername($this->socket, $address, $port); - if($result === FALSE) $this->error(); + if($result === FALSE) $this->handleSocketError(); return $address . ":" . $port; } @@ -165,7 +165,7 @@ class Socket_SocketHandler { public function getLocalName() { if($this->isBound === FALSE ^ $this->isConnected === FALSE) throw new Exception_SocketException("Socket is not bound or connected, no local name available!", 1289928256); $result = socket_getsockname($this->socket, $address, $port); - if($result === FALSE) $this->error(); + if($result === FALSE) $this->handleSocketError(); return $address . ":" . $port; } @@ -177,7 +177,7 @@ class Socket_SocketHandler { */ public function write($data) { $result = socket_write($this->socket, $data); - if($result === FALSE) $this->error(); + if($result === FALSE) $this->handleSocketError(); } /** @@ -188,7 +188,7 @@ class Socket_SocketHandler { */ public function read($length = 16384) { $result = socket_read($this->socket, $length, PHP_BINARY_READ); - if($result === FALSE) $this->error(); + if($result === FALSE) $this->handleSocketError(); return $result; } @@ -201,11 +201,11 @@ class Socket_SocketHandler { usleep(100000); if($this->isConnected === TRUE) { $result = socket_shutdown($this->socket); - if($result === FALSE) $this->error(); + if($result === FALSE) $this->handleSocketError(); } if(is_resource($this->socket)) { $result = socket_close($this->socket); - if($result === FALSE) $this->error(); + if($result === FALSE) $this->handleSocketError(); } $this->isConnected = FALSE; } @@ -215,7 +215,7 @@ class Socket_SocketHandler { * @throws Exception_SocketException * @return void */ - protected function error() { + protected function handleSocketError() { if(is_resource($this->socket) === FALSE) throw new Exception_SocketException("No socket resource available!", 1290954177); $errno = socket_last_error($this->socket); $error = socket_strerror($errno); diff --git a/Main.php b/Main.php index 6ad8b5d..75462d4 100644 --- a/Main.php +++ b/Main.php @@ -3,7 +3,7 @@ error_reporting(E_ALL); require_once('AutoLoader.php'); try { - require_once('Testcode/Client/ClientManagerTest.php'); + require_once('Testcode' . DIRECTORY_SEPARATOR . 'Client' . DIRECTORY_SEPARATOR . 'ClientManagerTest.php'); } catch(Exception $e) { echo PHP_EOL.PHP_EOL."Caught Exception: " . $e . PHP_EOL; diff --git a/Testcode/Client/ClientManagerTest.php b/Testcode/Client/ClientManagerTest.php index c7fa199..c80bb64 100644 --- a/Testcode/Client/ClientManagerTest.php +++ b/Testcode/Client/ClientManagerTest.php @@ -3,16 +3,17 @@ $clientManager = new Client_ClientManager(); $clientManager->registerProtocol("irc", "Irc"); $clientManager->registerProtocol("jpt", "Bot"); -/*$freenode = $clientManager->createTcpConnection("freenode", "irc"); +$freenode = $clientManager->createTcpConnection("freenode", "irc"); $clientManager->attachConfig(array( - "nick" => "Testinstanz", - "userident" => "uzuguck", - "channels" => array("#mstasty") + "nick" => "Pb42|test", + "userident" => "lalala", + "channels" => array("##available") ), $freenode); $freenode->connect("irc.freenode.net", 6667); $freenode->setReconnect(TRUE); -*/ + +/* $euirc = $clientManager->createTcpConnection("euirc", "irc"); $clientManager->attachConfig(array( "nick" => "Pb42", @@ -21,7 +22,7 @@ $clientManager->attachConfig(array( ), $euirc); $euirc->connect("irc.euirc.net", 6667); $euirc->setReconnect(TRUE); - +*/ /*$osuIRC = $clientManager->createTcpConnection("osuIRC", "irc"); $clientManager->attachConfig(array( "nick" => "Pb42",