bancho.irc
Provides an IRC connection to Bancho (osu!'s server system) and access to its commands (Multiplayer room creation)
-
Declaration
structMessage;Represents a simple sent message from bancho
-
Declaration
stringsender;User who wrote this message
-
Declaration
stringtarget;Target channel (#channel) or username
-
Declaration
stringmessage;content of the
message -
Declaration
stringtoString();Serializes to "[sender] -> [target]: [message]"
-
-
Declaration
structTopicChange; -
Declaration
structQuit; -
Declaration
templateProcessor(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
classBanchoBot;Represents a Bancho IRC connection.
Examples
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
MessagewaitForMessage(bool delegate(Message)check, Durationtimeout);
QuitwaitForQuit(bool delegate(Quit)check, Durationtimeout);
TopicChangewaitForTopic(bool delegate(TopicChange)check, Durationtimeout);Waits for an event or returns one which is in the backlog already. Removes matching backlog entries.
Throws
InterruptException on
timeoutParameters
bool delegate(Message)checka delegate checking for which object to
checkfor. Returntrueto return this object & not add it to the backlog.Durationtimeoutthe
timeoutafter which to interrupt the waiting task -
Declaration
voidprocessMessage(Messagemessage);
voidprocessQuit(Quitquit);
voidprocessTopic(TopicChangechange);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, boolreturnIt= true);
Quit[]fetchOldQuitLog(bool delegate(Quit)check, boolreturnIt= true);
TopicChange[]fetchOldTopicLog(bool delegate(TopicChange)check, boolreturnIt= true);Goes through the backlog and removes and optionally returns all matching objects.
Parameters
bool delegate(Message)checka delegate checking for which object to
checkfor. Returntrueto return this object & removing it from the backlog.boolreturnItpass
trueto return the list of objects (GC), passfalseto simply return an empty list and only remove from the backlog. -
Declaration
voidclearMessageLog();
voidclearQuitLog();
voidclearTopicLog();Clears all backlog & removes all event listeners for the object type.
-
Declaration
OsuRoom[]rooms; -
Declaration
TCPConnectionclient; -
Declaration
stringusername; -
Declaration
stringpassword; -
Declaration
this(stringusername, stringpassword);Prepares a bancho IRC connection with
username&password(can be obtained from https://osu.ppy.sh/p/irc) -
Declaration
voidclear();Clears all logs, called by connect
-
Declaration
voidconnect();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
voiddisconnect();Disconnects & closes the TCP socket.
-
Declaration
voidsendMessage(stringchannel, in char[]message);Sends a
messageto a username orchannel(#channel). -
Declaration
Message[]waitForMessageBunch(bool delegate(Message)check, Durationtimeout, DurationtotalTimeout= 5.seconds, DurationinbetweenTimeout= 300.msecs);Waits for multiple messages sent at once and returns them.
Parameters
bool delegate(Message)checkdelegate to
checkif the message matches expectations (author, channel, etc)Durationtimeouttimeoutto wait for first messageDurationtotalTimeouttotal time to spend starting waiting for messages
DurationinbetweenTimeouttimeoutfor a message after the first message.totalTimeout+inbetweenTimeoutis the maximum amount of time this function runs. -
Declaration
OsuRoomcreateRoom(stringtitle);Creates a new managed room with a
titleand returns it. Automatically gets room ID & game ID.
-
Declaration
enumTeamMode: int;-
Declaration
HeadToHead -
Declaration
TagCoop -
Declaration
TeamVs -
Declaration
TagTeamVs
-
-
Declaration
enumScoreMode: int; -
Declaration
enumTeam: int; -
Declaration
enumMod: string; -
Declaration
stringshortForm(Modmod);Generates the short form for a
mod(eg Hidden -> HD), can be more than 2 characters -
Declaration
aliasHighPriority= std.typecons.Flag!"highPriority".Flag; -
Declaration
classOsuRoom;Represents a multiplayer lobby in osu! Automatically does ratelimiting by not sending more than a message every 2 seconds.
Examples
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
structSettings;Returned by !mp settings
-
Declaration
structPlayer;Represents a player state in the settings result
-
Declaration
stringid;Player user information
-
Declaration
stringurl;Player user information
-
Declaration
stringname;Player user information
-
Declaration
boolready; -
Declaration
boolnoMap; -
Declaration
boolhost; -
Declaration
Mod[]mods;If freemods is enabled this contains user specific
mods -
Declaration
Teamteam;
-
-
Declaration
stringname;Game
name -
Declaration
stringhistory;URL to match
history -
Declaration
stringbeatmapID;Beatmap information
-
Declaration
stringbeatmapURL;Beatmap information
-
Declaration
stringbeatmapName;Beatmap information
-
Declaration
Mod[]activeMods;Global active mods or all mods if freemods is off, contains Mod.FreeMod if on
-
Declaration
TeamModeteamMode;Type of game (coop, tag team, etc.)
-
Declaration
ScoreModewinCondition;Win condition (score, acc, combo, etc.)
-
Declaration
intnumPlayers;Number of players in this match
-
Declaration
Player[16]players;All
playersfor every slot (empty slots are Player.init)
-
-
Declaration
const @property stringroom();Returns the
roomID as usable in the mp history URL or IRC joinable via #mp_ID -
Declaration
const @property stringmpid();Returns the game ID as usable in osu://mp/ID urls
-
Declaration
voidclose();Closes the room
-
Declaration
voidinvite(stringplayer);Invites a
playerto the room -
Declaration
voidkick(stringplayer);Kicks a
playerfrom the room -
Declaration
voidmove(stringplayer, intslot);Moves a
playerto anotherslot -
Declaration
voidhost(stringplayer);Gives
hostto aplayer -
Declaration
voidclearhost();Makes nobody host (make it system/bog managed)
-
Declaration
@property voidlocked(boollocked);Property to lock slots (disallow changing slots & joining)
-
Declaration
@property voidpassword(stringpw);Sets the match
password(passwordwill be visible to existing players) -
Declaration
voidsetTeam(stringuser, Teamteam);Changes a
user'steam -
Declaration
voidsize(ubyteslots);Changes the slot limit of this lobby
-
Declaration
voidset(TeamModeteammode, ScoreModescoremode, ubytesize);Sets up
teammode,scoremode& lobbysize -
Declaration
voidmods(Mod[]mods);Changes the
modsin this lobby (pass FreeMod first if you want FreeMod) -
Declaration
voidmap(stringid);Changes the
mapto a beatmap ID (b/ url) -
Declaration
voidsetTimer(Durationd);Sets a timer using !mp timer
-
Declaration
stringwaitForJoin(Durationtimeout);Waits for a player to join the room & return the username
Throws
InterruptException if
timeouttriggers -
Declaration
voidwaitForTimer(Durationtimeout);Waits for an existing timer/countdown to finish (wont start one)
Throws
InterruptException if
timeouttriggers -
Declaration
voidabortTimer();Aborts any running countdown
-
Declaration
voidabortMatch();Aborts a running match
-
Declaration
voidstart(Durationafter= Duration.zero);Starts a match
aftera specified amount of seconds. Ifafteris <= 0 the game will be started immediately. The timeout can be canceled using abortTimer. -
Declaration
voidsendMessage(in char[]message, HighPriorityhighPriority= HighPriority.no);Sends a
messagewith a 2 second ratelimitParameters
char[]messageraw
messageto sendHighPriorityhighPriorityif yes, already send after a 1.2 second ratelimit (before others)
-
Declaration
@property Settingssettings();Returns the current mp
settings