Changeset 467
- Timestamp:
- Aug 18, 2023, 12:08:10 PM (16 months ago)
- Location:
- TFP-WebServer
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
TFP-WebServer/WebServer/ModInfo.xml
r465 r467 5 5 <Description value="Integrated Webserver for the Web Dashboard and server APIs" /> 6 6 <Author value="The Fun Pimps LLC" /> 7 <Version value="21.1.16. 1" />7 <Version value="21.1.16.2" /> 8 8 <Website value="" /> 9 9 </xml> -
TFP-WebServer/WebServer/src/LogBuffer.cs
r434 r467 12 12 13 13 private int listOffset; 14 15 public static event Action<LogEntry> EntryAdded; 14 16 15 17 public static void Init () { … … 60 62 61 63 private void LogCallback (string _formattedMsg, string _plainMsg, string _trace, LogType _type, DateTime _timestamp, long _uptime) { 62 LogEntry le = new LogEntry (_timestamp, _plainMsg, _trace, _type, _uptime); 64 lock (logEntries) { 65 LogEntry le = new LogEntry (listOffset + logEntries.Count, _timestamp, _plainMsg, _trace, _type, _uptime); 63 66 64 lock (logEntries) {65 67 logEntries.Add (le); 68 EntryAdded?.Invoke (le); 69 66 70 if (logEntries.Count <= maxEntries) { 67 71 return; … … 126 130 127 131 public class LogEntry { 132 public readonly int MessageId; 128 133 public readonly DateTime Timestamp; 129 134 public readonly string IsoTime; … … 133 138 public readonly long Uptime; 134 139 135 public LogEntry (DateTime _timestamp, string _message, string _trace, LogType _type, long _uptime) { 140 public LogEntry (int _messageId, DateTime _timestamp, string _message, string _trace, LogType _type, long _uptime) { 141 MessageId = _messageId; 142 136 143 Timestamp = _timestamp; 137 144 IsoTime = _timestamp.ToString ("o"); -
TFP-WebServer/WebServer/src/SSE/EventLog.cs
r425 r467 1 using System;2 1 using JetBrains.Annotations; 3 using UnityEngine;4 2 using Utf8Json; 5 3 using Webserver.UrlHandlers; 6 using Webserver.WebAPI ;4 using Webserver.WebAPI.APIs; 7 5 8 6 namespace Webserver.SSE { … … 10 8 public class EventLog : AbsEvent { 11 9 public EventLog (SseHandler _parent) : base (_parent, _name: "log") { 12 Log .LogCallbacksExtended += LogCallback;10 LogBuffer.EntryAdded += LogCallback; 13 11 } 14 12 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 13 private void LogCallback (LogBuffer.LogEntry _logEntry) { 24 14 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 (); 15 LogApi.WriteLogMessageObject (ref writer, _logEntry); 42 16 43 17 SendData ("logLine", writer.ToString ()); -
TFP-WebServer/WebServer/src/UrlHandlers/ItemIconHandler.cs
r463 r467 122 122 Log.Out ($"[Web] IconHandler: Loaded {icons.Count} icons"); 123 123 } else { 124 stats ?.MswTotal.Stop ();124 stats.MswTotal.Stop (); 125 125 Log.Out ($"[Web] IconHandler: Loaded {icons.Count} icons ({stats.Files} source images with {stats.Tints} tints applied)"); 126 126 Log.Out ($"[Web] IconHandler: Total time {stats.MswTotal.ElapsedMilliseconds} ms, loading files {stats.MswLoading.ElapsedMilliseconds} ms, tinting files {stats.MswTinting.ElapsedMilliseconds} ms, encoding files {stats.MswEncoding.ElapsedMilliseconds} ms"); -
TFP-WebServer/WebServer/src/WebAPI/APIs/GameData/Mods.cs
r434 r467 19 19 } 20 20 21 writer.WriteBeginObject ();22 23 21 writeModJson (ref writer, webMod); 24 25 if (webMod.ReactBundle != null || webMod.CssPath != null) {26 writer.WriteValueSeparator ();27 28 writer.WritePropertyName ("web");29 writer.WriteBeginObject ();30 31 string webModReactBundle = webMod.ReactBundle;32 if (webModReactBundle != null) {33 writer.WritePropertyName ("bundle");34 writer.WriteString (webModReactBundle);35 }36 37 string webModCssFile = webMod.CssPath;38 if (webModCssFile != null) {39 if (webModReactBundle != null) {40 writer.WriteValueSeparator ();41 }42 43 writer.WritePropertyName ("css");44 writer.WriteString (webModCssFile);45 }46 47 writer.WriteEndObject ();48 }49 50 writer.WriteEndObject ();51 22 } 52 23 … … 56 27 } 57 28 58 private void writeModJson (ref JsonWriter _writer, WebMod _webMod) { 29 private static void writeModJson (ref JsonWriter _writer, WebMod _webMod) { 30 _writer.WriteBeginObject (); 31 59 32 _writer.WritePropertyName ("name"); 60 33 _writer.WriteString (_webMod.ParentMod.Name); … … 79 52 _writer.WritePropertyName ("website"); 80 53 _writer.WriteString (_webMod.ParentMod.Website); 54 55 writeWebModJson (ref _writer, _webMod); 56 57 _writer.WriteEndObject (); 58 } 59 60 private static void writeWebModJson (ref JsonWriter _writer, WebMod _webMod) { 61 if (_webMod.ModUrl != null) { 62 _writer.WriteValueSeparator (); 63 64 _writer.WritePropertyName ("web"); 65 _writer.WriteBeginObject (); 66 67 _writer.WritePropertyName ("baseUrl"); 68 _writer.WriteString (_webMod.ModUrl); 69 70 string webModReactBundle = _webMod.ReactBundle; 71 if (webModReactBundle != null) { 72 _writer.WriteValueSeparator (); 73 _writer.WritePropertyName ("bundle"); 74 _writer.WriteString (webModReactBundle); 75 } 76 77 string webModCssFile = _webMod.CssPath; 78 if (webModCssFile != null) { 79 _writer.WriteValueSeparator (); 80 _writer.WritePropertyName ("css"); 81 _writer.WriteString (webModCssFile); 82 } 83 84 _writer.WriteEndObject (); 85 } 81 86 } 82 87 -
TFP-WebServer/WebServer/src/WebAPI/APIs/GameData/Mods.openapi.yaml
r460 r467 37 37 type: object 38 38 properties: 39 baseUrl: 40 type: string 41 examples: 42 - /webmods/TFP_MarkersExample/ 43 description: Base URL of the WebMod folder of this mod. Always ends with a forward slash '/'. 39 44 bundle: 40 45 type: string 41 46 examples: 42 - /webmods/Xample_MarkersMod/bundle.js 47 - /webmods/TFP_MarkersExample/bundle.js 48 description: URL of the React bundle if the mod has one. 43 49 css: 44 50 type: string 45 51 examples: 46 - /webmods/Xample_MarkersMod/styling.css 52 - /webmods/TFP_MarkersExample/styling.css 53 description: URL of a styling CSS file if the mod has one. 54 required: 55 - baseUrl 47 56 required: 48 57 - name -
TFP-WebServer/WebServer/src/WebAPI/APIs/Log.openapi.yaml
r460 r467 8 8 LogEntry: 9 9 type: object 10 properties: 10 properties: 11 id: 12 type: integer 13 minimum: 0 14 description: Consecutive ID/number of this log line 11 15 msg: 12 16 type: string … … 33 37 examples: 34 38 - '87123' 35 description: Time since server was started in milliseconds .39 description: Time since server was started in milliseconds 36 40 required: 41 - id 37 42 - msg 38 43 - type -
TFP-WebServer/WebServer/src/WebAPI/APIs/LogApi.cs
r459 r467 12 12 private static readonly byte[] jsonKeyLastLine = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("lastLine"); 13 13 14 private static readonly byte[] jsonMsgKey = JsonWriter.GetEncodedPropertyNameWithBeginObject ("msg"); 14 private static readonly byte[] jsonIdKey = JsonWriter.GetEncodedPropertyNameWithBeginObject ("id"); 15 private static readonly byte[] jsonMsgKey = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("msg"); 15 16 private static readonly byte[] jsonTypeKey = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("type"); 16 17 private static readonly byte[] jsonTraceKey = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("trace"); … … 57 58 } 58 59 59 writer.WriteRaw (jsonMsgKey); 60 writer.WriteString (logEntry.Message); 61 62 writer.WriteRaw (jsonTypeKey); 63 writer.WriteString (logEntry.Type.ToStringCached ()); 64 65 writer.WriteRaw (jsonTraceKey); 66 writer.WriteString (logEntry.Trace); 67 68 writer.WriteRaw (jsonIsotimeKey); 69 writer.WriteString (logEntry.IsoTime); 70 71 writer.WriteRaw (jsonUptimeKey); 72 writer.WriteString (logEntry.Uptime.ToString ()); 73 74 writer.WriteEndObject (); 60 WriteLogMessageObject (ref writer, logEntry); 75 61 } 76 62 … … 87 73 SendEnvelopedResult (_context, ref writer); 88 74 } 75 76 public static void WriteLogMessageObject (ref JsonWriter _writer, LogBuffer.LogEntry _logEntry) { 77 _writer.WriteRaw (jsonIdKey); 78 _writer.WriteInt32 (_logEntry.MessageId); 79 80 _writer.WriteRaw (jsonMsgKey); 81 _writer.WriteString (_logEntry.Message); 82 83 _writer.WriteRaw (jsonTypeKey); 84 _writer.WriteString (_logEntry.Type.ToStringCached ()); 85 86 _writer.WriteRaw (jsonTraceKey); 87 _writer.WriteString (_logEntry.Trace); 88 89 _writer.WriteRaw (jsonIsotimeKey); 90 _writer.WriteString (_logEntry.IsoTime); 91 92 _writer.WriteRaw (jsonUptimeKey); 93 _writer.WriteString (_logEntry.Uptime.ToString ()); 94 95 _writer.WriteEndObject (); 96 } 89 97 } 90 98 } -
TFP-WebServer/bin/Mods/TFP_WebServer/ModInfo.xml
r465 r467 5 5 <Description value="Integrated Webserver for the Web Dashboard and server APIs" /> 6 6 <Author value="The Fun Pimps LLC" /> 7 <Version value="21.1.16. 1" />7 <Version value="21.1.16.2" /> 8 8 <Website value="" /> 9 9 </xml>
Note:
See TracChangeset
for help on using the changeset viewer.