@goodgamestudios/cxf-events
TypeScript icon, indicating that this package has built-in type declarations

1.23.1 • Public • Published

cxf-events

💬 Unified events for CXF extensions

Motivation

Games exchange messages in different formats and with different IDs. For example, a login command looks different on BigFarm and Empire. cxf-events normalizes & standardizes basic events in a game-agnostic way. Your CXF extension can subscribe to cxf.* events and work in almost all games.

+------------------+
|                  |
| LOGIN_BASIC_DATA |--->------+
|                  |       becomes
+------------------+          ↓
                      +---------------+
                      |               |
                      |   cxf.login   |---→ your CXF Extension
                      |               |
                      +---------------+
+------------------+          ↑
|                  |       becomes
|        gbd       |--->------+
|                  |
+------------------+

Usage

  • Include @goodgamestudios/cxf-events in @goodgamestudios/cxf-plugins
// Wait for cxf to be ready
require('@goodgamestudios/cxf-ready').then(cxf => {
  // Subscribe to relevant events
  cxf.on(CxfEvents.Login, loginData => {
    // do something on login
  })
})

Events

cxf.login

Emitted after a successful player login. In addition to sending the login arguments with the event, cxf.login also stores them in cxf.playerId, cxf.instanceId, cxf.networkId, cxf.gameId and cxf.language.

  • Event ID cxf.login
  • Arguments { playerId, instanceId, networkId, gameId, language }

Example

require('@goodgamestudios/cxf-ready').then(cxf => {
  cxf.on(CxfEvents.Login, loginData => {
    // do something on login
  })
})

How to listen for new game events

Bigfarm

To be able to listen for a new event from bigfarm, you will need to either listen to its descriptive event or its ID event. For instance: If you want to listen for the SUBSCRIPTION_INFO event (ID 460) you will need to:

To be able to listen for a new event from bigfarm, you will need to either listen to its descriptive event and also its ID event. For instance, if you want to listen for the SUBSCRIPTION_INFO event (ID 460) you will need to:

// Just listening for this event is not enough
cxf.once('SUBSCRIPTION_INFO', (e: BigfarmEvent<BigfarmSubscriptionEvent>) => {
  // Your code here
});
// Subscribing to event id, so the first event will be fowarded to CXF
cxf.on('460', () => {});

/@goodgamestudios/cxf-events/

    Package Sidebar

    Install

    npm i @goodgamestudios/cxf-events

    Weekly Downloads

    260

    Version

    1.23.1

    License

    MIT

    Unpacked Size

    74 kB

    Total Files

    7

    Last publish

    Collaborators

    • ntggs
    • pverza-ggs
    • prosenboom
    • sashamat
    • mbahri
    • rtryputsko-ext-ggs
    • abuhler_ggs
    • jonasbraga-ggs
    • rschmidt-ggs
    • ssydorenko-ggs
    • vtenekedzhiev-ggs
    • tschrader-ggs
    • goodgame
    • jenkinshtml5migra
    • ddepaolis-ggs
    • boczujda_ggs
    • guest-ggs
    • andreaspizsa
    • cgeisler-ggs
    • amartin-ggs
    • mabdallah-ggs
    • jenkinsempire-ggs
    • chadestioco
    • evmoroz
    • ggs-skunkbot
    • stp_ci_ggs
    • it_office
    • iskliarenko