@@ -6,8 +6,27 @@ import { TxConfigState } from "@shared/enums";
66import type { GlobalStatusType } from "@shared/socketioTypes" ;
77import quitProcess from "@lib/quitProcess" ;
88import consoleFactory , { processStdioEnsureEol , setTTYTitle } from "@lib/console" ;
9+ import { z } from "zod" ;
910const console = consoleFactory ( 'Manager' ) ;
1011
12+ //Types
13+ type HostStatusType = {
14+ //txAdmin state
15+ cfgPath : string | null ;
16+ dataPath : string | null ;
17+ isConfigured : boolean ;
18+ playerCount : number ;
19+ status : typeof txCore . fxMonitor . currentStatus ;
20+
21+ //Detected at runtime
22+ cfxId : string | null ;
23+ gameName : 'fivem' | 'redm' | null ;
24+ joinLink : string | null ;
25+ joinDeepLink : string | null ;
26+ playerSlots : number | null ;
27+ projectName : string | null ;
28+ }
29+
1130
1231/**
1332 * This class is for "high order" logic and methods that shouldn't live inside any specific component.
@@ -125,6 +144,31 @@ export default class TxManager {
125144 }
126145
127146
147+ /**
148+ * Returns the status object that is sent to the host status endpoint
149+ */
150+ get hostStatus ( ) : HostStatusType {
151+ const serverPaths = txCore . fxRunner . serverPaths ;
152+ const cfxId = txCore . cacheStore . getTyped ( 'fxsRuntime:cfxId' , z . string ( ) ) ?? null ;
153+ return {
154+ //txAdmin state
155+ isConfigured : this . configState === TxConfigState . Ready ,
156+ dataPath : serverPaths ?. dataPath ?? null ,
157+ cfgPath : serverPaths ?. cfgPath ?? null ,
158+ playerCount : txCore . fxPlayerlist . onlineCount ,
159+ status : txCore . fxMonitor . currentStatus ,
160+
161+ //Detected at runtime
162+ cfxId,
163+ gameName : txCore . cacheStore . getTyped ( 'fxsRuntime:gameName' , z . enum ( [ 'fivem' , 'redm' ] ) ) ?? null ,
164+ joinDeepLink : cfxId ? `fivem://connect/cfx.re/join/${ cfxId } ` : null ,
165+ joinLink : cfxId ? `https://cfx.re/join/${ cfxId } ` : null ,
166+ playerSlots : txCore . cacheStore . getTyped ( 'fxsRuntime:maxClients' , z . number ( ) ) ?? null ,
167+ projectName : txCore . cacheStore . getTyped ( 'fxsRuntime:projectName' , z . string ( ) ) ?? null ,
168+ }
169+ }
170+
171+
128172 /**
129173 * Returns the global status object that is sent to the clients
130174 */
@@ -141,7 +185,6 @@ export default class TxManager {
141185 name : txConfig . general . serverName ,
142186 whitelist : txConfig . whitelist . mode ,
143187 } ,
144- // @ts -ignore scheduler type narrowing is wrong because cant use "as const" in javascript
145188 scheduler : txCore . fxScheduler . getStatus ( ) , //no push events, updated every Scheduler.checkSchedule()
146189 }
147190 }
0 commit comments