Пример #1
0
    def func(self):

        caller = self.caller

        if self.args == 'all':
            table = self.styled_table("|wName", "|wRoom")
            sessions = SESSION_HANDLER.get_sessions()
            for session in sessions:
                puppet = session.get_puppet()
                if puppet:
                    location = puppet.location
                    locname = location.key if location else "(Outside somewhere)"
                    table.add_row(puppet, locname)
                else:
                    account = session.get_account()
                    table.add_row(account.get_display_name(caller), "(OOC)")

            txt = (f"|cPlayers active on this server|n:\n{table}\n"
                   "(use 'who' to see only those in your room)")

        else:
            chars = [
                f"{obj.get_display_name(caller)} - {obj.db.desc.strip()}"
                for obj in self.room.get_all_characters() if obj != caller
            ]
            chars = "\n".join(
                [f"{caller.key} - {caller.db.desc.strip()} (you)"] + chars)
            txt = (
                f"|cPlayers in this room (room-name '{self.room.name}')|n:\n  {chars}"
            )
        caller.msg(txt)
Пример #2
0
def _gamestats():
    # Some misc. configurable stuff.
    # TODO: Move this to either SQL or settings.py based configuration.
    fpage_player_limit = 4

    # A QuerySet of the most recently connected players.
    recent_users = PlayerDB.objects.get_recently_connected_players()[:fpage_player_limit]
    nplyrs_conn_recent = len(recent_users) or "none"
    nplyrs = PlayerDB.objects.num_total_players() or "none"
    nplyrs_reg_recent = len(PlayerDB.objects.get_recently_created_players()) or "none"
    nsess = SESSION_HANDLER.player_count()
    # nsess = len(PlayerDB.objects.get_connected_players()) or "no one"

    nobjs = ObjectDB.objects.all().count()
    nrooms = ObjectDB.objects.filter(db_location__isnull=True).exclude(db_typeclass_path=_BASE_CHAR_TYPECLASS).count()
    nexits = ObjectDB.objects.filter(db_location__isnull=False, db_destination__isnull=False).count()
    nchars = ObjectDB.objects.filter(db_typeclass_path=_BASE_CHAR_TYPECLASS).count()
    nothers = nobjs - nrooms - nchars - nexits

    pagevars = {
        "page_title": "Front Page",
        "players_connected_recent": recent_users,
        "num_players_connected": nsess or "no one",
        "num_players_registered": nplyrs or "no",
        "num_players_connected_recent": nplyrs_conn_recent or "no",
        "num_players_registered_recent": nplyrs_reg_recent or "no one",
        "num_rooms": nrooms or "none",
        "num_exits": nexits or "no",
        "num_objects": nobjs or "none",
        "num_characters": nchars or "no",
        "num_others": nothers or "no",
    }
    return pagevars
Пример #3
0
def _gamestats():
    # Some misc. configurable stuff.
    # TODO: Move this to either SQL or settings.py based configuration.
    fpage_account_limit = 4

    # A QuerySet of the most recently connected accounts.
    recent_users = AccountDB.objects.get_recently_connected_accounts()[:fpage_account_limit]
    nplyrs_conn_recent = len(recent_users)
    nplyrs = AccountDB.objects.num_total_accounts()
    nplyrs_reg_recent = len(AccountDB.objects.get_recently_created_accounts())
    nsess = SESSION_HANDLER.account_count()
    # nsess = len(AccountDB.objects.get_connected_accounts()) or "no one"

    nobjs = ObjectDB.objects.all().count()
    nrooms = ObjectDB.objects.filter(db_location__isnull=True).exclude(db_typeclass_path=_BASE_CHAR_TYPECLASS).count()
    nexits = ObjectDB.objects.filter(db_location__isnull=False, db_destination__isnull=False).count()
    nchars = ObjectDB.objects.filter(db_typeclass_path=_BASE_CHAR_TYPECLASS).count()
    nothers = nobjs - nrooms - nchars - nexits

    pagevars = {
        "page_title": "Front Page",
        "players_connected_recent": recent_users,
        "num_players_connected": nsess,
        "num_players_registered": nplyrs,
        "num_players_connected_recent": nplyrs_conn_recent,
        "num_players_registered_recent": nplyrs_reg_recent,
        "num_rooms": nrooms,
        "num_exits": nexits,
        "num_objects": nobjs,
        "num_characters": nchars,
        "num_others": nothers
    }
    return pagevars
