Skip to content

Commit

Permalink
Allow admins to bypass map regulations
Browse files Browse the repository at this point in the history
  • Loading branch information
matte-ek committed Apr 30, 2023
1 parent 19b75ba commit 942f361
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
8 changes: 5 additions & 3 deletions BanchoMultiplayerBot/Behaviour/MapManagerBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ private async void OnBeatmapChanged(BeatmapShell beatmap)

private async Task EnsureBeatmapLimits(BeatmapModel beatmap, int id)
{
if (IsAllowedBeatmapLength(beatmap) && IsAllowedBeatmapStarRating(beatmap) && IsAllowedBeatmapGameMode(beatmap) && !IsBannedBeatmap(beatmap))
bool hostIsAdministrator = _lobby.MultiplayerLobby.Host is not null && _lobby.IsAdministrator(_lobby.MultiplayerLobby.Host.Name);

if ((IsAllowedBeatmapLength(beatmap) && IsAllowedBeatmapStarRating(beatmap) && IsAllowedBeatmapGameMode(beatmap) && !IsBannedBeatmap(beatmap)) || hostIsAdministrator)
{
// Update the fallback id whenever someone picks a map that's
// within limits, so we don't have to reset to the osu!tutorial everytime.
// within limits, so we don't have to reset to the osu!tutorial every time.
_beatmapFallbackId = id;

CurrentBeatmapName = $"{beatmap.Artist} - {beatmap.Title}";
Expand All @@ -136,7 +138,7 @@ private async Task EnsureBeatmapLimits(BeatmapModel beatmap, int id)
_botAppliedBeatmap = true;
_lastBotAppliedBeatmap = CurrentBeatmapId;

// By "setting" the map ourself directly after the host picked it,
// By "setting" the map our self directly after the host picked it,
// it will automatically be set to the newest version, even if the host's one is outdated.
_lobby.SendMessage($"!mp map {CurrentBeatmapId} 0");

Expand Down
20 changes: 10 additions & 10 deletions BanchoMultiplayerBot/Lobby.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ public void SendMessage(string message)
Bot.SendMessage(Channel, message);
}

public bool IsAdministrator(string username)
{
if (Bot.Configuration.Username == username)
return true;
if (Bot.Configuration.Administrators != null && username.Any() && Bot.Configuration.Administrators.FirstOrDefault(x => x.Name == username) != null)
return true;

return false;
}

/// <summary>
/// Get what string to use when passing a player as a parameter in tournament commands.
/// This will make sure to prioritize player ID, or use player names if not available.
Expand Down Expand Up @@ -213,15 +223,5 @@ private void AddMessageToHistory(IPrivateIrcMessage message)
RecentMessages.Add(message);
}

private bool IsAdministrator(string username)
{
if (Bot.Configuration.Username == username)
return true;
if (Bot.Configuration.Administrators != null && username.Any() && Bot.Configuration.Administrators.FirstOrDefault(x => x.Name == username) != null)
return true;

return false;
}

private void AddBehaviour(IBotBehaviour behaviour) => Behaviours.Add(behaviour);
}

0 comments on commit 942f361

Please sign in to comment.