omegga 1.0.24 → 1.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,946 +1,973 @@
1
- # Omegga
2
-
3
- [Join the discord](https://discord.gg/UcdwTYhS75) to browse plugins and get support. Read the README first before asking questions!
4
-
5
- Omegga wraps brickadia's server console to provide interactivity and utility via plugins.
6
-
7
- ## Screenshots
8
-
9
- [<img src="https://i.imgur.com/AqJF2T0.png" width="512"/>](https://i.imgur.com/AqJF2T0.png)
10
- [<img src="https://i.imgur.com/vGjKoB6.png" width="512"/>](https://i.imgur.com/vGjKoB6.png)
11
- [<img src="https://i.imgur.com/EhT1GBR.png" width="512"/>](https://i.imgur.com/EhT1GBR.png)
12
- [<img src="https://i.imgur.com/PLwgVlx.png" width="512"/>](https://i.imgur.com/PLwgVlx.png)
13
- [<img src="https://i.imgur.com/bCnQ5Pb.png" width="512"/>](https://i.imgur.com/bCnQ5Pb.png)
14
-
15
- ## Install
16
-
17
- You can run omegga in the [Windows Subsystem for Linux](#wsl) (I recommend Ubuntu) or on an actual linux install.
18
-
19
- <font size="5" color="red">Do not install omegga or run brickadia/omegga as root/superuser</font>:
20
-
21
- - running `whoami` should NOT print "root"
22
- - your terminal prompt should NOT end with #
23
- - you should NOT be typing `sudo npm i -g omegga`
24
- - running `echo $EUID` should NOT print "0"
25
-
26
- If any of the above are true, [create a new user](#creating-a-new-user) and continue from there.
27
-
28
- ### Quick Setup (automatically download launcher)
29
-
30
- 1. Install linux if you haven't already ([Windows Install](#wsl))
31
-
32
- 2. If you type `whoami` and it says "root", [create a new user](#creating-a-new-user) and come back. This step is usually only necessary for people using a VPS.
33
-
34
- 3. Run these commands (Installs a node installer, installs node, installs omegga):
35
-
36
- ```sh
37
- curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
38
- . ~/.nvm/nvm.sh
39
- nvm install 16
40
- npm i -g omegga
41
- ```
42
-
43
- If you get an error like "gyp info find Python using Python version 3.8.10 found at /usr/bin/python3" you need to install python3: `sudo apt install python3` and re-run `npm i -g omegga`
44
- If you get an error like "gyp ERR! stack Error: not found: make" you need to install build-essential: `sudo apt install build-essential` and re-run `npm i -g omegga`
45
-
46
- If you are having trouble installing with nvm and are running Ubuntu/Debian, run the following commands (installs node, installs omegga) instead or install node&npm from [NodeSource Binary Distributions](https://github.com/nodesource/distributions/blob/master/README.md).
47
-
48
- ```sh
49
- curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
50
- sudo apt-get install -y nodejs
51
- npm i -g omegga
52
- ```
53
-
54
- Then head over to [Running Omegga](#running)!
55
-
56
- ### Manual Setup (you install stuff)
57
-
58
- Omegga depends on:
59
-
60
- - linux
61
- - [Windows Install](https://docs.microsoft.com/en-us/windows/wsl/install-win10#manual-installation-steps) (WSL 1 or WSL 2)
62
- - [Windows Ubuntu](https://www.microsoft.com/en-us/p/ubuntu/9nblggh4msv6)
63
- - Node v14+ ([ubuntu/deb](https://github.com/nodesource/distributions/blob/master/README.md#installation-instructions))
64
- - One of:
65
- - `tar` (most linuxes come with this, though you can `sudo apt install tar`)
66
- - [Brickadia linux launcher](https://brickadia.com/download)
67
-
68
- Omegga is installed as a global npm package
69
-
70
- npm i -g omegga
71
-
72
- Alternatively, you can use a development/local omegga.
73
-
74
- # clone omegga
75
- git clone https://github.com/brickadia-community/omegga.git && cd omegga
76
-
77
- # install dependencies
78
- npm i
79
-
80
- # point development omegga to global npm bin
81
- npm link
82
-
83
- # build the web ui, build omegga's typescript, and the plugin omegga.d.ts
84
- npm run dist
85
-
86
- If you accidentally install both from Github and `npm i -g omegga`, you can run `npm unlink omegga` to stop npm from using the git one.
87
-
88
- If you have EACCES errors on WSL, see the [troubleshooting](#troubleshooting) section for a potential fix.
89
-
90
- ### WSL
91
-
92
- These are simple instructions to get Windows System for Linux installed.
93
-
94
- **Note**: WSL 2 at the moment requires the [wsl2binds plugin](https://github.com/Meshiest/omegga-wsl2binds). You can install it with `omegga install gh:meshiest/wsl2binds`
95
-
96
- To enable WSL, run this in powershell as an administrator:
97
-
98
- ```powershell
99
- dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
100
- ```
101
-
102
- Then in the Microsoft Store, download a linux:
103
-
104
- - [Ubuntu](https://www.microsoft.com/en-us/p/ubuntu/9nblggh4msv6)
105
-
106
- [More Advanced Instructions here](https://docs.microsoft.com/en-us/windows/wsl/install-win10#manual-installation-steps) if the above is not sufficient.
107
-
108
- To set WSL version from 2 to 1:
109
-
110
- 1. Check WSL version with `wsl -l -v` in cmd
111
- 2. In Administrator cmd, run `wsl --set-version <distribution name> 1` where `<distribution name>` is `Ubuntu`, `Debian`, etc. (From the NAME section of the previous command)
112
-
113
- ### Creating a New User
114
-
115
- If you are running as root (terminal prompt ends with '#' instead of '$' or running `whoami` says "root"), create a new user.
116
-
117
- The following commands will create a user named `brickadia`. Feel free to replace it to `user` or your own name.
118
-
119
- ```sh
120
- # create the user
121
- useradd -m brickadia
122
- # set the new user's password
123
- passwd brickadia
124
- # allow "sudo apt install ...." to work in this user
125
- usermod -aG sudo brickadia
126
- # become this user
127
- su brickadia
128
- ```
129
-
130
- ## Running
131
-
132
- It's recommend to create a folder first _before_ starting your server:
133
-
134
- mkdir myServer && cd myServer
135
-
136
- To start a server, simply type the following in a linux shell after install:
137
-
138
- omegga
139
-
140
- Omegga will prompt for credentials as necessary and only stores the auth tokens brickadia generates on login. **Omegga does not store your password**
141
-
142
- ## Updating
143
-
144
- Omegga will tell you when it's out of date. You can update with this command:
145
-
146
- npm i -g omegga
147
-
148
- ## Configuration
149
-
150
- - CLI config via `omegga config`
151
- - Omegga config is located in a generated `omegga-config.yml`
152
- - Plugin config is handled by plugin or inside the web-ui's plugins tab.
153
-
154
- Example available `omegga-config.yml` fields
155
-
156
- ```yaml
157
- omegga:
158
- port: 8080
159
- webui: true
160
- https: true
161
- debug: false
162
- server:
163
- port: 7777
164
- map: Plate
165
- branch: unstable:unstable-server
166
- ```
167
-
168
- Note: `BRANCH-server` branches download only server data
169
-
170
- ## Troubleshooting
171
-
172
- Narrow down where the issue might be with the following options:
173
-
174
- - If your brickadia is crashing and omegga works, type `/debug` into omegga console or run with `omegga --debug`
175
- - If your omegga isn't starting, run with `omegga --verbose`
176
- - If a plugin is crashing, message the plugin developer
177
- - If you are on Ubuntu and the output of `which npm` is `/bin/npm`, run `sudo apt purge nodejs` and restart install instructions from `nvm install 16`.
178
- - If you're getting an EACCES error when running `npm i -g omegga`:
179
- 1. First, try [this](https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally).
180
- 2. If that doesn't work, try this horrible bodge method for WSL:
181
- 1. Set your WSL to WSL 2
182
- 2. `npm i -g omegga`
183
- 3. Set your WSL back to WSL 1
184
- - If you're getting a "gyp ERR! stack Error: not found: make" install [build-essential](https://wiki.gnucash.org/wiki/Install_Build_Tools)
185
-
186
- ## Uninstalling
187
-
188
- ```sh
189
- # uninstall omegga
190
- npm uninstall -g omegga
191
-
192
- # remove omegga config
193
- rm -rf ~/.config/omegga
194
-
195
- # remove brickadia installs
196
- rm -rf ~/.local/share/brickadia-launcher
197
-
198
- # potentially remove extra brickadia config
199
- rm ~/.config/Epic
200
- ```
201
-
202
- You will have to delete your omegga data folders manually
203
-
204
- # Planned Features
205
-
206
- - [ ] web interface (mostly done)
207
- - [x] reload plugins
208
- - [x] enable/disable plugins live
209
- - [x] live plugin reloading/unloading state
210
- - [x] browse chat history
211
- - [x] manage plugins config
212
- - [x] start/stop server
213
- - [x] chat with players
214
- - [ ] view recent console logs
215
- - [x] view server status
216
- - [x] multiple users
217
- - [ ] roles for each user
218
- - [ ] chatcmd history
219
- - [x] track players kicked/banned
220
- - [ ] automated/scheduled server restarting (when no one is on)
221
- - [x] terminal interface
222
- - [x] reload plugins
223
- - [x] chat with players
224
- - [x] view recent console logs
225
- - [x] view server status
226
- - [ ] metrics
227
- - [ ] bricks over time charts
228
- - [x] player online time tracking
229
- - [x] chat logs
230
- - [ ] chats/hour tracking
231
- - [x] plugins in other languages via JSON RPC over stdio
232
- - [ ] LogWrangler impl for other languages
233
- - [x] events sent JSON RPC
234
- - [ ] sandboxed node plugins (more secure, more stable)
235
- - [x] running in own thread (worker)
236
- - [x] running in own vm
237
- - [x] can `require`
238
- - [x] partial omegga spec (events, some features)
239
- - [x] full omegga spec
240
- - [ ] _good_ access restrictions (ask user for permission)
241
- - [x] plugin installation by `omegga install gh:user/repo`
242
- - [x] plugin updates by `omegga update`
243
- - [ ] server config bundling (making it easier to transfer configs)
244
- - [ ] omegga.server.json
245
- - [ ] list of installed omegga plugins, versions, and download urls
246
- - [ ] list of roles, bans, role assignments
247
-
248
- # Plugins
249
-
250
- Plugins are located in the `plugins` directory in an omegga config folder
251
-
252
- Plugins are most easily developed in Javascript at the moment using the Node VM Plugins and Node Plugins. You can use JSON RPC Plugins to write plugins in other languages.
253
-
254
- ## Installing Plugins
255
-
256
- ### CLI Installation
257
-
258
- You can install plugins with the `omegga install https://github.com/user/repo` command.
259
-
260
- You can install plugins using a shorthand `omegga install gh:user/repo` which will install the plugin located at `https://github.com/user/omegga-repo`
261
-
262
- ### Manual Installation
263
-
264
- Usually you can run `git clone https://github.com/user/repo` inside your `plugins` folder (created when you run `omegga` for the first time):
265
-
266
- - `cd plugins` to navigate to plugins folder
267
- - Make sure to read the plugin's README file for after-install instructions
268
-
269
- ## Updating Plugins
270
-
271
- Plugins can be updated with `omegga update` or `omegga update pluginName anotherPluginName`
272
-
273
- Plugins may also need to be updated based on the project's README file.
274
-
275
- ## Creating Plugins
276
-
277
- Plugins can be created manually using the file structure described below, or they can be initialized automatically using `omegga init-plugin`.
278
- Follow the prompts and your plugin will be generated for you.
279
-
280
- The plugin types are as follows:
281
-
282
- - `safe` (default), the standard Node VM plugin type
283
- - `unsafe`, an unsafe plugin with raw access to internal Omegga APIs
284
- - `rust`, an RPC plugin that makes use of the [omegga-rs](https://github.com/voximity/omegga-rs) Rust interface
285
- - `rpc`, a plugin that will interface another executable using RPC over STDIN/STDOUT
286
-
287
- ## Plugin Structure
288
-
289
- All plugins are located in a `plugins` directory where you are running Omegga:
290
-
291
- - `plugins/myPlugin` - plugin folder (required)
292
- - `plugins/myPlugin/doc.json` - plugin information (required)
293
- - `plugins/myPlugin/plugin.json` - plugin version information, validated with `omegga check` (optional, for now)
294
- - `plugins/myPlugin/setup.sh` - plugin setup script, run after installed by `omegga install` (optional)
295
- - `plugins/myPlugin/disable.omegga` - empty file only present if the plugin should be disabled (optional)
296
-
297
- Every plugin requires a `doc.json` file to document which briefly describes the plugin and its commands.
298
-
299
- ### `doc.json` (example)
300
-
301
- ```json
302
- {
303
- "name": "My Plugin",
304
- "description": "Example Plugin",
305
- "author": "cake",
306
- "config": {
307
- "example-text": {
308
- "description": "This is an example text input",
309
- "default": "default value",
310
- "type": "string"
311
- },
312
- "example-password": {
313
- "description": "This is example text input hidden as a password",
314
- "default": "hidden password value",
315
- "type": "password"
316
- },
317
- "example-number": {
318
- "description": "This is an example numerical input",
319
- "default": 5,
320
- "type": "number"
321
- },
322
- "example-bool": {
323
- "description": "This is an example boolean input",
324
- "default": false,
325
- "type": "boolean"
326
- }
327
- },
328
- "commands": [
329
- {
330
- "name": "!ping",
331
- "description": "sends a pong to the sender",
332
- "example": "!ping foo bar",
333
- "args": [
334
- {
335
- "name": "args",
336
- "description": "random filler arguments",
337
- "required": false
338
- }
339
- ]
340
- },
341
- {
342
- "name": "!pos",
343
- "description": "announces player position",
344
- "example": "!pos",
345
- "args": []
346
- }
347
- ]
348
- }
349
- ```
350
-
351
- ## Plugin Config
352
-
353
- This is an example config section of a `doc.json`. The web ui provides an interface for editing these configs.
354
-
355
- ```json
356
- {
357
- "config": {
358
- "example-text": {
359
- "description": "This is an example text input",
360
- "default": "default value",
361
- "type": "string"
362
- },
363
- "example-password": {
364
- "description": "This is example text input hidden as a password",
365
- "default": "hidden password value",
366
- "type": "password"
367
- },
368
- "example-number": {
369
- "description": "This is an example numerical input",
370
- "default": 5,
371
- "type": "number"
372
- },
373
- "example-bool": {
374
- "description": "This is an example boolean input",
375
- "default": false,
376
- "type": "boolean"
377
- },
378
- "example-list": {
379
- "description": "This is an example list input. List type can be string, password, number, or enum",
380
- "type": "list",
381
- "itemType": "string",
382
- "default": ["hello"]
383
- },
384
- "example-enum": {
385
- "description": "This is an example enum/dropdown input",
386
- "type": "enum",
387
- "options": ["foo", "bar", "baz", 1, 2, 3],
388
- "default": "foo"
389
- },
390
- "example-enum-list": {
391
- "description": "This is an example list of enums.",
392
- "type": "list",
393
- "itemType": "enum",
394
- "options": ["foo", "bar", "baz"],
395
- "default": ["foo"]
396
- },
397
- "example-players-list": {
398
- "description": "This is an example list of players.",
399
- "type": "players",
400
- "default": [
401
- {
402
- "id": "fa577b9e-f2be-493f-a30a-3789b02ba70b",
403
- "name": "Aware"
404
- }
405
- ]
406
- },
407
- "example-role": {
408
- "description": "This is an example role dropdown",
409
- "type": "role",
410
- "default": "Admin"
411
- }
412
- }
413
- }
414
- ```
415
-
416
- That config section would generate the following default config:
417
-
418
- ```json
419
- {
420
- "example-text": "default value",
421
- "example-password": "hidden password value",
422
- "example-number": 5,
423
- "example-bool": false,
424
- "example-list": ["hello"],
425
- "example-enum": "foo",
426
- "example-enum-list": ["foo"],
427
- "example-players-list": [
428
- { "id": "fa577b9e-f2be-493f-a30a-3789b02ba70b", "name": "Aware" }
429
- ]
430
- }
431
- ```
432
-
433
- This is provided to plugins in the constructor or the RPC init function.
434
-
435
- ## Plugin File
436
-
437
- This is an example `plugin.json`, located inside a plugin folder. The plugin file helps omegga know if the plugin is compatible with the current installation. Plugin files can be validated with the `omegga check` command.
438
-
439
- ```json
440
- {
441
- "formatVersion": 1,
442
- "omeggaVersion": ">=0.1.32",
443
- "emitConfig": "config.json"
444
- }
445
- ```
446
-
447
- - `formatVersion` - indicates the plugin file format version
448
- - `omeggaVersion` - indicates compatible omegga versions ([semver cheatsheet](https://www.npmjs.com/package/semver#user-content-ranges))
449
- - `emitConfig` - optional, a path to a json file where plugin config will be saved to before the plugin starts.
450
-
451
- ## Plugin Store
452
-
453
- All plugins have the capability to get/set values in a very lightweight "database"
454
-
455
- The following **asynchronous** methods are provided:
456
-
457
- | Method | Arguments | Description |
458
- | -------------- | ------------------------- | ---------------------------------------- |
459
- | `store.get` | key (string) | Get an object from plugin store |
460
- | `store.set` | key (string), value (any) | Store an object in plugin store |
461
- | `store.delete` | key (string) | Remove an object from plugin store |
462
- | `store.wipe` | _none_ | Remove all objects from plugin store |
463
- | `store.count` | _none_ | Count number of objects in plugin store |
464
- | `store.keys` | _none_ | Get keys for all objects in plugin store |
465
-
466
- ### Example usage:
467
-
468
- ```javascript
469
- // simple add function
470
- async function add() {
471
- const a = await store.get('foo');
472
- const b = await store.get('bar');
473
- await store.set('baz', a + b);
474
- await store.delete('foo');
475
- await store.delete('bar');
476
- }
477
-
478
- (async () => {
479
- // store foo and bar in the plugin store
480
- await Promise.all([store.set('foo', 5), store.set('bar', 2)]);
481
-
482
- // add foo and bar
483
- await add();
484
-
485
- // baz should be equal to 7
486
- console.log('assert', (await store.get('baz')) === 7);
487
-
488
- // demo of storing an object
489
- await store.set('example object', {
490
- foo: 'you can store objects in the store too',
491
- bar: "just don't expect it to work with anything recursive (cannot serialize)",
492
- });
493
- })();
494
- ```
495
-
496
- For Node Plugins, the `store` is the third argument passed into the constructor. For JSONRPC Plugins, the `"store.get"`/etc. methods can be used.
497
-
498
- **JSONRPC Note:** `store.set` has an array of arguments (`[key, value]`)
499
-
500
- ## Node VM Plugins
501
-
502
- Node VM Plugins are what you should be using. They are run inside a VM inside a Worker. This means when they crash, they do not crash the whole server, and they can in the future have locked down permissions (disable filesystem access, etc.).
503
-
504
- These plugins receive a "proxy" reference to `omegga` and have limited reach for what they can touch.
505
-
506
- Register custom `/commands` by returning `{registeredCommands: ['foo', 'bar']}` (registers command `/foo` and `/bar`) in the `async init()` method.
507
-
508
- By defining an `async pluginEvent(event, from, ...args)` method in your plugin class, you can respond to events from other plugins, where `from` is the name of the other plugin, `event` is the name of the custom event, and `args` is an array of any passed arguments.
509
-
510
- ### Globals
511
-
512
- - `OMEGGA_UTIL` - access to the `src/util/index.js` module
513
- - `Omegga` - access to the "proxy" omegga
514
- - `console.log` - and other variants (`console.error`, `console.info`) print specialized output to console
515
-
516
- ### Folder Structure
517
-
518
- In a `plugins` directory create the following folder structure:
519
-
520
- - `plugins/myPlugin` - plugin folder (required)
521
- - `plugins/myPlugin/omegga.plugin.js` - js plugin main file (required)
522
- - `plugins/myPlugin/doc.json`
523
- - `plugins/myPlugin/access.json` - plugin access information (required, but doesn't have to have anything right now). this will contain what things the vm will need to access
524
-
525
- ### `access.json` (examples)
526
-
527
- Access to any builtin modules (`fs`, `path`, etc.)
528
-
529
- ```json
530
- ["*"]
531
- ```
532
-
533
- Access to nothing - only the code in the `omegga.plugin.js`
534
-
535
- ```json
536
- []
537
- ```
538
-
539
- Access to only `fs`, (`const fs = require('fs');`)
540
-
541
- ```json
542
- ["fs"]
543
- ```
544
-
545
- ### `omegga.plugin.js` (example)
546
-
547
- ```javascript
548
- class PluginName {
549
- // the constructor also contains an omegga if you don't want to use the global one
550
- // config and store variables are optional but provide access to the plugin data store
551
- constructor(omegga, config, store) {
552
- this.omegga = omegga;
553
- this.config = config;
554
- this.store = store;
555
- console.info('constructed my plugin!');
556
- }
557
-
558
- async init() {
559
- Omegga.on('chatcmd:ping', (name, ...args) => {
560
- Omegga.broadcast(`pong @ ${name} + ${args.length} args`);
561
- }).on('chatcmd:pos', async name => {
562
- const [x, y, z] = await Omegga.getPlayer(name).getPosition();
563
- Omegga.broadcast(`<b>${name}</> is at ${x} ${y} ${z}`);
564
- });
565
- }
566
-
567
- async stop() {
568
- // any remove events are not necessary because the VM removes the code
569
- }
570
- }
571
-
572
- module.exports = PluginName;
573
- ```
574
-
575
- ### `omegga.plugin.ts` (example)
576
-
577
- Be sure to put `.build/` and `node_modules/` in your `.gitignore`
578
-
579
- **Requires a `tsconfig.json`**:
580
-
581
- ```json
582
- {
583
- "compilerOptions": {
584
- "noEmit": true,
585
- "esModuleInterop": true,
586
- "moduleResolution": "node",
587
- "resolveJsonModule": true,
588
- "target": "es2020",
589
- "baseUrl": ".",
590
- "paths": {
591
- "omegga/*": ["node_modules/omegga/dist/*"]
592
- }
593
- }
594
- }
595
- ```
596
-
597
- `omegga.plugin.ts`:
598
-
599
- ```ts
600
- import type { OmeggaPlugin, OL, PS, PC } from 'omegga/plugin';
601
-
602
- type Config = { foo: string };
603
- type Storage = { bar: string };
604
-
605
- export default class Plugin implements OmeggaPlugin<Config, Storage> {
606
- omegga: OL;
607
- config: PC<Config>;
608
- store: PS<Storage>;
609
-
610
- constructor(omegga: OL, config: PC<Config>, store: PS<Storage>) {
611
- this.omegga = omegga;
612
- this.config = config;
613
- this.store = store;
614
- }
615
-
616
- async init() {
617
- // Write your plugin!
618
- this.omegga.on('cmd:test', (speaker: string) => {
619
- this.omegga.broadcast(`Hello, ${speaker}!`);
620
- });
621
-
622
- return { registeredCommands: ['test'] };
623
- }
624
-
625
- async stop() {
626
- // Anything that needs to be cleaned up...
627
- }
628
- }
629
- ```
630
-
631
- ## Node Plugins
632
-
633
- Node plugins are effectively `require`'d into omegga. They have the potential to crash the entire service through uncaught exceptions and also can be insecure. Develop and run these at your own risk - your server stability may suffer.
634
-
635
- These plugins receive a direct reference to the `omegga` that wraps the brickadia server. As a result, they can directly modify how omegga runs.
636
-
637
- Cleanup is important as code can still be running after the plugin is unloaded resulting in strange and undefined behavior. Make sure to run `clearInterval` and `clearTimeout`
638
-
639
- Register custom `/commands` by returning `{registeredCommands: ['foo', 'bar']}` (registers command `/foo` and `/bar`) in the `async init()` method.
640
-
641
- ### Globals
642
-
643
- - `OMEGGA_UTIL` - access to the `src/util/index.js` module
644
-
645
- ### Folder Structure
646
-
647
- In a `plugins` directory create the following folder structure:
648
-
649
- - `plugins/myPlugin` - plugin folder (required)
650
- - `plugins/myPlugin/doc.json`
651
- - `plugins/myPlugin/omegga.main.js` - js plugin main file (required)
652
-
653
- ### `omegga.main.js` (example)
654
-
655
- ```javascript
656
- class PluginName {
657
- // config and store variables are optional but provide access to the plugin data store
658
- constructor(omegga, config, store) {
659
- this.omegga = omegga;
660
- this.config = config;
661
- this.store = store;
662
- }
663
-
664
- async init() {
665
- this.omegga
666
- .on('chatcmd:ping', (name, ...args) => {
667
- this.omegga.broadcast(`pong @ ${name} + ${args.length} args`);
668
- })
669
- .on('chatcmd:pos', async name => {
670
- const [x, y, z] = await this.omegga.getPlayer(name).getPosition();
671
- this.omegga.broadcast(`<b>${name}</> is at ${x} ${y} ${z}`);
672
- });
673
- }
674
-
675
- async stop() {
676
- this.omegga
677
- .removeAllListeners('chatcmd:ping')
678
- .removeAllListeners('chatcmd:pos');
679
- }
680
- }
681
-
682
- module.exports = PluginName;
683
- ```
684
-
685
- ## JSON RPC Plugins
686
-
687
- JSON RPC Plugins let you use any language you desire, as long as you can run it from a single executable file. They follow the [JSON-RPC 2.0 Specification](https://www.jsonrpc.org/specification)
688
-
689
- The server communicates with the plugin by sending messages to `stdin` and expects responses in `stdout`. All `stderr` is printed to the console.
690
-
691
- Register custom `/commands` by returning `{registeredCommands: ['foo', 'bar']}` (registers command `/foo` and `/bar`) in the `init` method.
692
-
693
- ### Omegga Methods (You can access these)
694
-
695
- | Method | Arguments | Description | Returns |
696
- | ------------------------------ | ---------------------------------------------------- | ------------------------------------------------------------------- | --------------------------------------------------------------- |
697
- | `log` | line (string) | Prints message to omegga console | |
698
- | `error` | line (string) | Same as `log` but with different colors | |
699
- | `info` | line (string) | Same as `log` but with different colors | |
700
- | `debug` | line (string) | Same as `log` but with different colors | |
701
- | `warn` | line (string) | Same as `log` but with different colors | |
702
- | `trace` | line (string) | Same as `log` but with different colors | |
703
- | `store.get` | key (string) | Get an object from plugin store | Object |
704
- | `store.set` | [key (string), value (any)] | Store an object in plugin store | |
705
- | `store.delete` | key (string) | Remove an object from plugin store | |
706
- | `store.wipe` | _none_ | Remove all objects from plugin store | |
707
- | `store.count` | _none_ | Count number of objects in plugin store | Integer |
708
- | `store.keys` | _none_ | Get keys for all objects in plugin store | List of Strings |
709
- | `exec` | cmd (string) | Writes a console command to Brickadia | |
710
- | `writeln` | cmd (string) | Same as `exec` | |
711
- | `broadcast` | line (string) | Broadcasts a message to the server | |
712
- | `whisper` | {target: string, line: string} | Sends a message to a specific client | |
713
- | `middlePrint` | {target: string, line: string} | Sends a middle print message to a specific client | |
714
- | `getPlayers` | _none_ | Online players | List of Players |
715
- | `getAllPlayerPositions` | _none_ | An array of objects with fields `pos` and `player`. | List of { _Player Object_(...), _Position_(...), isDead(bool) } |
716
- | `getRoleSetup` | _none_ | Server roles | _JSON Data_ |
717
- | `getBanList` | _none_ | List of bans | _JSON Data_ |
718
- | `getSaves` | _none_ | Saves in the saves directory | List Strings |
719
- | `getSavePath` | name (string) | The path to a specific save | String |
720
- | `getSaveData` | _none_ | Current save as brs-js data | _BRS Object_ |
721
- | `clearBricks` | {target: string, quiet: bool} | Clears a specific player's bricks | |
722
- | `clearAllBricks` | quiet | Clears all bricks on the server | |
723
- | `saveBricks` | name (string) | Save bricks to a save named `name` | |
724
- | `loadBricks` | {name: string, offX, offY, offY, quiet: bool} | Load bricks of save named `name` | |
725
- | `loadBricksOnPlayer` | {name: string, player: string, offX, offY, offY} | Load bricks of save named `name` on player clipboard | |
726
- | `readSaveData` | name (string) | Parses save into a brs-js save object, returns the object | _BRS Object_ |
727
- | `loadSaveData` | {data: object, offX, offY, offY, quiet: bool} | Builds brs file from data, loads the file | |
728
- | `loadSaveDataOnPlayer` | {data: object, player: string, offX, offY, offY} | Builds brs file from data, loads the file onto a player's clipboard | |
729
- | `changeMap` | map (string) | Change map to specified map name, returns success | Boolean |
730
- | `player.get` | target (string) | Gets the player by their name or UUID. | `{name, id, controller, state, host: bool}` |
731
- | `player.getRoles` | target (string) | Target's roles | |
732
- | `player.getPermissions` | target (string) | Target's permissions | List of Strings |
733
- | `player.getNameColor` | target (string) | Target's name color | _RGB Hex Object_ (int, int ,int) |
734
- | `player.getPosition` | target (string) | Target's position | _Position Object_ |
735
- | `player.getGhostBrick` | target (string) | Target's ghost brick | {targetGrid, location(_Location_), orientation} |
736
- | `player.getPaint` | target (string) | Target's current paint selection | {materialIndex, materialAlpha, material, color)} |
737
- | `player.getTemplateBounds` | target (string) | Target's template/selection bounds | {minBound, maxBound, Center} |
738
- | `player.getTemplateBoundsData` | target (string) | Target's template/selection as brs-js save data | _Brick Object_ |
739
- | `player.loadSaveData` | {target, data, offX, offY, offZ} | Loads brs-js save data to the targets clipboard | |
740
- | `player.loadDataAtGhostBrick` | {target, data, rotate=true, offX, offY, offZ, quiet} | Loads brs-js save data at the target's selection bounds | |
741
- | `plugin.get` | target (string) | Gets info on the target plugin | Object |
742
- | `plugin.emit` | [target (string), event (string), ...args (any)] | Emit a custom event to the target plugin | |
743
-
744
- ### Plugin Methods (You implement these)
745
-
746
- | Method | Arguments | Description | Required |
747
- | -------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- |
748
- | `init` | config object | Returns a start result, called on plugin start | &#9745; |
749
- | `stop` | _none_ | Returns _something_, called on plugin stop | &#9745; |
750
- | `bootstrap` | [{ omegga info (`host`, `version`, etc) }] | Run when plugin is started for base data | |
751
- | `plugin:players:raw` | [[... [player `name`, `id`, `controller`, `state`]]] | Lists players on the server | |
752
- | `plugin:emit` | [event, from, ...args] | Fired when another plugin sends an event | |
753
- | `line` | [brickadiaLog string] | A brickadia console log | |
754
- | `start` | [{map}] | On brickadia server start | |
755
- | `host` | [{name, id}] | When the host is detected | |
756
- | `version` | [-1 or the CL number] | When the version is detected | |
757
- | `unauthorized` | _none_ | On brickadia server fails an auth check | |
758
- | `join` | [{name, id, state, controller}] | Run when a player joins | |
759
- | `leave` | [{name, id, state, controller}] | Run when a player leaves | |
760
- | `cmd:command` | [playerName, ...args] | Runs when a player runs a `/command args` | |
761
- | `chatcmd:command` | [playerName, ...args] | Runs when a player runs a `!command args` | |
762
- | `chat` | [playerName, message] | Runs when a player sends a chat message | |
763
- | `interact` | {brick_asset: string;player: { id: string; name: string; controller: string; pawn: string };position: [number, number, number];} | Runs when a player clicks a brick with an interact component. `data` is parsed JSON if `line` (from interact component) starts with "json:{"your": "json"}`. Uses interact log field | |
764
- | `event:NAME` | [&gt;player from click&lt;, ...args] | Runs when an interact component has `event:NAME: arg1,arg2,arg\,3, | |
765
- | `mapchange` | \[{map}\] | Runs when the map changes | |
766
- | `autorestart` | [autorestart config] | Runs server has an autorestart scheduled | |
767
-
768
- ### Folder Structure
769
-
770
- In a `plugins` directory create the following folder structure:
771
-
772
- - `plugins/myPlugin` - plugin folder (required)
773
- - `plugins/myPlugin/doc.json`
774
- - `plugins/myPlugin/omegga_plugin` - executable plugin file (required)
775
-
776
- ### `omegga_plugin` (example, node javascript)
777
-
778
- ```javascript
779
- #!/usr/bin/env node
780
-
781
- const readline = require('readline');
782
- const { EventEmitter } = require('events');
783
- const {
784
- JSONRPCServer,
785
- JSONRPCServerAndClient,
786
- JSONRPCClient,
787
- } = require('json-rpc-2.0');
788
-
789
- // events
790
- const ev = new EventEmitter();
791
-
792
- // stdio handling
793
- const rl = readline.createInterface({
794
- input: process.stdin,
795
- output: process.stdout,
796
- terminal: false,
797
- });
798
-
799
- // rpc "server and client" for responding/receiving messages
800
- const rpc = new JSONRPCServerAndClient(
801
- new JSONRPCServer(),
802
- // the client outputs JSON to console
803
- new JSONRPCClient(async blob => console.log(JSON.stringify(blob)))
804
- );
805
-
806
- // on stdin, pass into rpc
807
- rl.on('line', line => {
808
- try {
809
- rpc.receiveAndSend(JSON.parse(line));
810
- } catch (e) {
811
- console.error(e);
812
- }
813
- });
814
-
815
- // regexes for matching brickadia console logs
816
- const GENERIC_LINE_REGEX =
817
- /^(\[(?<date>\d{4}\.\d\d.\d\d-\d\d.\d\d.\d\d:\d{3})\]\[\s*(?<counter>\d+)\])?(?<generator>\w+): (?<data>.+)$/;
818
- const LOG_LINE_REGEX =
819
- /\[(?<date>\d{4}\.\d\d.\d\d-\d\d.\d\d.\d\d:\d{3})\]\[\s*(?<counter>\d+)\](?<rest>.*)$/;
820
-
821
- ev.on('line', line => {
822
- const logMatch = line.match(LOG_LINE_REGEX);
823
- if (!logMatch) return;
824
- const {
825
- groups: { rest },
826
- } = logMatch;
827
- const dataMatch = rest.match(GENERIC_LINE_REGEX);
828
- if (dataMatch) ev.emit('logData', dataMatch.groups);
829
- else ev.emit('logLine', rest);
830
- });
831
-
832
- // list of players
833
- let players;
834
-
835
- // get a player by name
836
- const getPlayer = name => players.find(p => p.name === name);
837
-
838
- // watch console logs for a pattern, then remove the listener
839
- function watch(exec, pattern) {
840
- return new Promise(resolve => {
841
- function listener(line) {
842
- const match = line.match(pattern);
843
- // listener removes itself on a match
844
- if (match) {
845
- ev.off('logLine', listener);
846
- resolve(match.groups);
847
- }
848
- }
849
- // add the listener
850
- ev.on('logLine', listener);
851
-
852
- // run the console command
853
- rpc.notify('writeln', exec);
854
- });
855
- }
856
-
857
- // get a player's position
858
- async function getPlayerPos(name) {
859
- const player = getPlayer(name);
860
- if (!player) return;
861
-
862
- // get player position from player controller
863
- const pawnRegExp = new RegExp(
864
- `BP_PlayerController_C .+?PersistentLevel\\.${player.controller}\.Pawn = BP_FigureV2_C'.+?:PersistentLevel.(?<pawn>BP_FigureV2_C_\\d+)'`
865
- );
866
- const { pawn } = await watch(
867
- `GetAll BP_PlayerController_C Pawn Name=${player.controller}`,
868
- pawnRegExp
869
- );
870
-
871
- // get player position from pawn
872
- const posRegExp = new RegExp(
873
- `CapsuleComponent .+?PersistentLevel\\.${pawn}\\.CollisionCylinder\\.RelativeLocation = \\(X=(?<x>[\\d\\.-]+),Y=(?<y>[\\d\\.-]+),Z=(?<z>[\\d\\.-]+)\\)`
874
- );
875
- const { x, y, z } = await watch(
876
- `GetAll SceneComponent RelativeLocation Name=CollisionCylinder Outer=${pawn}`,
877
- posRegExp
878
- );
879
-
880
- return [x, y, z].map(Number);
881
- }
882
-
883
- // emit a console log
884
- const log = (...args) => rpc.notify('log', args.join(' '));
885
-
886
- // when available players updates - plugin:players:raw is emitted
887
- rpc.addMethod('plugin:players:raw', ([playerArr]) => {
888
- // update the players list
889
- players = playerArr.map(p => ({
890
- name: p[0],
891
- id: p[1],
892
- controller: p[2],
893
- state: p[3],
894
- }));
895
- });
896
-
897
- // ping command
898
- rpc.addMethod('chatcmd:ping', ([name, ...args]) => {
899
- rpc.notify('broadcast', `pong @ ${name} + ${args.length} args`);
900
- });
901
-
902
- // player position command
903
- rpc.addMethod('chatcmd:pos', async ([name]) => {
904
- log('player', name, 'requests position');
905
- const [x, y, z] = await getPlayerPos(name);
906
- rpc.notify('broadcast', `<b>${name}</> is at ${x} ${y} ${z}`);
907
- });
908
-
909
- // pass lines into the event emitter
910
- rpc.addMethod('line', ([line]) => {
911
- ev.emit('line', line);
912
- });
913
-
914
- // receive config object in init
915
- rpc.addMethod('init', async ([config]) => ({ registeredCommands: [] }));
916
- rpc.addMethod('stop', async () => 'ok');
917
- ```
918
-
919
- # Extra Features
920
-
921
- ## Environment Variables
922
-
923
- `omegga` accepts the following environment variables:
924
-
925
- - `BRICKADIA_USER` - brickadia auth username (on first start)
926
- - `BRICKADIA_PASS` - brickadia auth password (on first start)
927
- - `BRICKADIA_PORT` - brickadia server port (on config creation)
928
- - `OMEGGA_PORT` - omegga webserver port (on config creation)
929
-
930
- ## Config
931
-
932
- Default config values (including hidden ones)
933
-
934
- ```yaml
935
- omegga:
936
- port: 8080 # web-ui port
937
- webui: true # enable web-ui
938
- plugins: true # enable plugins
939
- singleUser: false # disable web-ui auth users
940
- https: true # enable https for web-ui
941
- debug: false # debug logging
942
- server:
943
- port: 7777 # game server port
944
- map: Plate # map name
945
- branch: unstable:unstable-server # branch alias:branch name
946
- ```
1
+ # Omegga
2
+
3
+ Read the README first before asking questions! [Join the discord](https://discord.gg/UcdwTYhS75) to browse plugins and get support.
4
+
5
+ Omegga wraps brickadia's server console to provide interactivity and utility via plugins.
6
+
7
+ ## Screenshots
8
+
9
+ [<img src="https://i.imgur.com/AqJF2T0.png" width="512"/>](https://i.imgur.com/AqJF2T0.png)
10
+ [<img src="https://i.imgur.com/vGjKoB6.png" width="512"/>](https://i.imgur.com/vGjKoB6.png)
11
+ [<img src="https://i.imgur.com/EhT1GBR.png" width="512"/>](https://i.imgur.com/EhT1GBR.png)
12
+ [<img src="https://i.imgur.com/PLwgVlx.png" width="512"/>](https://i.imgur.com/PLwgVlx.png)
13
+ [<img src="https://i.imgur.com/bCnQ5Pb.png" width="512"/>](https://i.imgur.com/bCnQ5Pb.png)
14
+
15
+ ## Install
16
+
17
+ You can run omegga in the [Windows Subsystem for Linux](#wsl) (I recommend Ubuntu) or on an actual linux install.
18
+
19
+ <font size="5" color="red">Do not install omegga or run brickadia/omegga as root/superuser</font>:
20
+
21
+ - running `whoami` should NOT print "root"
22
+ - your terminal prompt should NOT end with #
23
+ - you should NOT be typing `sudo npm i -g omegga`
24
+ - running `echo $EUID` should NOT print "0"
25
+ - if you type `pwd` it should NOT print "/root" (type `cd` to navigate to your user's home dir)
26
+
27
+ If any of the above are true, [create a new user](#creating-a-new-user) and continue from there.
28
+
29
+ ### Quick Setup (automatically download launcher)
30
+
31
+ 1. Install linux if you haven't already ([Windows Install](#wsl))
32
+
33
+ 2. If you type `whoami` and it says "root", [create a new user](#creating-a-new-user) and come back. This step is usually only necessary for people using a VPS.
34
+
35
+ 3. Run these commands (Installs a node installer, installs node, installs omegga):
36
+
37
+ ```sh
38
+ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
39
+ . ~/.nvm/nvm.sh
40
+ nvm install 16
41
+ npm i -g omegga
42
+ ```
43
+
44
+ 4. Head over to [Running Omegga](#running) or troubleshoot below.
45
+
46
+ ### Quick Setup Troubleshooting
47
+
48
+
49
+ - If you get "`sh: 28: cd: can't cd to .`", you need to be in `bash` (and probably type `cd` to navigate out of root directory):
50
+
51
+ ```sh
52
+ bash # use bash instead of sh
53
+ cd # navigate home
54
+ ```
55
+
56
+ - If you get an error like "`gyp info find Python using Python version 3.8.10 found at /usr/bin/python3`" you need to install python3:
57
+
58
+ ```sh
59
+ sudo apt install python3
60
+ npm i -g omegga
61
+ ```
62
+
63
+ - If you get an error like "`gyp ERR! stack Error: not found: make`" you need to install build-essential:
64
+ ```sh
65
+ sudo apt install build-essential
66
+ npm i -g omegga # re-run omegga install
67
+ ```
68
+
69
+ - If you get an error like "`Unable to fetch some archives, maybe run apt-get update`" you need to run this before running your original command:
70
+ ```sh
71
+ sudo apt update && sudo apt upgrade
72
+ ```
73
+
74
+ - If you are having trouble installing with nvm and are running **Ubuntu/Debian**, run the following commands (installs node, installs omegga) instead or install node&npm from [NodeSource Binary Distributions](https://github.com/nodesource/distributions/blob/master/README.md).
75
+
76
+ ```sh
77
+ curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
78
+ sudo apt-get install -y nodejs
79
+ npm i -g omegga
80
+ ```
81
+
82
+ ### Manual Setup (you install stuff)
83
+
84
+ Omegga depends on:
85
+
86
+ - linux
87
+ - [Windows Install](https://docs.microsoft.com/en-us/windows/wsl/install-win10#manual-installation-steps) (WSL 1 or WSL 2)
88
+ - [Windows Ubuntu](https://www.microsoft.com/en-us/p/ubuntu/9nblggh4msv6)
89
+ - Node v14+ ([ubuntu/deb](https://github.com/nodesource/distributions/blob/master/README.md#installation-instructions))
90
+ - One of:
91
+ - `tar` (most linuxes come with this, though you can `sudo apt install tar`)
92
+ - [Brickadia linux launcher](https://brickadia.com/download)
93
+
94
+ Omegga is installed as a global npm package
95
+
96
+ npm i -g omegga
97
+
98
+ Alternatively, you can use a development/local omegga.
99
+
100
+ # clone omegga
101
+ git clone https://github.com/brickadia-community/omegga.git && cd omegga
102
+
103
+ # install dependencies
104
+ npm i
105
+
106
+ # point development omegga to global npm bin
107
+ npm link
108
+
109
+ # build the web ui, build omegga's typescript, and the plugin omegga.d.ts
110
+ npm run dist
111
+
112
+ If you accidentally install both from Github and `npm i -g omegga`, you can run `npm unlink omegga` to stop npm from using the git one.
113
+
114
+ If you have EACCES errors on WSL, see the [troubleshooting](#troubleshooting) section for a potential fix.
115
+
116
+ ### WSL
117
+
118
+ These are simple instructions to get Windows System for Linux installed.
119
+
120
+ **Note**: WSL 2 at the moment requires the [wsl2binds plugin](https://github.com/Meshiest/omegga-wsl2binds). You can install it with `omegga install gh:meshiest/wsl2binds`
121
+
122
+ To enable WSL, run this in powershell as an administrator:
123
+
124
+ ```powershell
125
+ dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
126
+ ```
127
+
128
+ Then in the Microsoft Store, download a linux:
129
+
130
+ - [Ubuntu](https://www.microsoft.com/en-us/p/ubuntu/9nblggh4msv6)
131
+
132
+ [More Advanced Instructions here](https://docs.microsoft.com/en-us/windows/wsl/install-win10#manual-installation-steps) if the above is not sufficient.
133
+
134
+ To set WSL version from 2 to 1:
135
+
136
+ 1. Check WSL version with `wsl -l -v` in cmd
137
+ 2. In Administrator cmd, run `wsl --set-version <distribution name> 1` where `<distribution name>` is `Ubuntu`, `Debian`, etc. (From the NAME section of the previous command)
138
+
139
+ ### Creating a New User
140
+
141
+ If you are running as root (terminal prompt ends with '#' instead of '$' or running `whoami` says "root"), create a new user.
142
+
143
+ The following commands will create a user named `brickadia`. Feel free to replace it to `user` or your own name.
144
+
145
+ ```sh
146
+ # create the user
147
+ useradd -m brickadia
148
+ # set the new user's password
149
+ passwd brickadia
150
+ # allow "sudo apt install ...." to work in this user
151
+ usermod -aG sudo brickadia
152
+ # become this user
153
+ su brickadia
154
+ ```
155
+
156
+ ## Running
157
+
158
+ It's recommend to create a folder first _before_ starting your server:
159
+
160
+ mkdir myServer && cd myServer
161
+
162
+ To start a server, simply type the following in a linux shell after install:
163
+
164
+ omegga
165
+
166
+ Omegga will prompt for credentials as necessary and only stores the auth tokens brickadia generates on login. **Omegga does not store your password**
167
+
168
+ ## Updating
169
+
170
+ Omegga will tell you when it's out of date. You can update with this command:
171
+
172
+ npm i -g omegga
173
+
174
+ ## Configuration
175
+
176
+ - CLI config via `omegga config`
177
+ - Omegga config is located in a generated `omegga-config.yml`
178
+ - Plugin config is handled by plugin or inside the web-ui's plugins tab.
179
+
180
+ Example available `omegga-config.yml` fields
181
+
182
+ ```yaml
183
+ omegga:
184
+ port: 8080
185
+ webui: true
186
+ https: true
187
+ debug: false
188
+ server:
189
+ port: 7777
190
+ map: Plate
191
+ branch: unstable:unstable-server
192
+ ```
193
+
194
+ Note: `BRANCH-server` branches download only server data
195
+
196
+ ## Troubleshooting
197
+
198
+ Narrow down where the issue might be with the following options:
199
+
200
+ - If your brickadia is crashing and omegga works, type `/debug` into omegga console or run with `omegga --debug`
201
+ - If your omegga isn't starting, run with `omegga --verbose`
202
+ - If a plugin is crashing, message the plugin developer
203
+ - If you are on Ubuntu and the output of `which npm` is `/bin/npm`, run `sudo apt purge nodejs` and restart install instructions from `nvm install 16`.
204
+ - If you're getting an EACCES error when running `npm i -g omegga`:
205
+ 1. First, try [this](https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally).
206
+ 2. If that doesn't work, try this horrible bodge method for WSL:
207
+ 1. Set your WSL to WSL 2
208
+ 2. `npm i -g omegga`
209
+ 3. Set your WSL back to WSL 1
210
+ - If you're getting a "gyp ERR! stack Error: not found: make" install [build-essential](https://wiki.gnucash.org/wiki/Install_Build_Tools)
211
+
212
+ ## Uninstalling
213
+
214
+ ```sh
215
+ # uninstall omegga
216
+ npm uninstall -g omegga
217
+
218
+ # remove omegga config
219
+ rm -rf ~/.config/omegga
220
+
221
+ # remove brickadia installs
222
+ rm -rf ~/.local/share/brickadia-launcher
223
+
224
+ # potentially remove extra brickadia config
225
+ rm ~/.config/Epic
226
+ ```
227
+
228
+ You will have to delete your omegga data folders manually
229
+
230
+ # Planned Features
231
+
232
+ - [ ] web interface (mostly done)
233
+ - [x] reload plugins
234
+ - [x] enable/disable plugins live
235
+ - [x] live plugin reloading/unloading state
236
+ - [x] browse chat history
237
+ - [x] manage plugins config
238
+ - [x] start/stop server
239
+ - [x] chat with players
240
+ - [ ] view recent console logs
241
+ - [x] view server status
242
+ - [x] multiple users
243
+ - [ ] roles for each user
244
+ - [ ] chatcmd history
245
+ - [x] track players kicked/banned
246
+ - [ ] automated/scheduled server restarting (when no one is on)
247
+ - [x] terminal interface
248
+ - [x] reload plugins
249
+ - [x] chat with players
250
+ - [x] view recent console logs
251
+ - [x] view server status
252
+ - [ ] metrics
253
+ - [ ] bricks over time charts
254
+ - [x] player online time tracking
255
+ - [x] chat logs
256
+ - [ ] chats/hour tracking
257
+ - [x] plugins in other languages via JSON RPC over stdio
258
+ - [ ] LogWrangler impl for other languages
259
+ - [x] events sent JSON RPC
260
+ - [ ] sandboxed node plugins (more secure, more stable)
261
+ - [x] running in own thread (worker)
262
+ - [x] running in own vm
263
+ - [x] can `require`
264
+ - [x] partial omegga spec (events, some features)
265
+ - [x] full omegga spec
266
+ - [ ] _good_ access restrictions (ask user for permission)
267
+ - [x] plugin installation by `omegga install gh:user/repo`
268
+ - [x] plugin updates by `omegga update`
269
+ - [ ] server config bundling (making it easier to transfer configs)
270
+ - [ ] omegga.server.json
271
+ - [ ] list of installed omegga plugins, versions, and download urls
272
+ - [ ] list of roles, bans, role assignments
273
+
274
+ # Plugins
275
+
276
+ Plugins are located in the `plugins` directory in an omegga config folder
277
+
278
+ Plugins are most easily developed in Javascript at the moment using the Node VM Plugins and Node Plugins. You can use JSON RPC Plugins to write plugins in other languages.
279
+
280
+ ## Installing Plugins
281
+
282
+ ### CLI Installation
283
+
284
+ You can install plugins with the `omegga install https://github.com/user/repo` command.
285
+
286
+ You can install plugins using a shorthand `omegga install gh:user/repo` which will install the plugin located at `https://github.com/user/omegga-repo`
287
+
288
+ ### Manual Installation
289
+
290
+ Usually you can run `git clone https://github.com/user/repo` inside your `plugins` folder (created when you run `omegga` for the first time):
291
+
292
+ - `cd plugins` to navigate to plugins folder
293
+ - Make sure to read the plugin's README file for after-install instructions
294
+
295
+ ## Updating Plugins
296
+
297
+ Plugins can be updated with `omegga update` or `omegga update pluginName anotherPluginName`
298
+
299
+ Plugins may also need to be updated based on the project's README file.
300
+
301
+ ## Creating Plugins
302
+
303
+ Plugins can be created manually using the file structure described below, or they can be initialized automatically using `omegga init-plugin`.
304
+ Follow the prompts and your plugin will be generated for you.
305
+
306
+ The plugin types are as follows:
307
+
308
+ - `safe` (default), the standard Node VM plugin type
309
+ - `unsafe`, an unsafe plugin with raw access to internal Omegga APIs
310
+ - `rust`, an RPC plugin that makes use of the [omegga-rs](https://github.com/voximity/omegga-rs) Rust interface
311
+ - `rpc`, a plugin that will interface another executable using RPC over STDIN/STDOUT
312
+
313
+ ## Plugin Structure
314
+
315
+ All plugins are located in a `plugins` directory where you are running Omegga:
316
+
317
+ - `plugins/myPlugin` - plugin folder (required)
318
+ - `plugins/myPlugin/doc.json` - plugin information (required)
319
+ - `plugins/myPlugin/plugin.json` - plugin version information, validated with `omegga check` (optional, for now)
320
+ - `plugins/myPlugin/setup.sh` - plugin setup script, run after installed by `omegga install` (optional)
321
+ - `plugins/myPlugin/disable.omegga` - empty file only present if the plugin should be disabled (optional)
322
+
323
+ Every plugin requires a `doc.json` file to document which briefly describes the plugin and its commands.
324
+
325
+ ### `doc.json` (example)
326
+
327
+ ```json
328
+ {
329
+ "name": "My Plugin",
330
+ "description": "Example Plugin",
331
+ "author": "cake",
332
+ "config": {
333
+ "example-text": {
334
+ "description": "This is an example text input",
335
+ "default": "default value",
336
+ "type": "string"
337
+ },
338
+ "example-password": {
339
+ "description": "This is example text input hidden as a password",
340
+ "default": "hidden password value",
341
+ "type": "password"
342
+ },
343
+ "example-number": {
344
+ "description": "This is an example numerical input",
345
+ "default": 5,
346
+ "type": "number"
347
+ },
348
+ "example-bool": {
349
+ "description": "This is an example boolean input",
350
+ "default": false,
351
+ "type": "boolean"
352
+ }
353
+ },
354
+ "commands": [
355
+ {
356
+ "name": "!ping",
357
+ "description": "sends a pong to the sender",
358
+ "example": "!ping foo bar",
359
+ "args": [
360
+ {
361
+ "name": "args",
362
+ "description": "random filler arguments",
363
+ "required": false
364
+ }
365
+ ]
366
+ },
367
+ {
368
+ "name": "!pos",
369
+ "description": "announces player position",
370
+ "example": "!pos",
371
+ "args": []
372
+ }
373
+ ]
374
+ }
375
+ ```
376
+
377
+ ## Plugin Config
378
+
379
+ This is an example config section of a `doc.json`. The web ui provides an interface for editing these configs.
380
+
381
+ ```json
382
+ {
383
+ "config": {
384
+ "example-text": {
385
+ "description": "This is an example text input",
386
+ "default": "default value",
387
+ "type": "string"
388
+ },
389
+ "example-password": {
390
+ "description": "This is example text input hidden as a password",
391
+ "default": "hidden password value",
392
+ "type": "password"
393
+ },
394
+ "example-number": {
395
+ "description": "This is an example numerical input",
396
+ "default": 5,
397
+ "type": "number"
398
+ },
399
+ "example-bool": {
400
+ "description": "This is an example boolean input",
401
+ "default": false,
402
+ "type": "boolean"
403
+ },
404
+ "example-list": {
405
+ "description": "This is an example list input. List type can be string, password, number, or enum",
406
+ "type": "list",
407
+ "itemType": "string",
408
+ "default": ["hello"]
409
+ },
410
+ "example-enum": {
411
+ "description": "This is an example enum/dropdown input",
412
+ "type": "enum",
413
+ "options": ["foo", "bar", "baz", 1, 2, 3],
414
+ "default": "foo"
415
+ },
416
+ "example-enum-list": {
417
+ "description": "This is an example list of enums.",
418
+ "type": "list",
419
+ "itemType": "enum",
420
+ "options": ["foo", "bar", "baz"],
421
+ "default": ["foo"]
422
+ },
423
+ "example-players-list": {
424
+ "description": "This is an example list of players.",
425
+ "type": "players",
426
+ "default": [
427
+ {
428
+ "id": "fa577b9e-f2be-493f-a30a-3789b02ba70b",
429
+ "name": "Aware"
430
+ }
431
+ ]
432
+ },
433
+ "example-role": {
434
+ "description": "This is an example role dropdown",
435
+ "type": "role",
436
+ "default": "Admin"
437
+ }
438
+ }
439
+ }
440
+ ```
441
+
442
+ That config section would generate the following default config:
443
+
444
+ ```json
445
+ {
446
+ "example-text": "default value",
447
+ "example-password": "hidden password value",
448
+ "example-number": 5,
449
+ "example-bool": false,
450
+ "example-list": ["hello"],
451
+ "example-enum": "foo",
452
+ "example-enum-list": ["foo"],
453
+ "example-players-list": [
454
+ { "id": "fa577b9e-f2be-493f-a30a-3789b02ba70b", "name": "Aware" }
455
+ ]
456
+ }
457
+ ```
458
+
459
+ This is provided to plugins in the constructor or the RPC init function.
460
+
461
+ ## Plugin File
462
+
463
+ This is an example `plugin.json`, located inside a plugin folder. The plugin file helps omegga know if the plugin is compatible with the current installation. Plugin files can be validated with the `omegga check` command.
464
+
465
+ ```json
466
+ {
467
+ "formatVersion": 1,
468
+ "omeggaVersion": ">=0.1.32",
469
+ "emitConfig": "config.json"
470
+ }
471
+ ```
472
+
473
+ - `formatVersion` - indicates the plugin file format version
474
+ - `omeggaVersion` - indicates compatible omegga versions ([semver cheatsheet](https://www.npmjs.com/package/semver#user-content-ranges))
475
+ - `emitConfig` - optional, a path to a json file where plugin config will be saved to before the plugin starts.
476
+
477
+ ## Plugin Store
478
+
479
+ All plugins have the capability to get/set values in a very lightweight "database"
480
+
481
+ The following **asynchronous** methods are provided:
482
+
483
+ | Method | Arguments | Description |
484
+ | -------------- | ------------------------- | ---------------------------------------- |
485
+ | `store.get` | key (string) | Get an object from plugin store |
486
+ | `store.set` | key (string), value (any) | Store an object in plugin store |
487
+ | `store.delete` | key (string) | Remove an object from plugin store |
488
+ | `store.wipe` | _none_ | Remove all objects from plugin store |
489
+ | `store.count` | _none_ | Count number of objects in plugin store |
490
+ | `store.keys` | _none_ | Get keys for all objects in plugin store |
491
+
492
+ ### Example usage:
493
+
494
+ ```javascript
495
+ // simple add function
496
+ async function add() {
497
+ const a = await store.get('foo');
498
+ const b = await store.get('bar');
499
+ await store.set('baz', a + b);
500
+ await store.delete('foo');
501
+ await store.delete('bar');
502
+ }
503
+
504
+ (async () => {
505
+ // store foo and bar in the plugin store
506
+ await Promise.all([store.set('foo', 5), store.set('bar', 2)]);
507
+
508
+ // add foo and bar
509
+ await add();
510
+
511
+ // baz should be equal to 7
512
+ console.log('assert', (await store.get('baz')) === 7);
513
+
514
+ // demo of storing an object
515
+ await store.set('example object', {
516
+ foo: 'you can store objects in the store too',
517
+ bar: "just don't expect it to work with anything recursive (cannot serialize)",
518
+ });
519
+ })();
520
+ ```
521
+
522
+ For Node Plugins, the `store` is the third argument passed into the constructor. For JSONRPC Plugins, the `"store.get"`/etc. methods can be used.
523
+
524
+ **JSONRPC Note:** `store.set` has an array of arguments (`[key, value]`)
525
+
526
+ ## Node VM Plugins
527
+
528
+ Node VM Plugins are what you should be using. They are run inside a VM inside a Worker. This means when they crash, they do not crash the whole server, and they can in the future have locked down permissions (disable filesystem access, etc.).
529
+
530
+ These plugins receive a "proxy" reference to `omegga` and have limited reach for what they can touch.
531
+
532
+ Register custom `/commands` by returning `{registeredCommands: ['foo', 'bar']}` (registers command `/foo` and `/bar`) in the `async init()` method.
533
+
534
+ By defining an `async pluginEvent(event, from, ...args)` method in your plugin class, you can respond to events from other plugins, where `from` is the name of the other plugin, `event` is the name of the custom event, and `args` is an array of any passed arguments.
535
+
536
+ ### Globals
537
+
538
+ - `OMEGGA_UTIL` - access to the `src/util/index.js` module
539
+ - `Omegga` - access to the "proxy" omegga
540
+ - `console.log` - and other variants (`console.error`, `console.info`) print specialized output to console
541
+
542
+ ### Folder Structure
543
+
544
+ In a `plugins` directory create the following folder structure:
545
+
546
+ - `plugins/myPlugin` - plugin folder (required)
547
+ - `plugins/myPlugin/omegga.plugin.js` - js plugin main file (required)
548
+ - `plugins/myPlugin/doc.json`
549
+ - `plugins/myPlugin/access.json` - plugin access information (required, but doesn't have to have anything right now). this will contain what things the vm will need to access
550
+
551
+ ### `access.json` (examples)
552
+
553
+ Access to any builtin modules (`fs`, `path`, etc.)
554
+
555
+ ```json
556
+ ["*"]
557
+ ```
558
+
559
+ Access to nothing - only the code in the `omegga.plugin.js`
560
+
561
+ ```json
562
+ []
563
+ ```
564
+
565
+ Access to only `fs`, (`const fs = require('fs');`)
566
+
567
+ ```json
568
+ ["fs"]
569
+ ```
570
+
571
+ ### `omegga.plugin.js` (example)
572
+
573
+ ```javascript
574
+ class PluginName {
575
+ // the constructor also contains an omegga if you don't want to use the global one
576
+ // config and store variables are optional but provide access to the plugin data store
577
+ constructor(omegga, config, store) {
578
+ this.omegga = omegga;
579
+ this.config = config;
580
+ this.store = store;
581
+ console.info('constructed my plugin!');
582
+ }
583
+
584
+ async init() {
585
+ Omegga.on('chatcmd:ping', (name, ...args) => {
586
+ Omegga.broadcast(`pong @ ${name} + ${args.length} args`);
587
+ }).on('chatcmd:pos', async name => {
588
+ const [x, y, z] = await Omegga.getPlayer(name).getPosition();
589
+ Omegga.broadcast(`<b>${name}</> is at ${x} ${y} ${z}`);
590
+ });
591
+ }
592
+
593
+ async stop() {
594
+ // any remove events are not necessary because the VM removes the code
595
+ }
596
+ }
597
+
598
+ module.exports = PluginName;
599
+ ```
600
+
601
+ ### `omegga.plugin.ts` (example)
602
+
603
+ Be sure to put `.build/` and `node_modules/` in your `.gitignore`
604
+
605
+ **Requires a `tsconfig.json`**:
606
+
607
+ ```json
608
+ {
609
+ "compilerOptions": {
610
+ "noEmit": true,
611
+ "esModuleInterop": true,
612
+ "moduleResolution": "node",
613
+ "resolveJsonModule": true,
614
+ "target": "es2020",
615
+ "baseUrl": ".",
616
+ "paths": {
617
+ "omegga/*": ["node_modules/omegga/dist/*"]
618
+ }
619
+ }
620
+ }
621
+ ```
622
+
623
+ `omegga.plugin.ts`:
624
+
625
+ ```ts
626
+ import type { OmeggaPlugin, OL, PS, PC } from 'omegga/plugin';
627
+
628
+ type Config = { foo: string };
629
+ type Storage = { bar: string };
630
+
631
+ export default class Plugin implements OmeggaPlugin<Config, Storage> {
632
+ omegga: OL;
633
+ config: PC<Config>;
634
+ store: PS<Storage>;
635
+
636
+ constructor(omegga: OL, config: PC<Config>, store: PS<Storage>) {
637
+ this.omegga = omegga;
638
+ this.config = config;
639
+ this.store = store;
640
+ }
641
+
642
+ async init() {
643
+ // Write your plugin!
644
+ this.omegga.on('cmd:test', (speaker: string) => {
645
+ this.omegga.broadcast(`Hello, ${speaker}!`);
646
+ });
647
+
648
+ return { registeredCommands: ['test'] };
649
+ }
650
+
651
+ async stop() {
652
+ // Anything that needs to be cleaned up...
653
+ }
654
+ }
655
+ ```
656
+
657
+ ## Node Plugins
658
+
659
+ Node plugins are effectively `require`'d into omegga. They have the potential to crash the entire service through uncaught exceptions and also can be insecure. Develop and run these at your own risk - your server stability may suffer.
660
+
661
+ These plugins receive a direct reference to the `omegga` that wraps the brickadia server. As a result, they can directly modify how omegga runs.
662
+
663
+ Cleanup is important as code can still be running after the plugin is unloaded resulting in strange and undefined behavior. Make sure to run `clearInterval` and `clearTimeout`
664
+
665
+ Register custom `/commands` by returning `{registeredCommands: ['foo', 'bar']}` (registers command `/foo` and `/bar`) in the `async init()` method.
666
+
667
+ ### Globals
668
+
669
+ - `OMEGGA_UTIL` - access to the `src/util/index.js` module
670
+
671
+ ### Folder Structure
672
+
673
+ In a `plugins` directory create the following folder structure:
674
+
675
+ - `plugins/myPlugin` - plugin folder (required)
676
+ - `plugins/myPlugin/doc.json`
677
+ - `plugins/myPlugin/omegga.main.js` - js plugin main file (required)
678
+
679
+ ### `omegga.main.js` (example)
680
+
681
+ ```javascript
682
+ class PluginName {
683
+ // config and store variables are optional but provide access to the plugin data store
684
+ constructor(omegga, config, store) {
685
+ this.omegga = omegga;
686
+ this.config = config;
687
+ this.store = store;
688
+ }
689
+
690
+ async init() {
691
+ this.omegga
692
+ .on('chatcmd:ping', (name, ...args) => {
693
+ this.omegga.broadcast(`pong @ ${name} + ${args.length} args`);
694
+ })
695
+ .on('chatcmd:pos', async name => {
696
+ const [x, y, z] = await this.omegga.getPlayer(name).getPosition();
697
+ this.omegga.broadcast(`<b>${name}</> is at ${x} ${y} ${z}`);
698
+ });
699
+ }
700
+
701
+ async stop() {
702
+ this.omegga
703
+ .removeAllListeners('chatcmd:ping')
704
+ .removeAllListeners('chatcmd:pos');
705
+ }
706
+ }
707
+
708
+ module.exports = PluginName;
709
+ ```
710
+
711
+ ## JSON RPC Plugins
712
+
713
+ JSON RPC Plugins let you use any language you desire, as long as you can run it from a single executable file. They follow the [JSON-RPC 2.0 Specification](https://www.jsonrpc.org/specification)
714
+
715
+ The server communicates with the plugin by sending messages to `stdin` and expects responses in `stdout`. All `stderr` is printed to the console.
716
+
717
+ Register custom `/commands` by returning `{registeredCommands: ['foo', 'bar']}` (registers command `/foo` and `/bar`) in the `init` method.
718
+
719
+ ### Omegga Methods (You can access these)
720
+
721
+ | Method | Arguments | Description | Returns |
722
+ | ------------------------------ | ---------------------------------------------------- | ------------------------------------------------------------------- | --------------------------------------------------------------- |
723
+ | `log` | line (string) | Prints message to omegga console | |
724
+ | `error` | line (string) | Same as `log` but with different colors | |
725
+ | `info` | line (string) | Same as `log` but with different colors | |
726
+ | `debug` | line (string) | Same as `log` but with different colors | |
727
+ | `warn` | line (string) | Same as `log` but with different colors | |
728
+ | `trace` | line (string) | Same as `log` but with different colors | |
729
+ | `store.get` | key (string) | Get an object from plugin store | Object |
730
+ | `store.set` | [key (string), value (any)] | Store an object in plugin store | |
731
+ | `store.delete` | key (string) | Remove an object from plugin store | |
732
+ | `store.wipe` | _none_ | Remove all objects from plugin store | |
733
+ | `store.count` | _none_ | Count number of objects in plugin store | Integer |
734
+ | `store.keys` | _none_ | Get keys for all objects in plugin store | List of Strings |
735
+ | `exec` | cmd (string) | Writes a console command to Brickadia | |
736
+ | `writeln` | cmd (string) | Same as `exec` | |
737
+ | `broadcast` | line (string) | Broadcasts a message to the server | |
738
+ | `whisper` | {target: string, line: string} | Sends a message to a specific client | |
739
+ | `middlePrint` | {target: string, line: string} | Sends a middle print message to a specific client | |
740
+ | `getPlayers` | _none_ | Online players | List of Players |
741
+ | `getAllPlayerPositions` | _none_ | An array of objects with fields `pos` and `player`. | List of { _Player Object_(...), _Position_(...), isDead(bool) } |
742
+ | `getRoleSetup` | _none_ | Server roles | _JSON Data_ |
743
+ | `getBanList` | _none_ | List of bans | _JSON Data_ |
744
+ | `getSaves` | _none_ | Saves in the saves directory | List Strings |
745
+ | `getSavePath` | name (string) | The path to a specific save | String |
746
+ | `getSaveData` | _none_ | Current save as brs-js data | _BRS Object_ |
747
+ | `clearBricks` | {target: string, quiet: bool} | Clears a specific player's bricks | |
748
+ | `clearAllBricks` | quiet | Clears all bricks on the server | |
749
+ | `saveBricks` | name (string) | Save bricks to a save named `name` | |
750
+ | `loadBricks` | {name: string, offX, offY, offY, quiet: bool} | Load bricks of save named `name` | |
751
+ | `loadBricksOnPlayer` | {name: string, player: string, offX, offY, offY} | Load bricks of save named `name` on player clipboard | |
752
+ | `readSaveData` | name (string) | Parses save into a brs-js save object, returns the object | _BRS Object_ |
753
+ | `loadSaveData` | {data: object, offX, offY, offY, quiet: bool} | Builds brs file from data, loads the file | |
754
+ | `loadSaveDataOnPlayer` | {data: object, player: string, offX, offY, offY} | Builds brs file from data, loads the file onto a player's clipboard | |
755
+ | `changeMap` | map (string) | Change map to specified map name, returns success | Boolean |
756
+ | `player.get` | target (string) | Gets the player by their name or UUID. | `{name, id, controller, state, host: bool}` |
757
+ | `player.getRoles` | target (string) | Target's roles | |
758
+ | `player.getPermissions` | target (string) | Target's permissions | List of Strings |
759
+ | `player.getNameColor` | target (string) | Target's name color | _RGB Hex Object_ (int, int ,int) |
760
+ | `player.getPosition` | target (string) | Target's position | _Position Object_ |
761
+ | `player.getGhostBrick` | target (string) | Target's ghost brick | {targetGrid, location(_Location_), orientation} |
762
+ | `player.getPaint` | target (string) | Target's current paint selection | {materialIndex, materialAlpha, material, color)} |
763
+ | `player.getTemplateBounds` | target (string) | Target's template/selection bounds | {minBound, maxBound, Center} |
764
+ | `player.getTemplateBoundsData` | target (string) | Target's template/selection as brs-js save data | _Brick Object_ |
765
+ | `player.loadSaveData` | {target, data, offX, offY, offZ} | Loads brs-js save data to the targets clipboard | |
766
+ | `player.loadDataAtGhostBrick` | {target, data, rotate=true, offX, offY, offZ, quiet} | Loads brs-js save data at the target's selection bounds | |
767
+ | `plugin.get` | target (string) | Gets info on the target plugin | Object |
768
+ | `plugin.emit` | [target (string), event (string), ...args (any)] | Emit a custom event to the target plugin | |
769
+
770
+ ### Plugin Methods (You implement these)
771
+
772
+ | Method | Arguments | Description | Required |
773
+ | -------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- |
774
+ | `init` | config object | Returns a start result, called on plugin start | &#9745; |
775
+ | `stop` | _none_ | Returns _something_, called on plugin stop | &#9745; |
776
+ | `bootstrap` | [{ omegga info (`host`, `version`, etc) }] | Run when plugin is started for base data | |
777
+ | `plugin:players:raw` | [[... [player `name`, `id`, `controller`, `state`]]] | Lists players on the server | |
778
+ | `plugin:emit` | [event, from, ...args] | Fired when another plugin sends an event | |
779
+ | `line` | [brickadiaLog string] | A brickadia console log | |
780
+ | `start` | [{map}] | On brickadia server start | |
781
+ | `host` | [{name, id}] | When the host is detected | |
782
+ | `version` | [-1 or the CL number] | When the version is detected | |
783
+ | `unauthorized` | _none_ | On brickadia server fails an auth check | |
784
+ | `join` | [{name, id, state, controller}] | Run when a player joins | |
785
+ | `leave` | [{name, id, state, controller}] | Run when a player leaves | |
786
+ | `cmd:command` | [playerName, ...args] | Runs when a player runs a `/command args` | |
787
+ | `chatcmd:command` | [playerName, ...args] | Runs when a player runs a `!command args` | |
788
+ | `chat` | [playerName, message] | Runs when a player sends a chat message | |
789
+ | `interact` | {brick_asset: string;player: { id: string; name: string; controller: string; pawn: string };position: [number, number, number];} | Runs when a player clicks a brick with an interact component. `data` is parsed JSON if `line` (from interact component) starts with "json:{"your": "json"}`. Uses interact log field | |
790
+ | `event:NAME` | [&gt;player from click&lt;, ...args] | Runs when an interact component has `event:NAME: arg1,arg2,arg\,3, | |
791
+ | `mapchange` | \[{map}\] | Runs when the map changes | |
792
+ | `autorestart` | [autorestart config] | Runs server has an autorestart scheduled | |
793
+ | `minigamejoin` | {player: {name, id}; minigameName: string} | Runs when a player joins a minigame. Note that minigameName is not unique between minigames. minigameName will be null if player leaves all minigames. This will run before `join` | |
794
+
795
+ ### Folder Structure
796
+
797
+ In a `plugins` directory create the following folder structure:
798
+
799
+ - `plugins/myPlugin` - plugin folder (required)
800
+ - `plugins/myPlugin/doc.json`
801
+ - `plugins/myPlugin/omegga_plugin` - executable plugin file (required)
802
+
803
+ ### `omegga_plugin` (example, node javascript)
804
+
805
+ ```javascript
806
+ #!/usr/bin/env node
807
+
808
+ const readline = require('readline');
809
+ const { EventEmitter } = require('events');
810
+ const {
811
+ JSONRPCServer,
812
+ JSONRPCServerAndClient,
813
+ JSONRPCClient,
814
+ } = require('json-rpc-2.0');
815
+
816
+ // events
817
+ const ev = new EventEmitter();
818
+
819
+ // stdio handling
820
+ const rl = readline.createInterface({
821
+ input: process.stdin,
822
+ output: process.stdout,
823
+ terminal: false,
824
+ });
825
+
826
+ // rpc "server and client" for responding/receiving messages
827
+ const rpc = new JSONRPCServerAndClient(
828
+ new JSONRPCServer(),
829
+ // the client outputs JSON to console
830
+ new JSONRPCClient(async blob => console.log(JSON.stringify(blob)))
831
+ );
832
+
833
+ // on stdin, pass into rpc
834
+ rl.on('line', line => {
835
+ try {
836
+ rpc.receiveAndSend(JSON.parse(line));
837
+ } catch (e) {
838
+ console.error(e);
839
+ }
840
+ });
841
+
842
+ // regexes for matching brickadia console logs
843
+ const GENERIC_LINE_REGEX =
844
+ /^(\[(?<date>\d{4}\.\d\d.\d\d-\d\d.\d\d.\d\d:\d{3})\]\[\s*(?<counter>\d+)\])?(?<generator>\w+): (?<data>.+)$/;
845
+ const LOG_LINE_REGEX =
846
+ /\[(?<date>\d{4}\.\d\d.\d\d-\d\d.\d\d.\d\d:\d{3})\]\[\s*(?<counter>\d+)\](?<rest>.*)$/;
847
+
848
+ ev.on('line', line => {
849
+ const logMatch = line.match(LOG_LINE_REGEX);
850
+ if (!logMatch) return;
851
+ const {
852
+ groups: { rest },
853
+ } = logMatch;
854
+ const dataMatch = rest.match(GENERIC_LINE_REGEX);
855
+ if (dataMatch) ev.emit('logData', dataMatch.groups);
856
+ else ev.emit('logLine', rest);
857
+ });
858
+
859
+ // list of players
860
+ let players;
861
+
862
+ // get a player by name
863
+ const getPlayer = name => players.find(p => p.name === name);
864
+
865
+ // watch console logs for a pattern, then remove the listener
866
+ function watch(exec, pattern) {
867
+ return new Promise(resolve => {
868
+ function listener(line) {
869
+ const match = line.match(pattern);
870
+ // listener removes itself on a match
871
+ if (match) {
872
+ ev.off('logLine', listener);
873
+ resolve(match.groups);
874
+ }
875
+ }
876
+ // add the listener
877
+ ev.on('logLine', listener);
878
+
879
+ // run the console command
880
+ rpc.notify('writeln', exec);
881
+ });
882
+ }
883
+
884
+ // get a player's position
885
+ async function getPlayerPos(name) {
886
+ const player = getPlayer(name);
887
+ if (!player) return;
888
+
889
+ // get player position from player controller
890
+ const pawnRegExp = new RegExp(
891
+ `BP_PlayerController_C .+?PersistentLevel\\.${player.controller}\.Pawn = BP_FigureV2_C'.+?:PersistentLevel.(?<pawn>BP_FigureV2_C_\\d+)'`
892
+ );
893
+ const { pawn } = await watch(
894
+ `GetAll BP_PlayerController_C Pawn Name=${player.controller}`,
895
+ pawnRegExp
896
+ );
897
+
898
+ // get player position from pawn
899
+ const posRegExp = new RegExp(
900
+ `CapsuleComponent .+?PersistentLevel\\.${pawn}\\.CollisionCylinder\\.RelativeLocation = \\(X=(?<x>[\\d\\.-]+),Y=(?<y>[\\d\\.-]+),Z=(?<z>[\\d\\.-]+)\\)`
901
+ );
902
+ const { x, y, z } = await watch(
903
+ `GetAll SceneComponent RelativeLocation Name=CollisionCylinder Outer=${pawn}`,
904
+ posRegExp
905
+ );
906
+
907
+ return [x, y, z].map(Number);
908
+ }
909
+
910
+ // emit a console log
911
+ const log = (...args) => rpc.notify('log', args.join(' '));
912
+
913
+ // when available players updates - plugin:players:raw is emitted
914
+ rpc.addMethod('plugin:players:raw', ([playerArr]) => {
915
+ // update the players list
916
+ players = playerArr.map(p => ({
917
+ name: p[0],
918
+ id: p[1],
919
+ controller: p[2],
920
+ state: p[3],
921
+ }));
922
+ });
923
+
924
+ // ping command
925
+ rpc.addMethod('chatcmd:ping', ([name, ...args]) => {
926
+ rpc.notify('broadcast', `pong @ ${name} + ${args.length} args`);
927
+ });
928
+
929
+ // player position command
930
+ rpc.addMethod('chatcmd:pos', async ([name]) => {
931
+ log('player', name, 'requests position');
932
+ const [x, y, z] = await getPlayerPos(name);
933
+ rpc.notify('broadcast', `<b>${name}</> is at ${x} ${y} ${z}`);
934
+ });
935
+
936
+ // pass lines into the event emitter
937
+ rpc.addMethod('line', ([line]) => {
938
+ ev.emit('line', line);
939
+ });
940
+
941
+ // receive config object in init
942
+ rpc.addMethod('init', async ([config]) => ({ registeredCommands: [] }));
943
+ rpc.addMethod('stop', async () => 'ok');
944
+ ```
945
+
946
+ # Extra Features
947
+
948
+ ## Environment Variables
949
+
950
+ `omegga` accepts the following environment variables:
951
+
952
+ - `BRICKADIA_USER` - brickadia auth username (on first start)
953
+ - `BRICKADIA_PASS` - brickadia auth password (on first start)
954
+ - `BRICKADIA_PORT` - brickadia server port (on config creation)
955
+ - `OMEGGA_PORT` - omegga webserver port (on config creation)
956
+
957
+ ## Config
958
+
959
+ Default config values (including hidden ones)
960
+
961
+ ```yaml
962
+ omegga:
963
+ port: 8080 # web-ui port
964
+ webui: true # enable web-ui
965
+ plugins: true # enable plugins
966
+ singleUser: false # disable web-ui auth users
967
+ https: true # enable https for web-ui
968
+ debug: false # debug logging
969
+ server:
970
+ port: 7777 # game server port
971
+ map: Plate # map name
972
+ branch: unstable:unstable-server # branch alias:branch name
973
+ ```