Merged in master (pull request #38)

Upgrade to .net 5
This commit is contained in:
2021-01-24 00:56:31 +00:00
15 changed files with 71 additions and 99 deletions

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>

View File

@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Gameboard.Shogi.Api.ServiceModels" Version="1.0.8" />
<PackageReference Include="IdentityModel" Version="4.4.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.AzureAD.UI" Version="3.1.8" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.8" />
<PackageReference Include="Microsoft.Identity.Web" Version="1.0.0" />
<PackageReference Include="Microsoft.Identity.Web.MicrosoftGraph" Version="1.0.0" />
<PackageReference Include="Gameboard.Shogi.Api.ServiceModels" Version="2.4.0" />
<PackageReference Include="IdentityModel" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.AzureAD.UI" Version="5.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.2" />
<PackageReference Include="Microsoft.Identity.Web" Version="1.5.1" />
<PackageReference Include="Microsoft.Identity.Web.MicrosoftGraph" Version="1.5.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>

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)
{

View File

@@ -18,12 +18,11 @@
},
"AspShogiSockets": {
"commandName": "Project",
"launchBrowser": false,
"launchUrl": "Socket/Token",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://127.0.0.1:5101"
"applicationUrl": "http://127.0.0.1:5100"
}
}
}

View File

@@ -11,13 +11,13 @@ namespace Websockets.Repositories
public interface IGameboardRepository
{
Task DeleteGame(string gameName);
Task<GetGameResponse> GetGame(string gameName);
Task<GetGamesResponse> GetGames();
Task<GetGamesResponse> GetGames(string playerName);
Task<GetSessionResponse> GetGame(string gameName);
Task<GetSessionsResponse> GetGames();
Task<GetSessionsResponse> GetGames(string playerName);
Task<GetMovesResponse> GetMoves(string gameName);
Task<PostGameResponse> PostGame(PostGame request);
Task<PostJoinByCodeResponse> PostJoinByCode(PostJoinByCode request);
Task<PostJoinGameResponse> PostJoinGame(string gameName, PostJoinGame request);
Task<PostSessionResponse> PostSession(PostSession request);
Task<PostJoinPrivateSessionResponse> PostJoinPrivateSession(PostJoinPrivateSession request);
Task<PutJoinPublicSessionResponse> PutJoinPublicSession(string gameName, PutJoinPublicSession request);
Task PostMove(string gameName, PostMove request);
Task<PostJoinCodeResponse> PostJoinCode(string gameName, string userName);
Task<GetPlayerResponse> GetPlayer(string userName);
@@ -32,63 +32,63 @@ namespace Websockets.Repositories
this.client = client;
}
public async Task<GetGamesResponse> GetGames()
public async Task<GetSessionsResponse> GetGames()
{
var response = await client.GetAsync("Games");
var response = await client.GetAsync("Sessions");
var json = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<GetGamesResponse>(json);
return JsonConvert.DeserializeObject<GetSessionsResponse>(json);
}
public async Task<GetGamesResponse> GetGames(string playerName)
public async Task<GetSessionsResponse> GetGames(string playerName)
{
var uri = $"Games/{playerName}";
var uri = $"Sessions/{playerName}";
var response = await client.GetAsync(Uri.EscapeUriString(uri));
var json = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<GetGamesResponse>(json);
return JsonConvert.DeserializeObject<GetSessionsResponse>(json);
}
public async Task<GetGameResponse> GetGame(string gameName)
public async Task<GetSessionResponse> GetGame(string gameName)
{
var uri = $"Game/{gameName}";
var uri = $"Session/{gameName}";
var response = await client.GetAsync(Uri.EscapeUriString(uri));
var json = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<GetGameResponse>(json);
return JsonConvert.DeserializeObject<GetSessionResponse>(json);
}
public async Task DeleteGame(string gameName)
{
var uri = $"Game/{gameName}";
var uri = $"Session/{gameName}";
await client.DeleteAsync(Uri.EscapeUriString(uri));
}
public async Task<PostGameResponse> PostGame(PostGame request)
public async Task<PostSessionResponse> PostSession(PostSession request)
{
var content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json");
var response = await client.PostAsync("Game", content);
var response = await client.PostAsync("Session", content);
var json = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<PostGameResponse>(json);
return JsonConvert.DeserializeObject<PostSessionResponse>(json);
}
public async Task<PostJoinGameResponse> PostJoinGame(string gameName, PostJoinGame request)
public async Task<PutJoinPublicSessionResponse> PutJoinPublicSession(string gameName, PutJoinPublicSession request)
{
var uri = $"Game/{gameName}/Join";
var uri = $"Session/{gameName}/Join";
var content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json");
var response = await client.PostAsync(Uri.EscapeUriString(uri), content);
var json = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<PostJoinGameResponse>(json);
return JsonConvert.DeserializeObject<PutJoinPublicSessionResponse>(json);
}
public async Task<PostJoinByCodeResponse> PostJoinByCode(PostJoinByCode request)
public async Task<PostJoinPrivateSessionResponse> PostJoinPrivateSession(PostJoinPrivateSession request)
{
var content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json");
var response = await client.PostAsync("Game/Join", content);
var response = await client.PostAsync("Session/Join", content);
var json = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<PostJoinByCodeResponse>(json);
return JsonConvert.DeserializeObject<PostJoinPrivateSessionResponse>(json);
}
public async Task<GetMovesResponse> GetMoves(string gameName)
{
var uri = $"Game/{gameName}/Moves";
var uri = $"Session/{gameName}/Moves";
var response = await client.GetAsync(Uri.EscapeUriString(uri));
var json = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<GetMovesResponse>(json);
@@ -96,7 +96,7 @@ namespace Websockets.Repositories
public async Task PostMove(string gameName, PostMove request)
{
var uri = $"Game/{gameName}/Move";
var uri = $"Session/{gameName}/Move";
var content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json");
await client.PostAsync(Uri.EscapeUriString(uri), content);
}

View File

@@ -1,32 +0,0 @@
using Gameboard.Shogi.Api.ServiceModels.Messages;
using Newtonsoft.Json;
using System;
using System.Threading.Tasks;
using Websockets.Repositories.Utility;
namespace Websockets.Repositories
{
[Obsolete("Use GameboardRepository. Functions from PlayerRepository will be moved.")]
public class PlayerRepository
{
private readonly IAuthenticatedHttpClient client;
public PlayerRepository(IAuthenticatedHttpClient client)
{
this.client = client;
}
public async Task<GetPlayerResponse> GetPlayer(string playerName)
{
var response = await client.GetAsync($"/Player/{playerName}");
var json = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<GetPlayerResponse>(json);
}
public async Task DeletePlayer(string playerName)
{
var response = await client.DeleteAsync($"/Player/{playerName}");
await response.Content.ReadAsStringAsync();
}
}
}

View File

@@ -81,9 +81,10 @@ namespace Websockets.Repositories.Utility
response = await base.PostAsync(requestUri, content);
}
logger.LogInformation(
"Repository POST to {BaseUrl}{RequestUrl} \nRequest: {Request}\nResponse: {Response}\n",
"Repository POST to {BaseUrl}{RequestUrl} \n\tRespCode: {RespCode} \n\tRequest: {Request}\n\tResponse: {Response}\n",
BaseAddress,
requestUri,
response.StatusCode,
await content.ReadAsStringAsync(),
await response.Content.ReadAsStringAsync());
return response;

