Skip to content

Commit

Permalink
Merge pull request #70 from Gml-Launcher/develop
Browse files Browse the repository at this point in the history
Update to v1.0.3
  • Loading branch information
GamerVII-NET authored Dec 31, 2024
2 parents ac7b390 + 3da3c8d commit 0479839
Show file tree
Hide file tree
Showing 12 changed files with 383 additions and 162 deletions.
1 change: 1 addition & 0 deletions src/Gml.Core.Interfaces/Integrations/ITextureProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public interface ITextureProvider
Task<string> SetCloak(IUser user, string skinUrl);
Task<Stream> GetSkinStream(string? textureUrl);
Task<Stream> GetCloakStream(string? userTextureSkinUrl);
Task<Stream> GetHeadByNameStream(string? userName);
}
142 changes: 140 additions & 2 deletions src/Gml.Core.Interfaces/Launcher/IGameProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,179 @@ namespace GmlCore.Interfaces.Launcher
{
public interface IGameProfile : IDisposable
{
/// <summary>
/// Responsible for handling profile-specific operations.
/// </summary>
[JsonIgnore] IProfileProcedures ProfileProcedures { get; set; }

/// <summary>
/// Responsible for server-specific operations related to the profile.
/// </summary>
[JsonIgnore] IProfileServersProcedures ServerProcedures { get; set; }

/// <summary>
/// Manages game downloading operations.
/// </summary>
[JsonIgnore] IGameDownloaderProcedures GameLoader { get; set; }

/// <summary>
/// Name of the game profile.
/// </summary>
string Name { get; set; }

/// <summary>
/// Indicates if the game profile is enabled.
/// </summary>
bool IsEnabled { get; set; }

/// <summary>
/// Version of the game.
/// </summary>
string GameVersion { get; set; }

/// <summary>
/// Version of the game at launch.
/// </summary>
string? LaunchVersion { get; set; }

/// <summary>
/// Game loader associated with the profile.
/// </summary>
GameLoader Loader { get; }

/// <summary>
/// Path to the game client.
/// </summary>
string ClientPath { get; set; }

/// <summary>
/// Base64 encoded icon for the profile.
/// </summary>
string IconBase64 { get; set; }

/// <summary>
/// Key for the background image.
/// </summary>
string BackgroundImageKey { get; set; }

/// <summary>
/// Description of the game profile.
/// </summary>
string Description { get; set; }

/// <summary>
/// List of files permitted by the profile.
/// </summary>
List<IFileInfo>? FileWhiteList { get; set; }

/// <summary>
/// List of folders permitted by the profile.
/// </summary>
List<IFolderInfo>? FolderWhiteList { get; set; }
List<IProfileServer> Servers { get; set; }
DateTimeOffset CreateDate { get; set; }

/// <summary>
/// List of user GUIDs permitted by the profile.
/// </summary>
List<string> UserWhiteListGuid { get; set; }

/// <summary>
/// List of servers associated with the profile.
/// </summary>
List<IProfileServer> Servers { get; }

/// <summary>
/// Date and time when the profile was created.
/// </summary>
DateTimeOffset CreateDate { get; }

/// <summary>
/// JVM arguments for the game.
/// </summary>
string? JvmArguments { get; set; }

/// <summary>
/// Game arguments used at runtime.
/// </summary>
string? GameArguments { get; set; }

/// <summary>
/// Current state of the game profile.
/// </summary>
ProfileState State { get; set; }

/// <summary>
/// Validates the game profile.
/// </summary>
Task<bool> ValidateProfile();

/// <summary>
/// Checks if the profile is fully loaded.
/// </summary>
Task<bool> CheckIsFullLoaded(IStartupOptions startupOptions);

/// <summary>
/// Removes the game profile.
/// </summary>
Task Remove();

/// <summary>
/// Initiates the download process for the game.
/// </summary>
Task DownloadAsync();

/// <summary>
/// Creates a process for the game.
/// </summary>
Task<Process> CreateProcess(IStartupOptions startupOptions, IUser user);

/// <summary>
/// Checks if the game client exists.
/// </summary>
Task<bool> CheckClientExists();

/// <summary>
/// Checks if the operating system type is loaded.
/// </summary>
Task<bool> CheckOsTypeLoaded(IStartupOptions startupOptions);

/// <summary>
/// Installs authentication libraries.
/// </summary>
Task<string[]> InstallAuthLib();

/// <summary>
/// Retrieves cached profile information.
/// </summary>
Task<IGameProfileInfo?> GetCacheProfile();

/// <summary>
/// Adds a server to the profile.
/// </summary>
void AddServer(IProfileServer server);

/// <summary>
/// Removes a server from the profile.
/// </summary>
void RemoveServer(IProfileServer server);

/// <summary>
/// Creates a mods folder for the profile.
/// </summary>
Task CreateModsFolder();

/// <summary>
/// Retrieves profile files based on operating system details.
/// </summary>
Task<ICollection<IFileInfo>> GetProfileFiles(string osName, string osArchitecture);

/// <summary>
/// Retrieves all profile files, optionally restoring from cache.
/// </summary>
Task<IFileInfo[]> GetAllProfileFiles(bool needRestoreCache);

/// <summary>
/// Creates a user session asynchronously.
/// </summary>
Task CreateUserSessionAsync(IUser user);
}
}
4 changes: 4 additions & 0 deletions src/Gml.Core.Interfaces/Procedures/IUserProcedures.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
Expand All @@ -23,11 +24,14 @@ Task<IUser> GetAuthData(
Task<bool> ValidateUser(string userUuid, string uuid, string accessToken);
Task<bool> CanJoinToServer(IUser user, string serverId);
Task<IEnumerable<IUser>> GetUsers();
Task<IEnumerable<IUser>> GetUsers(int take, int offset, string findName);
Task<IEnumerable<IUser>> GetUsers(IEnumerable<string> userUuids);
Task UpdateUser(IUser user);
Task StartSession(IUser user);
Task EndSession(IUser user);
Task<Stream> GetSkin(IUser user);
Task<Stream> GetCloak(IUser user);
Task<Stream> GetHead(IUser user);
Task<IUser?> GetUserByAccessToken(string accessToken);
}
}
7 changes: 5 additions & 2 deletions src/Gml.Core/Core/Helpers/BugTracker/BugTrackerProcedures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -100,6 +99,10 @@ public IBugInfo CaptureException(Exception exception)
},
ProjectType = ProjectType.Backend,
};

