Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support team ID in population data #609

Merged
merged 3 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"logform": "^2.4.2",
"moment": "^2.29.4",
"moment-timezone": "^0.5.33",
"ps2census": "^4.3.0",
"ps2census": "^4.4.1",
"reflect-metadata": "^0.1.13",
"utf-8-validate": "^5.0.8",
"winston": "^3.8.1",
Expand Down
6 changes: 5 additions & 1 deletion src/brokers/CharacterBroker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ export default class CharacterBroker {
throw new Error('AttackerEvent had no actual attacker character ID! ps2census bug');
}

// Re-create character with teamID supplied
character = new Character(await payload.character(), parseInt(payload.team_id, 10));

const attackerCharacter = await payload.attacker<CharacterWorldOutfitLeader>();

if (!attackerCharacter) {
CharacterBroker.logger.warn('AttackerEvent returned no attacker!');
} else {
attacker = new Character(attackerCharacter);
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
attacker = new Character(attackerCharacter, parseInt(payload.attacker_team_id, 10));
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/data/Character.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ class Character implements CharacterInterface {
public id: string;
public name: string;
public faction: Faction;
public teamId: Faction;
public world: World;
public battleRank: number;
public asp: number;
public adjustedBattleRank: number;
public outfit: Outfit | null;

constructor(characterData: CharacterWorldOutfitLeader) {
constructor(characterData: CharacterWorldOutfitLeader, teamId: Faction | null = null) {
this.id = characterData.character_id;
this.name = characterData.name.first;
this.faction = parseInt(characterData.faction_id, 10);
Expand Down Expand Up @@ -45,6 +46,13 @@ class Character implements CharacterInterface {
} else {
this.outfit = new FakeOutfitFactory(this.faction).build();
}

// If we're injecting the teamId from a death / other event, add it now
if (teamId) {
this.teamId = teamId;
} else {
this.teamId = this.faction;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/handlers/CharacterPresenceHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class CharacterPresenceHandler implements CharacterPresenceHandle
await this.cacheClient.setex(`CharacterPresence-${character.id}`, 60 * 5, zone);

// Add character to overall redis set to be scanned later split by world and faction
const listName = `CharacterPresencePops-${instance.world}-${character.faction}`;
const listName = `CharacterPresencePops-${instance.world}-${character.teamId}`;
await this.cacheClient.sadd(listName, character.id);

// Add list to global list, so they can all be cleared up upon start of aggregator
Expand Down
9 changes: 3 additions & 6 deletions src/handlers/aggregate/global/GlobalCharacterAggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export default class GlobalCharacterAggregate implements AggregateHandlerInterfa

if (event.killType === Kill.Normal) {
attackerDocs.push({$inc: {kills: 1}});

const factionKey = `factionKills.${attackerFactionShort}.${victimFactionShort}`;
attackerDocs.push({$inc: {[factionKey]: 1}});
}

if (event.killType === Kill.TeamKill) {
Expand All @@ -83,12 +86,6 @@ export default class GlobalCharacterAggregate implements AggregateHandlerInterfa
attackerDocs.push({$inc: {headshots: 1}});
}

// Faction vs Faction
if (event.attackerCharacter.faction !== event.character.faction) {
const factionKey = `factionKills.${attackerFactionShort}.${victimFactionShort}`;
attackerDocs.push({$inc: {[factionKey]: 1}});
}

if (event.attackerCharacter && attackerDocs.length > 0) {
try {
if (event.instance.ps2AlertsEventType === Ps2AlertsEventType.LIVE_METAGAME) {
Expand Down
9 changes: 3 additions & 6 deletions src/handlers/aggregate/global/GlobalFactionCombatAggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export default class GlobalFactionCombatAggregate implements AggregateHandlerInt
{$inc: {[attackerKillKey]: 1}},
{$inc: {['totals.kills']: 1}},
);

const factionKey = `factionKills.${attackerFactionShort}.${victimFactionShort}`;
documents.push({$inc: {[factionKey]: 1}});
}

if (event.killType === Kill.TeamKill) {
Expand All @@ -59,12 +62,6 @@ export default class GlobalFactionCombatAggregate implements AggregateHandlerInt
{$inc: {['totals.headshots']: 1}},
);
}

// Faction vs Faction
if (event.attackerCharacter.faction !== event.character.faction) {
const factionKey = `factionKills.${attackerFactionShort}.${victimFactionShort}`;
documents.push({$inc: {[factionKey]: 1}});
}
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/restrict-template-expressions
Expand Down
9 changes: 3 additions & 6 deletions src/handlers/aggregate/global/GlobalLoadoutAggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export default class GlobalLoadoutAggregate implements AggregateHandlerInterface

if (event.killType === Kill.Normal) {
attackerDocs.push({$inc: {kills: 1}});

const factionKey = `factionKills.${attackerFactionShort}.${victimFactionShort}`;
attackerDocs.push({$inc: {[factionKey]: 1}});
}

if (event.killType === Kill.TeamKill) {
Expand All @@ -51,12 +54,6 @@ export default class GlobalLoadoutAggregate implements AggregateHandlerInterface
attackerDocs.push({$inc: {headshots: 1}});
}

// Faction vs Faction
if (event.attackerCharacter.faction !== event.character.faction) {
const factionKey = `factionKills.${attackerFactionShort}.${victimFactionShort}`;
attackerDocs.push({$inc: {[factionKey]: 1}});
}

if (attackerDocs.length > 0) {
try {
await this.apiMQDelayPublisher.send(new ApiMQGlobalAggregateMessage(
Expand Down
8 changes: 2 additions & 6 deletions src/handlers/aggregate/global/GlobalOutfitAggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export default class GlobalOutfitAggregate implements AggregateHandlerInterface<

if (event.killType === Kill.Normal) {
attackerDocs.push({$inc: {kills: 1}});
const factionKey = `factionKills.${attackerFactionShort}.${victimFactionShort}`;
attackerDocs.push({$inc: {[factionKey]: 1}});
}

if (event.killType === Kill.TeamKill) {
Expand All @@ -86,12 +88,6 @@ export default class GlobalOutfitAggregate implements AggregateHandlerInterface<
attackerDocs.push({$inc: {headshots: 1}});
}

// Faction vs Faction
if (event.attackerCharacter.faction !== event.character.faction) {
const factionKey = `factionKills.${attackerFactionShort}.${victimFactionShort}`;
attackerDocs.push({$inc: {[factionKey]: 1}});
}

// Purpose for this is we can aggregate stats for "outfitless" characters, e.g. TR (-3) got X kills
const attackerOutfitId = event.attackerCharacter.outfit ? event.attackerCharacter.outfit.id : `-${event.attackerCharacter.faction}`;
const victimOutfitId = event.character.outfit ? event.character.outfit.id : `-${event.character.faction}`;
Expand Down
9 changes: 3 additions & 6 deletions src/handlers/aggregate/global/GlobalWeaponAggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export default class GlobalWeaponAggregate implements AggregateHandlerInterface<

if (event.killType === Kill.Normal) {
documents.push({$inc: {kills: 1}});

const factionKey = `factionKills.${attackerFactionShort}.${victimFactionShort}`;
documents.push({$inc: {[factionKey]: 1}});
}

if (event.killType === Kill.TeamKill) {
Expand All @@ -49,12 +52,6 @@ export default class GlobalWeaponAggregate implements AggregateHandlerInterface<
documents.push({$inc: {headshots: 1}});
}

// Faction vs Faction
if (event.attackerCharacter.faction !== event.character.faction) {
const factionKey = `factionKills.${attackerFactionShort}.${victimFactionShort}`;
documents.push({$inc: {[factionKey]: 1}});
}

try {
await this.apiMQDelayPublisher.send(new ApiMQGlobalAggregateMessage(
MqAcceptedPatterns.GLOBAL_WEAPON_AGGREGATE,
Expand Down
8 changes: 2 additions & 6 deletions src/handlers/aggregate/instance/InstanceCharacterAggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export default class InstanceCharacterAggregate implements AggregateHandlerInter

if (event.killType === Kill.Normal) {
attackerDocs.push({$inc: {kills: 1}});
const factionKey = `factionKills.${attackerFactionShort}.${victimFactionShort}`;
attackerDocs.push({$inc: {[factionKey]: 1}});
}

if (event.killType === Kill.TeamKill) {
Expand All @@ -57,12 +59,6 @@ export default class InstanceCharacterAggregate implements AggregateHandlerInter
attackerDocs.push({$inc: {headshots: 1}});
}

// Faction vs Faction
if (event.attackerCharacter.faction !== event.character.faction) {
const factionKey = `factionKills.${attackerFactionShort}.${victimFactionShort}`;
attackerDocs.push({$inc: {[factionKey]: 1}});
}

if (event.attackerCharacter && attackerDocs.length > 0) {
try {
await this.apiMQPublisher.send(new ApiMQMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export default class InstanceFactionCombatAggregate implements AggregateHandlerI
{$inc: {[attackerKillKey]: 1}},
{$inc: {['totals.kills']: 1}},
);

const factionKey = `factionKills.${attackerFactionShort}.${victimFactionShort}`;
documents.push({$inc: {[factionKey]: 1}});
}

if (event.killType === Kill.TeamKill) {
Expand All @@ -53,12 +56,6 @@ export default class InstanceFactionCombatAggregate implements AggregateHandlerI
{$inc: {['totals.headshots']: 1}},
);
}

// Faction vs Faction
if (event.attackerCharacter.faction !== event.character.faction) {
const factionKey = `factionKills.${attackerFactionShort}.${victimFactionShort}`;
documents.push({$inc: {[factionKey]: 1}});
}
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/restrict-template-expressions
Expand Down
9 changes: 3 additions & 6 deletions src/handlers/aggregate/instance/InstanceLoadoutAggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export default class InstanceLoadoutAggregate implements AggregateHandlerInterfa

if (event.killType === Kill.Normal) {
attackerDocs.push({$inc: {kills: 1}});

const factionKey = `factionKills.${attackerFactionShort}.${victimFactionShort}`;
attackerDocs.push({$inc: {[factionKey]: 1}});
}

if (event.killType === Kill.TeamKill) {
Expand All @@ -46,12 +49,6 @@ export default class InstanceLoadoutAggregate implements AggregateHandlerInterfa
attackerDocs.push({$inc: {headshots: 1}});
}

// Faction vs Faction
if (event.attackerCharacter.faction !== event.character.faction) {
const factionKey = `factionKills.${attackerFactionShort}.${victimFactionShort}`;
attackerDocs.push({$inc: {[factionKey]: 1}});
}

if (event.attackerCharacter && attackerDocs.length > 0) {
try {
await this.apiMQPublisher.send(new ApiMQMessage(
Expand Down
9 changes: 3 additions & 6 deletions src/handlers/aggregate/instance/InstanceOutfitAggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ export default class InstanceOutfitAggregate implements AggregateHandlerInterfac

if (event.killType === Kill.Normal) {
attackerDocs.push({$inc: {kills: 1}});

const factionKey = `factionKills.${attackerFactionShort}.${victimFactionShort}`;
attackerDocs.push({$inc: {[factionKey]: 1}});
}

if (event.killType === Kill.TeamKill) {
Expand All @@ -87,12 +90,6 @@ export default class InstanceOutfitAggregate implements AggregateHandlerInterfac
attackerDocs.push({$inc: {headshots: 1}});
}

// Faction vs Faction
if (event.attackerCharacter.faction !== event.character.faction) {
const factionKey = `factionKills.${attackerFactionShort}.${victimFactionShort}`;
attackerDocs.push({$inc: {[factionKey]: 1}});
}

// Purpose for this is we can aggregate stats for "outfitless" characters, e.g. TR (-3) got X kills
const attackerOutfitId = event.attackerCharacter.outfit ? event.attackerCharacter.outfit.id : `-${event.attackerCharacter.faction}`;
const victimOutfitId = event.character.outfit ? event.character.outfit.id : `-${event.character.faction}`;
Expand Down
9 changes: 3 additions & 6 deletions src/handlers/aggregate/instance/InstanceWeaponAggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export default class InstanceWeaponAggregate implements AggregateHandlerInterfac

if (event.killType === Kill.Normal) {
documents.push({$inc: {kills: 1}});

const factionKey = `factionKills.${attackerFactionShort}.${victimFactionShort}`;
documents.push({$inc: {[factionKey]: 1}});
}

if (event.killType === Kill.TeamKill) {
Expand All @@ -45,12 +48,6 @@ export default class InstanceWeaponAggregate implements AggregateHandlerInterfac
documents.push({$inc: {headshots: 1}});
}

// Faction vs Faction
if (event.attackerCharacter.faction !== event.character.faction) {
const factionKey = `factionKills.${attackerFactionShort}.${victimFactionShort}`;
documents.push({$inc: {[factionKey]: 1}});
}

try {
await this.apiMQPublisher.send(new ApiMQMessage(
MqAcceptedPatterns.INSTANCE_WEAPON_AGGREGATE,
Expand Down
3 changes: 2 additions & 1 deletion src/logics/VehicleCharacterDeathLogic.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import LogicInterface from './LogicInterface';
import {getLogger} from '../logger';
import DeathEvent from '../handlers/ps2census/events/DeathEvent';
import {Kill} from 'ps2census';

export default class VehicleCharacterDeathLogic implements LogicInterface {
private static readonly logger = getLogger('VehicleCharacterDeathLogic');
Expand All @@ -25,7 +26,7 @@ export default class VehicleCharacterDeathLogic implements LogicInterface {
}

// If TK
if (this.event.attackerCharacter.faction === this.event.character.faction) {
if (this.event.killType === Kill.TeamKill) {
if (this.event.attackerCharacter.id !== this.event.character.id) {
VehicleCharacterDeathLogic.logger.silly(`[${this.mode}] VvI TK`);
attackerDocs.push({$inc: {['infantry.teamkills']: 1}});
Expand Down
6 changes: 3 additions & 3 deletions src/logics/VehicleDestroyLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export default class VehicleDestroyLogic implements LogicInterface {

// IvV
if (!this.event.attackerVehicleId) {
if (this.event.killType === Destroy.Normal || this.event.killType === Destroy.Undetermined) {
if (this.event.killType === Destroy.Normal) {
VehicleDestroyLogic.logger.silly(`[${this.mode}] IvV death`);
victimDocs.push({$inc: {['infantry.deaths']: 1}});
} else if (this.event.attackerCharacter.faction === this.event.character.faction) {
} else if (this.event.killType === Destroy.Friendly) {
VehicleDestroyLogic.logger.silly(`[${this.mode}] IvV TK`);
victimDocs.push({$inc: {['infantry.teamkilled']: 1}});
}
Expand All @@ -30,7 +30,7 @@ export default class VehicleDestroyLogic implements LogicInterface {
// VvV
if (this.event.attackerVehicleId) {
// Non TKs
if (this.event.killType === Destroy.Normal || this.event.killType === Destroy.Undetermined) {
if (this.event.killType === Destroy.Normal) {
// Kill - VvV
VehicleDestroyLogic.logger.silly(`[${this.mode}] VvV`);
attackerDocs.push({$inc: {['vehicles.kills']: 1}});
Expand Down
2 changes: 1 addition & 1 deletion src/ps2alerts-constants
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1888,10 +1888,10 @@ proxy-addr@~2.0.7:
forwarded "0.2.0"
ipaddr.js "1.9.1"

ps2census@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/ps2census/-/ps2census-4.3.0.tgz#42757e6a639427b3f340d46fe3bef646cfe4b828"
integrity sha512-7HN9YXs5XANsqpZJX4z9tI828x6m+PCA6WXDSncMYQkwqPFMpX3a1ukvdmmTSfoMv753SdJmApLFciaTBXcXpA==
ps2census@^4.4.1:
version "4.4.1"
resolved "https://registry.yarnpkg.com/ps2census/-/ps2census-4.4.1.tgz#54165a901d754b58cfa23925c1bab98feafaa2d7"
integrity sha512-3SPnzZALX+K9VlymMpssyOUmI69X/EOKWTkIJ2CKFcrMz3vhLiB2OW4vN5OFcBVkEe80iksN1buBGq57H6QBcQ==
dependencies:
axios "0.27.2"
eventemitter3 "4.0.7"
Expand Down