upgrade packages, and delete a few unneeded ones

fix search for client resulting in invalid GUID parse
simplify output from dvar not being found
make sure to prompt if not all servers could be reached
This commit is contained in:
RaidMax 2019-05-03 20:13:51 -05:00
parent b51af7ca9a
commit db11a5f480
15 changed files with 66 additions and 102 deletions

View File

@ -25,7 +25,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="RestEase" Version="1.4.7" />
<PackageReference Include="RestEase" Version="1.4.9" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.5.1" />
</ItemGroup>

View File

@ -341,9 +341,7 @@ namespace IW4MAdmin.Application
GetApplicationSettings().Configuration()?.DatabaseProvider))
{
await new ContextSeed(db).Seed();
}
PrivilegedClients = (await ClientSvc.GetPrivilegedClients()).ToDictionary(_client => _client.ClientId);
}
#endregion
#region COMMANDS
@ -520,14 +518,12 @@ namespace IW4MAdmin.Application
#endregion
#region INIT
int failedServers = 0;
int successServers = 0;
Exception lastException = null;
async Task Init(ServerConfiguration Conf)
{
// setup the event handler after the class is initialized
Handler = new GameEventHandler(this);
try
@ -560,22 +556,21 @@ namespace IW4MAdmin.Application
if (e.GetType() == typeof(DvarException))
{
Logger.WriteDebug($"{Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_DVAR"].FormatExt((e as DvarException).Data["dvar_name"])} ({Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_DVAR_HELP"]})");
Logger.WriteDebug($"{e.Message} {(e.GetType() == typeof(DvarException) ? $"({Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_DVAR_HELP"]})" : "")}");
}
else if (e.GetType() == typeof(NetworkException))
{
Logger.WriteDebug(e.Message);
}
failedServers++;
lastException = e;
}
}
await Task.WhenAll(config.Servers.Select(c => Init(c)).ToArray());
if (successServers - failedServers <= 0)
if (successServers == 0)
{
throw lastException;
}
if (successServers != config.Servers.Count)
{
if (!Utilities.PromptBool(Utilities.CurrentLocalization.LocalizationIndex["MANAGER_START_WITH_ERRORS"]))
{
@ -731,8 +726,6 @@ namespace IW4MAdmin.Application
return ConfigHandler;
}
public IDictionary<int, EFClient> PrivilegedClients { get; private set; }
public bool ShutdownRequested()
{
return !Running;

View File

@ -200,26 +200,6 @@ namespace IW4MAdmin
if (E.Type == GameEvent.EventType.ChangePermission)
{
var newPermission = (Permission)E.Extra;
if (newPermission < Permission.Moderator &&
!Manager.PrivilegedClients.Remove(E.Target.ClientId, out _))
{
Logger.WriteWarning($"Could not remove {E.Target}-{newPermission} from privileged users");
}
else
{
if (Manager.PrivilegedClients.ContainsKey(E.Target.ClientId))
{
Manager.PrivilegedClients[E.Target.ClientId] = E.Target;
}
else if (!Manager.PrivilegedClients.TryAdd(E.Target.ClientId, E.Target))
{
Logger.WriteWarning($"Could not add {E.Target}-{newPermission} to privileged clients");
}
}
Logger.WriteInfo($"{E.Origin} is setting {E.Target} to permission level {newPermission}");
await Manager.GetClientService().UpdateLevel(newPermission, E.Target, E.Origin);
}

View File

@ -66,22 +66,13 @@ namespace IW4MAdmin.Application.RconParsers
{
string[] lineSplit = await connection.SendQueryAsync(StaticHelpers.QueryType.GET_DVAR, dvarName);
string response = string.Join('\n', lineSplit.Skip(1));
if (!lineSplit[0].Contains(Configuration.CommandPrefixes.RConResponse))
{
throw new DvarException($"Could not retrieve DVAR \"{dvarName}\"");
}
if (response.Contains("Unknown command"))
{
throw new DvarException($"DVAR \"{dvarName}\" does not exist");
}
var match = Regex.Match(response, Configuration.Dvar.Pattern);
if (!match.Success)
if (!lineSplit[0].Contains(Configuration.CommandPrefixes.RConResponse) ||
response.Contains("Unknown command") ||
!match.Success)
{
throw new DvarException($"Could not retrieve DVAR \"{dvarName}\"");
throw new DvarException(Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_DVAR"].FormatExt(dvarName));
}
string value = match.Groups[Configuration.Dvar.GroupMapping[ParserRegex.GroupType.RConDvarValue]].Value.StripColors();
@ -91,9 +82,9 @@ namespace IW4MAdmin.Application.RconParsers
return new Dvar<T>()
{
Name = match.Groups[Configuration.Dvar.GroupMapping[ParserRegex.GroupType.RConDvarName]].Value.StripColors(),
Value = string.IsNullOrEmpty(value) ? default(T) : (T)Convert.ChangeType(value, typeof(T)),
DefaultValue = string.IsNullOrEmpty(defaultValue) ? default(T) : (T)Convert.ChangeType(defaultValue, typeof(T)),
LatchedValue = string.IsNullOrEmpty(latchedValue) ? default(T) : (T)Convert.ChangeType(latchedValue, typeof(T)),
Value = string.IsNullOrEmpty(value) ? default : (T)Convert.ChangeType(value, typeof(T)),
DefaultValue = string.IsNullOrEmpty(defaultValue) ? default : (T)Convert.ChangeType(defaultValue, typeof(T)),
LatchedValue = string.IsNullOrEmpty(latchedValue) ? default : (T)Convert.ChangeType(latchedValue, typeof(T)),
Domain = match.Groups[Configuration.Dvar.GroupMapping[ParserRegex.GroupType.RConDvarDomain]].Value.StripColors()
};
}

View File

@ -18,13 +18,12 @@ namespace IW4MAdmin.Plugins.Login.Commands
public override async Task ExecuteAsync(GameEvent E)
{
var client = E.Owner.Manager.PrivilegedClients[E.Origin.ClientId];
bool success = E.Owner.Manager.TokenAuthenticator.AuthorizeToken(E.Origin.NetworkId, E.Data);
if (!success)
{
string[] hashedPassword = await Task.FromResult(SharedLibraryCore.Helpers.Hashing.Hash(E.Data, client.PasswordSalt));
success = hashedPassword[0] == client.Password;
string[] hashedPassword = await Task.FromResult(SharedLibraryCore.Helpers.Hashing.Hash(E.Data, E.Origin.PasswordSalt));
success = hashedPassword[0] == E.Origin.Password;
}
if (success)

View File

@ -42,10 +42,8 @@ namespace IW4MAdmin.Plugins.Login
E.Origin.Level == EFClient.Permission.Console)
return Task.CompletedTask;
E.Owner.Manager.PrivilegedClients.TryGetValue(E.Origin.ClientId, out EFClient client);
if (((Command)E.Extra).Name == new SharedLibraryCore.Commands.CSetPassword().Name &&
client?.Password == null)
E.Origin?.Password == null)
return Task.CompletedTask;
if (((Command)E.Extra).Name == new Commands.CLogin().Name)

View File

@ -257,18 +257,18 @@ namespace IW4MAdmin.Plugins.Stats.Cheat
// ban on bone ratio
if (currentMaxBoneRatio > maxBoneRatioLerpValueForBan)
{
Log.WriteDebug("**Maximum Bone Ratio Reached For Ban**");
Log.WriteDebug($"ClientId: {hit.AttackerId}");
Log.WriteDebug($"**HitCount: {HitCount}");
Log.WriteDebug($"**Ratio {currentMaxBoneRatio}");
Log.WriteDebug($"**MaxRatio {maxBoneRatioLerpValueForBan}");
var sb = new StringBuilder();
foreach (var kvp in HitLocationCount)
{
sb.Append($"HitLocation: {kvp.Key} -> {kvp.Value}\r\n");
}
//Log.WriteDebug("**Maximum Bone Ratio Reached For Ban**");
//Log.WriteDebug($"ClientId: {hit.AttackerId}");
//Log.WriteDebug($"**HitCount: {HitCount}");
//Log.WriteDebug($"**Ratio {currentMaxBoneRatio}");
//Log.WriteDebug($"**MaxRatio {maxBoneRatioLerpValueForBan}");
//var sb = new StringBuilder();
//foreach (var kvp in HitLocationCount)
//{
// sb.Append($"HitLocation: {kvp.Key} -> {kvp.Value}\r\n");
//}
Log.WriteDebug(sb.ToString());
//Log.WriteDebug(sb.ToString());
result = new DetectionPenaltyResult()
{
@ -281,18 +281,18 @@ namespace IW4MAdmin.Plugins.Stats.Cheat
}
else
{
Log.WriteDebug("**Maximum Bone Ratio Reached For Flag**");
Log.WriteDebug($"ClientId: {hit.AttackerId}");
Log.WriteDebug($"**HitCount: {HitCount}");
Log.WriteDebug($"**Ratio {currentMaxBoneRatio}");
Log.WriteDebug($"**MaxRatio {maxBoneRatioLerpValueForFlag}");
var sb = new StringBuilder();
foreach (var kvp in HitLocationCount)
{
sb.Append($"HitLocation: {kvp.Key} -> {kvp.Value}\r\n");
}
//Log.WriteDebug("**Maximum Bone Ratio Reached For Flag**");
//Log.WriteDebug($"ClientId: {hit.AttackerId}");
//Log.WriteDebug($"**HitCount: {HitCount}");
//Log.WriteDebug($"**Ratio {currentMaxBoneRatio}");
//Log.WriteDebug($"**MaxRatio {maxBoneRatioLerpValueForFlag}");
//var sb = new StringBuilder();
//foreach (var kvp in HitLocationCount)
//{
// sb.Append($"HitLocation: {kvp.Key} -> {kvp.Value}\r\n");
//}
Log.WriteDebug(sb.ToString());
//Log.WriteDebug(sb.ToString());
result = new DetectionPenaltyResult()
{

View File

@ -13,7 +13,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.2" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>

View File

@ -1119,8 +1119,8 @@ namespace SharedLibraryCore.Commands
E.Origin.PasswordSalt = hashedPassword[1];
// update the password for the client in privileged
E.Owner.Manager.PrivilegedClients[E.Origin.ClientId].Password = hashedPassword[0];
E.Owner.Manager.PrivilegedClients[E.Origin.ClientId].PasswordSalt = hashedPassword[1];
//E.Owner.Manager.PrivilegedClients[E.Origin.ClientId].Password = hashedPassword[0];
//E.Owner.Manager.PrivilegedClients[E.Origin.ClientId].PasswordSalt = hashedPassword[1];
await E.Owner.Manager.GetClientService().Update(E.Origin);
E.Origin.Tell(Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_PASSWORD_SUCCESS"]);

View File

@ -24,7 +24,6 @@ namespace SharedLibraryCore.Interfaces
ClientService GetClientService();
AliasService GetAliasService();
PenaltyService GetPenaltyService();
IDictionary<int, EFClient> PrivilegedClients { get; }
/// <summary>
/// Get the event handlers
/// </summary>

View File

@ -413,7 +413,7 @@ namespace SharedLibraryCore.Services
}
}
public async Task<List<EFClient>> GetPrivilegedClients()
public async Task<List<EFClient>> GetPrivilegedClients(bool includeName = true)
{
using (var context = new DatabaseContext(disableTracking: true))
{
@ -451,7 +451,13 @@ namespace SharedLibraryCore.Services
using (var context = new DatabaseContext(disableTracking: true))
{
long networkId = identifier.ConvertGuidToLong();
long? networkId = null;
try
{
networkId = identifier.ConvertGuidToLong();
}
catch { }
int? ipAddress = identifier.ConvertToIP();
IQueryable<EFAlias> iqLinkIds = context.Aliases.Where(_alias => _alias.Active);
@ -477,10 +483,11 @@ namespace SharedLibraryCore.Services
var iqClients = context.Clients
.Where(_client => _client.Active);
if (networkId != long.MinValue)
if (networkId.HasValue)
{
iqClients = iqClients.Where(_client => networkId == _client.NetworkId);
iqClients = iqClients.Where(_client => networkId.Value == _client.NetworkId);
}
else
{
iqClients = iqClients.Where(_client => linkIds.Contains(_client.AliasLinkId));

View File

@ -24,9 +24,9 @@
<ItemGroup>
<PackageReference Include="Jint" Version="2.11.58" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.2">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
@ -35,8 +35,8 @@
<PackageReference Include="Microsoft.Extensions.Localization" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="Npgsql" Version="4.0.4" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="Npgsql" Version="4.0.6" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.2.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0" />
<PackageReference Include="SimpleCrypto.NetCore" Version="1.0.0" />

View File

@ -299,7 +299,7 @@ namespace SharedLibraryCore
public static int? ConvertToIP(this string str)
{
bool success = System.Net.IPAddress.TryParse(str, out System.Net.IPAddress ip);
bool success = IPAddress.TryParse(str, out IPAddress ip);
return success && ip.GetAddressBytes().Count(_byte => _byte == 0) != 4 ?
(int?)BitConverter.ToInt32(ip.GetAddressBytes(), 0) :
null;
@ -307,7 +307,7 @@ namespace SharedLibraryCore
public static string ConvertIPtoString(this int? ip)
{
return !ip.HasValue ? "" : new System.Net.IPAddress(BitConverter.GetBytes(ip.Value)).ToString();
return !ip.HasValue ? "" : new IPAddress(BitConverter.GetBytes(ip.Value)).ToString();
}
public static string GetTimePassed(DateTime start)

View File

@ -25,7 +25,7 @@ namespace WebfrontCore.Controllers
try
{
var privilegedClient = Manager.PrivilegedClients[clientId];
var privilegedClient = await Manager.GetClientService().Get(clientId);
bool loginSuccess = Manager.TokenAuthenticator.AuthorizeToken(privilegedClient.NetworkId, password) ||
(await Task.FromResult(SharedLibraryCore.Helpers.Hashing.Hash(password, privilegedClient.PasswordSalt)))[0] == privilegedClient.Password;

View File

@ -65,7 +65,7 @@
<ItemGroup>
<PackageReference Include="Bower" Version="1.3.11" />
<PackageReference Include="BuildBundlerMinifier" Version="2.8.391" />
<PackageReference Include="BuildBundlerMinifier" Version="2.9.406" />
<PackageReference Include="Microsoft.AspNetCore" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.2.0" />
@ -75,14 +75,12 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.0">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0" />
<PackageReference Update="Microsoft.NETCore.App" Version="2.2.2" />
<PackageReference Update="Microsoft.AspNetCore" Version="2.2.0" />
</ItemGroup>