Merge branch 'master' of https://github.com/danog/MadelineProto
This commit is contained in:
commit
fa1183b25e
@ -6,7 +6,7 @@ Created by [Daniil Gentili](https://daniil.it), licensed under AGPLv3.
|
||||
|
||||
PHP implementation of MTProto, based on [telepy](https://github.com/griganton/telepy_old).
|
||||
|
||||
This project can run on PHP 7, PHP 5.6 and HHVM.
|
||||
This project can run on PHP 7, PHP 5.6 and HHVM, only 64 bit systems are supported ATM.
|
||||
|
||||
Also note that MadelineProto will perform better if a big math extension like gmp o bcmath is installed.
|
||||
|
||||
|
@ -32,7 +32,6 @@ class API extends APIFactory
|
||||
\danog\MadelineProto\Logger::log('Getting future salts...');
|
||||
$this->future_salts = $this->get_future_salts([3]);
|
||||
|
||||
|
||||
\danog\MadelineProto\Logger::log('MadelineProto is ready!');
|
||||
restore_error_handler();
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ class Connection extends Tools
|
||||
public $authorization = null;
|
||||
public $waiting_code = false;
|
||||
|
||||
|
||||
public $incoming_messages = [];
|
||||
public $outgoing_messages = [];
|
||||
public $new_incoming = [];
|
||||
|
@ -49,6 +49,11 @@ class MTProto extends PrimeModule
|
||||
|
||||
public function __construct($settings = [])
|
||||
{
|
||||
// Detect 64 bit
|
||||
if (PHP_INT_SIZE < 8) {
|
||||
throw new Exception('MadelineProto supports only 64 bit systems ATM');
|
||||
}
|
||||
|
||||
// Detect ipv6
|
||||
$google = '';
|
||||
try {
|
||||
@ -57,7 +62,6 @@ class MTProto extends PrimeModule
|
||||
}
|
||||
$this->ipv6 = strlen($google) > 0;
|
||||
|
||||
|
||||
// Detect device model
|
||||
$device_model = 'Web server';
|
||||
try {
|
||||
@ -65,7 +69,6 @@ class MTProto extends PrimeModule
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
|
||||
// Detect system version
|
||||
$system_version = phpversion();
|
||||
try {
|
||||
|
@ -243,7 +243,6 @@ trait AuthKeyHandler
|
||||
|
||||
\danog\MadelineProto\Logger::log(sprintf('Server-client time delta = %.1f s', $this->datacenter->time_delta));
|
||||
|
||||
|
||||
/*
|
||||
* ***********************************************************************
|
||||
* Define some needed numbers for BigInteger
|
||||
@ -264,7 +263,6 @@ trait AuthKeyHandler
|
||||
throw new \danog\MadelineProto\Exception("dh_prime isn't a safe 2048-bit prime (dh_prime isn't a prime).");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ***********************************************************************
|
||||
* Check validity of dh_prime
|
||||
@ -407,7 +405,6 @@ trait AuthKeyHandler
|
||||
$new_nonce_hash2 = substr(sha1($new_nonce.chr(2).$auth_key_aux_hash, true), -16);
|
||||
$new_nonce_hash3 = substr(sha1($new_nonce.chr(3).$auth_key_aux_hash, true), -16);
|
||||
|
||||
|
||||
/*
|
||||
* ***********************************************************************
|
||||
* Check if the client's nonce and the server's nonce are the same
|
||||
|
@ -51,7 +51,6 @@ trait CallHandler
|
||||
\danog\MadelineProto\Logger::log('Received request to switch to DC '.$dc);
|
||||
$this->switch_dc($dc);
|
||||
throw new \danog\MadelineProto\Exception('I had to switch to datacenter '.$dc);
|
||||
|
||||
break;
|
||||
case 401:
|
||||
switch ($server_answer['error_message']) {
|
||||
|
@ -93,10 +93,10 @@ trait MessageHandler
|
||||
$message_id = \danog\PHP\Struct::unpack('<Q', substr($decrypted_data, 16, 8))[0];
|
||||
$this->check_message_id($message_id, false);
|
||||
|
||||
$seq_no = \danog\PHP\Struct::unpack('<I', substr($decrypted_data, 24, 4)) [0];
|
||||
$seq_no = \danog\PHP\Struct::unpack('<I', substr($decrypted_data, 24, 4))[0];
|
||||
// Dunno how to handle any incorrect sequence numbers
|
||||
|
||||
$message_data_length = \danog\PHP\Struct::unpack('<I', substr($decrypted_data, 28, 4)) [0];
|
||||
$message_data_length = \danog\PHP\Struct::unpack('<I', substr($decrypted_data, 28, 4))[0];
|
||||
|
||||
if ($message_data_length > strlen($decrypted_data)) {
|
||||
throw new \danog\MadelineProto\Exception('message_data_length is too big');
|
||||
|
@ -127,7 +127,6 @@ class PrimeModule extends Tools
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
throw new Exception("Couldn't calculate pq!");
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ class TL extends \danog\MadelineProto\Tools
|
||||
|
||||
public function deserialize_bool($data)
|
||||
{
|
||||
$id = \danog\PHP\Struct::unpack('<i', $data) [0];
|
||||
$id = \danog\PHP\Struct::unpack('<i', $data)[0];
|
||||
$tl_elem = $this->constructors->find_by_id($id);
|
||||
if ($tl_elem === false) {
|
||||
throw new Exception('Could not extract boolean');
|
||||
@ -240,13 +240,13 @@ class TL extends \danog\MadelineProto\Tools
|
||||
case 'Bool':
|
||||
return $this->deserialize_bool(fread($bytes_io, 4));
|
||||
case 'int':
|
||||
return \danog\PHP\Struct::unpack('<i', fread($bytes_io, 4)) [0];
|
||||
return \danog\PHP\Struct::unpack('<i', fread($bytes_io, 4))[0];
|
||||
case '#':
|
||||
return \danog\PHP\Struct::unpack('<I', fread($bytes_io, 4)) [0];
|
||||
return \danog\PHP\Struct::unpack('<I', fread($bytes_io, 4))[0];
|
||||
case 'long':
|
||||
return \danog\PHP\Struct::unpack('<q', fread($bytes_io, 8)) [0];
|
||||
return \danog\PHP\Struct::unpack('<q', fread($bytes_io, 8))[0];
|
||||
case 'double':
|
||||
return \danog\PHP\Struct::unpack('<d', fread($bytes_io, 8)) [0];
|
||||
return \danog\PHP\Struct::unpack('<d', fread($bytes_io, 8))[0];
|
||||
case 'int128':
|
||||
return fread($bytes_io, 16);
|
||||
case 'int256':
|
||||
@ -255,12 +255,12 @@ class TL extends \danog\MadelineProto\Tools
|
||||
return fread($bytes_io, 32);
|
||||
case 'string':
|
||||
case 'bytes':
|
||||
$l = \danog\PHP\Struct::unpack('<B', fread($bytes_io, 1)) [0];
|
||||
$l = \danog\PHP\Struct::unpack('<B', fread($bytes_io, 1))[0];
|
||||
if ($l > 254) {
|
||||
throw new Exception('Length is too big');
|
||||
}
|
||||
if ($l == 254) {
|
||||
$long_len = \danog\PHP\Struct::unpack('<I', fread($bytes_io, 3).$this->string2bin('\x00')) [0];
|
||||
$long_len = \danog\PHP\Struct::unpack('<I', fread($bytes_io, 3).$this->string2bin('\x00'))[0];
|
||||
$x = fread($bytes_io, $long_len);
|
||||
$resto = $this->posmod(-$long_len, 4);
|
||||
if ($resto > 0) {
|
||||
@ -281,7 +281,7 @@ class TL extends \danog\MadelineProto\Tools
|
||||
case 'true':
|
||||
return true;
|
||||
case 'Vector t':
|
||||
$id = \danog\PHP\Struct::unpack('<i', fread($bytes_io, 4)) [0];
|
||||
$id = \danog\PHP\Struct::unpack('<i', fread($bytes_io, 4))[0];
|
||||
$constructorData = $this->constructors->find_by_id($id);
|
||||
if ($constructorData === false) {
|
||||
throw new Exception('Could not extract type: '.$type['type'].' with id '.$id);
|
||||
@ -296,7 +296,7 @@ class TL extends \danog\MadelineProto\Tools
|
||||
throw new Exception('Invalid vector constructor: '.$constructorData['predicate']);
|
||||
}
|
||||
case 'vector':
|
||||
$count = \danog\PHP\Struct::unpack('<i', fread($bytes_io, 4)) [0];
|
||||
$count = \danog\PHP\Struct::unpack('<i', fread($bytes_io, 4))[0];
|
||||
$result = [];
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$result[] = $this->deserialize($bytes_io, ['type' => $type['subtype']]);
|
||||
@ -313,7 +313,7 @@ class TL extends \danog\MadelineProto\Tools
|
||||
} else {
|
||||
$constructorData = $this->constructors->find_by_predicate($type['type']);
|
||||
if ($constructorData === false) {
|
||||
$id = \danog\PHP\Struct::unpack('<i', fread($bytes_io, 4)) [0];
|
||||
$id = \danog\PHP\Struct::unpack('<i', fread($bytes_io, 4))[0];
|
||||
$constructorData = $this->constructors->find_by_id($id);
|
||||
if ($constructorData === false) {
|
||||
throw new Exception('Could not extract type: '.$type['type'].' with id '.$id);
|
||||
|
@ -13,7 +13,6 @@ If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
|
||||
if (file_exists('number.php') && !file_exists('session.madeline')) {
|
||||
include_once 'number.php';
|
||||
$MadelineProto = new \danog\MadelineProto\API();
|
||||
|
Loading…
Reference in New Issue
Block a user