Ejemplo n.º 1
0
    def execute(cls, spyd_server, room, client, command_string, arguments, raw_args):
        if len(arguments):
            if room.temporary:
                if not client.allowed(set_temporary_room_timeleft):
                    raise InsufficientPermissions(set_temporary_room_timeleft.denied_message)
            else:
                if not client.allowed(set_permanent_room_timeleft):
                    raise InsufficientPermissions(set_permanent_room_timeleft.denied_message)

            try:
                modifier, value = timestring.parseTimeString(raw_args)

                if modifier == '+':
                    new_timeleft = min(MAXTIMELEFT, max(0, room.timeleft + value))
                elif modifier == '-':
                    new_timeleft = min(MAXTIMELEFT, max(0, room.timeleft - value))
                elif modifier == '=':
                    new_timeleft = min(MAXTIMELEFT, max(0, value))

                timeleft = prettytime.createDurationString(new_timeleft)
                room._broadcaster.server_message(info(timeleft_set_str, client=client, timeleft=timeleft))

                room.timeleft = new_timeleft

            except timestring.MalformedTimeString:
                raise GenericError("Invalid time string specified.")
        else:
            timeleft = prettytime.createDurationString(room.timeleft)
            client.send_server_message(info(timeleft_get_str, timeleft=timeleft))
Ejemplo n.º 2
0
    def on_player_disconnected(self, player):
        if self._tist_state == tist_states.WAITING_TRAITOR:
            if self.room.playing_count < self.min_players:
                self._tist_traitor_waiting_deferred.cancel()
                self._waiting_players_message()
        elif self._tist_state == tist_states.WAITING_PLAYERS:
            self._waiting_players_message()
        elif self._tist_state == tist_states.PLAYING:
            if player is self._tist_traitor:
                self.room._broadcaster.server_message(
                    info('The traitor, {name#traitor}, has left the game.',
                         traitor=player))
                self._ended()
            else:
                alive_non_traitorous_players = [
                    p for p in self.room.players
                    if p.state.is_alive and p is not self._tist_traitor
                ]

                if len(alive_non_traitorous_players) == 0:
                    self.room._broadcaster.server_message(
                        info(
                            'The the last living innocent player, {name#player}, has left the game. The traitor, {name#traitor}, is victorious.',
                            traitor=self._tist_traitor,
                            player=player))
Ejemplo n.º 3
0
 def _select_traitor(self, player):
     self._tist_traitor = player
     self._tist_state = tist_states.PLAYING
     self.room._broadcaster.server_message(info('The traitor has been selected. Trust no one!'))
     player.client.send_server_message(info('You are the traitor! Go kill them all...sneakily.'))
     for player in self.room.players:
         ModeBase.on_player_request_spawn(self, player)
     self.room._broadcaster.sound(12)
Ejemplo n.º 4
0
 def _start_info_message(self):
     self.room._broadcaster.server_message(
         info(
             'Welcome to the Trouble in SauerTown gamemode. The first player to press their taunt bind will be the traitor.'
         ))
     self.room._broadcaster.server_message(
         info(
             'If no players do this a traitor will be selected at random in 5 seconds.'
         ))
Ejemplo n.º 5
0
 def _select_traitor(self, player):
     self._tist_traitor = player
     self._tist_state = tist_states.PLAYING
     self.room._broadcaster.server_message(
         info('The traitor has been selected. Trust no one!'))
     player.client.send_server_message(
         info('You are the traitor! Go kill them all...sneakily.'))
     for player in self.room.players:
         ModeBase.on_player_request_spawn(self, player)
     self.room._broadcaster.sound(12)
