Skip to content

Commit 205dd1a

Browse files
authored
Merge pull request #120 from blaho/session-mgr-cmp
Exposed information about banned players
2 parents 5eceb21 + 9c505c4 commit 205dd1a

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎Torch.API/Managers/IMultiplayerManagerServer.cs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,17 @@ public interface IMultiplayerManagerServer : IMultiplayerManagerBase
2020
/// Bans or unbans a player from the game.
2121
/// </summary>
2222
void BanPlayer(ulong steamId, bool banned = true);
23+
24+
/// <summary>
25+
/// List of the banned SteamID's
26+
/// </summary>
27+
IReadOnlyList<ulong> BannedPlayers { get; }
28+
29+
/// <summary>
30+
/// Checks if the player with the given SteamID is banned.
31+
/// </summary>
32+
/// <param name="steamId">The SteamID of the player.</param>
33+
/// <returns>True if the player is banned; otherwise false.</returns>
34+
bool IsBanned(ulong steamId);
2335
}
2436
}

‎Torch.Client/Manager/MultiplayerManagerLobby.cs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ namespace Torch.Client.Manager
1212
{
1313
public class MultiplayerManagerLobby : MultiplayerManagerBase, IMultiplayerManagerServer
1414
{
15+
/// <inheritdoc />
16+
public IReadOnlyList<ulong> BannedPlayers => new List<ulong>();
17+
1518
/// <inheritdoc />
1619
public MultiplayerManagerLobby(ITorchBase torch) : base(torch) { }
1720

@@ -21,6 +24,9 @@ public MultiplayerManagerLobby(ITorchBase torch) : base(torch) { }
2124
/// <inheritdoc />
2225
public void BanPlayer(ulong steamId, bool banned = true) => Torch.Invoke(() => MyMultiplayer.Static.BanClient(steamId, banned));
2326

27+
/// <inheritdoc />
28+
public bool IsBanned(ulong steamId) => false;
29+
2430
/// <inheritdoc/>
2531
public override void Attach()
2632
{

‎Torch.Server/Managers/MultiplayerManagerDedicated.cs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public class MultiplayerManagerDedicated : MultiplayerManagerBase, IMultiplayerM
3131
private static Func<MyDedicatedServerBase, HashSet<ulong>> _waitingForGroup;
3232
#pragma warning restore 649
3333

34+
/// <inheritdoc />
35+
public IReadOnlyList<ulong> BannedPlayers => MySandboxGame.ConfigDedicated.Banned;
36+
3437
private Dictionary<ulong, ulong> _gameOwnerIds = new Dictionary<ulong, ulong>();
3538

3639
/// <inheritdoc />
@@ -50,6 +53,9 @@ public void BanPlayer(ulong steamId, bool banned = true)
5053
});
5154
}
5255

56+
/// <inheritdoc />
57+
public bool IsBanned(ulong steamId) => _isClientBanned.Invoke(MyMultiplayer.Static, steamId) || MySandboxGame.ConfigDedicated.Banned.Contains(steamId);
58+
5359
/// <inheritdoc/>
5460
public override void Attach()
5561
{
@@ -107,7 +113,7 @@ public override void Detach()
107113
private void ValidateAuthTicketResponse(ulong steamID, JoinResult response, ulong steamOwner)
108114
{
109115
_log.Debug($"ValidateAuthTicketResponse(user={steamID}, response={response}, owner={steamOwner}");
110-
if (_isClientBanned.Invoke(MyMultiplayer.Static, steamOwner) || MySandboxGame.ConfigDedicated.Banned.Contains(steamOwner))
116+
if (IsBanned(steamOwner))
111117
{
112118
_userRejected.Invoke((MyDedicatedServerBase)MyMultiplayer.Static, steamID, JoinResult.BannedByAdmins);
113119
_raiseClientKicked.Invoke((MyDedicatedServerBase)MyMultiplayer.Static, steamID);

0 commit comments

Comments
 (0)