diff --git a/Gameboard.ShogiUI.Sockets.ServiceModels/Gameboard.ShogiUI.Sockets.ServiceModels.csproj b/Gameboard.ShogiUI.Sockets.ServiceModels/Gameboard.ShogiUI.Sockets.ServiceModels.csproj
index cb63190..f208d30 100644
--- a/Gameboard.ShogiUI.Sockets.ServiceModels/Gameboard.ShogiUI.Sockets.ServiceModels.csproj
+++ b/Gameboard.ShogiUI.Sockets.ServiceModels/Gameboard.ShogiUI.Sockets.ServiceModels.csproj
@@ -1,7 +1,7 @@
- netcoreapp3.1
+ net5.0
diff --git a/Gameboard.ShogiUI.Sockets/Gameboard.ShogiUI.Sockets.csproj b/Gameboard.ShogiUI.Sockets/Gameboard.ShogiUI.Sockets.csproj
index e12061c..20be479 100644
--- a/Gameboard.ShogiUI.Sockets/Gameboard.ShogiUI.Sockets.csproj
+++ b/Gameboard.ShogiUI.Sockets/Gameboard.ShogiUI.Sockets.csproj
@@ -1,16 +1,16 @@
-
+
- netcoreapp3.1
+ net5.0
-
-
-
-
-
-
+
+
+
+
+
+
@@ -18,8 +18,8 @@
-
-
+
+
diff --git a/Gameboard.ShogiUI.Sockets/Managers/ClientActionHandlers/CreateGameHandler.cs b/Gameboard.ShogiUI.Sockets/Managers/ClientActionHandlers/CreateGameHandler.cs
index f8e5fc0..07e29dd 100644
--- a/Gameboard.ShogiUI.Sockets/Managers/ClientActionHandlers/CreateGameHandler.cs
+++ b/Gameboard.ShogiUI.Sockets/Managers/ClientActionHandlers/CreateGameHandler.cs
@@ -30,9 +30,9 @@ namespace Websockets.Managers.ClientActionHandlers
{
logger.LogInformation("Socket Request \n{0}\n", new[] { json });
var request = JsonConvert.DeserializeObject(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.";
}
diff --git a/Gameboard.ShogiUI.Sockets/Managers/ClientActionHandlers/JoinByCodeHandler.cs b/Gameboard.ShogiUI.Sockets/Managers/ClientActionHandlers/JoinByCodeHandler.cs
index 56cedf1..4880007 100644
--- a/Gameboard.ShogiUI.Sockets/Managers/ClientActionHandlers/JoinByCodeHandler.cs
+++ b/Gameboard.ShogiUI.Sockets/Managers/ClientActionHandlers/JoinByCodeHandler.cs
@@ -30,7 +30,7 @@ namespace Websockets.Managers.ClientActionHandlers
{
logger.LogInformation("Socket Request \n{0}\n", new[] { json });
var request = JsonConvert.DeserializeObject(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)
diff --git a/Gameboard.ShogiUI.Sockets/Managers/ClientActionHandlers/JoinGameHandler.cs b/Gameboard.ShogiUI.Sockets/Managers/ClientActionHandlers/JoinGameHandler.cs
index 6fd209e..45b6e64 100644
--- a/Gameboard.ShogiUI.Sockets/Managers/ClientActionHandlers/JoinGameHandler.cs
+++ b/Gameboard.ShogiUI.Sockets/Managers/ClientActionHandlers/JoinGameHandler.cs
@@ -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
});
diff --git a/Gameboard.ShogiUI.Sockets/Managers/ClientActionHandlers/ListGamesHandler.cs b/Gameboard.ShogiUI.Sockets/Managers/ClientActionHandlers/ListGamesHandler.cs
index 3957910..de7361b 100644
--- a/Gameboard.ShogiUI.Sockets/Managers/ClientActionHandlers/ListGamesHandler.cs
+++ b/Gameboard.ShogiUI.Sockets/Managers/ClientActionHandlers/ListGamesHandler.cs
@@ -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()
};
var serialized = JsonConvert.SerializeObject(response);
diff --git a/Gameboard.ShogiUI.Sockets/Managers/ClientActionHandlers/LoadGameHandler.cs b/Gameboard.ShogiUI.Sockets/Managers/ClientActionHandlers/LoadGameHandler.cs
index 6eb674c..39c750c 100644
--- a/Gameboard.ShogiUI.Sockets/Managers/ClientActionHandlers/LoadGameHandler.cs
+++ b/Gameboard.ShogiUI.Sockets/Managers/ClientActionHandlers/LoadGameHandler.cs
@@ -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);
diff --git a/Gameboard.ShogiUI.Sockets/Managers/ClientActionHandlers/MoveHandler.cs b/Gameboard.ShogiUI.Sockets/Managers/ClientActionHandlers/MoveHandler.cs
index 13759b4..a5f8a78 100644
--- a/Gameboard.ShogiUI.Sockets/Managers/ClientActionHandlers/MoveHandler.cs
+++ b/Gameboard.ShogiUI.Sockets/Managers/ClientActionHandlers/MoveHandler.cs
@@ -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)
{
diff --git a/Gameboard.ShogiUI.Sockets/Properties/launchSettings.json b/Gameboard.ShogiUI.Sockets/Properties/launchSettings.json
index 9d79795..20f6c84 100644
--- a/Gameboard.ShogiUI.Sockets/Properties/launchSettings.json
+++ b/Gameboard.ShogiUI.Sockets/Properties/launchSettings.json
@@ -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"
}
}
-}
+}
\ No newline at end of file
diff --git a/Gameboard.ShogiUI.Sockets/Repositories/GameboardRepository.cs b/Gameboard.ShogiUI.Sockets/Repositories/GameboardRepository.cs
index 72f318b..a31e313 100644
--- a/Gameboard.ShogiUI.Sockets/Repositories/GameboardRepository.cs
+++ b/Gameboard.ShogiUI.Sockets/Repositories/GameboardRepository.cs
@@ -11,13 +11,13 @@ namespace Websockets.Repositories
public interface IGameboardRepository
{
Task DeleteGame(string gameName);
- Task GetGame(string gameName);
- Task GetGames();
- Task GetGames(string playerName);
+ Task GetGame(string gameName);
+ Task GetGames();
+ Task GetGames(string playerName);
Task GetMoves(string gameName);
- Task PostGame(PostGame request);
- Task PostJoinByCode(PostJoinByCode request);
- Task PostJoinGame(string gameName, PostJoinGame request);
+ Task PostSession(PostSession request);
+ Task PostJoinPrivateSession(PostJoinPrivateSession request);
+ Task PutJoinPublicSession(string gameName, PutJoinPublicSession request);
Task PostMove(string gameName, PostMove request);
Task PostJoinCode(string gameName, string userName);
Task GetPlayer(string userName);
@@ -32,63 +32,63 @@ namespace Websockets.Repositories
this.client = client;
}
- public async Task GetGames()
+ public async Task GetGames()
{
- var response = await client.GetAsync("Games");
+ var response = await client.GetAsync("Sessions");
var json = await response.Content.ReadAsStringAsync();
- return JsonConvert.DeserializeObject(json);
+ return JsonConvert.DeserializeObject(json);
}
- public async Task GetGames(string playerName)
+ public async Task 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(json);
+ return JsonConvert.DeserializeObject(json);
}
- public async Task GetGame(string gameName)
+ public async Task 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(json);
+ return JsonConvert.DeserializeObject(json);
}
public async Task DeleteGame(string gameName)
{
- var uri = $"Game/{gameName}";
+ var uri = $"Session/{gameName}";
await client.DeleteAsync(Uri.EscapeUriString(uri));
}
- public async Task PostGame(PostGame request)
+ public async Task 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(json);
+ return JsonConvert.DeserializeObject(json);
}
- public async Task PostJoinGame(string gameName, PostJoinGame request)
+ public async Task 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(json);
+ return JsonConvert.DeserializeObject(json);
}
- public async Task PostJoinByCode(PostJoinByCode request)
+ public async Task 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(json);
+ return JsonConvert.DeserializeObject(json);
}
public async Task 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(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);
}
diff --git a/Gameboard.ShogiUI.Sockets/Repositories/PlayerRepository.cs b/Gameboard.ShogiUI.Sockets/Repositories/PlayerRepository.cs
deleted file mode 100644
index 843f9e0..0000000
--- a/Gameboard.ShogiUI.Sockets/Repositories/PlayerRepository.cs
+++ /dev/null
@@ -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 GetPlayer(string playerName)
- {
- var response = await client.GetAsync($"/Player/{playerName}");
- var json = await response.Content.ReadAsStringAsync();
- return JsonConvert.DeserializeObject(json);
- }
-
- public async Task DeletePlayer(string playerName)
- {
- var response = await client.DeleteAsync($"/Player/{playerName}");
- await response.Content.ReadAsStringAsync();
- }
- }
-}
diff --git a/Gameboard.ShogiUI.Sockets/Repositories/Utility/AuthenticatedHttpClient.cs b/Gameboard.ShogiUI.Sockets/Repositories/Utility/AuthenticatedHttpClient.cs
index 62e066f..cd50a1a 100644
--- a/Gameboard.ShogiUI.Sockets/Repositories/Utility/AuthenticatedHttpClient.cs
+++ b/Gameboard.ShogiUI.Sockets/Repositories/Utility/AuthenticatedHttpClient.cs
@@ -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;
diff --git a/Gameboard.ShogiUI.Sockets/Startup.cs b/Gameboard.ShogiUI.Sockets/Startup.cs
index ba57a9f..ecb5f8d 100644
--- a/Gameboard.ShogiUI.Sockets/Startup.cs
+++ b/Gameboard.ShogiUI.Sockets/Startup.cs
@@ -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);
diff --git a/Gameboard.ShogiUI.Sockets/appsettings.json b/Gameboard.ShogiUI.Sockets/appsettings.json
index 48c43bd..1b50ee6 100644
--- a/Gameboard.ShogiUI.Sockets/appsettings.json
+++ b/Gameboard.ShogiUI.Sockets/appsettings.json
@@ -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"
diff --git a/nuget.config b/nuget.config
index 346522c..f0276c3 100644
--- a/nuget.config
+++ b/nuget.config
@@ -3,5 +3,6 @@
+
\ No newline at end of file