source: binary-improvements/MapRendering/Web/Handlers/UserStatusHandler.cs@ 317

Last change on this file since 317 was 309, checked in by alloc, 7 years ago

Fixes 14_16_21

File size: 1.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Net;
5using System.Threading;
6using System.Text;
7using AllocsFixes.JSON;
8
9namespace AllocsFixes.NetConnections.Servers.Web.Handlers
10{
11 public class UserStatusHandler : PathHandler {
12 public UserStatusHandler (string moduleName = null) : base(moduleName) {
13 }
14
15 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) {
16 JSONObject result = new JSONObject ();
17
18 result.Add ("loggedin", new JSONBoolean (user != null));
19 result.Add ("username", new JSONString (user != null ? user.SteamID.ToString () : string.Empty));
20
21 JSONArray perms = new JSONArray ();
22 foreach (WebPermissions.WebModulePermission perm in WebPermissions.Instance.GetModules ()) {
23 JSONObject permObj = new JSONObject ();
24 permObj.Add ("module", new JSONString (perm.module));
25 permObj.Add ("allowed", new JSONBoolean (WebPermissions.Instance.ModuleAllowedWithLevel (perm.module, permissionLevel)));
26 perms.Add (permObj);
27 }
28 result.Add ("permissions", perms);
29
30 AllocsFixes.NetConnections.Servers.Web.API.WebAPI.WriteJSON (resp, result);
31 }
32
33 }
34
35}
36
Note: See TracBrowser for help on using the repository browser.