Fixed bugs

This commit is contained in:
danogentili 2016-11-17 20:43:52 +03:00
parent b18c16aedc
commit 82dc195483
6 changed files with 24 additions and 24 deletions

View File

@ -141,8 +141,8 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
\danog\MadelineProto\Logger::log('Switching to DC '.$new_dc.'...'); \danog\MadelineProto\Logger::log('Switching to DC '.$new_dc.'...');
if ($this->datacenter->dc_connect($new_dc)) { if ($this->datacenter->dc_connect($new_dc)) {
$this->init_authorization(); $this->init_authorization();
$this->write_client_info(); $this->write_client_info($allow_nearest_dc_switch);
$this->bind_temp_auth_key($this->settings['authorization']['default_temp_auth_key_expires_in'], $allow_nearest_dc_switch); $this->bind_temp_auth_key($this->settings['authorization']['default_temp_auth_key_expires_in']);
} }
} }
@ -172,7 +172,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
'query' => $this->tl->serialize_method('initConnection', 'query' => $this->tl->serialize_method('initConnection',
array_merge( array_merge(
$this->settings['app_info'], $this->settings['app_info'],
['query' => $this->tl->serialize_method('help.getnearest_dc', [])] ['query' => $this->tl->serialize_method('help.getNearestDc', [])]
) )
), ),
] ]

View File

@ -20,8 +20,8 @@ class SeqNoHandler extends SaltHandler
public function generate_seq_no($content_related = true) public function generate_seq_no($content_related = true)
{ {
$in = $content_related ? 1 : 0; $in = $content_related ? 1 : 0;
$value = $this->seq_no; $value = $this->datacenter->seq_no;
$this->seq_no += $in; $this->datacenter->seq_no += $in;
return ($value * 2) + $in; return ($value * 2) + $in;
} }

View File

