source: binary-improvements/MapRendering/Web/Handlers/ApiHandler.cs@ 277

Last change on this file since 277 was 251, checked in by peter.souza, 10 years ago

Enemies (zombies and hostile animal entities) are now shown on the map as Hostiles and require permission level 'webapi.gethostilelocation' for web viewers to see.

Animals (non-hostile entities) are now shown on the map as Animals and require permission level 'webapi.getanimalslocation' for web viewers to see.

Permission level for 'webapi.viewallclaims' is now required for a viewer to see all claims, otherwise the permission level for 'webapi.getlandclaims' will only show viewer-owned claims. A viewer requires both 'webapi.getlandclaims' and 'webapi.viewallclaims' to be set for all claims to show (you can't just set 'webapi.viewallclaims').
https://7daystodie.com/forums/showthread.php?12837-Improvements-for-the-dedicated-server&p=317405&viewfull=1#post317405

Permission level for 'webapi.viewallplayers' is now required for a viewer to see all players, otherwise the permission level for 'webapi.getplayerslocation' will only show the player for the currently-authenticated viewer. A viewer requires both 'webapi.getplayerslocation' and 'webapi.viewallplayers' to be set for all players to show (you can't just set 'webapi.viewallplayers').
https://7daystodie.com/forums/showthread.php?12837-Improvements-for-the-dedicated-server&p=317405&viewfull=1#post317405

Banned players are now hidden from the web map.
https://7daystodie.com/forums/showthread.php?12837-Improvements-for-the-dedicated-server&p=320702&viewfull=1#post320702

Items using 'CustomIcon' and 'CustomIconTint' are now supported (although the exact tinting may not be perfectly the same as the game).
https://7daystodie.com/forums/showthread.php?12837-Improvements-for-the-dedicated-server&p=317117&viewfull=1#post317117
https://7daystodie.com/forums/showthread.php?12837-Improvements-for-the-dedicated-server&p=317679&viewfull=1#post317679

Map marker icons for players, hostiles, and animals have been updated.

File size: 2.9 KB
Line 
1using AllocsFixes.NetConnections.Servers.Web.API;
2using System;
3using System.Collections.Generic;
4using System.IO;
5using System.Net;
6using System.Reflection;
7using System.Threading;
8
9namespace AllocsFixes.NetConnections.Servers.Web.Handlers
10{
11 public class ApiHandler : PathHandler {
12 private string staticPart;
13 private Dictionary<String, WebAPI> apis = new Dictionary<string, WebAPI> ();
14
15 public ApiHandler (string staticPart, string moduleName = null) : base (moduleName) {
16 this.staticPart = staticPart;
17
18 foreach (Type t in Assembly.GetExecutingAssembly ().GetTypes ()) {
19 if (!t.IsAbstract && t.IsSubclassOf (typeof(WebAPI))) {
20 ConstructorInfo ctor = t.GetConstructor (new Type [0]);
21 if (ctor != null) {
22 WebAPI apiInstance = (WebAPI)ctor.Invoke (new object [0]);
23 addApi (t.Name.ToLower (), apiInstance);
24 }
25 }
26 }
27
28 // Add dummy types
29 Type dummy_t = typeof (API.Null);
30 ConstructorInfo dummy_ctor = dummy_t.GetConstructor (new Type [0]);
31 if (dummy_ctor != null) {
32 WebAPI dummy_apiInstance = (WebAPI)dummy_ctor.Invoke (new object[0]);
33
34 // Permissions that don't map to a real API
35 addApi("viewallclaims", dummy_apiInstance);
36 addApi("viewallplayers", dummy_apiInstance);
37 }
38 }
39
40 private void addApi (string _apiName, WebAPI _api) {
41 apis.Add (_apiName, _api);
42 WebPermissions.Instance.AddKnownModule ("webapi." + _apiName);
43 }
44
45 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) {
46 string apiName = req.Url.AbsolutePath.Remove (0, staticPart.Length);
47 if (!AuthorizeForCommand (apiName, user, permissionLevel)) {
48 resp.StatusCode = (int)HttpStatusCode.Forbidden;
49 if (user != null) {
50 //Log.Out ("ApiHandler: user '{0}' not allowed to execute '{1}'", user.SteamID, apiName);
51 } else {
52 //Log.Out ("ApiHandler: unidentified user from '{0}' not allowed to execute '{1}'", req.RemoteEndPoint.Address, apiName);
53 }
54 return;
55 } else {
56 foreach (KeyValuePair<string, WebAPI> kvp in apis) {
57 if (apiName.StartsWith (kvp.Key)) {
58 try {
59 kvp.Value.HandleRequest (req, resp, user, permissionLevel);
60 return;
61 } catch (Exception e) {
62 Log.Error ("Error in ApiHandler.HandleRequest(): Handler {0} threw an exception:", kvp.Key);
63 Log.Exception (e);
64 resp.StatusCode = (int)HttpStatusCode.InternalServerError;
65 return;
66 }
67 }
68 }
69 }
70
71 Log.Out ("Error in ApiHandler.HandleRequest(): No handler found for API \"" + apiName + "\"");
72 resp.StatusCode = (int)HttpStatusCode.NotFound;
73 }
74
75 private bool AuthorizeForCommand (string apiName, WebConnection user, int permissionLevel) {
76 return WebPermissions.Instance.ModuleAllowedWithLevel ("webapi." + apiName, permissionLevel);
77 }
78
79 }
80
81}
82
Note: See TracBrowser for help on using the repository browser.