FoxWorld-server/config.py
2025-04-11 11:22:16 +03:00

31 lines
601 B
Python

import yaml
import os.path
print("Loading config.")
_DEFAULT_CONFIGURATION = """
log_level: "INFO"
max_players: 10
world_seed: 0
net:
host: "::"
port: 7512
"""[1:] # remove leading \n
def _load_defconf():
global c
with open("config.yml", "w") as fp:
fp.write(_DEFAULT_CONFIGURATION)
c = yaml.safe_load(_DEFAULT_CONFIGURATION)
if os.path.isfile("config.yml"):
with open("config.yml") as fp:
try:
c = yaml.safe_load(fp)
except:
print("Error while loading config! Loading defaults.")
_load_defconf()
else:
print("Non existent config file! Loading defaults.")
_load_defconf()