Пример #4
0
def _gamestats():
    # Some misc. configurable stuff.
    # TODO: Move this to either SQL or settings.py based configuration.
    fpage_account_limit = 8

    # A QuerySet of the most recently connected accounts.
    recent_users = AccountDB.objects.get_recently_connected_accounts(
    )[:fpage_account_limit]
    current_users = AccountDB.objects.get_connected_accounts()
    current_chars = []
    for element in current_users:
        grid_char = element.puppet
        current_chars.append(grid_char.key if grid_char else '*ghost*')
    nplyrs_conn_recent = len(recent_users) or "none"
    nplyrs = AccountDB.objects.num_total_accounts() or "none"
    nplyrs_reg_recent = len(
        AccountDB.objects.get_recently_created_accounts()) or "none"
    nsess = SESSION_HANDLER.account_count()
    # nsess = len(PlayerDB.objects.get_connected_players()) or "no one"

    nobjs = ObjectDB.objects.all().count()
    nrooms = ObjectDB.objects.filter(db_location__isnull=True).exclude(
        db_typeclass_path=_BASE_CHAR_TYPECLASS).count()
    nexits = ObjectDB.objects.filter(db_location__isnull=False,
                                     db_destination__isnull=False).count()
    nchars = ObjectDB.objects.filter(
        db_typeclass_path=_BASE_CHAR_TYPECLASS).count()
    nothers = nobjs - nrooms - nchars - nexits

    pagevars = {
        "page_title": "Front Page",
        "accounts_connected_recent": recent_users,
        "accounts_connected_now": current_users,
        "characters_on_grid": current_chars,
        "num_accounts_connected": nsess or "no one",
        "num_accounts_registered": nplyrs or "no",
        "num_accounts_connected_recent": nplyrs_conn_recent or "no",
        "num_accounts_registered_recent": nplyrs_reg_recent or "no one",
        "num_rooms": nrooms or "none",
        "num_exits": nexits or "no",
        "num_objects": nobjs or "none",
        "num_characters": nchars or "no",
        "num_others": nothers or "no"
    }
    return pagevars
Пример #5
0
def _gamestats():
    # Some misc. configurable stuff.
    # TODO: Move this to either SQL or settings.py based configuration.
    fpage_account_limit = 4

    # A QuerySet of the most recently connected accounts.
    recent_users = AccountDB.objects.get_recently_connected_accounts(
    )[:fpage_account_limit]
    nplyrs_conn_recent = len(recent_users) or "none"
    nplyrs = AccountDB.objects.num_total_accounts() or "none"
    nplyrs_reg_recent = len(
        AccountDB.objects.get_recently_created_accounts()) or "none"
    nsess = SESSION_HANDLER.account_count()
    # nsess = len(AccountDB.objects.get_connected_accounts()) or "no one"

    nobjs = ObjectDB.objects.count()
    nobjs = nobjs or 1  # fix zero-div error with empty database
    Character = class_from_module(
        settings.BASE_CHARACTER_TYPECLASS,
        fallback=settings.FALLBACK_CHARACTER_TYPECLASS)
    nchars = Character.objects.all_family().count()
    Room = class_from_module(settings.BASE_ROOM_TYPECLASS,
                             fallback=settings.FALLBACK_ROOM_TYPECLASS)
    nrooms = Room.objects.all_family().count()
    Exit = class_from_module(settings.BASE_EXIT_TYPECLASS,
                             fallback=settings.FALLBACK_EXIT_TYPECLASS)
    nexits = Exit.objects.all_family().count()
    nothers = nobjs - nchars - nrooms - nexits

    pagevars = {
        "page_title": "Front Page",
        "accounts_connected_recent": recent_users,
        "num_accounts_connected": nsess or "no one",
        "num_accounts_registered": nplyrs or "no",
        "num_accounts_connected_recent": nplyrs_conn_recent or "no",
        "num_accounts_registered_recent": nplyrs_reg_recent or "no one",
        "num_rooms": nrooms or "none",
        "num_exits": nexits or "no",
        "num_objects": nobjs or "none",
        "num_characters": nchars or "no",
        "num_others": nothers or "no",
    }
    return pagevars
