Trying to fix serialization of flags...

This commit is contained in:
Daniil Gentili 2016-11-22 12:13:29 +00:00
parent 17f0de5e73
commit 0db89eaeb1
4 changed files with 26 additions and 12 deletions

View File

@ -177,7 +177,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
),
]
);
\danog\MadelineProto\Logger::log('Current dc is '.$nearest_dc['this_dc'].', nearest dc is '.$nearest_dc['nearest_dc'].' in '.$nearest_dc['country'].'.');
\danog\MadelineProto\Logger::log("We're in ".$nearest_dc['country'].', current dc is '.$nearest_dc['this_dc'].', nearest dc is '.$nearest_dc['nearest_dc'].'.');
if ($nearest_dc['nearest_dc'] != $nearest_dc['this_dc'] && $allow_switch) {
$this->switch_dc($nearest_dc['nearest_dc']);

View File

@ -78,18 +78,31 @@ class TL extends \danog\MadelineProto\Tools
}
$serialized = \danog\PHP\Struct::pack('<i', $tl_method['id']);
$flags = 0;
foreach ($tl_method['params'] as $cur_flag) {
if ($cur_flag['opt']) {
$flag_pow = pow(2, $cur_flag['pow']);
switch ($cur_flag['type']) {
case 'true':
case 'false':
$flags = (isset($arguments[$cur_flag['name']]) && $arguments[$cur_flag['name']]) ? ($flags | $flag_pow) : ($flags & ~$flag_pow);
unset($arguments[$cur_flag['name']]);
break;
case 'int':
case 'string':
$flags = (isset($arguments[$cur_flag['name']]) && $arguments[$cur_flag['name']] !== null) ? ($flags | $flag_pow) : ($flags & ~$flag_pow);
break;
default:
throw new Exception('Unrecognized flag type ('.$cur_flag['type'].')');
}
}
}
$arguments['flags'] = $flags;
foreach ($tl_method['params'] as $current_argument) {
if (!isset($arguments[$current_argument['name']])) {
if ($current_argument['name'] == 'flags') {
$arguments['flags'] = 0;
} else {
if ($current_argument['opt']) {
continue;
}
if ($current_argument['opt']) continue;
throw new Exception('Missing required parameter ('.$current_argument['name'].')');
}
}
$serialized .= $this->serialize_param($current_argument['type'], $current_argument['subtype'], $arguments[$current_argument['name']]);
}
@ -245,6 +258,7 @@ class TL extends \danog\MadelineProto\Tools
$x = $this->deserialize($bytes_io, $tl_elem['predicate'], $subtype);
} else {
$x = ['_' => $tl_elem['predicate']];
$done_opt = false;
foreach ($tl_elem['params'] as $arg) {
$x[$arg['name']] = $this->deserialize($bytes_io, $arg['type'], $arg['subtype']);
}

View File

@ -31,7 +31,7 @@ class TLConstructor
$param['subtype'] = null;
if (preg_match('/^flags\.\d\?/', $param['type'])) {
$param['opt'] = true;
$param['flag'] = preg_replace(['/^flags\./', '/\?.*/'], '', $param['type']);
$param['pow'] = preg_replace(['/^flags\./', '/\?.*/'], '', $param['type']);
$param['type'] = preg_replace('/^flags\.\d\?/', '', $param['type']);
}
if (preg_match('/vector<.*>/i', $param['type'])) {

View File

@ -37,7 +37,7 @@ class TLMethod
$param['subtype'] = null;
if (preg_match('/^flags\.\d\?/', $param['type'])) {
$param['opt'] = true;
$param['flag'] = preg_replace(['/^flags\./', '/\?.*/'], '', $param['type']);
$param['pow'] = preg_replace(['/^flags\./', '/\?.*/'], '', $param['type']);
$param['type'] = preg_replace('/^flags\.\d\?/', '', $param['type']);
}
if (preg_match('/vector<.*>/i', $param['type'])) {