Matchmaker Class
The Matchmaker class provides a wrapper of the game’s Matchmaker.
The Matchmaker is how you can connect to the game server to find things like public games.
bot.initMatchmaker()
and then use bot.matchmaker
The Matchmaker takes an object of configuration:
If a custom sesssion ID is omitted, the matchmaker will create an anonymous account and use that session ID. If a proxy is omitted, no proxy will be used. None of these are required, and you can specify nothing or an empty object:
<Matchmaker>.ws.close()
will instantly reopen the connection. If you need to close the Matchmaker, use <Matchmaker>.close()
Methods
These are all the things you can run on a Matchmaker
.
on
/off
/once
. This is assumed that you understand this. For an idea on how to use these functions, see the Node EventEmitter documentation. Note that you cannot call emit
.[async] waitForConnect
An easy async function that lets you wait for the Matchmaker to connect.
[async] getRegions
This fetches the region list from the game and then returns it, as well as stores it in <Matchmaker>.regionList
.
Example usage:
This will be required for getRandomRegion()
, as well as region validation in findGame()
.
Bot
, this is automatically called.[async] findGame
This finds a game with the specified parameters, region
and mode
.
A region list can be found using getRegions()
, and will a specified region will only be validated if getRegions()
has previously been called.
The mode
can be any of the following: ffa
, team
, spatula
, & kotc
.
It will return a standardized game object similar to the following:
The game code is <response>.id
. You can connect to this using <Player>.join('bot name', code)
.
Example usage:
getRandomRegion
Get a random region ID that can be directly passed to findGame().
You MUST have previously called getRegions()
.
getRandomGameMode
Get a random game mode ID that can be directly passed to findGame.
send
Sends a custom WebSocket message through the Matchmaker. This is automatically stringified, so all you need to pass is a JSON.
joinGame
directly! It is something a Bot
does for you. Use a Bot
if you need to join a game. This event is here as an EXAMPLE USE, NOT a recommended one.close
As mentioned above in the constructor, directly closing the matchmaker WebSocket (<Matchmaker>.ws.close()
) will cause it to instantly reopen, doing effectively nothing. In order to prevent it from reopening, call close()
.