mirror of
https://github.com/DorkSquadRR/DorkNet.git
synced 2026-10-26 07:28:45 -07:00
d471b418b9
Targets Rec Room 2020.03.10 client (also serves 2020.03.06).
Re-import after adding:
- DorkNet.ClientMod/dorknet-clientmod.json.template — config schema
the launcher's manifest-driven patcher renders into UserData/.
- tools/build-patcher-zip.ps1 — produces dorknet-clientpatch-{key}.zip
for v1-march-* Release uploads.
- .github/workflows/release.yml — on tag push publishes both
dorknet-server-march_2020_03_10-win-x64.zip and
dorknet-clientpatch-march_2020_03_10.zip as Release assets.
Same scrub rules as december; tools/build-patcher-zip.ps1 added to
the maintainer-side allow-list so it survives.
82 lines
2.7 KiB
C#
82 lines
2.7 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using DorkNet.Server.Auth;
|
|
using DorkNet.Server.Data;
|
|
using DorkNet.Server.Services;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace DorkNet.Server.Controllers.Econ;
|
|
|
|
/// <summary>
|
|
/// econ.{rec.net,localhost} — token balance + inventory queries used
|
|
/// by older client flows. Reads from <see cref="LevelService"/>
|
|
/// (currency type 0 = Token per <c>CurrencyType.cs</c>) and the
|
|
/// <see cref="PlayerInventoryEntity"/> table. Note: the primary
|
|
/// store/inventory surface is api.*/api/storefronts/* + api/inventory/*;
|
|
/// this host is a legacy alias.
|
|
/// </summary>
|
|
[ApiController]
|
|
[Authorize]
|
|
public class EconController(DorkNetDbContext db, LevelService level) : ControllerBase
|
|
{
|
|
[HttpGet("/econ/v1/balance/{accountId:long}")]
|
|
public async Task<ActionResult<TokenBalance>> GetBalance(long accountId)
|
|
{
|
|
var tokens = await level.GetBalanceAsync(accountId, 0);
|
|
return Ok(new TokenBalance
|
|
{
|
|
AccountId = accountId,
|
|
Tokens = (int)tokens,
|
|
BonusTokens = 0,
|
|
});
|
|
}
|
|
|
|
[HttpGet("/econ/v1/ownershipbatch")]
|
|
public async Task<IActionResult> GetOwnershipBatch([FromQuery] string? ids)
|
|
{
|
|
var pid = this.RequireCurrentPlayerId();
|
|
var slugs = (ids ?? string.Empty)
|
|
.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
|
|
.ToList();
|
|
var q = db.PlayerInventory.Where(p => p.PlayerId == pid);
|
|
if (slugs.Count > 0) q = q.Where(p => slugs.Contains(p.ItemSlug));
|
|
var rows = await q.Select(p => new { p.ItemSlug, p.Quantity }).ToListAsync();
|
|
return Ok(rows);
|
|
}
|
|
|
|
[HttpGet("/econ/v1/inventory/{accountId:long}")]
|
|
public async Task<IActionResult> GetInventory(long accountId)
|
|
{
|
|
var rows = await db.PlayerInventory
|
|
.Where(p => p.PlayerId == accountId)
|
|
.Select(p => new { p.ItemSlug, p.Quantity })
|
|
.ToListAsync();
|
|
return Ok(rows);
|
|
}
|
|
|
|
[HttpGet("/econ/v1/products")]
|
|
public async Task<IActionResult> GetProducts()
|
|
{
|
|
var rows = await db.StoreItems
|
|
.Where(s => s.IsActive)
|
|
.Select(s => new
|
|
{
|
|
Id = s.Id,
|
|
Slug = s.Slug,
|
|
Name = s.DisplayName,
|
|
Price = s.Price,
|
|
CurrencyType = s.CurrencyType,
|
|
})
|
|
.ToListAsync();
|
|
return Ok(rows);
|
|
}
|
|
}
|
|
|
|
public class TokenBalance
|
|
{
|
|
[JsonPropertyName("AccountId")] public long AccountId { get; set; }
|
|
[JsonPropertyName("Tokens")] public int Tokens { get; set; }
|
|
[JsonPropertyName("BonusTokens")] public int BonusTokens { get; set; }
|
|
}
|