]> git.deb.at Git - rhonda/impostor.git/commitdiff
Move config files to API
authorminiduikboot <mini@duikbo.at>
Mon, 29 Aug 2022 17:02:36 +0000 (19:02 +0200)
committerminiduikboot <mini@duikbo.at>
Mon, 29 Aug 2022 18:57:16 +0000 (20:57 +0200)
This makes it possible to access these from a plugin

28 files changed:
src/Impostor.Api/Config/AntiCheatConfig.cs [new file with mode: 0644]
src/Impostor.Api/Config/CompatibilityConfig.cs [new file with mode: 0644]
src/Impostor.Api/Config/DebugConfig.cs [new file with mode: 0644]
src/Impostor.Api/Config/DisconnectMessages.cs [new file with mode: 0644]
src/Impostor.Api/Config/ServerConfig.cs [new file with mode: 0644]
src/Impostor.Api/Config/ServerRedirectorConfig.cs [new file with mode: 0644]
src/Impostor.Api/Config/ServerRedirectorNode.cs [new file with mode: 0644]
src/Impostor.Api/Utils/IpUtils.cs [new file with mode: 0644]
src/Impostor.Server/Config/AntiCheatConfig.cs [deleted file]
src/Impostor.Server/Config/CompatibilityConfig.cs [deleted file]
src/Impostor.Server/Config/DebugConfig.cs [deleted file]
src/Impostor.Server/Config/DisconnectMessages.cs [deleted file]
src/Impostor.Server/Config/ServerConfig.cs [deleted file]
src/Impostor.Server/Config/ServerRedirectorConfig.cs [deleted file]
src/Impostor.Server/Config/ServerRedirectorNode.cs [deleted file]
src/Impostor.Server/Net/Client.cs
src/Impostor.Server/Net/Manager/ClientManager.cs
src/Impostor.Server/Net/Manager/GameManager.cs
src/Impostor.Server/Net/MatchmakerService.cs
src/Impostor.Server/Net/Redirector/ClientRedirector.cs
src/Impostor.Server/Net/Redirector/NodeLocatorUDP.cs
src/Impostor.Server/Net/Redirector/NodeLocatorUDPService.cs
src/Impostor.Server/Net/Redirector/NodeProviderConfig.cs
src/Impostor.Server/Net/State/Game.cs
src/Impostor.Server/Program.cs
src/Impostor.Server/Recorder/ClientRecorder.cs
src/Impostor.Server/Recorder/PacketRecorder.cs
src/Impostor.Server/Utils/IpUtils.cs [deleted file]

diff --git a/src/Impostor.Api/Config/AntiCheatConfig.cs b/src/Impostor.Api/Config/AntiCheatConfig.cs
new file mode 100644 (file)
index 0000000..d9eb532
--- /dev/null
@@ -0,0 +1,11 @@
+namespace Impostor.Api.Config
+{
+    public class AntiCheatConfig
+    {
+        public const string Section = "AntiCheat";
+
+        public bool Enabled { get; set; } = true;
+
+        public bool BanIpFromGame { get; set; } = true;
+    }
+}
diff --git a/src/Impostor.Api/Config/CompatibilityConfig.cs b/src/Impostor.Api/Config/CompatibilityConfig.cs
new file mode 100644 (file)
index 0000000..c18c7d8
--- /dev/null
@@ -0,0 +1,11 @@
+namespace Impostor.Api.Config
+{
+    public class CompatibilityConfig
+    {
+        public const string Section = "Compatibility";
+
+        public bool AllowFutureGameVersions { get; set; } = false;
+
+        public bool AllowVersionMixing { get; set; } = false;
+    }
+}
diff --git a/src/Impostor.Api/Config/DebugConfig.cs b/src/Impostor.Api/Config/DebugConfig.cs
new file mode 100644 (file)
index 0000000..47cddac
--- /dev/null
@@ -0,0 +1,11 @@
+namespace Impostor.Api.Config
+{
+    public class DebugConfig
+    {
+        public const string Section = "Debug";
+
+        public bool GameRecorderEnabled { get; set; }
+
+        public string GameRecorderPath { get; set; } = string.Empty;
+    }
+}
diff --git a/src/Impostor.Api/Config/DisconnectMessages.cs b/src/Impostor.Api/Config/DisconnectMessages.cs
new file mode 100644 (file)
index 0000000..353b79b
--- /dev/null
@@ -0,0 +1,30 @@
+namespace Impostor.Api.Config
+{
+    public static class DisconnectMessages
+    {
+        public const string Error = "There was an internal server error. " +
+                                    "Check the server console for more information. " +
+                                    "Please report the issue on the Impostor GitHub if it keeps happening.";
+
+        public const string ClientOutdated = "Please update your game to play in this lobby.";
+
+        public const string ClientTooNew = "Your game version is too new for this lobby. " +
+                                           "If you want to join this lobby you need to downgrade your client.";
+
+        public const string Destroyed = "The game you tried to join is being destroyed. " +
+                                        "Please create a new game.";
+
+        public const string NotImplemented = "Game listing has not been implemented in Impostor yet for servers " +
+                                             "running in server redirection mode.";
+
+        public const string UsernameLength = "Your username is too long, please make it shorter.";
+
+        public const string UsernameIllegalCharacters = "Your username contains illegal characters, please remove them.";
+
+        public const string VersionClientTooOld = "Please update your game to play on this server.";
+
+        public const string VersionServerTooOld = "Your client is too new, please update your Impostor server to play.";
+
+        public const string VersionUnsupported = "Your client version is unsupported, please update your Game and/or Impostor server.";
+    }
+}
diff --git a/src/Impostor.Api/Config/ServerConfig.cs b/src/Impostor.Api/Config/ServerConfig.cs
new file mode 100644 (file)
index 0000000..afcca03
--- /dev/null
@@ -0,0 +1,30 @@
+using Impostor.Api.Utils;
+
+namespace Impostor.Api.Config
+{
+    public class ServerConfig
+    {
+        public const string Section = "Server";
+
+        private string? _resolvedPublicIp;
+        private string? _resolvedListenIp;
+
+        public string PublicIp { get; set; } = "127.0.0.1";
+
+        public ushort PublicPort { get; set; } = 22023;
+
+        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);
+        }
+    }
+}
diff --git a/src/Impostor.Api/Config/ServerRedirectorConfig.cs b/src/Impostor.Api/Config/ServerRedirectorConfig.cs
new file mode 100644 (file)
index 0000000..0d11ab1
--- /dev/null
@@ -0,0 +1,27 @@
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+
+namespace Impostor.Api.Config
+{
+    public class ServerRedirectorConfig
+    {
+        public const string Section = "ServerRedirector";
+
+        public bool Enabled { get; set; }
+
+        public bool Master { get; set; }
+
+        public NodeLocator? Locator { get; set; }
+
+        public List<ServerRedirectorNode>? Nodes { get; set; }
+
+        public class NodeLocator
+        {
+            [AllowNull]
+            public string Redis { get; set; }
+
+            [AllowNull]
+            public string UdpMasterEndpoint { get; set; }
+        }
+    }
+}
diff --git a/src/Impostor.Api/Config/ServerRedirectorNode.cs b/src/Impostor.Api/Config/ServerRedirectorNode.cs
new file mode 100644 (file)
index 0000000..9980bd4
--- /dev/null
@@ -0,0 +1,13 @@
+using System.Diagnostics.CodeAnalysis;
+
+namespace Impostor.Api.Config
+{
+    public class ServerRedirectorNode
+    {
+        [AllowNull]
+        public string Ip { get; set; }
+
+        [AllowNull]
+        public ushort Port { get; set; }
+    }
+}
diff --git a/src/Impostor.Api/Utils/IpUtils.cs b/src/Impostor.Api/Utils/IpUtils.cs
new file mode 100644 (file)
index 0000000..c50eccf
--- /dev/null
@@ -0,0 +1,41 @@
+using System.Linq;
+using System.Net;
+using System.Net.Sockets;
+
+namespace Impostor.Api.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();
+        }
+    }
+}
diff --git a/src/Impostor.Server/Config/AntiCheatConfig.cs b/src/Impostor.Server/Config/AntiCheatConfig.cs
deleted file mode 100644 (file)
index ee1f62a..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-namespace Impostor.Server.Config
-{
-    public class AntiCheatConfig
-    {
-        public const string Section = "AntiCheat";
-
-        public bool Enabled { get; set; } = true;
-
-        public bool BanIpFromGame { get; set; } = true;
-    }
-}
diff --git a/src/Impostor.Server/Config/CompatibilityConfig.cs b/src/Impostor.Server/Config/CompatibilityConfig.cs
deleted file mode 100644 (file)
index d9fea81..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-namespace Impostor.Server.Config
-{
-    public class CompatibilityConfig
-    {
-        public const string Section = "Compatibility";
-
-        public bool AllowFutureGameVersions { get; set; } = false;
-
-        public bool AllowVersionMixing { get; set; } = false;
-    }
-}
diff --git a/src/Impostor.Server/Config/DebugConfig.cs b/src/Impostor.Server/Config/DebugConfig.cs
deleted file mode 100644 (file)
index 72529de..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-namespace Impostor.Server.Config
-{
-    public class DebugConfig
-    {
-        public const string Section = "Debug";
-
-        public bool GameRecorderEnabled { get; set; }
-
-        public string GameRecorderPath { get; set; } = string.Empty;
-    }
-}
diff --git a/src/Impostor.Server/Config/DisconnectMessages.cs b/src/Impostor.Server/Config/DisconnectMessages.cs
deleted file mode 100644 (file)
index 3384f32..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-namespace Impostor.Server.Config
-{
-    public static class DisconnectMessages
-    {
-        public const string Error = "There was an internal server error. " +
-                                    "Check the server console for more information. " +
-                                    "Please report the issue on the Impostor GitHub if it keeps happening.";
-
-        public const string ClientOutdated = "Please update your game to play in this lobby.";
-
-        public const string ClientTooNew = "Your game version is too new for this lobby. " +
-                                           "If you want to join this lobby you need to downgrade your client.";
-
-        public const string Destroyed = "The game you tried to join is being destroyed. " +
-                                        "Please create a new game.";
-
-        public const string NotImplemented = "Game listing has not been implemented in Impostor yet for servers " +
-                                             "running in server redirection mode.";
-
-        public const string UsernameLength = "Your username is too long, please make it shorter.";
-
-        public const string UsernameIllegalCharacters = "Your username contains illegal characters, please remove them.";
-
-        public const string VersionClientTooOld = "Please update your game to play on this server.";
-
-        public const string VersionServerTooOld = "Your client is too new, please update your Impostor server to play.";
-
-        public const string VersionUnsupported = "Your client version is unsupported, please update your Game and/or Impostor server.";
-    }
-}
diff --git a/src/Impostor.Server/Config/ServerConfig.cs b/src/Impostor.Server/Config/ServerConfig.cs
deleted file mode 100644 (file)
index 7ed3ae6..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-using Impostor.Server.Utils;
-
-namespace Impostor.Server.Config
-{
-    internal class ServerConfig
-    {
-        public const string Section = "Server";
-
-        private string? _resolvedPublicIp;
-        private string? _resolvedListenIp;
-
-        public string PublicIp { get; set; } = "127.0.0.1";
-
-        public ushort PublicPort { get; set; } = 22023;
-
-        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);
-        }
-    }
-}
diff --git a/src/Impostor.Server/Config/ServerRedirectorConfig.cs b/src/Impostor.Server/Config/ServerRedirectorConfig.cs
deleted file mode 100644 (file)
index 686ad7f..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-using System.Collections.Generic;
-using System.Diagnostics.CodeAnalysis;
-
-namespace Impostor.Server.Config
-{
-    public class ServerRedirectorConfig
-    {
-        public const string Section = "ServerRedirector";
-
-        public bool Enabled { get; set; }
-
-        public bool Master { get; set; }
-
-        public NodeLocator? Locator { get; set; }
-
-        public List<ServerRedirectorNode>? Nodes { get; set; }
-
-        public class NodeLocator
-        {
-            [AllowNull]
-            public string Redis { get; set; }
-
-            [AllowNull]
-            public string UdpMasterEndpoint { get; set; }
-        }
-    }
-}
diff --git a/src/Impostor.Server/Config/ServerRedirectorNode.cs b/src/Impostor.Server/Config/ServerRedirectorNode.cs
deleted file mode 100644 (file)
index c479512..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-using System.Diagnostics.CodeAnalysis;
-
-namespace Impostor.Server.Config
-{
-    public class ServerRedirectorNode
-    {
-        [AllowNull]
-        public string Ip { get; set; }
-
-        [AllowNull]
-        public ushort Port { get; set; }
-    }
-}
index 7a28371a02f5895e2fb400826f3d323cf5449a06..1b2dcde61f6558d5ceb33e4f8ca46106f01df786 100644 (file)
@@ -2,6 +2,7 @@ using System;
 using System.Linq;
 using System.Threading.Tasks;
 using Impostor.Api;
