47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
from dataclasses import asdict, dataclass
|
|
import os
|
|
import json
|
|
from dacite import from_dict
|
|
|
|
|
|
@dataclass
|
|
class ServerConfig:
|
|
IP: str
|
|
Port: int
|
|
|
|
|
|
@dataclass
|
|
class ConfigData:
|
|
LogLevel: str
|
|
GameServer: ServerConfig
|
|
SDKServer: ServerConfig
|
|
SRToolsServer: ServerConfig
|
|
RegionName: str
|
|
PacketLog: bool
|
|
def write_default_config():
|
|
config = ConfigData(
|
|
LogLevel="INFO",
|
|
GameServer=ServerConfig(IP="127.0.0.1", Port=23301),
|
|
SDKServer=ServerConfig(IP="127.0.0.1", Port=21000),
|
|
SRToolsServer=ServerConfig(IP="127.0.0.1", Port=25000),
|
|
RegionName="NeonSR",
|
|
PacketLog=True,
|
|
)
|
|
with open("Config.json", "w") as f:
|
|
f.write(json.dumps(asdict(config), indent=2))
|
|
|
|
return config
|
|
|
|
def load():
|
|
if not os.path.exists("Config.json"):
|
|
return ConfigData.write_default_config()
|
|
|
|
with open("Config.json", "r", encoding="utf-8") as f:
|
|
try:
|
|
return from_dict(ConfigData, json.load(f))
|
|
except Exception:
|
|
return ConfigData.write_default_config()
|
|
|
|
|
|
Config : ConfigData = ConfigData.load()
|