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

Last change on this file since 489 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
RevLine 
[332]1using System.Collections.Generic;
[321]2using AllocsFixes.PersistentData;
[455]3using JetBrains.Annotations;
4using Utf8Json;
[454]5using Webserver;
6using Webserver.WebAPI;
[321]7
[454]8namespace AllocsFixes.WebAPIs {
[455]9 [UsedImplicitly]
[454]10 public class GetPlayerInventories : AbsWebAPI {
11 public override void HandleRequest (RequestContext _context) {
12 GetPlayerInventory.GetInventoryArguments (_context, out bool showIconColor, out bool showIconName);
[348]13
[455]14 JsonWriter writer = new JsonWriter ();
15
16 writer.WriteBeginArray ();
17
18 bool first = true;
[321]19
[369]20 foreach (KeyValuePair<PlatformUserIdentifierAbs, Player> kvp in PersistentContainer.Instance.Players.Dict) {
[332]21 Player p = kvp.Value;
[325]22
[321]23 if (p == null) {
24 continue;
25 }
[325]26
27 if (p.IsOnline) {
[455]28 if (!first) {
29 writer.WriteValueSeparator ();
30 }
31
32 first = false;
33
34 GetPlayerInventory.DoPlayer (ref writer, p, showIconColor, showIconName);
[325]35 }
[321]36 }
[455]37
38 writer.WriteEndArray ();
39
40 WebUtils.WriteJsonData (_context.Response, ref writer);
[321]41 }
42 }
[325]43}
Note: See TracBrowser for help on using the repository browser.