Alert shared connections (#29405)
* add admin alert for active shared connections * update wizden config * review
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Content.Server.Chat.Managers;
|
||||||
using Content.Server.Database;
|
using Content.Server.Database;
|
||||||
using Content.Server.GameTicking;
|
using Content.Server.GameTicking;
|
||||||
using Content.Server.Preferences.Managers;
|
using Content.Server.Preferences.Managers;
|
||||||
@@ -10,7 +12,9 @@ using Content.Shared.GameTicking;
|
|||||||
using Content.Shared.Players.PlayTimeTracking;
|
using Content.Shared.Players.PlayTimeTracking;
|
||||||
using Robust.Server.Player;
|
using Robust.Server.Player;
|
||||||
using Robust.Shared.Configuration;
|
using Robust.Shared.Configuration;
|
||||||
|
using Robust.Shared.Enums;
|
||||||
using Robust.Shared.Network;
|
using Robust.Shared.Network;
|
||||||
|
using Robust.Shared.Player;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -50,6 +54,7 @@ namespace Content.Server.Connection
|
|||||||
[Dependency] private readonly ServerDbEntryManager _serverDbEntry = default!;
|
[Dependency] private readonly ServerDbEntryManager _serverDbEntry = default!;
|
||||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||||
[Dependency] private readonly ILogManager _logManager = default!;
|
[Dependency] private readonly ILogManager _logManager = default!;
|
||||||
|
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||||
|
|
||||||
private readonly Dictionary<NetUserId, TimeSpan> _temporaryBypasses = [];
|
private readonly Dictionary<NetUserId, TimeSpan> _temporaryBypasses = [];
|
||||||
private ISawmill _sawmill = default!;
|
private ISawmill _sawmill = default!;
|
||||||
@@ -60,6 +65,7 @@ namespace Content.Server.Connection
|
|||||||
|
|
||||||
_netMgr.Connecting += NetMgrOnConnecting;
|
_netMgr.Connecting += NetMgrOnConnecting;
|
||||||
_netMgr.AssignUserIdCallback = AssignUserIdCallback;
|
_netMgr.AssignUserIdCallback = AssignUserIdCallback;
|
||||||
|
_plyMgr.PlayerStatusChanged += PlayerStatusChanged;
|
||||||
// Approval-based IP bans disabled because they don't play well with Happy Eyeballs.
|
// Approval-based IP bans disabled because they don't play well with Happy Eyeballs.
|
||||||
// _netMgr.HandleApprovalCallback = HandleApproval;
|
// _netMgr.HandleApprovalCallback = HandleApproval;
|
||||||
}
|
}
|
||||||
@@ -128,6 +134,42 @@ namespace Content.Server.Connection
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void PlayerStatusChanged(object? sender, SessionStatusEventArgs args)
|
||||||
|
{
|
||||||
|
if (args.NewStatus == SessionStatus.Connected)
|
||||||
|
{
|
||||||
|
AdminAlertIfSharedConnection(args.Session);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AdminAlertIfSharedConnection(ICommonSession newSession)
|
||||||
|
{
|
||||||
|
var playerThreshold = _cfg.GetCVar(CCVars.AdminAlertMinPlayersSharingConnection);
|
||||||
|
if (playerThreshold < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var addr = newSession.Channel.RemoteEndPoint.Address;
|
||||||
|
|
||||||
|
var otherConnectionsFromAddress = _plyMgr.Sessions.Where(session =>
|
||||||
|
session.Status is SessionStatus.Connected or SessionStatus.InGame
|
||||||
|
&& session.Channel.RemoteEndPoint.Address.Equals(addr)
|
||||||
|
&& session.UserId != newSession.UserId)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var otherConnectionCount = otherConnectionsFromAddress.Count;
|
||||||
|
if (otherConnectionCount + 1 < playerThreshold) // Add one for the total, not just others, using the address
|
||||||
|
return;
|
||||||
|
|
||||||
|
var username = newSession.Name;
|
||||||
|
var otherUsernames = string.Join(", ",
|
||||||
|
otherConnectionsFromAddress.Select(session => session.Name));
|
||||||
|
|
||||||
|
_chatManager.SendAdminAlert(Loc.GetString("admin-alert-shared-connection",
|
||||||
|
("player", username),
|
||||||
|
("otherCount", otherConnectionCount),
|
||||||
|
("otherList", otherUsernames)));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO: Jesus H Christ what is this utter mess of a function
|
* TODO: Jesus H Christ what is this utter mess of a function
|
||||||
* TODO: Break this apart into is constituent steps.
|
* TODO: Break this apart into is constituent steps.
|
||||||
|
|||||||
@@ -832,6 +832,15 @@ namespace Content.Shared.CCVar
|
|||||||
public static readonly CVarDef<bool> ServerBanErasePlayer =
|
public static readonly CVarDef<bool> ServerBanErasePlayer =
|
||||||
CVarDef.Create("admin.server_ban_erase_player", false, CVar.ARCHIVE | CVar.SERVER | CVar.REPLICATED);
|
CVarDef.Create("admin.server_ban_erase_player", false, CVar.ARCHIVE | CVar.SERVER | CVar.REPLICATED);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Minimum players sharing a connection required to create an alert. -1 to disable the alert.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// If you set this to 0 or 1 then it will alert on every connection, so probably don't do that.
|
||||||
|
/// </remarks>
|
||||||
|
public static readonly CVarDef<int> AdminAlertMinPlayersSharingConnection =
|
||||||
|
CVarDef.Create("admin.alert.min_players_sharing_connection", -1, CVar.SERVERONLY);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Minimum explosion intensity to create an admin alert message. -1 to disable the alert.
|
/// Minimum explosion intensity to create an admin alert message. -1 to disable the alert.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ limit = 10.0
|
|||||||
see_own_notes = true
|
see_own_notes = true
|
||||||
deadmin_on_join = true
|
deadmin_on_join = true
|
||||||
new_player_threshold = 600
|
new_player_threshold = 600
|
||||||
|
alert.min_players_sharing_connection = 2
|
||||||
|
|
||||||
[worldgen]
|
[worldgen]
|
||||||
enabled = true
|
enabled = true
|
||||||
|
|||||||
1
Resources/Locale/en-US/administration/admin-alerts.ftl
Normal file
1
Resources/Locale/en-US/administration/admin-alerts.ftl
Normal file
@@ -0,0 +1 @@
|
|||||||
|
admin-alert-shared-connection = {$player} is sharing a connection with {$otherCount} connected player(s): {$otherList}
|
||||||
Reference in New Issue
Block a user