Skip to content

Commit

Permalink
Updating config
Browse files Browse the repository at this point in the history
  • Loading branch information
cubicgraphics committed May 11, 2024
1 parent c453ba7 commit 3628d6b
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ namespace BeatTogether.DedicatedServer.Instancing.Configuration
{
public sealed class InstancingConfiguration
{
//public string HostName { get; set; } = "192.168.0.21";
public string HostName { get; set; } = "127.0.0.1";
public string HostEndpoint { get; set; } = "127.0.0.1";
public int BasePort { get; set; } = 30000;
public int MaximumSlots { get; set; } = 10000;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static IHostBuilder UseDedicatedServerInstancing(this IHostBuilder hostBu
.UseDedicatedInstances()
.ConfigureServices((hostBuilderContext, services) =>
services
.AddConfiguration<InstancingConfiguration>("Instancing")
.AddConfiguration<InstancingConfiguration>("ServerConfiguration")
.AddSingleton<IPortAllocator, PortAllocator>()
.AddSingleton<IInstanceRegistry, InstanceRegistry>()
.AddSingleton<IInstanceFactory, InstanceFactory>()
Expand Down
2 changes: 1 addition & 1 deletion BeatTogether.DedicatedServer.Instancing/InstanceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public InstanceFactory(
}
instance.StopEvent += HandleStopEvent;

serverInstance.InstanceEndPoint = IPEndPoint.Parse($"{_config.HostName}:{instanceConfig.Port}");
serverInstance.InstanceEndPoint = IPEndPoint.Parse($"{_config.HostEndpoint}:{instanceConfig.Port}");

//Subscribe to server events if the layer above allows this.
if(_SendEventsLayer != null)
Expand Down
6 changes: 3 additions & 3 deletions BeatTogether.DedicatedServer.Instancing/LayerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Task DisconnectPlayer(string InstanceSecret, string PlayerUserId)
IServerInstance? serverInstance = null;
if (_instanceRegistry.TryGetAvailablePublicServer(invitePolicy, serverMode, songMode, serverControlSettings, difficultyMask, modifiersMask, songPackMasks, out var instance))
{
serverInstance = new ServerInstance(instance, IPEndPoint.Parse($"{_instancingConfiguration.HostName}:{instance._configuration.Port}"));
serverInstance = new ServerInstance(instance, IPEndPoint.Parse($"{_instancingConfiguration.HostEndpoint}:{instance._configuration.Port}"));
}
return Task.FromResult(serverInstance);
}
Expand All @@ -65,7 +65,7 @@ public Task DisconnectPlayer(string InstanceSecret, string PlayerUserId)
IServerInstance? serverInstance = null;
if (_instanceRegistry.TryGetInstance(secret, out var instance))
{
serverInstance = new ServerInstance(instance, IPEndPoint.Parse($"{_instancingConfiguration.HostName}:{instance._configuration.Port}"));
serverInstance = new ServerInstance(instance, IPEndPoint.Parse($"{_instancingConfiguration.HostEndpoint}:{instance._configuration.Port}"));
}
return Task.FromResult(serverInstance);
}
Expand All @@ -75,7 +75,7 @@ public Task DisconnectPlayer(string InstanceSecret, string PlayerUserId)
IServerInstance? serverInstance = null;
if (_instanceRegistry.TryGetInstanceByCode(code, out var instance))
{
serverInstance = new ServerInstance(instance, IPEndPoint.Parse($"{_instancingConfiguration.HostName}:{instance._configuration.Port}"));
serverInstance = new ServerInstance(instance, IPEndPoint.Parse($"{_instancingConfiguration.HostEndpoint}:{instance._configuration.Port}"));
}
return Task.FromResult(serverInstance);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ namespace BeatTogether.DedicatedServer.Node.Configuration
{
public sealed class NodeConfiguration
{
//public string HostName { get; set; } = "192.168.0.21";
public string HostName { get; set; } = "127.0.0.1";
public string HostEndpoint { get; set; } = "127.0.0.1";
public Version NodeVersion { get; } = new Version(2,0,0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static IHostBuilder UseDedicatedServerNode(this IHostBuilder hostBuilder)
.UseAutobus()
.ConfigureServices((hostBuilderContext, services) =>
services
.AddConfiguration<NodeConfiguration>("Node")
.AddConfiguration<NodeConfiguration>("ServerConfiguration")
.AddServiceKernel<IMatchmakingService, NodeMatchmakingService>()
.AddSingleton<ILayer1, ForwardServerEventsLayer>()
.AddHostedService<NodeMessageEventHandler>()
Expand Down
10 changes: 5 additions & 5 deletions BeatTogether.DedicatedServer.Node/NodeMessageEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public Task StartAsync(CancellationToken cancellationToken)
_autobus.Subscribe<CheckNodesEvent>(HandleCheckNode);
_autobus.Subscribe<DisconnectPlayerFromMatchmakingServerEvent>(HandleDisconnectPlayer);
_autobus.Subscribe<CloseServerInstanceEvent>(HandleCloseServer);
_autobus.Publish(new NodeStartedEvent(_configuration.HostName, _configuration.NodeVersion.ToString()));
_logger.Information("Dedicated node version: " + _configuration.NodeVersion.ToString() + " starting: " + _configuration.HostName);
_autobus.Publish(new NodeStartedEvent(_configuration.HostEndpoint, _configuration.NodeVersion.ToString()));
_logger.Information("Dedicated node version: " + _configuration.NodeVersion.ToString() + ". Host Endpoint: " + _configuration.HostEndpoint);
return Task.CompletedTask;
}

Expand All @@ -68,20 +68,20 @@ public Task StopAsync(CancellationToken cancellationToken)

private async Task HandlePlayerConnectedToMatchmaking(PlayerSessionDataSendToDediEvent SessionDataEvent)
{
if (SessionDataEvent.NodeEndpoint != _configuration.HostName)
if (SessionDataEvent.NodeEndpoint != _configuration.HostEndpoint)
return;

Core.Abstractions.IPlayer player = new PlayerFromMessage(SessionDataEvent.Player);
if (!await _Layer2.SetPlayerSessionData(SessionDataEvent.serverInstanceSecret, player))
return;

_autobus.Publish(new NodeReceivedPlayerSessionDataEvent(_configuration.HostName, SessionDataEvent.Player.PlayerSessionId));
_autobus.Publish(new NodeReceivedPlayerSessionDataEvent(_configuration.HostEndpoint, SessionDataEvent.Player.PlayerSessionId));
return;
}

private Task HandleCheckNode(CheckNodesEvent checkNodesEvent)
{
_autobus.Publish(new NodeOnlineEvent(_configuration.HostName, _configuration.NodeVersion.ToString()));
_autobus.Publish(new NodeOnlineEvent(_configuration.HostEndpoint, _configuration.NodeVersion.ToString()));
return Task.CompletedTask;
}

Expand Down
3 changes: 3 additions & 0 deletions BeatTogether.DedicatedServer/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"Overrides": {
"Microsoft": "Warning"
}
},
"ServerConfiguration": {
"HostEndpoint": "127.0.0.1"
}
}
}
3 changes: 3 additions & 0 deletions BeatTogether.DedicatedServer/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"Serilog": {
"File": {
"Path": "logs/BeatTogether.DedicatedServer-{Date}.log"
},
"ServerConfiguration": {
"HostEndpoint": "127.0.0.1"
}
}
}

0 comments on commit 3628d6b

Please sign in to comment.