-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
274 lines (236 loc) · 9.98 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
const axios = require('axios');
const fs = require('fs');
const AdmZip = require("adm-zip");
const { spawn } = require("child_process");
var readlineSync = require("readline-sync");
const blue = '\u001b[34m'
const white = '\u001b[0m'
//const cyan = '\u001b[36;1m'
const cyan = '\u001b[36m'
const red = '\u001b[31m'
const ver = '1.0.0'
console.log(cyan)
console.log(" _ _ _ _ ")
console.log("| | | | | | ___ __ _ __| | ___ _ __ ")
console.log("| | | | _____| | / _ \\ / _` |/ _` |/ _ \\ '__|")
console.log("| |___| |__|_____| |__| (_) | (_| | (_| | __/ | ")
console.log("|_____|_____| |_____\\___/ \\__,_|\\__,_|\\___|_| ")
console.log(cyan + 'INFO' + white + " Version: " + ver)
console.log(cyan + 'INFO' + white + " Made by prorok, js & LiteLoader community")
console.log(cyan + 'INFO' + white + " Made with love to bedrock community")
console.log(white)
let BDS
let LL_link
let LL
//config
let server_name
let gamemode
let difficulty
let allow_cheats
let max_players
let server_port
let level_name
let level_seed
function setconf(){
file = fs.readFile('./LiteLoader-' + BDS + '/server.properties', 'utf8', function (err,data) {
let config = data.replace('server-name=Dedicated Server', 'server-name=' + server_name);
config = config.replace('gamemode=survival','gamemode=' + gamemode)
config = config.replace('difficulty=easy','difficulty=' + difficulty)
config = config.replace('allow-cheats=false','allow-cheats=' + allow_cheats)
config = config.replace('max-players=10','max-players=' + max_players)
config = config.replace('server-port=19132','server-port=' + server_port)
config = config.replace('level-name=Bedrock level','level-name=' + level_name)
config = config.replace('level-seed=','level-seed' + level_seed)
fs.writeFile('./LiteLoader-' + BDS + '/server.properties', config, 'utf8', function (err) {
if (err) return console.log(err);
console.log(cyan + 'INFO' + white + ' Done! Now you can start your server (./LiteLoader-' + BDS + '/bedrock_server_mod.exe)')
console.log(cyan + 'INFO' + white + ' Thanks for using LLL')
console.log(cyan + 'INFO' + white + ' GitHub: https://github.com/LiteAdminProd/LL-Loader')
console.log(cyan + 'INFO' + white + ' Discord: prorok#1433')
console.log(cyan + 'INFO' + white + ' Telegram: https://t.me/Prorok_ilon')
});
});
}
function config(){
server_name = readlineSync.question(cyan + 'INFO' + white + ' server_name(motd) > ');
gamemode = readlineSync.question(cyan + 'INFO' + white + ' gamemode(survival/creative/adventure) > ');
difficulty = readlineSync.question(cyan + 'INFO' + white + ' difficulty(peaceful/easy/normal/hard) > ');
allow_cheats = readlineSync.question(cyan + 'INFO' + white + ' allow_cheats(true/false) > ');
max_players = readlineSync.question(cyan + 'INFO' + white + ' max_players > ');
server_port = readlineSync.question(cyan + 'INFO' + white + ' server_port > ');
level_name = readlineSync.question(cyan + 'INFO' + white + ' level_name > ');
level_seed = readlineSync.question(cyan + 'INFO' + white + ' level_seed(none if random seed) > ')
download_bds()
}
function gen(){
if(parseInt(LL.split('.')[0]) >= 2 && parseInt(LL.split('.')[1]) >= 2){
console.log(cyan + 'INFO' + white + ' Generating bedrock_server_mod...')
const bat = spawn('cmd.exe', ['/c', 'cd .\\LiteLoader-' + BDS + '&& LLPeEditor.exe']);
interval = setInterval(() => {
bat.stdin.write('\n')
}, 2000);
bat.on('exit', (code) => {
if(code != 0){
console.log(red + 'FATAL' + ' Failed generate bedrock_server_mod ')
process.exit(1)
}
else{
clearInterval(interval)
console.log(cyan + 'INFO' + white + ' Successfully generated bedrock_server_mod')
setconf()
}
});
}
else{
console.log(cyan + 'INFO' + white + ' Generating bedrock_server_mod...')
const bat = spawn('cmd.exe', ['/c', 'cd .\\LiteLoader-' + BDS + '&& SymDB2.exe']);
interval = setInterval(() => {
bat.stdin.write('\n')
}, 2000);
bat.on('exit', (code) => {
if(code != 0){
console.log(red + 'FATAL' + ' Failed generate bedrock_server_mod ')
process.exit(1)
}
else{
clearInterval(interval)
console.log(cyan + 'INFO' + white + ' Successfully generated bedrock_server_mod')
setconf()
}
});
}
}
function unzip(){
console.log(cyan + 'INFO' + white + ' Start unziping BDS...')
let bds = new AdmZip('./LiteLoader-' + BDS + '/Bedrock_Server.zip');
bds.extractAllTo(/*target path*/ './LiteLoader-' + BDS, /*overwrite*/ true);
console.log(cyan + 'INFO' + white + ' Successfully unzipped BDS')
console.log(cyan + 'INFO' + white + ' Start unziping LL...')
let ll = new AdmZip('LiteLoader-' + BDS + '/LiteLoader.zip');
ll.extractAllTo(/*target path*/ './LiteLoader-' + BDS, /*overwrite*/ true);
console.log(cyan + 'INFO' + white + ' Successfully unzipped LL')
console.log(cyan + 'INFO' + white + ' Start deleting BDS...')
fs.unlink('./LiteLoader-' + BDS + '/Bedrock_Server.zip',err => {
if(err){
console.log(red + 'FATAL' + ' Failed remove BDS')
process.exit(1)
}
else console.log(cyan + 'INFO' + white + ' Successfully deleted BDS')
gen()
})
console.log(cyan + 'INFO' + white + ' Start deleting LL...')
fs.unlink('LiteLoader-' + BDS + '/LiteLoader.zip',err => {
if(err){
console.log(red + 'FATAL' + ' Failed remove LiteLoader')
process.exit(1)
}
else console.log(cyan + 'INFO' + white + ' Successfully deleted LL')
})
}
async function download_ll(){
console.log(cyan + 'INFO' + white + ' Start downloading LL...')
await axios({
method: 'get',
url: LL_link,
responseType: 'stream'
})
.then(async function (response) {
await response.data.pipe(fs.createWriteStream('LiteLoader-' + BDS + '/LiteLoader.zip')).on("finish", function(){
console.log(cyan + 'INFO' + white + ' Successfully downloaded LiteLoader')
unzip()
});
})
.catch(error => {
console.error(error);
});
}
async function download_bds(){
console.log(cyan + 'INFO' + white + ' Creating dirictory of server...')
fs.mkdir('LiteLoader-' + BDS, err => {})
console.log(cyan + 'INFO' + white + ' Start downloading BDS...')
await axios({
method: 'get',
url: 'https://minecraft.azureedge.net/bin-win/bedrock-server-' + BDS + '.zip',
responseType: 'stream'
})
.then(async function (response) {
await response.data.pipe(fs.createWriteStream('LiteLoader-' + BDS + '/Bedrock_Server.zip')).on("finish", function(){
console.log(cyan + 'INFO' + white + ' Successfully downloaded BDS')
download_ll()
});
})
.catch(error => {
console.error(error);
});
}
function bds(){
console.log(cyan + 'INFO' + white + ' Getting all BDS versions...')
axios.get('https://raw.githubusercontent.com/StarsDream00/BDSVersions/main/bds_ver_win.json').then(res => {
res = JSON.parse(JSON.stringify(res.data))
let string = ''
for(let i = 0; i < res.length; i++){
if(res.length - i == 1){
string += res[i] + '.'
}
else{
string += res[i]+ ', '
}
}
//bds
console.log(cyan + 'INFO' + white + ' It is all BDS versions:')
console.log(string)
console.log(cyan + 'INFO' + white + ' Choose one from it and send')
nice = false
BDS = readlineSync.question(cyan + 'INFO' + white + ' version > ')
for(let i = 0; i < res.length; i++){
if(BDS == res[i]){
console.log(cyan + 'INFO' + white + ' You choose ' + BDS + ' version')
nice = true
config()
}
}
if(nice == false){
console.log('Invalid version')
}
})
.catch(error => {
console.error(error);
});
}
function main(){
console.log(cyan + 'INFO' + white + ' Getting all LiteLoader versions...')
axios.get('https://api.github.com/repos/LiteLDev/LiteLoaderBDS/releases').then(res => {
res = JSON.parse(JSON.stringify(res.data))
// console.log(res[2]['assets'][0]['browser_download_url'])
let string = ''
for(let i = 0; i < res.length; i++){
if(res.length - i == 1){
string += res[i]['tag_name'] + '.'
}
else{
string += res[i]['tag_name'] + ', '
}
}
console.log(cyan + 'INFO' + white + ' It is all LiteLoader versions:')
console.log(string)
console.log(cyan + 'INFO' + white + ' Choose one from it and send')
nice = false
LL = readlineSync.question(cyan + 'INFO' + white + ' version > ')
for(let i = 0; i < res.length; i++){
if(LL == res[i]['tag_name']){
console.log(cyan + 'INFO' + white + ' You choose ' + LL + ' version')
nice = true
LL_link = res[i]['assets'][0]['browser_download_url']
LL = res[i]['tag_name']
bds()
}
}
if(nice == false){
console.log('Invalid version')
}
})
.catch(error => {
console.error(error);
});
}
main()