Initial commit, basic work
This commit is contained in:
+421
@@ -0,0 +1,421 @@
|
||||
## 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/master/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/
|
||||
[Aa][Rr][Mm]/
|
||||
[Aa][Rr][Mm]64/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
|
||||
# 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
|
||||
|
||||
# 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/
|
||||
|
||||
# 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
|
||||
*.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
|
||||
|
||||
# JustCode is a .NET coding add-in
|
||||
.JustCode
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# AxoCover is a Code Coverage Tool
|
||||
.axoCover/*
|
||||
!.axoCover/settings.json
|
||||
|
||||
# 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
|
||||
# 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
|
||||
*- Backup*.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 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/
|
||||
|
||||
# BeatPulse healthcheck temp database
|
||||
healthchecksdb
|
||||
|
||||
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||
MigrationBackup/
|
||||
|
||||
|
||||
|
||||
## VS CODE
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
|
||||
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/.idea.server-csharp.iml
|
||||
/modules.xml
|
||||
/projectSettingsUpdater.xml
|
||||
/contentModel.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||
</project>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace Types.Annotations;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class Injectable(InjectionType injectionType = InjectionType.Scoped, Type? type = null) : Attribute
|
||||
{
|
||||
public InjectionType InjectionType { get; set; } = injectionType;
|
||||
public Type? InjectableTypeOverride { get; set; } = type;
|
||||
}
|
||||
|
||||
public enum InjectionType
|
||||
{
|
||||
Singleton,
|
||||
Transient,
|
||||
Scoped
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Types.Context;
|
||||
|
||||
public class ContextVariable(object value, ContextVariableType contextVariableType)
|
||||
{
|
||||
public object Value { get; } = value;
|
||||
public DateTime Timestamp { get; } = DateTime.Now;
|
||||
public ContextVariableType Type { get; } = contextVariableType;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace Types.Context;
|
||||
|
||||
public enum ContextVariableType
|
||||
{
|
||||
/** Logged in users session id */
|
||||
SESSION_ID = 0,
|
||||
/** Currently acive raid information */
|
||||
RAID_CONFIGURATION = 1,
|
||||
/** SessionID + Timestamp when client first connected, has _ between values */
|
||||
CLIENT_START_TIMESTAMP = 2,
|
||||
/** When player is loading into map and loot is requested */
|
||||
REGISTER_PLAYER_REQUEST = 3,
|
||||
RAID_ADJUSTMENTS = 4,
|
||||
/** Data returned from client request object from endLocalRaid() */
|
||||
TRANSIT_INFO = 5,
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Types.Context;
|
||||
|
||||
public interface IApplicationContext
|
||||
{
|
||||
ContextVariable? GetLatestValue(ContextVariableType type);
|
||||
ICollection<ContextVariable> GetValues(ContextVariableType type);
|
||||
void AddValue(ContextVariableType type, object value);
|
||||
void ClearValues(ContextVariableType type);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>Types</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Helpers\" />
|
||||
<Folder Include="Servers\Http\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Types.Models.Config;
|
||||
|
||||
public class HttpConfig
|
||||
{
|
||||
public int Port { get; set; }
|
||||
public string Ip { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Types.Models.Enums;
|
||||
|
||||
public enum ConfigTypes
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace Types.Models.Utils;
|
||||
|
||||
public interface ILogger
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace Types.Servers;
|
||||
|
||||
public interface IConfigServer
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Types.Servers;
|
||||
|
||||
public interface IHttpServer
|
||||
{
|
||||
public void Load(WebApplicationBuilder builder);
|
||||
public bool IsStarted();
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace Types.Servers;
|
||||
|
||||
public interface IWebSocketServer
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace Types.Services;
|
||||
|
||||
public interface ILocalisationService
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using Types.Annotations;
|
||||
using Types.Context;
|
||||
|
||||
namespace Server.Context;
|
||||
|
||||
[Injectable(InjectionType.Singleton)]
|
||||
public class ApplicationContext : IApplicationContext
|
||||
{
|
||||
private const short MaxSavedValues = 10;
|
||||
private Dictionary<ContextVariableType, LinkedList<ContextVariable>> variables = new();
|
||||
private object variablesLock = new();
|
||||
|
||||
|
||||
public ContextVariable? GetLatestValue(ContextVariableType type)
|
||||
{
|
||||
lock (variablesLock)
|
||||
{
|
||||
if (variables.TryGetValue(type, out var savedValues))
|
||||
return savedValues.Last!.Value;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICollection<ContextVariable> GetValues(ContextVariableType type)
|
||||
{
|
||||
lock (variablesLock)
|
||||
{
|
||||
var values = new List<ContextVariable>();
|
||||
if (variables.TryGetValue(type, out var savedValues))
|
||||
{
|
||||
values.AddRange(savedValues);
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddValue(ContextVariableType type, object value)
|
||||
{
|
||||
lock (variablesLock)
|
||||
{
|
||||
if (!variables.TryGetValue(type, out var savedValues))
|
||||
{
|
||||
savedValues = [];
|
||||
variables.Add(type, savedValues);
|
||||
}
|
||||
|
||||
if (savedValues.Count >= MaxSavedValues)
|
||||
savedValues.RemoveFirst();
|
||||
|
||||
savedValues.AddLast(new ContextVariable(value, type));
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearValues(ContextVariableType type)
|
||||
{
|
||||
lock (variablesLock)
|
||||
{
|
||||
variables.Remove(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using Types.Annotations;
|
||||
using Types.Servers;
|
||||
|
||||
namespace Server;
|
||||
|
||||
public static class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
RegisterSptComponents(builder.Services);
|
||||
|
||||
// TODO: deal with modding overriding services here!
|
||||
|
||||
var httpServer = builder.Services.BuildServiceProvider().GetService<IHttpServer>();
|
||||
httpServer.Load(builder);
|
||||
}
|
||||
|
||||
private static void RegisterComponents(IServiceCollection builderServices, IEnumerable<Type> types)
|
||||
{
|
||||
// We get all injectable services to register them on our services
|
||||
foreach (var injectableType in types)
|
||||
{
|
||||
var attribute = (Injectable) Attribute.GetCustomAttribute(injectableType, typeof(Injectable))!;
|
||||
var registerableType = injectableType;
|
||||
// if we have a type override this takes priority
|
||||
if (attribute.InjectableTypeOverride != null)
|
||||
{
|
||||
registerableType = attribute.InjectableTypeOverride;
|
||||
}
|
||||
// if this class only has 1 interface we register it on that interface
|
||||
else if (registerableType.GetInterfaces().Length == 1)
|
||||
{
|
||||
registerableType = registerableType.GetInterfaces()[0];
|
||||
}
|
||||
|
||||
switch (attribute.InjectionType)
|
||||
{
|
||||
case InjectionType.Singleton:
|
||||
builderServices.AddSingleton(registerableType, injectableType);
|
||||
break;
|
||||
case InjectionType.Transient:
|
||||
builderServices.AddTransient(registerableType, injectableType);
|
||||
break;
|
||||
case InjectionType.Scoped:
|
||||
builderServices.AddScoped(registerableType, injectableType);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void RegisterSptComponents(IServiceCollection builderServices)
|
||||
{
|
||||
// We get all the services from this assembly first, since mods will override them later
|
||||
RegisterComponents(builderServices, typeof(Program).Assembly.GetTypes()
|
||||
.Where(type => Attribute.IsDefined(type, typeof(Injectable))));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Exe</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Core\Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Helpers\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,9 @@
|
||||
using Types.Annotations;
|
||||
using Types.Servers;
|
||||
|
||||
namespace Server.Servers;
|
||||
|
||||
[Injectable(InjectionType.Singleton)]
|
||||
public class ConfigServer : IConfigServer
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
using System.Net.WebSockets;
|
||||
using System.Text;
|
||||
using Types.Annotations;
|
||||
using Types.Context;
|
||||
using Types.Models.Config;
|
||||
using Types.Servers;
|
||||
using Types.Services;
|
||||
using ILogger = Types.Models.Utils.ILogger;
|
||||
|
||||
namespace Server.Servers;
|
||||
|
||||
[Injectable(InjectionType.Singleton)]
|
||||
public class HttpServer : IHttpServer
|
||||
{
|
||||
protected HttpConfig httpConfig;
|
||||
protected bool started;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
private readonly ILocalisationService _localisationService;
|
||||
private readonly IConfigServer _configServer;
|
||||
private readonly IApplicationContext _applicationContext;
|
||||
private readonly IWebSocketServer _webSocketServer;
|
||||
|
||||
public HttpServer(
|
||||
ILogger logger,
|
||||
ILocalisationService localisationService,
|
||||
IConfigServer configServer,
|
||||
IApplicationContext applicationContext,
|
||||
IWebSocketServer webSocketServer
|
||||
)
|
||||
{
|
||||
_logger = logger;
|
||||
_localisationService = localisationService;
|
||||
_configServer = configServer;
|
||||
_applicationContext = applicationContext;
|
||||
_webSocketServer = webSocketServer;
|
||||
|
||||
// TODO: hook up the config server to put the HttpConfig here
|
||||
httpConfig = new HttpConfig() { Ip = "127.0.0.1", Port = 80 };
|
||||
}
|
||||
|
||||
public void Load(WebApplicationBuilder builder)
|
||||
{
|
||||
builder.WebHost.UseKestrel();
|
||||
//builder.Services.AddControllers();
|
||||
// At the end
|
||||
var app = builder.Build();
|
||||
|
||||
// enable web socket
|
||||
app.UseWebSockets();
|
||||
|
||||
app.UseRouting();
|
||||
app.UseEndpoints(endpointBuilder =>
|
||||
{
|
||||
endpointBuilder.MapFallback(HandleFallback);
|
||||
});
|
||||
started = true;
|
||||
app.Run($"http://{httpConfig.Ip}:{httpConfig.Port}");
|
||||
}
|
||||
|
||||
private Task HandleFallback(HttpContext context)
|
||||
{
|
||||
if (context.WebSockets.IsWebSocketRequest)
|
||||
{
|
||||
return context.WebSockets.AcceptWebSocketAsync()
|
||||
.ContinueWith(task => Converse(task.Result));
|
||||
}
|
||||
else
|
||||
{
|
||||
// This http request would be passed through the SPT Router and handled by an ICallback
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private void Converse(WebSocket connection)
|
||||
{
|
||||
var buffer = new byte[1024 * 4];
|
||||
var receive = connection.ReceiveAsync(
|
||||
new ArraySegment<byte>(buffer), CancellationToken.None);
|
||||
receive.Wait();
|
||||
var receiveResult = receive.Result;
|
||||
|
||||
while (!receiveResult.CloseStatus.HasValue)
|
||||
{
|
||||
connection.SendAsync(
|
||||
new ArraySegment<byte>(buffer, 0, receiveResult.Count),
|
||||
receiveResult.MessageType,
|
||||
receiveResult.EndOfMessage,
|
||||
CancellationToken.None);
|
||||
|
||||
receive = connection.ReceiveAsync(
|
||||
new ArraySegment<byte>(buffer), CancellationToken.None);
|
||||
receive.Wait();
|
||||
receiveResult = receive.Result;
|
||||
}
|
||||
|
||||
connection.CloseAsync(
|
||||
receiveResult.CloseStatus.Value,
|
||||
receiveResult.CloseStatusDescription,
|
||||
CancellationToken.None);
|
||||
}
|
||||
|
||||
public bool IsStarted() => started;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using Types.Annotations;
|
||||
using Types.Servers;
|
||||
|
||||
namespace Server.Servers;
|
||||
|
||||
[Injectable(InjectionType.Singleton)]
|
||||
public class WebSocketServer : IWebSocketServer
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using Types.Annotations;
|
||||
using Types.Services;
|
||||
|
||||
namespace Server.Services;
|
||||
|
||||
[Injectable(InjectionType.Singleton)]
|
||||
public class LocalisationService : ILocalisationService
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using Types.Annotations;
|
||||
using ILogger = Types.Models.Utils.ILogger;
|
||||
|
||||
namespace Server.Utils.Logging;
|
||||
|
||||
[Injectable(InjectionType.Singleton)]
|
||||
public class SimpleTextLogger : ILogger
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "Server\Server.csproj", "{1F5ED9C6-8B1F-4776-85AB-B387CBBC5557}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core", "Core\Core.csproj", "{AC8643DC-8779-4B4A-BBDA-2D4CC466F765}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{1F5ED9C6-8B1F-4776-85AB-B387CBBC5557}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1F5ED9C6-8B1F-4776-85AB-B387CBBC5557}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1F5ED9C6-8B1F-4776-85AB-B387CBBC5557}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1F5ED9C6-8B1F-4776-85AB-B387CBBC5557}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{AC8643DC-8779-4B4A-BBDA-2D4CC466F765}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AC8643DC-8779-4B4A-BBDA-2D4CC466F765}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AC8643DC-8779-4B4A-BBDA-2D4CC466F765}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AC8643DC-8779-4B4A-BBDA-2D4CC466F765}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
Reference in New Issue
Block a user