source: TFP-WebServer/WebServer/src/SSE/EventLog.cs@ 460

Last change on this file since 460 was 425, checked in by alloc, 20 months ago
  • API "map" added, currently only supports GET with the ID "config"
  • API "player" added, currently only supports getting online players with some of the info not supported yet (playtime, last online, level)
  • Only logged in player's data is shown unless the user has the permission for "webapi.viewallplayers"
  • Internal refactoring
  • (Updated version to 21.0.258)
File size: 1.6 KB
Line 
1using System;
2using JetBrains.Annotations;
3using UnityEngine;
4using Utf8Json;
5using Webserver.UrlHandlers;
6using Webserver.WebAPI;
7
8namespace Webserver.SSE {
9 [UsedImplicitly]
10 public class EventLog : AbsEvent {
11 public EventLog (SseHandler _parent) : base (_parent, _name: "log") {
12 Log.LogCallbacksExtended += LogCallback;
13 }
14
15 private static readonly byte[] jsonMsgKey = JsonWriter.GetEncodedPropertyNameWithBeginObject ("msg");
16 private static readonly byte[] jsonTypeKey = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("type");
17 private static readonly byte[] jsonTraceKey = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("trace");
18 private static readonly byte[] jsonIsotimeKey = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("isotime");
19 private static readonly byte[] jsonUptimeKey = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("uptime");
20
21 private void LogCallback (string _formattedMsg, string _plainMsg, string _trace, LogType _type, DateTime _timestamp, long _uptime) {
22 string uptime = _uptime.ToString ();
23
24 JsonWriter writer = new JsonWriter ();
25
26 writer.WriteRaw (jsonMsgKey);
27 writer.WriteString (_plainMsg);
28
29 writer.WriteRaw (jsonTypeKey);
30 writer.WriteString (_type.ToStringCached ());
31
32 writer.WriteRaw (jsonTraceKey);
33 writer.WriteString (_trace);
34
35 writer.WriteRaw (jsonIsotimeKey);
36 JsonCommons.WriteDateTime (ref writer, _timestamp);
37
38 writer.WriteRaw (jsonUptimeKey);
39 writer.WriteString (uptime);
40
41 writer.WriteEndObject ();
42
43 SendData ("logLine", writer.ToString ());
44 }
45 }
46}
Note: See TracBrowser for help on using the repository browser.