+using Impostor.Api.Config;
 using Impostor.Api.Games;
 using Impostor.Api.Innersloth;
 using Impostor.Api.Net;
@@ -10,7 +11,6 @@ using Impostor.Api.Net.Messages;
 using Impostor.Api.Net.Messages.C2S;
 using Impostor.Api.Net.Messages.S2C;
 using Impostor.Hazel;
-using Impostor.Server.Config;
 using Impostor.Server.Net.Manager;
 using Microsoft.Extensions.Logging;
 using Microsoft.Extensions.Options;
index 34001de8668e653b66381d64a0514476aeb034d4..efff8c96fc2a1bf3c284ff3d05f9f887f84e4445 100644 (file)
@@ -4,12 +4,12 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Threading;
 using System.Threading.Tasks;
+using Impostor.Api.Config;
 using Impostor.Api.Events.Managers;
 using Impostor.Api.Innersloth;
 using Impostor.Api.Net;
 using Impostor.Api.Net.Messages;
 using Impostor.Hazel;
-using Impostor.Server.Config;
 using Impostor.Server.Events.Client;
 using Impostor.Server.Net.Factories;
 using Microsoft.Extensions.Logging;
index f567f615a6e421f14dbf2edff4d10c279707087d..f4c6b1dc0b23c7332f6493e3fa8288be7cf4925a 100644 (file)
@@ -5,12 +5,12 @@ using System.Linq;
 using System.Net;
 using System.Threading.Tasks;
 using Impostor.Api;
