yuanshen/Yuanshen.SDK/Handlers/TelemetryHandler.cs
wisedev fc2ac1050f First working version of the server
KCP gameserver with packet dispatch, scene streaming, combat, gacha and the
shop, plus a small HTTP server for the login flow and the wish history page.

Game data under assets is pulled out of the client instead of being typed by
hand. The excel tables come from the packed bin container and the spawn points
from the compiled scene scripts.
2026-09-04 02:10:50 +03:00

34 lines
1.2 KiB
C#

namespace Yuanshen.SDK.Handlers;
public static class TelemetryHandler
{
private const int PreviewLimit = 1200;
public static async Task<IResult> OnLog(HttpRequest request)
{
Log.Info($"telemetry {request.Path} {await BodyAsync(request)}");
return TypedResults.Text("{\"code\":0}", "application/json");
}
public static async Task<IResult> OnUnhandled(HttpRequest request)
{
string path = $"{request.Path}{request.QueryString}";
Log.Unhandled(request.Method, path);
if (HttpMethods.IsPost(request.Method) || HttpMethods.IsPut(request.Method))
Log.Info($"body {await BodyAsync(request)}");
return TypedResults.Text("{\"retcode\":0,\"message\":\"OK\",\"data\":null}", "application/json");
}
private static async Task<string> BodyAsync(HttpRequest request)
{
using StreamReader reader = new(request.Body, leaveOpen: true);
string body = (await reader.ReadToEndAsync()).ReplaceLineEndings(" ");
if (body.Length == 0)
return "<empty>";
return body.Length <= PreviewLimit ? body : body[..PreviewLimit] + $"... (+{body.Length - PreviewLimit} bytes)";
}
}