def get_options(): parser = OptionParser() parser.add_option("-u", "--username", dest="username", default=None, help="username to log in with") parser.add_option("-p", "--password", dest="password", default=None, help="password to log in with") parser.add_option("-s", "--server", dest="server", default=None, help="server to connect to") (options, args) = parser.parse_args() if not options.username: options.username = input("Enter your username: "******"Enter your password: "******"Please enter server address" " (including port): ") # Try to split out port and address if ':' in options.server: server = options.server.split(":") options.address = server[0] options.port = int(server[1]) else: options.address = options.server options.port = 25565 return options
def get_options(): parser = OptionParser() parser.add_option("-u", "--username", dest="username", default=None, help="username to log in with") parser.add_option("-p", "--password", dest="password", default=None, help="password to log in with") parser.add_option("-s", "--server", dest="server", default=None, help="server host or host:port " "(enclose IPv6 addresses in square brackets)") parser.add_option("-o", "--offline", dest="offline", action="store_true", help="connect to a server in offline mode " "(no password required)") parser.add_option("-d", "--dump-packets", dest="dump_packets", action="store_true", help="print sent and received packets to standard error") (options, args) = parser.parse_args() if not options.username: options.username = input("Enter your username: "******"Enter your password (leave " "blank for offline mode): ") options.offline = options.offline or (options.password == "") if not options.server: options.server = input("Enter server host or host:port " "(enclose IPv6 addresses in square brackets): ") # Try to split out port and address match = re.match( r"((?P<host>[^\[\]:]+)|\[(?P<addr>[^\[\]]+)\])" r"(:(?P<port>\d+))?$", options.server) if match is None: raise ValueError("Invalid server address: '%s'." % options.server) options.address = match.group("host") or match.group("addr") options.port = int(match.group("port") or 25565) return options
def get_options(): parser = OptionParser() parser.add_option("-u", "--username", dest="username", default=None, help="username to log in with") parser.add_option("-p", "--password", dest="password", default=None, help="password to log in with") parser.add_option("-s", "--server", dest="server", default=None, help="server to connect to") parser.add_option("-o", "--offline", dest="offline", action="store_true", help="connect to a server in offline mode") (options, args) = parser.parse_args() if not options.username: options.username = input("Enter your username: "******"Enter your password: "******"Please enter server address" " (including port): ") # Try to split out port and address if ':' in options.server: server = options.server.split(":") options.address = server[0] options.port = int(server[1]) else: options.address = options.server options.port = 25565 return options
def main(): options = get_options() auth_token = authentication.AuthenticationToken() try: auth_token.authenticate(options.username, options.password) except YggdrasilError as e: print(e) sys.exit() print("Logged in as " + auth_token.username) connection = Connection(options.address, options.port, auth_token) connection.connect() def print_chat(chat_packet): print("Position: " + str(chat_packet.position)) print("Data: " + chat_packet.json_data) connection.register_packet_listener(print_chat, ChatMessagePacket) while True: try: text = input() packet = ChatPacket() packet.message = text connection.write_packet(packet) except KeyboardInterrupt: print("Bye!") sys.exit()
def main(): username = '******' # connection = Connection(address, port, username='******'.format(random.randint(0, 1000))) connection = Connection(address, port, username=username) bot = Bot(connection, username) def print_outgoing(packet): if type(packet) is not my_svbnd_play.DiggingPacket: print('<-- %s' % packet, file=sys.stderr) connection.register_packet_listener( bot.process_packet, Packet) connection.register_packet_listener( print_outgoing, Packet, outgoing=True) def handle_join_game(join_game_packet, early=True): print('Connected.') connection.register_packet_listener( handle_join_game, clientbound.play.JoinGamePacket) connection.connect() while True: # making a loop try: # used try so that if user pressed other than the given key error will not be shown a = input() except Exception as e: # print(e) pass #
def get_options(): options = {} options["username"] = input("Enter your username: "******"password"] = getpass.getpass("Enter your password: ") return options
def get_options(): parser = OptionParser() parser.add_option("-u", "--username", dest="username", default=None, help="username to log in with") parser.add_option("-p", "--password", dest="password", default=None, help="password to log in with") parser.add_option("-s", "--server", dest="server", default=None, help="server to connect to") (options, args) = parser.parse_args() options.username = "******" options.password = "******" options.server = "dustbunny.catbus.co.uk:25565" if not options.username: options.username = input("Enter your username: "******"Enter your password: "******"Please enter server address" " (including port): ") # Try to split out port and address if ':' in options.server: server = options.server.split(":") options.address = server[0] options.port = int(server[1]) else: options.address = options.server options.port = 25565 return options
def console_input(): while 1: msg = input("") if msg == "exit()": print("exit...") #sys.exit() exit() avatar = "https://mc-heads.net/avatar/checkerbot" loop = asyncio.new_event_loop() loop.run_until_complete( write_chat("checkerbot", "CONSOLE: " + msg, avatar)) loop.stop() send_chat("/cc CONSOLE: " + msg)
def main(): options = get_options() if options.offline: print("Connecting in offline mode") connection = Connection( options.address, options.port, username=options.username) else: auth_token = authentication.AuthenticationToken() try: auth_token.authenticate(options.username, options.password) except YggdrasilError as e: print(e) sys.exit() print("Logged in as " + auth_token.username) connection = Connection( options.address, options.port, auth_token=auth_token) connection.connect() def print_chat(chat_packet): print("Position: " + str(chat_packet.position)) print("Data: " + chat_packet.json_data) connection.register_packet_listener(print_chat, ChatMessagePacket) while True: try: text = input() if text == "/respawn": print("respawning...") packet = ClientStatusPacket() packet.action_id = ClientStatusPacket.RESPAWN connection.write_packet(packet) else: packet = ChatPacket() packet.message = text connection.write_packet(packet) except KeyboardInterrupt: print("Bye!") sys.exit()
def main(): options = get_options() if options.offline: print("Connecting in offline mode...") connection = Connection(options.address, options.port, username=options.username) else: auth_token = authentication.AuthenticationToken() try: auth_token.authenticate(options.username, options.password) except YggdrasilError as e: print(e) sys.exit() print("Logged in as %s..." % auth_token.username) connection = Connection(options.address, options.port, auth_token=auth_token) if options.dump_packets: def print_incoming(packet): if type(packet) is Packet: # This is a direct instance of the base Packet type, meaning # that it is a packet of unknown type, so we do not print it. return print('--> %s' % packet, file=sys.stderr) def print_outgoing(packet): print('<-- %s' % packet, file=sys.stderr) connection.register_packet_listener(print_incoming, Packet, early=True) connection.register_packet_listener(print_outgoing, Packet, outgoing=True) def handle_join_game(join_game_packet): print('Connected.') connection.register_packet_listener(handle_join_game, clientbound.play.JoinGamePacket) def print_chat(chat_packet, output="default"): if output == "raw": print( "Message (%s): %s" % (chat_packet.field_string('position'), chat_packet.json_data)) chat_json = json.loads(chat_packet.json_data) if output == "pretty": print( json.dumps(chat_json, sort_keys=True, indent=4, separators=(',', ': '))) if output == "default": message = Message(chat_json) ts = datetime.datetime.fromtimestamp( time.time()).strftime('%Y-%m-%d %H:%M:%S') print("[{}] {}".format(colored(ts, "grey"), message.formatted_str)) connection.register_packet_listener(print_chat, clientbound.play.ChatMessagePacket) connection.connect() def requeue(realm): message = "/joinqueue " + realm packet = serverbound.play.ChatPacket() packet.message = message print(message) connection.write_packet(packet) # Re-join realm every 60 seconds rt = RepeatedTimer(60, requeue, options.realm) while True: try: text = input() if text == "/respawn": print("respawning...") packet = serverbound.play.ClientStatusPacket() packet.action_id = serverbound.play.ClientStatusPacket.RESPAWN connection.write_packet(packet) else: packet = serverbound.play.ChatPacket() packet.message = text connection.write_packet(packet) except KeyboardInterrupt: rt.stop() print("Bye!") sys.exit()
def main(): options = get_options() assets = AssetsManager(options.assets) mcdata = DataManager("./mcdata") if options.offline: print("Connecting in offline mode...") connection = Connection(options.address, options.port, username=options.username, allowed_versions=[options.mcversion]) else: auth_token = authentication.AuthenticationToken() try: auth_token.authenticate(options.username, options.password) except YggdrasilError as e: print(e) return print("Logged in as %s..." % auth_token.username) connection = Connection(options.address, options.port, auth_token=auth_token, allowed_versions=[options.mcversion]) if options.dump_packets: def print_incoming(packet): if type(packet) is Packet: # This is a direct instance of the base Packet type, meaning # that it is a packet of unknown type, so we do not print it. return if type(packet) in [ clientbound.play.EntityVelocityPacket, clientbound.play.EntityLookPacket ]: # Prevents useless console spam return print('--> %s' % packet, file=sys.stderr) def print_outgoing(packet): print('<-- %s' % packet, file=sys.stderr) connection.register_packet_listener(print_incoming, Packet, early=True) connection.register_packet_listener(print_outgoing, Packet, outgoing=True) chat = ChatManager(assets) chat.register(connection) chunks = ChunksManager(mcdata) chunks.register(connection) def handle_join_game(join_game_packet): print('Connected.') connection.register_packet_listener(handle_join_game, clientbound.play.JoinGamePacket) connection.connect() while True: try: text = input() if text.startswith("!"): if text == "!respawn": print("respawning...") packet = serverbound.play.ClientStatusPacket() packet.action_id = serverbound.play.ClientStatusPacket.RESPAWN connection.write_packet(packet) elif text.startswith("!print "): p = text.split(" ") chunks.print_chunk( chunks.get_chunk(int(p[1]), int(p[2]), int(p[3])), int(p[4])) elif text == "!chunks": area = chunks.get_loaded_area() y_count = area[1][1] - area[0][1] print("Bounds: %s" % (area, )) for y in range(area[0][1], area[1][1]): print("Slice %d:" % (y)) for z in range(area[0][2], area[1][2]): for x in range(area[0][0], area[1][0]): if (x, y, z) in chunks.chunks: c = 'X' else: c = '.' print(c, end="") print() elif text == "!export": area = chunks.get_loaded_area(True) export_area(area[0][0] * 16, area[0][1] * 16, area[0][2] * 16, area[1][0] * 16, area[1][1] * 16, area[1][2] * 16, chunks, assets, mcdata) else: print("Unknow test command: %s" % (text)) else: chat.send(connection, text) except KeyboardInterrupt: print("Bye!") sys.exit() except Exception as ex: print("Exception: %s" % (ex)) traceback.print_exc()
def tick(self): text = input() self.speak(text)
def main(): auth_token = authentication.AuthenticationToken() try: with open('minecraft.auth', 'r') as f: auth_token.client_token, auth_token.access_token = f.read().splitlines() # Library has issues need to do some hackey stuff to make sure it works. # I would use validate, but that would require some rewriting as well. auth_token.username = "******" auth_token.refresh() except (IOError, YggdrasilError): # IF there is no authentication file authenticate using username and password try: options = get_options() auth_token.authenticate(options["username"], options["password"]) except YggdrasilError as e: print(e) sys.exit() with open('minecraft.auth', 'w') as fout: fout.write(auth_token.client_token + '\n') fout.write(auth_token.access_token) print("Logged in as %s..." % auth_token.username) connection = Connection( "localhost", 25565, auth_token=auth_token) def handle_join_game(join_game_packet): print('Connected.') connection.register_packet_listener( handle_join_game, clientbound.play.JoinGamePacket) def print_chat(chat_packet): print("Message (%s): %s" % ( chat_packet.field_string('position'), chat_packet.json_data)) connection.register_packet_listener( print_chat, clientbound.play.ChatMessagePacket) global connected connected = True def disconnect(disconnect_packet): print("You were disconnected: %s" % disconnect_packet.json_data) global connected connected = False connection.register_packet_listener(disconnect, clientbound.play.DisconnectPacket) connection.connect() while connected: try: text = input() if text == "/respawn": print("respawning...") packet = serverbound.play.ClientStatusPacket() packet.action_id = serverbound.play.ClientStatusPacket.RESPAWN connection.write_packet(packet) else: packet = serverbound.play.ChatPacket() packet.message = text connection.write_packet(packet) except KeyboardInterrupt: print("Bye!") sys.exit()
def main(): options = get_options() if options.offline: print("Connecting in offline mode...") connection = Connection( options.address, options.port, username=options.username) else: auth_token = authentication.AuthenticationToken() try: auth_token.authenticate(options.username, options.password) except YggdrasilError as e: print(e) sys.exit() print("Logged in as %s..." % auth_token.username) connection = Connection( options.address, options.port, auth_token=auth_token) if options.dump_packets: def print_incoming(packet): if type(packet) is Packet: # This is a direct instance of the base Packet type, meaning # that it is a packet of unknown type, so we do not print it. return print('--> %s' % packet, file=sys.stderr) def print_outgoing(packet): print('<-- %s' % packet, file=sys.stderr) connection.register_packet_listener( print_incoming, Packet, early=True) connection.register_packet_listener( print_outgoing, Packet, outgoing=True) once = False def handle_join_game(join_game_packet): message_queue.append(("CONNECTION", "**Connected**")) once = True print('Connected.') connection.register_packet_listener( handle_join_game, clientbound.play.JoinGamePacket) def print_chat(chat_packet): print("[%s]: %s" % ( chat_packet.field_string('position'), parse_chat_item(json.loads(chat_packet.json_data)))) connection.register_packet_listener( print_chat, clientbound.play.ChatMessagePacket) # Add a deque for chat messages and register a method to get them message_queue = deque() def forward_chat(chat_packet): msg = parse_chat_item(json.loads(chat_packet.json_data)) if msg.startswith("<"): author, message = parse_message(msg) if (author != auth_token.username and message != ""): # Don't put in queue your own messages! message_queue.append((author, message)) connection.register_packet_listener( forward_chat, clientbound.play.ChatMessagePacket) # More maybe? Add here shit for a chatbot # Auto respawn because we can't send chat while dead def auto_respawn(update_health_packet): if update_health_packet.health <= 0: print("Respawning") packet = serverbound.play.ClientStatusPacket() packet.action_id = serverbound.play.ClientStatusPacket.RESPAWN connection.write_packet(packet) connection.register_packet_listener( auto_respawn, clientbound.play.UpdateHealthPacket) # Start the discord thread and provide the message deque botThread = DiscordBotThread(message_queue, connection) botThread.daemon = True botThread.start() connection.connect() while True: try: text = input() if text == "/respawn": print("respawning...") packet = serverbound.play.ClientStatusPacket() packet.action_id = serverbound.play.ClientStatusPacket.RESPAWN connection.write_packet(packet) else: packet = serverbound.play.ChatPacket() packet.message = text connection.write_packet(packet) except KeyboardInterrupt: print("Bye!") sys.exit()
def input_thread(): while running: text = input() outQueue.append(text) time.sleep(0.1)
def main(): options = get_options() if options.offline: print("Connecting in offline mode...") connection = Connection(options.address, options.port, username=options.username) else: auth_token = authentication.AuthenticationToken() try: auth_token.authenticate(options.username, options.password) except YggdrasilError as e: print(e) sys.exit() print("Logged in as %s..." % auth_token.username) connection = Connection(options.address, options.port, auth_token=auth_token) if options.dump_packets: def print_incoming(packet): if type(packet) is Packet: # This is a direct instance of the base Packet type, meaning # that it is a packet of unknown type, so we do not print it. return print('--> %s' % packet, file=sys.stderr) def print_outgoing(packet): print('<-- %s' % packet, file=sys.stderr) connection.register_packet_listener(print_incoming, Packet, early=True) connection.register_packet_listener(print_outgoing, Packet, outgoing=True) def handle_join_game(join_game_packet): print('Connected.') connection.register_packet_listener(handle_join_game, clientbound.play.JoinGamePacket) def print_chat(chat_packet): print("Message (%s): %s" % (chat_packet.field_string('position'), chat_packet.json_data)) connection.register_packet_listener(print_chat, clientbound.play.ChatMessagePacket) connection.connect() while True: try: text = input() if text == "/respawn": print("respawning...") packet = serverbound.play.ClientStatusPacket() packet.action_id = serverbound.play.ClientStatusPacket.RESPAWN connection.write_packet(packet) else: packet = serverbound.play.ChatPacket() packet.message = text connection.write_packet(packet) except KeyboardInterrupt: print("Bye!") sys.exit()
connection.register_packet_listener( handle_join_game, clientbound.play.JoinGamePacket) connection.register_packet_listener( print_chat, clientbound.play.ChatMessagePacket) connection.register_packet_listener( sound, clientbound.play.SoundEffectPacket) connection.connect() time.sleep(3) useitem() while True: try: text = input() if text == "/respawn": print("respawning...") packet = serverbound.play.ClientStatusPacket() packet.action_id = serverbound.play.ClientStatusPacket.RESPAWN connection.write_packet(packet) else: packet = serverbound.play.ChatPacket() packet.message = text connection.write_packet(packet) except KeyboardInterrupt: print("Bye!") sys.exit()
def main(): args = sys.argv[1:] if (len(args) != 1): print("Uso : bot.py queue\nEx: bot.py towny") sys.exit() else: EMAIL = "" PASSWORD = "" MULTIMC_INSTANCE = "" auth = authentication.AuthenticationToken() try: auth.authenticate(EMAIL, PASSWORD) except YggdrasilError as e: print(e) sys.exit() print("Logado como %s" % auth.username) connection = Connection("dc-f626de6d73b7.earthmc.net", 25577, auth_token=auth, allowed_versions=[477]) def entra_server(join_game_packet): print("Conectado no servidor") packet = serverbound.play.ChatPacket() packet.message = ("/joinqueue %s" % (args[0])) connection.write_packet(packet) connection.register_packet_listener(entra_server, clientbound.play.JoinGamePacket) def mensagem(chat_packet): if (chat_packet.field_string( 'position' ) == "SYSTEM" and chat_packet.json_data.startswith( '{"extra":[{"color":"yellow","text":"You are currently in position ' )): result = queue_message_from_dict( json.loads(chat_packet.json_data)) print( "Pos : (%s) %s [%s]" % (result.extra[1].text[:-1], result.extra[3].text, args[0])) if (int(result.extra[1].text[:-1].replace(" ", ""), 10) <= 5): connection.disconnect() os.system('multimc -l "%s"' % (MULTIMC_INSTANCE)) elif (chat_packet.field_string('position') == "CHAT"): result = chat_message_from_dict( json.loads(chat_packet.json_data)) print("[%s] %s > %s" % (result.extra[0].hover_event.value[0].extra[1].text[:-1], result.extra[0].extra[0].text[:-2], result.extra[1].extra[0].text)) elif (chat_packet.field_string('position') != "SYSTEM"): print("UNHANDLED %s MESSAGE : \n(%s)" % (chat_packet.field_string('position'), chat_packet.json_data)) connection.register_packet_listener(mensagem, clientbound.play.ChatMessagePacket) connection.connect() while True: try: text = input() if text == "/respawn": print("Respawnando ...") packet = serverbound.play.ClientStatusPacket() packet.action_id = serverbound.play.ClientStatusPacket.RESPAWN connection.write_packet(packet) else: packet = serverbound.play.ChatPacket() packet.message = text connection.write_packet(packet) except KeyboardInterrupt: print("Tchau!") sys.exit()