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>
|
||||
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
|
||||
<PackageId>RaidMax.IW4MAdmin.Application</PackageId>
|
||||
<Version>2.2.2.0</Version>
|
||||
<Version>2.2.3.0</Version>
|
||||
<Authors>RaidMax</Authors>
|
||||
<Company>Forever None</Company>
|
||||
<Product>IW4MAdmin</Product>
|
||||
|
@ -34,6 +34,7 @@ namespace IW4MAdmin
|
||||
override public async Task OnClientConnected(EFClient clientFromLog)
|
||||
{
|
||||
Logger.WriteDebug($"Client slot #{clientFromLog.ClientNumber} now reserved");
|
||||
Clients[clientFromLog.ClientNumber] = new EFClient();
|
||||
|
||||
try
|
||||
{
|
||||
@ -50,8 +51,11 @@ namespace IW4MAdmin
|
||||
else
|
||||
{
|
||||
// this is only a temporary version until the IPAddress is transmitted
|
||||
client.CurrentAlias.Active = false;
|
||||
client.CurrentAlias.Name = clientFromLog.Name;
|
||||
client.CurrentAlias = new EFAlias
|
||||
{
|
||||
Name = clientFromLog.Name,
|
||||
IPAddress = clientFromLog.IPAddress
|
||||
};
|
||||
}
|
||||
|
||||
Logger.WriteInfo($"Client {client} connected...");
|
||||
@ -65,11 +69,6 @@ namespace IW4MAdmin
|
||||
|
||||
Clients[client.ClientNumber] = client;
|
||||
|
||||
if (clientFromLog.IPAddress != null)
|
||||
{
|
||||
await client.OnJoin(clientFromLog.IPAddress);
|
||||
}
|
||||
|
||||
client.State = EFClient.ClientState.Connected;
|
||||
#if DEBUG == true
|
||||
Logger.WriteDebug($"End PreConnect for {client}");
|
||||
@ -82,6 +81,11 @@ namespace IW4MAdmin
|
||||
};
|
||||
|
||||
Manager.GetEventHandler().AddEvent(e);
|
||||
|
||||
if (client.IPAddress != null)
|
||||
{
|
||||
await client.OnJoin(client.IPAddress);
|
||||
}
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
@ -297,7 +301,7 @@ namespace IW4MAdmin
|
||||
|
||||
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");
|
||||
E.FailReason = GameEvent.EventFailReason.Invalid;
|
||||
|
@ -8,7 +8,6 @@ using SharedLibraryCore.Objects;
|
||||
using SharedLibraryCore.Database;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
using SharedLibraryCore.Localization;
|
||||
using IW4MAdmin.Application.Migration;
|
||||
|
||||
@ -22,6 +21,7 @@ namespace IW4MAdmin.Application
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
AppDomain.CurrentDomain.SetData("DataDirectory", Utilities.OperatingDirectory);
|
||||
Console.OutputEncoding = Encoding.UTF8;
|
||||
Console.ForegroundColor = ConsoleColor.Gray;
|
||||
|
||||
|
@ -459,7 +459,10 @@ namespace SharedLibraryCore.Database.Models
|
||||
var loc = Utilities.CurrentLocalization.LocalizationIndex;
|
||||
var autoKickClient = Utilities.IW4MAdminClient(CurrentServer);
|
||||
|
||||
if (ipAddress != null)
|
||||
{
|
||||
await CurrentServer.Manager.GetClientService().UpdateAlias(this);
|
||||
}
|
||||
|
||||
OnConnect();
|
||||
|
||||
|
@ -37,6 +37,7 @@ namespace SharedLibraryCore.Services
|
||||
Name = entity.Name,
|
||||
Link = client.AliasLink,
|
||||
DateAdded = DateTime.UtcNow,
|
||||
IPAddress = entity.IPAddress,
|
||||
// the first time a client is created, we may not have their ip,
|
||||
// so we create a temporary alias
|
||||
Active = false
|
||||
@ -52,15 +53,14 @@ namespace SharedLibraryCore.Services
|
||||
public async Task UpdateAlias(EFClient entity)
|
||||
{
|
||||
// todo: move this out
|
||||
#if DEBUG == false
|
||||
if (entity.IsBot)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
context.Attach(entity);
|
||||
|
||||
string name = entity.Name;
|
||||
int? ip = entity.IPAddress;
|
||||
|
||||
@ -70,8 +70,8 @@ namespace SharedLibraryCore.Services
|
||||
// get all aliases by IP address and LinkId
|
||||
var iqAliases = context.Aliases
|
||||
.Include(a => a.Link)
|
||||
.Where(a => a.Link.Active)
|
||||
.Where(a => (a.IPAddress != null && a.IPAddress == ip) ||
|
||||
//.Where(a => a.Link.Active)
|
||||
.Where(a => (a.IPAddress == ip) ||
|
||||
a.LinkId == entity.AliasLinkId);
|
||||
|
||||
#if DEBUG == true
|
||||
@ -100,7 +100,6 @@ namespace SharedLibraryCore.Services
|
||||
{
|
||||
context.Update(entity);
|
||||
|
||||
entity.CurrentAlias = existingAlias;
|
||||
if (existingAlias.AliasId > 0)
|
||||
{
|
||||
entity.CurrentAliasId = existingAlias.AliasId;
|
||||
@ -109,36 +108,58 @@ namespace SharedLibraryCore.Services
|
||||
{
|
||||
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
|
||||
else if (hasExistingAlias)
|
||||
{
|
||||
context.Update(entity);
|
||||
entity.AliasLink = aliasLink;
|
||||
entity.AliasLinkId = aliasLink.AliasLinkId;
|
||||
|
||||
// the current link is temporary so we need to update
|
||||
if (!entity.AliasLink.Active)
|
||||
{
|
||||
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
|
||||
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}");
|
||||
|
||||
var newAlias = new EFAlias()
|
||||
{
|
||||
DateAdded = DateTime.UtcNow,
|
||||
IPAddress = ip,
|
||||
Link = aliasLink,
|
||||
Name = name
|
||||
LinkId = aliasLink.AliasLinkId,
|
||||
Name = name,
|
||||
Active = true,
|
||||
};
|
||||
|
||||
context.Aliases.Add(newAlias);
|
||||
@ -151,27 +172,41 @@ namespace SharedLibraryCore.Services
|
||||
else
|
||||
{
|
||||
entity.CurrentServer.Logger.WriteDebug($"{entity} has not be seen before");
|
||||
|
||||
if (name != entity.CurrentAlias.Name)
|
||||
{
|
||||
var newAlias = new EFAlias()
|
||||
{
|
||||
DateAdded = DateTime.UtcNow,
|
||||
IPAddress = ip,
|
||||
Link = entity.AliasLink,
|
||||
Name = name
|
||||
LinkId = entity.AliasLink.AliasLinkId,
|
||||
Name = name,
|
||||
Active = true
|
||||
};
|
||||
|
||||
context.Update(entity);
|
||||
context.Update(entity.AliasLink);
|
||||
|
||||
entity.AliasLink.Active = true;
|
||||
context.Aliases.Add(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();
|
||||
}
|
||||
|
||||
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
|
||||
.Where(c => linkIds.Contains(c.AliasLinkId))
|
||||
|
@ -55,7 +55,7 @@ namespace SharedLibraryCore.Services
|
||||
{
|
||||
await context.Clients
|
||||
.Include(c => c.ReceivedPenalties)
|
||||
.Where(c => c.AliasLinkId == newEntity.LinkId)
|
||||
.Where(c => c.AliasLinkId == newEntity.Link.AliasLinkId)
|
||||
.ForEachAsync(c =>
|
||||
{
|
||||
if (c.Level != Permission.Flagged)
|
||||
@ -81,7 +81,7 @@ namespace SharedLibraryCore.Services
|
||||
// we just want to add it to the database
|
||||
else
|
||||
{
|
||||
context.Penalties.Add(new EFPenalty()
|
||||
var penalty = new EFPenalty()
|
||||
{
|
||||
Active = true,
|
||||
OffenderId = newEntity.Offender.ClientId,
|
||||
@ -93,7 +93,10 @@ namespace SharedLibraryCore.Services
|
||||
When = DateTime.UtcNow,
|
||||
AutomatedOffense = newEntity.AutomatedOffense,
|
||||
IsEvadedOffense = newEntity.IsEvadedOffense
|
||||
});
|
||||
};
|
||||
|
||||
newEntity.Offender.ReceivedPenalties.Add(penalty);
|
||||
context.Penalties.Add(penalty);
|
||||
}
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
|
Loading…
Reference in New Issue
Block a user