xtrime-ru / TelegramApiServer

Fast, simple, async php telegram api server: MadelineProto + Amp HTTP Server
https://tg.i-c-a.su
MIT License
529 stars 116 forks source link

How to catch USER_DEACTIVATED_BAN and delete or ignore the corresponding session #108

Closed shirakun closed 1 year ago

shirakun commented 1 year ago

Hi

After I run through php server.php --session=* and log into multiple accounts, If one of the accounts is banned, the server will stop running When I run it again with php server.php --session=* it stops immediately because the sessionfile contains a banned account, but I'm not sure which one I can only delete all sessions and log in again

When I read the code, I found that this exception is thrown by MadelineProto, then MadelineProto will stop, but at the same time TelegramApiServer also terminates

How can I catch the corresponding exception and ignore or delete the corresponding session or any other way to keep TelegramApiServer running?

This is Log

[2022-10-16 12:36:26] [warning] 
Starting MadelineProto...

[2022-10-16 12:36:26] [warning] Reconnecting to DC 2 (-1) from existing 
[2022-10-16 12:36:26] [warning] Connecting to DC 2.0 
[2022-10-16 12:36:26] [warning] Resetting session in DC 2.0... 
[2022-10-16 12:36:26] [warning] Reconnecting to DC 1 (-1) from existing 
[2022-10-16 12:36:26] [warning] Connecting to DC 1.0 
[2022-10-16 12:36:26] [warning] Resetting session in DC 1.0... 
[2022-10-16 12:36:26] [warning] Reconnecting to DC 2_media (-1) from existing 
[2022-10-16 12:36:26] [warning] Connecting to DC 2_media.0 
[2022-10-16 12:36:26] [warning] Resetting session in DC 2_media.0... 
[2022-10-16 12:36:26] [warning] Reconnecting to DC 3 (-1) from existing 
[2022-10-16 12:36:26] [warning] Connecting to DC 3.0 
[2022-10-16 12:36:26] [warning] Resetting session in DC 3.0... 
[2022-10-16 12:36:26] [warning] Reconnecting to DC 4 (-1) from existing 
[2022-10-16 12:36:26] [warning] Connecting to DC 4.0 
[2022-10-16 12:36:26] [warning] Resetting session in DC 4.0... 
[2022-10-16 12:36:26] [warning] Reconnecting to DC 4_media (-1) from existing 
[2022-10-16 12:36:26] [warning] Connecting to DC 4_media.0 
[2022-10-16 12:36:26] [warning] Resetting session in DC 4_media.0... 
[2022-10-16 12:36:26] [warning] Reconnecting to DC 5 (-1) from existing 
[2022-10-16 12:36:26] [warning] Connecting to DC 5.0 
[2022-10-16 12:36:26] [warning] Resetting session in DC 5.0... 
[2022-10-16 12:36:26] [warning] Connected to DC 5.0! 
[2022-10-16 12:36:26] [warning] OK! 
[2022-10-16 12:36:27] [warning] Connected to DC 1.0! 
[2022-10-16 12:36:27] [warning] OK! 
[2022-10-16 12:36:27] [warning] Connected to DC 3.0! 
[2022-10-16 12:36:27] [warning] OK! 
[2022-10-16 12:36:27] [warning] Received bad_msg_notification: incorrect server salt (in this case, the bad_server_salt response is received with the correct salt, and the message is to be re-sent with it) 
[2022-10-16 12:36:27] [warning] Connected to DC 2_media.0! 
[2022-10-16 12:36:27] [warning] Connecting to DC 2_media.1 
[2022-10-16 12:36:27] [warning] Resetting session in DC 2_media.1... 
[2022-10-16 12:36:27] [warning] Connected to DC 4_media.0! 
[2022-10-16 12:36:27] [warning] Connecting to DC 4_media.1 
[2022-10-16 12:36:27] [warning] Resetting session in DC 4_media.1... 
[2022-10-16 12:36:27] [warning] Connected to DC 2.0! 
[2022-10-16 12:36:27] [warning] OK! 
[2022-10-16 12:36:27] [warning] Connected to DC 4.0! 
[2022-10-16 12:36:27] [warning] OK! 
[2022-10-16 12:36:27] [warning] Connected to DC 2_media.1! 
[2022-10-16 12:36:27] [warning] Connecting to DC 2_media.2 
[2022-10-16 12:36:27] [warning] Resetting session in DC 2_media.2... 
[2022-10-16 12:36:27] [warning] Connected to DC 4_media.1! 
[2022-10-16 12:36:27] [warning] Connecting to DC 4_media.2 
[2022-10-16 12:36:27] [warning] Resetting session in DC 4_media.2... 
[2022-10-16 12:36:27] [warning] Received bad_msg_notification: incorrect server salt (in this case, the bad_server_salt response is received with the correct salt, and the message is to be re-sent with it) 
[2022-10-16 12:36:27] [warning] Received bad_msg_notification: incorrect server salt (in this case, the bad_server_salt response is received with the correct salt, and the message is to be re-sent with it) 
[2022-10-16 12:36:27] [warning] Connected to DC 2_media.2! 
[2022-10-16 12:36:27] [warning] Connecting to DC 2_media.3 
[2022-10-16 12:36:27] [warning] Resetting session in DC 2_media.3... 
[2022-10-16 12:36:27] [warning] Connected to DC 4_media.2! 
[2022-10-16 12:36:27] [warning] Connecting to DC 4_media.3 
[2022-10-16 12:36:27] [warning] Resetting session in DC 4_media.3... 
[2022-10-16 12:36:27] [warning] Received bad_msg_notification: incorrect server salt (in this case, the bad_server_salt response is received with the correct salt, and the message is to be re-sent with it) 
[2022-10-16 12:36:27] [warning] Received bad_msg_notification: incorrect server salt (in this case, the bad_server_salt response is received with the correct salt, and the message is to be re-sent with it) 
[2022-10-16 12:36:27] [warning] Connected to DC 2_media.3! 
[2022-10-16 12:36:27] [warning] Connecting to DC 2_media.4 
[2022-10-16 12:36:27] [warning] Resetting session in DC 2_media.4... 
[2022-10-16 12:36:27] [warning] Connected to DC 4_media.3! 
[2022-10-16 12:36:27] [warning] Connecting to DC 4_media.4 
[2022-10-16 12:36:27] [warning] Resetting session in DC 4_media.4... 
[2022-10-16 12:36:28] [warning] Connected to DC 2_media.4! 
[2022-10-16 12:36:28] [warning] OK! 
[2022-10-16 12:36:28] [warning] Connected to DC 4_media.4! 
[2022-10-16 12:36:28] [warning] OK! 
[2022-10-16 12:36:28] [warning] Reconnecting to DC 2 (-1) from existing 
[2022-10-16 12:36:28] [warning] Already connected! 
[2022-10-16 12:36:28] [warning] OK! 
[2022-10-16 12:36:28] [warning] Reconnecting to DC 1 (-1) from existing 
[2022-10-16 12:36:28] [warning] Already connected! 
[2022-10-16 12:36:28] [warning] OK! 
[2022-10-16 12:36:28] [warning] Reconnecting to DC 2_media (-1) from existing 
[2022-10-16 12:36:28] [warning] Already connected! 
[2022-10-16 12:36:28] [warning] OK! 
[2022-10-16 12:36:28] [warning] Reconnecting to DC 3 (-1) from existing 
[2022-10-16 12:36:28] [warning] Already connected! 
[2022-10-16 12:36:28] [warning] OK! 
[2022-10-16 12:36:28] [warning] Reconnecting to DC 4 (-1) from existing 
[2022-10-16 12:36:28] [warning] Already connected! 
[2022-10-16 12:36:28] [warning] OK! 
[2022-10-16 12:36:28] [warning] Reconnecting to DC 4_media (-1) from existing 
[2022-10-16 12:36:28] [warning] Already connected! 
[2022-10-16 12:36:28] [warning] OK! 
[2022-10-16 12:36:28] [warning] Reconnecting to DC 5 (-1) from existing 
[2022-10-16 12:36:28] [warning] Already connected! 
[2022-10-16 12:36:28] [warning] OK! 
[2022-10-16 12:36:28] [critical] USER_DEACTIVATED_BAN 
[2022-10-16 12:36:28] [critical] !!!!!!! WARNING !!!!!!! 
[2022-10-16 12:36:28] [error] Telegram's flood prevention system suspended this account. 
[2022-10-16 12:36:28] [critical] To continue, manual verification is required. 
[2022-10-16 12:36:28] [critical] Send an email to recover@telegram.org, asking to unban the phone number +8613055119456, and shortly describe what will you do with this phone number. 
[2022-10-16 12:36:28] [critical] Then login again. 
[2022-10-16 12:36:28] [critical] If you intentionally deleted this account, ignore this message. 
[2022-10-16 12:36:28] [critical] USER_DEACTIVATED_BAN 
[2022-10-16 12:36:28] [critical] !!!!!!! WARNING !!!!!!! 
[2022-10-16 12:36:28] [error] Telegram's flood prevention system suspended this account. 
[2022-10-16 12:36:28] [critical] To continue, manual verification is required. 
[2022-10-16 12:36:28] [critical] Send an email to recover@telegram.org, asking to unban the phone number +8613055119456, and shortly describe what will you do with this phone number. 
[2022-10-16 12:36:28] [critical] Then login again. 
[2022-10-16 12:36:28] [critical] If you intentionally deleted this account, ignore this message. 
[2022-10-16 12:36:28] [critical] USER_DEACTIVATED_BAN 
[2022-10-16 12:36:28] [critical] !!!!!!! WARNING !!!!!!! 
[2022-10-16 12:36:28] [error] Telegram's flood prevention system suspended this account. 
[2022-10-16 12:36:28] [critical] To continue, manual verification is required. 
[2022-10-16 12:36:28] [critical] Send an email to recover@telegram.org, asking to unban the phone number +8613055119456, and shortly describe what will you do with this phone number. 
[2022-10-16 12:36:28] [critical] Then login again. 
[2022-10-16 12:36:28] [critical] If you intentionally deleted this account, ignore this message. 
[2022-10-16 12:36:28] [critical]  
{
    "exception": "danog\\MadelineProto\\RPCErrorException",
    "message": "USER_DEACTIVATED_BAN",
    "file": "\/data\/wwwroot\/api.141.164.43.189.nip.io\/TelegramApiServer\/vendor\/danog\/madelineproto\/src\/danog\/MadelineProto\/MTProtoSession\/ResponseHandler.php",
    "line": 338,
    "code": 401,
    "backtrace": [
        {
            "file": "\/data\/wwwroot\/api.141.164.43.189.nip.io\/TelegramApiServer\/vendor\/danog\/madelineproto\/src\/danog\/MadelineProto\/MTProtoSession\/ResponseHandler.php",
            "line": 194,
            "function": "handleRpcError",
            "class": "danog\\MadelineProto\\Connection",
            "type": "->"
        },
        {
            "file": "\/data\/wwwroot\/api.141.164.43.189.nip.io\/TelegramApiServer\/vendor\/danog\/madelineproto\/src\/danog\/MadelineProto\/MTProtoSession\/ResponseHandler.php",
            "line": 73,
            "function": "handleResponse",
            "class": "danog\\MadelineProto\\Connection",
            "type": "->"
        },
        {
            "file": "\/data\/wwwroot\/api.141.164.43.189.nip.io\/TelegramApiServer\/vendor\/amphp\/amp\/lib\/Loop\/Driver.php",
            "line": 119,
            "function": "handleMessages",
            "class": "danog\\MadelineProto\\Connection",
            "type": "->"
        }
    ]
}
[2022-10-16 12:36:28] [critical] Loop exceptionally stopped without resolving the promise 
[2022-10-16 12:36:28] [critical] Telegram returned an RPC error: USER_DEACTIVATED_BAN (401) (USER_DEACTIVATED_BAN), caused by /data/wwwroot/api.141.164.43.189.nip.io/TelegramApiServer/vendor/danog/madelineproto/src/danog/MadelineProto/MTProtoSession/ResponseHandler.php:338

