checkpoint
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using Gameboard.ShogiUI.Sockets.Extensions;
|
||||
using Gameboard.ShogiUI.Sockets.Managers;
|
||||
using Gameboard.ShogiUI.Sockets.Managers;
|
||||
using Gameboard.ShogiUI.Sockets.Repositories;
|
||||
using Gameboard.ShogiUI.Sockets.ServiceModels.Api;
|
||||
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket;
|
||||
@@ -7,10 +6,8 @@ using Gameboard.ShogiUI.Sockets.ServiceModels.Types;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Gameboard.ShogiUI.Sockets.Controllers
|
||||
@@ -169,25 +166,48 @@ namespace Gameboard.ShogiUI.Sockets.Controllers
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var playerPerspective = WhichPerspective.Spectator;
|
||||
if (session.Player1.Id == user.Id)
|
||||
{
|
||||
playerPerspective = WhichPerspective.Player1;
|
||||
}
|
||||
else if (session.Player2?.Id == user.Id)
|
||||
{
|
||||
playerPerspective = WhichPerspective.Player2;
|
||||
}
|
||||
var playerPerspective = session.Player2Name == user.Id
|
||||
? WhichPlayer.Player2
|
||||
: WhichPlayer.Player1;
|
||||
|
||||
communicationManager.SubscribeToGame(session, user!.Id);
|
||||
var response = new GetSessionResponse()
|
||||
var response = new Session
|
||||
{
|
||||
Game = new Models.SessionMetadata(session).ToServiceModel(),
|
||||
BoardState = session.Shogi.ToServiceModel(),
|
||||
MoveHistory = session.Shogi.MoveHistory.Select(_ => _.ToServiceModel()).ToList(),
|
||||
PlayerPerspective = playerPerspective
|
||||
BoardState = new BoardState
|
||||
{
|
||||
Board = null,
|
||||
Player1Hand = session.Player1Hand.Select(MapPiece).ToList(),
|
||||
Player2Hand = session.Player2Hand.Select(MapPiece).ToList(),
|
||||
PlayerInCheck = session.InCheck.HasValue ? Map(session.InCheck.Value) : null
|
||||
},
|
||||
GameName = session.Name,
|
||||
Player1 = session.Player1Name,
|
||||
Player2 = session.Player2Name
|
||||
};
|
||||
return new JsonResult(response);
|
||||
return this.Ok(response);
|
||||
|
||||
static WhichPlayer Map(Shogi.Domain.WhichPlayer whichPlayer)
|
||||
{
|
||||
return whichPlayer == Shogi.Domain.WhichPlayer.Player1
|
||||
? WhichPlayer.Player1
|
||||
: WhichPlayer.Player2;
|
||||
}
|
||||
static Piece MapPiece(Shogi.Domain.Pieces.Piece piece)
|
||||
{
|
||||
var owner = Map(piece.Owner);
|
||||
var whichPiece = piece.WhichPiece switch
|
||||
{
|
||||
Shogi.Domain.WhichPiece.King => WhichPiece.King,
|
||||
Shogi.Domain.WhichPiece.GoldGeneral => WhichPiece.GoldGeneral,
|
||||
Shogi.Domain.WhichPiece.SilverGeneral => WhichPiece.SilverGeneral,
|
||||
Shogi.Domain.WhichPiece.Bishop => WhichPiece.Bishop,
|
||||
Shogi.Domain.WhichPiece.Rook => WhichPiece.Rook,
|
||||
Shogi.Domain.WhichPiece.Knight => WhichPiece.Knight,
|
||||
Shogi.Domain.WhichPiece.Lance => WhichPiece.Lance,
|
||||
Shogi.Domain.WhichPiece.Pawn => WhichPiece.Pawn,
|
||||
_ => throw new ArgumentException($"Unknown value for {nameof(WhichPiece)}")
|
||||
};
|
||||
return new Piece { IsPromoted = piece.IsPromoted, Owner = owner, WhichPiece = whichPiece };
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@@ -207,8 +227,8 @@ namespace Gameboard.ShogiUI.Sockets.Controllers
|
||||
|
||||
return new GetSessionsResponse
|
||||
{
|
||||
PlayerHasJoinedSessions = new Collection<Game>(sessionsJoinedByUser),
|
||||
AllOtherSessions = new Collection<Game>(sessionsNotJoinedByUser)
|
||||
PlayerHasJoinedSessions = new Collection<Session>(sessionsJoinedByUser),
|
||||
AllOtherSessions = new Collection<Session>(sessionsNotJoinedByUser)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Gameboard.ShogiUI.Sockets.Extensions;
|
||||
using Gameboard.ShogiUI.Sockets.Managers;
|
||||
using Gameboard.ShogiUI.Sockets.Models;
|
||||
using Gameboard.ShogiUI.Sockets.Repositories;
|
||||
using Gameboard.ShogiUI.Sockets.ServiceModels.Api;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
@@ -56,7 +55,7 @@ namespace Gameboard.ShogiUI.Sockets.Controllers
|
||||
var userId = User?.UserId();
|
||||
if (!string.IsNullOrEmpty(userId))
|
||||
{
|
||||
connectionManager.UnsubscribeFromBroadcastAndGames(userId);
|
||||
connectionManager.Unsubscribe(userId);
|
||||
}
|
||||
|
||||
await signoutTask;
|
||||
|
||||
Reference in New Issue
Block a user