Add global/lobby auto-join and match chat lifecycle
This commit is contained in:
@@ -2,12 +2,15 @@ namespace SOR.Game.Handlers;
|
||||
|
||||
using System.Text.Json;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Database.Entities.Game;
|
||||
using SOR.Database.Enums;
|
||||
using SOR.Networking.Abstractions.EventBus;
|
||||
using SOR.Networking.Abstractions.Messaging;
|
||||
using SOR.Networking.Abstractions.Push;
|
||||
using SOR.Networking.Abstractions.Transport;
|
||||
using SOR.Shared.Nats;
|
||||
using SOR.Shared.Networking;
|
||||
|
||||
/// <summary>
|
||||
@@ -22,15 +25,21 @@ internal sealed class GameJoinCustomLobbyHandler : GameHandlerBase, IMessageHand
|
||||
private readonly IMessageSerializer _serializer;
|
||||
private readonly GameDbContext _gameDb;
|
||||
private readonly IClientPush _clientPush;
|
||||
private readonly IEventBus _eventBus;
|
||||
private readonly ILogger<GameJoinCustomLobbyHandler> _logger;
|
||||
|
||||
public GameJoinCustomLobbyHandler(
|
||||
IMessageSerializer serializer,
|
||||
GameDbContext gameDb,
|
||||
IClientPush clientPush)
|
||||
IClientPush clientPush,
|
||||
IEventBus eventBus,
|
||||
ILogger<GameJoinCustomLobbyHandler> logger)
|
||||
{
|
||||
_serializer = serializer;
|
||||
_gameDb = gameDb;
|
||||
_clientPush = clientPush;
|
||||
_eventBus = eventBus;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public string MessageType => "game.custom.join";
|
||||
@@ -88,6 +97,23 @@ internal sealed class GameJoinCustomLobbyHandler : GameHandlerBase, IMessageHand
|
||||
|
||||
await _gameDb.SaveChangesAsync(ct);
|
||||
|
||||
try
|
||||
{
|
||||
await _eventBus.PublishAsync(
|
||||
NatsSubjects.GameStarted,
|
||||
new GameStartedEvent(
|
||||
session.Id,
|
||||
new[] { lobby.HostAccountId, accountId },
|
||||
DateTimeOffset.UtcNow),
|
||||
ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex,
|
||||
"Failed publishing game-started event for custom lobby session {SessionId}",
|
||||
session.Id);
|
||||
}
|
||||
|
||||
// Push game-started notification to both players.
|
||||
var push = new CustomLobbyGameStartedPush(session.Id, accountId);
|
||||
var pushToHost = new CustomLobbyGameStartedPush(session.Id, accountId);
|
||||
|
||||
Reference in New Issue
Block a user