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 JoinByCodeHandler : IActionHandler
public interface IJoinByCodeHandler
{
Task Handle(JoinByCodeRequest request, string userName);
}
public class JoinByCodeHandler : IJoinByCodeHandler
{
private readonly IGameboardRepository repository;
private readonly ISocketCommunicationManager communicationManager;
@@ -20,44 +21,44 @@ namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
this.communicationManager = communicationManager;
}
public async Task Handle(string json, string userName)
public async Task Handle(JoinByCodeRequest request, string userName)
{
var request = JsonConvert.DeserializeObject<JoinByCode>(json);
var sessionName = await repository.PostJoinPrivateSession(new PostJoinPrivateSession
{
PlayerName = userName,
JoinCode = request.JoinCode
});
//var request = JsonConvert.DeserializeObject<JoinByCode>(json);
//var sessionName = await repository.PostJoinPrivateSession(new PostJoinPrivateSession
//{
// PlayerName = userName,
// JoinCode = request.JoinCode
//});
if (sessionName == null)
{
var response = new JoinGameResponse(ClientAction.JoinByCode)
{
PlayerName = userName,
GameName = sessionName,
Error = "Error joining game."
};
await communicationManager.BroadcastToPlayers(response, userName);
}
else
{
// Other members of the game see a regular JoinGame occur.
var response = new JoinGameResponse(ClientAction.JoinGame)
{
PlayerName = userName,
GameName = sessionName
};
// At this time, userName hasn't subscribed and won't receive this message.
await communicationManager.BroadcastToGame(sessionName, response);
//if (sessionName == null)
//{
// var response = new JoinGameResponse(ClientAction.JoinByCode)
// {
// PlayerName = userName,
// GameName = sessionName,
// Error = "Error joining game."
// };
// await communicationManager.BroadcastToPlayers(response, userName);
//}
//else
//{
// // Other members of the game see a regular JoinGame occur.
// var response = new JoinGameResponse(ClientAction.JoinGame)
// {
// PlayerName = userName,
// GameName = sessionName
// };
// // At this time, userName hasn't subscribed and won't receive this message.
// await communicationManager.BroadcastToGame(sessionName, response);
// The player joining sees the JoinByCode occur.
response = new JoinGameResponse(ClientAction.JoinByCode)
{
PlayerName = userName,
GameName = sessionName
};
await communicationManager.BroadcastToPlayers(response, userName);
}
// // The player joining sees the JoinByCode occur.
// response = new JoinGameResponse(ClientAction.JoinByCode)
// {
// PlayerName = userName,
// GameName = sessionName
// };
// await communicationManager.BroadcastToPlayers(response, userName);
//}
}
}
}