1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-10 15:20:48 -05:00

update map names for IW4 (issue #48)

only check shared GUID for IW4
optimized get privileged clients query
fine-tuned the version printout to include revision numbers
This commit is contained in:
RaidMax
2018-09-13 14:34:42 -05:00
parent d6996f96e6
commit 9295f9aa5b
11 changed files with 102 additions and 68 deletions

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static SharedLibraryCore.Objects.Player;
namespace SharedLibraryCore.Dtos
{
@ -10,5 +11,7 @@ namespace SharedLibraryCore.Dtos
{
public string Name { get; set; }
public int ClientId { get; set; }
public int LinkId { get; set; }
public Permission Level { get; set; }
}
}

View File

@ -9,6 +9,7 @@ using SharedLibraryCore.Database.Models;
using System.Linq.Expressions;
using SharedLibraryCore.Objects;
using Microsoft.EntityFrameworkCore;
using SharedLibraryCore.Dtos;
namespace SharedLibraryCore.Services
{
@ -94,10 +95,9 @@ namespace SharedLibraryCore.Services
{
return await Task.Run(() =>
{
using (var context = new DatabaseContext())
using (var context = new DatabaseContext(true))
{
return context.Clients
.AsNoTracking()
.Include(c => c.CurrentAlias)
.Include(c => c.AliasLink.Children)
.Where(e).ToList();
@ -107,11 +107,8 @@ namespace SharedLibraryCore.Services
public async Task<EFClient> Get(int entityID)
{
using (var context = new DatabaseContext())
using (var context = new DatabaseContext(true))
{
context.ChangeTracker.AutoDetectChangesEnabled = false;
context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
var iqClient = from client in context.Clients
.Include(c => c.CurrentAlias)
.Include(c => c.AliasLink.Children)
@ -128,6 +125,9 @@ namespace SharedLibraryCore.Services
linkedClient.NetworkId
})
};
#if DEBUG == true
var clientSql = iqClient.ToSql();
#endif
var foundClient = await iqClient.FirstOrDefaultAsync();
if (foundClient == null)
@ -143,15 +143,19 @@ namespace SharedLibraryCore.Services
}
}
private static readonly Func<DatabaseContext, long, Task<EFClient>> _getUniqueQuery =
EF.CompileAsyncQuery((DatabaseContext context, long networkId) =>
context.Clients
.Include(c => c.CurrentAlias)
.Include(c => c.AliasLink.Children)
.FirstOrDefault(c => c.NetworkId == networkId)
);
public async Task<EFClient> GetUnique(long entityAttribute)
{
using (var context = new DatabaseContext())
using (var context = new DatabaseContext(true))
{
return await context.Clients
.AsNoTracking()
.Include(c => c.CurrentAlias)
.Include(c => c.AliasLink.Children)
.SingleOrDefaultAsync(c => c.NetworkId == entityAttribute);
return await _getUniqueQuery(context, entityAttribute);
}
}
@ -219,7 +223,7 @@ namespace SharedLibraryCore.Services
}
}
#region ServiceSpecific
#region ServiceSpecific
public async Task<IList<EFClient>> GetOwners()
{
using (var context = new DatabaseContext())
@ -228,32 +232,24 @@ namespace SharedLibraryCore.Services
.ToListAsync();
}
public async Task<bool> IsAuthenticated(int clientIP)
public async Task<IList<ClientInfo>> GetPrivilegedClients()
{
using (var context = new DatabaseContext())
using (var context = new DatabaseContext(disableTracking: true))
{
var iqMatching = from alias in context.Aliases
where alias.IPAddress == clientIP
join client in context.Clients
on alias.LinkId equals client.AliasLinkId
where client.Level > Player.Permission.Trusted
select client;
return (await iqMatching.CountAsync()) > 0;
}
}
public async Task<IList<EFClient>> GetPrivilegedClients()
{
using (var context = new DatabaseContext())
{
context.ChangeTracker.AutoDetectChangesEnabled = false;
context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
var iqClients = from client in context.Clients
.Include(c => c.CurrentAlias)
where client.Level >= Player.Permission.Trusted
select client;
where client.Active
select new ClientInfo()
{
ClientId = client.ClientId,
Name = client.CurrentAlias.Name,
LinkId = client.AliasLinkId,
Level = client.Level
};
#if DEBUG == true
var clientsSql = iqClients.ToSql();
#endif
return await iqClients.ToListAsync();
}
@ -356,6 +352,6 @@ namespace SharedLibraryCore.Services
using (var context = new DatabaseContext())
return await context.Clients.SumAsync(c => c.TotalConnectionTime);
}
#endregion
#endregion
}
}

View File

@ -507,6 +507,14 @@ namespace SharedLibraryCore
return response.FirstOrDefault(r => r[0] == '\\')?.DictionaryFromKeyValue();
}
public static double GetVersionAsDouble()
{
string version = Assembly.GetCallingAssembly().GetName().Version.ToString();
version = version.Replace(".", "");
return double.Parse(version) / 1000.0;
}
public static string GetVersionAsString() => Assembly.GetCallingAssembly().GetName().Version.ToString();
#if DEBUG == true
@ -530,7 +538,7 @@ namespace SharedLibraryCore
var queryCompilationContext = databaseDependencies.QueryCompilationContextFactory.Create(false);
var modelVisitor = (RelationalQueryModelVisitor)queryCompilationContext.CreateQueryModelVisitor();
modelVisitor.CreateQueryExecutor<TEntity>(queryModel);
var sql = modelVisitor.Queries.First().ToString();
var sql = modelVisitor.Queries.First().ToString().Replace("\"", "`");
return sql;
}