Bugfixes to combined API, perfomance improvements, additional internal processing for config/user updates
This commit is contained in:
parent
0820d61545
commit
94f20292c3
2
docs
2
docs
@ -1 +1 @@
|
|||||||
Subproject commit 4462f6f0c4391a3a1c6ce4f2b5cb02081a635a88
|
Subproject commit 1c204d1dbdaea25559ac9a89d51c8850e005b772
|
@ -9,7 +9,7 @@ MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY
|
|||||||
See the GNU Affero General Public License for more details.
|
See the GNU Affero General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License along with MadelineProto.
|
You should have received a copy of the GNU General Public License along with MadelineProto.
|
||||||
If not, see <http://www.gnu.org/licenses/>.
|
If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace danog\MadelineProto;
|
namespace danog\MadelineProto;
|
||||||
|
|
||||||
@ -32,6 +32,10 @@ class CombinedAPI
|
|||||||
|
|
||||||
\danog\MadelineProto\Magic::class_exists();
|
\danog\MadelineProto\Magic::class_exists();
|
||||||
|
|
||||||
|
foreach ($paths as $path => $settings) {
|
||||||
|
$this->addInstance($path, $settings);
|
||||||
|
}
|
||||||
|
|
||||||
if (file_exists($realpaths['file'])) {
|
if (file_exists($realpaths['file'])) {
|
||||||
if (!file_exists($realpaths['lockfile'])) {
|
if (!file_exists($realpaths['lockfile'])) {
|
||||||
touch($realpaths['lockfile']);
|
touch($realpaths['lockfile']);
|
||||||
@ -50,21 +54,26 @@ class CombinedAPI
|
|||||||
}
|
}
|
||||||
$deserialized = unserialize($tounserialize);
|
$deserialized = unserialize($tounserialize);
|
||||||
|
|
||||||
foreach ($deserialized['instance_paths'] as $path) {
|
/*foreach ($deserialized['instance_paths'] as $path) {
|
||||||
$this->addInstance($path, isset($paths[$path]) ? $paths[$path] : []);
|
$this->addInstance($path, isset($paths[$path]) ? $paths[$path] : []);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
$this->event_handler = $deserialized['event_handler'];
|
$this->event_handler = $deserialized['event_handler'];
|
||||||
$this->event_handler_instance = $deserialized['event_handler_instance'];
|
$this->event_handler_instance = $deserialized['event_handler_instance'];
|
||||||
|
$this->setEventHandler($this->event_handler);
|
||||||
}
|
}
|
||||||
foreach ($paths as $path => $settings) {
|
foreach ($paths as $path => $settings) {
|
||||||
$this->addInstance($path, $settings);
|
$this->addInstance($path, $settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addInstance($path, $settings = [])
|
public function addInstance($path, $settings = [])
|
||||||
{
|
{
|
||||||
if (isset($this->instances[$path]) && isset($this->instance_paths[$path])) {
|
if (isset($this->instances[$path]) && isset($this->instance_paths[$path])) {
|
||||||
|
if (isset($this->event_handler_instance)) {
|
||||||
|
$this->event_handler_instance->referenceInstance($path);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +114,7 @@ class CombinedAPI
|
|||||||
public function serialize($filename = '')
|
public function serialize($filename = '')
|
||||||
{
|
{
|
||||||
/*foreach ($this->instances as $instance) {
|
/*foreach ($this->instances as $instance) {
|
||||||
$instance->serialize();
|
$instance->serialize();
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
if (is_null($this->session)) {
|
if (is_null($this->session)) {
|
||||||
@ -163,7 +172,7 @@ class CombinedAPI
|
|||||||
|
|
||||||
public function event_update_handler($update, $instance)
|
public function event_update_handler($update, $instance)
|
||||||
{
|
{
|
||||||
$method_name = 'on'.ucfirst($update['_']);
|
$method_name = 'on' . ucfirst($update['_']);
|
||||||
if (method_exists($this->event_handler_instance, $method_name)) {
|
if (method_exists($this->event_handler_instance, $method_name)) {
|
||||||
$this->event_handler_instance->$method_name($update, $instance);
|
$this->event_handler_instance->$method_name($update, $instance);
|
||||||
} elseif (method_exists($this->event_handler_instance, 'onAny')) {
|
} elseif (method_exists($this->event_handler_instance, 'onAny')) {
|
||||||
@ -190,8 +199,8 @@ class CombinedAPI
|
|||||||
} catch (\danog\MadelineProto\Exception $e) {
|
} catch (\danog\MadelineProto\Exception $e) {
|
||||||
register_shutdown_function(function () {
|
register_shutdown_function(function () {
|
||||||
\danog\MadelineProto\Logger::log(['Restarting script...']);
|
\danog\MadelineProto\Logger::log(['Restarting script...']);
|
||||||
$a = fsockopen((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'tls' : 'tcp').'://'.$_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT']);
|
$a = fsockopen((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'tls' : 'tcp') . '://' . $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT']);
|
||||||
fwrite($a, $_SERVER['REQUEST_METHOD'].' '.$_SERVER['REQUEST_URI'].' '.$_SERVER['SERVER_PROTOCOL']."\r\n".'Host: '.$_SERVER['SERVER_NAME']."\r\n\r\n");
|
fwrite($a, $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . ' ' . $_SERVER['SERVER_PROTOCOL'] . "\r\n" . 'Host: ' . $_SERVER['SERVER_NAME'] . "\r\n\r\n");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -227,7 +236,7 @@ class CombinedAPI
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($instance->API->datacenter->sockets as $id => $connection) {
|
foreach ($instance->API->datacenter->sockets as $id => $connection) {
|
||||||
$read[$id.'-'.$path] = $connection->getSocket();
|
$read[$id . '-' . $path] = $connection->getSocket();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (time() - $this->serialized > $this->serialization_interval) {
|
if (time() - $this->serialized > $this->serialization_interval) {
|
||||||
|
@ -475,7 +475,7 @@ class Lang
|
|||||||
'method_users.getFullUser' => 'You cannot use this method directly, use the get_pwr_chat, get_info, get_full_info methods instead (see https://docs.madelineproto.xyz for more info)',
|
'method_users.getFullUser' => 'You cannot use this method directly, use the get_pwr_chat, get_info, get_full_info methods instead (see https://docs.madelineproto.xyz for more info)',
|
||||||
'method_users.getFullUser_param_id_type_InputUser' => 'You cannot use this method directly, use the get_pwr_chat, get_info, get_full_info methods instead (see https://docs.madelineproto.xyz for more info)',
|
'method_users.getFullUser_param_id_type_InputUser' => 'You cannot use this method directly, use the get_pwr_chat, get_info, get_full_info methods instead (see https://docs.madelineproto.xyz for more info)',
|
||||||
'method_contacts.getStatuses' => 'Get online status of all users',
|
'method_contacts.getStatuses' => 'Get online status of all users',
|
||||||
'method_contacts.getContacts' => 'Get info about a certain contact',
|
'method_contacts.getContacts' => 'Get all contacts',
|
||||||
'method_contacts.getContacts_param_hash_type_int' => '$ids is the list ids of previously fetched contacts, `$hash = $MadelineProto->gen_vector_hash($ids);`',
|
'method_contacts.getContacts_param_hash_type_int' => '$ids is the list ids of previously fetched contacts, `$hash = $MadelineProto->gen_vector_hash($ids);`',
|
||||||
'method_contacts.importContacts' => 'Add phone number as contact',
|
'method_contacts.importContacts' => 'Add phone number as contact',
|
||||||
'method_contacts.importContacts_param_contacts_type_Vector t' => 'The numbers to import',
|
'method_contacts.importContacts_param_contacts_type_Vector t' => 'The numbers to import',
|
||||||
@ -4758,7 +4758,7 @@ class Lang
|
|||||||
'method_users.getFullUser' => 'You cannot use this method directly, use the get_pwr_chat, get_info, get_full_info methods instead (see https://docs.madelineproto.xyz for more info)',
|
'method_users.getFullUser' => 'You cannot use this method directly, use the get_pwr_chat, get_info, get_full_info methods instead (see https://docs.madelineproto.xyz for more info)',
|
||||||
'method_users.getFullUser_param_id_type_InputUser' => 'You cannot use this method directly, use the get_pwr_chat, get_info, get_full_info methods instead (see https://docs.madelineproto.xyz for more info)',
|
'method_users.getFullUser_param_id_type_InputUser' => 'You cannot use this method directly, use the get_pwr_chat, get_info, get_full_info methods instead (see https://docs.madelineproto.xyz for more info)',
|
||||||
'method_contacts.getStatuses' => 'Get online status of all users',
|
'method_contacts.getStatuses' => 'Get online status of all users',
|
||||||
'method_contacts.getContacts' => 'Get info about a certain contact',
|
'method_contacts.getContacts' => 'Get all contacts',
|
||||||
'method_contacts.getContacts_param_hash_type_int' => '$ids is the list ids of previously fetched contacts, `$hash = $MadelineProto->gen_vector_hash($ids);`',
|
'method_contacts.getContacts_param_hash_type_int' => '$ids is the list ids of previously fetched contacts, `$hash = $MadelineProto->gen_vector_hash($ids);`',
|
||||||
'method_contacts.importContacts' => 'Add phone number as contact',
|
'method_contacts.importContacts' => 'Add phone number as contact',
|
||||||
'method_contacts.importContacts_param_contacts_type_Vector t' => 'The numbers to import',
|
'method_contacts.importContacts_param_contacts_type_Vector t' => 'The numbers to import',
|
||||||
|
@ -471,11 +471,13 @@ trait PeerHandler
|
|||||||
$full = $this->method_call('channels.getFullChannel', ['channel' => $partial['InputChannel']], ['datacenter' => $this->datacenter->curdc])['full_chat'];
|
$full = $this->method_call('channels.getFullChannel', ['channel' => $partial['InputChannel']], ['datacenter' => $this->datacenter->curdc])['full_chat'];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = [];
|
$res = [];
|
||||||
$res['full'] = $full;
|
$res['full'] = $full;
|
||||||
$res['last_update'] = time();
|
$res['last_update'] = time();
|
||||||
$this->full_chats[$partial['bot_api_id']] = $res;
|
$this->full_chats[$partial['bot_api_id']] = $res;
|
||||||
|
|
||||||
|
$partial = $this->get_info($id);
|
||||||
return array_merge($partial, $res);
|
return array_merge($partial, $res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,6 +272,14 @@ trait ResponseHandler
|
|||||||
if (strpos($datacenter, 'cdn') === false) {
|
if (strpos($datacenter, 'cdn') === false) {
|
||||||
$this->handle_updates($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']);
|
$this->handle_updates($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['users'])) {
|
||||||
|
unset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['users']);
|
||||||
|
}
|
||||||
|
if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['chats'])) {
|
||||||
|
unset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['chats']);
|
||||||
|
}
|
||||||
|
|
||||||
$only_updates = true && $only_updates;
|
$only_updates = true && $only_updates;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -294,15 +302,20 @@ trait ResponseHandler
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['users'])) {
|
if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['users'])) {
|
||||||
$this->add_users($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['users']);
|
$this->add_users($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['users']);
|
||||||
}
|
}
|
||||||
if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['chats'])) {
|
if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['chats'])) {
|
||||||
$this->add_chats($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['chats']);
|
$this->add_chats($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['chats']);
|
||||||
}
|
}
|
||||||
|
if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['user'])) {
|
||||||
|
$this->add_users([$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['user']]);
|
||||||
|
}
|
||||||
if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['chat'])) {
|
if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['chat'])) {
|
||||||
$this->add_chats([$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['chat']]);
|
$this->add_chats([$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['chat']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['result']['users'])) {
|
if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['result']['users'])) {
|
||||||
$this->add_users($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['result']['users']);
|
$this->add_users($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['result']['users']);
|
||||||
}
|
}
|
||||||
|
@ -511,6 +511,15 @@ trait UpdateHandler
|
|||||||
|
|
||||||
public function save_update($update)
|
public function save_update($update)
|
||||||
{
|
{
|
||||||
|
if ($update['_'] === 'updateConfig') {
|
||||||
|
$this->config['expires'] = 0;
|
||||||
|
$this->get_config();
|
||||||
|
}
|
||||||
|
if (in_array($update['_'], ['updateUserName', 'updateUserPhone', 'updateUserBlocked', 'updateUserPhoto', 'updateContactRegistered', 'updateContactLink'])) {
|
||||||
|
$id = $this->get_info($update)['bot_api_id'];
|
||||||
|
$this->full_chats[$id]['last_update'] = 0;
|
||||||
|
$this->get_full_info($id);
|
||||||
|
}
|
||||||
if ($update['_'] === 'updateDcOptions') {
|
if ($update['_'] === 'updateDcOptions') {
|
||||||
$this->logger->logger('Got new dc options', \danog\MadelineProto\Logger::VERBOSE);
|
$this->logger->logger('Got new dc options', \danog\MadelineProto\Logger::VERBOSE);
|
||||||
$this->parse_dc_options($update['dc_options']);
|
$this->parse_dc_options($update['dc_options']);
|
||||||
|
Loading…
Reference in New Issue
Block a user