+using Impostor.Api.Config;
 using Impostor.Api.Events.Managers;
 using Impostor.Api.Games;
 using Impostor.Api.Games.Managers;
 using Impostor.Api.Innersloth;
 using Impostor.Api.Net;
-using Impostor.Server.Config;
 using Impostor.Server.Events;
 using Impostor.Server.Net.Redirector;
 using Impostor.Server.Net.State;
index bd9a855381e6ae7c51b5b6c5afd86db0bdd5d387..35ff6dff374b09103ae385e4d67eb54c2c637ef4 100644 (file)
@@ -1,7 +1,7 @@
 using System.Net;
 using System.Threading;
 using System.Threading.Tasks;
-using Impostor.Server.Config;
+using Impostor.Api.Config;
 using Microsoft.Extensions.Hosting;
 using Microsoft.Extensions.Logging;
 using Microsoft.Extensions.Options;
index f463abb6b364eff11889af36ec287d7ead15d6bf..67ad0482a57d13e4d30442d81e7765a811a1aa35 100644 (file)
@@ -1,10 +1,10 @@
 using System.Threading.Tasks;
+using Impostor.Api.Config;
 using Impostor.Api.Innersloth;
 using Impostor.Api.Net.Messages;
 using Impostor.Api.Net.Messages.C2S;
 using Impostor.Api.Net.Messages.S2C;
 using Impostor.Hazel;
-using Impostor.Server.Config;
 using Impostor.Server.Net.Hazel;
 using Impostor.Server.Net.Manager;
 using Serilog;
index c75392adf5e466aacb7ce883ee8151f6a5e419ff..4b640a9401c80ae4777db6dab16f548f52118299 100644 (file)
@@ -4,7 +4,7 @@ using System.Net;
 using System.Net.Sockets;
 using System.Text;
 using System.Threading.Tasks;
