Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified events draft #396

Merged
merged 23 commits into from
Jul 26, 2024
Merged

Conversation

SebastienGllmt
Copy link
Contributor

@SebastienGllmt SebastienGllmt commented Jul 16, 2024

This PR simplifies the event system, also sets up the events to use typebox so that it is both strongly typed and so that we can later export them as json-schema for documentation purposes and so that it works well with the json-schema we'll use for the log system

  • doesn't solve the ENV issue
  • disable external users from sending messages to the engine/batcher (I believe this can be done with this)
  • add more status options to the batcher event
  • don't only send block events when a block is non-empty (non-empty should maybe just be a filter on blocks?)
  • fix the issue where block events may be skipped if paima engine shuts down (see Handling shutdowns in event listeners in Emit event standard for games #373)
  • Disable MQTT reserved keywords (/, +, #) in event names
  • test this PR

Define an event

const QuestCompletionEvent = genEvent({
  name: 'QuestCompletion',
  fields: [
    {
      name: 'questId',
      type: Type.Integer(),
      indexed: true,
    },
    {
      name: 'playerId',
      type: Type.Integer(),
    },
  ],
} as const);

Listen to Messages

Listen to an event

PaimaEventManager.Instance.subscribe(
  {
    topic: QuestCompletionEvent,
    filter: { questId: undefined }, // all quests
  },
  event => {
    console.log(`Quest ${event.questId} cleared by ${event.playerId}`);
  }
);

Send Messages

Sent an event

PaimaEventListener.Instance.sendMessage(
  QuestCompletionEvent,
  {
    questId: 5,
    playerId: 10
  }
);

@SebastienGllmt SebastienGllmt merged commit a085293 into feature/emit-events Jul 26, 2024
@SebastienGllmt SebastienGllmt deleted the simplified-events branch July 26, 2024 23:32
SebastienGllmt added a commit that referenced this pull request Jul 28, 2024
* Simplified events draft

* Simplify even more

* lint fix

* make indexed optional, fix exports, rename fields

* MQTT async update

* move to qos2 by default

* eslint & bug fixes

* temp fix on packaeg resolution

* Create new local SDK packing tool

* Add missing packages to local SDK output

* more improvements to local SDK setup

* add missing @paima/precompiles exports

* fix paima-event bugs

* small eslint fix

* Fix topic generation & parsing bugs

* Better 'this' handling for events

* More fixes and improvements

* Make batcher filter indexable

* Fix incorrect casing on BatcherStatus

* Restrict event publishing just to localhost

* fix batcher localhost startup script

* Add localhost package check

* document edge-case on BatcherStatus updates
SebastienGllmt added a commit that referenced this pull request Jul 28, 2024
* Emit MQTT Events basic implementation

* MQTT Client

* Batcher Server Echo

* Updated Client

* Added ENV

* Only emit if block has data to be processed by stf.

* Paima Events V1

* lint

* Revert Changes

* Paima Events v1

* batcher hashes

* Remove mqtt:// protocol

* Update fetch for last STF block

* Removed ENV dependency

* Added Frontend Helpers.

* Removed unused hash

* env removed coalescing

* removed .gitignore

* env variables update

* Simplified events draft (#396)

* Simplified events draft

* Simplify even more

* lint fix

* make indexed optional, fix exports, rename fields

* MQTT async update

* move to qos2 by default

* eslint & bug fixes

* temp fix on packaeg resolution

* Create new local SDK packing tool

* Add missing packages to local SDK output

* more improvements to local SDK setup

* add missing @paima/precompiles exports

* fix paima-event bugs

* small eslint fix

* Fix topic generation & parsing bugs

* Better 'this' handling for events

* More fixes and improvements

* Make batcher filter indexable

* Fix incorrect casing on BatcherStatus

* Restrict event publishing just to localhost

* fix batcher localhost startup script

* Add localhost package check

* document edge-case on BatcherStatus updates

* Include batcher MQTT updates

* fix env.process lookup

---------

Co-authored-by: Sebastien Guillemot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants