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 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 handleBRECV(client): try: while True: client.rbuff.save() packet = read_packet(client.rbuff) client.dispatch_packet(packet) except BufferUnderflowException: client.rbuff.revert()
def handleSRECV(client): try: data = client.sock.recv(client.bufsize) client.rbuff.append(client.cipher.decrypt(data) if client.encrypted else data) except socket.error as error: logging.info(str(error)) try: while True: client.rbuff.save() packet = read_packet(client.rbuff) client.dispatch_packet(packet) except BufferUnderflowException: client.rbuff.revert()
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
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