-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
229 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,47 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.8.34525.116 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "A2SService", "A2SService\A2SService.csproj", "{64F34E17-19DD-47B0-BF4B-5C7BD34B99E5}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "UnitTests\UnitTests.csproj", "{2C00A9D7-DC9F-4A9F-8A34-E5AC09604B4E}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{64F34E17-19DD-47B0-BF4B-5C7BD34B99E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{64F34E17-19DD-47B0-BF4B-5C7BD34B99E5}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{64F34E17-19DD-47B0-BF4B-5C7BD34B99E5}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{64F34E17-19DD-47B0-BF4B-5C7BD34B99E5}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{2C00A9D7-DC9F-4A9F-8A34-E5AC09604B4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{2C00A9D7-DC9F-4A9F-8A34-E5AC09604B4E}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{2C00A9D7-DC9F-4A9F-8A34-E5AC09604B4E}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{2C00A9D7-DC9F-4A9F-8A34-E5AC09604B4E}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {73DD4E4E-B4EB-472F-93D9-1AE45DFF4741} | ||
EndGlobalSection | ||
EndGlobal | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.8.34525.116 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "A2SService", "A2SService\A2SService.csproj", "{64F34E17-19DD-47B0-BF4B-5C7BD34B99E5}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests", "UnitTests\UnitTests.csproj", "{2C00A9D7-DC9F-4A9F-8A34-E5AC09604B4E}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{41CD9BD9-5437-40D2-A8F1-D3CCB5AA8AA9}" | ||
ProjectSection(SolutionItems) = preProject | ||
.editorconfig = .editorconfig | ||
.gitignore = .gitignore | ||
common.props = common.props | ||
LICENSE = LICENSE | ||
NuGet.Config = NuGet.Config | ||
README.md = README.md | ||
EndProjectSection | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FakeA2SServer", "FakeA2SServer\FakeA2SServer.csproj", "{7402E4BF-BEEE-4EBA-B016-B8CBFE62862F}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{64F34E17-19DD-47B0-BF4B-5C7BD34B99E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{64F34E17-19DD-47B0-BF4B-5C7BD34B99E5}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{64F34E17-19DD-47B0-BF4B-5C7BD34B99E5}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{64F34E17-19DD-47B0-BF4B-5C7BD34B99E5}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{2C00A9D7-DC9F-4A9F-8A34-E5AC09604B4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{2C00A9D7-DC9F-4A9F-8A34-E5AC09604B4E}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{2C00A9D7-DC9F-4A9F-8A34-E5AC09604B4E}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{2C00A9D7-DC9F-4A9F-8A34-E5AC09604B4E}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{7402E4BF-BEEE-4EBA-B016-B8CBFE62862F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{7402E4BF-BEEE-4EBA-B016-B8CBFE62862F}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{7402E4BF-BEEE-4EBA-B016-B8CBFE62862F}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{7402E4BF-BEEE-4EBA-B016-B8CBFE62862F}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {73DD4E4E-B4EB-472F-93D9-1AE45DFF4741} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
namespace FakeA2SServer; | ||
|
||
[UsedImplicitly] | ||
public class A2SServerService : ITransientDependency | ||
{ | ||
public required IAbpLazyServiceProvider LazyServiceProvider { get; [UsedImplicitly] init; } | ||
|
||
private ILogger<A2SServerService> Logger => LazyServiceProvider.LazyGetRequiredService<ILogger<A2SServerService>>(); | ||
|
||
private IConfiguration Configuration => LazyServiceProvider.LazyGetRequiredService<IConfiguration>(); | ||
|
||
private readonly CancellationTokenSource _cts = new(); | ||
|
||
private A2SServer? _server; | ||
|
||
public async ValueTask StartAsync() | ||
{ | ||
IPEndPoint serverAddress = IPEndPoint.Parse(Configuration.GetValue(@"A2SListenEndpoint", @"[::]:27015")!); | ||
|
||
_server = new A2SServer(serverAddress); | ||
if (Equals(serverAddress.Address, IPAddress.IPv6Any)) | ||
{ | ||
_server.Server.Client.DualMode = true; | ||
} | ||
|
||
const string prefix = @"A2S"; | ||
|
||
_server.A2SInfo = new A2SInfo | ||
{ | ||
Protocol = Configuration.GetValue<byte>(prefix + nameof(A2SInfo.Protocol)), | ||
Name = Configuration.GetValue<string?>(prefix + nameof(A2SInfo.Name)), | ||
Map = Configuration.GetValue<string?>(prefix + nameof(A2SInfo.Map)), | ||
Folder = Configuration.GetValue<string?>(prefix + nameof(A2SInfo.Folder)), | ||
Game = Configuration.GetValue<string?>(prefix + nameof(A2SInfo.Game)), | ||
ID = (short)Configuration.GetValue<ushort>(prefix + nameof(A2SInfo.ID)), | ||
Players = Configuration.GetValue<byte>(prefix + nameof(A2SInfo.Players)), | ||
MaxPlayers = Configuration.GetValue<byte>(prefix + nameof(A2SInfo.MaxPlayers)), | ||
Bots = Configuration.GetValue<byte>(prefix + nameof(A2SInfo.Bots)), | ||
ServerType = Configuration.GetValue(prefix + nameof(A2SInfo.ServerType), A2SType.Dedicated), | ||
Environment = Configuration.GetValue(prefix + nameof(A2SInfo.Environment), _server.A2SInfo.Environment), | ||
Visibility = Configuration.GetValue<A2SVisibility>(prefix + nameof(A2SInfo.Visibility)), | ||
Vac = Configuration.GetValue<A2SVacStatus>(prefix + nameof(A2SInfo.Vac)), | ||
Version = Configuration.GetValue<string?>(prefix + nameof(A2SInfo.Version)), | ||
Port = (short)Configuration.GetValue(prefix + nameof(A2SInfo.Port), (ushort)serverAddress.Port), | ||
SteamID = (long)Configuration.GetValue<ulong>(prefix + nameof(A2SInfo.SteamID)), | ||
SourceTvPort = (short)Configuration.GetValue<ushort>(prefix + nameof(A2SInfo.SourceTvPort)), | ||
SourceTvName = Configuration.GetValue<string?>(prefix + nameof(A2SInfo.SourceTvName)), | ||
Keywords = Configuration.GetValue<string?>(prefix + nameof(A2SInfo.Keywords)), | ||
GameID = (long)Configuration.GetValue<ulong>(prefix + nameof(A2SInfo.GameID)) | ||
}; | ||
|
||
_cts.Token.Register(() => _server.Dispose()); | ||
|
||
ValueTask _ = _server.StartAsync(_cts.Token); | ||
|
||
Logger.LogInformation(@"A2S Server listen on {endpoint}: {info}", serverAddress, _server.A2SInfo); | ||
|
||
await ValueTask.CompletedTask; | ||
} | ||
|
||
public async ValueTask StopAsync() | ||
{ | ||
await _cts.CancelAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<Import Project="..\common.props" /> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" /> | ||
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" /> | ||
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" /> | ||
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" /> | ||
<PackageReference Include="Volo.Abp.Autofac" Version="8.0.3" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\A2SService\A2SService.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace FakeA2SServer; | ||
|
||
public class FakeA2SServerHostedService : IHostedService | ||
{ | ||
public required IAbpLazyServiceProvider LazyServiceProvider { get; [UsedImplicitly] init; } | ||
|
||
private A2SServerService Service => LazyServiceProvider.LazyGetRequiredService<A2SServerService>(); | ||
|
||
public async Task StartAsync(CancellationToken cancellationToken) | ||
{ | ||
await Service.StartAsync(); | ||
} | ||
|
||
public async Task StopAsync(CancellationToken cancellationToken) | ||
{ | ||
await Service.StopAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
global using A2SService; | ||
global using FakeA2SServer; | ||
global using JetBrains.Annotations; | ||
global using Microsoft.Extensions.Configuration; | ||
global using Microsoft.Extensions.DependencyInjection; | ||
global using Microsoft.Extensions.Hosting; | ||
global using Microsoft.Extensions.Logging; | ||
global using Serilog; | ||
global using Serilog.Events; | ||
global using System.Net; | ||
global using Volo.Abp; | ||
global using Volo.Abp.Autofac; | ||
global using Volo.Abp.DependencyInjection; | ||
global using Volo.Abp.Modularity; | ||
|
||
namespace FakeA2SServer; | ||
|
||
[DependsOn( | ||
typeof(AbpAutofacModule) | ||
)] | ||
[UsedImplicitly] | ||
internal class FakeA2SServerModule : AbpModule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
Log.Logger = new LoggerConfiguration() | ||
#if DEBUG | ||
.MinimumLevel.Debug() | ||
#else | ||
.MinimumLevel.Information() | ||
#endif | ||
.MinimumLevel.Override(@"Microsoft", LogEventLevel.Information) | ||
.MinimumLevel.Override(@"Volo.Abp", LogEventLevel.Warning) | ||
.Enrich.FromLogContext() | ||
.WriteTo.Async(c => c.Console(outputTemplate: @"[{Timestamp:O}] [{Level}] {Message:lj}{NewLine}{Exception}")) | ||
.CreateLogger(); | ||
|
||
try | ||
{ | ||
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args); | ||
|
||
builder.Logging.ClearProviders().AddSerilog(); | ||
|
||
builder.ConfigureContainer(builder.Services.AddAutofacServiceProviderFactory()); | ||
|
||
builder.Services.AddHostedService<FakeA2SServerHostedService>(); | ||
|
||
await builder.Services.AddApplicationAsync<FakeA2SServerModule>(); | ||
|
||
using IHost host = builder.Build(); | ||
|
||
await host.InitializeAsync(); | ||
|
||
await host.RunAsync(); | ||
|
||
return 0; | ||
} | ||
catch (HostAbortedException) | ||
{ | ||
throw; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Fatal(ex, @"Host terminated unexpectedly!"); | ||
return 1; | ||
} | ||
finally | ||
{ | ||
Log.CloseAndFlush(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters