From 952a155003e1823330c882ddd7007c180df0d4b6 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Sun, 26 Sep 2021 09:06:12 +0200 Subject: [PATCH] MultiServer: move permissions to an IntEnum --- MultiServer.py | 7 ++++++- NetUtils.py | 19 +++++++++++++++++++ host.yaml | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/MultiServer.py b/MultiServer.py index ddf98100..28a510b9 100644 --- a/MultiServer.py +++ b/MultiServer.py @@ -31,7 +31,7 @@ from worlds import network_data_package, lookup_any_item_id_to_name, lookup_any_ import Utils from Utils import get_item_name_from_id, get_location_name_from_id, \ version_tuple, restricted_loads, Version -from NetUtils import Endpoint, ClientStatus, NetworkItem, decode, encode, NetworkPlayer +from NetUtils import Endpoint, ClientStatus, NetworkItem, decode, encode, NetworkPlayer, Permission colorama.init() @@ -469,8 +469,13 @@ async def on_client_connected(ctx: Context, client: Client): # Name them by feature or fork, as you feel is appropriate. 'tags': ctx.tags, 'version': Utils.version_tuple, + # TODO ~0.2.0 remove forfeit_mode and remaining_mode in favor of permissions 'forfeit_mode': ctx.forfeit_mode, 'remaining_mode': ctx.remaining_mode, + 'permissions': { + "forfeit": Permission.from_text(ctx.forfeit_mode), + "remaining": Permission.from_text(ctx.remaining_mode), + }, 'hint_cost': ctx.hint_cost, 'location_check_points': ctx.location_check_points, 'datapackage_version': network_data_package["version"], diff --git a/NetUtils.py b/NetUtils.py index 6b45c3ca..ee89ccc8 100644 --- a/NetUtils.py +++ b/NetUtils.py @@ -25,6 +25,25 @@ class ClientStatus(enum.IntEnum): CLIENT_GOAL = 30 +class Permission(enum.IntEnum): + disabled = 0b000 # 0, completely disables access + enabled = 0b001 # 1, allows manual use + goal = 0b010 # 2, allows manual use after goal completion + auto = 0b110 # 6, forces use after goal completion, only works for forfeit + auto_enabled = 0b111 # 7, forces use after goal completion, allows manual use any time + + @staticmethod + def from_text(text: str): + data = 0 + if "auto" in text: + data |= 0b110 + elif "goal" in text: + data |= 0b010 + if "enabled" in text: + data |= 0b001 + return Permission(data) + + class NetworkPlayer(typing.NamedTuple): team: int slot: int diff --git a/host.yaml b/host.yaml index ed65d37b..e8d1ee4c 100644 --- a/host.yaml +++ b/host.yaml @@ -27,6 +27,7 @@ server_options: # "enabled" -> clients can always forfeit # "auto" -> automatic forfeit on goal completion, "goal" -> clients can forfeit after achieving their goal # "auto-enabled" -> automatic forfeit on goal completion and manual forfeit is also enabled + # "goal" -> forfeit is allowed after goal completion forfeit_mode: "goal" # Remaining modes # !remaining handling, that tells a client which items remain in their pool