def __init__(self, minecraft_version=None, continue_after_status=True): if minecraft_version is None: minecraft_version = VERSIONS[-1][0] self.minecraft_version = minecraft_version self.continue_after_status = continue_after_status protocol_version = SUPPORTED_MINECRAFT_VERSIONS[minecraft_version] self.context = connection.ConnectionContext( protocol_version=protocol_version) self.packets_handshake = { p.get_id(self.context): p for p in packets.state_handshake_serverbound(self.context)} self.packets_login = { p.get_id(self.context): p for p in packets.state_login_serverbound(self.context)} self.packets_playing = { p.get_id(self.context): p for p in packets.state_playing_serverbound(self.context)} self.packets_status = { p.get_id(self.context): p for p in packets.state_status_serverbound(self.context)} self.listen_socket = socket.socket() self.listen_socket.bind(('0.0.0.0', 0)) self.listen_socket.listen(0) super(FakeServer, self).__init__()
def __init__( self, minecraft_version=None, compression_threshold=None, client_handler_type=FakeClientHandler, private_key=None, public_key_bytes=None, test_case=None, ): if minecraft_version is None: minecraft_version = VERSIONS[-1][0] if isinstance(minecraft_version, Integral): proto = minecraft_version minecraft_version = "FakeVersion%d" % proto for ver, ver_proto in SUPPORTED_MINECRAFT_VERSIONS.items(): if ver_proto == proto: minecraft_version = ver else: proto = SUPPORTED_MINECRAFT_VERSIONS[minecraft_version] self.context = connection.ConnectionContext(protocol_version=proto) self.minecraft_version = minecraft_version self.compression_threshold = compression_threshold self.client_handler_type = client_handler_type self.private_key = private_key self.public_key_bytes = public_key_bytes self.test_case = test_case self.packets_handshake = { p.get_id(self.context): p for p in serverbound.handshake.get_packets(self.context) } self.packets_login = { p.get_id(self.context): p for p in serverbound.login.get_packets(self.context) } self.packets_playing = { p.get_id(self.context): p for p in serverbound.play.get_packets(self.context) } self.packets_status = { p.get_id(self.context): p for p in serverbound.status.get_packets(self.context) } self.listen_socket = socket.socket() self.listen_socket.settimeout(0.1) self.listen_socket.bind(("localhost", 0)) self.listen_socket.listen(0) self.lock = threading.Lock() self.stopping = False super(FakeServer, self).__init__()
def pycraft_packet_classes(matrix, versions): """Returns a dict mapping `PacketClass' instances to `PyClassInfo' tuples, where `versions' is a set of `Ver` instances giving the protocol versions for which each packet class is supported by the locally installed version of the pyCraft library, and `py_name' is the name of the corresponding pyCraft class, as it occurs in the code, including two parent modules.""" classes = {} all_packets = set() errors = [] for ver in matrix.keys() if versions is None else versions: ver_matrix = matrix[ver] if ver.protocol not in pycraft.SUPPORTED_PROTOCOL_VERSIONS: continue assert pycraft.SUPPORTED_MINECRAFT_VERSIONS[ver.name] == ver.protocol context = pycraft_connection.ConnectionContext() context.protocol_version = ver.protocol packets = {} for bound in PACKET_BOUND_VALUES: for state in PACKET_STATE_VALUES: module = getattr(pycraft_packets, pycraft_packet_category(bound)) module = getattr(module, pycraft_packet_category(state)) state_packets = module.get_packets(context) all_packets |= state_packets packets[bound, state] = state_packets for packet_class, matrix_id in ver_matrix.items(): pycraft_name = pycraft_packet_name(packet_class.name) for packet in packets[packet_class.bound, packet_class.state]: expected = (matrix_id.id, pycraft_packet_name(packet_class.name)) actual = (packet.get_id(context), packet.__name__) if all(x != y for (x, y) in zip(actual, expected)): continue all_packets.discard(packet) if actual != expected: error = '[%s] pyCraft: (0x%02X, %r), wiki: (0x%02X, %r)' % \ ((ver.name,) + actual + (matrix_id.id, packet_class.name)) if error not in pycraft_ignore_errors: errors.append(error) continue if packet_class not in classes: classes[packet_class] = PyClassInfo( versions=set(), py_name=pycraft_packet_name_ext(packet_class), ) classes[packet_class].versions.add(ver) errors.extend('Packet not accounted for: %r' % p for p in all_packets) assert not errors, 'Errors found with pyCraft packets:\n' + '\n'.join( errors) return classes
def __init__(self, minecraft_version=None, compression_threshold=None, client_handler_type=FakeClientHandler): if minecraft_version is None: minecraft_version = VERSIONS[-1][0] self.minecraft_version = minecraft_version self.compression_threshold = compression_threshold self.client_handler_type = client_handler_type protocol_version = SUPPORTED_MINECRAFT_VERSIONS[minecraft_version] self.context = connection.ConnectionContext( protocol_version=protocol_version) self.packets_handshake = { p.get_id(self.context): p for p in serverbound.handshake.get_packets(self.context) } self.packets_login = { p.get_id(self.context): p for p in serverbound.login.get_packets(self.context) } self.packets_playing = { p.get_id(self.context): p for p in serverbound.play.get_packets(self.context) } self.packets_status = { p.get_id(self.context): p for p in serverbound.status.get_packets(self.context) } self.listen_socket = socket.socket() self.listen_socket.settimeout(0.1) self.listen_socket.bind(('localhost', 0)) self.listen_socket.listen(0) self.lock = threading.Lock() self.stopping = False super(FakeServer, self).__init__()
def __init__(self, minecraft_version=None, continue_after_status=True, compression_threshold=None): if minecraft_version is None: minecraft_version = VERSIONS[-1][0] self.minecraft_version = minecraft_version self.continue_after_status = continue_after_status self.compression_threshold = compression_threshold protocol_version = SUPPORTED_MINECRAFT_VERSIONS[minecraft_version] self.context = connection.ConnectionContext( protocol_version=protocol_version) self.compression_enabled = False self.packets_handshake = { p.get_id(self.context): p for p in serverbound.handshake.get_packets(self.context) } self.packets_login = { p.get_id(self.context): p for p in serverbound.login.get_packets(self.context) } self.packets_playing = { p.get_id(self.context): p for p in serverbound.play.get_packets(self.context) } self.packets_status = { p.get_id(self.context): p for p in serverbound.status.get_packets(self.context) } self.listen_socket = socket.socket() self.listen_socket.bind(('0.0.0.0', 0)) self.listen_socket.listen(0) super(FakeServer, self).__init__()