@@ -5,6 +5,7 @@ import { EncryptionService } from "../encryption/encryption.service";
55import { NotificationsService } from "../notifications/notifications.service" ;
66import { TypeSenseService } from "../type-sense/type-sense.service" ;
77import { RedisManagerService } from "../redis/redis-manager/redis-manager.service" ;
8+ import { CacheService } from "../cache/cache.service" ;
89
910@Injectable ( )
1011export class RconService {
@@ -15,6 +16,7 @@ export class RconService {
1516 private readonly logger : Logger ,
1617 private readonly typeSenseService : TypeSenseService ,
1718 private readonly redisManager : RedisManagerService ,
19+ private readonly cache : CacheService ,
1820 ) { }
1921
2022 private CONNECTION_TIMEOUT = 3 * 1000 ;
@@ -115,7 +117,11 @@ export class RconService {
115117 }
116118
117119 const version = server . game_server_node ?. version ;
118- if ( version ?. current === true && version ?. cvars === false ) {
120+ if ( server . is_dedicated && ! version ) {
121+ if ( ! ( await this . cache . has ( "cvars" ) ) ) {
122+ void this . genreateCvars ( serverId ) ;
123+ }
124+ } else if ( version ?. current === true && version ?. cvars === false ) {
119125 void this . genreateCvars ( serverId ) ;
120126 }
121127 } catch {
@@ -179,6 +185,7 @@ export class RconService {
179185 __args : {
180186 id : serverId ,
181187 } ,
188+ is_dedicated : true ,
182189 game_server_node : {
183190 version : {
184191 build_id : true ,
@@ -189,17 +196,35 @@ export class RconService {
189196 } ,
190197 } ) ;
191198
192- if (
193- server . game_server_node ?. version ?. current === false ||
194- server . game_server_node ?. version ?. cvars === true
195- ) {
196- return ;
197- }
199+ let buildId : string | undefined ;
200+ if ( server . is_dedicated ) {
201+ const { game_versions } = await this . hasuraService . query ( {
202+ game_versions : {
203+ __args : {
204+ where : {
205+ current : {
206+ _eq : true ,
207+ } ,
208+ } ,
209+ } ,
210+ build_id : true ,
211+ cvars : true ,
212+ } ,
213+ } ) ;
214+ buildId = game_versions . at ( 0 ) ?. build_id . toString ( ) ;
215+ } else {
216+ if (
217+ server . game_server_node ?. version ?. current === false ||
218+ server . game_server_node ?. version ?. cvars === true
219+ ) {
220+ return ;
221+ }
198222
199- const buildId = server . game_server_node ?. version ?. build_id . toString ( ) ;
223+ buildId = server . game_server_node ?. version ?. build_id . toString ( ) ;
224+ }
200225
201226 if ( ! buildId ) {
202- throw Error ( `unable to find build id for server ${ serverId } ` ) ;
227+ return ;
203228 }
204229
205230 this . logger . log ( `generating cvars for build: ${ buildId } ` ) ;
@@ -243,6 +268,8 @@ export class RconService {
243268 cvars : true ,
244269 } ,
245270 } ) ;
271+
272+ await this . cache . put ( "cvars" , true ) ;
246273 } catch ( error ) {
247274 this . logger . error (
248275 `unable to generate cvars for build: ${ buildId } ` ,
0 commit comments