Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from socket import socket, AF_INET, SOCK_STREAM
- from sys import stderr, exit
- from threading import Thread
- from struct import pack, unpack, unpack_from, calcsize
- from reciver import *
- import random
- # Settings
- host = "127.0.0.1"
- port = 25566
- debug = False
- handshake = '\x0f\x00\x04\t127.0.0.1\xde\x02'.encode("utf-8")
- user = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
- def getRandomChar():
- return str(user[random.randint(0, len(user)-1)])
- def getRandomUsername():
- username = ''
- for x in range(0,9):
- username = username + getRandomChar()
- return username
- sock = socket(AF_INET, SOCK_STREAM)
- try:
- sock.connect((host, port))
- except ConnectionRefusedError:
- print("Server is not online", file=stderr)
- exit(1)
- def varint_pack(d):
- o = b''
- while True:
- b = d & 0x7F
- d >>= 7
- o += pack("B", b | (0x80 if d > 0 else 0))
- if d == 0:
- break
- return o
- def varint_unpack(s):
- d, l = 0, 0
- length = len(s)
- if length > 5:
- length = 5
- for i in range(length):
- l += 1
- b = s[i]
- d |= (b & 0x7F) << 7 * i
- if not b & 0x80:
- break
- return (d, s[l:])
- def data_pack(data):
- return varint_pack(len(data)) + data
- def data_unpack(bytes):
- length, bytes = varint_unpack(bytes)
- return bytes[:length], bytes[length:]
- def string_pack(string):
- return data_pack(string.encode())
- def string_unpack(bytes):
- string, rest = data_unpack(bytes)
- return string.decode(), rest
- def struct_unpack(format, struct):
- data = unpack_from(format, struct)
- rest = struct[calcsize(format):]
- return data, rest
- def send(id, packet):
- packid = varint_pack(int(id, 16))
- data = packet
- sock.sendall(data_pack(packid + data))
- def handshake(v, ip, port, next):
- version = varint_pack(v)
- host = string_pack(ip)
- port = pack('!H', port)
- next = varint_pack(next)
- return version + host + port + next
- def login(nick):
- nick = string_pack(nick)
- return nick
- send("0x00", handshake(47, "127.0.0.1", 25566, 2))
- send("0x00", login(getRandomUsername()))
- packet_listener.run(sock)
- reciver:
- import threading
- from leave import *
- class packet_listener(threading.Thread):
- def __init__(self,connection):
- threading.Thread.__init__(self)
- self.packet_functions = {
- 0xff: xd()
- }
- self.connection=connection
- def run(self):
- packet_functions=self.packet_functions
- connection=self.connection
- while True:
- fileobj = connection.makefile()
- packet_id = ord(fileobj.read(1))
- if packet_id in packet_functions:
- print(packet_functions[packet_id](fileobj, connection))
- leave:
- def xd():
- print("Kicked")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement