before deleting Rules

This commit is contained in:
2021-05-08 10:26:04 -05:00
parent 05a9c71499
commit f8f779e84c
80 changed files with 1109 additions and 832 deletions

View File

@@ -1,4 +1,4 @@
using Gameboard.Shogi.Api.ServiceModels.Messages;
using Gameboard.ShogiUI.Sockets.Models;
using System;
using System.Threading.Tasks;
@@ -9,7 +9,7 @@ namespace Gameboard.ShogiUI.Sockets.Repositories.RepositoryManagers
Task<string> CreateGuestUser();
Task<bool> IsPlayer1(string sessionName, string playerName);
bool IsGuest(string playerName);
Task<bool> PlayerExists(string playerName);
Task<bool> CreateSession(Session session);
}
public class GameboardRepositoryManager : IGameboardRepositoryManager
@@ -30,11 +30,7 @@ namespace Gameboard.ShogiUI.Sockets.Repositories.RepositoryManagers
{
count++;
var clientId = $"Guest-{Guid.NewGuid()}";
var request = new PostPlayer
{
PlayerName = clientId
};
var isCreated = await repository.PostPlayer(request);
var isCreated = await repository.CreateGuestUser(clientId);
if (isCreated)
{
return clientId;
@@ -45,22 +41,31 @@ namespace Gameboard.ShogiUI.Sockets.Repositories.RepositoryManagers
public async Task<bool> IsPlayer1(string sessionName, string playerName)
{
var session = await repository.GetGame(sessionName);
return session?.Player1 == playerName;
//var session = await repository.GetGame(sessionName);
//return session?.Player1 == playerName;
return true;
}
public async Task<string> CreateJoinCode(string sessionName, string playerName)
{
var session = await repository.GetGame(sessionName);
if (playerName == session?.Player1)
{
return await repository.PostJoinCode(sessionName, playerName);
}
//var session = await repository.GetGame(sessionName);
//if (playerName == session?.Player1)
//{
// return await repository.PostJoinCode(sessionName, playerName);
//}
return null;
}
public bool IsGuest(string playerName) => playerName.StartsWith(GuestPrefix);
public async Task<bool> CreateSession(Session session)
{
var success = await repository.CreateSession(session);
if (success)
{
return await repository.CreateBoardState(session.Name, new BoardState(), null);
}
return false;
}
public async Task<bool> PlayerExists(string playerName) => await repository.GetPlayer(playerName) != null;
public bool IsGuest(string playerName) => playerName.StartsWith(GuestPrefix);
}
}