From ef3ce84aecd86dfe5d5ab07a4fa270f39899466e Mon Sep 17 00:00:00 2001 From: dingo Date: Wed, 24 Dec 2025 20:34:48 -0500 Subject: [PATCH] AdminPanel --- Program.cs | 24 ++ Services/Admin/Pages/AdminPageModel.cs | 29 ++ Services/Admin/Pages/Assets/Index.cshtml | 210 ++++++++++++ Services/Admin/Pages/Assets/Index.cshtml.cs | 75 ++++ Services/Admin/Pages/Index.cshtml | 146 ++++++++ Services/Admin/Pages/Index.cshtml.cs | 38 +++ Services/Admin/Pages/Items/Edit.cshtml | 338 +++++++++++++++++++ Services/Admin/Pages/Items/Edit.cshtml.cs | 180 ++++++++++ Services/Admin/Pages/Items/Index.cshtml | 214 ++++++++++++ Services/Admin/Pages/Items/Index.cshtml.cs | 78 +++++ Services/Admin/Pages/Login.cshtml | 68 ++++ Services/Admin/Pages/Login.cshtml.cs | 81 +++++ Services/Admin/Pages/Logout.cshtml | 5 + Services/Admin/Pages/Logout.cshtml.cs | 13 + Services/Admin/Pages/Mobs/Index.cshtml | 25 ++ Services/Admin/Pages/Mobs/Index.cshtml.cs | 21 ++ Services/Admin/Pages/Players/Index.cshtml | 17 + Services/Admin/Pages/Players/Index.cshtml.cs | 21 ++ Services/Admin/Pages/Recipes/Index.cshtml | 25 ++ Services/Admin/Pages/Recipes/Index.cshtml.cs | 21 ++ Services/Admin/Pages/Shared/_Layout.cshtml | 148 ++++++++ Services/Admin/Pages/_ViewImports.cshtml | 2 + Services/Admin/Pages/_ViewStart.cshtml | 3 + 23 files changed, 1782 insertions(+) create mode 100644 Services/Admin/Pages/AdminPageModel.cs create mode 100644 Services/Admin/Pages/Assets/Index.cshtml create mode 100644 Services/Admin/Pages/Assets/Index.cshtml.cs create mode 100644 Services/Admin/Pages/Index.cshtml create mode 100644 Services/Admin/Pages/Index.cshtml.cs create mode 100644 Services/Admin/Pages/Items/Edit.cshtml create mode 100644 Services/Admin/Pages/Items/Edit.cshtml.cs create mode 100644 Services/Admin/Pages/Items/Index.cshtml create mode 100644 Services/Admin/Pages/Items/Index.cshtml.cs create mode 100644 Services/Admin/Pages/Login.cshtml create mode 100644 Services/Admin/Pages/Login.cshtml.cs create mode 100644 Services/Admin/Pages/Logout.cshtml create mode 100644 Services/Admin/Pages/Logout.cshtml.cs create mode 100644 Services/Admin/Pages/Mobs/Index.cshtml create mode 100644 Services/Admin/Pages/Mobs/Index.cshtml.cs create mode 100644 Services/Admin/Pages/Players/Index.cshtml create mode 100644 Services/Admin/Pages/Players/Index.cshtml.cs create mode 100644 Services/Admin/Pages/Recipes/Index.cshtml create mode 100644 Services/Admin/Pages/Recipes/Index.cshtml.cs create mode 100644 Services/Admin/Pages/Shared/_Layout.cshtml create mode 100644 Services/Admin/Pages/_ViewImports.cshtml create mode 100644 Services/Admin/Pages/_ViewStart.cshtml diff --git a/Program.cs b/Program.cs index 36061e7..43386d4 100644 --- a/Program.cs +++ b/Program.cs @@ -20,6 +20,24 @@ using VoidScavengers.Game; var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers(); + +// ---- Razor Pages for Admin Panel ---- +builder.Services.AddRazorPages() + .AddRazorPagesOptions(options => + { + options.RootDirectory = "/Admin/Pages"; + }); + +// ---- Session for Admin Auth ---- +builder.Services.AddDistributedMemoryCache(); +builder.Services.AddSession(options => +{ + options.IdleTimeout = TimeSpan.FromHours(8); + options.Cookie.HttpOnly = true; + options.Cookie.IsEssential = true; + options.Cookie.Name = ".VoidScavengers.Admin"; +}); + // ---- MySQL conn string from env ---- string mysqlConnectionString = ConnectionStringFactory.BuildMySqlFromEnv(); @@ -153,6 +171,9 @@ app.MapGet("/health/ready", async (IRedisManager rm, HealthCheckService hc) => catch { return Results.StatusCode(503); } }); +// ---- Session middleware (must be before routing) ---- +app.UseSession(); + // ---- WebSockets endpoint ---- app.UseWebSockets(new WebSocketOptions { KeepAliveInterval = TimeSpan.FromSeconds(20) }); @@ -197,4 +218,7 @@ app.Lifetime.ApplicationStopping.Register(() => // var leases = app.Services.GetRequiredService(); // _ = leases.TryAcquireAsync(zoneId: 1); app.MapControllers(); +app.MapRazorPages(); + +app.Logger.LogInformation("Admin panel available at /admin"); await app.RunAsync(); diff --git a/Services/Admin/Pages/AdminPageModel.cs b/Services/Admin/Pages/AdminPageModel.cs new file mode 100644 index 0000000..fbdc161 --- /dev/null +++ b/Services/Admin/Pages/AdminPageModel.cs @@ -0,0 +1,29 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace VoidScavengers.Admin.Pages; + +/// +/// Base class for all admin pages that require authentication +/// +public class AdminPageModel : PageModel +{ + public override void OnPageHandlerExecuting(PageHandlerExecutingContext context) + { + // Check if logged in + var adminId = HttpContext.Session.GetString("AdminId"); + if (string.IsNullOrEmpty(adminId)) + { + context.Result = new RedirectToPageResult("/Login"); + return; + } + + // Set ViewData for layout + ViewData["AdminId"] = adminId; + ViewData["AdminUsername"] = HttpContext.Session.GetString("AdminUsername"); + ViewData["AdminRole"] = HttpContext.Session.GetString("AdminRole"); + + base.OnPageHandlerExecuting(context); + } +} diff --git a/Services/Admin/Pages/Assets/Index.cshtml b/Services/Admin/Pages/Assets/Index.cshtml new file mode 100644 index 0000000..5815f26 --- /dev/null +++ b/Services/Admin/Pages/Assets/Index.cshtml @@ -0,0 +1,210 @@ +@page "/admin/assets" +@model VoidScavengers.Admin.Pages.Assets.IndexModel +@{ + ViewData["Title"] = "CDN Assets"; +} + +
+
+
+