Ejemplo n.º 6
0
    def handle(room, client, pause):
        if not client.allowed(pause_resume_functionality):
            raise InsufficientPermissions(pause_resume_functionality.denied_message)

        if pause:
            if room.is_paused and not room.is_resuming: raise StateError('The game is already paused.')
            room.pause()
            room._broadcaster.server_message(info("{name#client} has paused the game.", client=client))
        elif not pause:
            if not room.is_paused: raise StateError('The game is already resumed.')
            room.resume()
            room._broadcaster.server_message(info("{name#client} has resumed the game.", client=client))
Ejemplo n.º 7
0
    def execute(cls, spyd_server, room, client, command_string, arguments,
                raw_args):
        try:
            cn, mode_name, map_name = parse_arguments(raw_args)

            if mode_name is not None:
                valid_mode_names = list(gamemodes.keys())
                mode_name_match = match_fuzzy(str(mode_name), valid_mode_names)

                if mode_name_match is None:
                    raise GenericError(
                        'Could not resolve mode name {value#mode_name} to valid mode. Please try again.',
                        mode_name=mode_name)

                mode_name = mode_name_match

            if map_name is not None:
                map_name = yield resolve_map_name(room, map_name)

            duel_command_msg = duel_command.format(client=client)
            challenge_details = get_challenge_details(mode_name, map_name)

            if cn is not None:
                target = room.get_client(int(cn))
                if target is client:
                    raise GenericError("You can't duel yourself.")

                existing_challenge = get_existing_challenge(target, client)

                if existing_challenge is not None:
                    begin_duel(room, client, target, existing_challenge)

                else:
                    save_specific_challenge(client, target, mode_name,
                                            map_name)
                    target.send_server_message(
                        info(cn_chall_msg,
                             client=client,
                             challenge_details=challenge_details,
                             duel_command=duel_command_msg))
                    client.send_server_message(info(chall_sent_msg))

            else:
                save_general_challenge(client, mode_name, map_name)
                room.server_message(info(looking_msg,
                                         client=client,
                                         challenge_details=challenge_details,
                                         duel_command=duel_command_msg),
                                    exclude=(client, ))
                client.send_server_message(info(chall_sent_msg))
        except:
            traceback.print_exc()
Ejemplo n.º 8
0
 def execute(cls, spyd_server, room, client, command_string, arguments,
             raw_args):
     if len(arguments):
         try:
             room.resume_delay = max(0, min(10, int(arguments[0])))
             room._broadcaster.server_message(
                 info(
                     "{name#client} has set the resume delay to {value#resume_delay} seconds.",
                     client=client,
                     resume_delay=room.resume_delay))
         except:
             raise UsageError("The resume delay must be an number.")
     else:
         client.send_server_message(
             info("The resume delay is {value#resume_delay} seconds.",
                  resume_delay=room.resume_delay))
Ejemplo n.º 9
0
    def client_change_room(client, target_room, announce_follow=True):
        player = client.get_player()

        try:
            room_entry_context = target_room.get_entry_context(client, player)
        except RoomEntryFailure as e:
            raise GenericError(e.message)

        if announce_follow:
            client.room._broadcaster.server_message(info(
                "{name#client} is leaving to join {room#room}. Use {action#follow} to go there too.",
                client=client,
                room=target_room,
                follow="follow"),
                                                    exclude=[client])

        old_room = client.room

        old_room.client_leave(client)

        old_room.last_destination_room = target_room.name

        client.room = target_room

        target_room.client_enter(room_entry_context)
Ejemplo n.º 10
0
    def on_player_disconnected(self, player):
        if self._tist_state == tist_states.WAITING_TRAITOR:
            if self.room.playing_count < self.min_players:
                self._tist_traitor_waiting_deferred.cancel()
                self._waiting_players_message()
        elif self._tist_state == tist_states.WAITING_PLAYERS:
            self._waiting_players_message()
        elif self._tist_state == tist_states.PLAYING:
            if player is self._tist_traitor:
                self.room._broadcaster.server_message(info('The traitor, {name#traitor}, has left the game.', traitor=player))
                self._ended()
            else:
                alive_non_traitorous_players = filter(lambda p: p.state.is_alive and p is not self._tist_traitor, self.room.players)

                if len(alive_non_traitorous_players) == 0:
                    self.room._broadcaster.server_message(info('The the last living innocent player, {name#player}, has left the game. The traitor, {name#traitor}, is victorious.', traitor=self._tist_traitor, player=player))
