-
Notifications
You must be signed in to change notification settings - Fork 9
Plugin
Plugins are useful ways to abstract code from a user and make it easy for them to gain functionality with little to no code.
As an example,
let mongo = new Dimension.MongoDB('mongodb://localhost:27017/dimensions');
await myDimension.use(mongo)
is how simple it is to integrate a scalable database and user authentication and login API straight into your dimension through the use of a plugin.
There are three kinds of plugins, Storage, Database, and Other.
Database Plugins are for setting up dimensions to store data onto a database, such as user data, match data, tournament statistics etc.
Storage plugins are used for storing any match replays and user uploaded files such as bot files. NOTE that once a storage plugin is used, it should not be removed, otherwise matches won't run because bot files cannot be retrieved once they're stored into a storage service like Google Cloud Storage or AWS S3. It is highly suggested to attach a database plugin in addition to a storage plugin.
Other plugins are usually just for configuration changes, such as changing default match configurations or match engine configurations to achieve certain specific engine behavior.
For the MongoDB plugin (and probably most database plugins), you need to provide a .env
file (a file named .env
) at the root folder. In this file, you need two keys as so
JWT_SECRET=your_secret_value_dont_share_this
ADMIN_PASSWORD=a_password_for_admin_account
Then the standard two liner:
let mongo = new Dimension.MongoDB('your_mongo_connection_string');
await myDimension.use(mongo);
Note that myDimension.use
is an asynchronous function that resolves once a plugin is ready to use. So we use await to make sure we don't run any code before the dimension is finished attaching the plugin.
To set up Google Cloud Storage for file storage (such as uploaded bots), run the following
let gcloudstorage = new Dimension.GCloudStorage({keyFilename: "keyfile.json"});
await myDimension.use(gcloudstorage);
You will need a file called keyfile.json, which can be generated by using a service account, follow instructions here: https://cloud.google.com/storage/docs/authentication#libauth