forked from negezor/srcds
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from blastorg/left-buyzone-with
left buyzone with
- Loading branch information
Showing
4 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { IBaseEvent, defineParser } from "./parser"; | ||
import { concatPattern } from "../helpers"; | ||
import { Entity, entityRe, parseEntity } from "../entities"; | ||
|
||
export type LeftBuyzoneWithEventPayload = { | ||
entity: Entity; | ||
kind: string; | ||
value: string[]; | ||
}; | ||
|
||
export type LeftBuyzoneWithEvent = IBaseEvent<"left_buyzone_with", LeftBuyzoneWithEventPayload>; | ||
|
||
// eslint-disable-next-line max-len | ||
// "Player<93><STEAM_1:0:12345><CT>" left buyzone with [ weapon_knife_butterfly weapon_usp_silencer kevlar(100) ] | ||
export const leftBuyzoneWithParser = defineParser<LeftBuyzoneWithEvent>({ | ||
type: "left_buyzone_with", | ||
|
||
patterns: [concatPattern`^(?<entity>${entityRe}) left buyzone with (?<value>\\[.*\\])$`], | ||
|
||
parse({ entity, kind = "left_buyzone_with", value }) { | ||
return { | ||
entity: parseEntity(entity), | ||
kind, | ||
value: value.trim().replaceAll("[", "").replaceAll("]", "").split(" ").slice(1, -1), | ||
}; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { ok } from "assert"; | ||
import { parse } from "../src"; | ||
import { getEventString } from "./helpers/getEventString"; | ||
import { counterTerroristTeam } from "./helpers/teams"; | ||
|
||
describe("left buyzone with", (): void => { | ||
it("should correctly parse", () => { | ||
const log = getEventString( | ||
'"Player<93><[U:1:230970467]><CT>" left buyzone with [ weapon_knife_butterfly weapon_usp_silencer kevlar(100) ]', | ||
); | ||
|
||
const result = parse(log); | ||
|
||
ok(result !== undefined, `Failed parse log: ${log}`); | ||
|
||
expect(result.type).toBe("left_buyzone_with"); | ||
expect(result.payload).toMatchObject({ | ||
entity: { | ||
kind: "player", | ||
|
||
entityId: 93, | ||
steamId: "76561198191236195", | ||
|
||
name: "Player", | ||
|
||
team: counterTerroristTeam, | ||
}, | ||
kind: "left_buyzone_with", | ||
value: ["weapon_knife_butterfly", "weapon_usp_silencer", "kevlar(100)"], | ||
}); | ||
}); | ||
}); |