diff --git a/Application/Application.csproj b/Application/Application.csproj index a795dc8d7..d51fa7f89 100644 --- a/Application/Application.csproj +++ b/Application/Application.csproj @@ -1,8 +1,9 @@ - + Exe netcoreapp2.0 + false RaidMax.IW4MAdmin.Application 2.0.0 RaidMax @@ -15,6 +16,7 @@ https://github.com/RaidMax/IW4M-Admin https://raidmax.org/IW4MAdmin/img/iw4adminicon-3.png + IW4MAdmin @@ -43,7 +45,7 @@ - + diff --git a/Application/BuildScripts/PostBuild.bat b/Application/BuildScripts/PostBuild.bat index 33c48a91f..88a048f9c 100644 --- a/Application/BuildScripts/PostBuild.bat +++ b/Application/BuildScripts/PostBuild.bat @@ -3,7 +3,7 @@ set ProjectDir=%2 set TargetDir=%3 set OutDir=%4 -echo "Copying dependency configs" +echo Copying dependency configs copy "%SolutionDir%WebfrontCore\%OutDir%*.deps.json" "%TargetDir%" copy "%SolutionDir%SharedLibaryCore\%OutDir%*.deps.json" "%TargetDir%" @@ -12,4 +12,7 @@ if not exist "%TargetDir%Plugins" ( md "%TargetDir%Plugins" ) -xcopy /y "%SolutionDir%Build\Plugins" "%TargetDir%Plugins\" \ No newline at end of file +xcopy /y "%SolutionDir%Build\Plugins" "%TargetDir%Plugins\" + +echo Copying plugins for publish +xcopy /Y "%SolutionDir%BUILD\Plugins" "%SolutionDir%Publish\Windows\Plugins\" diff --git a/Application/BuildScripts/PostPublish.bat b/Application/BuildScripts/PostPublish.bat index c171f9dde..93db844e1 100644 --- a/Application/BuildScripts/PostPublish.bat +++ b/Application/BuildScripts/PostPublish.bat @@ -1,5 +1 @@ set SolutionDir=%1 - -;echo "Copying files for publish" -;xcopy /Y "%SolutionDir%WebfrontCore\Views" "%SolutionDir%Publish\Windows\Views\" -;xcopy /Y "%SolutionDir%WebfrontCore\wwwroot" "%SolutionDir%Publish\Windows\wwwroot\" diff --git a/Application/Main.cs b/Application/Main.cs index ac2ac05cc..1d2b3a3da 100644 --- a/Application/Main.cs +++ b/Application/Main.cs @@ -1,11 +1,12 @@ - -using System; -using SharedLibraryCore; +using System; using System.Threading.Tasks; using System.IO; -using SharedLibraryCore.Objects; using System.Reflection; +using SharedLibraryCore; +using SharedLibraryCore.Objects; +using SharedLibraryCore.Database; + namespace IW4MAdmin.Application { public class Program @@ -29,6 +30,9 @@ namespace IW4MAdmin.Application try { + using (var db = new DatabaseContext()) + new ContextSeed(db).Seed().Wait(); + CheckDirectories(); ServerManager = ApplicationManager.GetInstance(); @@ -66,7 +70,7 @@ namespace IW4MAdmin.Application catch (Exception e) { Console.WriteLine($"Fatal Error during initialization: {e.Message}"); - while(e.InnerException != null) + while (e.InnerException != null) { e = e.InnerException; Console.WriteLine($"Inner exception: {e.Message}"); diff --git a/Application/Server.cs b/Application/Server.cs index db1917f29..4a2cb7cc5 100644 --- a/Application/Server.cs +++ b/Application/Server.cs @@ -9,7 +9,6 @@ using System.Text.RegularExpressions; using SharedLibraryCore; using SharedLibraryCore.Interfaces; using SharedLibraryCore.Objects; -using SharedLibraryCore.Services; using SharedLibraryCore.Database.Models; using SharedLibraryCore.Dtos; using SharedLibraryCore.Configuration; @@ -95,7 +94,9 @@ namespace IW4MAdmin // client has connected in the past else { + player.LastConnection = DateTime.UtcNow; client.Connections += 1; + var existingAlias = client.AliasLink.Children .FirstOrDefault(a => a.Name == polledPlayer.Name && a.IPAddress == polledPlayer.IPAddress); @@ -641,17 +642,13 @@ namespace IW4MAdmin string mainPath = (GameName == Game.IW4 && onelog.Value >= 0) ? "userraw" : "main"; // patch for T5M:V2 log path mainPath = (GameName == Game.T5M) ? "rzodemo" : mainPath; + // patch for T6M:PLUTONIUM + mainPath = (GameName == Game.T6M) ? "t6r/data" : mainPath; string logPath = (game.Value == "" || onelog?.Value == 1) ? $"{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!"); @@ -964,7 +961,7 @@ namespace IW4MAdmin override public void InitializeTokens() { Manager.GetMessageTokens().Add(new SharedLibraryCore.Helpers.MessageToken("TOTALPLAYERS", Manager.GetClientService().GetTotalClientsAsync().Result.ToString)); - Manager.GetMessageTokens().Add(new SharedLibraryCore.Helpers.MessageToken("VERSION", IW4MAdmin.Application.Program.Version.ToString)); + Manager.GetMessageTokens().Add(new SharedLibraryCore.Helpers.MessageToken("VERSION", Application.Program.Version.ToString)); } } } diff --git a/IW4MAdmin.sln b/IW4MAdmin.sln index 2480e6a8c..46cfb152f 100644 --- a/IW4MAdmin.sln +++ b/IW4MAdmin.sln @@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.26730.16 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WelcomePlugin", "Plugins\Welcome\WelcomePlugin.csproj", "{AF097E6B-48D5-4452-9CCF-0A81A21F341D}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugins", "Plugins", "{26E8B310-269E-46D4-A612-24601F16065F}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8C8F3945-0AEF-4949-A1F7-B18E952E50BC}" @@ -26,6 +24,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Application", "Application\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stats", "Plugins\Stats\Stats.csproj", "{98BE4A81-8AFD-4957-83F7-009D353C6BCB}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Welcome", "Plugins\Welcome\Welcome.csproj", "{179140D3-97AA-4CB4-8BF6-A0C73CA75701}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -38,22 +38,6 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {AF097E6B-48D5-4452-9CCF-0A81A21F341D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AF097E6B-48D5-4452-9CCF-0A81A21F341D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AF097E6B-48D5-4452-9CCF-0A81A21F341D}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 - {AF097E6B-48D5-4452-9CCF-0A81A21F341D}.Debug|Mixed Platforms.Build.0 = Debug|x86 - {AF097E6B-48D5-4452-9CCF-0A81A21F341D}.Debug|x64.ActiveCfg = Debug|x64 - {AF097E6B-48D5-4452-9CCF-0A81A21F341D}.Debug|x64.Build.0 = Debug|x64 - {AF097E6B-48D5-4452-9CCF-0A81A21F341D}.Debug|x86.ActiveCfg = Debug|x86 - {AF097E6B-48D5-4452-9CCF-0A81A21F341D}.Debug|x86.Build.0 = Debug|x86 - {AF097E6B-48D5-4452-9CCF-0A81A21F341D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AF097E6B-48D5-4452-9CCF-0A81A21F341D}.Release|Any CPU.Build.0 = Release|Any CPU - {AF097E6B-48D5-4452-9CCF-0A81A21F341D}.Release|Mixed Platforms.ActiveCfg = Release-Stable|x86 - {AF097E6B-48D5-4452-9CCF-0A81A21F341D}.Release|Mixed Platforms.Build.0 = Release-Stable|x86 - {AF097E6B-48D5-4452-9CCF-0A81A21F341D}.Release|x64.ActiveCfg = Release|x64 - {AF097E6B-48D5-4452-9CCF-0A81A21F341D}.Release|x64.Build.0 = Release|x64 - {AF097E6B-48D5-4452-9CCF-0A81A21F341D}.Release|x86.ActiveCfg = Release|x86 - {AF097E6B-48D5-4452-9CCF-0A81A21F341D}.Release|x86.Build.0 = Release|x86 {B8C2A759-8663-4F6F-9BA4-19595F5E12C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B8C2A759-8663-4F6F-9BA4-19595F5E12C1}.Debug|Any CPU.Build.0 = Debug|Any CPU {B8C2A759-8663-4F6F-9BA4-19595F5E12C1}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU @@ -150,15 +134,31 @@ Global {98BE4A81-8AFD-4957-83F7-009D353C6BCB}.Release|x64.Build.0 = Release|Any CPU {98BE4A81-8AFD-4957-83F7-009D353C6BCB}.Release|x86.ActiveCfg = Release|Any CPU {98BE4A81-8AFD-4957-83F7-009D353C6BCB}.Release|x86.Build.0 = Release|Any CPU + {179140D3-97AA-4CB4-8BF6-A0C73CA75701}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {179140D3-97AA-4CB4-8BF6-A0C73CA75701}.Debug|Any CPU.Build.0 = Debug|Any CPU + {179140D3-97AA-4CB4-8BF6-A0C73CA75701}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {179140D3-97AA-4CB4-8BF6-A0C73CA75701}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {179140D3-97AA-4CB4-8BF6-A0C73CA75701}.Debug|x64.ActiveCfg = Debug|Any CPU + {179140D3-97AA-4CB4-8BF6-A0C73CA75701}.Debug|x64.Build.0 = Debug|Any CPU + {179140D3-97AA-4CB4-8BF6-A0C73CA75701}.Debug|x86.ActiveCfg = Debug|Any CPU + {179140D3-97AA-4CB4-8BF6-A0C73CA75701}.Debug|x86.Build.0 = Debug|Any CPU + {179140D3-97AA-4CB4-8BF6-A0C73CA75701}.Release|Any CPU.ActiveCfg = Release|Any CPU + {179140D3-97AA-4CB4-8BF6-A0C73CA75701}.Release|Any CPU.Build.0 = Release|Any CPU + {179140D3-97AA-4CB4-8BF6-A0C73CA75701}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {179140D3-97AA-4CB4-8BF6-A0C73CA75701}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {179140D3-97AA-4CB4-8BF6-A0C73CA75701}.Release|x64.ActiveCfg = Release|Any CPU + {179140D3-97AA-4CB4-8BF6-A0C73CA75701}.Release|x64.Build.0 = Release|Any CPU + {179140D3-97AA-4CB4-8BF6-A0C73CA75701}.Release|x86.ActiveCfg = Release|Any CPU + {179140D3-97AA-4CB4-8BF6-A0C73CA75701}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {AF097E6B-48D5-4452-9CCF-0A81A21F341D} = {26E8B310-269E-46D4-A612-24601F16065F} {B8C2A759-8663-4F6F-9BA4-19595F5E12C1} = {26E8B310-269E-46D4-A612-24601F16065F} {3EA31029-C76F-4C8E-AFD4-79F77DEA7033} = {26E8B310-269E-46D4-A612-24601F16065F} {98BE4A81-8AFD-4957-83F7-009D353C6BCB} = {26E8B310-269E-46D4-A612-24601F16065F} + {179140D3-97AA-4CB4-8BF6-A0C73CA75701} = {26E8B310-269E-46D4-A612-24601F16065F} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {84F8F8E0-1F73-41E0-BD8D-BB6676E2EE87} diff --git a/Plugins/Stats/Models/EFClientStatistics.cs b/Plugins/Stats/Models/EFClientStatistics.cs index e27c826b9..8c114b399 100644 --- a/Plugins/Stats/Models/EFClientStatistics.cs +++ b/Plugins/Stats/Models/EFClientStatistics.cs @@ -12,11 +12,9 @@ namespace IW4MAdmin.Plugins.Stats.Models { public class EFClientStatistics : SharedEntity { - //[Key, Column(Order = 0)] public int ClientId { get; set; } [ForeignKey("ClientId")] public virtual EFClient Client { get; set; } - //[Key, Column(Order = 1)] public int ServerId { get; set; } [ForeignKey("ServerId")] public virtual EFServer Server { get; set; } diff --git a/Plugins/Stats/Models/EFHitLocationCount.cs b/Plugins/Stats/Models/EFHitLocationCount.cs index a6cb53ded..13495ea01 100644 --- a/Plugins/Stats/Models/EFHitLocationCount.cs +++ b/Plugins/Stats/Models/EFHitLocationCount.cs @@ -1,5 +1,6 @@ using SharedLibraryCore.Database.Models; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; namespace IW4MAdmin.Plugins.Stats.Models { @@ -13,5 +14,12 @@ namespace IW4MAdmin.Plugins.Stats.Models public int HitCount { get; set; } [Required] public float HitOffsetAverage { get; set; } + public int ClientId { get; set; } + [ForeignKey("ClientId"), Column(Order = 0 )] + public EFClient Client { get; set; } + public int ServerId { get; set; } + [ForeignKey("ServerId"), Column(Order = 1)] + public EFServer Server { get; set; } + } } diff --git a/Plugins/Stats/Models/ModelConfiguration.cs b/Plugins/Stats/Models/ModelConfiguration.cs index ad7e3d53b..45fbdae18 100644 --- a/Plugins/Stats/Models/ModelConfiguration.cs +++ b/Plugins/Stats/Models/ModelConfiguration.cs @@ -11,6 +11,23 @@ namespace Stats.Models { builder.Entity() .HasKey(cs => new { cs.ClientId, cs.ServerId }); + + // fix linking from SQLCe + builder.Entity() + .Property(c => c.ClientId) + .HasColumnName("EFClientStatistics_ClientId"); + + builder.Entity() + .Property(c => c.ServerId) + .HasColumnName("EFClientStatistics_ServerId"); + + // force pluralization + builder.Entity().ToTable("EFClientKills"); + builder.Entity().ToTable("EFClientMessages"); + builder.Entity().ToTable("EFClientStatistics"); + builder.Entity().ToTable("EFHitLocationCounts"); + builder.Entity().ToTable("EFServers"); + builder.Entity().ToTable("EFServerStatistics"); } } } diff --git a/Plugins/Stats/Stats.csproj b/Plugins/Stats/Stats.csproj index 522cd2053..927ca6841 100644 --- a/Plugins/Stats/Stats.csproj +++ b/Plugins/Stats/Stats.csproj @@ -17,8 +17,12 @@ + + + + - + diff --git a/Plugins/Welcome/GeoIP.dat b/Plugins/Welcome/GeoIP.dat deleted file mode 100644 index 9813562ce..000000000 Binary files a/Plugins/Welcome/GeoIP.dat and /dev/null differ diff --git a/Plugins/Welcome/CountryLookup.cs b/Plugins/Welcome/MaxMind/CountryLookup.cs similarity index 95% rename from Plugins/Welcome/CountryLookup.cs rename to Plugins/Welcome/MaxMind/CountryLookup.cs index 6fb653324..63e3d7220 100644 --- a/Plugins/Welcome/CountryLookup.cs +++ b/Plugins/Welcome/MaxMind/CountryLookup.cs @@ -17,9 +17,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +using SharedLibraryCore; using System; using System.IO; -using System.Data; using System.Net; @@ -59,24 +59,10 @@ namespace CountryLookupProj fileInput = new FileStream(fileName, FileMode.Open, FileAccess.Read); } - public string LookupCountryCode(string str) - { - IPAddress addr; - try - { - addr = IPAddress.Parse(str); - } - catch (FormatException) - { - return "--"; - } - return LookupCountryCode(addr); - } - private long AddrToNum(IPAddress addr) { long ipnum = 0; - byte[] b = BitConverter.GetBytes(addr.Address); + byte[] b = BitConverter.GetBytes((UInt32)addr.ToString().ConvertToIP()); for (int i = 0; i < 4; ++i) { long y = b[i]; diff --git a/Plugins/Welcome/MaxMind/GeoIP.dat b/Plugins/Welcome/MaxMind/GeoIP.dat new file mode 100644 index 000000000..be8b031f7 Binary files /dev/null and b/Plugins/Welcome/MaxMind/GeoIP.dat differ diff --git a/Plugins/Welcome/Plugin.cs b/Plugins/Welcome/Plugin.cs index 3debc33d1..c2241c9cd 100644 --- a/Plugins/Welcome/Plugin.cs +++ b/Plugins/Welcome/Plugin.cs @@ -1,12 +1,12 @@ using System; using System.Threading.Tasks; -using SharedLibrary; -using SharedLibrary.Interfaces; -using SharedLibrary.Objects; -using SharedLibrary.Configuration; +using SharedLibraryCore; +using SharedLibraryCore.Interfaces; +using SharedLibraryCore.Objects; +using SharedLibraryCore.Configuration; -namespace Welcome_Plugin +namespace IW4MAdmin.Plugins.Welcome { public class Plugin : IPlugin { @@ -45,12 +45,6 @@ namespace Welcome_Plugin return "fourth"; case 5: return "fifth"; - /* case 100: - return "One-Hundreth (amazing!)"; - case 500: - return "you're really ^5dedicated ^7to this server! This is your ^5500th^7"; - case 1000: - return "you deserve a medal. it's your ^11000th^7";*/ default: return connection.ToString() + Prefix; } @@ -108,7 +102,7 @@ namespace Welcome_Plugin catch (Exception) { - joining.CurrentServer.Manager.GetLogger().WriteError("Could not open file Plugins/GeoIP.dat for Welcome Plugin"); + joining.CurrentServer.Manager.GetLogger().WriteError("Could not open file Plugins\\GeoIP.dat for Welcome Plugin"); } msg = msg.Replace("{{TimesConnected}}", TimesConnected(joining)); diff --git a/Plugins/Welcome/Properties/AssemblyInfo.cs b/Plugins/Welcome/Properties/AssemblyInfo.cs deleted file mode 100644 index 60132458c..000000000 --- a/Plugins/Welcome/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Welcome Plugin")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Welcome Plugin")] -[assembly: AssemblyCopyright("Copyright © 2015")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("fd92be42-d165-449d-8648-fb1f6638b451")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Plugins/Welcome/Welcome.csproj b/Plugins/Welcome/Welcome.csproj new file mode 100644 index 000000000..690e8a343 --- /dev/null +++ b/Plugins/Welcome/Welcome.csproj @@ -0,0 +1,30 @@ + + + + Library + netcoreapp2.0 + + + RaidMax.IW4MAdmin.Plugins.Welcome + RaidMax + Forever None + Welcome Plugin for IW4MAdmin + Welcome plugin for IW4MAdmin welcomes clients to the server + 2018 + + + + + + + + + Never + + + + + + + + diff --git a/Plugins/Welcome/WelcomeConfiguration.cs b/Plugins/Welcome/WelcomeConfiguration.cs index bffaf3cbf..bc77486a0 100644 --- a/Plugins/Welcome/WelcomeConfiguration.cs +++ b/Plugins/Welcome/WelcomeConfiguration.cs @@ -1,11 +1,6 @@ -using SharedLibrary.Interfaces; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using SharedLibraryCore.Interfaces; -namespace Welcome_Plugin +namespace IW4MAdmin.Plugins.Welcome { class WelcomeConfiguration : IBaseConfiguration { diff --git a/Plugins/Welcome/WelcomePlugin.csproj b/Plugins/Welcome/WelcomePlugin.csproj deleted file mode 100644 index f389c702c..000000000 --- a/Plugins/Welcome/WelcomePlugin.csproj +++ /dev/null @@ -1,148 +0,0 @@ - - - - - Debug - AnyCPU - {AF097E6B-48D5-4452-9CCF-0A81A21F341D} - Library - Properties - Welcome_Plugin - WelcomePlugin - v4.5.2 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false - - - bin\Release-Stable\ - TRACE - true - pdbonly - AnyCPU - prompt - MinimumRecommendedRules.ruleset - - - x86 - bin\x86\Debug\ - TRACE;DEBUG - - - x86 - bin\x86\Release\ - true - - - x86 - bin\x86\Release-Stable\ - true - - - true - bin\x64\Debug\ - DEBUG;TRACE - full - x64 - prompt - MinimumRecommendedRules.ruleset - - - bin\x64\Release-Nightly\ - TRACE - true - pdbonly - x64 - prompt - MinimumRecommendedRules.ruleset - - - bin\x64\Release-Stable\ - TRACE - true - pdbonly - x64 - prompt - MinimumRecommendedRules.ruleset - - - bin\Release\ - TRACE - true - pdbonly - AnyCPU - prompt - MinimumRecommendedRules.ruleset - - - bin\x86\Release\ - true - x86 - MinimumRecommendedRules.ruleset - - - bin\x64\Release\ - TRACE - true - pdbonly - x64 - prompt - MinimumRecommendedRules.ruleset - - - - - - - - - - - - - - - - - - - - - - - {d51eeceb-438a-47da-870f-7d7b41bc24d6} - SharedLibrary - False - - - - - copy /Y "$(TargetDir)$(TargetName).dll" "$(SolutionDir)BUILD\plugins\$(TargetName).dll" -copy /Y "$(ProjectDir)GeoIP.dat" "$(SolutionDir)BUILD\plugins\GeoIP.dat" - - - \ No newline at end of file diff --git a/Plugins/Welcome/packages.config b/Plugins/Welcome/packages.config deleted file mode 100644 index 8a2091aab..000000000 --- a/Plugins/Welcome/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/SharedLibraryCore/Database/ContextSeed.cs b/SharedLibraryCore/Database/ContextSeed.cs index a1615db97..e46705536 100644 --- a/SharedLibraryCore/Database/ContextSeed.cs +++ b/SharedLibraryCore/Database/ContextSeed.cs @@ -17,6 +17,10 @@ namespace SharedLibraryCore.Database public async Task Seed() { + // make sure database exists + //context.Database.EnsureCreated(); + context.Database.Migrate(); + if (context.AliasLinks.Count() == 0) { context.AliasLinks.Add(new EFAliasLink() diff --git a/SharedLibraryCore/Database/DatabaseContext.cs b/SharedLibraryCore/Database/DatabaseContext.cs index 2a1a3cf36..85e9dc78b 100644 --- a/SharedLibraryCore/Database/DatabaseContext.cs +++ b/SharedLibraryCore/Database/DatabaseContext.cs @@ -63,6 +63,12 @@ namespace SharedLibraryCore.Database .OnDelete(DeleteBehavior.Restrict); }); + // force full name for database conversion + modelBuilder.Entity().ToTable("EFClients"); + modelBuilder.Entity().ToTable("EFAlias"); + modelBuilder.Entity().ToTable("EFAliasLinks"); + modelBuilder.Entity().ToTable("EFPenalties"); + // https://aleemkhan.wordpress.com/2013/02/28/dynamically-adding-dbset-properties-in-dbcontext-for-entity-framework-code-first/ #if !DEBUG foreach (string dllPath in Directory.GetFiles($"{Utilities.OperatingDirectory}Plugins")) diff --git a/SharedLibraryCore/Migrations/20180408213153_Initial Create.Designer.cs b/SharedLibraryCore/Migrations/20180409183408_InitialCreate.Designer.cs similarity index 90% rename from SharedLibraryCore/Migrations/20180408213153_Initial Create.Designer.cs rename to SharedLibraryCore/Migrations/20180409183408_InitialCreate.Designer.cs index 2465f20c6..4beb9d71b 100644 --- a/SharedLibraryCore/Migrations/20180408213153_Initial Create.Designer.cs +++ b/SharedLibraryCore/Migrations/20180409183408_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using System; namespace SharedLibraryCore.Migrations { [DbContext(typeof(DatabaseContext))] - [Migration("20180408213153_Initial Create")] + [Migration("20180409183408_InitialCreate")] partial class InitialCreate { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -66,7 +66,7 @@ namespace SharedLibraryCore.Migrations b.HasIndex("ViewAnglesVector3Id"); - b.ToTable("EFClientKill"); + b.ToTable("EFClientKills"); }); modelBuilder.Entity("IW4MAdmin.Plugins.Stats.Models.EFClientMessage", b => @@ -90,7 +90,7 @@ namespace SharedLibraryCore.Migrations b.HasIndex("ServerId"); - b.ToTable("EFClientMessage"); + b.ToTable("EFClientMessages"); }); modelBuilder.Entity("IW4MAdmin.Plugins.Stats.Models.EFClientStatistics", b => @@ -125,9 +125,8 @@ namespace SharedLibraryCore.Migrations b.Property("Active"); - b.Property("EFClientStatisticsClientId"); - - b.Property("EFClientStatisticsServerId"); + b.Property("ClientId") + .HasColumnName("EFClientStatistics_ClientId"); b.Property("HitCount"); @@ -135,11 +134,16 @@ namespace SharedLibraryCore.Migrations b.Property("Location"); + b.Property("ServerId") + .HasColumnName("EFClientStatistics_ServerId"); + b.HasKey("HitLocationCountId"); - b.HasIndex("EFClientStatisticsClientId", "EFClientStatisticsServerId"); + b.HasIndex("ServerId"); - b.ToTable("EFHitLocationCount"); + b.HasIndex("ClientId", "ServerId"); + + b.ToTable("EFHitLocationCounts"); }); modelBuilder.Entity("IW4MAdmin.Plugins.Stats.Models.EFServer", b => @@ -152,7 +156,7 @@ namespace SharedLibraryCore.Migrations b.HasKey("ServerId"); - b.ToTable("EFServer"); + b.ToTable("EFServers"); }); modelBuilder.Entity("IW4MAdmin.Plugins.Stats.Models.EFServerStatistics", b => @@ -195,7 +199,7 @@ namespace SharedLibraryCore.Migrations b.HasIndex("LinkId"); - b.ToTable("Aliases"); + b.ToTable("EFAlias"); }); modelBuilder.Entity("SharedLibraryCore.Database.Models.EFAliasLink", b => @@ -207,7 +211,7 @@ namespace SharedLibraryCore.Migrations b.HasKey("AliasLinkId"); - b.ToTable("AliasLinks"); + b.ToTable("EFAliasLinks"); }); modelBuilder.Entity("SharedLibraryCore.Database.Models.EFClient", b => @@ -248,7 +252,7 @@ namespace SharedLibraryCore.Migrations b.HasIndex("NetworkId") .IsUnique(); - b.ToTable("Clients"); + b.ToTable("EFClients"); }); modelBuilder.Entity("SharedLibraryCore.Database.Models.EFPenalty", b => @@ -281,7 +285,7 @@ namespace SharedLibraryCore.Migrations b.HasIndex("PunisherId"); - b.ToTable("Penalties"); + b.ToTable("EFPenalties"); }); modelBuilder.Entity("SharedLibraryCore.Helpers.Vector3", b => @@ -358,9 +362,20 @@ namespace SharedLibraryCore.Migrations modelBuilder.Entity("IW4MAdmin.Plugins.Stats.Models.EFHitLocationCount", b => { + b.HasOne("SharedLibraryCore.Database.Models.EFClient", "Client") + .WithMany() + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("IW4MAdmin.Plugins.Stats.Models.EFServer", "Server") + .WithMany() + .HasForeignKey("ServerId") + .OnDelete(DeleteBehavior.Cascade); + b.HasOne("IW4MAdmin.Plugins.Stats.Models.EFClientStatistics") .WithMany("HitLocations") - .HasForeignKey("EFClientStatisticsClientId", "EFClientStatisticsServerId"); + .HasForeignKey("ClientId", "ServerId") + .OnDelete(DeleteBehavior.Cascade); }); modelBuilder.Entity("IW4MAdmin.Plugins.Stats.Models.EFServerStatistics", b => diff --git a/SharedLibraryCore/Migrations/20180408213153_Initial Create.cs b/SharedLibraryCore/Migrations/20180409183408_InitialCreate.cs similarity index 70% rename from SharedLibraryCore/Migrations/20180408213153_Initial Create.cs rename to SharedLibraryCore/Migrations/20180409183408_InitialCreate.cs index 9454b1b50..e713086f6 100644 --- a/SharedLibraryCore/Migrations/20180408213153_Initial Create.cs +++ b/SharedLibraryCore/Migrations/20180409183408_InitialCreate.cs @@ -9,7 +9,7 @@ namespace SharedLibraryCore.Migrations protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( - name: "AliasLinks", + name: "EFAliasLinks", columns: table => new { AliasLinkId = table.Column(nullable: false) @@ -18,11 +18,11 @@ namespace SharedLibraryCore.Migrations }, constraints: table => { - table.PrimaryKey("PK_AliasLinks", x => x.AliasLinkId); + table.PrimaryKey("PK_EFAliasLinks", x => x.AliasLinkId); }); migrationBuilder.CreateTable( - name: "EFServer", + name: "EFServers", columns: table => new { ServerId = table.Column(nullable: false), @@ -31,7 +31,7 @@ namespace SharedLibraryCore.Migrations }, constraints: table => { - table.PrimaryKey("PK_EFServer", x => x.ServerId); + table.PrimaryKey("PK_EFServers", x => x.ServerId); }); migrationBuilder.CreateTable( @@ -50,7 +50,7 @@ namespace SharedLibraryCore.Migrations }); migrationBuilder.CreateTable( - name: "Aliases", + name: "EFAlias", columns: table => new { AliasId = table.Column(nullable: false) @@ -63,11 +63,11 @@ namespace SharedLibraryCore.Migrations }, constraints: table => { - table.PrimaryKey("PK_Aliases", x => x.AliasId); + table.PrimaryKey("PK_EFAlias", x => x.AliasId); table.ForeignKey( - name: "FK_Aliases_AliasLinks_LinkId", + name: "FK_EFAlias_EFAliasLinks_LinkId", column: x => x.LinkId, - principalTable: "AliasLinks", + principalTable: "EFAliasLinks", principalColumn: "AliasLinkId", onDelete: ReferentialAction.Restrict); }); @@ -87,15 +87,15 @@ namespace SharedLibraryCore.Migrations { table.PrimaryKey("PK_EFServerStatistics", x => x.StatisticId); table.ForeignKey( - name: "FK_EFServerStatistics_EFServer_ServerId", + name: "FK_EFServerStatistics_EFServers_ServerId", column: x => x.ServerId, - principalTable: "EFServer", + principalTable: "EFServers", principalColumn: "ServerId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( - name: "Clients", + name: "EFClients", columns: table => new { ClientId = table.Column(nullable: false) @@ -115,23 +115,23 @@ namespace SharedLibraryCore.Migrations }, constraints: table => { - table.PrimaryKey("PK_Clients", x => x.ClientId); + table.PrimaryKey("PK_EFClients", x => x.ClientId); table.ForeignKey( - name: "FK_Clients_AliasLinks_AliasLinkId", + name: "FK_EFClients_EFAliasLinks_AliasLinkId", column: x => x.AliasLinkId, - principalTable: "AliasLinks", + principalTable: "EFAliasLinks", principalColumn: "AliasLinkId", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_Clients_Aliases_CurrentAliasId", + name: "FK_EFClients_EFAlias_CurrentAliasId", column: x => x.CurrentAliasId, - principalTable: "Aliases", + principalTable: "EFAlias", principalColumn: "AliasId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( - name: "EFClientKill", + name: "EFClientKills", columns: table => new { KillId = table.Column(nullable: false) @@ -152,39 +152,39 @@ namespace SharedLibraryCore.Migrations }, constraints: table => { - table.PrimaryKey("PK_EFClientKill", x => x.KillId); + table.PrimaryKey("PK_EFClientKills", x => x.KillId); table.ForeignKey( - name: "FK_EFClientKill_Clients_AttackerId", + name: "FK_EFClientKills_EFClients_AttackerId", column: x => x.AttackerId, - principalTable: "Clients", + principalTable: "EFClients", principalColumn: "ClientId", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_EFClientKill_Vector3_DeathOriginVector3Id", + name: "FK_EFClientKills_Vector3_DeathOriginVector3Id", column: x => x.DeathOriginVector3Id, principalTable: "Vector3", principalColumn: "Vector3Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( - name: "FK_EFClientKill_Vector3_KillOriginVector3Id", + name: "FK_EFClientKills_Vector3_KillOriginVector3Id", column: x => x.KillOriginVector3Id, principalTable: "Vector3", principalColumn: "Vector3Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( - name: "FK_EFClientKill_EFServer_ServerId", + name: "FK_EFClientKills_EFServers_ServerId", column: x => x.ServerId, - principalTable: "EFServer", + principalTable: "EFServers", principalColumn: "ServerId", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_EFClientKill_Clients_VictimId", + name: "FK_EFClientKills_EFClients_VictimId", column: x => x.VictimId, - principalTable: "Clients", + principalTable: "EFClients", principalColumn: "ClientId", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_EFClientKill_Vector3_ViewAnglesVector3Id", + name: "FK_EFClientKills_Vector3_ViewAnglesVector3Id", column: x => x.ViewAnglesVector3Id, principalTable: "Vector3", principalColumn: "Vector3Id", @@ -192,7 +192,7 @@ namespace SharedLibraryCore.Migrations }); migrationBuilder.CreateTable( - name: "EFClientMessage", + name: "EFClientMessages", columns: table => new { MessageId = table.Column(nullable: false) @@ -205,17 +205,17 @@ namespace SharedLibraryCore.Migrations }, constraints: table => { - table.PrimaryKey("PK_EFClientMessage", x => x.MessageId); + table.PrimaryKey("PK_EFClientMessages", x => x.MessageId); table.ForeignKey( - name: "FK_EFClientMessage_Clients_ClientId", + name: "FK_EFClientMessages_EFClients_ClientId", column: x => x.ClientId, - principalTable: "Clients", + principalTable: "EFClients", principalColumn: "ClientId", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_EFClientMessage_EFServer_ServerId", + name: "FK_EFClientMessages_EFServers_ServerId", column: x => x.ServerId, - principalTable: "EFServer", + principalTable: "EFServers", principalColumn: "ServerId", onDelete: ReferentialAction.Cascade); }); @@ -237,21 +237,21 @@ namespace SharedLibraryCore.Migrations { table.PrimaryKey("PK_EFClientStatistics", x => new { x.ClientId, x.ServerId }); table.ForeignKey( - name: "FK_EFClientStatistics_Clients_ClientId", + name: "FK_EFClientStatistics_EFClients_ClientId", column: x => x.ClientId, - principalTable: "Clients", + principalTable: "EFClients", principalColumn: "ClientId", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_EFClientStatistics_EFServer_ServerId", + name: "FK_EFClientStatistics_EFServers_ServerId", column: x => x.ServerId, - principalTable: "EFServer", + principalTable: "EFServers", principalColumn: "ServerId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( - name: "Penalties", + name: "EFPenalties", columns: table => new { PenaltyId = table.Column(nullable: false) @@ -267,160 +267,177 @@ namespace SharedLibraryCore.Migrations }, constraints: table => { - table.PrimaryKey("PK_Penalties", x => x.PenaltyId); + table.PrimaryKey("PK_EFPenalties", x => x.PenaltyId); table.ForeignKey( - name: "FK_Penalties_AliasLinks_LinkId", + name: "FK_EFPenalties_EFAliasLinks_LinkId", column: x => x.LinkId, - principalTable: "AliasLinks", + principalTable: "EFAliasLinks", principalColumn: "AliasLinkId", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_Penalties_Clients_OffenderId", + name: "FK_EFPenalties_EFClients_OffenderId", column: x => x.OffenderId, - principalTable: "Clients", + principalTable: "EFClients", principalColumn: "ClientId", onDelete: ReferentialAction.Restrict); table.ForeignKey( - name: "FK_Penalties_Clients_PunisherId", + name: "FK_EFPenalties_EFClients_PunisherId", column: x => x.PunisherId, - principalTable: "Clients", + principalTable: "EFClients", principalColumn: "ClientId", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( - name: "EFHitLocationCount", + name: "EFHitLocationCounts", columns: table => new { HitLocationCountId = table.Column(nullable: false) .Annotation("Sqlite:Autoincrement", true), Active = table.Column(nullable: false), - EFClientStatisticsClientId = table.Column(nullable: true), - EFClientStatisticsServerId = table.Column(nullable: true), + EFClientStatistics_ClientId = table.Column(nullable: false), HitCount = table.Column(nullable: false), HitOffsetAverage = table.Column(nullable: false), - Location = table.Column(nullable: false) + Location = table.Column(nullable: false), + EFClientStatistics_ServerId = table.Column(nullable: false) }, constraints: table => { - table.PrimaryKey("PK_EFHitLocationCount", x => x.HitLocationCountId); + table.PrimaryKey("PK_EFHitLocationCounts", x => x.HitLocationCountId); table.ForeignKey( - name: "FK_EFHitLocationCount_EFClientStatistics_EFClientStatisticsClientId_EFClientStatisticsServerId", - columns: x => new { x.EFClientStatisticsClientId, x.EFClientStatisticsServerId }, + name: "FK_EFHitLocationCounts_EFClients_EFClientStatistics_ClientId", + column: x => x.EFClientStatistics_ClientId, + principalTable: "EFClients", + principalColumn: "ClientId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_EFHitLocationCounts_EFServers_EFClientStatistics_ServerId", + column: x => x.EFClientStatistics_ServerId, + principalTable: "EFServers", + principalColumn: "ServerId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_EFHitLocationCounts_EFClientStatistics_EFClientStatistics_ClientId_EFClientStatistics_ServerId", + columns: x => new { x.EFClientStatistics_ClientId, x.EFClientStatistics_ServerId }, principalTable: "EFClientStatistics", principalColumns: new[] { "ClientId", "ServerId" }, - onDelete: ReferentialAction.Restrict); + onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( - name: "IX_Aliases_LinkId", - table: "Aliases", + name: "IX_EFAlias_LinkId", + table: "EFAlias", column: "LinkId"); migrationBuilder.CreateIndex( - name: "IX_Clients_AliasLinkId", - table: "Clients", - column: "AliasLinkId"); - - migrationBuilder.CreateIndex( - name: "IX_Clients_CurrentAliasId", - table: "Clients", - column: "CurrentAliasId"); - - migrationBuilder.CreateIndex( - name: "IX_Clients_NetworkId", - table: "Clients", - column: "NetworkId", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_EFClientKill_AttackerId", - table: "EFClientKill", + name: "IX_EFClientKills_AttackerId", + table: "EFClientKills", column: "AttackerId"); migrationBuilder.CreateIndex( - name: "IX_EFClientKill_DeathOriginVector3Id", - table: "EFClientKill", + name: "IX_EFClientKills_DeathOriginVector3Id", + table: "EFClientKills", column: "DeathOriginVector3Id"); migrationBuilder.CreateIndex( - name: "IX_EFClientKill_KillOriginVector3Id", - table: "EFClientKill", + name: "IX_EFClientKills_KillOriginVector3Id", + table: "EFClientKills", column: "KillOriginVector3Id"); migrationBuilder.CreateIndex( - name: "IX_EFClientKill_ServerId", - table: "EFClientKill", + name: "IX_EFClientKills_ServerId", + table: "EFClientKills", column: "ServerId"); migrationBuilder.CreateIndex( - name: "IX_EFClientKill_VictimId", - table: "EFClientKill", + name: "IX_EFClientKills_VictimId", + table: "EFClientKills", column: "VictimId"); migrationBuilder.CreateIndex( - name: "IX_EFClientKill_ViewAnglesVector3Id", - table: "EFClientKill", + name: "IX_EFClientKills_ViewAnglesVector3Id", + table: "EFClientKills", column: "ViewAnglesVector3Id"); migrationBuilder.CreateIndex( - name: "IX_EFClientMessage_ClientId", - table: "EFClientMessage", + name: "IX_EFClientMessages_ClientId", + table: "EFClientMessages", column: "ClientId"); migrationBuilder.CreateIndex( - name: "IX_EFClientMessage_ServerId", - table: "EFClientMessage", + name: "IX_EFClientMessages_ServerId", + table: "EFClientMessages", column: "ServerId"); + migrationBuilder.CreateIndex( + name: "IX_EFClients_AliasLinkId", + table: "EFClients", + column: "AliasLinkId"); + + migrationBuilder.CreateIndex( + name: "IX_EFClients_CurrentAliasId", + table: "EFClients", + column: "CurrentAliasId"); + + migrationBuilder.CreateIndex( + name: "IX_EFClients_NetworkId", + table: "EFClients", + column: "NetworkId", + unique: true); + migrationBuilder.CreateIndex( name: "IX_EFClientStatistics_ServerId", table: "EFClientStatistics", column: "ServerId"); migrationBuilder.CreateIndex( - name: "IX_EFHitLocationCount_EFClientStatisticsClientId_EFClientStatisticsServerId", - table: "EFHitLocationCount", - columns: new[] { "EFClientStatisticsClientId", "EFClientStatisticsServerId" }); + name: "IX_EFHitLocationCounts_EFClientStatistics_ServerId", + table: "EFHitLocationCounts", + column: "EFClientStatistics_ServerId"); + + migrationBuilder.CreateIndex( + name: "IX_EFHitLocationCounts_EFClientStatistics_ClientId_EFClientStatistics_ServerId", + table: "EFHitLocationCounts", + columns: new[] { "EFClientStatistics_ClientId", "EFClientStatistics_ServerId" }); + + migrationBuilder.CreateIndex( + name: "IX_EFPenalties_LinkId", + table: "EFPenalties", + column: "LinkId"); + + migrationBuilder.CreateIndex( + name: "IX_EFPenalties_OffenderId", + table: "EFPenalties", + column: "OffenderId"); + + migrationBuilder.CreateIndex( + name: "IX_EFPenalties_PunisherId", + table: "EFPenalties", + column: "PunisherId"); migrationBuilder.CreateIndex( name: "IX_EFServerStatistics_ServerId", table: "EFServerStatistics", column: "ServerId"); - - migrationBuilder.CreateIndex( - name: "IX_Penalties_LinkId", - table: "Penalties", - column: "LinkId"); - - migrationBuilder.CreateIndex( - name: "IX_Penalties_OffenderId", - table: "Penalties", - column: "OffenderId"); - - migrationBuilder.CreateIndex( - name: "IX_Penalties_PunisherId", - table: "Penalties", - column: "PunisherId"); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( - name: "EFClientKill"); + name: "EFClientKills"); migrationBuilder.DropTable( - name: "EFClientMessage"); + name: "EFClientMessages"); migrationBuilder.DropTable( - name: "EFHitLocationCount"); + name: "EFHitLocationCounts"); + + migrationBuilder.DropTable( + name: "EFPenalties"); migrationBuilder.DropTable( name: "EFServerStatistics"); - migrationBuilder.DropTable( - name: "Penalties"); - migrationBuilder.DropTable( name: "Vector3"); @@ -428,16 +445,16 @@ namespace SharedLibraryCore.Migrations name: "EFClientStatistics"); migrationBuilder.DropTable( - name: "Clients"); + name: "EFClients"); migrationBuilder.DropTable( - name: "EFServer"); + name: "EFServers"); migrationBuilder.DropTable( - name: "Aliases"); + name: "EFAlias"); migrationBuilder.DropTable( - name: "AliasLinks"); + name: "EFAliasLinks"); } } } diff --git a/SharedLibraryCore/Migrations/DatabaseContextModelSnapshot.cs b/SharedLibraryCore/Migrations/DatabaseContextModelSnapshot.cs index 90b9994ca..9515d23d4 100644 --- a/SharedLibraryCore/Migrations/DatabaseContextModelSnapshot.cs +++ b/SharedLibraryCore/Migrations/DatabaseContextModelSnapshot.cs @@ -65,7 +65,7 @@ namespace SharedLibraryCore.Migrations b.HasIndex("ViewAnglesVector3Id"); - b.ToTable("EFClientKill"); + b.ToTable("EFClientKills"); }); modelBuilder.Entity("IW4MAdmin.Plugins.Stats.Models.EFClientMessage", b => @@ -89,7 +89,7 @@ namespace SharedLibraryCore.Migrations b.HasIndex("ServerId"); - b.ToTable("EFClientMessage"); + b.ToTable("EFClientMessages"); }); modelBuilder.Entity("IW4MAdmin.Plugins.Stats.Models.EFClientStatistics", b => @@ -124,9 +124,8 @@ namespace SharedLibraryCore.Migrations b.Property("Active"); - b.Property("EFClientStatisticsClientId"); - - b.Property("EFClientStatisticsServerId"); + b.Property("ClientId") + .HasColumnName("EFClientStatistics_ClientId"); b.Property("HitCount"); @@ -134,11 +133,16 @@ namespace SharedLibraryCore.Migrations b.Property("Location"); + b.Property("ServerId") + .HasColumnName("EFClientStatistics_ServerId"); + b.HasKey("HitLocationCountId"); - b.HasIndex("EFClientStatisticsClientId", "EFClientStatisticsServerId"); + b.HasIndex("ServerId"); - b.ToTable("EFHitLocationCount"); + b.HasIndex("ClientId", "ServerId"); + + b.ToTable("EFHitLocationCounts"); }); modelBuilder.Entity("IW4MAdmin.Plugins.Stats.Models.EFServer", b => @@ -151,7 +155,7 @@ namespace SharedLibraryCore.Migrations b.HasKey("ServerId"); - b.ToTable("EFServer"); + b.ToTable("EFServers"); }); modelBuilder.Entity("IW4MAdmin.Plugins.Stats.Models.EFServerStatistics", b => @@ -194,7 +198,7 @@ namespace SharedLibraryCore.Migrations b.HasIndex("LinkId"); - b.ToTable("Aliases"); + b.ToTable("EFAlias"); }); modelBuilder.Entity("SharedLibraryCore.Database.Models.EFAliasLink", b => @@ -206,7 +210,7 @@ namespace SharedLibraryCore.Migrations b.HasKey("AliasLinkId"); - b.ToTable("AliasLinks"); + b.ToTable("EFAliasLinks"); }); modelBuilder.Entity("SharedLibraryCore.Database.Models.EFClient", b => @@ -247,7 +251,7 @@ namespace SharedLibraryCore.Migrations b.HasIndex("NetworkId") .IsUnique(); - b.ToTable("Clients"); + b.ToTable("EFClients"); }); modelBuilder.Entity("SharedLibraryCore.Database.Models.EFPenalty", b => @@ -280,7 +284,7 @@ namespace SharedLibraryCore.Migrations b.HasIndex("PunisherId"); - b.ToTable("Penalties"); + b.ToTable("EFPenalties"); }); modelBuilder.Entity("SharedLibraryCore.Helpers.Vector3", b => @@ -357,9 +361,20 @@ namespace SharedLibraryCore.Migrations modelBuilder.Entity("IW4MAdmin.Plugins.Stats.Models.EFHitLocationCount", b => { + b.HasOne("SharedLibraryCore.Database.Models.EFClient", "Client") + .WithMany() + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("IW4MAdmin.Plugins.Stats.Models.EFServer", "Server") + .WithMany() + .HasForeignKey("ServerId") + .OnDelete(DeleteBehavior.Cascade); + b.HasOne("IW4MAdmin.Plugins.Stats.Models.EFClientStatistics") .WithMany("HitLocations") - .HasForeignKey("EFClientStatisticsClientId", "EFClientStatisticsServerId"); + .HasForeignKey("ClientId", "ServerId") + .OnDelete(DeleteBehavior.Cascade); }); modelBuilder.Entity("IW4MAdmin.Plugins.Stats.Models.EFServerStatistics", b => diff --git a/SharedLibraryCore/RCon/Connection.cs b/SharedLibraryCore/RCon/Connection.cs index 098323c84..f24b18482 100644 --- a/SharedLibraryCore/RCon/Connection.cs +++ b/SharedLibraryCore/RCon/Connection.cs @@ -130,7 +130,10 @@ namespace SharedLibraryCore.RCon #if DEBUG Log.WriteDebug($"Received {bytesRead} bytes from {ServerConnection.RemoteEndPoint}"); #endif - connectionState.ResponseString.Append(Encoding.UTF7.GetString(connectionState.Buffer, 0, bytesRead).TrimEnd('\0')); + connectionState.ResponseString.Append(Encoding.UTF7.GetString(connectionState.Buffer, 0, bytesRead).TrimEnd('\0') + '\n'); + + if (!connectionState.Buffer.Take(4).ToArray().SequenceEqual(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF })) + throw new NetworkException("Unexpected packet received"); if (serverConnection.Available > 0) { @@ -159,9 +162,9 @@ namespace SharedLibraryCore.RCon public async Task SendQueryAsync(StaticHelpers.QueryType type, string parameters = "") { // will this really prevent flooding? - if ((DateTime.Now - LastQuery).TotalMilliseconds < 150) + if ((DateTime.Now - LastQuery).TotalMilliseconds < 35) { - await Task.Delay(150); + await Task.Delay(35); } LastQuery = DateTime.Now; @@ -174,10 +177,10 @@ namespace SharedLibraryCore.RCon { case StaticHelpers.QueryType.DVAR: case StaticHelpers.QueryType.COMMAND: - queryString = $"ÿÿÿÿrcon {RConPassword} {parameters}"; + queryString = $"ÿÿÿÿ\x02rcon {RConPassword} {parameters}"; break; case StaticHelpers.QueryType.GET_STATUS: - queryString = "ÿÿÿÿgetstatus"; + queryString = "ÿÿÿÿ\x02getstatus"; break; } @@ -288,8 +291,9 @@ namespace SharedLibraryCore.RCon string[] splitResponse = queryResponse.Split(new char[] { - StaticHelpers.SeperatorChar - }, StringSplitOptions.RemoveEmptyEntries); + '\n' + }, StringSplitOptions.RemoveEmptyEntries) + .Select(line => line.Trim()).ToArray(); return splitResponse; } } diff --git a/SharedLibraryCore/Services/ClientService.cs b/SharedLibraryCore/Services/ClientService.cs index 291e89dbb..43610034c 100644 --- a/SharedLibraryCore/Services/ClientService.cs +++ b/SharedLibraryCore/Services/ClientService.cs @@ -193,7 +193,7 @@ namespace SharedLibraryCore.Services { using (var context = new DatabaseContext()) return await context.Clients - .Where(c => c.Level == Objects.Player.Permission.Owner) + .Where(c => c.Level == Player.Permission.Owner) .ToListAsync(); } @@ -229,18 +229,18 @@ namespace SharedLibraryCore.Services using (var context = new DatabaseContext()) { var iqClients = (from alias in context.Aliases - .AsNoTracking() - where alias.Name - .Contains(name) - join link in context.AliasLinks - on alias.LinkId equals link.AliasLinkId - join client in context.Clients - .AsNoTracking() - on alias.LinkId equals client.AliasLinkId - select client) - .Distinct() - .Include(c => c.CurrentAlias) - .Include(c => c.AliasLink.Children); + .AsNoTracking() + where alias.Name + .Contains(name) + join link in context.AliasLinks + on alias.LinkId equals link.AliasLinkId + join client in context.Clients + .AsNoTracking() + on alias.LinkId equals client.AliasLinkId + select client) + .Distinct() + .Include(c => c.CurrentAlias) + .Include(c => c.AliasLink.Children); return await iqClients.ToListAsync(); } @@ -251,17 +251,17 @@ namespace SharedLibraryCore.Services using (var context = new DatabaseContext()) { var iqClients = (from alias in context.Aliases - .AsNoTracking() - where alias.IPAddress == ipAddress - join link in context.AliasLinks - on alias.LinkId equals link.AliasLinkId - join client in context.Clients - .AsNoTracking() - on alias.LinkId equals client.AliasLinkId - select client) - .Distinct() - .Include(c => c.CurrentAlias) - .Include(c => c.AliasLink.Children); + .AsNoTracking() + where alias.IPAddress == ipAddress + join link in context.AliasLinks + on alias.LinkId equals link.AliasLinkId + join client in context.Clients + .AsNoTracking() + on alias.LinkId equals client.AliasLinkId + select client) + .Distinct() + .Include(c => c.CurrentAlias) + .Include(c => c.AliasLink.Children); return await iqClients.ToListAsync(); } @@ -288,7 +288,7 @@ namespace SharedLibraryCore.Services .AsNoTracking() .Where(c => (DateTime.UtcNow - c.LastConnection).TotalDays >= inactiveDays) .ToListAsync(); - inactive.ForEach(c => c.Level = Objects.Player.Permission.User); + inactive.ForEach(c => c.Level = Player.Permission.User); await context.SaveChangesAsync(); return inactive; } diff --git a/SharedLibraryCore/Services/GenericRepository.cs b/SharedLibraryCore/Services/GenericRepository.cs index 616366614..4d5ee4047 100644 --- a/SharedLibraryCore/Services/GenericRepository.cs +++ b/SharedLibraryCore/Services/GenericRepository.cs @@ -51,11 +51,14 @@ namespace SharedLibraryCore.Services return this.GetQuery(predicate, orderExpression).AsEnumerable(); } - public virtual IQueryable GetQuery(Expression> predicate = null, Func, IOrderedQueryable> orderExpression = null) { IQueryable qry = this.DBSet; + foreach (var property in this.Context.Model.FindEntityType(typeof(TEntity)).GetNavigations()) + qry = qry.Include(property.Name); + + if (predicate != null) qry = qry.Where(predicate); diff --git a/SharedLibraryCore/Services/PenaltyService.cs b/SharedLibraryCore/Services/PenaltyService.cs index 1179350a3..8cc54a924 100644 --- a/SharedLibraryCore/Services/PenaltyService.cs +++ b/SharedLibraryCore/Services/PenaltyService.cs @@ -14,36 +14,45 @@ namespace SharedLibraryCore.Services { public class PenaltyService : Interfaces.IEntityService { - public async Task Create(EFPenalty entity) + public async Task Create(EFPenalty newEntity) { using (var context = new DatabaseContext()) { - entity.Offender = context.Clients.Single(e => e.ClientId == entity.Offender.ClientId); - entity.Punisher = context.Clients.Single(e => e.ClientId == entity.Punisher.ClientId); - entity.Link = context.AliasLinks.Single(l => l.AliasLinkId == entity.Link.AliasLinkId); + // create the actual EFPenalty + EFPenalty addedEntity = new EFPenalty() + { + OffenderId = newEntity.Offender.ClientId, + PunisherId = newEntity.Punisher.ClientId, + LinkId = newEntity.Link.AliasLinkId, + Type = newEntity.Type, + Active = true, + Expires = newEntity.Expires, + Offense = newEntity.Offense, + When = newEntity.When, + }; - if (entity.Expires == DateTime.MaxValue) - entity.Expires = DateTime.Parse(System.Data.SqlTypes.SqlDateTime.MaxValue.ToString()); + if (addedEntity.Expires == DateTime.MaxValue) + addedEntity.Expires = DateTime.Parse(System.Data.SqlTypes.SqlDateTime.MaxValue.ToString()); // make bans propogate to all aliases - if (entity.Type == Objects.Penalty.PenaltyType.Ban) + if (addedEntity.Type == Objects.Penalty.PenaltyType.Ban) { await context.Clients - .Where(c => c.AliasLinkId == entity.Link.AliasLinkId) + .Where(c => c.AliasLinkId == addedEntity.LinkId) .ForEachAsync(c => c.Level = Objects.Player.Permission.Banned); } // make flags propogate to all aliases - else if (entity.Type == Objects.Penalty.PenaltyType.Flag) + else if (addedEntity.Type == Objects.Penalty.PenaltyType.Flag) { await context.Clients - .Where(c => c.AliasLinkId == entity.Link.AliasLinkId) + .Where(c => c.AliasLinkId == addedEntity.LinkId) .ForEachAsync(c => c.Level = Objects.Player.Permission.Flagged); } - context.Penalties.Add(entity); + context.Penalties.Add(addedEntity); await context.SaveChangesAsync(); - return entity; + return addedEntity; } } diff --git a/SharedLibraryCore/Utilities.cs b/SharedLibraryCore/Utilities.cs index a4eeb73eb..03a800aed 100644 --- a/SharedLibraryCore/Utilities.cs +++ b/SharedLibraryCore/Utilities.cs @@ -362,7 +362,7 @@ namespace SharedLibraryCore Name = client.CurrentAlias.Name, IPAddress = client.CurrentAlias.IPAddress, Level = client.Level, - LastConnection = DateTime.UtcNow, + LastConnection = client.LastConnection == DateTime.MinValue ? DateTime.UtcNow : client.LastConnection, CurrentAlias = client.CurrentAlias, CurrentAliasId = client.CurrentAlias.AliasId }; @@ -391,7 +391,9 @@ namespace SharedLibraryCore public static async Task> GetDvarAsync(this Server server, string dvarName) { - string[] LineSplit = await server.RemoteConnection.SendQueryAsync(QueryType.DVAR, dvarName); + string[] LineSplit = server.GameName != Game.T6M ? + await server.RemoteConnection.SendQueryAsync(QueryType.DVAR, dvarName) : + await server.RemoteConnection.SendQueryAsync(QueryType.COMMAND, $"get {dvarName}"); if (LineSplit.Length != 3) { diff --git a/WebfrontCore/Controllers/BaseController.cs b/WebfrontCore/Controllers/BaseController.cs index 7e93167ed..4943f8d6b 100644 --- a/WebfrontCore/Controllers/BaseController.cs +++ b/WebfrontCore/Controllers/BaseController.cs @@ -18,11 +18,6 @@ namespace WebfrontCore.Controllers protected bool Authorized { get; private set; } protected EFClient User { get; private set; } - /* public BaseController(DatabaseContext ctx) - { - Context = ctx; - }*/ - public override void OnActionExecuting(ActionExecutingContext context) { Manager = Program.Manager; diff --git a/WebfrontCore/Program.cs b/WebfrontCore/Program.cs index 9d35a4a69..968bb6e44 100644 --- a/WebfrontCore/Program.cs +++ b/WebfrontCore/Program.cs @@ -8,6 +8,11 @@ namespace WebfrontCore { public static IManager Manager; + static void Main(string[] args) + { + throw new System.Exception("Webfront core cannot be run as a standalone application"); + } + public static void Init(IManager mgr) { Manager = mgr; diff --git a/WebfrontCore/Startup.cs b/WebfrontCore/Startup.cs index 68ed2302c..7bfa981f3 100644 --- a/WebfrontCore/Startup.cs +++ b/WebfrontCore/Startup.cs @@ -20,19 +20,12 @@ namespace WebfrontCore { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) - .AddJsonFile("appsettings.json", optional: true, reloadOnChange: false) + .AddJsonFile("WebfrontSettings.json", optional: true, reloadOnChange: false) .AddEnvironmentVariables(); Configuration = builder.Build(); _appHost = env; - - using (var db = new DatabaseContext()) - { - db.Database.EnsureCreated(); - db.Database.Migrate(); - new ContextSeed(db).Seed().Wait(); - } } // This method gets called by the runtime. Use this method to add services to the container. diff --git a/WebfrontCore/Views/Shared/_Layout.cshtml b/WebfrontCore/Views/Shared/_Layout.cshtml index 8c7226e8d..0894a04d7 100644 --- a/WebfrontCore/Views/Shared/_Layout.cshtml +++ b/WebfrontCore/Views/Shared/_Layout.cshtml @@ -12,11 +12,11 @@ - + - + @@ -103,7 +103,7 @@ else @RenderBody()
- + @@ -111,7 +111,7 @@ else - + diff --git a/WebfrontCore/Views/_ViewImports.cshtml b/WebfrontCore/Views/_ViewImports.cshtml index d2e8b7fbe..b245e221c 100644 --- a/WebfrontCore/Views/_ViewImports.cshtml +++ b/WebfrontCore/Views/_ViewImports.cshtml @@ -1,2 +1 @@ @using WebfrontCore -@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers diff --git a/WebfrontCore/WebfrontCore.csproj b/WebfrontCore/WebfrontCore.csproj index a0f2eedff..141e10afe 100644 --- a/WebfrontCore/WebfrontCore.csproj +++ b/WebfrontCore/WebfrontCore.csproj @@ -2,6 +2,8 @@ netcoreapp2.0 + false + true 2.6 RaidMax.IW4MAdmin.WebfrontCore 2.0.0 @@ -15,7 +17,7 @@ https://github.com/RaidMax/IW4M-Admin https://raidmax.org/IW4MAdmin/img/iw4adminicon-3.png - Library + Exe @@ -26,7 +28,6 @@ - @@ -41,13 +42,17 @@ - + + + - + PreserveNewest + + diff --git a/WebfrontCore/appsettings.json b/WebfrontCore/WebfrontSettings.json similarity index 53% rename from WebfrontCore/appsettings.json rename to WebfrontCore/WebfrontSettings.json index 1e422f4f3..407850b38 100644 --- a/WebfrontCore/appsettings.json +++ b/WebfrontCore/WebfrontSettings.json @@ -9,9 +9,5 @@ }, "Web": { "Address": "http://127.0.0.1:5000" - }, - "ConnectionStrings": { - "WindowsConnection": "Data Source=|DataDirectory|\\Database.sdf", - "LinuxConnection": "Server=127.0.0.1;User=user;Database=IW4MAdmin;Password=password" } }