mirror of
https://github.com/DorkSquadRR/DorkNet.git
synced 2026-10-26 15:38:45 -07:00
Support local domains and bundled client patching
This commit is contained in:
@@ -20,14 +20,12 @@ public class ConfigService(IConfiguration config, DomainConfig domain)
|
||||
// the client used to hit us. The baseUrl parameter is kept
|
||||
// for API stability but is no longer dereferenced.
|
||||
_ = baseUrl;
|
||||
var apex = domain.Apex;
|
||||
|
||||
return new RecRoomConfig
|
||||
{
|
||||
MessageOfTheDay = config["Server:MOTD"] ?? "Welcome to the private server!",
|
||||
CdnBaseUri = $"https://{domain.Sub("cdn")}",
|
||||
CdnBaseUri = domain.SubUrl("cdn"),
|
||||
PhotonConfig = photon,
|
||||
ServiceUrls = BuildServiceUrlMap(apex),
|
||||
ServiceUrls = BuildServiceUrlMap(domain),
|
||||
ConfigTable = new Dictionary<string, string>
|
||||
{
|
||||
// Season keys the 2019/2020 client checks at startup
|
||||
@@ -106,4 +104,15 @@ public class ConfigService(IConfiguration config, DomainConfig domain)
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static Dictionary<string, string> BuildServiceUrlMap(DomainConfig domain)
|
||||
{
|
||||
var map = new Dictionary<string, string>(ServiceSubdomains.Length);
|
||||
foreach (var (service, sub) in ServiceSubdomains)
|
||||
{
|
||||
var host = string.IsNullOrEmpty(sub) ? domain.Apex : domain.Sub(sub);
|
||||
map[service] = domain.Url(host);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,19 @@ namespace DorkNet.Server.Services;
|
||||
public sealed class DomainConfig
|
||||
{
|
||||
public string Apex { get; }
|
||||
public DomainConfig(string apex) { Apex = apex; }
|
||||
public string Scheme { get; }
|
||||
public string? Port { get; }
|
||||
|
||||
public DomainConfig(string apex, string scheme = "https", string? port = null)
|
||||
{
|
||||
Apex = apex;
|
||||
Scheme = string.IsNullOrWhiteSpace(scheme) ? "https" : scheme.TrimEnd(':', '/', '\\');
|
||||
Port = string.IsNullOrWhiteSpace(port) ? null : port.Trim().TrimStart(':');
|
||||
}
|
||||
|
||||
public string Sub(string prefix) => $"{prefix}.{Apex}";
|
||||
public string Url(string host) => Port is null ? $"{Scheme}://{host}" : $"{Scheme}://{host}:{Port}";
|
||||
public string SubUrl(string prefix) => Url(Sub(prefix));
|
||||
public static bool MatchesSubdomain(string host, string prefix)
|
||||
=> host.StartsWith(prefix + ".", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
@@ -923,14 +923,27 @@ public class RoomService(DorkNetDbContext db)
|
||||
// Name="BloodMoon" because SaveChanges hadn't fired yet, so
|
||||
// the image binding silently no-op'd. Mutating the already-
|
||||
// loaded entity sidesteps that race.
|
||||
var bloodmoon = await db.Rooms.FirstOrDefaultAsync(r => r.Name == "BloodMoon" || r.Name == "Crescendo");
|
||||
if (bloodmoon is not null)
|
||||
var crescendoRooms = await db.Rooms
|
||||
.Where(r => r.Name.ToLower() == "bloodmoon" || r.Name.ToLower() == "crescendo")
|
||||
.ToListAsync();
|
||||
var crescendo = crescendoRooms.FirstOrDefault(r =>
|
||||
string.Equals(r.Name, "Crescendo", StringComparison.OrdinalIgnoreCase));
|
||||
var bloodMoon = crescendoRooms.FirstOrDefault(r =>
|
||||
string.Equals(r.Name, "BloodMoon", StringComparison.OrdinalIgnoreCase));
|
||||
var shouldRenameBloodMoon = crescendo is null;
|
||||
crescendo ??= bloodMoon;
|
||||
if (crescendo is not null)
|
||||
{
|
||||
if (bloodmoon.Name != "Crescendo") bloodmoon.Name = "Crescendo";
|
||||
if (string.IsNullOrWhiteSpace(bloodmoon.Description))
|
||||
bloodmoon.Description = "Brave the haunted halls of Castle Dracula and survive the night.";
|
||||
if (bloodmoon.ImageName != "image_Crescendo.png")
|
||||
bloodmoon.ImageName = "image_Crescendo.png";
|
||||
if (shouldRenameBloodMoon && crescendo.Name != "Crescendo")
|
||||
crescendo.Name = "Crescendo";
|
||||
if (string.IsNullOrWhiteSpace(crescendo.Description))
|
||||
crescendo.Description = "Brave the haunted halls of Castle Dracula and survive the night.";
|
||||
if (crescendo.ImageName != "image_Crescendo.png")
|
||||
crescendo.ImageName = "image_Crescendo.png";
|
||||
}
|
||||
foreach (var duplicate in crescendoRooms.Where(r => r.Id != crescendo?.Id))
|
||||
{
|
||||
duplicate.HiddenFromBrowse = true;
|
||||
}
|
||||
|
||||
var paintball = await db.Rooms.FirstOrDefaultAsync(r => r.Name == "Paintball");
|
||||
|
||||
Reference in New Issue
Block a user