Example #1
0
    def cmd_name(self, player, msg, channel):
        name_key = _name_key.format(player.steam_id)

        if len(msg) < 2:
            if name_key not in self.db:
                return minqlx.RET_USAGE
            else:
                del self.db[name_key]
                player.tell("Your registered name has been removed.")
                return minqlx.RET_STOP_EVENT

        name = self.clean_excessive_colors(" ".join(msg[1:]))
        if len(name.encode()) > 36:
            player.tell("The name is too long. Consider using fewer colors or a shorter name.")
            return minqlx.RET_STOP_EVENT
        elif self.clean_text(name) != player.clean_name and self.get_cvar("qlx_enforceSteamName", bool):
            player.tell("The colored name must match your current Steam name.")
            return minqlx.RET_STOP_EVENT

        info = minqlx.parse_variables(minqlx.player_info(player.id)["userinfo"], ordered=True)
        info["name"] = name
        new_info = "".join(["\\{}\\{}".format(key, info[key]) for key in info])
        minqlx.client_command(player.id, 'userinfo "{}"'.format(new_info))
        self.db[name_key] = name
        player.tell(
            "The name has been registered. To make me forget about it, a simple ^6{}name^7 will do it.".format(
                self.get_cvar("qlx_commandPrefix")
            )
        )
        return minqlx.RET_STOP_EVENT
Example #2
0
    def __init__(self, client_id, info=None):
        self._valid = True

        # Can pass own info for efficiency when getting all players and to allow dummy players.
        if info:
            self._id = client_id
            self._info = info
        else:
            self._id = client_id
            self._info = minqlx.player_info(client_id)
            if not self._info:
                self._invalidate("Tried to initialize a Player instance of nonexistant player {}."
                    .format(client_id))

        self._userinfo = None
        self._steam_id = self._info.steam_id

        # When a player connects, a the name field in the client struct has yet to be initialized,
        # so we fall back to the userinfo and try parse it ourselves to get the name if needed.
        if self._info.name:
            self._name = self._info.name
        else:
            self._userinfo = minqlx.parse_variables(self._info.userinfo, ordered=True)
            if "name" in self._userinfo:
                self._name = self._userinfo["name"]
            else: # No name at all. Weird userinfo during connection perhaps?
                self._name = ""
Example #3
0
    def __init__(self, client_id, info=None):
        self._valid = True

        # Can pass own info for efficiency when getting all players and to allow dummy players.
        if info:
            self._id = client_id
            self._info = info
        else:
            self._id = client_id
            self._info = minqlx.player_info(client_id)
            if not self._info:
                self._invalidate(
                    "Tried to initialize a Player instance of nonexistant player {}."
                    .format(client_id))

        self._userinfo = None
        self._steam_id = self._info.steam_id

        # When a player connects, a the name field in the client struct has yet to be initialized,
        # so we fall back to the userinfo and try parse it ourselves to get the name if needed.
        if self._info.name:
            self._name = self._info.name
        else:
            self._userinfo = minqlx.parse_variables(self._info.userinfo,
                                                    ordered=True)
            if "name" in self._userinfo:
                self._name = self._userinfo["name"]
            else:  # No name at all. Weird userinfo during connection perhaps?
                self._name = ""
Example #4
0
 def handle_player_loaded(self, player):
     name_key = _name_key.format(player.steam_id)
     if name_key in self.db:
         db_name = self.db[name_key]
         if not self.get_cvar("qlx_enforceSteamName", bool) or self.clean_text(db_name) == player.clean_name:
             info = minqlx.parse_variables(minqlx.player_info(player.id)["userinfo"], ordered=True)
             info["name"] = db_name
             new_info = "".join(["\\{}\\{}".format(key, info[key]) for key in info])
             minqlx.client_command(player.id, 'userinfo "{}"'.format(new_info))
Example #5
0
def _player(client_id):
    """A wrapper for minqlx.Player to make the output more usable."""
    info = minqlx.player_info(client_id)
    if info == None:
        return None

    d = {}
    for key in info:
        if key == "configstring":
            d.update(minqlx.parse_variables(info["configstring"]))
        elif key == "userinfo":
            d.update(minqlx.parse_variables(info["userinfo"]))
        else:
            d[key] = info[key]
    return d
Example #6
0
def _player(client_id):
    """A wrapper for minqlx.Player to make the output more usable."""
    info = minqlx.player_info(client_id)
    if info == None:
        return None
    
    d = {}
    for key in info:
        if key == "configstring":
            d.update(minqlx.parse_variables(info["configstring"]))
        elif key == "userinfo":
            d.update(minqlx.parse_variables(info["userinfo"]))
        else:
            d[key] = info[key]
    return d
Example #7
0
    def update(self):
        """Update the player information with the latest data. If the player
        disconnected it will raise an exception and invalidates a player.
        The player's name and Steam ID can still be accessed after being 
        invalidated, but anything else will make it throw an exception too.

        :raises: minqlx.NonexistentPlayerError

        """
        self._info = minqlx.player_info(self._id)

        if not self._info or self._steam_id != self._info.steam_id:
            self._invalidate()

        if self._info.name:
            self._name = self._info.name
        else:
            self._userinfo = minqlx.parse_variables(self._info.userinfo, ordered=True)
            if "name" in self._userinfo:
                self._name = self._userinfo["name"]
            else:
                self._name = ""
Example #8
0
    def update(self):
        """Update the player information with the latest data. If the player
        disconnected it will raise an exception and invalidates a player.
        The player's name and Steam ID can still be accessed after being
        invalidated, but anything else will make it throw an exception too.

        :raises: minqlx.NonexistentPlayerError

        """
        self._info = minqlx.player_info(self._id)

        if not self._info or self._steam_id != self._info.steam_id:
            self._invalidate()

        if self._info.name:
            self._name = self._info.name
        else:
            self._userinfo = minqlx.parse_variables(self._info.userinfo, ordered=True)
            if "name" in self._userinfo:
                self._name = self._userinfo["name"]
            else:
                self._name = ""