def initialize_bot(args, to_bot=None, to_gui=None): if args.log2file: logbot.start_bot_filelog() config.USERNAME = args.botname config.COMMANDER = args.commandername world = World(host=args.serverhost, port=args.serverport, commander_name=args.commandername, bot_name=args.botname, to_bot_q=to_bot, to_gui_q=to_gui) reactor.addSystemEventTrigger("before", "shutdown", world.on_shutdown) mc_factory = MineCraftFactory(world) world.reactor = reactor return world, mc_factory
def start(): parser = argparse.ArgumentParser(description="Bot arguments.") parser.add_argument("--serverhost", default=config.SERVER_HOST, dest="serverhost", help="Minecraft server host") parser.add_argument( "--serverport", type=int, default=config.SERVER_PORT, dest="serverport", help="Minecraft server port" ) parser.add_argument( "--botname", default=config.USERNAME, dest="botname", help="username that will be used by the bot" ) parser.add_argument( "--commandername", default=config.COMMANDER, dest="commandername", help="your username that you use in Minecraft", ) parser.add_argument("--log2file", action="store_true", help="Save log data to file") args = parser.parse_args() if args.log2file: logbot.start_bot_filelog() config.USERNAME = args.botname config.COMMANDER = args.commandername host = args.serverhost port = args.serverport world = World(host=host, port=port, commander_name=args.commandername, bot_name=args.botname) try: from twisted.internet import stdio stdio.StandardIO(ConsoleChat(world)) except ImportError: pass mc_factory = MineCraftFactory(world) def customKeyboardInterruptHandler(signum, stackframe): log.msg("CTRL-C from user, exiting....") mc_factory.log_connection_lost = False reactor.callFromThread(reactor.stop) signal.signal(signal.SIGINT, customKeyboardInterruptHandler) reactor.addSystemEventTrigger("before", "shutdown", world.on_shutdown) reactor.connectTCP(host, port, mc_factory) reactor.run()
def start(): parser = argparse.ArgumentParser(description='Bot arguments.') parser.add_argument('--serverhost', default=config.SERVER_HOST, dest='serverhost', help='Minecraft server host') parser.add_argument('--serverport', type=int, default=config.SERVER_PORT, dest='serverport', help='Minecraft server port') parser.add_argument('--botname', default=config.USERNAME, dest='botname', help='username that will be used by the bot') parser.add_argument('--botpass', default=config.PASSWORD, dest='botpass', help='password that will be used by the bot') parser.add_argument('--botemail', default=config.EMAIL, dest='botemail', help='email address that will be used by the bot') parser.add_argument('--onlinemode', action='store_true', help='Authenticate with Mojang') parser.add_argument('--use_encryption', action='store_true', help='use encryption, turned true if onlinemode used') parser.add_argument('--commandername', default=config.COMMANDER, dest='commandername', help='your username that you use in Minecraft') parser.add_argument('--log2file', action='store_true', help='Save log data to file') args = parser.parse_args() if args.log2file: logbot.start_bot_filelog() config.USERNAME = args.botname config.PASSWORD = args.botpass config.EMAIL = args.botemail config.USE_ENCRYPTION = args.use_encryption or args.onlinemode config.ONLINE_LOGIN = args.onlinemode if config.USE_ENCRYPTION: factory.import_encryption() config.COMMANDER = args.commandername.lower() host = args.serverhost port = args.serverport world = World(host=host, port=port, commander_name=args.commandername, bot_name=args.botname) try: from twisted.internet import stdio stdio.StandardIO(ConsoleChat(world)) except ImportError: log.msg("no terminal chat available") mc_factory = factory.MineCraftFactory(world) def customKeyboardInterruptHandler(signum, stackframe): log.msg("CTRL-C from user, exiting....") mc_factory.log_connection_lost = False reactor.callFromThread(reactor.stop) @inlineCallbacks def connect(): if config.ONLINE_LOGIN: yield mc_factory.online_auth() if mc_factory.clean_to_connect: reactor.connectTCP(host, port, mc_factory) connect() signal.signal(signal.SIGINT, customKeyboardInterruptHandler) reactor.addSystemEventTrigger("before", "shutdown", world.on_shutdown) reactor.run()
def start(): parser = argparse.ArgumentParser(description='Bot arguments.') parser.add_argument('--serverhost', default=config.SERVER_HOST, dest='serverhost', help='Minecraft server host') parser.add_argument('--serverport', type=int, default=config.SERVER_PORT, dest='serverport', help='Minecraft server port') parser.add_argument('--botname', default=config.USERNAME, dest='botname', help='username that will be used by the bot') parser.add_argument('--botpass', default=config.PASSWORD, dest='botpass', help='password that will be used by the bot') parser.add_argument('--botemail', default=config.EMAIL, dest='botemail', help='email address that will be used by the bot') parser.add_argument('--onlinemode', action='store_true', help='Authenticate with Mojang') parser.add_argument('--use_encryption', action='store_true', help='use encryption, turned true if onlinemode used') parser.add_argument('--commandername', default=config.COMMANDER, dest='commandername', help='your username that you use in Minecraft') parser.add_argument('--log2file', action='store_true', help='Save log data to file') args = parser.parse_args() if args.log2file: logbot.start_bot_filelog() config.USERNAME = args.botname config.PASSWORD = args.botpass config.EMAIL = args.botemail config.USE_ENCRYPTION = args.use_encryption or args.onlinemode config.ONLINE_LOGIN = args.onlinemode if config.USE_ENCRYPTION: factory.import_encryption() config.COMMANDER = args.commandername.lower() host = args.serverhost port = args.serverport world = World(host=host, port=port, commander_name=args.commandername, bot_name=args.botname) try: from twisted.internet import stdio stdio.StandardIO(ConsoleChat(world)) except ImportError: log.msg("no terminal chat available") mc_factory = factory.MineCraftFactory(world) def customKeyboardInterruptHandler(signum, stackframe): log.msg("CTRL-C from user, exiting....") mc_factory.log_connection_lost = False reactor.callFromThread(reactor.stop) @inlineCallbacks def connect(): if config.ONLINE_LOGIN: yield mc_factory.online_auth() if mc_factory.clean_to_connect: reactor.connectTCP(host, port, mc_factory) # connects to the minecraft server reactor.listenTCP(9393, WebClientFactory(world)) # listens for incoming connections - currently via telnet connect() signal.signal(signal.SIGINT, customKeyboardInterruptHandler) reactor.addSystemEventTrigger("before", "shutdown", world.on_shutdown) reactor.run()