38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
using AyCode.Core.Loggers;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
using System.Net.Http;
|
|
using TIAM.Core.Loggers;
|
|
|
|
namespace TIAMWebApp.Server.Services;
|
|
public class GameHub : Hub
|
|
{
|
|
|
|
private readonly TIAM.Core.Loggers.ILogger _logger;
|
|
public GameHub(IEnumerable<IAcLogWriterBase> logWriters)
|
|
{
|
|
|
|
_logger = new TIAM.Core.Loggers.Logger<SumupService>(logWriters.ToArray());
|
|
}
|
|
|
|
public async Task MakeMove(string groupName, int row, int col, string player)
|
|
{
|
|
_logger.Detail($"{groupName}, {row}, {col}, {player}");
|
|
await Clients.Group(groupName).SendAsync("ReceiveMove", row, col, player);
|
|
}
|
|
|
|
public async Task JoinGame(string groupName)
|
|
{
|
|
_logger.Detail(groupName);
|
|
await Groups.AddToGroupAsync(Context.ConnectionId, groupName);
|
|
await Clients.Group(groupName).SendAsync("PlayerJoined", Context.ConnectionId);
|
|
}
|
|
|
|
|
|
public async Task LeaveGame(string groupName)
|
|
{
|
|
await Groups.RemoveFromGroupAsync(Context.ConnectionId, groupName);
|
|
await Clients.Group(groupName).SendAsync("PlayerLeft", Context.ConnectionId);
|
|
}
|
|
}
|
|
|