Exemple #1
0
    def resolve_command(self, internal_message):
        command = self.command
        username = internal_message.split(" ", 1)[1]

        if "%PLR" in self.command:
            player = self.server.get_player_by_username(username)
            pos_kills = self.server.database.rank_kills(player.steam_id)
            pos_dosh = self.server.database.rank_dosh(player.steam_id)
            pos_time = self.server.database.rank_time(player.steam_id)

            command = command.replace("%PLR", player.username)
            command = command.replace(
                "%BCK", "back" if player.sessions > 1 else ""
            )

            command = command.replace("%DSH", str(player.total_dosh))
            command = command.replace("%DRK", str(pos_dosh))

            command = command.replace("%KLL", str(player.total_kills))
            command = command.replace("%KRK", str(pos_kills))

            command = command.replace(
                "%TME", seconds_to_hhmmss(player.total_time)
            )
            command = command.replace("%TRK", str(pos_time))
            command = command.replace("%SES", str(player.sessions))

        return command
Exemple #2
0
    def execute(self, username, args, admin):
        if not self.authorise(admin):
            return self.not_auth_message
        if len(args) < 2:
            return "Missing argument (username)"

        self.server.write_all_players()
        requested_username = "******".join(args[1:])

        player = self.server.get_player(requested_username)
        if player:
            now = datetime.datetime.now()
            elapsed_time = now - player.session_start
            session_time = elapsed_time.total_seconds()
        else:
            session_time = 0
            player = Player(requested_username, "no-perk")
            self.server.database.load_player(player)

        time = seconds_to_hhmmss(player.total_time + session_time)
        message = "Stats for {}:\n".format(player.username) +\
                  "Total play time: {} ({} sessions)\n"\
                      .format(time, player.total_logins) +\
                  "Total deaths: {}\n".format(player.total_deaths) +\
                  "Total kills: {}\n".format(millify(player.total_kills)) +\
                  "Total dosh earned: {}\n"\
                      .format(millify(player.total_dosh)) +\
                  "Dosh this game: {}".format(millify(player.game_dosh))

        return message
    def execute(self, username, args, admin):
        if not self.authorise(admin):
            return self.not_auth_message

        if args[0] == "new_game":
            logger.debug("Greeter received new game event")
            self.new_game_time = datetime.datetime.now()
            return None
        now = datetime.datetime.now()
        elapsed_time = now - self.new_game_time
        seconds = elapsed_time.total_seconds()

        if seconds < self.new_game_grace:
            logger.debug("Skipping welcome {}, new_game happened recently ({})"
                         " [{}/{}]".format(username, self.server.name, seconds,
                                           self.new_game_grace))
            return None

        if len(args) < 2:
            return "Missing argument (username)"

        requested_username = "******".join(args[1:])

        player = self.server.get_player(requested_username)
        if not player:
            logger.debug(
                "DEBUG: Bad player join command (not found) [{}]".format(
                    requested_username))
            return "Couldn't greet player {}.".format(requested_username)

        if player.total_logins > 1:
            pos_kills = self.server.database.rank_kills(requested_username)
            pos_dosh = self.server.database.rank_dosh(requested_username)
            return "\nWelcome back {}.\n" \
                   "You've killed {} zeds (#{}) and  \n" \
                   "earned £{} (#{}) \nover {} sessions " \
                   "({}).".format(player.username,
                                  millify(player.total_kills),
                                  pos_kills,
                                  millify(player.total_dosh),
                                  pos_dosh,
                                  player.total_logins,
                                  seconds_to_hhmmss(player.total_time))\
                .encode("iso-8859-1", "ignore")
        else:
            return None
    def execute(self, username, args, user_flags):
        args, err = self.parse_args(username, args, user_flags)
        if err:
            return err
        if args.help:
            return self.format_response(self.help_text, args)

        records = self.server.database.top_time()

        message = _("Top 5 players by play time:\n")

        for player in records[:5]:
            username = trim_string(player['username'], 20)
            time = seconds_to_hhmmss(player['score'])
            message += "\t{}\t-   {}\n".format(time, username)

        return self.format_response(message[:-1], args)
def test_seconds_to_hhmmss():
    tests = [{
        "seconds": 12,
        "expected": "00:00:12"
    }, {
        "seconds": 0,
        "expected": "00:00:00"
    }, {
        "seconds": 60 * 60 * 3,
        "expected": "03:00:00"
    }, {
        "seconds": 71237934,
        "expected": "19788:18:54"
    }]

    for test in tests:
        result = seconds_to_hhmmss(test["seconds"])
        assert result == test["expected"]
Exemple #6
0
    def execute(self, username, args, user_flags):
        args, err = self.parse_args(username, args, user_flags)
        if err:
            return err
        elif args.help:
            return self.format_response(self.help_text, args)

        self.server.write_all_players()

        if args.username:
            username = "******".join(args.username)

        print(username)

        player = self.server.get_player_by_username(username)
        if player:
            # TODO: Move this ...
            now = time.time()
            elapsed_time = now - player.session_start
        else:
            elapsed_time = 0
            player = Player(username, "no-perk")
            self.server.database.load_player(player)

        # ... And this
        fmt_time = seconds_to_hhmmss(player.total_time + elapsed_time)

        pos_kills = self.server.database.rank_kills(player.steam_id) or 0
        pos_dosh = self.server.database.rank_dosh(player.steam_id) or 0
        # todo Add pos_time to output
        # pos_time = self.server.database.rank_time(player.steam_id) or 0

        message = "Stats for {}:\n" \
            "Total play time: {} ({} sessions)\n" \
            "Total deaths: {}\n" \
            "Total kills: {} (rank #{}) \n" \
            "Total dosh earned: £{} (rank #{})\n" \
            "Dosh this game: {}".format(
                player.username, fmt_time, player.sessions,
                player.total_deaths, millify(player.total_kills), pos_kills,
                millify(player.total_dosh), pos_dosh, millify(player.game_dosh)
            )

        return self.format_response(message, args)