Additional tools for Admin portal, and huge NameSpace Revamp

This commit is contained in:
dingo
2025-12-26 09:10:43 -05:00
parent ba747d1891
commit 244635ca3f
133 changed files with 2153 additions and 4776 deletions
+145
View File
@@ -0,0 +1,145 @@
@page "/admin/server"
@model Server.IndexModel
@{
ViewData["Title"] = "Server";
}
<div class="space-y-6">
<!-- Header -->
<div class="flex items-center justify-between">
<div>
<h1 class="text-3xl font-bold text-white">Server Management</h1>
<p class="text-gray-400 mt-1">Broadcast messages and manage server state</p>
</div>
</div>
@if (!string.IsNullOrEmpty(Model.Message))
{
<div class="p-4 rounded-lg @(Model.IsError ? "bg-red-900/50 border border-red-700 text-red-300" : "bg-green-900/50 border border-green-700 text-green-300")">
@Model.Message
</div>
}
<!-- Stats -->
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
<div class="card p-4">
<p class="text-2xl font-bold text-green-400">@Model.ActiveConnections</p>
<p class="text-sm text-gray-400">Active Connections</p>
</div>
<div class="card p-4">
<p class="text-2xl font-bold text-white">@Model.TotalAccounts</p>
<p class="text-sm text-gray-400">Total Accounts</p>
</div>
<div class="card p-4">
<p class="text-2xl font-bold text-indigo-400">@Model.TotalCharacters</p>
<p class="text-sm text-gray-400">Total Characters</p>
</div>
<div class="card p-4">
<p class="text-2xl font-bold text-yellow-400">@Model.TrackedAssets</p>
<p class="text-sm text-gray-400">Tracked Assets</p>
</div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<!-- Broadcast Message -->
<div class="card p-6">
<h2 class="text-lg font-semibold text-white mb-4">Broadcast Message</h2>
<p class="text-sm text-gray-400 mb-4">Send a system message to all connected players.</p>
<form method="post" asp-page-handler="Broadcast" class="space-y-4">
@Html.AntiForgeryToken()
<div>
<label class="label">Message Type</label>
<select name="messageType" class="input">
<option value="system">System (Gray)</option>
<option value="announcement">Announcement (Yellow)</option>
<option value="alert">Alert (Red)</option>
<option value="info">Info (Blue)</option>
</select>
</div>
<div>
<label class="label">Message</label>
<textarea name="message" class="input" rows="3" required placeholder="Enter your message..."></textarea>
</div>
<button type="submit" class="btn btn-primary w-full">
<svg class="w-4 h-4 mr-2 inline" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5.882V19.24a1.76 1.76 0 01-3.417.592l-2.147-6.15M18 13a3 3 0 100-6M5.436 13.683A4.001 4.001 0 017 6h1.832c4.1 0 7.625-1.234 9.168-3v14c-1.543-1.766-5.067-3-9.168-3H7a3.988 3.988 0 01-1.564-.317z"/>
</svg>
Send Broadcast
</button>
</form>
</div>
<!-- Quick Actions -->
<div class="card p-6">
<h2 class="text-lg font-semibold text-white mb-4">Quick Actions</h2>
<div class="space-y-3">
<form method="post" asp-page-handler="RefreshAssets">
@Html.AntiForgeryToken()
<button type="submit" class="btn btn-secondary w-full flex items-center justify-center gap-2">
<svg class="w-4 h-4" 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>
Signal Asset Refresh to Clients
</button>
</form>
<form method="post" asp-page-handler="MaintenanceWarning">
@Html.AntiForgeryToken()
<button type="submit" class="btn bg-yellow-700 hover:bg-yellow-600 text-white w-full flex items-center justify-center gap-2">
<svg class="w-4 h-4" 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>
Send Maintenance Warning (5 min)
</button>
</form>
<form method="post" asp-page-handler="ServerRestart">
@Html.AntiForgeryToken()
<button type="submit" class="btn bg-red-700 hover:bg-red-600 text-white w-full flex items-center justify-center gap-2" onclick="return confirm('Send server restart warning to all players?')">
<svg class="w-4 h-4" 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>
Send Server Restart Warning
</button>
</form>
</div>
</div>
</div>
<!-- Recent Broadcasts -->
<div class="card p-6">
<h2 class="text-lg font-semibold text-white mb-4">Recent Broadcasts</h2>
@if (Model.RecentBroadcasts.Any())
{
<div class="space-y-2">
@foreach (var broadcast in Model.RecentBroadcasts)
{
var typeColor = broadcast.Type switch
{
"announcement" => "border-yellow-600 bg-yellow-900/20",
"alert" => "border-red-600 bg-red-900/20",
"info" => "border-blue-600 bg-blue-900/20",
_ => "border-gray-600 bg-gray-800"
};
<div class="@typeColor border rounded-lg p-3">
<div class="flex items-center justify-between mb-1">
<span class="text-xs text-gray-400 uppercase">@broadcast.Type</span>
<span class="text-xs text-gray-500">@broadcast.SentAt.ToString("HH:mm:ss")</span>
</div>
<p class="text-white">@broadcast.Message</p>
</div>
}
</div>
}
else
{
<p class="text-gray-500 text-center py-4">No recent broadcasts.</p>
}
</div>
</div>
+114
View File
@@ -0,0 +1,114 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using DataServer.Data;
using DataServer.Data.Entities;
using Server.Services;
namespace Server.Services.Admin.Pages.Server;
public class IndexModel : AdminPageModel
{
private readonly GameDbContext _db;
private readonly IServerBroadcastService _broadcast;
private static readonly List<BroadcastRecord> _recentBroadcasts = new();
private static readonly object _lock = new();
public IndexModel(GameDbContext db, IServerBroadcastService broadcast)
{
_db = db;
_broadcast = broadcast;
}
public int ActiveConnections { get; set; }
public int TotalAccounts { get; set; }
public int TotalCharacters { get; set; }
public int TrackedAssets { get; set; }
public List<BroadcastRecord> RecentBroadcasts { get; set; } = new();
public string? Message { get; set; }
public bool IsError { get; set; }
public async Task OnGetAsync()
{
ActiveConnections = _broadcast.GetActiveConnectionCount();
TotalAccounts = await _db.Accounts.CountAsync();
TotalCharacters = await _db.DungeonCharacters.CountAsync(c => !c.IsDeleted);
TrackedAssets = await _db.ClientAssets.CountAsync();
lock (_lock)
{
RecentBroadcasts = _recentBroadcasts.OrderByDescending(b => b.SentAt).Take(10).ToList();
}
}
public async Task<IActionResult> OnPostBroadcastAsync(string message, string messageType)
{
if (string.IsNullOrWhiteSpace(message))
{
Message = "Message cannot be empty.";
IsError = true;
await OnGetAsync();
return Page();
}
_broadcast.QueueBroadcast(message, messageType);
lock (_lock)
{
_recentBroadcasts.Add(new BroadcastRecord(message, messageType, DateTime.UtcNow));
// Keep only last 50
while (_recentBroadcasts.Count > 50)
_recentBroadcasts.RemoveAt(0);
}
Message = $"Broadcast queued ({messageType}): {message}";
await OnGetAsync();
return Page();
}
public async Task<IActionResult> OnPostRefreshAssetsAsync()
{
_broadcast.QueueAssetRefresh();
_broadcast.QueueBroadcast("Asset update available. Your client will refresh automatically.", "info");
lock (_lock)
{
_recentBroadcasts.Add(new BroadcastRecord("Asset refresh signal sent", "system", DateTime.UtcNow));
}
Message = "Asset refresh signal queued.";
await OnGetAsync();
return Page();
}
public async Task<IActionResult> OnPostMaintenanceWarningAsync()
{
_broadcast.QueueBroadcast("⚠️ Server maintenance in 5 minutes. Please finish your current activities.", "announcement");
lock (_lock)
{
_recentBroadcasts.Add(new BroadcastRecord("Maintenance warning (5 min)", "announcement", DateTime.UtcNow));
}
Message = "Maintenance warning sent.";
await OnGetAsync();
return Page();
}
public async Task<IActionResult> OnPostServerRestartAsync()
{
_broadcast.QueueBroadcast("🔄 Server restart imminent. Please save your progress and return to hub.", "alert");
lock (_lock)
{
_recentBroadcasts.Add(new BroadcastRecord("Server restart warning", "alert", DateTime.UtcNow));
}
Message = "Server restart warning sent.";
await OnGetAsync();
return Page();
}
public record BroadcastRecord(string Message, string Type, DateTime SentAt);
}