From 79618223b7bab5f1e9d8e570d0367a22fd45c1dd Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sun, 25 Feb 2018 16:17:28 +0000 Subject: [PATCH] Improve peer management and phar creation, implement secondary auto-update mechanism --- makephar.php | 16 +++++++++++++++- .../MTProtoTools/MessageHandler.php | 8 ++------ .../MadelineProto/MTProtoTools/PeerHandler.php | 4 +++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/makephar.php b/makephar.php index cbaf0d9f..88ad3ee0 100755 --- a/makephar.php +++ b/makephar.php @@ -20,6 +20,20 @@ if (!isset($argv[3])) { $p = new Phar(__DIR__.'/'.$argv[2], 0, $argv[2]); $p->buildFromDirectory(realpath($argv[1]), '/^((?!tests).)*(\.php|\.py|\.tl|\.json)$/i'); +$p->addFromString('vendor/danog/madelineproto/.git/refs/heads/master', $argv[3]); $p->addFromString('.git/refs/heads/master', $argv[3]); -$p->setStub(''); +$p->setStub('getContent() !== file_get_contents("https://phar.madelineproto.xyz/release?v=new") && !isset($phar_debug)) { + file_put_contents(__FILE__, file_get_contents("https://phar.madelineproto.xyz/madeline.phar?v=new")); +} +Phar::interceptFileFuncs(); +Phar::mapPhar("'.$argv[2].'"); +require_once "phar://'.$argv[2].'/vendor/autoload.php"; + +__HALT_COMPILER(); ?>'); diff --git a/src/danog/MadelineProto/MTProtoTools/MessageHandler.php b/src/danog/MadelineProto/MTProtoTools/MessageHandler.php index 7d3b4959..94782523 100644 --- a/src/danog/MadelineProto/MTProtoTools/MessageHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/MessageHandler.php @@ -71,12 +71,8 @@ trait MessageHandler public function recv_message($datacenter) { if ($this->datacenter->sockets[$datacenter]->must_open) { - \danog\MadelineProto\Logger::log(['Trying to write in closed socket, sending initial ping/http_wait']); - if ($this->is_http($datacenter)) { - $this->method_call('http_wait', ['max_wait' => 500, 'wait_after' => 150, 'max_delay' => 500], ['datacenter' => $datacenter]); - } else { - $this->method_call('ping', ['ping_id' => 0], ['datacenter' => $datacenter]); - } + \danog\MadelineProto\Logger::log(['Trying to read from closed socket, sending initial ping']); + $this->method_call('ping', ['ping_id' => 0], ['datacenter' => $datacenter]); } $payload = $this->datacenter->sockets[$datacenter]->read_message(); if (strlen($payload) === 4) { diff --git a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php index d2620b58..05822b06 100644 --- a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php @@ -208,7 +208,9 @@ trait PeerHandler if (!isset($this->settings['pwr']['requests']) || $this->settings['pwr']['requests'] === true) { $dbres = json_decode(@file_get_contents('https://id.pwrtelegram.xyz/db/getusername?id='.$id, false, stream_context_create(['http' => ['timeout' => 2]])), true); if (isset($dbres['ok']) && $dbres['ok']) { - return $this->get_info('@'.$dbres['result']); + $this->resolve_username('@'.$dbres['result']); + + return $this->get_info($id, false); } }