diff --git a/server.js b/server.js index 6d25dc7..30e46dd 100644 --- a/server.js +++ b/server.js @@ -3,7 +3,7 @@ const BodyParser = require("body-parser"); const mongodb = require("mongodb"); const ObjectId = require("mongodb").ObjectID; const CONNECTION_URL = "mongodb+srv://edgenetworknode:yUiWfJBYCGwdRayj@matchnethop.hgxv0xd.mongodb.net/?retryWrites=true&w=majority"; -const DATABASE_NAME = "DelegationRequest"; +const DATABASE_NAME = "edgecomm"; const COLLECTION_NAME = "nettranslate"; const sha256 = require('js-sha256'); var cors = require('cors'); @@ -41,17 +41,79 @@ app.get("/lobby/listall/", async (request, response) => { Field LBN[num] breaks down into Lobby Name [Number], this informs the client what the name is of the assosiated lobby Field LBIP[num] breaks down into Lobby IP [Number], this informs the client what the IP is of the assosiated lobby */ - response.status(200).json({ - LobbyCount: 4, - LBN1: "DebugLobbyOne", - LBIP1: "xxx.xxx.xxx.xxx", - LBN2: "DebugLobbyTwo", - LBIP2: "xxx.xxx.xxx.xxx", - LBN3: "Ability to post lobbies", - LBIP3: "xxx.xxx.xxx.xxx", - LBN4: "Coming soon! (Just have to figure out the database stuff)", - LBIP4: "xxx.xxx.xxx.xxx" - }); + var o_id = new mongodb.ObjectID(); + var ar; + auth.insertOne({ + _id : o_id, + type: 1, + status: false + }) + await auth.findOne({_id: o_id}, (err, res) => { + const delay = ms => new Promise(resolve => setTimeout(resolve, ms)) + const dec = async i => (await delay(200), --i) + ar = res; + const verifyUser = async () => { + let responseEnabled = true; + let enableLookup = true; + let i = 8; + let timeout = 7; + while(i = await dec(i)) + try { + if (enableLookup) { + timeout = timeout - 1; + if (timeout > 0) { + await auth.findOne({_id: o_id}, (err, res) => { + if (res.status) { + if (responseEnabled) { + timeout = 0; + i = 1; + if (res.type == 2) { + responseEnabled = false; + enableLookup = false; + response.status(200).json({ + LBN : res.lobbies, + LBIP : res.ip, + LobbyCount : res.LobbyCount + }); + res = null; + } else { + responseEnabled = false; + ar = null; + res = null; + response.status(403).json({ + Info: "Forbidden", + Message: "Something went wrong." + }); + } + } + } + }); + } else { + if (responseEnabled) { + response.status(403).json({ + Info: "Forbidden", + Message: "Something went wrong..." + }); + responseEnabled = false; + ar = null; + res = null; + } + } + } + } catch (err) { + enableLookup = false; + res = null; + if (responseEnabled) { + response.sendStatus(500); + } + responseEnabled = false; + console.log(err); + timeout = 1; + } + } + verifyUser(); + }); + }); app.get("/lobby/submit/", async (request, response) => { /**