From 4cf03efa0b37de65ab32d12f508444d878567b26 Mon Sep 17 00:00:00 2001 From: Rin Date: Mon, 11 Jul 2022 15:19:36 +0100 Subject: [PATCH] Add ping method yes I am committing this change from a hotel room --- src/index.ts | 2 +- src/modules/startup.ts | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 4cbe9e8..9270ef0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -31,7 +31,7 @@ for (let i of dirs) { } app.all('*', (req, res) => { - console.log(`CATCH-ALL: ${req.method} ${req.originalUrl}`); + res.status(200).end(); }) https.createServer({ diff --git a/src/modules/startup.ts b/src/modules/startup.ts index d58e221..a6fbe60 100644 --- a/src/modules/startup.ts +++ b/src/modules/startup.ts @@ -48,5 +48,22 @@ export default class StartupModule extends Module { .status(200); r.send(Buffer.from(end)); }) + + app.post('/method/ping', (req, res) => { + console.log('ping'); + let body = wm.wm.protobuf.PingRequest.decode(req.body); + let ping = { + error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS, + pong: body.ping || 1 + }; + let resp = wm.wm.protobuf.PingResponse.encode(ping); + let end = resp.finish(); + let r = res + .header('Server', 'v388 wangan') + .header('Content-Type', 'application/x-protobuf; revision=8053') + .header('Content-Length', end.length.toString()) + .status(200); + r.send(Buffer.from(end)); + }) } } \ No newline at end of file