-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.js
80 lines (73 loc) · 3.01 KB
/
main.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
74
75
76
77
78
79
80
const { readConfig, exit } = require("./files/util")
const checkDanserVersion = require("./files/checkDanserVersion")
const axios = require("axios")
const fs = require("fs")
const version = 24
module.exports = { version }
const { startServer } = require("./files/server")
const firstLaunch = require("./files/firstLaunch")
async function main() {
let config = await readConfig()
if (config.logTimestamps) {
require("log-timestamp")
}
let clientData
// we don't check for the client version on custom servers, but we do on dev mode
if (config.customServer.apiUrl === "" || config.dev) {
try {
// we check for customServer.apiUrl here because we may be on dev mode
clientData = await axios.get((config.customServer.apiUrl !== "" ? config.customServer.apiUrl : "https://apis.issou.best/ordr") + "/servers/version")
} catch (e) {
console.log("There was an issue while fetching initial client data. Check your internet connection, or is the o!rdr server down?")
await exit()
}
clientData = clientData.data
} else {
// if we're using a custom server, we set the version that the server should have sent us to the current version to bypass the check
clientData = { clientVersion: version }
}
if (version != clientData.clientVersion) {
const clientUpdater = require("./files/clientUpdater")
console.log("Client version seems incorrect or out of date. Running updater.")
clientUpdater()
} else if (config.id && (config.customServer.apiUrl === "" || config.dev)) {
if (config.discordPresence) {
const { startPresence } = require("./files/presence")
startPresence()
}
if (!fs.existsSync("files/danser")) {
await firstLaunch()
} else {
await checkDanserVersion(clientData.danserHashes, clientData.danserVersion)
startServer()
}
} else if (config.id) {
// custom server
if (config.discordPresence && (config.customServer.apiUrl === "" || config.dev)) {
const { startPresence } = require("./files/presence")
startPresence()
}
if (!fs.existsSync("files/danser")) {
await firstLaunch()
} else {
startServer()
}
} else {
firstLaunch()
}
}
main()
// we don't use the helper "exit" function because it exits cleanly, we don't want to let the user press a key to close the client since it's a fatal error
process.on("uncaughtException", async e => {
console.log("Fatal error (uncaught exception)", e)
process.exit(1)
})
process.on("unhandledRejection", async e => {
if (e.toString() === "Error: Could not connect") {
// "Error: Could not connect" is the error when the Discord rich presence cannot connect to Discord
console.log("Cannot connect to Discord to start the Rich Presence!")
return
}
console.log("Fatal error (unhandled rejection)", e)
process.exit(1)
})