MAX && TT: общение в таме, и корректировки под веб морду

This commit is contained in:
Alexey Polyakov
2026-05-06 15:58:27 +03:00
parent 0b6eda6178
commit f1ff4fd062
5 changed files with 120 additions and 13 deletions

View File

@@ -10,13 +10,18 @@ from common.opcodes import Opcodes
class OnemeController(ControllerBase):
def __init__(self):
self.config = ServerConfig()
self.proto = MobileProto()
self.proto_tcp = MobileProto()
self.proto_web = WebProto()
self.opcodes = Opcodes()
async def event(self, target, client, eventData):
# Извлекаем тип события и врайтер
eventType = eventData.get("eventType")
writer = client.get("writer")
is_web = client.get("type") == "web"
# Выбираем протокол в зависимости от типа подключения
proto = self.proto_web if is_web else self.proto_tcp
# Не отправляем событие самому себе
if writer == eventData.get("writer"):
@@ -41,7 +46,7 @@ class OnemeController(ControllerBase):
}
# Создаем пакет
packet = self.proto.pack_packet(
packet = proto.pack_packet(
cmd=0, seq=1, opcode=self.opcodes.NOTIF_MESSAGE, payload=payload
)
elif eventType == "typing":
@@ -58,7 +63,7 @@ class OnemeController(ControllerBase):
}
# Создаем пакет
packet = self.proto.pack_packet(
packet = proto.pack_packet(
cmd=0, seq=1, opcode=self.opcodes.NOTIF_TYPING, payload=payload
)
elif eventType == "profile_updated":
@@ -71,7 +76,7 @@ class OnemeController(ControllerBase):
}
# Создаем пакет
packet = self.proto.pack_packet(
packet = proto.pack_packet(
cmd=0, seq=1, opcode=self.opcodes.NOTIF_PROFILE, payload=payload
)
elif eventType == "presence":
@@ -85,13 +90,16 @@ class OnemeController(ControllerBase):
"time": event_time
}
packet = self.proto.pack_packet(
packet = proto.pack_packet(
cmd=0, seq=1, opcode=self.opcodes.NOTIF_PRESENCE, payload=payload
)
# Отправляем пакет
writer.write(packet)
await writer.drain()
if is_web:
await writer.send(packet)
else:
writer.write(packet)
await writer.drain()
def launch(self, api):
async def _start_all():

View File

@@ -320,7 +320,8 @@ class OnemeWS:
"writer": websocket,
"ip": addr[0],
"port": addr[1],
"protocol": "oneme"
"protocol": "oneme",
"type": "web"
}
)
else:
@@ -334,7 +335,8 @@ class OnemeWS:
"writer": websocket,
"ip": addr[0],
"port": addr[1],
"protocol": "oneme"
"protocol": "oneme",
"type": "web"
}
]
}

View File

@@ -3,10 +3,103 @@ from tamtam.socket import TamTamMobile
from tamtam.websocket import TamTamWS
from classes.controllerbase import ControllerBase
from common.config import ServerConfig
from common.proto_tcp import MobileProto
from common.proto_web import WebProto
from common.opcodes import Opcodes
class TTController(ControllerBase):
def __init__(self):
self.config = ServerConfig()
self.proto_tcp = MobileProto()
self.proto_web = WebProto()
self.opcodes = Opcodes()
async def event(self, target, client, eventData):
# Извлекаем тип события и врайтер
eventType = eventData.get("eventType")
writer = client.get("writer")
is_web = client.get("type") == "web"
# Выбираем протокол в зависимости от типа подключения
proto = self.proto_web if is_web else self.proto_tcp
# Не отправляем событие самому себе
if writer == eventData.get("writer"):
return
# Обрабатываем событие
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 = 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 = 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 = proto.pack_packet(
cmd=0, seq=1, opcode=self.opcodes.NOTIF_PROFILE, payload=payload
)
elif eventType == "presence":
userId = eventData.get("userId")
presence = eventData.get("presence")
event_time = eventData.get("time")
payload = {
"userId": userId,
"presence": presence,
"time": event_time
}
packet = proto.pack_packet(
cmd=0, seq=1, opcode=self.opcodes.NOTIF_PRESENCE, payload=payload
)
# Отправляем пакет
if is_web:
await writer.send(packet)
else:
writer.write(packet)
await writer.drain()
def launch(self, api):
async def _start_all():

View File

@@ -199,7 +199,8 @@ class TamTamMobile:
"writer": writer,
"ip": addr[0],
"port": addr[1],
"protocol": "tamtam"
"protocol": "tamtam",
"type": "tcp"
}
)
else:
@@ -211,7 +212,8 @@ class TamTamMobile:
"writer": writer,
"ip": addr[0],
"port": addr[1],
"protocol": "tamtam"
"protocol": "tamtam",
"type": "tcp"
}
]
}

View File

@@ -187,7 +187,8 @@ class TamTamWS:
"writer": websocket,
"ip": addr[0],
"port": addr[1],
"protocol": "tamtam"
"protocol": "tamtam",
"type": "web"
}
)
else:
@@ -199,7 +200,8 @@ class TamTamWS:
"writer": websocket,
"ip": addr[0],
"port": addr[1],
"protocol": "tamtam"
"protocol": "tamtam",
"type": "web"
}
]
}