source: binary-improvements2/WebServer/src/WebAPI/JsonCommons.cs@ 425

Last change on this file since 425 was 425, checked in by alloc, 19 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: 2.3 KB
RevLine 
[425]1using System;
2using UnityEngine;
[402]3using Utf8Json;
4
5namespace Webserver.WebAPI {
6 public static class JsonCommons {
7 private static readonly byte[] jsonKeyPositionX = JsonWriter.GetEncodedPropertyNameWithBeginObject ("x");
8 private static readonly byte[] jsonKeyPositionY = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("y");
9 private static readonly byte[] jsonKeyPositionZ = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("z");
10
[408]11 public static void WritePositionObject (ref JsonWriter _writer, Vector3i _position) {
[402]12 _writer.WriteRaw (jsonKeyPositionX);
13 _writer.WriteInt32 (_position.x);
14
15 _writer.WriteRaw (jsonKeyPositionY);
16 _writer.WriteInt32 (_position.y);
17
18 _writer.WriteRaw (jsonKeyPositionZ);
19 _writer.WriteInt32 (_position.z);
20
21 _writer.WriteEndObject ();
22 }
[425]23
24 public static void WritePositionObject (ref JsonWriter _writer, Vector3 _position) {
25 _writer.WriteRaw (jsonKeyPositionX);
26 _writer.WriteSingle (_position.x);
27
28 _writer.WriteRaw (jsonKeyPositionY);
29 _writer.WriteSingle (_position.y);
30
31 _writer.WriteRaw (jsonKeyPositionZ);
32 _writer.WriteSingle (_position.z);
33
34 _writer.WriteEndObject ();
35 }
36
37 private static readonly byte[] jsonKeyCombinedString = JsonWriter.GetEncodedPropertyNameWithBeginObject ("combinedString");
38 private static readonly byte[] jsonKeyPlatformId = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("platformId");
39 private static readonly byte[] jsonKeyUserId = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("userId");
40
41 public static void WritePlatformUserIdentifier (ref JsonWriter _writer, PlatformUserIdentifierAbs _userIdentifier) {
42 if (_userIdentifier == null) {
43 _writer.WriteNull ();
44 return;
45 }
46
47 _writer.WriteRaw (jsonKeyCombinedString);
48 _writer.WriteString (_userIdentifier.CombinedString);
49
50 _writer.WriteRaw (jsonKeyPlatformId);
51 _writer.WriteString (_userIdentifier.PlatformIdentifierString);
52
53 _writer.WriteRaw (jsonKeyUserId);
54 _writer.WriteString (_userIdentifier.ReadablePlatformUserIdentifier);
55
56 _writer.WriteEndObject ();
57 }
58
59 public static void WriteDateTime (ref JsonWriter _writer, DateTime _dateTime) {
60 _writer.WriteString (_dateTime.ToString ("o"));
61 }
[402]62 }
63}
Note: See TracBrowser for help on using the repository browser.