From 34287a214cd88b3be2b3be21f462c5c6588b119b Mon Sep 17 00:00:00 2001 From: "terentev.a.a" Date: Sun, 8 Dec 2024 19:34:09 +0300 Subject: [PATCH 01/10] Add pagination and search to user retrieval Introduced a new method to retrieve users with pagination and search capabilities by adding `GetUsers` with parameters for take, offset, and findName. This enhancement allows more efficient querying of user data and improves performance when dealing with large datasets. Updated interfaces and storage services to support these changes consistently. --- .../Procedures/IUserProcedures.cs | 1 + src/Gml.Core/Core/Helpers/User/UserProcedures.cs | 10 ++++++++++ .../Core/Services/Storage/IStorageService.cs | 2 ++ .../Core/Services/Storage/SqliteStorageService.cs | 14 ++++++++++++++ 4 files changed, 27 insertions(+) diff --git a/src/Gml.Core.Interfaces/Procedures/IUserProcedures.cs b/src/Gml.Core.Interfaces/Procedures/IUserProcedures.cs index 99b4567..0cbbdc4 100644 --- a/src/Gml.Core.Interfaces/Procedures/IUserProcedures.cs +++ b/src/Gml.Core.Interfaces/Procedures/IUserProcedures.cs @@ -23,6 +23,7 @@ Task GetAuthData( Task ValidateUser(string userUuid, string uuid, string accessToken); Task CanJoinToServer(IUser user, string serverId); Task> GetUsers(); + Task> GetUsers(int take, int offset, string findName); Task UpdateUser(IUser user); Task StartSession(IUser user); Task EndSession(IUser user); diff --git a/src/Gml.Core/Core/Helpers/User/UserProcedures.cs b/src/Gml.Core/Core/Helpers/User/UserProcedures.cs index 9a4582b..be54d8f 100644 --- a/src/Gml.Core/Core/Helpers/User/UserProcedures.cs +++ b/src/Gml.Core/Core/Helpers/User/UserProcedures.cs @@ -143,6 +143,16 @@ public async Task> GetUsers() }); } + public async Task> GetUsers(int take, int offset, string findName) + { + var authUsers = await _storage.GetUsersAsync(new JsonSerializerOptions + { + Converters = { new SessionConverter() } + }, take, offset, findName).ConfigureAwait(false); + + return authUsers; + } + public Task UpdateUser(IUser user) { return _storage.SetUserAsync(user.Name, user.Uuid, (AuthUser)user); diff --git a/src/Gml.Core/Core/Services/Storage/IStorageService.cs b/src/Gml.Core/Core/Services/Storage/IStorageService.cs index 7d417a5..6e78c54 100644 --- a/src/Gml.Core/Core/Services/Storage/IStorageService.cs +++ b/src/Gml.Core/Core/Services/Storage/IStorageService.cs @@ -49,6 +49,8 @@ public interface IStorageService Task GetUserBySkinAsync(string guid, JsonSerializerOptions jsonSerializerOptions); Task SetUserAsync(string login, string uuid, T value); Task> GetUsersAsync(JsonSerializerOptions jsonSerializerOptions); + Task> GetUsersAsync(JsonSerializerOptions jsonSerializerOptions, int take, int offset, + string findName); Task AddBugAsync(IBugInfo bugInfo); Task ClearBugsAsync(); Task> GetBugsAsync(); diff --git a/src/Gml.Core/Core/Services/Storage/SqliteStorageService.cs b/src/Gml.Core/Core/Services/Storage/SqliteStorageService.cs index 96531b7..577c608 100644 --- a/src/Gml.Core/Core/Services/Storage/SqliteStorageService.cs +++ b/src/Gml.Core/Core/Services/Storage/SqliteStorageService.cs @@ -115,6 +115,20 @@ public async Task> GetUsersAsync(JsonSerializerOptions jsonSer return users!; } + public async Task> GetUsersAsync(JsonSerializerOptions jsonSerializerOptions, int take, + int offset, string findName) + { + var users = (await _database + .Table() + .Where(c => c.Login.Contains(findName)) + .Take(take) + .Skip(offset) + .ToListAsync()) + .Select(x => JsonSerializer.Deserialize(x.Value, jsonSerializerOptions)); + + return users!; + } + public async Task AddBugAsync(IBugInfo bugInfo) { var serializedValue = JsonSerializer.Serialize(bugInfo, new JsonSerializerOptions { WriteIndented = true }); From f5f18bbae30c9963e980fefd18e65d16201d08d1 Mon Sep 17 00:00:00 2001 From: "terentev.a.a" Date: Sun, 8 Dec 2024 19:56:52 +0300 Subject: [PATCH 02/10] Add `UserWhiteListGuid` to game profiles Introduced a new `UserWhiteListGuid` property in `IGameProfile` and `BaseProfile` to manage user GUID permissions within a game profile. This change enhances the flexibility and control over user access in game profiles. --- .../Launcher/IGameProfile.cs | 142 +++++++++++++++++- src/Gml.Core/Models/BaseProfile.cs | 1 + 2 files changed, 141 insertions(+), 2 deletions(-) diff --git a/src/Gml.Core.Interfaces/Launcher/IGameProfile.cs b/src/Gml.Core.Interfaces/Launcher/IGameProfile.cs index fe725c3..8938397 100644 --- a/src/Gml.Core.Interfaces/Launcher/IGameProfile.cs +++ b/src/Gml.Core.Interfaces/Launcher/IGameProfile.cs @@ -14,41 +14,179 @@ namespace GmlCore.Interfaces.Launcher { public interface IGameProfile : IDisposable { + /// + /// Responsible for handling profile-specific operations. + /// [JsonIgnore] IProfileProcedures ProfileProcedures { get; set; } + + /// + /// Responsible for server-specific operations related to the profile. + /// [JsonIgnore] IProfileServersProcedures ServerProcedures { get; set; } + + /// + /// Manages game downloading operations. + /// [JsonIgnore] IGameDownloaderProcedures GameLoader { get; set; } + /// + /// Name of the game profile. + /// string Name { get; set; } + + /// + /// Indicates if the game profile is enabled. + /// bool IsEnabled { get; set; } + + /// + /// Version of the game. + /// string GameVersion { get; set; } + + /// + /// Version of the game at launch. + /// string? LaunchVersion { get; set; } + + /// + /// Game loader associated with the profile. + /// GameLoader Loader { get; } + + /// + /// Path to the game client. + /// string ClientPath { get; set; } + + /// + /// Base64 encoded icon for the profile. + /// string IconBase64 { get; set; } + + /// + /// Key for the background image. + /// string BackgroundImageKey { get; set; } + + /// + /// Description of the game profile. + /// string Description { get; set; } + + /// + /// List of files permitted by the profile. + /// List? FileWhiteList { get; set; } + + /// + /// List of folders permitted by the profile. + /// List? FolderWhiteList { get; set; } - List Servers { get; set; } - DateTimeOffset CreateDate { get; set; } + + /// + /// List of user GUIDs permitted by the profile. + /// + List UserWhiteListGuid { get; set; } + + /// + /// List of servers associated with the profile. + /// + List Servers { get; } + + /// + /// Date and time when the profile was created. + /// + DateTimeOffset CreateDate { get; } + + /// + /// JVM arguments for the game. + /// string? JvmArguments { get; set; } + + /// + /// Game arguments used at runtime. + /// string? GameArguments { get; set; } + + /// + /// Current state of the game profile. + /// ProfileState State { get; set; } + /// + /// Validates the game profile. + /// Task ValidateProfile(); + + /// + /// Checks if the profile is fully loaded. + /// Task CheckIsFullLoaded(IStartupOptions startupOptions); + + /// + /// Removes the game profile. + /// Task Remove(); + + /// + /// Initiates the download process for the game. + /// Task DownloadAsync(); + + /// + /// Creates a process for the game. + /// Task CreateProcess(IStartupOptions startupOptions, IUser user); + + /// + /// Checks if the game client exists. + /// Task CheckClientExists(); + + /// + /// Checks if the operating system type is loaded. + /// Task CheckOsTypeLoaded(IStartupOptions startupOptions); + + /// + /// Installs authentication libraries. + /// Task InstallAuthLib(); + + /// + /// Retrieves cached profile information. + /// Task GetCacheProfile(); + + /// + /// Adds a server to the profile. + /// void AddServer(IProfileServer server); + + /// + /// Removes a server from the profile. + /// void RemoveServer(IProfileServer server); + + /// + /// Creates a mods folder for the profile. + /// Task CreateModsFolder(); + + /// + /// Retrieves profile files based on operating system details. + /// Task> GetProfileFiles(string osName, string osArchitecture); + + /// + /// Retrieves all profile files, optionally restoring from cache. + /// Task GetAllProfileFiles(bool needRestoreCache); + + /// + /// Creates a user session asynchronously. + /// Task CreateUserSessionAsync(IUser user); } } diff --git a/src/Gml.Core/Models/BaseProfile.cs b/src/Gml.Core/Models/BaseProfile.cs index a97b85b..07475cc 100644 --- a/src/Gml.Core/Models/BaseProfile.cs +++ b/src/Gml.Core/Models/BaseProfile.cs @@ -57,6 +57,7 @@ internal BaseProfile(string name, string gameVersion, GameLoader loader) public List? FileWhiteList { get; set; } public List? FolderWhiteList { get; set; } + public List UserWhiteListGuid { get; set; } = []; public List Servers { get; set; } = new(); From 14394caf23585d8c367fbaf40bfc80159145dacb Mon Sep 17 00:00:00 2001 From: "terentev.a.a" Date: Sun, 8 Dec 2024 20:49:33 +0300 Subject: [PATCH 03/10] Convert UserWhitelistGuid to List and add GetUsers. Changed UserWhiteListGuid properties from List to List to accommodate non-GUID identifiers, enhancing flexibility. Added a GetUsers method to UserProcedures and related interfaces and services, enabling retrieval of users by UUID strings. This update improves the ability to handle user identifiers consistently across the application. --- src/Gml.Core.Interfaces/Launcher/IGameProfile.cs | 2 +- .../Procedures/IUserProcedures.cs | 2 ++ src/Gml.Core/Core/Helpers/User/UserProcedures.cs | 10 ++++++++++ .../Core/Services/Storage/IStorageService.cs | 2 ++ .../Core/Services/Storage/SqliteStorageService.cs | 12 ++++++++++++ src/Gml.Core/Models/BaseProfile.cs | 2 +- 6 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Gml.Core.Interfaces/Launcher/IGameProfile.cs b/src/Gml.Core.Interfaces/Launcher/IGameProfile.cs index 8938397..d46c994 100644 --- a/src/Gml.Core.Interfaces/Launcher/IGameProfile.cs +++ b/src/Gml.Core.Interfaces/Launcher/IGameProfile.cs @@ -87,7 +87,7 @@ public interface IGameProfile : IDisposable /// /// List of user GUIDs permitted by the profile. /// - List UserWhiteListGuid { get; set; } + List UserWhiteListGuid { get; set; } /// /// List of servers associated with the profile. diff --git a/src/Gml.Core.Interfaces/Procedures/IUserProcedures.cs b/src/Gml.Core.Interfaces/Procedures/IUserProcedures.cs index 0cbbdc4..c6eb2a2 100644 --- a/src/Gml.Core.Interfaces/Procedures/IUserProcedures.cs +++ b/src/Gml.Core.Interfaces/Procedures/IUserProcedures.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.IO; using System.Net; @@ -24,6 +25,7 @@ Task GetAuthData( Task CanJoinToServer(IUser user, string serverId); Task> GetUsers(); Task> GetUsers(int take, int offset, string findName); + Task> GetUsers(IEnumerable userUuids); Task UpdateUser(IUser user); Task StartSession(IUser user); Task EndSession(IUser user); diff --git a/src/Gml.Core/Core/Helpers/User/UserProcedures.cs b/src/Gml.Core/Core/Helpers/User/UserProcedures.cs index be54d8f..a309ea4 100644 --- a/src/Gml.Core/Core/Helpers/User/UserProcedures.cs +++ b/src/Gml.Core/Core/Helpers/User/UserProcedures.cs @@ -153,6 +153,16 @@ public async Task> GetUsers(int take, int offset, string find return authUsers; } + public async Task> GetUsers(IEnumerable userUuids) + { + var users = await _storage.GetUsersAsync(new JsonSerializerOptions + { + Converters = { new SessionConverter() } + }, userUuids).ConfigureAwait(false); + + return users; + } + public Task UpdateUser(IUser user) { return _storage.SetUserAsync(user.Name, user.Uuid, (AuthUser)user); diff --git a/src/Gml.Core/Core/Services/Storage/IStorageService.cs b/src/Gml.Core/Core/Services/Storage/IStorageService.cs index 6e78c54..e6e96cb 100644 --- a/src/Gml.Core/Core/Services/Storage/IStorageService.cs +++ b/src/Gml.Core/Core/Services/Storage/IStorageService.cs @@ -49,6 +49,8 @@ public interface IStorageService Task GetUserBySkinAsync(string guid, JsonSerializerOptions jsonSerializerOptions); Task SetUserAsync(string login, string uuid, T value); Task> GetUsersAsync(JsonSerializerOptions jsonSerializerOptions); + Task> GetUsersAsync(JsonSerializerOptions jsonSerializerOptions, + IEnumerable userUuids); Task> GetUsersAsync(JsonSerializerOptions jsonSerializerOptions, int take, int offset, string findName); Task AddBugAsync(IBugInfo bugInfo); diff --git a/src/Gml.Core/Core/Services/Storage/SqliteStorageService.cs b/src/Gml.Core/Core/Services/Storage/SqliteStorageService.cs index 577c608..46b7ebe 100644 --- a/src/Gml.Core/Core/Services/Storage/SqliteStorageService.cs +++ b/src/Gml.Core/Core/Services/Storage/SqliteStorageService.cs @@ -115,6 +115,18 @@ public async Task> GetUsersAsync(JsonSerializerOptions jsonSer return users!; } + public async Task> GetUsersAsync(JsonSerializerOptions jsonSerializerOptions, + IEnumerable userUuids) + { + var users = (await _database + .Table() + .Where(c => userUuids.Contains(c.Uuid)) + .ToListAsync()) + .Select(x => JsonSerializer.Deserialize(x.Value, jsonSerializerOptions)); + + return users.OfType(); + } + public async Task> GetUsersAsync(JsonSerializerOptions jsonSerializerOptions, int take, int offset, string findName) { diff --git a/src/Gml.Core/Models/BaseProfile.cs b/src/Gml.Core/Models/BaseProfile.cs index 07475cc..3923a53 100644 --- a/src/Gml.Core/Models/BaseProfile.cs +++ b/src/Gml.Core/Models/BaseProfile.cs @@ -57,7 +57,7 @@ internal BaseProfile(string name, string gameVersion, GameLoader loader) public List? FileWhiteList { get; set; } public List? FolderWhiteList { get; set; } - public List UserWhiteListGuid { get; set; } = []; + public List UserWhiteListGuid { get; set; } = []; public List Servers { get; set; } = new(); From 13da1f979ebec32b43085b80bc72266089482bfd Mon Sep 17 00:00:00 2001 From: "terentev.a.a" Date: Sun, 8 Dec 2024 21:37:40 +0300 Subject: [PATCH 04/10] Add GetHead method to UserProcedures and ITextureProvider Introduced a new method, `GetHead`, in both `UserProcedures` and `ITextureProvider` to fetch a user's head texture stream by their name. This addition supports retrieving texture data, enhancing the user customization functionality. Changes include corresponding implementations in `TextureProvider` and interface updates. --- src/Gml.Core.Interfaces/Integrations/ITextureProvider.cs | 1 + src/Gml.Core.Interfaces/Procedures/IUserProcedures.cs | 1 + src/Gml.Core/Core/Helpers/User/UserProcedures.cs | 5 +++++ src/Gml.Core/Core/Integrations/TextureProvider.cs | 5 +++++ 4 files changed, 12 insertions(+) diff --git a/src/Gml.Core.Interfaces/Integrations/ITextureProvider.cs b/src/Gml.Core.Interfaces/Integrations/ITextureProvider.cs index e703481..8ef91a0 100644 --- a/src/Gml.Core.Interfaces/Integrations/ITextureProvider.cs +++ b/src/Gml.Core.Interfaces/Integrations/ITextureProvider.cs @@ -10,4 +10,5 @@ public interface ITextureProvider Task SetCloak(IUser user, string skinUrl); Task GetSkinStream(string? textureUrl); Task GetCloakStream(string? userTextureSkinUrl); + Task GetHeadByNameStream(string? userName); } diff --git a/src/Gml.Core.Interfaces/Procedures/IUserProcedures.cs b/src/Gml.Core.Interfaces/Procedures/IUserProcedures.cs index c6eb2a2..ae6cbbd 100644 --- a/src/Gml.Core.Interfaces/Procedures/IUserProcedures.cs +++ b/src/Gml.Core.Interfaces/Procedures/IUserProcedures.cs @@ -31,6 +31,7 @@ Task GetAuthData( Task EndSession(IUser user); Task GetSkin(IUser user); Task GetCloak(IUser user); + Task GetHead(IUser user); Task GetUserByAccessToken(string accessToken); } } diff --git a/src/Gml.Core/Core/Helpers/User/UserProcedures.cs b/src/Gml.Core/Core/Helpers/User/UserProcedures.cs index a309ea4..5a9ce33 100644 --- a/src/Gml.Core/Core/Helpers/User/UserProcedures.cs +++ b/src/Gml.Core/Core/Helpers/User/UserProcedures.cs @@ -192,6 +192,11 @@ public Task GetCloak(IUser user) return _gmlManager.Integrations.TextureProvider.GetCloakStream(user.TextureCloakUrl); } + public Task GetHead(IUser user) + { + return _gmlManager.Integrations.TextureProvider.GetHeadByNameStream(user.Name); + } + public async Task GetUserByAccessToken(string accessToken) { return await _storage.GetUserByAccessToken(accessToken, new JsonSerializerOptions diff --git a/src/Gml.Core/Core/Integrations/TextureProvider.cs b/src/Gml.Core/Core/Integrations/TextureProvider.cs index 16914c6..2ba25c6 100644 --- a/src/Gml.Core/Core/Integrations/TextureProvider.cs +++ b/src/Gml.Core/Core/Integrations/TextureProvider.cs @@ -68,6 +68,11 @@ public Task GetCloakStream(string? textureUrl) return _httpClintSkinChecker.GetStreamAsync(textureUrl); } + public Task GetHeadByNameStream(string? userName) + { + return _httpClientLoader.GetStreamAsync($"/skin/{userName}/head/128"); + } + private async Task UpdateTexture(IUser user, string skinUrl, string requestUri, string prefix) { var skinResponseMessage = await _httpClintSkinChecker.GetStreamAsync(skinUrl); From d8f8eda6c71bfebd26fb7f4742229df009f6c152 Mon Sep 17 00:00:00 2001 From: "terentev.a.a" Date: Mon, 9 Dec 2024 19:15:26 +0300 Subject: [PATCH 05/10] Add 'Player' role claim in JWT token generation This change introduces the 'Player' role claim to the JWT token generation process, enhancing authorization granularity. By adding user roles directly to tokens, subsequent role-based access controls can now be more effectively enforced. --- src/Gml.Core/Core/Helpers/User/UserProcedures.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Gml.Core/Core/Helpers/User/UserProcedures.cs b/src/Gml.Core/Core/Helpers/User/UserProcedures.cs index 5a9ce33..c15ce82 100644 --- a/src/Gml.Core/Core/Helpers/User/UserProcedures.cs +++ b/src/Gml.Core/Core/Helpers/User/UserProcedures.cs @@ -215,6 +215,7 @@ private string GenerateJwtToken(string login) new Claim(JwtRegisteredClaimNames.Sub, Guid.NewGuid().ToString()), new Claim(JwtRegisteredClaimNames.Jti, DateTime.Now.Ticks.ToString()), new Claim(JwtRegisteredClaimNames.UniqueName, login), + new Claim(ClaimTypes.Role, "Player"), new Claim(JwtRegisteredClaimNames.Name, login) }; From 52ee3f81a1c0629e35a20ccbf8df3cf035011303 Mon Sep 17 00:00:00 2001 From: "terentev.a.a" Date: Thu, 19 Dec 2024 21:17:26 +0300 Subject: [PATCH 06/10] Add player ban and pardon functionality with related checks Implemented ban and pardon endpoints to manage player access. Updated handlers and authentication logic to respect the ban status by blocking banned players from logging in or joining a server. Enhanced the system to handle empty input lists for ban/pardon actions with appropriate error responses. --- src/Gml.Core/Core/Helpers/User/UserProcedures.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Gml.Core/Core/Helpers/User/UserProcedures.cs b/src/Gml.Core/Core/Helpers/User/UserProcedures.cs index c15ce82..eba2b65 100644 --- a/src/Gml.Core/Core/Helpers/User/UserProcedures.cs +++ b/src/Gml.Core/Core/Helpers/User/UserProcedures.cs @@ -105,6 +105,9 @@ public async Task ValidateUser(string userUuid, string serverUuid, string if (!handler.CanReadToken(user.AccessToken)) return false; + if (user.IsBanned) + return false; + var jwtToken = handler.ReadJwtToken(user.AccessToken); var claims = jwtToken.Claims.FirstOrDefault(c => c.Type == "name"); From 87ae925d52d85664429d0bcc3f2737d6d1ca354c Mon Sep 17 00:00:00 2001 From: "terentev.a.a" Date: Fri, 20 Dec 2024 16:28:32 +0300 Subject: [PATCH 07/10] Add call to CaptureException before returning BugInfo The CaptureException method is now invoked to process the BugInfo instance before it is returned. This ensures exceptions are appropriately captured and handled as part of the bug tracking workflow. --- .../Core/Helpers/BugTracker/BugTrackerProcedures.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Gml.Core/Core/Helpers/BugTracker/BugTrackerProcedures.cs b/src/Gml.Core/Core/Helpers/BugTracker/BugTrackerProcedures.cs index c51534f..e3a125c 100644 --- a/src/Gml.Core/Core/Helpers/BugTracker/BugTrackerProcedures.cs +++ b/src/Gml.Core/Core/Helpers/BugTracker/BugTrackerProcedures.cs @@ -71,8 +71,7 @@ public void CaptureException(IBugInfo bugInfo) public IBugInfo CaptureException(Exception exception) { - - return new BugInfo + var bugInfo = new BugInfo { SendAt = DateTime.Now, Username = _settings.Name, @@ -100,6 +99,10 @@ public IBugInfo CaptureException(Exception exception) }, ProjectType = ProjectType.Backend, }; + + CaptureException(bugInfo); + + return bugInfo; } private async Task ProcessBugAsync(IBugInfo bug) From 463efea793cda325d587dbc307589c36f8b7405e Mon Sep 17 00:00:00 2001 From: "terentev.a.a" Date: Tue, 31 Dec 2024 07:41:40 +0300 Subject: [PATCH 08/10] Refactor Java version parsing and re-enable server ping tests. Replaced inline parsing with `TryParseMajorVersion` for improved readability and error handling. Re-enabled previously commented-out server ping tests to ensure compatibility across multiple Minecraft versions. This enhances both code clarity and test coverage. --- .../Core/Helpers/System/SystemProcedures.cs | 7 +- tests/GmlCore.Tests/UnitTests.cs | 311 +++++++++--------- 2 files changed, 161 insertions(+), 157 deletions(-) diff --git a/src/Gml.Core/Core/Helpers/System/SystemProcedures.cs b/src/Gml.Core/Core/Helpers/System/SystemProcedures.cs index 9955782..08efaac 100644 --- a/src/Gml.Core/Core/Helpers/System/SystemProcedures.cs +++ b/src/Gml.Core/Core/Helpers/System/SystemProcedures.cs @@ -141,13 +141,18 @@ public async Task> GetJavaVersions() .GroupBy(c => new { Name = c.Component, - MajorVersion = int.Parse(c.GetMajorVersion() ?? "0"), + MajorVersion = TryParseMajorVersion(c.GetMajorVersion()), Version = c.VersionName }); return javaVersions.Select(c => new JavaBootstrapProgram(c.Key.Name, c.Key.Version!, c.Key.MajorVersion!)); } + private int TryParseMajorVersion(string? majorVersion) + { + return int.TryParse(majorVersion, out var result) ? result : 0; + } + public async Task DownloadFileAsync(string url, string destinationFilePath) { _downloadLogs.OnNext($"Starting download: {url}"); diff --git a/tests/GmlCore.Tests/UnitTests.cs b/tests/GmlCore.Tests/UnitTests.cs index b4b1855..6ca5d8d 100644 --- a/tests/GmlCore.Tests/UnitTests.cs +++ b/tests/GmlCore.Tests/UnitTests.cs @@ -256,161 +256,161 @@ public async Task Remove_Profile() Assert.That(checkProfile, Is.Null); } - // [Test] - // [Order(41)] - // public async Task ServerPing1_20_6() - // { - // try - // { - // // 1.20.6 - // var options = new MinecraftPingOptions - // { - // Address = "45.153.68.20", - // Port = 25565 - // }; - // - // var status = await Minecraft.PingAsync(options) as JavaStatus; - // - // Console.WriteLine($"{status?.OnlinePlayers} / {status?.MaximumPlayers}"); - // - // Assert.That(actual: true, Is.True); - // } - // catch (SocketException e) - // { - // Console.WriteLine(e); - // } - // } - // - // [Test] - // [Order(42)] - // public async Task ServerPing1_7_10() - // { - // try - // { - // // 1.7.10 - // var options = new MinecraftPingOptions - // { - // Address = "45.153.68.20", - // Port = 25565 - // }; - // - // var status = await Minecraft.PingAsync(options) as JavaStatus; - // - // Console.WriteLine($"{status?.OnlinePlayers} / {status?.MaximumPlayers}"); - // - // Assert.That(actual: true, Is.True); - // } - // catch (SocketException e) - // { - // Console.WriteLine(e); - // } - // } - // - // [Test] - // [Order(43)] - // public async Task ServerPing1_5_2() - // { - // try - // { - // // 1.5.2 - // var options = new MinecraftPingOptions - // { - // Address = "45.153.68.20", - // Port = 25565 - // }; - // - // var status = await Minecraft.PingAsync(options) as JavaStatus; - // - // Console.WriteLine($"{status?.OnlinePlayers} / {status?.MaximumPlayers}"); - // - // Assert.That(actual: true, Is.True); - // } - // catch (SocketException e) - // { - // Console.WriteLine(e); - // } - // } - // - // [Test] - // [Order(44)] - // public async Task ServerPing1_12_2() - // { - // try - // { - // // 1.12.2 - // var options = new MinecraftPingOptions - // { - // Address = "45.153.68.20", - // Port = 25565 - // }; - // - // var status = await Minecraft.PingAsync(options) as JavaStatus; - // - // Console.WriteLine($"{status?.OnlinePlayers} / {status?.MaximumPlayers}"); - // } - // catch (SocketException e) - // { - // Console.WriteLine(e); - // } - // finally - // { - // Assert.That(actual: true, Is.True); - // } - // } - // - // [Test] - // [Order(45)] - // public async Task ServerPing1_16_5() - // { - // try - // { - // // 1.16.5 - // var options = new MinecraftPingOptions - // { - // Address = "45.153.68.20", - // Port = 25565 - // }; - // - // var status = await Minecraft.PingAsync(options) as JavaStatus; - // - // Console.WriteLine($"{status?.OnlinePlayers} / {status?.MaximumPlayers}"); - // } - // catch (SocketException e) - // { - // Console.WriteLine(e); - // } - // finally - // { - // Assert.That(actual: true, Is.True); - // } - // } - // - // [Test] - // [Order(46)] - // public async Task ServerPing1_20_1() - // { - // try - // { - // // 1.20.1 - // var options = new MinecraftPingOptions - // { - // Address = "45.153.68.20", - // Port = 25565 - // }; - // - // var status = await Minecraft.PingAsync(options) as JavaStatus; - // - // Console.WriteLine($"{status?.OnlinePlayers} / {status?.MaximumPlayers}"); - // } - // catch (SocketException e) - // { - // Console.WriteLine(e); - // } - // finally - // { - // Assert.That(actual: true, Is.True); - // } - // } + [Test] + [Order(41)] + public async Task ServerPing1_20_6() + { + try + { + // 1.20.6 + var options = new MinecraftPingOptions + { + Address = "45.153.68.20", + Port = 25565 + }; + + var status = await Minecraft.PingAsync(options) as JavaStatus; + + Console.WriteLine($"{status?.OnlinePlayers} / {status?.MaximumPlayers}"); + + Assert.That(actual: true, Is.True); + } + catch (SocketException e) + { + Console.WriteLine(e); + } + } + + [Test] + [Order(42)] + public async Task ServerPing1_7_10() + { + try + { + // 1.7.10 + var options = new MinecraftPingOptions + { + Address = "45.153.68.20", + Port = 25565 + }; + + var status = await Minecraft.PingAsync(options) as JavaStatus; + + Console.WriteLine($"{status?.OnlinePlayers} / {status?.MaximumPlayers}"); + + Assert.That(actual: true, Is.True); + } + catch (SocketException e) + { + Console.WriteLine(e); + } + } + + [Test] + [Order(43)] + public async Task ServerPing1_5_2() + { + try + { + // 1.5.2 + var options = new MinecraftPingOptions + { + Address = "45.153.68.20", + Port = 25565 + }; + + var status = await Minecraft.PingAsync(options) as JavaStatus; + + Console.WriteLine($"{status?.OnlinePlayers} / {status?.MaximumPlayers}"); + + Assert.That(actual: true, Is.True); + } + catch (SocketException e) + { + Console.WriteLine(e); + } + } + + [Test] + [Order(44)] + public async Task ServerPing1_12_2() + { + try + { + // 1.12.2 + var options = new MinecraftPingOptions + { + Address = "45.153.68.20", + Port = 25565 + }; + + var status = await Minecraft.PingAsync(options) as JavaStatus; + + Console.WriteLine($"{status?.OnlinePlayers} / {status?.MaximumPlayers}"); + } + catch (SocketException e) + { + Console.WriteLine(e); + } + finally + { + Assert.That(actual: true, Is.True); + } + } + + [Test] + [Order(45)] + public async Task ServerPing1_16_5() + { + try + { + // 1.16.5 + var options = new MinecraftPingOptions + { + Address = "45.153.68.20", + Port = 25565 + }; + + var status = await Minecraft.PingAsync(options) as JavaStatus; + + Console.WriteLine($"{status?.OnlinePlayers} / {status?.MaximumPlayers}"); + } + catch (SocketException e) + { + Console.WriteLine(e); + } + finally + { + Assert.That(actual: true, Is.True); + } + } + + [Test] + [Order(46)] + public async Task ServerPing1_20_1() + { + try + { + // 1.20.1 + var options = new MinecraftPingOptions + { + Address = "45.153.68.20", + Port = 25565 + }; + + var status = await Minecraft.PingAsync(options) as JavaStatus; + + Console.WriteLine($"{status?.OnlinePlayers} / {status?.MaximumPlayers}"); + } + catch (SocketException e) + { + Console.WriteLine(e); + } + finally + { + Assert.That(actual: true, Is.True); + } + } [Test] [Order(50)] @@ -532,7 +532,6 @@ public async Task ClientStartup() [Order(91)] public async Task GetJavaVersions() { - return; var versions = await GmlManager.System.GetJavaVersions(); Assert.That(versions, Is.Not.Empty); From 07bc1af8ed5872bdaab658117edb2c743219d628 Mon Sep 17 00:00:00 2001 From: "terentev.a.a" Date: Tue, 31 Dec 2024 07:50:40 +0300 Subject: [PATCH 09/10] Add timeout option to MinecraftPingOptions in tests The `TimeOut` property was added to all instances of `MinecraftPingOptions` used in unit tests with a default of 3 seconds. This improves the reliability and control of the tests by preventing indefinite waits in case of network delays or issues. --- tests/GmlCore.Tests/UnitTests.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/GmlCore.Tests/UnitTests.cs b/tests/GmlCore.Tests/UnitTests.cs index 6ca5d8d..083a96b 100644 --- a/tests/GmlCore.Tests/UnitTests.cs +++ b/tests/GmlCore.Tests/UnitTests.cs @@ -266,7 +266,8 @@ public async Task ServerPing1_20_6() var options = new MinecraftPingOptions { Address = "45.153.68.20", - Port = 25565 + Port = 25565, + TimeOut = TimeSpan.FromSeconds(3) }; var status = await Minecraft.PingAsync(options) as JavaStatus; @@ -291,7 +292,8 @@ public async Task ServerPing1_7_10() var options = new MinecraftPingOptions { Address = "45.153.68.20", - Port = 25565 + Port = 25565, + TimeOut = TimeSpan.FromSeconds(3) }; var status = await Minecraft.PingAsync(options) as JavaStatus; @@ -316,7 +318,8 @@ public async Task ServerPing1_5_2() var options = new MinecraftPingOptions { Address = "45.153.68.20", - Port = 25565 + Port = 25565, + TimeOut = TimeSpan.FromSeconds(3) }; var status = await Minecraft.PingAsync(options) as JavaStatus; @@ -341,7 +344,8 @@ public async Task ServerPing1_12_2() var options = new MinecraftPingOptions { Address = "45.153.68.20", - Port = 25565 + Port = 25565, + TimeOut = TimeSpan.FromSeconds(3) }; var status = await Minecraft.PingAsync(options) as JavaStatus; @@ -368,7 +372,8 @@ public async Task ServerPing1_16_5() var options = new MinecraftPingOptions { Address = "45.153.68.20", - Port = 25565 + Port = 25565, + TimeOut = TimeSpan.FromSeconds(3) }; var status = await Minecraft.PingAsync(options) as JavaStatus; @@ -395,7 +400,8 @@ public async Task ServerPing1_20_1() var options = new MinecraftPingOptions { Address = "45.153.68.20", - Port = 25565 + Port = 25565, + TimeOut = TimeSpan.FromSeconds(3) }; var status = await Minecraft.PingAsync(options) as JavaStatus; From 3da3c8dae2d4213fab47afb24ddbc1004c5af81a Mon Sep 17 00:00:00 2001 From: "terentev.a.a" Date: Tue, 31 Dec 2024 08:21:49 +0300 Subject: [PATCH 10/10] Update submodule link Pingo --- src/Pingo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pingo b/src/Pingo index ecd7843..6c898c1 160000 --- a/src/Pingo +++ b/src/Pingo @@ -1 +1 @@ -Subproject commit ecd784336e9290035aecf5ccfccc968ca7c97b09 +Subproject commit 6c898c1b17ec2c1e218f8dcb32bafecebb0fda7c