Ejemplo n.º 1
0
 def get(self, request):
     game = most_recent_game()
     return self.mobile_or_desktop(
         request, {
             'game': game,
             'participant': request.user.participant(game)
         })
Ejemplo n.º 2
0
 def handle(self, *args, **options):
     game = most_recent_game()
     unclaimed_codes = SupplyCode.objects.filter(game=game,
                                                 claimed_by__isnull=True)
     for code in unclaimed_codes:
         code.active = False
         code.save()
Ejemplo n.º 3
0
    def post(self, request):
        game = most_recent_game()
        participant = request.user.participant(game)
        message_players_form = MessagePlayersForm(request.POST,
                                                  player=participant)
        if not message_players_form.is_valid():
            return self.get(request, message_players_form=message_players_form)

        cd = message_players_form.cleaned_data
        recipients = []
        if cd['recipients'] == "All":
            recipients = Player.objects \
                .filter(game=game, active=True) \
                .values_list('user__email', flat=True)
        elif cd['recipients'] == "Zombies":
            if not participant.is_zombie:
                messages.error(request, "Only zombies can email only zombies.")
                return redirect('message_players')
            recipients = Player.objects \
                .filter(game=game, active=True, role=PlayerRole.ZOMBIE) \
                .values_list('user__email', flat=True)

        EmailMultiAlternatives(
            subject=f"Message from {request.user.get_full_name()}",
            body=cd['message'],
            from_email=settings.DEFAULT_FROM_EMAIL,
            to=[],
            bcc=recipients).send()

        if cd['recipients'] == "All":
            messages.success(request, "You've sent an email to all players.")
        elif cd['recipients'] == "Zombies":
            messages.success(request, "You've sent an email to all zombies.")
        return redirect('message_players')
Ejemplo n.º 4
0
    def post(self, request, signup_invite):
        game = most_recent_game()
        invite = SignupInvite.objects.get(pk=signup_invite)
        forced_role = invite.participant_role

        in_oz_pool = request.POST.get('is_oz', 'off') == 'on'
        has_signed_waiver = request.POST.get('accept_waiver', 'off') == 'on'

        if not has_signed_waiver:
            messages.warning(request, "Please sign the waiver.")
            return self.get(request)

        if request.user.participant(game):
            messages.warning(request,
                             f"You're already signed up for the {game} game.")
            return redirect('dashboard')

        if forced_role:
            if forced_role == ParticipantRole.MODERATOR:
                Moderator.objects.create_moderator(request.user, game)
            elif forced_role == ParticipantRole.SPECTATOR:
                Spectator.objects.create_spectator(request.user, game)
            else:
                equivalent_role = PlayerRole.HUMAN if forced_role == ParticipantRole.HUMAN else PlayerRole.ZOMBIE
                Player.objects.create_player(request.user, game,
                                             equivalent_role)
        else:
            Player.objects.create_player(request.user,
                                         game,
                                         PlayerRole.HUMAN,
                                         in_oz_pool=in_oz_pool)

        messages.success(
            request, f"You've successfully signed up for the {game} game.")
        return redirect('dashboard')
Ejemplo n.º 5
0
    def get(self, request):
        game = most_recent_game()

        participants = get_game_participants(game)
        spectators = Spectator.objects.filter(game=game)
        moderators = Moderator.objects.filter(game=game)
        humans = Player.objects.filter(game=game,
                                       active=True,
                                       role=PlayerRole.HUMAN)
        zombies = Player.objects.filter(game=game,
                                        active=True,
                                        role=PlayerRole.ZOMBIE)

        all_emails = [p.user.email for p in participants]
        spectator_emails = [s.user.email for s in spectators]
        moderator_emails = [m.user.email for m in moderators]
        human_emails = [h.user.email
                        for h in humans] + spectator_emails + moderator_emails
        zombie_emails = [z.user.email for z in zombies
                         ] + spectator_emails + moderator_emails

        return render(
            request, self.template_name, {
                'game': game,
                'participant': request.user.participant(game),
                'all_emails': all_emails,
                'human_emails': human_emails,
                'zombie_emails': zombie_emails,
            })
Ejemplo n.º 6
0
 def get_context(self, request, *args, **kwargs):
     context = super(AnnouncementPage, self).get_context(request)
     game = most_recent_game()
     participant = request.user.participant(game)
     context['participant'] = participant
     context['game'] = game
     return context
