2021-08-20 06:43:59 +02:00
|
|
|
import copy
|
|
|
|
import os
|
|
|
|
from sqlalchemy.engine import Engine # type: ignore
|
|
|
|
from typing import Any, Dict, Optional, Set
|
|
|
|
|
2021-09-07 04:48:33 +02:00
|
|
|
from bemani.common import GameConstants, RegionConstants
|
2021-08-20 06:43:59 +02:00
|
|
|
from bemani.data.types import ArcadeID
|
|
|
|
|
|
|
|
|
|
|
|
class Database:
|
|
|
|
def __init__(self, parent_config: "Config") -> None:
|
|
|
|
self.__config = parent_config
|
|
|
|
|
|
|
|
@property
|
|
|
|
def address(self) -> str:
|
2022-10-15 20:56:30 +02:00
|
|
|
return str(self.__config.get("database", {}).get("address", "localhost"))
|
2021-08-20 06:43:59 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def database(self) -> str:
|
2022-10-15 20:56:30 +02:00
|
|
|
return str(self.__config.get("database", {}).get("database", "bemani"))
|
2021-08-20 06:43:59 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def user(self) -> str:
|
2022-10-15 20:56:30 +02:00
|
|
|
return str(self.__config.get("database", {}).get("user", "bemani"))
|
2021-08-20 06:43:59 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def password(self) -> str:
|
2022-10-15 20:56:30 +02:00
|
|
|
return str(self.__config.get("database", {}).get("password", "bemani"))
|
2021-08-20 06:43:59 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def engine(self) -> Engine:
|
2022-10-15 20:56:30 +02:00
|
|
|
engine = self.__config.get("database", {}).get("engine")
|
2021-08-20 06:43:59 +02:00
|
|
|
if engine is None:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception(
|
|
|
|
"Config object is not instantiated properly, no SQLAlchemy engine present!"
|
|
|
|
)
|
2021-08-20 06:43:59 +02:00
|
|
|
if not isinstance(engine, Engine):
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception(
|
|
|
|
"Config object is not instantiated properly, engine property is not a SQLAlchemy Engine!"
|
|
|
|
)
|
2021-08-20 06:43:59 +02:00
|
|
|
return engine
|
|
|
|
|
|
|
|
@property
|
|
|
|
def read_only(self) -> bool:
|
2022-10-15 20:56:30 +02:00
|
|
|
return bool(self.__config.get("database", {}).get("read_only", False))
|
2021-08-20 06:43:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Server:
|
|
|
|
def __init__(self, parent_config: "Config") -> None:
|
|
|
|
self.__config = parent_config
|
|
|
|
|
|
|
|
@property
|
|
|
|
def address(self) -> str:
|
2022-10-15 20:56:30 +02:00
|
|
|
return str(self.__config.get("server", {}).get("address", "127.0.0.1"))
|
2021-08-20 06:43:59 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def keepalive(self) -> str:
|
2022-10-15 20:56:30 +02:00
|
|
|
return str(self.__config.get("server", {}).get("keepalive", self.address))
|
2021-08-20 06:43:59 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def port(self) -> int:
|
2022-10-15 20:56:30 +02:00
|
|
|
return int(self.__config.get("server", {}).get("port", 80))
|
2021-08-20 06:43:59 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def https(self) -> bool:
|
2022-10-15 20:56:30 +02:00
|
|
|
return bool(self.__config.get("server", {}).get("https", False))
|
2021-08-20 06:43:59 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def uri(self) -> Optional[str]:
|
2022-10-15 20:56:30 +02:00
|
|
|
uri = self.__config.get("server", {}).get("uri")
|
2021-08-20 06:43:59 +02:00
|
|
|
return str(uri) if uri else None
|
|
|
|
|
|
|
|
@property
|
|
|
|
def redirect(self) -> Optional[str]:
|
2022-10-15 20:56:30 +02:00
|
|
|
redirect = self.__config.get("server", {}).get("redirect")
|
2021-08-20 06:43:59 +02:00
|
|
|
return str(redirect) if redirect else None
|
|
|
|
|
|
|
|
@property
|
|
|
|
def enforce_pcbid(self) -> bool:
|
2022-10-15 20:56:30 +02:00
|
|
|
return bool(self.__config.get("server", {}).get("enforce_pcbid", False))
|
2021-08-20 06:43:59 +02:00
|
|
|
|
2021-08-29 03:47:45 +02:00
|
|
|
@property
|
|
|
|
def pcbid_self_grant_limit(self) -> int:
|
2022-10-15 20:56:30 +02:00
|
|
|
return int(self.__config.get("server", {}).get("pcbid_self_grant_limit", 0))
|
2021-08-29 03:47:45 +02:00
|
|
|
|
2021-09-07 04:48:33 +02:00
|
|
|
@property
|
|
|
|
def region(self) -> int:
|
2022-10-15 20:56:30 +02:00
|
|
|
region = int(self.__config.get("server", {}).get("region", RegionConstants.USA))
|
2021-09-07 04:48:33 +02:00
|
|
|
if region in {RegionConstants.EUROPE, RegionConstants.NO_MAPPING}:
|
|
|
|
# Bogus values we support.
|
|
|
|
return region
|
|
|
|
if region < RegionConstants.MIN or region > RegionConstants.MAX:
|
|
|
|
# Pick the original default for the network (USA).
|
|
|
|
return RegionConstants.USA
|
|
|
|
# Region was fine.
|
|
|
|
return region
|
|
|
|
|
2022-10-16 00:05:08 +02:00
|
|
|
@property
|
|
|
|
def area(self) -> Optional[str]:
|
|
|
|
area = self.__config.get("server", {}).get("area")
|
|
|
|
return str(area) if area else None
|
|
|
|
|
2021-08-20 06:43:59 +02:00
|
|
|
|
|
|
|
class Client:
|
|
|
|
def __init__(self, parent_config: "Config") -> None:
|
|
|
|
self.__config = parent_config
|
|
|
|
|
|
|
|
@property
|
|
|
|
def address(self) -> str:
|
2022-10-15 20:56:30 +02:00
|
|
|
address = self.__config.get("client", {}).get("address")
|
2021-08-20 06:43:59 +02:00
|
|
|
if address is None:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception(
|
|
|
|
"Config object is not instantiated properly, no client address present!"
|
|
|
|
)
|
2021-08-20 06:43:59 +02:00
|
|
|
return str(address)
|
|
|
|
|
|
|
|
|
|
|
|
class Machine:
|
|
|
|
def __init__(self, parent_config: "Config") -> None:
|
|
|
|
self.__config = parent_config
|
|
|
|
|
|
|
|
@property
|
|
|
|
def pcbid(self) -> str:
|
2022-10-15 20:56:30 +02:00
|
|
|
pcbid = self.__config.get("machine", {}).get("pcbid")
|
2021-08-20 06:43:59 +02:00
|
|
|
if pcbid is None:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception(
|
|
|
|
"Config object is not instantiated properly, no machine pcbid present!"
|
|
|
|
)
|
2021-08-20 06:43:59 +02:00
|
|
|
return str(pcbid)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def arcade(self) -> Optional[ArcadeID]:
|
2022-10-15 20:56:30 +02:00
|
|
|
return self.__config.get("machine", {}).get("arcade")
|
2021-08-20 06:43:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
class PASELI:
|
|
|
|
def __init__(self, parent_config: "Config") -> None:
|
|
|
|
self.__config = parent_config
|
|
|
|
|
|
|
|
@property
|
|
|
|
def enabled(self) -> bool:
|
2022-10-15 20:56:30 +02:00
|
|
|
return bool(self.__config.get("paseli", {}).get("enabled", False))
|
2021-08-20 06:43:59 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def infinite(self) -> bool:
|
2022-10-15 20:56:30 +02:00
|
|
|
return bool(self.__config.get("paseli", {}).get("infinite", False))
|
2021-08-20 06:43:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
class WebHooks:
|
|
|
|
def __init__(self, parent_config: "Config") -> None:
|
|
|
|
self.discord = DiscordWebHooks(parent_config)
|
|
|
|
|
|
|
|
|
|
|
|
class DiscordWebHooks:
|
|
|
|
def __init__(self, parent_config: "Config") -> None:
|
|
|
|
self.__config = parent_config
|
|
|
|
|
|
|
|
def __getitem__(self, key: GameConstants) -> Optional[str]:
|
2022-10-15 20:56:30 +02:00
|
|
|
uri = self.__config.get("webhooks", {}).get("discord", {}).get(key.value)
|
2021-08-20 06:43:59 +02:00
|
|
|
return str(uri) if uri else None
|
|
|
|
|
|
|
|
|
2022-11-13 17:56:59 +01:00
|
|
|
class Assets:
|
|
|
|
def __init__(self, parent_config: "Config") -> None:
|
|
|
|
self.jubeat = JubeatAssets(parent_config)
|
|
|
|
|
|
|
|
|
|
|
|
class JubeatAssets:
|
|
|
|
def __init__(self, parent_config: "Config") -> None:
|
|
|
|
self.__config = parent_config
|
|
|
|
|
|
|
|
@property
|
|
|
|
def emblems(self) -> Optional[str]:
|
|
|
|
directory = self.__config.get("assets", {}).get("jubeat", {}).get("emblems")
|
|
|
|
return str(directory) if directory else None
|
|
|
|
|
|
|
|
|
2021-08-20 06:43:59 +02:00
|
|
|
class Config(dict):
|
|
|
|
def __init__(self, existing_contents: Dict[str, Any] = {}) -> None:
|
|
|
|
super().__init__(existing_contents or {})
|
|
|
|
|
|
|
|
self.database = Database(self)
|
|
|
|
self.server = Server(self)
|
|
|
|
self.client = Client(self)
|
|
|
|
self.paseli = PASELI(self)
|
|
|
|
self.webhooks = WebHooks(self)
|
2022-11-13 17:56:59 +01:00
|
|
|
self.assets = Assets(self)
|
2021-08-20 06:43:59 +02:00
|
|
|
self.machine = Machine(self)
|
|
|
|
|
|
|
|
def clone(self) -> "Config":
|
|
|
|
# Somehow its not possible to clone this object if an instantiated Engine is present,
|
|
|
|
# so we do a little shenanigans here.
|
2022-10-15 20:56:30 +02:00
|
|
|
engine = self.get("database", {}).get("engine")
|
2021-08-20 06:43:59 +02:00
|
|
|
if engine is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
self["database"]["engine"] = None
|
2021-08-20 06:43:59 +02:00
|
|
|
|
|
|
|
clone = Config(copy.deepcopy(self))
|
|
|
|
|
|
|
|
if engine is not None:
|
2022-10-15 20:56:30 +02:00
|
|
|
self["database"]["engine"] = engine
|
|
|
|
clone["database"]["engine"] = engine
|
2021-08-20 06:43:59 +02:00
|
|
|
|
|
|
|
return clone
|
|
|
|
|
|
|
|
@property
|
|
|
|
def filename(self) -> str:
|
2022-10-15 20:56:30 +02:00
|
|
|
filename = self.get("filename")
|
2021-08-20 06:43:59 +02:00
|
|
|
if filename is None:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception(
|
|
|
|
"Config object is not instantiated properly, no filename present!"
|
|
|
|
)
|
2021-08-20 06:43:59 +02:00
|
|
|
return os.path.abspath(str(filename))
|
|
|
|
|
|
|
|
@property
|
|
|
|
def support(self) -> Set[GameConstants]:
|
2022-10-15 20:56:30 +02:00
|
|
|
support = self.get("support")
|
2021-08-20 06:43:59 +02:00
|
|
|
if support is None:
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception(
|
|
|
|
"Config object is not instantiated properly, no support list present!"
|
|
|
|
)
|
2021-08-20 06:43:59 +02:00
|
|
|
if not isinstance(support, set):
|
2022-10-15 20:56:30 +02:00
|
|
|
raise Exception(
|
|
|
|
"Config object is not instantiated properly, support property is not a Set!"
|
|
|
|
)
|
2021-08-20 06:43:59 +02:00
|
|
|
return support
|
|
|
|
|
|
|
|
@property
|
|
|
|
def secret_key(self) -> str:
|
2022-10-15 20:56:30 +02:00
|
|
|
return str(self.get("secret_key", "youdidntchangethisatalldidyou?"))
|
2021-08-20 06:43:59 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self) -> str:
|
2022-10-15 20:56:30 +02:00
|
|
|
return str(self.get("name", "e-AMUSEMENT Network"))
|
2021-08-20 06:43:59 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def email(self) -> str:
|
2022-10-15 20:56:30 +02:00
|
|
|
return str(self.get("email", "nobody@nowhere.com"))
|
2021-08-20 06:43:59 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def cache_dir(self) -> str:
|
2022-10-15 20:56:30 +02:00
|
|
|
return os.path.abspath(str(self.get("cache_dir", "/tmp")))
|
2021-08-20 06:43:59 +02:00
|
|
|
|
2021-08-31 23:40:30 +02:00
|
|
|
@property
|
|
|
|
def theme(self) -> str:
|
2022-10-15 20:56:30 +02:00
|
|
|
return str(self.get("theme", "default"))
|
2021-08-31 23:40:30 +02:00
|
|
|
|
2021-08-20 06:43:59 +02:00
|
|
|
@property
|
|
|
|
def event_log_duration(self) -> Optional[int]:
|
2022-10-15 20:56:30 +02:00
|
|
|
duration = self.get("event_log_duration")
|
2021-08-20 06:43:59 +02:00
|
|
|
return int(duration) if duration else None
|