const { serverType, ArtConnSettings,DXMemorialImageDirectory } = require('./config.json'); const sqlite3 = require('sqlite3').verbose(); let db = new sqlite3.Database(DXMemorialImageDirectory + '\\db.sqlite'); // index.js route '/' async function getUserCount() { if (serverType === 0) { return new Promise((resolve, reject) => { db.all('SELECT * FROM sega_card', (err, rows) => { if (err) { console.error(err); res.render('error', { error: err }); reject(err) } else { resolve(rows.length) } }); }); } else { } } // index.js & api.js /getUserData/ async function getUserData(req) { if (serverType === 0) { return new Promise((resolve, reject) => { const cookies = req.cookies db.all('SELECT * FROM maimai2_user_detail', (err, rows) => { if (err) { console.error(err); // Return a Failed Message. reject(err) } else { // Make the Request easier to get to. var mUser = undefined // Leave the Matched User undefined until the user is found. for (user of rows) { // For Each User in Rows if (cookies.aime_card_id === user.aime_card_id.toString()) { // If the Access Code for the card is in the system, mUser = user; // set the Matched User Variable to the User, and break the for Loop. break; } } if (mUser) { // Return a Response with the whole identifiable user data. the EXT_ID will be used later to identify images and other things and match them to the user's profile. resolve(mUser); } else { reject(new Error('User not found')); } } }); }); // function is required to obtain the User Data, and create the user profile. I'm going to bed. } else { // 07-23 oh god im going to have to recreate this function again aren't i } } // api.js /getExtId/ async function getExtId(req) { if (serverType === 0) { return new Promise((resolve, reject) => { db.all('SELECT * FROM sega_card', (err, rows) => { if (err) { console.error(err); // Return a Failed Message. reject(err) } else { // Make the Request easier to get to. var request = req.body; var mUser = undefined // Leave the Matched User undefined until the user is found. for (user of rows) { // For Each User in Rows if (request.input === user.luid) { // If the Access Code for the card is in the system, mUser = user; // set the Matched User Variable to the User, and break the for Loop. break } } // Return a Response with the whole identifiable user data. the EXT_ID will be used later to identify images and other things and match them to the user's profile. resolve(mUser) } }); }); } else { } } // api /getUserScores/ async function getUserScores(req) { if (serverType === 0) { return new Promise((resolve, reject) => { db.all('SELECT * FROM maimai2_user_playlog', (err, rows) => { if (err) { console.error(err); reject(err) // Return a Failed Message. } else { // Make the Request easier to get to. var request = req.body; var mUser = new Array(); // Leave the Matched User's Scores undefined until the user is found. for (score of rows) { // For Each Score in Rows if (request.input == score.user_id) { // If the inputed User ID and Score's User ID Matches, mUser.push(score) // add that score into the array. } } // Return a Response with all the Scores listed under that user. resolve(mUser) } }); }); } else { } } // api /getUserArea/ async function getUserArea(req) { if (serverType === 0) { return new Promise((resolve, reject) => { db.all('SELECT * FROM maimai2_user_map', (err, rows) => { if (err) { console.error(err); // Return a Failed Message. reject(err) } else { // Make the Request easier to get to. var request = req.body; var mUser = new Array(); // Leave the Matched User's Areas undefined until the user is found. for (map of rows) { // For Each Area in Rows if (request.input == map.user_id) { // If the inputed User ID and Score's User ID Matches, mUser.push(map) // add that Area into the array. } } // Return a Response with all the Areas listed under that user. resolve(mUser) } }); }); } else { } } /* side note: User Banned & User Unbanned should be tied into 1 commnand that toggles it but maybe not, i dont really know */ // api /getUserBanned/ async function getUserBanned(req) { if (serverType === 0) { return new Promise((resolve, reject) => { var request = req.body; if (request.input === undefined) { return reject('Failed to update user ban state, insufficent paramaters') return } db.run('UPDATE maimai2_user_detail SET ban_state = ? WHERE id = ?', [2, request.input], function (err) { if (err) { console.error(err.message); reject({"status":"failure","message":"Unable to ban user, see reason","reason":err}); } else { resolve({ "status": "Success", "message": `User ${request.input} banned.` }) } }); }); } else { } } // api /getUserUnbanned/ async function getUserUnbanned(req) { if (serverType === 0) { return new Promise((resolve, reject) => { var request = req.body; if (request.input === undefined) { return reject('Failed to update user ban state, insufficent paramaters') return } db.run('UPDATE maimai2_user_detail SET ban_state = ? WHERE id = ?', [0, request.input], function (err) { if (err) { console.error(err.message); reject({"status":"failure","message":"Unable to ban user, see reason","reason":err}); } else { resolve({ "status": "Success", "message": `User ${request.input} banned.` }) } }); }); } else { } } module.exports = {getUserCount,getUserData,getUserScores,getUserArea,getUserBanned,getUserUnbanned,getExtId};