Minor bugfixes

This commit is contained in:
Daniil Gentili 2018-04-19 13:16:16 +02:00
parent d4ca6c7fa0
commit 0fbc6cbb13
3 changed files with 13 additions and 7 deletions

View File

@ -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()

View File

@ -121,7 +121,7 @@ If not, see <http://www.gnu.org/licenses/>.
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;
}

View File

@ -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']);