Пример #6
0
def _gamestats():
    # Some misc. configurable stuff.
    # TODO: Move this to either SQL or settings.py based configuration.
    fpage_account_limit = 8

    # A QuerySet of the most recently connected accounts.
    recent_users = AccountDB.objects.get_recently_connected_accounts()[:fpage_account_limit]
    current_users = AccountDB.objects.get_connected_accounts()
    current_chars = []
    for element in current_users:
        grid_char = element.puppet
        current_chars.append(grid_char.key if grid_char else '*ghost*')
    nplyrs_conn_recent = len(recent_users) or "none"
    nplyrs = AccountDB.objects.num_total_accounts() or "none"
    nplyrs_reg_recent = len(AccountDB.objects.get_recently_created_accounts()) or "none"
    nsess = SESSION_HANDLER.account_count()
    # nsess = len(PlayerDB.objects.get_connected_players()) or "no one"

    nobjs = ObjectDB.objects.all().count()
    nrooms = ObjectDB.objects.filter(db_location__isnull=True).exclude(db_typeclass_path=_BASE_CHAR_TYPECLASS).count()
    nexits = ObjectDB.objects.filter(db_location__isnull=False, db_destination__isnull=False).count()
    nchars = ObjectDB.objects.filter(db_typeclass_path=_BASE_CHAR_TYPECLASS).count()
    nothers = nobjs - nrooms - nchars - nexits

    pagevars = {
        "page_title": "Front Page",
        "accounts_connected_recent": recent_users,
        "accounts_connected_now": current_users,
        "characters_on_grid": current_chars,
        "num_accounts_connected": nsess or "no one",
        "num_accounts_registered": nplyrs or "no",
        "num_accounts_connected_recent": nplyrs_conn_recent or "no",
        "num_accounts_registered_recent": nplyrs_reg_recent or "no one",
        "num_rooms": nrooms or "none",
        "num_exits": nexits or "no",
        "num_objects": nobjs or "none",
        "num_characters": nchars or "no",
        "num_others": nothers or "no"
    }
    return pagevars
Пример #7
0
def page_index(request):
    """
    Main root page.
    """
    # Some misc. configurable stuff.
    # TODO: Move this to either SQL or settings.py based configuration.
    fpage_player_limit = 4

    # A QuerySet of the most recently connected players.
    recent_users = PlayerDB.objects.get_recently_connected_players()[:fpage_player_limit]
    nplyrs_conn_recent = len(recent_users) or "none"
    nplyrs = PlayerDB.objects.num_total_players() or "none"
    nplyrs_reg_recent = len(PlayerDB.objects.get_recently_created_players()) or "none"
    nsess = SESSION_HANDLER.player_count()
    # nsess = len(PlayerDB.objects.get_connected_players()) or "no one"

    nobjs = ObjectDB.objects.all().count()
    nrooms = ObjectDB.objects.filter(db_location__isnull=True).exclude(db_typeclass_path=_BASE_CHAR_TYPECLASS).count()
    nexits = ObjectDB.objects.filter(db_location__isnull=False, db_destination__isnull=False).count()
    nchars = ObjectDB.objects.filter(db_typeclass_path=_BASE_CHAR_TYPECLASS).count()
    nothers = nobjs - nrooms - nchars - nexits

    pagevars = {
        "page_title": "Front Page",
        "players_connected_recent": recent_users,
        "num_players_connected": nsess or "no one",
        "num_players_registered": nplyrs or "no",
        "num_players_connected_recent": nplyrs_conn_recent or "no",
        "num_players_registered_recent": nplyrs_reg_recent or "no one",
        "num_rooms": nrooms or "none",
        "num_exits": nexits or "no",
        "num_objects": nobjs or "none",
        "num_characters": nchars or "no",
        "num_others": nothers or "no"
    }

    return render(request, 'index.html', pagevars)
