From 164f121d2296f6ed13c9c9728b5b78c59802da05 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Sat, 7 Apr 2018 14:49:00 -0500 Subject: [PATCH] rcon command formatted to work in linux fixes to work with mono --- Plugins/SimpleStats/Plugin.cs | 1 - SharedLibrary/PluginImporter.cs | 2 +- SharedLibrary/RCon/Connection.cs | 3 +- SharedLibrary/Server.cs | 1 - WebfrontCore/Application/Server.cs | 72 +++++------------------------- WebfrontCore/Program.cs | 14 ++++-- WebfrontCore/Startup.cs | 5 +-- WebfrontCore/WebfrontCore.csproj | 3 ++ WebfrontCore/appsettings.json | 2 +- 9 files changed, 30 insertions(+), 73 deletions(-) diff --git a/Plugins/SimpleStats/Plugin.cs b/Plugins/SimpleStats/Plugin.cs index 270262ba..1999aea4 100644 --- a/Plugins/SimpleStats/Plugin.cs +++ b/Plugins/SimpleStats/Plugin.cs @@ -230,7 +230,6 @@ namespace StatsPlugin MetaService.AddMeta(getMessages); - // todo: is this fast? make async? string totalKills() { var serverStats = new GenericRepository(); diff --git a/SharedLibrary/PluginImporter.cs b/SharedLibrary/PluginImporter.cs index 2f6ec717..74daa3d3 100644 --- a/SharedLibrary/PluginImporter.cs +++ b/SharedLibrary/PluginImporter.cs @@ -13,7 +13,7 @@ namespace SharedLibrary.Plugins public static bool Load(IManager Manager) { - string[] dllFileNames = Directory.GetFiles(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\plugins", "*.dll"); + string[] dllFileNames = Directory.GetFiles($"{Utilities.OperatingDirectory}Plugins{Path.DirectorySeparatorChar}", "*.dll"); if (dllFileNames.Length == 0) { diff --git a/SharedLibrary/RCon/Connection.cs b/SharedLibrary/RCon/Connection.cs index 54e9fc9b..2008953e 100644 --- a/SharedLibrary/RCon/Connection.cs +++ b/SharedLibrary/RCon/Connection.cs @@ -1,6 +1,7 @@ using SharedLibrary.Exceptions; using SharedLibrary.Interfaces; using System; +using System.Linq; using System.Net; using System.Net.Sockets; using System.Text; @@ -180,7 +181,7 @@ namespace SharedLibrary.RCon break; } - byte[] payload = Encoding.Default.GetBytes(queryString); + byte[] payload = queryString.Select(Convert.ToByte).ToArray(); retrySend: try diff --git a/SharedLibrary/Server.cs b/SharedLibrary/Server.cs index 05c4ff6a..7665a4e1 100644 --- a/SharedLibrary/Server.cs +++ b/SharedLibrary/Server.cs @@ -258,7 +258,6 @@ namespace SharedLibrary /// /// Initialize the messages to be broadcasted - /// todo: this needs to be a serialized file /// protected void InitializeAutoMessages() { diff --git a/WebfrontCore/Application/Server.cs b/WebfrontCore/Application/Server.cs index 8d1f17b5..1e5906a7 100644 --- a/WebfrontCore/Application/Server.cs +++ b/WebfrontCore/Application/Server.cs @@ -625,10 +625,6 @@ namespace IW4MAdmin await this.SetDvarAsync("sv_kickbantime", 60); - // I don't think this belongs in an admin tool - /*await this.SetDvarAsync("sv_network_fps", 1000); - await this.SetDvarAsync("com_maxfps", 1000);*/ - if (logsync.Value == 0 || logfile.Value == string.Empty) { // this DVAR isn't set until the a map is loaded @@ -641,14 +637,7 @@ namespace IW4MAdmin } CustomCallback = await ScriptLoaded(); -#if DEBUG - { - basepath.Value = (GameName == Game.IW4) ? - @"D:\" : - @"\\tsclient\G\Program Files (x86)\Steam\SteamApps\common\Call of Duty 4"; - } -#endif string mainPath = (GameName == Game.IW4 && onelog.Value >= 0) ? "userraw" : "main"; // patch for T5M:V2 log path mainPath = (GameName == Game.T5M) ? "rzodemo" : mainPath; @@ -657,6 +646,12 @@ namespace IW4MAdmin $"{basepath.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{mainPath}{Path.DirectorySeparatorChar}{logfile.Value}" : $"{basepath.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{game.Value.Replace('/', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{logfile.Value}"; + // fix to prevent wine drive prefix when running in mono + if (Utilities.IsRunningOnMono()) + { + logPath = Regex.Replace(logPath, @"[A-Z]:", ""); + } + if (!File.Exists(logPath)) { Logger.WriteError($"Gamelog {logPath} does not exist!"); @@ -666,15 +661,13 @@ namespace IW4MAdmin } else { - //#if !DEBUG LogFile = new IFile(logPath); - //#else } + + Logger.WriteInfo($"Log file is {logPath}"); #if DEBUG //LogFile = new RemoteFile("https://raidmax.org/IW4MAdmin/getlog.php"); -#endif - Logger.WriteInfo($"Log file is {logPath}"); -#if !DEBUG +#else await Broadcast("IW4M Admin is now ^2ONLINE"); #endif } @@ -693,18 +686,6 @@ namespace IW4MAdmin if (E.Origin.Level > Player.Permission.Moderator) await E.Origin.Tell($"There are ^5{Reports.Count} ^7recent reports"); - - /*// give trusted rank - if (Manager.GetApplicationSettings().Configuration().EnableSteppedHierarchy && - 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) @@ -786,39 +767,6 @@ namespace IW4MAdmin string mapname = this.GetDvarAsync("mapname").Result.Value; CurrentMap = Maps.Find(m => m.Name == mapname) ?? new Map() { Alias = mapname, Name = mapname }; - - // todo: make this more efficient - /*((ApplicationManager)(Manager)).PrivilegedClients = new Dictionary(); - var ClientSvc = new ClientService(); - var ipList = (await ClientSvc.Find(c => c.Level > Player.Permission.Trusted)) - .Select(c => new - { - c.Password, - c.PasswordSalt, - c.ClientId, - c.Level, - c.Name - }); - - foreach (var a in ipList) - { - try - { - ((ApplicationManager)(Manager)).PrivilegedClients.Add(a.ClientId, new Player() - { - Name = a.Name, - ClientId = a.ClientId, - Level = a.Level, - PasswordSalt = a.PasswordSalt, - Password = a.Password - }); - } - - catch (ArgumentException) - { - continue; - } - }*/ } if (E.Type == Event.GType.MapEnd) @@ -975,7 +923,7 @@ namespace IW4MAdmin Target.Level = Player.Permission.Banned; #if !DEBUG await Target.CurrentServer.ExecuteCommandAsync($"clientkick {Target.ClientNumber} \"Player Banned: ^5{Message} ^7(appeal at {Website}) ^7\""); -#else +#else await Target.CurrentServer.RemovePlayer(Target.ClientNumber); #endif } diff --git a/WebfrontCore/Program.cs b/WebfrontCore/Program.cs index 4b889bd6..88ff0ae5 100644 --- a/WebfrontCore/Program.cs +++ b/WebfrontCore/Program.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; @@ -15,12 +16,19 @@ namespace WebfrontCore var host = new WebHostBuilder() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) - .UseIISIntegration() .UseStartup() .UseUrls(config["Web:Address"]) .Build(); - host.Run(); + if (!SharedLibrary.Utilities.IsRunningOnMono()) + { + host.Run(); + } + + else + { + Console.ReadLine(); + } } } } diff --git a/WebfrontCore/Startup.cs b/WebfrontCore/Startup.cs index 7222c87b..57968f54 100644 --- a/WebfrontCore/Startup.cs +++ b/WebfrontCore/Startup.cs @@ -17,7 +17,6 @@ namespace WebfrontCore .AddJsonFile("appsettings.json", optional: true, reloadOnChange: false) .AddEnvironmentVariables(); - Configuration = builder.Build(); // fixme: this is really really terrible if (!SharedLibrary.Utilities.IsRunningOnMono()) @@ -63,11 +62,11 @@ namespace WebfrontCore app.UseCookieAuthentication(new CookieAuthenticationOptions() { - AccessDeniedPath = "/Account/Login/", + AccessDeniedPath = "/", AuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme, AutomaticAuthenticate = true, AutomaticChallenge = true, - LoginPath = "/Account/Login/", + LoginPath = "/", ExpireTimeSpan = TimeSpan.FromDays(30), }); diff --git a/WebfrontCore/WebfrontCore.csproj b/WebfrontCore/WebfrontCore.csproj index c5c437ef..977bf2a0 100644 --- a/WebfrontCore/WebfrontCore.csproj +++ b/WebfrontCore/WebfrontCore.csproj @@ -85,6 +85,9 @@ + + PreserveNewest + PreserveNewest diff --git a/WebfrontCore/appsettings.json b/WebfrontCore/appsettings.json index 282edf0c..1e422f4f 100644 --- a/WebfrontCore/appsettings.json +++ b/WebfrontCore/appsettings.json @@ -12,6 +12,6 @@ }, "ConnectionStrings": { "WindowsConnection": "Data Source=|DataDirectory|\\Database.sdf", - "LinuxConnection": "server=server;user=user;database=db;password=pass" + "LinuxConnection": "Server=127.0.0.1;User=user;Database=IW4MAdmin;Password=password" } }