Тестовый SQLite.
This commit is contained in:
parent
de07725212
commit
bcba51ac5d
|
|
@ -7,12 +7,16 @@ tamtam_ws_port = "82"
|
||||||
|
|
||||||
log_level = "debug"
|
log_level = "debug"
|
||||||
|
|
||||||
|
db_type = "mysql"
|
||||||
|
|
||||||
db_host = "localhost"
|
db_host = "localhost"
|
||||||
db_port = "3306"
|
db_port = "3306"
|
||||||
db_user = "root"
|
db_user = "root"
|
||||||
db_password = "password"
|
db_password = "password"
|
||||||
db_name = "openmax"
|
db_name = "openmax"
|
||||||
|
|
||||||
|
db_file = ""
|
||||||
|
|
||||||
certfile = "cert.pem"
|
certfile = "cert.pem"
|
||||||
keyfile = "key.pem"
|
keyfile = "key.pem"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
__pycache__
|
__pycache__
|
||||||
.env
|
.env
|
||||||
cert.pem
|
*.pem
|
||||||
key.pem
|
*.sqlite
|
||||||
1
LICENSE
1
LICENSE
|
|
@ -1,4 +1,5 @@
|
||||||
Copyright 2025-2026 Alexey Polyakov
|
Copyright 2025-2026 Alexey Polyakov
|
||||||
|
2026 Inception Time
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,9 @@
|
||||||
# Требования
|
# Требования
|
||||||
|
|
||||||
- Python 3.12+ (поддержка версий ниже не гарантирована)
|
- Python 3.12+ (поддержка версий ниже не гарантирована)
|
||||||
- MariaDB или MySQL
|
- MariaDB, MySQL или SQLite
|
||||||
- Уметь патчить клиент MAX или собирать Komet из исходного кода (естественно с заменой сервера)
|
- Уметь патчить клиент MAX или собирать Komet из исходного кода (естественно с заменой сервера)
|
||||||
|
- Сертификат и приватный ключ X.509
|
||||||
|
|
||||||
# Требования к клиенту
|
# Требования к клиенту
|
||||||
|
|
||||||
|
|
@ -20,7 +21,6 @@
|
||||||
```bash
|
```bash
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Настройте сервер (пример в `.env.example`)
|
3. Настройте сервер (пример в `.env.example`)
|
||||||
4. Импортируйте схему таблиц в свою базу данных из `tables.sql`
|
4. Импортируйте схему таблиц в свою базу данных из `tables.sql`
|
||||||
5. Запустите сервер
|
5. Запустите сервер
|
||||||
|
|
|
||||||
|
|
@ -3,4 +3,7 @@ aiomysql
|
||||||
python-dotenv
|
python-dotenv
|
||||||
msgpack
|
msgpack
|
||||||
lz4
|
lz4
|
||||||
websockets
|
websockets
|
||||||
|
pydantic
|
||||||
|
aiohttp
|
||||||
|
aiosqlite
|
||||||
|
|
@ -20,6 +20,9 @@ class ServerConfig:
|
||||||
### Уровень отладки
|
### Уровень отладки
|
||||||
log_level = os.getenv("log_level") or "debug"
|
log_level = os.getenv("log_level") or "debug"
|
||||||
|
|
||||||
|
### Тип базы данных
|
||||||
|
db_type = os.getenv("db_type") or "mysql"
|
||||||
|
|
||||||
### MySQL
|
### MySQL
|
||||||
db_host = os.getenv("db_host") or "127.0.0.1"
|
db_host = os.getenv("db_host") or "127.0.0.1"
|
||||||
db_port = int(os.getenv("db_port") or 3306)
|
db_port = int(os.getenv("db_port") or 3306)
|
||||||
|
|
@ -27,6 +30,9 @@ class ServerConfig:
|
||||||
db_password = os.getenv("db_password") or "qwerty"
|
db_password = os.getenv("db_password") or "qwerty"
|
||||||
db_name = os.getenv("db_name") or "openmax"
|
db_name = os.getenv("db_name") or "openmax"
|
||||||
|
|
||||||
|
### SQLite
|
||||||
|
db_file = os.getenv("db_file") or "openmax.db"
|
||||||
|
|
||||||
### SSL
|
### SSL
|
||||||
certfile = os.getenv("certfile") or "cert.pem"
|
certfile = os.getenv("certfile") or "cert.pem"
|
||||||
keyfile = os.getenv("keyfile") or "key.pem"
|
keyfile = os.getenv("keyfile") or "key.pem"
|
||||||
|
|
|
||||||
30
src/main.py
30
src/main.py
|
|
@ -1,5 +1,5 @@
|
||||||
# Импортирование библиотек
|
# Импортирование библиотек
|
||||||
import aiomysql, ssl, logging, asyncio
|
import ssl, logging, asyncio
|
||||||
from common.config import ServerConfig
|
from common.config import ServerConfig
|
||||||
from oneme_tcp.controller import OnemeMobileController
|
from oneme_tcp.controller import OnemeMobileController
|
||||||
from telegrambot.controller import TelegramBotController
|
from telegrambot.controller import TelegramBotController
|
||||||
|
|
@ -10,16 +10,24 @@ server_config = ServerConfig()
|
||||||
|
|
||||||
async def init_db():
|
async def init_db():
|
||||||
"""Инициализация базы данных"""
|
"""Инициализация базы данных"""
|
||||||
# Создаем пул
|
|
||||||
db = await aiomysql.create_pool(
|
db = {}
|
||||||
host=server_config.db_host,
|
|
||||||
port=server_config.db_port,
|
if server_config.db_type == "mysql":
|
||||||
user=server_config.db_user,
|
import aiomysql
|
||||||
password=server_config.db_password,
|
db = await aiomysql.create_pool(
|
||||||
db=server_config.db_name,
|
host=server_config.db_host,
|
||||||
cursorclass=aiomysql.DictCursor,
|
port=server_config.db_port,
|
||||||
autocommit=True
|
user=server_config.db_user,
|
||||||
)
|
password=server_config.db_password,
|
||||||
|
db=server_config.db_name,
|
||||||
|
cursorclass=aiomysql.DictCursor,
|
||||||
|
autocommit=True
|
||||||
|
)
|
||||||
|
elif server_config.db_type == "sqlite":
|
||||||
|
import aiosqlite
|
||||||
|
raw_db = await aiosqlite.connect(server_config.db_file)
|
||||||
|
db["acquire"] = raw_db
|
||||||
|
|
||||||
# Возвращаем
|
# Возвращаем
|
||||||
return db
|
return db
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue