Skip to content

Commit 7347c01

Browse files
authored
Merge pull request #5 from blastorg/support-old-steam-id
support old steam id
2 parents d2ba484 + c966e32 commit 7347c01

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

src/entities.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
const basePlayerRe = /"(?<name>.+)<(?<entityId>\d*)><(?<steamId>(?:\[U:[01]:\d+\]|BOT|Console))>(?:<(?<team>[^>]*)>)?"/;
1+
const basePlayerRe =
2+
/"(?<name>.+)<(?<entityId>\d*)><(?<steamId>(?:\[U:[01]:\d+\]|STEAM_[0-5]:[01]:\d+|BOT|Console))>(?:<(?<team>[^>]*)>)?"/;
23
const baseEntityRe = /"chicken<(?<entityId>\d+)>"/;
34
const baseWorldRe = /World/;
45

5-
export const entityRe = /".+<\d*><(?:\[U:[01]:\d+\]|BOT|Console)>(?:<[^>]*>)?"|"chicken<\d+>"|World/;
6+
export const entityRe =
7+
/".+<\d*><(?:\[U:[01]:\d+\]|STEAM_[0-5]:[01]:\d+|BOT|Console)>(?:<[^>]*>)?"|"chicken<\d+>"|World/;
68
export const vectorRe = /\[?[-.\d]+ [-.\d]+ [-.\d]+\]?/;
79

810
export enum Team {
@@ -145,6 +147,19 @@ export const parseEntity = (rawEntity: string): Entity => {
145147
export const parseVector = (rawVector: string): Vector => rawVector.split(" ").map(Number) as Vector;
146148

147149
export const convertSteamIdTo64Dec = (steamId: string): string => {
150+
// old steam id format: STEAM_1:0:12345
151+
if (steamId.includes("STEAM")) {
152+
const steamIdSplit = steamId.split(":");
153+
let commId = parseInt(steamIdSplit[2]) * 2;
154+
155+
if (steamIdSplit[1] === "1") {
156+
commId += 1;
157+
}
158+
const newCommId = BigInt(commId) + BigInt(76561197960265728);
159+
return newCommId.toString();
160+
}
161+
162+
// new steam id format: [U:1:230970467]
148163
const cleanedSteamId = steamId.replaceAll(/\[|\]/g, "");
149164
const uSteamIdSplit = cleanedSteamId.split(":");
150165
const commId = BigInt(uSteamIdSplit[2]) + BigInt(76561197960265728);

tests/steam_id.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { ok } from "assert";
2+
import { parse } from "../src";
3+
import { getEventString } from "./helpers/getEventString";
4+
import { counterTerroristTeam } from "./helpers/teams";
5+
6+
describe("steam id", () => {
7+
const event = {
8+
player: {
9+
kind: "player",
10+
entityId: 93,
11+
steamId: "76561198191236195",
12+
name: "PlayerName",
13+
team: counterTerroristTeam,
14+
},
15+
how: "world",
16+
};
17+
18+
it("should correctly parse with new steam id", () => {
19+
const log = '"PlayerName<93><[U:1:230970467]><CT>" [-1117 2465 -72] committed suicide with "world"';
20+
const result = parse(getEventString(log));
21+
22+
ok(result !== undefined, `Failed parse log: ${log}`);
23+
24+
expect(result.type).toBe("suicide");
25+
expect(result.payload).toMatchObject(event);
26+
});
27+
28+
it("should correctly parse with old steam id", () => {
29+
const log = '"PlayerName<93><STEAM_0:1:115485233><CT>" [-1117 2465 -72] committed suicide with "world"';
30+
const result = parse(getEventString(log));
31+
32+
ok(result !== undefined, `Failed parse log: ${log}`);
33+
34+
expect(result.type).toBe("suicide");
35+
expect(result.payload).toMatchObject(event);
36+
});
37+
});

0 commit comments

Comments
 (0)