namespaces and guest game invitations
This commit is contained in:
@@ -4,9 +4,9 @@ using System;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
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
|
||||
{
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
using Gameboard.Shogi.Api.ServiceModels.Messages;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Websockets.Repositories;
|
||||
|
||||
namespace AspShogiSockets.Repositories.RepositoryManagers
|
||||
namespace Gameboard.ShogiUI.Sockets.Repositories.RepositoryManagers
|
||||
{
|
||||
public interface IGameboardRepositoryManager
|
||||
{
|
||||
Task<string> CreateGuestUser();
|
||||
Task<bool> IsPlayer1(string sessionName, string playerName);
|
||||
bool IsGuest(string playerName);
|
||||
}
|
||||
|
||||
public class GameboardRepositoryManager : IGameboardRepositoryManager
|
||||
{
|
||||
private readonly IGameboardRepository repository;
|
||||
private const int MaxTries = 3;
|
||||
private const string GuestPrefix = "Guest-";
|
||||
private readonly 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.");
|
||||
}
|
||||
|
||||
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.Threading.Tasks;
|
||||
|
||||
namespace Websockets.Repositories.Utility
|
||||
namespace Gameboard.ShogiUI.Sockets.Repositories.Utility
|
||||
{
|
||||
public interface IAuthenticatedHttpClient
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user