0

Ok, so this is my code basicly:

class Server:
    def __init__(self, addr, port, mc):
        self.mc = mc
        data = {'user': mc.user, 'password': mc.pswd, 'version': '12'}
        data = urllib.urlencode(data)
        dta = urllib.urlopen("https://login.minecraft.net", data=data).read()
        dta = dta.split(":")
        self.sessionid = dta[3]
        self.socket = socket.socket()
        self.socket.connect((addr, port))
        data = {"user": mc.user, "host": addr, "port": port}
        enc = mc.user.encode('utf-16BE')
        structfmt = '!bh'
        bytes = struct.pack(structfmt, 2, len(enc))
        bytes = bytes + enc
        self.socket.send(self.get_login_packet(mc.user, mc.pswd, addr, port))
        self.random = False
        self.world = World()
    def test(self):
        self.socket.send(self.get_chat_packet(raw_input("Enter a message: ")))
        self.disconnect(raw_input("Enter the disconnect message: "))
    def keep_alive(self):
        if self.random:
            self.socket.send(struct.pack("!bi", 0, self.random))
    def get_login_packet(self, user, password, addr, port):
        data = {"user": mc.user, "host": addr, "port": port}
        enc = mc.user.encode('utf-16BE')
        structfmt = '!bh'
        bytes = struct.pack(structfmt, 2, len(enc))
        bytes = bytes + enc
        return bytes
    def get_chat_packet(self, message):
        if len(message) > 100:
            message = message[:100]
        return struct.pack("!bs", 3, message)
    def get_disconnect_packet(self, message):
        return struct.pack("!bs", 0xFF, message)
    def disconnect(self, message):
        self.socket.send(self.get_disconnect_packet(message))
        time.sleep(0.1)
        self.socket.close()

mc is a Minecraft instance in python which basicly has 4 attributes, server (the class above), user, pswd, and world (for now, a None type).

I am NOT trying to connect to a Minecraft Classic, I am trying to connect to the payed version. I am using Python 2.5 on Windows XP. The error it gave me when I tried to connect on the server is

[INFO] Disconnecting /127.0.0.1:2292: Took too long to log in
[INFO] /127.0.0.1:2295 lost connection

The error on Python is

    self.socket.send(self.get_chat_packet(raw_input("Enter a message: ")))
socket.error: (10053, 'Software caused connection abort')

Please tell me why this is happening and preferably how to fix it also. Thanks!

Tom
  • 846
  • 5
  • 18
  • 30
  • You don't ever read from the socket - just a guess but try printing out self.socket.recv(100) when you connect and after you send the login packet and see what it says. – ed. Oct 15 '12 at 21:47
  • That won't help, the server doesn't answer if there is no complete packet. – dav1d Oct 15 '12 at 21:50

1 Answers1

-1

Your code is horrible and you will fail with a code like this to implement all Packets in a useful and relativly efficent manner. Take a look e.g. at mc3p how the protocol is implemented.

Now to your problem, you're not sending a protocol version (= 39 for minecraft 1.3) with your Handshake packet, there is also no host and no port sent with the packet.

dav1d
  • 5,917
  • 1
  • 33
  • 52