-using Impostor.Server.Config;
+using Impostor.Api.Config;
 using Microsoft.Extensions.Logging;
 using Microsoft.Extensions.Options;
 
index 781e91f316b8fe4eef2103468681028523104dcb..fba9ac1f63677835ecc7d202fa3df350506b9648 100644 (file)
@@ -4,7 +4,7 @@ using System.Net.Sockets;
 using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
-using Impostor.Server.Config;
+using Impostor.Api.Config;
 using Microsoft.Extensions.Hosting;
 using Microsoft.Extensions.Logging;
 using Microsoft.Extensions.Options;
index 7e2982e80065ba2b7bf1bfb9ec3df19f5ffcb649..7111bd0b8c0cb38a8eeea57120ff70a909ffbeb1 100644 (file)
@@ -1,6 +1,6 @@
 using System.Collections.Generic;
 using System.Net;
-using Impostor.Server.Config;
+using Impostor.Api.Config;
 using Microsoft.Extensions.Options;
 
 namespace Impostor.Server.Net.Redirector
index 5da19d4a251ddd3e47faa03f08a016456d21514d..63680f898a6a66c2c4298381c8e4ed80dac23264 100644 (file)
@@ -6,13 +6,13 @@ using System.Linq;
 using System.Net;
 using System.Numerics;
 using System.Threading.Tasks;
+using Impostor.Api.Config;
 using Impostor.Api.Events.Managers;
 using Impostor.Api.Games;
 using Impostor.Api.Innersloth;
 using Impostor.Api.Net;
 using Impostor.Api.Net.Messages;
 using Impostor.Api.Net.Messages.S2C;
-using Impostor.Server.Config;
 using Impostor.Server.Events;
 using Impostor.Server.Net.Manager;
 using Microsoft.Extensions.Logging;
index 1c575dd7cae7bccde7e2c63e92cf8da7876cc741..ed972ca1703f1355a3f2de673773f47942fb5fe9 100644 (file)
@@ -3,6 +3,7 @@ using System.IO;
 using System.Linq;
 using System.Reflection;
 using System.Runtime.Loader;
+using Impostor.Api.Config;
 using Impostor.Api.Events.Managers;
 using Impostor.Api.Games;
 using Impostor.Api.Games.Managers;
@@ -11,7 +12,6 @@ using Impostor.Api.Net.Manager;
 using Impostor.Api.Net.Messages;
 using Impostor.Api.Utils;
 using Impostor.Hazel.Extensions;
-using Impostor.Server.Config;
 using Impostor.Server.Events;
 using Impostor.Server.Net;
 using Impostor.Server.Net.Custom;
index 4acf2a5921d47ab28b8d6e996ea6e9ea686ed7f2..3029652e0b6a6308393440b357611a7eedd90a79 100644 (file)
@@ -1,8 +1,8 @@
 using System.Threading.Tasks;
+using Impostor.Api.Config;
 using Impostor.Api.Innersloth;
 using Impostor.Api.Net.Custom;
 using Impostor.Api.Net.Messages;
-using Impostor.Server.Config;
 using Impostor.Server.Net;
 using Impostor.Server.Net.Hazel;
 using Impostor.Server.Net.Manager;
index 12985f1a211ac960148b63978218b137e894cf27..704f26bd35b8459025c75ee103fdae3ff430b7fc 100644 (file)
@@ -4,9 +4,9 @@ using System.Net;
 using System.Threading;
 using System.Threading.Channels;
 using System.Threading.Tasks;
+using Impostor.Api.Config;
 using Impostor.Api.Games;
 using Impostor.Api.Net.Messages;
-using Impostor.Server.Config;
 using Impostor.Server.Net;
 using Impostor.Server.Utils;
 using Microsoft.Extensions.Hosting;
diff --git a/src/Impostor.Server/Utils/IpUtils.cs b/src/Impostor.Server/Utils/IpUtils.cs
deleted file mode 100644 (file)
index 649d45a..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-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();
-        }
-    }
-}