Поделил процессоры в таме

This commit is contained in:
Alexey Polyakov
2026-03-19 16:21:48 +03:00
parent 11b2e2748d
commit 9bc6c15d82
4 changed files with 151 additions and 114 deletions

View File

@@ -0,0 +1,49 @@
import logging
from common.config import ServerConfig
from common.static import Static
from common.tools import Tools
from common.proto_tcp import MobileProto
from common.proto_web import WebProto
from common.opcodes import Opcodes
class BaseProcessor:
def __init__(self, db_pool=None, clients=None, send_event=None, type="socket"):
if clients is None:
clients = {}
self.config = ServerConfig()
self.static = Static()
self.tools = Tools()
self.opcodes = Opcodes()
self.error_types = self.static.ErrorTypes()
self.db_pool = db_pool
self.clients = clients
self.send_event = send_event
self.logger = logging.getLogger(__name__)
if type == "socket":
self.proto = MobileProto()
elif type == "web":
self.proto = WebProto()
async def _send(self, writer, packet):
"""Send packet to client."""
try:
writer.write(packet)
await writer.drain()
except Exception:
pass
async def _send_error(self, seq, opcode, error_type, writer):
"""Send error response."""
payload = self.static.ERROR_TYPES.get(error_type, {
"localizedMessage": "Неизвестная ошибка",
"error": "unknown.error",
"message": "Unknown error",
"title": "Неизвестная ошибка"
})
packet = self.proto.pack_packet(
cmd=self.proto.CMD_ERR, seq=seq, opcode=opcode, payload=payload
)
await self._send(writer, packet)