diff --git a/src/danog/MadelineProto/Connection.php b/src/danog/MadelineProto/Connection.php index 4e0c531b..db42bed5 100644 --- a/src/danog/MadelineProto/Connection.php +++ b/src/danog/MadelineProto/Connection.php @@ -40,6 +40,15 @@ class Connection extends \Volatile public $max_incoming_id; public $max_outgoing_id; + public $i = []; +/* public function __get($name) { + echo "GETTING $name\n"; + if (isset($this->i[$name]) && $this->{$name} === null) var_dump($this->i[$name]); + if ($this->{$name} instanceof \Volatile) $this->i[$name] = debug_backtrace(0); +var_dump(is_null($this->{$name})); + return $this->{$name}; + }*/ + public function ___construct($ip, $port, $protocol, $timeout, $ipv6) { diff --git a/src/danog/MadelineProto/DataCenter.php b/src/danog/MadelineProto/DataCenter.php index 43e5d08f..56d4aca4 100644 --- a/src/danog/MadelineProto/DataCenter.php +++ b/src/danog/MadelineProto/DataCenter.php @@ -24,7 +24,16 @@ class DataCenter extends \Volatile public $curdc = 0; public $dclist = []; public $settings = []; - +/* + public $i = []; + public function __get($name) { + echo "GETTING $name\n"; + if (isset($this->i[$name]) && $this->{$name} === null) var_dump($this->i[$name]); + if ($this->{$name} instanceof \Volatile) $this->i[$name] = debug_backtrace(0); +var_dump(is_null($this->{$name})); + return $this->{$name}; + } +*/ public function __sleep() { return ['sockets', 'curdc', 'dclist', 'settings']; diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index 827600f6..3e29e895 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -242,8 +242,8 @@ class MTProto extends \Volatile \danog\MadelineProto\Logger::log(["We're in ".$nearest_dc['country'].', current dc is '.$nearest_dc['this_dc'].', nearest dc is '.$nearest_dc['nearest_dc'].'.'], Logger::NOTICE); if ($nearest_dc['nearest_dc'] != $nearest_dc['this_dc']) { - $this->datacenter->curdc = $nearest_dc['nearest_dc']; - $this->settings['connection_settings']['default_dc'] = $nearest_dc['nearest_dc']; + $this->datacenter->curdc = (int) $nearest_dc['nearest_dc']; + $this->settings['connection_settings']['default_dc'] = (int)$nearest_dc['nearest_dc']; $this->should_serialize = true; } } catch (RPCErrorException $e) { @@ -706,6 +706,7 @@ class MTProto extends \Volatile $id .= $dc['media_only'] ? '_media' : ''; $ipv6 = ($dc['ipv6'] ? 'ipv6' : 'ipv4'); $id .= (isset($this->settings['connection'][$test][$ipv6][$id]) && $this->settings['connection'][$test][$ipv6][$id]['ip_address'] != $dc['ip_address']) ? '_bk' : ''; + if (is_numeric($id)) $id = (int)$id; $this->settings['connection'][$test][$ipv6][$id] = $dc; } $this->datacenter->__construct($this->settings['connection'], $this->settings['connection_settings']); diff --git a/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php b/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php index d2225df7..c407721d 100644 --- a/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php @@ -79,13 +79,7 @@ trait ResponseHandler $this->ack_incoming_message_id($current_msg_id, $datacenter); // Acknowledge that I received the server's response $this->ack_outgoing_message_id($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['req_msg_id'], $datacenter); // Acknowledge that the server received my request $this->datacenter->sockets[$datacenter]->outgoing_messages[$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['req_msg_id']]['response'] = $current_msg_id; - //švar_dump($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]); $this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content'] = $this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['result']; - //var_dump($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]); - ///var_dump($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]); - ///var_dump($this->datacenter->sockets[$datacenter]->incoming_messages[$this->datacenter->sockets[$datacenter]->outgoing_messages[$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['req_msg_id']]['response']]['content']); - ///$this->stop = true; - //var_dump(base64_encode($current_msg_id), $this->datacenter->sockets[$datacenter]->incoming_messages); $this->check_in_seq_no($datacenter, $current_msg_id); $only_updates = false; break; @@ -119,16 +113,12 @@ trait ResponseHandler case 'pong': $this->check_in_seq_no($datacenter, $current_msg_id); $only_updates = false; - foreach ($this->datacenter->sockets[$datacenter]->outgoing_messages as $msg_id => &$omessage) { - if (isset($omessage['content']['args']['ping_id']) && $omessage['content']['args']['ping_id'] === $this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['ping_id']) { - $this->ack_outgoing_message_id($msg_id, $datacenter); - $omessage['response'] = $this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['msg_id']; - $this->datacenter->sockets[$datacenter]->incoming_messages[$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['msg_id']]['content'] = $this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']; - unset($this->datacenter->sockets[$datacenter]->new_incoming[$current_msg_id]); - unset($this->datacenter->sockets[$datacenter]->new_outgoing[$msg_id]); - } - } + unset($this->datacenter->sockets[$datacenter]->new_incoming[$current_msg_id]); + unset($this->datacenter->sockets[$datacenter]->new_outgoing[$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['msg_id']]); + $this->ack_outgoing_message_id($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['msg_id'], $datacenter); // Acknowledge that the server received my request + $this->datacenter->sockets[$datacenter]->outgoing_messages[$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['msg_id']]['response'] = $current_msg_id; break; + case 'new_session_created': $this->check_in_seq_no($datacenter, $current_msg_id); $only_updates = false;