CDN Integration

This commit is contained in:
dingo
2025-12-19 10:12:17 -05:00
parent 351478fedb
commit 260e6fa072
11 changed files with 2316 additions and 63 deletions
+52 -17
View File
@@ -80,7 +80,9 @@ public sealed class DungeonHandler : IClientMessageHandler
// Dungeon browser
DungeonOpCodes.DUNGEON_LIST_REQUEST,
DungeonOpCodes.DUNGEON_CREATE,
DungeonOpCodes.DUNGEON_JOIN
DungeonOpCodes.DUNGEON_JOIN,
// Asset management
DungeonOpCodes.ASSET_MANIFEST_REQUEST
};
public async Task InitializeAsync()
@@ -228,6 +230,9 @@ public sealed class DungeonHandler : IClientMessageHandler
case DungeonOpCodes.DUNGEON_JOIN:
await HandleDungeonJoin(connection, session, payload, ct);
break;
case DungeonOpCodes.ASSET_MANIFEST_REQUEST:
await HandleAssetManifestRequest(connection, ct);
break;
}
}
catch (Exception ex)
@@ -783,7 +788,7 @@ public sealed class DungeonHandler : IClientMessageHandler
var emptyTime = DateTime.UtcNow - instance.LastPlayerActivity;
// If boss not killed and empty for 10+ minutes, persist to database
if (!instance.BossKilled && !instance.IsPersisted && emptyTime.TotalMinutes >= 5)
if (!instance.BossKilled && !instance.IsPersisted && emptyTime.TotalMinutes >= 10)
{
_ = PersistDungeonAsync(instance, CancellationToken.None);
_dungeons.TryRemove(dungeonId, out _);
@@ -1614,6 +1619,38 @@ public sealed class DungeonHandler : IClientMessageHandler
#region Dungeon Browser Handlers
/// <summary>
/// Handle request for asset manifest (list of all CDN files for hot-update)
/// </summary>
private async Task HandleAssetManifestRequest(IConnection connection, CancellationToken ct)
{
using var scope = _scopeFactory.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<GameDbContext>();
var assets = await db.ClientAssets
.Where(a => a.IsEnabled)
.Select(a => new
{
filePath = a.FilePath,
assetType = (int)a.AssetType,
fileHash = a.FileHash,
fileSize = a.FileSize,
version = a.Version,
isRequired = a.IsRequired,
minClientVersion = a.MinClientVersion,
cdnPath = a.CdnPath ?? a.FilePath
})
.ToListAsync(ct);
await SendAsync(connection, DungeonOpCodes.ASSET_MANIFEST_RESPONSE, new
{
cdnBaseUrl = "https://assets.aeternalisgames.com/downloads/",
assets = assets
}, ct);
_log.LogInformation("Sent asset manifest with {Count} files", assets.Count);
}
/// <summary>
/// Handle request for list of available dungeons
/// </summary>
@@ -1905,10 +1942,9 @@ public sealed class DungeonHandler : IClientMessageHandler
y = m.Y,
health = m.Health,
maxHealth = m.MaxHealth,
spriteSheet = m.SpriteSheet,
spriteWidth = m.SpriteWidth,
spriteHeight = m.SpriteHeight,
tintColor = m.TintColor
scenePath = m.ScenePath,
tintColor = m.TintColor,
scale = m.Scale
}),
chests = instance.Simulation.Chests.Values.Select(c => new
{
@@ -2022,13 +2058,13 @@ public sealed class DungeonHandler : IClientMessageHandler
instance.Simulation.DroppedItems.Clear();
// Reset portals (exit portal should be inactive until boss killed)
//foreach (var portal in instance.Simulation.Portals.Values)
//{
// if (portal.Type == PortalType.Exit)
// {
// portal.IsActive = false;
// }
//}
foreach (var portal in instance.Simulation.Portals.Values)
{
if (portal.Type == PortalType.Exit)
{
portal.IsActive = false;
}
}
_log.LogDebug("Respawned {MobCount} mobs in dungeon {Id}", instance.Simulation.Mobs.Count, instance.Id);
}
@@ -2455,10 +2491,9 @@ public sealed class DungeonHandler : IClientMessageHandler
health = m.Health,
maxHealth = m.MaxHealth,
state = m.State.ToString().ToLower(),
spriteSheet = m.SpriteSheet,
spriteWidth = m.SpriteWidth,
spriteHeight = m.SpriteHeight,
tintColor = m.TintColor
scenePath = m.ScenePath,
tintColor = m.TintColor,
scale = m.Scale
}),
chests = sim.Chests.Values.Select(c => new