Ejemplo n.º 7
0
    def post(self, request):
        report_tag_form = ReportTagForm(request.POST)
        if not report_tag_form.is_valid():
            return render_player_info(request, report_tag_form=report_tag_form)

        game = most_recent_game()
        initiating_player = request.user.participant(game)

        cleaned_data = report_tag_form.cleaned_data
        receiver_code = cleaned_data['player_code'].upper()

        try:
            receiving_player = Player.objects.get(code=receiver_code,
                                                  active=True)
        except ObjectDoesNotExist:
            report_tag_form.add_error('player_code',
                                      "No player with that code exists.")
            return render_player_info(request, report_tag_form=report_tag_form)

        tag_modifier_amount = 0
        try:
            tag_modifier = Modifier.objects.get(
                faction=initiating_player.faction,
                modifier_type=ModifierType.TAG)
            tag_modifier_amount = tag_modifier.modifier_amount
        except ObjectDoesNotExist:
            pass

        if Tag.objects.filter(
                initiator=initiating_player,
                receiver=receiving_player,
                tagged_at=cleaned_data['datetime'],
                location=cleaned_data['location'],
                description=cleaned_data['description']).exists():
            return redirect('player_info')

        try:
            tag = Tag.objects.create_tag(initiating_player, receiving_player,
                                         cleaned_data['datetime'],
                                         cleaned_data['location'],
                                         cleaned_data['description'],
                                         tag_modifier_amount)
        except ValueError as err:
            messages.error(request, err)
            return redirect('player_info')

        if initiating_player.is_human:
            send_stun_email(request, tag)
            messages.success(
                request,
                f"You've successfully submitted a stun on {receiving_player.user.get_full_name()}."
            )
        else:
            send_tag_email(request, tag)
            messages.success(
                request,
                f"You've successfully submitted a tag on {receiving_player.user.get_full_name()}."
            )
        return redirect('player_info')
Ejemplo n.º 8
0
 def get(self, request):
     # While it would be nice to use running_game_required and player_required
     # due to the fact that we redirect here from login for all users we must
     # account for spectators/moderators and when the game isn't running as well.
     game = most_recent_game()
     if not game.is_running or not request.user.participant(
             game) or not request.user.participant(game).is_player:
         return redirect('dashboard')
     return render_player_info(request)
Ejemplo n.º 9
0
 def get(self, request):
     game = most_recent_game()
     supply_codes = SupplyCode.objects.filter(game=game, active=True)
     return render(
         request, self.template_name, {
             'game': game,
             'participant': request.user.participant(game),
             'supply_codes': supply_codes
         })
Ejemplo n.º 10
0
 def get(self, request):
     game = most_recent_game()
     players = Player.objects.filter(
         game=game, in_oz_pool=True).order_by('user__first_name')
     return render(
         request, self.template_name, {
             'game': game,
             'participant': request.user.participant(game),
             'players': players
         })
Ejemplo n.º 11
0
    def get(self, request):
        game = most_recent_game()
        participant = request.user.participant(game)
        participants = get_game_participants(game).order_by('user__first_name')

        return render(request, self.template_name, {
            'game': game,
            'participant': participant,
            'participants': participants
        })
Ejemplo n.º 12
0
    def get(self, request, **kwargs):
        game = most_recent_game()
        participant = request.user.participant(game)
        message_players_form = kwargs.get(
            'message_players_form', MessagePlayersForm(player=participant))

        return render(
            request, self.template_name, {
                'game': game,
                'participant': participant,
                'message_players_form': message_players_form
            })
Ejemplo n.º 13
0
    def post(self, request):
        minimum_score_threshold = 5
        game = most_recent_game()
        human_players = Player.objects.filter(game=game,
                                              role=PlayerRole.HUMAN,
                                              active=True)

        for human in human_players:
            if human.score() < minimum_score_threshold:
                human.kill()

        return redirect('manage_game')
