improvement on gm windows, ai
This commit is contained in:
16
apps/backend/Universe/Api/GetBalanceHandler.cs
Normal file
16
apps/backend/Universe/Api/GetBalanceHandler.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using FastEndpoints;
|
||||
using SpaceGame.Api.Universe.Simulation;
|
||||
|
||||
namespace SpaceGame.Api.Universe.Api;
|
||||
|
||||
public sealed class GetBalanceHandler(WorldService worldService) : EndpointWithoutRequest
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/balance");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override Task HandleAsync(CancellationToken cancellationToken) =>
|
||||
SendOkAsync(worldService.GetBalance(), cancellationToken);
|
||||
}
|
||||
49
apps/backend/Universe/Api/GetTelemetryHandler.cs
Normal file
49
apps/backend/Universe/Api/GetTelemetryHandler.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using FastEndpoints;
|
||||
using SpaceGame.Api.Universe.Simulation;
|
||||
|
||||
namespace SpaceGame.Api.Universe.Api;
|
||||
|
||||
public sealed class GetTelemetryHandler(TelemetryService telemetry, WorldService worldService) : EndpointWithoutRequest
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/telemetry");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override Task HandleAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var status = worldService.GetStatus();
|
||||
var connections = worldService.GetConnectionStats();
|
||||
var uptime = telemetry.Uptime;
|
||||
|
||||
return SendOkAsync(new
|
||||
{
|
||||
process = new
|
||||
{
|
||||
uptimeSeconds = uptime.TotalSeconds,
|
||||
cpuPercent = Math.Round(telemetry.CpuPercent, 1),
|
||||
workingSetMb = Math.Round(telemetry.WorkingSetBytes / 1_048_576.0, 1),
|
||||
gcMemoryMb = Math.Round(telemetry.GcMemoryBytes / 1_048_576.0, 1),
|
||||
threadCount = telemetry.ThreadCount,
|
||||
processorCount = Environment.ProcessorCount,
|
||||
},
|
||||
simulation = new
|
||||
{
|
||||
sequence = status.Sequence,
|
||||
connectedClients = connections.ConnectedClients,
|
||||
deltaHistoryCount = connections.DeltaHistoryCount,
|
||||
tickIntervalMs = 200,
|
||||
},
|
||||
runtime = new
|
||||
{
|
||||
frameworkDescription = RuntimeInformation.FrameworkDescription,
|
||||
osDescription = RuntimeInformation.OSDescription,
|
||||
gcGen0 = GC.CollectionCount(0),
|
||||
gcGen1 = GC.CollectionCount(1),
|
||||
gcGen2 = GC.CollectionCount(2),
|
||||
},
|
||||
}, cancellationToken);
|
||||
}
|
||||
}
|
||||
20
apps/backend/Universe/Api/UpdateBalanceHandler.cs
Normal file
20
apps/backend/Universe/Api/UpdateBalanceHandler.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using FastEndpoints;
|
||||
using SpaceGame.Api.Definitions;
|
||||
using SpaceGame.Api.Universe.Simulation;
|
||||
|
||||
namespace SpaceGame.Api.Universe.Api;
|
||||
|
||||
public sealed class UpdateBalanceHandler(WorldService worldService) : Endpoint<BalanceDefinition>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Put("/api/balance");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override Task HandleAsync(BalanceDefinition req, CancellationToken cancellationToken)
|
||||
{
|
||||
var applied = worldService.UpdateBalance(req);
|
||||
return SendOkAsync(applied, cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user