fix bug with wrong locale when master is down

fix issue with reapplying penalties
show subset of penalties that are linked on client profile
This commit is contained in:
RaidMax 2019-06-28 16:57:01 -05:00
parent 3d468e32b9
commit 042327840f
5 changed files with 35 additions and 15 deletions

View File

@ -58,7 +58,7 @@ namespace IW4MAdmin.Application
{
ServerManager = ApplicationManager.GetInstance();
var configuration = ServerManager.GetApplicationSettings().Configuration();
Localization.Configure.Initialize(configuration?.EnableCustomLocale ?? false ? (configuration.CustomLocale ?? "windows-1252") : "windows-1252");
Localization.Configure.Initialize(configuration?.EnableCustomLocale ?? false ? (configuration.CustomLocale ?? "en-US") : "en-US");
// do any needed housekeeping file/folder migrations
ConfigurationMigration.MoveConfigFolder10518(null);

View File

@ -162,6 +162,14 @@ namespace IW4MAdmin.Application.RconParsers
State = EFClient.ClientState.Connecting
};
#if DEBUG
if (client.NetworkId < 1000)
{
client.IPAddress = 2147483646;
client.Ping = 0;
}
#endif
StatusPlayers.Add(client);
}
}

View File

@ -552,7 +552,7 @@ namespace SharedLibraryCore.Database.Models
// we want to get any penalties that are tied to their IP or AliasLink (but not necessarily their GUID)
var activePenalties = await CurrentServer.Manager.GetPenaltyService().GetActivePenaltiesAsync(AliasLinkId, ipAddress);
var banPenalty = ReceivedPenalties.FirstOrDefault(_penalty => _penalty.Type == EFPenalty.PenaltyType.Ban);
var banPenalty = activePenalties.FirstOrDefault(_penalty => _penalty.Type == EFPenalty.PenaltyType.Ban);
var tempbanPenalty = activePenalties.FirstOrDefault(_penalty => _penalty.Type == EFPenalty.PenaltyType.TempBan);
var flagPenalty = activePenalties.FirstOrDefault(_penalty => _penalty.Type == EFPenalty.PenaltyType.Flag);
@ -568,8 +568,9 @@ namespace SharedLibraryCore.Database.Models
else
{
CurrentServer.Logger.WriteWarning($"Client {this} is GUID banned, but no previous penalty exists for their ban");
Ban(loc["SERVER_BAN_UNKNOWN"], autoKickClient, false);
CurrentServer.Logger.WriteDebug($"Client {this} is banned, but using a new GUID, we we're updating their level and kicking them");
await SetLevel(Permission.Banned, autoKickClient).WaitAsync(Utilities.DefaultCommandTimeout, CurrentServer.Manager.CancellationToken);
Kick(loc["SERVER_BAN_PREV"].FormatExt(banPenalty?.Offense), autoKickClient);
return false;
}
}
@ -585,7 +586,8 @@ namespace SharedLibraryCore.Database.Models
// if we found a flag, we need to make sure all the accounts are flagged
if (flagPenalty != null && Level != Permission.Flagged)
{
SetLevel(Permission.Flagged, autoKickClient);
CurrentServer.Logger.WriteDebug($"Flagged client {this} joining with new GUID, so we are changing their level to flagged");
await SetLevel(Permission.Flagged, autoKickClient).WaitAsync(Utilities.DefaultCommandTimeout, CurrentServer.Manager.CancellationToken);
}
// remove their auto flag

View File

@ -104,6 +104,8 @@ namespace SharedLibraryCore.Services
/// <returns></returns>
public async Task<IList<PenaltyInfo>> GetClientPenaltyForMetaAsync(int clientId, int count, int offset, DateTime? startAt)
{
var linkedPenaltyType = Utilities.LinkedPenaltyTypes();
using (var ctx = new DatabaseContext(true))
{
var linkId = await ctx.Clients.AsNoTracking()
@ -112,7 +114,7 @@ namespace SharedLibraryCore.Services
.FirstOrDefaultAsync();
var iqPenalties = ctx.Penalties.AsNoTracking()
.Where(_penalty => _penalty.OffenderId == clientId || _penalty.PunisherId == clientId || _penalty.LinkId == linkId)
.Where(_penalty => _penalty.OffenderId == clientId || _penalty.PunisherId == clientId || (linkedPenaltyType.Contains(_penalty.Type) && _penalty.LinkId == linkId))
.Where(_penalty => _penalty.When <= startAt)
.OrderByDescending(_penalty => _penalty.When)
.Skip(offset)
@ -136,8 +138,7 @@ namespace SharedLibraryCore.Services
#if DEBUG == true
var querySql = iqPenalties.ToSql();
#endif
return await iqPenalties.ToListAsync();
return await iqPenalties.Distinct().ToListAsync();
}
}

View File

@ -31,7 +31,6 @@ namespace SharedLibraryCore
public static Encoding EncodingType;
public static Localization.Layout CurrentLocalization = new Localization.Layout(new Dictionary<string, string>());
public static TimeSpan DefaultCommandTimeout = new TimeSpan(0, 0, 10);
public static CultureInfo BestCulture = CultureInfo.CreateSpecificCulture("en-US");
public static EFClient IW4MAdminClient(Server server = null)
{
@ -295,6 +294,9 @@ namespace SharedLibraryCore
else if (!string.IsNullOrEmpty(bot))
{
id = -1;
#if DEBUG
id = str.Sum(_c => _c);
#endif
}
if (id == 0)
@ -492,13 +494,20 @@ namespace SharedLibraryCore
return "unknown";
}
public static bool ShouldPenaltyApplyToAllProfiles(this PenaltyType penaltyType)
/// <summary>
/// returns a list of penalty types that should be shown across all profiles
/// </summary>
/// <returns></returns>
public static PenaltyType[] LinkedPenaltyTypes()
{
return penaltyType == PenaltyType.Ban ||
penaltyType == PenaltyType.Unban ||
penaltyType == PenaltyType.Flag ||
penaltyType == PenaltyType.Unflag ||
penaltyType == PenaltyType.TempBan;
return new PenaltyType[]
{
PenaltyType.Ban,
PenaltyType.Unban,
PenaltyType.TempBan,
PenaltyType.Flag,
PenaltyType.Unflag,
};
}
/// <summary>