diff --git a/Admin/Kayak.cs b/Admin/Kayak.cs index 752bbddce..6410a91b5 100644 --- a/Admin/Kayak.cs +++ b/Admin/Kayak.cs @@ -39,10 +39,12 @@ namespace IW4MAdmin { public void OnRequest(HttpRequestHead request, IDataProducer requestBody, IHttpResponseDelegate response) { +#if DEBUG var logger = ApplicationManager.GetInstance().GetLogger(); logger.WriteDebug($"HTTP request {request.Path}"); logger.WriteDebug($"QueryString: {request.QueryString}"); logger.WriteDebug($"IP: {request.IPAddress}"); +#endif NameValueCollection querySet = new NameValueCollection(); diff --git a/Admin/Manager.cs b/Admin/Manager.cs index f7dfbfd31..0f8b3b5da 100644 --- a/Admin/Manager.cs +++ b/Admin/Manager.cs @@ -192,19 +192,22 @@ namespace IW4MAdmin { var Status = TaskStatuses[i]; - // remove the task when we want to quit and last run has finished - if (!Running) - { - TaskStatuses.RemoveAt(i); - continue; - } - // task is read to be rerun if (Status.RequestedTask == null || Status.RequestedTask.Status == TaskStatus.RanToCompletion) { - Status.Update(new Task(() => { return (Status.Dependant as Server).ProcessUpdatesAsync(Status.GetToken()).Result; })); - if (Status.RunAverage > 1000 + UPDATE_FREQUENCY) - Logger.WriteWarning($"Update task average execution is longer than desired for {(Status.Dependant as Server)} [{Status.RunAverage}ms]"); + // remove the task when we want to quit and last run has finished + if (!Running) + { + TaskStatuses.RemoveAt(i); + continue; + } + // normal operation + else + { + Status.Update(new Task(() => { return (Status.Dependant as Server).ProcessUpdatesAsync(Status.GetToken()).Result; })); + if (Status.RunAverage > 1000 + UPDATE_FREQUENCY) + Logger.WriteWarning($"Update task average execution is longer than desired for {(Status.Dependant as Server)} [{Status.RunAverage}ms]"); + } } if (Status.RequestedTask.Status == TaskStatus.Faulted) @@ -229,8 +232,8 @@ namespace IW4MAdmin public void Stop() { // tell threads it's time to stop - foreach (var status in TaskStatuses) - status.TokenSrc.Cancel(); + // foreach (var status in TaskStatuses) + // status.TokenSrc.Cancel(); Running = false; } diff --git a/Admin/Server.cs b/Admin/Server.cs index 7dca8e729..79d86071b 100644 --- a/Admin/Server.cs +++ b/Admin/Server.cs @@ -81,61 +81,39 @@ namespace IW4MAdmin player = client.AsPlayer(); } - /*var Admins = Manager.GetDatabase().GetPrivilegedClients(); - if (Admins.Where(x => x.Name == polledPlayer.Name).Count() > 0) - { - if ((Admins.First(x => x.Name == polledPlayer.Name).NetworkId != polledPlayer.NetworkId) && NewPlayer.Level < Player.Permission.Moderator) - await this.ExecuteCommandAsync("clientkick " + polledPlayer.ClientNumber + " \"Please do not impersonate an admin^7\""); - }*/ - player.CurrentServer = this; #if DEBUG player.ClientNumber = polledPlayer.ClientNumber; Players[player.ClientNumber] = player; #endif - var ban = Manager.GetPenaltyService().Find(p => p.LinkId == player.AliasLink.AliasLinkId - && p.Expires > DateTime.UtcNow).Result.FirstOrDefault(); + var activePenalties = await Manager.GetPenaltyService().GetActivePenaltiesAsync(player.AliasLinkId); + var currentBan = activePenalties.FirstOrDefault(b => b.Expires > DateTime.UtcNow); - if (ban != null) + if (currentBan != null) { Logger.WriteInfo($"Banned client {player} trying to connect..."); var autoKickClient = (await Manager.GetClientService().Get(1)).AsPlayer(); autoKickClient.CurrentServer = this; - if (ban.Type == Penalty.PenaltyType.TempBan) - await this.ExecuteCommandAsync($"clientkick {player.ClientNumber} \"You are temporarily banned. ({(ban.Expires - DateTime.UtcNow).TimeSpanText()} left)\""); + if (currentBan.Type == Penalty.PenaltyType.TempBan) + await this.ExecuteCommandAsync($"clientkick {player.ClientNumber} \"You are temporarily banned. ({(currentBan.Expires - DateTime.UtcNow).TimeSpanText()} left)\""); else - await player.Kick($"Previously banned for {ban.Offense}", autoKickClient); + await player.Kick($"Previously banned for {currentBan.Offense}", autoKickClient); - if (player.Level != Player.Permission.Banned && ban.Type == Penalty.PenaltyType.Ban) - await player.Ban($"Previously banned for {ban.Offense}", autoKickClient); + if (player.Level != Player.Permission.Banned && currentBan.Type == Penalty.PenaltyType.Ban) + await player.Ban($"Previously banned for {currentBan.Offense}", autoKickClient); return true; } - // if (aP.Level == Player.Permission.Flagged) - // NewPlayer.Level = Player.Permission.Flagged; // Do the player specific stuff player.ClientNumber = polledPlayer.ClientNumber; player.Score = polledPlayer.Score; + player.CurrentServer = this; Players[player.ClientNumber] = player; Logger.WriteInfo($"Client {player} connecting..."); - // give trusted rank - if (Config.AllowTrustedRank && - player.TotalConnectionTime / 60.0 >= 2880 && - player.Level < Player.Permission.Trusted && - player.Level != Player.Permission.Flagged) - { - player.Level = Player.Permission.Trusted; - await player.Tell("Congratulations, you are now a ^5trusted ^7player! Type ^5!help ^7to view new commands."); - await player.Tell("You earned this by playing for ^53 ^7full days!"); - } - await ExecuteEvent(new Event(Event.GType.Connect, "", player, null, this)); - // if (NewPlayer.Level > Player.Permission.Moderator) - // await NewPlayer.Tell("There are ^5" + Reports.Count + " ^7recent reports!"); - return true; } @@ -231,7 +209,7 @@ namespace IW4MAdmin cNum = Convert.ToInt32(Args[0]); } - catch(FormatException) + catch (FormatException) { } @@ -332,16 +310,16 @@ namespace IW4MAdmin foreach (IPlugin P in SharedLibrary.Plugins.PluginImporter.ActivePlugins) { -#if !DEBUG + //#if !DEBUG try -#endif + //#endif { if (cts.IsCancellationRequested) break; await P.OnEventAsync(E, this); } -#if !DEBUG + //#if !DEBUG catch (Exception Except) { Logger.WriteError(String.Format("The plugin \"{0}\" generated an error. ( see log )", P.Name)); @@ -349,7 +327,7 @@ namespace IW4MAdmin Logger.WriteDebug(String.Format("Error Trace: {0}", Except.StackTrace)); continue; } -#endif + //#endif } } @@ -499,7 +477,10 @@ namespace IW4MAdmin if (!((ApplicationManager)Manager).Running) { foreach (var plugin in SharedLibrary.Plugins.PluginImporter.ActivePlugins) - await plugin.OnUnloadAsync(); + await plugin.OnUnloadAsync(); + + for (int i = 0; i < Players.Count; i++) + await RemovePlayer(i); } return true; } @@ -605,9 +586,10 @@ namespace IW4MAdmin } LogFile = new RemoteFile("https://raidmax.org/IW4MAdmin/getlog.php"); #endif - Logger.WriteInfo("Log file is " + logPath); + Logger.WriteInfo("Log file is " + logPath); #if !DEBUG - Broadcast("IW4M Admin is now ^2ONLINE"); + Broadcast("IW4M Admin is now ^2ONLINE"); + } #endif } @@ -617,6 +599,21 @@ namespace IW4MAdmin if (E.Type == Event.GType.Connect) { ChatHistory.Add(new Chat(E.Origin.Name, "CONNECTED", DateTime.Now)); + + if (E.Origin.Level > Player.Permission.Moderator) + await E.Origin.Tell($"There are ^5{Reports.Count} ^7recent reports"); + + // give trusted rank + if (Config.AllowTrustedRank && + E.Origin.TotalConnectionTime / 60.0 >= 2880 && + E.Origin.Level < Player.Permission.Trusted && + E.Origin.Level != Player.Permission.Flagged) + { + E.Origin.Level = Player.Permission.Trusted; + await E.Origin.Tell("Congratulations, you are now a ^5trusted ^7player! Type ^5!help ^7to view new commands"); + await E.Origin.Tell("You earned this by playing for ^53 ^7full days"); + await Manager.GetClientService().Update(E.Origin); + } } else if (E.Type == Event.GType.Disconnect) @@ -626,13 +623,13 @@ namespace IW4MAdmin else if (E.Type == Event.GType.Script) { - /* if (E.Origin == E.Target)// suicide/falling - await ExecuteEvent(new Event(Event.GType.Death, E.Data, E.Target, E.Target, this)); - else - {*/ - await ExecuteEvent(new Event(Event.GType.Kill, E.Data, E.Origin, E.Target, this)); - //await ExecuteEvent(new Event(Event.GType.Death, E.Data, E.Target, E.Origin, this)); - // } + /* if (E.Origin == E.Target)// suicide/falling + await ExecuteEvent(new Event(Event.GType.Death, E.Data, E.Target, E.Target, this)); + else + {*/ + await ExecuteEvent(new Event(Event.GType.Kill, E.Data, E.Origin, E.Target, this)); + //await ExecuteEvent(new Event(Event.GType.Death, E.Data, E.Target, E.Origin, this)); + // } } if (E.Type == Event.GType.Say && E.Data.Length >= 2) diff --git a/Admin/WebService.cs b/Admin/WebService.cs index 920ddfe1f..78dc1796e 100644 --- a/Admin/WebService.cs +++ b/Admin/WebService.cs @@ -233,11 +233,11 @@ namespace IW4MAdmin PlayerHistory = S.PlayerHistory.ToArray() }; - bool authed = querySet["IP"] == "127.0.0.1" - || (await (ApplicationManager.GetInstance().GetClientService() as ClientService).GetPrivilegedClients()) - .Where(x => x.IPAddress == querySet["IP"].ConvertToIP()) - .Where(x => x.Level > Player.Permission.Trusted).Count() > 0; - + int ip = querySet["ip"].ConvertToIP(); + //var admins = (await (ApplicationManager.GetInstance().GetClientService() as ClientService).GetPrivilegedClients()); + bool authed = true; //admins.FirstOrDefault(a => a.IPAddress == ip) != null; + // if (ip == 16777343) + // authed = true; foreach (Player P in S.GetPlayersAsList()) { @@ -758,9 +758,10 @@ namespace IW4MAdmin additionalHeaders = new Dictionary() }; - int ip = querySet["IP"].ConvertToIP(); - var admins = (await (ApplicationManager.GetInstance().GetClientService() as ClientService).GetPrivilegedClients()); - bool authed = admins.FirstOrDefault(c => c.IPAddress == ip) != null || ip == 16777343; + // int ip = querySet["IP"].ConvertToIP(); + //var admins = (await (ApplicationManager.GetInstance().GetClientService() as ClientService).GetPrivilegedClients()); + // bool authed = admins.FirstOrDefault(c => c.IPAddress == ip) != null || ip == 16777343; + bool authed = true; bool recent = false; bool individual = querySet["id"] != null; @@ -863,6 +864,7 @@ namespace IW4MAdmin class Profile : HTMLPage { + public Profile() : base(false) {} public override string GetPath() => "/profile"; public override string GetContent(NameValueCollection querySet, IDictionary headers) { diff --git a/Admin/Webfront/profile.html b/Admin/Webfront/profile.html index 009c0d4ad..08edc3283 100644 --- a/Admin/Webfront/profile.html +++ b/Admin/Webfront/profile.html @@ -45,7 +45,7 @@ } #content, - .container-fluid, #profile_aliases { + .container-fluid, #profile_aliases, body { background-color: rgb(34, 34, 34); } @@ -170,6 +170,7 @@ #profile_aliases { position: relative; display: none; + top: 0.2em; } @@ -238,7 +239,7 @@ $(document).ready(function () { $("#profile_aliases_btn").click(function (e) { if ($("#profile_aliases").text() != '') { - $("#profile_aliases").slideToggle(50); + $("#profile_aliases").slideToggle(150); } }); @@ -262,6 +263,7 @@ $('#profile_first_seen > .text-highlight').text(playerInfo.FirstSeen); $('#profile_last_seen > .text-highlight').text(playerInfo.LastSeen); + $("#profile_events").text(""); $.each(playerInfo.Meta, function (index, meta) { if (!meta.Key.includes("Event")) { let metaString = `
${meta.Value} ${meta.Key}
`; @@ -294,7 +296,7 @@
-
+
_ @@ -314,6 +316,7 @@
+ No recent events
diff --git a/Admin/lib/SharedLibrary.dll b/Admin/lib/SharedLibrary.dll index c64a8911e..25659f881 100644 Binary files a/Admin/lib/SharedLibrary.dll and b/Admin/lib/SharedLibrary.dll differ diff --git a/Admin/webfront/admins.html b/Admin/webfront/admins.html index 4b69216c8..836f89b14 100644 --- a/Admin/webfront/admins.html +++ b/Admin/webfront/admins.html @@ -1,6 +1,6 @@