fix aliases for real (hopefully)
fix bug with flag not being applied fix level being set based on IP instead of IP and name
This commit is contained in:
parent
07ec5cf52f
commit
7b75c35c9b
@ -6,7 +6,7 @@
|
|||||||
<RuntimeFrameworkVersion>2.1.5</RuntimeFrameworkVersion>
|
<RuntimeFrameworkVersion>2.1.5</RuntimeFrameworkVersion>
|
||||||
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
|
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
|
||||||
<PackageId>RaidMax.IW4MAdmin.Application</PackageId>
|
<PackageId>RaidMax.IW4MAdmin.Application</PackageId>
|
||||||
<Version>2.2.2.0</Version>
|
<Version>2.2.3.0</Version>
|
||||||
<Authors>RaidMax</Authors>
|
<Authors>RaidMax</Authors>
|
||||||
<Company>Forever None</Company>
|
<Company>Forever None</Company>
|
||||||
<Product>IW4MAdmin</Product>
|
<Product>IW4MAdmin</Product>
|
||||||
|
@ -34,6 +34,7 @@ namespace IW4MAdmin
|
|||||||
override public async Task OnClientConnected(EFClient clientFromLog)
|
override public async Task OnClientConnected(EFClient clientFromLog)
|
||||||
{
|
{
|
||||||
Logger.WriteDebug($"Client slot #{clientFromLog.ClientNumber} now reserved");
|
Logger.WriteDebug($"Client slot #{clientFromLog.ClientNumber} now reserved");
|
||||||
|
Clients[clientFromLog.ClientNumber] = new EFClient();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -50,8 +51,11 @@ namespace IW4MAdmin
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// this is only a temporary version until the IPAddress is transmitted
|
// this is only a temporary version until the IPAddress is transmitted
|
||||||
client.CurrentAlias.Active = false;
|
client.CurrentAlias = new EFAlias
|
||||||
client.CurrentAlias.Name = clientFromLog.Name;
|
{
|
||||||
|
Name = clientFromLog.Name,
|
||||||
|
IPAddress = clientFromLog.IPAddress
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.WriteInfo($"Client {client} connected...");
|
Logger.WriteInfo($"Client {client} connected...");
|
||||||
@ -65,11 +69,6 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
Clients[client.ClientNumber] = client;
|
Clients[client.ClientNumber] = client;
|
||||||
|
|
||||||
if (clientFromLog.IPAddress != null)
|
|
||||||
{
|
|
||||||
await client.OnJoin(clientFromLog.IPAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
client.State = EFClient.ClientState.Connected;
|
client.State = EFClient.ClientState.Connected;
|
||||||
#if DEBUG == true
|
#if DEBUG == true
|
||||||
Logger.WriteDebug($"End PreConnect for {client}");
|
Logger.WriteDebug($"End PreConnect for {client}");
|
||||||
@ -82,6 +81,11 @@ namespace IW4MAdmin
|
|||||||
};
|
};
|
||||||
|
|
||||||
Manager.GetEventHandler().AddEvent(e);
|
Manager.GetEventHandler().AddEvent(e);
|
||||||
|
|
||||||
|
if (client.IPAddress != null)
|
||||||
|
{
|
||||||
|
await client.OnJoin(client.IPAddress);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -297,7 +301,7 @@ namespace IW4MAdmin
|
|||||||
|
|
||||||
else if (E.Type == GameEvent.EventType.PreDisconnect)
|
else if (E.Type == GameEvent.EventType.PreDisconnect)
|
||||||
{
|
{
|
||||||
if ((DateTime.UtcNow - SessionStart).TotalSeconds < 10)
|
if ((DateTime.UtcNow - SessionStart).TotalSeconds < 30)
|
||||||
{
|
{
|
||||||
Logger.WriteInfo($"Cancelling pre disconnect for {E.Origin} as it occured too close to map end");
|
Logger.WriteInfo($"Cancelling pre disconnect for {E.Origin} as it occured too close to map end");
|
||||||
E.FailReason = GameEvent.EventFailReason.Invalid;
|
E.FailReason = GameEvent.EventFailReason.Invalid;
|
||||||
|
@ -8,7 +8,6 @@ using SharedLibraryCore.Objects;
|
|||||||
using SharedLibraryCore.Database;
|
using SharedLibraryCore.Database;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Collections.Generic;
|
|
||||||
using SharedLibraryCore.Localization;
|
using SharedLibraryCore.Localization;
|
||||||
using IW4MAdmin.Application.Migration;
|
using IW4MAdmin.Application.Migration;
|
||||||
|
|
||||||
@ -22,6 +21,7 @@ namespace IW4MAdmin.Application
|
|||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
AppDomain.CurrentDomain.SetData("DataDirectory", Utilities.OperatingDirectory);
|
||||||
Console.OutputEncoding = Encoding.UTF8;
|
Console.OutputEncoding = Encoding.UTF8;
|
||||||
Console.ForegroundColor = ConsoleColor.Gray;
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
|
|
||||||
|
@ -459,7 +459,10 @@ namespace SharedLibraryCore.Database.Models
|
|||||||
var loc = Utilities.CurrentLocalization.LocalizationIndex;
|
var loc = Utilities.CurrentLocalization.LocalizationIndex;
|
||||||
var autoKickClient = Utilities.IW4MAdminClient(CurrentServer);
|
var autoKickClient = Utilities.IW4MAdminClient(CurrentServer);
|
||||||
|
|
||||||
|
if (ipAddress != null)
|
||||||
|
{
|
||||||
await CurrentServer.Manager.GetClientService().UpdateAlias(this);
|
await CurrentServer.Manager.GetClientService().UpdateAlias(this);
|
||||||
|
}
|
||||||
|
|
||||||
OnConnect();
|
OnConnect();
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ namespace SharedLibraryCore.Services
|
|||||||
Name = entity.Name,
|
Name = entity.Name,
|
||||||
Link = client.AliasLink,
|
Link = client.AliasLink,
|
||||||
DateAdded = DateTime.UtcNow,
|
DateAdded = DateTime.UtcNow,
|
||||||
|
IPAddress = entity.IPAddress,
|
||||||
// the first time a client is created, we may not have their ip,
|
// the first time a client is created, we may not have their ip,
|
||||||
// so we create a temporary alias
|
// so we create a temporary alias
|
||||||
Active = false
|
Active = false
|
||||||
@ -52,15 +53,14 @@ namespace SharedLibraryCore.Services
|
|||||||
public async Task UpdateAlias(EFClient entity)
|
public async Task UpdateAlias(EFClient entity)
|
||||||
{
|
{
|
||||||
// todo: move this out
|
// todo: move this out
|
||||||
|
#if DEBUG == false
|
||||||
if (entity.IsBot)
|
if (entity.IsBot)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
using (var context = new DatabaseContext())
|
using (var context = new DatabaseContext())
|
||||||
{
|
{
|
||||||
context.Attach(entity);
|
|
||||||
|
|
||||||
string name = entity.Name;
|
string name = entity.Name;
|
||||||
int? ip = entity.IPAddress;
|
int? ip = entity.IPAddress;
|
||||||
|
|
||||||
@ -70,8 +70,8 @@ namespace SharedLibraryCore.Services
|
|||||||
// get all aliases by IP address and LinkId
|
// get all aliases by IP address and LinkId
|
||||||
var iqAliases = context.Aliases
|
var iqAliases = context.Aliases
|
||||||
.Include(a => a.Link)
|
.Include(a => a.Link)
|
||||||
.Where(a => a.Link.Active)
|
//.Where(a => a.Link.Active)
|
||||||
.Where(a => (a.IPAddress != null && a.IPAddress == ip) ||
|
.Where(a => (a.IPAddress == ip) ||
|
||||||
a.LinkId == entity.AliasLinkId);
|
a.LinkId == entity.AliasLinkId);
|
||||||
|
|
||||||
#if DEBUG == true
|
#if DEBUG == true
|
||||||
@ -100,7 +100,6 @@ namespace SharedLibraryCore.Services
|
|||||||
{
|
{
|
||||||
context.Update(entity);
|
context.Update(entity);
|
||||||
|
|
||||||
entity.CurrentAlias = existingAlias;
|
|
||||||
if (existingAlias.AliasId > 0)
|
if (existingAlias.AliasId > 0)
|
||||||
{
|
{
|
||||||
entity.CurrentAliasId = existingAlias.AliasId;
|
entity.CurrentAliasId = existingAlias.AliasId;
|
||||||
@ -109,36 +108,58 @@ namespace SharedLibraryCore.Services
|
|||||||
{
|
{
|
||||||
entity.CurrentServer.Logger.WriteDebug($"Updating alias for {entity} failed");
|
entity.CurrentServer.Logger.WriteDebug($"Updating alias for {entity} failed");
|
||||||
}
|
}
|
||||||
await context.SaveChangesAsync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!entity.CurrentAlias.Active)
|
||||||
|
{
|
||||||
|
existingAlias.Active = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity.CurrentAlias = existingAlias;
|
||||||
|
await context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
// theres no exact match, but they've played before with the GUID or IP
|
// theres no exact match, but they've played before with the GUID or IP
|
||||||
else if (hasExistingAlias)
|
else if (hasExistingAlias)
|
||||||
{
|
{
|
||||||
context.Update(entity);
|
|
||||||
entity.AliasLink = aliasLink;
|
|
||||||
entity.AliasLinkId = aliasLink.AliasLinkId;
|
|
||||||
|
|
||||||
// the current link is temporary so we need to update
|
// the current link is temporary so we need to update
|
||||||
if (!entity.AliasLink.Active)
|
if (!entity.AliasLink.Active)
|
||||||
{
|
{
|
||||||
entity.CurrentServer.Logger.WriteDebug($"{entity} has temporary alias so we are deleting");
|
entity.CurrentServer.Logger.WriteDebug($"{entity} has temporary alias so we are deleting");
|
||||||
|
|
||||||
|
foreach (var alias in aliases.Where(_alias => !_alias.Active))
|
||||||
|
{
|
||||||
|
context.Update(alias);
|
||||||
|
|
||||||
|
if (alias.IPAddress == null && alias.Name == name)
|
||||||
|
{
|
||||||
|
context.Entry(alias).State = EntityState.Deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
alias.Active = true;
|
||||||
|
alias.LinkId = aliasLink.AliasLinkId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// we want to delete the temporary alias link
|
// we want to delete the temporary alias link
|
||||||
context.Entry(entity.AliasLink).State = EntityState.Deleted;
|
context.Entry(entity.AliasLink).State = EntityState.Deleted;
|
||||||
entity.AliasLink = null;
|
|
||||||
await context.SaveChangesAsync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.Update(entity);
|
||||||
|
entity.AliasLink = aliasLink;
|
||||||
|
entity.AliasLinkId = aliasLink.AliasLinkId;
|
||||||
|
|
||||||
entity.CurrentServer.Logger.WriteDebug($"Connecting player is using a new alias {entity}");
|
entity.CurrentServer.Logger.WriteDebug($"Connecting player is using a new alias {entity}");
|
||||||
|
|
||||||
var newAlias = new EFAlias()
|
var newAlias = new EFAlias()
|
||||||
{
|
{
|
||||||
DateAdded = DateTime.UtcNow,
|
DateAdded = DateTime.UtcNow,
|
||||||
IPAddress = ip,
|
IPAddress = ip,
|
||||||
Link = aliasLink,
|
LinkId = aliasLink.AliasLinkId,
|
||||||
Name = name
|
Name = name,
|
||||||
|
Active = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
context.Aliases.Add(newAlias);
|
context.Aliases.Add(newAlias);
|
||||||
@ -151,27 +172,41 @@ namespace SharedLibraryCore.Services
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
entity.CurrentServer.Logger.WriteDebug($"{entity} has not be seen before");
|
entity.CurrentServer.Logger.WriteDebug($"{entity} has not be seen before");
|
||||||
|
|
||||||
|
if (name != entity.CurrentAlias.Name)
|
||||||
|
{
|
||||||
var newAlias = new EFAlias()
|
var newAlias = new EFAlias()
|
||||||
{
|
{
|
||||||
DateAdded = DateTime.UtcNow,
|
DateAdded = DateTime.UtcNow,
|
||||||
IPAddress = ip,
|
IPAddress = ip,
|
||||||
Link = entity.AliasLink,
|
LinkId = entity.AliasLink.AliasLinkId,
|
||||||
Name = name
|
Name = name,
|
||||||
|
Active = true
|
||||||
};
|
};
|
||||||
|
|
||||||
context.Update(entity);
|
context.Update(entity);
|
||||||
context.Update(entity.AliasLink);
|
|
||||||
|
|
||||||
entity.AliasLink.Active = true;
|
|
||||||
context.Aliases.Add(newAlias);
|
context.Aliases.Add(newAlias);
|
||||||
entity.CurrentAlias = newAlias;
|
entity.CurrentAlias = newAlias;
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.Update(entity.CurrentAlias);
|
||||||
|
entity.CurrentAlias.Active = true;
|
||||||
|
entity.CurrentAlias.IPAddress = ip;
|
||||||
|
entity.CurrentAlias.Link = entity.AliasLink;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.Update(entity.AliasLink);
|
||||||
|
entity.AliasLink.Active = true;
|
||||||
|
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
var linkIds = aliases.Select(a => a.LinkId);
|
var linkIds = aliases.Select(a => a.LinkId);
|
||||||
|
|
||||||
if (linkIds.Count() > 0)
|
if (linkIds.Count() > 0 &&
|
||||||
|
aliases.Count(_alias => _alias.Name == name && _alias.IPAddress == ip) > 0)
|
||||||
{
|
{
|
||||||
var highestLevel = await context.Clients
|
var highestLevel = await context.Clients
|
||||||
.Where(c => linkIds.Contains(c.AliasLinkId))
|
.Where(c => linkIds.Contains(c.AliasLinkId))
|
||||||
|
@ -55,7 +55,7 @@ namespace SharedLibraryCore.Services
|
|||||||
{
|
{
|
||||||
await context.Clients
|
await context.Clients
|
||||||
.Include(c => c.ReceivedPenalties)
|
.Include(c => c.ReceivedPenalties)
|
||||||
.Where(c => c.AliasLinkId == newEntity.LinkId)
|
.Where(c => c.AliasLinkId == newEntity.Link.AliasLinkId)
|
||||||
.ForEachAsync(c =>
|
.ForEachAsync(c =>
|
||||||
{
|
{
|
||||||
if (c.Level != Permission.Flagged)
|
if (c.Level != Permission.Flagged)
|
||||||
@ -81,7 +81,7 @@ namespace SharedLibraryCore.Services
|
|||||||
// we just want to add it to the database
|
// we just want to add it to the database
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
context.Penalties.Add(new EFPenalty()
|
var penalty = new EFPenalty()
|
||||||
{
|
{
|
||||||
Active = true,
|
Active = true,
|
||||||
OffenderId = newEntity.Offender.ClientId,
|
OffenderId = newEntity.Offender.ClientId,
|
||||||
@ -93,7 +93,10 @@ namespace SharedLibraryCore.Services
|
|||||||
When = DateTime.UtcNow,
|
When = DateTime.UtcNow,
|
||||||
AutomatedOffense = newEntity.AutomatedOffense,
|
AutomatedOffense = newEntity.AutomatedOffense,
|
||||||
IsEvadedOffense = newEntity.IsEvadedOffense
|
IsEvadedOffense = newEntity.IsEvadedOffense
|
||||||
});
|
};
|
||||||
|
|
||||||
|
newEntity.Offender.ReceivedPenalties.Add(penalty);
|
||||||
|
context.Penalties.Add(penalty);
|
||||||
}
|
}
|
||||||
|
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
|
Loading…
Reference in New Issue
Block a user