File tree Expand file tree Collapse file tree 2 files changed +54
-2
lines changed Expand file tree Collapse file tree 2 files changed +54
-2
lines changed Original file line number Diff line number Diff line change 1- const basePlayerRe = / " (?< name > .+ ) < (?< entityId > \d * ) > < (?< steamId > (?: \[ U : [ 0 1 ] : \d + \] | B O T | C o n s o l e ) ) > (?: < (?< team > [ ^ > ] * ) > ) ? " / ;
1+ const basePlayerRe =
2+ / " (?< name > .+ ) < (?< entityId > \d * ) > < (?< steamId > (?: \[ U : [ 0 1 ] : \d + \] | S T E A M _ [ 0 - 5 ] : [ 0 1 ] : \d + | B O T | C o n s o l e ) ) > (?: < (?< team > [ ^ > ] * ) > ) ? " / ;
23const baseEntityRe = / " c h i c k e n < (?< entityId > \d + ) > " / ;
34const baseWorldRe = / W o r l d / ;
45
5- export const entityRe = / " .+ < \d * > < (?: \[ U : [ 0 1 ] : \d + \] | B O T | C o n s o l e ) > (?: < [ ^ > ] * > ) ? " | " c h i c k e n < \d + > " | W o r l d / ;
6+ export const entityRe =
7+ / " .+ < \d * > < (?: \[ U : [ 0 1 ] : \d + \] | S T E A M _ [ 0 - 5 ] : [ 0 1 ] : \d + | B O T | C o n s o l e ) > (?: < [ ^ > ] * > ) ? " | " c h i c k e n < \d + > " | W o r l d / ;
68export const vectorRe = / \[ ? [ - . \d ] + [ - . \d ] + [ - . \d ] + \] ? / ;
79
810export enum Team {
@@ -145,6 +147,19 @@ export const parseEntity = (rawEntity: string): Entity => {
145147export const parseVector = ( rawVector : string ) : Vector => rawVector . split ( " " ) . map ( Number ) as Vector ;
146148
147149export 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 ) ;
Original file line number Diff line number Diff line change 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+ } ) ;
You can’t perform that action at this time.
0 commit comments