Пример #8
0
    def func(self):
        """
        Create a new message and send it to channel, using
        the already formatted input.
        """
        channelkey, msg = self.args
        caller = self.caller
        channel = ChannelDB.objects.get_channel(channelkey)
        admin_switches = ("destroy", "emit", "lock", "locks", "desc", "kick")

        # Check that the channel exist
        if not channel:
            self.msg(_("Channel '%s' not found.") % channelkey)
            return

        # Check that the caller is connected
        if not channel.has_connection(caller):
            string = _("You are not connected to channel '%s'.")
            self.msg(string % channelkey)
            return

        # Check that the caller has send access
        if not channel.access(caller, 'send'):
            string = _("You are not permitted to send to channel '%s'.")
            self.msg(string % channelkey)
            return

        # Get the list of connected to this channel
        puppets = [session.puppet for session in SESSION_HANDLER.values() \
                if session.puppet]
        connected = [
            obj for obj in channel.subscriptions.all() if obj in puppets
        ]

        # Handle the various switches
        if self.switch == "me":
            if not msg:
                self.msg("What do you want to do on this channel?")
            else:
                msg = "{} {}".format(caller.key, msg)
                channel.msg(msg, online=True)
        elif self.switch == "who":
            keys = [obj.key for obj in connected]
            keys.sort()
            string = "Connected to the {} channel:".format(channel.key)
            string += ", ".join(keys) if keys else "(no one)"
            string += "."
            self.msg(string)
        elif channel.access(caller,
                            'control') and self.switch in admin_switches:
            if self.switch == "destroy":
                confirm = yield (
                    "Are you sure you want to delete the channel {}? (Y?N)".
                    format(channel.key))
                if confirm.lower() in ("y", "yes"):
                    channel.msg("Destroying the channel.")
                    channel.delete()
                    CHANNELHANDLER.update()
                    self.msg("The channel was destroyed.")
                else:
                    self.msg("Operation cancelled, do not destroy.")
            elif self.switch == "emit":
                if not msg:
                    self.msg("What do you want to say on this channel?")
                else:
                    channel.msg(msg, online=True)
            elif self.switch in ("lock", "locks"):
                if msg:
                    try:
                        channel.locks.add(msg)
                    except LockException as err:
                        self.msg(err)
                        return
                    else:
                        self.msg("Channel permissions were edited.")

                string = "Current locks on {}:\n  {}".format(
                    channel.key, channel.locks)
                self.msg(string)
            elif self.switch == "desc":
                if msg:
                    channel.db.desc = msg
                    self.msg("Channel description was updated.")

                self.msg("Description of the {} channel: {}".format(
                    channel.key, channel.db.desc))
            elif self.switch == "kick":
                if not msg:
                    self.msg("Who do you want to kick from this channel?")
                else:
                    to_kick = caller.search(msg, candidates=connected)
                    if to_kick is None:
                        return

                    channel.disconnect(to_kick)
                    channel.msg("{} has been kicked from the channel.".format(
                        to_kick.key))
                    to_kick.msg(
                        "You have been kicked from the {} channel.".format(
                            channel.key))
        elif self.history_start is not None:
            # Try to view history
            log_file = channel.attributes.get("log_file",
                                              default="channel_%s.log" %
                                              channel.key)
            send_msg = lambda lines: self.msg("".join(
                line.split("[-]", 1)[1] if "[-]" in line else line
                for line in lines))
            tail_log_file(log_file, self.history_start, 20, callback=send_msg)
        elif self.switch:
            self.msg("{}: Invalid switch {}.".format(channel.key, self.switch))
        elif not msg:
            self.msg(_("Say what?"))
            return
        else:
            if caller in channel.mutelist:
                self.msg("You currently have %s muted." % channel)
                return
            channel.msg(msg, senders=self.caller, online=True)
Пример #9
0
    def func(self):
        """Body of the command."""
        caller = self.caller

        # If there's an argument, it's a channel name
        channel = None
        if self.args.strip():
            channel = search_channel(self.args)
            if not channel:
                return

            # Check permissions
            if not channel.access(caller, 'listen'):
                self.msg("%s: You are not allowed to listen to this channel." %
                         channel.key)
                return

        if "join" in self.switches:
            if not channel:
                self.msg("Which channel do you want to join?")
                return

            # If not connected to the channel, try to connect
            if not channel.has_connection(caller):
                if not channel.connect(caller):
                    self.msg("%s: You are not allowed to join this channel." %
                             channel.key)
                    return
                else:
                    self.msg("You now are connected to the %s channel. " %
                             channel.key.lower())
            else:
                self.msg("You already are connected to the %s channel. " %
                         channel.key.lower())
        elif "leave" in self.switches:
            if not channel:
                self.msg("Which channel do you want to leave?")
                return

            # If connected to the channel, try to disconnect
            if channel.has_connection(caller):
                if not channel.disconnect(caller):
                    self.msg(
                        "%s: You are not allowed to disconnect from this channel."
                        % channel.key)
                    return
                else:
                    self.msg("You stop listening to the %s channel. " %
                             channel.key.lower())
            else:
                self.msg("You are not connected to the %s channel. " %
                         channel.key.lower())
        else:
            channels = sorted(ChannelDB.objects.all(),
                              key=lambda chan: chan.key)
            channels = [
                chan for chan in channels if chan.access(caller, 'listen')
            ]
            if channels:
                puppets = [session.puppet for session in SESSION_HANDLER.values() \
                        if session.puppet]
                table = evtable.EvTable("Channel", "Descriptions", "Nb")
                for channel in channels:
                    nb = len([obj for obj in channel.subscriptions.all() \
                            if obj in puppets])
                    table.add_row(channel.key, channel.db.desc, nb)
                self.msg(unicode(table))
            else:
                self.msg("There's currently no channel here... odd...")