2023-02-16 06:06:42 +01:00
|
|
|
import logging, os
|
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
class ServerConfig:
|
|
|
|
def __init__(self, parent_config: "CoreConfig") -> None:
|
|
|
|
self.__config = parent_config
|
|
|
|
|
|
|
|
@property
|
|
|
|
def listen_address(self) -> str:
|
2024-01-09 09:07:04 +01:00
|
|
|
"""
|
|
|
|
Address Artemis will bind to and listen on
|
|
|
|
"""
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "server", "listen_address", default="127.0.0.1"
|
|
|
|
)
|
2024-01-09 09:07:04 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def hostname(self) -> str:
|
|
|
|
"""
|
|
|
|
Hostname sent to games
|
|
|
|
"""
|
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "server", "hostname", default="localhost"
|
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def port(self) -> int:
|
|
|
|
"""
|
|
|
|
Port the game will listen on
|
|
|
|
"""
|
|
|
|
return CoreConfig.get_config_field(
|
2024-01-11 18:08:22 +01:00
|
|
|
self.__config, "core", "server", "port", default=80
|
2024-01-09 09:07:04 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def ssl_key(self) -> str:
|
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "server", "ssl_key", default="cert/title.key"
|
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def ssl_cert(self) -> str:
|
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "title", "ssl_cert", default="cert/title.pem"
|
|
|
|
)
|
2023-02-16 06:06:42 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def allow_user_registration(self) -> bool:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "server", "allow_user_registration", default=True
|
|
|
|
)
|
2023-02-16 06:06:42 +01:00
|
|
|
|
|
|
|
@property
|
2023-02-18 06:00:30 +01:00
|
|
|
def allow_unregistered_serials(self) -> bool:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "server", "allow_unregistered_serials", default=True
|
|
|
|
)
|
2023-02-16 06:06:42 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self) -> str:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "server", "name", default="ARTEMiS"
|
|
|
|
)
|
2023-02-16 06:06:42 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_develop(self) -> bool:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "server", "is_develop", default=True
|
|
|
|
)
|
2023-02-16 06:06:42 +01:00
|
|
|
|
2023-11-09 03:17:48 +01:00
|
|
|
@property
|
|
|
|
def is_using_proxy(self) -> bool:
|
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "server", "is_using_proxy", default=False
|
|
|
|
)
|
|
|
|
|
2023-07-08 06:34:55 +02:00
|
|
|
@property
|
2024-01-09 09:07:04 +01:00
|
|
|
def proxy_port(self) -> int:
|
|
|
|
"""
|
|
|
|
What port the proxy is listening on. This will be sent instead of 'port' if
|
|
|
|
is_using_proxy is True and this value is non-zero
|
|
|
|
"""
|
2023-07-08 06:34:55 +02:00
|
|
|
return CoreConfig.get_config_field(
|
2024-01-09 09:07:04 +01:00
|
|
|
self.__config, "core", "title", "proxy_port", default=0
|
2023-07-08 06:34:55 +02:00
|
|
|
)
|
|
|
|
|
2024-01-09 23:49:18 +01:00
|
|
|
@property
|
|
|
|
def proxy_port_ssl(self) -> int:
|
|
|
|
"""
|
|
|
|
What port the proxy is listening for secure connections on. This will be sent
|
|
|
|
instead of 'port' if is_using_proxy is True and this value is non-zero
|
|
|
|
"""
|
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "title", "proxy_port_ssl", default=0
|
|
|
|
)
|
|
|
|
|
2023-02-16 06:06:42 +01:00
|
|
|
@property
|
|
|
|
def log_dir(self) -> str:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "server", "log_dir", default="logs"
|
|
|
|
)
|
|
|
|
|
2023-08-08 16:24:28 +02:00
|
|
|
@property
|
|
|
|
def check_arcade_ip(self) -> bool:
|
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "server", "check_arcade_ip", default=False
|
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def strict_ip_checking(self) -> bool:
|
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "server", "strict_ip_checking", default=False
|
|
|
|
)
|
|
|
|
|
2023-02-16 06:06:42 +01:00
|
|
|
class TitleConfig:
|
|
|
|
def __init__(self, parent_config: "CoreConfig") -> None:
|
|
|
|
self.__config = parent_config
|
|
|
|
|
|
|
|
@property
|
|
|
|
def loglevel(self) -> int:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.str_to_loglevel(
|
|
|
|
CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "title", "loglevel", default="info"
|
|
|
|
)
|
|
|
|
)
|
2023-02-16 06:06:42 +01:00
|
|
|
|
2023-10-16 15:22:18 +02:00
|
|
|
@property
|
|
|
|
def reboot_start_time(self) -> str:
|
|
|
|
return CoreConfig.get_config_field(
|
2024-01-11 18:08:22 +01:00
|
|
|
self.__config, "core", "title", "reboot_start_time", default=""
|
2023-10-16 15:22:18 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def reboot_end_time(self) -> str:
|
|
|
|
return CoreConfig.get_config_field(
|
2024-01-11 18:08:22 +01:00
|
|
|
self.__config, "core", "title", "reboot_end_time", default=""
|
2023-10-16 15:22:18 +02:00
|
|
|
)
|
|
|
|
|
2023-02-16 06:06:42 +01:00
|
|
|
class DatabaseConfig:
|
|
|
|
def __init__(self, parent_config: "CoreConfig") -> None:
|
|
|
|
self.__config = parent_config
|
|
|
|
|
|
|
|
@property
|
|
|
|
def host(self) -> str:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "database", "host", default="localhost"
|
|
|
|
)
|
2023-02-16 06:06:42 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def username(self) -> str:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "database", "username", default="aime"
|
|
|
|
)
|
2023-02-16 06:06:42 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def password(self) -> str:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "database", "password", default="aime"
|
|
|
|
)
|
2023-02-16 06:06:42 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self) -> str:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "database", "name", default="aime"
|
|
|
|
)
|
2023-02-16 06:06:42 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def port(self) -> int:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "database", "port", default=3306
|
|
|
|
)
|
2023-02-16 06:06:42 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def protocol(self) -> str:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "database", "type", default="mysql"
|
|
|
|
)
|
|
|
|
|
2023-02-16 06:06:42 +01:00
|
|
|
@property
|
|
|
|
def sha2_password(self) -> bool:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "database", "sha2_password", default=False
|
|
|
|
)
|
|
|
|
|
2023-02-16 06:06:42 +01:00
|
|
|
@property
|
|
|
|
def loglevel(self) -> int:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.str_to_loglevel(
|
|
|
|
CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "database", "loglevel", default="info"
|
|
|
|
)
|
|
|
|
)
|
2023-02-16 06:06:42 +01:00
|
|
|
|
2023-10-06 04:16:50 +02:00
|
|
|
@property
|
|
|
|
def enable_memcached(self) -> bool:
|
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "database", "enable_memcached", default=True
|
|
|
|
)
|
|
|
|
|
2023-02-16 06:06:42 +01:00
|
|
|
@property
|
|
|
|
def memcached_host(self) -> str:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "database", "memcached_host", default="localhost"
|
|
|
|
)
|
|
|
|
|
2023-02-16 06:06:42 +01:00
|
|
|
class FrontendConfig:
|
|
|
|
def __init__(self, parent_config: "CoreConfig") -> None:
|
|
|
|
self.__config = parent_config
|
|
|
|
|
|
|
|
@property
|
2024-01-11 18:08:22 +01:00
|
|
|
def enable(self) -> bool:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.get_config_field(
|
2024-01-11 18:08:22 +01:00
|
|
|
self.__config, "core", "frontend", "enable", default=False
|
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def port(self) -> int:
|
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "frontend", "port", default=8080
|
2023-03-09 17:38:58 +01:00
|
|
|
)
|
|
|
|
|
2023-02-16 06:06:42 +01:00
|
|
|
@property
|
|
|
|
def loglevel(self) -> int:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.str_to_loglevel(
|
|
|
|
CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "frontend", "loglevel", default="info"
|
|
|
|
)
|
|
|
|
)
|
2024-01-09 09:07:04 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def secret(self) -> str:
|
2024-01-09 21:54:34 +01:00
|
|
|
return CoreConfig.get_config_field(
|
2024-01-09 09:07:04 +01:00
|
|
|
self.__config, "core", "frontend", "secret", default=""
|
|
|
|
)
|
2023-02-16 06:06:42 +01:00
|
|
|
|
|
|
|
class AllnetConfig:
|
|
|
|
def __init__(self, parent_config: "CoreConfig") -> None:
|
|
|
|
self.__config = parent_config
|
|
|
|
|
2024-01-11 18:08:22 +01:00
|
|
|
@property
|
|
|
|
def standalone(self) -> bool:
|
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "allnet", "standalone", default=False
|
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def port(self) -> int:
|
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "allnet", "port", default=80
|
|
|
|
)
|
|
|
|
|
2023-02-16 06:06:42 +01:00
|
|
|
@property
|
|
|
|
def loglevel(self) -> int:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.str_to_loglevel(
|
|
|
|
CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "allnet", "loglevel", default="info"
|
|
|
|
)
|
|
|
|
)
|
2023-02-16 06:06:42 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def allow_online_updates(self) -> int:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "allnet", "allow_online_updates", default=False
|
|
|
|
)
|
|
|
|
|
2023-04-24 01:00:30 +02:00
|
|
|
@property
|
|
|
|
def update_cfg_folder(self) -> str:
|
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "allnet", "update_cfg_folder", default=""
|
|
|
|
)
|
2023-02-16 06:06:42 +01:00
|
|
|
|
|
|
|
class BillingConfig:
|
|
|
|
def __init__(self, parent_config: "CoreConfig") -> None:
|
|
|
|
self.__config = parent_config
|
2024-01-09 09:07:04 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def standalone(self) -> bool:
|
|
|
|
return CoreConfig.get_config_field(
|
2024-01-11 18:09:19 +01:00
|
|
|
self.__config, "core", "billing", "standalone", default=True
|
2024-01-09 09:07:04 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def loglevel(self) -> int:
|
|
|
|
return CoreConfig.str_to_loglevel(
|
|
|
|
CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "billing", "loglevel", default="info"
|
|
|
|
)
|
|
|
|
)
|
2023-02-16 06:06:42 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def port(self) -> int:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "billing", "port", default=8443
|
|
|
|
)
|
2023-02-16 06:06:42 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def ssl_key(self) -> str:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "billing", "ssl_key", default="cert/server.key"
|
|
|
|
)
|
2023-02-16 06:06:42 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def ssl_cert(self) -> str:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "billing", "ssl_cert", default="cert/server.pem"
|
|
|
|
)
|
|
|
|
|
2023-02-16 06:06:42 +01:00
|
|
|
@property
|
|
|
|
def signing_key(self) -> str:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "billing", "signing_key", default="cert/billing.key"
|
|
|
|
)
|
|
|
|
|
2023-02-16 06:06:42 +01:00
|
|
|
class AimedbConfig:
|
|
|
|
def __init__(self, parent_config: "CoreConfig") -> None:
|
|
|
|
self.__config = parent_config
|
2023-03-09 17:38:58 +01:00
|
|
|
|
2024-01-11 18:25:35 +01:00
|
|
|
@property
|
|
|
|
def enable(self) -> bool:
|
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "aimedb", "enable", default=True
|
|
|
|
)
|
|
|
|
|
2023-02-16 06:06:42 +01:00
|
|
|
@property
|
|
|
|
def loglevel(self) -> int:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.str_to_loglevel(
|
|
|
|
CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "aimedb", "loglevel", default="info"
|
|
|
|
)
|
|
|
|
)
|
2023-02-16 06:06:42 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def port(self) -> int:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "aimedb", "port", default=22345
|
|
|
|
)
|
2023-02-16 06:06:42 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def key(self) -> str:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "aimedb", "key", default=""
|
|
|
|
)
|
|
|
|
|
2023-11-30 00:01:19 +01:00
|
|
|
@property
|
|
|
|
def id_secret(self) -> str:
|
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "aimedb", "id_secret", default=""
|
|
|
|
)
|
|
|
|
|
2023-12-01 00:22:01 +01:00
|
|
|
@property
|
|
|
|
def id_lifetime_seconds(self) -> int:
|
|
|
|
return CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "aimedb", "id_lifetime_seconds", default=86400
|
|
|
|
)
|
|
|
|
|
2023-02-17 07:37:59 +01:00
|
|
|
class MuchaConfig:
|
|
|
|
def __init__(self, parent_config: "CoreConfig") -> None:
|
|
|
|
self.__config = parent_config
|
|
|
|
|
|
|
|
@property
|
|
|
|
def loglevel(self) -> int:
|
2023-03-09 17:38:58 +01:00
|
|
|
return CoreConfig.str_to_loglevel(
|
|
|
|
CoreConfig.get_config_field(
|
|
|
|
self.__config, "core", "mucha", "loglevel", default="info"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2023-02-16 06:06:42 +01:00
|
|
|
class CoreConfig(dict):
|
|
|
|
def __init__(self) -> None:
|
|
|
|
self.server = ServerConfig(self)
|
|
|
|
self.title = TitleConfig(self)
|
|
|
|
self.database = DatabaseConfig(self)
|
|
|
|
self.frontend = FrontendConfig(self)
|
|
|
|
self.allnet = AllnetConfig(self)
|
|
|
|
self.billing = BillingConfig(self)
|
|
|
|
self.aimedb = AimedbConfig(self)
|
2023-02-21 22:46:43 +01:00
|
|
|
self.mucha = MuchaConfig(self)
|
2023-02-16 06:06:42 +01:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def str_to_loglevel(cls, level_str: str):
|
|
|
|
if level_str.lower() == "error":
|
|
|
|
return logging.ERROR
|
2023-03-09 17:38:58 +01:00
|
|
|
elif level_str.lower().startswith("warn"): # Fits warn or warning
|
2023-02-16 06:06:42 +01:00
|
|
|
return logging.WARN
|
|
|
|
elif level_str.lower() == "debug":
|
|
|
|
return logging.DEBUG
|
|
|
|
else:
|
2023-03-09 17:38:58 +01:00
|
|
|
return logging.INFO
|
2024-01-11 18:08:22 +01:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def loglevel_to_str(cls, level: int) -> str:
|
|
|
|
if level == logging.ERROR:
|
|
|
|
return "error"
|
|
|
|
elif level == logging.WARN:
|
|
|
|
return "warn"
|
|
|
|
elif level == logging.INFO:
|
|
|
|
return "info"
|
|
|
|
elif level == logging.DEBUG:
|
|
|
|
return "debug"
|
|
|
|
else:
|
|
|
|
return "notset"
|
2023-02-16 06:06:42 +01:00
|
|
|
|
|
|
|
@classmethod
|
2023-03-09 17:38:58 +01:00
|
|
|
def get_config_field(
|
|
|
|
cls, __config: dict, module, *path: str, default: Any = ""
|
|
|
|
) -> Any:
|
|
|
|
envKey = f"CFG_{module}_"
|
2023-02-16 06:06:42 +01:00
|
|
|
for arg in path:
|
2023-03-09 17:38:58 +01:00
|
|
|
envKey += arg + "_"
|
|
|
|
|
|
|
|
if envKey.endswith("_"):
|
2023-02-16 06:06:42 +01:00
|
|
|
envKey = envKey[:-1]
|
|
|
|
|
|
|
|
if envKey in os.environ:
|
|
|
|
return os.environ.get(envKey)
|
|
|
|
|
|
|
|
read = __config
|
|
|
|
|
|
|
|
for x in range(len(path) - 1):
|
|
|
|
read = read.get(path[x], {})
|
|
|
|
|
|
|
|
return read.get(path[len(path) - 1], default)
|