Events Manager
Reldens is a full base-events platform, so here we are going to explain how to interact with it.
How the EventsManager works?
When you create a new ServerManager or GameManager (client-side) the EventsManagerSingleton is automatically assigned to that manager so you can use it for any listener you like to attach. This way you will be able to listen to all the platform events and modify the server or the client behavior without requiring to modify the core code.
In the future this approach will help us with the hot-plug of new features and server management without requiring to restart the server.
In the skeleton example you will find the server manager initialization in the index file:
Here you can see that you only need to access the ServerManager.events property (which is the EventsManagerSingleton instance), and append your event, that's it!
The same applies for the GameManager on the client side:
The EventsManager is an extension of the AwaitEventEmitter, which by default allow us to use sync and async events. In our case we extended it a bit further to include some extra features:
- The main addition are the "removeKey" and the "masterKey", you can specify these while adding an event listener and that listener will be associated to an specific "group" under those keys, this way you can turn off multiple events at once using any of the keys.
- The second is the debug mode that will generate logs for every listener added and every time an event is fired. This debug mode can be set using the EventsManager.debug property, and it can be configured as "all" (for every event), or for specific events (see debug configuration below).
Types of events
Since we are working with a multiplayer platform in the server side we have different event types.
What does this mean? It means that some events are going to be executed "globally" and some are going to use keys for specific rooms, players or objects.
We have to differentiate between these because the EventsManager is a singleton, which give us the possibility to easily implement it anywhere, but at the same time it will make us to get every single event fired, and for that we had created the event keys otherwise you would need to apply tons of filters on each listener to make sure the event was fired in an specific room, for an specific player or object.
For example:
- The event "reldens.beforeLoadConfigurations" is going to be executed globally (and for now, only once) when the server is initialized.
- But also you can find events with dynamic keys like in the skills package:
"p+[player-id]+.reldens.items.equipItem" => "p1.reldens.items.equipItem"
Which is designed to affect only the player with id = 1.
This was design in this way because otherwise if we don't apply a key, then the server will trigger the event "reldens.items.equipItem", and you will need to manually send and validate on which player the item was been equipped.
Let's move on to the events list and there you will find all you need: Events List.