Files
Flypaper/src/Flypaper.Core/Runtime/ConfiguredStrategySelector.cs
T
TomandClaude Sonnet 5.5 c5167262b9
Build and deploy / build (push) Successful in 1m34s
Build and deploy / deploy (push) Successful in 20s
Remove the unused content choice and the plain-text hold method
The link labyrinth held every catch that mattered, text-drip was never
used. Flypaper__Drip__Content now only triggers the removed-settings warning.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-21 14:21:54 +01:00

54 lines
2.3 KiB
C#

using Flypaper.Core.Abstractions;
using Flypaper.Core.Models;
using Flypaper.Core.Strategies;
using Microsoft.Extensions.Options;
namespace Flypaper.Core.Runtime;
public sealed class ConfiguredStrategySelector(
IEnumerable<ITarpitStrategy> strategies,
IOptionsMonitor<DripOptions> options,
IRandomSource random) : ITrapStrategySelector
{
public ITarpitStrategy? Select(TrapContext context)
{
var candidates = strategies.Where(strategy => strategy.Supports(context.Session.Protocol)).ToList();
if (string.Equals(context.Path, RobotsStaticStrategy.Path, StringComparison.OrdinalIgnoreCase)
&& candidates.FirstOrDefault(strategy => strategy.Name == RobotsStaticStrategy.StrategyName) is { } robots)
{
return robots;
}
if (context.IsNewIp && options.CurrentValue.Lure && LureContent.Handles(context.Path)
&& candidates.FirstOrDefault(strategy => strategy.Name == (context.Path == LureContent.PagePath ? LureStrategy.PageName : LureStrategy.IconName)) is { } lure)
{
return lure;
}
if (BaitPaths.Matches(BaitPaths.Parse(options.CurrentValue.BaitPaths), context.Path)
&& candidates.FirstOrDefault(strategy => strategy.Name == MazeDripStrategy.BaitName) is { } bait)
{
return bait;
}
if (options.CurrentValue.MatchPath && FileContent.Match(context.Path) is { } profile
&& candidates.FirstOrDefault(strategy => strategy.Name == profile.Name) is { } fileStrategy)
{
return fileStrategy;
}
var maze = options.CurrentValue.LinkSpacing > 0
&& candidates.Any(strategy => strategy.Name == MazeDripStrategy.PageName);
var page = maze ? MazeDripStrategy.PageName : HtmlDripStrategy.StrategyName;
var matching = candidates.Where(strategy => strategy.Name == page).ToList();
var chosen = matching.Count == 0
? candidates.FirstOrDefault()
: matching[random.Next(0, matching.Count)];
return chosen?.Name == MazeDripStrategy.PageName && MazeContent.IsDirectory(context.Path)
&& candidates.FirstOrDefault(strategy => strategy.Name == MazeDripStrategy.ListingName) is { } listing
? listing
: chosen;
}
}