Ejemplo n.º 14
0
    def get(self, request):
        game = most_recent_game()
        participant = request.user.participant(game)
        if not participant:
            return redirect('dashboard')

        if not request.user.is_staff and participant.is_player and participant.is_human:
            raise PermissionDenied

        player_codes = {}
        nodes = []
        edges = []
        ozs = set()
        all_zombies = Player.objects.filter(game=game,
                                            role=PlayerRole.ZOMBIE,
                                            active=True)
        for zombie in all_zombies:
            # We mutate the OZs' role rather than setting inactive, so an OZ won't have
            # an inactive human player.
            if not Player.objects.filter(game=game,
                                         code=zombie.code,
                                         role=PlayerRole.HUMAN).exists():
                ozs.add(zombie)

        nodes.append({'id': 'NECROMANCER', 'label': "Necromancer"})
        for oz in ozs:
            edges.append({'from': 'NECROMANCER', 'to': oz.code})
            player_codes[oz.code] = oz.user.get_full_name()

        tags = Tag.objects.filter(initiator__game=game,
                                  receiver__game=game,
                                  initiator__role=PlayerRole.ZOMBIE,
                                  receiver__role=PlayerRole.HUMAN,
                                  active=True)

        for tag in tags:
            edges.append({'from': tag.initiator.code, 'to': tag.receiver.code})

            player_codes[
                tag.initiator.code] = tag.initiator.user.get_full_name()
            player_codes[tag.receiver.code] = tag.receiver.user.get_full_name()

        for code, name in player_codes.items():
            nodes.append({'id': code, 'label': name})

        return render(
            request, self.template_name, {
                'game': game,
                'participant': participant,
                'nodes': json.dumps(nodes),
                'edges': json.dumps(edges),
            })
Ejemplo n.º 15
0
    def render_signup_players(
        self,
        request,
        volunteer_signup_player_form=VolunteerSignupPlayerForm()):
        game = most_recent_game()
        locations = SignupLocation.objects.filter(game=game)

        return render(
            request, self.template_name, {
                'game': game,
                'participant': request.user.participant(game),
                'signup_locations': locations,
                'volunteer_signup_player_form': volunteer_signup_player_form
            })
Ejemplo n.º 16
0
    def render_manage_players(
        self, request, mod_signup_player_form=ModeratorSignupPlayerForm()):
        game = most_recent_game()
        participants = get_game_participants(game).order_by('user__first_name')
        locations = SignupLocation.objects.filter(game=game)

        return render(
            request, self.template_name, {
                'game': game,
                'participant': request.user.participant(game),
                'participants': participants,
                'signup_locations': locations,
                'mod_signup_player_form': mod_signup_player_form
            })
Ejemplo n.º 17
0
    def is_viewable_by(self, participant) -> bool:
        game = most_recent_game()
        if self.game != game or not participant:
            return False

        if self.viewable_by == ViewableBy.ALL.value:
            return True
        if self.viewable_by == ViewableBy.HUMANS.value and participant.is_player and participant.is_human:
            return True
        if self.viewable_by == ViewableBy.ZOMBIES.value and participant.is_player and participant.is_zombie:
            return True
        if participant.is_spectator or participant.is_moderator or participant.user.is_staff:
            return True
        return False
Ejemplo n.º 18
0
    def get_context(self, request, *args, **kwargs):
        context = super(GameInfoPage, self).get_context(request)
        game = most_recent_game()
        participant = request.user.participant(game)
        context['is_mobile'] = request.user_agent.is_mobile
        context['participant'] = participant
        context['game'] = game

        announcements = self.get_children().type(AnnouncementPage).live().order_by('-first_published_at')
        viewable_announcements = [a for a in announcements if a.specific.is_viewable_by(participant)]
        context['announcements'] = viewable_announcements

        missions = self.get_children().type(MissionPage).live().order_by('-first_published_at')
        viewable_missions = [m for m in missions if m.specific.is_viewable_by(participant)]
        context['missions'] = viewable_missions
        return context
Ejemplo n.º 19
0
    def post(self, request):
        volunteer_signup_player_form = VolunteerSignupPlayerForm(request.POST)
        if not volunteer_signup_player_form.is_valid():
            return self.render_signup_players(
                request,
                volunteer_signup_player_form=volunteer_signup_player_form)

        game = most_recent_game()
        cleaned_data = volunteer_signup_player_form.cleaned_data
        location, email = cleaned_data['location'], cleaned_data['email']

        signup_invite = SignupInvite.objects.create_signup_invite(
            game, location, email)
        send_signup_email(request, signup_invite, game)
        messages.success(request, f"Sent a signup email to {email}.")
        return redirect('signup_players')
Ejemplo n.º 20
0
    def post(self, request):
        mod_signup_player_form = ModeratorSignupPlayerForm(request.POST)
        if not mod_signup_player_form.is_valid():
            return self.render_manage_players(
                request, mod_signup_player_form=mod_signup_player_form)

        game = most_recent_game()
        cleaned_data = mod_signup_player_form.cleaned_data
        location, email, participant_role = cleaned_data[
            'location'], cleaned_data['email'], cleaned_data[
                'participant_role']

        signup_invite = SignupInvite.objects.create_signup_invite(
            game, location, email, participant_role)
        send_signup_email(request, signup_invite, game)
        messages.success(request, f"Sent a signup email to {email}.")
        return redirect('manage_players')
