Changeset 251 for binary-improvements/MapRendering
- Timestamp:
- Oct 28, 2015, 7:51:20 PM (9 years ago)
- Location:
- binary-improvements/MapRendering
- Files:
-
- 4 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Web/API/GetLandClaims.cs
r245 r251 11 11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 12 12 { 13 string steamid = string.Empty; 13 string ViewersSteamID = string.Empty; 14 ulong lViewersSteamID = 0L; 14 15 15 16 if (req.QueryString ["steamid"] != null) { 16 long tempLong; 17 steamid = req.QueryString ["steamid"]; 18 if (steamid.Length != 17 || !long.TryParse (steamid, out tempLong)) { 17 ViewersSteamID = req.QueryString ["steamid"]; 18 if (ViewersSteamID.Length != 17 || !ulong.TryParse (ViewersSteamID, out lViewersSteamID)) { 19 19 resp.StatusCode = (int)HttpStatusCode.BadRequest; 20 20 Web.SetResponseTextContent (resp, "Invalid SteamID given"); … … 23 23 } 24 24 25 // default user, cheap way to avoid 'null reference exception' 26 try { user = user ?? new WebConnection ("", "", 0L); } catch { } 27 28 bool bViewAll = false; try { bViewAll = user.CanViewAllClaims (permissionLevel); } catch { } 29 25 30 JSONObject result = new JSONObject (); 26 31 result.Add ("claimsize", new JSONNumber (GamePrefs.GetInt (EnumGamePrefs.LandClaimSize))); … … 33 38 World w = GameManager.Instance.World; 34 39 Dictionary<PersistentPlayerData, List<Vector3i>> owners = new Dictionary<PersistentPlayerData, List<Vector3i>> (); 40 41 // Add all owners to this temporary list regardless of permissions 35 42 foreach (KeyValuePair<Vector3i, PersistentPlayerData> kvp in d) { 36 if ( steamid.Length == 0 || kvp.Value.PlayerId.Equals (steamid)) {43 if (kvp.Value.PlayerId.Equals (ViewersSteamID)) { 37 44 if (!owners.ContainsKey (kvp.Value)) { 38 45 owners.Add (kvp.Value, new List<Vector3i> ()); … … 42 49 } 43 50 51 // Loop through all claim owners... 44 52 foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) { 45 if (steamid.Length == 0 || kvp.Key.PlayerId.Equals (steamid)) { 46 string curID = kvp.Key.PlayerId; 47 bool isActive = w.IsLandProtectionValidForPlayer (kvp.Key); 53 try 54 { 55 // ... but only show us claims that are from the current web user or if the current web user can see all claims regardless of ownership 56 if (kvp.Key.PlayerId.Equals (ViewersSteamID) || bViewAll) 57 { 58 string currentSteamID = kvp.Key.PlayerId; 59 bool isActive = w.IsLandProtectionValidForPlayer (kvp.Key); 48 60 49 50 61 JSONObject owner = new JSONObject (); 62 claimOwners.Add (owner); 51 63 52 owner.Add ("steamid", new JSONString (curID));53 owner.Add("claimactive", new JSONBoolean (isActive));64 owner.Add("steamid", new JSONString (currentSteamID)); 65 owner.Add("claimactive", new JSONBoolean (isActive)); 54 66 55 if (PersistentContainer.Instance.Players [curID, false] != null) {56 owner.Add ("playername", new JSONString (PersistentContainer.Instance.Players [curID, false].Name));57 58 owner.Add("playername", new JSONNull ());59 67 if (PersistentContainer.Instance.Players [currentSteamID, false] != null) { 68 owner.Add("playername", new JSONString (PersistentContainer.Instance.Players [currentSteamID, false].Name)); 69 } else { 70 owner.Add("playername", new JSONNull ()); 71 } 60 72 61 62 73 JSONArray claims = new JSONArray (); 74 owner.Add ("claims", claims); 63 75 64 65 66 67 68 76 foreach (Vector3i v in kvp.Value) { 77 JSONObject claim = new JSONObject (); 78 claim.Add ("x", new JSONNumber (v.x)); 79 claim.Add ("y", new JSONNumber (v.y)); 80 claim.Add ("z", new JSONNumber (v.z)); 69 81 70 claims.Add (claim); 71 } 72 } 82 claims.Add (claim); 83 } 84 } 85 } 86 catch { } 73 87 } 74 88 } -
binary-improvements/MapRendering/Web/API/GetPlayerInventory.cs
r250 r251 75 75 JSONObject jsonItem = new JSONObject (); 76 76 jsonItem.Add ("count", new JSONNumber (_item.count)); 77 jsonItem.Add ("name", new JSONString (_item.itemName)); 78 jsonItem.Add ("quality", new JSONNumber (_item.quality)); 77 jsonItem.Add ("name", new JSONString (_item.itemName)); 78 jsonItem.Add ("icon", new JSONString (_item.icon)); 79 jsonItem.Add ("iconcolor", new JSONString ((string.IsNullOrEmpty (_item.iconcolor) || _item.iconcolor == "FFFFFF" ? "" : _item.iconcolor))); 80 jsonItem.Add ("quality", new JSONNumber(_item.quality)); 79 81 if (_item.quality >= 0) { 80 82 jsonItem.Add ("qualitycolor", new JSONString (QualityInfo.GetQualityColorHex (_item.quality))); -
binary-improvements/MapRendering/Web/API/GetPlayersLocation.cs
r244 r251 11 11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 12 12 { 13 JSONArray playersJsResult = new JSONArray (); 13 AdminTools admTools = null; 14 15 try { admTools = GameManager.Instance.adminTools; } catch { } 16 try { user = user ?? new WebConnection ("", "", 0L); } catch { } // default user, cheap way to avoid 'null reference exception' 17 18 bool bViewAll = false; try { bViewAll = user.CanViewAllPlayers (permissionLevel); } catch { } 19 20 JSONArray playersJsResult = new JSONArray (); 14 21 15 22 Players playersList = PersistentContainer.Instance.Players; 16 23 17 24 foreach (string sid in playersList.SteamIDs) { 18 Player p = playersList[sid, false]; 25 try { 26 if ((admTools != null) && (PetesUtils.ValidText (sid))) 27 if (admTools.IsBanned (sid)) 28 continue; 29 } 30 catch { } 19 31 20 JSONObject pos = new JSONObject(); 21 pos.Add("x", new JSONNumber(p.LastPosition.x)); 22 pos.Add("y", new JSONNumber(p.LastPosition.y)); 23 pos.Add("z", new JSONNumber(p.LastPosition.z)); 32 try 33 { 34 Player p = playersList [sid, false]; 24 35 25 JSONObject pJson = new JSONObject(); 26 pJson.Add("steamid", new JSONString(sid)); 27 pJson.Add("ip", new JSONString(p.IP)); 28 pJson.Add("name", new JSONString(p.Name)); 29 pJson.Add("online", new JSONBoolean(p.IsOnline)); 30 pJson.Add("position", pos); 36 ulong player_steam_ID = 0L; 37 if (!ulong.TryParse (sid, out player_steam_ID)) 38 player_steam_ID = 0L; 31 39 32 playersJsResult.Add(pJson); 33 } 40 if ((player_steam_ID == user.SteamID) || bViewAll) { 41 JSONObject pos = new JSONObject (); 42 pos.Add("x", new JSONNumber (p.LastPosition.x)); 43 pos.Add("y", new JSONNumber (p.LastPosition.y)); 44 pos.Add("z", new JSONNumber (p.LastPosition.z)); 34 45 35 WriteJSON(resp, playersJsResult); 46 JSONObject pJson = new JSONObject (); 47 pJson.Add("steamid", new JSONString (sid)); 48 pJson.Add("ip", new JSONString (p.IP)); 49 pJson.Add("name", new JSONString (p.Name)); 50 pJson.Add("online", new JSONBoolean (p.IsOnline)); 51 pJson.Add("position", pos); 52 53 playersJsResult.Add (pJson); 54 } 55 } 56 catch { } 57 } 58 59 WriteJSON (resp, playersJsResult); 36 60 } 37 61 } -
binary-improvements/MapRendering/Web/API/GetStats.cs
r245 r251 1 1 using AllocsFixes.JSON; 2 using AllocsFixes.LiveData; 2 3 using AllocsFixes.PersistentData; 3 4 using System; … … 20 21 21 22 result.Add ("players", new JSONNumber (GameManager.Instance.World.Players.Count)); 23 result.Add ("hostiles", new JSONNumber (Hostiles.Count)); 24 result.Add ("animals", new JSONNumber (Animals.Count)); 22 25 23 26 WriteJSON (resp, result); -
binary-improvements/MapRendering/Web/API/GetWebUIUpdates.cs
r250 r251 1 1 using AllocsFixes.JSON; 2 using AllocsFixes.LiveData; 2 3 using AllocsFixes.PersistentData; 3 4 using System; … … 23 24 24 25 result.Add ("players", new JSONNumber (GameManager.Instance.World.Players.Count)); 26 result.Add ("hostiles", new JSONNumber (Hostiles.Count)); 27 result.Add ("animals", new JSONNumber (Animals.Count)); 25 28 26 29 result.Add ("newlogs", new JSONNumber (LogBuffer.Instance.LatestLine - latestLine)); -
binary-improvements/MapRendering/Web/Handlers/ApiHandler.cs
r250 r251 13 13 private Dictionary<String, WebAPI> apis = new Dictionary<string, WebAPI> (); 14 14 15 public ApiHandler (string staticPart, string moduleName = null) : base (moduleName) {15 public ApiHandler (string staticPart, string moduleName = null) : base (moduleName) { 16 16 this.staticPart = staticPart; 17 17 18 18 foreach (Type t in Assembly.GetExecutingAssembly ().GetTypes ()) { 19 19 if (!t.IsAbstract && t.IsSubclassOf (typeof(WebAPI))) { 20 ConstructorInfo ctor = t.GetConstructor (new Type [0]);20 ConstructorInfo ctor = t.GetConstructor (new Type [0]); 21 21 if (ctor != null) { 22 WebAPI apiInstance = (WebAPI)ctor.Invoke (new object [0]);22 WebAPI apiInstance = (WebAPI)ctor.Invoke (new object [0]); 23 23 addApi (t.Name.ToLower (), apiInstance); 24 24 } 25 25 } 26 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 } 27 38 } 28 39 -
binary-improvements/MapRendering/Web/Handlers/ItemIconHandler.cs
r244 r251 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.IO;4 3 using System.Net; 5 4 using System.Threading; … … 13 12 private string staticPart; 14 13 private bool logMissingFiles; 15 16 14 private Dictionary<string, byte[]> icons = new Dictionary<string, byte[]> (); 15 private bool loaded = false; 17 16 18 17 public ItemIconHandler (string staticPart, bool logMissingFiles, string moduleName = null) : base(moduleName) { … … 30 29 } 31 30 32 string fn = req.Url.AbsolutePath.Remove (0, staticPart.Length); 33 fn = fn.Remove (fn.LastIndexOf ('.')); 31 // BEGIN CHANGED BY PSOUZA4 32 string requestFileName = req.Url.AbsolutePath.Remove (0, staticPart.Length); 33 requestFileName = requestFileName.Remove (requestFileName.LastIndexOf ('.')); 34 34 35 if (icons.ContainsKey (fn)) { 35 string requestColorTintHex = string.Empty; 36 37 // Chose a split instead of using a querystring variable in the URI, but that may arguably be cleaner 38 if (requestFileName.Contains("@@")) { 39 try { 40 string[] tempTintingOptions = requestFileName.Split (new string[] { "@@" }, StringSplitOptions.RemoveEmptyEntries); 41 requestFileName = tempTintingOptions [0]; 42 requestColorTintHex = tempTintingOptions [1].Trim ().ToUpper (); 43 } 44 catch { } 45 } 46 47 if (icons.ContainsKey (requestFileName) && req.Url.AbsolutePath.ToLower ().EndsWith(".png")) { 36 48 resp.ContentType = MimeType.GetMimeType (".png"); 37 resp.ContentLength64 = icons [fn].Length; 38 resp.OutputStream.Write (icons [fn], 0, icons [fn].Length); 49 50 byte[] itemIconData = icons [requestFileName]; 51 52 // Note: optionally split this code into a ImageMultiplyBlend method 53 if (!string.IsNullOrEmpty (requestColorTintHex) && (requestColorTintHex != "FFFFFF")) { 54 try { 55 System.Drawing.Color colorTint = System.Drawing.ColorTranslator.FromHtml ("#" + requestColorTintHex); 56 System.Drawing.Bitmap image = (System.Drawing.Bitmap)PetesUtils.GetImageFromBytes (itemIconData); 57 58 for (var x = 0; x < image.Width; x++) { 59 for (int y = 0; y < image.Height; y++) { 60 System.Drawing.Color originalColor = image.GetPixel (x, y); 61 System.Drawing.Color changedColor = originalColor; 62 63 // Only change the icon tinting if the alpha channel is fully opaque 64 if (originalColor.A == 255) { 65 // based on http://stackoverflow.com/questions/3837757/multiply-two-images-in-c-sharp-as-multiply-two-layers-in-photoshop 66 67 double component_R = (((double)originalColor.R) * ((double)colorTint.R)) / 255.0; 68 double component_G = (((double)originalColor.G) * ((double)colorTint.G)) / 255.0; 69 double component_B = (((double)originalColor.B) * ((double)colorTint.B)) / 255.0; 70 71 if (component_R > 255.0) component_R = 255.0; 72 if (component_G > 255.0) component_G = 255.0; 73 if (component_B > 255.0) component_B = 255.0; 74 75 // multiply blend shouldn't ever calculate below 0, but for completeness let's leave in this logic 76 if (component_R < 0.0) component_R = 0.0; 77 if (component_G < 0.0) component_G = 0.0; 78 if (component_B < 0.0) component_B = 0.0; 79 80 changedColor = System.Drawing.Color.FromArgb (originalColor.A, (int)component_R, (int)component_G, (int)component_B); 81 } 82 83 image.SetPixel (x, y, changedColor); 84 } 85 } 86 87 itemIconData = PetesUtils.SaveImage_ToBytes (image, true); 88 } 89 catch { } 90 } 91 92 resp.ContentLength64 = itemIconData.Length; 93 resp.OutputStream.Write (itemIconData, 0, itemIconData.Length); 94 // END CHANGED BY PSOUZA4 39 95 } else { 40 96 resp.StatusCode = (int)HttpStatusCode.NotFound; -
binary-improvements/MapRendering/Web/Handlers/StaticHandler.cs
r244 r251 27 27 28 28 byte[] content = cache.GetFileContent (datapath + "/" + fn); 29 29 30 if (content != null) { 30 31 resp.ContentType = MimeType.GetMimeType (Path.GetExtension (fn)); -
binary-improvements/MapRendering/Web/WebConnection.cs
r250 r251 1 1 using System; 2 2 using System.Collections.Generic; 3 3 using AllocsFixes.NetConnections.Servers.Web; 4 4 using UnityEngine; 5 5 … … 29 29 get { return DateTime.Now - lastAction; } 30 30 } 31 32 public bool CanViewAllPlayers (int _permissionLevel) { 33 bool val = false; 34 35 try { 36 const int defaultPermissionLevel = 0; 37 38 val = _permissionLevel <= defaultPermissionLevel; 39 40 foreach (WebPermissions.WebModulePermission wap in WebPermissions.Instance.GetModules ()) 41 if (wap.module.Trim ().ToLower () == "webapi.viewallplayers") 42 val = _permissionLevel <= wap.permissionLevel; 43 } 44 catch { } 45 46 return val; 47 } 48 49 public bool CanViewAllClaims (int _permissionLevel) { 50 bool val = false; 51 52 try { 53 const int defaultPermissionLevel = 0; 54 55 val = _permissionLevel <= defaultPermissionLevel; 56 57 foreach (WebPermissions.WebModulePermission wap in WebPermissions.Instance.GetModules ()) 58 if (wap.module.Trim ().ToLower () == "webapi.viewallclaims") 59 val = _permissionLevel <= wap.permissionLevel; 60 } 61 catch { } 62 63 return val; 64 } 31 65 32 66 public WebConnection (string _sessionId, string _endpoint, ulong _steamId) { -
binary-improvements/MapRendering/Web/WebPermissions.cs
r244 r251 99 99 if (!string.IsNullOrEmpty (_module)) { 100 100 lock (this) { 101 knownModules.Add (_module, new WebModulePermission (_module, 0)); 101 if (!IsKnownModule( _module)) { 102 knownModules.Add (_module, new WebModulePermission (_module, 0)); 103 } 102 104 } 103 105 } … … 269 271 270 272 using (StreamWriter sw = new StreamWriter(GetFullPath ())) { 271 sw.WriteLine ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); 272 sw.WriteLine ("<webpermissions>"); 273 sw.WriteLine (" <admintokens>"); 274 sw.WriteLine (" <!-- <token name=\"adminuser1\" token=\"supersecrettoken\" permission_level=\"0\" /> -->"); 275 foreach (AdminToken at in admintokens.Values) { 276 sw.WriteLine (string.Format (" <token name=\"{0}\" token=\"{1}\" permission_level=\"{2}\" />", at.name, at.token, at.permissionLevel)); 277 } 278 sw.WriteLine (" </admintokens>"); 279 sw.WriteLine (); 280 sw.WriteLine (" <permissions>"); 281 sw.WriteLine (" <!-- <permission module=\"webapi.executeconsolecommand\" permission_level=\"0\" /> -->"); 282 sw.WriteLine (" <!-- <permission module=\"webapi.getplayersonline\" permission_level=\"1\" /> -->"); 283 sw.WriteLine (" <!-- <permission module=\"web.map\" permission_level=\"1000\" /> -->"); 284 foreach (WebModulePermission wap in modules.Values) { 285 sw.WriteLine (string.Format (" <permission module=\"{0}\" permission_level=\"{1}\" />", wap.module, wap.permissionLevel)); 286 } 287 sw.WriteLine (" </permissions>"); 288 sw.WriteLine (); 289 sw.WriteLine ("</webpermissions>"); 290 273 sw.WriteLine ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); 274 sw.WriteLine ("<webpermissions>"); 275 sw.WriteLine (); 276 sw.WriteLine (" <admintokens>"); 277 sw.WriteLine (" <!-- <token name=\"adminuser1\" token=\"supersecrettoken\" permission_level=\"0\" /> -->"); 278 foreach (AdminToken at in admintokens.Values) { 279 sw.WriteLine (string.Format (" <token name=\"{0}\" token=\"{1}\" permission_level=\"{2}\" />", at.name, at.token, at.permissionLevel)); 280 } 281 sw.WriteLine (" </admintokens>"); 282 sw.WriteLine (); 283 sw.WriteLine (" <permissions>"); 284 foreach (WebModulePermission wap in modules.Values) { 285 sw.WriteLine (string.Format (" <permission module=\"{0}\" permission_level=\"{1}\" />", wap.module, wap.permissionLevel)); 286 } 287 sw.WriteLine (" <!-- <permission module=\"web.map\" permission_level=\"1000\" /> -->"); 288 sw.WriteLine (); 289 sw.WriteLine (" <!-- <permission module=\"webapi.getlog\" permission_level=\"0\" /> -->"); 290 sw.WriteLine (" <!-- <permission module=\"webapi.executeconsolecommand\" permission_level=\"0\" /> -->"); 291 sw.WriteLine (); 292 sw.WriteLine (" <!-- <permission module=\"webapi.getstats\" permission_level=\"1000\" /> -->"); 293 sw.WriteLine (" <!-- <permission module=\"webapi.getplayersonline\" permission_level=\"1000\" /> -->"); 294 sw.WriteLine (); 295 sw.WriteLine (" <!-- <permission module=\"webapi.getplayerslocation\" permission_level=\"1000\" /> -->"); 296 sw.WriteLine (" <!-- <permission module=\"webapi.viewallplayers\" permission_level=\"1\" /> -->"); 297 sw.WriteLine (); 298 sw.WriteLine (" <!-- <permission module=\"webapi.getlandclaims\" permission_level=\"1000\" /> -->"); 299 sw.WriteLine (" <!-- <permission module=\"webapi.viewallclaims\" permission_level=\"1\" /> -->"); 300 sw.WriteLine (); 301 sw.WriteLine (" <!-- <permission module=\"webapi.getplayerinventory\" permission_level=\"1\" /> -->"); 302 sw.WriteLine (); 303 sw.WriteLine (" <!-- <permission module=\"webapi.gethostilelocation\" permission_level=\"1\" /> -->"); 304 sw.WriteLine (" <!-- <permission module=\"webapi.getanimalslocation\" permission_level=\"1\" /> -->"); 305 sw.WriteLine (" </permissions>"); 306 sw.WriteLine (); 307 sw.WriteLine ("</webpermissions>"); 308 291 309 sw.Flush (); 292 310 sw.Close (); -
binary-improvements/MapRendering/WebAndMapRendering.csproj
r250 r251 1 <?xml version="1.0" encoding="utf-8"?>1 <?xml version="1.0" encoding="utf-8"?> 2 2 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 3 3 <PropertyGroup> … … 21 21 </PropertyGroup> 22 22 <ItemGroup> 23 <Reference Include="System" /> 23 <Reference Include="System"> 24 <HintPath>..\7dtd-binaries\System.dll</HintPath> 25 <Private>False</Private> 26 </Reference> 27 <Reference Include="System.Drawing"> 28 <HintPath>..\7dtd-binaries\System.Drawing.dll</HintPath> 29 <Private>False</Private> 30 </Reference> 24 31 <Reference Include="LogLibrary"> 25 32 <HintPath>..\7dtd-binaries\LogLibrary.dll</HintPath> … … 51 58 <Compile Include="Commands\EnableRendering.cs" /> 52 59 <Compile Include="API.cs" /> 60 <Compile Include="Web\API\GetAnimalsLocation.cs" /> 61 <Compile Include="Web\API\GetRawEntitiesList.cs" /> 62 <Compile Include="Web\API\GetHostileLocation.cs" /> 63 <Compile Include="Web\API\Null.cs" /> 53 64 <Compile Include="Web\Web.cs" /> 54 65 <Compile Include="Web\MimeType.cs" /> … … 87 98 </ProjectReference> 88 99 </ItemGroup> 89 <ItemGroup> 90 <Folder Include="Commands\" /> 91 <Folder Include="Web\Handlers\" /> 92 </ItemGroup> 100 <ItemGroup /> 93 101 <ItemGroup> 94 102 <None Include="ModInfo.xml">
Note:
See TracChangeset
for help on using the changeset viewer.