From f528175d8a2245113df52e3fdfaa4dee793b6ebc Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Mon, 13 Feb 2023 01:56:20 +0100 Subject: [PATCH] Core: prepare server for removal of names in multidata (#1430) --- Main.py | 5 ++--- MultiServer.py | 55 ++++++++++++++++++++------------------------------ Utils.py | 4 ++-- 3 files changed, 26 insertions(+), 38 deletions(-) diff --git a/Main.py b/Main.py index 879ca720..ecb55660 100644 --- a/Main.py +++ b/Main.py @@ -13,7 +13,7 @@ from BaseClasses import Item, MultiWorld, CollectionState, Region, RegionType, L import worlds from worlds.alttp.Regions import is_main_entrance from Fill import distribute_items_restrictive, flood_items, balance_multiworld_progression, distribute_planned -from worlds.alttp.Shops import SHOP_ID_START, total_shop_slots, FillDisabledShopSlots +from worlds.alttp.Shops import FillDisabledShopSlots from Utils import output_path, get_options, __version__, version_tuple from worlds.generic.Rules import locality_rules, exclusion_rules from worlds import AutoWorld @@ -365,8 +365,7 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No multidata = { "slot_data": slot_data, "slot_info": slot_info, - "names": names, # TODO: remove around 0.2.5 in favor of slot_info - "games": games, # TODO: remove around 0.2.5 in favor of slot_info + "names": names, # TODO: remove after 0.3.9 "connect_names": {name: (0, player) for player, name in world.player_name.items()}, "locations": locations_data, "checks_in_area": checks_in_area, diff --git a/MultiServer.py b/MultiServer.py index e7151919..90572ec1 100644 --- a/MultiServer.py +++ b/MultiServer.py @@ -158,6 +158,7 @@ class Context: stored_data: typing.Dict[str, object] read_data: typing.Dict[str, object] stored_data_notification_clients: typing.Dict[str, typing.Set[Client]] + slot_info: typing.Dict[int, NetworkSlot] item_names: typing.Dict[int, str] = Utils.KeyedDefaultDict(lambda code: f'Unknown item (ID:{code})') item_name_groups: typing.Dict[str, typing.Dict[str, typing.Set[str]]] @@ -170,7 +171,7 @@ class Context: remaining_mode: str = "disabled", auto_shutdown: typing.SupportsFloat = 0, compatibility: int = 2, log_network: bool = False): super(Context, self).__init__() - self.slot_info: typing.Dict[int, NetworkSlot] = {} + self.slot_info = {} self.log_network = log_network self.endpoints = [] self.clients = {} @@ -378,15 +379,23 @@ class Context: for player, version in clients_ver.items(): self.minimum_client_versions[player] = max(Utils.Version(*version), min_client_version) - self.clients = {} - for team, names in enumerate(decoded_obj['names']): - self.clients[team] = {} - for player, name in enumerate(names, 1): - self.clients[team][player] = [] - self.player_names[team, player] = name - self.player_name_lookup[name] = team, player - self.read_data[f"hints_{team}_{player}"] = lambda local_team=team, local_player=player: \ - list(self.get_rechecked_hints(local_team, local_player)) + self.slot_info = decoded_obj["slot_info"] + self.games = {slot: slot_info.game for slot, slot_info in self.slot_info.items()} + self.groups = {slot: slot_info.group_members for slot, slot_info in self.slot_info.items() + if slot_info.type == SlotType.group} + + self.clients = {0: {}} + slot_info: NetworkSlot + slot_id: int + + team_0 = self.clients[0] + for slot_id, slot_info in self.slot_info.items(): + team_0[slot_id] = [] + self.player_names[0, slot_id] = slot_info.name + self.player_name_lookup[slot_info.name] = 0, slot_id + self.read_data[f"hints_{0}_{slot_id}"] = lambda local_team=0, local_player=slot_id: \ + list(self.get_rechecked_hints(local_team, local_player)) + self.seed_name = decoded_obj["seed_name"] self.random.seed(self.seed_name) self.connect_names = decoded_obj['connect_names'] @@ -401,29 +410,9 @@ class Context: for slot, item_codes in decoded_obj["precollected_items"].items(): self.start_inventory[slot] = [NetworkItem(item_code, -2, 0) for item_code in item_codes] - for team in range(len(decoded_obj['names'])): - for slot, hints in decoded_obj["precollected_hints"].items(): - self.hints[team, slot].update(hints) - if "slot_info" in decoded_obj: - self.slot_info = decoded_obj["slot_info"] - self.games = {slot: slot_info.game for slot, slot_info in self.slot_info.items()} - self.groups = {slot: slot_info.group_members for slot, slot_info in self.slot_info.items() - if slot_info.type == SlotType.group} - else: - self.games = decoded_obj["games"] - self.groups = {} - self.slot_info = { - slot: NetworkSlot( - self.player_names[0, slot], - self.games[slot], - SlotType(int(bool(locations)))) - for slot, locations in self.locations.items() - } - # locations may need converting - for slot, locations in self.locations.items(): - for location, item_data in locations.items(): - if len(item_data) < 3: - locations[location] = (*item_data, 0) + for slot, hints in decoded_obj["precollected_hints"].items(): + self.hints[0, slot].update(hints) + # declare slots that aren't players as done for slot, slot_info in self.slot_info.items(): if slot_info.type.always_goal: diff --git a/Utils.py b/Utils.py index 48ec9346..133f1c45 100644 --- a/Utils.py +++ b/Utils.py @@ -12,7 +12,7 @@ import io import collections import importlib import logging -from typing import BinaryIO, ClassVar, Coroutine, Optional, Set +from typing import BinaryIO, Coroutine, Optional, Set from yaml import load, load_all, dump, SafeLoader @@ -38,7 +38,7 @@ class Version(typing.NamedTuple): build: int -__version__ = "0.3.8" +__version__ = "0.3.9" version_tuple = tuplize_version(__version__) is_linux = sys.platform.startswith("linux")