mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-09 23:00:57 -05:00
adding Cod4 support (for steam GUID is truncated to 16 characters)
exit properly whoops add all linked accounts to drop down consolidate linked admin accounts to the most recently seen one limited some waits to 5s to hopefully prevent a rare thread lock
This commit is contained in:
@ -387,7 +387,7 @@ namespace SharedLibraryCore.Commands
|
||||
await E.Owner.Broadcast($"{Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_MAPROTATE"]} [^5{E.Origin.Name}^7]");
|
||||
else
|
||||
await E.Owner.Broadcast(Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_MAPROTATE"]);
|
||||
Task.Delay(5000).Wait();
|
||||
await Task.Delay(5000);
|
||||
await E.Owner.ExecuteCommandAsync("map_rotate");
|
||||
}
|
||||
}
|
||||
@ -553,14 +553,14 @@ namespace SharedLibraryCore.Commands
|
||||
if (m.Name.ToLower() == newMap || m.Alias.ToLower() == newMap)
|
||||
{
|
||||
await E.Owner.Broadcast($"{Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_MAP_SUCCESS"]} ^5{m.Alias}");
|
||||
Task.Delay(5000).Wait();
|
||||
await Task.Delay(5000);
|
||||
await E.Owner.LoadMap(m.Name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
await E.Owner.Broadcast($"{Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_MAP_UKN"]} ^5{newMap}");
|
||||
Task.Delay(5000).Wait();
|
||||
await Task.Delay(5000);
|
||||
await E.Owner.LoadMap(newMap);
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +50,8 @@ namespace SharedLibraryCore.Database.Models
|
||||
|
||||
[NotMapped]
|
||||
public string IPAddressString => new System.Net.IPAddress(BitConverter.GetBytes(IPAddress)).ToString();
|
||||
[NotMapped]
|
||||
public virtual IDictionary<int, long> LinkedAccounts { get; set; }
|
||||
|
||||
public virtual ICollection<EFPenalty> ReceivedPenalties { get; set; }
|
||||
public virtual ICollection<EFPenalty> AdministeredPenalties { get; set; }
|
||||
|
@ -24,5 +24,6 @@ namespace SharedLibraryCore.Dtos
|
||||
public List<ProfileMeta> Meta { get; set; }
|
||||
public bool Online { get; set; }
|
||||
public string TimeOnline { get; set; }
|
||||
public IDictionary<int, long> LinkedAccounts { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ namespace SharedLibraryCore.Dtos
|
||||
public string GameType { get; set; }
|
||||
public int ClientCount { get; set; }
|
||||
public int MaxClients { get; set; }
|
||||
public ChatInfo[] ChatHistory { get; set; }
|
||||
public List<ChatInfo> ChatHistory { get; set; }
|
||||
public List<PlayerInfo> Players { get; set; }
|
||||
public Helpers.PlayerHistory[] PlayerHistory { get; set; }
|
||||
public int ID { get; set; }
|
||||
|
@ -33,25 +33,6 @@ namespace SharedLibraryCore.RCon
|
||||
}
|
||||
}
|
||||
|
||||
class ResponseEvent
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string[] Response { get; set; }
|
||||
public Task Awaiter
|
||||
{
|
||||
get
|
||||
{
|
||||
return Task.Run(() => FinishedEvent.Wait());
|
||||
}
|
||||
}
|
||||
private ManualResetEventSlim FinishedEvent;
|
||||
|
||||
public ResponseEvent()
|
||||
{
|
||||
FinishedEvent = new ManualResetEventSlim();
|
||||
}
|
||||
}
|
||||
|
||||
public class Connection
|
||||
{
|
||||
public IPEndPoint Endpoint { get; private set; }
|
||||
@ -110,7 +91,7 @@ namespace SharedLibraryCore.RCon
|
||||
OnSent.Set();
|
||||
}
|
||||
|
||||
catch (SocketException)
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -167,9 +148,9 @@ namespace SharedLibraryCore.RCon
|
||||
public async Task<string[]> SendQueryAsync(StaticHelpers.QueryType type, string parameters = "", bool waitForResponse = true)
|
||||
{
|
||||
// will this really prevent flooding?
|
||||
if ((DateTime.Now - LastQuery).TotalMilliseconds < 250)
|
||||
if ((DateTime.Now - LastQuery).TotalMilliseconds < 350)
|
||||
{
|
||||
await Task.Delay(250);
|
||||
await Task.Delay(350);
|
||||
}
|
||||
|
||||
LastQuery = DateTime.Now;
|
||||
|
@ -107,11 +107,33 @@ namespace SharedLibraryCore.Services
|
||||
{
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
return await context.Clients
|
||||
.AsNoTracking()
|
||||
.Include(c => c.CurrentAlias)
|
||||
.Include(c => c.AliasLink.Children)
|
||||
.SingleOrDefaultAsync(e => e.ClientId == entityID);
|
||||
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)
|
||||
where client.ClientId == entityID
|
||||
select new
|
||||
{
|
||||
Client = client,
|
||||
LinkedAccounts = (from linkedClient in context.Clients
|
||||
where client.AliasLinkId == linkedClient.AliasLinkId
|
||||
select new
|
||||
{
|
||||
linkedClient.ClientId,
|
||||
linkedClient.NetworkId
|
||||
})
|
||||
};
|
||||
var foundClient = await iqClient.FirstOrDefaultAsync();
|
||||
|
||||
foundClient.Client.LinkedAccounts = new Dictionary<int, long>();
|
||||
// todo: find out the best way to do this
|
||||
// I'm doing this here because I don't know the best way to have multiple awaits in the query
|
||||
foreach (var linked in foundClient.LinkedAccounts)
|
||||
foundClient.Client.LinkedAccounts.Add(linked.ClientId, linked.NetworkId);
|
||||
|
||||
return foundClient.Client;
|
||||
}
|
||||
}
|
||||
|
||||
@ -216,11 +238,15 @@ namespace SharedLibraryCore.Services
|
||||
{
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
return await context.Clients
|
||||
.AsNoTracking()
|
||||
.Include(c => c.CurrentAlias)
|
||||
.Where(c => c.Level >= Player.Permission.Trusted)
|
||||
.ToListAsync();
|
||||
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;
|
||||
|
||||
return await iqClients.ToListAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@ -233,14 +259,14 @@ namespace SharedLibraryCore.Services
|
||||
{
|
||||
var iqClients = (from alias in context.Aliases
|
||||
.AsNoTracking()
|
||||
where alias.Name.ToLower()
|
||||
.Contains(name.ToLower())
|
||||
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)
|
||||
where alias.Name.ToLower()
|
||||
.Contains(name.ToLower())
|
||||
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);
|
||||
@ -255,13 +281,13 @@ namespace SharedLibraryCore.Services
|
||||
{
|
||||
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)
|
||||
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);
|
||||
|
@ -12,7 +12,7 @@ namespace SharedLibraryCore.Services
|
||||
// https://stackoverflow.com/questions/43677906/crud-operations-with-entityframework-using-generic-type
|
||||
public class GenericRepository<TEntity> where TEntity : class
|
||||
{
|
||||
private dynamic _context;
|
||||
private DatabaseContext _context;
|
||||
private DbSet<TEntity> _dbSet;
|
||||
|
||||
protected DbContext Context
|
||||
@ -101,7 +101,6 @@ namespace SharedLibraryCore.Services
|
||||
dbSet.Attach(entity);
|
||||
|
||||
dbSet.Remove(entity);
|
||||
|
||||
}
|
||||
|
||||
public virtual void Delete(TEntity entity)
|
||||
@ -119,7 +118,6 @@ namespace SharedLibraryCore.Services
|
||||
T entity = dbSet.Find(id);
|
||||
dbSet.Attach(entity);
|
||||
dbSet.Remove(entity);
|
||||
|
||||
}
|
||||
|
||||
public virtual void Delete(object id)
|
||||
|
@ -208,7 +208,8 @@ namespace SharedLibraryCore.Services
|
||||
Offense = penalty.Offense,
|
||||
Type = penalty.Type.ToString()
|
||||
},
|
||||
When = penalty.When
|
||||
When = penalty.When,
|
||||
Sensitive = penalty.Type == Penalty.PenaltyType.Flag
|
||||
};
|
||||
// fixme: is this good and fast?
|
||||
var list = await iqPenalties.ToListAsync();
|
||||
|
@ -182,6 +182,7 @@ namespace SharedLibraryCore
|
||||
|
||||
public static long ConvertLong(this string str)
|
||||
{
|
||||
str = str.Substring(0, Math.Min(str.Length, 16));
|
||||
if (Int64.TryParse(str, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out long id))
|
||||
return id;
|
||||
var bot = Regex.Match(str, @"bot[0-9]+").Value;
|
||||
|
Reference in New Issue
Block a user