mirror of
https://github.com/openmax-server/server.git
synced 2026-05-23 03:51:43 +03:00
Поделил процессоры в таме
This commit is contained in:
49
src/classes/baseprocessor.py
Normal file
49
src/classes/baseprocessor.py
Normal 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)
|
||||
Reference in New Issue
Block a user