-
Notifications
You must be signed in to change notification settings - Fork 6
/
globals.ts
86 lines (77 loc) · 2.43 KB
/
globals.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import * as moment from "moment";
import SrcdsType = require("./Types/SrcdsLog");
var RootSteamIdRegex = /".+?\<\d*\>\<(?:\[U:1:\d+\]|STEAM_\d+:\d+:\d+|BOT|Console)\>(?:\<\w*\>)?"/;
var RootChickenRegex = /"chicken\<\d+\>"/;
export var SteamIdRegex = new RegExp("(" + RootSteamIdRegex.source + "|World|" + RootChickenRegex.source + ")");
export var TeamRegex = /["<]?(CT|TERRORIST|Spectator|Unassigned)[">]?/;
export var VectorRegex = /\[?([-.\d]+) ([-.\d]+) ([-.\d]+)\]?/;
export function getTeam(team:string) {
if (team == "TERRORIST") {
return Team.Terrorist;
} else if (team == "CT") {
return Team.CounterTerrorist;
} else if (team == "Unassigned") {
return Team.Unassigned;
} else if (team == "Spectator") {
return Team.Spectator;
} else {
return Team.Unknown;
}
}
export enum Team {
CounterTerrorist,
Terrorist,
Unassigned,
Spectator,
Unknown,
}
export class Player {
static regex: RegExp = /^"(.+)\<(\d*)\>\<(\[U:1:\d+\]|STEAM_\d+:\d+:\d+|BOT|Console)\>(?:\<(\w*)\>)?"/;
static chickenRegex = /^"chicken\<(\d+)\>"$/
public Name: string;
public PlayerID: number;
public SteamID: string;
public Team: Team;
constructor(playerString: string) {
if (playerString == 'World') {
this.Name = 'World';
this.SteamID == 'World';
} else if (playerString && playerString.length > 0) {
var regexResult = Player.regex.exec(playerString);
if (regexResult) {
this.Name = regexResult[1];
this.PlayerID = parseInt(regexResult[2]);
this.SteamID = regexResult[3];
this.Team = getTeam(regexResult[4]);
} else {
regexResult = Player.chickenRegex.exec(playerString);
if (regexResult) {
this.Name = "chicken";
this.PlayerID = parseInt(regexResult[1]);
} else {
throw `INvalid player :( ${playerString}`;
}
}
}
}
}
export class Vector {
public x: number;
public y: number;
public z: number;
static ReplaceRegex = /[\[\]\s]/g;
constructor(x:string,y:string,z:string) {
this.x = parseInt(x.replace(Vector.ReplaceRegex, ''));
this.y = parseInt(y.replace(Vector.ReplaceRegex, ''));
this.z = parseInt(z.replace(Vector.ReplaceRegex, ''));
}
}
export interface ConstructableType {
new(time:moment.Moment, data: RegExpExecArray, extraArg?: any): SrcdsType.ISrcdsLog;
Identifier: RegexAssignment | RegexAssignment[];
}
export interface RegexAssignment {
regex: RegExp;
//class: ConstructableType; //(time:moment.Moment, data: RegExpExecArray, extraArg?: any) => void;
extraArg?: any;
}