Ejemplo n.º 1
0
    def run(self):
        """Run the main program's logic."""

        # Change into the server's directory.
        os.chdir(self.args.server)

        # If we're only culling backups, do that and exit.
        if self.args.clean:
            return self.cull_backups()

        # Backups directory.
        backups = os.path.join(self.args.server, "backups")
        if not os.path.isdir(backups):
            log.info("Creating backups directory: {}".format(backups))
            os.mkdir(backups)

        # Connect to the Minecraft-Control server.
        log.info("Connecting to Minecraft control server...")
        self.client = MinecraftClient(
            host=self.config["host"],
            port=self.config["port"],
            password=self.config["password"],
            methods=[self.config["method"]],
        )
        self.client.add_handler("auth_ok", self.on_auth_ok)
        self.client.add_handler("auth_error", self.on_auth_error)
        self.client.add_handler("server_message", self.on_message)

        self.client.connect()
        self.client.start()
Ejemplo n.º 2
0
debug = False
host, port, password = None, None, None
whitelist = []

if sys.argv[1] == "--debug":
    debug = True
    host, port, password = sys.argv[2:5]
    whitelist = [x.lower() for x in sys.argv[5:]]
else:
    host, port, password = sys.argv[1:4]
    whitelist = [x.lower() for x in sys.argv[4:]]

# Connect to the server.
client = MinecraftClient(
    debug=debug,
    host=host,
    port=port,
    password=password,
)


def on_authed(client):
    print("Authentication successful!")
    client.sendline("say 01-gamemode.py demo started. Whitelist: {}".format(
        str(whitelist)))


def on_error(client, error):
    print("Failed to authenticate: {}".format(error))


def on_message(client, message):