From e44efc79c25fa02a50e77eee2d9980569468e324 Mon Sep 17 00:00:00 2001 From: linmeideli <2558527373@qq.com> Date: Sat, 1 Aug 2026 00:03:03 +0800 Subject: [PATCH] Enhanced Titles & Welcome Plugins with Anti-Cheat --- marketplace/Empostor.Plugins.Titles1.1.0.dll | Bin 0 -> 19456 bytes marketplace/Empostor.Plugins.Welcome1.2.0.dll | Bin 0 -> 22528 bytes marketplace/plugins.json | 10 ++ src/Empostor.Api/CheatCategory.cs | 3 + src/Empostor.Api/Config/AntiCheatConfig.cs | 4 + .../Events/Client/IClientConnectedEvent.cs | 6 +- src/Empostor.Api/Net/IClient.cs | 4 +- src/Empostor.Api/packages.lock.json | 6 - .../Service/FriendCodeTitleListener.cs | 74 ++++++---- .../Service/TitleApiMiddleware.cs | 108 +++++++++++++++ .../Service/TitleEventListener.cs | 8 +- src/Empostor.Plugins.Titles/TitlesPlugin.cs | 2 +- .../TitlesPluginStartup.cs | 9 +- .../packages.lock.json | 3 +- .../Empostor.Plugins.Welcome.csproj | 1 + .../Service/WelcomeEventListener.cs | 130 +++++++++++++++++- src/Empostor.Plugins.Welcome/WelcomePlugin.cs | 2 +- .../WelcomePluginStartup.cs | 1 + .../packages.lock.json | 74 +++++++++- src/Empostor.Server/Net/Client.cs | 1 + src/Empostor.Server/Net/ClientBase.cs | 2 +- .../Net/Hazel/HazelConnection.cs | 20 ++- src/Empostor.Server/Net/Matchmaker.cs | 7 +- src/Empostor.Server/config.json | 4 +- src/Empostor.Server/packages.lock.json | 6 - 25 files changed, 426 insertions(+), 59 deletions(-) create mode 100644 marketplace/Empostor.Plugins.Titles1.1.0.dll create mode 100644 marketplace/Empostor.Plugins.Welcome1.2.0.dll create mode 100644 src/Empostor.Plugins.Titles/Service/TitleApiMiddleware.cs diff --git a/marketplace/Empostor.Plugins.Titles1.1.0.dll b/marketplace/Empostor.Plugins.Titles1.1.0.dll new file mode 100644 index 0000000000000000000000000000000000000000..cc3e3005a2bdf5816567e7cdb7b4d48f7c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#?{`H?(_a0e4Zz{8Pakba~wQ{EI`4 zZ~xHuz+IJJo@W358A8LC4)V8VlhgG}(BVW&=kdARW?VNya?*_!W&vLTcmuYb{eay# z^Ymgvw;d<3e%!a=Y_wgVuTeC^^VWCm>hH7mWb#31Aa%@7=TR`I=rs!~7jh;ok}z8sGywFTh_J z$QhcSEpQuS#S9LQc8$n(Ue5f#gWfje zYpv*^8|2uKgVut+Ww4~Jc(EP$dkOJm`Qf8*cK%=O7e6D(;2-{O9wUfEi1vrzt&DhX z1U};)4&kW?&cGDIwNKjL?(un4xOBlUOz|21celeGw;j;Whr?0$IRC#jZXcoL=+|_8 zGre5$aVy%iaD;1t&y)CO+d}ODT!zh=L1MbD`;j#b!zyH@g@IL_{$s_9k literal 0 HcmV?d00001 diff --git a/marketplace/Empostor.Plugins.Welcome1.2.0.dll b/marketplace/Empostor.Plugins.Welcome1.2.0.dll new file mode 100644 index 0000000000000000000000000000000000000000..30515211642986f84410b77de81a624b5daca714 GIT binary patch literal 22528 zcmeHve|#L(k!N+!OwSKVBh5(i?;j)o99z~{Ka4S8jAdD}2V1sm$rytjc{J0K21e6z z&&XKFB2owtvIz%AvWc^h#0iAWCOD9g4cW_O@ovIG7Lq^~E+lIQ4w7ZbZupVg4Yy0| z{nmTk^Ftcjkh{HXJ>q@3?onm?({(+A$xLY2GzQGrP$(Wtr;Ti=PY;D12dDm2z{D7Xts`0eNEYQ4I{;88=5Eac zCGiOn9gLV6GmeswZ2}1EXE(kDpN+Xm7ZA^ZvJ5J@XlsP%ryGcbZqL#7eB?{j@Ju3~ z>KJFEtfcBj2dzX0@C$^YM@;qZ3F>edpguesoq}|xHi)JgI#f3*DPqk zpq=?y?lu=#cpktq=3m|Dq&jc{+rX4YK217R3Ij3V`=Q8V<$`f@mhGJRTjKGfMzr@6ulfLJyp!30IQUhn!{KEY`g+Bz?U*!$@m!!Zlz_Gfe>B}z(!}DSAZwn zDiEY_m>a{7oIz5@;T^a-#^Eox){f5-*Q2sJ3@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opR z#bF$pXvF+3f>v5E^A^12zZfu%-?F#hSEM?w{QS5PE%0k*w7_3_fVZzj?>O*2T-Tx8 pj8Y6(92kGr3A?w#*8I$P2<=kPbOA packet was sent on an invalid network object, like a PlayerControl without PlayerInfo. InvalidObject, + /// A packet was sent that exceeded the maximum allowed RPC size. + PacketSize, + /// Legacy category for unsorted anticheat checks. Other, } diff --git a/src/Empostor.Api/Config/AntiCheatConfig.cs b/src/Empostor.Api/Config/AntiCheatConfig.cs index fa631e3..03b3328 100644 --- a/src/Empostor.Api/Config/AntiCheatConfig.cs +++ b/src/Empostor.Api/Config/AntiCheatConfig.cs @@ -27,5 +27,9 @@ namespace Empostor.Api.Config public bool EnableTargetChecks { get; set; } = true; public bool ForbidProtocolExtensions { get; set; } = true; + + public bool EnablePacketSizeChecks { get; set; } = true; + + public int PacketSizeLimit { get; set; } = 1203; } } diff --git a/src/Empostor.Api/Events/Client/IClientConnectedEvent.cs b/src/Empostor.Api/Events/Client/IClientConnectedEvent.cs index e0d8b32..ed6034e 100644 --- a/src/Empostor.Api/Events/Client/IClientConnectedEvent.cs +++ b/src/Empostor.Api/Events/Client/IClientConnectedEvent.cs @@ -3,10 +3,14 @@ using Empostor.Api.Net; namespace Empostor.Api.Events.Client { /// - /// Called just after a is created and connected. + /// Called after a has been fully registered + /// and all auth data (including friend code) has been resolved. /// public interface IClientConnectedEvent : IClientEvent { + /// + /// Gets the registered . + /// IClient Client { get; } } } diff --git a/src/Empostor.Api/Net/IClient.cs b/src/Empostor.Api/Net/IClient.cs index d2aba4a..3ec1d34 100644 --- a/src/Empostor.Api/Net/IClient.cs +++ b/src/Empostor.Api/Net/IClient.cs @@ -20,12 +20,12 @@ namespace Empostor.Api.Net int Id { get; set; } /// - /// Gets the name that was provided by the player in the client. + /// Gets or sets the name that was provided by the player in the client. /// /// /// The name is provided by the player and should not be used to store persisted data. /// - string Name { get; } + string Name { get; set; } /// /// Gets the language. diff --git a/src/Empostor.Api/packages.lock.json b/src/Empostor.Api/packages.lock.json index 049e555..e851b84 100644 --- a/src/Empostor.Api/packages.lock.json +++ b/src/Empostor.Api/packages.lock.json @@ -34,12 +34,6 @@ "Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.0" } }, - "Microsoft.NET.ILLink.Tasks": { - "type": "Direct", - "requested": "[8.0.28, )", - "resolved": "8.0.28", - "contentHash": "XMqgVjlLxLqWmEh3c49haXLQwsMNtvo6YscUaqfvEGfg1iA8hnYgkUVq3i9Zu9gKeNKMWiiZKVwZExc/qyEAsQ==" - }, "StyleCop.Analyzers": { "type": "Direct", "requested": "[1.2.0-beta.556, )", diff --git a/src/Empostor.Plugins.Titles/Service/FriendCodeTitleListener.cs b/src/Empostor.Plugins.Titles/Service/FriendCodeTitleListener.cs index e9631d8..403a0d1 100644 --- a/src/Empostor.Plugins.Titles/Service/FriendCodeTitleListener.cs +++ b/src/Empostor.Plugins.Titles/Service/FriendCodeTitleListener.cs @@ -1,9 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; using Empostor.Api.Events; -using Empostor.Api.Events.Game.Player; +using Empostor.Api.Events.Client; using Microsoft.Extensions.Logging; namespace Empostor.Plugins.Titles.Service; @@ -11,49 +10,66 @@ namespace Empostor.Plugins.Titles.Service; public sealed class FriendCodeTitleListener : IEventListener { private readonly ILogger _logger; - private readonly Dictionary _map; + private readonly TitlesConfig _config; + private Dictionary _map; public FriendCodeTitleListener( ILogger logger, TitlesConfig config) { _logger = logger; - _map = config.Titles - .Where(t => !string.IsNullOrWhiteSpace(t.FriendCode) && !string.IsNullOrWhiteSpace(t.Title)) - .ToDictionary(t => t.FriendCode, t => t.Title, StringComparer.OrdinalIgnoreCase); + _config = config; + _map = BuildMap(); _logger.LogInformation("[FriendCodeTitles] Loaded {Count} title mapping(s).", _map.Count); } - [EventListener] - public void OnPlayerReady(IPlayerReadyEvent e) + /// + /// Reloads the title mappings from config. Called by the API middleware + /// after a new title is added. + /// + public void Reload() { - var fc = e.ClientPlayer.Client.FriendCode; + _map = BuildMap(); + _logger.LogInformation("[FriendCodeTitles] Reloaded {Count} title mapping(s).", _map.Count); + } + + [EventListener] + public void OnClientConnected(IClientConnectedEvent e) + { + var fc = e.Client.FriendCode; if (string.IsNullOrEmpty(fc)) return; if (!_map.TryGetValue(fc, out var title)) return; - var player = e.ClientPlayer; - var ctrl = e.PlayerControl; - - Task.Run(async () => + try { - try + var displayName = TitleStore.BuildDisplayName(title, e.Client.Name); + e.Client.Name = displayName; + + _logger.LogInformation("[FriendCodeTitles] Applied [{Title}] to {Name} ({FC})", + title, e.Client.Name, fc); + + // Remove applied title so it is only used once + _map.Remove(fc); + + // Also remove from config so it persists across reloads + var entry = _config.Titles.FirstOrDefault(t => + string.Equals(t.FriendCode, fc, StringComparison.OrdinalIgnoreCase)); + if (entry != null) { - await Task.Delay(TimeSpan.FromMilliseconds(600)); - - if (player.Client.Connection == null || !player.Client.Connection.IsConnected) - return; - - var displayName = TitleStore.BuildDisplayName(title, player.Client.Name); - await ctrl.SetNameAsync(displayName); - - _logger.LogInformation("[FriendCodeTitles] Applied [{Title}] to {Name} ({FC})", - title, player.Client.Name, fc); + _config.Titles.Remove(entry); } - catch (Exception ex) - { - _logger.LogWarning(ex, "[FriendCodeTitles] Failed to apply title for {FC}", fc); - } - }); + } + catch (Exception ex) + { + _logger.LogWarning(ex, "[FriendCodeTitles] Failed to apply title for {FC}", fc); + } + } + + private Dictionary BuildMap() + { + return _config.Titles + .Where(t => !string.IsNullOrWhiteSpace(t.FriendCode) && !string.IsNullOrWhiteSpace(t.Title)) + .ToDictionary(t => t.FriendCode, t => t.Title, StringComparer.OrdinalIgnoreCase); } } diff --git a/src/Empostor.Plugins.Titles/Service/TitleApiMiddleware.cs b/src/Empostor.Plugins.Titles/Service/TitleApiMiddleware.cs new file mode 100644 index 0000000..ba311d4 --- /dev/null +++ b/src/Empostor.Plugins.Titles/Service/TitleApiMiddleware.cs @@ -0,0 +1,108 @@ +using System; +using System.IO; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Logging; + +namespace Empostor.Plugins.Titles.Service; + +public sealed class TitleApiMiddleware +{ + private readonly RequestDelegate _next; + private readonly ILogger _logger; + private readonly TitlesConfig _config; + private readonly string _configPath; + private readonly FriendCodeTitleListener? _friendCodeListener; + + public TitleApiMiddleware( + RequestDelegate next, + ILogger logger, + TitlesConfig config, + string configPath, + FriendCodeTitleListener? friendCodeListener = null) + { + _next = next; + _logger = logger; + _config = config; + _configPath = configPath; + _friendCodeListener = friendCodeListener; + } + + public async Task InvokeAsync(HttpContext context) + { + if (context.Request.Path == "/api/title/add" + && context.Request.Method == "POST") + { + await HandleAddTitleAsync(context); + return; + } + + await _next(context); + } + + private async Task HandleAddTitleAsync(HttpContext context) + { + try + { + using var reader = new StreamReader(context.Request.Body); + var body = await reader.ReadToEndAsync(); + + var request = JsonSerializer.Deserialize(body); + if (request == null + || string.IsNullOrWhiteSpace(request.FriendCode) + || string.IsNullOrWhiteSpace(request.Title)) + { + context.Response.StatusCode = 400; + context.Response.ContentType = "application/json"; + await context.Response.WriteAsync( + "{\"ok\":false,\"error\":\"friendCode and title are required.\"}"); + return; + } + + // Add to config + _config.Titles.Add(new FriendCodeTitle + { + FriendCode = request.FriendCode.Trim(), + Title = request.Title.Trim() + }); + + // Persist to file + var json = JsonSerializer.Serialize(_config, new JsonSerializerOptions + { + WriteIndented = true, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + }); + await File.WriteAllTextAsync(_configPath, json); + + // Reload mappings in the listener + _friendCodeListener?.Reload(); + + var addedBy = request.AddedBy ?? "unknown"; + _logger.LogInformation( + "[TitleApi] Added title [{Title}] for friend code {FC} (added by {AddedBy})", + request.Title, request.FriendCode, addedBy); + + context.Response.StatusCode = 200; + context.Response.ContentType = "application/json"; + await context.Response.WriteAsync("{\"ok\":true}"); + } + catch (Exception ex) + { + _logger.LogWarning(ex, "[TitleApi] Failed to add title"); + context.Response.StatusCode = 500; + context.Response.ContentType = "application/json"; + await context.Response.WriteAsync( + "{\"ok\":false,\"error\":\"Internal server error.\"}"); + } + } + + private sealed record TitleAddRequest( + [property: JsonPropertyName("friendCode")] + string? FriendCode, + [property: JsonPropertyName("title")] + string? Title, + [property: JsonPropertyName("addedBy")] + string? AddedBy); +} diff --git a/src/Empostor.Plugins.Titles/Service/TitleEventListener.cs b/src/Empostor.Plugins.Titles/Service/TitleEventListener.cs index ae59566..ddbf6e0 100644 --- a/src/Empostor.Plugins.Titles/Service/TitleEventListener.cs +++ b/src/Empostor.Plugins.Titles/Service/TitleEventListener.cs @@ -20,19 +20,21 @@ public sealed class TitleEventListener : IEventListener [EventListener] public void OnPlayerSpawned(IPlayerSpawnedEvent e) { + // Titles are now applied natively via IClientConnectedEvent in FriendCodeTitleListener. + // TitleStore-based titles (set via API) are still available via the store. var clientId = e.ClientPlayer.Client.Id; var title = _store.Get(clientId); if (title == null) return; + // For API-applied titles on already-connected players, we still use SetNameAsync + // since the client.Name was already set before the API title was added. var player = e.ClientPlayer; var playerCtrl = e.PlayerControl; - Task.Run(async () => + _ = Task.Run(async () => { try { - await Task.Delay(TimeSpan.FromMilliseconds(600)); - if (player.Client.Connection == null || !player.Client.Connection.IsConnected) return; diff --git a/src/Empostor.Plugins.Titles/TitlesPlugin.cs b/src/Empostor.Plugins.Titles/TitlesPlugin.cs index 5a1f709..63ec840 100644 --- a/src/Empostor.Plugins.Titles/TitlesPlugin.cs +++ b/src/Empostor.Plugins.Titles/TitlesPlugin.cs @@ -5,7 +5,7 @@ using Microsoft.Extensions.Logging; namespace Empostor.Plugins.Titles; -[EmpostorPlugin("cn.Empostor.titles", "Title System", "Empostor", "1.0.0")] +[EmpostorPlugin("cn.Empostor.titles", "Title System", "Empostor", "1.1.0")] public sealed class TitlesPlugin : PluginBase, IPluginLanguageProvider { private readonly ILogger _logger; diff --git a/src/Empostor.Plugins.Titles/TitlesPluginStartup.cs b/src/Empostor.Plugins.Titles/TitlesPluginStartup.cs index 2e72fb6..d64cc78 100644 --- a/src/Empostor.Plugins.Titles/TitlesPluginStartup.cs +++ b/src/Empostor.Plugins.Titles/TitlesPluginStartup.cs @@ -1,12 +1,13 @@ using Empostor.Api.Events; using Empostor.Api.Plugins; using Empostor.Plugins.Titles.Service; +using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; namespace Empostor.Plugins.Titles; -public sealed class TitlesPluginStartup : IPluginStartup +public sealed class TitlesPluginStartup : IPluginHttpStartup { private string _configPath = "[Title System]Config.json"; @@ -17,7 +18,13 @@ public sealed class TitlesPluginStartup : IPluginStartup public void ConfigureServices(IServiceCollection services) { services.AddSingleton(_ => PluginConfigLoader.Load(_configPath)); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); } + + public void ConfigureWebApplication(IApplicationBuilder builder) + { + builder.UseMiddleware(); + } } diff --git a/src/Empostor.Plugins.Titles/packages.lock.json b/src/Empostor.Plugins.Titles/packages.lock.json index ac11d80..0dc3fc6 100644 --- a/src/Empostor.Plugins.Titles/packages.lock.json +++ b/src/Empostor.Plugins.Titles/packages.lock.json @@ -132,6 +132,7 @@ "NextFast.Hazel.Abstractions": { "type": "Project" } - } + }, + "net8.0/win-x64": {} } } \ No newline at end of file diff --git a/src/Empostor.Plugins.Welcome/Empostor.Plugins.Welcome.csproj b/src/Empostor.Plugins.Welcome/Empostor.Plugins.Welcome.csproj index bd21363..ba34673 100644 --- a/src/Empostor.Plugins.Welcome/Empostor.Plugins.Welcome.csproj +++ b/src/Empostor.Plugins.Welcome/Empostor.Plugins.Welcome.csproj @@ -6,5 +6,6 @@ + diff --git a/src/Empostor.Plugins.Welcome/Service/WelcomeEventListener.cs b/src/Empostor.Plugins.Welcome/Service/WelcomeEventListener.cs index 0f6fcef..2bf157a 100644 --- a/src/Empostor.Plugins.Welcome/Service/WelcomeEventListener.cs +++ b/src/Empostor.Plugins.Welcome/Service/WelcomeEventListener.cs @@ -1,5 +1,8 @@ using System; using System.IO; +using System.Net.Http; +using System.Text.Json; +using System.Text.RegularExpressions; using System.Threading.Tasks; using Empostor.Api.Events; using Empostor.Api.Service; @@ -14,11 +17,20 @@ public sealed class WelcomeEventListener : IEventListener private const string TextDir = "Message"; private const string FallbackFile = "EnglishHelloWord.txt"; - private readonly ILogger _logger; + private static readonly Regex CaveRegex = new( + @"\(.+?)\", + RegexOptions.Compiled | RegexOptions.IgnoreCase, + TimeSpan.FromMilliseconds(100)); - public WelcomeEventListener(ILogger logger) + private readonly ILogger _logger; + private readonly IHttpClientFactory _httpClientFactory; + + public WelcomeEventListener( + ILogger logger, + IHttpClientFactory httpClientFactory) { _logger = logger; + _httpClientFactory = httpClientFactory; } [EventListener] @@ -50,6 +62,10 @@ public sealed class WelcomeEventListener : IEventListener } var template = File.ReadAllText(filePath); + + // Process URL tags before final formatting + template = await ProcessCaveTagsAsync(template); + var message = FormatMessage(template, player); await playerCtrl.SendChatToPlayerAsync(message, playerCtrl); @@ -61,6 +77,116 @@ public sealed class WelcomeEventListener : IEventListener }); } + /// + /// Finds all URL tags in the template, fetches content from each URL, + /// and replaces the tags with the fetched text. + /// + private async Task ProcessCaveTagsAsync(string template) + { + var matches = CaveRegex.Matches(template); + if (matches.Count == 0) return template; + + foreach (Match match in matches) + { + var url = match.Groups[1].Value.Trim(); + var replacement = await FetchCaveContentAsync(url); + template = template.Replace(match.Value, replacement); + } + + return template; + } + + /// + /// Fetches content from a URL. Supports: + /// - Plain text responses (returned as-is) + /// - JSON responses with a "hitokoto" field (Hitokoto API format) + /// - JSON responses with a "content" field + /// Returns an empty string on failure. + /// + private async Task FetchCaveContentAsync(string url) + { + try + { + using var client = _httpClientFactory.CreateClient("cave"); + client.Timeout = TimeSpan.FromSeconds(5); + + var response = await client.GetAsync(url); + if (!response.IsSuccessStatusCode) + { + _logger.LogWarning("[Welcome] fetch failed for {Url}: HTTP {Status}", + url, (int)response.StatusCode); + return string.Empty; + } + + var body = await response.Content.ReadAsStringAsync(); + + // Try to detect content type + var contentType = response.Content.Headers.ContentType?.MediaType; + + if (contentType != null && contentType.Contains("json", StringComparison.OrdinalIgnoreCase)) + { + return TryParseJsonContent(body); + } + + // If content-type is not JSON, try to detect JSON anyway + if (body.TrimStart().StartsWith("{")) + { + return TryParseJsonContent(body); + } + + // Plain text — return directly + return body.Trim(); + } + catch (TaskCanceledException) + { + _logger.LogWarning("[Welcome] fetch timed out for {Url}", url); + return string.Empty; + } + catch (Exception ex) + { + _logger.LogWarning(ex, "[Welcome] fetch error for {Url}", url); + return string.Empty; + } + } + + /// + /// Tries to parse JSON content looking for known fields. + /// Falls back to returning the raw trimmed string. + /// + private static string TryParseJsonContent(string body) + { + try + { + using var doc = JsonDocument.Parse(body); + var root = doc.RootElement; + + // Hitokoto API: {"hitokoto": "...", "from": "..."} + if (root.TryGetProperty("hitokoto", out var hitokoto)) + { + var text = hitokoto.GetString() ?? string.Empty; + if (root.TryGetProperty("from", out var from) && !string.IsNullOrWhiteSpace(from.GetString())) + { + text += $" —— {from.GetString()}"; + } + + return text; + } + + // Generic: {"content": "..."} + if (root.TryGetProperty("content", out var content)) + { + return content.GetString() ?? string.Empty; + } + + // Unknown JSON — return raw + return body.Trim(); + } + catch + { + return body.Trim(); + } + } + private static string FormatMessage(string template, Api.Net.IClientPlayer player) { var lastConnect = player.Client.ProductUserId != null diff --git a/src/Empostor.Plugins.Welcome/WelcomePlugin.cs b/src/Empostor.Plugins.Welcome/WelcomePlugin.cs index a55eece..c8948f4 100644 --- a/src/Empostor.Plugins.Welcome/WelcomePlugin.cs +++ b/src/Empostor.Plugins.Welcome/WelcomePlugin.cs @@ -6,7 +6,7 @@ using Microsoft.Extensions.Logging; namespace Empostor.Plugins.Welcome; -[EmpostorPlugin("cn.hayashiume.welcome", "Welcome Messages", "HayashiUme", "1.1.0")] +[EmpostorPlugin("cn.hayashiume.welcome", "Welcome Messages", "HayashiUme", "1.2.0")] public sealed class WelcomePlugin : PluginBase { private const string TextDir = "Message"; diff --git a/src/Empostor.Plugins.Welcome/WelcomePluginStartup.cs b/src/Empostor.Plugins.Welcome/WelcomePluginStartup.cs index 8d356b0..cfbc498 100644 --- a/src/Empostor.Plugins.Welcome/WelcomePluginStartup.cs +++ b/src/Empostor.Plugins.Welcome/WelcomePluginStartup.cs @@ -12,6 +12,7 @@ public sealed class WelcomePluginStartup : IPluginStartup public void ConfigureServices(IServiceCollection services) { + services.AddHttpClient(); services.AddSingleton(); } } diff --git a/src/Empostor.Plugins.Welcome/packages.lock.json b/src/Empostor.Plugins.Welcome/packages.lock.json index ac11d80..b721a9c 100644 --- a/src/Empostor.Plugins.Welcome/packages.lock.json +++ b/src/Empostor.Plugins.Welcome/packages.lock.json @@ -2,6 +2,20 @@ "version": 1, "dependencies": { "net8.0": { + "Microsoft.Extensions.Http": { + "type": "Direct", + "requested": "[8.0.0, )", + "resolved": "8.0.0", + "contentHash": "cWz4caHwvx0emoYe7NkHPxII/KkTI8R/LC9qdqJqnKv2poTJ4e2qqPGQqvRoQ5kaSA4FU5IV3qFAuLuOhoqULQ==", + "dependencies": { + "Microsoft.Extensions.Configuration.Abstractions": "8.0.0", + "Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.0", + "Microsoft.Extensions.Diagnostics": "8.0.0", + "Microsoft.Extensions.Logging": "8.0.0", + "Microsoft.Extensions.Logging.Abstractions": "8.0.0", + "Microsoft.Extensions.Options": "8.0.0" + } + }, "BouncyCastle.Cryptography": { "type": "Transitive", "resolved": "2.6.1", @@ -24,6 +38,15 @@ "Microsoft.Extensions.Primitives": "2.2.0" } }, + "Microsoft.Extensions.Configuration": { + "type": "Transitive", + "resolved": "8.0.0", + "contentHash": "0J/9YNXTMWSZP2p2+nvl8p71zpSwokZXZuJW+VjdErkegAnFdO1XlqtA62SJtgVYHdKu3uPxJHcMR/r35HwFBA==", + "dependencies": { + "Microsoft.Extensions.Configuration.Abstractions": "8.0.0", + "Microsoft.Extensions.Primitives": "8.0.0" + } + }, "Microsoft.Extensions.Configuration.Abstractions": { "type": "Transitive", "resolved": "8.0.0", @@ -32,11 +55,37 @@ "Microsoft.Extensions.Primitives": "8.0.0" } }, + "Microsoft.Extensions.Configuration.Binder": { + "type": "Transitive", + "resolved": "8.0.0", + "contentHash": "mBMoXLsr5s1y2zOHWmKsE9veDcx8h1x/c3rz4baEdQKTeDcmQAPNbB54Pi/lhFO3K431eEq6PFbMgLaa6PHFfA==", + "dependencies": { + "Microsoft.Extensions.Configuration.Abstractions": "8.0.0" + } + }, + "Microsoft.Extensions.DependencyInjection": { + "type": "Transitive", + "resolved": "8.0.0", + "contentHash": "V8S3bsm50ig6JSyrbcJJ8bW2b9QLGouz+G1miK3UTaOWmMtFwNNNzUf4AleyDWUmTrWMLNnFSLEQtxmxgNQnNQ==", + "dependencies": { + "Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.0" + } + }, "Microsoft.Extensions.DependencyInjection.Abstractions": { "type": "Transitive", "resolved": "9.0.6", "contentHash": "0Zn6nR/6g+90MxskZyOOMPQvnPnrrGu6bytPwkV+azDcTtCSuQ1+GJUrg8Klmnrjk1i6zMpw2lXijl+tw7Q3kA==" }, + "Microsoft.Extensions.Diagnostics": { + "type": "Transitive", + "resolved": "8.0.0", + "contentHash": "3PZp/YSkIXrF7QK7PfC1bkyRYwqOHpWFad8Qx+4wkuumAeXo1NHaxpS9LboNA9OvNSAu+QOVlXbMyoY+pHSqcw==", + "dependencies": { + "Microsoft.Extensions.Configuration": "8.0.0", + "Microsoft.Extensions.Diagnostics.Abstractions": "8.0.0", + "Microsoft.Extensions.Options.ConfigurationExtensions": "8.0.0" + } + }, "Microsoft.Extensions.Diagnostics.Abstractions": { "type": "Transitive", "resolved": "8.0.0", @@ -67,6 +116,16 @@ "Microsoft.Extensions.Logging.Abstractions": "8.0.0" } }, + "Microsoft.Extensions.Logging": { + "type": "Transitive", + "resolved": "8.0.0", + "contentHash": "tvRkov9tAJ3xP51LCv3FJ2zINmv1P8Hi8lhhtcKGqM+ImiTCC84uOPEI4z8Cdq2C3o9e+Aa0Gw0rmrsJD77W+w==", + "dependencies": { + "Microsoft.Extensions.DependencyInjection": "8.0.0", + "Microsoft.Extensions.Logging.Abstractions": "8.0.0", + "Microsoft.Extensions.Options": "8.0.0" + } + }, "Microsoft.Extensions.Logging.Abstractions": { "type": "Transitive", "resolved": "8.0.0", @@ -89,6 +148,18 @@ "Microsoft.Extensions.Primitives": "8.0.0" } }, + "Microsoft.Extensions.Options.ConfigurationExtensions": { + "type": "Transitive", + "resolved": "8.0.0", + "contentHash": "0f4DMRqEd50zQh+UyJc+/HiBsZ3vhAQALgdkcQEalSH1L2isdC7Yj54M3cyo5e+BeO5fcBQ7Dxly8XiBBcvRgw==", + "dependencies": { + "Microsoft.Extensions.Configuration.Abstractions": "8.0.0", + "Microsoft.Extensions.Configuration.Binder": "8.0.0", + "Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.0", + "Microsoft.Extensions.Options": "8.0.0", + "Microsoft.Extensions.Primitives": "8.0.0" + } + }, "Microsoft.Extensions.Primitives": { "type": "Transitive", "resolved": "8.0.0", @@ -132,6 +203,7 @@ "NextFast.Hazel.Abstractions": { "type": "Project" } - } + }, + "net8.0/win-x64": {} } } \ No newline at end of file diff --git a/src/Empostor.Server/Net/Client.cs b/src/Empostor.Server/Net/Client.cs index 2530638..3b1f3ec 100644 --- a/src/Empostor.Server/Net/Client.cs +++ b/src/Empostor.Server/Net/Client.cs @@ -75,6 +75,7 @@ namespace Empostor.Server.Net CheatCategory.ProtocolExtension => _antiCheatConfig.ForbidProtocolExtensions, CheatCategory.GameFlow => _antiCheatConfig.EnableGameFlowChecks, CheatCategory.InvalidObject => _antiCheatConfig.EnableInvalidObjectChecks, + CheatCategory.PacketSize => _antiCheatConfig.EnablePacketSizeChecks, CheatCategory.MustBeHost => _antiCheatConfig.EnableMustBeHostChecks, CheatCategory.ColorLimits => _antiCheatConfig.EnableColorLimitChecks, CheatCategory.NameLimits => _antiCheatConfig.EnableNameLimitChecks, diff --git a/src/Empostor.Server/Net/ClientBase.cs b/src/Empostor.Server/Net/ClientBase.cs index cbe7dd3..287642f 100644 --- a/src/Empostor.Server/Net/ClientBase.cs +++ b/src/Empostor.Server/Net/ClientBase.cs @@ -29,7 +29,7 @@ namespace Empostor.Server.Net /// public int DeltaPort { get; set; } - public string Name { get; } + public string Name { get; set; } public Language Language { get; } diff --git a/src/Empostor.Server/Net/Hazel/HazelConnection.cs b/src/Empostor.Server/Net/Hazel/HazelConnection.cs index 8db517c..f998783 100644 --- a/src/Empostor.Server/Net/Hazel/HazelConnection.cs +++ b/src/Empostor.Server/Net/Hazel/HazelConnection.cs @@ -1,18 +1,23 @@ using System.Net; using System.Threading.Tasks; +using Empostor.Api; +using Empostor.Api.Config; using Empostor.Api.Net; using Next.Hazel; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; namespace Empostor.Server.Net.Hazel { internal class HazelConnection : IHazelConnection { private readonly ILogger _logger; + private readonly AntiCheatConfig _antiCheatConfig; - public HazelConnection(Connection innerConnection, ILogger logger) + public HazelConnection(Connection innerConnection, ILogger logger, IOptions antiCheatOptions) { _logger = logger; + _antiCheatConfig = antiCheatOptions.Value; InnerConnection = innerConnection; innerConnection.DataReceived = ConnectionOnDataReceived; innerConnection.Disconnected = ConnectionOnDisconnected; @@ -58,6 +63,19 @@ namespace Empostor.Server.Net.Hazel return; } + // Check raw message size against the configured limit. + // Innersloth requires full packet ≤ 1200 bytes (1168 bytes payload after 32 bytes IP+UDP headers). + if (e.Message.Length > _antiCheatConfig.PacketSizeLimit) + { + if (await Client.ReportCheatAsync( + new CheatContext("RootMessage"), + CheatCategory.PacketSize, + $"Received a message that is too large, length: {e.Message.Length}")) + { + return; + } + } + while (true) { if (e.Message.Position >= e.Message.Length) diff --git a/src/Empostor.Server/Net/Matchmaker.cs b/src/Empostor.Server/Net/Matchmaker.cs index 3916a46..019cb8f 100644 --- a/src/Empostor.Server/Net/Matchmaker.cs +++ b/src/Empostor.Server/Net/Matchmaker.cs @@ -29,6 +29,7 @@ namespace Empostor.Server.Net private readonly IFirewallService _firewall; private readonly ServerConfig _serverConfig; private readonly AuthCacheService _authCache; + private readonly IOptions _antiCheatOptions; private UdpConnectionListener? _mainListener; private readonly ConcurrentDictionary _deltaListeners = new(); @@ -44,7 +45,8 @@ namespace Empostor.Server.Net PortPoolService portPool, IFirewallService firewall, IOptions serverConfig, - AuthCacheService authCache) + AuthCacheService authCache, + IOptions antiCheatOptions) { _eventManager = eventManager; _clientManager = clientManager; @@ -55,6 +57,7 @@ namespace Empostor.Server.Net _firewall = firewall; _serverConfig = serverConfig.Value; _authCache = authCache; + _antiCheatOptions = antiCheatOptions; // Subscribe to port return events from the pool _portPool.OnPortReturned += OnPortReturned; @@ -182,7 +185,7 @@ namespace Empostor.Server.Net out var chatMode, out var platformSpecificData); - var connection = new HazelConnection(e.Connection, _connectionLogger); + var connection = new HazelConnection(e.Connection, _connectionLogger, _antiCheatOptions); await _eventManager.CallAsync(new ClientConnectionEvent(connection, e.HandshakeData)); await _clientManager.RegisterConnectionAsync( connection, name, clientVersion, language, chatMode, platformSpecificData, diff --git a/src/Empostor.Server/config.json b/src/Empostor.Server/config.json index 130a954..3365ae6 100644 --- a/src/Empostor.Server/config.json +++ b/src/Empostor.Server/config.json @@ -25,7 +25,9 @@ "EnableOwnershipChecks": true, "EnableRoleChecks": true, "EnableTargetChecks": true, - "ForbidProtocolExtensions": true + "ForbidProtocolExtensions": true, + "EnablePacketSizeChecks": true, + "PacketSizeLimit": 1203 }, "Timeout": { "SpawnTimeout": 2500, diff --git a/src/Empostor.Server/packages.lock.json b/src/Empostor.Server/packages.lock.json index 4588685..9d36848 100644 --- a/src/Empostor.Server/packages.lock.json +++ b/src/Empostor.Server/packages.lock.json @@ -58,12 +58,6 @@ "resolved": "8.0.1", "contentHash": "X21b8D6z58EG34OMLH955750mFaEaGs5xLGe9Vyi3059Cgb3sk+p2k/JlQXaieEBRrk+SVlFzDei3Q6PdVzJOA==" }, - "Microsoft.NET.ILLink.Tasks": { - "type": "Direct", - "requested": "[8.0.28, )", - "resolved": "8.0.28", - "contentHash": "XMqgVjlLxLqWmEh3c49haXLQwsMNtvo6YscUaqfvEGfg1iA8hnYgkUVq3i9Zu9gKeNKMWiiZKVwZExc/qyEAsQ==" - }, "Serilog.Extensions.Hosting": { "type": "Direct", "requested": "[8.0.0, )",