Stash and player management fix
This commit is contained in:
@@ -760,6 +760,9 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
|||||||
|
|
||||||
// Process pending broadcasts
|
// Process pending broadcasts
|
||||||
ProcessPendingBroadcasts();
|
ProcessPendingBroadcasts();
|
||||||
|
|
||||||
|
// Update active connection count for admin display
|
||||||
|
_broadcastService.SetActiveConnectionCount(_playerSessions.Count);
|
||||||
|
|
||||||
foreach (var (dungeonId, instance) in _dungeons)
|
foreach (var (dungeonId, instance) in _dungeons)
|
||||||
{
|
{
|
||||||
|
|||||||
+11
-1
@@ -28,13 +28,23 @@ builder.Services.AddRazorPages()
|
|||||||
});
|
});
|
||||||
|
|
||||||
// ---- Session for Admin Auth ----
|
// ---- Session for Admin Auth ----
|
||||||
builder.Services.AddDistributedMemoryCache();
|
// Use Redis for distributed session storage (required for multi-instance/Kubernetes)
|
||||||
|
var redisConnString = Environment.GetEnvironmentVariable("REDIS_URL")
|
||||||
|
?? Environment.GetEnvironmentVariable("REDIS_HOST") + ":" + (Environment.GetEnvironmentVariable("REDIS_PORT") ?? "6379");
|
||||||
|
builder.Services.AddStackExchangeRedisCache(options =>
|
||||||
|
{
|
||||||
|
options.Configuration = redisConnString;
|
||||||
|
options.InstanceName = "VoidScavengers:Sessions:";
|
||||||
|
});
|
||||||
|
|
||||||
builder.Services.AddSession(options =>
|
builder.Services.AddSession(options =>
|
||||||
{
|
{
|
||||||
options.IdleTimeout = TimeSpan.FromHours(8);
|
options.IdleTimeout = TimeSpan.FromHours(8);
|
||||||
options.Cookie.HttpOnly = true;
|
options.Cookie.HttpOnly = true;
|
||||||
options.Cookie.IsEssential = true;
|
options.Cookie.IsEssential = true;
|
||||||
options.Cookie.Name = ".VoidScavengers.Admin";
|
options.Cookie.Name = ".VoidScavengers.Admin";
|
||||||
|
options.Cookie.SameSite = SameSiteMode.Lax;
|
||||||
|
options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
|
||||||
});
|
});
|
||||||
|
|
||||||
// ---- MySQL conn string from env ----
|
// ---- MySQL conn string from env ----
|
||||||
|
|||||||
@@ -148,6 +148,47 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Stash Grid (VIP Feature) -->
|
||||||
|
<div class="card p-4">
|
||||||
|
<h2 class="text-md font-semibold text-white mb-3">🔐 Stash (@Model.StashItems.Count/50)</h2>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-10 gap-1">
|
||||||
|
@for (int i = 0; i < 50; i++)
|
||||||
|
{
|
||||||
|
var item = Model.StashItems.FirstOrDefault(s => s.SlotIndex == i);
|
||||||
|
var rarityBorder = item?.Definition?.Rarity switch
|
||||||
|
{
|
||||||
|
ItemRarity.Uncommon => "border-green-500",
|
||||||
|
ItemRarity.Rare => "border-blue-500",
|
||||||
|
ItemRarity.Epic => "border-purple-500",
|
||||||
|
ItemRarity.Legendary => "border-orange-500",
|
||||||
|
_ => "border-gray-700"
|
||||||
|
};
|
||||||
|
<div class="w-10 h-10 bg-gray-900 rounded border @rarityBorder flex items-center justify-center relative group cursor-pointer"
|
||||||
|
@if (item != null) { <text>onclick="showStashModal(@item.Id, @item.Quantity, @item.SlotIndex)"</text> }>
|
||||||
|
@if (item?.Definition != null)
|
||||||
|
{
|
||||||
|
@if (!string.IsNullOrEmpty(item.Definition.SpritePath))
|
||||||
|
{
|
||||||
|
<img src="@Model.CdnBaseUrl/downloads/@item.Definition.SpritePath" class="w-8 h-8 object-contain" />
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<span class="text-xs text-gray-400">@item.Definition.Name.Substring(0, Math.Min(2, item.Definition.Name.Length))</span>
|
||||||
|
}
|
||||||
|
@if (item.Quantity > 1)
|
||||||
|
{
|
||||||
|
<span class="absolute bottom-0 right-0 bg-black/80 text-white text-[10px] px-0.5 rounded-tl">@item.Quantity</span>
|
||||||
|
}
|
||||||
|
<div class="absolute left-full ml-1 top-0 z-50 hidden group-hover:block">
|
||||||
|
@await Html.PartialAsync("_ItemTooltip", item.Definition)
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Lifetime Stats -->
|
<!-- Lifetime Stats -->
|
||||||
<div class="card p-4">
|
<div class="card p-4">
|
||||||
<h2 class="text-md font-semibold text-white mb-3">Lifetime Stats</h2>
|
<h2 class="text-md font-semibold text-white mb-3">Lifetime Stats</h2>
|
||||||
@@ -251,9 +292,51 @@
|
|||||||
<input type="hidden" name="itemId" id="deleteItemId" />
|
<input type="hidden" name="itemId" id="deleteItemId" />
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<!-- Stash Edit Modal -->
|
||||||
|
<div id="stashModal" class="fixed inset-0 bg-black/70 hidden items-center justify-center z-50">
|
||||||
|
<div class="bg-gray-800 rounded-xl p-4 max-w-xs w-full mx-4 border border-gray-700">
|
||||||
|
<h3 class="text-md font-semibold text-white mb-3">🔐 Edit Stash Item</h3>
|
||||||
|
|
||||||
|
<div class="space-y-3 mb-4">
|
||||||
|
<div>
|
||||||
|
<label class="label text-xs">Quantity</label>
|
||||||
|
<input type="number" id="stashModalQuantity" class="input text-sm py-1" min="1" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="label text-xs">Slot (0-49)</label>
|
||||||
|
<input type="number" id="stashModalSlotIndex" class="input text-sm py-1" min="0" max="49" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex justify-between gap-2 pt-3 border-t border-gray-700">
|
||||||
|
<button type="button" onclick="deleteStashItem()" class="btn bg-red-700 hover:bg-red-600 text-white btn-sm">Delete</button>
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<button type="button" onclick="closeStashModal()" class="btn btn-secondary btn-sm">Cancel</button>
|
||||||
|
<button type="button" onclick="saveStashItem()" class="btn btn-primary btn-sm">Save</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Hidden stash forms -->
|
||||||
|
<form id="updateStashItemForm" method="post" asp-page-handler="UpdateStashItem" style="display:none">
|
||||||
|
@Html.AntiForgeryToken()
|
||||||
|
<input type="hidden" name="characterId" value="@Model.Character.Id" />
|
||||||
|
<input type="hidden" name="stashItemId" id="updateStashItemId" />
|
||||||
|
<input type="hidden" name="quantity" id="updateStashQuantity" />
|
||||||
|
<input type="hidden" name="slotIndex" id="updateStashSlotIndex" />
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<form id="deleteStashItemForm" method="post" asp-page-handler="DeleteStashItem" style="display:none">
|
||||||
|
@Html.AntiForgeryToken()
|
||||||
|
<input type="hidden" name="characterId" value="@Model.Character.Id" />
|
||||||
|
<input type="hidden" name="stashItemId" id="deleteStashItemId" />
|
||||||
|
</form>
|
||||||
|
|
||||||
@section Scripts {
|
@section Scripts {
|
||||||
<script>
|
<script>
|
||||||
let currentItemId = null;
|
let currentItemId = null;
|
||||||
|
let currentStashItemId = null;
|
||||||
|
|
||||||
function showItemModal(itemId, quantity, slotIndex) {
|
function showItemModal(itemId, quantity, slotIndex) {
|
||||||
currentItemId = itemId;
|
currentItemId = itemId;
|
||||||
@@ -284,6 +367,41 @@
|
|||||||
document.getElementById('deleteItemForm').submit();
|
document.getElementById('deleteItemForm').submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('keydown', e => { if (e.key === 'Escape') closeItemModal(); });
|
// Stash functions
|
||||||
|
function showStashModal(stashItemId, quantity, slotIndex) {
|
||||||
|
currentStashItemId = stashItemId;
|
||||||
|
document.getElementById('stashModalQuantity').value = quantity;
|
||||||
|
document.getElementById('stashModalSlotIndex').value = slotIndex;
|
||||||
|
document.getElementById('stashModal').classList.remove('hidden');
|
||||||
|
document.getElementById('stashModal').classList.add('flex');
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeStashModal() {
|
||||||
|
document.getElementById('stashModal').classList.add('hidden');
|
||||||
|
document.getElementById('stashModal').classList.remove('flex');
|
||||||
|
currentStashItemId = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveStashItem() {
|
||||||
|
if (!currentStashItemId) return;
|
||||||
|
document.getElementById('updateStashItemId').value = currentStashItemId;
|
||||||
|
document.getElementById('updateStashQuantity').value = document.getElementById('stashModalQuantity').value;
|
||||||
|
document.getElementById('updateStashSlotIndex').value = document.getElementById('stashModalSlotIndex').value;
|
||||||
|
document.getElementById('updateStashItemForm').submit();
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteStashItem() {
|
||||||
|
if (!currentStashItemId) return;
|
||||||
|
if (!confirm('Delete this stash item permanently?')) return;
|
||||||
|
document.getElementById('deleteStashItemId').value = currentStashItemId;
|
||||||
|
document.getElementById('deleteStashItemForm').submit();
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('keydown', e => {
|
||||||
|
if (e.key === 'Escape') {
|
||||||
|
closeItemModal();
|
||||||
|
closeStashModal();
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public class CharacterModel : AdminPageModel
|
|||||||
public DungeonCharacter Character { get; set; } = new();
|
public DungeonCharacter Character { get; set; } = new();
|
||||||
public List<DungeonCharacterItem> InventoryItems { get; set; } = new();
|
public List<DungeonCharacterItem> InventoryItems { get; set; } = new();
|
||||||
public List<DungeonCharacterItem> EquippedItems { get; set; } = new();
|
public List<DungeonCharacterItem> EquippedItems { get; set; } = new();
|
||||||
|
public List<DungeonStashItem> StashItems { get; set; } = new();
|
||||||
|
|
||||||
public string CdnBaseUrl { get; set; } = "https://assets.aeternalisgames.com";
|
public string CdnBaseUrl { get; set; } = "https://assets.aeternalisgames.com";
|
||||||
|
|
||||||
@@ -54,6 +55,12 @@ public class CharacterModel : AdminPageModel
|
|||||||
|
|
||||||
InventoryItems = allItems.Where(i => !i.IsEquipped).OrderBy(i => i.SlotIndex).ToList();
|
InventoryItems = allItems.Where(i => !i.IsEquipped).OrderBy(i => i.SlotIndex).ToList();
|
||||||
EquippedItems = allItems.Where(i => i.IsEquipped).ToList();
|
EquippedItems = allItems.Where(i => i.IsEquipped).ToList();
|
||||||
|
|
||||||
|
StashItems = await _db.DungeonStashItems
|
||||||
|
.Include(s => s.Definition)
|
||||||
|
.Where(s => s.CharacterId == Character.Id)
|
||||||
|
.OrderBy(s => s.SlotIndex)
|
||||||
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostUpdateBasicAsync(
|
public async Task<IActionResult> OnPostUpdateBasicAsync(
|
||||||
@@ -158,4 +165,49 @@ public class CharacterModel : AdminPageModel
|
|||||||
|
|
||||||
return RedirectToPage(new { id = characterId });
|
return RedirectToPage(new { id = characterId });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostUpdateStashItemAsync(
|
||||||
|
ulong characterId,
|
||||||
|
ulong stashItemId,
|
||||||
|
int quantity,
|
||||||
|
int slotIndex)
|
||||||
|
{
|
||||||
|
var item = await _db.DungeonStashItems
|
||||||
|
.FirstOrDefaultAsync(s => s.Id == stashItemId && s.CharacterId == characterId);
|
||||||
|
|
||||||
|
if (item == null)
|
||||||
|
{
|
||||||
|
Message = "Stash item not found.";
|
||||||
|
IsError = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
item.Quantity = Math.Max(1, quantity);
|
||||||
|
item.SlotIndex = Math.Clamp(slotIndex, 0, 49);
|
||||||
|
await _db.SaveChangesAsync();
|
||||||
|
Message = "Stash item updated.";
|
||||||
|
}
|
||||||
|
|
||||||
|
return RedirectToPage(new { id = characterId });
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostDeleteStashItemAsync(ulong characterId, ulong stashItemId)
|
||||||
|
{
|
||||||
|
var item = await _db.DungeonStashItems
|
||||||
|
.FirstOrDefaultAsync(s => s.Id == stashItemId && s.CharacterId == characterId);
|
||||||
|
|
||||||
|
if (item != null)
|
||||||
|
{
|
||||||
|
_db.DungeonStashItems.Remove(item);
|
||||||
|
await _db.SaveChangesAsync();
|
||||||
|
Message = "Stash item deleted.";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Message = "Stash item not found.";
|
||||||
|
IsError = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return RedirectToPage(new { id = characterId });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,11 @@ public class EditModel : AdminPageModel
|
|||||||
public List<DungeonCharacter> Characters { get; set; } = new();
|
public List<DungeonCharacter> Characters { get; set; } = new();
|
||||||
|
|
||||||
public bool IsNew => Account.Id == 0;
|
public bool IsNew => Account.Id == 0;
|
||||||
|
|
||||||
|
[TempData]
|
||||||
public string? Message { get; set; }
|
public string? Message { get; set; }
|
||||||
|
|
||||||
|
[TempData]
|
||||||
public bool IsError { get; set; }
|
public bool IsError { get; set; }
|
||||||
|
|
||||||
public async Task<IActionResult> OnGetAsync(ulong? id)
|
public async Task<IActionResult> OnGetAsync(ulong? id)
|
||||||
@@ -147,26 +151,16 @@ public class EditModel : AdminPageModel
|
|||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(newPassword) || newPassword.Length < 6)
|
if (string.IsNullOrWhiteSpace(newPassword) || newPassword.Length < 6)
|
||||||
{
|
{
|
||||||
Account = account;
|
|
||||||
Characters = await _db.DungeonCharacters
|
|
||||||
.Where(c => c.AccountId == accountId && !c.IsDeleted)
|
|
||||||
.OrderByDescending(c => c.Level)
|
|
||||||
.ToListAsync();
|
|
||||||
Message = "Password must be at least 6 characters.";
|
Message = "Password must be at least 6 characters.";
|
||||||
IsError = true;
|
IsError = true;
|
||||||
return Page();
|
return RedirectToPage(new { id = accountId });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newPassword != confirmPassword)
|
if (newPassword != confirmPassword)
|
||||||
{
|
{
|
||||||
Account = account;
|
|
||||||
Characters = await _db.DungeonCharacters
|
|
||||||
.Where(c => c.AccountId == accountId && !c.IsDeleted)
|
|
||||||
.OrderByDescending(c => c.Level)
|
|
||||||
.ToListAsync();
|
|
||||||
Message = "Passwords do not match.";
|
Message = "Passwords do not match.";
|
||||||
IsError = true;
|
IsError = true;
|
||||||
return Page();
|
return RedirectToPage(new { id = accountId });
|
||||||
}
|
}
|
||||||
|
|
||||||
_passwordHasher.Hash(newPassword, out var hash, out var salt);
|
_passwordHasher.Hash(newPassword, out var hash, out var salt);
|
||||||
@@ -174,13 +168,8 @@ public class EditModel : AdminPageModel
|
|||||||
account.PasswordSalt = salt;
|
account.PasswordSalt = salt;
|
||||||
await _db.SaveChangesAsync();
|
await _db.SaveChangesAsync();
|
||||||
|
|
||||||
Account = account;
|
Message = "Password has been reset successfully.";
|
||||||
Characters = await _db.DungeonCharacters
|
IsError = false;
|
||||||
.Where(c => c.AccountId == accountId && !c.IsDeleted)
|
return RedirectToPage(new { id = accountId });
|
||||||
.OrderByDescending(c => c.Level)
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
Message = "Password has been reset.";
|
|
||||||
return Page();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
<PackageReference Include="Polly" Version="8.6.4" />
|
<PackageReference Include="Polly" Version="8.6.4" />
|
||||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0" />
|
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0" />
|
||||||
<PackageReference Include="StackExchange.Redis" Version="2.9.32" />
|
<PackageReference Include="StackExchange.Redis" Version="2.9.32" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="9.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user