forked from AxTps/Starlight_Lancher
feat:移除了弹窗,服务器添加sls
This commit is contained in:
36
packages/server/src/log-parse.ts
Normal file
36
packages/server/src/log-parse.ts
Normal file
@ -0,0 +1,36 @@
|
||||
export interface ServerLogSignal {
|
||||
eulaRequired?: boolean
|
||||
started?: boolean
|
||||
stopping?: boolean
|
||||
}
|
||||
|
||||
const EULA_RE = /you need to agree to the eula|eula\.txt/i
|
||||
const DONE_RE = /Done \([\d.]+s\)!/
|
||||
const STOPPING_RE = /Stopping (the )?server|Stopping singleplayer server/i
|
||||
|
||||
/** Classifies a dedicated server log line for status tracking. */
|
||||
export function classifyServerLogLine(line: string): ServerLogSignal {
|
||||
const signals: ServerLogSignal = {}
|
||||
if (EULA_RE.test(line)) signals.eulaRequired = true
|
||||
if (DONE_RE.test(line)) signals.started = true
|
||||
if (STOPPING_RE.test(line)) signals.stopping = true
|
||||
return signals
|
||||
}
|
||||
|
||||
export interface ServerExitSummary {
|
||||
crashed: boolean
|
||||
eulaRequired: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Summarizes the outcome of a server process run from its log lines and exit
|
||||
* code. A clean exit right after the EULA notice is the expected first-run
|
||||
* behavior, not a crash.
|
||||
*/
|
||||
export function summarizeServerExit(lines: string[], exitCode: number | null): ServerExitSummary {
|
||||
const eulaRequired = lines.some((line) => classifyServerLogLine(line).eulaRequired)
|
||||
return {
|
||||
crashed: exitCode !== null && exitCode !== 0 && !eulaRequired,
|
||||
eulaRequired,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user