checkpoint

This commit is contained in:
2022-06-12 12:37:32 -05:00
parent 2dcc6ca417
commit 4ca0b63564
43 changed files with 563 additions and 2128 deletions

View File

@@ -5,7 +5,6 @@ using Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers;
using Gameboard.ShogiUI.Sockets.Repositories;
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket;
using Gameboard.ShogiUI.Sockets.ServiceModels.Types;
using Gameboard.ShogiUI.Sockets.Services.Utility;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
@@ -17,7 +16,7 @@ using System.Threading.Tasks;
namespace Gameboard.ShogiUI.Sockets.Services
{
public interface ISocketService
public interface ISocketService
{
Task HandleSocketRequest(HttpContext context);
}
@@ -74,7 +73,7 @@ namespace Gameboard.ShogiUI.Sockets.Services
}
var socket = await context.WebSockets.AcceptWebSocketAsync();
communicationManager.SubscribeToBroadcast(socket, userName);
communicationManager.Subscribe(socket, userName);
while (socket.State == WebSocketState.Open)
{
try
@@ -82,7 +81,7 @@ namespace Gameboard.ShogiUI.Sockets.Services
var message = await socket.ReceiveTextAsync();
if (string.IsNullOrWhiteSpace(message)) continue;
logger.LogInformation("Request \n{0}\n", message);
var request = JsonConvert.DeserializeObject<Request>(message);
var request = JsonConvert.DeserializeObject<IRequest>(message);
if (request == null || !Enum.IsDefined(typeof(ClientAction), request.Action))
{
await socket.SendTextAsync("Error: Action not recognized.");
@@ -114,7 +113,7 @@ namespace Gameboard.ShogiUI.Sockets.Services
logger.LogInformation("Probably tried writing to a closed socket.");
logger.LogError(ex.Message);
}
communicationManager.UnsubscribeFromBroadcastAndGames(userName);
communicationManager.Unsubscribe(userName);
}
}