diff --git a/Admin/Kayak.cs b/Admin/Kayak.cs index d5a2ec2a1..17116a83a 100644 --- a/Admin/Kayak.cs +++ b/Admin/Kayak.cs @@ -54,6 +54,7 @@ namespace IW4MAdmin if (requestedPage.content != null && requestedPage.content.GetType() != typeof(string)) requestedPage.content = Newtonsoft.Json.JsonConvert.SerializeObject(requestedPage.content); + string maxAge = requestedPage.contentType == "application/json" ? "0" : "31536000"; var headers = new HttpResponseHead() { Status = "200 OK", @@ -62,6 +63,7 @@ namespace IW4MAdmin { "Content-Type", requestedPage.contentType }, { "Content-Length", binaryContent ? requestedPage.BinaryContent.Length.ToString() : requestedPage.content.ToString().Length.ToString() }, { "Access-Control-Allow-Origin", "*" }, + { "Cache-Control", $"public,max-age={maxAge}"} } }; diff --git a/Admin/Manager.cs b/Admin/Manager.cs index db688a796..eeeb9e74b 100644 --- a/Admin/Manager.cs +++ b/Admin/Manager.cs @@ -15,7 +15,8 @@ namespace IW4MAdmin { class ApplicationManager : IManager { - public List Servers { get; private set; } + private List _servers; + public List Servers => _servers.OrderByDescending(s => s.ClientNum).ToList(); public ILogger Logger { get; private set; } public bool Running { get; private set; } @@ -38,7 +39,7 @@ namespace IW4MAdmin private ApplicationManager() { Logger = new Logger("Logs/IW4MAdmin.log"); - Servers = new List(); + _servers = new List(); Commands = new List(); TaskStatuses = new List(); MessageTokens = new List(); @@ -113,9 +114,9 @@ namespace IW4MAdmin var ServerInstance = new IW4MServer(this, Conf); await ServerInstance.Initialize(); - lock (Servers) + lock (_servers) { - Servers.Add(ServerInstance); + _servers.Add(ServerInstance); } Logger.WriteVerbose($"Now monitoring {ServerInstance.Hostname}"); @@ -210,7 +211,7 @@ namespace IW4MAdmin foreach (var S in Servers) S.Broadcast("^1IW4MAdmin going offline!"); #endif - Servers.Clear(); + _servers.Clear(); WebThread.Abort(); webServiceTask.Stop(); } @@ -250,7 +251,7 @@ namespace IW4MAdmin { var ActiveClients = new List(); - foreach (var server in Servers) + foreach (var server in _servers) ActiveClients.AddRange(server.Players.Where(p => p != null)); return ActiveClients; diff --git a/Admin/WebService.cs b/Admin/WebService.cs index 796cb06d5..aa4dcf5dd 100644 --- a/Admin/WebService.cs +++ b/Admin/WebService.cs @@ -206,8 +206,6 @@ namespace IW4MAdmin public HttpResponse GetPage(System.Collections.Specialized.NameValueCollection querySet, IDictionary headers) { var info = new List(); - - int i = 0; foreach (Server S in ApplicationManager.GetInstance().Servers) { ServerInfo eachServer = new ServerInfo() @@ -220,11 +218,9 @@ namespace IW4MAdmin currentPlayers = S.GetPlayersAsList().Count, chatHistory = S.ChatHistory, players = new List(), - ID = i + PlayerHistory = S.PlayerHistory.ToArray() }; - i++; - bool authed = ApplicationManager.GetInstance().GetPrivilegedClients() .Where(x => x.IP == querySet["IP"]) .Where(x => x.Level > Player.Permission.Trusted).Count() > 0 @@ -253,7 +249,7 @@ namespace IW4MAdmin return resp; } - public string GetContentType() + public string GetContentType() { return "application/json"; } @@ -701,26 +697,18 @@ namespace IW4MAdmin public HttpResponse GetPage(System.Collections.Specialized.NameValueCollection querySet, IDictionary headers) { - List pages = new List(); - - foreach (var p in SharedLibrary.WebService.PageList.Where(x => x.Visible())) + + var pages = SharedLibrary.WebService.PageList.Select(p => new { - if (p == this) - continue; - - PageInfo pi = new PageInfo() - { - pagePath = p.GetPath(), - pageName = p.GetName(), - visible = p.Visible() - }; - pages.Add(pi); - } + pagePath = p.GetPath(), + pageName = p.GetName(), + visible = p.Visible(), + }); HttpResponse resp = new HttpResponse() { contentType = GetContentType(), - content = Newtonsoft.Json.JsonConvert.SerializeObject(pages), + content = Newtonsoft.Json.JsonConvert.SerializeObject(pages.ToArray()), additionalHeaders = new Dictionary() }; return resp; @@ -846,6 +834,7 @@ namespace IW4MAdmin public int maxPlayers; public List chatHistory; public List players; + public SharedLibrary.Helpers.PlayerHistory[] PlayerHistory; public int ID; } diff --git a/Admin/lib/SharedLibrary.dll b/Admin/lib/SharedLibrary.dll index 0cc1ad4cd..4c5f4fbb0 100644 Binary files a/Admin/lib/SharedLibrary.dll and b/Admin/lib/SharedLibrary.dll differ diff --git a/Admin/webfront/footer.html b/Admin/webfront/footer.html index 97e7c71f6..80a785395 100644 --- a/Admin/webfront/footer.html +++ b/Admin/webfront/footer.html @@ -1,6 +1,7 @@ + diff --git a/Admin/webfront/header.html b/Admin/webfront/header.html index aca2ff546..59a6316f2 100644 --- a/Admin/webfront/header.html +++ b/Admin/webfront/header.html @@ -7,7 +7,6 @@ - diff --git a/Admin/webfront/main.html b/Admin/webfront/main.html index cc58c003b..10b86989d 100644 --- a/Admin/webfront/main.html +++ b/Admin/webfront/main.html @@ -1,101 +1,99 @@ +
diff --git a/Admin/webfront/stats.html b/Admin/webfront/stats.html index e2ae0b6b0..55601c308 100644 --- a/Admin/webfront/stats.html +++ b/Admin/webfront/stats.html @@ -7,6 +7,7 @@ diff --git a/Plugins/SimpleStats/Plugin.cs b/Plugins/SimpleStats/Plugin.cs index aac033d36..860b8378d 100644 --- a/Plugins/SimpleStats/Plugin.cs +++ b/Plugins/SimpleStats/Plugin.cs @@ -268,7 +268,7 @@ namespace StatsPlugin CalculateAndSaveSkill(P, statLists.Find(x => x.Port == S.GetPort())); ResetCounters(P.ClientID, S.GetPort()); - E.Owner.Logger.WriteInfo("Updated skill for client #" + P.DatabaseID); + E.Owner.Logger.WriteInfo($"Updated skill for {P}"); //E.Owner.Log.Write(String.Format("\r\nJoin: {0}\r\nInactive Minutes: {1}\r\nnewPlayTime: {2}\r\nnewSPM: {3}\r\nkdrWeight: {4}\r\nMultiplier: {5}\r\nscoreWeight: {6}\r\nnewSkillFactor: {7}\r\nprojectedNewSkill: {8}\r\nKills: {9}\r\nDeaths: {10}", connectionTime[P.clientID].ToShortTimeString(), inactiveMinutes[P.clientID], newPlayTime, newSPM, kdrWeight, Multiplier, scoreWeight, newSkillFactor, disconnectStats.Skill, disconnectStats.Kills, disconnectStats.Deaths)); } } @@ -311,6 +311,7 @@ namespace StatsPlugin ServerStats[S.GetPort()].GetKillQueue().Enqueue(killEvent); //S.Logger.WriteInfo($"{E.Origin.Name} killed {E.Target.Name} with a {killEvent.Weapon} from a distance of {Vector3.Distance(killEvent.KillOrigin, killEvent.DeathOrigin)} with {killEvent.Damage} damage, at {killEvent.HitLoc}"); curServer.playerStats.AddKill(killEvent); + S.Logger.WriteInfo(killEvent.ID.ToString()); return; } @@ -521,10 +522,10 @@ namespace StatsPlugin return resultList; } - public List GetKillsByMap(Map map) + public List GetKillsByMap(Map map, int count) { var mapID = ParseEnum.Get(map.Name, typeof(IW4Info.MapName)); - var queryResult = GetDataTable($"select * from KILLS where MapID == {(int)mapID} LIMIT 500 OFFSET (SELECT COUNT(*) FROM KILLS)-500"); //GetDataTable("KILLS", new KeyValuePair("MapID", mapID)); + var queryResult = GetDataTable($"select * from KILLS where MapID == {(int)mapID} LIMIT {count} OFFSET (SELECT COUNT(*) FROM KILLS)-500"); //GetDataTable("KILLS", new KeyValuePair("MapID", mapID)); var resultList = new List(); if (queryResult?.Rows.Count > 0) diff --git a/Plugins/SimpleStats/StatsPage.cs b/Plugins/SimpleStats/StatsPage.cs index ea65daca5..b7f4aab96 100644 --- a/Plugins/SimpleStats/StatsPage.cs +++ b/Plugins/SimpleStats/StatsPage.cs @@ -55,8 +55,9 @@ namespace StatsPlugin ServerMap = s.CurrentMap.Alias, ServerInfo = Stats.ServerStats[s.GetPort()], Minimap = MinimapConfig.Read(@"Config\minimaps.cfg").MapInfo.Where(m => m.MapName == s.CurrentMap.Name), - MapKills = Stats.ServerStats[s.GetPort()].GetKillQueue().ToArray() - .Skip(Math.Min(Stats.MAX_KILLEVENTS - selectCount, Stats.ServerStats[s.GetPort()].GetKillQueue().Count - selectCount)) + MapKills = selectCount < 300 ? Stats.ServerStats[s.GetPort()].GetKillQueue().ToArray() + .Skip(Math.Min(Stats.MAX_KILLEVENTS - selectCount, Stats.ServerStats[s.GetPort()].GetKillQueue().Count - selectCount)) : + Stats.statLists.FirstOrDefault(x => x.Port == s.GetPort()).playerStats.GetKillsByMap(s.CurrentMap, selectCount) }) }, additionalHeaders = new Dictionary() diff --git a/Plugins/Tests/Plugin.cs b/Plugins/Tests/Plugin.cs index b2755abb9..5cf4818fa 100644 --- a/Plugins/Tests/Plugin.cs +++ b/Plugins/Tests/Plugin.cs @@ -74,14 +74,17 @@ namespace IW4MAdmin.Plugins string[] eventLine = null; - if (S.GameName == Server.Game.IW4) + for (int i = 0; i < 1; i++) { - // attackerID ; victimID ; attackerOrigin ; victimOrigin ; Damage ; Weapon ; hitLocation ; meansOfDeath - var minimapInfo = StatsPlugin.MinimapConfig.IW4Minimaps().MapInfo.FirstOrDefault(m => m.MapName == S.CurrentMap.Name); - if (minimapInfo == null) - return; - eventLine = new string[] + if (S.GameName == Server.Game.IW4) { + + // attackerID ; victimID ; attackerOrigin ; victimOrigin ; Damage ; Weapon ; hitLocation ; meansOfDeath + var minimapInfo = StatsPlugin.MinimapConfig.IW4Minimaps().MapInfo.FirstOrDefault(m => m.MapName == S.CurrentMap.Name); + if (minimapInfo == null) + return; + eventLine = new string[] + { "ScriptKill", attackerPlayer.NetworkID, victimPlayer.NetworkID, @@ -91,13 +94,13 @@ namespace IW4MAdmin.Plugins ((StatsPlugin.IW4Info.WeaponName)rand.Next(0, Enum.GetValues(typeof(StatsPlugin.IW4Info.WeaponName)).Length - 1)).ToString(), ((StatsPlugin.IW4Info.HitLocation)rand.Next(0, Enum.GetValues(typeof(StatsPlugin.IW4Info.HitLocation)).Length - 1)).ToString(), ((StatsPlugin.IW4Info.MeansOfDeath)rand.Next(0, Enum.GetValues(typeof(StatsPlugin.IW4Info.MeansOfDeath)).Length - 1)).ToString() - }; - } + }; - else - { - eventLine = new string[] - { + } + else + { + eventLine = new string[] + { "K", victimPlayer.NetworkID, victimPlayer.ClientID.ToString(), @@ -111,11 +114,12 @@ namespace IW4MAdmin.Plugins rand.Next(50, 105).ToString(), // Damage ((StatsPlugin.IW4Info.MeansOfDeath)rand.Next(0, Enum.GetValues(typeof(StatsPlugin.IW4Info.MeansOfDeath)).Length - 1)).ToString(), // Means of Death ((StatsPlugin.IW4Info.HitLocation)rand.Next(0, Enum.GetValues(typeof(StatsPlugin.IW4Info.HitLocation)).Length - 1)).ToString(), // Hit Location - }; - } + }; + } - var _event = Event.ParseEventString(eventLine, S); - await S.ExecuteEvent(_event); + var _event = Event.ParseEventString(eventLine, S); + await S.ExecuteEvent(_event); + } } }