CaptureException(bugInfo);

return bugInfo;
}

private async Task ProcessBugAsync(IBugInfo bug)
Expand Down
7 changes: 6 additions & 1 deletion src/Gml.Core/Core/Helpers/System/SystemProcedures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,18 @@ public async Task<IEnumerable<IBootstrapProgram>> 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}");
Expand Down
29 changes: 29 additions & 0 deletions src/Gml.Core/Core/Helpers/User/UserProcedures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public async Task<bool> 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");
Expand Down Expand Up @@ -143,6 +146,26 @@ public async Task<IEnumerable<IUser>> GetUsers()
});
}

public async Task<IEnumerable<IUser>> GetUsers(int take, int offset, string findName)
{
var authUsers = await _storage.GetUsersAsync<AuthUser>(new JsonSerializerOptions
{
Converters = { new SessionConverter() }
}, take, offset, findName).ConfigureAwait(false);

return authUsers;
}

public async Task<IEnumerable<IUser>> GetUsers(IEnumerable<string> userUuids)
{
var users = await _storage.GetUsersAsync<AuthUser>(new JsonSerializerOptions
{
Converters = { new SessionConverter() }
}, userUuids).ConfigureAwait(false);

return users;
}

public Task UpdateUser(IUser user)
{
return _storage.SetUserAsync(user.Name, user.Uuid, (AuthUser)user);
Expand Down Expand Up @@ -172,6 +195,11 @@ public Task<Stream> GetCloak(IUser user)
return _gmlManager.Integrations.TextureProvider.GetCloakStream(user.TextureCloakUrl);
}

