86 lines
3.1 KiB
JavaScript
86 lines
3.1 KiB
JavaScript
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("/lobby/listall/", 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: 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"
|
|
});
|
|
});
|
|
app.get("/lobby/submit/", async (request, response) => {
|
|
/**
|
|
Lobby submission documentation
|
|
*/
|
|
response.status(503).json({
|
|
INFORMATION: "THE LOBBY SUBMISSION ENDPOINT IS NOT ACTIVE, TRY AGAIN LATER.",
|
|
VERSION: 1.0
|
|
});
|
|
});
|
|
app.get("/lobby/remove/", async (request, response) => {
|
|
/**
|
|
Lobby removal documentation
|
|
*/
|
|
response.status(503).json({
|
|
INFORMATION: "THE LOBBY REMOVAL ENDPOINT IS NOT ACTIVE, TRY AGAIN LATER.",
|
|
VERSION: 1.0
|
|
});
|
|
});
|
|
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...");
|
|
});
|
|
});
|