mirror of
https://github.com/MeowCraftMC/CrystalConnector
synced 2025-05-22 02:43:00 +00:00
@@ -8,19 +8,19 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0-preview.7.23375.6" />
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0-preview.7.23375.6"/>
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0-preview.7.23375.6" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0-preview.7.23375.6"/>
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0-preview.7.23375.6" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0-preview.7.23375.6"/>
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0-preview.7.23375.6" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0-preview.7.23375.6"/>
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0-preview.7.23375.6" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0-preview.7.23375.6"/>
|
||||||
<PackageReference Include="NLog" Version="5.2.4" />
|
<PackageReference Include="NLog" Version="5.2.4"/>
|
||||||
<PackageReference Include="NLog.Extensions.Hosting" Version="5.3.4" />
|
<PackageReference Include="NLog.Extensions.Hosting" Version="5.3.4"/>
|
||||||
<PackageReference Include="Spectre.Console" Version="0.47.1-preview.0.12" />
|
<PackageReference Include="Spectre.Console" Version="0.47.1-preview.0.12"/>
|
||||||
<PackageReference Include="Telegram.Bot" Version="19.0.0" />
|
<PackageReference Include="Telegram.Bot" Version="19.0.0"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
<FrameworkReference Include="Microsoft.AspNetCore.App"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
+47
-10
@@ -1,4 +1,6 @@
|
|||||||
using CrystalConnector;
|
using System.Net;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
using CrystalConnector;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
@@ -25,15 +27,6 @@ builder.ConfigureAppConfiguration((context, config) =>
|
|||||||
|
|
||||||
builder.UseContentRoot(Environment.CurrentDirectory);
|
builder.UseContentRoot(Environment.CurrentDirectory);
|
||||||
|
|
||||||
builder.ConfigureWebHost(webHost =>
|
|
||||||
{
|
|
||||||
webHost.UseStartup<Startup>();
|
|
||||||
|
|
||||||
webHost.UseKestrel(kestrel =>
|
|
||||||
{
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.ConfigureLogging(logging =>
|
builder.ConfigureLogging(logging =>
|
||||||
{
|
{
|
||||||
logging.ClearProviders()
|
logging.ClearProviders()
|
||||||
@@ -41,6 +34,50 @@ builder.ConfigureLogging(logging =>
|
|||||||
.AddNLog();
|
.AddNLog();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
builder.ConfigureWebHost(webHost =>
|
||||||
|
{
|
||||||
|
webHost.UseStartup<Startup>();
|
||||||
|
|
||||||
|
webHost.UseKestrel();
|
||||||
|
|
||||||
|
webHost.ConfigureKestrel((context, kestrel) =>
|
||||||
|
{
|
||||||
|
var config = context.Configuration;
|
||||||
|
foreach (var listener in config.GetSection("Server:Listener").GetChildren())
|
||||||
|
{
|
||||||
|
if (listener.GetValue<bool>("Enabled"))
|
||||||
|
{
|
||||||
|
var ipStr = listener.GetValue<string>("IP");
|
||||||
|
if (!IPAddress.TryParse(ipStr, out var ip))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var port = listener.GetValue<int>("Port");
|
||||||
|
|
||||||
|
var https = listener.GetSection("Https");
|
||||||
|
if (!https.GetValue<bool>("Enabled") || https.GetValue<string>("Cert") == null)
|
||||||
|
{
|
||||||
|
kestrel.Listen(ip, port);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var cert = https.GetValue<string>("Cert");
|
||||||
|
var password = https.GetValue<string>("Password");
|
||||||
|
|
||||||
|
kestrel.Listen(ip, port, listenOptions =>
|
||||||
|
{
|
||||||
|
listenOptions.UseHttps(httpsOptions =>
|
||||||
|
{
|
||||||
|
httpsOptions.ServerCertificate = X509Certificate2.CreateFromEncryptedPemFile(cert!, password);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
using var host = builder.Build();
|
using var host = builder.Build();
|
||||||
|
|
||||||
await host.RunAsync();
|
await host.RunAsync();
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using NLog;
|
||||||
|
|
||||||
namespace CrystalConnector;
|
namespace CrystalConnector;
|
||||||
|
|
||||||
public class Startup
|
public class Startup
|
||||||
{
|
{
|
||||||
public IConfiguration Config { get; }
|
private IConfiguration Config { get; }
|
||||||
|
|
||||||
|
private Logger Logger { get; } = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
public Startup(IConfiguration config)
|
public Startup(IConfiguration config)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
{
|
{
|
||||||
"server": {
|
"Server": {
|
||||||
"listen": [
|
"Listener": [
|
||||||
{
|
{
|
||||||
"enabled": true,
|
"Enabled": true,
|
||||||
"ip": "0.0.0.0",
|
"IP": "0.0.0.0",
|
||||||
"port": 33927,
|
"Port": 33927,
|
||||||
"https": {
|
"Https": {
|
||||||
"enabled": false,
|
"Enabled": false,
|
||||||
"cert": "cert.pfx",
|
"Cert": "cert.pfx",
|
||||||
"password": ""
|
"Password": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user