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