def fall(self, packet): print "Entering fall func" if not self.client.position['on_ground']: print "Trying to Fall" y = int(math.floor(self.client.position['y'])) x = int(math.floor(self.client.position['x'])) z = int(math.floor(self.client.position['z'])) ground = self.findground(x, y, z) if ground == -1: return if (self.client.position['y'] - ground) > 1: self.client.push( Packet(ident=0x0B, data={ 'x': self.client.position['x'], 'y': (self.client.position['y'] - 1), 'z': self.client.position['z'], 'stance': (self.client.position['stance'] - 1), 'on_ground': False, })) else: self.client.push( Packet(ident=0x0B, data={ 'x': self.client.position['x'], 'y': (ground + 1), 'z': self.client.position['z'], 'stance': (ground + 2), 'on_ground': True, }))
def get_info(host='localhost', port=25565): #Set up our socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host, port)) #Make our buffer bbuff = BoundBuffer() #Send 0xFE: Server list ping s.send( Packet(ident=0xFE, data={ 'magic': SERVER_LIST_PING_MAGIC, }).encode()) #Read some data bbuff.append(s.recv(1024)) #We don't need the socket anymore s.close() #Read a packet out of our buffer packet = read_packet(bbuff) #This particular packet is a special case, so we have #a utility function do a second decoding step. return DecodeSLP(packet)
def avoid_afk(self, packet): msg = packet.data['text'].lower() if ('afk plugin' in msg): self.client.push( Packet( ident=0x03, data={ "text": "Hello, I am Spock_Bot, this message is to avoid AFKGC" }))
def initial_spawn(self, name, event): if self.alive: return self.event.unreg_event_handler( mcdata.packet_idents['PLAY<Spawn Position'], self.initial_spawn) self.net.push( Packet(ident='PLAY>Client Settings', data={ 'locale': 'en_US', 'view_distance': 12, 'chat_flags': 0, 'chat_colors': 1, 'difficulty': 0, 'show_cape': 1 })) self.send_respawn() self.net.push( Packet(ident='PLAY>Chat Message', data={'message': "/join"})) self.alive = True
def handle_position_update(self, name, packet): self.client_info.position['x'] = packet.data['x'] self.client_info.position['y'] = packet.data['y'] - HEAD_HEIGHT self.client_info.position['z'] = packet.data['z'] self.client_info.position['yaw'] = packet.data['yaw'] self.client_info.position['pitch'] = packet.data['pitch'] self.client_info.position['on_ground'] = packet.data['on_ground'] self.client_info.update_stance() self.net.push(Packet(ident='PLAY>Player Position and Look', data=self.client_info.position)) self.emit('cl_position_update', self.client_info.position)
def eat(self): """ Attempts to eat the held item. Assumes held item implements eatable """ self.worldadapter.logger.debug('eating a bread') data = { 'location': self.get_int_coordinates(), 'direction': -1, 'held_item': { 'id': 297, 'amount': 1, 'damage': 0 }, 'cur_pos_x': -1, 'cur_pos_y': -1, 'cur_pos_z': -1 } self.net.push(Packet(ident='PLAY>Player Block Placement', data=data))
def sleep(self): """ Attempts to use the bed located at -103/63/59""" self.logger.debug('going to sleep') data = { 'location': { 'x': -103, 'y': 63, 'z': 59 }, 'direction': 1, 'held_item': { 'id': 297, 'amount': 0, 'damage': 0 }, 'cur_pos_x': -103, 'cur_pos_y': 63, 'cur_pos_z': 59 } self.spockplugin.net.push( Packet(ident='PLAY>Player Block Placement', data=data))
def revive(self, packet): if self.client.health['health'] <= 0: self.client.push(Packet(ident=0xCD, data={'payload': 1}))
def send_pm(self, user, message): self.client.push( Packet(ident=0x03, data={'text': "/msg %s %s" % (user, message)}))
from spock.mcp.mcpacket import Packet, read_packet from spock.bound_buffer import BoundBuffer from spock.mcp import mcdata p = Packet(ident=02, data={ 'protocol_version': mcdata.MC_PROTOCOL_VERSION, 'username': '******', 'host': 'localhost', 'port': 25565, }) b = Packet(ident=0xC9, data={ 'player_name': 'nickelpro', 'online': True, 'ping': 52 }) bbuff = BoundBuffer(p.encode() + b.encode()) packet = read_packet(bbuff) print packet packet = read_packet(bbuff) print packet
def echo_keep_alive(self, name, packet): self.net.push( Packet(ident='PLAY>Keep Alive', data={'keep_alive': packet.data['keep_alive']}))
def chat(self, message): # else push chat message self.net.push(Packet(ident='PLAY>Chat Message', data={'message': message}))
from spock.mcp.mcpacket import Packet, read_packet from spock.bound_buffer import BoundBuffer from spock.mcp import mcdata p = Packet( ident=02, data={"protocol_version": mcdata.MC_PROTOCOL_VERSION, "username": "******", "host": "localhost", "port": 25565}, ) b = Packet(ident=0xC9, data={"player_name": "nickelpro", "online": True, "ping": 52}) bbuff = BoundBuffer(p.encode() + b.encode()) packet = read_packet(bbuff) print packet packet = read_packet(bbuff) print packet
def change_held_item(self, target_slot): """ Changes the held item to a quick inventory slot """ self.net.push(Packet(ident='PLAY>Held Item Change', data={'slot': target_slot}))
def give_item(self, item, amount=1): message = "/item %s %d" % (str(item), amount) self.net.push(Packet(ident='PLAY>Chat Message', data={'message': message}))
def revive(self, packet): if self.client.health['health'] <= 0: self.client.push( Packet(ident='PLAY>Client Status', data={'action': 0}))
def close_window(self, name, packet): self.net.push( Packet(ident='PLAY>Close Window', data={'window_id': packet.data['window_id']}))
def send_respawn(self): self.net.push(Packet(ident='PLAY>Client Status', data={'action': 0}))