diff --git a/Application/Application.csproj b/Application/Application.csproj
index 254f4e90..2870f098 100644
--- a/Application/Application.csproj
+++ b/Application/Application.csproj
@@ -6,7 +6,7 @@
2.1.5
false
RaidMax.IW4MAdmin.Application
- 2.2.2.0
+ 2.2.3.0
RaidMax
Forever None
IW4MAdmin
diff --git a/Application/IW4MServer.cs b/Application/IW4MServer.cs
index a35833d1..ca5e5285 100644
--- a/Application/IW4MServer.cs
+++ b/Application/IW4MServer.cs
@@ -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;
diff --git a/Application/Main.cs b/Application/Main.cs
index d0c1269e..2c0a0623 100644
--- a/Application/Main.cs
+++ b/Application/Main.cs
@@ -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;
diff --git a/SharedLibraryCore/Objects/EFClient.cs b/SharedLibraryCore/Objects/EFClient.cs
index dae6e8dd..f72be830 100644
--- a/SharedLibraryCore/Objects/EFClient.cs
+++ b/SharedLibraryCore/Objects/EFClient.cs
@@ -459,7 +459,10 @@ namespace SharedLibraryCore.Database.Models
var loc = Utilities.CurrentLocalization.LocalizationIndex;
var autoKickClient = Utilities.IW4MAdminClient(CurrentServer);
- await CurrentServer.Manager.GetClientService().UpdateAlias(this);
+ if (ipAddress != null)
+ {
+ await CurrentServer.Manager.GetClientService().UpdateAlias(this);
+ }
OnConnect();
diff --git a/SharedLibraryCore/Services/ClientService.cs b/SharedLibraryCore/Services/ClientService.cs
index 01b8fbf0..af9726bb 100644
--- a/SharedLibraryCore/Services/ClientService.cs
+++ b/SharedLibraryCore/Services/ClientService.cs
@@ -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");
- var newAlias = new EFAlias()
+
+ if (name != entity.CurrentAlias.Name)
{
- DateAdded = DateTime.UtcNow,
- IPAddress = ip,
- Link = entity.AliasLink,
- Name = name
- };
+ var newAlias = new EFAlias()
+ {
+ DateAdded = DateTime.UtcNow,
+ IPAddress = ip,
+ LinkId = entity.AliasLink.AliasLinkId,
+ Name = name,
+ Active = true
+ };
+
+ context.Update(entity);
+ 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);
context.Update(entity.AliasLink);
-
entity.AliasLink.Active = true;
- context.Aliases.Add(newAlias);
- entity.CurrentAlias = newAlias;
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))
diff --git a/SharedLibraryCore/Services/PenaltyService.cs b/SharedLibraryCore/Services/PenaltyService.cs
index b7339f5b..12f5b6d0 100644
--- a/SharedLibraryCore/Services/PenaltyService.cs
+++ b/SharedLibraryCore/Services/PenaltyService.cs
@@ -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();