mirror of
https://github.com/openmax-server/server.git
synced 2026-06-19 09:21:07 +03:00
Швырнул архитектуру, чтобы позже объединить контроллеры веба и сокета в одно, а также разделить процессоры
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
import asyncio
|
||||
from oneme.socket import OnemeMobileServer
|
||||
from common.proto_tcp import MobileProto
|
||||
from common.proto_web import WebProto
|
||||
from classes.controllerbase import ControllerBase
|
||||
from common.config import ServerConfig
|
||||
from common.opcodes import Opcodes
|
||||
|
||||
class OnemeMobileController(ControllerBase):
|
||||
def __init__(self):
|
||||
self.config = ServerConfig()
|
||||
self.proto = MobileProto()
|
||||
self.opcodes = Opcodes()
|
||||
|
||||
async def event(self, target, client, eventData):
|
||||
# Извлекаем тип события и врайтер
|
||||
eventType = eventData.get("eventType")
|
||||
writer = client.get("writer")
|
||||
|
||||
# Обрабатываем событие
|
||||
if eventType == "new_msg":
|
||||
# Данные сообщения
|
||||
chatId = eventData.get("chatId")
|
||||
message = eventData.get("message")
|
||||
prevMessageId = eventData.get("prevMessageId")
|
||||
time = eventData.get("time")
|
||||
|
||||
# Данные пакета
|
||||
payload = {
|
||||
"chatId": chatId,
|
||||
"message": message,
|
||||
"prevMessageId": prevMessageId,
|
||||
"ttl": False,
|
||||
"unread": 0,
|
||||
"mark": time
|
||||
}
|
||||
|
||||
# Создаем пакет
|
||||
packet = self.proto.pack_packet(
|
||||
cmd=0, seq=1, opcode=self.opcodes.NOTIF_MESSAGE, payload=payload
|
||||
)
|
||||
elif eventType == "typing":
|
||||
# Данные события
|
||||
chatId = eventData.get("chatId")
|
||||
userId = eventData.get("userId")
|
||||
type = eventData.get("type")
|
||||
|
||||
# Данные пакета
|
||||
payload = {
|
||||
"chatId": chatId,
|
||||
"userId": userId,
|
||||
"type": type
|
||||
}
|
||||
|
||||
# Создаем пакет
|
||||
packet = self.proto.pack_packet(
|
||||
cmd=0, seq=1, opcode=self.opcodes.NOTIF_TYPING, payload=payload
|
||||
)
|
||||
elif eventType == "profile_updated":
|
||||
# Данные события
|
||||
profile = eventData.get("profile")
|
||||
|
||||
# Данные пакета
|
||||
payload = {
|
||||
"profile": profile
|
||||
}
|
||||
|
||||
# Создаем пакет
|
||||
packet = self.proto.pack_packet(
|
||||
cmd=0, seq=1, opcode=self.opcodes.NOTIF_PROFILE, payload=payload
|
||||
)
|
||||
|
||||
# Отправляем пакет
|
||||
writer.write(packet)
|
||||
await writer.drain()
|
||||
|
||||
def launch(self, api):
|
||||
async def _start_all():
|
||||
await asyncio.gather(
|
||||
OnemeMobileServer(
|
||||
host=self.config.host,
|
||||
port=self.config.oneme_tcp_port,
|
||||
ssl_context=api['ssl'],
|
||||
db_pool=api['db'],
|
||||
clients=api['clients'],
|
||||
send_event=api['event'],
|
||||
telegram_bot=api.get('telegram_bot'),
|
||||
).start()
|
||||
)
|
||||
|
||||
return _start_all()
|
||||
Reference in New Issue
Block a user