示例#1
0
    def check_for_players(self):
        if not self._host_configured():
            return

        self.player_state.last_time_checked_players = timezone.now()
        self.player_state.save()
        rcon = MCRcon()

        try:
            rcon.connect(self.settings.ip_address, self.settings.rcon_port)
            rcon.login(self.settings.rcon_password)
            out = rcon.command('/list')
        except socket.error as e:
            # TODO: We should log errors if we get connection-refused
            # errors for too long.
            if e.errno != errno.ECONNREFUSED:
                logging.warning('Unexpected socket error when accessing '
                                'Minecraft RCON port: %s' % e)
            return 0

        m = NUM_PLAYERS_RE.match(out)

        if not m:
            logging.error('Invalid output from /list: %s' % out)
            return 0

        self.player_state.num_players = int(m.group(1))
        if self.player_state.num_players:
            self.player_state.last_time_seen_player = \
                self.player_state.last_time_checked_players
        self.player_state.save()
示例#2
0
    def check_for_players(self):
        if not self._host_configured():
            return

        self.player_state.last_time_checked_players = timezone.now()
        self.player_state.save()
        rcon = MCRcon()

        try:
            rcon.connect(self.settings.ip_address, self.settings.rcon_port)
            rcon.login(self.settings.rcon_password)
            out = rcon.command('/list')
        except socket.error as e:
            # TODO: We should log errors if we get connection-refused
            # errors for too long.
            if e.errno != errno.ECONNREFUSED:
                logging.warning('Unexpected socket error when accessing '
                                'Minecraft RCON port: %s' % e)
            return 0

        m = NUM_PLAYERS_RE.match(out)

        if not m:
            logging.error('Invalid output from /list: %s' % out)
            return 0

        self.player_state.num_players = int(m.group(1))
        if self.player_state.num_players:
            self.player_state.last_time_seen_player = \
                self.player_state.last_time_checked_players
        self.player_state.save()
示例#3
0
文件: droplet.py 项目: atraczyk/ood
    def _num_players(self):
        rcon = MCRcon()
        try:
            rcon.connect(self.droplet_ip, MINECRAFT_RCON_PORT)
            rcon.login(file(self.rcon_pw_path).read().strip())
            out = rcon.command('/list')
        except socket.error as e:
            # TODO: We should log errors if we get connection-refused
            # errors for too long.
            if e.errno != errno.ECONNREFUSED:
                logging.warning('Unexpected socket error when accessing '
                                'Minecraft RCON port: %s' % e)
            return 0

        m = NUM_PLAYERS_RE.match(out)

        if not m:
            logging.error('Invalid output from /list: %s' % out)
            return

        return int(m.group(1))