Skip to content

Commit

Permalink
Configurable Connection-Key
Browse files Browse the repository at this point in the history
proepkes committed Jul 15, 2018
1 parent 6ac8860 commit 12554e1
Showing 5 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions ConsoleGameServer.Example/ConsoleGameServer.Example.csproj
Original file line number Diff line number Diff line change
@@ -8,4 +8,9 @@
<ProjectReference Include="..\SpeedDate.ClientPlugins.GameServer\SpeedDate.ClientPlugins.GameServer.csproj" />
<ProjectReference Include="..\SpeedDate.Client\SpeedDate.Client.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="GameServerConfig.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion ConsoleGameServer.Example/GameServerConfig.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<Network Address="127.0.0.1" Port="8888"/>
<Network Address="127.0.0.1" Port="60125"/>
<Plugins Namespaces="SpeedDate.ClientPlugins;SpeedDate.ClientPlugins.GameServer*" ExcludeDlls="host*"/>
</configuration>
4 changes: 2 additions & 2 deletions SpeedDate.Client/SpeedDateClient.cs
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ void StartAfterStop()

AppUpdater.Instance.Add(this);
_manager.Start();
_netPeer = _manager.Connect(Config.Network.Address, Config.Network.Port, "TundraNet");
_netPeer = _manager.Connect(Config.Network.Address, Config.Network.Port, Config.Network.Key);
}

Stopped += StartAfterStop;
@@ -193,7 +193,7 @@ public void Start(IConfigProvider configProvider)
Config = config;

_manager.Start();
_netPeer = _manager.Connect(config.Network.Address, config.Network.Port, "TundraNet");
_netPeer = _manager.Connect(config.Network.Address, config.Network.Port, config.Network.Key);
});
}

5 changes: 4 additions & 1 deletion SpeedDate.Server/SpeedDateServer.cs
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ public sealed class SpeedDateServer : IServer, ISpeedDateStartable, IDisposable,

private readonly NetManager _manager;
private SpeedDateNetListener _listener;
private SpeedDateConfig _config;

public event Action Started;
public event Action Stopped;
@@ -35,7 +36,7 @@ public SpeedDateServer()
_listener = new SpeedDateNetListener();
_listener.ConnectionRequestEvent += request =>
{
request.AcceptIfKey("TundraNet");
request.AcceptIfKey(_config.Network.Key);
};

_listener.PeerConnectedEvent += peer =>
@@ -82,6 +83,8 @@ public void Start(IConfigProvider configProvider)
{
_kernel.Load(this, configProvider, config =>
{
_config = config;

AppUpdater.Instance.Add(this);
if (_manager.Start(config.Network.Port))
{
4 changes: 2 additions & 2 deletions SpeedDate/Configuration/SpeedDateConfig.cs
Original file line number Diff line number Diff line change
@@ -57,14 +57,14 @@ public override string ToString()
return $"{Address}:{Port}";
}

public NetworkConfig(string address = default(string), int port = default(int), string key = "TundraNet")
public NetworkConfig(string address = default(string), int port = default(int), string key = "SpeedDate")
{
Address = address;
Port = port;
Key = key;
}

public NetworkConfig(IPAddress address, int port = default(int), string key = "TundraNet")
public NetworkConfig(IPAddress address, int port = default(int), string key = "SpeedDate")
{
Address = address.ToString();
Port = port;

0 comments on commit 12554e1

Please sign in to comment.