Skip to content

Commit

Permalink
Merge pull request #496 from markus-wa/weapon-names
Browse files Browse the repository at this point in the history
fix: possible invalid weapon in kill events
  • Loading branch information
markus-wa authored Jan 21, 2024
2 parents 935fd38 + d7f0779 commit d812f4a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/demoinfocs/common/equipment.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func MapEquipment(eqName string) EquipmentType {
wep = EqHelmet
} else {
for name := range eqNameToWeapon {
if strings.HasPrefix(eqName, name) {
if strings.HasPrefix(eqName, name) || strings.HasSuffix(eqName, name) {
wep = eqNameToWeapon[name]
break
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/demoinfocs/common/equipment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ func TestMapEquipment(t *testing.T) {
assert.Equal(t, EqUnknown, MapEquipment("asdf"), "'asdf' should be mapped to EqUnknown")
}

func TestWeirdCS2Values(t *testing.T) {
assert.Equal(t, EqDeagle, MapEquipment("deagle_vip"), "'deagle_vip' should be mapped to EqDeagle")
assert.Equal(t, EqUSP, MapEquipment("usp_silencer_vip"), "'usp_silencer_vip' should be mapped to EqUSP")
assert.Equal(t, EqUSP, MapEquipment("5e_vip_usp_silencer"), "'5e_vip_usp_silencer' should be mapped to EqUSP")
assert.Equal(t, EqAK47, MapEquipment("5e_vip_ak47"), "'5e_vip_ak47' should be mapped to EqAK47")
assert.Equal(t, EqDeagle, MapEquipment("5e_default_deagle"), "'5e_default_deagle' should be mapped to EqDeagle")
}

func TestEquipment_Class(t *testing.T) {
assert.Equal(t, EqClassUnknown, NewEquipment(EqUnknown).Class(), "EqUnknown should have the class EqClassUnknown")
assert.Equal(t, EqClassPistols, NewEquipment(EqP2000).Class(), "EqP2000 should have the class EqClassPistols")
Expand Down

0 comments on commit d812f4a

Please sign in to comment.