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 a786541484
commit 98adfb12d2
11 changed files with 102 additions and 68 deletions

View File

@ -5,7 +5,7 @@
<TargetFramework>netcoreapp2.1</TargetFramework>
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
<PackageId>RaidMax.IW4MAdmin.Application</PackageId>
<Version>2.1.9</Version>
<Version>2.1.9.1</Version>
<Authors>RaidMax</Authors>
<Company>Forever None</Company>
<Product>IW4MAdmin</Product>

View File

@ -171,7 +171,7 @@
},
{
"Alias": "IW4 Credits",
"Alias": "Test map",
"Name": "iw4_credits"
},
@ -190,6 +190,11 @@
"Name": "mp_cargoship_sh"
},
{
"Alias": "Cargoship",
"Name": "mp_cargoship"
},
{
"Alias": "Shipment",
"Name": "mp_shipment"
@ -216,23 +221,43 @@
},
{
"Alias": "Favela - Tropical",
"Alias": "Tropical Favela",
"Name": "mp_fav_tropical"
},
{
"Alias": "Estate - Tropical",
"Alias": "Tropical Estate",
"Name": "mp_estate_tropical"
},
{
"Alias": "Crash - Tropical",
"Alias": "Tropical Crash",
"Name": "mp_crash_tropical"
},
{
"Alias": "Forgotten City",
"Name": "mp_bloc_sh"
},
{
"Alias": "Crossfire",
"Name": "mp_cross_fire"
},
{
"Alias": "Bloc",
"Name": "mp_bloc"
},
{
"Alias": "Oilrig",
"Name": "oilrig"
},
{
"Name": "Village",
"Alias": "co_hunted"
}
]
},

View File

@ -18,23 +18,23 @@ namespace IW4MAdmin.Application
{
Manager = mgr;
OutOfOrderEvents = new SortedList<long, GameEvent>();
IsProcessingEvent = new SemaphoreSlim(2, 2);
IsProcessingEvent = new SemaphoreSlim(1, 1);
}
public void AddEvent(GameEvent gameEvent)
{
IsProcessingEvent.Wait();
// IsProcessingEvent.Wait();
((Manager as ApplicationManager).OnServerEvent)(this, new GameEventArgs(null, false, gameEvent));
if (gameEvent.Type == GameEvent.EventType.Connect)
{
IsProcessingEvent.Wait();
if (!gameEvent.OnProcessed.Wait(30 * 1000))
{
Manager.GetLogger().WriteError($"{Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_COMMAND_TIMEOUT"]} [{gameEvent.Id}, {gameEvent.Type}]");
}
IsProcessingEvent.Release(1);
}
IsProcessingEvent.Release(1);
// IsProcessingEvent.Release(1);
//if (gameEvent.Type == GameEvent.EventType.Connect)
//{
// IsProcessingEvent.Wait();
// if (!gameEvent.OnProcessed.Wait(10 * 1000))
// {
// Manager.GetLogger().WriteError($"{Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_COMMAND_TIMEOUT"]} [{gameEvent.Id}, {gameEvent.Type}]");
// }
// IsProcessingEvent.Release(1);
//}
return;
#if DEBUG

View File

@ -23,20 +23,16 @@ namespace IW4MAdmin.Application
public static void Main(string[] args)
{
AppDomain.CurrentDomain.SetData("DataDirectory", OperatingDirectory);
//System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.BelowNormal;
Console.OutputEncoding = Encoding.UTF8;
Console.ForegroundColor = ConsoleColor.Gray;
Version = Assembly.GetExecutingAssembly().GetName().Version.Major +
Assembly.GetExecutingAssembly().GetName().Version.Minor / 10.0f +
Assembly.GetExecutingAssembly().GetName().Version.Build / 100.0f;
Version = Math.Round(Version, 3);
Version = Utilities.GetVersionAsDouble();
Console.WriteLine("=====================================================");
Console.WriteLine(" IW4M ADMIN");
Console.WriteLine(" by RaidMax ");
Console.WriteLine($" Version {Version.ToString("0.00")}");
Console.WriteLine($" Version {Utilities.GetVersionAsString()}");
Console.WriteLine("=====================================================");
Index loc = null;
@ -111,7 +107,7 @@ namespace IW4MAdmin.Application
var consoleTask = Task.Run(async () =>
{
String userInput;
Player Origin = ServerManager.GetClientService().Get(1).Result.AsPlayer();
Player Origin = Utilities.IW4MAdminClient;
do
{

View File

@ -263,6 +263,7 @@ namespace IW4MAdmin.Application
await new ContextSeed(db).Seed();
}
// todo: optimize this
var ipList = (await ClientSvc.Find(c => c.Level > Player.Permission.Trusted))
.Select(c => new
{

View File

@ -206,7 +206,7 @@ namespace IW4MAdmin
if (currentBan != null)
{
Logger.WriteInfo($"Banned client {player} trying to connect...");
var autoKickClient = (await Manager.GetClientService().Get(1)).AsPlayer();
var autoKickClient = Utilities.IW4MAdminClient;
autoKickClient.CurrentServer = this;
// the player is permanently banned
@ -847,7 +847,7 @@ namespace IW4MAdmin
{
if (Target.Warnings >= 4)
{
await Target.Kick(loc["SERVER_WARNLIMT_REACHED"], (await Manager.GetClientService().Get(1)).AsPlayer());
await Target.Kick(loc["SERVER_WARNLIMT_REACHED"], Utilities.IW4MAdminClient);
return;
}

View File

@ -4,9 +4,15 @@ var plugin = {
name: 'Shared GUID Kicker Plugin',
onEventAsync: function (gameEvent, server) {
// connect event
// make sure we only check for IW4(x)
if (server.GameName !== 2) {
return false;
}
// connect or join event
if (gameEvent.Type === 3 ||
gameEvent.Type === 4) {
// this GUID seems to have been packed in a IW4 torrent and results in an unreasonable amount of people using the same GUID
if (gameEvent.Origin.NetworkId === -805366929435212061) {
gameEvent.Origin.Kick('Your GUID is generic. Delete players/guids.dat and rejoin', _IW4MAdminClient);
}

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
}
}
public async Task<EFClient> GetUnique(long entityAttribute)
{
using (var context = new DatabaseContext())
{
return await context.Clients
.AsNoTracking()
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)
.SingleOrDefaultAsync(c => c.NetworkId == entityAttribute);
.FirstOrDefault(c => c.NetworkId == networkId)
);
public async Task<EFClient> GetUnique(long entityAttribute)
{
using (var context = new DatabaseContext(true))
{
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;
}

View File

@ -119,9 +119,8 @@ namespace WebfrontCore.Controllers
public async Task<IActionResult> PrivilegedAsync()
{
var admins = (await Manager.GetClientService().GetPrivilegedClients())
.Where(a => a.Active)
.OrderByDescending(a => a.Level).ThenByDescending(a => a.LastConnection)
.GroupBy(a => a.AliasLinkId).Select(a => a.First());
.OrderByDescending(a => a.Level)
.GroupBy(a => a.LinkId).Select(a => a.First());
var adminsDict = new Dictionary<SharedLibraryCore.Objects.Player.Permission, IList<ClientInfo>>();