arrow_back
logo
search
SupportlaunchAPI
menulaunchSign In
close
OverviewConceptsAdmin PanelCloudAPICompliance
Overview
Get StartedAuthorizationMessagingJackpotsMultiplayerGame Client InterfaceErrors Handle
Get StartedAuthorizationGame SessionMessagingBettings and WinningsRandom Numbers GeneratorJackpotsMultiplayerTesting
Overview
Overview
Using the client libraryImplementing an integrationDeploying an integration
Replying to a gamePending Winnings
.NET CoreGoJavaNodeJsPHPPythonRuby
OverviewOverwriting jackpots
launchAPISupport
launchSign In

Messaging

Before you begin

Before you can send a messages from Client Game to Server Game function, you need to:

  1. Create a Game inside the Fireball Admin panel
  2. Deploy your first simple server game function
  3. Add Fireball SDK into the Unity project
  4. Initialize and Authorize Fireball

Messaging concept

Fireball uses an async method for delivering messages from client to server and backward. Any message requires having a Name that is unique for each type of message. Some names (such as authenticate, session etc.) are registered by Fireball and can't be used for custom messaging. Any message must be a child class from BaseMessage that contains a bunch of required fields that are automatically filled up from player's Fireball session on message creation.

Send Custom Message

  1. Create a custom Request class as BaseRequest class child:
public class SpinRequest : BaseRequest
{
    private const string NAME = "spin";

    public long Amount;

    public SpinRequest(long betAmount, FireballSession session, string customActionID = null)
            : base(NAME, session, customActionID)
    {
        Amount = betAmount;
    }
}
  1. Create a custom Response class as BaseResponse class child:
public class SpinResult : BaseResponse
{
    private const string NAME = "spin-result";

    public List<int> Symbols;
    public long WinAmount;
    public long Balance;
    public bool IsWon;

    public SpinResult()
    {
        Name = NAME;
    }
}
  1. Send a custom request with Fireball using fireball.SendRequest method, where you can specify custom request and response messages types:
var spinRequest = new SpinRequest(100, fireball.CurrentSession);
fireball.SendRequest<SpinRequest, SpinResult>(spinRequest, (response) =>
{
    // spin result response
    Debug.Log($"Is Won: {response.IsWon}");
    Debug.Log($"Win Amount: {response.Currency} {response.WinAmount}");
},
(error) =>
{
    // handle error
    Debug.LogError($"Error: {error.Reason}");
});

Messages timeout

For a different reason (message lost, internal server error etc.) but the response could not come. You can better handle this case by specifying message timeout (in seconds) and the number of retrying attempts for any request. By default, the message will send one time and wait for a response as long as it is needed.

var timeoutSec = 10.0f;
var retryAttempts = 3;
var spinRequest = new SpinRequest(100, fireball.CurrentSession);
fireball.SendRequest<SpinRequest, SpinResult>(spinRequest,
    (response) =>
    {
        // spin result response
        Debug.Log($"Is Won: {response.IsWon}");
        Debug.Log($"Win Amount: {response.Currency} {response.WinAmount}");
    },
    (error) =>
    {
        if (error.IsTimeout)
        {
            // handle timeout
            Debug.LogError($"Error: {error.Reason}");
        }
        else
        {
            // handle error
            Debug.LogError($"Error: {error.Reason}");
        }
    },
timeoutSec, retryAttempts);

More about errors handling you can find here

Next Steps

  • Jackpots
  • Sample Project
  • API Reference
Copyright © 2020-. All rights reserved.v1.0.8