Fixed accidentally building the board from player2 perspective.
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
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.Threading.Tasks;
|
||||
|
||||
@@ -10,16 +9,13 @@ namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
|
||||
{
|
||||
public class JoinByCodeHandler : IActionHandler
|
||||
{
|
||||
private readonly ILogger<JoinByCodeHandler> logger;
|
||||
private readonly IGameboardRepository repository;
|
||||
private readonly ISocketCommunicationManager communicationManager;
|
||||
|
||||
public JoinByCodeHandler(
|
||||
ILogger<JoinByCodeHandler> logger,
|
||||
ISocketCommunicationManager communicationManager,
|
||||
IGameboardRepository repository)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.repository = repository;
|
||||
this.communicationManager = communicationManager;
|
||||
}
|
||||
@@ -27,38 +23,38 @@ namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
|
||||
public async Task Handle(string json, string userName)
|
||||
{
|
||||
var request = JsonConvert.DeserializeObject<JoinByCode>(json);
|
||||
var joinGameResponse = await repository.PostJoinPrivateSession(new PostJoinPrivateSession
|
||||
var sessionName = await repository.PostJoinPrivateSession(new PostJoinPrivateSession
|
||||
{
|
||||
PlayerName = userName,
|
||||
JoinCode = request.JoinCode
|
||||
});
|
||||
|
||||
if (joinGameResponse.JoinSucceeded)
|
||||
if (sessionName == null)
|
||||
{
|
||||
// Other members of the game see a regular JoinGame occur.
|
||||
var response = new JoinGameResponse(ClientAction.JoinGame)
|
||||
var response = new JoinGameResponse(ClientAction.JoinByCode)
|
||||
{
|
||||
PlayerName = userName,
|
||||
GameName = joinGameResponse.SessionName
|
||||
};
|
||||
// At this time, userName hasn't subscribed and won't receive this message.
|
||||
await communicationManager.BroadcastToGame(joinGameResponse.SessionName, response);
|
||||
|
||||
// The player joining sees the JoinByCode occur.
|
||||
response = new JoinGameResponse(ClientAction.JoinByCode)
|
||||
{
|
||||
PlayerName = userName,
|
||||
GameName = joinGameResponse.SessionName
|
||||
GameName = sessionName,
|
||||
Error = "Error joining game."
|
||||
};
|
||||
await communicationManager.BroadcastToPlayers(response, userName);
|
||||
}
|
||||
else
|
||||
{
|
||||
var response = new JoinGameResponse(ClientAction.JoinByCode)
|
||||
// Other members of the game see a regular JoinGame occur.
|
||||
var response = new JoinGameResponse(ClientAction.JoinGame)
|
||||
{
|
||||
PlayerName = userName,
|
||||
GameName = joinGameResponse.SessionName,
|
||||
Error = "Error joining game."
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user