Implement hash abstracion

This commit is contained in:
Daniil Gentili 2018-08-29 17:16:38 +02:00
parent b304e6b923
commit 32e45b83f6
5 changed files with 39 additions and 25 deletions

View File

@ -105,6 +105,11 @@ trait Methods
if ($param['name'] === 'chat_id' && $data['method'] !== 'messages.discardEncryption' && !isset($this->settings['td'])) {
$param['type'] = 'InputPeer';
}
if ($param['name'] === 'hash' && $param['type'] === 'int') {
$param['pow'] = 'hi';
$param['type'] = 'Vector t';
$param['subtype'] = 'int';
}
$ptype = str_replace('.', '_', $param[$type_or_subtype = isset($param['subtype']) ? 'subtype' : 'type']);
switch ($ptype) {
case 'true':

View File

@ -476,7 +476,7 @@ class Lang
'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.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' => 'user ids of contacts previously fetched with this method',
'method_contacts.importContacts' => 'Add phone number as contact',
'method_contacts.importContacts_param_contacts_type_Vector t' => 'The numbers to import',
'method_contacts.deleteContact' => 'Delete a contact',
@ -507,7 +507,7 @@ class Lang
'method_contacts.getTopPeers_param_channels_type_true' => 'Fetch channels and supergroups?',
'method_contacts.getTopPeers_param_offset_type_int' => 'Initially 0, then `$offset += $contacts_TopPeers[\'categories\'][\'count\'];`',
'method_contacts.getTopPeers_param_limit_type_int' => 'How many results to fetch',
'method_contacts.getTopPeers_param_hash_type_int' => '$MadelineProto->gen_vector_hash(previously fetched peer ids);',
'method_contacts.getTopPeers_param_hash_type_int' => 'peer ids previously fetched with this method',
'method_contacts.resetTopPeerRating' => 'Reset top peer rating for a certain category/peer',
'method_contacts.resetTopPeerRating_param_category_type_TopPeerCategory' => 'The category ',
'method_contacts.resetTopPeerRating_param_peer_type_InputPeer' => 'The peer',
@ -528,7 +528,7 @@ class Lang
'method_messages.getHistory_param_limit_type_int' => 'Number of messages to fetch',
'method_messages.getHistory_param_max_id_type_int' => 'Maximum message ID to fetch',
'method_messages.getHistory_param_min_id_type_int' => 'Minumum message ID to fetch',
'method_messages.getHistory_param_hash_type_int' => 'hash of old messages, $MadelineProto->gen_vector_hash($parsedMessageIds)',
'method_messages.getHistory_param_hash_type_int' => 'list of IDs of already parsed messages',
'method_messages.search' => 'Search peers or messages',
'method_messages.search_param_peer_type_InputPeer' => 'Where to search',
'method_messages.search_param_q_type_string' => 'What to search',
@ -646,7 +646,7 @@ class Lang
'method_messages.readMessageContents_param_id_type_Vector t' => 'The messages to mark as read (only users and normal chats, not supergroups)',
'method_messages.getStickers' => 'Get stickers',
'method_messages.getStickers_param_emoticon_type_string' => 'Search by emoji',
'method_messages.getStickers_param_hash_type_string' => '0 or $MadelineProto->gen_vector_hash(previously fetched sticker IDs)',
'method_messages.getStickers_param_hash_type_string' => 'previously fetched sticker IDs',
'method_messages.getAllStickers' => 'Get all stickerpacks',
'method_messages.getAllStickers_param_hash_type_int' => '0 or $result[\'hash\']',
'method_messages.getWebPagePreview' => 'Get webpage preview',
@ -950,7 +950,7 @@ class Lang
'method_channels.getParticipants_param_filter_type_ChannelParticipantsFilter' => 'Member filter',
'method_channels.getParticipants_param_offset_type_int' => 'Offset',
'method_channels.getParticipants_param_limit_type_int' => 'Limit',
'method_channels.getParticipants_param_hash_type_int' => '$MadelineProto->gen_vector_hash(ids of previously fetched participant IDs)',
'method_channels.getParticipants_param_hash_type_int' => 'sorted list of IDs of participants you already fetched',
'method_channels.getParticipant' => 'Get info about a certain channel/supergroup participant',
'method_channels.getParticipant_param_channel_type_InputChannel' => 'The channel/supergroup',
'method_channels.getParticipant_param_user_id_type_InputUser' => 'The user to fetch info about',
@ -1114,7 +1114,7 @@ class Lang
'method_account.registerDevice_param_system_version_type_string' => 'System version',
'method_account.registerDevice_param_app_version_type_string' => 'App version',
'method_account.registerDevice_param_lang_code_type_string' => 'Language code',
'method_contacts.getContacts_param_hash_type_string' => '$MadelineProto->gen_vector_hash(previously fetched user IDs);',
'method_contacts.getContacts_param_hash_type_string' => 'List of contact user IDs you already cached',
'method_contacts.importContacts_param_replace_type_Bool' => 'Replace contacts?',
'method_contacts.getSuggested' => 'Get suggested contacts',
'method_contacts.getSuggested_param_limit_type_int' => 'Number of results to return',
@ -4144,20 +4144,20 @@ class Lang
'method_users.setSecureValueErrors' => 'Set secure value error for telegram passport',
'method_users.setSecureValueErrors_param_id_type_InputUser' => 'The user ID',
'method_users.setSecureValueErrors_param_errors_type_Vector t' => 'The errors',
'method_messages.search_param_hash_type_int' => '$MadelineProto->gen_vector_hash(ids of previously fetched messages);',
'method_messages.search_param_hash_type_int' => 'IDs of messages you already fetched',
'method_messages.report' => 'Report a message',
'method_messages.report_param_peer_type_InputPeer' => 'The user that sent the messages',
'method_messages.report_param_id_type_Vector t' => 'The messages to report',
'method_messages.report_param_reason_type_ReportReason' => 'The reason why you\'re sending this report',
'method_messages.getStickers_param_hash_type_int' => '$MadelineProto->gen_vector_hash(ids of previously fetched stickers, or []);',
'method_messages.getStickers_param_hash_type_int' => 'IDs of previously fetched stickers',
'method_messages.editMessage_param_media_type_InputMedia' => 'The media to substitute',
'method_messages.editInlineBotMessage_param_media_type_InputMedia' => 'The media to substitute',
'method_messages.toggleDialogPin_param_peer_type_InputDialogPeer' => 'The dialog to pin',
'method_messages.getRecentLocations_param_hash_type_int' => '$MadelineProto->gen_vector_hash(ids of previously fetched locations, or []);',
'method_messages.getRecentLocations_param_hash_type_int' => 'IDs of previously fetched locations',
'method_messages.searchStickerSets' => 'Find a sticker set',
'method_messages.searchStickerSets_param_exclude_featured_type_true' => 'Exclude featured sticker sets from the search?',
'method_messages.searchStickerSets_param_q_type_string' => 'The search query',
'method_messages.searchStickerSets_param_hash_type_int' => '$MadelineProto->gen_vector_hash(ids of previously searched stickers, or []);',
'method_messages.searchStickerSets_param_hash_type_int' => 'ids of stickers you already cached',
'method_upload.getFileHashes' => 'Get file hashes',
'method_upload.getFileHashes_param_location_type_InputFileLocation' => 'The file',
'method_upload.getFileHashes_param_offset_type_int' => 'Offset',
@ -4410,7 +4410,7 @@ class Lang
'object_account.takeout_param_id_type_long' => '',
'method_contacts.toggleTopPeers' => 'Toggle top peers',
'method_contacts.toggleTopPeers_param_enabled_type_Bool' => 'Enable or disable top peer',
'method_messages.getDialogs_param_hash_type_int' => '$MadelineProto->gen_vector_hash(ids of previously fetched dialogs or [])',
'method_messages.getDialogs_param_hash_type_int' => 'IDs of previously fetched dialogs',
'method_messages.markDialogUnread' => 'Mark dialog as unread ',
'method_messages.markDialogUnread_param_unread_type_true' => 'Should it be marked or unmarked as read',
'method_messages.markDialogUnread_param_peer_type_InputDialogPeer' => 'The dialog to mark as unread',
@ -4759,7 +4759,7 @@ class Lang
'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.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' => 'User IDs of previously fetched contacts`',
'method_contacts.importContacts' => 'Add phone number as contact',
'method_contacts.importContacts_param_contacts_type_Vector t' => 'The numbers to import',
'method_contacts.deleteContact' => 'Delete a contact',
@ -4790,7 +4790,7 @@ class Lang
'method_contacts.getTopPeers_param_channels_type_true' => 'Fetch channels and supergroups?',
'method_contacts.getTopPeers_param_offset_type_int' => 'Initially 0, then `$offset += $contacts_TopPeers[\'categories\'][\'count\'];`',
'method_contacts.getTopPeers_param_limit_type_int' => 'How many results to fetch',
'method_contacts.getTopPeers_param_hash_type_int' => '$MadelineProto->gen_vector_hash(previously fetched peer ids);',
'method_contacts.getTopPeers_param_hash_type_int' => 'IDs of peers you already cached',
'method_contacts.resetTopPeerRating' => 'Reset top peer rating for a certain category/peer',
'method_contacts.resetTopPeerRating_param_category_type_TopPeerCategory' => 'The category ',
'method_contacts.resetTopPeerRating_param_peer_type_InputPeer' => 'The peer',
@ -4811,7 +4811,7 @@ class Lang
'method_messages.getHistory_param_limit_type_int' => 'Number of messages to fetch',
'method_messages.getHistory_param_max_id_type_int' => 'Maximum message ID to fetch',
'method_messages.getHistory_param_min_id_type_int' => 'Minumum message ID to fetch',
'method_messages.getHistory_param_hash_type_int' => 'hash of old messages, $MadelineProto->gen_vector_hash($parsedMessageIds)',
'method_messages.getHistory_param_hash_type_int' => 'IDs of messages you already fetched',
'method_messages.search' => 'Search peers or messages',
'method_messages.search_param_peer_type_InputPeer' => 'Where to search',
'method_messages.search_param_q_type_string' => 'What to search',
@ -4929,7 +4929,7 @@ class Lang
'method_messages.readMessageContents_param_id_type_Vector t' => 'The messages to mark as read (only users and normal chats, not supergroups)',
'method_messages.getStickers' => 'Get stickers',
'method_messages.getStickers_param_emoticon_type_string' => 'Search by emoji',
'method_messages.getStickers_param_hash_type_string' => '0 or $MadelineProto->gen_vector_hash(previously fetched sticker IDs)',
'method_messages.getStickers_param_hash_type_string' => 'IDs of stickers you already cached',
'method_messages.getAllStickers' => 'Get all stickerpacks',
'method_messages.getAllStickers_param_hash_type_int' => '0 or $result[\'hash\']',
'method_messages.getWebPagePreview' => 'Get webpage preview',
@ -5233,7 +5233,7 @@ class Lang
'method_channels.getParticipants_param_filter_type_ChannelParticipantsFilter' => 'Member filter',
'method_channels.getParticipants_param_offset_type_int' => 'Offset',
'method_channels.getParticipants_param_limit_type_int' => 'Limit',
'method_channels.getParticipants_param_hash_type_int' => '$MadelineProto->gen_vector_hash(ids of previously fetched participant IDs)',
'method_channels.getParticipants_param_hash_type_int' => 'sorted list of IDs of participants you already fetched',
'method_channels.getParticipant' => 'Get info about a certain channel/supergroup participant',
'method_channels.getParticipant_param_channel_type_InputChannel' => 'The channel/supergroup',
'method_channels.getParticipant_param_user_id_type_InputUser' => 'The user to fetch info about',
@ -5397,7 +5397,7 @@ class Lang
'method_account.registerDevice_param_system_version_type_string' => 'System version',
'method_account.registerDevice_param_app_version_type_string' => 'App version',
'method_account.registerDevice_param_lang_code_type_string' => 'Language code',
'method_contacts.getContacts_param_hash_type_string' => '$MadelineProto->gen_vector_hash(previously fetched user IDs);',
'method_contacts.getContacts_param_hash_type_string' => 'List of contact user IDs you already cached',
'method_contacts.importContacts_param_replace_type_Bool' => 'Replace contacts?',
'method_contacts.getSuggested' => 'Get suggested contacts',
'method_contacts.getSuggested_param_limit_type_int' => 'Number of results to return',
@ -8427,20 +8427,20 @@ class Lang
'method_users.setSecureValueErrors' => 'Set secure value error for telegram passport',
'method_users.setSecureValueErrors_param_id_type_InputUser' => 'The user ID',
'method_users.setSecureValueErrors_param_errors_type_Vector t' => 'The errors',
'method_messages.search_param_hash_type_int' => '$MadelineProto->gen_vector_hash(ids of previously fetched messages);',
'method_messages.search_param_hash_type_int' => 'IDs of messages you already fetched',
'method_messages.report' => 'Report a message',
'method_messages.report_param_peer_type_InputPeer' => 'The user that sent the messages',
'method_messages.report_param_id_type_Vector t' => 'The messages to report',
'method_messages.report_param_reason_type_ReportReason' => 'The reason why you\'re sending this report',
'method_messages.getStickers_param_hash_type_int' => '$MadelineProto->gen_vector_hash(ids of previously fetched stickers, or []);',
'method_messages.getStickers_param_hash_type_int' => 'IDs of previously fetched stickers',
'method_messages.editMessage_param_media_type_InputMedia' => 'The media to substitute',
'method_messages.editInlineBotMessage_param_media_type_InputMedia' => 'The media to substitute',
'method_messages.toggleDialogPin_param_peer_type_InputDialogPeer' => 'The dialog to pin',
'method_messages.getRecentLocations_param_hash_type_int' => '$MadelineProto->gen_vector_hash(ids of previously fetched locations, or []);',
'method_messages.getRecentLocations_param_hash_type_int' => 'IDs of previously fetched locations',
'method_messages.searchStickerSets' => 'Find a sticker set',
'method_messages.searchStickerSets_param_exclude_featured_type_true' => 'Exclude featured sticker sets from the search?',
'method_messages.searchStickerSets_param_q_type_string' => 'The search query',
'method_messages.searchStickerSets_param_hash_type_int' => '$MadelineProto->gen_vector_hash(ids of previously searched stickers, or []);',
'method_messages.searchStickerSets_param_hash_type_int' => 'ids of stickers you already cached',
'method_upload.getFileHashes' => 'Get file hashes',
'method_upload.getFileHashes_param_location_type_InputFileLocation' => 'The file',
'method_upload.getFileHashes_param_offset_type_int' => 'Offset',
@ -8693,7 +8693,7 @@ class Lang
'object_account.takeout_param_id_type_long' => '',
'method_contacts.toggleTopPeers' => 'Toggle top peers',
'method_contacts.toggleTopPeers_param_enabled_type_Bool' => 'Enable or disable top peer',
'method_messages.getDialogs_param_hash_type_int' => '$MadelineProto->gen_vector_hash(ids of previously fetched dialogs or [])',
'method_messages.getDialogs_param_hash_type_int' => 'IDs of previously fetched dialogs',
'method_messages.markDialogUnread' => 'Mark dialog as unread ',
'method_messages.markDialogUnread_param_unread_type_true' => 'Should it be marked or unmarked as read',
'method_messages.markDialogUnread_param_peer_type_InputDialogPeer' => 'The dialog to mark as unread',

View File

@ -737,6 +737,7 @@ trait PeerHandler
foreach ($gres['participants'] as $participant) {
$ids[] = $participant['user_id'];
}
sort($ids, SORT_NUMERIC);
$gres['hash'] = $this->gen_vector_hash($ids);
$this->channel_participants[$channel['channel_id']][$filter][$q][$offset][$limit] = $gres;
}

