-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathindex.js
More file actions
103 lines (81 loc) · 3.98 KB
/
index.js
File metadata and controls
103 lines (81 loc) · 3.98 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env node
const chalk = require('chalk')
const child_process = require('child_process')
const { version } = require("./package.json")
const fs = require('fs');
const { LogType, log } = require("./src/logger.js")
if (!fs.existsSync("./config.json")) {
log(LogType.Error, `Config does not exist! Make a copy of the file "config.template.json", rename it to "config.json", and edit the values inside the config.`)
process.exit(1)
}
log(LogType.Debug, "Debug Logging Enabled!")
const { discord_bot, token_signature, allow2016AndEarly2017, clearImageCacheOnLaunch } = require("./config.json")
const { webhookMessage } = require("./src/webhook.js")
//Token Signature Warnings
if (token_signature === "LunarRec_ReplaceMeWithSomethingElsePlz") {
log(LogType.Warn, "⚠️SECURITY RISK DETECTED - CHANGE YOUR JWT TOKEN SIGNATURE⚠️")
log(LogType.Warn, "Your \"token_signature\" in your config is still set to the default value! (LunarRec_ReplaceMeWithSomethingElsePlz)")
log(LogType.Warn, "This means anyone can create JWT tokens and log into any account that is on this server!")
log(LogType.Warn, "Please change this variable to something long and unique before making this server public to other players.")
} else if (token_signature.length < 10) {
log(LogType.Warn, "⚠️SECURITY RISK DETECTED - CHANGE YOUR JWT TOKEN SIGNATURE⚠️")
log(LogType.Warn, "Your \"token_signature\" in your config is less than 10 characters.")
log(LogType.Warn, "This makes it easier for people to brute force your JWT password!")
log(LogType.Warn, "Please change this variable to something long and unique before making this server public to other players.")
}
//Old version warning
if (allow2016AndEarly2017) {
log(LogType.Warn, "⚠️EARLY BUILD MODE ENABLED⚠️")
log(LogType.Warn, "This server has \"allow2016AndEarly2017\" in the config set to true.")
log(LogType.Warn, "Due to weak security, it is easy for anyone to generate auth tokens for this version.")
log(LogType.Warn, "Please disable old build mode if you aren't supporting 2016 and early 2017 builds.")
}
let colors = require('./colors.json')
try{process.commit = child_process.execSync('git rev-parse HEAD').toString().substring(0, 7)} catch(e) {process.commit = "[git not installed]"}
let versionStr = ` Version ${version} (commit ${process.commit})`
console.log(`${" ".repeat((versionStr.length-"lunarrec".length)/2)}${chalk.hex(colors.logo)("LunarRec")}\n${versionStr}\n${"=".repeat(versionStr.length+1)}`)
//Reset data command
if (process.argv[2] == "reset"){
return require('./util.js').resetServerData()
}
//Init DB
process.db = require('./database.js')
//Admin panel
if (process.argv[2] == "admin"){
return require("./src/admin.js").admin()
}
async function start() {
//check for first run
if (!fs.existsSync("./.first_run")) {
fs.writeFileSync("./.first_run", "# Dummy file generated by LunarRec.\n# Used to tell LunarRec that the first time setup has executed already.\n# Delete this if you want to re-run the first time setup.\n# Completed: " + new Date())
console.log(`Hello there 👋!
It looks like this is your first time running LunarRec.
Please check out the github repo for first time install steps.
Also note that LunarRec is still a heavy work in progress project that is not production ready.
To read this message again, Delete the file ".first_run" in the root directory of LunarRec.
`)}
await process.db.users.sync()
//reset everyone's session to NULL incase it isn't already.
try {
await process.db.users.update(
{ session: null },
{ where: {} }
);
} catch (error) {
log(LogType.Error, "Failed to set user sessions to \"NULL\". Invalid active player count and player login issues may happen.")
}
if (clearImageCacheOnLaunch) {
require('./util.js').clearImages()
}
if (discord_bot.enabled) {
log(LogType.Bot, "Discord Bot enabled!")
//push commands
require(`./src/bot/deploy.js`)
//start the bot
require('./src/bot/index.js')
}
//start the server
require('./src/server.js')
webhookMessage(0, "")
}
start()