mirror of
https://github.com/Empostor/Empostor.git
synced 2026-11-19 13:16:48 +00:00
Add #end/#ban/#kick host commands, fix admin panel Active Games filter, fix double-title bug, make channel messages visible to all
This commit is contained in:
1 parent
0190bb854c
commit
92defb754f
22 files changed
+318
-46
No files matched your search
@@ -47,17 +47,6 @@ public sealed class PlayerConnectStore : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
public void RecordConnect(string productUserId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(productUserId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_lastConnect[productUserId] = DateTime.UtcNow;
|
||||
_dirty = true;
|
||||
}
|
||||
|
||||
public void RecordDisconnect(string productUserId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(productUserId))
|
||||
|
||||
@@ -57,10 +57,6 @@ public sealed class PlayerChannelCommand : ICommand
|
||||
|
||||
foreach (var player in ctx.Game.Players)
|
||||
{
|
||||
var fc = player.Client.FriendCode;
|
||||
if (string.IsNullOrEmpty(fc)) continue;
|
||||
if (!channel.FriendCodes.Contains(fc)) continue;
|
||||
|
||||
var targetCtrl = player.Character;
|
||||
if (targetCtrl == null) continue;
|
||||
|
||||
|
||||
@@ -132,6 +132,7 @@
|
||||
"NextFast.Hazel.Abstractions": {
|
||||
"type": "Project"
|
||||
}
|
||||
}
|
||||
},
|
||||
"net8.0/win-x64": {}
|
||||
}
|
||||
}
|
||||
@@ -46,16 +46,11 @@ public sealed class FriendCodeTitleListener : IEventListener
|
||||
|
||||
try
|
||||
{
|
||||
// Update server-side name for logging/admin panel
|
||||
var originalName = e.Client.Name;
|
||||
var displayName = TitleStore.BuildDisplayName(title, originalName);
|
||||
e.Client.Name = displayName;
|
||||
|
||||
// Store title so TitleEventListener can apply it in-game via SetNameAsync
|
||||
_store.Set(e.Client.Id, title);
|
||||
|
||||
_logger.LogInformation("[FriendCodeTitles] Applied [{Title}] to {Name} ({FC})",
|
||||
title, displayName, fc);
|
||||
_logger.LogInformation("[FriendCodeTitles] Stored [{Title}] for {Name} ({FC})",
|
||||
title, e.Client.Name, fc);
|
||||
|
||||
// Remove applied title so it is only used once
|
||||
_map.Remove(fc);
|
||||
|
||||
@@ -132,6 +132,7 @@
|
||||
"NextFast.Hazel.Abstractions": {
|
||||
"type": "Project"
|
||||
}
|
||||
}
|
||||
},
|
||||
"net8.0/win-x64": {}
|
||||
}
|
||||
}
|
||||
@@ -203,6 +203,7 @@
|
||||
"NextFast.Hazel.Abstractions": {
|
||||
"type": "Project"
|
||||
}
|
||||
}
|
||||
},
|
||||
"net8.0/win-x64": {}
|
||||
}
|
||||
}
|
||||
@@ -13,17 +13,20 @@ internal sealed class CommandBootstrapper : IHostedService
|
||||
private readonly ILogger<CommandBootstrapper> _logger;
|
||||
private readonly CommandService _commands;
|
||||
private readonly StatCommand _statCommand;
|
||||
private readonly BanCommand _banCommand;
|
||||
private readonly IEnumerable<ICommand> _pluginCommands;
|
||||
|
||||
public CommandBootstrapper(
|
||||
ILogger<CommandBootstrapper> logger,
|
||||
CommandService commands,
|
||||
StatCommand statCommand,
|
||||
BanCommand banCommand,
|
||||
IEnumerable<ICommand> pluginCommands)
|
||||
{
|
||||
_logger = logger;
|
||||
_commands = commands;
|
||||
_statCommand = statCommand;
|
||||
_banCommand = banCommand;
|
||||
_pluginCommands = pluginCommands;
|
||||
}
|
||||
|
||||
@@ -35,6 +38,9 @@ internal sealed class CommandBootstrapper : IHostedService
|
||||
_commands.Register(new MaxCommand());
|
||||
_commands.Register(new PlayersCommand());
|
||||
_commands.Register(new PingCommand());
|
||||
_commands.Register(new EndCommand());
|
||||
_commands.Register(new KickCommand());
|
||||
_commands.Register(_banCommand);
|
||||
_commands.Register(_statCommand);
|
||||
_commands.RegisterAll(_pluginCommands);
|
||||
_logger.LogInformation(
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Empostor.Api.Commands;
|
||||
using Empostor.Api.Net;
|
||||
using Empostor.Server.Service.Admin.Ban;
|
||||
using Next.Hazel;
|
||||
|
||||
namespace Empostor.Server.Commands.Commands;
|
||||
|
||||
public sealed class BanCommand : ICommand
|
||||
{
|
||||
private readonly BanStore _banStore;
|
||||
|
||||
public BanCommand(BanStore banStore)
|
||||
{
|
||||
_banStore = banStore;
|
||||
}
|
||||
|
||||
public string Name => "ban";
|
||||
|
||||
public string Description => "Ban a player by friend code or name. Host only.";
|
||||
|
||||
public string Usage => "ban <player> [reason]";
|
||||
|
||||
public async ValueTask<bool> ExecuteAsync(CommandContext ctx)
|
||||
{
|
||||
if (!ctx.Sender.IsHost)
|
||||
{
|
||||
await ctx.PlayerControl.SendChatToPlayerAsync(
|
||||
ctx.GetString("command.ban.not_host"), ctx.PlayerControl);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ctx.Args.Length == 0)
|
||||
{
|
||||
await ctx.PlayerControl.SendChatToPlayerAsync(
|
||||
ctx.GetString("command.ban.usage"), ctx.PlayerControl);
|
||||
return true;
|
||||
}
|
||||
|
||||
var search = ctx.Args[0].Trim();
|
||||
var reason = ctx.Args.Length > 1
|
||||
? string.Join(" ", ctx.Args.Skip(1))
|
||||
: "Banned by host";
|
||||
|
||||
var target = FindPlayer(ctx, search);
|
||||
if (target == null)
|
||||
{
|
||||
await ctx.PlayerControl.SendChatToPlayerAsync(
|
||||
ctx.GetString("command.ban.not_found").Format(search), ctx.PlayerControl);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (target.IsHost)
|
||||
{
|
||||
await ctx.PlayerControl.SendChatToPlayerAsync(
|
||||
ctx.GetString("command.ban.cannot_ban_self"), ctx.PlayerControl);
|
||||
return true;
|
||||
}
|
||||
|
||||
var name = target.Client.Name;
|
||||
var fc = target.Client.FriendCode;
|
||||
|
||||
// Ban by friend code if available
|
||||
if (!string.IsNullOrEmpty(fc))
|
||||
{
|
||||
_banStore.BanFriendCode(fc, reason);
|
||||
}
|
||||
|
||||
// Ban by IP
|
||||
var ip = target.Client.Connection?.EndPoint?.Address;
|
||||
if (ip != null)
|
||||
{
|
||||
_banStore.BanIp(ip, reason);
|
||||
}
|
||||
|
||||
await target.Client.DisconnectAsync(DisconnectReason.Banned, reason);
|
||||
|
||||
var key = !string.IsNullOrEmpty(fc) ? fc : name;
|
||||
await ctx.PlayerControl.SendChatToPlayerAsync(
|
||||
ctx.GetString("command.ban.banned").Format(key, reason), ctx.PlayerControl);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static IClientPlayer? FindPlayer(CommandContext ctx, string search)
|
||||
{
|
||||
return ctx.Game.Players.FirstOrDefault(p =>
|
||||
{
|
||||
var fc = p.Client.FriendCode;
|
||||
if (!string.IsNullOrEmpty(fc) && fc.Equals(search, System.StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
if (!string.IsNullOrEmpty(fc) && fc.Contains(search, System.StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
if (!string.IsNullOrEmpty(p.Client.Name) && p.Client.Name.Contains(search, System.StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Empostor.Api.Commands;
|
||||
using Empostor.Api.Net;
|
||||
using Next.Hazel;
|
||||
|
||||
namespace Empostor.Server.Commands.Commands;
|
||||
|
||||
public sealed class EndCommand : ICommand
|
||||
{
|
||||
public string Name => "end";
|
||||
|
||||
public string Description => "End the current game. Host only.";
|
||||
|
||||
public string Usage => "end [reason]";
|
||||
|
||||
public async ValueTask<bool> ExecuteAsync(CommandContext ctx)
|
||||
{
|
||||
if (!ctx.Sender.IsHost)
|
||||
{
|
||||
await ctx.PlayerControl.SendChatToPlayerAsync(
|
||||
ctx.GetString("command.end.not_host"), ctx.PlayerControl);
|
||||
return true;
|
||||
}
|
||||
|
||||
var reason = string.IsNullOrWhiteSpace(ctx.RawArgs)
|
||||
? "Game ended by host"
|
||||
: ctx.RawArgs.Trim();
|
||||
|
||||
var players = ctx.Game.Players.ToList();
|
||||
foreach (var p in players)
|
||||
{
|
||||
await p.Client.DisconnectAsync(DisconnectReason.Custom, reason);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Empostor.Api.Commands;
|
||||
using Empostor.Api.Net;
|
||||
using Next.Hazel;
|
||||
|
||||
namespace Empostor.Server.Commands.Commands;
|
||||
|
||||
public sealed class KickCommand : ICommand
|
||||
{
|
||||
public string Name => "kick";
|
||||
|
||||
public string Description => "Kick a player by friend code or name. Host only.";
|
||||
|
||||
public string Usage => "kick <player> [reason]";
|
||||
|
||||
public async ValueTask<bool> ExecuteAsync(CommandContext ctx)
|
||||
{
|
||||
if (!ctx.Sender.IsHost)
|
||||
{
|
||||
await ctx.PlayerControl.SendChatToPlayerAsync(
|
||||
ctx.GetString("command.kick.not_host"), ctx.PlayerControl);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ctx.Args.Length == 0)
|
||||
{
|
||||
await ctx.PlayerControl.SendChatToPlayerAsync(
|
||||
ctx.GetString("command.kick.usage"), ctx.PlayerControl);
|
||||
return true;
|
||||
}
|
||||
|
||||
var search = ctx.Args[0].Trim();
|
||||
var reason = ctx.Args.Length > 1
|
||||
? string.Join(" ", ctx.Args.Skip(1))
|
||||
: "Kicked by host";
|
||||
|
||||
var target = FindPlayer(ctx, search);
|
||||
if (target == null)
|
||||
{
|
||||
await ctx.PlayerControl.SendChatToPlayerAsync(
|
||||
ctx.GetString("command.kick.not_found").Format(search), ctx.PlayerControl);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (target.IsHost)
|
||||
{
|
||||
await ctx.PlayerControl.SendChatToPlayerAsync(
|
||||
ctx.GetString("command.kick.cannot_kick_self"), ctx.PlayerControl);
|
||||
return true;
|
||||
}
|
||||
|
||||
var name = target.Client.Name;
|
||||
await target.Client.DisconnectAsync(DisconnectReason.Kicked, reason);
|
||||
|
||||
await ctx.PlayerControl.SendChatToPlayerAsync(
|
||||
ctx.GetString("command.kick.kicked").Format(name, reason), ctx.PlayerControl);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static IClientPlayer? FindPlayer(CommandContext ctx, string search)
|
||||
{
|
||||
return ctx.Game.Players.FirstOrDefault(p =>
|
||||
{
|
||||
var fc = p.Client.FriendCode;
|
||||
if (!string.IsNullOrEmpty(fc) && fc.Equals(search, System.StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
if (!string.IsNullOrEmpty(fc) && fc.Contains(search, System.StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
if (!string.IsNullOrEmpty(p.Client.Name) && p.Client.Name.Contains(search, System.StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -166,7 +166,7 @@ namespace Empostor.Server.Http
|
||||
Response.Cookies.Append("empostor_admin", _passwordHash, new CookieOptions
|
||||
{
|
||||
HttpOnly = true,
|
||||
Secure = true,
|
||||
Secure = Request.IsHttps,
|
||||
SameSite = SameSiteMode.Strict,
|
||||
MaxAge = TimeSpan.FromHours(8),
|
||||
});
|
||||
@@ -231,14 +231,21 @@ namespace Empostor.Server.Http
|
||||
}
|
||||
|
||||
[HttpGet("/api/admin/games")]
|
||||
public IActionResult GetGames()
|
||||
public IActionResult GetGames([FromQuery] string? state = null)
|
||||
{
|
||||
if (!IsAuthenticated())
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
return Ok(_gameManager.Games.Select(Snap));
|
||||
var games = _gameManager.Games.AsEnumerable();
|
||||
if (!string.IsNullOrWhiteSpace(state)
|
||||
&& Enum.TryParse<GameStates>(state, ignoreCase: true, out var filterState))
|
||||
{
|
||||
games = games.Where(g => g.GameState == filterState);
|
||||
}
|
||||
|
||||
return Ok(games.Select(Snap));
|
||||
}
|
||||
|
||||
[HttpGet("/api/admin/clients")]
|
||||
|
||||
@@ -1148,8 +1148,9 @@ internal static class AdminTemplateDefaults
|
||||
} catch { document.getElementById('dot').style.background = 'var(--r)'; }
|
||||
}
|
||||
|
||||
async function fGames(tid, short) {
|
||||
const { data: gs } = await api('GET', '/api/admin/games');
|
||||
async function fGames(tid, short, state) {
|
||||
const url = '/api/admin/games' + (state ? '?state=' + state : '');
|
||||
const { data: gs } = await api('GET', url);
|
||||
const tb = document.getElementById(tid);
|
||||
if (!gs.length) {
|
||||
tb.innerHTML = `<tr><td colspan="${short ? 6 : 7}" class="empty">${_('games.none', 'No games')}</td></tr>`;
|
||||
@@ -1479,7 +1480,7 @@ internal static class AdminTemplateDefaults
|
||||
}
|
||||
|
||||
function refreshTab() {
|
||||
if (cur === 'ov') fGames('ov-t', true);
|
||||
if (cur === 'ov') fGames('ov-t', true, 'Started');
|
||||
if (cur === 'gm') fGames('gm-t', false);
|
||||
if (cur === 'cl') fClients();
|
||||
if (cur === 'ki') fKickList();
|
||||
|
||||
@@ -49,5 +49,22 @@
|
||||
"command.note.description": "Set or clear a lobby note (host only).",
|
||||
"command.note.usage": "note <text> | note clear",
|
||||
"command.max.description": "Set max players for the lobby (host only).",
|
||||
"command.max.usage": "max <1-15>"
|
||||
"command.max.usage": "max <1-15>",
|
||||
"command.end.not_host": "Only the host can end the game.",
|
||||
"command.end.description": "End the current game. Host only.",
|
||||
"command.end.usage": "end [reason]",
|
||||
"command.kick.not_host": "Only the host can kick players.",
|
||||
"command.kick.usage": "Usage: #kick <player> [reason]",
|
||||
"command.kick.not_found": "Player not found: {0}",
|
||||
"command.kick.cannot_kick_self": "You cannot kick yourself.",
|
||||
"command.kick.kicked": "{0} has been kicked. Reason: {1}",
|
||||
"command.kick.description": "Kick a player by friend code or name. Host only.",
|
||||
"command.kick.usage_cmd": "kick <player> [reason]",
|
||||
"command.ban.not_host": "Only the host can ban players.",
|
||||
"command.ban.usage": "Usage: #ban <player> [reason]",
|
||||
"command.ban.not_found": "Player not found: {0}",
|
||||
"command.ban.cannot_ban_self": "You cannot ban yourself.",
|
||||
"command.ban.banned": "{0} has been banned. Reason: {1}",
|
||||
"command.ban.description": "Ban a player by friend code or name. Host only.",
|
||||
"command.ban.usage_cmd": "ban <player> [reason]"
|
||||
}
|
||||
@@ -48,5 +48,22 @@
|
||||
"command.note.description": "设置或清除房间备注(仅房主)。",
|
||||
"command.note.usage": "note <文字> | note clear",
|
||||
"command.max.description": "设置房间最大人数(仅房主)。",
|
||||
"command.max.usage": "max <1-15>"
|
||||
"command.max.usage": "max <1-15>",
|
||||
"command.end.not_host": "只有房主可以解散游戏。",
|
||||
"command.end.description": "解散当前游戏(仅房主)。",
|
||||
"command.end.usage": "end [原因]",
|
||||
"command.kick.not_host": "只有房主可以踢出玩家。",
|
||||
"command.kick.usage": "用法:#kick <玩家> [原因]",
|
||||
"command.kick.not_found": "未找到玩家:{0}",
|
||||
"command.kick.cannot_kick_self": "你不能踢出自己。",
|
||||
"command.kick.kicked": "{0} 已被踢出。原因:{1}",
|
||||
"command.kick.description": "通过好友代码或名称踢出玩家(仅房主)。",
|
||||
"command.kick.usage_cmd": "kick <玩家> [原因]",
|
||||
"command.ban.not_host": "只有房主可以封禁玩家。",
|
||||
"command.ban.usage": "用法:#ban <玩家> [原因]",
|
||||
"command.ban.not_found": "未找到玩家:{0}",
|
||||
"command.ban.cannot_ban_self": "你不能封禁自己。",
|
||||
"command.ban.banned": "{0} 已被封禁。原因:{1}",
|
||||
"command.ban.description": "通过好友代码或名称封禁玩家(仅房主)。",
|
||||
"command.ban.usage_cmd": "ban <玩家> [原因]"
|
||||
}
|
||||
@@ -220,11 +220,6 @@ namespace Empostor.Server.Net.Manager
|
||||
client.ProductUserId = authInfo?.ProductUserId;
|
||||
client.DeltaPort = deltaPort;
|
||||
|
||||
if (!string.IsNullOrEmpty(client.ProductUserId))
|
||||
{
|
||||
_playerConnectStore.RecordConnect(client.ProductUserId);
|
||||
}
|
||||
|
||||
client.Id = id;
|
||||
_logger.LogDebug("#{Id} {Name} │ connected │ FC={FC} │ port {DP}", id, name, client.FriendCode ?? "(none)", deltaPort);
|
||||
_clients.TryAdd(id, client);
|
||||
|
||||
@@ -141,6 +141,23 @@ namespace Empostor.Server.Net.Manager
|
||||
_logger.LogWarning("Client {Name}({ClientId}) left empty game open when disconnecting", client.Name, client.Id);
|
||||
await RemoveAsync(game.Code);
|
||||
}
|
||||
|
||||
// Also clean up games where this client is the current host but not the original creator
|
||||
foreach (var g in _games.Values)
|
||||
{
|
||||
if (g.GameState == GameStates.Destroyed)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (g.Host?.Client == client)
|
||||
{
|
||||
_logger.LogWarning(
|
||||
"Game {Code} host {Name}({ClientId}) disconnected, cleaning up",
|
||||
GameCodeParser.IntToGameName(g.Code), client.Name, client.Id);
|
||||
await RemoveAsync(g.Code);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,10 @@ namespace Empostor.Server.Net
|
||||
};
|
||||
|
||||
await _mainListener.StartAsync();
|
||||
|
||||
// Open firewall for the main port (delta ports are handled in StartDeltaListenerAsync)
|
||||
await _firewall.OpenPortAsync((ushort)ipEndPoint.Port);
|
||||
|
||||
_logger.LogInformation("Matchmaker UDP listener started on {EP}", ipEndPoint);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Empostor.Api.Config;
|
||||
using Empostor.Server.Service.Firewall;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
@@ -16,19 +17,22 @@ namespace Empostor.Server.Net
|
||||
private readonly HttpServerConfig _httpServerConfig;
|
||||
private readonly Matchmaker _matchmaker;
|
||||
private readonly PortPoolService _portPool;
|
||||
private readonly IFirewallService _firewall;
|
||||
|
||||
public MatchmakerService(
|
||||
ILogger<MatchmakerService> logger,
|
||||
IOptions<ServerConfig> serverConfig,
|
||||
IOptions<HttpServerConfig> httpServerConfig,
|
||||
Matchmaker matchmaker,
|
||||
PortPoolService portPool)
|
||||
PortPoolService portPool,
|
||||
IFirewallService firewall)
|
||||
{
|
||||
_logger = logger;
|
||||
_serverConfig = serverConfig.Value;
|
||||
_httpServerConfig = httpServerConfig.Value;
|
||||
_matchmaker = matchmaker;
|
||||
_portPool = portPool;
|
||||
_firewall = firewall;
|
||||
}
|
||||
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
@@ -37,6 +41,12 @@ namespace Empostor.Server.Net
|
||||
|
||||
await _matchmaker.StartAsync(endpoint);
|
||||
|
||||
// Open firewall for HTTP server TCP port
|
||||
if (_httpServerConfig.Enabled)
|
||||
{
|
||||
await _firewall.OpenPortAsync(_httpServerConfig.ListenPort, cancellationToken, "tcp");
|
||||
}
|
||||
|
||||
_logger.LogInformation(
|
||||
"Matchmaker is listening on {Address}:{Port}, the public server ip is {PublicIp}:{PublicPort}.",
|
||||
endpoint.Address,
|
||||
|
||||
@@ -19,9 +19,9 @@ public sealed class FirewalldFirewallService : IFirewallService
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async ValueTask OpenPortAsync(ushort port, CancellationToken ct = default)
|
||||
public async ValueTask OpenPortAsync(ushort port, CancellationToken ct = default, string protocol = "udp")
|
||||
{
|
||||
await RunFirewallCmdAsync($"--add-port={port}/udp --permanent", ct);
|
||||
await RunFirewallCmdAsync($"--add-port={port}/{protocol} --permanent", ct);
|
||||
await RunFirewallCmdAsync("--reload", ct);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Empostor.Server.Service.Firewall;
|
||||
|
||||
public interface IFirewallService
|
||||
{
|
||||
ValueTask OpenPortAsync(ushort port, CancellationToken ct = default);
|
||||
ValueTask OpenPortAsync(ushort port, CancellationToken ct = default, string protocol = "udp");
|
||||
|
||||
ValueTask ClosePortAsync(ushort port, CancellationToken ct = default);
|
||||
}
|
||||
@@ -16,9 +16,9 @@ public sealed class NoopFirewallService : IFirewallService
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public ValueTask OpenPortAsync(ushort port, CancellationToken ct = default)
|
||||
public ValueTask OpenPortAsync(ushort port, CancellationToken ct = default, string protocol = "udp")
|
||||
{
|
||||
_logger.LogDebug("FirewallNoop: would open port {Port}/udp", port);
|
||||
_logger.LogDebug("FirewallNoop: would open port {Port}/{Protocol}", port, protocol);
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@ public sealed class UfwFirewallService : IFirewallService
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async ValueTask OpenPortAsync(ushort port, CancellationToken ct = default)
|
||||
public async ValueTask OpenPortAsync(ushort port, CancellationToken ct = default, string protocol = "udp")
|
||||
{
|
||||
await RunUfwAsync($"allow {port}/udp", ct);
|
||||
await RunUfwAsync($"allow {port}/{protocol}", ct);
|
||||
}
|
||||
|
||||
public async ValueTask ClosePortAsync(ushort port, CancellationToken ct = default)
|
||||
|
||||
Reference in new issue
Block a user