示例#1
0
文件: senders.py 项目: totu/mcbot
    def send(self, packet):
        if self.compression:
            packet = PackVarInt(0) + packet

        packet = [len(packet)] + packet
        packet = [ord(x) if isinstance(x, str) else x for x in packet]
        self.sock.send(bytes(packet))
示例#2
0
文件: libmc.py 项目: totu/mcbot
    def attack(self, name):
        """send_UseEntity"""
        print("MCBot attacking:", name)
        distance = 3
        with self.lock:
            entities = copy.deepcopy(self.entities)

        for entity in entities:
            ent = entities[entity]
            if ent.is_name(name) and ent.is_inrange(self.position, distance):
                # Jump for crit
                x, y, z = self.position
                self.send_PlayerPositionAndLook(x,
                                                y + 0.5,
                                                z,
                                                self.yaw,
                                                self.pitch,
                                                on_ground=False)
                time.sleep(0.05)
                self.send_PlayerPositionAndLook(x,
                                                y + 1,
                                                z,
                                                self.yaw,
                                                self.pitch,
                                                on_ground=False)
                time.sleep(0.05)
                self.send_PlayerPositionAndLook(x,
                                                y,
                                                z + 0.5,
                                                self.yaw,
                                                self.pitch,
                                                on_ground=False)
                time.sleep(0.05)
                # 0: interact, 1: attack, 2: interact
                packet = PackVarInt(0x0D) + PackVarInt(entity) + PackVarInt(1)
                self.send(packet)
                # animation
                packet = PackVarInt(0x27) + PackVarInt(0)
                self.send(packet)
                # land?
                time.sleep(0.05)
                self.send_PlayerPositionAndLook(x,
                                                y,
                                                z,
                                                self.yaw,
                                                self.pitch,
                                                on_ground=True)
示例#3
0
文件: senders.py 项目: totu/mcbot
 def send_PlayerPositionAndLook(self, x, y, z, yaw, pitch, on_ground=True):
     self.position = [x, y, z]
     self.yaw = yaw
     self.pitch = pitch
     packet = (PackVarInt(0x11) + PackDouble(x) + PackDouble(y) +
               PackDouble(z) + PackFloat(yaw) + PackFloat(pitch) +
               PackBool(on_ground))
     self.send(packet)
示例#4
0
文件: senders.py 项目: totu/mcbot
 def send_PlayerLook(self, yaw, pitch):
     """Look at something"""
     packet = PackVarInt(0x12) + PackFloat(yaw) + PackFloat(
         pitch) + PackBool(True)
     self.send(packet)
示例#5
0
文件: senders.py 项目: totu/mcbot
 def send_PlayerPosition(self, x, y, z):
     self.position = [x, y, z]
     # y = y - 1.62
     packet = (PackVarInt(0x10) + PackDouble(x) + PackDouble(y) +
               PackDouble(z) + PackBool(True))
     self.send(packet)
示例#6
0
文件: senders.py 项目: totu/mcbot
 def send_TeleportConfirm(self, teleport_id):
     """Teleport Confirm"""
     print("Sending Server TeleportConfirm")
     packet = PackVarInt(0x00) + PackVarInt(teleport_id)
     self.send(packet)
     self.accepted_teleport = teleport_id
示例#7
0
文件: senders.py 项目: totu/mcbot
 def send_ClientStatus(self, action_id):
     """Client Status"""
     print("Sending Server ClientStatus")
     packet = PackVarInt(0x03) + PackVarInt(action_id)
     self.send(packet)
示例#8
0
文件: senders.py 项目: totu/mcbot
 def send_LoginStart(self):
     """Login start"""
     print("Sending Server LoginStart")
     packet = PackVarInt(0) + PackString(self.name)
     self.send(packet)
示例#9
0
文件: senders.py 项目: totu/mcbot
 def send_HandShake(self):
     """Server Handshake"""
     print("Sending Server HandShake")
     packet = (PackVarInt(0) + PackVarInt(404) + PackString(self.host) +
               PackUnsignedShort(self.port) + PackVarInt(2))
     self.send(packet)
示例#10
0
文件: senders.py 项目: totu/mcbot
 def send_KeepAlive(self, packet):
     # print("Sending KeepAlive")
     packet = PackVarInt(0x0E) + packet
     self.send(packet)