Esempio n. 1
0
    def set_name(self, name):

        name = name.strip()
        lower_name = name.lower()

        # Fail if:
        # - The name is already in use;
        # - The name has invalid characters;
        # - The name is too long.
        for other in self.server.players:
            if other.name == lower_name and self != other:
                self.tell("That name is already in use.\n")
                self.server.log.log("%s attempted to change name to in-use name %s." % (self.name, other.name))
                return False

        if len(name) > MAX_NAME_LENGTH:
            self.tell("Names must be less than %d characters long.\n" % MAX_NAME_LENGTH)
            self.server.log.log("%s attempted to change to too-long name %s." % (self.name, name))
            return False

        if not name_is_valid(name):
            self.tell("Names must be alphanumeric and start with a letter.\n")
            self.server.log.log("%s attempted to change to non-valid name %s." % (self.name, name))
            return False

        # Okay, the name looks legitimate.
        self.server.log.log("%s is now known as %s." % (self, name))
        self.display_name = name
        self.name = lower_name
        self.tell("Your name is now %s.\n" % name)
        return True
Esempio n. 2
0
    def alias(self, alias_string, player):

        if not alias_string:
            player.tell("Invalid alias command.\n")
            return False

        alias_bits = alias_string.split()

        # Bail if we didn't get three bits.
        if len(alias_bits) != 3:
            player.tell("Invalid alias command.\n")
            return False

        # Extract the values from the bits.
        a_type = alias_bits[0]
        a_name = alias_bits[1]
        a_num = alias_bits[2]

        # Bail if the name isn't valid.
        if not name_is_valid(a_name):
            player.tell("Cannot alias an invalid name.\n")
            return False

        # Bail if the number isn't a number or is > 99.  Convert otherwise.
        if not a_num.isdigit():
            player.tell("Cannot alias to a non-number.\n")
            return False

        a_num = int(a_num)
        if a_num > 99:
            player.tell("Cannot alias to a number greater than 99.\n")
            return False

        # Get the type that we're aliasing.  If it's invalid, we'll bail.
        if a_type in ("channel", "chan", "ch", "c",):
            alias_dict = player.config["channel_aliases"]
            type_str = "channel"
        elif a_type in ("player", "pl", "p",):
            alias_dict = player.config["player_aliases"]
            type_str = "player"
        elif a_type in ("table", "tab", "ta", "t",):
            alias_dict = player.config["table_aliases"]
            type_str = "table"
        else:
            player.tell("Invalid type to alias to.  Must be one of channel, player, or table.\n")
            return False

        # Is this already an alias?
        addendum_str = ""
        if a_num in alias_dict:
            addendum_str = ", ^Rreplacing^~ ^c%s^~" % alias_dict[a_num]

        # Either way, add the new alias.
        alias_dict[a_num] = a_name
        player.tell_cc("^C%d^~ is now a ^M%s^~ alias for ^G%s^~%s.\n" % (a_num, type_str, a_name, addendum_str))
        return True
Esempio n. 3
0
    def add_channel(self, name, persistent=False, notifications=True, gameable=False, key=None):

        if not name_is_valid(name):
            return False

        # Make sure this isn't a duplicate.
        if self.has_channel(name):
            return False

        # Not a duplicate.  Make a new entry.  Like users, 'name' is for
        # comparison; the channel itself tracks its display name.
        self.channels.append(Channel(name, persistent, notifications, gameable, key))
        return self.channels[-1]
Esempio n. 4
0
    def set_name(self, name):

        name = name.strip()
        lower_name = name.lower()

        # Fail if:
        # - The name is already in use;
        # - The name has invalid characters;
        # - The name is too long.
        for other in self.server.players:
            if other.name == lower_name and self != other:
                self.tell("That name is already in use.\n")
                self.server.log.log(
                    "%s attempted to change name to in-use name %s." %
                    (self.name, other.name))
                return False

        if len(name) > MAX_NAME_LENGTH:
            self.tell("Names must be less than %d characters long.\n" %
                      MAX_NAME_LENGTH)
            self.server.log.log("%s attempted to change to too-long name %s." %
                                (self.name, name))
            return False

        if not name_is_valid(name):
            self.tell("Names must be alphanumeric and start with a letter.\n")
            self.server.log.log(
                "%s attempted to change to non-valid name %s." %
                (self.name, name))
            return False

        # Okay, the name looks legitimate.
        self.server.log.log("%s is now known as %s." % (self, name))
        self.display_name = name
        self.name = lower_name
        self.tell("Your name is now %s.\n" % name)
        return True
