checkpoint

This commit is contained in:
2021-02-23 18:03:23 -06:00
parent 8d79c75616
commit f644795cd3
38 changed files with 1451 additions and 177 deletions

View File

@@ -1,11 +1,9 @@
using Gameboard.Shogi.Api.ServiceModels.Messages;
using Gameboard.ShogiUI.Sockets.Extensions;
using Gameboard.ShogiUI.Sockets.Repositories;
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages;
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Net.WebSockets;
using System.Threading.Tasks;
namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
@@ -26,7 +24,7 @@ namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
this.communicationManager = communicationManager;
}
public async Task Handle(WebSocket socket, string json, string userName)
public async Task Handle(string json, string userName)
{
var request = JsonConvert.DeserializeObject<JoinByCode>(json);
var joinGameResponse = await repository.PostJoinPrivateSession(new PostJoinPrivateSession
@@ -37,37 +35,32 @@ namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
if (joinGameResponse.JoinSucceeded)
{
var gameName = (await repository.GetGame(joinGameResponse.SessionName)).Session.Name;
// Other members of the game see a regular JoinGame occur.
var response = new JoinGameResponse(ClientAction.JoinGame)
{
PlayerName = userName,
GameName = gameName
GameName = joinGameResponse.SessionName
};
// At this time, userName hasn't subscribed and won't receive this broadcasted messages.
await communicationManager.BroadcastToGame(gameName, response);
// At this time, userName hasn't subscribed and won't receive this message.
await communicationManager.BroadcastToGame(joinGameResponse.SessionName, response);
// But the player joining sees the JoinByCode occur.
// The player joining sees the JoinByCode occur.
response = new JoinGameResponse(ClientAction.JoinByCode)
{
PlayerName = userName,
GameName = gameName
GameName = joinGameResponse.SessionName
};
var serialized = JsonConvert.SerializeObject(response);
logger.LogInformation("Response to {0} \n{1}\n", userName, serialized);
await socket.SendTextAsync(serialized);
await communicationManager.BroadcastToPlayers(response, userName);
}
else
{
var response = new JoinGameResponse(ClientAction.JoinByCode)
{
PlayerName = userName,
GameName = joinGameResponse.SessionName,
Error = "Error joining game."
};
var serialized = JsonConvert.SerializeObject(response);
logger.LogInformation("Response to {0} \n{1}\n", userName, serialized);
await socket.SendTextAsync(serialized);
await communicationManager.BroadcastToPlayers(response, userName);
}
}
}