@ -80,7 +80,7 @@ class PrimeModule extends Tools
{ {
$pqstr = (string) $pq; $pqstr = (string) $pq;
\danog\MadelineProto\Logging::log('Trying to use the python factorization module'); \danog\MadelineProto\Logger::log('Trying to use the python factorization module');
if (function_exists('shell_exec')) { if (function_exists('shell_exec')) {
try { try {
$res = json_decode(shell_exec('python '.__DIR__.'/getpq.py '.$pqstr)); $res = json_decode(shell_exec('python '.__DIR__.'/getpq.py '.$pqstr));
@ -91,7 +91,7 @@ class PrimeModule extends Tools
} }
} }
\danog\MadelineProto\Logging::log('Trying to use the wolfram alpha factorization module'); \danog\MadelineProto\Logger::log('Trying to use the wolfram alpha factorization module');
$query = 'Do prime factorization of '.$pqstr; $query = 'Do prime factorization of '.$pqstr;
$params = [ $params = [
'async' => true, 'async' => true,
@ -120,7 +120,7 @@ class PrimeModule extends Tools
return $res; return $res;
} }
\danog\MadelineProto\Logging::log('Trying to use the native factorization module'); \danog\MadelineProto\Logger::log('Trying to use the native factorization module');
$res = $this->find_small_multiplier_lopatin((int) $pqstr); $res = $this->find_small_multiplier_lopatin((int) $pqstr);
$res = [$res, $pqstr / $res]; $res = [$res, $pqstr / $res];
if ($res[1] != 1) { if ($res[1] != 1) {

View File

@ -39,7 +39,7 @@ class TL extends \danog\MadelineProto\Tools
public function get_named_method_args($method, $arguments) public function get_named_method_args($method, $arguments)
{ {
$tl_method = $this->methods->find_by_method($method); $tl_method = $this->methods->find_by_method($method);
if ($tl_method == false) { if ($tl_method === false) {
throw new Exception('Could not extract type: '.$method); throw new Exception('Could not extract type: '.$method);
} }
@ -57,8 +57,8 @@ class TL extends \danog\MadelineProto\Tools
public function serialize_obj($object, $arguments) public function serialize_obj($object, $arguments)
{ {
$tl_constructor = $this->constructors->find_by_type($object); $tl_constructor = $this->constructors->find_by_predicate($object);
if ($tl_constructor == false) { if ($tl_constructor === false) {
throw new Exception('Could not extract type: '.$object); throw new Exception('Could not extract type: '.$object);
} }
@ -74,7 +74,7 @@ class TL extends \danog\MadelineProto\Tools
public function serialize_method($method, $arguments) public function serialize_method($method, $arguments)
{ {
$tl_method = $this->methods->find_by_method($method); $tl_method = $this->methods->find_by_method($method);
if ($tl_method == false) { if ($tl_method === false) {
throw new Exception('Could not extract type: '.$method); throw new Exception('Could not extract type: '.$method);
} }
@ -148,7 +148,7 @@ class TL extends \danog\MadelineProto\Tools
case '!X': case '!X':
return $value; return $value;
case 'Vector t': case 'Vector t':
$concat = \danog\PHP\Struct::pack('<i', $this->constructors->find_by_type('vector')['id']); $concat = \danog\PHP\Struct::pack('<i', $this->constructors->find_by_predicate('vector')['id']);
$concat .= \danog\PHP\Struct::pack('<l', count($value)); $concat .= \danog\PHP\Struct::pack('<l', count($value));
foreach ($value as $curv) { foreach ($value as $curv) {
@ -226,16 +226,16 @@ class TL extends \danog\MadelineProto\Tools
} }
$count = \danog\PHP\Struct::unpack('<l', fread($bytes_io, 4)) [0]; $count = \danog\PHP\Struct::unpack('<l', fread($bytes_io, 4)) [0];
$x = []; $x = [];
foreach ($this->range($count) as $i) { for ($i = 0; $i < $count; $i++) {
$x[] = $this->deserialize($bytes_io, $subtype); $x[] = $this->deserialize($bytes_io, $subtype);
} }
break; break;
default: default:
$tl_elem = $this->constructors->find_by_type($type); $tl_elem = $this->constructors->find_by_predicate($type);
if ($tl_elem == false) { if ($tl_elem === false) {
$id = \danog\PHP\Struct::unpack('<i', fread($bytes_io, 4)) [0]; $id = \danog\PHP\Struct::unpack('<i', fread($bytes_io, 4)) [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 type: '.$type.' with id '.$id); throw new Exception('Could not extract type: '.$type.' with id '.$id);
} }
} }

View File

@ -44,18 +44,19 @@ class TLConstructor
$param['type'] = 'Vector t'; $param['type'] = 'Vector t';
} }
if (preg_match('/^\%/', $param['subtype'])) { if (preg_match('/^\%/', $param['subtype'])) {
$param['subtype'] = lcfirst(preg_replace('/^\%/', '', $param['subtype'])); $param['subtype'] = preg_replace('/^\%/', '', $param['subtype']);
} }
//lcfirst
} }
} }
$this->key++; $this->key++;
} }
public function find_by_type($type) public function find_by_predicate($predicate)
{ {
$key = array_search($type, $this->type); $key = array_search($predicate, $this->predicate);
return ($key == false) ? false : [ return ($key === false) ? false : [
'id' => $this->id[$key], 'id' => $this->id[$key],
'predicate' => $this->predicate[$key], 'predicate' => $this->predicate[$key],
'type' => $this->type[$key], 'type' => $this->type[$key],
@ -67,7 +68,7 @@ class TLConstructor
{ {
$key = array_search($id, $this->id); $key = array_search($id, $this->id);
return ($key == false) ? false : [ return ($key === false) ? false : [
'id' => $this->id[$key], 'id' => $this->id[$key],
'predicate' => $this->predicate[$key], 'predicate' => $this->predicate[$key],
'type' => $this->type[$key], 'type' => $this->type[$key],

View File

@ -57,8 +57,7 @@ class TLMethod
public function find_by_method($method) public function find_by_method($method)
{ {
$key = array_search($method, $this->method); $key = array_search($method, $this->method);
return ($key === false) ? false : [
return ($key == false) ? false : [
'id' => $this->id[$key], 'id' => $this->id[$key],
'method' => $this->method[$key], 'method' => $this->method[$key],
'type' => $this->type[$key], 'type' => $this->type[$key],