Esempio n. 5
0
    def new_table(self, player, game_name, table_name, scope="local",
                  private=False):

        if not name_is_valid(table_name):
            player.tell_cc("Invalid table name.\n")
            return False

        # Make sure this isn't a duplicate table name.  It also can't
        # match a non-gameable channel.
        chan = self.server.channel_manager.has_channel(table_name)
        if chan and not chan.gameable:
            player.tell_cc("A channel named ^R%s^~ already exists.\n" % table_name)
            return False

        lower_table_name = table_name.lower()
        for table in self.tables:
            if table.table_name == lower_table_name:
                player.tell_cc("A table named ^R%s^~ already exists.\n" % table_name)
                return False

        # Check our list of games and see if we have this.
        lower_game_name = game_name.lower()
        if lower_game_name in self.games:

            # If this game is admin-only, verify that the player is an admin.
            if self.games[lower_game_name].admin_only:
                if not self.server.admin_manager.is_admin(player):
                    player.tell_cc("You cannot create a table; this game is admin-only.\n")
                    self.log("Non-admin %s failed to create table of admin-only game %s." % (player, lower_game_name))
                    return False

            # Okay.  Create the new table.
            try:
                table = self.games[lower_game_name].game_class(self.server, table_name)
            except Exception as e:
                player.tell_cc("Creating the table failed!  ^RAlert the admin^~.\n")
                self.log("Creating table %s of game %s failed.\n%s" % (table_name, lower_game_name, traceback.format_exc()))
                return False
            table.private = private

            # Connect the player to its channel, because presumably they
            # want to actually hear what's going on.
            if not table.channel.is_connected(player):
                table.channel.connect(player)

            # Send a message to the channel...
            table.channel.broadcast_cc("%s created a new table of ^M%s^~.\n" % (player, table.game_display_name))

            # ...and notify the proper scope.
            if scope == "personal":
                player.tell_cc("A new table of ^M%s^~ called ^R%s^~ has been created.\n" % (table.game_display_name, table.table_display_name))
                self.log("%s created new personal table %s of %s (%s)." % (player, table.table_display_name, table.game_name, table.game_display_name))
            elif scope == "global":
                self.server.wall.broadcast_cc("%s created a new table of ^M%s^~ called ^R%s^~.\n" % (player, table.game_display_name, table.table_display_name))
                self.log("%s created new global table %s of %s (%s)." % (player, table.table_display_name, table.game_name, table.game_display_name))
            else:
                player.location.notify_cc("%s created a new table of ^M%s^~ called ^R%s^~.\n" % (player, table.game_display_name, table.table_display_name))
                self.log("%s created new local table %s of %s (%s)." % (player, table.table_display_name, table.game_name, table.game_display_name))
            self.tables.append(table)
            return True

        player.tell_cc("No such game ^R%s^~.\n" % game_name)
        return False
