0

我已经开始了一个项目来编写一个基于 python 的 minecraft 客户端/机器人来连接到标准的 minecraft 服务器。我正在使用一个名为py-mine-client的库来执行数据包处理。我一直无法使用库接收数据包 - 我不知道要调用哪些函数/可以访问接收到的数据的位置。主要问题是弄清楚如何接收握手响应。我以为我可以使用 client.recievePacket 函数访问它,但它似乎不起作用。

这是我的代码:

import sys
import string
from client import *

def main():
    client = Client("192.168.1.15")
    client.connect()
    client.handshake("MyUsername")
    handshake = string16("\x02")
    client.recieve_packet(handshake)
    client.login_request("MyUsername")
    client.listener.stop()

if __name__ == "__main__":
    sys.exit(main())

这是一个 wiki,其中包含有关协议如何工作的信息:
http ://wiki.vg/Protocol

4

1 回答 1

0

Looking at the library source code, they have a Listener class collecting all packets in the separate thread automatically. The receive_packet method shouldn't be then called by the user (it's used by listener to report new incoming data). All packets are appended to client.packets array which you can access. Unfortunately, the library doesn't seem to be thread-safe (probably relies on the global lock) and they seem to have many socket-related bugs.

As the library seems to be very simple, you might like just to rewrite it.

于 2012-07-04T14:57:28.130 回答