yuanshen/Yuanshen.SDK/Handlers/TelemetryHandler.cs
wisedev 49450270db World drops, group based spawning and a pile of fixes
Drops now land on the ground as gadgets and are picked up with F instead of
appearing in the bag out of nowhere. Chests, ore, crystals and plants all spawn
and can be interacted with.

Monsters load by scene group rather than by a radius around each one, so a camp
shows up as a camp and nothing pops into existence mid fight. The group anchors
come out of the scene Lua, which also killed four invented tuning constants.

The gateway was creating a whole new session for every handshake datagram, and
the client retransmits those until it gets an answer. That is where the piles of
duplicated monsters and the chests coming back from the dead were coming from.

Also: monster level scales to the party now, path queries return an actual two
point path instead of an empty one, NpcTalk closes properly, and the ability and
combat invocations are no longer echoed back to the client that sent them.
2026-09-04 17:44:02 +03:00

51 lines
1.7 KiB
C#

namespace Yuanshen.SDK.Handlers;
public static class TelemetryHandler
{
private const int PreviewLimit = 1200;
private static readonly object FileLock = new();
private static readonly string LogPath = Path.Combine(AppContext.BaseDirectory, "client-telemetry.log");
public static async Task<IResult> OnLog(HttpRequest request)
{
string body = await BodyAsync(request);
Append(request.Path, body);
Log.Info($"telemetry {request.Path} {body}");
return TypedResults.Text("{\"code\":0}", "application/json");
}
private static void Append(string path, string body)
{
try
{
lock (FileLock)
File.AppendAllText(LogPath, $"{DateTime.Now:HH:mm:ss} {path} {body}{Environment.NewLine}");
}
catch (IOException)
{
}
}
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)";
}
}