AdminPanel

This commit is contained in:
dingo
2025-12-24 20:34:48 -05:00
parent ddf9a4b8c5
commit ef3ce84aec
23 changed files with 1782 additions and 0 deletions
+24
View File
@@ -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<IZoneLeaseService>();
// _ = leases.TryAcquireAsync(zoneId: 1);
app.MapControllers();
app.MapRazorPages();
app.Logger.LogInformation("Admin panel available at /admin");
await app.RunAsync();
+29
View File
@@ -0,0 +1,29 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace VoidScavengers.Admin.Pages;
/// <summary>
/// Base class for all admin pages that require authentication
/// </summary>
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);
}
}
+210
View File
@@ -0,0 +1,210 @@
@page "/admin/assets"
@model VoidScavengers.Admin.Pages.Assets.IndexModel
@{
ViewData["Title"] = "CDN Assets";
}
<div class="space-y-6">
<div class="flex items-center justify-between">
<div>
<h1 class="text-3xl font-bold text-white">CDN Assets</h1>
<p class="text-gray-400 mt-1">Browse and manage assets from your CDN</p>
</div>
<a href="/admin/assets/sync" class="btn btn-secondary flex items-center gap-2">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
</svg>
Sync from CDN
</a>
</div>
<!-- CDN Info -->
<div class="card p-4">
<div class="flex items-center gap-4">
<div class="p-3 bg-indigo-600/20 rounded-lg">
<svg class="w-6 h-6 text-indigo-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 15a4 4 0 004 4h9a5 5 0 10-.1-9.999 5.002 5.002 0 10-9.78 2.096A4.001 4.001 0 003 15z"/>
</svg>
</div>
<div>
<p class="text-sm text-gray-400">CDN Base URL</p>
<p class="text-white font-mono">@Model.CdnBaseUrl</p>
</div>
<div class="ml-auto text-right">
<p class="text-sm text-gray-400">Registered Assets</p>
<p class="text-2xl font-bold text-white">@Model.AssetCount</p>
</div>
</div>
</div>
<!-- Filters -->
<div class="card p-4">
<form method="get" class="flex flex-wrap items-end gap-4">
<div class="flex-1 min-w-[200px]">
<label class="label">Search</label>
<input type="text" name="search" value="@Model.Search" class="input" placeholder="Search by path..." />
</div>
<div class="w-48">
<label class="label">Type</label>
<select name="type" class="input">
<option value="">All Types</option>
<option value="sprite" selected="@(Model.TypeFilter == "sprite")">Sprites</option>
<option value="scene" selected="@(Model.TypeFilter == "scene")">Scenes</option>
<option value="script" selected="@(Model.TypeFilter == "script")">Scripts</option>
<option value="audio" selected="@(Model.TypeFilter == "audio")">Audio</option>
</select>
</div>
<button type="submit" class="btn btn-secondary">Filter</button>
<a href="/admin/assets" class="btn btn-secondary">Clear</a>
</form>
</div>
<!-- Assets Grid -->
<div class="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-4">
@foreach (var asset in Model.Assets)
{
<div class="card p-3 hover:border-indigo-500 transition-colors cursor-pointer group"
onclick="showAssetDetails('@asset.FilePath.Replace("'", "\\'")}')" >
<div class="aspect-square bg-gray-900 rounded-lg flex items-center justify-center mb-2 overflow-hidden">
@if (asset.AssetType == Server.Data.Entities.ClientAssetType.Texture)
{
<img src="@Model.CdnBaseUrl/@asset.DownloadPath"
alt="@asset.FilePath"
class="max-w-full max-h-full object-contain"
onerror="this.style.display='none'; this.nextElementSibling.style.display='flex'" />
<div class="hidden items-center justify-center text-gray-600">
<svg class="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/>
</svg>
</div>
}
else if (asset.AssetType == Server.Data.Entities.ClientAssetType.Scene)
{
<svg class="w-12 h-12 text-purple-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 5a1 1 0 011-1h14a1 1 0 011 1v2a1 1 0 01-1 1H5a1 1 0 01-1-1V5zM4 13a1 1 0 011-1h6a1 1 0 011 1v6a1 1 0 01-1 1H5a1 1 0 01-1-1v-6zM16 13a1 1 0 011-1h2a1 1 0 011 1v6a1 1 0 01-1 1h-2a1 1 0 01-1-1v-6z"/>
</svg>
}
else if (asset.AssetType == Server.Data.Entities.ClientAssetType.Script)
{
<svg class="w-12 h-12 text-blue-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"/>
</svg>
}
else
{
<svg class="w-12 h-12 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"/>
</svg>
}
</div>
<p class="text-xs text-gray-400 truncate" title="@asset.FilePath">@System.IO.Path.GetFileName(asset.FilePath)</p>
</div>
}
@if (!Model.Assets.Any())
{
<div class="col-span-full card p-8 text-center">
<p class="text-gray-500">No assets found.</p>
<p class="text-gray-600 text-sm mt-2">Assets are registered in the client_assets table.</p>
</div>
}
</div>
<!-- Pagination -->
@if (Model.TotalPages > 1)
{
<div class="flex items-center justify-between">
<p class="text-sm text-gray-400">
Showing @((Model.Page - 1) * Model.PageSize + 1) to @Math.Min(Model.Page * Model.PageSize, Model.TotalCount) of @Model.TotalCount assets
</p>
<div class="flex items-center gap-2">
@if (Model.Page > 1)
{
<a href="/admin/assets?page=@(Model.Page - 1)&search=@Model.Search&type=@Model.TypeFilter" class="btn btn-secondary">Previous</a>
}
<span class="text-gray-400">Page @Model.Page of @Model.TotalPages</span>
@if (Model.Page < Model.TotalPages)
{
<a href="/admin/assets?page=@(Model.Page + 1)&search=@Model.Search&type=@Model.TypeFilter" class="btn btn-secondary">Next</a>
}
</div>
</div>
}
</div>
<!-- Asset Details Modal -->
<div id="assetModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50">
<div class="bg-gray-800 rounded-xl p-6 max-w-2xl w-full mx-4 border border-gray-700 max-h-[80vh] overflow-auto">
<div class="flex items-center justify-between mb-4">
<h3 class="text-lg font-semibold text-white">Asset Details</h3>
<button onclick="closeAssetModal()" class="text-gray-400 hover:text-white">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
</svg>
</button>
</div>
<div id="assetModalContent">
<!-- Filled by JS -->
</div>
</div>
</div>
@section Scripts {
<script>
const cdnBaseUrl = '@Model.CdnBaseUrl';
function showAssetDetails(path) {
const modal = document.getElementById('assetModal');
const content = document.getElementById('assetModalContent');
const isImage = /\.(png|jpg|jpeg|webp|gif)$/i.test(path);
content.innerHTML = `
<div class="space-y-4">
${isImage ? `
<div class="bg-gray-900 rounded-lg p-4 flex items-center justify-center">
<img src="${cdnBaseUrl}/${path}" alt="${path}" class="max-w-full max-h-64 object-contain" />
</div>
` : ''}
<div>
<p class="text-sm text-gray-400">Path</p>
<p class="text-white font-mono text-sm break-all">${path}</p>
</div>
<div>
<p class="text-sm text-gray-400">Full URL</p>
<p class="text-indigo-400 font-mono text-sm break-all">
<a href="${cdnBaseUrl}/${path}" target="_blank">${cdnBaseUrl}/${path}</a>
</p>
</div>
<div class="flex gap-2">
<button onclick="copyToClipboard('${path}')" class="btn btn-secondary flex-1">
Copy Path
</button>
<button onclick="copyToClipboard('${cdnBaseUrl}/${path}')" class="btn btn-secondary flex-1">
Copy URL
</button>
</div>
</div>
`;
modal.classList.remove('hidden');
modal.classList.add('flex');
}
function closeAssetModal() {
const modal = document.getElementById('assetModal');
modal.classList.add('hidden');
modal.classList.remove('flex');
}
function copyToClipboard(text) {
navigator.clipboard.writeText(text).then(() => {
alert('Copied to clipboard!');
});
}
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') closeAssetModal();
});
</script>
}
@@ -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<ClientAsset> 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();
}
}
+146
View File
@@ -0,0 +1,146 @@
@page "/admin"
@model VoidScavengers.Admin.Pages.IndexModel
@{
ViewData["Title"] = "Dashboard";
}
<div class="space-y-8">
<!-- Header -->
<div>
<h1 class="text-3xl font-bold text-white">Dashboard</h1>
<p class="text-gray-400 mt-1">Welcome back, @ViewData["AdminUsername"]</p>
</div>
<!-- Stats Grid -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
<!-- Items -->
<div class="card p-6">
<div class="flex items-center gap-4">
<div class="p-3 bg-indigo-600/20 rounded-lg">
<svg class="w-8 h-8 text-indigo-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"/>
</svg>
</div>
<div>
<p class="text-2xl font-bold text-white">@Model.ItemCount</p>
<p class="text-sm text-gray-400">Items</p>
</div>
</div>
<a href="/admin/items" class="mt-4 block text-sm text-indigo-400 hover:text-indigo-300">
Manage items →
</a>
</div>
<!-- Mobs -->
<div class="card p-6">
<div class="flex items-center gap-4">
<div class="p-3 bg-red-600/20 rounded-lg">
<svg class="w-8 h-8 text-red-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253"/>
</svg>
</div>
<div>
<p class="text-2xl font-bold text-white">@Model.MobCount</p>
<p class="text-sm text-gray-400">Mobs</p>
</div>
</div>
<a href="/admin/mobs" class="mt-4 block text-sm text-red-400 hover:text-red-300">
Manage mobs →
</a>
</div>
<!-- Recipes -->
<div class="card p-6">
<div class="flex items-center gap-4">
<div class="p-3 bg-green-600/20 rounded-lg">
<svg class="w-8 h-8 text-green-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19.428 15.428a2 2 0 00-1.022-.547l-2.387-.477a6 6 0 00-3.86.517l-.318.158a6 6 0 01-3.86.517L6.05 15.21a2 2 0 00-1.806.547M8 4h8l-1 1v5.172a2 2 0 00.586 1.414l5 5c1.26 1.26.367 3.414-1.415 3.414H4.828c-1.782 0-2.674-2.154-1.414-3.414l5-5A2 2 0 009 10.172V5L8 4z"/>
</svg>
</div>
<div>
<p class="text-2xl font-bold text-white">@Model.RecipeCount</p>
<p class="text-sm text-gray-400">Recipes</p>
</div>
</div>
<a href="/admin/recipes" class="mt-4 block text-sm text-green-400 hover:text-green-300">
Manage recipes →
</a>
</div>
<!-- Players -->
<div class="card p-6">
<div class="flex items-center gap-4">
<div class="p-3 bg-yellow-600/20 rounded-lg">
<svg class="w-8 h-8 text-yellow-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z"/>
</svg>
</div>
<div>
<p class="text-2xl font-bold text-white">@Model.PlayerCount</p>
<p class="text-sm text-gray-400">Players</p>
</div>
</div>
<a href="/admin/players" class="mt-4 block text-sm text-yellow-400 hover:text-yellow-300">
Manage players →
</a>
</div>
</div>
<!-- Quick Actions -->
<div class="card">
<div class="p-6 border-b border-gray-700">
<h2 class="text-lg font-semibold text-white">Quick Actions</h2>
</div>
<div class="p-6 grid grid-cols-1 md:grid-cols-3 gap-4">
<a href="/admin/items/edit" class="flex items-center gap-3 p-4 bg-gray-700/50 rounded-lg hover:bg-gray-700 transition-colors">
<div class="p-2 bg-indigo-600 rounded-lg">
<svg class="w-5 h-5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
</svg>
</div>
<div>
<p class="font-medium text-white">Create Item</p>
<p class="text-sm text-gray-400">Add a new item definition</p>
</div>
</a>
<a href="/admin/mobs/edit" class="flex items-center gap-3 p-4 bg-gray-700/50 rounded-lg hover:bg-gray-700 transition-colors">
<div class="p-2 bg-red-600 rounded-lg">
<svg class="w-5 h-5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
</svg>
</div>
<div>
<p class="font-medium text-white">Create Mob</p>
<p class="text-sm text-gray-400">Add a new mob definition</p>
</div>
</a>
<a href="/admin/recipes/edit" class="flex items-center gap-3 p-4 bg-gray-700/50 rounded-lg hover:bg-gray-700 transition-colors">
<div class="p-2 bg-green-600 rounded-lg">
<svg class="w-5 h-5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
</svg>
</div>
<div>
<p class="font-medium text-white">Create Recipe</p>
<p class="text-sm text-gray-400">Add a new crafting recipe</p>
</div>
</a>
</div>
</div>
<!-- CDN Assets -->
<div class="card">
<div class="p-6 border-b border-gray-700">
<h2 class="text-lg font-semibold text-white">CDN Assets</h2>
<p class="text-sm text-gray-400 mt-1">@Model.AssetCount assets registered</p>
</div>
<div class="p-6">
<p class="text-gray-400 mb-4">CDN Base URL: <code class="text-indigo-400">@Model.CdnBaseUrl</code></p>
<a href="/admin/assets" class="btn btn-secondary">
Browse Assets
</a>
</div>
</div>
</div>
+38
View File
@@ -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;
}
}
}
+338
View File
@@ -0,0 +1,338 @@
@page "/admin/items/edit"
@model VoidScavengers.Admin.Pages.Items.EditModel
@{
ViewData["Title"] = Model.IsNew ? "Create Item" : $"Edit: {Model.Item.Name}";
}
<div class="space-y-6 max-w-4xl">
<!-- Header -->
<div class="flex items-center gap-4">
<a href="/admin/items" class="p-2 hover:bg-gray-800 rounded-lg transition-colors">
<svg class="w-6 h-6 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"/>
</svg>
</a>
<div>
<h1 class="text-3xl font-bold text-white">@(Model.IsNew ? "Create Item" : "Edit Item")</h1>
<p class="text-gray-400 mt-1">@(Model.IsNew ? "Add a new item definition" : $"Editing item #{Model.Item.Id}")</p>
</div>
</div>
@if (!string.IsNullOrEmpty(Model.Message))
{
<div class="p-4 @(Model.IsError ? "bg-red-900/50 border-red-700 text-red-200" : "bg-green-900/50 border-green-700 text-green-200") border rounded-lg">
@Model.Message
</div>
}
<form method="post" class="space-y-6">
@Html.AntiForgeryToken()
<input type="hidden" name="Item.Id" value="@Model.Item.Id" />
<!-- Basic Info -->
<div class="card">
<div class="p-4 border-b border-gray-700">
<h2 class="text-lg font-semibold text-white">Basic Information</h2>
</div>
<div class="p-6 grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<label class="label">Name *</label>
<input type="text" name="Item.Name" value="@Model.Item.Name" class="input" required maxlength="64" />
</div>
<div>
<label class="label">Type *</label>
<select name="Item.Type" class="input" required>
@foreach (var type in Enum.GetValues<Server.Data.Enums.ItemType>())
{
<option value="@type" selected="@(Model.Item.Type == type)">@type</option>
}
</select>
</div>
<div class="md:col-span-2">
<label class="label">Description</label>
<textarea name="Item.Description" class="input" rows="3" maxlength="256">@Model.Item.Description</textarea>
</div>
<div>
<label class="label">Rarity</label>
<select name="Item.Rarity" class="input">
@foreach (var rarity in Enum.GetValues<Server.Data.Enums.ItemRarity>())
{
<option value="@rarity" selected="@(Model.Item.Rarity == rarity)">@rarity</option>
}
</select>
</div>
<div>
<label class="label">Equipment Slot</label>
<select name="Item.EquipSlot" class="input">
<option value="">Not Equippable</option>
@foreach (var slot in Enum.GetValues<Server.Data.Enums.DungeonEquipmentSlot>())
{
<option value="@slot" selected="@(Model.Item.EquipSlot == slot)">@slot</option>
}
</select>
</div>
<div>
<label class="label">Required Level</label>
<input type="number" name="Item.RequiredLevel" value="@Model.Item.RequiredLevel" class="input" min="1" />
</div>
<div class="flex items-center gap-6">
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" name="Item.IsEnabled" value="true" checked="@Model.Item.IsEnabled" class="w-4 h-4 rounded border-gray-600 bg-gray-800 text-indigo-600 focus:ring-indigo-500" />
<span class="text-gray-300">Enabled</span>
</label>
</div>
</div>
</div>
<!-- Stacking -->
<div class="card">
<div class="p-4 border-b border-gray-700">
<h2 class="text-lg font-semibold text-white">Stacking</h2>
</div>
<div class="p-6 grid grid-cols-1 md:grid-cols-2 gap-6">
<div class="flex items-center gap-6">
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" name="Item.Stackable" value="true" checked="@Model.Item.Stackable"
class="w-4 h-4 rounded border-gray-600 bg-gray-800 text-indigo-600 focus:ring-indigo-500"
onchange="document.getElementById('maxStackInput').disabled = !this.checked" />
<span class="text-gray-300">Stackable</span>
</label>
</div>
<div>
<label class="label">Max Stack</label>
<input type="number" id="maxStackInput" name="Item.MaxStack" value="@Model.Item.MaxStack" class="input" min="1"
disabled="@(!Model.Item.Stackable)" />
</div>
</div>
</div>
<!-- Visual -->
<div class="card">
<div class="p-4 border-b border-gray-700">
<h2 class="text-lg font-semibold text-white">Visual</h2>
</div>
<div class="p-6 grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<label class="label">Sprite Path</label>
<div class="flex gap-2">
<input type="text" id="spritePath" name="Item.SpritePath" value="@Model.Item.SpritePath" class="input flex-1"
placeholder="textures/items/sword.png"
oninput="updateSpritePreview()" />
<button type="button" onclick="openAssetBrowser()" class="btn btn-secondary">Browse</button>
</div>
<p class="text-xs text-gray-500 mt-1">Path relative to CDN root</p>
</div>
<div>
<label class="label">Preview</label>
<div class="w-24 h-24 bg-gray-900 rounded-lg flex items-center justify-center border border-gray-700">
<img id="spritePreview"
src="@(string.IsNullOrEmpty(Model.Item.SpritePath) ? "" : $"{Model.CdnBaseUrl}/{Model.Item.SpritePath}")"
class="max-w-full max-h-full object-contain @(string.IsNullOrEmpty(Model.Item.SpritePath) ? "hidden" : "")"
onerror="this.classList.add('hidden'); document.getElementById('spritePreviewPlaceholder').classList.remove('hidden')" />
<div id="spritePreviewPlaceholder" class="text-gray-600 @(string.IsNullOrEmpty(Model.Item.SpritePath) ? "" : "hidden")">
<svg class="w-12 h-12" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>
</svg>
</div>
</div>
</div>
<div>
<label class="label">Tint Color</label>
<div class="flex gap-2">
<input type="color" id="tintColorPicker" value="@(string.IsNullOrEmpty(Model.Item.TintColor) ? "#ffffff" : Model.Item.TintColor)"
class="w-12 h-10 rounded border border-gray-700 bg-gray-800 cursor-pointer"
oninput="document.getElementById('tintColor').value = this.value" />
<input type="text" id="tintColor" name="Item.TintColor" value="@Model.Item.TintColor" class="input flex-1"
placeholder="#ffffff" pattern="#[0-9A-Fa-f]{6}"
oninput="document.getElementById('tintColorPicker').value = this.value || '#ffffff'" />
</div>
</div>
</div>
</div>
<!-- Stat Requirements -->
<div class="card">
<div class="p-4 border-b border-gray-700">
<h2 class="text-lg font-semibold text-white">Stat Requirements</h2>
</div>
<div class="p-6 grid grid-cols-2 md:grid-cols-5 gap-4">
<div>
<label class="label">Strength</label>
<input type="number" name="Item.RequiredStrength" value="@Model.Item.RequiredStrength" class="input" min="0" />
</div>
<div>
<label class="label">Intelligence</label>
<input type="number" name="Item.RequiredIntelligence" value="@Model.Item.RequiredIntelligence" class="input" min="0" />
</div>
<div>
<label class="label">Wisdom</label>
<input type="number" name="Item.RequiredWisdom" value="@Model.Item.RequiredWisdom" class="input" min="0" />
</div>
<div>
<label class="label">Dexterity</label>
<input type="number" name="Item.RequiredDexterity" value="@Model.Item.RequiredDexterity" class="input" min="0" />
</div>
<div>
<label class="label">Level</label>
<input type="number" name="Item.RequiredLevel" value="@Model.Item.RequiredLevel" class="input" min="1" />
</div>
</div>
</div>
<!-- Stat Bonuses -->
<div class="card">
<div class="p-4 border-b border-gray-700">
<h2 class="text-lg font-semibold text-white">Stat Bonuses (When Equipped)</h2>
</div>
<div class="p-6 grid grid-cols-2 md:grid-cols-4 gap-4">
<div>
<label class="label">+ Strength</label>
<input type="number" name="Item.BonusStrength" value="@Model.Item.BonusStrength" class="input" />
</div>
<div>
<label class="label">+ Intelligence</label>
<input type="number" name="Item.BonusIntelligence" value="@Model.Item.BonusIntelligence" class="input" />
</div>
<div>
<label class="label">+ Wisdom</label>
<input type="number" name="Item.BonusWisdom" value="@Model.Item.BonusWisdom" class="input" />
</div>
<div>
<label class="label">+ Endurance</label>
<input type="number" name="Item.BonusEndurance" value="@Model.Item.BonusEndurance" class="input" />
</div>
<div>
<label class="label">+ Dexterity</label>
<input type="number" name="Item.BonusDexterity" value="@Model.Item.BonusDexterity" class="input" />
</div>
<div>
<label class="label">+ Health</label>
<input type="number" name="Item.BonusHealth" value="@Model.Item.BonusHealth" class="input" />
</div>
<div>
<label class="label">+ Mana</label>
<input type="number" name="Item.BonusMana" value="@Model.Item.BonusMana" class="input" />
</div>
</div>
</div>
<!-- Combat Stats -->
<div class="card">
<div class="p-4 border-b border-gray-700">
<h2 class="text-lg font-semibold text-white">Combat Stats</h2>
</div>
<div class="p-6 grid grid-cols-2 md:grid-cols-4 gap-4">
<div>
<label class="label">Min Damage</label>
<input type="number" name="Item.MinDamage" value="@Model.Item.MinDamage" class="input" min="0" />
</div>
<div>
<label class="label">Max Damage</label>
<input type="number" name="Item.MaxDamage" value="@Model.Item.MaxDamage" class="input" min="0" />
</div>
<div>
<label class="label">Armor</label>
<input type="number" name="Item.Armor" value="@Model.Item.Armor" class="input" min="0" />
</div>
<div>
<label class="label">Magic Resist</label>
<input type="number" name="Item.MagicResist" value="@Model.Item.MagicResist" class="input" min="0" />
</div>
<div>
<label class="label">Attack Range</label>
<input type="number" name="Item.AttackRange" value="@Model.Item.AttackRange" class="input" min="0" step="0.1" />
</div>
<div>
<label class="label">Damage Type</label>
<select name="Item.DamageType" class="input">
@foreach (var dmgType in Enum.GetValues<Server.Data.Enums.DamageType>())
{
<option value="@dmgType" selected="@(Model.Item.DamageType == dmgType)">@dmgType</option>
}
</select>
</div>
</div>
</div>
<!-- Consumable Effects -->
<div class="card">
<div class="p-4 border-b border-gray-700">
<h2 class="text-lg font-semibold text-white">Consumable Effects</h2>
</div>
<div class="p-6 grid grid-cols-2 md:grid-cols-3 gap-4">
<div>
<label class="label">Heal Amount</label>
<input type="number" name="Item.HealAmount" value="@Model.Item.HealAmount" class="input" min="0" />
</div>
<div>
<label class="label">Mana Restore</label>
<input type="number" name="Item.ManaRestore" value="@Model.Item.ManaRestore" class="input" min="0" />
</div>
<div>
<label class="label">Stamina Restore</label>
<input type="number" name="Item.StaminaRestore" value="@Model.Item.StaminaRestore" class="input" min="0" />
</div>
</div>
</div>
<!-- Submit -->
<div class="flex items-center gap-4">
<button type="submit" class="btn btn-primary">
@(Model.IsNew ? "Create Item" : "Save Changes")
</button>
<a href="/admin/items" class="btn btn-secondary">Cancel</a>
@if (!Model.IsNew)
{
<div class="flex-1"></div>
<button type="submit" name="action" value="duplicate" class="btn btn-secondary">
Duplicate
</button>
}
</div>
</form>
</div>
@section Scripts {
<script>
const cdnBaseUrl = '@Model.CdnBaseUrl';
function updateSpritePreview() {
const path = document.getElementById('spritePath').value;
const img = document.getElementById('spritePreview');
const placeholder = document.getElementById('spritePreviewPlaceholder');
if (path) {
img.src = cdnBaseUrl + '/' + path;
img.classList.remove('hidden');
placeholder.classList.add('hidden');
img.onerror = function() {
this.classList.add('hidden');
placeholder.classList.remove('hidden');
};
} else {
img.classList.add('hidden');
placeholder.classList.remove('hidden');
}
}
function openAssetBrowser() {
// Open asset browser in a new window/modal
window.open('/admin/assets/browser?select=true&callback=setSpritePath', 'assetBrowser', 'width=800,height=600');
}
// Called by asset browser when an asset is selected
function setSpritePath(path) {
document.getElementById('spritePath').value = path;
updateSpritePreview();
}
</script>
}
+180
View File
@@ -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<IActionResult> 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();
}
}
+214
View File
@@ -0,0 +1,214 @@
@page "/admin/items"
@model VoidScavengers.Admin.Pages.Items.IndexModel
@{
ViewData["Title"] = "Items";
}
<div class="space-y-6">
<!-- Header -->
<div class="flex items-center justify-between">
<div>
<h1 class="text-3xl font-bold text-white">Items</h1>
<p class="text-gray-400 mt-1">Manage item definitions</p>
</div>
<a href="/admin/items/edit" class="btn btn-primary flex items-center gap-2">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
</svg>
Create Item
</a>
</div>
<!-- Filters -->
<div class="card p-4">
<form method="get" class="flex flex-wrap items-end gap-4">
<div class="flex-1 min-w-[200px]">
<label class="label">Search</label>
<input type="text" name="search" value="@Model.Search" class="input" placeholder="Search by name..." />
</div>
<div class="w-48">
<label class="label">Type</label>
<select name="type" class="input">
<option value="">All Types</option>
@foreach (var type in Enum.GetValues<Server.Data.Enums.ItemType>())
{
<option value="@type" selected="@(Model.TypeFilter == type)">@type</option>
}
</select>
</div>
<div class="w-48">
<label class="label">Rarity</label>
<select name="rarity" class="input">
<option value="">All Rarities</option>
@foreach (var rarity in Enum.GetValues<Server.Data.Enums.ItemRarity>())
{
<option value="@rarity" selected="@(Model.RarityFilter == rarity)">@rarity</option>
}
</select>
</div>
<button type="submit" class="btn btn-secondary">Filter</button>
<a href="/admin/items" class="btn btn-secondary">Clear</a>
</form>
</div>
<!-- Items Table -->
<div class="card overflow-hidden">
<table class="w-full">
<thead class="bg-gray-900">
<tr>
<th class="table-header">ID</th>
<th class="table-header">Icon</th>
<th class="table-header">Name</th>
<th class="table-header">Type</th>
<th class="table-header">Rarity</th>
<th class="table-header">Stackable</th>
<th class="table-header">Enabled</th>
<th class="table-header">Actions</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-700">
@foreach (var item in Model.Items)
{
<tr class="hover:bg-gray-700/50">
<td class="table-cell font-mono text-gray-400">@item.Id</td>
<td class="table-cell">
@if (!string.IsNullOrEmpty(item.SpritePath))
{
<img src="@Model.CdnBaseUrl/@item.SpritePath"
alt="@item.Name"
class="w-10 h-10 object-contain bg-gray-900 rounded"
onerror="this.style.display='none'" />
}
else
{
<div class="w-10 h-10 bg-gray-900 rounded flex items-center justify-center text-gray-600">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>
</svg>
</div>
}
</td>
<td class="table-cell font-medium text-white">@item.Name</td>
<td class="table-cell">@item.Type</td>
<td class="table-cell">
<span class="badge badge-@item.Rarity.ToString().ToLower()">@item.Rarity</span>
</td>
<td class="table-cell">
@if (item.Stackable)
{
<span class="text-green-400">Yes (@item.MaxStack)</span>
}
else
{
<span class="text-gray-500">No</span>
}
</td>
<td class="table-cell">
@if (item.IsEnabled)
{
<span class="inline-flex items-center gap-1 text-green-400">
<svg class="w-4 h-4" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"/>
</svg>
Yes
</span>
}
else
{
<span class="inline-flex items-center gap-1 text-red-400">
<svg class="w-4 h-4" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"/>
</svg>
No
</span>
}
</td>
<td class="table-cell">
<div class="flex items-center gap-2">
<a href="/admin/items/edit?id=@item.Id" class="text-indigo-400 hover:text-indigo-300" title="Edit">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/>
</svg>
</a>
<button type="button"
onclick="confirmDelete(@item.Id, '@item.Name.Replace("'", "\\'")}')"
class="text-red-400 hover:text-red-300"
title="Delete">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
</svg>
</button>
</div>
</td>
</tr>
}
@if (!Model.Items.Any())
{
<tr>
<td colspan="8" class="table-cell text-center text-gray-500 py-8">
No items found.
<a href="/admin/items/edit" class="text-indigo-400 hover:text-indigo-300">Create one?</a>
</td>
</tr>
}
</tbody>
</table>
</div>
<!-- Pagination -->
@if (Model.TotalPages > 1)
{
<div class="flex items-center justify-between">
<p class="text-sm text-gray-400">
Showing @((Model.Page - 1) * Model.PageSize + 1) to @Math.Min(Model.Page * Model.PageSize, Model.TotalCount) of @Model.TotalCount items
</p>
<div class="flex items-center gap-2">
@if (Model.Page > 1)
{
<a href="/admin/items?page=@(Model.Page - 1)&search=@Model.Search&type=@Model.TypeFilter&rarity=@Model.RarityFilter" class="btn btn-secondary">Previous</a>
}
<span class="text-gray-400">Page @Model.Page of @Model.TotalPages</span>
@if (Model.Page < Model.TotalPages)
{
<a href="/admin/items?page=@(Model.Page + 1)&search=@Model.Search&type=@Model.TypeFilter&rarity=@Model.RarityFilter" class="btn btn-secondary">Next</a>
}
</div>
</div>
}
</div>
<!-- Delete confirmation modal -->
<div id="deleteModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50">
<div class="bg-gray-800 rounded-xl p-6 max-w-md w-full mx-4 border border-gray-700">
<h3 class="text-lg font-semibold text-white mb-2">Delete Item</h3>
<p class="text-gray-400 mb-4">Are you sure you want to delete "<span id="deleteItemName"></span>"? This action cannot be undone.</p>
<form id="deleteForm" method="post" asp-page-handler="Delete" class="flex justify-end gap-3">
@Html.AntiForgeryToken()
<input type="hidden" name="id" id="deleteItemId" />
<button type="button" onclick="closeDeleteModal()" class="btn btn-secondary">Cancel</button>
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</div>
</div>
@section Scripts {
<script>
function confirmDelete(id, name) {
document.getElementById('deleteItemId').value = id;
document.getElementById('deleteItemName').textContent = name;
document.getElementById('deleteModal').classList.remove('hidden');
document.getElementById('deleteModal').classList.add('flex');
}
function closeDeleteModal() {
document.getElementById('deleteModal').classList.add('hidden');
document.getElementById('deleteModal').classList.remove('flex');
}
// Close modal on escape key
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') closeDeleteModal();
});
</script>
}
@@ -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<DungeonItemDefinition> 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<IActionResult> OnPostDeleteAsync(int id)
{
var item = await _db.DungeonItemDefinitions.FindAsync(id);
if (item != null)
{
_db.DungeonItemDefinitions.Remove(item);
await _db.SaveChangesAsync();
}
return RedirectToPage();
}
}
+68
View File
@@ -0,0 +1,68 @@
@page "/admin/login"
@model VoidScavengers.Admin.Pages.LoginModel
@{
Layout = null;
ViewData["Title"] = "Login";
}
<!DOCTYPE html>
<html lang="en" class="h-full bg-gray-900">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Admin Login - Void Scavengers</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="h-full flex items-center justify-center">
<div class="w-full max-w-md">
<div class="bg-gray-800 rounded-2xl shadow-xl border border-gray-700 p-8">
<!-- Logo -->
<div class="text-center mb-8">
<div class="inline-flex items-center justify-center w-16 h-16 rounded-full bg-indigo-600 mb-4">
<svg class="w-10 h-10 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/>
</svg>
</div>
<h1 class="text-2xl font-bold text-white">Void Scavengers</h1>
<p class="text-gray-400 mt-1">Admin Panel</p>
</div>
<!-- Error message -->
@if (!string.IsNullOrEmpty(Model.ErrorMessage))
{
<div class="mb-6 p-4 bg-red-900/50 border border-red-700 rounded-lg text-red-200 text-sm">
@Model.ErrorMessage
</div>
}
<!-- Login form -->
<form method="post" class="space-y-6">
@Html.AntiForgeryToken()
<div>
<label for="username" class="block text-sm font-medium text-gray-300 mb-2">Username</label>
<input type="text" id="username" name="Username" value="@Model.Username" required
class="w-full px-4 py-3 bg-gray-900 border border-gray-700 rounded-lg text-white placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent"
placeholder="Enter your username" />
</div>
<div>
<label for="password" class="block text-sm font-medium text-gray-300 mb-2">Password</label>
<input type="password" id="password" name="Password" required
class="w-full px-4 py-3 bg-gray-900 border border-gray-700 rounded-lg text-white placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent"
placeholder="Enter your password" />
</div>
<button type="submit"
class="w-full py-3 px-4 bg-indigo-600 hover:bg-indigo-700 text-white font-medium rounded-lg transition-colors focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 focus:ring-offset-gray-800">
Sign In
</button>
</form>
<p class="mt-6 text-center text-sm text-gray-500">
Only authorized administrators can access this panel.
</p>
</div>
</div>
</body>
</html>
+81
View File
@@ -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<IActionResult> 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");
}
}
+5
View File
@@ -0,0 +1,5 @@
@page "/admin/logout"
@model VoidScavengers.Admin.Pages.LogoutModel
@{
// This page just redirects after clearing session
}
+13
View File
@@ -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");
}
}
+25
View File
@@ -0,0 +1,25 @@
@page "/admin/mobs"
@model VoidScavengers.Admin.Pages.Mobs.IndexModel
@{
ViewData["Title"] = "Mobs";
}
<div class="space-y-6">
<div class="flex items-center justify-between">
<div>
<h1 class="text-3xl font-bold text-white">Mobs</h1>
<p class="text-gray-400 mt-1">Manage mob definitions</p>
</div>
<a href="/admin/mobs/edit" class="btn btn-primary flex items-center gap-2">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
</svg>
Create Mob
</a>
</div>
<div class="card p-8 text-center">
<p class="text-gray-400">@Model.MobCount mobs defined</p>
<p class="text-gray-500 mt-2">Full mob editor coming soon...</p>
</div>
</div>
+21
View File
@@ -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();
}
}
+17
View File
@@ -0,0 +1,17 @@
@page "/admin/players"
@model VoidScavengers.Admin.Pages.Players.IndexModel
@{
ViewData["Title"] = "Players";
}
<div class="space-y-6">
<div>
<h1 class="text-3xl font-bold text-white">Players</h1>
<p class="text-gray-400 mt-1">Manage player accounts</p>
</div>
<div class="card p-8 text-center">
<p class="text-gray-400">@Model.PlayerCount registered accounts</p>
<p class="text-gray-500 mt-2">Full player management coming soon...</p>
</div>
</div>
@@ -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();
}
}
+25
View File
@@ -0,0 +1,25 @@
@page "/admin/recipes"
@model VoidScavengers.Admin.Pages.Recipes.IndexModel
@{
ViewData["Title"] = "Recipes";
}
<div class="space-y-6">
<div class="flex items-center justify-between">
<div>
<h1 class="text-3xl font-bold text-white">Recipes</h1>
<p class="text-gray-400 mt-1">Manage crafting recipes</p>
</div>
<a href="/admin/recipes/edit" class="btn btn-primary flex items-center gap-2">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
</svg>
Create Recipe
</a>
</div>
<div class="card p-8 text-center">
<p class="text-gray-400">@Model.RecipeCount recipes defined</p>
<p class="text-gray-500 mt-2">Full recipe editor coming soon...</p>
</div>
</div>
@@ -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();
}
}
+148
View File
@@ -0,0 +1,148 @@
@using Microsoft.AspNetCore.Http
<!DOCTYPE html>
<html lang="en" class="h-full bg-gray-900">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - Void Scavengers Admin</title>
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
colors: {
primary: '#6366f1',
secondary: '#8b5cf6',
}
}
}
}
</script>
<style>
.sidebar-link { display: flex; align-items: center; gap: 0.75rem; padding: 0.625rem 1rem; color: #d1d5db; border-radius: 0.5rem; transition: all 0.15s; }
.sidebar-link:hover { background-color: #1f2937; color: white; }
.sidebar-link.active { background-color: #4f46e5; color: white; }
.btn { padding: 0.5rem 1rem; border-radius: 0.5rem; font-weight: 500; transition: all 0.15s; outline: none; }
.btn:focus { box-shadow: 0 0 0 2px #111827, 0 0 0 4px #6366f1; }
.btn-primary { background-color: #4f46e5; color: white; }
.btn-primary:hover { background-color: #4338ca; }
.btn-secondary { background-color: #374151; color: #e5e7eb; }
.btn-secondary:hover { background-color: #4b5563; }
.btn-danger { background-color: #dc2626; color: white; }
.btn-danger:hover { background-color: #b91c1c; }
.btn-success { background-color: #16a34a; color: white; }
.btn-success:hover { background-color: #15803d; }
.input { width: 100%; padding: 0.5rem 0.75rem; background-color: #1f2937; border: 1px solid #374151; border-radius: 0.5rem; color: #e5e7eb; }
.input::placeholder { color: #6b7280; }
.input:focus { outline: none; box-shadow: 0 0 0 2px #6366f1; border-color: transparent; }
.label { display: block; font-size: 0.875rem; font-weight: 500; color: #d1d5db; margin-bottom: 0.25rem; }
.card { background-color: #1f2937; border-radius: 0.75rem; border: 1px solid #374151; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); }
.table-header { padding: 0.75rem 1rem; text-align: left; font-size: 0.75rem; font-weight: 500; color: #9ca3af; text-transform: uppercase; letter-spacing: 0.05em; }
.table-cell { padding: 0.75rem 1rem; font-size: 0.875rem; color: #d1d5db; }
.badge { display: inline-flex; align-items: center; padding: 0.125rem 0.625rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 500; }
.badge-common { background-color: #4b5563; color: #e5e7eb; }
.badge-uncommon { background-color: #16a34a; color: white; }
.badge-rare { background-color: #2563eb; color: white; }
.badge-epic { background-color: #9333ea; color: white; }
.badge-legendary { background-color: #f97316; color: white; }
</style>
</head>
<body class="h-full">
<div class="flex h-full">
<!-- Sidebar -->
<aside class="w-64 bg-gray-800 border-r border-gray-700 flex flex-col">
<!-- Logo -->
<div class="p-4 border-b border-gray-700">
<h1 class="text-xl font-bold text-white flex items-center gap-2">
<svg class="w-8 h-8 text-indigo-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/>
</svg>
Void Scavengers
</h1>
<p class="text-xs text-gray-500 mt-1">Admin Panel</p>
</div>
<!-- Navigation -->
<nav class="flex-1 p-4 space-y-1">
<a href="/admin" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString() == "/Index" ? "active" : "")">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"/>
</svg>
Dashboard
</a>
<div class="pt-4">
<p class="px-4 text-xs font-semibold text-gray-500 uppercase tracking-wider">Content</p>
</div>
<a href="/admin/items" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/Items") == true ? "active" : "")">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"/>
</svg>
Items
</a>
<a href="/admin/recipes" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/Recipes") == true ? "active" : "")">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19.428 15.428a2 2 0 00-1.022-.547l-2.387-.477a6 6 0 00-3.86.517l-.318.158a6 6 0 01-3.86.517L6.05 15.21a2 2 0 00-1.806.547M8 4h8l-1 1v5.172a2 2 0 00.586 1.414l5 5c1.26 1.26.367 3.414-1.415 3.414H4.828c-1.782 0-2.674-2.154-1.414-3.414l5-5A2 2 0 009 10.172V5L8 4z"/>
</svg>
Recipes
</a>
<a href="/admin/mobs" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/Mobs") == true ? "active" : "")">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253"/>
</svg>
Mobs
</a>
<a href="/admin/assets" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/Assets") == true ? "active" : "")">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>
</svg>
CDN Assets
</a>
<div class="pt-4">
<p class="px-4 text-xs font-semibold text-gray-500 uppercase tracking-wider">Management</p>
</div>
<a href="/admin/players" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/Players") == true ? "active" : "")">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z"/>
</svg>
Players
</a>
</nav>
<!-- User info -->
<div class="p-4 border-t border-gray-700">
<div class="flex items-center gap-3">
<div class="w-10 h-10 rounded-full bg-indigo-600 flex items-center justify-center text-white font-bold">
@(ViewData["AdminUsername"]?.ToString()?.Substring(0, 1).ToUpper() ?? "A")
</div>
<div class="flex-1 min-w-0">
<p class="text-sm font-medium text-white truncate">@ViewData["AdminUsername"]</p>
<p class="text-xs text-gray-400">@ViewData["AdminRole"]</p>
</div>
<a href="/admin/logout" class="text-gray-400 hover:text-white">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"/>
</svg>
</a>
</div>
</div>
</aside>
<!-- Main content -->
<main class="flex-1 overflow-auto">
<div class="p-8">
@RenderBody()
</div>
</main>
</div>
@await RenderSectionAsync("Scripts", required: false)
</body>
</html>
+2
View File
@@ -0,0 +1,2 @@
@namespace VoidScavengers.Admin.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
+3
View File
@@ -0,0 +1,3 @@
@{
Layout = "_Layout";
}