Ejemplo n.º 11
0
 def _waiting_players_message(self):
     deficit = self.min_players - self.room.playing_count
     format_args = {
                    'min_players': self.min_players,
                    'deficit': deficit,
                    'pl': 's' if deficit > 1 else '',
                    }
     self.room._broadcaster.server_message(info('The Trouble in SauerTown gamemode must be played with at least {min_players} players. Waiting for {deficit} more player{pl}.'.format(**format_args)))
Ejemplo n.º 12
0
    def handle(room, client, pause):
        if not client.allowed(pause_resume_functionality):
            raise InsufficientPermissions(
                pause_resume_functionality.denied_message)

        if pause:
            if room.is_paused and not room.is_resuming:
                raise StateError('The game is already paused.')
            room.pause()
            room._broadcaster.server_message(
                info(f"{client.get_player().name} has paused the game."))
        elif not pause:
            if not room.is_paused:
                raise StateError('The game is already resumed.')
            room.resume()
            room._broadcaster.server_message(
                info(f"{client.get_player().name} has resumed the game."))
Ejemplo n.º 13
0
    def execute(cls, spyd_server, room, client, command_string, arguments, raw_args):
        if len(arguments):
            player = room.get_player(int(arguments[0]))
        else:
            player = client.get_player()

        time_online_str = shortDurationString(player.client.time_online)
        client.send_server_message(info(stats_msg, player=player, time_online_str=time_online_str))
Ejemplo n.º 14
0
    def execute(cls, spyd_server, room, client, command_string, arguments, raw_args):
        if len(arguments):
            target = room.get_client(int(arguments[0]))
        else:
            target = client
            
        formatted_groups = ", ".join(map(lambda group: smf.format("{value#group}", group=group), target._client_permissions.get_group_names()))

        client.send_server_message(info("groups: {formatted_groups}", formatted_groups=formatted_groups))
Ejemplo n.º 15
0
    def on_auth_success(self, auth_success):
        if auth_success is not None:
            self.client.add_group_name_provider(auth_success.group_provider)

            if auth_success.room_message is not None and self.client.connection_sequence_complete:
                auth_success.room_message_kwargs['client'] = self.client
                self.client.room._broadcaster.server_message(info(auth_success.room_message, **auth_success.room_message_kwargs))

        self.auth_deferred.callback(auth_success)
        self.auth_deferred = None
Ejemplo n.º 16
0
 def _waiting_players_message(self):
     deficit = self.min_players - self.room.playing_count
     format_args = {
         'min_players': self.min_players,
         'deficit': deficit,
         'pl': 's' if deficit > 1 else '',
     }
     self.room._broadcaster.server_message(
         info(
             'The Trouble in SauerTown gamemode must be played with at least {min_players} players. Waiting for {deficit} more player{pl}.'
             .format(**format_args)))
Ejemplo n.º 17
0
    def on_player_death(self, player, killer):
        if self._tist_state == tist_states.PLAYING:
            player.client.send_server_message(info('You have been betrayed, choose your friends more wisely.'))

            alive_non_traitorous_players = filter(lambda p: p.state.is_alive and p is not self._tist_traitor, self.room.players)

            if player is self._tist_traitor:
                if player is killer:
                    self.room._broadcaster.server_message(info('The traitor, {name#traitor}, has suicided.', traitor=player))
                else:
                    self.room._broadcaster.server_message(info('The traitor, {name#traitor}, has been put down by {name#killer}.', killer=killer, traitor=player))
                self._ended()
            else:
                if len(alive_non_traitorous_players) == 0:
                    if killer is self._tist_traitor:
                        self.room._broadcaster.server_message(info('The traitor, {name#traitor}, has slaughtered all the innocents, claiming victory.', traitor=killer))
                    else:
                        self.room._broadcaster.server_message(info('The last innocent has died. The traitor, {name#traitor}, is victorious.', traitor=killer))
                    self._ended()

        ModeBase.on_player_death(self, player, killer)
