コード例 #1
0
ファイル: formatter.py プロジェクト: volundmush/pymush
    def text(
        self,
        formatter,
        conn: "Connection",
        user: Optional["User"] = None,
        character: Optional["GameObject"] = None,
    ):
        colors = dict()
        styler = formatter.style
        colors["border"] = styler.get(self.color_category, "border_color")
        colors["headertext"] = styler.get(self.color_category,
                                          f"{self.mode}_text_color")
        colors["headerstar"] = styler.get(self.color_category,
                                          f"{self.mode}_star_color")
        width = conn.details.width
        if self.edge_character:
            width -= 2

        contained_text = self.contained_text.strip()
        if contained_text:
            if self.color:
                header_text = ansi_fun(colors["headertext"], contained_text)
            if self.mode == "header":
                col_star = ansi_fun(colors["headerstar"], "*")
                begin_center = ansi_fun(colors["border"], "<") + col_star
                end_center = col_star + ansi_fun(colors["border"], ">")
                center_string = begin_center + " " + header_text + " " + end_center
            else:
                center_string = (ansi_fun(None, " ") +
                                 ansi_fun(colors["headertext"], header_text) +
                                 " ")
        else:
            center_string = ansi_fun(None, "")

        fill_character = styler.get(self.color_category, f"{self.mode}_fill")

        remain_fill = width - len(center_string)
        if remain_fill % 2 == 0:
            right_width = remain_fill / 2
            left_width = remain_fill / 2
        else:
            right_width = math.floor(remain_fill / 2)
            left_width = math.ceil(remain_fill / 2)
        right_fill = ansi_fun(colors["border"],
                              fill_character * int(right_width))
        left_fill = ansi_fun(colors["border"],
                             fill_character * int(left_width))

        if self.edge_character:
            edge_fill = ansi_fun(colors["border"], self.edge_character)
            main_string = center_string
            final_send = edge_fill + left_fill + main_string + right_fill + edge_fill
        else:
            final_send = left_fill + center_string + right_fill
        conn.print(final_send)
コード例 #2
0
ファイル: base.py プロジェクト: volundmush/pymush
 def format_name(obj, cmd=None):
     name = viewer.get_dub_or_keyphrase_for(obj)
     display = ansi_fun("hw", name)
     if cmd:
         display = send_menu(display, [(f"{cmd} {name}", cmd)])
     if see_dbrefs:
         display += f" ({obj.dbref})"
     return display
コード例 #3
0
class CreateCommand(_LoginCommand):
    """
    Creates a new Account.

    Usage:
        create <username> <password>

    If username contains spaces:
        create "<user name>" <password>
    """

    name = "create"
    re_match = re.compile(r"^(?P<cmd>create)(?: +(?P<args>.+)?)?",
                          flags=re.IGNORECASE)
    usage = ("Usage: " + ansi_fun("hw", "create <username> <password>") +
             " or " + ansi_fun("hw", 'create "<user name>" <password>'))

    async def execute(self):
        name, password = self.parse_login(self.usage)
        result, err = await self.entry.create_user(name, password)
        if not result:
            raise CommandException(err)
コード例 #4
0
class ConnectCommand(_LoginCommand):
    """
    Logs in to an existing User Account.

    Usage:
        connect <username> <password>

    If username contains spaces:
        connect "<user name>" <password>
    """

    name = "connect"
    re_match = re.compile(r"^(?P<cmd>connect)(?: +(?P<args>.+))?",
                          flags=re.IGNORECASE)
    usage = ("Usage: " + ansi_fun("hw", "connect <username> <password>") +
             " or " + ansi_fun("hw", 'connect "<user name>" password'))

    async def execute(self):
        name, password = self.parse_login(self.usage)
        result, err = await self.entry.check_login(name, password)
        if not result:
            raise CommandException(err)
コード例 #5
0
class CharCreateCommand(Command):
    name = "@charcreate"
    re_match = re.compile(
        r"^(?P<cmd>@charcreate)(?: +(?P<args>.+)?)?", flags=re.IGNORECASE
    )
    help_category = "Character Management"
    character_type = "PLAYER"

    async def execute(self):
        mdict = self.match_obj.groupdict()
        if not (name := mdict.get("args", None)):
            raise CommandException("Must enter a name for the character!")
        user = self.entry.user
        char, error = await self.game.create_object(
            self.entry, self.character_type, name, namespace=user, owner=user
        )
        if error:
            raise CommandException(error)
        self.msg(
            text=ansi_fun("", f"Character '{char.name}' created! Use ")
            + ansi_fun("hw", f"@ic {char.name}")
            + " to join the game!"
        )
コード例 #6
0
    async def create_user(
        self, name: str, password: str
    ) -> Tuple[bool, Optional[Text]]:
        try:
            user = await self.game.users.create_user(name=name, password=password)
        except ValueError as err:
            return False, Text(str(err))

        cmd = (
            f'connect "{user.name}" <password>'
            if " " in user.name
            else f"connect {user.name} <password>"
        )
        self.msg(text="User Account created! You can login with " + ansi_fun("hw", cmd))
        return user, None
コード例 #7
0
ファイル: welcome.py プロジェクト: volundmush/pymush
from mudrich.encodings.pennmush import ansi_fun

logo = ansi_fun(
    "",
    r"""
.______   ____    ____ .___  ___.  __    __       _______. __    __  
|   _  \  \   \  /   / |   \/   | |  |  |  |     /       ||  |  |  | 
|  |_)  |  \   \/   /  |  \  /  | |  |  |  |    |   (----`|  |__|  | 
|   ___/    \_    _/   |  |\/|  | |  |  |  |     \   \    |   __   | 
|  |          |  |     |  |  |  | |  `--'  | .----)   |   |  |  |  | 
| _|          |__|     |__|  |__|  \______/  |_______/    |__|  |__| 
                                                                     
                                                                                                           
                                                                                                           \n""",
)

instructions = (ansi_fun("hw", "connect <username> <password>") +
                " connects you to an existing Account.\n")
instructions2 = (ansi_fun("hw", "create <username> <password>") +
                 " creates a new Account.\n")
instructions3 = ("Enclose multi-word names in quotations. Example: " +
                 ansi_fun("hw", 'connect "<user name>" <password>') + "\n")
instructions4 = ansi_fun("hw", "QUIT") + " exits the game and disconnects.\n"

line = ansi_fun(
    "",
    "------------------------------------------------------------------------------\n",
)

message = (logo + line + instructions + instructions2 + instructions3 +
           instructions4 + line)