From 958fc0105656bc41c7bf6370f69e459de498aa6a Mon Sep 17 00:00:00 2001 From: dingo Date: Thu, 25 Dec 2025 21:32:36 -0500 Subject: [PATCH] Pageing on CDN Assets Page, and Player management --- Services/Admin/Pages/Assets/Index.cshtml | 21 ++ Services/Admin/Pages/Assets/Index.cshtml.cs | 26 ++- Services/Admin/Pages/Mobs/Edit.cshtml | 53 +++++ Services/Admin/Pages/Mobs/Edit.cshtml.cs | 27 +++ Services/Admin/Pages/Players/Edit.cshtml | 222 +++++++++++++++++++ Services/Admin/Pages/Players/Edit.cshtml.cs | 186 ++++++++++++++++ Services/Admin/Pages/Players/Index.cshtml | 163 +++++++++++++- Services/Admin/Pages/Players/Index.cshtml.cs | 64 +++++- appsettings.json | 9 +- 9 files changed, 755 insertions(+), 16 deletions(-) create mode 100644 Services/Admin/Pages/Players/Edit.cshtml create mode 100644 Services/Admin/Pages/Players/Edit.cshtml.cs diff --git a/Services/Admin/Pages/Assets/Index.cshtml b/Services/Admin/Pages/Assets/Index.cshtml index 045a646..f2abd00 100644 --- a/Services/Admin/Pages/Assets/Index.cshtml +++ b/Services/Admin/Pages/Assets/Index.cshtml @@ -169,6 +169,27 @@ MINIO_USE_SSL=true + + + @if (Model.BrowseTotalPages > 1) + { +
+

+ Showing @((Model.BrowsePage - 1) * Model.BrowsePageSize + 1)-@Math.Min(Model.BrowsePage * Model.BrowsePageSize, Model.AllFiles.Count) of @Model.AllFiles.Count files +

+
+ @if (Model.BrowsePage > 1) + { + ← Prev + } + @Model.BrowsePage / @Model.BrowseTotalPages + @if (Model.BrowsePage < Model.BrowseTotalPages) + { + Next → + } +
+
+ } } else if (!Model.Subfolders.Any()) { diff --git a/Services/Admin/Pages/Assets/Index.cshtml.cs b/Services/Admin/Pages/Assets/Index.cshtml.cs index 2317ee5..15f4e5c 100644 --- a/Services/Admin/Pages/Assets/Index.cshtml.cs +++ b/Services/Admin/Pages/Assets/Index.cshtml.cs @@ -27,7 +27,16 @@ public class IndexModel : AdminPageModel public string? Prefix { get; set; } public bool CdnConfigured => _cdnService.IsConfigured; - public List Files { get; set; } = new(); + // Browse tab pagination + [FromQuery(Name = "bpage")] + public int BrowsePage { get; set; } = 1; + public int BrowsePageSize { get; set; } = 100; + public int BrowseTotalPages => (int)Math.Ceiling(AllFiles.Count / (double)BrowsePageSize); + public List AllFiles { get; set; } = new(); + public List Files => AllFiles + .Skip((BrowsePage - 1) * BrowsePageSize) + .Take(BrowsePageSize) + .ToList(); public List Subfolders { get; set; } = new(); public List AvailableFolders { get; set; } = new() { @@ -67,6 +76,13 @@ public class IndexModel : AdminPageModel public string? Message { get; set; } public bool IsError { get; set; } + public string GetBrowsePageUrl(int page) + { + var parts = new List { $"tab=browse", $"bpage={page}" }; + if (!string.IsNullOrEmpty(Prefix)) parts.Add($"prefix={Uri.EscapeDataString(Prefix)}"); + return "/admin/assets?" + string.Join("&", parts); + } + public string GetTrackedPageUrl(int page) { var parts = new List { $"tab=tracked", $"tpage={page}" }; @@ -91,13 +107,15 @@ public class IndexModel : AdminPageModel if (Tab == "browse" && CdnConfigured) { + if (BrowsePage < 1) BrowsePage = 1; + // Normalize prefix Prefix = Prefix?.TrimEnd('/'); if (!string.IsNullOrEmpty(Prefix)) Prefix += "/"; - // List files from MinIO - var allItems = await _cdnService.ListFilesAsync(Prefix ?? "", 200); + // List files from MinIO (increased limit) + var allItems = await _cdnService.ListFilesAsync(Prefix ?? "", 100000); // Separate files and folders Subfolders = allItems @@ -106,7 +124,7 @@ public class IndexModel : AdminPageModel .OrderBy(f => f) .ToList(); - Files = allItems + AllFiles = allItems .Where(f => !f.IsDirectory) .OrderBy(f => f.Name) .ToList(); diff --git a/Services/Admin/Pages/Mobs/Edit.cshtml b/Services/Admin/Pages/Mobs/Edit.cshtml index d39e1eb..42f773d 100644 --- a/Services/Admin/Pages/Mobs/Edit.cshtml +++ b/Services/Admin/Pages/Mobs/Edit.cshtml @@ -174,6 +174,59 @@ + +
+
+

Damage Resistances

+

Negative = weakness (takes more damage), Positive = resistance, 1.0 = immune

+
+
+
+ @foreach (var dt in Enum.GetValues()) + { + var currentValue = Model.GetResistance(dt.ToString().ToLower()); + var bgColor = currentValue < 0 ? "bg-red-900/30 border-red-700" : + currentValue > 0 ? "bg-green-900/30 border-green-700" : + "bg-gray-800 border-gray-700"; +
+ +
+ + +
+

+ @if (currentValue < 0) + { + +@((-currentValue * 100).ToString("0"))% damage taken + } + else if (currentValue > 0 && currentValue < 1) + { + -@((currentValue * 100).ToString("0"))% damage taken + } + else if (currentValue >= 1) + { + Immune + } + else + { + Normal damage + } +

+
+ } +
+
+
+
diff --git a/Services/Admin/Pages/Mobs/Edit.cshtml.cs b/Services/Admin/Pages/Mobs/Edit.cshtml.cs index 80452bb..6d1a784 100644 --- a/Services/Admin/Pages/Mobs/Edit.cshtml.cs +++ b/Services/Admin/Pages/Mobs/Edit.cshtml.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Data.Entities; +using System.Text.Json; namespace VoidScavengers.Services.Admin.Pages.Mobs; @@ -23,6 +24,19 @@ public class EditModel : AdminPageModel public bool IsNew => Mob.Id == 0; public string? Message { get; set; } public bool IsError { get; set; } + + // Helper to get resistance value for a damage type + public float GetResistance(string damageType) + { + try + { + var resistances = JsonSerializer.Deserialize>(Mob.ResistancesJson ?? "{}"); + if (resistances != null && resistances.TryGetValue(damageType, out var value)) + return value; + } + catch { } + return 0f; + } public async Task OnGetAsync(int? id) { @@ -79,6 +93,18 @@ public class EditModel : AdminPageModel // Ensure nullable strings are never null Mob.Description ??= ""; Mob.TintColor ??= "#ffffff"; + + // Parse resistances from form + var resistances = new Dictionary(); + foreach (var key in Request.Form.Keys.Where(k => k.StartsWith("resistance_"))) + { + var damageType = key.Replace("resistance_", ""); + if (float.TryParse(Request.Form[key], out var value) && value != 0) + { + resistances[damageType] = value; + } + } + Mob.ResistancesJson = JsonSerializer.Serialize(resistances); if (string.IsNullOrWhiteSpace(Mob.Name)) { @@ -171,6 +197,7 @@ public class EditModel : AdminPageModel existing.Scale = Mob.Scale; existing.AnimationSpeed = Mob.AnimationSpeed; existing.SpriteConfigJson = Mob.SpriteConfigJson; + existing.ResistancesJson = Mob.ResistancesJson; existing.IsEnabled = Mob.IsEnabled; await _db.SaveChangesAsync(); diff --git a/Services/Admin/Pages/Players/Edit.cshtml b/Services/Admin/Pages/Players/Edit.cshtml new file mode 100644 index 0000000..343cb56 --- /dev/null +++ b/Services/Admin/Pages/Players/Edit.cshtml @@ -0,0 +1,222 @@ +@page "/admin/players/edit" +@model Players.EditModel +@using Server.Data +@{ + ViewData["Title"] = Model.IsNew ? "New Account" : $"Edit: {Model.Account.Username}"; +} + +
+ +
+
+ ← Back to Players +

@(Model.IsNew ? "New Account" : Model.Account.Username)

+ @if (!Model.IsNew) + { +

Account ID: @Model.Account.Id • Created: @Model.Account.CreatedAt.ToString("yyyy-MM-dd HH:mm")

+ } +
+
+ + @if (!string.IsNullOrEmpty(Model.Message)) + { +
+ @Model.Message +
+ } + +
+ +
+

Account Information

+ +
+
+ + +

Username cannot be changed

+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+
+ + +
+

Role Management

+ +
+ @Html.AntiForgeryToken() + + +
+ + @{ + var roleColor = Model.Account.Role switch + { + AccountRole.SuperAdmin => "bg-red-600", + AccountRole.Admin => "bg-orange-600", + AccountRole.Moderator => "bg-yellow-600", + AccountRole.Vip => "bg-purple-600", + _ => "bg-gray-600" + }; + } + @Model.Account.Role +
+ +
+ + +
+ + +
+
+ + +
+

Ban Management

+ + @{ + var isBanned = Model.Account.IsBanned || (Model.Account.BannedUntil.HasValue && Model.Account.BannedUntil > DateTime.UtcNow); + } + +
+ + @if (isBanned) + { +
+ BANNED + @if (Model.Account.IsBanned) + { + (Permanent) + } + else if (Model.Account.BannedUntil.HasValue) + { + (Until @Model.Account.BannedUntil.Value.ToString("yyyy-MM-dd HH:mm UTC")) + } +
+ } + else + { +
+ ACTIVE + Account in good standing +
+ } +
+ + @if (isBanned) + { +
+ @Html.AntiForgeryToken() + + +
+ } + else + { +
+ @Html.AntiForgeryToken() + + +
+ + +
+ + + + +
+ } +
+ + +
+

Password Reset

+ +
+ @Html.AntiForgeryToken() + + +
+ + +

Minimum 6 characters

+
+ +
+ + +
+ + +
+
+
+ + + @if (Model.Characters.Any()) + { +
+

Characters (@Model.Characters.Count)

+ +
+ @foreach (var character in Model.Characters) + { +
+
+ @character.Name + Lv @character.Level +
+
+

Gold: @character.Gold.ToString("N0")

+

Created: @character.CreatedAt.ToString("yyyy-MM-dd")

+
+
+ } +
+
+ } +
+ +@section Scripts { + +} diff --git a/Services/Admin/Pages/Players/Edit.cshtml.cs b/Services/Admin/Pages/Players/Edit.cshtml.cs new file mode 100644 index 0000000..576a387 --- /dev/null +++ b/Services/Admin/Pages/Players/Edit.cshtml.cs @@ -0,0 +1,186 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Server.Data; +using Server.Data.Entities; +using Server.Services.Auth; + +namespace VoidScavengers.Services.Admin.Pages.Players; + +public class EditModel : AdminPageModel +{ + private readonly GameDbContext _db; + private readonly IPasswordHasher _passwordHasher; + + public EditModel(GameDbContext db, IPasswordHasher passwordHasher) + { + _db = db; + _passwordHasher = passwordHasher; + } + + public Account Account { get; set; } = new(); + public List Characters { get; set; } = new(); + + public bool IsNew => Account.Id == 0; + public string? Message { get; set; } + public bool IsError { get; set; } + + public async Task OnGetAsync(ulong? id) + { + if (!id.HasValue) + { + return RedirectToPage("/Players/Index"); + } + + var account = await _db.Set().FirstOrDefaultAsync(a => a.Id == id.Value); + if (account == null) + { + return RedirectToPage("/Players/Index"); + } + + Account = account; + + // Load characters + Characters = await _db.DungeonCharacters + .Where(c => c.AccountId == id.Value && !c.IsDeleted) + .OrderByDescending(c => c.Level) + .ToListAsync(); + + return Page(); + } + + public async Task OnPostSetRoleAsync(ulong accountId, AccountRole newRole) + { + var account = await _db.Set().FirstOrDefaultAsync(a => a.Id == accountId); + if (account == null) + { + Message = "Account not found."; + IsError = true; + return RedirectToPage("/Players/Index"); + } + + var oldRole = account.Role; + account.Role = newRole; + await _db.SaveChangesAsync(); + + Account = account; + Characters = await _db.DungeonCharacters + .Where(c => c.AccountId == accountId && !c.IsDeleted) + .OrderByDescending(c => c.Level) + .ToListAsync(); + + Message = $"Role changed from {oldRole} to {newRole}."; + return Page(); + } + + public async Task OnPostBanAsync(ulong accountId, string banType, DateTime? bannedUntil) + { + var account = await _db.Set().FirstOrDefaultAsync(a => a.Id == accountId); + if (account == null) + { + Message = "Account not found."; + IsError = true; + return RedirectToPage("/Players/Index"); + } + + if (banType == "permanent") + { + account.IsBanned = true; + account.BannedUntil = null; + Message = "Account permanently banned."; + } + else if (banType == "temporary" && bannedUntil.HasValue) + { + account.IsBanned = false; + account.BannedUntil = bannedUntil.Value.ToUniversalTime(); + Message = $"Account banned until {account.BannedUntil.Value:yyyy-MM-dd HH:mm} UTC."; + } + else + { + Message = "Invalid ban parameters."; + IsError = true; + } + + await _db.SaveChangesAsync(); + + Account = account; + Characters = await _db.DungeonCharacters + .Where(c => c.AccountId == accountId && !c.IsDeleted) + .OrderByDescending(c => c.Level) + .ToListAsync(); + + return Page(); + } + + public async Task OnPostUnbanAsync(ulong accountId) + { + var account = await _db.Set().FirstOrDefaultAsync(a => a.Id == accountId); + if (account == null) + { + Message = "Account not found."; + IsError = true; + return RedirectToPage("/Players/Index"); + } + + account.IsBanned = false; + account.BannedUntil = null; + await _db.SaveChangesAsync(); + + Account = account; + Characters = await _db.DungeonCharacters + .Where(c => c.AccountId == accountId && !c.IsDeleted) + .OrderByDescending(c => c.Level) + .ToListAsync(); + + Message = "Ban removed. Account is now active."; + return Page(); + } + + public async Task OnPostResetPasswordAsync(ulong accountId, string newPassword, string confirmPassword) + { + var account = await _db.Set().FirstOrDefaultAsync(a => a.Id == accountId); + if (account == null) + { + Message = "Account not found."; + IsError = true; + return RedirectToPage("/Players/Index"); + } + + if (string.IsNullOrWhiteSpace(newPassword) || newPassword.Length < 6) + { + Account = account; + Characters = await _db.DungeonCharacters + .Where(c => c.AccountId == accountId && !c.IsDeleted) + .OrderByDescending(c => c.Level) + .ToListAsync(); + Message = "Password must be at least 6 characters."; + IsError = true; + return Page(); + } + + if (newPassword != confirmPassword) + { + Account = account; + Characters = await _db.DungeonCharacters + .Where(c => c.AccountId == accountId && !c.IsDeleted) + .OrderByDescending(c => c.Level) + .ToListAsync(); + Message = "Passwords do not match."; + IsError = true; + return Page(); + } + + _passwordHasher.Hash(newPassword, out var hash, out var salt); + account.PasswordHash = hash; + account.PasswordSalt = salt; + await _db.SaveChangesAsync(); + + Account = account; + Characters = await _db.DungeonCharacters + .Where(c => c.AccountId == accountId && !c.IsDeleted) + .OrderByDescending(c => c.Level) + .ToListAsync(); + + Message = "Password has been reset."; + return Page(); + } +} diff --git a/Services/Admin/Pages/Players/Index.cshtml b/Services/Admin/Pages/Players/Index.cshtml index 37795c9..48d22be 100644 --- a/Services/Admin/Pages/Players/Index.cshtml +++ b/Services/Admin/Pages/Players/Index.cshtml @@ -1,16 +1,167 @@ @page "/admin/players" @model Players.IndexModel +@using Server.Data @{ ViewData["Title"] = "Players"; }
-
-

Players

-

Manage player accounts (@Model.PlayerCount total)

+ +
+
+

Players

+

Manage player accounts

+
- -
-

Player management coming soon...

+ + +
+
+
+ + +
+
+ + +
+
+ + +
+ + Clear +
+ + +
+
+

@Model.TotalCount

+

Total Accounts

+
+
+

@Model.ActiveCount

+

Active

+
+
+

@Model.BannedCount

+

Banned

+
+
+

@Model.AdminCount

+

Admins

+
+
+ + +
+ + + + + + + + + + + + + + @foreach (var account in Model.Accounts) + { + var isBanned = account.IsBanned || (account.BannedUntil.HasValue && account.BannedUntil > DateTime.UtcNow); + + + + + + + + + + } + + @if (!Model.Accounts.Any()) + { + + + + } + +
IDUsernameEmailRoleStatusCreatedActions
@account.Id + @account.Username + @(account.Email ?? "-") + @{ + var roleColor = account.Role switch + { + AccountRole.SuperAdmin => "bg-red-600", + AccountRole.Admin => "bg-orange-600", + AccountRole.Moderator => "bg-yellow-600", + AccountRole.Vip => "bg-purple-600", + _ => "bg-gray-600" + }; + } + @account.Role + + @if (isBanned) + { + + @if (account.BannedUntil.HasValue && account.BannedUntil > DateTime.UtcNow) + { + Until @account.BannedUntil.Value.ToString("MMM d") + } + else + { + Permanent + } + + } + else + { + Active + } + @account.CreatedAt.ToString("yyyy-MM-dd") + Edit +
No accounts found.
+
+ + + @if (Model.TotalPages > 1) + { +
+

+ Showing @((Model.CurrentPage - 1) * Model.PageSize + 1)-@Math.Min(Model.CurrentPage * Model.PageSize, Model.TotalCount) of @Model.TotalCount +

+
+ @if (Model.CurrentPage > 1) + { + ← Prev + } + @Model.CurrentPage / @Model.TotalPages + @if (Model.CurrentPage < Model.TotalPages) + { + Next → + } +
+
+ }
+ +@if (!string.IsNullOrEmpty(Model.Message)) +{ +
+ @Model.Message +
+} diff --git a/Services/Admin/Pages/Players/Index.cshtml.cs b/Services/Admin/Pages/Players/Index.cshtml.cs index 27767e5..ba4b1a9 100644 --- a/Services/Admin/Pages/Players/Index.cshtml.cs +++ b/Services/Admin/Pages/Players/Index.cshtml.cs @@ -1,3 +1,4 @@ +using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Server.Data; @@ -12,10 +13,69 @@ public class IndexModel : AdminPageModel _db = db; } - public int PlayerCount { get; set; } + public List Accounts { get; set; } = new(); + + [FromQuery(Name = "search")] + public string? Search { get; set; } + + [FromQuery(Name = "role")] + public AccountRole? RoleFilter { get; set; } + + [FromQuery(Name = "status")] + public string? StatusFilter { get; set; } + + [FromQuery(Name = "page")] + public int CurrentPage { get; set; } = 1; + + public int PageSize { get; set; } = 25; + public int TotalCount { get; set; } + public int TotalPages => (int)Math.Ceiling(TotalCount / (double)PageSize); + + // Stats + public int ActiveCount { get; set; } + public int BannedCount { get; set; } + public int AdminCount { get; set; } + + public string? Message { get; set; } + public bool IsError { get; set; } + + public string GetPageUrl(int page) + { + var parts = new List { $"page={page}" }; + if (!string.IsNullOrEmpty(Search)) parts.Add($"search={Uri.EscapeDataString(Search)}"); + if (RoleFilter.HasValue) parts.Add($"role={RoleFilter}"); + if (!string.IsNullOrEmpty(StatusFilter)) parts.Add($"status={StatusFilter}"); + return "/admin/players?" + string.Join("&", parts); + } public async Task OnGetAsync() { - PlayerCount = await _db.Accounts.CountAsync(); + if (CurrentPage < 1) CurrentPage = 1; + + // Stats + ActiveCount = await _db.Set().CountAsync(a => !a.IsBanned && (a.BannedUntil == null || a.BannedUntil <= DateTime.UtcNow)); + BannedCount = await _db.Set().CountAsync(a => a.IsBanned || (a.BannedUntil != null && a.BannedUntil > DateTime.UtcNow)); + AdminCount = await _db.Set().CountAsync(a => a.Role >= AccountRole.Admin); + + var query = _db.Set().AsQueryable(); + + if (!string.IsNullOrWhiteSpace(Search)) + query = query.Where(a => a.Username.Contains(Search) || (a.Email != null && a.Email.Contains(Search))); + + if (RoleFilter.HasValue) + query = query.Where(a => a.Role == RoleFilter.Value); + + if (StatusFilter == "banned") + query = query.Where(a => a.IsBanned || (a.BannedUntil != null && a.BannedUntil > DateTime.UtcNow)); + else if (StatusFilter == "active") + query = query.Where(a => !a.IsBanned && (a.BannedUntil == null || a.BannedUntil <= DateTime.UtcNow)); + + TotalCount = await query.CountAsync(); + + Accounts = await query + .OrderByDescending(a => a.CreatedAt) + .Skip((CurrentPage - 1) * PageSize) + .Take(PageSize) + .ToListAsync(); } } diff --git a/appsettings.json b/appsettings.json index a2113df..a9f2ac2 100644 --- a/appsettings.json +++ b/appsettings.json @@ -7,16 +7,17 @@ }, "AllowedHosts": "*", "Database": { - "ConnectionString": "Server=a2nlmysql45plsk.secureserver.net;Port=3306;Database=Theraborn;User ID=tbadmin;Password=8N10ml9x?;Pooling=true;Minimum Pool Size=0;Maximum Pool Size=50;", + "ConnectionString": "",//Server=a2nlmysql45plsk.secureserver.net;Port=3306;Database=Theraborn;User ID=tbadmin;Password=8N10ml9x?;Pooling=true;Minimum Pool Size=0;Maximum Pool Size=50;", "CommandTimeoutSeconds": 30, "MaxRetryCount": 3, "RetryBaseDelayMs": 100 }, "MinIO": { "Endpoint": "assets.aeternalisgames.com", - "AccessKey": "STTQyhxgIWf4NvqQG06f", - "SecretKey": "uN4ui336iVJcwBjT3mEv", + "AccessKey": "", + "SecretKey": "", "BucketName": "downloads", - "UseSSL": true + "UseSSL": true, + "AnonymousAccess": true } }