Пример #1
0
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)
Пример #2
0
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)
Пример #3
0
def decode_nbt(data, compressed = True):
	if compressed:
		bbuff = BoundBuffer(zlib.decompress(data, wbits_length))
	else:
		bbuff = BoundBuffer(data)
	type = TAG_Byte(buffer = bbuff)
	name = TAG_String(buffer = bbuff).value
	tag = TAG_Compound(buffer = bbuff)
	tag.name = name
	return tag
Пример #4
0
def encode_nbt(data, compressed = True):
	bbuff = BoundBuffer()
	TAG_Byte(data.id)._render_buffer(bbuff)
	TAG_String(data.name)._render_buffer(bbuff)
	data._render_buffer(bbuff)
	if compressed:
		#Forced to use gzip to get the correct headers
		#Which means we have to hack around file objects
		gzipstring = io.StringIO()
		gzipfile = gzip.GzipFile(fileobj = gzipstring, mode = 'wb')
		gzipfile.write(bbuff.flush())
		gzipfile.close()
		return gzipstring.getvalue()
	else:
		return bbuff.flush()
Пример #5
0
def encode_nbt(data, compressed = True):
	bbuff = BoundBuffer()
	TAG_Byte(data.id)._render_buffer(bbuff)
	TAG_String(data.name)._render_buffer(bbuff)
	data._render_buffer(bbuff)
	if compressed:
		#Forced to use gzip to get the correct headers
		#Which means we have to hack around file objects
		gzipstring = StringIO.StringIO()
		gzipfile = gzip.GzipFile(fileobj = gzipstring, mode = 'wb')
		gzipfile.write(bbuff.flush())
		gzipfile.close()
		return gzipstring.getvalue()
	else:
		return bbuff.flush()
Пример #6
0
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