Skip to content
Open
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
27 changes: 19 additions & 8 deletions src/matchmaking/matchmaking.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { e_match_types_enum } from "generated";
import { MatchmakeService } from "./matchmake.service";
import { MatchmakingLobbyService } from "./matchmaking-lobby.service";
import { RedisManagerService } from "../redis/redis-manager/redis-manager.service";
import { CacheService } from "src/cache/cache.service";
import { FiveStackWebSocketClient } from "src/sockets/types/FiveStackWebSocketClient";
import {
ConnectedSocket,
Expand All @@ -12,6 +13,7 @@ import {
WebSocketGateway,
} from "@nestjs/websockets";
import { JoinQueueError } from "./utilities/joinQueueError";
import { PlayerLobby } from "./types/PlayerLobby";
import { HasuraService } from "src/hasura/hasura.service";
import { isRoleAbove } from "src/utilities/isRoleAbove";
import { e_player_roles_enum } from "generated";
Expand All @@ -29,6 +31,7 @@ export class MatchmakingGateway {
public readonly redisManager: RedisManagerService,
public readonly matchmakeService: MatchmakeService,
public readonly matchmakingLobbyService: MatchmakingLobbyService,
private readonly cache: CacheService,
) {
this.redis = this.redisManager.getConnection();
}
Expand Down Expand Up @@ -122,7 +125,7 @@ export class MatchmakingGateway {
throw new JoinQueueError("You do not have permission to join this queue");
}

let lobby;
let lobby: PlayerLobby | undefined;
const user = client.user;

if (!user) {
Expand Down Expand Up @@ -220,16 +223,24 @@ export class MatchmakingGateway {
throw new JoinQueueError("Unable to find Player Lobby");
}

await this.matchmakingLobbyService.verifyLobby(lobby, user, type);

try {
await this.matchmakingLobbyService.setLobbyDetails(
regions,
type,
lobby,
await this.cache.lock(
`matchmaking:verify:${lobby.id}`,
async () => {
await this.matchmakingLobbyService.verifyLobby(lobby, user, type);
await this.matchmakingLobbyService.setLobbyDetails(
regions,
type,
lobby,
);
await this.matchmakeService.addLobbyToQueue(lobby.id);
return true;
},
);
await this.matchmakeService.addLobbyToQueue(lobby.id);
} catch (error) {
if (error instanceof JoinQueueError) {
throw error;
}
this.logger.error(`unable to add lobby to queue`, error);
await this.matchmakingLobbyService.removeLobbyFromQueue(lobby.id);
await this.matchmakingLobbyService.removeLobbyDetails(lobby.id);
Expand Down
2 changes: 2 additions & 0 deletions src/matchmaking/matchmaking.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { loggerFactory } from "../utilities/LoggerFactory";
import { MatchmakingGateway } from "./matchmaking.gateway";
import { HasuraModule } from "src/hasura/hasura.module";
import { RedisModule } from "src/redis/redis.module";
import { CacheModule } from "src/cache/cache.module";
import { MatchesModule } from "src/matches/matches.module";
import { MatchmakeService } from "./matchmake.service";
import { MatchmakingLobbyService } from "./matchmaking-lobby.service";
Expand All @@ -19,6 +20,7 @@ import { MarkPlayerOffline } from "./jobs/MarkPlayerOffline";
imports: [
RedisModule,
HasuraModule,
CacheModule,
forwardRef(() => MatchesModule),
BullModule.registerQueue({
name: MatchmakingQueues.Matchmaking,
Expand Down
5 changes: 3 additions & 2 deletions src/sockets/sockets.gateway.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
ConnectedSocket,
OnGatewayConnection,
SubscribeMessage,
WebSocketGateway,
} from "@nestjs/websockets";
Expand All @@ -10,7 +11,7 @@ import { SocketsService } from "./sockets.service";
@WebSocketGateway({
path: "/ws/web",
})
export class SocketsGateway {
export class SocketsGateway implements OnGatewayConnection {
constructor(private readonly sockets: SocketsService) {}

@SubscribeMessage("ping")
Expand All @@ -22,7 +23,7 @@ export class SocketsGateway {
await this.sockets.updateClient(client.user.steam_id, client.id);
}

private async handleConnection(
public async handleConnection(
@ConnectedSocket() client: FiveStackWebSocketClient,
request: Request,
) {
Expand Down
Loading