mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 15:20:48 -05:00
add ability to register custom event generators for event parsers / truncate long client names fix
This commit is contained in:
@ -13,13 +13,16 @@ namespace SharedLibraryCore.Database.Models
|
||||
[ForeignKey("LinkId")]
|
||||
public virtual EFAliasLink Link { get; set; }
|
||||
[Required]
|
||||
[MaxLength(24)]
|
||||
[MaxLength(MAX_NAME_LENGTH)]
|
||||
public string Name { get; set; }
|
||||
[MaxLength(24)]
|
||||
[MaxLength(MAX_NAME_LENGTH)]
|
||||
public string SearchableName { get; set; }
|
||||
[Required]
|
||||
public int? IPAddress { get; set; }
|
||||
[Required]
|
||||
public DateTime DateAdded { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public const int MAX_NAME_LENGTH = 24;
|
||||
}
|
||||
}
|
||||
|
@ -214,6 +214,10 @@ namespace SharedLibraryCore
|
||||
}
|
||||
|
||||
public EventType Type;
|
||||
/// <summary>
|
||||
/// suptype of the event for more detailed classification
|
||||
/// </summary>
|
||||
public string Subtype { get; set; }
|
||||
public EventRequiredEntity RequiredEntity { get; set; }
|
||||
public string Data; // Data is usually the message sent by player
|
||||
public string Message;
|
||||
|
@ -1,4 +1,5 @@
|
||||
using static SharedLibraryCore.Server;
|
||||
using System;
|
||||
using static SharedLibraryCore.Server;
|
||||
|
||||
namespace SharedLibraryCore.Interfaces
|
||||
{
|
||||
@ -33,8 +34,16 @@ namespace SharedLibraryCore.Interfaces
|
||||
string URLProtocolFormat { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the text name of the game the parser is for
|
||||
/// specifies the text name of the game the parser is for
|
||||
/// </summary>
|
||||
string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// registers a custom event subtype to be triggered when a value is detected
|
||||
/// </summary>
|
||||
/// <param name="eventSubtype">subtype assigned to the event when generated</param>
|
||||
/// <param name="eventTriggerValue">event keyword to trigger an event generation</param>
|
||||
/// <param name="eventModifier">function pointer that modifies the generated game event</param>
|
||||
void RegisterCustomEvent(string eventSubtype, string eventTriggerValue, Func<string, IEventParserConfiguration, GameEvent, GameEvent> eventModifier);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
namespace SharedLibraryCore.Interfaces
|
||||
{
|
||||
|
19
SharedLibraryCore/Interfaces/IRegisterEvent.cs
Normal file
19
SharedLibraryCore/Interfaces/IRegisterEvent.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SharedLibraryCore.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// interface defining the capabilities of a custom event registration
|
||||
/// </summary>
|
||||
public interface IRegisterEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// collection of custom event registrations
|
||||
/// <remarks>
|
||||
/// (Subtype, trigger value, event generator)
|
||||
/// </remarks>
|
||||
/// </summary>
|
||||
IEnumerable<(string, string, Func<string, IEventParserConfiguration, GameEvent, GameEvent>)> Events { get; }
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ namespace SharedLibraryCore.Services
|
||||
{
|
||||
int? linkId = null;
|
||||
int? aliasId = null;
|
||||
entity.Name = entity.Name.CapClientName(EFAlias.MAX_NAME_LENGTH);
|
||||
|
||||
if (entity.IPAddress != null)
|
||||
{
|
||||
@ -102,19 +103,21 @@ namespace SharedLibraryCore.Services
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UpdateAlias(string name, int? ip, EFClient entity, DatabaseContext context)
|
||||
private async Task UpdateAlias(string originalName, int? ip, EFClient entity, DatabaseContext context)
|
||||
{
|
||||
string name = originalName.CapClientName(EFAlias.MAX_NAME_LENGTH);
|
||||
|
||||
// entity is the tracked db context item
|
||||
// get all aliases by IP address and LinkId
|
||||
var iqAliases = context.Aliases
|
||||
.Include(a => a.Link)
|
||||
// we only want alias that have the same IP address or share a link
|
||||
.Where(_alias => _alias.IPAddress == ip || (_alias.LinkId == entity.AliasLinkId));
|
||||
|
||||
|
||||
var aliases = await iqAliases.ToListAsync();
|
||||
var currentIPs = aliases.Where(_a2 => _a2.IPAddress != null).Select(_a2 => _a2.IPAddress).Distinct();
|
||||
var floatingIPAliases = await context.Aliases.Where(_alias => currentIPs.Contains(_alias.IPAddress)).ToListAsync();
|
||||
aliases.AddRange(floatingIPAliases);
|
||||
aliases.AddRange(floatingIPAliases);
|
||||
|
||||
// see if they have a matching IP + Name but new NetworkId
|
||||
var existingExactAlias = aliases.OrderBy(_alias => _alias.LinkId).FirstOrDefault(a => a.Name == name && a.IPAddress == ip);
|
||||
|
@ -6,7 +6,7 @@
|
||||
<ApplicationIcon />
|
||||
<StartupObject />
|
||||
<PackageId>RaidMax.IW4MAdmin.SharedLibraryCore</PackageId>
|
||||
<Version>2.2.7</Version>
|
||||
<Version>2.2.8</Version>
|
||||
<Authors>RaidMax</Authors>
|
||||
<Company>Forever None</Company>
|
||||
<Configurations>Debug;Release;Prerelease</Configurations>
|
||||
@ -15,13 +15,13 @@
|
||||
<PackageTags>IW4MAdmin</PackageTags>
|
||||
<RepositoryUrl>https://github.com/RaidMax/IW4M-Admin/</RepositoryUrl>
|
||||
<PackageProjectUrl>https://www.raidmax.org/IW4MAdmin/</PackageProjectUrl>
|
||||
<Copyright>2019</Copyright>
|
||||
<Copyright>2020</Copyright>
|
||||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<Description>Shared Library for IW4MAdmin</Description>
|
||||
<AssemblyVersion>2.2.7.0</AssemblyVersion>
|
||||
<FileVersion>2.2.7.0</FileVersion>
|
||||
<AssemblyVersion>2.2.8.0</AssemblyVersion>
|
||||
<FileVersion>2.2.8.0</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Prerelease|AnyCPU'">
|
||||
|
@ -94,6 +94,18 @@ namespace SharedLibraryCore
|
||||
return newStr;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// caps client name to the specified character length - 3
|
||||
/// and adds ellipses to the end of the reamining client name
|
||||
/// </summary>
|
||||
/// <param name="str">client name</param>
|
||||
/// <param name="maxLength">max number of characters for the name</param>
|
||||
/// <returns></returns>
|
||||
public static string CapClientName(this string str, int maxLength) =>
|
||||
str.Length > maxLength ?
|
||||
$"{str.Substring(0, maxLength - 3)}..." :
|
||||
str;
|
||||
|
||||
/// <summary>
|
||||
/// helper method to get the information about an exception and inner exceptions
|
||||
/// </summary>
|
||||
|
Reference in New Issue
Block a user