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

prevent partial client updates from setting things they shouldn't be *cough* mask *cough*

setup shared library for NuGet package
fix a couple things with offset detection calc
get cod4x working again
This commit is contained in:
RaidMax
2019-06-13 19:10:08 -05:00
parent 48c86d8cf5
commit d35d569a99
8 changed files with 43 additions and 28 deletions

View File

@ -360,28 +360,36 @@ namespace SharedLibraryCore.Services
{
using (var context = new DatabaseContext())
{
if (temporalClient.LastConnection == DateTime.MinValue || temporalClient.FirstConnection == DateTime.MinValue)
{
throw new InvalidOperationException($"client {temporalClient} trying to update but parameters are invalid");
}
// grab the context version of the entity
var entity = context.Clients
.First(client => client.ClientId == temporalClient.ClientId);
if (entity.TotalConnectionTime > temporalClient.TotalConnectionTime || entity.Connections > temporalClient.Connections ||
entity.LastConnection > temporalClient.LastConnection || entity.FirstConnection > temporalClient.FirstConnection)
if (temporalClient.LastConnection > entity.LastConnection)
{
throw new InvalidOperationException($"client {temporalClient} trying to update but new parameters don't match saved parameters");
entity.LastConnection = temporalClient.LastConnection;
}
if (temporalClient.Connections > entity.Connections)
{
entity.Connections = temporalClient.Connections;
}
entity.LastConnection = temporalClient.LastConnection;
entity.Connections = temporalClient.Connections;
entity.FirstConnection = temporalClient.FirstConnection;
entity.Masked = temporalClient.Masked;
entity.TotalConnectionTime = temporalClient.TotalConnectionTime;
entity.Password = temporalClient.Password;
entity.PasswordSalt = temporalClient.PasswordSalt;
if (temporalClient.TotalConnectionTime > entity.TotalConnectionTime)
{
entity.TotalConnectionTime = temporalClient.TotalConnectionTime;
}
if (temporalClient.Password != null)
{
entity.Password = temporalClient.Password;
}
if (temporalClient.PasswordSalt != null)
{
entity.PasswordSalt = temporalClient.PasswordSalt;
}
// update in database
await context.SaveChangesAsync();