AclManager
Provides access to the server’s Access Control Manager to configure operators, bans, whitelist, and associated rule records. The acl global exposes the existing ServerObject.acl manager.
Rules are represented by AclRule, including users and IP addresses. Rules can be local or global, organized under the 'bans', 'ops', 'wl', and 'subnets' keys in acl.rules.
View the source: AclManager
Methods
Section titled “Methods”acl.get_uuid(username)
Section titled “acl.get_uuid(username)”Returns a dict of a player’s connection data given their username and other rules. Use acl.get_uuid('Username')['uuid'] to get their UUID
| Parameters | Type | Description |
|---|---|---|
username* | str | Username of the player |
acl.kick_player(rule_list, reason=None)
Section titled “acl.kick_player(rule_list, reason=None)”Kicks a player or list of players, optionally with a reason
| Parameters | Type | Description |
|---|---|---|
rule_list* | PlayerScriptObject / str / list | Player object, username, or a list containing either |
reason | str | Reason for the kick displayed to the client, and in the log |
acl.ban_player(rule_list, remove=False, reason=None, length="forever")
Section titled “acl.ban_player(rule_list, remove=False, reason=None, length="forever")”Bans/pardons a player, IP, list of players, or list of IPs, optionally with a reason. A subnet range such as 192.168.0.0/24 is also acceptable. You can whitelist an IP or subnet with !w192.168.0.5
| Parameters | Type | Description |
|---|---|---|
rule_list* | PlayerScriptObject / str / list | Player object, username/IP, or a list containing either |
remove | bool | Removes rule from effect. Defaults to False |
reason | str | Reason shown in the ban message and log |
length | str | Ban duration; defaults to 'forever'. Uses inference with formatting like '1y', '2mo', '5d', etc. |
acl.op_player(rule_list, remove=False)
Section titled “acl.op_player(rule_list, remove=False)”Ops/de-ops a player or list of players
| Parameters | Type | Description |
|---|---|---|
rule_list* | PlayerScriptObject / str / list | Player object, username, or a list containing either |
remove | bool | Removes rule from effect. Defaults to False |
acl.whitelist_player(rule_list, remove=False)
Section titled “acl.whitelist_player(rule_list, remove=False)”Adds/removes a player or list of players to/from the whitelist
| Parameters | Type | Description |
|---|---|---|
rule_list* | PlayerScriptObject / str / list | Player object, username, or a list containing either |
remove | bool | Removes rule from effect. Defaults to False |
acl.enable_whitelist(enabled=True)
Section titled “acl.enable_whitelist(enabled=True)”Enables or disables the server whitelist
| Parameters | Type | Description |
|---|---|---|
enabled | bool | Defaults to True |
acl.add_global_rule(rule_list, list_type, remove=False)
Section titled “acl.add_global_rule(rule_list, list_type, remove=False)”Adds a player or list of players to a specified list type for every server. Learn more about global rules
| Parameters | Type | Description |
|---|---|---|
rule_list* | PlayerScriptObject / str / list | Player object, username, or a list containing either |
list_type* | str | Can be 'ops', 'bans', or 'wl' |
remove | bool | Removes rule from effect. Defaults to False |
acl.reload_list(list_type=None)
Section titled “acl.reload_list(list_type=None)”Reloads the list type from the server’s access control files, and refreshes acl.rules. If list_type is unspecified, all data is reloaded
| Parameters | Type | Description |
|---|---|---|
list_type | str | Can be 'ops', 'bans', or 'wl' |
acl.edit_list(rule_list, list_type, remove=False, overwrite=False)
Section titled “acl.edit_list(rule_list, list_type, remove=False, overwrite=False)”Similar to the acl.*_player methods, but only edits acl.rules in memory without writing to disk
| Parameters | Type | Description |
|---|---|---|
rule_list* | PlayerScriptObject / str / list | Player object, username, or a list containing either |
list_type* | str | Can be 'ops', 'bans', or 'wl' |
remove | bool | Removes rule from effect. Defaults to False |
overwrite | bool | Replaces an existing matching in-memory rule when adding. Defaults to False |
acl.write_rules()
Section titled “acl.write_rules()”Writes data from acl.rules to disk in their respective format. Works pre-1.8 for .txt files, and post-1.8 for .json files
acl.rule_in_acl(rule, list_type)
Section titled “acl.rule_in_acl(rule, list_type)”Looks up a player/IP in the specified list and returns the matching AclRule, or None if absent. This return value is also truthy in conditionals
| Parameters | Type | Description |
|---|---|---|
rule* | str | Username, IP, or subnet |
list_type* | str | Can be 'ops', 'bans', 'wl', or 'subnets' |
acl.count_rules(list_type=None)
Section titled “acl.count_rules(list_type=None)”Returns a dict of counts. When list_type is passed, it returns {list_type: int}. Without passing list_type, it returns {'ops': int, 'bans': int, 'wl': int, 'total': int}
| Parameters | Type | Description |
|---|---|---|
list_type | str | Can be 'ops', 'bans', or 'wl' |
acl.get_rule(rule_name)
Section titled “acl.get_rule(rule_name)”Retrieves all the access control data associated with a rule. Returns a new AclRule with additional data in the AclRule.extra_data dictionary
| Parameters | Type | Description |
|---|---|---|
rule_name* | str | Username, IP, or subnet |
Attributes
Section titled “Attributes”| Attribute | Type | Description |
|---|---|---|
acl.rules | dict | Contains lists of AclRule objects keyed by rule types. See the example below. |
acl.playerdata | list | Contains an AclRule for every player who has joined the server in the usercache.json, or who has player data in the world |
acl.list_items | dict | Structured similarly to acl.rules, but contains an organized list of disabled and enabled items for each list type; for the UI |
acl.displayed_rule | AclRule / None | Contains the rule returned from the acl.get_rule() method, or None when no rule is displayed |
acl.whitelist_enabled | bool | Whether or not the server whitelist is enforced |
Examples
Section titled “Examples”Rules structure:
Section titled “Rules structure:”acl.rules = { 'ops': [AclRule, AclRule, ...], 'bans': [AclRule, AclRule, ...], 'wl': [AclRule, AclRule, ...], 'subnets': [AclRule, AclRule, ...]}