TL trace:
['updates.getChannelDifference']
CallHandler.php(61):    methodCallAsyncRead("updates.getChannelDifference",{"channel":"channel#1477231512","filter":{"_":"channelMessagesFilterEmpty"},"pts":771522,"limit":100,"force":true},{"datacenter":5,"postpone":true})
UpdateLoop.php(99):     methodCallAsyncRead("updates.getChannelDifference",{"channel":"channel#1477231512","filter":{"_":"channelMessagesFilterEmpty"},"pts":771522,"limit":100,"force":true},{"datacenter":5,"postpone":true})
LoggerLoop.php(59):     loop()
danog\MadelineProto\Loop\{closure}()
danog\MadelineProto\Loop\{closure}()

Previous TL trace:
['updates.getChannelDifference']
ResponseHandler.php(194):   handleRpcError()
ResponseHandler.php(73):    handleResponse()
Driver.php(119):        handleMessages()
Driver.php(72):         tick()
Loop.php(95):           run()
Server.php(40):         run()
server.php(102):        __construct()
reza305z commented 1 year ago

[2022-10-16 12:36:28] [critical] Send an email to recover@telegram.org, asking to unban the phone number +8613055119456, and shortly describe what will you do with this phone number.

The banned phone number is in the logs. does this number belong to API Id?

shirakun commented 1 year ago

[2022-10-16 12:36:28] [critical] Send an email to recover@telegram.org, asking to unban the phone number +8613055119456, and shortly describe what will you do with this phone number.

The banned phone number is in the logs. does this number belong to API Id?

Hi The api id is created through another account, not related to this number This number was intentionally ban by me by passing unknown device number

What I want to say is that when multiple sessions are added to the TelegramApiServer If one session is banned like this, the whole TelegramApiServer will exit and cannot be restarted with the command php server.php --session=*.

I have now modified server.php to continue to run in the event of a session exception However, when accessing this session, TelegramApiServer is blocked and cannot handle other requests.

Is there a way to delete or deactivate the abnormal session and ensure the rest of the session is working properly?

I also found that some accounts that can't initiate sessions also cause TelegramApiServer to stop when some api is called.

xtrime-ru commented 1 year ago

The proper way - start different process/container per session.