ReboundEmulator/Controllers/CDLController.cs
Moonbase 2631d3199c Implement Multiplayer Support
Implement Custom Screen Name Support
2026-10-06 19:00:15 -07:00

51 lines
1.8 KiB
C#

using Microsoft.AspNetCore.Mvc;
using NotPogo.Core;
using NotPogo.Core.Rooms;
namespace NotPogo.Controllers
{
public class CDLController : Controller
{
[HttpGet]
[Route("/cdl/cdl-info.jsp")]
public IResult CDLInfo(string lkey)
{
var acct = Sessions.Find(lkey);
if (acct is null)
return Results.Text("error notloggedin", "text/plain"); // see note below
var enti = $"oava {(acct.OwnsPremiumAvatar ? 1 : 0)} obad {(acct.OwnsBadges ? 1 : 0)}";
var body = string.Join(" ",
"error", "none",
"screenname", Q(acct.ScreenName),
"site", Q(acct.Site),
"tokens", acct.Tokens.ToString(),
"enti", Q(enti),
"avatar", Q(acct.Avatar));
return Results.Text(body, "text/plain");
}
static string Q(string s) => "'" + s.Replace("\\", "\\\\").Replace("'", "\\'") + "'";
[HttpGet("/cdl/1/login")]
public IResult CDLLogin(string name)
{
var lkey = Sessions.Issue(name);
// more satisfying
return Results.Text($"<LoginResponse error=\"none\">\n<LoginSessionKey>{lkey}</LoginSessionKey></LoginResponse>", "text/xml");
}
[HttpGet("/cdl/1/cdl-clientprops")]
public IActionResult CDLClientProps(string game)
{
string pathToProps = Path.Combine(AppContext.BaseDirectory, "StaticFiles", "Configs", "CDL", $"{game}.properties");
if (System.IO.File.Exists(pathToProps))
return Ok(System.IO.File.ReadAllText(pathToProps));
else
return Ok(); // don't send anything since we don't have the config for it on the server yet
}
}
}