Applied fixes from StyleCI
This commit is contained in:
parent
7be648fb20
commit
3bba37ef1d
@ -35,23 +35,29 @@ class API extends APIFactory
|
||||
\danog\MadelineProto\Logger::log('MadelineProto is ready!');
|
||||
restore_error_handler();
|
||||
}
|
||||
public function APIFactory() {
|
||||
|
||||
public function APIFactory()
|
||||
{
|
||||
\danog\MadelineProto\Logger::log('Running APIFactory...');
|
||||
foreach ($this->API->tl->methods->method_namespace as $namespace => $method) {
|
||||
$this->{$method} = new APIFactory($method, $this->API);
|
||||
}
|
||||
}
|
||||
|
||||
public function logout() {
|
||||
public function logout()
|
||||
{
|
||||
$this->API->datacenter->authorized = false;
|
||||
$this->API->datacenter->authorization = null;
|
||||
if (!$this->API->method_call('auth.logOut')) {
|
||||
throw new Exception('An error occurred while logging out!');
|
||||
}
|
||||
\danog\MadelineProto\Logger::log('Logged out successfully!');
|
||||
|
||||
return true;
|
||||
}
|
||||
public function bot_login($token) {
|
||||
|
||||
public function bot_login($token)
|
||||
{
|
||||
if ($this->API->datacenter->authorized) {
|
||||
\danog\MadelineProto\Logger::log('This instance of MadelineProto is already logged in. Logging out first...');
|
||||
$this->logout();
|
||||
@ -67,9 +73,12 @@ class API extends APIFactory
|
||||
);
|
||||
$this->API->datacenter->authorized = true;
|
||||
\danog\MadelineProto\Logger::log('Logged in successfully!');
|
||||
|
||||
return $this->API->datacenter->authorization;
|
||||
}
|
||||
public function phone_login($number, $sms_type = 5) {
|
||||
|
||||
public function phone_login($number, $sms_type = 5)
|
||||
{
|
||||
if ($this->API->datacenter->authorized) {
|
||||
\danog\MadelineProto\Logger::log('This instance of MadelineProto is already logged in. Logging out first...');
|
||||
$this->logout();
|
||||
@ -88,9 +97,12 @@ class API extends APIFactory
|
||||
$this->API->datacenter->authorization['phone_number'] = $number;
|
||||
$this->API->datacenter->waiting_code = true;
|
||||
\danog\MadelineProto\Logger::log('Code sent successfully! Once you receive the code you should use the complete_phone_login function.');
|
||||
|
||||
return $this->API->datacenter->authorization;
|
||||
}
|
||||
public function complete_phone_login($code) {
|
||||
|
||||
public function complete_phone_login($code)
|
||||
{
|
||||
if (!$this->API->datacenter->waiting_code) {
|
||||
throw new Exception("I'm not waiting for the code! Please call the phone_login method first");
|
||||
}
|
||||
@ -106,9 +118,12 @@ class API extends APIFactory
|
||||
$this->API->datacenter->waiting_code = false;
|
||||
$this->API->datacenter->authorized = true;
|
||||
\danog\MadelineProto\Logger::log('Logged in successfully!');
|
||||
|
||||
return $this->API->datacenter->authorization;
|
||||
}
|
||||
public function __wakeup() {
|
||||
|
||||
public function __wakeup()
|
||||
{
|
||||
$this->APIFactory();
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ class APIFactory
|
||||
{
|
||||
set_error_handler(['\danog\MadelineProto\Exception', 'ExceptionErrorHandler']);
|
||||
$this->API->get_config();
|
||||
|
||||
return $this->API->method_call($this->namespace.$name, is_array($arguments[0]) ? $arguments[0] : []);
|
||||
restore_error_handler();
|
||||
}
|
||||
|
@ -111,9 +111,12 @@ class Connection extends Tools
|
||||
$this->__destruct();
|
||||
$this->__construct($this->ip, $this->port, $this->protocol, $this->timeout);
|
||||
}
|
||||
public function __wakeup() {
|
||||
|
||||
public function __wakeup()
|
||||
{
|
||||
$this->close_and_reopen();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get hex crc32.
|
||||
*
|
||||
|
@ -17,7 +17,6 @@ namespace danog\MadelineProto;
|
||||
*/
|
||||
class DataCenter extends Tools
|
||||
{
|
||||
|
||||
public $sockets;
|
||||
public $curdc = 0;
|
||||
public $dclist = [];
|
||||
@ -62,6 +61,7 @@ class DataCenter extends Tools
|
||||
\danog\MadelineProto\Logger::log('Connecting to DC '.$dc_number.' ('.$test.' server, '.$ipv6.')...');
|
||||
|
||||
$this->sockets[$dc_number] = new Connection($address, $port, $settings['protocol'], $settings['timeout']);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -69,6 +69,7 @@ class DataCenter extends Tools
|
||||
{
|
||||
return $this->sockets[$this->curdc]->{$name};
|
||||
}
|
||||
|
||||
public function __set($name, $value)
|
||||
{
|
||||
$this->sockets[$this->curdc]->{$name} = &$value;
|
||||
|
@ -28,7 +28,8 @@ class MTProto extends MTProtoTools
|
||||
$google = '';
|
||||
try {
|
||||
$google = file_get_contents('https://ipv6.google.com');
|
||||
} catch (Exception $e) { ; };
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
$this->ipv6 = strlen($google) > 0;
|
||||
|
||||
// Set default settings
|
||||
@ -58,17 +59,17 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
|
||||
'ip_address' => '149.154.167.40',
|
||||
'port' => 443,
|
||||
'media_only' => false,
|
||||
'tcpo_only' => false
|
||||
]
|
||||
'tcpo_only' => false,
|
||||
],
|
||||
],
|
||||
'ipv6' => [ // ipv6 addresses
|
||||
2 => [ // The rest will be fetched using help.getConfig
|
||||
'ip_address' => '2001:067c:04e8:f002:0000:0000:0000:000e',
|
||||
'port' => 443,
|
||||
'media_only' => false,
|
||||
'tcpo_only' => false
|
||||
]
|
||||
]
|
||||
'tcpo_only' => false,
|
||||
],
|
||||
],
|
||||
],
|
||||
'main' => [ // Main datacenters
|
||||
'ipv4' => [ // ipv4 addresses
|
||||
@ -76,17 +77,17 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
|
||||
'ip_address' => '149.154.167.51',
|
||||
'port' => 443,
|
||||
'media_only' => false,
|
||||
'tcpo_only' => false
|
||||
]
|
||||
'tcpo_only' => false,
|
||||
],
|
||||
],
|
||||
'ipv6' => [ // ipv6 addresses
|
||||
2 => [ // The rest will be fetched using help.getConfig
|
||||
'ip_address' => '2001:067c:04e8:f002:0000:0000:0000:000a',
|
||||
'port' => 443,
|
||||
'media_only' => false,
|
||||
'tcpo_only' => false
|
||||
]
|
||||
]
|
||||
'tcpo_only' => false,
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'connection_settings' => [ // connection settings
|
||||
@ -94,7 +95,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
|
||||
'protocol' => 'tcp_full', // can be tcp_full, tcp_abridged, tcp_intermediate, http (unsupported), https (unsupported), udp (unsupported)
|
||||
'test_mode' => false, // decides whether to connect to the main telegram servers or to the testing servers (deep telegram)
|
||||
'ipv6' => $this->ipv6, // decides whether to use ipv6, ipv6 attribute of API attribute of API class contains autodetected boolean
|
||||
'timeout' => 10 // timeout for sockets
|
||||
'timeout' => 10, // timeout for sockets
|
||||
],
|
||||
],
|
||||
'app_info' => [ // obtained in https://my.telegram.org
|
||||
@ -171,11 +172,15 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
|
||||
$this->switch_dc(2, true);
|
||||
$this->get_config();
|
||||
}
|
||||
public function __wakeup() {
|
||||
|
||||
public function __wakeup()
|
||||
{
|
||||
$this->setup_logger();
|
||||
$this->mk_datacenter();
|
||||
}
|
||||
public function mk_datacenter() {
|
||||
|
||||
public function mk_datacenter()
|
||||
{
|
||||
// Connect to servers
|
||||
\danog\MadelineProto\Logger::log('Istantiating DataCenter...');
|
||||
$this->datacenter = new DataCenter($this->settings['connection'], $this->settings['connection_settings']);
|
||||
@ -228,6 +233,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
|
||||
public function write_client_info($method, $arguments = [])
|
||||
{
|
||||
\danog\MadelineProto\Logger::log('Writing client info (also executing '.$method.')...');
|
||||
|
||||
return $this->method_call(
|
||||
'invokeWithLayer',
|
||||
[
|
||||
@ -241,7 +247,9 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
|
||||
]
|
||||
);
|
||||
}
|
||||
public function get_nearest_dc($allow_switch) {
|
||||
|
||||
public function get_nearest_dc($allow_switch)
|
||||
{
|
||||
$nearest_dc = $this->method_call('help.getNearestDc');
|
||||
\danog\MadelineProto\Logger::log("We're in ".$nearest_dc['country'].', current dc is '.$nearest_dc['this_dc'].', nearest dc is '.$nearest_dc['nearest_dc'].'.');
|
||||
|
||||
@ -251,7 +259,8 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
|
||||
}
|
||||
}
|
||||
|
||||
public function get_config() {
|
||||
public function get_config()
|
||||
{
|
||||
if ($this->config['expires'] > time()) {
|
||||
return;
|
||||
}
|
||||
@ -259,9 +268,10 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
|
||||
$this->parse_config();
|
||||
}
|
||||
|
||||
public function parse_config() {
|
||||
public function parse_config()
|
||||
{
|
||||
\danog\MadelineProto\Logger::log('Received config!', $this->config);
|
||||
foreach ($this->config["dc_options"] as $dc) {
|
||||
foreach ($this->config['dc_options'] as $dc) {
|
||||
$test = $this->config['test_mode'] ? 'test' : 'main';
|
||||
$ipv6 = ($dc['ipv6'] ? 'ipv6' : 'ipv4');
|
||||
$id = $dc['id'];
|
||||
|
@ -113,7 +113,7 @@ class AuthKeyHandler extends AckHandler
|
||||
'nonce' => $nonce,
|
||||
'server_nonce' => $server_nonce,
|
||||
'new_nonce' => $new_nonce,
|
||||
'expires_in' => $expires_in
|
||||
'expires_in' => $expires_in,
|
||||
];
|
||||
$p_q_inner_data = $this->tl->serialize_obj('p_q_inner_data'.(($expires_in < 0) ? '' : '_temp'), $data_unserialized);
|
||||
|
||||
|
@ -33,6 +33,7 @@ class ResponseHandler extends MsgIdHandler
|
||||
$this->ack_outgoing_message_id($response['req_msg_id']); // Acknowledge that the server received my request
|
||||
$this->datacenter->outgoing_messages[$response['req_msg_id']]['response'] = $last_received;
|
||||
$this->datacenter->incoming_messages[$last_received]['content'] = $response['result'];
|
||||
|
||||
return $this->handle_message($last_sent, $last_received);
|
||||
break;
|
||||
|
||||
@ -126,6 +127,7 @@ class ResponseHandler extends MsgIdHandler
|
||||
break;
|
||||
case 'gzip_packed':
|
||||
$this->datacenter->incoming_messages[$last_received]['content'] = $this->tl->deserialize($this->fopen_and_write('php://memory', 'rw+b', gzdecode($response['packed_data'])));
|
||||
|
||||
return $this->handle_message($last_sent, $last_received);
|
||||
break;
|
||||
case 'rpc_answer_dropped_running':
|
||||
|
@ -20,7 +20,7 @@ if (file_exists('number.php')) {
|
||||
|
||||
$checkedPhone = $MadelineProto->auth->checkPhone(// auth.checkPhone becomes auth->checkPhone
|
||||
[
|
||||
'phone_number' => $number
|
||||
'phone_number' => $number,
|
||||
]
|
||||
);
|
||||
var_dump($checkedPhone);
|
||||
|
Loading…
Reference in New Issue
Block a user