View File

@@ -83,7 +83,11 @@ namespace Websockets
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ISocketConnectionManager socketConnectionManager)
{
var origins = new[] { "https://localhost:3000", "https://dev.lucaserver.space", "https://lucaserver.space" };
var origins = new[] {
"http://localhost:3000", "https://localhost:3000",
"http://127.0.0.1:3000", "https://127.0.0.1:3000",
"https://dev.lucaserver.space", "https://lucaserver.space"
};
var socketOptions = new WebSocketOptions();
foreach (var o in origins)
socketOptions.AllowedOrigins.Add(o);

View File

@@ -1,7 +1,7 @@
{
"AppSettings": {
"IdentityServer": "https://identity.lucaserver.space/",
"GameboardShogiApi": "https://api.lucaserver.space/Gameboard.Shogi.Api/",
"GameboardShogiApi": "https://dev.lucaserver.space/Gameboard.Shogi.Api/",
"ClientId": "DevClientId",
"ClientSecret": "DevSecret",
"Scope": "DevEnvironment"

View File

@@ -3,5 +3,6 @@
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="Gameboard.Shogi.Api" value="https://pkgs.dev.azure.com/hauth/GameBoard/_packaging/Gameboard.Shogi.Api/nuget/v3/index.json" />
<add key="Dev-Gameboard.Shogi.Api" value="https://pkgs.dev.azure.com/hauth/GameBoard/_packaging/Dev-Gameboard.Shogi.Api/nuget/v3/index.json" />
</packageSources>
</configuration>