public Task<Stream> GetHead(IUser user)
{
return _gmlManager.Integrations.TextureProvider.GetHeadByNameStream(user.Name);
}

public async Task<IUser?> GetUserByAccessToken(string accessToken)
{
return await _storage.GetUserByAccessToken<AuthUser>(accessToken, new JsonSerializerOptions
Expand All @@ -190,6 +218,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)
};

Expand Down
5 changes: 5 additions & 0 deletions src/Gml.Core/Core/Integrations/TextureProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public Task<Stream> GetCloakStream(string? textureUrl)
return _httpClintSkinChecker.GetStreamAsync(textureUrl);
}

public Task<Stream> GetHeadByNameStream(string? userName)
{
return _httpClientLoader.GetStreamAsync($"/skin/{userName}/head/128");
}

private async Task<TextureReadDto?> UpdateTexture(IUser user, string skinUrl, string requestUri, string prefix)
{
var skinResponseMessage = await _httpClintSkinChecker.GetStreamAsync(skinUrl);
Expand Down
4 changes: 4 additions & 0 deletions src/Gml.Core/Core/Services/Storage/IStorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public interface IStorageService
Task<T?> GetUserBySkinAsync<T>(string guid, JsonSerializerOptions jsonSerializerOptions);
Task SetUserAsync<T>(string login, string uuid, T value);
Task<IEnumerable<T>> GetUsersAsync<T>(JsonSerializerOptions jsonSerializerOptions);
Task<IEnumerable<T>> GetUsersAsync<T>(JsonSerializerOptions jsonSerializerOptions,
IEnumerable<string> userUuids);
Task<IEnumerable<T>> GetUsersAsync<T>(JsonSerializerOptions jsonSerializerOptions, int take, int offset,
string findName);
Task AddBugAsync(IBugInfo bugInfo);
Task ClearBugsAsync();
Task<IEnumerable<T>> GetBugsAsync<T>();
Expand Down
26 changes: 26 additions & 0 deletions src/Gml.Core/Core/Services/Storage/SqliteStorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,32 @@ public async Task<IEnumerable<T>> GetUsersAsync<T>(JsonSerializerOptions jsonSer
return users!;
}

public async Task<IEnumerable<T>> GetUsersAsync<T>(JsonSerializerOptions jsonSerializerOptions,
IEnumerable<string> userUuids)
{
var users = (await _database
.Table<UserStorageItem>()
.Where(c => userUuids.Contains(c.Uuid))
.ToListAsync())
.Select(x => JsonSerializer.Deserialize<T>(x.Value, jsonSerializerOptions));

return users.OfType<T>();
}

public async Task<IEnumerable<T>> GetUsersAsync<T>(JsonSerializerOptions jsonSerializerOptions, int take,
int offset, string findName)
{
var users = (await _database
.Table<UserStorageItem>()
.Where(c => c.Login.Contains(findName))
.Take(take)
.Skip(offset)
.ToListAsync())
.Select(x => JsonSerializer.Deserialize<T>(x.Value, jsonSerializerOptions));

return users!;
}

public async Task AddBugAsync(IBugInfo bugInfo)
{
var serializedValue = JsonSerializer.Serialize(bugInfo, new JsonSerializerOptions { WriteIndented = true });
Expand Down
1 change: 1 addition & 0 deletions src/Gml.Core/Models/BaseProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ internal BaseProfile(string name, string gameVersion, GameLoader loader)
public List<IFileInfo>? FileWhiteList { get; set; }

public List<IFolderInfo>? FolderWhiteList { get; set; }
public List<string> UserWhiteListGuid { get; set; } = [];

public List<IProfileServer> Servers { get; set; } = new();

Expand Down
2 changes: 1 addition & 1 deletion src/Pingo
Submodule Pingo updated 1 files
+50 −30 Pingo/Minecraft.cs
Loading

0 comments on commit 0479839

Please sign in to comment.