Ejemplo n.º 21
0
    def post(self, request):
        game = most_recent_game()
        in_oz_pool = request.POST.get('is_oz', 'off') == 'on'
        has_signed_waiver = request.POST.get('accept_waiver', 'off') == 'on'

        if not has_signed_waiver:
            messages.warning(request, "Please sign the waiver.")
            return self.get(request)

        if request.user.participant(game):
            messages.warning(request,
                             f"You're already signed up for the {game} game.")
            return redirect('dashboard')

        Player.objects.create_player(request.user,
                                     game,
                                     PlayerRole.HUMAN,
                                     in_oz_pool=in_oz_pool)
        return redirect('dashboard')
Ejemplo n.º 22
0
    def get(self, request):
        game = most_recent_game()

        if request.user.participant(game):
            return redirect('dashboard')

        if game.is_running:
            messages.warning(
                request, "The game has already started please contact a mod.")
            return redirect('dashboard')

        if game.is_finished:
            messages.warning(request, "The game is over.")
            return redirect('dashboard')

        return render(request, "registration/game_signup.html", {
            'game': game,
            'participant_role': None
        })
Ejemplo n.º 23
0
def render_player_info(request,
                       report_tag_form=ReportTagForm(),
                       claim_supply_code_form=ClaimSupplyCodeForm()):
    template_name = "mobile/dashboard/player.html" if request.user_agent.is_mobile else "dashboard/player.html"

    game = most_recent_game()
    participant = request.user.participant(game)
    team_score = sum([
        p.score()
        for p in Player.objects.filter(game=game, role=participant.role)
    ])

    return render(
        request, template_name, {
            'game': game,
            'participant': participant,
            'team_score': team_score,
            'report_tag_form': report_tag_form,
            'claim_supply_code_form': claim_supply_code_form,
        })
Ejemplo n.º 24
0
    def get(self, request, signup_invite):
        game = most_recent_game()
        invite = SignupInvite.objects.get(pk=signup_invite)
        forced_role = invite.participant_role

        if request.user.participant(game):
            messages.warning(request, "You're already signed up for the game.")
            return redirect('dashboard')

        if game.is_running and not forced_role:
            messages.warning(
                request, "The game has already started please contact a mod.")
            return redirect('dashboard')

        if game.is_finished:
            messages.warning(request, "The game is over.")
            return redirect('dashboard')

        return render(request, "registration/game_signup.html", {
            'game': game,
            'participant_role': forced_role
        })
Ejemplo n.º 25
0
    def post(self, request):
        claim_supply_code_form = ClaimSupplyCodeForm(request.POST)
        if not claim_supply_code_form.is_valid():
            return render_player_info(
                request, claim_supply_code_form=claim_supply_code_form)

        game = most_recent_game()
        player = request.user.participant(game)

        cleaned_data = claim_supply_code_form.cleaned_data
        cleaned_supply_code = cleaned_data['code'].upper()
        try:
            supply_code = SupplyCode.objects.get(game=game,
                                                 code=cleaned_supply_code,
                                                 claimed_by__isnull=True,
                                                 active=True)
        except ObjectDoesNotExist:
            claim_supply_code_form.add_error(
                'code',
                "That supply code does not exist or has already been redeemed."
            )
            return render_player_info(
                request, claim_supply_code_form=claim_supply_code_form)

        if not player.is_human:
            messages.error(request, "Only humans can redeem supply codes.")
            return redirect('player_info')

        supply_code_modifier_amount = 0
        try:
            supply_code_modifier = Modifier.objects.get(
                faction=player.faction, modifier_type=ModifierType.SUPPLY_CODE)
            supply_code_modifier_amount = supply_code_modifier.modifier_amount
        except ObjectDoesNotExist:
            pass

        supply_code.claim(player, supply_code_modifier_amount)
        messages.success(request, "The code has been redeemed successfully.")
        return redirect('player_info')
Ejemplo n.º 26
0
 def get(self, request):
     game = most_recent_game()
     return self.mobile_or_desktop(request, {'game': game})
Ejemplo n.º 27
0
def get_signup_locations():
    return ((x.id, x)
            for x in SignupLocation.objects.filter(game=most_recent_game()))
Ejemplo n.º 28
0
 def post(self, request):
     game = most_recent_game()
     supply_code = SupplyCode.objects.create_supply_code(game)
     messages.success(request,
                      f"Generated new supply code \"{supply_code}\".")
     return redirect('generate_supply_codes')