Esempio n. 6
0
    def new_table(self,
                  player,
                  game_name,
                  table_name,
                  scope="local",
                  private=False):

        if not name_is_valid(table_name):
            player.tell_cc("Invalid table name.\n")
            return False

        # Make sure this isn't a duplicate table name.  It also can't
        # match a non-gameable channel.
        chan = self.server.channel_manager.has_channel(table_name)
        if chan and not chan.gameable:
            player.tell_cc("A channel named ^R%s^~ already exists.\n" %
                           table_name)
            return False

        lower_table_name = table_name.lower()
        for table in self.tables:
            if table.table_name == lower_table_name:
                player.tell_cc("A table named ^R%s^~ already exists.\n" %
                               table_name)
                return False

        # Check our list of games and see if we have this.
        lower_game_name = game_name.lower()
        if lower_game_name in self.games:

            # If this game is admin-only, verify that the player is an admin.
            if self.games[lower_game_name].admin_only:
                if not self.server.admin_manager.is_admin(player):
                    player.tell_cc(
                        "You cannot create a table; this game is admin-only.\n"
                    )
                    self.log(
                        "Non-admin %s failed to create table of admin-only game %s."
                        % (player, lower_game_name))
                    return False

            # Okay.  Create the new table.
            try:
                table = self.games[lower_game_name].game_class(
                    self.server, table_name)
            except Exception as e:
                player.tell_cc(
                    "Creating the table failed!  ^RAlert the admin^~.\n")
                self.log("Creating table %s of game %s failed.\n%s" %
                         (table_name, lower_game_name, traceback.format_exc()))
                return False
            table.private = private

            # Connect the player to its channel, because presumably they
            # want to actually hear what's going on.
            if not table.channel.is_connected(player):
                table.channel.connect(player)

            # Send a message to the channel...
            table.channel.broadcast_cc("%s created a new table of ^M%s^~.\n" %
                                       (player, table.game_display_name))

            # ...and notify the proper scope.
            if scope == "personal":
                player.tell_cc(
                    "A new table of ^M%s^~ called ^R%s^~ has been created.\n" %
                    (table.game_display_name, table.table_display_name))
                self.log("%s created new personal table %s of %s (%s)." %
                         (player, table.table_display_name, table.game_name,
                          table.game_display_name))
            elif scope == "global":
                self.server.wall.broadcast_cc(
                    "%s created a new table of ^M%s^~ called ^R%s^~.\n" %
                    (player, table.game_display_name,
                     table.table_display_name))
                self.log("%s created new global table %s of %s (%s)." %
                         (player, table.table_display_name, table.game_name,
                          table.game_display_name))
            else:
                player.location.notify_cc(
                    "%s created a new table of ^M%s^~ called ^R%s^~.\n" %
                    (player, table.game_display_name,
                     table.table_display_name))
                self.log("%s created new local table %s of %s (%s)." %
                         (player, table.table_display_name, table.game_name,
                          table.game_display_name))
            self.tables.append(table)
            return True

        player.tell_cc("No such game ^R%s^~.\n" % game_name)
        return False
Esempio n. 7
0
    def alias(self, alias_string, player):

        if not alias_string:
            player.tell("Invalid alias command.\n")
            return False

        alias_bits = alias_string.split()

        # Bail if we didn't get three bits.
        if len(alias_bits) != 3:
            player.tell("Invalid alias command.\n")
            return False

        # Extract the values from the bits.
        a_type = alias_bits[0]
        a_name = alias_bits[1]
        a_num = alias_bits[2]

        # Bail if the name isn't valid.
        if not name_is_valid(a_name):
            player.tell("Cannot alias an invalid name.\n")
            return False

        # Bail if the number isn't a number or is > 99.  Convert otherwise.
        if not a_num.isdigit():
            player.tell("Cannot alias to a non-number.\n")
            return False

        a_num = int(a_num)
        if a_num > 99:
            player.tell("Cannot alias to a number greater than 99.\n")
            return False

        # Get the type that we're aliasing.  If it's invalid, we'll bail.
        if a_type in (
                "channel",
                "chan",
                "ch",
                "c",
        ):
            alias_dict = player.config["channel_aliases"]
            type_str = "channel"
        elif a_type in (
                "player",
                "pl",
                "p",
        ):
            alias_dict = player.config["player_aliases"]
            type_str = "player"
        elif a_type in (
                "table",
                "tab",
                "ta",
                "t",
        ):
            alias_dict = player.config["table_aliases"]
            type_str = "table"
        else:
            player.tell(
                "Invalid type to alias to.  Must be one of channel, player, or table.\n"
            )
            return False

        # Is this already an alias?
        addendum_str = ""
        if a_num in alias_dict:
            addendum_str = ", ^Rreplacing^~ ^c%s^~" % alias_dict[a_num]

        # Either way, add the new alias.
        alias_dict[a_num] = a_name
        player.tell_cc("^C%d^~ is now a ^M%s^~ alias for ^G%s^~%s.\n" %
                       (a_num, type_str, a_name, addendum_str))
        return True