Add Dynamic Game Page Generation

This commit is contained in:
Alan Moon 2026-09-14 23:08:35 -07:00
parent 253dccb25b
commit 2c42c46033
3 changed files with 65 additions and 8 deletions

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using NotPogo.Model;
using System.IO.Compression; using System.IO.Compression;
using System.Net; using System.Net;
using System.Reflection.Metadata.Ecma335; using System.Reflection.Metadata.Ecma335;
@ -16,17 +17,39 @@ namespace NotPogo.Controllers
// might aswell provide a minimal way to play the games supported // might aswell provide a minimal way to play the games supported
[HttpGet] [HttpGet]
[Route("/play-game")] [Route("/play-game")]
public IActionResult GetGamePage(string game) public IActionResult GamePage(string? name,
string game,
string appletClass,
string site,
string locale,
string hostedGameClass)
{ {
var path = Path.Combine(AppContext.BaseDirectory, "StaticFiles", "GameAssets", game, "index.html"); var gamePage = new GamePage
_logger.LogInformation("Attempting To Serve Game Applet At {Path}", path);
return new ContentResult
{ {
Content = System.IO.File.Exists(path) ? System.IO.File.ReadAllText(path) : $"Game Not Found - {game}", GameName = name ?? game,
ContentType = "text/html", InternalName = game,
StatusCode = (int)HttpStatusCode.OK JavaAppletClass = appletClass,
JavaAppletParameters = new()
{
{ "name", game },
{ "hosted.game.class", hostedGameClass },
{ "standalone", "false" },
{ "type", game },
{ "config", $"client-props.jsp?game={game}" },
{ "locale", locale },
{ "site", site },
{ "rkey", "" },
{ "unid", "" },
{ "sourceid", "" },
{ "launchPage", "" },
{ "lkey", "" },
{ "cnid", "" },
{ "isSingleApplet", "true" },
{ "browserInfo", "" }
}
}; };
return View(gamePage);
} }
[HttpGet] [HttpGet]

12
Model/GamePage.cs Normal file
View File

@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace NotPogo.Model
{
public class GamePage : PageModel
{
public string GameName { get; set; } = string.Empty;
public string InternalName { get; set; } = string.Empty;
public string JavaAppletClass { get; set; } = string.Empty;
public Dictionary<string, string> JavaAppletParameters { get; set; } = [];
}
}

View File

@ -0,0 +1,22 @@
@model NotPogo.Model.GamePage
<!DOCTYPE html>
<html>
<head>
<title>@($"Not Pogo - {Model.GameName}")</title>
</head>
<body style="margin:0; padding:0;">
<applet code="@Model.JavaAppletClass"
codebase="@($"{Context.Request.Scheme}://{Context.Request.Host.Value}")"
archive="@($"{Context.Request.Scheme}://{Context.Request.Host.Value}/get-jar?game={Model.InternalName}")"
width="784" height="506">
@foreach (var kv in Model.JavaAppletParameters)
{
<param name="@kv.Key" value="@kv.Value">
}
Unfortunately, In Order To Use Not Pogo, You Need To Use A Browser That Still Supports Java Applets
</applet>
</body>
</html>