Extend

How to extend GS2’s microservices functionality.

GS2 provides several functions as microservices. However, there may be situations where you want to extend the functionality.

GS2-Script provides scripting capabilities using the Lua language and can extend the functionality of GS2 microservices. Scripts written in GS2-Script are not invoked at all times, but are executed in response to triggers defined by each GS2 microservice.

For example, GS2-Account has the following triggers

  • Create new account
  • Authentication execution
  • Register transfer information
  • Transfer execution

For each of these, “synchronous processing” and “asynchronous processing” are available as the timing for script execution.

Example of script executed when creating a new account

Request

TypeDescription
namespaceNamespaceNamespace
accountAccountGame player’s account

Result

TypeRequiredDefaultValue ConstraintsDescription
permitboolWhether to allow creating an account

Implementation Example

namespace = args.namespace
account = args.account

result = {
  permit=permit
}

Synchronous processing

When synchronous processing is set for a trigger, API processing is blocked until script execution is complete. Instead of slowing down the response time of the API for the duration of the script execution, you can “fake” the results of the script or “stop processing”.

To give a more concrete example, you can use a script to double the amount of experience gained from a quest, or to cause a response error if the party formed at the start of a quest does not include a certain character.

Asynchronous processing

When asynchronous processing is set for a trigger, the script is executed asynchronously after the API responds.

If you want to implement a ranking based on the number of items owned, you can assign an asynchronous script to the trigger when an item is acquired or consumed. This allows you to register the number of items owned as a score in the ranking without affecting the response time of the API.

Asynchronous processing in Amazon Event Bridge

GS2 can use the Amazon Event Bridge provided by AWS to implement asynchronous processing. See the separate document for details on using the Amazon Event Bridge.


Using Amazon Event Bridge

Using Amazon Event Bridge Extending GS2 functionality with Amazon Event Bridge.