source: binary-improvements/MapRendering/API/GetPlayerInventories.cs@ 458

Last change on this file since 458 was 455, checked in by alloc, 16 months ago

25_30_44

  • Got rid (mostly) of custom JSON serialization
  • Some code cleanup
File size: 1012 bytes
Line 
1using System.Collections.Generic;
2using AllocsFixes.PersistentData;
3using JetBrains.Annotations;
4using Utf8Json;
5using Webserver;
6using Webserver.WebAPI;
7
8namespace AllocsFixes.WebAPIs {
9 [UsedImplicitly]
10 public class GetPlayerInventories : AbsWebAPI {
11 public override void HandleRequest (RequestContext _context) {
12 GetPlayerInventory.GetInventoryArguments (_context, out bool showIconColor, out bool showIconName);
13
14 JsonWriter writer = new JsonWriter ();
15
16 writer.WriteBeginArray ();
17
18 bool first = true;
19
20 foreach (KeyValuePair<PlatformUserIdentifierAbs, Player> kvp in PersistentContainer.Instance.Players.Dict) {
21 Player p = kvp.Value;
22
23 if (p == null) {
24 continue;
25 }
26
27 if (p.IsOnline) {
28 if (!first) {
29 writer.WriteValueSeparator ();
30 }
31
32 first = false;
33
34 GetPlayerInventory.DoPlayer (ref writer, p, showIconColor, showIconName);
35 }
36 }
37
38 writer.WriteEndArray ();
39
40 WebUtils.WriteJsonData (_context.Response, ref writer);
41 }
42 }
43}
Note: See TracBrowser for help on using the repository browser.