Skip to content

Commit

Permalink
Fix bans not being applied immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
matte-ek committed Sep 14, 2023
1 parent 8a117ff commit fe538dd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
15 changes: 15 additions & 0 deletions BanchoMultiplayerBot/Behaviour/AutoHostRotateBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,21 @@ public void MovePlayer(MultiplayerPlayer player, int newPosition)
OnQueueUpdated();
}

public async Task RefreshPlayerBanStates()
{
foreach (var player in _lobby.MultiplayerLobby.Players)
{
if (!(await BanBehaviour.GetActivePlayerBans(player.Name)).Any())
continue;

// To make sure they aren't added afterwards.
_queueIgnorePlayers.Add(player.Name);

if (Queue.Contains(player.Name))
Queue.Remove(player.Name);
}
}

private void OnUserMessage(PlayerMessage message)
{
if (message.Content.ToLower().Equals("!q") || message.Content.ToLower().Equals("!queue"))
Expand Down
19 changes: 18 additions & 1 deletion BanchoMultiplayerBot/Behaviour/BanBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,29 @@ private async void OnAdminMessage(IPrivateIrcMessage e)
return;
}

var hostBan = hostBanOnly.ToLower() == "yes" || hostBanOnly.ToLower() == "true";

await banRepository.CreateBan(
user,
hostBanOnly.ToLower() == "yes" || hostBanOnly.ToLower() == "true",
hostBan,
reason,
expireTime != null ? DateTime.Now.AddDays(int.Parse(expireTime)) : null);

// If the user is banned from the lobby, we might as well ban him immediately
if (!hostBan)
{
_lobby.SendMessage($"!mp ban {playerName.ToIrcNameFormat()}");
}
else
{
// Or we'll have to make sure the AHR system gets notified of the news.
if (_lobby.Behaviours.Find(x => x.GetType() == typeof(AutoHostRotateBehaviour)) is
AutoHostRotateBehaviour autoHostRotateBehaviour)
{
await autoHostRotateBehaviour.RefreshPlayerBanStates();
}
}

_lobby.SendMessage("Player was successfully put on ban list.");
}

Expand Down

0 comments on commit fe538dd

Please sign in to comment.