fix player deaths with filter
This commit is contained in:
@@ -22,6 +22,8 @@ export async function populatePlayerSet(server?: number, weapon?: string) {
|
|||||||
const weaponPrefix = weapon ? `weapons:${weapon}:` : ''
|
const weaponPrefix = weapon ? `weapons:${weapon}:` : ''
|
||||||
const cacheLocation = serverPrefix + weaponPrefix + `players`
|
const cacheLocation = serverPrefix + weaponPrefix + `players`
|
||||||
const last_entry = Number(await cache.GET(cacheLocation + ':last_entry')) || 0
|
const last_entry = Number(await cache.GET(cacheLocation + ':last_entry')) || 0
|
||||||
|
|
||||||
|
//processKills
|
||||||
let query = db
|
let query = db
|
||||||
.selectFrom('kill')
|
.selectFrom('kill')
|
||||||
.select([
|
.select([
|
||||||
@@ -39,7 +41,7 @@ export async function populatePlayerSet(server?: number, weapon?: string) {
|
|||||||
if (weapon) {
|
if (weapon) {
|
||||||
query = query.where('cause_of_death', '=', weapon)
|
query = query.where('cause_of_death', '=', weapon)
|
||||||
}
|
}
|
||||||
const newData = await query.execute()
|
let newData = await query.execute()
|
||||||
if (newData.length == 0) {
|
if (newData.length == 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -51,7 +53,36 @@ export async function populatePlayerSet(server?: number, weapon?: string) {
|
|||||||
}
|
}
|
||||||
promises.push(cache.SADD(cacheLocation, attacker_id))
|
promises.push(cache.SADD(cacheLocation, attacker_id))
|
||||||
})
|
})
|
||||||
promises.push(cache.SET(cacheLocation + ':last_entry', newData[0].last_entry))
|
|
||||||
|
//processDeaths
|
||||||
|
let query2 = db
|
||||||
|
.selectFrom('kill')
|
||||||
|
.select([
|
||||||
|
sql<string>`DISTINCT(victim_id)`.as('victim_id'),
|
||||||
|
db
|
||||||
|
.selectFrom('kill')
|
||||||
|
.select(max('kill.id').as('last_entry'))
|
||||||
|
.as('last_entry')
|
||||||
|
])
|
||||||
|
.where('kill.id', '>', last_entry)
|
||||||
|
if (server) {
|
||||||
|
query2 = query2.where('server', '=', server)
|
||||||
|
}
|
||||||
|
if (weapon) {
|
||||||
|
query2 = query2.where('cause_of_death', '=', weapon)
|
||||||
|
}
|
||||||
|
const newData2 = await query2.execute()
|
||||||
|
newData2.forEach(({ victim_id }) => {
|
||||||
|
if (victim_id == 'last_entry' || victim_id == 'processedList') {
|
||||||
|
console.error('victim_id cannot be ' + victim_id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
promises.push(cache.SADD(cacheLocation, victim_id))
|
||||||
|
})
|
||||||
|
newData = await query.execute()
|
||||||
|
promises.push(
|
||||||
|
cache.SET(cacheLocation + ':last_entry', newData2[0].last_entry)
|
||||||
|
)
|
||||||
await Promise.all(promises)
|
await Promise.all(promises)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,14 +150,26 @@ export async function processPlayerReport(
|
|||||||
const promises: Promise<any>[] = []
|
const promises: Promise<any>[] = []
|
||||||
newData.forEach(
|
newData.forEach(
|
||||||
({ kills, avg_kill_distance, max_kill_distance, deaths, username }) => {
|
({ kills, avg_kill_distance, max_kill_distance, deaths, username }) => {
|
||||||
if (!username) return
|
promises.push(
|
||||||
|
(async () => {
|
||||||
|
if (!username) {
|
||||||
|
await cache.HSET(
|
||||||
|
cacheLocation,
|
||||||
|
'username',
|
||||||
|
(await cache.HGET(`players:` + player, 'username')) || ''
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
await cache.HSET(cacheLocation, 'username', username)
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
)
|
||||||
promises.push(
|
promises.push(
|
||||||
processAvg(cacheLocation, 'avg_kill_distance', {
|
processAvg(cacheLocation, 'avg_kill_distance', {
|
||||||
newkills: kills || 0,
|
newkills: kills || 0,
|
||||||
newavg: avg_kill_distance || 0
|
newavg: avg_kill_distance || 0
|
||||||
}).then((e) => cache.HINCRBY(cacheLocation, 'kills', kills || 0)),
|
}).then((e) => cache.HINCRBY(cacheLocation, 'kills', kills || 0)),
|
||||||
cache.HINCRBY(cacheLocation, 'deaths', deaths || 0),
|
cache.HINCRBY(cacheLocation, 'deaths', deaths || 0),
|
||||||
cache.HSET(cacheLocation, 'username', username),
|
|
||||||
processMax(cacheLocation, 'max_kill_distance', max_kill_distance)
|
processMax(cacheLocation, 'max_kill_distance', max_kill_distance)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user