bancho.irc

Provides an IRC connection to Bancho (osu!'s server system) and access to its commands (Multiplayer room creation)

  • Declaration

    struct Message;

    Represents a simple sent message from bancho

    • Declaration

      string sender;

      User who wrote this message

    • Declaration

      string target;

      Target channel (#channel) or username

    • Declaration

      string message;

      content of the message

    • Declaration

      string toString();

      Serializes to "[sender] -> [target]: [message]"

  • Declaration

    struct TopicChange;

    Represents a topic change event (in the case of a multi room being created)

    • Declaration

      string channel;

    • Declaration

      string topic;

  • Declaration

    struct Quit;

    Represents a user quitting or joining the IRC ingame or via web/irc

    • Declaration

      string user;

    • Declaration

      string reason;

      Mostly one out of: - "ping timeout 80s" - "quit" - "replaced (None 0ea7ac91-60bf-448b-adda-bc6b8d096dc7)" - "replaced (Supporter c83820bb-a602-43f0-8f17-04718e34b72d)"

  • Declaration

    template Processor(string fn, Arg, size_t backlog)

    Utility mixin template implementing dynamic timeout based event subscribing + static backlog Creates methods waitFor, process[fn], fetchOld[fn]Log, clear[fn]Log

  • Declaration

    class BanchoBot;

    Represents a Bancho IRC connection.

    Examples

    1. BanchoBot bot = new BanchoBot("User", "hunter2"); runTask({ while (true) { bot.connect(); logDiagnostic("Got disconnected from bancho..."); sleep(2.seconds); } });

    • Declaration

      bool delegate(Message)[] processorsMessage;
      bool delegate(Quit)[] processorsQuit;
      bool delegate(TopicChange)[] processorsTopic;

      list of event subscribers. Gets removed automatically when called and returns true, otherwise caller has to remove it.

    • Declaration

      Message[256] backlogsMessage;
      Quit[256] backlogsQuit;
      TopicChange[8] backlogsTopic;

      list of backlog which hasn't been handled by any event subscribers, oldest one will always be replaced on new ones.

    • Declaration

      Message waitForMessage(bool delegate(Message) check, Duration timeout);
      Quit waitForQuit(bool delegate(Quit) check, Duration timeout);
      TopicChange waitForTopic(bool delegate(TopicChange) check, Duration timeout);

      Waits for an event or returns one which is in the backlog already. Removes matching backlog entries.

      Throws

      InterruptException on timeout

      Parameters

      bool delegate(Message) check

      a delegate checking for which object to check for. Return true to return this object & not add it to the backlog.

      Duration timeout

      the timeout after which to interrupt the waiting task

    • Declaration

      void processMessage(Message message);
      void processQuit(Quit quit);
      void processTopic(TopicChange change);

      Calls all event subscribers to try to match this object, otherwise replace the oldest element in the backlog with this.

      Throws

      anything thrown in event subscribers will get thrown here too.

    • Declaration

      Message[] fetchOldMessageLog(bool delegate(Message) check, bool returnIt = true);
      Quit[] fetchOldQuitLog(bool delegate(Quit) check, bool returnIt = true);
      TopicChange[] fetchOldTopicLog(bool delegate(TopicChange) check, bool returnIt = true);

      Goes through the backlog and removes and optionally returns all matching objects.

      Parameters

      bool delegate(Message) check

      a delegate checking for which object to check for. Return true to return this object & removing it from the backlog.

      bool returnIt

      pass true to return the list of objects (GC), pass false to simply return an empty list and only remove from the backlog.

    • Declaration

      void clearMessageLog();
      void clearQuitLog();
      void clearTopicLog();

      Clears all backlog & removes all event listeners for the object type.

    • Declaration

      OsuRoom[] rooms;

    • Declaration

      TCPConnection client;

    • Declaration

      string username;

    • Declaration

      string password;

    • Declaration

      this(string username, string password);

      Prepares a bancho IRC connection with username & password (can be obtained from https://osu.ppy.sh/p/irc)

    • Declaration

      void clear();

      Clears all logs, called by connect

    • Declaration

      void connect();

      Connects to irc.ppy.sh:6667 and authenticates with username & password. Blocks and processes all messages sent by the TCP socket. Recommended to be called in runTask. Cleans up on exit properly and is safe to be called again once returned.

    • Declaration

      void disconnect();

      Disconnects & closes the TCP socket.

    • Declaration

      void sendMessage(string channel, in char[] message);

      Sends a message to a username or channel (#channel).

    • Declaration

      Message[] waitForMessageBunch(bool delegate(Message) check, Duration timeout, Duration totalTimeout = 5.seconds, Duration inbetweenTimeout = 300.msecs);

      Waits for multiple messages sent at once and returns them.

      Parameters

      bool delegate(Message) check

      delegate to check if the message matches expectations (author, channel, etc)

      Duration timeout

      timeout to wait for first message

      Duration totalTimeout

      total time to spend starting waiting for messages

      Duration inbetweenTimeout

      timeout for a message after the first message. totalTimeout + inbetweenTimeout is the maximum amount of time this function runs.

    • Declaration

      OsuRoom createRoom(string title);

      Creates a new managed room with a title and returns it. Automatically gets room ID & game ID.

  • Declaration

    enum TeamMode: int;

  • Declaration

    enum ScoreMode: int;

  • Declaration

    enum Team: int;

    • Declaration

      None

      default, used when mode is not TeamVs/TagTeamVs

    • Red

      Declaration

      Red

    • Declaration

      Blue

  • Mod

    Declaration

    enum Mod: string;

  • Declaration

    string shortForm(Mod mod);

    Generates the short form for a mod (eg Hidden -> HD), can be more than 2 characters

  • Declaration

    alias HighPriority = std.typecons.Flag!"highPriority".Flag;

  • Declaration

    class OsuRoom;

    Represents a multiplayer lobby in osu! Automatically does ratelimiting by not sending more than a message every 2 seconds.

    Examples

    1. BanchoBot banchoConnection = new BanchoBot("WebFreak", ""); bool running = true; auto botTask = runTask({ while (running) { banchoConnection.connect(); logDiagnostic("Got disconnected from bancho..."); sleep(2.seconds); } }); sleep(3.seconds); auto users = ["WebFreak", "Node"]; OsuRoom room = banchoConnection.createRoom("bob"); runTask({ foreach (user; users) room.invite(user); }); runTask({ room.password = "123456"; room.size = 8; room.mods = [Mod.Hidden, Mod.DoubleTime]; room.map = "1158325"; }); runTask({ int joined; try { while (true) { string user = room.waitForJoin(30.seconds); joined++; room.sendMessage("yay welcome " ~ user ~ "!", HighPriority.yes); } } catch (InterruptException) { if (joined == 0) { // forever alone room.close(); return; } } room.sendMessage("This is an automated test, this room will close in 10 seconds on timer"); room.setTimer(10.seconds); try { room.waitForTimer(15.seconds); } catch (InterruptException) { room.sendMessage("Timer didn't trigger :("); room.sendMessage("closing the room in 5s"); sleep(5.seconds); } room.close(); }).join(); running = false; banchoConnection.disconnect(); botTask.join();

    • Declaration

      struct Settings;

      Returned by !mp settings

      • Declaration

        struct Player;

        Represents a player state in the settings result

        • id

          Declaration

          string id;

          Player user information

        • url

          Declaration

          string url;

          Player user information

        • Declaration

          string name;

          Player user information

        • Declaration

          bool ready;

        • Declaration

          bool noMap;

        • Declaration

          bool host;

        • Declaration

          Mod[] mods;

          If freemods is enabled this contains user specific mods

        • Declaration

          Team team;

      • Declaration

        string name;

        Game name

      • Declaration

        string history;

        URL to match history

      • Declaration

        string beatmapID;

        Beatmap information

      • Declaration

        string beatmapURL;

        Beatmap information

      • Declaration

        string beatmapName;

        Beatmap information

      • Declaration

        Mod[] activeMods;

        Global active mods or all mods if freemods is off, contains Mod.FreeMod if on

      • Declaration

        TeamMode teamMode;

        Type of game (coop, tag team, etc.)

      • Declaration

        ScoreMode winCondition;

        Win condition (score, acc, combo, etc.)

      • Declaration

        int numPlayers;

        Number of players in this match

      • Declaration

        Player[16] players;

        All players for every slot (empty slots are Player.init)

    • Declaration

      const @property string room();

      Returns the room ID as usable in the mp history URL or IRC joinable via #mp_ID

    • Declaration

      const @property string mpid();

      Returns the game ID as usable in osu://mp/ID urls

    • Declaration

      void close();

      Closes the room

    • Declaration

      void invite(string player);

      Invites a player to the room

    • Declaration

      void kick(string player);

      Kicks a player from the room

    • Declaration

      void move(string player, int slot);

      Moves a player to another slot

    • Declaration

      void host(string player);

      Gives host to a player

    • Declaration

      void clearhost();

      Makes nobody host (make it system/bog managed)

    • Declaration

      @property void locked(bool locked);

      Property to lock slots (disallow changing slots & joining)

    • Declaration

      @property void password(string pw);

      Sets the match password (password will be visible to existing players)

    • Declaration

      void setTeam(string user, Team team);

      Changes a user's team

    • Declaration

      void size(ubyte slots);

      Changes the slot limit of this lobby

    • set

      Declaration

      void set(TeamMode teammode, ScoreMode scoremode, ubyte size);

      Sets up teammode, scoremode & lobby size

    • Declaration

      void mods(Mod[] mods);

      Changes the mods in this lobby (pass FreeMod first if you want FreeMod)

    • map

      Declaration

      void map(string id);

      Changes the map to a beatmap ID (b/ url)

    • Declaration

      void setTimer(Duration d);

      Sets a timer using !mp timer

    • Declaration

      string waitForJoin(Duration timeout);

      Waits for a player to join the room & return the username

      Throws

      InterruptException if timeout triggers

    • Declaration

      void waitForTimer(Duration timeout);

      Waits for an existing timer/countdown to finish (wont start one)

      Throws

      InterruptException if timeout triggers

    • Declaration

      void abortTimer();

      Aborts any running countdown

    • Declaration

      void abortMatch();

      Aborts a running match

    • Declaration

      void start(Duration after = Duration.zero);

      Starts a match after a specified amount of seconds. If after is <= 0 the game will be started immediately. The timeout can be canceled using abortTimer.

    • Declaration

      void sendMessage(in char[] message, HighPriority highPriority = HighPriority.no);

      Sends a message with a 2 second ratelimit

      Parameters

      char[] message

      raw message to send

      HighPriority highPriority

      if yes, already send after a 1.2 second ratelimit (before others)

    • Declaration

      @property Settings settings();

      Returns the current mp settings