diff --git a/src/HttpProxy.php b/src/HttpProxy.php index 1c74d65a..8d30b97f 100644 --- a/src/HttpProxy.php +++ b/src/HttpProxy.php @@ -170,11 +170,11 @@ class HttpProxy implements \danog\MadelineProto\Proxy private function getProxyAuthHeader() { - if (!isset($this->extra['user']) || !isset($this->extra['password'])) { + if (!isset($this->extra['username']) || !isset($this->extra['password'])) { return ''; } - return 'Proxy-Authorization: Basic '.base64_encode($this->extra['user'].':'.$this->extra['password'])."\r\n"; + return 'Proxy-Authorization: Basic '.base64_encode($this->extra['username'].':'.$this->extra['password'])."\r\n"; } public function getProxyHeaders() diff --git a/src/Socket.php b/src/Socket.php index 7881d52a..2521c35e 100644 --- a/src/Socket.php +++ b/src/Socket.php @@ -121,7 +121,7 @@ If not, see . while (strlen($packet) < $length) { $read = stream_get_contents($this->sock, $length - strlen($packet)); if ($read === false || strlen($read) === 0) { - throw new \danog\MadelineProto\NothingInTheSocketException(); + throw new \danog\MadelineProto\NothingInTheSocketException('Nothing in the socket!'); } $packet .= $read; } @@ -285,8 +285,8 @@ if (!extension_loaded('pthreads')) { $packet = ''; while (strlen($packet) < $length) { $read = socket_read($this->sock, $length - strlen($packet), $flags); - if ($read === false || strlen($read) === false) { - throw new \danog\MadelineProto\NothingInTheSocketException(); + if ($read === false || strlen($read) === 0) { + throw new \danog\MadelineProto\NothingInTheSocketException('Nothing in the socket!'); } $packet .= $read; } diff --git a/src/danog/MadelineProto/Server/Handler.php b/src/danog/MadelineProto/Server/Handler.php index f1805646..3c4b92fc 100644 --- a/src/danog/MadelineProto/Server/Handler.php +++ b/src/danog/MadelineProto/Server/Handler.php @@ -101,6 +101,7 @@ class Handler extends \danog\MadelineProto\Connection $message = $this->read_message(); } } catch (\danog\MadelineProto\NothingInTheSocketException $e) { + echo $e; if (time() - $time < 2) { $this->sock = null; } @@ -135,6 +136,9 @@ class Handler extends \danog\MadelineProto\Connection if (count($method) === 0 || count($method) > 2) { throw new \danog\MadelineProto\Exception('Invalid method called'); } + + array_walk($args, [$this, 'walker']); + if ($method[0] === '__construct') { if (count($args) === 1 && is_array($args[0])) { $args[0]['logger'] = ['logger' => 4, 'logger_param' => [$this, 'logger']]; @@ -155,8 +159,6 @@ class Handler extends \danog\MadelineProto\Connection throw new \danog\MadelineProto\Exception('__construct was not called'); } - array_walk($args, [$this, 'walker']); - if (count($method) === 1) { return $this->madeline->{$method[0]}(...$args); } @@ -183,6 +185,10 @@ class Handler extends \danog\MadelineProto\Connection } elseif ($arg['_'] === 'stream' && isset($arg['stream_id'])) { $arg = fopen('madelineSocket://', 'r+b', false, Stream::getContext($this, $arg['stream_id'])); + return; + } elseif ($arg['_'] === 'bytes' && isset($arg['bytes'])) { + $arg = base64_decode($args['bytes']); + return; } else { array_walk($arg, [$this, 'walker']);