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

More work modifying client stuff

This commit is contained in:
RaidMax
2018-11-07 20:30:11 -06:00
parent a320389736
commit 1cfe7047a2
14 changed files with 255 additions and 307 deletions

View File

@ -41,13 +41,13 @@ namespace SharedLibraryCore.Database.Models
public virtual string Name
{
get { return CurrentAlias.Name; }
set { }
set { CurrentAlias.Name = value; }
}
[NotMapped]
public virtual int IPAddress
{
get { return CurrentAlias.IPAddress; }
set { }
set { CurrentAlias.IPAddress = value; }
}
[NotMapped]

View File

@ -1,8 +1,7 @@
using System;
using SharedLibraryCore.Database.Models;
using System;
using System.Threading;
using System.Threading.Tasks;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Objects;
namespace SharedLibraryCore
{
@ -74,6 +73,18 @@ namespace SharedLibraryCore
/// the current map changed
/// </summary>
MapChange,
/// <summary>
/// a client was detected as starting to connect
/// </summary>
PreConnect,
/// <summary>
/// a client was detecting as starting to disconnect
/// </summary>
PreDisconnect,
/// <summary>
/// a client's information was updated
/// </summary>
Update,
// events "generated" by clients
/// <summary>
@ -159,7 +170,10 @@ namespace SharedLibraryCore
}
static long NextEventId;
static long GetNextEventId() => Interlocked.Increment(ref NextEventId);
static long GetNextEventId()
{
return Interlocked.Increment(ref NextEventId);
}
public GameEvent()
{
@ -186,11 +200,14 @@ namespace SharedLibraryCore
/// asynchronously wait for GameEvent to be processed
/// </summary>
/// <returns>waitable task </returns>
public Task<GameEvent> WaitAsync(int timeOut = int.MaxValue) => Task.Run(() =>
public Task<GameEvent> WaitAsync(int timeOut = int.MaxValue)
{
OnProcessed.Wait(timeOut);
return this;
});
return Task.Run(() =>
{
OnProcessed.Wait(timeOut);
return this;
});
}
/// <summary>
/// determine whether an event should be delayed or not

View File

@ -1,28 +0,0 @@
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Objects;
using System;
using System.Collections.Generic;
using System.Text;
namespace SharedLibraryCore.Interfaces
{
public interface IClientAuthentication
{
/// <summary>
/// request authentication when a client join event
/// occurs in the log, as no IP is given
/// </summary>
/// <param name="client">client that has joined from the log</param>
void RequestClientAuthentication(EFClient client);
/// <summary>
/// get all clients that have been authenticated by the status poll
/// </summary>
/// <returns>list of all authenticated clients</returns>
IList<EFClient> GetAuthenticatedClients();
/// <summary>
/// authenticate a list of clients from status poll
/// </summary>
/// <param name="clients">list of clients to authenticate</param>
void AuthenticateClients(IList<EFClient> clients);
}
}

View File

@ -1,5 +1,4 @@
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Objects;
using SharedLibraryCore.Objects;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
@ -18,11 +17,6 @@ namespace SharedLibraryCore.Database.Models
/// </summary>
Connecting,
/// <summary>
/// represents when the client has been parsed by RCon,
/// but has not been validated against the database
/// </summary>
Authenticated,
/// <summary>
/// represents when the client has been authenticated by RCon
/// and validated by the database
/// </summary>
@ -86,6 +80,7 @@ namespace SharedLibraryCore.Database.Models
{
{ "_reportCount", 0 }
};
CurrentAlias = CurrentAlias ?? new EFAlias();
}
public override string ToString()
@ -410,7 +405,7 @@ namespace SharedLibraryCore.Database.Models
public void OnConnect()
{
var loc = Utilities.CurrentLocalization.LocalizationIndex;
//#if !DEBUG
#if !DEBUG
if (Name.Length < 3)
{
CurrentServer.Logger.WriteDebug($"Kicking {this} because their name is too short");
@ -435,7 +430,7 @@ namespace SharedLibraryCore.Database.Models
}
// reserved slots stuff
if ((CurrentServer.GetClientsAsList().Count(_client => !_client.IsPrivileged()) - CurrentServer.MaxClients) < CurrentServer.ServerConfig.ReservedSlotNumber &&
if (CurrentServer.MaxClients - (CurrentServer.GetClientsAsList().Count(_client => !_client.IsPrivileged())) < CurrentServer.ServerConfig.ReservedSlotNumber &&
!this.IsPrivileged())
{
CurrentServer.Logger.WriteDebug($"Kicking {this} their spot is reserved");
@ -446,13 +441,34 @@ namespace SharedLibraryCore.Database.Models
LastConnection = DateTime.UtcNow;
Connections += 1;
//#endif
#endif
}
public async Task OnDisconnect()
{
State = ClientState.Disconnecting;
TotalConnectionTime += ConnectionLength;
LastConnection = DateTime.UtcNow;
await CurrentServer.Manager.GetClientService().Update(this);
}
public async Task OnJoin(int ipAddress)
{
// todo: fix this up
CurrentAlias.IPAddress = IPAddress;
var existingAlias = AliasLink.Children
.FirstOrDefault(a => a.Name == Name && a.IPAddress == ipAddress);
if (existingAlias == null)
{
CurrentServer.Logger.WriteDebug($"Client {this} has connected previously under a different ip/name");
CurrentAlias = new EFAlias()
{
IPAddress = ipAddress,
Name = Name
};
}
await CurrentServer.Manager.GetClientService().Update(this);
var loc = Utilities.CurrentLocalization.LocalizationIndex;
@ -477,9 +493,8 @@ namespace SharedLibraryCore.Database.Models
CurrentServer.Logger.WriteInfo($"Banned client {this} trying to join...");
var autoKickClient = Utilities.IW4MAdminClient(CurrentServer);
// reban the "evading" guid
if (Level != Permission.Banned &&
if (Level != Permission.Banned &&
currentBan.Type == Penalty.PenaltyType.Ban)
{
// hack: re apply the automated offense to the reban
@ -501,11 +516,7 @@ namespace SharedLibraryCore.Database.Models
else
{
//string formattedKick = String.Format(
// RconParser.GetCommandPrefixes().Kick,
// polledPlayer.ClientNumber,
// $"{loc["SERVER_TB_REMAIN"]} ({(currentBan.Expires.Value - DateTime.UtcNow).TimeSpanText()} {loc["WEBFRONT_PENALTY_TEMPLATE_REMAINING"]})");
//await this.ExecuteCommandAsync(formattedKick);
Kick($"{loc["SERVER_TB_REMAIN"]} ({(currentBan.Expires.Value - DateTime.UtcNow).TimeSpanText()} {loc["WEBFRONT_PENALTY_TEMPLATE_REMAINING"]})", autoKickClient);
}
}
}

View File

@ -106,11 +106,17 @@ namespace SharedLibraryCore.RCon
try
{
response = await SendPayloadAsync(payload, waitForResponse);
if (response.Length == 0)
{
throw new Exception();
}
connectionState.OnComplete.Release(1);
connectionState.ConnectionAttempts = 0;
}
catch/* (Exception ex)*/
catch
{
if (connectionState.ConnectionAttempts < StaticHelpers.AllowedConnectionFails)
{

View File

@ -79,7 +79,7 @@ namespace SharedLibraryCore
/// </summary>
/// <param name="cNum">Client ID of player to be removed</param>
/// <returns>true if removal succeded, false otherwise</returns>
abstract public Task RemoveClient(int cNum);
abstract public Task OnClientDisconnected(EFClient client);
/// <summary>