Ejemplo n.º 18
0
    def on_auth_success(self, auth_success):
        if auth_success is not None:
            self.client.add_group_name_provider(auth_success.group_provider)

            if auth_success.room_message is not None and self.client.connection_sequence_complete:
                auth_success.room_message_kwargs['client'] = self.client
                self.client.room._broadcaster.server_message(
                    info(auth_success.room_message,
                         **auth_success.room_message_kwargs))

        self.auth_deferred.callback(auth_success)
        self.auth_deferred = None
Ejemplo n.º 19
0
Archivo: duel.py Proyecto: fdChasm/spyd
    def execute(cls, spyd_server, room, client, command_string, arguments, raw_args):
        try:
            cn, mode_name, map_name = parse_arguments(raw_args)

            if mode_name is not None:
                valid_mode_names = gamemodes.keys()
                mode_name_match = match_fuzzy(str(mode_name), valid_mode_names)

                if mode_name_match is None:
                    raise GenericError('Could not resolve mode name {value#mode_name} to valid mode. Please try again.', mode_name=mode_name)

                mode_name = mode_name_match

            if map_name is not None:
                map_name = yield resolve_map_name(room, map_name)

            duel_command_msg = duel_command.format(client=client)
            challenge_details = get_challenge_details(mode_name, map_name)

            if cn is not None:
                target = room.get_client(int(cn))
                if target is client:
                    raise GenericError("You can't duel yourself.")

                existing_challenge = get_existing_challenge(target, client)

                if existing_challenge is not None:
                    begin_duel(room, client, target, existing_challenge)

                else:
                    save_specific_challenge(client, target, mode_name, map_name)
                    target.send_server_message(info(cn_chall_msg, client=client, challenge_details=challenge_details, duel_command=duel_command_msg))
                    client.send_server_message(info(chall_sent_msg))

            else:
                save_general_challenge(client, mode_name, map_name)
                room.server_message(info(looking_msg, client=client, challenge_details=challenge_details, duel_command=duel_command_msg), exclude=(client,))
                client.send_server_message(info(chall_sent_msg))
        except:
            traceback.print_exc()
Ejemplo n.º 20
0
    def on_player_death(self, player, killer):
        if self._tist_state == tist_states.PLAYING:
            player.client.send_server_message(
                info('You have been betrayed, choose your friends more wisely.'
                     ))

            alive_non_traitorous_players = [
                p for p in self.room.players
                if p.state.is_alive and p is not self._tist_traitor
            ]

            if player is self._tist_traitor:
                if player is killer:
                    self.room._broadcaster.server_message(
                        info('The traitor, {name#traitor}, has suicided.',
                             traitor=player))
                else:
                    self.room._broadcaster.server_message(
                        info(
                            'The traitor, {name#traitor}, has been put down by {name#killer}.',
                            killer=killer,
                            traitor=player))
                self._ended()
            else:
                if len(alive_non_traitorous_players) == 0:
                    if killer is self._tist_traitor:
                        self.room._broadcaster.server_message(
                            info(
                                'The traitor, {name#traitor}, has slaughtered all the innocents, claiming victory.',
                                traitor=killer))
                    else:
                        self.room._broadcaster.server_message(
                            info(
                                'The last innocent has died. The traitor, {name#traitor}, is victorious.',
                                traitor=killer))
                    self._ended()

        ModeBase.on_player_death(self, player, killer)
