Initial commit

This commit is contained in:
Naruse
2024-11-07 23:25:15 +08:00
commit e8e5f3a1a7
246 changed files with 27356 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
# 头文件, 负责统一引用外部库
# 本文件夹下的文件禁止引用此文件
import os
import sys
import json
import time
import zlib
import base64
import socket
import struct
import logging
import requests
import threading
from dynaconf import Dynaconf
from flask import Flask, request, jsonify, send_from_directory, Blueprint
from pathlib import Path
from enum import Enum
from .config import *
from .log import * # TODO: After config to tempfix config.json not found error
from lib import proto as protos
from pprint import pprint
import importlib
import re
__all__ = [
"os",
"sys",
"json",
"time",
"zlib",
"base64",
"socket",
"struct",
"logging",
"threading",
"Dynaconf",
"Flask",
"request",
"requests",
"jsonify",
"send_from_directory",
"Blueprint",
"Path",
"Enum",
"Log",
"Error",
"Warn",
"Info",
"Debug",
"Config",
"Root",
"protos",
"pprint",
"importlib",
"re"
]

View File

@@ -0,0 +1,42 @@
import os
import json
from dynaconf import Dynaconf
# 此处设置默认值
Root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
ConfigData = {
"LogLevel": "INFO",
"MaxSessions": 10,
"GameServer": {
"Ip": "127.0.0.1",
"Port": 16100
},
"SdkServer": {
"Ip": "127.0.0.1",
"Port": 80
},
"VerboseLevel":1,
"RegionName":"MikuBH3",
"UseLocalCache":False
}
class ConfigInit:
def __init__(self):
self.ConfigPath = f"{Root}/../Config.json"
self.ConfigData = self.Load()
if not os.path.exists(self.ConfigPath):
with open(self.ConfigPath, 'w') as f:
json.dump(ConfigData, f, indent=4)
def Load(self):
Settings = Dynaconf(
settings_files = [self.ConfigPath],
default_settings = ConfigData
)
return Settings
def Get(self):
return self.ConfigData
Config = ConfigInit().Load()

37
game_server/config/log.py Normal file
View File

@@ -0,0 +1,37 @@
import json
import sys
from loguru import logger
# Configuration for the logger
logger.remove()
with open("Config.json", "r", encoding="utf-8") as f:
LogLevel = json.load(f)["LogLevel"]
LevelList = ["ERROR", "WARNING", "INFO", "DEBUG"]
CodeColorDict = {
"ERROR": "red",
"WARNING": "yellow",
"INFO": "green",
"DEBUG": "blue"
}
def custom_format(record):
color = CodeColorDict[record["level"].name]
return f"<{color}>{record['level'].name}</{color}> : {record['message']}\n"
logger.add(sys.stdout, format=custom_format, colorize=True, level=LogLevel)
def Log(msg, types):
if types in CodeColorDict and LevelList.index(types) <= LevelList.index(LogLevel):
getattr(logger, types.lower())(msg)
def Error(msg):
Log(msg, "ERROR")
def Warn(msg):
Log(msg, "WARNING")
def Info(msg):
Log(msg, "INFO")
def Debug(msg):
Log(msg, "DEBUG")