source: TFP-WebServer/WebServer/src/WebAPI/APIs/ServerState/ServerInfo.cs@ 457

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

Refactored APIs GamePrefs, GameStats, ServerInfo: Using arrays as result instead of objects, code sharing

File size: 1.3 KB
Line 
1using System.Collections.Generic;
2using JetBrains.Annotations;
3using Utf8Json;
4using Webserver.Permissions;
5
6namespace Webserver.WebAPI.APIs.ServerState {
7 [UsedImplicitly]
8 public class ServerInfo : KeyValueListAbs {
9 public ServerInfo () : base ("ServerInfo") {
10 }
11
12 protected override void iterateList (ref JsonWriter _writer, ref bool _first) {
13 GameServerInfo gsi = ConnectionManager.Instance.LocalServerInfo;
14
15 IList<GameInfoString> list = EnumUtils.Values<GameInfoString> ();
16 for (int i = 0; i < list.Count; i++) {
17 GameInfoString stringGamePref = list [i];
18 addItem (ref _writer, ref _first, stringGamePref.ToStringCached (), gsi.GetValue (stringGamePref));
19 }
20
21 IList<GameInfoInt> ints = EnumUtils.Values<GameInfoInt> ();
22 for (int i = 0; i < ints.Count; i++) {
23 GameInfoInt intGamePref = ints [i];
24 addItem (ref _writer, ref _first, intGamePref.ToStringCached (), gsi.GetValue (intGamePref));
25 }
26
27 IList<GameInfoBool> prefs = EnumUtils.Values<GameInfoBool> ();
28 for (int i = 0; i < prefs.Count; i++) {
29 GameInfoBool boolGamePref = prefs [i];
30 addItem (ref _writer, ref _first, boolGamePref.ToStringCached (), gsi.GetValue (boolGamePref));
31 }
32 }
33
34 public override int DefaultPermissionLevel () => AdminWebModules.PermissionLevelGuest;
35 }
36}
Note: See TracBrowser for help on using the repository browser.