Gateway configuration in appsettings.json
This commit is contained in:
parent
7392b2d20a
commit
7921b2149e
5 changed files with 38 additions and 3 deletions
|
@ -16,4 +16,10 @@
|
|||
<ProjectReference Include="..\Protocol\Protocol.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
using System.Buffers.Binary;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using GameServer.Settings;
|
||||
using KcpSharp;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace GameServer.Network.Kcp;
|
||||
internal class KcpGateway
|
||||
|
@ -15,21 +17,22 @@ internal class KcpGateway
|
|||
private const byte NetFlagAck = 0xEE;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOptions<GatewaySettings> _options;
|
||||
private readonly SessionManager _sessionManager;
|
||||
|
||||
private IKcpTransport<IKcpMultiplexConnection>? _kcpTransport;
|
||||
private int _convCounter;
|
||||
|
||||
public KcpGateway(ILogger<KcpGateway> logger, SessionManager sessionManager)
|
||||
public KcpGateway(ILogger<KcpGateway> logger, IOptions<GatewaySettings> options, SessionManager sessionManager)
|
||||
{
|
||||
_logger = logger;
|
||||
_options = options;
|
||||
_sessionManager = sessionManager;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
IPEndPoint endPoint = new(IPAddress.Any, 1337);
|
||||
|
||||
IPEndPoint endPoint = _options.Value.EndPoint;
|
||||
_kcpTransport = KcpSocketTransport.CreateMultiplexConnection(new(endPoint), 1400);
|
||||
_kcpTransport.SetHandshakeHandler(KcpSynPacketSize, HandleKcpSynPacket);
|
||||
_kcpTransport.Start();
|
||||
|
|
|
@ -6,8 +6,10 @@ using GameServer.Network;
|
|||
using GameServer.Network.Kcp;
|
||||
using GameServer.Network.Messages;
|
||||
using GameServer.Network.Rpc;
|
||||
using GameServer.Settings;
|
||||
using GameServer.Systems.Entity;
|
||||
using GameServer.Systems.Event;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
@ -21,6 +23,8 @@ internal static class Program
|
|||
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
|
||||
builder.Logging.AddConsole();
|
||||
|
||||
builder.Services.Configure<GatewaySettings>(builder.Configuration.GetRequiredSection("Gateway"));
|
||||
|
||||
builder.Services.AddControllers()
|
||||
.AddSingleton<KcpGateway>().AddScoped<PlayerSession>()
|
||||
.AddScoped<MessageManager>().AddSingleton<EventHandlerFactory>()
|
||||
|
|
17
GameServer/Settings/GatewaySettings.cs
Normal file
17
GameServer/Settings/GatewaySettings.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using System.Net;
|
||||
|
||||
namespace GameServer.Settings;
|
||||
internal class GatewaySettings
|
||||
{
|
||||
public required string Host { get; set; }
|
||||
|
||||
public IPEndPoint EndPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
string[] split = Host.Split(':');
|
||||
|
||||
return new IPEndPoint(IPAddress.Parse(split[0]), int.Parse(split[1]));
|
||||
}
|
||||
}
|
||||
}
|
5
GameServer/appsettings.json
Normal file
5
GameServer/appsettings.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"Gateway": {
|
||||
"Host": "0.0.0.0:1337"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue