1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-10 07:13:58 -05:00

renable weapon name in anticheat snapshot list

update migrations for unique index
fix missing total connection time
include total connection time in get client query
This commit is contained in:
RaidMax
2019-11-25 12:05:12 -06:00
parent 89b690938a
commit 86dd6db3e5
18 changed files with 221 additions and 114 deletions

View File

@ -10,6 +10,8 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
namespace SharedLibraryCore.Database
{
@ -69,8 +71,8 @@ namespace SharedLibraryCore.Database
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// optionsBuilder.UseLoggerFactory(_loggerFactory)
// .EnableSensitiveDataLogging();
// optionsBuilder.UseLoggerFactory(_loggerFactory)
// .EnableSensitiveDataLogging();
if (string.IsNullOrEmpty(_ConnectionString))
{
@ -102,6 +104,41 @@ namespace SharedLibraryCore.Database
}
}
private void SetAuditColumns()
{
return;
var entries = ChangeTracker
.Entries()
.Where(e => e.Entity is SharedEntity && (
e.State == EntityState.Added
|| e.State == EntityState.Modified)).ToList();
foreach (var entityEntry in entries)
{
if (entityEntry.State == EntityState.Added)
{
//((SharedEntity)entityEntry.Entity).CreatedDateTime = DateTime.UtcNow;
}
else
{
//((SharedEntity)entityEntry.Entity).UpdatedDateTime = DateTime.UtcNow;
}
}
}
public override Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default)
{
SetAuditColumns();
return base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
}
public override int SaveChanges()
{
SetAuditColumns();
return base.SaveChanges();
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// make network id unique

View File

@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace SharedLibraryCore.Database.Models
{
public partial class EFAlias
public partial class EFAlias : SharedEntity
{
[Key]
public int AliasId { get; set; }

View File

@ -1,13 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations.Schema;
namespace SharedLibraryCore.Database.Models
{
public class SharedEntity
{
/// <summary>
/// indicates if the entity is active
/// </summary>
public bool Active { get; set; } = true;
///// <summary>
///// Specifies when the entity was created
///// </summary>
//[Column(TypeName="datetime")]
//public DateTime CreatedDateTime { get; set; }
///// <summary>
///// Specifies when the entity was updated
///// </summary>
//[Column(TypeName = "datetime")]
//public DateTime? UpdatedDateTime { get;set; }
}
}

View File

@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Threading.Tasks;
namespace SharedLibraryCore.Interfaces
{

View File

@ -8,11 +8,55 @@ namespace SharedLibraryCore.Migrations
{
if (migrationBuilder.ActiveProvider == "Microsoft.EntityFrameworkCore.Sqlite")
{
migrationBuilder.Sql(@"DELETE FROM EFAlias WHERE AliasId IN (
SELECT AliasId from (
SELECT AliasId, Name, Min(DateAdded), IPAddress FROM EFAlias where (IPAddress, Name) in (SELECT DISTINCT IPAddress, Name FROM EFAlias GROUP BY EFAlias.IPAddress, Name HAVING count(IPAddress) > 1 AND count(Name) > 1)
GROUP BY IPAddress ORDER BY IPAddress))", true);
migrationBuilder.Sql(@"CREATE UNIQUE INDEX IX_EFAlias_Name_IPAddress ON EFAlias ( IPAddress, Name );", true);
migrationBuilder.Sql(@"DROP TABLE IF EXISTS DUPLICATE_ALIASES;
CREATE TABLE DUPLICATE_ALIASES AS
SELECT
MIN(AliasId) MIN,
MAX(AliasId) MAX,
LinkId
FROM
EFAlias
WHERE
(IPAddress, NAME) IN(
SELECT DISTINCT
IPAddress,
NAME
FROM
EFAlias
GROUP BY
EFAlias.IPAddress,
NAME
HAVING
COUNT(IPAddress) > 1 AND COUNT(NAME) > 1
)
GROUP BY
IPAddress
ORDER BY
IPAddress;
UPDATE
EFClients
SET CurrentAliasId = (SELECT MAX FROM DUPLICATE_ALIASES WHERE CurrentAliasId = MIN)
WHERE
CurrentAliasId IN(
SELECT
MIN
FROM
DUPLICATE_ALIASES
);
DELETE
FROM
EFAlias
WHERE
AliasId IN(
SELECT
MIN
FROM
DUPLICATE_ALIASES
);
DROP TABLE
DUPLICATE_ALIASES;");
return;
}
@ -77,30 +121,57 @@ DROP TABLE
else
{
migrationBuilder.Sql(@"DELETE
FROM ""EFAlias""
WHERE ""AliasId""
IN
(
SELECT MIN(""AliasId"") AliasId
FROM ""EFAlias"" WHERE(""IPAddress"", ""Name"")
IN
(
SELECT DISTINCT ""IPAddress"", ""Name""
FROM ""EFAlias""
GROUP BY ""EFAlias"".""IPAddress"", ""Name""
HAVING COUNT(""IPAddress"") > 1 AND COUNT(""Name"") > 1
)
GROUP BY ""IPAddress""
ORDER BY ""IPAddress""
)", true);
migrationBuilder.Sql(@"CREATE TEMPORARY TABLE DUPLICATE_ALIASES AS
SELECT
MIN(""AliasId"") ""MIN"",
MAX(""AliasId"") ""MAX"",
MIN(""LinkId"") ""LinkId""
FROM
""EFAlias""
WHERE
(""IPAddress"", ""Name"") IN(
SELECT DISTINCT
""IPAddress"",
""Name""
FROM
""EFAlias""
GROUP BY
""EFAlias"".""IPAddress"",
""Name""
HAVING
COUNT(""IPAddress"") > 1 AND COUNT(""Name"") > 1
)
GROUP BY
""IPAddress""
ORDER BY
""IPAddress"";
UPDATE
""EFClients"" AS ""Client""
SET
""CurrentAliasId"" = ""Duplicate"".""MAX""
FROM
DUPLICATE_ALIASES ""Duplicate""
WHERE
""Client"".""CurrentAliasId"" IN(
SELECT
""MIN""
FROM
DUPLICATE_ALIASES
)
AND
""Client"".""CurrentAliasId"" = ""Duplicate"".""MIN"";
DELETE
FROM
""EFAlias""
WHERE
""AliasId"" IN(
SELECT
""MIN""
FROM
DUPLICATE_ALIASES
);
DROP TABLE
DUPLICATE_ALIASES;");
}
migrationBuilder.CreateIndex(
@ -112,9 +183,6 @@ IN
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_EFAlias_Name_IPAddress",
table: "EFAlias");
}
}
}

View File

@ -540,6 +540,7 @@ namespace SharedLibraryCore.Database.Models
else
{
CurrentServer.Logger.WriteDebug($"Creating join event for {this}");
var e = new GameEvent()
{
Type = GameEvent.EventType.Join,

View File

@ -103,8 +103,6 @@ namespace SharedLibraryCore.Services
private async Task UpdateAlias(string name, int? ip, EFClient entity, DatabaseContext context)
{
entity.CurrentServer.Manager.GetLogger(0).WriteDebug($"Begin update alias for {entity}");
// entity is the tracked db context item
// get all aliases by IP address and LinkId
var iqAliases = context.Aliases
@ -216,8 +214,6 @@ namespace SharedLibraryCore.Services
entity.CurrentAliasId = 0;
await context.SaveChangesAsync();
}
entity.CurrentServer.Manager.GetLogger(0).WriteDebug($"End update alias for {entity}");
}
/// <summary>
@ -308,7 +304,8 @@ namespace SharedLibraryCore.Services
{
Name = _client.CurrentAlias.Name,
IPAddress = _client.CurrentAlias.IPAddress
}
},
TotalConnectionTime = _client.TotalConnectionTime
})
.FirstOrDefault(_client => _client.ClientId == entityId);
@ -362,8 +359,6 @@ namespace SharedLibraryCore.Services
EF.CompileAsyncQuery((DatabaseContext context, long networkId) =>
context.Clients
.Include(c => c.CurrentAlias)
//.Include(c => c.AliasLink.Children)
//.Include(c => c.ReceivedPenalties)
.Select(_client => new EFClient()
{
ClientId = _client.ClientId,
@ -373,7 +368,8 @@ namespace SharedLibraryCore.Services
FirstConnection = _client.FirstConnection,
LastConnection = _client.LastConnection,
Masked = _client.Masked,
NetworkId = _client.NetworkId
NetworkId = _client.NetworkId,
TotalConnectionTime = _client.TotalConnectionTime
})
.FirstOrDefault(c => c.NetworkId == networkId)
);

View File

@ -34,26 +34,32 @@
<Compile Remove="Migrations\20190223012312_SetMaxLengthForMetaKey.cs" />
<Compile Remove="Migrations\20190907222702_AddMomentViewAnglesToAcSnapshot.cs" />
<Compile Remove="Migrations\20190907222702_AddMomentViewAnglesToAcSnapshot.Designer.cs" />
<Compile Remove="Migrations\20191120170503_AddDateAuditColumnsToSharedEntity.cs" />
<Compile Remove="Migrations\20191120170503_AddDateAuditColumnsToSharedEntity.Designer.cs" />
<Compile Remove="Migrations\20191120204934_AddDateAuditColumnsToSharedEntity.cs" />
<Compile Remove="Migrations\20191120204934_AddDateAuditColumnsToSharedEntity.Designer.cs" />
<Compile Remove="Migrations\20191120205633_AddDateAuditColumnsToSharedEntity.cs" />
<Compile Remove="Migrations\20191120205633_AddDateAuditColumnsToSharedEntity.Designer.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Jint" Version="2.11.58" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="Npgsql" Version="4.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.0.1" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="3.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Npgsql" Version="4.1.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.0.1" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.0.0-rc3.final" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.0.0" />
<PackageReference Include="SimpleCrypto.NetCore" Version="1.0.0" />
</ItemGroup>