From fce8db2c3e37cf44e797dfa1d063a29fcd1dcc78 Mon Sep 17 00:00:00 2001 From: oatmealine Date: Mon, 27 Jan 2020 19:28:21 +0300 Subject: [PATCH] getGJComments implemented, and updateDJUserScore placeholder --- src/getGJComments21.ts | 50 ++++++++++++++++++++++++++++++++++++++ src/index.ts | 7 +++++- src/updateGJUserScore22.ts | 5 ++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/getGJComments21.ts create mode 100644 src/updateGJUserScore22.ts diff --git a/src/getGJComments21.ts b/src/getGJComments21.ts new file mode 100644 index 0000000..9a486a5 --- /dev/null +++ b/src/getGJComments21.ts @@ -0,0 +1,50 @@ +module.exports = (app) : void => { + app.post('/' + app.get('config').addtopath + 'database/getGJComments21.php', async (req, res) => { + let comments = await app.get('db').collection('comments').find({ + levelID: Number(req.body.levelID) + }).toArray(); + + let mode = 0; + let count = 10; + let offset = Number(req.body.page) * count; + + if (req.body.mode) + mode = Number(req.body.mode); + + if (req.body.count) + mode = Number(req.body.mode); + + switch(mode) { + case 0: + comments.sort((a, b) => b.id - a.id); + break; + case 1: + comments.sort((a, b) => b.likes - a.likes); + } + + const foundComments = comments + .slice(offset, offset + count); + + if (foundComments.count <= 0) + return res.status(200).send('#0:0:0'); + + let commentString = foundComments.map(c => { + let result = ''; + let uploadDate = new Date(c.uploadDate).toISOString(); + let commentContent = c.commentContent; + + if (Number(req.body.gameVersion) < 20) + commentContent = Buffer.from(commentContent, 'base64').toString('utf8'); + + result += `2~${commentContent}~3~${c.userID}~4~${c.likes}~5~0~7~${Number(c.isSpam)}~9~${uploadDate}~6~${c.id}~10~${c.percent}`; + + // dummy data for now cus no users + result += `~11~0~12~0:1~oat~7~1~9~${Math.floor(Math.random() * 142) /* icon */}~10~${Math.floor(Math.random() * 64) /* color1 */}~11~${Math.floor(Math.random() * 64) /* color2 */}~14~${0 /* icontype */}~15~${1 /* special */}~16~${0 /*extID*/}`; + + return result; + }) + .join('|'); + + res.status(200).send(`${commentString}#${count}:${offset}:10`); + }); +}; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 51245ed..154a02f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,8 +28,13 @@ dbClient.connect((err) => { require('./getGJLevels21')(app); require('./uploadGJLevel21')(app); require('./downloadGJLevel22')(app); + require('./getGJComments21')(app); + require('./updateGJUserScore22')(app); - app.get('*', (req, res) => res.status(404).send('wrong page dumbass')); + app.get('*', (req, res) => { + console.log('got 404 for ' + req.url); + res.status(404).send('wrong page dumbass'); + }); app.listen(config.port, () => { console.log(`expressjs server launched on port ${config.port}, gdps should now function properly`); diff --git a/src/updateGJUserScore22.ts b/src/updateGJUserScore22.ts new file mode 100644 index 0000000..2de9ece --- /dev/null +++ b/src/updateGJUserScore22.ts @@ -0,0 +1,5 @@ +module.exports = (app): void => { + app.post('/' + app.get('config').addtopath + 'database/updateGJUserScore22.php', async (req, res) => { + res.status(200).send('0'); // temporary + }); +}; \ No newline at end of file