CDN Assets

+

Browse and manage assets from your CDN

+
+ + + + + Sync from CDN + +
+ + +
+
+
+ + + +
+
+

CDN Base URL

+

@Model.CdnBaseUrl

+
+
+

Registered Assets

+

@Model.AssetCount

+
+
+
+ + +
+
+
+ + +
+
+ + +
+ + Clear +
+
+ + +
+ @foreach (var asset in Model.Assets) + { +
+
+ @if (asset.AssetType == Server.Data.Entities.ClientAssetType.Texture) + { + @asset.FilePath + + } + else if (asset.AssetType == Server.Data.Entities.ClientAssetType.Scene) + { + + + + } + else if (asset.AssetType == Server.Data.Entities.ClientAssetType.Script) + { + + + + } + else + { + + + + } +
+

@System.IO.Path.GetFileName(asset.FilePath)

+
+ } + + @if (!Model.Assets.Any()) + { +
+

No assets found.

+

Assets are registered in the client_assets table.

+
+ } +
+ + + @if (Model.TotalPages > 1) + { +
+

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

+
+ @if (Model.Page > 1) + { + Previous + } + Page @Model.Page of @Model.TotalPages + @if (Model.Page < Model.TotalPages) + { + Next + } +
+
+ } +
+ + + + +@section Scripts { + +} diff --git a/Services/Admin/Pages/Assets/Index.cshtml.cs b/Services/Admin/Pages/Assets/Index.cshtml.cs new file mode 100644 index 0000000..ca9974b --- /dev/null +++ b/Services/Admin/Pages/Assets/Index.cshtml.cs @@ -0,0 +1,75 @@ +using Microsoft.EntityFrameworkCore; +using Server.Data; +using Server.Data.Entities; + +namespace VoidScavengers.Admin.Pages.Assets; + +public class IndexModel : AdminPageModel +{ + private readonly GameDbContext _db; + + public IndexModel(GameDbContext db) + { + _db = db; + } + + public List Assets { get; set; } = new(); + public string? Search { get; set; } + public string? TypeFilter { get; set; } + public int Page { get; set; } = 1; + public int PageSize { get; set; } = 24; + public int TotalCount { get; set; } + public int AssetCount { get; set; } + public int TotalPages => (int)Math.Ceiling(TotalCount / (double)PageSize); + public string CdnBaseUrl { get; set; } = "https://assets.aeternalisgames.com"; + + public async Task OnGetAsync(string? search, string? type, int page = 1) + { + Search = search; + TypeFilter = type; + Page = Math.Max(1, page); + + // Get CDN URL from environment + var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL"); + if (!string.IsNullOrEmpty(cdnUrl)) + { + CdnBaseUrl = cdnUrl; + } + + AssetCount = await _db.ClientAssets.CountAsync(); + + var query = _db.ClientAssets.AsQueryable(); + + if (!string.IsNullOrWhiteSpace(search)) + { + query = query.Where(a => a.FilePath.Contains(search)); + } + + if (!string.IsNullOrWhiteSpace(type)) + { + switch (type.ToLower()) + { + case "sprite": + query = query.Where(a => a.AssetType == ClientAssetType.Texture); + break; + case "scene": + query = query.Where(a => a.AssetType == ClientAssetType.Scene); + break; + case "script": + query = query.Where(a => a.AssetType == ClientAssetType.Script); + break; + case "audio": + query = query.Where(a => a.AssetType == ClientAssetType.Audio); + break; + } + } + + TotalCount = await query.CountAsync(); + + Assets = await query + .OrderBy(a => a.FilePath) + .Skip((Page - 1) * PageSize) + .Take(PageSize) + .ToListAsync(); + } +} diff --git a/Services/Admin/Pages/Index.cshtml b/Services/Admin/Pages/Index.cshtml new file mode 100644 index 0000000..3db43d3 --- /dev/null +++ b/Services/Admin/Pages/Index.cshtml @@ -0,0 +1,146 @@ +@page "/admin" +@model VoidScavengers.Admin.Pages.IndexModel +@{ + ViewData["Title"] = "Dashboard"; +} + +
+ +
+

Dashboard

+

Welcome back, @ViewData["AdminUsername"]

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

@Model.ItemCount

+

Items

+
+
+ + Manage items → + +
+ + +
+
+
+ + + +
+
+

@Model.MobCount

+

Mobs

+
+
+ + Manage mobs → + +
+ + +
+
+
+ + + +
+
+

@Model.RecipeCount

+

Recipes

+
+
+ + Manage recipes → + +
+ + +
+
+
+ + + +
+
+

@Model.PlayerCount

+

Players

+
+
+ + Manage players → + +
+
+ + + + + +
+
+

CDN Assets

+

@Model.AssetCount assets registered

+
+
+

CDN Base URL: @Model.CdnBaseUrl

+ + Browse Assets + +
+
+
diff --git a/Services/Admin/Pages/Index.cshtml.cs b/Services/Admin/Pages/Index.cshtml.cs new file mode 100644 index 0000000..38a9265 --- /dev/null +++ b/Services/Admin/Pages/Index.cshtml.cs @@ -0,0 +1,38 @@ +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; +using Server.Data; + +namespace VoidScavengers.Admin.Pages; + +public class IndexModel : AdminPageModel +{ + private readonly GameDbContext _db; + + public IndexModel(GameDbContext db) + { + _db = db; + } + + public int ItemCount { get; set; } + public int MobCount { get; set; } + public int RecipeCount { get; set; } + public int PlayerCount { get; set; } + public int AssetCount { get; set; } + public string CdnBaseUrl { get; set; } = "https://assets.aeternalisgames.com"; + + public async Task OnGetAsync() + { + ItemCount = await _db.DungeonItemDefinitions.CountAsync(); + MobCount = await _db.DungeonMobDefinitions.CountAsync(); + RecipeCount = await _db.DungeonCraftingRecipes.CountAsync(); + PlayerCount = await _db.Accounts.CountAsync(); + AssetCount = await _db.ClientAssets.CountAsync(); + + // Get CDN URL from environment if set + var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL"); + if (!string.IsNullOrEmpty(cdnUrl)) + { + CdnBaseUrl = cdnUrl; + } + } +} diff --git a/Services/Admin/Pages/Items/Edit.cshtml b/Services/Admin/Pages/Items/Edit.cshtml new file mode 100644 index 0000000..78e0ae1 --- /dev/null +++ b/Services/Admin/Pages/Items/Edit.cshtml @@ -0,0 +1,338 @@ +@page "/admin/items/edit" +@model VoidScavengers.Admin.Pages.Items.EditModel +@{ + ViewData["Title"] = Model.IsNew ? "Create Item" : $"Edit: {Model.Item.Name}"; +} + +
+ +
+ + + + + +
+

@(Model.IsNew ? "Create Item" : "Edit Item")

+

@(Model.IsNew ? "Add a new item definition" : $"Editing item #{Model.Item.Id}")

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

Basic Information

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

Stacking

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

Visual

+
+
+
+ +
+ + +
+

Path relative to CDN root

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

Stat Requirements

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

Stat Bonuses (When Equipped)

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

Combat Stats

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

Consumable Effects

+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+ + Cancel + + @if (!Model.IsNew) + { +
+ + } +
+
+
+ +@section Scripts { + +} diff --git a/Services/Admin/Pages/Items/Edit.cshtml.cs b/Services/Admin/Pages/Items/Edit.cshtml.cs new file mode 100644 index 0000000..3418e6c --- /dev/null +++ b/Services/Admin/Pages/Items/Edit.cshtml.cs @@ -0,0 +1,180 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Server.Data; +using Server.Data.Entities; + +namespace VoidScavengers.Admin.Pages.Items; + +public class EditModel : AdminPageModel +{ + private readonly GameDbContext _db; + + public EditModel(GameDbContext db) + { + _db = db; + } + + [BindProperty] + public DungeonItemDefinition Item { get; set; } = new(); + + public bool IsNew => Item.Id == 0; + public string? Message { get; set; } + public bool IsError { get; set; } + public string CdnBaseUrl { get; set; } = "https://assets.aeternalisgames.com"; + + public async Task OnGetAsync(int? id) + { + // Get CDN URL from environment + var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL"); + if (!string.IsNullOrEmpty(cdnUrl)) + { + CdnBaseUrl = cdnUrl; + } + + if (id.HasValue) + { + var item = await _db.DungeonItemDefinitions.FindAsync(id.Value); + if (item != null) + { + Item = item; + } + } + else + { + // Set defaults for new item + Item.IsEnabled = true; + Item.RequiredLevel = 1; + Item.MaxStack = 1; + } + } + + public async Task OnPostAsync(string? action) + { + // Get CDN URL from environment + var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL"); + if (!string.IsNullOrEmpty(cdnUrl)) + { + CdnBaseUrl = cdnUrl; + } + + if (!ModelState.IsValid) + { + Message = "Please fix the errors below."; + IsError = true; + return Page(); + } + + try + { + if (action == "duplicate") + { + // Create a duplicate + var newItem = new DungeonItemDefinition + { + Name = Item.Name + " (Copy)", + Description = Item.Description, + Type = Item.Type, + Rarity = Item.Rarity, + EquipSlot = Item.EquipSlot, + RequiredStrength = Item.RequiredStrength, + RequiredIntelligence = Item.RequiredIntelligence, + RequiredWisdom = Item.RequiredWisdom, + RequiredDexterity = Item.RequiredDexterity, + RequiredLevel = Item.RequiredLevel, + BonusStrength = Item.BonusStrength, + BonusIntelligence = Item.BonusIntelligence, + BonusWisdom = Item.BonusWisdom, + BonusEndurance = Item.BonusEndurance, + BonusDexterity = Item.BonusDexterity, + BonusHealth = Item.BonusHealth, + BonusMana = Item.BonusMana, + MinDamage = Item.MinDamage, + MaxDamage = Item.MaxDamage, + AttackRange = Item.AttackRange, + DamageType = Item.DamageType, + Armor = Item.Armor, + MagicResist = Item.MagicResist, + HealAmount = Item.HealAmount, + ManaRestore = Item.ManaRestore, + StaminaRestore = Item.StaminaRestore, + Stackable = Item.Stackable, + MaxStack = Item.MaxStack, + SpritePath = Item.SpritePath, + TintColor = Item.TintColor, + IsEnabled = Item.IsEnabled + }; + + _db.DungeonItemDefinitions.Add(newItem); + await _db.SaveChangesAsync(); + + return RedirectToPage("/Items/Edit", new { id = newItem.Id }); + } + + if (Item.Id == 0) + { + // Create new + _db.DungeonItemDefinitions.Add(Item); + await _db.SaveChangesAsync(); + + Message = $"Item '{Item.Name}' created successfully with ID {Item.Id}"; + return RedirectToPage("/Items/Edit", new { id = Item.Id }); + } + else + { + // Update existing + var existing = await _db.DungeonItemDefinitions.FindAsync(Item.Id); + if (existing == null) + { + Message = "Item not found."; + IsError = true; + return Page(); + } + + // Update all properties + existing.Name = Item.Name; + existing.Description = Item.Description; + existing.Type = Item.Type; + existing.Rarity = Item.Rarity; + existing.EquipSlot = Item.EquipSlot; + existing.RequiredStrength = Item.RequiredStrength; + existing.RequiredIntelligence = Item.RequiredIntelligence; + existing.RequiredWisdom = Item.RequiredWisdom; + existing.RequiredDexterity = Item.RequiredDexterity; + existing.RequiredLevel = Item.RequiredLevel; + existing.BonusStrength = Item.BonusStrength; + existing.BonusIntelligence = Item.BonusIntelligence; + existing.BonusWisdom = Item.BonusWisdom; + existing.BonusEndurance = Item.BonusEndurance; + existing.BonusDexterity = Item.BonusDexterity; + existing.BonusHealth = Item.BonusHealth; + existing.BonusMana = Item.BonusMana; + existing.MinDamage = Item.MinDamage; + existing.MaxDamage = Item.MaxDamage; + existing.AttackRange = Item.AttackRange; + existing.DamageType = Item.DamageType; + existing.Armor = Item.Armor; + existing.MagicResist = Item.MagicResist; + existing.HealAmount = Item.HealAmount; + existing.ManaRestore = Item.ManaRestore; + existing.StaminaRestore = Item.StaminaRestore; + existing.Stackable = Item.Stackable; + existing.MaxStack = Item.MaxStack; + existing.SpritePath = Item.SpritePath; + existing.TintColor = Item.TintColor; + existing.IsEnabled = Item.IsEnabled; + + await _db.SaveChangesAsync(); + + Item = existing; + Message = "Changes saved successfully."; + } + } + catch (Exception ex) + { + Message = $"Error saving item: {ex.Message}"; + IsError = true; + } + + return Page(); + } +} diff --git a/Services/Admin/Pages/Items/Index.cshtml b/Services/Admin/Pages/Items/Index.cshtml new file mode 100644 index 0000000..a5a5f68 --- /dev/null +++ b/Services/Admin/Pages/Items/Index.cshtml @@ -0,0 +1,214 @@ +@page "/admin/items" +@model VoidScavengers.Admin.Pages.Items.IndexModel +@{ + ViewData["Title"] = "Items"; +} + +
+ +
+
+

Items

+

Manage item definitions

+
+ + + + + Create Item + +
+ + +
+
+
+ + +
+
+ + +
+
+ + +
+ + Clear +
+
+ + +
+ + + + + + + + + + + + + + + @foreach (var item in Model.Items) + { + + + + + + + + + + + } + + @if (!Model.Items.Any()) + { + + + + } + +
IDIconNameTypeRarityStackableEnabledActions
@item.Id + @if (!string.IsNullOrEmpty(item.SpritePath)) + { + @item.Name + } + else + { +
+ + + +
+ } +
@item.Name@item.Type + @item.Rarity + + @if (item.Stackable) + { + Yes (@item.MaxStack) + } + else + { + No + } + + @if (item.IsEnabled) + { + + + + + Yes + + } + else + { + + + + + No + + } + +
+ + + + + + +
+
+ No items found. + Create one? +
+
+ + + @if (Model.TotalPages > 1) + { +
+

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

+
+ @if (Model.Page > 1) + { + Previous + } + Page @Model.Page of @Model.TotalPages + @if (Model.Page < Model.TotalPages) + { + Next + } +
+
+ } +
+ + + + +@section Scripts { + +} diff --git a/Services/Admin/Pages/Items/Index.cshtml.cs b/Services/Admin/Pages/Items/Index.cshtml.cs new file mode 100644 index 0000000..e165b86 --- /dev/null +++ b/Services/Admin/Pages/Items/Index.cshtml.cs @@ -0,0 +1,78 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Server.Data; +using Server.Data.Entities; +using Server.Data.Enums; + +namespace VoidScavengers.Admin.Pages.Items; + +public class IndexModel : AdminPageModel +{ + private readonly GameDbContext _db; + + public IndexModel(GameDbContext db) + { + _db = db; + } + + public List Items { get; set; } = new(); + public string? Search { get; set; } + public ItemType? TypeFilter { get; set; } + public ItemRarity? RarityFilter { get; set; } + public int Page { get; set; } = 1; + public int PageSize { get; set; } = 20; + public int TotalCount { get; set; } + public int TotalPages => (int)Math.Ceiling(TotalCount / (double)PageSize); + public string CdnBaseUrl { get; set; } = "https://assets.aeternalisgames.com"; + + public async Task OnGetAsync(string? search, ItemType? type, ItemRarity? rarity, int page = 1) + { + Search = search; + TypeFilter = type; + RarityFilter = rarity; + Page = Math.Max(1, page); + + var query = _db.DungeonItemDefinitions.AsQueryable(); + + if (!string.IsNullOrWhiteSpace(search)) + { + query = query.Where(i => i.Name.Contains(search) || i.Description.Contains(search)); + } + + if (type.HasValue) + { + query = query.Where(i => i.Type == type.Value); + } + + if (rarity.HasValue) + { + query = query.Where(i => i.Rarity == rarity.Value); + } + + TotalCount = await query.CountAsync(); + + Items = await query + .OrderBy(i => i.Id) + .Skip((Page - 1) * PageSize) + .Take(PageSize) + .ToListAsync(); + + // Get CDN URL from environment if set + var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL"); + if (!string.IsNullOrEmpty(cdnUrl)) + { + CdnBaseUrl = cdnUrl; + } + } + + public async Task OnPostDeleteAsync(int id) + { + var item = await _db.DungeonItemDefinitions.FindAsync(id); + if (item != null) + { + _db.DungeonItemDefinitions.Remove(item); + await _db.SaveChangesAsync(); + } + return RedirectToPage(); + } +} diff --git a/Services/Admin/Pages/Login.cshtml b/Services/Admin/Pages/Login.cshtml new file mode 100644 index 0000000..4caf465 --- /dev/null +++ b/Services/Admin/Pages/Login.cshtml @@ -0,0 +1,68 @@ +@page "/admin/login" +@model VoidScavengers.Admin.Pages.LoginModel +@{ + Layout = null; + ViewData["Title"] = "Login"; +} + + + + + + + Admin Login - Void Scavengers + + + +
+
+ +
+
+ + + +
+

Void Scavengers

+

Admin Panel

+
+ + + @if (!string.IsNullOrEmpty(Model.ErrorMessage)) + { +
+ @Model.ErrorMessage +
+ } + + +
+ @Html.AntiForgeryToken() + +
+ + +
+ +
+ + +
+ + +
+ +

+ Only authorized administrators can access this panel. +

+
+
+ + diff --git a/Services/Admin/Pages/Login.cshtml.cs b/Services/Admin/Pages/Login.cshtml.cs new file mode 100644 index 0000000..1122b40 --- /dev/null +++ b/Services/Admin/Pages/Login.cshtml.cs @@ -0,0 +1,81 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; +using Server.Data; +using Server.Services.Auth; + +namespace VoidScavengers.Admin.Pages; + +public class LoginModel : PageModel +{ + private readonly GameDbContext _db; + private readonly IPasswordHasher _hasher; + + public LoginModel(GameDbContext db, IPasswordHasher hasher) + { + _db = db; + _hasher = hasher; + } + + [BindProperty] + public string Username { get; set; } = ""; + + [BindProperty] + public string Password { get; set; } = ""; + + public string? ErrorMessage { get; set; } + + public void OnGet() + { + // Check if already logged in + if (HttpContext.Session.GetString("AdminId") != null) + { + Response.Redirect("/admin"); + } + } + + public async Task OnPostAsync() + { + if (string.IsNullOrWhiteSpace(Username) || string.IsNullOrWhiteSpace(Password)) + { + ErrorMessage = "Username and password are required."; + return Page(); + } + + var account = await _db.Accounts + .FirstOrDefaultAsync(a => a.Username == Username); + + if (account == null) + { + ErrorMessage = "Invalid username or password."; + return Page(); + } + + if (!_hasher.Verify(Password, account.PasswordHash, account.PasswordSalt)) + { + ErrorMessage = "Invalid username or password."; + return Page(); + } + + // Check if admin + if (account.Role < AccountRole.Moderator) + { + ErrorMessage = "You do not have permission to access the admin panel."; + return Page(); + } + + // Check if banned + if (account.IsBanned) + { + ErrorMessage = "Your account has been banned."; + return Page(); + } + + // Set session + HttpContext.Session.SetString("AdminId", account.Id.ToString()); + HttpContext.Session.SetString("AdminUsername", account.Username); + HttpContext.Session.SetString("AdminRole", account.Role.ToString()); + + return RedirectToPage("/Index"); + } +} diff --git a/Services/Admin/Pages/Logout.cshtml b/Services/Admin/Pages/Logout.cshtml new file mode 100644 index 0000000..f28931f --- /dev/null +++ b/Services/Admin/Pages/Logout.cshtml @@ -0,0 +1,5 @@ +@page "/admin/logout" +@model VoidScavengers.Admin.Pages.LogoutModel +@{ + // This page just redirects after clearing session +} diff --git a/Services/Admin/Pages/Logout.cshtml.cs b/Services/Admin/Pages/Logout.cshtml.cs new file mode 100644 index 0000000..c34b84d --- /dev/null +++ b/Services/Admin/Pages/Logout.cshtml.cs @@ -0,0 +1,13 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace VoidScavengers.Admin.Pages; + +public class LogoutModel : PageModel +{ + public IActionResult OnGet() + { + HttpContext.Session.Clear(); + return RedirectToPage("/Login"); + } +} diff --git a/Services/Admin/Pages/Mobs/Index.cshtml b/Services/Admin/Pages/Mobs/Index.cshtml new file mode 100644 index 0000000..659303e --- /dev/null +++ b/Services/Admin/Pages/Mobs/Index.cshtml @@ -0,0 +1,25 @@ +@page "/admin/mobs" +@model VoidScavengers.Admin.Pages.Mobs.IndexModel +@{ + ViewData["Title"] = "Mobs"; +} + +
+
+
+

Mobs

+

Manage mob definitions

+
+ + + + + Create Mob + +
+ +
+

@Model.MobCount mobs defined

+

Full mob editor coming soon...

+
+
diff --git a/Services/Admin/Pages/Mobs/Index.cshtml.cs b/Services/Admin/Pages/Mobs/Index.cshtml.cs new file mode 100644 index 0000000..038f047 --- /dev/null +++ b/Services/Admin/Pages/Mobs/Index.cshtml.cs @@ -0,0 +1,21 @@ +using Microsoft.EntityFrameworkCore; +using Server.Data; + +namespace VoidScavengers.Admin.Pages.Mobs; + +public class IndexModel : AdminPageModel +{ + private readonly GameDbContext _db; + + public IndexModel(GameDbContext db) + { + _db = db; + } + + public int MobCount { get; set; } + + public async Task OnGetAsync() + { + MobCount = await _db.DungeonMobDefinitions.CountAsync(); + } +} diff --git a/Services/Admin/Pages/Players/Index.cshtml b/Services/Admin/Pages/Players/Index.cshtml new file mode 100644 index 0000000..0f9ea65 --- /dev/null +++ b/Services/Admin/Pages/Players/Index.cshtml @@ -0,0 +1,17 @@ +@page "/admin/players" +@model VoidScavengers.Admin.Pages.Players.IndexModel +@{ + ViewData["Title"] = "Players"; +} + +
+
+

Players

+

Manage player accounts

+
+ +
+

@Model.PlayerCount registered accounts

+

Full player management coming soon...

+
+
diff --git a/Services/Admin/Pages/Players/Index.cshtml.cs b/Services/Admin/Pages/Players/Index.cshtml.cs new file mode 100644 index 0000000..2b8a08c --- /dev/null +++ b/Services/Admin/Pages/Players/Index.cshtml.cs @@ -0,0 +1,21 @@ +using Microsoft.EntityFrameworkCore; +using Server.Data; + +namespace VoidScavengers.Admin.Pages.Players; + +public class IndexModel : AdminPageModel +{ + private readonly GameDbContext _db; + + public IndexModel(GameDbContext db) + { + _db = db; + } + + public int PlayerCount { get; set; } + + public async Task OnGetAsync() + { + PlayerCount = await _db.Accounts.CountAsync(); + } +} diff --git a/Services/Admin/Pages/Recipes/Index.cshtml b/Services/Admin/Pages/Recipes/Index.cshtml new file mode 100644 index 0000000..e7b8329 --- /dev/null +++ b/Services/Admin/Pages/Recipes/Index.cshtml @@ -0,0 +1,25 @@ +@page "/admin/recipes" +@model VoidScavengers.Admin.Pages.Recipes.IndexModel +@{ + ViewData["Title"] = "Recipes"; +} + +
+
+
+

Recipes

+

Manage crafting recipes

+
+ + + + + Create Recipe + +
+ +
+

@Model.RecipeCount recipes defined

+

Full recipe editor coming soon...

+
+
diff --git a/Services/Admin/Pages/Recipes/Index.cshtml.cs b/Services/Admin/Pages/Recipes/Index.cshtml.cs new file mode 100644 index 0000000..17c4e67 --- /dev/null +++ b/Services/Admin/Pages/Recipes/Index.cshtml.cs @@ -0,0 +1,21 @@ +using Microsoft.EntityFrameworkCore; +using Server.Data; + +namespace VoidScavengers.Admin.Pages.Recipes; + +public class IndexModel : AdminPageModel +{ + private readonly GameDbContext _db; + + public IndexModel(GameDbContext db) + { + _db = db; + } + + public int RecipeCount { get; set; } + + public async Task OnGetAsync() + { + RecipeCount = await _db.DungeonCraftingRecipes.CountAsync(); + } +} diff --git a/Services/Admin/Pages/Shared/_Layout.cshtml b/Services/Admin/Pages/Shared/_Layout.cshtml new file mode 100644 index 0000000..55ac6c6 --- /dev/null +++ b/Services/Admin/Pages/Shared/_Layout.cshtml @@ -0,0 +1,148 @@ +@using Microsoft.AspNetCore.Http + + + + + + @ViewData["Title"] - Void Scavengers Admin + + + + + +
+ + + + +
+
+ @RenderBody() +
+
+
+ + @await RenderSectionAsync("Scripts", required: false) + + diff --git a/Services/Admin/Pages/_ViewImports.cshtml b/Services/Admin/Pages/_ViewImports.cshtml new file mode 100644 index 0000000..712017f --- /dev/null +++ b/Services/Admin/Pages/_ViewImports.cshtml @@ -0,0 +1,2 @@ +@namespace VoidScavengers.Admin.Pages +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers diff --git a/Services/Admin/Pages/_ViewStart.cshtml b/Services/Admin/Pages/_ViewStart.cshtml new file mode 100644 index 0000000..820a2f6 --- /dev/null +++ b/Services/Admin/Pages/_ViewStart.cshtml @@ -0,0 +1,3 @@ +@{ + Layout = "_Layout"; +}