Merge branch 'master' of https://github.com/danog/MadelineProto
This commit is contained in:
commit
95ba5a33f0
@ -40,7 +40,7 @@ class MTProto extends MTProtoTools
|
|||||||
$device_model = php_uname('s');
|
$device_model = php_uname('s');
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Detect system version
|
// Detect system version
|
||||||
$system_version = phpversion();
|
$system_version = phpversion();
|
||||||
@ -48,7 +48,7 @@ class MTProto extends MTProtoTools
|
|||||||
$system_version = php_uname('r');
|
$system_version = php_uname('r');
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set default settings
|
// Set default settings
|
||||||
$default_settings = [
|
$default_settings = [
|
||||||
'authorization' => [ // Authorization settings
|
'authorization' => [ // Authorization settings
|
||||||
|
@ -22,8 +22,10 @@ class AckHandler extends \danog\MadelineProto\PrimeModule
|
|||||||
// The server acknowledges that it received my message
|
// The server acknowledges that it received my message
|
||||||
if (!isset($this->datacenter->outgoing_messages[$message_id])) {
|
if (!isset($this->datacenter->outgoing_messages[$message_id])) {
|
||||||
\danog\MadelineProto\Logger::log("Couldn't find message id ".$message_id.' in the array of outgoing messages. Maybe try to increase its size?');
|
\danog\MadelineProto\Logger::log("Couldn't find message id ".$message_id.' in the array of outgoing messages. Maybe try to increase its size?');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->datacenter->outgoing_messages[$message_id]['ack'] = true;
|
return $this->datacenter->outgoing_messages[$message_id]['ack'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,6 +40,7 @@ class AckHandler extends \danog\MadelineProto\PrimeModule
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->object_call('msgs_ack', ['msg_ids' => [$message_id]]);
|
$this->object_call('msgs_ack', ['msg_ids' => [$message_id]]);
|
||||||
|
|
||||||
return $this->datacenter->incoming_messages[$message_id]['ack'] = true;
|
return $this->datacenter->incoming_messages[$message_id]['ack'] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,9 @@ class ResponseHandler extends MsgIdHandler
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public function try_store_response($request, $response, $type, $force = true) {
|
|
||||||
|
public function try_store_response($request, $response, $type, $force = true)
|
||||||
|
{
|
||||||
if ($force) {
|
if ($force) {
|
||||||
return $this->datacenter->outgoing_messages[$request]['response'] = $response;
|
return $this->datacenter->outgoing_messages[$request]['response'] = $response;
|
||||||
}
|
}
|
||||||
|
@ -54,15 +54,19 @@ class TL extends \danog\MadelineProto\Tools
|
|||||||
return $arguments;
|
return $arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function serialize_bool($bool) {
|
public function serialize_bool($bool)
|
||||||
|
{
|
||||||
return \danog\PHP\Struct::pack('<i', $this->constructors->find_by_predicate('bool'.($bool ? 'True' : 'False'))['id']);
|
return \danog\PHP\Struct::pack('<i', $this->constructors->find_by_predicate('bool'.($bool ? 'True' : 'False'))['id']);
|
||||||
}
|
}
|
||||||
public function deserialize_bool($data) {
|
|
||||||
|
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);
|
$tl_elem = $this->constructors->find_by_id($id);
|
||||||
if ($tl_elem === false) {
|
if ($tl_elem === false) {
|
||||||
throw new Exception('Could not extract boolean');
|
throw new Exception('Could not extract boolean');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $tl_elem['predicate'] === 'boolTrue';
|
return $tl_elem['predicate'] === 'boolTrue';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +87,7 @@ class TL extends \danog\MadelineProto\Tools
|
|||||||
return \danog\PHP\Struct::pack('<I', $object);
|
return \danog\PHP\Struct::pack('<I', $object);
|
||||||
case 'long':
|
case 'long':
|
||||||
if (!is_numeric($object)) {
|
if (!is_numeric($object)) {
|
||||||
var_dump($object);
|
var_dump($object);
|
||||||
throw new Exception("given value isn't numeric");
|
throw new Exception("given value isn't numeric");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,6 +112,7 @@ var_dump($object);
|
|||||||
$concat .= $object;
|
$concat .= $object;
|
||||||
$concat .= pack('@'.$this->posmod(-$l, 4));
|
$concat .= pack('@'.$this->posmod(-$l, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $concat;
|
return $concat;
|
||||||
case 'Bool':
|
case 'Bool':
|
||||||
if (!is_bool($object)) {
|
if (!is_bool($object)) {
|
||||||
@ -125,6 +130,7 @@ var_dump($object);
|
|||||||
foreach ($object as $current_object) {
|
foreach ($object as $current_object) {
|
||||||
$concat .= $this->serialize_object(['type' => $type['subtype']], $current_object);
|
$concat .= $this->serialize_object(['type' => $type['subtype']], $current_object);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $concat;
|
return $concat;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -144,7 +150,7 @@ var_dump($object);
|
|||||||
throw new Exception('Could not extract type: '.$object);
|
throw new Exception('Could not extract type: '.$object);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($bare = ($type['type'] != '' && $type['type'][0] == "%")) {
|
if ($bare = ($type['type'] != '' && $type['type'][0] == '%')) {
|
||||||
$type['type'] = substr($type['type'], 1);
|
$type['type'] = substr($type['type'], 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,17 +162,20 @@ var_dump($object);
|
|||||||
if (!$bare) {
|
if (!$bare) {
|
||||||
$concat .= \danog\PHP\Struct::pack('<i', $constructorData['id']);
|
$concat .= \danog\PHP\Struct::pack('<i', $constructorData['id']);
|
||||||
}
|
}
|
||||||
return $concat.$this->serialize_params($constructorData, $object);
|
|
||||||
|
|
||||||
|
return $concat.$this->serialize_params($constructorData, $object);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function serialize_method($method, $arguments)
|
public function serialize_method($method, $arguments)
|
||||||
{
|
{
|
||||||
$tl = $this->methods->find_by_method($method);
|
$tl = $this->methods->find_by_method($method);
|
||||||
if ($tl === false) {
|
if ($tl === false) {
|
||||||
throw new Exception('Could not extract type: '.$method);
|
throw new Exception('Could not extract type: '.$method);
|
||||||
}
|
}
|
||||||
|
|
||||||
return \danog\PHP\Struct::pack('<i', $tl['id']).$this->serialize_params($tl, $arguments);
|
return \danog\PHP\Struct::pack('<i', $tl['id']).$this->serialize_params($tl, $arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function serialize_params($tl, $arguments)
|
public function serialize_params($tl, $arguments)
|
||||||
{
|
{
|
||||||
$serialized = '';
|
$serialized = '';
|
||||||
@ -267,6 +276,7 @@ var_dump($object);
|
|||||||
if (!is_string($x)) {
|
if (!is_string($x)) {
|
||||||
throw new Exception("deserialize: generated value isn't a string");
|
throw new Exception("deserialize: generated value isn't a string");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $x;
|
return $x;
|
||||||
case 'true':
|
case 'true':
|
||||||
return true;
|
return true;
|
||||||
@ -291,13 +301,14 @@ var_dump($object);
|
|||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$result[] = $this->deserialize($bytes_io, ['type' => $type['subtype']]);
|
$result[] = $this->deserialize($bytes_io, ['type' => $type['subtype']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
if ($type['type'] != '' && $type['type'][0] == '%') {
|
if ($type['type'] != '' && $type['type'][0] == '%') {
|
||||||
$checkType = substr($type['type'], 1);
|
$checkType = substr($type['type'], 1);
|
||||||
$constructorData = $this->constructors->find_by_type($checkType);
|
$constructorData = $this->constructors->find_by_type($checkType);
|
||||||
if ($constructorData === false) {
|
if ($constructorData === false) {
|
||||||
throw new Exception('Constructor not found for type: '. $checkType);
|
throw new Exception('Constructor not found for type: '.$checkType);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$constructorData = $this->constructors->find_by_predicate($type['type']);
|
$constructorData = $this->constructors->find_by_predicate($type['type']);
|
||||||
@ -337,6 +348,7 @@ var_dump($object);
|
|||||||
if (isset($x['flags'])) { // I don't think we need this anymore
|
if (isset($x['flags'])) { // I don't think we need this anymore
|
||||||
unset($x['flags']);
|
unset($x['flags']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $x;
|
return $x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user