The code runtime built into the server includes a module with functions to implement various logic and custom behavior, enabling you to define authoritative code and conditions on input received by clients. Learn more about it in the Server Framework documentation.
This page lists all functions available within Layerg and their respective parameters, with corresponding code samples for each. If you haven’t already, see the documentation on using the server framework.
The creation of custom tables is strongly discouraged.
Accounts
accountDeleteId
Delete an account by user ID.
Name | Default | Description |
---|
userId string REQUIRED | | User ID for the account to be deleted. Must be valid UUID. |
recorded bool | false | Whether to record this deletion in the database. |
Name | Description |
---|
error error | An optional error value if an error occurred. |
let userId = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
try {
lg.accountDeleteId(userId, false);
} catch (error) {
}
accountExportId
Export account information for a specified user ID.
Name | Default | Description |
---|
userId string REQUIRED | | User ID for the account to be exported. Must be valid UUID. |
Name | Description |
---|
export string | Account information for the provided user ID, in JSON format. |
error error | An optional error value if an error occurred. |
let userId = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
try {
let accountJson = lg.accountExportId(userId);
} catch (error) {
}
accountGetId
Fetch account information by user ID.
Name | Default | Description |
---|
userId string REQUIRED | | User ID to fetch information for. Must be valid UUID. |
Name | Description |
---|
account lgruntime.Account | All account information including wallet, device IDs and more. |
error error | An optional error value if an error occurred. |
let userId = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
try {
let account = lg.accountGetId(userId);
} catch (error) {
}
accountsGetId
Fetch information for multiple accounts by user IDs.
Name | Default | Description |
---|
userIds []string REQUIRED | | Array of user IDs to fetch information for. Must be valid UUID. |
Returns |
---|
Name |
--- |
account lgruntime.Account[] |
error error |
let userIds = ['4ec4f126-3f9d-11e7-84ef-b7c182b36521', '6134d1cf-4b55-497f-b9e9-fc5090b76475'];
try {
let accounts = lg.accountsGetId(userIds);
} catch (error) {
}
accountUpdateId
Update an account by user ID.
Name | Default | Description |
---|
userId string REQUIRED | | User ID for which the information is to be updated. Must be valid UUID. |
metadata object | | The metadata to update for this account. |
username string | | Username to be set. Must be unique. Use null if it is not being updated. |
displayName string | | Display name to be updated. Use null if it is not being updated. |
timezone string | | Timezone to be updated. Use null if it is not being updated. |
location string | | Location to be updated. Use null if it is not being updated. |
language string | | Lang tag to be updated. Use null if it is not being updated. |
avatarUrl string | | User's avatar URL. Use null if it is not being updated. |
Returns |
---|
Name |
--- |
error error |
let userId = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
let username = null;
let metadata = {pro: true};
let displayName = 'new display name';
let timezone = null;
let location = null;
let langTag = null;
let avatarUrl = null;
try {
lg.accountUpdateId(userId, username, displayName, timezone, location, langTag, avatarUrl, metadata);
} catch (error) {
}
Authenticate
authenticateApple
Authenticate user and create a session token using an Apple sign in token.
Name | Default | Description |
---|
token string REQUIRED | | Apple sign in token. |
username string | | The user's username. If left empty, one is generated. |
create bool | true | Create user if one didn't exist previously. |
Name | Description |
---|
userID string | The user ID of the authenticated user. |
username string | The username of the authenticated user. |
create bool | Value indicating if this account was just created or already existed. |
error error | An optional error value if an error occurred. |
let result = {} as lgruntime.AuthResult;
try {
result = lg.authenticateApple('some-oauth-access-token', 'username', true);
} catch (error) {
}
authenticateCustom
Authenticate user and create a session token using a custom authentication managed by an external service or source not already supported by Layerg.
Name | Default | Description |
---|
id string REQUIRED | | Custom ID to use to authenticate the user. Must be between 6-128 characters. |
username string | | The user's username. If left empty, one is generated. |
create bool | true | Create user if one didn't exist previously. |
Name | Description |
---|
userID string | The user ID of the authenticated user. |
username string | The username of the authenticated user. |
create bool | Value indicating if this account was just created or already existed. |
error error | An optional error value if an error occurred. |
let result = {} as lgruntime.AuthResult;
try {
result = lg.authenticateCustom('48656C6C6F20776F726C64', 'username', true);
} catch (error) {
}
authenticateDevice
Authenticate user and create a session token using a device identifier.
Name | Default | Description |
---|
id string REQUIRED | | Device ID to use to authenticate the user. Must be between 1-128 characters. |
username string | | The user's username. If left empty, one is generated. |
create bool | true | Create user if one didn't exist previously. |
Name | Description |
---|
userID string | The user ID of the authenticated user. |
username string | The username of the authenticated user. |
create bool | Value indicating if this account was just created or already existed. |
error error | An optional error value if an error occurred. |
let result = {} as lgruntime.AuthResult;
try {
result = lg.authenticateDevice('48656C6C6F20776F726C64', 'username', true);
} catch (error) {
}
authenticateEmail
Authenticate user and create a session token using an email address and password.
Name | Default | Description |
---|
email string REQUIRED | | Email address to use to authenticate the user. Must be between 10-255 characters. |
password string REQUIRED | | Password to set. Must be longer than 8 characters. |
username string | | The user's username. If left empty, one is generated. |
create bool | true | Create user if one didn't exist previously. |
Name | Description |
---|
userID string | The user ID of the authenticated user. |
username string | The username of the authenticated user. |
create bool | Value indicating if this account was just created or already existed. |
error error | An optional error value if an error occurred. |
let result = {} as lgruntime.AuthResult;
try {
result = lg.authenticateEmail('[email protected]', 'password', 'username', true);
} catch (error) {
}
authenticateFacebook
Authenticate user and create a session token using a Facebook account token.
Name | Default | Description |
---|
token string REQUIRED | | Facebook OAuth or Limited Login (JWT) access token. |
import bool | true | Whether to automatically import Facebook friends after authentication. |
username string | | The user's username. If left empty, one is generated. |
create bool | true | Create user if one didn't exist previously. |
Name | Description |
---|
userID string | The user ID of the authenticated user. |
username string | The username of the authenticated user. |
create bool | Value indicating if this account was just created or already existed. |
error error | An optional error value if an error occurred. |
let result = {} as lgruntime.AuthResult;
try {
result = lg.authenticateFacebook('some-oauth-access-token', 'username', true);
} catch (error) {
}
authenticateFacebookInstantGame
Authenticate user and create a session token using a Facebook Instant Game.
Name | Default | Description |
---|
playerInfo string REQUIRED | | Facebook Player info. |
username string | | The user's username. If left empty, one is generated. |
create bool | true | Create user if one didn't exist previously. |
Name | Description |
---|
userID string | The user ID of the authenticated user. |
username string | The username of the authenticated user. |
create bool | Value indicating if this account was just created or already existed. |
error error | An optional error value if an error occurred. |
let result = {} as lgruntime.AuthResult;
try {
result = lg.authenticateFacebookInstantGame('player-info', 'username', true);
} catch (error) {
}
authenticateGameCenter
Authenticate user and create a session token using Apple Game Center credentials.
Name | Default | Description |
---|
playerId string REQUIRED | | PlayerId provided by GameCenter. |
bundleId string REQUIRED | | BundleId of your app on iTunesConnect. |
timestamp int REQUIRED | | Timestamp at which Game Center authenticated the client and issued a signature. |
salt string REQUIRED | | A random string returned by Game Center authentication on client. |
signature string REQUIRED | | A signature returned by Game Center authentication on client. |
publicKeyUrl string REQUIRED | | A URL to the public key returned by Game Center authentication on client. |
username string | | The user's username. If left empty, one is generated. |
create bool | true | Create user if one didn't exist previously. |
Name | Description |
---|
userID string | The user ID of the authenticated user. |
username string | The username of the authenticated user. |
create bool | Value indicating if this account was just created or already existed. |
error error | An optional error value if an error occurred. |
let result = {} as lgruntime.AuthResult;
try {
result = lg.authenticateGameCenter(playerId, bundleId, timestamp, salt, signature, publicKeyUrl, username, create);
} catch (error) {
}
authenticateGoogle
Authenticate user and create a session token using a Google ID token.
Name | Default | Description |
---|
token string REQUIRED | | Google OAuth access token. |
username string | | The user's username. If left empty, one is generated. |
create bool | true | Create user if one didn't exist previously. |
Name | Description |
---|
userID string | The user ID of the authenticated user. |
username string | The username of the authenticated user. |
create bool | Value indicating if this account was just created or already existed. |
error error | An optional error value if an error occurred. |
let result = {} as lgruntime.AuthResult;
try {
result = lg.authenticateGoogle('some-id-token', 'username', true);
} catch (error) {
}
authenticateSteam
Authenticate user and create a session token using a Steam account token.
Name | Default | Description |
---|
token string REQUIRED | | Steam token. |
username string | | The user's username. If left empty, one is generated. |
import bool | true | Whether to automatically import Steam friends after authentication. |
create bool | true | Create user if one didn't exist previously. |
Name | Description |
---|
userID string | The user ID of the authenticated user. |
username string | The username of the authenticated user. |
create bool | Value indicating if this account was just created or already existed. |
error error | |
let result = {} as lgruntime.AuthResult;
try {
result = lg.authenticateSteam('steam-token', 'username', true);
} catch (error) {
}
authenticateTokenGenerate
Generate a Layerg session token from a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | User ID to use to generate the token. |
username string | | The user's username. If left empty, one is generated. |
expiresAt number | | UTC time in seconds when the token must expire. Defaults to server configured expiry time. |
vars | | Extra information that will be bundled in the session token. |
Name | | Description |
---|
token string | | The Layerg session token. |
validity number | | The period for which the token remains valid. |
error error | | An optional error value if an error occurred. |
let result = {} as lgruntime.TokenGenerateResult;
try {
result = lg.authenticateTokenGenerate('steam-token', 'username', true);
} catch (error) {
}
linkApple
Link Apple authentication to a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be linked. |
token string REQUIRED | | Apple sign in token. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let token = '<Token>';
try {
lg.linkApple(userId, token);
} catch (error) {
}
linkCustom
Link custom authentication to a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be linked. |
customId string REQUIRED | | Custom ID to be linked to the user. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let customId = '<CustomId>';
try {
lg.linkCustom(userId, customId);
} catch (error) {
}
linkDevice
Link device authentication to a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be linked. |
deviceId string REQUIRED | | Device ID to be linked to the user. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let deviceId = '<Deviceid>';
try {
lg.linkDevice(userId, deviceId);
} catch (error) {
}
linkEmail
Link email authentication to a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be linked. |
email string REQUIRED | | Authentication email to be linked to the user. |
password string REQUIRED | | Password to set. Must be longer than 8 characters. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let email = '[email protected]';
let password = 'correct horse battery staple'
try {
lg.linkEmail(userId, email, password);
} catch (error) {
}
linkFacebook
Link Facebook authentication to a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be linked. |
username string | | If left empty, one is generated. |
token string REQUIRED | | Facebook OAuth or Limited Login (JWT) access token. |
importFriends bool | true | Whether to automatically import Facebook friends after authentication. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let username = '<Username>';
let token = '<Token>';
let importFriends = true;
try {
lg.linkFacebook(userId, username, token, importFriends);
} catch (error) {
}
linkFacebookInstantGame
Link Facebook Instant Game authentication to a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be linked. |
playerInfo string REQUIRED | | Facebook player info. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let signedPlayerInfo = '<SignedPlayerInfo>';
try {
lg.linkFacebookInstantGame(userId, signedPlayerInfo);
} catch (error) {
}
linkGameCenter
Link Apple Game Center authentication to a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be linked. |
playerId string REQUIRED | | Player ID provided by Game Center. |
bundleId string REQUIRED | | Bundle ID of your app on iTunesConnect. |
timestamp int REQUIRED | | Timestamp at which Game Center authenticated the client and issued a signature. |
salt string REQUIRED | | A random string returned by Game Center authentication on client. |
signature string REQUIRED | | A signature returned by Game Center authentication on client. |
publicKeyUrl string REQUIRED | | A URL to the public key returned by Game Center authentication on client. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let playerId = '<PlayerId>';
let bundleId = '<BundleId>';
let timestamp = 0;
let salt = "<Salt>";
let signature = "<Signature>";
let publicKeyUrl = "<PublicKeyUrl>";
try {
lg.linkGameCenter(userId, playerId, bundleId, timestamp, salt, signature, publicKeyUrl);
} catch (error) {
}
linkGoogle
Link Google authentication to a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be linked. |
token string REQUIRED | | Google OAuth access token. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let token = '<Token>';
try {
lg.linkGoogle(userId, token);
} catch (error) {
}
linkSteam
Link Steam authentication to a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be linked. |
username string | | If left empty, one is generated. |
token string REQUIRED | | Steam access token. |
importFriends bool | true | Whether to automatically import Steam friends after authentication. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let username = '<Username>';
let token = '<Token>';
let importFriends = true;
try {
lg.linkSteam(userId, username, token, importFriends);
} catch (error) {
}
unlinkApple
Unlink Apple authentication from a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be unlinked. |
token string REQUIRED | | Apple sign in token. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let token = '<Token>';
try {
lg.unlinkApple(userId, token);
} catch (error) {
}
unlinkCustom
Unlink custom authentication from a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be unlinked. |
customId string | | Custom ID to be unlinked from the user. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let customId = '<CustomId>';
try {
lg.unlinkCustom(userId, customId);
} catch (error) {
}
unlinkDevice
Unlink device authentication from a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be unlinked. |
deviceId string REQUIRED | | Device ID to be unlinked to the user. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let deviceId = '<Deviceid>';
try {
lg.unlinkDevice(userId, deviceId);
} catch (error) {
}
unlinkEmail
Unlink email authentication from a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be unlinked. |
email string | | Email to be unlinked from the user. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let email = '[email protected]';
try {
lg.unlinkEmail(userId, email);
} catch (error) {
}
unlinkFacebook
Unlink Facebook authentication from a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be unlinked. |
token string | | Facebook OAuth or Limited Login (JWT) access token. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let token = '<Token>';
try {
lg.unlinkFacebook(userId, token);
} catch (error) {
}
unlinkFacebookInstantGame
Unlink Facebook Instant Game authentication from a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be unlinked. |
playerInfo string | | Facebook player info. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let signedPlayerInfo = '<SignedPlayerInfo>';
try {
lg.unlinkFacebookInstantGame(userId, signedPlayerInfo);
} catch (error) {
}
unlinkGameCenter
Unlink Apple Game Center authentication from a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be unlinked. |
playerId string REQUIRED | | Player ID provided by Game Center. |
bundleId string REQUIRED | | Bundle ID of your app on iTunesConnect. |
timestamp int REQUIRED | | Timestamp at which Game Center authenticated the client and issued a signature. |
salt string REQUIRED | | A random string returned by Game Center authentication on client. |
signature string REQUIRED | | A signature returned by Game Center authentication on client. |
publicKeyUrl string REQUIRED | | A URL to the public key returned by Game Center authentication on client. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let playerId = '<PlayerId>';
let bundleId = '<BundleId>';
let timestamp = 0;
let salt = "<Salt>";
let signature = "<Signature>";
let publicKeyUrl = "<PublicKeyUrl>";
try {
lg.unlinkGameCenter(userId, playerId, bundleId, timestamp, salt, signature, publicKeyUrl);
} catch (error) {
}
unlinkGoogle
Unlink Google authentication from a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be unlinked. |
token string | | Google OAuth access token. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let token = '<Token>';
try {
lg.unlinkGoogle(userId, token);
} catch (error) {
}
unlinkSteam
Unlink Steam authentication from a user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be unlinked. |
token string | | Steam access token. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '<UserId>';
let token = '<Token>';
try {
lg.unlinkSteam(userId, token);
} catch (error) {
}
Chat
channelIdBuild
Create a channel identifier to be used in other runtime calls. Does not create a channel.
Name | Default | Description |
---|
senderId string REQUIRED | | UserID of the message sender (when applicable). Defaults to the system user if void. |
target string REQUIRED | | Can be the room name, group identifier, or another username. |
chanType lgruntime.ChannelType REQUIRED | | The type of channel, either Room (1), Direct (2), or Group (3). |
Name | | Description |
---|
channelId string | | The generated ID representing a channel. |
error error | | An optional error value if an error occurred. |
let result: string;
try {
result = lg.channelIdBuild('<SenderId>', '<RoomName>', lgruntime.ChannelType.Room);
} catch (error) {
}
channelMessageRemove
Remove a message on a realtime chat channel.
Name | Default | Description |
---|
channelId string REQUIRED | | The ID of the channel to send the message on. |
messageId string REQUIRED | | The ID of the message to remove. |
senderId string REQUIRED | | The UUID for the sender of this message. If left empty, it will be assumed that it is a system message. |
senderUsername string REQUIRED | | The username of the user to send this message as. If left empty, it will be assumed that it is a system message. |
persist bool | true | Whether to record this message in the channel history. |
Name | | Description |
---|
channelMessageRemove lgruntime.ChannelMessageAck | | Message removed ack containing the following variables: 'channelId', 'messageId', 'code', 'username', 'createTime', 'updateTime', and 'persistent'. |
error error | | An optional error value if an error occurred. |
let result: lgruntime.ChannelMessageAck;
let channelId = '<ChannelId>';
let messageId = '<MessageId>';
let senderId = '<SenderId>';
let senderUsername = 'Someone';
let persist = true;
try {
result = lg.channelMessageRemove(channelId, messageId, senderId, senderUsername, persist);
} catch (error) {
}
channelMessageSend
Send a message on a realtime chat channel.
Name | Default | Description |
---|
channelId string REQUIRED | | The ID of the channel to send the message on. |
content object REQUIRED | | Message content. |
senderId string REQUIRED | | The UUID for the sender of this message. If left empty, it will be assumed that it is a system message. |
senderUsername string REQUIRED | | The username of the user to send this message as. If left empty, it will be assumed that it is a system message. |
persist bool | true | Whether to record this message in the channel history. |
Name | | Description |
---|
channelMessageSend lgruntime.ChannelMessageAck | | Message sent ack containing the following variables: 'channelId', 'messageId', 'code', 'username', 'createTime', 'updateTime', and 'persistent'. |
error error | | An optional error value if an error occurred. |
let result: lgruntime.ChannelMessageSendAck;
let channelId = '<ChannelId>';
let content = { message: 'Hello world' };
let senderId = '<SenderId>';
let senderUsername = 'Someone';
let persist = true;
try {
result = lg.channelMessageSend(channelId, content, senderId, senderUsername, persist);
} catch (error) {
}
channelMessagesList
List messages from a realtime chat channel.
Name | Default | Description |
---|
channelId string REQUIRED | | The ID of the channel to list messages from. |
limit number | 100 | The number of messages to return per page. |
forward bool | true | Whether to list messages from oldest to newest, or newest to oldest. |
cursor string | | Pagination cursor from previous result. Don't set to start fetching from the beginning. |
Name | | Description |
---|
channelMessagesList lgruntime.ChannelMessageList | | Messages from the specified channel and possibly a cursor. If cursor is empty/null there are no further results. |
error error | | An optional error value if an error occurred. |
let messages = {} as lgruntime.ChannelMessageList;
try {
let channelId = "<channelId>";
messages = lg.channelMessagesList(channelId);
} catch (error) {
}
channelMessageUpdate
Update a message on a realtime chat channel.
Name | Default | Description |
---|
channelId string REQUIRED | | The ID of the channel to send the message on. |
messageId string REQUIRED | | The ID of the message to update. |
content object REQUIRED | | Message content. |
senderId string REQUIRED | | The UUID for the sender of this message. If left empty, it will be assumed that it is a system message. |
senderUsername string REQUIRED | | The username of the user to send this message as. If left empty, it will be assumed that it is a system message. |
persist bool | true | Whether to record this message in the channel history. |
Name | | Description |
---|
channelMessageUpdate lgruntime.ChannelMessageAck | | Message updated ack containing the following variables: 'channelId', 'messageId', 'code', 'username', 'createTime', 'updateTime', and 'persistent'. |
error error | | An optional error value if an error occurred. |
let channelId = '<ChannelId>';
let messageId = '<MessageId>';
let content = { message: 'Hello another world' };
let senderId = '<SenderId>';
let senderUsername = 'Someone';
let persist = true;
try {
result = lg.channelMessageUpdate(channelId, messageId, content, senderId, senderUsername, persist);
} catch (error) {
}
Events
event
Generate an event.
Name | Default | Description |
---|
event_name string REQUIRED | | The name of the event to be created. |
properties []string REQUIRED | | An array of event properties. |
ts int | | Timestamp for when event is created. |
external bool | false | Whether the event is external. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let eventName = '<EventName>';
let properties = [ 'properties' ];
let timestamp = 0;
let external = true;
try {
lg.event(eventName, properties, timestamp, external);
} catch (error) {
}
Friends
friendsAdd
Add friends to a user.
Name | Default | Description |
---|
userId string REQUIRED | | The ID of the user to whom you want to add friends. |
username string REQUIRED | | The name of the user to whom you want to add friends. |
ids []string REQUIRED | | Table array of IDs of the users you want to add as friends. |
usernames []string REQUIRED | | Table array of usernames of the users you want to add as friends. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = "b1aafe16-7540-11e7-9738-13777fcc7cd8";
let username = "username";
let userIds = ['9a51cf3a-2377-11eb-b713-e7d403afe081', 'a042c19c-2377-11eb-b7c1-cfafae11cfbc'];
let usernames = ["newfriend1", "newfriend2"];
try {
lg.friendsAdd(userId, username, userIds, usernames);
} catch (error) {
}
friendsBlock
Block friends for a user.
Name | Default | Description |
---|
userId string REQUIRED | | The ID of the user for whom you want to block friends. |
username string REQUIRED | | The name of the user for whom you want to block friends. |
ids []string REQUIRED | | Table array of IDs of the users you want to block as friends. |
usernames []string REQUIRED | | Table array of usernames of the users you want to block as friends. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = "b1aafe16-7540-11e7-9738-13777fcc7cd8";
let username = "username";
let userIds = ['9a51cf3a-2377-11eb-b713-e7d403afe081', 'a042c19c-2377-11eb-b7c1-cfafae11cfbc'];
let usernames = ["exfriend1", "exfriend2"];
try {
lg.friendsBlock(userId, username, userIds, usernames);
} catch (error) {
}
friendsDelete
Delete friends from a user.
Name | Default | Description |
---|
userId string REQUIRED | | The ID of the user from whom you want to delete friends. |
username string REQUIRED | | The name of the user from whom you want to delete friends. |
ids []string REQUIRED | | Table array of IDs of the users you want to delete as friends. |
usernames []string REQUIRED | | Table array of usernames of the users you want to delete as friends. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = "b1aafe16-7540-11e7-9738-13777fcc7cd8";
let username = "username";
let userIds = ['9a51cf3a-2377-11eb-b713-e7d403afe081', 'a042c19c-2377-11eb-b7c1-cfafae11cfbc'];
let usernames = ["exfriend1", "exfriend2"];
try {
lg.friendsDelete(userId, username, userIds, usernames);
} catch (error) {
}
friendsList
List all friends, invites, invited, and blocked which belong to a user.
Name | Default | Description |
---|
userId string REQUIRED | | The ID of the user whose friends, invites, invited, and blocked you want to list. |
limit number | 100 | The number of friends to retrieve in this page of results. No more than 100 limit allowed per result. |
state number | | The state of the friendship with the user. If unspecified this returns friends in all states for the user. |
cursor string | | Pagination cursor from previous result. Don't set to start fetching from the beginning. |
Name | | Description |
---|
friends lgruntime.FriendList | | The user information for users that are friends of the current user. |
cursor string | | An optional next page cursor that can be used to retrieve the next page of records (if any). Will be set to "" or null when fetching last available page. |
error error | | An optional error value if an error occurred. |
let friends = {} as lgruntime.FriendList;
try {
let userId = 'b1aafe16-7540-11e7-9738-13777fcc7cd8';
let limit = 100;
let state = 0;
friends = lg.friendsList(userId, limit, state);
} catch (error) {
}
friendsOfFriendsList
List all friends of friends of a user.
Name | Default | Description |
---|
userId string REQUIRED | | The ID of the user whose friends of friends you want to list. |
limit number | 10 | The number of friends to retrieve in this page of results. No more than 100 limit allowed per result. |
cursor string | | Pagination cursor from previous result. Don't set to start fetching from the beginning. |
Name | | Description |
---|
friends lgruntime.FriendsOfFriendsList | | The user information for users that are friends of friends of the current user. |
cursor string | | An optional next page cursor that can be used to retrieve the next page of records (if any). Will be set to "" or null when fetching last available page. |
error error | | An optional error value if an error occurred. |
let friends = {} as lgruntime.FriendList;
try {
let userId = "b1aafe16-7540-11e7-9738-13777fcc7cd8";
let limit = 100;
friends = lg.friendsOfFriendsList(userId, limit);
} catch (error) {
}
Groups
groupCreate
Setup a group with various configuration settings. The group will be created if they don't exist or fail if the group name is taken.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be associated as the group superadmin. |
name string REQUIRED | | Group name, must be unique. |
creatorId string | | The user ID to be associated as creator. If not set or nil/null, system user will be set. |
langTag string | | Group language. |
description string | | Group description, can be left empty as nil/null. |
avatarUrl string | | URL to the group avatar, can be left empty as nil/null. |
open bool | false | Whether the group is for anyone to join, or members will need to send invitations to join. |
metadata object | | Custom information to store for this group. Can be left empty as nil/null. |
maxCount number | 100 | Maximum number of members to have in the group. |
Name | | Description |
---|
createGroup lgruntime.Group | | The groupId of the newly created group. |
error error | | An optional error value if an error occurred. |
let userId = 'dcb891ea-a311-4681-9213-6741351c9994';
let creatorId = 'dcb891ea-a311-4681-9213-6741351c9994';
let name = 'Some unique group name';
let description = 'My awesome group.';
let lang = 'en';
let open = true;
let avatarURL = 'url://somelink';
let metadata = { custom_field: 'some_value' };
let maxCount = 100;
let group = {} as lgruntime.Group;
try {
group = lg.groupCreate(userId, name, creatorId, lang, description, avatarURL, open, metadata, maxCount);
} catch (error) {
}
groupDelete
Delete a group.
Name | Default | Description |
---|
groupId string REQUIRED | | The ID of the group to delete. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
try {
lg.groupDelete('f00fa79a-750f-11e7-8626-0fb79f45ff97');
} catch (error) {
}
groupsGetId
Fetch one or more groups by their ID.
Name | Default | Description |
---|
groupIds string[] REQUIRED | | An array of strings of the IDs for the groups to get. |
Name | | Description |
---|
getGroups lgruntime.Group[] | | An array of groups with their fields. |
error error | | An optional error value if an error occurred. |
let groups: lgruntime.Group[];
try {
let groupIds = ['dcb891ea-a311-4681-9213-6741351c9994'];
groups = lg.groupsGetId(groupIds);
} catch (error) {
}
groupsGetRandom
Fetch one or more groups randomly.
Name | Default | Description |
---|
count number REQUIRED | | The number of groups to fetch. |
Name | | Description |
---|
groups lgruntime.Group[] | | A list of group record objects. |
error error | | An optional error value if an error occurred. |
groupsList
Find groups based on the entered criteria.
Name | Default | Description |
---|
name string REQUIRED | | Search for groups that contain this value in their name. |
langTag string | | Filter based upon the entered language tag. |
members number | | Search by number of group members. |
open bool | | Filter based on whether groups are Open or Closed. |
limit number | 100 | Return only the required number of groups denoted by this limit value. |
cursor string | | Pagination cursor from previous result. Don't set to start fetching from the beginning. |
Name | | Description |
---|
groups lgruntime.GroupList | | A list of groups. |
cursor string | | An optional next page cursor that can be used to retrieve the next page of records (if any). Will be set to "" or null when fetching last available page. |
error error | | An optional error value if an error occurred. |
let groupName = "LayerG";
let langTag = "en";
let members = 10;
let open = true;
let limit = 100;
let results: lgruntime.GroupList = {};
try {
results = lg.groupsList(groupName, langTag, open, members, limit);
} catch (error) {
}
groupUpdate
Update a group with various configuration settings. The group which is updated can change some or all of its fields.
Name | Default | Description |
---|
groupId string REQUIRED | | The ID of the group to update. |
userId string REQUIRED | | User ID calling the update operation for permission checking. Set as nil to enact the changes as the system user. |
name string | | Group name, can be empty if not changed. |
creatorId string | | The user ID to be associated as creator. Can be empty if not changed. |
langTag string | | Group language. Empty if not updated. |
description string | | Group description, can be left empty if not updated. |
avatarUrl string | | URL to the group avatar, can be left empty if not updated. |
open bool | | Whether the group is for anyone to join or not. |
metadata object | | Custom information to store for this group. Use nil if field is not being updated. |
maxCount number | | Maximum number of members to have in the group. Use 0, nil/null if field is not being updated. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let metadata = { someField: 'some value' };
let groupId = 'f00fa79a-750f-11e7-8626-0fb79f45ff97';
let description = 'An updated description';
try {
lg.groupUpdate(groupId, null, null, null, null, description, null, true, metadata);
} catch (error) {
}
groupUserJoin
Join a group for a particular user.
Name | Default | Description |
---|
groupId string REQUIRED | | The ID of the group to join. |
userId string REQUIRED | | The user ID to add to this group. |
username string REQUIRED | | The username of the user to add to this group. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let groupId = 'dcb891ea-a311-4681-9213-6741351c9994';
let userId = '9a51cf3a-2377-11eb-b713-e7d403afe081';
let username = 'myusername';
try {
lg.groupUserJoin(groupId, userId, username);
} catch (error) {
}
groupUserLeave
Leave a group for a particular user.
Name | Default | Description |
---|
groupId string REQUIRED | | The ID of the group to leave. |
userId string REQUIRED | | The user ID to remove from this group. |
username string REQUIRED | | The username of the user to remove from this group. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let groupId = 'dcb891ea-a311-4681-9213-6741351c9994';
let userId = '9a51cf3a-2377-11eb-b713-e7d403afe081';
let username = 'myusername';
try {
lg.groupUserLeave(groupId, userId, username);
} catch (error) {
}
groupUsersAdd
Add users to a group.
Name | Default | Description |
---|
groupId string REQUIRED | | The ID of the group to add users to. |
userIds string[] REQUIRED | | Table array of user IDs to add to this group. |
callerId string | | User ID of the caller, will apply permissions checks of the user. If empty defaults to system user and permission checks are bypassed. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let groupId = 'dcb891ea-a311-4681-9213-6741351c9994';
let userIds = ['9a51cf3a-2377-11eb-b713-e7d403afe081', 'a042c19c-2377-11eb-b7c1-cfafae11cfbc'];
try {
lg.groupUsersAdd(groupId, userIds);
} catch (error) {
}
groupUsersBan
Ban users from a group.
Name | Default | Description |
---|
groupId REQUIRED | | The ID of the group to ban users from. |
userIds REQUIRED | | Table array of user IDs to ban from this group. |
callerId string | | User ID of the caller, will apply permissions checks of the user. If empty defaults to system user and permission checks are bypassed. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let groupId = 'dcb891ea-a311-4681-9213-6741351c9994';
let userIds = ['9a51cf3a-2377-11eb-b713-e7d403afe081', 'a042c19c-2377-11eb-b7c1-cfafae11cfbc'];
let callerId = '6ffededc-bfec-4ea1-a070-274a05825a47';
try {
lg.groupUsersBan(groupId, userIds, callerId);
} catch (error) {
}
groupUsersDemote
Demote users in a group.
Name | Default | Description |
---|
groupId string REQUIRED | | The ID of the group whose members are being demoted. |
userIds string[] REQUIRED | | Table array of user IDs to demote. |
callerId string | | User ID of the caller, will apply permissions checks of the user. If empty defaults to system user and permission checks are bypassed. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let groupId = 'dcb891ea-a311-4681-9213-6741351c9994';
let userIds = ['9a51cf3a-2377-11eb-b713-e7d403afe081', 'a042c19c-2377-11eb-b7c1-cfafae11cfbc'];
try {
lg.groupUsersDemote(groupId, userIds);
} catch (error) {
}
groupUsersKick
Kick users from a group.
Name | Default | Description |
---|
groupId string REQUIRED | | The ID of the group to kick users from. |
userIds string[] REQUIRED | | Table array of user IDs to kick. |
callerId string | | User ID of the caller, will apply permissions checks of the user. If empty defaults to system user and permission checks are bypassed. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let groupId = 'dcb891ea-a311-4681-9213-6741351c9994';
let userIds = ['9a51cf3a-2377-11eb-b713-e7d403afe081', 'a042c19c-2377-11eb-b7c1-cfafae11cfbc'];
try {
lg.groupUsersKick(groupId, userIds);
} catch (error) {
}
groupUsersList
List all members, admins and superadmins which belong to a group. This also list incoming join requests.
Name | Default | Description |
---|
groupId string REQUIRED | | The ID of the group to list members for. |
limit int | 100 | The maximum number of entries in the listing. |
state int | null | The state of the user within the group. If unspecified this returns users in all states. |
cursor string | | Pagination cursor from previous result. Don't set to start fetching from the beginning. |
Name | | Description |
---|
groupUsers lgruntime.GroupUserList | | The user information for members, admins and superadmins for the group. Also users who sent a join request. |
error error | | An optional error value if an error occurred. |
let groupId = 'dcb891ea-a311-4681-9213-6741351c9994';
let groupUsers = {} as lgruntime.GroupUserList;
try {
groupUsers = lg.groupUsersList(groupId);
} catch (error) {
}
Promote users in a group.
Name | Default | Description |
---|
groupId string REQUIRED | | The ID of the group whose members are being promoted. |
userIds string[] REQUIRED | | Table array of user IDs to promote. |
callerId string | | User ID of the caller, will apply permissions checks of the user. If empty defaults to system user and permission checks are bypassed. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let groupId = 'dcb891ea-a311-4681-9213-6741351c9994';
let userIds = ['9a51cf3a-2377-11eb-b713-e7d403afe081', 'a042c19c-2377-11eb-b7c1-cfafae11cfbc'];
try {
lg.groupUsersPromote(groupId, userIds);
} catch (error) {
}
userGroupsList
List all groups which a user belongs to and whether they've been accepted or if it's an invite.
Name | Default | Description |
---|
userId string REQUIRED | | The ID of the user to list groups for. |
Name | | Description |
---|
userGroups lgruntime.UserGroupList | | A table of groups with their fields. |
cursor string | | An optional next page cursor that can be used to retrieve the next page of records (if any). |
error error | | An optional error value if an error occurred. |
let userId = '64ef6cb0-7512-11e7-9e52-d7789d80b70b';
let groups: lgruntime.UserGroupList;
try {
groups = lg.userGroupsList(userId);
} catch (error) {
}
Leaderboards
leaderboardCreate
Setup a new dynamic leaderboard with the specified ID and various configuration settings. The leaderboard will be created if it doesn't already exist, otherwise its configuration will not be updated.
Name | Default | Description |
---|
leaderboardID string REQUIRED | | The unique identifier for the new leaderboard. This is used by clients to submit scores. |
authoritative bool | false | Mark the leaderboard as authoritative which ensures updates can only be made via the Go runtime. No client can submit a score directly. |
sortOrder string | | The sort order for records in the leaderboard. Possible values are "asc" or "desc". |
operator string | | The operator that determines how scores behave when submitted. Possible values are "best", "set", or "incr". |
resetSchedule string | | The cron format used to define the reset schedule for the leaderboard. This controls when a leaderboard is reset and can be used to power daily/weekly/monthly leaderboards. |
metadata object | | The metadata you want associated to the leaderboard. Some good examples are weather conditions for a racing game. |
enableRanks bool | false | Whether to enable rank values for the leaderboard. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let id = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
let authoritative = false;
let sort = lgruntime.SortOrder.DESCENDING;
let operator = lgruntime.Operator.BEST;
let reset = '0 0 * * 1';
let metadata = {
weatherConditions: 'rain',
};
let enableRanks = true
try {
lg.leaderboardCreate(id, authoritative, sort, operator, reset, metadata, enableRanks);
} catch(error) {
}
leaderboardDelete
Delete a leaderboard and all scores that belong to it.
Name | Default | Description |
---|
id string REQUIRED | | The unique identifier for the leaderboard to delete. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let id = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
try {
lg.leaderboardDelete(id);
} catch(error) {
}
leaderboardList
Find leaderboards which have been created on the server. Leaderboards can be filtered with categories.
Name | Default | Description |
---|
limit number | 10 | Return only the required number of leaderboards denoted by this limit value. |
cursor string | | Pagination cursor from previous result. Don't set to start fetching from the beginning. |
Name | | Description |
---|
leaderboardList lgruntime.LeaderboardList[] | | A list of leaderboard results and possibly a cursor. If cursor is empty/null there are no further results. |
error error | | An optional error value if an error occurred. |
let limit = 100;
let results: lgruntime.LeaderboardList = {};
try {
results = lg.leaderboardList(limit);
} catch (error) {
}
leaderboardRanksDisable
Disable a leaderboard rank cache freeing its allocated resources. If already disabled is a NOOP.
Name | Default | Description |
---|
id string REQUIRED | | The leaderboard id. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let id = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
try {
lg.leaderboardRanksDisable(id);
} catch(error) {
}
leaderboardRecordDelete
Remove an owner's record from a leaderboard, if one exists.
Name | Default | Description |
---|
id string REQUIRED | | The unique identifier for the leaderboard to delete from. |
owner string REQUIRED | | The owner of the score to delete. Mandatory field. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let id = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
let owner = '4c2ae592-b2a7-445e-98ec-697694478b1c';
try {
lg.leaderboardRecordDelete(id, owner);
} catch(error) {
}
leaderboardRecordsHaystack
Fetch the list of leaderboard records around the owner.
Name | Default | Description |
---|
id string REQUIRED | | The unique identifier for the leaderboard. |
owner string REQUIRED | | The owner of the score to list records around. Mandatory field. |
limit number REQUIRED | | Return only the required number of leaderboard records denoted by this limit value. |
cursor string | | Pagination cursor from previous result. Don't set to start fetching from the beginning. |
overrideExpiry number | 0 | Optionally retrieve records from previous resets by specifying the reset point in time in UTC seconds. Must be equal or greater than 0. |
Name | | Description |
---|
records lgruntime.LeaderboardRecordList | | The leaderboard records according to ID and possibly a cursor. If cursor is empty/null there are no further results. |
error error | | An optional error value if an error occurred. |
let id = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
let owner = '4c2ae592-b2a7-445e-98ec-697694478b1c';
let limit = 10;
let overrideExpiry = 3600;
let results: lgruntime.Leaderboard[] = [];
try {
results = lg.leaderboardRecordsHaystack(id, owner, limit, overrideExpiry);
} catch (error) {
}
leaderboardRecordsList
List records on the specified leaderboard, optionally filtering to only a subset of records by their owners. Records will be listed in the preconfigured leaderboard sort order.
Name | Default | Description |
---|
id string REQUIRED | | The unique identifier for the leaderboard to list. Mandatory field. |
owners string[] REQUIRED | | Array of owners to filter to. |
limit number REQUIRED | | The maximum number of records to return (Max 10,000). |
cursor string | | Pagination cursor from previous result. Don't set to start fetching from the beginning. |
overrideExpiry int | | Records with expiry in the past are not returned unless within this defined limit. Must be equal or greater than 0. |
Name | | Description |
---|
records lgruntime.LeaderboardRecord[] | | A page of leaderboard records. |
ownerRecords lgruntime.LeaderboardRecord[] | | A list of owner leaderboard records (empty if the owners input parameter is not set). |
nextCursor string | | An optional next page cursor that can be used to retrieve the next page of records (if any). Will be set to "" or null when fetching last available page. |
prevCursor string | | An optional previous page cursor that can be used to retrieve the previous page of records (if any). |
error error | | An optional error value if an error occurred. |
let result: lgruntime.LeaderboardRecordList;
let id = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
let ownerIds: string[] = [];
let limit = 100;
let cursor = '';
let overrideExpiry = 3600;
try {
result = lg.leaderboardRecordsList(id, ownerIds, limit, cursor, overrideExpiry);
} catch(error) {
}
leaderboardRecordsListCursorFromRank
Build a cursor to be used with leaderboardRecordsList to fetch records starting at a given rank. Only available if rank cache is not disabled for the leaderboard.
Name | Default | Description |
---|
leaderboardID string REQUIRED | | The unique identifier of the leaderboard. |
rank number REQUIRED | | The rank to start listing leaderboard records from. |
overrideExpiry number | | Records with expiry in the past are not returned unless within this defined limit. Must be equal or greater than 0. |
Name | | Description |
---|
leaderboardListCursor string | | A string cursor to be used with leaderboardRecordsList. |
error error | | An optional error value if an error occurred. |
let id = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
let rank = 1;
let overrideExpiry = 3600;
try {
result = lg.leaderboardRecordsListCursorFromRank(id, rank, overrideExpiry);
} catch(error) {
}
leaderboardRecordWrite
Use the preconfigured operator for the given leaderboard to submit a score for a particular user.
Name | Default | Description |
---|
id string REQUIRED | | The unique identifier for the leaderboard to submit to. |
owner string REQUIRED | | The owner of this score submission. |
username string | | The owner username of this score submission, if it's a user. |
score number | 0 | The score to submit. |
subscore number | 0 | A secondary subscore parameter for the submission. |
metadata object | | The metadata you want associated to this submission. Some good examples are weather conditions for a racing game. |
Name | | Description |
---|
record lgruntime.LeaderboardRecord | | The newly created leaderboard record. |
error error | | An optional error value if an error occurred. |
let id = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
let ownerID = '4c2ae592-b2a7-445e-98ec-697694478b1c';
let username = '02ebb2c8';
let score = 10;
let subscore = 0;
let metadata = {
weatherConditions: 'rain',
};
let result: lgruntime.LeaderboardRecord;
try {
result = lg.leaderboardRecordWrite(id, ownerID, username, score, subscore, metadata);
} catch(error) {
}
leaderboardsGetId
Fetch one or more leaderboards by ID.
Name | Default | Description |
---|
ids string[] REQUIRED | | The array of leaderboard ids. |
Name | | Description |
---|
leaderboards lgruntime.Leaderboard[] | | The leaderboard records according to ID. |
error error | | An optional error value if an error occurred. |
let leaderboardIds = [
'3ea5608a-43c3-11e7-90f9-7b9397165f34',
'447524be-43c3-11e7-af09-3f7172f05936',
]
let leaderboards: lgruntime.Leaderboard[];
try {
leaderboards = lg.leaderboardsGetId(leaderboardIds);
} catch (error) {
}
Matches
matchCreate
Create a new authoritative realtime multiplayer match running on the given runtime module name. The given params are passed to the match's init hook.
Name | Default | Description |
---|
module string REQUIRED | | The name of an available runtime module that will be responsible for the match. This was registered in InitModule. |
params | | Any value to pass to the match init hook. |
Name | | Description |
---|
matchId string | | The match ID of the newly created match. Clients can immediately use this ID to join the match. |
error error | | An optional error value if an error occurred. |
let module = 'some.folder.module';
let params = {
some: 'data',
}
let matchId: string;
try {
matchId = lg.matchCreate(module, params);
} catch(error) {
}
matchGet
Get information on a running match.
Name | Default | Description |
---|
id string REQUIRED | | The ID of the match to fetch. |
Name | | Description |
---|
match lgruntime.Match | | Information for the running match. |
error error | | An optional error value if an error occurred. |
let matchId = '52f02f3e-5b48-11eb-b182-0f5058adfcc6';
let match: lgruntime.Match;
try {
match = lg.matchGet(matchId);
} catch(error) {
}
matchList
List currently running realtime multiplayer matches and optionally filter them by authoritative mode, label, and current participant count.
Name | Default | Description |
---|
limit number | 1 | The maximum number of matches to list. |
authoritative bool | nil | Set true to only return authoritative matches, false to only return relayed matches and nil to return both. |
label string | | A label to filter authoritative matches by. Default "" meaning any label matches. |
minSize number | | Inclusive lower limit of current match participants. |
maxSize number | | Inclusive upper limit of current match participants. |
query string | | Additional query parameters to shortlist matches. |
Name | | Description |
---|
match lgruntime.Match[] | | A list of matches matching the parameters criteria. |
error error | | An optional error value if an error occurred. |
let limit = 10;
let isAuthoritative = false;
let label = '';
let minSize = 2;
let maxSize = 4;
let matches: lgruntime.Match[] = [];
try {
matches = lg.matchList(limit, isAuthoritative, label, minSize, maxSize);
} catch(error) {
}
matchSignal
Allow the match handler to be sent a reservation signal to mark a user ID or session ID into the match state ahead of their join attempt and eventual join flow. Called when the match handler receives a runtime signal.
Name | Default | Description |
---|
id string REQUIRED | | The user ID or session ID to send a reservation signal for. |
data string REQUIRED | | An arbitrary input supplied by the runtime caller of the signal. |
Name | | Description |
---|
data string | | Arbitrary data to return to the runtime caller of the signal. May be a string or nil. |
error error | | An optional error value if an error occurred. |
let matchId = '<MatchId>';
let data = '<Data>';
let result: string;
try {
result = lg.matchSignal(matchId, data);
} catch(error) {
}
Metrics
metricsCounterAdd
Add a custom metrics counter.
Name | Default | Description |
---|
name string REQUIRED | | The name of the custom metrics counter. |
tags map[string]string REQUIRED | | The metrics tags associated with this counter. |
delta number REQUIRED | | An integer value to update this metric with. |
let name = "metricName";
let tags = new Map<string, string>();
let delta = 100;
try {
lg.metricsCounterAdd(name, tags, delta);
} catch(error) {
}
metricsGaugeSet
Add a custom metrics gauge.
Name | Default | Description |
---|
name string REQUIRED | | The name of the custom metrics gauge. |
tags map[string]string REQUIRED | | The metrics tags associated with this gauge. |
value number REQUIRED | | A value to update this metric with. |
let name = "metricName";
let tags = new Map<string, string>();
let value = 3.14
try {
lg.metricsGaugeSet(name, tags, value);
} catch(error) {
}
metricsTimerRecord
Add a custom metrics timer.
Name | Default | Description |
---|
name string REQUIRED | | The name of the custom metrics timer. |
tags map[string]string REQUIRED | | The metrics tags associated with this timer. |
value number REQUIRED | | An integer value to update this metric with (in nanoseconds). |
let name = "metricName";
let tags = new Map<string, string>();
let value = 100000000000;
try {
lg.metricsTimerRecord(name, tags, value)
} catch(error) {
}
Notifications
notificationsDelete
Delete one or more in-app notifications.
Name | Default | Description |
---|
notifications any[] REQUIRED | | A list of notifications to be deleted. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = "b1aafe16-7540-11e7-9738-13777fcc7cd8";
let notificationId = "9a51cf3a-2377-11eb-b713-e7d403afe081";
let notifications = [userId = userId, notificationId = notificationId];
try {
lg.notificationsDelete(notifications);
} catch (error) {
}
notificationsDeleteId
Delete notifications by their id.
Name | Default | Description |
---|
ids string[] REQUIRED | | A list of notification ids. |
userID string REQUIRED | | Optional userID to scope deletions to that user only. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = "b1aafe16-7540-11e7-9738-13777fcc7cd8";
let notificationId = "9a51cf3a-2377-11eb-b713-e7d403afe081";
let notifications = [notificationId];
try {
lg.notificationsDeleteId(notifications, userId);
} catch (error) {
}
notificationSend
Send one in-app notification to a user.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID of the user to be sent the notification. |
subject string REQUIRED | | Notification subject. |
content object REQUIRED | | Notification content. Must be set but can be empty object. |
code number REQUIRED | | Notification code to use. Must be equal or greater than 0. |
sender string | | The sender of this notification. If left empty, it will be assumed that it is a system notification. |
persistent bool | false | Whether to record this in the database for later listing. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let receiverId = '4c2ae592-b2a7-445e-98ec-697694478b1c';
let subject = "You've unlocked level 100!";
let content = {
rewardCoins: 1000,
}
let code = 101;
let senderId = 'dcb891ea-a311-4681-9213-6741351c9994'
let persistent = true;
try {
lg.notificationSend(receiverId, subject, content, code, senderId, persistent);
} catch (error) {
}
notificationSendAll
Send an in-app notification to all users.
Name | Default | Description |
---|
subject string REQUIRED | | Notification subject. |
content object REQUIRED | | Notification content. Must be set but can be an empty object. |
code number REQUIRED | | Notification code to use. Must be greater than or equal to 0. |
persistent bool | false | Whether to record this in the database for later listing. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let subject = "You've unlocked level 100!";
let content = {
rewardCoins: 1000,
}
let code = 101;
let persistent = true;
try {
lg.notificationSendAll(subject, content, code, persistent);
} catch (error) {
}
notificationsGetId
Get notifications by their id.
Name | Default | Description |
---|
ids string[] REQUIRED | | A list of notification ids. |
userID string REQUIRED | | Optional userID to scope results to that user only. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = "b1aafe16-7540-11e7-9738-13777fcc7cd8";
let notificationId = "9a51cf3a-2377-11eb-b713-e7d403afe081";
let notifications = [notificationId];
try {
lg.notificationsGetId(notifications, userId);
} catch (error) {
}
notificationsList
List notifications by user id.
Name | Default | Description |
---|
userID string REQUIRED | | Optional userID to scope results to that user only. |
limit int REQUIRED | 100 | Limit number of results. Must be a value between 1 and 1000. |
cursor string | | Pagination cursor from previous result. Don't set to start fetching from the beginning. |
Name | | Description |
---|
notifications lgruntime.NotificationList | | A list of notifications. |
error error | | An optional error value if an error occurred. |
let notifications = {} as lgruntime.NotificationList;
let userId = "b1aafe16-7540-11e7-9738-13777fcc7cd8";
let limit = 20;
try{
notifications = lg.notificationsList(userId, limit);
} catch (error) {
}
notificationsSend
Send one or more in-app notifications to a user.
Name | Default | Description |
---|
notifications any[] REQUIRED | | A list of notifications to be sent together. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let notifications: lgruntime.NotificationRequest[] = [
{
userId: '4c2ae592-b2a7-445e-98ec-697694478b1c',
subject: "You've unlocked level 100!",
content: { rewardCoins: 1000 },
code: 101,
persistent: true,
},
{
userId: '69769447-b2a7-445e-98ec-8b1c4c2ae592',
subject: "You've unlocked level 100!",
content: { rewardCoins: 1000 },
code: 101,
persistent: true,
},
];
try {
lg.notificationsSend(notifications);
} catch (error) {
}
Purchases
purchaseGetByTransactionId
Look up a purchase receipt by transaction ID.
Name | Default | Description |
---|
transactionId string REQUIRED | | Transaction ID of the purchase to look up. |
Name | | Description |
---|
purchase lgruntime.ValidatedPurchaseAroundOwner | | A validated purchase. |
error error | | An optional error value if an error occurred. |
let transactionId = '809346e9-3d71-4aa8-9938-0ea566a0ed11';
let result: lgruntime.ValidatedPurchaseOwner;
try {
result = lg.purchaseGetByTransactionId(transactionId);
} catch(error) {
}
purchasesList
List stored validated purchase receipts.
Name | Default | Description |
---|
userId string | | Filter by user ID. Can be an empty string to list purchases for all users. |
limit number | 100 | Limit number of records retrieved. |
cursor string | | Pagination cursor from previous result. Don't set to start fetching from the beginning. |
Name | | Description |
---|
listPurchases lgruntime.ValidatedPurchaseList | | A page of stored validated purchases and possibly a cursor. If cursor is empty/null there are no further results. |
error error | | An optional error value if an error occurred. |
let userId = '4c2ae592-b2a7-445e-98ec-697694478b1c';
let validation: lgruntime.ValidatedPurchaseList;
try {
validation = lg.purchasesList(userId);
} catch(error) {
}
purchaseValidateApple
Validates and stores the purchases present in an Apple App Store Receipt.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID of the owner of the receipt. |
receipt string REQUIRED | | Base-64 encoded receipt data returned by the purchase operation itself. |
persist bool | true | Persist the purchase so that seenBefore can be computed to protect against replay attacks. |
passwordOverride string | | Override the iap.apple.shared_password provided in your configuration. |
Name | | Description |
---|
validation lgruntime.ValidatePurchaseResponse | | The resulting successfully validated purchases. Any previously validated purchases are returned with a seenBefore flag. |
error error | | An optional error value if an error occurred. |
let userId = '4c2ae592-b2a7-445e-98ec-697694478b1c';
let receipt = '<base64-receipt-data>';
let validation: lgruntime.ValidatePurchaseResponse;
try {
validation = lg.purchaseValidateApple(userId, receipt);
} catch(error) {
}
purchaseValidateFacebookInstant
Validates and stores a purchase receipt from Facebook Instant Games.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID of the owner of the receipt. |
signedRequest string REQUIRED | | The Facebook Instant signedRequest receipt data. |
persist bool | true | Persist the purchase so that seenBefore can be computed to protect against replay attacks. |
Name | | Description |
---|
validation lgruntime.ValidatePurchaseResponse | | The resulting successfully validated purchases. Any previously validated purchases are returned with a seenBefore flag. |
error error | | An optional error value if an error occurred. |
let userId = '4c2ae592-b2a7-445e-98ec-697694478b1c';
let signedRequest = '<signedRequest-data>';
try {
validation = lg.purchaseValidateFacebookInstant(userId, signedRequest);
} catch(error) {
}
purchaseValidateGoogle
Validates and stores a purchase receipt from the Google Play Store.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID of the owner of the receipt. |
receipt string REQUIRED | | JSON encoded Google receipt. |
persist bool | true | Persist the purchase so that seenBefore can be computed to protect against replay attacks. |
Name | | Description |
---|
validation lgruntime.ValidatePurchaseResponse | | The resulting successfully validated purchases. Any previously validated purchases are returned with a seenBefore flag. |
error error | | An optional error value if an error occurred. |
let userId = '4c2ae592-b2a7-445e-98ec-697694478b1c';
let receipt = '{\"json\":{\"orderId \":\"..\",\"packageName \":\"..\",\"productId \":\"..\",\"purchaseTime\":1607721533824,\"purchaseState\":0,\"purchaseToken\":\"..\",\"acknowledged\":false},\"signature \":\"..\",\"skuDetails \":{\"productId\":\"..\",\"type\":\"inapp\",\"price\":\"u20ac82.67\",\"price_amount_micros\":82672732,\"price_currency_code\":\"EUR\",\"title\":\"..\",\"description\":\"..\",\"skuDetailsToken\":\"..\"}}';
let validation: lgruntime.ValidatePurchaseResponse;
try {
validation = lg.purchaseValidateGoogle(userId, receipt);
} catch(error) {
}
purchaseValidateHuawei
Validates and stores a purchase receipt from the Huawei App Gallery.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID of the owner of the receipt. |
receipt string REQUIRED | | The Huawei receipt data. |
signature string REQUIRED | | The receipt signature. |
persist bool | true | Persist the purchase so that seenBefore can be computed to protect against replay attacks. |
Name | | Description |
---|
validation lgruntime.ValidatePurchaseResponse | | The resulting successfully validated purchases. Any previously validated purchases are returned with a seenBefore flag. |
error error | | An optional error value if an error occurred. |
let userId = '4c2ae592-b2a7-445e-98ec-697694478b1c';
let receipt = '<receipt-data>';
let signature = '<signature-data>';
let validation: lgruntime.ValidatePurchaseResponse;
try {
validation = lg.purchaseValidateHuawei(userId, receipt, signature);
} catch(error) {
}
Sessions
sessionDisconnect
Disconnect a session.
Name | Default | Description |
---|
sessionId string REQUIRED | | The ID of the session to be disconnected. |
reason lgruntime.PresenceReason REQUIRED | | The reason for the session disconnect. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
const sessionId = "81550806-a751-45c3-a667-574c916e06aa";
const reason = lgruntime.PresenceReason.PresenceReasonDisconnect;
lg.sessionDisconnect(sessionId, reason);
sessionLogout
Log out a user from their current session.
Name | Default | Description |
---|
userId string REQUIRED | | The ID of the user to be logged out. |
token string | | The current session authentication token. If the current auth and refresh tokens are not provided, all user sessions will be logged out. |
refreshToken string | | The current session refresh token. If the current auth and refresh tokens are not provided, all user sessions will be logged out. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
const userId = "1467c4f5-df88-43df-98c5-6bd09723aa70";
const token = "<Token>";
const refreshToken = "<RefreshToken>";
lg.sessionLogout(userId, token, refreshToken);
Storage
storageDelete
Remove one or more objects by their collection/keyname and optional user.
Name | Default | Description |
---|
objectIds lgruntime.StorageDeleteRequest[] REQUIRED | | An array of object identifiers to be deleted. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userId = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
let friendUserId = '8d98ee3f-8c9f-42c5-b6c9-c8f79ad1b820';
let objectIds: lgruntime.StorageDeleteRequest[] = [
{ collection: 'save', key: 'save1', userId },
{ collection: 'save', key: 'save2', userId },
{ collection: 'public', key: 'progress', userId: friendUserId },
];
try {
lg.storageDelete(objectIds);
} catch (error) {
}
storageIndexList
List storage index entries
Name | Default | Description |
---|
indexName string REQUIRED | | Name of the index to list entries from. |
queryString string REQUIRED | | Query to filter index entries. |
limit int REQUIRED | | Maximum number of results to be returned. |
order []string | | The storage object fields to sort the query results by. The prefix '-' before a field name indicates descending order. All specified fields must be indexed and sortable. |
callerId string | | User ID of the caller, will apply permissions checks of the user. If empty defaults to system user and permission checks are bypassed. |
Name | | Description |
---|
objects lgruntime.StorageIndexResult | | A list of storage objects. |
error error | | An optional error value if an error occurred. |
const name = "index_name";
const query = "+field1:1 field2:foo";
const limit = 10;
try {
let objects = lg.storageIndexList(name, query, limit);
} (catch err) {
}
storageList
List records in a collection and page through results. The records returned can be filtered to those owned by the user or "" for public records.
Name | Default | Description |
---|
userId string REQUIRED | | User ID to list records for or "" (empty string) for public records. |
collection string REQUIRED | | Collection to list data from. |
limit number | 100 | Limit number of records retrieved. |
cursor string | | Pagination cursor from previous result. Don't set to start fetching from the beginning. |
Name | | Description |
---|
objects lgruntime.StorageObjectList | | A list of storage objects. |
cursor string | | Pagination cursor. Will be set to "" or null when fetching last available page. |
error error | | An optional error value if an error occurred. |
let user_id = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
let result: lgruntime.StorageObjectList = {};
try {
let result = lg.storageList(user_id, 'collection', 10);
} catch (error) {
}
storageRead
Fetch one or more records by their bucket/collection/keyname and optional user.
Name | Default | Description |
---|
objectIds lgruntime.StorageReadRequest[] REQUIRED | | An array of object identifiers to be fetched. |
Name | | Description |
---|
objects lgruntime.StorageObject[] | | A list of storage records matching the parameters criteria. |
error error | | An optional error value if an error occurred. |
let userId = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
let objectIds: lgruntime.StorageReadRequest[] = [
{ collection: 'save', key: 'save1', userId: userId },
{ collection: 'save', key: 'save2', userId },
{ collection: 'save', key: 'save3', userId },
];
let results: lgruntime.StorageObject[] = [];
try {
results = lg.storageRead(objectIds);
} catch (error) {
}
storageWrite
Write one or more objects by their collection/keyname and optional user.
Name | Default | Description |
---|
objectIds lgruntime.StorageWriteRequest[] REQUIRED | | An array of object identifiers to be written. |
Name | | Description |
---|
acks lgruntime.StorageWriteAck[] | | A list of acks with the version of the written objects. |
error error | | An optional error value if an error occurred. |
let userId = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
let newObjects: lgruntime.StorageWriteRequest[] = [
{ collection: 'save', key: 'save1', userId, value: {} },
{ collection: 'save', key: 'save2', userId, value: {} },
{ collection: 'save', key: 'save3', userId, value: {}, permissionRead: 2, permissionWrite: 1 },
{ collection: 'save', key: 'save3', userId, value: {}, version: '<some_version>', permissionRead: 1, permissionWrite: 1 }
];
try {
lg.storageWrite(newObjects);
} catch (error) {
}
const name = "index_name";
Streams
streamClose
Close a stream and remove all presences on it.
Name | Default | Description |
---|
stream lgruntime.Stream REQUIRED | | A stream object. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
try {
let stream: lgruntime.Stream;
lg.streamClose(stream);
} catch (err) {
}
streamCount
Get a count of stream presences.
Name | Default | Description |
---|
stream lgruntime.Stream REQUIRED | | A stream object. |
Name | | Description |
---|
countByStream number | | Number of current stream presences. |
error error | | An optional error value if an error occurred. |
try {
let stream: lgruntime.Stream;
const count = lg.streamCount(stream);
} catch (err) {
}
streamSend
Send data to presences on a stream.
Name | Default | Description |
---|
stream lgruntime.Stream REQUIRED | | A stream object. |
data string REQUIRED | | The data to send. |
presences lgruntime.Presence[] | all | Array of presences to receive the sent data. |
reliable bool | true | Whether the sender has been validated prior. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
try {
let stream: lgruntime.Stream;
let presences: lgruntime.Presence[];
const data = "<Data>";
const reliable = true;
lg.streamSend(stream, data, presences, reliable);
} catch (err) {
}
streamSendRaw
Send a message to presences on a stream.
Name | Default | Description |
---|
stream lgruntime.Stream REQUIRED | | A stream object. |
msg REQUIRED | | The message to send. |
presences lgruntime.Presence[] | all | Array of presences to receive the sent data. |
reliable bool | true | Whether the sender has been validated prior. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
try {
let stream: lgruntime.Stream;
let presences: lgruntime.Presence[];
const envelope = {};
const reliable = true;
lg.streamSendRaw(stream, envelope, presences, reliable);
} catch (err) {
}
streamUserGet
Retrieve a stream presence and metadata by user ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to fetch information for. |
sessionId string REQUIRED | | The current session ID for the user. |
stream lgruntime.Stream REQUIRED | | A stream object. |
Name | | Description |
---|
meta lgruntime.Presence | | Presence for the user. |
error error | | An optional error value if an error occurred. |
try {
let stream: lgruntime.Stream;
const userId = "7d8252ef-8bc7-4d7d-a828-e99733046355";
const sessionId = "ef54eece-ddd1-4c62-b567-6d6c8c902c9c";
const presence = lg.streamUserGet(userId, sessionId, stream);
} catch (err) {
}
streamUserJoin
Add a user to a stream.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be added. |
sessionId string REQUIRED | | The current session ID for the user. |
stream lgruntime.Stream REQUIRED | | A stream object. |
hidden bool REQUIRED | | Whether the user will be marked as hidden. |
persistence bool REQUIRED | | Whether message data should be stored in the database. |
status string REQUIRED | | User status message. |
Name | | Description |
---|
success bool | | Whether the user was successfully added. |
error error | | An optional error value if an error occurred. |
try {
let stream: lgruntime.Stream;
const userId = "7d8252ef-8bc7-4d7d-a828-e99733046355";
const sessionId = "ef54eece-ddd1-4c62-b567-6d6c8c902c9c";
const hidden = false;
const persistence = true;
const status = "Some Status";
lg.streamUserJoin(userId, sessionId, stream, hidden, persistence, status);
} catch (err) {
}
streamUserKick
Kick a user from a stream.
Name | Default | Description |
---|
presence lgruntime.Presence REQUIRED | | The presence to be kicked. |
stream lgruntime.Stream REQUIRED | | A stream object. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
try {
let stream: lgruntime.Stream;
let presence: lgruntime.Presence;
lg.streamUserKick(presence, stream);
} catch (err) {
}
streamUserLeave
Remove a user from a stream.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be removed. |
sessionId string REQUIRED | | The current session ID for the user. |
stream lgruntime.Stream REQUIRED | | A stream object. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
try {
let stream: lgruntime.Stream;
const userId = "7d8252ef-8bc7-4d7d-a828-e99733046355";
const sessionId = "ef54eece-ddd1-4c62-b567-6d6c8c902c9c";
lg.streamUserLeave(userId, sessionId, stream);
} catch (err) {
}```
### streamUserList
List all users currently online and connected to a stream.
| Parameters |
| --- |
| Name | Default | Description |
| --- | --- | --- |
| stream lgruntime.Stream REQUIRED | | A stream object. |
| includeHidden bool | | Include stream presences marked as hidden in the results. |
| includeNotHidden bool | | Include stream presences not marked as hidden in the results. |
| Returns |
| --- |
| Name | | Description |
| --- | --- | --- |
| presences lgruntime.Presences\[\] | | Array of stream presences and their information. |
| error error | | An optional error value if an error occurred. |
```js showLineNumbers
try {
let stream: lgruntime.Stream;
const includeHidden = true;
const includeNotHidden = true;
const presences = lg.streamUserList(stream, includeHidden, includeNotHidden);
} catch (err) {
}
streamUserUpdate
Update a stream user by ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID to be updated. |
sessionId string REQUIRED | | The current session ID for the user. |
stream lgruntime.Stream REQUIRED | | A stream object. |
hidden bool REQUIRED | | Whether the user will be marked as hidden. |
persistence bool REQUIRED | | Whether message data should be stored in the database. |
status string REQUIRED | | User status message. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
try {
let stream: lgruntime.Stream;
const userId = "7d8252ef-8bc7-4d7d-a828-e99733046355";
const sessionId = "ef54eece-ddd1-4c62-b567-6d6c8c902c9c";
const hidden = true;
const persistence = true;
lg.streamUserUpdate(userId, sessionId, stream, hidden, persistence);
} catch (err) {
}
Subscriptions
subscriptionGetByProductId
Look up a subscription by product ID.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID of the subscription owner. |
subscriptionId string REQUIRED | | Transaction ID of the purchase to look up. |
Name | | Description |
---|
subscription lgruntime.ValidatedSubscription | | A validated subscription. |
error error | | An optional error value if an error occurred. |
let userId = '4c2ae592-b2a7-445e-98ec-697694478b1c';
let subscriptionId = 'subscriptionId';
let result: lgruntime.ValidatedSubscription;
try {
result = lg.subscriptionGetByProductId(userId, subscriptionId);
} catch(error) {
}
subscriptionsList
List stored validated subscriptions.
Name | Default | Description |
---|
userId string | | Filter by user ID. Can be an empty string to list subscriptions for all users. |
limit number | 100 | Limit number of records retrieved. |
cursor string | | Pagination cursor from previous result. Don't set to start fetching from the beginning. |
Name | | Description |
---|
listSubscriptions lgruntime.SubscriptionList | | A page of stored validated subscriptions and possibly a cursor. If cursor is empty/null there are no further results. |
error error | | An optional error value if an error occurred. |
let userId = '4c2ae592-b2a7-445e-98ec-697694478b1c';
let validation: lgruntime.ValidatedPurchaseList;
try {
validation = lg.subscriptionsList(userId);
} catch(error) {
}
subscriptionValidateApple
Validates and stores the subscription present in an Apple App Store Receipt.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID of the owner of the receipt. |
receipt string REQUIRED | | Base-64 encoded receipt data returned by the purchase operation itself. |
persist bool | true | Persist the purchase so that seenBefore can be computed to protect against replay attacks. |
passwordOverride string | | Override the iap.apple.shared_password provided in your configuration. |
Name | | Description |
---|
validation lgruntime.ValidateSubscriptionResponse | | The resulting successfully validated subscription. |
error error | | An optional error value if an error occurred. |
let userId = '4c2ae592-b2a7-445e-98ec-697694478b1c';
let receipt = '<base64-receipt-data>';
let validation: lgruntime.ValidateSubscriptionResponse;
try {
validation = lg.subscriptionValidateApple(userId, receipt);
} catch(error) {
}
subscriptionValidateGoogle
Validates and stores a subscription purchase receipt from the Google Play Store.
Name | Default | Description |
---|
userId string REQUIRED | | The user ID of the owner of the receipt. |
receipt string REQUIRED | | JSON encoded Google receipt. |
persist bool | true | Persist the subscription. |
Name | | Description |
---|
validation lgruntime.ValidateSubscriptionResponse | | The resulting successfully validated subscriptions. |
error error | | An optional error value if an error occurred. |
let userId = '4c2ae592-b2a7-445e-98ec-697694478b1c';
let receipt = '{\"json\":{\"orderId \":\"..\",\"packageName \":\"..\",\"productId \":\"..\",\"purchaseTime\":1607721533824,\"purchaseState\":0,\"purchaseToken\":\"..\",\"acknowledged\":false},\"signature \":\"..\",\"skuDetails \":{\"productId\":\"..\",\"type\":\"inapp\",\"price\":\"u20ac82.67\",\"price_amount_micros\":82672732,\"price_currency_code\":\"EUR\",\"title\":\"..\",\"description\":\"..\",\"skuDetailsToken\":\"..\"}}';
let validation: lgruntime.ValidatePurchaseResponse;
try {
validation = lg.subscriptionValidateGoogle(userId, receipt);
} catch(error) {
}
Tournaments
tournamentAddAttempt
Add additional score attempts to the owner's tournament record. This overrides the max number of score attempts allowed in the tournament for this specific owner.
Name | Default | Description |
---|
id string REQUIRED | | The unique identifier for the tournament to update. |
owner string REQUIRED | | The owner of the records to increment the count for. |
count number REQUIRED | | The number of attempt counts to increment. Can be negative to decrease count. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let id = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
let owner = 'leaderboard-record-owner';
let count = -10;
try {
lg.tournamentAddAttempt(id, owner, count);
} catch (error) {
}
tournamentCreate
Setup a new dynamic tournament with the specified ID and various configuration settings. The underlying leaderboard will be created if it doesn't already exist, otherwise its configuration will not be updated.
Name | Default | Description |
---|
id string REQUIRED | | The unique identifier for the new tournament. This is used by clients to submit scores. |
authoritative bool | true | Whether the tournament created is server authoritative. |
sortOrder string | | The sort order for records in the tournament. Possible values are "asc" or "desc". |
operator string | | The operator that determines how scores behave when submitted. The possible values are "best", "set", or "incr". |
resetSchedule string | | The cron format used to define the reset schedule for the tournament. This controls when the underlying leaderboard resets and the tournament is considered active again. |
metadata object | | The metadata you want associated to the tournament. Some good examples are weather conditions for a racing game. |
title string | | The title of the tournament. |
description string | | The description of the tournament. |
category number | | A category associated with the tournament. This can be used to filter different types of tournaments. Between 0 and 127. |
startTime number | | The start time of the tournament. Leave empty for immediately or a future time. |
endTime number | never | The end time of the tournament. When the end time is elapsed, the tournament will not reset and will cease to exist. Must be greater than startTime if set. |
duration number REQUIRED | | The active duration for a tournament. This is the duration when clients are able to submit new records. The duration starts from either the reset period or tournament start time whichever is sooner. A game client can query the tournament for results between end of duration and next reset period. |
maxSize number | | Maximum size of participants in a tournament. |
maxNumScore number | 1000000 | Maximum submission attempts for a tournament record. |
joinRequired bool | false | Whether the tournament needs to be joined before a record write is allowed. |
enableRanks bool | false | Whether to enable rank values for the tournament. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let id = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
let authoritative = false
let sortOrder = lgruntime.SortOrder.DESCENDING;
let operator = lgruntime.Operator.BEST;
let duration = 3600;
let resetSchedule = '0 12 * * *';
let metadata = {
weatherConditions: 'rain',
};
let title = 'Daily Dash';
let description = "Dash past your opponents for high scores and big rewards!";
let category = 1;
let startTime = 0;
let endTime = 0;
let maxSize = 10000;
let maxNumScore = 3;
let joinRequired = true;
let enableRanks = true;
try {
lg.tournamentCreate(id, authoritative, sortOrder, operator, duration, resetSchedule, metadata, title, description, category, startTime, endTime, maxSize, maxNumScore, joinRequired, enableRanks);
} catch (error) {
}
tournamentDelete
Delete a tournament and all records that belong to it.
Name | Default | Description |
---|
id string REQUIRED | | The unique identifier for the tournament to delete. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let id = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
try {
lg.tournamentDelete(id);
} catch (error) {
}
tournamentJoin
A tournament may need to be joined before the owner can submit scores. This operation is idempotent and will always succeed for the owner even if they have already joined the tournament.
Name | Default | Description |
---|
id string REQUIRED | | The unique identifier for the tournament to join. |
ownerId string REQUIRED | | The owner of the record. |
username string REQUIRED | | The username of the record owner. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let id = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
let owner = 'leaderboard-record-owner';
let username = 'myusername';
try {
lg.tournamentJoin(id, owner, username);
} catch (error) {
}
tournamentList
Find tournaments which have been created on the server. Tournaments can be filtered with categories and via start and end times.
Name | Default | Description |
---|
categoryStart number REQUIRED | | Filter tournament with categories greater or equal than this value. |
categoryEnd number REQUIRED | | Filter tournament with categories equal or less than this value. |
startTime number | | Filter tournament with that start after this time. |
endTime number | | Filter tournament with that end before this time. |
limit number | 10 | Return only the required number of tournament denoted by this limit value. |
cursor string | | Pagination cursor from previous result. Don't set to start fetching from the beginning. |
Name | | Description |
---|
tournamentList lgruntime.TournamentList[] | | A list of tournament results and possibly a cursor. If cursor is empty/null there are no further results. |
error error | | An optional error value if an error occurred. |
let categoryStart = 1;
let categoryEnd = 2;
let startTime = 1538147711;
let endTime = 0
let limit = 100
let results: lgruntime.TournamentList = {};
try {
results = lg.tournamentList(categoryStart, categoryEnd, startTime, endTime, limit);
} catch (error) {
}
tournamentRanksDisable
Disable a tournament rank cache freeing its allocated resources. If already disabled is a NOOP.
Name | Default | Description |
---|
id string REQUIRED | | The tournament id. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let id = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
try {
lg.tournamentRanksDisable(id);
} catch(error) {
}
tournamentRecordDelete
Remove an owner's record from a tournament, if one exists.
Name | Default | Description |
---|
id string REQUIRED | | The unique identifier for the tournament to delete from. |
owner string REQUIRED | | The owner of the score to delete. Mandatory field. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
tournamentRecordsHaystack
Fetch the list of tournament records around the owner.
Name | Default | Description |
---|
id string REQUIRED | | The ID of the tournament to list records for. |
ownerId string REQUIRED | | The owner ID around which to show records. |
limit number | 10 | Return only the required number of tournament records denoted by this limit value. Between 1-100. |
cursor string | | Pagination cursor from previous result. Don't set to start fetching from the beginning. |
expiry number | 0 | Time since epoch in seconds. Must be greater than 0. |
Name | | Description |
---|
tournamentRecordsHaystack lgruntime.LeaderboardRecord | | A list of tournament records and possibly a cursor. If cursor is empty/null there are no further results. |
error error | | An optional error value if an error occurred. |
let id = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
let owner = '4c2ae592-b2a7-445e-98ec-697694478b1c';
let results: lgruntime.Tournament[] = [];
try {
results = lg.tournamentRecordsHaystack(id, owner);
} catch (error) {
}
tournamentRecordsList
List records on the specified tournament, optionally filtering to only a subset of records by their owners. Records will be listed in the preconfigured tournament sort order.
Name | Default | Description |
---|
tournamentId string REQUIRED | | The ID of the tournament to list records for. |
ownerIds string[] | | Array of owner IDs to filter results by. Optional. |
cursor string | | Pagination cursor from previous result. Don't set to start fetching from the beginning. |
overrideExpiry number | 0 | Optionally retrieve records from previous resets by specifying the reset point in time in UTC seconds. Must be equal or greater than 0. |
Name | | Description |
---|
records lgruntime.LeaderboardRecord | | A page of tournament records. |
ownerRecords lgruntime.LeaderboardRecord | | A list of owner tournament records (empty if the owners input parameter is not set). |
prevCursor string | | An optional previous page cursor that can be used to retrieve the previous page of records (if any). |
nextCursor string | | An optional next page cursor that can be used to retrieve the next page of records (if any). Will be set to "" or null when fetching last available page. |
error error | | An optional error value if an error occurred. |
let tournamentId = '809346e9-3d71-4aa8-9938-0ea566a0ed11';
let tournamentOwners = ['385ad06e-95a5-4a1e-811a-d7ef242a3ea2', 'f8f55fd8-2ca8-46d1-9f39-82f72fe4e2c4'];
let limit = 10;
let cursor = null;
let overrideExpiry = null;
let result: lgruntime.TournamentRecordList;
try {
result = lg.tournamentRecordsList(tournamentId, tournamentOwners, limit, cursor, overrideExpiry);
} catch(error) {
}
tournamentRecordWrite
Submit a score and optional subscore to a tournament leaderboard. If the tournament has been configured with join required this will fail unless the owner has already joined the tournament.
Name | Default | Description |
---|
id string REQUIRED | | The unique identifier for the tournament leaderboard to submit to. |
owner string REQUIRED | | The owner of this score submission. Mandatory field. |
username string | | The owner username of this score submission, if it's a user. |
score number | 0 | The score to submit. |
subscore number | 0 | A secondary subscore parameter for the submission. |
metadata object REQUIRED | | The metadata you want associated to this submission. Some good examples are weather conditions for a racing game. |
Name | | Description |
---|
result lgruntime.LeaderboardRecord | | The newly created leaderboard record. |
error error | | An optional error value if an error occurred. |
let id = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
let owner = '4c2ae592-b2a7-445e-98ec-697694478b1c';
let username = '02ebb2c8';
let score = 10;
let subscore = 0;
let metadata = {
'weather_conditions' = 'rain',
};
try {
lg.tournamentRecordWrite(categoryStart, categoryEnd, startTime, endTime, limit);
} catch (error) {
}
tournamentsGetId
Fetch one or more tournaments by ID.
Name | Default | Description |
---|
ids string[] REQUIRED | | The table array of tournament ids. |
Name | | Description |
---|
result lgruntime.Tournament[] | | Array of tournament records. |
error error | | An optional error value if an error occurred. |
let tournamentIds = [
'3ea5608a-43c3-11e7-90f9-7b9397165f34',
'447524be-43c3-11e7-af09-3f7172f05936',
]
let owner = 'leaderboard-record-owner';
let username = 'myusername';
let tournaments: lgruntime.Tournament[];
try {
tournaments = lg.tournamentsGetId(id, owner, username);
} catch (error) {
}``
Users
multiUpdate
Update account, storage, and wallet information simultaneously.
Name | Default | Description |
---|
accountUpdates lgruntime.AccountUpdate[] REQUIRED | | Array of account information to be updated. |
storageWrites lgruntime.StorageWriteRequest[] REQUIRED | | Array of storage objects to be updated. |
storageDeletes lgruntime.StorageDeleteRequest[] REQUIRED | | Array of storage objects to be deleted. |
walletUpdates lgruntime.WalletUpdate[] REQUIRED | | Array of wallet updates to be made. |
updateLedger bool | false | Whether to record this wallet update in the ledger. |
Name | | Description |
---|
storageWriteAcks lgruntime.StorageWriteAck[] | | A list of acks with the version of the written objects. |
walletUpdateAcks lgruntime.WalletUpdateResult[] | | A list of wallet updates results. |
error error | | An optional error value if an error occurred. |
let accountUpdates: lgruntime.UserUpdateAccount[];
let storageWrites: lgruntime.StorageWriteRequest[];
let walletUpdates: lgruntime.WalletUpdate[];
let updateLedger = true;
try {
const result = lg.multiUpdate(accountUpdates, storageWrites, walletUpdates, updateLedger);
logger.info("Storage Acks: " + result.storageWriteAcks.length);
logger.info("Wallet Acks: " + result.walletUpdateAcks.length);
} catch (error) {
}
usersBanId
Ban one or more users by ID.
Name | Default | Description |
---|
userIds string[] REQUIRED | | An array of user IDs to ban. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userIds = [
'3ea5608a-43c3-11e7-90f9-7b9397165f34',
'447524be-43c3-11e7-af09-3f7172f05936',
];
try {
lg.usersBanId(userIds);
} catch (error) {
}
usersGetId
Fetch one or more users by ID.
Name | Default | Description |
---|
userIds []string REQUIRED | | An array of user IDs to fetch. |
Name | | Description |
---|
users lgruntime.User[] | | A list of user record objects. |
error error | | An optional error value if an error occurred. |
let userIds = [
'3ea5608a-43c3-11e7-90f9-7b9397165f34',
'447524be-43c3-11e7-af09-3f7172f05936',
];
let users: lgruntime.Users[];
try {
users = lg.usersGetId(userIds);
} catch (error) {
}
usersGetRandom
Fetch one or more users randomly.
Name | Default | Description |
---|
count number REQUIRED | | The number of users to fetch. |
Name | | Description |
---|
users lgruntime.User[] | | A list of user record objects. |
error error | | An optional error value if an error occurred. |
let users: lgruntime.Users[];
try {
users = lg.usersGetRandom(100);
} catch (error) {
}
usersGetUsername
Fetch one or more users by username.
Name | Default | Description |
---|
usernames []string REQUIRED | | An array of usernames to fetch. |
Name | | Description |
---|
users lgruntime.User[] | | A list of user record objects. |
error error | | An optional error value if an error occurred. |
let usernames = [
'b7865e7e',
'c048ba7a',
];
let users: lgruntime.Users[];
try {
users = lg.usersGetUsername(usernames);
} catch (error) {
}
usersUnbanId
Unban one or more users by ID.
Name | Default | Description |
---|
userIds string[] REQUIRED | | An array of user IDs to unban. |
Name | | Description |
---|
error error | | An optional error value if an error occurred. |
let userIds = [
'3ea5608a-43c3-11e7-90f9-7b9397165f34',
'447524be-43c3-11e7-af09-3f7172f05936',
];
try {
lg.usersUnbanId(userIds);
} catch (error) {
}
Utils
aes128Decrypt
Decrypt an aes128 encrypted string.
Name | Default | Description |
---|
input string REQUIRED | | The string to be decrypted. |
key string REQUIRED | | The 16 Byte decryption key. |
Name | | Description |
---|
clearText string | | The deciphered input. |
error error | | An optional error value if an error occurred. |
try {
let clearText = lg.aes128Decrypt('48656C6C6F20776F726C64', 'goldenbridge_key');
} catch (error) {
}
aes128Encrypt
aes128 encrypt a string input.
Name | Default | Description |
---|
input string REQUIRED | | The string which will be aes128 encrypted. |
key string REQUIRED | | The 16 Byte encryption key. |
Name | | Description |
---|
cipherText string | | The ciphered input. |
error error | | An optional error value if an error occurred. |
try {
let cipherText = lg.aes128Encrypt('Hello world', 'goldenbridge_key');
} catch (error) {
}
aes256Decrypt
Decrypt an aes256 encrypted string.
Name | Default | Description |
---|
input string REQUIRED | | The string to be decrypted. |
key string REQUIRED | | The 32 Byte decryption key. |
Name | | Description |
---|
clearText string | | The deciphered input. |
error error | | An optional error value if an error occurred. |
try {
let clearText = lg.aes256Decrypt('48656C6C6F20776F726C64', 'goldenbridge_key');
} catch (error) {
}
aes256Encrypt
aes256 encrypt a string input.
Name | Default | Description |
---|
input string REQUIRED | | The string which will be aes256 encrypted. |
key string REQUIRED | | The 32 Byte encryption key. |
Name | | Description |
---|
cipherText string | | The ciphered input. |
error error | | An optional error value if an error occurred. |
try {
let cipherText = lg.aes256Encrypt('Hello world', 'goldenbridge_key');
} catch (error) {
}
aesDecrypt
aes decrypt a base 64 encoded string input.
Name | Default | Description |
---|
keySize int REQUIRED | | The size in bytes of the decryption key. |
input string REQUIRED | | The string which will be decrypted. |
key string REQUIRED | | The encryption key. |
Name | | Description |
---|
clearText string | | The deciphered and decoded input. |
error error | | An optional error value if an error occurred. |
try {
let clearText = lg.aesDecrypt(16, '48656C6C6F20776F726C64', 'goldenbridge_key');
} catch (error) {
}
aesEncrypt
aes encrypt a string input and return the cipher text base64 encoded.
Name | Default | Description |
---|
keySize int REQUIRED | | The size in bytes of the encryption key. |
input string REQUIRED | | The string which will be encrypted. |
key string REQUIRED | | The encryption key. |
Name | | Description |
---|
cipherText string | | The ciphered and base64 encoded input. |
error error | | An optional error value if an error occurred. |
try {
let cipherText = lg.aesEncrypt(16, 'Hello world', 'goldenbridge_key');
} catch (error) {
}
base16Decode
Decode a base16 encoded string.
Name | Default | Description |
---|
input string REQUIRED | | The string to be decoded. |
Name | | Description |
---|
out ArrayBuffer | | Decoded data. |
error error | | An optional error value if an error occurred. |
let result: string;
try {
result = lg.base16Decode('48656C6C6F20776F726C64');
} catch (error) {
}
base16Encode
base16 encode a string or ArrayBuffer input.
Name | Default | Description |
---|
input string REQUIRED | | The string to be encoded. |
Name | | Description |
---|
out string | | Encoded string. |
error error | | An optional error value if an error occurred. |
let result: string;
try {
result = lg.base16Encode('Hello World');
} catch (error) {
}
base64Decode
Decode a base64 encoded string.
Name | Default | Description |
---|
input string REQUIRED | | The string which will be base64 decoded. |
padding bool | true | Pad the string if padding is missing. |
Name | | Description |
---|
out ArrayBuffer | | Decoded data. |
error error | | An optional error value if an error occurred. |
let result: string;
try {
result = lg.base64Decode('SGVsbG8gd29ybGQ=');
} catch (error) {
}
base64Encode
Base64 encode a string or ArrayBuffer input.
Name | Default | Description |
---|
input string REQUIRED | | The string which will be base64 encoded. |
Name | | Description |
---|
out string | | Encoded string. |
error error | | An optional error value if an error occurred. |
let result: string;
try {
result = lg.base64Encode('Hello World');
} catch (error) {
}
base64UrlDecode
Decode a base64 URL encoded string.
Name | Default | Description |
---|
input string REQUIRED | | The string to be decoded. |
Name | | Description |
---|
out ArrayBuffer | | Decoded data. |
error error | | An optional error value if an error occurred. |
let result: string;
try {
result = lg.base64UrlDecode('SGVsbG8gd29ybGQ=');
} catch (error) {
}
base64UrlEncode
Base64 URL encode a string or ArrayBuffer input.
Name | Default | Description |
---|
input string REQUIRED | | The string which will be base64 URL encoded. |
Name | | Description |
---|
out string | | Encoded string. |
error error | | An optional error value if an error occurred. |
let result: string;
try {
result = lg.base64UrlEncode('Hello World');
} catch (error) {
}```
### bcryptCompare
Compare hashed input against a plaintext input.
| Parameters |
| --- |
| Name | Default | Description |
| --- | --- | --- |
| input string REQUIRED | | The bcrypted input string. |
| plaintext string REQUIRED | | Plaintext input to compare against. |
| Returns |
| --- |
| Name | | Description |
| --- | --- | --- |
| result bool | | True if they are the same, false otherwise. |
| error error | | An optional error value if an error occurred. |
```js showLineNumbers
let result: boolean;
try {
result = lg.bcryptCompare('$2a$04$bl3tac7Gwbjy04Q8H2QWLuUOEkpoNiAeTxazxi4fVQQRMGbMaUHQ2', '123456');
} catch (error) {
}
bcryptHash
Generate one-way hashed string using bcrypt.
Name | Default | Description |
---|
input string REQUIRED | | The input string to bcrypt. |
Name | | Description |
---|
hash string | | Hashed string. |
error error | | An optional error value if an error occurred. |
let result: string;
try {
result = lg.bcryptHash('Hello World');
} catch (error) {
}
binaryToString
Convert binary data to string.
Name | Default | Description |
---|
data ArrayBuffer REQUIRED | | The binary data to be converted. |
Name | | Description |
---|
result string | | The resulting string. |
error error | | An optional error value if an error occurred. |
let result: string;
try {
result = lg.binaryToString('\x48\x65\x72\x6F\x69\x63\x4C\x61\x62\x73');
} catch (error) {
}
cronNext
Parses a CRON expression and a timestamp in UTC seconds, and returns the next matching timestamp in UTC seconds.
Name | Default | Description |
---|
expression string REQUIRED | | A valid CRON expression in standard format, for example "0 0 * * *" (meaning at midnight). |
timestamp number REQUIRED | | A time value expressed as UTC seconds. |
Name | | Description |
---|
next_ts number | | The next UTC seconds timestamp (number) that matches the given CRON expression, and is immediately after the given timestamp. |
error error | | An optional error value if an error occurred. |
let result: number;
try {
let expr = '0 0 * * 1';
let ts = Math.floor(Date.now() / 1000);
result = lg.cronNext(expr, ts);
} catch (error) {
}
cronPrev
Parses a CRON expression and a timestamp in UTC seconds, and returns the previous matching timestamp in UTC seconds.
Name | Default | Description |
---|
expression string REQUIRED | | A valid CRON expression in standard format, for example "0 0 * * *" (meaning at midnight). |
timestamp number REQUIRED | | A time value expressed as UTC seconds. |
Name | | Description |
---|
prev_ts number | | The previous UTC seconds timestamp (number) that matches the given CRON expression, and is immediately before the given timestamp. |
error error | | An optional error value if an error occurred. |
let result: number;
try {
let expr = '0 0 * * 1';
let ts = Math.floor(Date.now() / 1000);
result = lg.cronPrev(expr, ts);
} catch (error) {
}
fileRead
Read file from user device.
Name | Default | Description |
---|
relPath string REQUIRED | | Relative path to the file to be read. |
Name | | Description |
---|
fileRead string | | The read file contents. |
error error | | An optional error value if an error occurred. |
let result: string;
let relativePath = '<RelativePath>';
try {
result = lg.fileRead(relativePath);
} catch (error) {
}
hmacSHA256Hash
Create a HMAC-SHA256 hash from input and key.
Name | Default | Description |
---|
input string REQUIRED | | The input string to hash. |
key string REQUIRED | | The hashing key. |
Name | | Description |
---|
mac string | | Hashed input as a string using the key. |
error error | | An optional error value if an error occurred. |
let hash: string;
try {
hash = lg.hmacSha256Hash('some input text to hash', 'some_key');
} catch (error) {
}
httpRequest
Send an HTTP request that returns a data type containing the result of the HTTP response.
Name | Default | Description |
---|
url string REQUIRED | | The URL of the web resource to request. |
method string REQUIRED | | The HTTP method verb used with the request. |
headers string REQUIRED | | A table of headers used with the request. |
content string REQUIRED | | The bytes to send with the request. |
timeout number | 5000 | Timeout of the request in milliseconds. |
insecure bool | false | Set to true to skip request TLS validations. |
Name | | Description |
---|
returnVal lgruntime.httpResponse | | Code, Headers, and Body response values for the HTTP response. |
error error | | An optional error value if an error occurred. |
let method: lgruntime.RequestMethod = 'get';
let headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
};
let body = JSON.stringify({});
let res = {} as lgruntime.HttpResponse;
try {
res = lg.httpRequest('https://google.com', method, headers, body);
} catch (error) {
}
jwtGenerate
Generate a JSON Web Token.
Name | Default | Description |
---|
signingMethod string REQUIRED | | The signing method to be used, either HS256 or RS256. |
claims []string REQUIRED | | The JWT payload. |
Name | | Description |
---|
signedToken string | | The newly generated JWT. |
error error | | An optional error value if an error occurred. |
let result: string
let signingKey = 'goldenbridge_key';
let claims = { email: '[email protected]' }
try {
result = lg.jwtGenerate('HS256', signingKey, claims);
} catch (error) {
}
md5Hash
Create an md5 hash from the input.
Name | Default | Description |
---|
input string REQUIRED | | The input string to hash. |
Name | | Description |
---|
hash string | | A string with the md5 hash of the input. |
error error | | An optional error value if an error occurred. |
let input = 'somestring';
let hashed = lg.md5Hash(input);
rsaSHA256Hash
Create a RSA encrypted SHA256 hash from the input.
Name | Default | Description |
---|
input string REQUIRED | | The input string to hash. |
key string REQUIRED | | The RSA private key. |
Name | | Description |
---|
signature string | | A string with the RSA encrypted SHA256 hash of the input. |
error error | | An optional error value if an error occurred. |
const cipherText = lg.rsaSha256Hash("Hello world", "<RSAPrivateKey>")
sha256Hash
Create an SHA256 hash from the input.
Name | Default | Description |
---|
input string REQUIRED | | The input string to hash. |
Name | | Description |
---|
hash string | | A string with the SHA256 hash of the input. |
error error | | An optional error value if an error occurred. |
const cipherText = lg.sha256Hash("Hello world");
sqlExec
Execute an arbitrary SQL query and return the number of rows affected. Typically, an "INSERT", "DELETE", or "UPDATE" statement with no return columns.
Name | Default | Description |
---|
query string REQUIRED | | A SQL query to execute. |
parameters any[] REQUIRED | | Arbitrary parameters to pass to placeholders in the query. |
Name | | Description |
---|
rowsAffected number | | A list of matches matching the parameters criteria. |
error error | | An optional error value if an error occurred. |
let query = 'DELETE FROM leaderboard_record WHERE expires_at > 0 AND expires_at <= $1';
let parameters = [ Math.floor(Date.now() / 1000) ];
let result: lgruntime.SqlExecResult;
try {
result = lg.sqlExec(query, parameters);
} catch (error) {
}
sqlQuery
Execute an arbitrary SQL query that is expected to return row data. Typically a "SELECT" statement.
Name | Default | Description |
---|
query string REQUIRED | | A SQL query to execute. |
parameters any[] REQUIRED | | Arbitrary parameters to pass to placeholders in the query. |
Name | | Description |
---|
result lgruntime.SqlQueryResult | | An array of rows and the respective columns and values. |
error error | | An optional error value if an error occurred. |
let query = 'SELECT username, create_time FROM users ORDER BY create_time DESC LIMIT 100';
let parameters: any[] = [];
let rows: lgruntime.SqlQueryResult = [];
try {
rows = lg.sqlQuery(query, parameters);
} catch (error) {
}
stringToBinary
Convert string data to binary.
Name | Default | Description |
---|
str string REQUIRED | | The string to be converted. |
Name | | Description |
---|
result ArrayBuffer | | The resulting binary data. |
error error | | An optional error value if an error occurred. |
let result: Uint8Array
try {
result = lg.stringToBinary('LayerG');
} catch (error) {
}
uuidV4
Generate a version 4 UUID in the standard 36-character string representation.
Name | | Description |
---|
uuid string | | The newly generated version 4 UUID identifier string. |
error error | | An optional error value if an error occurred. |
Wallets
walletLedgerList
List all wallet updates for a particular user from oldest to newest.
Name | Default | Description |
---|
userId string REQUIRED | | The ID of the user to list wallet updates for. |
limit number | 100 | Limit number of results. |
cursor string | | Pagination cursor from previous result. Don't set to start fetching from the beginning. |
Name | | Description |
---|
runtimeItems lgruntime.WalletLedgerItem[] | | A JavaScript Object containing wallet entries with Id, UserId, CreateTime, UpdateTime, Changeset, Metadata parameters, and possibly a cursor. If cursor is empty/null there are no further results. |
error error | | An optional error value if an error occurred. |
let userId = '8f4d52c7-bf28-4fcf-8af2-1d4fcf685592';
let results: lgruntime.WalletLedgerList[];
try {
results = lg.walletLedgerList(userId);
} catch (error) {
}
walletLedgerUpdate
Update the metadata for a particular wallet update in a user's wallet ledger history. Useful when adding a note to a transaction for example.
Name | Default | Description |
---|
itemId string REQUIRED | | The ID of the wallet ledger item to update. |
metadata object REQUIRED | | The new metadata to set on the wallet ledger item. |
Name | | Description |
---|
updateWalletLedger lgruntime.WalletLedgerItem | | The updated wallet ledger item. |
error error | | An optional error value if an error occurred. |
let id = '2745ba53-4b43-4f83-ab8f-93e9b677f33a';
let metadata = {
gameResult: 'loss'
};
let result: lgruntime.WalletLedgerResult;
try {
result = lg.walletLedgerUpdate(id, metadata);
} catch (error) {
}
walletsUpdate
Update one or more user wallets with individual changesets. This function will also insert a new wallet ledger item into each user's wallet history that tracks their update.
Name | Default | Description |
---|
updates lgruntime.WalletUpdate[] REQUIRED | | The set of user wallet update operations to apply. |
updateLedger bool | false | Whether to record this update in the ledger. |
Name | | Description |
---|
updateWallets lgruntime.WalletUpdateResult[] | | A list of wallet update results. |
error error | | An optional error value if an error occurred. |
let updates: lgruntime.WalletUpdate[] = [
{
userId: '8f4d52c7-bf28-4fcf-8af2-1d4fcf685592',
changeset: {
coins: 10,
gems: -5,
},
metadata: {
gameResult: 'won',
}
}
];
let results: lgruntime.WalletUpdateResult[];
try {
results = lg.walletsUpdate(updates);
} catch (error) {
}
walletUpdate
Update a user's wallet with the given changeset.
Name | Default | Description |
---|
userId string REQUIRED | | The ID of the user whose wallet to update. |
changeset REQUIRED | | The set of wallet operations to apply. |
metadata object | | Additional metadata to tag the wallet update with. |
updateLedger bool | false | Whether to record this update in the ledger. |
Name | | Description |
---|
result lgruntime.WalletUpdateResult | | The changeset after the update and before to the update, respectively. |
error error | | An optional error value if an error occurred. |
let user_id = '8f4d52c7-bf28-4fcf-8af2-1d4fcf685592';
let changeset = {
coins: 10,
gems: -5,
};
let metadata = {
gameResult: 'won'
};
let result: lgruntime.WalletUpdateResult;
try {
result = lg.walletUpdate(user_id, changeset, metadata, true);
} catch (error) {
}```