diff --git a/src/danog/MadelineProto/API.php b/src/danog/MadelineProto/API.php index 5881f7999..ba9f52149 100644 --- a/src/danog/MadelineProto/API.php +++ b/src/danog/MadelineProto/API.php @@ -23,10 +23,8 @@ class API extends Tools $this->API = new MTProto($params); \danog\MadelineProto\Logger::log('Running APIFactory...'); - foreach ($this->API->tl->methods->method_namespaced as $method) { - if (isset($method[1]) && !isset($this->{$method[0]})) { - $this->{$method[0]} = new APIFactory($method[0], $this->API); - } + foreach ($this->API->tl->methods->method_namespace as $namespace => $method) { + $this->{$method} = new APIFactory($method, $this->API); } \danog\MadelineProto\Logger::log('Ping...'); diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index ec52cff6a..9a015568c 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -74,8 +74,8 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB 'tl_schema' => [ 'layer' => 55, 'src' => [ - __DIR__.'/TL_mtproto_v1.json', - __DIR__.'/TL_telegram_v55.json', + 'mtproto' => __DIR__.'/TL_mtproto_v1.json', + 'telegram' => __DIR__.'/TL_telegram_v55.json', ], ], 'logger' => [ diff --git a/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php b/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php index 8ae6cda33..96cda65c4 100644 --- a/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php @@ -494,7 +494,6 @@ class AuthKeyHandler extends AckHandler ] ); $int_message_id = $this->generate_message_id(); - $this->check_message_id($int_message_id, true); $message_id = \danog\PHP\Struct::pack('generate_message_id(); } - $this->check_message_id($int_message_id, true); + if (!is_int($int_message_id)) { + throw new Exception("Specified message id isn't an integer"); + } $message_id = \danog\PHP\Struct::pack('datacenter->temp_auth_key['auth_key'] == null || $this->datacenter->temp_auth_key['server_salt'] == null) { diff --git a/src/danog/MadelineProto/MTProtoTools/MsgIdHandler.php b/src/danog/MadelineProto/MTProtoTools/MsgIdHandler.php index cc1e0f142..38b8ce110 100644 --- a/src/danog/MadelineProto/MTProtoTools/MsgIdHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/MsgIdHandler.php @@ -81,7 +81,7 @@ class MsgIdHandler extends MessageHandler if ($int_message_id <= $keys) { $int_message_id = $keys + 4; } - + $this->check_message_id($int_message_id, true); return $int_message_id; } } diff --git a/src/danog/MadelineProto/TL/TL.php b/src/danog/MadelineProto/TL/TL.php index 81750250d..4cd6ca03d 100644 --- a/src/danog/MadelineProto/TL/TL.php +++ b/src/danog/MadelineProto/TL/TL.php @@ -17,22 +17,21 @@ class TL extends \danog\MadelineProto\Tools public function __construct($filename) { \danog\MadelineProto\Logger::log('Loading TL schemes...'); - $TL_dict = ['constructors' => [], 'methods' => []]; - foreach ($filename as $file) { - $TL_dict['constructors'] = array_merge(json_decode(file_get_contents($file), true)['constructors'], $TL_dict['constructors']); - $TL_dict['methods'] = array_merge(json_decode(file_get_contents($file), true)['methods'], $TL_dict['methods']); - } - - \danog\MadelineProto\Logger::log('Translating objects...'); $this->constructors = new \danog\MadelineProto\TL\TLConstructor(); - foreach ($TL_dict['constructors'] as $elem) { - $this->constructors->add($elem); - } - - \danog\MadelineProto\Logger::log('Translating methods...'); $this->methods = new \danog\MadelineProto\TL\TLMethod(); - foreach ($TL_dict['methods'] as $elem) { - $this->methods->add($elem); + foreach ($filename as $type => $file) { + $type = $type === "mtproto"; + $TL_dict = json_decode(file_get_contents($file), true); + + \danog\MadelineProto\Logger::log('Translating objects...'); + foreach ($TL_dict['constructors'] as $elem) { + $this->constructors->add($elem, $type); + } + + \danog\MadelineProto\Logger::log('Translating methods...'); + foreach ($TL_dict['methods'] as $elem) { + $this->methods->add($elem); + } } } diff --git a/src/danog/MadelineProto/TL/TLConstructor.php b/src/danog/MadelineProto/TL/TLConstructor.php index 93c54b4de..9fbdbe563 100644 --- a/src/danog/MadelineProto/TL/TLConstructor.php +++ b/src/danog/MadelineProto/TL/TLConstructor.php @@ -20,10 +20,10 @@ class TLConstructor public $params = []; public $key = 0; - public function add($json_dict) + public function add($json_dict, $mtproto) { $this->id[$this->key] = (int) $json_dict['id']; - $this->predicate[$this->key] = $json_dict['predicate']; + $this->predicate[$this->key] = (($mtproto && $json_dict['predicate'] == "message") ? "MT" : "").$json_dict['predicate']; $this->type[$this->key] = $json_dict['type']; $this->params[$this->key] = $json_dict['params']; foreach ($this->params[$this->key] as &$param) { @@ -44,9 +44,9 @@ class TLConstructor $param['type'] = 'Vector t'; } if (preg_match('/^\%/', $param['subtype'])) { - $param['subtype'] = preg_replace('/^\%/', '', $param['subtype']); + $param['subtype'] = lcfirst(preg_replace('/^\%/', '', $param['subtype'])); } -//lcfirst + $param['subtype'] = (($mtproto && $param['subtype'] == "message") ? "MT" : "").$param['subtype']; } } $this->key++; @@ -55,7 +55,6 @@ class TLConstructor public function find_by_predicate($predicate) { $key = array_search($predicate, $this->predicate); - return ($key === false) ? false : [ 'id' => $this->id[$key], 'predicate' => $this->predicate[$key], diff --git a/src/danog/MadelineProto/TL/TLMethod.php b/src/danog/MadelineProto/TL/TLMethod.php index b0b59bdd3..8a05c71b0 100644 --- a/src/danog/MadelineProto/TL/TLMethod.php +++ b/src/danog/MadelineProto/TL/TLMethod.php @@ -18,7 +18,7 @@ class TLMethod public $method = []; public $type = []; public $params = []; - public $method_namespaced = []; + public $method_namespace = []; public $key = 0; public function add($json_dict) @@ -27,7 +27,10 @@ class TLMethod $this->method[$this->key] = $json_dict['method']; $this->type[$this->key] = $json_dict['type']; $this->params[$this->key] = $json_dict['params']; - $this->method_namespaced[$this->key] = explode('.', $json_dict['method']); + $namespace = explode('.', $json_dict['method']); + if (isset($namespace[1])) { + $this->method_namespace[$namespace[0]] = $namespace[0]; + } foreach ($this->params[$this->key] as &$param) { $param['opt'] = false; @@ -63,7 +66,6 @@ class TLMethod 'method' => $this->method[$key], 'type' => $this->type[$key], 'params' => $this->params[$key], - 'method_namespaced' => $this->method_namespaced[$key], ]; } }