Fixes #81 - Adds hostname support to the config file

This commit is contained in:
AeonLucid committed 2020-10-26 19:43:20 +01:00
1 parent 39bfc139f8
commit 9e55a9738b
8 files changed
+91 -10

No files matched your search

+1 -1
View File
@@ -10,7 +10,7 @@ We support steam, itch, android and iOS. The latest version supported is `2020.9
| Impostor version | Among Us version | Experimental | Download |
|-|-|-|-|
| 1.1.0 | 2020.09.07 - 2020.09.22 | No | [![Download](https://img.shields.io/badge/Download-v1.1.0-blue?style=flat-square)](https://github.com/Impostor/Impostor/releases/tag/v1.1.0) |
| 1.2.1 | 2020.09.22 - 2020.10.22 | Yes | [![Download](https://img.shields.io/badge/Download-v1.2.1-blue?style=flat-square)](https://ci.appveyor.com/project/Impostor/Impostor/branch/dev/artifacts) |
| 1.2.2 | 2020.09.22 - 2020.10.22 | Yes | [![Download](https://img.shields.io/badge/Download-v1.2.2-blue?style=flat-square)](https://ci.appveyor.com/project/Impostor/Impostor/branch/dev/artifacts) |
There are no special features at this moment, the goal is aiming to be as close as possible to the real server, for now. In a later stage, making modifications to game logic by modifying `GameData` packets can be looked at.
+1 -1
View File
@@ -1,7 +1,7 @@
version: '{build}'
environment:
IMPOSTOR_VERSION: '1.2.1'
IMPOSTOR_VERSION: '1.2.2'
DOTNET_CLI_TELEMETRY_OPTOUT: 1
branches:
+2 -2
View File
@@ -8,9 +8,9 @@ Some information about all the possible configurations. Click [here](https://git
| Key | Default | Description |
|-|-|-|
| **PublicIp** | `127.0.0.1` | This needs to the IPv4 address of the server, what you give to others to connect. You can find the your IPv4 address [here](http://whatismyip.host/). |
| **PublicIp** | `127.0.0.1` | This needs to the IPv4 address of the server, what you give to others to connect. You can find the your IPv4 address [here](http://whatismyip.host/). Since 1.2.2 it is also possible to use hostnames instead of IPv4 addresses, these must resolve to a valid IPv4 address. |
| **PublicPort** | `22023` | The public port of the server, what you give to others to connect. Usually `22023`. |
| **ListenIp** | `0.0.0.0` | The network interface to listen on. If you do not know what to put here, use `0.0.0.0`. |
| **ListenIp** | `0.0.0.0` | The network interface to listen on. If you do not know what to put here, use `0.0.0.0`. Since 1.2.2 it is also possible to use hostnames instead of IPv4 addresses, these must resolve to a valid IPv4 address. |
| **ListenPort** | `22023` | The listen port of the server, usually `22023`. |
### AntiCheat
@@ -0,0 +1,24 @@
using System;
using System.Runtime.Serialization;
namespace Impostor.Api
{
public class ImpostorConfigException : ImpostorException
{
public ImpostorConfigException()
{
}
protected ImpostorConfigException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public ImpostorConfigException(string? message) : base(message)
{
}
public ImpostorConfigException(string? message, Exception? innerException) : base(message, innerException)
{
}
}
}
+17 -2
View File
@@ -1,7 +1,12 @@
namespace Impostor.Server.Config
using Impostor.Server.Utils;
namespace Impostor.Server.Config
{
internal class ServerConfig
{
private string? _resolvedPublicIp;
private string? _resolvedListenIp;
public const string Section = "Server";
public string PublicIp { get; set; } = "127.0.0.1";
@@ -11,5 +16,15 @@
public string ListenIp { get; set; } = "127.0.0.1";
public ushort ListenPort { get; set; } = 22023;
public string ResolvePublicIp()
{
return _resolvedPublicIp ??= IpUtils.ResolveIp(PublicIp);
}
public string ResolveListenIp()
{
return _resolvedListenIp ??= IpUtils.ResolveIp(ListenIp);
}
}
}
}
@@ -36,7 +36,7 @@ namespace Impostor.Server.Net.Manager
_serviceProvider = serviceProvider;
_eventManager = eventManager;
_gameCodeFactory = gameCodeFactory;
_publicIp = new IPEndPoint(IPAddress.Parse(config.Value.PublicIp), config.Value.PublicPort);
_publicIp = new IPEndPoint(IPAddress.Parse(config.Value.ResolvePublicIp()), config.Value.PublicPort);
_games = new ConcurrentDictionary<int, Game>();
}
+3 -3
View File
@@ -29,7 +29,7 @@ namespace Impostor.Server.Net
public async Task StartAsync(CancellationToken cancellationToken)
{
var endpoint = new IPEndPoint(IPAddress.Parse(_serverConfig.ListenIp), _serverConfig.ListenPort);
var endpoint = new IPEndPoint(IPAddress.Parse(_serverConfig.ResolveListenIp()), _serverConfig.ListenPort);
await _matchmaker.StartAsync(endpoint);
@@ -37,7 +37,7 @@ namespace Impostor.Server.Net
"Matchmaker is listening on {0}:{1}, the public server ip is {2}:{3}.",
endpoint.Address,
endpoint.Port,
_serverConfig.PublicIp,
_serverConfig.ResolvePublicIp(),
_serverConfig.PublicPort);
if (_redirectorConfig.Enabled)
@@ -54,4 +54,4 @@ namespace Impostor.Server.Net
await _matchmaker.StopAsync();
}
}
}
}
+42
View File
@@ -0,0 +1,42 @@
using System.Linq;
using System.Net;
using System.Net.Sockets;
using Impostor.Api;
namespace Impostor.Server.Utils
{
internal static class IpUtils
{
public static string ResolveIp(string ip)
{
// Check if valid ip was entered.
if (!IPAddress.TryParse(ip, out var ipAddress))
{
// Attempt to resolve DNS.
try
{
var hostAddresses = Dns.GetHostAddresses(ip);
if (hostAddresses.Length == 0)
{
throw new ImpostorConfigException($"Invalid IP Address entered '{ip}'.");
}
// Use first IPv4 result.
ipAddress = hostAddresses.First(x => x.AddressFamily == AddressFamily.InterNetwork);
}
catch (SocketException)
{
throw new ImpostorConfigException($"Failed to resolve hostname '{ip}'.");
}
}
// Only IPv4.
if (ipAddress.AddressFamily == AddressFamily.InterNetworkV6)
{
throw new ImpostorConfigException($"Invalid IP Address entered '{ipAddress}', only IPv4 is supported by Among Us.");
}
return ipAddress.ToString();
}
}
}