2015-08-20 01:06:44 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2021-07-11 18:26:30 -04:00
|
|
|
|
using System.Net;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2022-01-26 11:32:16 -05:00
|
|
|
|
using Data.Models;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Serilog.Context;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using SharedLibraryCore.Configuration;
|
2018-11-05 22:01:29 -05:00
|
|
|
|
using SharedLibraryCore.Database.Models;
|
2022-01-26 11:32:16 -05:00
|
|
|
|
using SharedLibraryCore.Dtos;
|
|
|
|
|
using SharedLibraryCore.Exceptions;
|
|
|
|
|
using SharedLibraryCore.Helpers;
|
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
|
|
|
|
|
namespace SharedLibraryCore
|
2015-08-20 01:06:44 -04:00
|
|
|
|
{
|
2020-11-17 19:24:54 -05:00
|
|
|
|
public abstract class Server : IGameServer
|
2015-08-20 01:06:44 -04:00
|
|
|
|
{
|
2017-08-08 22:44:52 -04:00
|
|
|
|
public enum Game
|
|
|
|
|
{
|
2019-02-05 19:02:45 -05:00
|
|
|
|
COD = -1,
|
|
|
|
|
UKN = 0,
|
|
|
|
|
IW3 = 1,
|
|
|
|
|
IW4 = 2,
|
|
|
|
|
IW5 = 3,
|
|
|
|
|
IW6 = 4,
|
2019-05-08 21:34:17 -04:00
|
|
|
|
T4 = 5,
|
|
|
|
|
T5 = 6,
|
|
|
|
|
T6 = 7,
|
2021-04-16 14:35:51 -04:00
|
|
|
|
T7 = 8,
|
2021-06-03 11:51:03 -04:00
|
|
|
|
SHG1 = 9,
|
2022-06-07 13:10:39 -04:00
|
|
|
|
CSGO = 10,
|
|
|
|
|
H1 = 11
|
2017-08-08 22:44:52 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-26 11:32:16 -05:00
|
|
|
|
// only here for performance
|
|
|
|
|
private readonly bool CustomSayEnabled;
|
|
|
|
|
protected readonly string CustomSayName;
|
|
|
|
|
protected readonly DefaultSettings DefaultSettings;
|
|
|
|
|
protected readonly ILogger ServerLogger;
|
|
|
|
|
protected List<string> BroadcastMessages;
|
|
|
|
|
protected int ConnectionErrors;
|
|
|
|
|
protected string FSGame;
|
|
|
|
|
protected IGameLogReaderFactory gameLogReaderFactory;
|
|
|
|
|
|
|
|
|
|
// Info
|
|
|
|
|
private string hostname;
|
|
|
|
|
protected TimeSpan LastMessage;
|
|
|
|
|
protected DateTime LastPoll;
|
|
|
|
|
protected int NextMessage;
|
|
|
|
|
protected ManualResetEventSlim OnRemoteCommandResponse;
|
|
|
|
|
protected IRConConnectionFactory RConConnectionFactory;
|
|
|
|
|
|
|
|
|
|
#pragma warning disable CS0612
|
|
|
|
|
public Server(ILogger<Server> logger, Interfaces.ILogger deprecatedLogger,
|
|
|
|
|
#pragma warning restore CS0612
|
|
|
|
|
ServerConfiguration config, IManager mgr, IRConConnectionFactory rconConnectionFactory,
|
2021-11-28 11:17:56 -05:00
|
|
|
|
IGameLogReaderFactory gameLogReaderFactory, IServiceProvider serviceProvider)
|
2015-08-20 01:06:44 -04:00
|
|
|
|
{
|
2017-06-19 13:58:01 -04:00
|
|
|
|
Password = config.Password;
|
2018-03-14 01:36:25 -04:00
|
|
|
|
IP = config.IPAddress;
|
2017-06-19 13:58:01 -04:00
|
|
|
|
Port = config.Port;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
Manager = mgr;
|
2022-01-26 11:32:16 -05:00
|
|
|
|
#pragma warning disable CS0612
|
|
|
|
|
Logger = deprecatedLogger ?? throw new ArgumentNullException(nameof(deprecatedLogger));
|
|
|
|
|
#pragma warning restore CS0612
|
2018-03-14 01:36:25 -04:00
|
|
|
|
ServerConfig = config;
|
2019-10-09 16:51:02 -04:00
|
|
|
|
EventProcessing = new SemaphoreSlim(1, 1);
|
2020-12-02 15:29:49 -05:00
|
|
|
|
Clients = new List<EFClient>(new EFClient[64]);
|
2015-08-20 01:06:44 -04:00
|
|
|
|
Reports = new List<Report>();
|
2022-03-29 17:42:53 -04:00
|
|
|
|
ClientHistory = new ClientHistoryInfo();
|
2018-03-09 03:01:12 -05:00
|
|
|
|
ChatHistory = new List<ChatInfo>();
|
2017-06-19 13:58:01 -04:00
|
|
|
|
NextMessage = 0;
|
2018-03-30 00:13:40 -04:00
|
|
|
|
CustomSayEnabled = Manager.GetApplicationSettings().Configuration().EnableCustomSayName;
|
|
|
|
|
CustomSayName = Manager.GetApplicationSettings().Configuration().CustomSayName;
|
2020-05-04 17:50:02 -04:00
|
|
|
|
this.gameLogReaderFactory = gameLogReaderFactory;
|
2021-06-03 11:51:03 -04:00
|
|
|
|
RConConnectionFactory = rconConnectionFactory;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
ServerLogger = logger;
|
2021-11-28 11:17:56 -05:00
|
|
|
|
DefaultSettings = serviceProvider.GetRequiredService<DefaultSettings>();
|
2017-06-12 13:50:00 -04:00
|
|
|
|
InitializeTokens();
|
|
|
|
|
InitializeAutoMessages();
|
2015-08-20 01:06:44 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-26 11:32:16 -05:00
|
|
|
|
public long EndPoint => IPAddress.TryParse(IP, out _)
|
|
|
|
|
? Convert.ToInt64($"{IP.Replace(".", "")}{Port}")
|
2021-07-11 18:26:30 -04:00
|
|
|
|
: $"{IP.Replace(".", "")}{Port}".GetStableHashCode();
|
2018-11-27 19:31:48 -05:00
|
|
|
|
|
2022-01-26 11:32:16 -05:00
|
|
|
|
// Objects
|
|
|
|
|
public IManager Manager { get; protected set; }
|
|
|
|
|
|
|
|
|
|
[Obsolete] public Interfaces.ILogger Logger { get; }
|
|
|
|
|
|
|
|
|
|
public ServerConfiguration ServerConfig { get; }
|
|
|
|
|
public List<Map> Maps { get; protected set; } = new List<Map>();
|
|
|
|
|
public List<Report> Reports { get; set; }
|
|
|
|
|
public List<ChatInfo> ChatHistory { get; protected set; }
|
2022-03-29 17:42:53 -04:00
|
|
|
|
public ClientHistoryInfo ClientHistory { get; }
|
2022-01-26 11:32:16 -05:00
|
|
|
|
public Game GameName { get; set; }
|
|
|
|
|
|
|
|
|
|
public string Hostname
|
|
|
|
|
{
|
|
|
|
|
get => ServerConfig.CustomHostname ?? hostname;
|
|
|
|
|
protected set => hostname = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Website { get; protected set; }
|
|
|
|
|
public string Gametype { get; set; }
|
|
|
|
|
|
|
|
|
|
public string GametypeName => DefaultSettings.Gametypes.FirstOrDefault(gt => gt.Game == GameName)?.Gametypes
|
|
|
|
|
?.FirstOrDefault(gt => gt.Name == Gametype)?.Alias ?? Gametype;
|
|
|
|
|
|
|
|
|
|
public string GamePassword { get; protected set; }
|
|
|
|
|
public Map CurrentMap { get; set; }
|
|
|
|
|
|
|
|
|
|
public int ClientNum
|
|
|
|
|
{
|
2022-04-19 19:43:58 -04:00
|
|
|
|
get { return Clients.ToArray().Count(p => p != null && Utilities.IsDevelopment || (!p?.IsBot ?? false)); }
|
2022-01-26 11:32:16 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int MaxClients { get; protected set; }
|
|
|
|
|
public List<EFClient> Clients { get; protected set; }
|
|
|
|
|
public string Password { get; }
|
|
|
|
|
public bool Throttled { get; protected set; }
|
|
|
|
|
public bool CustomCallback { get; protected set; }
|
|
|
|
|
public string WorkingDirectory { get; protected set; }
|
|
|
|
|
public IRConConnection RemoteConnection { get; protected set; }
|
|
|
|
|
public IRConParser RconParser { get; set; }
|
|
|
|
|
public IEventParser EventParser { get; set; }
|
|
|
|
|
public string LogPath { get; protected set; }
|
|
|
|
|
public bool RestartRequested { get; set; }
|
|
|
|
|
public SemaphoreSlim EventProcessing { get; }
|
|
|
|
|
|
|
|
|
|
// Internal
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// this is actually the hostname now
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string IP { get; protected set; }
|
|
|
|
|
|
|
|
|
|
public IPEndPoint ResolvedIpEndPoint { get; protected set; }
|
|
|
|
|
public string Version { get; protected set; }
|
|
|
|
|
public bool IsInitialized { get; set; }
|
|
|
|
|
|
|
|
|
|
public int Port { get; }
|
|
|
|
|
public abstract Task Kick(string reason, EFClient target, EFClient origin, EFPenalty originalPenalty);
|
|
|
|
|
|
2019-05-31 11:17:01 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// Returns list of all current players
|
2019-05-31 11:17:01 -04:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2018-11-05 22:01:29 -05:00
|
|
|
|
public List<EFClient> GetClientsAsList()
|
2015-08-20 01:06:44 -04:00
|
|
|
|
{
|
2019-01-02 19:32:39 -05:00
|
|
|
|
return Clients.FindAll(x => x != null && x.NetworkId != 0);
|
2015-08-20 01:06:44 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// Add a player to the server's player list
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// </summary>
|
2018-11-05 22:01:29 -05:00
|
|
|
|
/// <param name="P">EFClient pulled from memory reading</param>
|
2022-03-24 12:34:32 -04:00
|
|
|
|
/// <returns>True if player added successfully, false otherwise</returns>
|
2019-11-15 15:50:20 -05:00
|
|
|
|
public abstract Task<EFClient> OnClientConnected(EFClient P);
|
2015-08-20 01:06:44 -04:00
|
|
|
|
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// Remove player by client number
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// </summary>
|
2022-03-24 12:34:32 -04:00
|
|
|
|
/// <returns>true if removal succeeded, false otherwise</returns>
|
2019-05-31 11:17:01 -04:00
|
|
|
|
public abstract Task OnClientDisconnected(EFClient client);
|
2015-08-20 01:06:44 -04:00
|
|
|
|
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// Get a player by name
|
|
|
|
|
/// todo: make this an extension
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// </summary>
|
2018-11-05 22:01:29 -05:00
|
|
|
|
/// <param name="pName">EFClient name to search for</param>
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// <returns>Matching player if found</returns>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
public List<EFClient> GetClientByName(string pName)
|
2015-08-20 01:06:44 -04:00
|
|
|
|
{
|
2019-04-02 21:20:37 -04:00
|
|
|
|
if (string.IsNullOrEmpty(pName))
|
|
|
|
|
{
|
|
|
|
|
return new List<EFClient>();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-11 16:26:13 -04:00
|
|
|
|
pName = pName.Trim().StripColors();
|
|
|
|
|
|
2022-01-26 11:32:16 -05:00
|
|
|
|
var QuoteSplit = pName.Split('"');
|
|
|
|
|
var literal = false;
|
2017-06-16 17:35:51 -04:00
|
|
|
|
if (QuoteSplit.Length > 1)
|
2017-11-16 18:09:19 -05:00
|
|
|
|
{
|
2017-06-16 17:35:51 -04:00
|
|
|
|
pName = QuoteSplit[1];
|
2017-11-16 18:09:19 -05:00
|
|
|
|
literal = true;
|
|
|
|
|
}
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2017-11-16 18:09:19 -05:00
|
|
|
|
if (literal)
|
2019-04-02 21:20:37 -04:00
|
|
|
|
{
|
2021-06-06 14:40:58 -04:00
|
|
|
|
return GetClientsAsList().Where(p => p.Name?.StripColors()?.ToLower() == pName.ToLower()).ToList();
|
2019-04-02 21:20:37 -04:00
|
|
|
|
}
|
2017-11-16 18:09:19 -05:00
|
|
|
|
|
2022-01-26 11:32:16 -05:00
|
|
|
|
return GetClientsAsList().Where(p => (p.Name?.StripColors()?.ToLower() ?? "").Contains(pName.ToLower()))
|
|
|
|
|
.ToList();
|
2015-08-20 01:06:44 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-08 10:10:31 -04:00
|
|
|
|
public virtual Task<bool> ProcessUpdatesAsync(CancellationToken token)
|
2022-01-26 11:32:16 -05:00
|
|
|
|
{
|
|
|
|
|
return (Task<bool>)Task.CompletedTask;
|
|
|
|
|
}
|
2017-10-15 21:40:27 -04:00
|
|
|
|
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// Process any server event
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="E">Event</param>
|
|
|
|
|
/// <returns>True on sucess</returns>
|
2019-05-31 11:17:01 -04:00
|
|
|
|
protected abstract Task<bool> ProcessEvent(GameEvent E);
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2019-05-31 11:17:01 -04:00
|
|
|
|
public abstract Task ExecuteEvent(GameEvent E);
|
2015-08-20 01:06:44 -04:00
|
|
|
|
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// Send a message to all players
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// </summary>
|
2018-09-29 15:52:22 -04:00
|
|
|
|
/// <param name="message">Message to be sent to all players</param>
|
2022-03-24 12:34:32 -04:00
|
|
|
|
/// <param name="sender">Client that initiated the broadcast</param>
|
2018-11-05 22:01:29 -05:00
|
|
|
|
public GameEvent Broadcast(string message, EFClient sender = null)
|
2015-08-20 01:06:44 -04:00
|
|
|
|
{
|
2021-11-23 18:26:33 -05:00
|
|
|
|
var formattedMessage = string.Format(RconParser.Configuration.CommandPrefixes.Say ?? "",
|
2022-04-27 16:36:58 -04:00
|
|
|
|
$"{(CustomSayEnabled && GameName == Game.IW4 ? $"{CustomSayName}: " : "")}{message}");
|
2021-11-23 18:26:33 -05:00
|
|
|
|
ServerLogger.LogDebug("All-> {Message}",
|
2022-07-06 16:42:31 -04:00
|
|
|
|
message.FormatMessageForEngine(RconParser.Configuration).StripColors());
|
2018-10-25 09:14:39 -04:00
|
|
|
|
|
2021-11-23 18:26:33 -05:00
|
|
|
|
var e = new GameEvent
|
2018-06-16 22:11:25 -04:00
|
|
|
|
{
|
|
|
|
|
Type = GameEvent.EventType.Broadcast,
|
2018-08-31 23:35:51 -04:00
|
|
|
|
Data = formattedMessage,
|
|
|
|
|
Owner = this,
|
2022-01-26 11:32:16 -05:00
|
|
|
|
Origin = sender
|
2018-08-30 21:53:00 -04:00
|
|
|
|
};
|
|
|
|
|
|
2020-05-04 17:50:02 -04:00
|
|
|
|
Manager.AddEvent(e);
|
2018-09-29 15:52:22 -04:00
|
|
|
|
return e;
|
2015-08-20 01:06:44 -04:00
|
|
|
|
}
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2022-03-23 12:43:20 -04:00
|
|
|
|
[Obsolete("Use BroadcastAsync")]
|
2021-01-24 12:47:19 -05:00
|
|
|
|
public void Broadcast(IEnumerable<string> messages, EFClient sender = null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var message in messages)
|
|
|
|
|
{
|
|
|
|
|
#pragma warning disable 4014
|
|
|
|
|
Broadcast(message, sender).WaitAsync();
|
|
|
|
|
#pragma warning restore 4014
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2022-03-23 12:43:20 -04:00
|
|
|
|
public async Task BroadcastAsync(IEnumerable<string> messages, EFClient sender = null,
|
|
|
|
|
CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
foreach (var message in messages)
|
|
|
|
|
{
|
|
|
|
|
if (Manager.CancellationToken.IsCancellationRequested)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await Broadcast(message, sender).WaitAsync(Utilities.DefaultCommandTimeout, Manager.CancellationToken);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// Send a message to a particular players
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// </summary>
|
2019-08-02 19:04:34 -04:00
|
|
|
|
/// <param name="message">Message to send</param>
|
2021-06-03 11:51:03 -04:00
|
|
|
|
/// <param name="targetClient">EFClient to send message to</param>
|
|
|
|
|
protected async Task Tell(string message, EFClient targetClient)
|
2015-08-20 01:06:44 -04:00
|
|
|
|
{
|
2020-11-11 18:31:26 -05:00
|
|
|
|
if (!Utilities.IsDevelopment)
|
|
|
|
|
{
|
2021-06-03 11:51:03 -04:00
|
|
|
|
var temporalClientId = targetClient.GetAdditionalProperty<string>("ConnectionClientId");
|
|
|
|
|
var parsedClientId = string.IsNullOrEmpty(temporalClientId) ? (int?)null : int.Parse(temporalClientId);
|
|
|
|
|
var clientNumber = parsedClientId ?? targetClient.ClientNumber;
|
|
|
|
|
|
2020-11-11 18:31:26 -05:00
|
|
|
|
var formattedMessage = string.Format(RconParser.Configuration.CommandPrefixes.Tell,
|
2021-06-03 11:51:03 -04:00
|
|
|
|
clientNumber,
|
2022-04-27 16:36:58 -04:00
|
|
|
|
$"{(CustomSayEnabled && GameName == Game.IW4 ? $"{CustomSayName}: " : "")}{message}");
|
2022-01-26 11:32:16 -05:00
|
|
|
|
if (targetClient.ClientNumber > -1 && message.Length > 0 &&
|
|
|
|
|
targetClient.Level != Data.Models.Client.EFClient.Permission.Console)
|
|
|
|
|
{
|
2020-11-11 18:31:26 -05:00
|
|
|
|
await this.ExecuteCommandAsync(formattedMessage);
|
2022-01-26 11:32:16 -05:00
|
|
|
|
}
|
2020-11-11 18:31:26 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-11-23 18:26:33 -05:00
|
|
|
|
ServerLogger.LogDebug("Tell[{ClientNumber}]->{Message}", targetClient.ClientNumber,
|
2022-07-06 16:42:31 -04:00
|
|
|
|
message.FormatMessageForEngine(RconParser.Configuration).StripColors());
|
2020-11-11 18:31:26 -05:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-26 11:32:16 -05:00
|
|
|
|
if (targetClient.Level == Data.Models.Client.EFClient.Permission.Console)
|
2015-08-22 02:04:30 -04:00
|
|
|
|
{
|
2019-05-08 21:34:17 -04:00
|
|
|
|
Console.ForegroundColor = ConsoleColor.Green;
|
2022-07-06 16:42:31 -04:00
|
|
|
|
var cleanMessage = message.FormatMessageForEngine(RconParser.Configuration)
|
2022-04-27 16:36:58 -04:00
|
|
|
|
.StripColors();
|
2020-11-11 18:31:26 -05:00
|
|
|
|
using (LogContext.PushProperty("Server", ToString()))
|
|
|
|
|
{
|
2022-04-27 16:36:58 -04:00
|
|
|
|
ServerLogger.LogInformation("Command output received: {Message}", cleanMessage);
|
2020-11-11 18:31:26 -05:00
|
|
|
|
}
|
2022-01-26 11:32:16 -05:00
|
|
|
|
|
2022-04-27 16:36:58 -04:00
|
|
|
|
Console.WriteLine(cleanMessage);
|
2015-08-22 02:04:30 -04:00
|
|
|
|
Console.ForegroundColor = ConsoleColor.Gray;
|
|
|
|
|
}
|
2015-08-20 01:06:44 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// Send a message to all admins on the server
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message">Message to send out</param>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
public void ToAdmins(string message)
|
2015-08-20 01:06:44 -04:00
|
|
|
|
{
|
2022-01-26 11:32:16 -05:00
|
|
|
|
foreach (var client in GetClientsAsList()
|
|
|
|
|
.Where(c => c.Level > Data.Models.Client.EFClient.Permission.Flagged))
|
2018-09-29 15:52:22 -04:00
|
|
|
|
client.Tell(message);
|
2015-08-20 01:06:44 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// Kick a player from the server
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// </summary>
|
2020-11-17 19:24:54 -05:00
|
|
|
|
/// <param name="reason">Reason for kicking</param>
|
2022-03-24 12:34:32 -04:00
|
|
|
|
/// <param name="target">EFClient to kick</param>
|
|
|
|
|
/// <param name="origin">Client initating the kick</param>
|
|
|
|
|
public Task Kick(string reason, EFClient target, EFClient origin)
|
2022-01-26 11:32:16 -05:00
|
|
|
|
{
|
2022-03-24 12:34:32 -04:00
|
|
|
|
return Kick(reason, target, origin, null);
|
2022-01-26 11:32:16 -05:00
|
|
|
|
}
|
2015-08-20 01:06:44 -04:00
|
|
|
|
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// Temporarily ban a player ( default 1 hour ) from the server
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// </summary>
|
2021-10-31 12:57:32 -04:00
|
|
|
|
/// <param name="reason">Reason for banning the player</param>
|
2022-03-24 12:34:32 -04:00
|
|
|
|
/// <param name="length">Duration of the ban</param>
|
|
|
|
|
/// <param name="target">The client to ban</param>
|
|
|
|
|
/// <param name="origin">The client performing the ban</param>
|
|
|
|
|
public abstract Task TempBan(string reason, TimeSpan length, EFClient target, EFClient origin);
|
2015-08-20 01:06:44 -04:00
|
|
|
|
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// Perm ban a player from the server
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// </summary>
|
2022-03-24 12:34:32 -04:00
|
|
|
|
/// <param name="reason">The reason for the ban</param>
|
|
|
|
|
/// <param name="target">The person to ban</param>
|
|
|
|
|
/// <param name="origin">The person who banned the target</param>
|
|
|
|
|
/// <param name="isEvade">obsolete</param>
|
|
|
|
|
public abstract Task Ban(string reason, EFClient target, EFClient origin, bool isEvade = false);
|
2015-08-20 15:23:13 -04:00
|
|
|
|
|
2022-03-24 12:34:32 -04:00
|
|
|
|
public abstract Task Warn(string reason, EFClient target, EFClient origin);
|
2016-01-16 17:58:24 -05:00
|
|
|
|
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// Unban a player by npID / GUID
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// </summary>
|
2022-03-24 12:34:32 -04:00
|
|
|
|
/// <param name="reason">reason for unban</param>
|
|
|
|
|
/// <param name="targetClient">client being unbanned</param>
|
|
|
|
|
/// <param name="originClient">client performing the unban</param>
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// <returns></returns>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
public abstract Task Unban(string reason, EFClient targetClient, EFClient originClient);
|
2015-08-20 01:06:44 -04:00
|
|
|
|
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// <summary>
|
2022-03-24 12:34:32 -04:00
|
|
|
|
/// Change the current server map
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// </summary>
|
2017-05-26 18:49:27 -04:00
|
|
|
|
/// <param name="mapName">Non-localized map name</param>
|
|
|
|
|
public async Task LoadMap(string mapName)
|
2015-08-20 01:06:44 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
await this.ExecuteCommandAsync($"map {mapName}");
|
2015-08-20 01:06:44 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// Initalize the macro variables
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// </summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
public abstract void InitializeTokens();
|
2015-08-20 01:06:44 -04:00
|
|
|
|
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// Initialize the messages to be broadcasted
|
2015-08-20 15:23:13 -04:00
|
|
|
|
/// </summary>
|
2017-06-12 13:50:00 -04:00
|
|
|
|
protected void InitializeAutoMessages()
|
2015-08-20 01:06:44 -04:00
|
|
|
|
{
|
2022-01-26 11:32:16 -05:00
|
|
|
|
BroadcastMessages = new List<string>();
|
2015-08-20 01:06:44 -04:00
|
|
|
|
|
2018-05-10 01:34:29 -04:00
|
|
|
|
if (ServerConfig.AutoMessages != null)
|
2022-01-26 11:32:16 -05:00
|
|
|
|
{
|
2018-03-18 22:25:11 -04:00
|
|
|
|
BroadcastMessages.AddRange(ServerConfig.AutoMessages);
|
2022-01-26 11:32:16 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-18 22:25:11 -04:00
|
|
|
|
BroadcastMessages.AddRange(Manager.GetApplicationSettings().Configuration().AutoMessages);
|
2015-08-20 01:06:44 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-06 23:45:21 -04:00
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
2019-04-25 14:00:54 -04:00
|
|
|
|
return $"{IP}:{Port}";
|
2017-06-06 23:45:21 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
protected async Task<bool> ScriptLoaded()
|
2017-11-02 12:49:45 -04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2022-02-28 21:44:30 -05:00
|
|
|
|
return (await this.GetDvarAsync("sv_customcallbacks", "0", Manager.CancellationToken)).Value == "1";
|
2017-11-02 12:49:45 -04:00
|
|
|
|
}
|
2017-11-25 20:29:58 -05:00
|
|
|
|
|
2022-01-26 11:32:16 -05:00
|
|
|
|
catch (DvarException)
|
2017-11-02 12:49:45 -04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-26 18:35:05 -04:00
|
|
|
|
public abstract Task<long> GetIdForServer(Server server = null);
|
2022-02-07 19:43:36 -05:00
|
|
|
|
|
2022-03-07 20:59:34 -05:00
|
|
|
|
public string[] ExecuteServerCommand(string command, int timeoutMs = 1000)
|
2022-02-07 19:43:36 -05:00
|
|
|
|
{
|
2022-02-13 22:38:40 -05:00
|
|
|
|
var tokenSource = new CancellationTokenSource();
|
2022-03-07 20:59:34 -05:00
|
|
|
|
tokenSource.CancelAfter(TimeSpan.FromSeconds(timeoutMs));
|
2022-02-13 22:38:40 -05:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2022-02-28 21:44:30 -05:00
|
|
|
|
return this.ExecuteCommandAsync(command, tokenSource.Token).GetAwaiter().GetResult();
|
2022-02-13 22:38:40 -05:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2022-02-07 19:43:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-07 20:59:34 -05:00
|
|
|
|
public string GetServerDvar(string dvarName, int timeoutMs = 1000)
|
2022-02-07 19:43:36 -05:00
|
|
|
|
{
|
2022-02-13 22:38:40 -05:00
|
|
|
|
var tokenSource = new CancellationTokenSource();
|
2022-03-07 20:59:34 -05:00
|
|
|
|
tokenSource.CancelAfter(TimeSpan.FromSeconds(timeoutMs));
|
2022-02-13 22:38:40 -05:00
|
|
|
|
try
|
|
|
|
|
{
|
2022-02-28 21:44:30 -05:00
|
|
|
|
return this.GetDvarAsync<string>(dvarName, token: tokenSource.Token).GetAwaiter().GetResult().Value;
|
2022-02-13 22:38:40 -05:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2022-02-07 19:43:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-07 20:59:34 -05:00
|
|
|
|
public bool SetServerDvar(string dvarName, string dvarValue, int timeoutMs = 1000)
|
2022-02-07 19:43:36 -05:00
|
|
|
|
{
|
2022-02-13 22:38:40 -05:00
|
|
|
|
var tokenSource = new CancellationTokenSource();
|
2022-03-07 20:59:34 -05:00
|
|
|
|
tokenSource.CancelAfter(TimeSpan.FromSeconds(timeoutMs));
|
2022-02-13 22:38:40 -05:00
|
|
|
|
try
|
|
|
|
|
{
|
2022-02-28 21:44:30 -05:00
|
|
|
|
this.SetDvarAsync(dvarName, dvarValue, tokenSource.Token).GetAwaiter().GetResult();
|
2022-02-13 22:38:40 -05:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-02-07 19:43:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public EFClient GetClientByNumber(int clientNumber) =>
|
|
|
|
|
GetClientsAsList().FirstOrDefault(client => client.ClientNumber == clientNumber);
|
2015-08-20 01:06:44 -04:00
|
|
|
|
}
|
2022-02-07 19:43:36 -05:00
|
|
|
|
}
|