qubard/mcidle-python

I'm unable to make the program running properly

Closed this issue · 7 comments

Hey I tried to run the program by modifying the test.py file with my little python knowledge but I'm stuck on this error:

Started thread
Started thread
Started thread
Started thread
Started thread
Started thread
Started thread
Started thread
Started thread
Started thread
Started thread
Started thread
Started thread
Started thread
Started thread
Started thread
Connected
Waiting for client
Waiting for client
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib64/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/home/emilien/Documents/mcidle-python/src/networking/connection.py", line 65, in run
    self.packet_handler.handle()
  File "/home/emilien/Documents/mcidle-python/src/networking/packet_handler/serverbound/login_handler.py", line 10, in handle
    self.login()
  File "/home/emilien/Documents/mcidle-python/src/networking/packet_handler/serverbound/login_handler.py", line 22, in login
    encryption_request = EncryptionRequest().read(self.read_packet().packet_buffer)
  File "/home/emilien/Documents/mcidle-python/src/networking/packets/packet.py", line 48, in read
    assert (id_ == self.id or (self.ids and id_ in self.ids))
AssertionError

Here is the content of my test.py (the access token is obviously not valid but the IP is a real server):

from src.networking.connection import MinecraftConnection, MinecraftServer

conn = MinecraftConnection(ip="172.65.194.229", protocol=340, username="contact@example.com", \
                  profile={
         "accessToken":"leeGhei5eiDa1vaegh3fieghoo2cubuaG",
         "clientToken":"ahr5phuM6ain3eewaachoeJ4Tholum7ee",
         "selectedProfile":{
            "agent":"minecraft",
            "id":"4c89601e88f6476a8198383a2e259c40",
            "name":"username",
            "userId":"jo7eiHea4oob7sooth4Aeng9ooChoonai",
            "createdAt":1309975185000
         },
         "availableProfiles":[
            {
               "agent":"minecraft",
               "id":"eingaiw9tigooW3ahngai4thiesu8shiu",
               "name":"username",
               "userId":"jo7eiHea4oob7sooth4Aeng9ooChoonai",
               "createdAt":1309975185000
            }
         ]
      }).start()

server = MinecraftServer(port=25565)
server.start()

What did I do wrong? If you can help me that would be kind of you.

If you're connecting to a server that's 1.12.2 it should work if you provide a valid access token, but since your accessToken is invalid you didn't connect properly when it tried to read EncryptionRequest it read an invalid packet (this could be because the server isn't 1.12.2, or you didn't provide a valid access token to connect to the server).

I haven't written the docs yet but it'll just be as simple as passing in a username and password to the cli when they're done.

The server is compatible up-to 1.13. About the token I purposely changed it on this issue but in reality in my code it's a valid access token.

I found the bug. You're right, there was a bug that I didn't notice and it had to do with test.py and the way I started the Minecraft connection. It's fixed now and I've pushed the changes. It happened because I forgot to commit the old code Let me know if it still doesn't work.

I've also added command-line arguments and instructions in the README on how to use them. I recommend starting mcidle first and THEN connecting to the local server otherwise you'll invalidate your session and have to re-login to Minecraft again.

Thank you for trying to fix the bug.
I tried your updated code but it seems to still not working.
I'm getting this error after launching run.py with valid credentials:

Credentials are valid!
Started thread
Started thread
Started thread
Started thread
Started thread
Started thread
Started thread
Started thread
Started thread
Started thread
Started thread
Started thread
Started thread
Started thread
Started thread
Started thread
Connected
Waiting for client
Exception in thread Thread-19:
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/home/emilien/Documents/mcidle-python/src/networking/connection.py", line 63, in run
    self.initialize_connection()
  File "/home/emilien/Documents/mcidle-python/src/networking/connection.py", line 124, in initialize_connection
    self.socket.bind(self.address)
OSError: [Errno 98] Address already in use

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/home/emilien/Documents/mcidle-python/src/networking/connection.py", line 65, in run
    self.packet_handler.handle()
  File "/home/emilien/Documents/mcidle-python/src/networking/packet_handler/serverbound/login_handler.py", line 10, in handle
    self.login()
  File "/home/emilien/Documents/mcidle-python/src/networking/packet_handler/serverbound/login_handler.py", line 45, in login
    set_compression = SetCompression().read(self.read_packet().packet_buffer)
  File "/home/emilien/Documents/mcidle-python/src/networking/packets/packet.py", line 48, in read
    assert (id_ == self.id or (self.ids and id_ in self.ids))
AssertionError

I ran the program on 2b2t.org and on my server to be sure that my server wasn't the issue. I even tried to run the program as root and on different ports with --dport.

That error is saying you already have another instance of mcidle running (OSError: [Errno 98] Address already in use). Close all of them and try again. It should work if you do it correctly--I tested it 10 mins ago.

The thing is I don't have any other instance running. That's why I tried to change the port multiple times with --dport to see if there was something else running on the default port.
I get this Address already in use error when I try to connect to the mcidle server not before.
EDIT: I'm using Linux, I don't know if that would be the cause of the issue.

I think I fixed that Address already in use issue by using pipenv to install the exact same version of the dependencies but nonetheless why I try to login with my Minecraft client I get stuck on logging in screen for a few seconds then I get a timeout error screen.
Just after that the server stop to respond and throw these errors:

Exception in thread Thread-18:
Traceback (most recent call last):
  File "/home/emilien/Documents/mcidle-python/src/networking/packet_handler/clientbound/login_handler.py", line 103, in handle
    encryption_response = EncryptionResponse().read(self.read_packet().packet_buffer)
  File "/home/emilien/Documents/mcidle-python/src/networking/packet_handler/packet_handler.py", line 16, in read_packet
    length = VarInt.read(self.connection.stream)
  File "/home/emilien/Documents/mcidle-python/src/networking/types/type.py", line 105, in read
    raise EOFError("Unexpected end of message.")
EOFError: Unexpected end of message.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib64/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/home/emilien/Documents/mcidle-python/src/networking/connection.py", line 65, in run
    self.packet_handler.handle()
  File "/home/emilien/Documents/mcidle-python/src/networking/packet_handler/clientbound/login_handler.py", line 126, in handle
    self.restart()
  File "/home/emilien/Documents/mcidle-python/src/networking/packet_handler/clientbound/login_handler.py", line 88, in restart
    self.connection.reset_socket()
  File "/home/emilien/Documents/mcidle-python/src/networking/connection.py", line 33, in reset_socket
    self.socket.shutdown(2)
OSError: [Errno 107] Transport endpoint is not connected
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib64/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/home/emilien/Documents/mcidle-python/src/networking/connection.py", line 65, in run
    self.packet_handler.handle()
  File "/home/emilien/Documents/mcidle-python/src/networking/packet_handler/serverbound/login_handler.py", line 10, in handle
    self.login()
  File "/home/emilien/Documents/mcidle-python/src/networking/packet_handler/serverbound/login_handler.py", line 45, in login
    set_compression = SetCompression().read(self.read_packet().packet_buffer)
  File "/home/emilien/Documents/mcidle-python/src/networking/packet_handler/packet_handler.py", line 16, in read_packet
    length = VarInt.read(self.connection.stream)
  File "/home/emilien/Documents/mcidle-python/src/networking/types/type.py", line 105, in read
    raise EOFError("Unexpected end of message.")
EOFError: Unexpected end of message.

EDIT: I was using the same Minecraft client version as the server.