moved multikills to gc response, fixed multikills being incorrectly tracked

This commit is contained in:
2021-10-21 15:52:08 +02:00
parent 6aaa0f2e48
commit d9f944c3d6
2 changed files with 50 additions and 32 deletions

View File

@@ -63,6 +63,16 @@ func SteamId2AccountId(steamId uint64) uint32 {
return uint32(steamId - 76561197960265728)
}
func playerStatsFromRound(round *protobuf.CMsgGCCStrike15V2_MatchmakingServerRoundStats, p *ent.Player) (int32, int32, int32, int32, int32, int32) {
for i, acc := range round.GetReservation().GetAccountIds() {
if AccountId2SteamId(acc) == p.ID {
return round.GetKills()[i], round.GetDeaths()[i], round.GetAssists()[i], round.GetEnemyHeadshots()[i], round.GetScores()[i], round.GetMvps()[i]
}
}
return 0, 0, 0, 0, 0, 0
}
func (d *DemoMatchLoader) HandleGCPacket(pkg *gamecoordinator.GCPacket) {
switch pkg.MsgType {
case uint32(protobuf.EGCBaseClientMsg_k_EMsgGCClientWelcome):
@@ -364,6 +374,7 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) {
log.Warningf("[DL] Failure to get match-details for %d from GC: %v", demo.MatchId, err)
continue
}
matchZero := matchDetails.GetMatches()[0]
lastRound := matchZero.GetRoundstatsall()[len(matchZero.Roundstatsall)-1]
var players []*ent.Player
@@ -403,23 +414,55 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) {
}
for i, mPlayer := range players {
var teamId int
var (
teamId int
mk2 uint
mk3 uint
mk4 uint
mk5 uint
)
if i > 4 {
teamId = 2
} else {
teamId = 1
}
var oldKills int32
for _, round := range matchZero.GetRoundstatsall() {
kills, _, _, _, _, _ := playerStatsFromRound(round, mPlayer)
killDiff := kills - oldKills
switch killDiff {
case 2:
mk2++
case 3:
mk3++
case 4:
mk4++
case 5:
mk5++
}
oldKills = kills
}
kills, deaths, assists, hs, score, mvp := playerStatsFromRound(lastRound, mPlayer)
d.lock.Lock()
err := d.db.Stats.Create().
SetMatches(tMatch).
SetPlayers(mPlayer).
SetTeamID(teamId).
SetKills(int(lastRound.GetKills()[i])).
SetDeaths(int(lastRound.GetDeaths()[i])).
SetAssists(int(lastRound.GetAssists()[i])).
SetMvp(uint(lastRound.GetMvps()[i])).
SetScore(int(lastRound.GetScores()[i])).
SetHeadshot(int(lastRound.GetEnemyHeadshots()[i])).
SetKills(int(kills)).
SetDeaths(int(deaths)).
SetAssists(int(assists)).
SetMvp(uint(mvp)).
SetScore(int(score)).
SetHeadshot(int(hs)).
SetMk2(mk2).
SetMk3(mk3).
SetMk4(mk4).
SetMk5(mk5).
Exec(context.Background())
d.lock.Unlock()
if err != nil {

View File

@@ -147,7 +147,6 @@ func (p *DemoParser) parseWorker() {
continue
}
killMap := make(map[uint64]int, 10)
eqMap := make(map[uint64][]*struct {
Eq int
HitGroup int
@@ -218,26 +217,6 @@ func (p *DemoParser) parseWorker() {
Spent int
}{Round: gs.TotalRoundsPlayed(), EqV: p.EquipmentValueCurrent(), Bank: p.Money(), Spent: p.MoneySpentThisRound()})
}
// track multikills
for _, igp := range gs.Participants().Playing() {
if igp != nil && igp.SteamID64 != 0 {
killDiff := igp.Kills() - killMap[igp.SteamID64]
tPlayer := p.getMatchPlayerBySteamID(tStats, igp.SteamID64)
switch killDiff {
case 2:
tPlayer.Mk2++
case 3:
tPlayer.Mk3++
case 4:
tPlayer.Mk4++
case 5:
tPlayer.Mk5++
}
killMap[igp.SteamID64] = igp.Kills()
}
}
})
// onPlayerFlashed
@@ -336,10 +315,6 @@ func (p *DemoParser) parseWorker() {
SetUdFlash(tMatchPlayer.UdFlash).
SetUdSmoke(tMatchPlayer.UdSmoke).
SetUdFlames(tMatchPlayer.UdFlames).
SetMk2(tMatchPlayer.Mk2).
SetMk3(tMatchPlayer.Mk3).
SetMk4(tMatchPlayer.Mk4).
SetMk5(tMatchPlayer.Mk5).
SetRankOld(tMatchPlayer.RankOld).
SetRankNew(tMatchPlayer.RankNew).
SetColor(tMatchPlayer.Color).