View File

@ -218,7 +218,11 @@ trait TL
switch ($type['type']) {
case 'int':
if (!is_numeric($object)) {
throw new Exception(\danog\MadelineProto\Lang::$current_lang['not_numeric']);
if (is_array($object) && $type['name'] === 'hash') {
$object = $this->gen_vector_hash($object);
} else {
throw new Exception(\danog\MadelineProto\Lang::$current_lang['not_numeric']);
}
}
return $this->pack_signed_int($object);
@ -498,6 +502,10 @@ trait TL
}
}
}
if ($current_argument['name'] === 'hash' && $current_argument['type'] === 'int') {
$serialized .= pack('@4');
continue;
}
if ($tl['type'] === 'InputMedia' && $current_argument['name'] === 'mime_type') {
$serialized .= $this->serialize_object($current_argument, $arguments['file']['mime_type'], $current_argument['name'], $layer);
continue;

View File

@ -19,7 +19,7 @@ trait Tools
{
public function gen_vector_hash($ints)
{
sort($ints, SORT_NUMERIC);
//sort($ints, SORT_NUMERIC);
if (\danog\MadelineProto\Magic::$bigint) {
$hash = new \phpseclib\Math\BigInteger(0);
foreach ($ints as $int) {
@ -29,7 +29,7 @@ trait Tools
} else {
$hash = 0;
foreach ($ints as $int) {
$hash = (($hash * 20261) + 0x80000000 + $int) % 0x80000000;
$hash = ((($hash * 20261) & 0x7FFFFFFF) + $int) & 0x7FFFFFFF;
}
}