From 37be23c824f4de1349f985edb27619ba38c6a689 Mon Sep 17 00:00:00 2001 From: James Quinley Date: Sun, 18 Jun 2023 09:31:07 -0700 Subject: [PATCH] Adds inital stuff, inlcudes basic documentation. --- .gitignore | 2 ++ config.json | 4 ++++ server.js | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 .gitignore create mode 100644 config.json create mode 100644 server.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..074ab52 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +package-lock.json +node_modules \ No newline at end of file diff --git a/config.json b/config.json new file mode 100644 index 0000000..b1ef30a --- /dev/null +++ b/config.json @@ -0,0 +1,4 @@ +{ +"clientID" : "1046218306736095352", +"clientSecret": "WLFoLaE_Kx5yRMhBfiaGWZmsWsLL3BaQ" +} \ No newline at end of file diff --git a/server.js b/server.js new file mode 100644 index 0000000..1ca523e --- /dev/null +++ b/server.js @@ -0,0 +1,64 @@ +const Express = require("express"); +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 COLLECTION_NAME = "nettranslate"; +const sha256 = require('js-sha256'); +var cors = require('cors'); +const Collection = require("mongodb/lib/collection"); +const Db = require("mongodb/lib/db"); +const MongoClient = require("mongodb").MongoClient; +const request = require('undici'); +const axios = require('axios'); +const requestIp = require('request-ip'); +let requestEnable = false; +var app = Express(); +app.use(cors()); +app.use(BodyParser.json()); +app.use(BodyParser.urlencoded({ extended: true })); +app.use(requestIp.mw()); +app.enable('trust proxy'); +var corsOptions = { + origin: 'http://matchmaking.obsidiancorestudios.com', + optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204 + } +var database, collection; +/**GET*/ +app.get("/", (request, response) => { + response.json({ + Error: "Please refer to documentation.", + Status: "Failed", + Info: "Matchmaking Server" + }) + +}); +/**GET:USRPASS:SESSION*/ +app.get("/lobbylist/", async (request, response) => { + /** + Field LobbyCount notifies the client of the number of indexed lobbies in the 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: 2, + LBN1: "DebugLobbyOne", + LBIP1: "xxx.xxx.xxx.xxx", + LBN2: "DebugLobbyTwo", + LBIP2: "xxx.xxx.xxx.xxx" + }); +}); + + app.listen(10000, () => { + console.log("Application is now online, attempting to connect to Database. Requests will be set to 503 until connected!") + MongoClient.connect(CONNECTION_URL, { useNewUrlParser: true, useUnifiedTopology: true} , (error, client) => { + if(error) { + throw error; + } + database = client.db(DATABASE_NAME); + auth = database.collection(COLLECTION_NAME); + requestEnable = true; + console.log("Database is connected and requests are enabled..."); + }); +});