matte-ek / BanchoMultiplayerBot

Auto host rotation multiplayer bot for osu! written in C#
GNU General Public License v3.0
25 stars 6 forks source link
bot csharp osugame

Bancho Multiplayer Bot

Multiplayer bot for osu! written in C#, powered by BanchoSharp

image

v2.0 branch

Why?

Been wanting to re-write the bot (or parts of the bot) for a while, both due to the messy code and "execution flow", but also due to general stability issues. Some of the initial goals of V2 where:

Progress

As of 2024-08-11 most of the user facing features are pretty much 1:1 to v1, with the exception of announcements. However the API and frontend is not completed yet, and there will also be a lot of stability and testing to be done. While the earlier version may have buggy code, it's up-time is very good.

Implementation Details

To make things easier and cleaner on the bot side, I've decided to move out Bancho and bancho connection related stuff to it's own project BanchoMultiplayerBot.Bancho, of which will completely abstract:

The new event system treats behavious similarly to a controller in ASP, where a new instance of the behavior will be created for each event, and the appropriate event will be executed inside of the behavior. A behavior will therefore not have to handle subscribing and unsubscribing to events, nor will it have to deal with saving/loading data. A fully functional behavior can therefore be implemented as such:

public class TestBehavior(BehaviorEventContext context) : IBehavior
{
    [BanchoEvent(BanchoEventType.MatchStarted)]
    public void OnMatchStarted()
    {
        context.SendMessage("Good luck!");
    }
}

Dealing with data inside of a behavior is dealt via BehaviorDataProvider<T> and BehaviorConfigProvider<T>. The data provider should be used for dynamic data related to the current lobby itself, such as the current queue for example. While the config provider should be used for static configuration such as the minimum/maximum map length etc. There is still some minor things I probably want to change with these, so they aren't really final at all.

Timers and votes are also a somewhat common thing to deal with, and for that the VoteProvider and TimerProvider can be used, see below example for a timer:

public class TestBehavior(BehaviorEventContext context) : IBehavior
{
    [BanchoEvent(BanchoEventType.MatchStarted)]
    public void OnMatchStarted()
    {
        _context.SendMessage("Waiting for 30 seconds...");
        _context.TimerProvider.FindOrCreateTimer("TestTimer").Start(TimeSpan.FromSeconds(30));
    }

    [BotEvent(BotEventType.TimerElapsed, "TestTimer")]
    public void OnTestTimerElapsed()
    {
        _context.SendMessage("30 seconds has passed!");
    }
}

You can also for example send arbitrary events to all behaviors in the lobby with BehaviorEventProcessor.OnBehaviorEvent("MyEvent", optionalParameter).

Commands can now also be created more easily, by implementing the IPlayerCommand interface. Commands can also be processed in an event by the attribute [BotEvent(BotEventType.CommandExecuted, "MyCommand")].

Libraries used

(And also the "bigger" ones such as the ASP.NET stack, SeriLog, EntityFrameworkCore, Newtonsoft.Json, Moq, prometheus-net)

Additional Thanks

hburn7 (Stage) for BanchoSharp and other help

iWeeti for a very nice statistics website built for the bot

bitknox for giving me cool ideas for the project and additional help