Skip to content

Commit 38f415b

Browse files
committed
wip
1 parent ca32107 commit 38f415b

3 files changed

Lines changed: 58 additions & 18 deletions

File tree

src/dedicated-servers/dedicated-servers.service.ts

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -439,21 +439,47 @@ export class DedicatedServersService {
439439
}
440440
}
441441

442+
private async getServerStatusInfo(
443+
serverId: string,
444+
game: string,
445+
steamRelayEnabled: boolean,
446+
): Promise<{ steamId: string | null; clients_human: number; map: string }> {
447+
const rcon = await this.RconService.connect(serverId);
448+
if (!rcon) {
449+
return;
450+
}
451+
452+
if (game === "csgo") {
453+
const output = await rcon.send("status");
454+
const mapMatch = output.match(/^map\s*:\s*(\S+)/m);
455+
const playersMatch = output.match(/^players\s*:\s*(\d+)\s+humans/m);
456+
return {
457+
steamId: null,
458+
clients_human: playersMatch ? parseInt(playersMatch[1]) : 0,
459+
map: mapMatch ? mapMatch[1] : "unknown",
460+
};
461+
} else {
462+
const status = JSON.parse(await rcon.send("status_json"));
463+
return {
464+
steamId: steamRelayEnabled ? status.server.steamid : null,
465+
clients_human: status.server.clients_human,
466+
map: status.server.map || "unknown",
467+
};
468+
}
469+
}
470+
442471
public async pingDedicatedServer(serverId: string): Promise<void> {
443472
const { servers_by_pk: server } = await this.hasura.query({
444473
servers_by_pk: {
445474
__args: { id: serverId },
475+
game: true,
446476
connected: true,
447477
steam_relay: true,
448478
server_region: {
449479
steam_relay: true,
450480
},
451481
},
452482
});
453-
const rcon = await this.RconService.connect(serverId);
454-
if (!rcon) {
455-
return;
456-
}
457483

458484
if (!server.connected) {
459485
await this.hasura.mutation({
@@ -464,20 +490,30 @@ export class DedicatedServersService {
464490
});
465491
}
466492

467-
let steamId = null;
468-
const status = JSON.parse(await rcon.send("status_json"));
493+
// TODO - fix steam relay for csgo
494+
const steamRelayeEnabled =
495+
server.game === "csgo" ? false : server.server_region?.steam_relay;
496+
const { steamId, clients_human, map } = await this.getServerStatusInfo(
497+
serverId,
498+
server.game,
499+
steamRelayeEnabled,
500+
);
469501

470-
const steamRelayeEnabled = server.server_region?.steam_relay;
471-
if (steamRelayeEnabled) {
472-
steamId = status.server.steamid;
473-
}
502+
console.log({
503+
serverId,
504+
game: server.game,
505+
steamId,
506+
clients_human,
507+
map,
508+
steamRelayeEnabled,
509+
});
474510

475511
await this.redis.hset(
476512
"dedicated-servers:stats",
477513
serverId,
478514
JSON.stringify({
479-
clients_human: status.server.clients_human,
480-
map: status.server.map || "unknown",
515+
clients_human,
516+
map,
481517
last_ping: new Date().toISOString(),
482518
}),
483519
);

src/game-server-node/game-server-node.controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class GameServerNodeController {
4646
nodeIP: string;
4747
publicIP: string;
4848
csBuild: number;
49+
csgoBuild: number;
4950
supportsLowLatency: boolean;
5051
supportsCpuPinning: boolean;
5152
nodeStats: NodeStats;
@@ -80,6 +81,7 @@ export class GameServerNodeController {
8081
payload.lanIP,
8182
payload.publicIP,
8283
payload.csBuild,
84+
payload.csgoBuild,
8385
payload.supportsCpuPinning,
8486
payload.supportsLowLatency,
8587
payload.nodeStats.cpuInfo,

src/game-server-node/game-server-node.service.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ export class GameServerNodeService {
4747
this.batchApi = kc.makeApiClient(BatchV1Api);
4848
}
4949

50-
public static GET_UPDATE_JOB_NAME(
51-
gameServerNodeId: string,
52-
game = "cs2",
53-
) {
50+
public static GET_UPDATE_JOB_NAME(gameServerNodeId: string, game = "cs2") {
5451
const sanitized = gameServerNodeId.replaceAll(".", "-");
5552
return game === "csgo"
5653
? `update-csgo-server-${sanitized}`
@@ -131,6 +128,7 @@ export class GameServerNodeService {
131128
lanIP: string,
132129
publicIP: string,
133130
csBulid: number,
131+
csgoBuildId: number,
134132
supportsCpuPinning: boolean,
135133
supportsLowLatency: boolean,
136134
cpuInfo: {
@@ -161,6 +159,7 @@ export class GameServerNodeService {
161159
lan_ip: true,
162160
node_ip: true,
163161
build_id: true,
162+
csgo_build_id: true,
164163
public_ip: true,
165164
gpu: true,
166165
cpu_sockets: true,
@@ -178,7 +177,6 @@ export class GameServerNodeService {
178177
this.logger.log(`Creating volumes for node ${node}`);
179178
await this.createVolumes(node);
180179
}
181-
182180
if (game_server_nodes_by_pk?.status === "NotAcceptingNewMatches") {
183181
status = "NotAcceptingNewMatches";
184182
}
@@ -198,6 +196,8 @@ export class GameServerNodeService {
198196
game_server_nodes_by_pk.status !== status ||
199197
(game_server_nodes_by_pk.build_id !== csBulid &&
200198
game_server_nodes_by_pk.update_status === null) ||
199+
(game_server_nodes_by_pk.csgo_build_id !== csgoBuildId &&
200+
game_server_nodes_by_pk.update_status === null) ||
201201
game_server_nodes_by_pk.supports_cpu_pinning !== supportsCpuPinning ||
202202
game_server_nodes_by_pk.supports_low_latency !== supportsLowLatency ||
203203
game_server_nodes_by_pk.gpu !== nvidiaGPU ||
@@ -228,6 +228,9 @@ export class GameServerNodeService {
228228
...(game_server_nodes_by_pk.update_status === null
229229
? { build_id: csBulid }
230230
: {}),
231+
...(game_server_nodes_by_pk.update_status === null
232+
? { csgo_build_id: csgoBuildId }
233+
: {}),
231234
gpu: nvidiaGPU,
232235
cpu_sockets: cpuInfo.sockets,
233236
cpu_cores_per_socket: cpuInfo.coresPerSocket,
@@ -680,7 +683,6 @@ export class GameServerNodeService {
680683
},
681684
_set: {
682685
update_status: null,
683-
...(game === "csgo" ? { csgo_build_id: 1 } : {}),
684686
},
685687
},
686688
update_status: true,

0 commit comments

Comments
 (0)