source: binary-improvements2/WebServer/src/WebAPI/APIs/ServerInfo.cs@ 404

Last change on this file since 404 was 404, checked in by alloc, 21 months ago

Latest state including reworking to the permissions system

File size: 2.5 KB
RevLine 
[404]1using System.Collections.Generic;
[391]2using JetBrains.Annotations;
[402]3using Utf8Json;
[391]4
[402]5namespace Webserver.WebAPI.APIs {
[391]6 [UsedImplicitly]
[402]7 public class ServerInfo : AbsRestApi {
8 private static readonly UnityEngine.Profiling.CustomSampler buildSampler = UnityEngine.Profiling.CustomSampler.Create ("JSON_ServerInfo_BuildSampler");
[391]9
[402]10 private static readonly byte[] keyType = JsonWriter.GetEncodedPropertyNameWithBeginObject ("type");
11 private static readonly byte[] keyValue = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("value");
12
13 private int largestBuffer;
14
15 protected override void HandleRestGet (RequestContext _context) {
16 buildSampler.Begin ();
17
18 PrepareEnvelopedResult (out JsonWriter writer);
19
20 writer.EnsureCapacity (largestBuffer);
21 writer.WriteBeginObject ();
22
[391]23 GameServerInfo gsi = ConnectionManager.Instance.LocalServerInfo;
24
[404]25 IList<GameInfoString> list = EnumUtils.Values<GameInfoString> ();
26 for (int i = 0; i < list.Count; i++) {
27 GameInfoString stringGamePref = list [i];
[391]28
[404]29 if (i > 0) {
[402]30 writer.WriteValueSeparator ();
31 }
32
33 writer.WriteString (stringGamePref.ToStringCached ());
34 writer.WriteNameSeparator ();
[404]35
[402]36 writer.WriteRaw (keyType);
37 writer.WriteString ("string");
[404]38
[402]39 writer.WriteRaw (keyValue);
[404]40 writer.WriteString (gsi.GetValue (stringGamePref));
41
[402]42 writer.WriteEndObject ();
[391]43 }
44
[404]45 IList<GameInfoInt> ints = EnumUtils.Values<GameInfoInt> ();
46 for (int i = 0; i < ints.Count; i++) {
47 GameInfoInt intGamePref = ints [i];
[391]48
[404]49 if (i > 0) {
[402]50 writer.WriteValueSeparator ();
51 }
[391]52
[402]53 writer.WriteString (intGamePref.ToStringCached ());
54 writer.WriteNameSeparator ();
[404]55
[402]56 writer.WriteRaw (keyType);
57 writer.WriteString ("int");
[404]58
[402]59 writer.WriteRaw (keyValue);
[404]60 writer.WriteInt32 (gsi.GetValue (intGamePref));
61
[402]62 writer.WriteEndObject ();
[391]63 }
64
[404]65 IList<GameInfoBool> prefs = EnumUtils.Values<GameInfoBool> ();
66 for (int i = 0; i < prefs.Count; i++) {
67 GameInfoBool boolGamePref = prefs [i];
[391]68
[404]69 if (i > 0) {
[402]70 writer.WriteValueSeparator ();
71 }
[391]72
[402]73 writer.WriteString (boolGamePref.ToStringCached ());
74 writer.WriteNameSeparator ();
[404]75
[402]76 writer.WriteRaw (keyType);
77 writer.WriteString ("bool");
[404]78
[402]79 writer.WriteRaw (keyValue);
[404]80 writer.WriteBoolean (gsi.GetValue (boolGamePref));
81
[402]82 writer.WriteEndObject ();
[391]83 }
[404]84
[402]85 writer.WriteEndObject ();
86
87 buildSampler.End ();
[391]88
[402]89 int bufferContentSize = writer.CurrentOffset + 128;
90 if (bufferContentSize > largestBuffer) {
91 largestBuffer = bufferContentSize;
92 }
93
94 SendEnvelopedResult (_context, ref writer);
[391]95 }
96 }
97}
Note: See TracBrowser for help on using the repository browser.