Ejemplo n.º 21
0
    def execute(cls, spyd_server, room, client, command_string, arguments,
                raw_args):
        if len(arguments):
            target = room.get_client(int(arguments[0]))
        else:
            target = client

        formatted_groups = ", ".join([
            smf.format("{value#group}", group=group)
            for group in target._client_permissions.get_group_names()
        ])

        client.send_server_message(
            info("groups: {formatted_groups}",
                 formatted_groups=formatted_groups))
Ejemplo n.º 22
0
    def execute(cls, spyd_server, room, client, command_string, arguments,
                raw_args):
        if len(arguments):
            if room.temporary:
                if not client.allowed(set_temporary_room_timeleft):
                    raise InsufficientPermissions(
                        set_temporary_room_timeleft.denied_message)
            else:
                if not client.allowed(set_permanent_room_timeleft):
                    raise InsufficientPermissions(
                        set_permanent_room_timeleft.denied_message)

            try:
                modifier, value = timestring.parseTimeString(raw_args)

                if modifier == '+':
                    new_timeleft = min(MAXTIMELEFT,
                                       max(0, room.timeleft + value))
                elif modifier == '-':
                    new_timeleft = min(MAXTIMELEFT,
                                       max(0, room.timeleft - value))
                elif modifier == '=':
                    new_timeleft = min(MAXTIMELEFT, max(0, value))

                timeleft = prettytime.createDurationString(new_timeleft)
                room._broadcaster.server_message(
                    info(timeleft_set_str, client=client, timeleft=timeleft))

                room.timeleft = new_timeleft

            except timestring.MalformedTimeString:
                raise GenericError("Invalid time string specified.")
        else:
            timeleft = prettytime.createDurationString(room.timeleft)
            client.send_server_message(
                info(timeleft_get_str, timeleft=timeleft))
Ejemplo n.º 23
0
    def client_change_room(client, target_room, announce_follow=True):
        player = client.get_player()

        try:
            room_entry_context = target_room.get_entry_context(client, player)
        except RoomEntryFailure as e:
            raise GenericError(e.message)

        if announce_follow:
            client.room._broadcaster.server_message(info("{name#client} is leaving to join {room#room}. Use {action#follow} to go there too.", client=client, room=target_room, follow="follow"), exclude=[client])

        old_room = client.room

        old_room.client_leave(client)

        old_room.last_destination_room = target_room.name

        client.room = target_room

        target_room.client_enter(room_entry_context)
Ejemplo n.º 24
0
 def execute(cls, spyd_server, room, client, command_string, arguments,
             raw_args):
     for room in room.manager.rooms.values():
         if room.empty: continue
         client.send_server_message(info(room_info_msg, room=room))
Ejemplo n.º 25
0
 def on_player_request_spawn(self, player):
     if self._tist_state == tist_states.PLAYING:
         player.client.send_server_message(info('Please wait until the next round to spawn.'))
     else:
         ModeBase.on_player_request_spawn(self, player)
Ejemplo n.º 26
0
 def _start_info_message(self):
     self.room._broadcaster.server_message(info('Welcome to the Trouble in SauerTown gamemode. The first player to press their taunt bind will be the traitor.'))
     self.room._broadcaster.server_message(info('If no players do this a traitor will be selected at random in 5 seconds.'))
Ejemplo n.º 27
0
 def execute(cls, spyd_server, room, client, command_string, arguments,
             raw_args):
     client.send_server_message(info(spyd_server.server_info_model.value))
Ejemplo n.º 28
0
 def on_player_request_spawn(self, player):
     if self._tist_state == tist_states.PLAYING:
         player.client.send_server_message(
             info('Please wait until the next round to spawn.'))
     else:
         ModeBase.on_player_request_spawn(self, player)
Ejemplo n.º 29
0
 def execute(cls, spyd_server, room, client, command_string, arguments, raw_args):
     for room in room.manager.rooms.itervalues():
         if room.empty: continue
         client.send_server_message(info(room_info_msg, room=room))