Remove synchronous http requests
This commit is contained in:
parent
83d9e3aa75
commit
803a57a62b
2 changed files with 21 additions and 16 deletions
|
@ -1,7 +1,7 @@
|
||||||
const osu = require("osu-packet"),
|
const osu = require("osu-packet"),
|
||||||
User = require("./User.js"),
|
User = require("./User.js"),
|
||||||
{ v4: uuid } = require('uuid'),
|
{ v4: uuid } = require('uuid'),
|
||||||
request = require("sync-request"),
|
ahttp = require("./util/AsyncHttpRequest.js"),
|
||||||
|
|
||||||
getUserByUsername = require("./util/getUserByUsername.js"),
|
getUserByUsername = require("./util/getUserByUsername.js"),
|
||||||
getUserByToken = require("./util/getUserByToken.js"),
|
getUserByToken = require("./util/getUserByToken.js"),
|
||||||
|
@ -13,7 +13,8 @@ const osu = require("osu-packet"),
|
||||||
|
|
||||||
module.exports = async function(req, res, loginInfo) {
|
module.exports = async function(req, res, loginInfo) {
|
||||||
// Get time at the start of login
|
// Get time at the start of login
|
||||||
const loginStartTime = new Date().getTime();
|
const loginStartTime = new Date().getTime(),
|
||||||
|
isTourneyClient = loginInfo.osuversion.includes("tourney");
|
||||||
|
|
||||||
// Check login
|
// Check login
|
||||||
const loginCheck = await loginHelper.checkLogin(loginInfo);
|
const loginCheck = await loginHelper.checkLogin(loginInfo);
|
||||||
|
@ -40,7 +41,7 @@ module.exports = async function(req, res, loginInfo) {
|
||||||
userLocation = [0, 0];
|
userLocation = [0, 0];
|
||||||
} else {
|
} else {
|
||||||
// Get user's location using zxq
|
// Get user's location using zxq
|
||||||
userLocationData = JSON.parse(request("GET", `http://ip.zxq.co/${requestIP}`).getBody());
|
userLocationData = JSON.parse(await ahttp(`http://ip.zxq.co/${requestIP}`));
|
||||||
userLocation = userLocationData.loc.split(",");
|
userLocation = userLocationData.loc.split(",");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,24 +53,18 @@ module.exports = async function(req, res, loginInfo) {
|
||||||
|
|
||||||
// Make sure user is not already connected, kick off if so.
|
// Make sure user is not already connected, kick off if so.
|
||||||
const checkForPreexistingUser = getUserByUsername(loginInfo.username);
|
const checkForPreexistingUser = getUserByUsername(loginInfo.username);
|
||||||
if (checkForPreexistingUser != null && !loginInfo.osuversion.includes("tourney")) {
|
if (checkForPreexistingUser != null && !isTourneyClient) {
|
||||||
if (checkForPreexistingUser.uuid != newClientToken) {
|
|
||||||
let userCurrentIndex, isTourneyUser = false;
|
|
||||||
// Find the index that the user's class is at
|
|
||||||
for (let i = 0; i < global.users.length; i++) {
|
for (let i = 0; i < global.users.length; i++) {
|
||||||
if (checkForPreexistingUser.uuid == global.users[i].uuid && !global.users[i].isTourneyUser) {
|
const user = global.users[i];
|
||||||
userCurrentIndex = i;
|
// Make sure they are not a tourney user
|
||||||
isTourneyUser = global.users[i].isTourneyUser;
|
if (!user.isTourneyUser && user.uuid != newClientToken) {
|
||||||
break;
|
global.users.splice(i, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isTourneyUser) global.users.splice(userCurrentIndex, 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create user object
|
// Create user object
|
||||||
global.users.push(new User(userDB.id, loginInfo.username, newClientToken, new Date().getTime(), loginInfo.osuversion.includes("tourney")));
|
global.users.push(new User(userDB.id, loginInfo.username, newClientToken, new Date().getTime(), isTourneyClient));
|
||||||
|
|
||||||
// Retreive the newly created user
|
// Retreive the newly created user
|
||||||
const NewUser = getUserByToken(newClientToken);
|
const NewUser = getUserByToken(newClientToken);
|
||||||
|
|
10
server/util/AsyncHttpRequest.js
Normal file
10
server/util/AsyncHttpRequest.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
const request = require("request");
|
||||||
|
|
||||||
|
module.exports = async function(url) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
request(url, (err, res, body) => {
|
||||||
|
if (err) reject(err);
|
||||||
|
else resolve(body);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in a new issue