before deleting Rules

This commit is contained in:
2021-05-08 10:26:04 -05:00
parent 05a9c71499
commit f8f779e84c
80 changed files with 1109 additions and 832 deletions

View File

@@ -1,13 +1,14 @@
using Gameboard.Shogi.Api.ServiceModels.Messages;
using Gameboard.ShogiUI.Sockets.Repositories;
using Gameboard.ShogiUI.Sockets.Repositories;
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages;
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
using Newtonsoft.Json;
using System.Threading.Tasks;
namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
{
public class JoinGameHandler : IActionHandler
public interface IJoinGameHandler
{
Task Handle(JoinGameRequest request, string userName);
}
public class JoinGameHandler : IJoinGameHandler
{
private readonly IGameboardRepository gameboardRepository;
private readonly ISocketCommunicationManager communicationManager;
@@ -19,30 +20,30 @@ namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
this.communicationManager = communicationManager;
}
public async Task Handle(string json, string userName)
public async Task Handle(JoinGameRequest request, string userName)
{
var request = JsonConvert.DeserializeObject<JoinGameRequest>(json);
//var request = JsonConvert.DeserializeObject<JoinGameRequest>(json);
var joinSucceeded = await gameboardRepository.PutJoinPublicSession(new PutJoinPublicSession
{
PlayerName = userName,
SessionName = request.GameName
});
//var joinSucceeded = await gameboardRepository.PutJoinPublicSession(new PutJoinPublicSession
//{
// PlayerName = userName,
// SessionName = request.GameName
//});
var response = new JoinGameResponse(ClientAction.JoinGame)
{
PlayerName = userName,
GameName = request.GameName
};
if (joinSucceeded)
{
await communicationManager.BroadcastToAll(response);
}
else
{
response.Error = "Game is full.";
await communicationManager.BroadcastToPlayers(response, userName);
}
//var response = new JoinGameResponse(ClientAction.JoinGame)
//{
// PlayerName = userName,
// GameName = request.GameName
//};
//if (joinSucceeded)
//{
// await communicationManager.BroadcastToAll(response);
//}
//else
//{
// response.Error = "Game is full.";
// await communicationManager.BroadcastToPlayers(response, userName);
//}
}
}
}