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
; -
Declaration
struct
Quit
; -
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
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
, 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
timeout
Parameters
bool delegate(Message)
check
a delegate checking for which object to
check
for. Returntrue
to return this object & not add it to the backlog.Duration
timeout
the
timeout
after which to interrupt the waiting task -
Declaration
void
processMessage
(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)
check
a delegate checking for which object to
check
for. Returntrue
to return this object & removing it from the backlog.bool
returnIt
pass
true
to return the list of objects (GC), passfalse
to simply return an empty list and only remove from the backlog. -
Declaration
void
clearMessageLog
();
voidclearQuitLog
();
voidclearTopicLog
();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
, stringpassword
);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
(stringchannel
, in char[]message
);Sends a
message
to 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)
check
delegate to
check
if the message matches expectations (author, channel, etc)Duration
timeout
timeout
to wait for first messageDuration
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
(stringtitle
);Creates a new managed room with a
title
and returns it. Automatically gets room ID & game ID.
-
Declaration
enum
TeamMode
: int;-
Declaration
HeadToHead
-
Declaration
TagCoop
-
Declaration
TeamVs
-
Declaration
TagTeamVs
-
-
Declaration
enum
ScoreMode
: int; -
Declaration
enum
Team
: int; -
Declaration
enum
Mod
: string; -
Declaration
string
shortForm
(Modmod
);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
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
-
Declaration
string
id
;Player user information
-
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
(stringplayer
);Invites a
player
to the room -
Declaration
void
kick
(stringplayer
);Kicks a
player
from the room -
Declaration
void
move
(stringplayer
, intslot
);Moves a
player
to anotherslot
-
Declaration
void
host
(stringplayer
);Gives
host
to aplayer
-
Declaration
void
clearhost
();Makes nobody host (make it system/bog managed)
-
Declaration
@property void
locked
(boollocked
);Property to lock slots (disallow changing slots & joining)
-
Declaration
@property void
password
(stringpw
);Sets the match
password
(password
will be visible to existing players) -
Declaration
void
setTeam
(stringuser
, Teamteam
);Changes a
user
'steam
-
Declaration
void
size
(ubyteslots
);Changes the slot limit of this lobby
-
Declaration
void
set
(TeamModeteammode
, ScoreModescoremode
, ubytesize
);Sets up
teammode
,scoremode
& lobbysize
-
Declaration
void
mods
(Mod[]mods
);Changes the
mods
in this lobby (pass FreeMod first if you want FreeMod) -
Declaration
void
map
(stringid
);Changes the
map
to a beatmap ID (b/ url) -
Declaration
void
setTimer
(Durationd
);Sets a timer using !mp timer
-
Declaration
string
waitForJoin
(Durationtimeout
);Waits for a player to join the room & return the username
Throws
InterruptException if
timeout
triggers -
Declaration
void
waitForTimer
(Durationtimeout
);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
(Durationafter
= Duration.zero);Starts a match
after
a specified amount of seconds. Ifafter
is <= 0 the game will be started immediately. The timeout can be canceled using abortTimer. -
Declaration
void
sendMessage
(in char[]message
, HighPriorityhighPriority
= HighPriority.no);Sends a
message
with a 2 second ratelimitParameters
char[]
message
raw
message
to sendHighPriority
highPriority
if yes, already send after a 1.2 second ratelimit (before others)
-
Declaration
@property Settings
settings
();Returns the current mp
settings