Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a Web UI to the project #111

Merged
merged 13 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion PlayFabBuddy.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{2C2E8368
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlayFabBuddy.Lib.Tests", "src\PlayFabBuddy.Tests\PlayFabBuddy.Lib.Tests\PlayFabBuddy.Lib.Tests.csproj", "{B5976ACF-C71D-4FDE-8CFC-1F2870173BA9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlayFabBuddy.Infrastructure.Tests", "src\PlayFabBuddy.Tests\PlayFabBuddy.Infrastructure.Tests\PlayFabBuddy.Infrastructure.Tests.csproj", "{FDEDB431-DA25-46AB-980C-CBEF672AC4E8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlayFabBuddy.Infrastructure.Tests", "src\PlayFabBuddy.Tests\PlayFabBuddy.Infrastructure.Tests\PlayFabBuddy.Infrastructure.Tests.csproj", "{FDEDB431-DA25-46AB-980C-CBEF672AC4E8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlayFabBuddy.UI", "src\PlayFabBuddy.UI\PlayFabBuddy.UI.csproj", "{59A6981A-2938-47EB-8058-53071791A494}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -46,6 +48,10 @@ Global
{FDEDB431-DA25-46AB-980C-CBEF672AC4E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FDEDB431-DA25-46AB-980C-CBEF672AC4E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FDEDB431-DA25-46AB-980C-CBEF672AC4E8}.Release|Any CPU.Build.0 = Release|Any CPU
{59A6981A-2938-47EB-8058-53071791A494}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{59A6981A-2938-47EB-8058-53071791A494}.Debug|Any CPU.Build.0 = Debug|Any CPU
{59A6981A-2938-47EB-8058-53071791A494}.Release|Any CPU.ActiveCfg = Release|Any CPU
{59A6981A-2938-47EB-8058-53071791A494}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 4 additions & 0 deletions src/PlayFabBuddy.Cli/PlayFabBuddy.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
</Content>
</ItemGroup>

<ItemGroup>
<None Remove="local.settings.json" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\PlayFabBuddy.Infrastructure\PlayFabBuddy.Infrastructure.csproj" />
<ProjectReference Include="..\PlayFabBuddy.Lib\PlayFabBuddy.Lib.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public async Task<MasterPlayerAccountAggregate> GetTitleAccountsAndCustomId(Mast
account.MasterPlayerAccount.CustomId = response.Result.UserInfo.CustomIdInfo.CustomId;

var titlePlayerAccount = new TitlePlayerAccountEntity {
Id = response.Result.UserInfo.TitleInfo.TitlePlayerAccount.Id, TitleId = _playFabApiSettings.TitleId
Id = response.Result.UserInfo.TitleInfo.TitlePlayerAccount.Id, TitleId = _playFabApiSettings.TitleId, IsBanned = response.Result.UserInfo.TitleInfo.isBanned
};

account.AddTitlePlayerAccount(titlePlayerAccount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class TitlePlayerAccountEntity
{
public string? Id { get; init; }
public string? Id { get; set; }

public MasterPlayerAccountEntity? MasterAccount { get; set; }

Expand Down
12 changes: 12 additions & 0 deletions src/PlayFabBuddy.UI/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
140 changes: 140 additions & 0 deletions src/PlayFabBuddy.UI/Data/PlayFabService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
using PlayFabBuddy.Lib.Aggregate;
using PlayFabBuddy.Lib.Entities.Accounts;
using PlayFabBuddy.Lib.Interfaces.Adapter;
using PlayFabBuddy.Lib.UseCases.Player;
using System.Net;

namespace PlayFabBuddy.UI.Data
{
public class PlayFabService
{
private readonly IDataExplorerAdapter _dataAdapter;
private readonly IPlayerAccountAdapter _playerAdapter;

public PlayFabService(IDataExplorerAdapter dataAdapter, IPlayerAccountAdapter playerAccountAdapter)
{
_dataAdapter = dataAdapter;
_playerAdapter = playerAccountAdapter;
}

/// <summary>
/// Get a list of all players for a given IP Address
/// </summary>
/// <param name="ipAddress">The Ip Address.</param>
/// <returns></returns>
private async Task<PlayerData[]> GetPlayers(string ipAddress)
{
var getPlayerUsecase = new GetPlayersByIpUseCAse(_dataAdapter, _playerAdapter, IPAddress.Parse(ipAddress));

var playerList = await getPlayerUsecase.ExecuteAsync();

List<PlayerData> playerDataList = new List<PlayerData>();

foreach (var aggregate in playerList)
{
PlayerData playerData = new PlayerData();

if (aggregate.MasterPlayerAccount.PlayerAccounts != null)
{
foreach (var playerAccount in aggregate.MasterPlayerAccount.PlayerAccounts)
{
playerData.Id = playerAccount.Id;
playerData.IsBanned = playerAccount.IsBanned;
playerData.LastKnownIP = aggregate.MasterPlayerAccount.LastKnownIp;
playerData.TitleId = playerAccount.TitleId;
playerData.CustomId = aggregate.MasterPlayerAccount.CustomId;
playerData.MasterPlayerAccountId = aggregate.MasterPlayerAccount.Id;

playerDataList.Add(playerData);
}
}
}

return playerDataList.ToArray();
}

/// <summary>
/// Ban players based on their Ip and player Id.
/// </summary>
/// <param name="IpAddress">The Ip Address.</param>
/// <returns></returns>
private async Task<bool> BanPlayers(string ipAddress)
{
var getPlayerUsecase = new GetPlayersByIpUseCAse(_dataAdapter, _playerAdapter, IPAddress.Parse(ipAddress));

var playerList = await getPlayerUsecase.ExecuteAsync();

var banUseCase = new BanTitlePlayerAccountsByIpUseCase(_playerAdapter, playerList, IPAddress.Parse(ipAddress), " Test Dean");

return await banUseCase.ExecuteAsync();
}

/// <summary>
/// Ban a single player only based on their masterPlayerAccountId
/// </summary>
/// <param name="ipAddress">The Ip Address.</param>
/// <param name="masterPlayerAccountId"></param>
/// <param name="customId"></param>
/// <param name="titleId"></param>
/// <param name="id"></param>
/// <returns></returns>
private async Task<bool> BanSinglePlayer(string ipAddress, string masterPlayerAccountId, string customId, string titleId, string id)
{
// Build up the Player Account Object
List<MasterPlayerAccountAggregate> aggregateList = new List<MasterPlayerAccountAggregate>();

MasterPlayerAccountAggregate player = new MasterPlayerAccountAggregate(masterPlayerAccountId);
player.MasterPlayerAccount.Id = masterPlayerAccountId;
player.MasterPlayerAccount.CustomId = customId;
player.MasterPlayerAccount.LastKnownIp = ipAddress;

TitlePlayerAccountEntity titlePlayerAccount = new TitlePlayerAccountEntity();
titlePlayerAccount.TitleId = titleId;
titlePlayerAccount.Id = id;

player.MasterPlayerAccount.PlayerAccounts.Add(titlePlayerAccount);
aggregateList.Add(player);

// Call API and ban the individual player
var banUseCase = new BanTitlePlayerAccountsByIpUseCase(_playerAdapter, aggregateList, IPAddress.Parse(ipAddress), " Test Dean");

return await banUseCase.ExecuteAsync();
}

/// <summary>
/// Ban players based on an IP address
/// </summary>
/// <param name="ipAddress"></param>
/// <returns></returns>
public Task<bool> BanPlayerByIPAsync(string ipAddress)
{
return BanPlayers(ipAddress);
}

/// <summary>
/// Ban a single player
/// </summary>
/// <param name="ipAddress"></param>
/// <param name="masterPlayerAccountId"></param>
/// <param name="customId"></param>
/// <param name="titleId"></param>
/// <param name="id"></param>
/// <returns></returns>
public Task<bool> BanSinglePlayerAsync(string ipAddress, string masterPlayerAccountId, string customId, string titleId, string id)
{
return BanSinglePlayer(ipAddress, masterPlayerAccountId, customId, titleId, id);
}

/// <summary>
/// Get all the players for a given IP Address
/// </summary>
/// <param name="ipAddress"></param>
/// <returns></returns>
public Task<PlayerData[]> GetPlayersAsync(string ipAddress)
{
var playerDatas = GetPlayers(ipAddress);

return playerDatas;
}
}
}
12 changes: 12 additions & 0 deletions src/PlayFabBuddy.UI/Data/PlayerData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace PlayFabBuddy.UI.Data
{
public class PlayerData
{
public bool? IsBanned { get; internal set; }
public string? Id { get; internal set; }
public string? LastKnownIP { get; internal set; }
public string? TitleId { get; internal set; }
public string? MasterPlayerAccountId { get; internal set; }
public string? CustomId { get; internal set; }
}
}
42 changes: 42 additions & 0 deletions src/PlayFabBuddy.UI/Pages/Error.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@page
@model PlayFabBuddy.UI.Pages.ErrorModel

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>Error</title>
<link href="~/css/bootstrap/bootstrap.min.css" rel="stylesheet" />
<link href="~/css/site.css" rel="stylesheet" asp-append-version="true" />
</head>

<body>
<div class="main">
<div class="content px-4">
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
</div>
</div>
</body>

</html>
27 changes: 27 additions & 0 deletions src/PlayFabBuddy.UI/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace PlayFabBuddy.UI.Pages
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
public string? RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

private readonly ILogger<ErrorModel> _logger;

public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}

public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
}
Loading