Commit 4160e021 authored by valtron's avatar valtron

playing around with YMSG

parent 6524d952
......@@ -6,7 +6,6 @@ from util.misc import Logger
from .msnp import MSNPReader, MSNPWriter
def register(loop, backend, *, http_port = None, devmode = False):
from functools import partial
from util.misc import AIOHTTPRunner, ProtocolRunner
from .http import create_app
from .msnp import MSNP_NS_SessState, MSNP_SB_SessState
......
from .entry import register
import asyncio
import struct
from core.session import PersistentSession
from util.misc import Logger
def register(loop, backend):
from util.misc import ProtocolRunner
backend.add_runner(ProtocolRunner('0.0.0.0', 5050, ListenerYMSG, args = ['YH', backend]))
class ListenerYMSG(asyncio.Protocol):
def __init__(self, logger_prefix, backend):
super().__init__()
self.logger_prefix = logger_prefix
self.backend = backend
self.transport = None
self.logger = None
def connection_made(self, transport):
self.transport = transport
self.logger = Logger(self.logger_prefix, transport)
self.logger.log_connect()
def connection_lost(self, exc):
self.logger.log_disconnect()
self.logger = None
self.transport = None
def data_received(self, data):
self.logger.info('>>>', data)
raw_data = data
assert data[:4] == b'YMSG'
assert len(data) >= 20
header = data[4:20]
data = data[20:]
(version, pkt_len, service, status, session_id) = struct.unpack('!B3xHHII', header)
assert len(data) == pkt_len
if service == YMSGService.Verify:
msg = b'YMSG' + header
self.logger.info('<<<', msg)
self.transport.write(msg)
return
if service == YMSGService.Auth:
email = data[3:-2]
self.logger.info("email", email)
else:
self.logger.info("unknown", service)
self.transport.write(b'YMSG')
self.transport.write(struct.pack('!B3xHHII', version, 0, YMSGService.LogOff, 0, 0))
self.transport.close()
class YMSGService:
LogOn = 0x01
LogOff = 0x02
Verify = 0x4c
AuthResp = 0x54
Auth = 0x57
......@@ -2,6 +2,7 @@ def main(*, devmode = False):
import asyncio
from core.backend import Backend
import front.msn
import front.ymsg
if devmode:
http_port = 80
......@@ -11,6 +12,7 @@ def main(*, devmode = False):
loop = asyncio.get_event_loop()
backend = Backend(loop)
front.msn.register(loop, backend, http_port = http_port, devmode = devmode)
front.ymsg.register(loop, backend)
backend.run_forever()
if __name__ == '__main__':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment