WebHost: CustomServer: use defaultdicts
also change non_hintable to defaultdict in MultiServer and add some typing
This commit is contained in:
parent
101dab0ea4
commit
4686881566
|
@ -126,6 +126,7 @@ class Context:
|
||||||
location_names: typing.Dict[int, str] = Utils.KeyedDefaultDict(lambda code: f'Unknown location (ID:{code})')
|
location_names: typing.Dict[int, str] = Utils.KeyedDefaultDict(lambda code: f'Unknown location (ID:{code})')
|
||||||
all_item_and_group_names: typing.Dict[str, typing.Set[str]]
|
all_item_and_group_names: typing.Dict[str, typing.Set[str]]
|
||||||
forced_auto_forfeits: typing.Dict[str, bool]
|
forced_auto_forfeits: typing.Dict[str, bool]
|
||||||
|
non_hintable_names: typing.Dict[str, typing.Set[str]]
|
||||||
|
|
||||||
def __init__(self, host: str, port: int, server_password: str, password: str, location_check_points: int,
|
def __init__(self, host: str, port: int, server_password: str, password: str, location_check_points: int,
|
||||||
hint_cost: int, item_cheat: bool, forfeit_mode: str = "disabled", collect_mode="disabled",
|
hint_cost: int, item_cheat: bool, forfeit_mode: str = "disabled", collect_mode="disabled",
|
||||||
|
@ -196,7 +197,7 @@ class Context:
|
||||||
self.item_name_groups = {}
|
self.item_name_groups = {}
|
||||||
self.all_item_and_group_names = {}
|
self.all_item_and_group_names = {}
|
||||||
self.forced_auto_forfeits = collections.defaultdict(lambda: False)
|
self.forced_auto_forfeits = collections.defaultdict(lambda: False)
|
||||||
self.non_hintable_names = {}
|
self.non_hintable_names = collections.defaultdict(frozenset)
|
||||||
|
|
||||||
self._load_game_data()
|
self._load_game_data()
|
||||||
self._init_game_data()
|
self._init_game_data()
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import functools
|
|
||||||
import websockets
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import collections
|
||||||
|
import datetime
|
||||||
|
import functools
|
||||||
|
import logging
|
||||||
|
import pickle
|
||||||
|
import random
|
||||||
import socket
|
import socket
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import random
|
import websockets
|
||||||
import pickle
|
|
||||||
import logging
|
|
||||||
import datetime
|
|
||||||
|
|
||||||
import Utils
|
import Utils
|
||||||
from .models import db_session, Room, select, commit, Command, db
|
from .models import db_session, Room, select, commit, Command, db
|
||||||
|
@ -49,6 +50,8 @@ class DBCommandProcessor(ServerCommandProcessor):
|
||||||
|
|
||||||
|
|
||||||
class WebHostContext(Context):
|
class WebHostContext(Context):
|
||||||
|
room_id: int
|
||||||
|
|
||||||
def __init__(self, static_server_data: dict):
|
def __init__(self, static_server_data: dict):
|
||||||
# static server data is used during _load_game_data to load required data,
|
# static server data is used during _load_game_data to load required data,
|
||||||
# without needing to import worlds system, which takes quite a bit of memory
|
# without needing to import worlds system, which takes quite a bit of memory
|
||||||
|
@ -62,6 +65,8 @@ class WebHostContext(Context):
|
||||||
def _load_game_data(self):
|
def _load_game_data(self):
|
||||||
for key, value in self.static_server_data.items():
|
for key, value in self.static_server_data.items():
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
|
self.forced_auto_forfeits = collections.defaultdict(lambda: False, self.forced_auto_forfeits)
|
||||||
|
self.non_hintable_names = collections.defaultdict(frozenset, self.non_hintable_names)
|
||||||
|
|
||||||
def listen_to_db_commands(self):
|
def listen_to_db_commands(self):
|
||||||
cmdprocessor = DBCommandProcessor(self)
|
cmdprocessor = DBCommandProcessor(self)
|
||||||
|
|
Loading…
Reference in New Issue