-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
73 lines (61 loc) · 2.57 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const bodyparser = require("body-parser")
const mongoose = require("mongoose")
const express = require("express")
const fs = require("fs")
const app = express()
const logging = require(`${__dirname}/structs/logs`)
const config = require(`${__dirname}/config.json`)
//i know global isn't the best practice, but it works good enough
global.exchangeCodes = {}
global.clientTokens = []
global.accessTokens = []
global.xmppClients = {}
global.parties = []
global.invites = []
global.pings = []
app.use(bodyparser.json())
app.use(bodyparser.urlencoded({extended: true}))
require("./xmpp")
//db
mongoose.connect(config.db, { useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: true}, async e => {
if (e) throw e
logging.fdev(`Connected to Mongo DB`)
})
app.use(require(`${__dirname}/routes`))
//gets the services working n shit
app.use("/waitingroom", require(`${__dirname}/routes/services/waitingroom`))
app.use("/lightswitch", require(`${__dirname}/routes/services/lightswitch`))
app.use("/datarouter", require(`${__dirname}/routes/services/datarouter`))
app.use("/fortnite", require(`${__dirname}/routes/services/fortnite`))
app.use("/presence", require(`${__dirname}/routes/services/presence`))
app.use("/content", require(`${__dirname}/routes/services/content`))
app.use("/account", require(`${__dirname}/routes/services/account`))
app.use("/friends", require(`${__dirname}/routes/services/friends`))
app.use("/party", require(`${__dirname}/routes/services/party`))
global.launcherversion = fs.readFileSync(`${__dirname}/public/files/version`).toString()
global.serverversion = "1.5"
//hopefully this should fix the memory leak issue
setInterval(() => {
parties.forEach(party => {
// check if the member still exists in xmpp, if not delete them and then do the check
party.members.forEach(member => {
if (!xmppClients[member.account_id]) {
let index = party.members.indexOf(member);
if (index !== 1) {
party.members.splice(index, 1);
}
}
});
if (party.members.length <= 0) {
let index = parties.indexOf(party);
if (index !== -1) {
parties.splice(index, 1);
}
}
});
}, 30000);
app.listen(process.env.port || config.port || 80, () => {
logging.fdev(`Created by Slushia and Cyuubi, Version \x1b[36m${serverversion}`)
logging.fdev(`Listening on port \x1b[36m${process.env.port || config.port || 80}`)
logging.fdev(`XMPP listening on port \x1b[36m${process.env.xmppPort || config.xmppPort || 443}`)
})