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