Skip to content
This repository has been archived by the owner on Nov 11, 2021. It is now read-only.

Commit

Permalink
Added fsm checks to detect duos matches
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasK33 committed Dec 22, 2020
1 parent 76bca0c commit 2257e5c
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 27 deletions.
6 changes: 3 additions & 3 deletions devops/kubernetes/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export class Fortify extends Chart {
new WebService(this, "sentry-discord-webhook", {
name: "sentry-discord-webhook",
replicas: 1,
version: "1.1.3",
version: "1.1.4",
env: [
{ name: "LISTEN_ADDRESS", value: ":8080" },
{ name: "WEBHOOK_ENV", value: "prod" },
Expand All @@ -277,8 +277,8 @@ export class Fortify extends Chart {
new WebService(this, "sentry-discord-dev-webhook", {
name: "sentry-discord-dev-webhook",
replicas: 1,
version: "1.1.3",
image: REGISTRY + "sentry-discord-webhook:1.1.3",
version: "1.1.4",
image: REGISTRY + "sentry-discord-webhook:1.1.4",
env: [
{ name: "LISTEN_ADDRESS", value: ":8080" },
{
Expand Down
2 changes: 1 addition & 1 deletion services/fsm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion services/fsm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fsm",
"version": "1.6.1",
"version": "1.6.2",
"description": "Finite State Machine",
"author": {
"name": "Thomas Kosiewski"
Expand Down
64 changes: 45 additions & 19 deletions services/fsm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { SystemEventType } from "@shared/events/systemEvents";
import { ConsumerCrashEvent } from "kafkajs";
import { Secrets } from "./secrets";
import { HealthCheck } from "@shared/services/healthCheck";
import { MatchService } from "@shared/services/match";
import { MatchService, MatchServicePlayer } from "@shared/services/match";
import { MatchProcessor } from "./processors/match";
import { UserCacheKey } from "@shared/state";

Expand Down Expand Up @@ -202,30 +202,56 @@ const {

let newMatchID: string | null = null;

// Calculate new matchID once we have collected 8 players
// Calculate new matchID once we have collected more than 8 players
if (Object.keys(cache.players).length > 7) {
newMatchID = await matchService.generateMatchID(
Object.values(cache.players).map(
({
public_player_state: {
account_id,
final_place,
persona_name,
player_slot,
},
}) => ({
accountID: account_id.toString(),
finalPlace: final_place,
name: persona_name,
slot: player_slot,
}),
),
// Check if we have received data from a duos lobby
const hasDuosData = Object.values(
cache.players,
).reduce(
(acc, player) =>
acc ||
player.public_player_state
.player_slot > 8,
false,
);

const matchServicePlayers: MatchServicePlayer[] = Object.values(
cache.players,
).map(
({
public_player_state: {
account_id,
final_place,
persona_name,
player_slot,
},
}) => ({
accountID: account_id.toString(),
finalPlace: final_place,
name: persona_name,
slot: player_slot,
}),
);

if (hasDuosData) {
if (
Object.keys(cache.players).length >
15
) {
newMatchID = await matchService.generateMatchID(
matchServicePlayers,
);
}
} else {
newMatchID = await matchService.generateMatchID(
matchServicePlayers,
);
}
}

// As matchID calculation happens over a period of time
// the newMatchID is going to be null until information
// of all 8 players is received
// of all players is received
if (newMatchID) {
await stateService.setUserMatchID(
id,
Expand Down
6 changes: 5 additions & 1 deletion services/fsm/src/processors/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ export class MatchProcessor {
);

if (isStandard) {
matchState.mode = FortifyGameMode.Normal;
if (Object.values(matchState.players).length > 8) {
matchState.mode = FortifyGameMode.Duos;
} else {
matchState.mode = FortifyGameMode.Normal;
}
} else {
matchState.mode = FortifyGameMode.Turbo;
}
Expand Down
2 changes: 1 addition & 1 deletion services/sentry-discord-webhook/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3"

services:
discord-webhook:
image: ghcr.io/fortify-labs/fortify/sentry-discord-webhook:1.1.3
image: ghcr.io/fortify-labs/fortify/sentry-discord-webhook:1.1.4
build: .

ports:
Expand Down
12 changes: 11 additions & 1 deletion services/sentry-discord-webhook/pkg/discord/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func SendMessage(alert *sentry.IssueAlert) {
sugar := logger.Sugar()

if alert.Data.TriggeredRule == nil || alert.Data.Event == nil {
sugar.Infow("TriggeredRule or Event is nil")
sugar.Infow("TriggeredRule or Event is nil", "alert", alert)
return
}

Expand Down Expand Up @@ -66,6 +66,16 @@ func SendMetricAlertMessage(alert *sentry.MetricAlert) {
defer logger.Sync() // flushes buffer, if any
sugar := logger.Sugar()

if alert.Data == nil ||
alert.Data.MetricAlert == nil ||
alert.Data.MetricAlert.Title == nil ||
alert.Data.WebURL == nil ||
alert.Data.DescriptionTitle == nil {

sugar.Infow("Data, MetricAlert, WebURL or DescriptionTitle is nil", "alert", alert)
return
}

webhook := Webhook{
Username: "Fortify Monitoring",
AvatarURL: "https://fortify.gg/favicon.ico",
Expand Down

0 comments on commit 2257e5c

Please sign in to comment.