Updates
This commit is contained in:
411
.gitignore
vendored
Normal file
411
.gitignore
vendored
Normal file
@@ -0,0 +1,411 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/modules.xml
|
||||
/contentModel.xml
|
||||
/.idea.DCGEngine.iml
|
||||
/projectSettingsUpdater.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
|
||||
|
||||
# User-specific files
|
||||
*.rsuser
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Mono auto generated files
|
||||
mono_crash.*
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
[Ww][Ii][Nn]32/
|
||||
[Aa][Rr][Mm]/
|
||||
[Aa][Rr][Mm]64/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
[Ll]ogs/
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# Visual Studio 2017 auto generated files
|
||||
Generated\ Files/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUnit
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
nunit-*.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# Benchmark Results
|
||||
BenchmarkDotNet.Artifacts/
|
||||
|
||||
# .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
# ASP.NET Scaffolding
|
||||
ScaffoldingReadMe.txt
|
||||
|
||||
# StyleCop
|
||||
StyleCopReport.xml
|
||||
|
||||
# Files built by Visual Studio
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_h.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.iobj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.ipdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*_wpftmp.csproj
|
||||
*.log
|
||||
*.tlog
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# Visual Studio Trace Files
|
||||
*.e2e
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# AxoCover is a Code Coverage Tool
|
||||
.axoCover/*
|
||||
!.axoCover/settings.json
|
||||
|
||||
# Coverlet is a free, cross platform Code Coverage Tool
|
||||
coverage*.json
|
||||
coverage*.xml
|
||||
coverage*.info
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# NuGet Symbol Packages
|
||||
*.snupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/[Pp]ackages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/[Pp]ackages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/[Pp]ackages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
*.appx
|
||||
*.appxbundle
|
||||
*.appxupload
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!?*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
orleans.codegen.cs
|
||||
|
||||
# Including strong name files can present a security risk
|
||||
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||
#*.snk
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
ServiceFabricBackup/
|
||||
*.rptproj.bak
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
*.ndf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
*.rptproj.rsuser
|
||||
*- [Bb]ackup.rdl
|
||||
*- [Bb]ackup ([0-9]).rdl
|
||||
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
node_modules/
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
|
||||
*.vbp
|
||||
|
||||
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
|
||||
*.dsw
|
||||
*.dsp
|
||||
|
||||
# Visual Studio 6 technical files
|
||||
*.ncb
|
||||
*.aps
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# CodeRush personal settings
|
||||
.cr/personal
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Tabs Studio
|
||||
*.tss
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
|
||||
# OpenCover UI analysis results
|
||||
OpenCover/
|
||||
|
||||
# Azure Stream Analytics local run output
|
||||
ASALocalRun/
|
||||
|
||||
# MSBuild Binary and Structured Log
|
||||
*.binlog
|
||||
|
||||
# NVidia Nsight GPU debugger configuration file
|
||||
*.nvuser
|
||||
|
||||
# MFractors (Xamarin productivity tool) working folder
|
||||
.mfractor/
|
||||
|
||||
# Local History for Visual Studio
|
||||
.localhistory/
|
||||
|
||||
# Visual Studio History (VSHistory) files
|
||||
.vshistory/
|
||||
|
||||
# BeatPulse healthcheck temp database
|
||||
healthchecksdb
|
||||
|
||||
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||
MigrationBackup/
|
||||
|
||||
# Ionide (cross platform F# VS Code tools) working folder
|
||||
.ionide/
|
||||
|
||||
# Fody - auto-generated XML schema
|
||||
FodyWeavers.xsd
|
||||
|
||||
# VS Code files for those working on multiple tools
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
*.code-workspace
|
||||
|
||||
# Local History for Visual Studio Code
|
||||
.history/
|
||||
|
||||
# Windows Installer files from build outputs
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# JetBrains Rider
|
||||
*.sln.iml
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Reflection;
|
||||
using DCGEngine.Database.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace DCGEngine.Database.Configuration;
|
||||
|
||||
public class DCGEDatabaseConfiguration
|
||||
{
|
||||
/// <summary>
|
||||
/// The default name of the appsettings section where these are configured.
|
||||
/// </summary>
|
||||
public const string DefaultSectionName = "DCGEDatabaseConfiguration";
|
||||
|
||||
#region Appsettings
|
||||
|
||||
// TODO
|
||||
|
||||
#endregion
|
||||
|
||||
#region Manual Configuration
|
||||
|
||||
/// <summary>
|
||||
/// Assemblies to be searched for classes implementing <see cref="BaseEntity{TKey}"/> to be added as <see cref="DbSet{TEntity}"/>s. Should be set in code, not in appsettings.
|
||||
/// </summary>
|
||||
public List<Assembly> DbSetSearchAssemblies { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
72
DCGEngine.Database/DCGEDbContext.cs
Normal file
72
DCGEngine.Database/DCGEDbContext.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using DCGEngine.Database.Configuration;
|
||||
using DCGEngine.Database.Interfaces;
|
||||
using DCGEngine.Database.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace DCGEngine.Database;
|
||||
|
||||
public class DCGEDbContext : DbContext
|
||||
{
|
||||
private readonly DCGEDatabaseConfiguration _configuration;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public DCGEDbContext(IOptions<DCGEDatabaseConfiguration> configuration, ILogger<DCGEDbContext> logger, DbContextOptions options) : base(options)
|
||||
{
|
||||
_logger = logger;
|
||||
_configuration = configuration.Value;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async Task<int> SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
foreach (var entityEntry in ChangeTracker.Entries())
|
||||
{
|
||||
if (entityEntry.Entity is ITimeTrackedEntity timeTrackedEntity)
|
||||
{
|
||||
if (entityEntry.State is EntityState.Added && timeTrackedEntity.DateCreated is null)
|
||||
{
|
||||
timeTrackedEntity.DateCreated = DateTime.UtcNow;
|
||||
}
|
||||
if (entityEntry.State is EntityState.Modified or EntityState.Added)
|
||||
{
|
||||
timeTrackedEntity.DateUpdated = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return await base.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
_configuration.DbSetSearchAssemblies.ForEach(assembly =>
|
||||
{
|
||||
foreach (var typeInfo in assembly.DefinedTypes.Where(type => type.IsAssignableTo(typeof(IDbTrackedEntity))))
|
||||
{
|
||||
modelBuilder.Entity(typeInfo.AsType());
|
||||
}
|
||||
});
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
|
||||
public void UpdateDatabase()
|
||||
{
|
||||
IEnumerable<string> pendingMigrations = Database.GetPendingMigrations();
|
||||
if (!pendingMigrations.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (string migration in pendingMigrations)
|
||||
{
|
||||
_logger.LogInformation("Found pending migration with name {migrationName}.", migration);
|
||||
}
|
||||
_logger.LogInformation("Attempting to apply pending migrations...");
|
||||
Database.Migrate();
|
||||
_logger.LogInformation("Migrations applied.");
|
||||
}
|
||||
}
|
||||
20
DCGEngine.Database/DCGEngine.Database.csproj
Normal file
20
DCGEngine.Database/DCGEngine.Database.csproj
Normal file
@@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Attributes\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.8" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
11
DCGEngine.Database/Interfaces/IDbTrackedEntity.cs
Normal file
11
DCGEngine.Database/Interfaces/IDbTrackedEntity.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace DCGEngine.Database.Interfaces;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates a class should have a <see cref="DbSet{TEntity}"/> created and be tracked by the <see cref="DbContext"/>.
|
||||
/// </summary>
|
||||
public interface IDbTrackedEntity
|
||||
{
|
||||
|
||||
}
|
||||
14
DCGEngine.Database/Interfaces/ITimeTrackedEntity.cs
Normal file
14
DCGEngine.Database/Interfaces/ITimeTrackedEntity.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace DCGEngine.Database.Interfaces;
|
||||
|
||||
public interface ITimeTrackedEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="DateTime"/> this entity was first added to the database.
|
||||
/// </summary>
|
||||
public DateTime? DateCreated { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="DateTime"/> this entity was last updated.
|
||||
/// </summary>
|
||||
public DateTime? DateUpdated { get; set; }
|
||||
}
|
||||
14
DCGEngine.Database/Models/BaseEntity.cs
Normal file
14
DCGEngine.Database/Models/BaseEntity.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using DCGEngine.Database.Interfaces;
|
||||
|
||||
namespace DCGEngine.Database.Models;
|
||||
|
||||
public class BaseEntity<TKey> : ITimeTrackedEntity, IDbTrackedEntity
|
||||
{
|
||||
[Key]
|
||||
public virtual TKey Id { get; set; }
|
||||
|
||||
public DateTime? DateCreated { get; set; }
|
||||
|
||||
public DateTime? DateUpdated { get; set; }
|
||||
}
|
||||
27
DCGEngine.Database/Models/CardEntry.cs
Normal file
27
DCGEngine.Database/Models/CardEntry.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
namespace DCGEngine.Database.Models;
|
||||
|
||||
/// <summary>
|
||||
/// A card within the system.
|
||||
/// </summary>
|
||||
public abstract class CardEntry : BaseEntity<long>
|
||||
{
|
||||
/// <summary>
|
||||
/// The name of this card used internally, to separate it from any localization key stored.
|
||||
/// </summary>
|
||||
public virtual string InternalName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The offensive power of this card.
|
||||
/// </summary>
|
||||
public virtual int? Attack { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The defensive power of this card.
|
||||
/// </summary>
|
||||
public virtual int? Defense { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// How much of the primary resource (ie mana, energy) does this card cost to play in a match.
|
||||
/// </summary>
|
||||
public virtual int? PrimaryResourceCost { get; set; }
|
||||
}
|
||||
17
DCGEngine.Database/Models/DeckEntry.cs
Normal file
17
DCGEngine.Database/Models/DeckEntry.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace DCGEngine.Database.Models;
|
||||
|
||||
/// <summary>
|
||||
/// A deck consisting of multiple <see cref="CardEntry"/> stored in the DB.
|
||||
/// </summary>
|
||||
public abstract class DeckEntry : BaseEntity<long>
|
||||
{
|
||||
/// <summary>
|
||||
/// How this deck is referred to internally.
|
||||
/// </summary>
|
||||
public virtual string InternalName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The cards present in this deck.
|
||||
/// </summary>
|
||||
public virtual List<CardEntry> Cards { get; set; }
|
||||
}
|
||||
9
DCGEngine.Engine/DCGEngine.Engine.csproj
Normal file
9
DCGEngine.Engine/DCGEngine.Engine.csproj
Normal file
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
46
DCGEngine.sln
Normal file
46
DCGEngine.sln
Normal file
@@ -0,0 +1,46 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DCGEngine.Engine", "DCGEngine.Engine\DCGEngine.Engine.csproj", "{F7124233-E421-4770-A63F-66623529116D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SVSim.Content", "SVSim.Content\SVSim.Content.csproj", "{7D990EA3-0A15-4A71-A992-7E0FC8F4F677}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SVSim.EmulatedEntrypoint", "SVSim.EmulatedEntrypoint\SVSim.EmulatedEntrypoint.csproj", "{B345A858-043F-404E-9D98-B5A6CA2EACA9}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DCGEngine.Database", "DCGEngine.Database\DCGEngine.Database.csproj", "{8D5DF264-F1A7-4455-837A-EC64849E0AE3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SVSim.Database", "SVSim.Database\SVSim.Database.csproj", "{9CE5D4F0-0D98-4E1C-942F-D692978F6103}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SVSim.UnitTests", "SVSim.UnitTests\SVSim.UnitTests.csproj", "{00E87101-F286-46F3-858E-83AB1CEBF8D1}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{F7124233-E421-4770-A63F-66623529116D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F7124233-E421-4770-A63F-66623529116D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F7124233-E421-4770-A63F-66623529116D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F7124233-E421-4770-A63F-66623529116D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7D990EA3-0A15-4A71-A992-7E0FC8F4F677}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7D990EA3-0A15-4A71-A992-7E0FC8F4F677}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7D990EA3-0A15-4A71-A992-7E0FC8F4F677}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7D990EA3-0A15-4A71-A992-7E0FC8F4F677}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B345A858-043F-404E-9D98-B5A6CA2EACA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B345A858-043F-404E-9D98-B5A6CA2EACA9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B345A858-043F-404E-9D98-B5A6CA2EACA9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B345A858-043F-404E-9D98-B5A6CA2EACA9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8D5DF264-F1A7-4455-837A-EC64849E0AE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8D5DF264-F1A7-4455-837A-EC64849E0AE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8D5DF264-F1A7-4455-837A-EC64849E0AE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8D5DF264-F1A7-4455-837A-EC64849E0AE3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9CE5D4F0-0D98-4E1C-942F-D692978F6103}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9CE5D4F0-0D98-4E1C-942F-D692978F6103}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9CE5D4F0-0D98-4E1C-942F-D692978F6103}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9CE5D4F0-0D98-4E1C-942F-D692978F6103}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{00E87101-F286-46F3-858E-83AB1CEBF8D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{00E87101-F286-46F3-858E-83AB1CEBF8D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{00E87101-F286-46F3-858E-83AB1CEBF8D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{00E87101-F286-46F3-858E-83AB1CEBF8D1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
5
SVSim.Content/Class1.cs
Normal file
5
SVSim.Content/Class1.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
namespace SVSim.Content;
|
||||
|
||||
public class Class1
|
||||
{
|
||||
}
|
||||
9
SVSim.Content/SVSim.Content.csproj
Normal file
9
SVSim.Content/SVSim.Content.csproj
Normal file
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
12
SVSim.Database/Models/ShadowverseCardEntry.cs
Normal file
12
SVSim.Database/Models/ShadowverseCardEntry.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using DCGEngine.Database.Models;
|
||||
|
||||
namespace SVSim.Database.Models;
|
||||
|
||||
public class ShadowverseCardEntry : CardEntry
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.None)]
|
||||
public override long Id { get; set; }
|
||||
}
|
||||
8
SVSim.Database/Models/ShadowverseDeckEntry.cs
Normal file
8
SVSim.Database/Models/ShadowverseDeckEntry.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using DCGEngine.Database.Models;
|
||||
|
||||
namespace SVSim.Database.Models;
|
||||
|
||||
public class ShadowverseDeckEntry : DeckEntry
|
||||
{
|
||||
|
||||
}
|
||||
15
SVSim.Database/Models/User.cs
Normal file
15
SVSim.Database/Models/User.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using DCGEngine.Database.Models;
|
||||
|
||||
namespace SVSim.Database.Models;
|
||||
|
||||
/// <summary>
|
||||
/// A user within the game system.
|
||||
/// </summary>
|
||||
public class User : BaseEntity<long>
|
||||
{
|
||||
public string ViewerId { get; set; }
|
||||
public ulong SteamId { get; set; }
|
||||
public string DisplayName { get; set; }
|
||||
|
||||
|
||||
}
|
||||
13
SVSim.Database/SVSim.Database.csproj
Normal file
13
SVSim.Database/SVSim.Database.csproj
Normal file
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DCGEngine.Database\DCGEngine.Database.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
14
SVSim.Database/SVSimDbContext.cs
Normal file
14
SVSim.Database/SVSimDbContext.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using DCGEngine.Database;
|
||||
using DCGEngine.Database.Configuration;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace SVSim.Database;
|
||||
|
||||
public class SVSimDbContext : DCGEDbContext
|
||||
{
|
||||
public SVSimDbContext(IOptions<DCGEDatabaseConfiguration> configuration, ILogger<DCGEDbContext> logger, DbContextOptions options) : base(configuration, logger, options)
|
||||
{
|
||||
}
|
||||
}
|
||||
93
SVSim.EmulatedEntrypoint/Controllers/CheckController.cs
Normal file
93
SVSim.EmulatedEntrypoint/Controllers/CheckController.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using System.Buffers.Text;
|
||||
using System.Text;
|
||||
using MessagePack;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos;
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos.Requests;
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos.Responses;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class CheckController : SVSimController
|
||||
{
|
||||
private ILogger _logger;
|
||||
|
||||
public CheckController(ILogger<CheckController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpPost("special_title")]
|
||||
public async Task<DataWrapper<SpecialTitleCheckResponse>> SpecialTitleCheck(SpecialTitleCheckRequest request)
|
||||
{
|
||||
int titleId = Random.Shared.Next(8, 33);
|
||||
var res = new DataWrapper<SpecialTitleCheckResponse>
|
||||
{
|
||||
Data = new SpecialTitleCheckResponse
|
||||
{
|
||||
TitleImageId = titleId,
|
||||
TitleSoundId = titleId
|
||||
},
|
||||
DataHeaders = new DataHeaders
|
||||
{
|
||||
ShortUdid = 411054851,
|
||||
ViewerId = 906243102,
|
||||
Sid = string.Empty,
|
||||
Servertime = DateTime.UtcNow.Ticks,
|
||||
ResultCode = 1
|
||||
}
|
||||
};
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
[HttpPost("game_start")]
|
||||
public async Task<DataWrapper<GameStartResponse>> GameStart(GameStartRequest request)
|
||||
{
|
||||
return new DataWrapper<GameStartResponse>()
|
||||
{
|
||||
DataHeaders = new DataHeaders
|
||||
{
|
||||
ShortUdid = 411054851,
|
||||
ViewerId = 906243102,
|
||||
Sid = string.Empty,
|
||||
Servertime = DateTime.UtcNow.Ticks,
|
||||
ResultCode = 1
|
||||
},
|
||||
Data = new GameStartResponse()
|
||||
{
|
||||
IsSetTransitionPassword = true,
|
||||
KorAuthorityId = default,
|
||||
KorAuthorityState = default,
|
||||
NowRank = new Dictionary<string, string>()
|
||||
{
|
||||
{"1", "RankName_010"},
|
||||
{"2", "RankName_010"},
|
||||
{"4", "RankName_017"}
|
||||
},
|
||||
NowName = "combusty7",
|
||||
PolicyState = default,
|
||||
PolicyId = default,
|
||||
NowTutorialStep = "100",
|
||||
NowViewerId = 906243102,
|
||||
TosId = default,
|
||||
TosState = default,
|
||||
TransitionAccountData = new List<TransitionAccountData>()
|
||||
{
|
||||
new TransitionAccountData()
|
||||
{
|
||||
ConnectedViewerId = "906243102",
|
||||
SocialAccountType = "5",
|
||||
SocialAccountId = "76561197970830305"
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
19
SVSim.EmulatedEntrypoint/Controllers/SVSimController.cs
Normal file
19
SVSim.EmulatedEntrypoint/Controllers/SVSimController.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SVSim.EmulatedEntrypoint.Security;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// A base controller for SVSim with helpers for getting some values.
|
||||
/// </summary>
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public abstract class SVSimController : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the UdId of the user making the request. Can be null or empty, as only certain requests will send it. Known requests to send this value are: SignUp, CheckSpecialTitle, CheckiCloudUser, MigrateiCloudUser
|
||||
/// </summary>
|
||||
public string? UdId => Encryption.Decode(Request.Headers["UDID"]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using System.Text;
|
||||
using MessagePack;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using Newtonsoft.Json;
|
||||
using SVSim.EmulatedEntrypoint.Security;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Middlewares;
|
||||
|
||||
/// <summary>
|
||||
/// Translates incoming requests and outgoing responses from the Shadowverse client into the messagepack format.
|
||||
/// </summary>
|
||||
public class ShadowverseTranslationMiddleware : IMiddleware
|
||||
{
|
||||
private readonly IActionDescriptorCollectionProvider _actionDescriptorCollectionProvider;
|
||||
|
||||
public ShadowverseTranslationMiddleware(IActionDescriptorCollectionProvider actionDescriptorCollectionProvider)
|
||||
{
|
||||
_actionDescriptorCollectionProvider = actionDescriptorCollectionProvider;
|
||||
}
|
||||
|
||||
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
|
||||
{
|
||||
bool isUnity = context.Request.Headers.UserAgent.Any(agent => agent?.Contains("UnityPlayer") ?? false);
|
||||
string path = context.Request.Path;
|
||||
var endpointDescriptor =
|
||||
_actionDescriptorCollectionProvider.ActionDescriptors.Items.FirstOrDefault(ad =>
|
||||
$"/{ad.AttributeRouteInfo.Template}".Equals(path, StringComparison.InvariantCultureIgnoreCase));
|
||||
if (!isUnity || endpointDescriptor == null)
|
||||
{
|
||||
await next.Invoke(context);
|
||||
return;
|
||||
}
|
||||
using var requestBytesStream = new MemoryStream();
|
||||
using var tempResponseBody = new MemoryStream();
|
||||
var originalResponsebody = context.Response.Body;
|
||||
context.Response.Body = tempResponseBody;
|
||||
await context.Request.Body.CopyToAsync(requestBytesStream);
|
||||
byte[] requestBytes = requestBytesStream.ToArray();
|
||||
// Decrypt incoming data. Placeholder.
|
||||
requestBytes = Encryption.Decrypt(requestBytes, Encryption.Decode(context.Request.Headers["UDID"]));
|
||||
object? data = MessagePackSerializer.Deserialize(endpointDescriptor.Parameters.FirstOrDefault().ParameterType,
|
||||
requestBytes);
|
||||
var json = JsonConvert.SerializeObject(data);
|
||||
var newStream = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
context.Request.Body = newStream.ReadAsStream();
|
||||
context.Request.Headers.ContentType = new StringValues("application/json");
|
||||
await next.Invoke(context);
|
||||
var responseType = ((ControllerActionDescriptor)endpointDescriptor).MethodInfo.ReturnType;
|
||||
if (responseType.IsGenericType && responseType.GetGenericTypeDefinition() == typeof(Task<>))
|
||||
{
|
||||
responseType = responseType.GetGenericArguments()[0];
|
||||
}
|
||||
using var responseBytesStream = new MemoryStream();
|
||||
context.Response.Body.Seek(0, SeekOrigin.Begin);
|
||||
await context.Response.Body.CopyToAsync(responseBytesStream);
|
||||
var responseBytes = responseBytesStream.ToArray();
|
||||
var responseData = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(responseBytes), responseType);
|
||||
var packedData = MessagePackSerializer.Serialize(responseType, responseData);
|
||||
packedData = Encryption.Encrypt(packedData, Encryption.Decode(context.Request.Headers["UDID"]));
|
||||
await originalResponsebody.WriteAsync(Encoding.UTF8.GetBytes(Convert.ToBase64String(packedData)));
|
||||
context.Response.Body = originalResponsebody;
|
||||
}
|
||||
}
|
||||
18
SVSim.EmulatedEntrypoint/Models/Dtos/DataHeaders.cs
Normal file
18
SVSim.EmulatedEntrypoint/Models/Dtos/DataHeaders.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using MessagePack;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Models.Dtos;
|
||||
|
||||
[MessagePackObject]
|
||||
public class DataHeaders
|
||||
{
|
||||
[Key("short_udid")]
|
||||
public int ShortUdid { get; set; }
|
||||
[Key("viewer_id")]
|
||||
public int ViewerId { get; set; }
|
||||
[Key("sid")]
|
||||
public string Sid { get; set; }
|
||||
[Key("servertime")]
|
||||
public long Servertime { get; set; }
|
||||
[Key("result_code")]
|
||||
public int ResultCode { get; set; }
|
||||
}
|
||||
12
SVSim.EmulatedEntrypoint/Models/Dtos/DataWrapper.cs
Normal file
12
SVSim.EmulatedEntrypoint/Models/Dtos/DataWrapper.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using MessagePack;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Models.Dtos;
|
||||
|
||||
[MessagePackObject]
|
||||
public class DataWrapper<T>
|
||||
{
|
||||
[Key("data_headers")]
|
||||
public DataHeaders DataHeaders { get; set; }
|
||||
[Key("data")]
|
||||
public T Data { get; set; }
|
||||
}
|
||||
14
SVSim.EmulatedEntrypoint/Models/Dtos/Requests/BaseRequest.cs
Normal file
14
SVSim.EmulatedEntrypoint/Models/Dtos/Requests/BaseRequest.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using MessagePack;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Models.Dtos.Requests;
|
||||
|
||||
[MessagePackObject]
|
||||
public abstract class BaseRequest
|
||||
{
|
||||
[Key("viewer_id")]
|
||||
public string ViewerId { get; set; }
|
||||
[Key("steam_id")]
|
||||
public long SteamId { get; set; }
|
||||
[Key("steam_session_ticket")]
|
||||
public string SteamSessionTicket { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using MessagePack;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Models.Dtos.Requests;
|
||||
|
||||
[MessagePackObject]
|
||||
public class GameStartRequest : BaseRequest
|
||||
{
|
||||
[Key("app_type")]
|
||||
public int AppType { get; set; }
|
||||
[Key("campaign_data")]
|
||||
public string CampaignData { get; set; }
|
||||
[Key("campaign_sign")]
|
||||
public string CampaignSign { get; set; }
|
||||
[Key("campaign_user")]
|
||||
public int CampaignUser { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using MessagePack;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Models.Dtos.Requests;
|
||||
|
||||
[MessagePackObject]
|
||||
public class SpecialTitleCheckRequest : BaseRequest
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using MessagePack;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Models.Dtos.Responses;
|
||||
|
||||
[MessagePackObject]
|
||||
public class GameStartResponse
|
||||
{
|
||||
[Key("now_viewer_id")]
|
||||
public long NowViewerId { get; set; }
|
||||
[Key("is_set_transition_password")]
|
||||
public bool IsSetTransitionPassword { get; set; }
|
||||
[Key("now_name")]
|
||||
public string NowName { get; set; }
|
||||
[Key("now_rank")]
|
||||
public Dictionary<string, string> NowRank { get; set; }
|
||||
[Key("now_tutorial_step")]
|
||||
public string NowTutorialStep { get; set; }
|
||||
[Key("transition_account_data")]
|
||||
public List<TransitionAccountData> TransitionAccountData { get; set; }
|
||||
[Key("tos_state")]
|
||||
public int TosState { get; set; }
|
||||
[Key("tos_id")]
|
||||
public int TosId { get; set; }
|
||||
[Key("policy_state")]
|
||||
public int PolicyState { get; set; }
|
||||
[Key("policy_id")]
|
||||
public int PolicyId { get; set; }
|
||||
[Key("kor_authority_id")]
|
||||
public int KorAuthorityId { get; set; }
|
||||
[Key("kor_authority_state")]
|
||||
public int KorAuthorityState { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using MessagePack;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Models.Dtos.Responses;
|
||||
|
||||
[MessagePackObject]
|
||||
public class SpecialTitleCheckResponse
|
||||
{
|
||||
[Key("title_image_id")]
|
||||
public int TitleImageId { get; set; }
|
||||
[Key("title_sound_id")]
|
||||
public int TitleSoundId { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using MessagePack;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Models.Dtos;
|
||||
|
||||
[MessagePackObject]
|
||||
public class TransitionAccountData
|
||||
{
|
||||
[Key("social_account_id")]
|
||||
public string SocialAccountId { get; set; }
|
||||
[Key("social_account_type")]
|
||||
public string SocialAccountType { get; set; }
|
||||
[Key("connected_viewer_id")]
|
||||
public string ConnectedViewerId { get; set; }
|
||||
}
|
||||
59
SVSim.EmulatedEntrypoint/Program.cs
Normal file
59
SVSim.EmulatedEntrypoint/Program.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
|
||||
using System.Reflection;
|
||||
using DCGEngine.Database.Configuration;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SVSim.Database;
|
||||
using SVSim.Database.Models;
|
||||
using SVSim.EmulatedEntrypoint.Middlewares;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
builder.Services.AddHttpLogging(opt =>
|
||||
{
|
||||
|
||||
});
|
||||
builder.Services.AddDbContext<SVSimDbContext>(opt =>
|
||||
{
|
||||
opt.UseSqlite();
|
||||
});
|
||||
builder.Services.AddTransient<ShadowverseTranslationMiddleware>();
|
||||
builder.Services.Configure<DCGEDatabaseConfiguration>(opt =>
|
||||
{
|
||||
opt.DbSetSearchAssemblies = new List<Assembly> { Assembly.GetAssembly(typeof(SVSimDbContext)) };
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseHttpLogging();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
//app.UseHttpsRedirection();
|
||||
|
||||
app.UseMiddleware<ShadowverseTranslationMiddleware>();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
41
SVSim.EmulatedEntrypoint/Properties/launchSettings.json
Normal file
41
SVSim.EmulatedEntrypoint/Properties/launchSettings.json
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:11677",
|
||||
"sslPort": 44324
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "http://localhost:5148",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7267;http://localhost:5148",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
35
SVSim.EmulatedEntrypoint/SVSim.EmulatedEntrypoint.csproj
Normal file
35
SVSim.EmulatedEntrypoint/SVSim.EmulatedEntrypoint.csproj
Normal file
@@ -0,0 +1,35 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Facepunch.Steamworks" Version="2.3.3" />
|
||||
<PackageReference Include="MessagePack" Version="2.5.172" />
|
||||
<PackageReference Include="MessagePackAnalyzer" Version="2.5.172">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.8">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.4" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Configuration\" />
|
||||
<Folder Include="Controllers\" />
|
||||
<Folder Include="Utility\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SVSim.Database\SVSim.Database.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
6
SVSim.EmulatedEntrypoint/SVSim.EmulatedEntrypoint.http
Normal file
6
SVSim.EmulatedEntrypoint/SVSim.EmulatedEntrypoint.http
Normal file
@@ -0,0 +1,6 @@
|
||||
@SVSim.EmulatedEntrypoint_HostAddress = http://localhost:5148
|
||||
|
||||
GET {{SVSim.EmulatedEntrypoint_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
152
SVSim.EmulatedEntrypoint/Security/Encryption.cs
Normal file
152
SVSim.EmulatedEntrypoint/Security/Encryption.cs
Normal file
@@ -0,0 +1,152 @@
|
||||
using System.Globalization;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Security;
|
||||
|
||||
/// <summary>
|
||||
/// Helper class for encrypting/decrypting requests bodies and responses to/from the game client.
|
||||
/// </summary>
|
||||
public static class Encryption
|
||||
{
|
||||
private const int EncryptionKeySize = 256;
|
||||
private const int EncryptionBlockSize = 128;
|
||||
private const CipherMode EncryptionMode = CipherMode.CBC;
|
||||
private const int UdIdKeySize = 16;
|
||||
private const int KeyStringSize = 32;
|
||||
private const int EncodingValueOffset = 10;
|
||||
|
||||
/// <summary>
|
||||
/// Encrypts an array of bytes using RJ256 with a subset of the user's UdId as the key.
|
||||
/// </summary>
|
||||
/// <param name="sourceData">the data to encrypt</param>
|
||||
/// <param name="udId">the UdId of the user this data is encrypted for</param>
|
||||
/// <returns>the encrypted bytes</returns>
|
||||
public static byte[] Encrypt(byte[] sourceData, string udId)
|
||||
{
|
||||
using (var rj = Aes.Create())
|
||||
{
|
||||
rj.KeySize = EncryptionKeySize;
|
||||
rj.Mode = EncryptionMode;
|
||||
rj.BlockSize = EncryptionBlockSize;
|
||||
string keyString = GenerateKeyString();
|
||||
string udIdKey = udId.Replace("-", string.Empty).Substring(0, UdIdKeySize);
|
||||
byte[] keyStringBytes = Encoding.UTF8.GetBytes(keyString);
|
||||
byte[] rgbIV = Encoding.UTF8.GetBytes(udIdKey);
|
||||
ICryptoTransform transform = rj.CreateEncryptor(keyStringBytes, rgbIV);
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
using (CryptoStream cs = new CryptoStream(ms, transform, CryptoStreamMode.Write))
|
||||
{
|
||||
cs.Write(sourceData);
|
||||
cs.FlushFinalBlock();
|
||||
byte[] encryptedResults = ms.ToArray();
|
||||
byte[] encryptedResultsAndKey = new byte[encryptedResults.Length + keyStringBytes.Length];
|
||||
Array.Copy(encryptedResults, 0, encryptedResultsAndKey, 0, encryptedResults.Length);
|
||||
Array.Copy(keyStringBytes, 0, encryptedResultsAndKey, encryptedResults.Length, keyStringBytes.Length);
|
||||
return encryptedResultsAndKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decrypts data that has been encrypted with the given UdId.
|
||||
/// </summary>
|
||||
/// <param name="encryptedData">Previously encrypted data</param>
|
||||
/// <param name="udId">The UdId previously used to encrypt the data</param>
|
||||
/// <returns>the decrypted bytes</returns>
|
||||
public static byte[] Decrypt(byte[] encryptedData, string udId)
|
||||
{
|
||||
using (var rj = Aes.Create())
|
||||
{
|
||||
rj.KeySize = EncryptionKeySize;
|
||||
rj.Mode = EncryptionMode;
|
||||
rj.BlockSize = EncryptionBlockSize;
|
||||
byte[] rgbIv = Encoding.UTF8.GetBytes(udId.Replace("-", string.Empty).Substring(0, UdIdKeySize));
|
||||
byte[] keyBytes = new byte[KeyStringSize];
|
||||
byte[] encryptedValueBytes = new byte[encryptedData.Length - KeyStringSize];
|
||||
Array.Copy(encryptedData, encryptedData.Length - keyBytes.Length, keyBytes, 0, keyBytes.Length);
|
||||
Array.Copy(encryptedData, 0, encryptedValueBytes, 0, encryptedValueBytes.Length);
|
||||
ICryptoTransform transform = rj.CreateDecryptor(keyBytes, rgbIv);
|
||||
using (MemoryStream ms = new MemoryStream(encryptedValueBytes))
|
||||
{
|
||||
using (CryptoStream cs = new CryptoStream(ms, transform, CryptoStreamMode.Read))
|
||||
{
|
||||
byte[] decryptedValueBytes = new byte[encryptedValueBytes.Length];
|
||||
cs.Read(decryptedValueBytes, 0, encryptedValueBytes.Length);
|
||||
cs.FlushFinalBlock();
|
||||
return decryptedValueBytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string Encode(string sourceData)
|
||||
{
|
||||
int length = sourceData.Length;
|
||||
string encodeBuf = $"{length:x4}";
|
||||
foreach (char value in sourceData)
|
||||
{
|
||||
encodeBuf += $"{GetRandom(),1:x}";
|
||||
encodeBuf += $"{GetRandom(),1:x}";
|
||||
encodeBuf += ((char)(Convert.ToInt32(value) + EncodingValueOffset)).ToString();
|
||||
encodeBuf += $"{GetRandom(),1:x}";
|
||||
}
|
||||
|
||||
encodeBuf += GenerateIvString();
|
||||
return encodeBuf;
|
||||
}
|
||||
|
||||
public static string? Decode(string? encodedData)
|
||||
{
|
||||
if (encodedData == null || encodedData.Length < 4)
|
||||
{
|
||||
return encodedData;
|
||||
}
|
||||
int num = int.Parse(encodedData.Substring(0, 4), NumberStyles.AllowHexSpecifier);
|
||||
string text = "";
|
||||
int num2 = 2;
|
||||
foreach (char value in encodedData.Substring(4, encodedData.Length - 4))
|
||||
{
|
||||
if (num2 % 4 == 0)
|
||||
{
|
||||
text += ((char)(Convert.ToInt32(value) - EncodingValueOffset)).ToString();
|
||||
}
|
||||
num2++;
|
||||
if (text.Length >= num)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
// TODO Clean this up and de-magic number it
|
||||
private static string GenerateIvString()
|
||||
{
|
||||
string text = "";
|
||||
for (int i = 0; i < KeyStringSize; i++)
|
||||
{
|
||||
text += $"{GetRandom()}";
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
private static string GenerateKeyString()
|
||||
{
|
||||
string text = "";
|
||||
for (int i = 0; i < KeyStringSize; i++)
|
||||
{
|
||||
text += $"{Random.Shared.Next(0, ushort.MaxValue):x}";
|
||||
}
|
||||
return Convert.ToBase64String(Encoding.ASCII.GetBytes(text)).Substring(0, KeyStringSize);
|
||||
}
|
||||
|
||||
private static int GetRandom()
|
||||
{
|
||||
const int MinRandomValue = 1;
|
||||
const int MaxRandomValue = 9;
|
||||
return Random.Shared.Next(MinRandomValue, MaxRandomValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Security.SteamSessionAuthentication;
|
||||
|
||||
public class SteamAuthenticationHandlerOptions : AuthenticationSchemeOptions
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Text.Encodings.Web;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Security.SteamSessionAuthentication;
|
||||
|
||||
public class SteamSessionAuthenticationHandler : AuthenticationHandler<SteamAuthenticationHandlerOptions>
|
||||
{
|
||||
public SteamSessionAuthenticationHandler(IOptionsMonitor<SteamAuthenticationHandlerOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock)
|
||||
{
|
||||
}
|
||||
|
||||
public SteamSessionAuthenticationHandler(IOptionsMonitor<SteamAuthenticationHandlerOptions> options, ILoggerFactory logger, UrlEncoder encoder) : base(options, logger, encoder)
|
||||
{
|
||||
}
|
||||
|
||||
protected async override Task<AuthenticateResult> HandleAuthenticateAsync()
|
||||
{
|
||||
return AuthenticateResult.Fail("Not implemented");
|
||||
}
|
||||
}
|
||||
56
SVSim.EmulatedEntrypoint/Services/SteamSessionService.cs
Normal file
56
SVSim.EmulatedEntrypoint/Services/SteamSessionService.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Globalization;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Steamworks;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Services;
|
||||
|
||||
public class SteamSessionService : IDisposable
|
||||
{
|
||||
private readonly ConcurrentDictionary<string, ulong> _validatedSessionTickets;
|
||||
|
||||
private const int ShadowVerseAppId = 453480;
|
||||
|
||||
public SteamSessionService()
|
||||
{
|
||||
_validatedSessionTickets = new ConcurrentDictionary<string, ulong>();
|
||||
SteamServer.Init(ShadowVerseAppId, new SteamServerInit
|
||||
{
|
||||
GamePort = default,
|
||||
QueryPort = default
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates if a given session ticket is valid, and matches up with the given steamid.
|
||||
/// </summary>
|
||||
/// <param name="ticket">the ticket, represented as a hexadecimal string</param>
|
||||
/// <param name="steamId">the steamid that should be associated with the ticket</param>
|
||||
/// <returns>whether the ticket is valid for the given steamid</returns>
|
||||
public bool IsTicketValidForUser(string ticket, ulong steamId)
|
||||
{
|
||||
if (_validatedSessionTickets.TryGetValue(ticket, out ulong storedSteamId))
|
||||
{
|
||||
return storedSteamId == steamId;
|
||||
}
|
||||
|
||||
List<byte> ticketBytes = new List<byte>();
|
||||
for (int i = 0; i < ticket.Length; i += 2)
|
||||
{
|
||||
ticketBytes.Add(Convert.ToByte(ticket.Substring(i, 2), 16));
|
||||
}
|
||||
|
||||
var steamCheckResults = SteamServer.BeginAuthSession(ticketBytes.ToArray(), new SteamId { Value = steamId });
|
||||
if (steamCheckResults)
|
||||
{
|
||||
_validatedSessionTickets.TryAdd(ticket, storedSteamId);
|
||||
}
|
||||
|
||||
return steamCheckResults;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
SteamServer.Shutdown();
|
||||
}
|
||||
}
|
||||
12
SVSim.EmulatedEntrypoint/WeatherForecast.cs
Normal file
12
SVSim.EmulatedEntrypoint/WeatherForecast.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace SVSim.EmulatedEntrypoint;
|
||||
|
||||
public class WeatherForecast
|
||||
{
|
||||
public DateOnly Date { get; set; }
|
||||
|
||||
public int TemperatureC { get; set; }
|
||||
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
|
||||
public string? Summary { get; set; }
|
||||
}
|
||||
8
SVSim.EmulatedEntrypoint/appsettings.Development.json
Normal file
8
SVSim.EmulatedEntrypoint/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
10
SVSim.EmulatedEntrypoint/appsettings.json
Normal file
10
SVSim.EmulatedEntrypoint/appsettings.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware": "Information"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
BIN
SVSim.EmulatedEntrypoint/lib/steam_api.dll
Normal file
BIN
SVSim.EmulatedEntrypoint/lib/steam_api.dll
Normal file
Binary file not shown.
BIN
SVSim.EmulatedEntrypoint/lib/steam_api64.dll
Normal file
BIN
SVSim.EmulatedEntrypoint/lib/steam_api64.dll
Normal file
Binary file not shown.
2
SVSim.UnitTests/GlobalUsings.cs
Normal file
2
SVSim.UnitTests/GlobalUsings.cs
Normal file
@@ -0,0 +1,2 @@
|
||||
global using NUnit.Framework;
|
||||
using SVSim.EmulatedEntrypoint;
|
||||
24
SVSim.UnitTests/SVSim.UnitTests.csproj
Normal file
24
SVSim.UnitTests/SVSim.UnitTests.csproj
Normal file
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
|
||||
<PackageReference Include="NUnit" Version="3.13.3" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SVSim.EmulatedEntrypoint\SVSim.EmulatedEntrypoint.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
21
SVSim.UnitTests/UnitTest1.cs
Normal file
21
SVSim.UnitTests/UnitTest1.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using SVSim.EmulatedEntrypoint.Services;
|
||||
|
||||
namespace SVSim.UnitTests;
|
||||
|
||||
public class Tests
|
||||
{
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test1()
|
||||
{
|
||||
const string ticket =
|
||||
"140000005ee7d30c1263e214e133a10001001001e07cd866180000000100000002000000b8526bb7b8946cd27c214574f1000000b20000003200000004000000e133a1000100100168eb0600488cc2443101a8c0000000008165d4660115f06601005c7e010000000000cad61456a2b83d39595c3e3749b96b4537ebde88d048103a6f6c7b2b81ee68711378836872a11422f5bd16fad803f81122c5ae98d986b693bbbc00ac7d30a8f85af2c1a7dce57751eb2c7f21130284aa8d9ee787246c8ccc138f05936bacb1ba4baba5fa5fbf6158002cf7207ae25a6f6ee8e3fc8edbb84903d346a249179637";
|
||||
using var steamService = new SteamSessionService();
|
||||
bool validTicket = steamService.IsTicketValidForUser(ticket, 76561197970830305);
|
||||
Assert.AreEqual(true, validTicket);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user