namespaces and guest game invitations
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace AspShogiSockets.ServiceModels.Api.Messages
|
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Api.Messages
|
||||||
{
|
{
|
||||||
public class GetGuestToken
|
public class GetGuestToken
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Websockets.ServiceModels
|
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Api.Messages
|
||||||
{
|
{
|
||||||
public class GetTokenResponse
|
public class GetTokenResponse
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
namespace AspShogiSockets.ServiceModels.Api.Messages
|
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Api.Messages
|
||||||
{
|
{
|
||||||
public class PostGameInvitation
|
public class PostGameInvitation
|
||||||
{
|
{
|
||||||
public string SessionName { get; set; }
|
public string SessionName { get; set; }
|
||||||
}
|
}
|
||||||
|
public class PostGuestGameInvitation
|
||||||
|
{
|
||||||
|
public string GuestId { get; set; }
|
||||||
|
public string SessionName { get; set; }
|
||||||
|
}
|
||||||
public class PostGameInvitationResponse
|
public class PostGameInvitationResponse
|
||||||
{
|
{
|
||||||
public string Code { get; }
|
public string Code { get; }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using Websockets.ServiceModels.Types;
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||||
|
|
||||||
namespace Websockets.ServiceModels.Interfaces
|
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Interfaces
|
||||||
{
|
{
|
||||||
public interface IRequest
|
public interface IRequest
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Websockets.ServiceModels.Interfaces
|
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Interfaces
|
||||||
{
|
{
|
||||||
public interface IResponse
|
public interface IResponse
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Websockets.ServiceModels.Interfaces;
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Interfaces;
|
||||||
using Websockets.ServiceModels.Types;
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||||
|
|
||||||
namespace Websockets.ServiceModels.Messages
|
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages
|
||||||
{
|
{
|
||||||
public class CreateGameRequest : IRequest
|
public class CreateGameRequest : IRequest
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Websockets.ServiceModels.Interfaces;
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Interfaces;
|
||||||
using Websockets.ServiceModels.Types;
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||||
|
|
||||||
namespace Websockets.ServiceModels.Messages
|
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages
|
||||||
{
|
{
|
||||||
public class ErrorResponse : IResponse
|
public class ErrorResponse : IResponse
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Websockets.ServiceModels.Interfaces;
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Interfaces;
|
||||||
using Websockets.ServiceModels.Types;
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||||
|
|
||||||
namespace Websockets.ServiceModels.Messages
|
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages
|
||||||
{
|
{
|
||||||
public class JoinByCode : IRequest
|
public class JoinByCode : IRequest
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Websockets.ServiceModels.Interfaces;
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Interfaces;
|
||||||
using Websockets.ServiceModels.Types;
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||||
|
|
||||||
namespace Websockets.ServiceModels.Messages
|
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages
|
||||||
{
|
{
|
||||||
public class JoinGameRequest : IRequest
|
public class JoinGameRequest : IRequest
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
using System.Collections.Generic;
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Interfaces;
|
||||||
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
using Websockets.ServiceModels.Interfaces;
|
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages
|
||||||
using Websockets.ServiceModels.Types;
|
|
||||||
|
|
||||||
namespace Websockets.ServiceModels.Messages
|
|
||||||
{
|
{
|
||||||
public class ListGamesRequest : IRequest
|
public class ListGamesRequest : IRequest
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using System.Collections.Generic;
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Interfaces;
|
||||||
using Websockets.ServiceModels.Interfaces;
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||||
using Websockets.ServiceModels.Types;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Websockets.ServiceModels.Messages
|
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages
|
||||||
{
|
{
|
||||||
public class LoadGameRequest : IRequest
|
public class LoadGameRequest : IRequest
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Websockets.ServiceModels.Interfaces;
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Interfaces;
|
||||||
using Websockets.ServiceModels.Types;
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||||
|
|
||||||
namespace Websockets.ServiceModels.Messages
|
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages
|
||||||
{
|
{
|
||||||
public class MoveRequest : IRequest
|
public class MoveRequest : IRequest
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Websockets.ServiceModels.Types
|
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types
|
||||||
{
|
{
|
||||||
public enum ClientAction
|
public enum ClientAction
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Websockets.ServiceModels.Types
|
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types
|
||||||
{
|
{
|
||||||
public class Coords
|
public class Coords
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Websockets.ServiceModels.Types
|
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types
|
||||||
{
|
{
|
||||||
public class Game
|
public class Game
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Websockets.ServiceModels.Types
|
namespace Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types
|
||||||
{
|
{
|
||||||
public class Move
|
public class Move
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,30 +1,61 @@
|
|||||||
using AspShogiSockets.ServiceModels.Api.Messages;
|
using Gameboard.ShogiUI.Sockets.Repositories;
|
||||||
|
using Gameboard.ShogiUI.Sockets.Repositories.RepositoryManagers;
|
||||||
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Api.Messages;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Websockets.Repositories;
|
|
||||||
|
|
||||||
namespace AspShogiSockets.Controllers
|
namespace Gameboard.ShogiUI.Sockets.Controllers
|
||||||
{
|
{
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("[controller]")]
|
[Route("[controller]")]
|
||||||
public class GameController : ControllerBase
|
public class GameController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly IGameboardRepository gameboardRepository;
|
private readonly IGameboardRepositoryManager manager;
|
||||||
|
private readonly IGameboardRepository repository;
|
||||||
|
|
||||||
public GameController(IGameboardRepository gameboardRepository)
|
public GameController(
|
||||||
|
IGameboardRepository repository,
|
||||||
|
IGameboardRepositoryManager manager)
|
||||||
{
|
{
|
||||||
this.gameboardRepository = gameboardRepository;
|
this.manager = manager;
|
||||||
|
this.repository = repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("JoinCode")]
|
[Route("JoinCode")]
|
||||||
public async Task<IActionResult> PostGameInvitation([FromBody] PostGameInvitation request)
|
public async Task<IActionResult> PostGameInvitation([FromBody] PostGameInvitation request)
|
||||||
{
|
{
|
||||||
var userName = HttpContext.User.Claims.First(c => c.Type == "preferred_username").Value;
|
var userName = HttpContext.User.Claims.First(c => c.Type == "preferred_username").Value;
|
||||||
var code = (await gameboardRepository.PostJoinCode(request.SessionName, userName)).JoinCode;
|
var isPlayer1 = await manager.IsPlayer1(request.SessionName, userName);
|
||||||
|
if (isPlayer1)
|
||||||
|
{
|
||||||
|
var code = (await repository.PostJoinCode(request.SessionName, userName)).JoinCode;
|
||||||
return new CreatedResult("", new PostGameInvitationResponse(code));
|
return new CreatedResult("", new PostGameInvitationResponse(code));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new UnauthorizedResult();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[AllowAnonymous]
|
||||||
|
[Route("GuestJoinCode")]
|
||||||
|
public async Task<IActionResult> PostGuestGameInvitation([FromBody] PostGuestGameInvitation request)
|
||||||
|
{
|
||||||
|
|
||||||
|
var isGuest = manager.IsGuest(request.GuestId);
|
||||||
|
var isPlayer1 = manager.IsPlayer1(request.SessionName, request.GuestId);
|
||||||
|
if (isGuest && await isPlayer1)
|
||||||
|
{
|
||||||
|
var code = (await repository.PostJoinCode(request.SessionName, request.GuestId)).JoinCode;
|
||||||
|
return new CreatedResult("", new PostGameInvitationResponse(code));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new UnauthorizedResult();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
using AspShogiSockets.Repositories.RepositoryManagers;
|
using Gameboard.ShogiUI.Sockets.Managers;
|
||||||
using AspShogiSockets.ServiceModels.Api.Messages;
|
using Gameboard.ShogiUI.Sockets.Repositories;
|
||||||
|
using Gameboard.ShogiUI.Sockets.Repositories.RepositoryManagers;
|
||||||
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Api.Messages;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Websockets.Managers;
|
|
||||||
using Websockets.Repositories;
|
|
||||||
using Websockets.ServiceModels;
|
|
||||||
|
|
||||||
namespace Websockets.Controllers
|
namespace Gameboard.ShogiUI.Sockets.Controllers
|
||||||
{
|
{
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[Route("[controller]")]
|
[Route("[controller]")]
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using System.Text;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AspShogiSockets.Extensions
|
namespace Gameboard.ShogiUI.Sockets.Extensions
|
||||||
{
|
{
|
||||||
public static class WebSocketExtensions
|
public static class WebSocketExtensions
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
<Controller_SelectedScaffolderID>ApiControllerEmptyScaffolder</Controller_SelectedScaffolderID>
|
<Controller_SelectedScaffolderID>ApiControllerEmptyScaffolder</Controller_SelectedScaffolderID>
|
||||||
<Controller_SelectedScaffolderCategoryPath>root/Controller</Controller_SelectedScaffolderCategoryPath>
|
<Controller_SelectedScaffolderCategoryPath>root/Controller</Controller_SelectedScaffolderCategoryPath>
|
||||||
<ActiveDebugProfile>AspShogiSockets</ActiveDebugProfile>
|
<ActiveDebugProfile>AspShogiSockets</ActiveDebugProfile>
|
||||||
|
<ShowAllFiles>false</ShowAllFiles>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
|
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
using AspShogiSockets.Extensions;
|
using Gameboard.Shogi.Api.ServiceModels.Messages;
|
||||||
using Gameboard.Shogi.Api.ServiceModels.Messages;
|
using Gameboard.ShogiUI.Sockets.Extensions;
|
||||||
|
using Gameboard.ShogiUI.Sockets.Repositories;
|
||||||
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages;
|
||||||
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Websockets.Repositories;
|
|
||||||
using Websockets.ServiceModels.Messages;
|
|
||||||
using Websockets.ServiceModels.Types;
|
|
||||||
|
|
||||||
namespace Websockets.Managers.ClientActionHandlers
|
namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
|
||||||
{
|
{
|
||||||
public class CreateGameHandler : IActionHandler
|
public class CreateGameHandler : IActionHandler
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using System.Net.WebSockets;
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||||
|
using System.Net.WebSockets;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Websockets.ServiceModels.Types;
|
|
||||||
|
|
||||||
namespace Websockets.Managers.ClientActionHandlers
|
namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
|
||||||
{
|
{
|
||||||
public interface IActionHandler
|
public interface IActionHandler
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
using AspShogiSockets.Extensions;
|
using Gameboard.Shogi.Api.ServiceModels.Messages;
|
||||||
using Gameboard.Shogi.Api.ServiceModels.Messages;
|
using Gameboard.ShogiUI.Sockets.Extensions;
|
||||||
|
using Gameboard.ShogiUI.Sockets.Repositories;
|
||||||
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages;
|
||||||
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Websockets.Repositories;
|
|
||||||
using Websockets.ServiceModels.Messages;
|
|
||||||
using Websockets.ServiceModels.Types;
|
|
||||||
|
|
||||||
namespace Websockets.Managers.ClientActionHandlers
|
namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
|
||||||
{
|
{
|
||||||
public class JoinByCodeHandler : IActionHandler
|
public class JoinByCodeHandler : IActionHandler
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
using Gameboard.Shogi.Api.ServiceModels.Messages;
|
using Gameboard.Shogi.Api.ServiceModels.Messages;
|
||||||
|
using Gameboard.ShogiUI.Sockets.Repositories;
|
||||||
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages;
|
||||||
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Websockets.Repositories;
|
|
||||||
using Websockets.ServiceModels.Messages;
|
|
||||||
using Websockets.ServiceModels.Types;
|
|
||||||
|
|
||||||
namespace Websockets.Managers.ClientActionHandlers
|
namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
|
||||||
{
|
{
|
||||||
public class JoinGameHandler : IActionHandler
|
public class JoinGameHandler : IActionHandler
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
using AspShogiSockets.Extensions;
|
using Gameboard.ShogiUI.Sockets.Extensions;
|
||||||
|
using Gameboard.ShogiUI.Sockets.Repositories;
|
||||||
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages;
|
||||||
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Websockets.Repositories;
|
|
||||||
using Websockets.ServiceModels.Messages;
|
|
||||||
using Websockets.ServiceModels.Types;
|
|
||||||
|
|
||||||
namespace Websockets.Managers.ClientActionHandlers
|
namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
|
||||||
{
|
{
|
||||||
public class ListGamesHandler : IActionHandler
|
public class ListGamesHandler : IActionHandler
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
using AspShogiSockets.Extensions;
|
using Gameboard.ShogiUI.Sockets.Extensions;
|
||||||
|
using Gameboard.ShogiUI.Sockets.Managers.Utility;
|
||||||
|
using Gameboard.ShogiUI.Sockets.Repositories;
|
||||||
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages;
|
||||||
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Websockets.Managers.Utility;
|
|
||||||
using Websockets.Repositories;
|
|
||||||
using Websockets.ServiceModels.Messages;
|
|
||||||
using Websockets.ServiceModels.Types;
|
|
||||||
|
|
||||||
namespace Websockets.Managers.ClientActionHandlers
|
namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
|
||||||
{
|
{
|
||||||
public class LoadGameHandler : IActionHandler
|
public class LoadGameHandler : IActionHandler
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
using AspShogiSockets.Extensions;
|
using Gameboard.Shogi.Api.ServiceModels.Messages;
|
||||||
using Gameboard.Shogi.Api.ServiceModels.Messages;
|
using Gameboard.ShogiUI.Sockets.Extensions;
|
||||||
|
using Gameboard.ShogiUI.Sockets.Managers.Utility;
|
||||||
|
using Gameboard.ShogiUI.Sockets.Repositories;
|
||||||
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages;
|
||||||
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Websockets.Managers.Utility;
|
|
||||||
using Websockets.Repositories;
|
|
||||||
using Websockets.ServiceModels.Messages;
|
|
||||||
using Websockets.ServiceModels.Types;
|
|
||||||
|
|
||||||
namespace Websockets.Managers.ClientActionHandlers
|
namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
|
||||||
{
|
{
|
||||||
public class MoveHandler : IActionHandler
|
public class MoveHandler : IActionHandler
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using AspShogiSockets.Extensions;
|
using Gameboard.ShogiUI.Sockets.Extensions;
|
||||||
using AspShogiSockets.Managers.Utility;
|
using Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers;
|
||||||
|
using Gameboard.ShogiUI.Sockets.Managers.Utility;
|
||||||
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
@@ -8,10 +10,8 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Websockets.Managers.ClientActionHandlers;
|
|
||||||
using Websockets.ServiceModels.Types;
|
|
||||||
|
|
||||||
namespace Websockets.Managers
|
namespace Gameboard.ShogiUI.Sockets.Managers
|
||||||
{
|
{
|
||||||
public interface ISocketCommunicationManager
|
public interface ISocketCommunicationManager
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using System;
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Websockets.Managers
|
namespace Gameboard.ShogiUI.Sockets.Managers
|
||||||
{
|
{
|
||||||
public interface ISocketConnectionManager
|
public interface ISocketConnectionManager
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Websockets.Managers
|
namespace Gameboard.ShogiUI.Sockets.Managers
|
||||||
{
|
{
|
||||||
public interface ISocketTokenManager
|
public interface ISocketTokenManager
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using Websockets.ServiceModels.Interfaces;
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Interfaces;
|
||||||
|
|
||||||
namespace Websockets.Managers.Utility
|
namespace Gameboard.ShogiUI.Sockets.Managers.Utility
|
||||||
{
|
{
|
||||||
public class JsonRequest
|
public class JsonRequest
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using Microsoft.FSharp.Core;
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||||
using Websockets.ServiceModels.Types;
|
using Microsoft.FSharp.Core;
|
||||||
using GameboardTypes = Gameboard.Shogi.Api.ServiceModels.Types;
|
using GameboardTypes = Gameboard.Shogi.Api.ServiceModels.Types;
|
||||||
|
|
||||||
namespace Websockets.Managers.Utility
|
namespace Gameboard.ShogiUI.Sockets.Managers.Utility
|
||||||
{
|
{
|
||||||
public static class Mapper
|
public static class Mapper
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Websockets.ServiceModels.Interfaces;
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Interfaces;
|
||||||
using Websockets.ServiceModels.Types;
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||||
|
|
||||||
namespace AspShogiSockets.Managers.Utility
|
namespace Gameboard.ShogiUI.Sockets.Managers.Utility
|
||||||
{
|
{
|
||||||
public class Request : IRequest
|
public class Request : IRequest
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
namespace Websockets
|
namespace Gameboard.ShogiUI.Sockets
|
||||||
{
|
{
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ using System;
|
|||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Websockets.Repositories.Utility;
|
using Gameboard.ShogiUI.Sockets.Repositories.Utility;
|
||||||
|
|
||||||
namespace Websockets.Repositories
|
namespace Gameboard.ShogiUI.Sockets.Repositories
|
||||||
{
|
{
|
||||||
public interface IGameboardRepository
|
public interface IGameboardRepository
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,19 +1,21 @@
|
|||||||
using Gameboard.Shogi.Api.ServiceModels.Messages;
|
using Gameboard.Shogi.Api.ServiceModels.Messages;
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Websockets.Repositories;
|
|
||||||
|
|
||||||
namespace AspShogiSockets.Repositories.RepositoryManagers
|
namespace Gameboard.ShogiUI.Sockets.Repositories.RepositoryManagers
|
||||||
{
|
{
|
||||||
public interface IGameboardRepositoryManager
|
public interface IGameboardRepositoryManager
|
||||||
{
|
{
|
||||||
Task<string> CreateGuestUser();
|
Task<string> CreateGuestUser();
|
||||||
|
Task<bool> IsPlayer1(string sessionName, string playerName);
|
||||||
|
bool IsGuest(string playerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GameboardRepositoryManager : IGameboardRepositoryManager
|
public class GameboardRepositoryManager : IGameboardRepositoryManager
|
||||||
{
|
{
|
||||||
private readonly IGameboardRepository repository;
|
|
||||||
private const int MaxTries = 3;
|
private const int MaxTries = 3;
|
||||||
|
private const string GuestPrefix = "Guest-";
|
||||||
|
private readonly IGameboardRepository repository;
|
||||||
|
|
||||||
public GameboardRepositoryManager(IGameboardRepository repository)
|
public GameboardRepositoryManager(IGameboardRepository repository)
|
||||||
{
|
{
|
||||||
@@ -39,5 +41,23 @@ namespace AspShogiSockets.Repositories.RepositoryManagers
|
|||||||
}
|
}
|
||||||
throw new OperationCanceledException($"Failed to create guest user after {MaxTries} tries.");
|
throw new OperationCanceledException($"Failed to create guest user after {MaxTries} tries.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<bool> IsPlayer1(string sessionName, string playerName)
|
||||||
|
{
|
||||||
|
var session = await repository.GetGame(sessionName);
|
||||||
|
return session?.Session.Player1 == playerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<string> CreateJoinCode(string sessionName, string playerName)
|
||||||
|
{
|
||||||
|
var getGameResponse = await repository.GetGame(sessionName);
|
||||||
|
if (playerName == getGameResponse?.Session.Player1)
|
||||||
|
{
|
||||||
|
return (await repository.PostJoinCode(sessionName, playerName)).JoinCode;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsGuest(string playerName) => playerName.StartsWith(GuestPrefix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using System.Net;
|
|||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Websockets.Repositories.Utility
|
namespace Gameboard.ShogiUI.Sockets.Repositories.Utility
|
||||||
{
|
{
|
||||||
public interface IAuthenticatedHttpClient
|
public interface IAuthenticatedHttpClient
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using AspShogiSockets.Repositories.RepositoryManagers;
|
using Gameboard.ShogiUI.Sockets.Repositories.RepositoryManagers;
|
||||||
using Gameboard.ShogiUI.Sockets.Extensions;
|
using Gameboard.ShogiUI.Sockets.Extensions;
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
@@ -12,13 +12,13 @@ using Newtonsoft.Json.Serialization;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Websockets.Managers;
|
using Gameboard.ShogiUI.Sockets.Managers;
|
||||||
using Websockets.Managers.ClientActionHandlers;
|
using Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers;
|
||||||
using Websockets.Repositories;
|
using Gameboard.ShogiUI.Sockets.Repositories;
|
||||||
using Websockets.Repositories.Utility;
|
using Gameboard.ShogiUI.Sockets.Repositories.Utility;
|
||||||
using Websockets.ServiceModels.Types;
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||||
|
|
||||||
namespace Websockets
|
namespace Gameboard.ShogiUI.Sockets
|
||||||
{
|
{
|
||||||
public class Startup
|
public class Startup
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user