From c3ab347ce7242fd0e12a44756e59c49c25810145 Mon Sep 17 00:00:00 2001 From: aga Date: Mon, 23 Feb 2026 02:46:24 +0200 Subject: [PATCH] Support configured ServerId [build] Add optional ServerId to VipConfig and allow the server identifier to use a configured ID. --- VIPCore/src/Config/ConfigModels.cs | 1 + VIPCore/src/Services/ServerIdentifier.cs | 16 +++++++++++++++- VIPCore/src/VIPCore.cs | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/VIPCore/src/Config/ConfigModels.cs b/VIPCore/src/Config/ConfigModels.cs index b8fb07f..e11fee9 100644 --- a/VIPCore/src/Config/ConfigModels.cs +++ b/VIPCore/src/Config/ConfigModels.cs @@ -7,6 +7,7 @@ public class VipConfig public string DatabaseConnection { get; set; } = "default"; public int TimeMode { get; set; } = 0; public bool VipLogging { get; set; } = true; + public int? ServerId { get; set; } = null; } public class GroupsConfig diff --git a/VIPCore/src/Services/ServerIdentifier.cs b/VIPCore/src/Services/ServerIdentifier.cs index 0df0bfa..2165992 100644 --- a/VIPCore/src/Services/ServerIdentifier.cs +++ b/VIPCore/src/Services/ServerIdentifier.cs @@ -2,8 +2,10 @@ using VIPCore.Database; using VIPCore.Database.Repositories; using VIPCore.Models; +using VIPCore.Config; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; namespace VIPCore.Services; @@ -12,6 +14,7 @@ public class ServerIdentifier private readonly ISwiftlyCore _core; private readonly DatabaseConnectionFactory _connectionFactory; private readonly IUserRepository _userRepository; + private readonly IOptionsMonitor _coreConfigMonitor; private long _serverId; private string? _serverIp; @@ -23,17 +26,28 @@ public class ServerIdentifier public int ServerPort => _serverPort; public bool IsInitialized => _initialized; - public ServerIdentifier(ISwiftlyCore core, DatabaseConnectionFactory connectionFactory, IUserRepository userRepository) + public ServerIdentifier(ISwiftlyCore core, DatabaseConnectionFactory connectionFactory, IUserRepository userRepository, IOptionsMonitor coreConfigMonitor) { _core = core; _connectionFactory = connectionFactory; _userRepository = userRepository; + _coreConfigMonitor = coreConfigMonitor; } public async Task InitializeAsync() { try { + if (_coreConfigMonitor.CurrentValue.ServerId.HasValue) + { + _serverId = _coreConfigMonitor.CurrentValue.ServerId.Value; + _serverIp = "configured"; + _serverPort = 0; + _initialized = true; + _core.Logger.LogInformation("[VIPCore] Server identified using configured ID {ServerId}.", _serverId); + return; + } + _serverIp = _core.Engine.ServerIP; var hostport = _core.ConVar.Find("hostport"); diff --git a/VIPCore/src/VIPCore.cs b/VIPCore/src/VIPCore.cs index 454c09f..d7c7339 100644 --- a/VIPCore/src/VIPCore.cs +++ b/VIPCore/src/VIPCore.cs @@ -19,7 +19,7 @@ namespace VIPCore; -[PluginMetadata(Id = "VIPCore", Version = "1.0.1", Name = "VIPCore", Author = "aga", Description = "Core VIP management plugin ported to SwiftlyS2.")] +[PluginMetadata(Id = "VIPCore", Version = "1.0.1-beta", Name = "VIPCore", Author = "aga", Description = "Core VIP management plugin ported to SwiftlyS2.")] public partial class VIPCore : BasePlugin { private VipConfig? _config;