Upgrade to .net 5

Address breaking changes from Shogi.API nuget
This commit is contained in:
2021-01-23 18:11:19 -06:00
parent 1bbab8fe8f
commit 2c8e692d38
15 changed files with 71 additions and 99 deletions

View File

@@ -30,9 +30,9 @@ namespace Websockets.Managers.ClientActionHandlers
{
logger.LogInformation("Socket Request \n{0}\n", new[] { json });
var request = JsonConvert.DeserializeObject<CreateGameRequest>(json);
var postGameResponse = await repository.PostGame(new PostGame
var postSessionResponse = await repository.PostSession(new PostSession
{
GameName = request.GameName,
SessionName = request.GameName,
PlayerName = userName, // TODO : Investigate if needed by UI
IsPrivate = request.IsPrivate
});
@@ -42,12 +42,12 @@ namespace Websockets.Managers.ClientActionHandlers
PlayerName = userName,
Game = new Game
{
GameName = postGameResponse.GameName,
GameName = postSessionResponse.SessionName,
Players = new string[] { userName }
}
};
if (string.IsNullOrWhiteSpace(postGameResponse.GameName))
if (string.IsNullOrWhiteSpace(postSessionResponse.SessionName))
{
response.Error = "Game already exists.";
}

View File

@@ -30,7 +30,7 @@ namespace Websockets.Managers.ClientActionHandlers
{
logger.LogInformation("Socket Request \n{0}\n", new[] { json });
var request = JsonConvert.DeserializeObject<JoinByCode>(json);
var joinGameResponse = await repository.PostJoinByCode(new PostJoinByCode
var joinGameResponse = await repository.PostJoinPrivateSession(new PostJoinPrivateSession
{
PlayerName = userName,
JoinCode = request.JoinCode
@@ -38,7 +38,7 @@ namespace Websockets.Managers.ClientActionHandlers
if (joinGameResponse.JoinSucceeded)
{
var gameName = (await repository.GetGame(joinGameResponse.GameName)).GameName;
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)

View File

@@ -33,7 +33,7 @@ namespace Websockets.Managers.ClientActionHandlers
PlayerName = userName
};
var joinGameResponse = await gameboardRepository.PostJoinGame(request.GameName, new PostJoinGame
var joinGameResponse = await gameboardRepository.PutJoinPublicSession(request.GameName, new PutJoinPublicSession
{
PlayerName = userName
});

View File

@@ -1,6 +1,7 @@
using AspShogiSockets.Extensions;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.Linq;
using System.Net.WebSockets;
using System.Threading.Tasks;
@@ -31,16 +32,16 @@ namespace Websockets.Managers.ClientActionHandlers
? await repository.GetGames()
: await repository.GetGames(userName);
var games = getGamesResponse.Games
.OrderBy(g => g.Players.Contains(userName))
.Select(g => new Game
var games = getGamesResponse.Sessions
.OrderBy(s => s.Player1 == userName || s.Player2 == userName)
.Select(s => new Game
{
GameName = g.GameName,
Players = g.Players
GameName = s.Name,
Players = new[] { s.Player1, s.Player2 }
});
var response = new ListGamesResponse(ClientAction.ListGames)
{
Games = games ?? new Game[0]
Games = games ?? Array.Empty<Game>()
};
var serialized = JsonConvert.SerializeObject(response);

View File

@@ -41,18 +41,18 @@ namespace Websockets.Managers.ClientActionHandlers
}
else
{
var player1 = getGameResponse.Players[0];
var session = getGameResponse.Session;
response.Game = new Game
{
GameName = getGameResponse.GameName,
Players = getGameResponse.Players
GameName = session.Name,
Players = new[] { session.Player1, session.Player2 }
};
response.Moves = userName.Equals(player1)
response.Moves = userName.Equals(session.Player1)
? getMovesResponse.Moves.Select(_ => Mapper.Map(_))
: getMovesResponse.Moves.Select(_ => Move.ConvertPerspective(Mapper.Map(_)));
communicationManager.SubscribeToGame(socket, getGameResponse.GameName, userName);
communicationManager.SubscribeToGame(socket, session.Name, userName);
}
var serialized = JsonConvert.SerializeObject(response);

View File

@@ -43,17 +43,15 @@ namespace Websockets.Managers.ClientActionHandlers
return;
}
var getGameResponse = await gameboardRepository.GetGame(request.GameName);
var isPlayer1 = userName.Equals(getGameResponse.Players[0]);
var getSessionResponse = await gameboardRepository.GetGame(request.GameName);
var isPlayer1 = userName == getSessionResponse.Session.Player1;
if (!isPlayer1)
{
// Convert the move coords to player1 perspective.
move = Move.ConvertPerspective(move);
}
await gameboardRepository.PostMove(
request.GameName,
new PostMove { Move = Mapper.Map(move) });
await gameboardRepository.PostMove(request.GameName, new PostMove(Mapper.Map(move)));
var response = new MoveResponse(ClientAction.Move)
{