This commit is contained in:
HolographicHat
2022-03-23 20:27:43 +08:00
parent b03bc2add8
commit 7b18bcfbd3
4 changed files with 26 additions and 17 deletions

23
app.js
View File

@@ -7,11 +7,11 @@ const { initConfig, splitPacket, upload, decodeProto, log, setupHost, KPacket, d
const { exportData } = require("./export")
const { exitHook } = require("./exitHook.js");
// TODO: i18n
// TODO: send ack to avoid resend
// TODO: use kotlin rewrite it
(async () => {
try {
exitHook(() => {
setupHost(true)
console.log("按任意键退出")
cp.execSync("pause > nul", { stdio: "inherit" })
})
@@ -25,17 +25,18 @@ const { exitHook } = require("./exitHook.js");
}
await checkUpdate()
checkCDN().then(_ => debug("CDN check success."))
let gameProcess
let unexpectedExit = true
const gameProcess = cp.execFile(conf.executable, { cwd: conf.path },err => {
if (err !== null && !err.killed) {
throw err
}
})
gameProcess.on("exit", () => {
if (unexpectedExit) process.exit(0)
})
rs.create(conf,() => {
setupHost()
gameProcess = cp.execFile(conf.executable, { cwd: conf.path },err => {
if (err !== null && !err.killed) {
throw err
}
})
gameProcess.on("exit", () => {
if (unexpectedExit) process.exit(0)
})
},(ip, port, hServer) => {
let login = false
let cache = new Map()
@@ -143,6 +144,6 @@ const { exitHook } = require("./exitHook.js");
} else {
appcenter.uploadError(Error(e), true)
}
process.exit(0)
process.exit(1)
}
})()

View File

@@ -4,8 +4,8 @@
"description": "",
"main": "app.js",
"scripts": {
"pkg": "pkg -t node16-win-x64 -C Brotli app.js --build",
"pkg-for-windows7": "pkg -t node14-win-x64 -C Brotli app.js --build"
"pkg": "pkg -t node16-win-x64 -C Brotli app.js --build -o app.exe",
"pkg-for-windows7": "pkg -t node14-win-x64 -C Brotli app.js --build -o app-win7.exe"
},
"keywords": [],
"author": "",

View File

@@ -64,7 +64,6 @@ const agent = new https.Agent({
const create = async (conf, regionListLoadedCallback, regionSelectCallback) => {
const regions = await getModifiedRegionList(conf)
regionListLoadedCallback()
const hServer = https.createServer({
pfx: fs.readFileSync(cert),
passphrase: ""
@@ -84,7 +83,16 @@ const create = async (conf, regionListLoadedCallback, regionSelectCallback) => {
})
response.end(frontResponse.data)
}
}).listen(443, "127.0.0.1")
})
hServer.on("error", err => {
if (err["code"] === "EADDRINUSE") {
console.log("本机 443 端口被其它程序占用,请关闭后重试")
}
throw err
})
hServer.listen(443, "127.0.0.1", () => {
regionListLoadedCallback()
})
}
module.exports = {

View File

@@ -1,6 +1,6 @@
const version = {
code: 1,
name: "1.0.0"
code: 2,
name: "1.0.1"
}
module.exports = { version }