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

Authorization

Before you begin

Before you can use it, 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

Initialization

Initialization needs to take all settings, prepare all Fireball modules and as result create FireballSession object:

  • for Web GL: it will take all settings from the game URL query params and convert it into FireballSession
  • for Unity Editor: you need to create and setup FireballSettings for initialize Fireball

Get a Fireball instance:

public IFireball fireball;

...

public void Start()
{
     fireball = Fireball.Game.Client.Fireball.Instance;
}

or just add Fireball.cs script on scene and get it reference.

Initialization for WebGL

fireball.Init((session) =>
{
    // success initialization
},
(error) =>
{
    // handle error
});

Initialization for Unity Editor with Custom settings

  1. Create a FireballSettings scriptable object - right-click inside the assets folder in Unity Editor and chose: Create > Fireball > New Settings
  2. Fill up all required fields:
  • GameMode
  • Environment
  • OperatorId
  • GameId
  • OperatorPlayerId
  • Token

NOTE: Some operators require additional parameters, for this purpose you can use Extra field to set up these parameters as key-value pairs.

  1. Initialize Fireball with newly created settings:
public FireballSettings CustomSettings;

...

fireball.Init(CustomSettings, (session) =>
{
    // success initialization
},
(error) =>
{
    // handle error
});

You can create a few different FireballSettings files to easily switch between different operators and players, or setup differently other settings during developing games into Unity Editor.

Authorize

Default authorization

AuthRequest request = new AuthRequest(session);
fireball.Authorize(request,
    (response) =>
    {
        // success authorization
        Debug.Log($"Balance: {response.Currency} {response.Balance}");
    },
    (error) =>
    {
        // handle error
        Debug.LogError($"Error: {error.Reason}");
    });

Custom authorization

If you need to pass some additional data into server game function and back to client on authorization, you can easily create your own custom authorize request (and response) based on Fireball AuthRequest and AuthResponse class.

  1. Create a custom authorize request class:
public class CustomAutorizeRequest : AuthRequest
{
    public int CustiomId;
    public string CustomField;

    public CustomAutorizeRequest(int id, string field, FireballSession session) : base(session)
    {
        CustiomId = id;
        CustomField = field;
    }
}
  1. (Optional) Also, you can create a custom authorize response class, if you want to receive some additional data from your server game function:
public class CustomAutorizeResponse : AuthResponse
{
    public int SomeIntField;
    public string SomeStringField;
    public Dictionary<string, string> AdditionalData;
}
  1. Send new custom authorize request
var request = new CustomAutorizeRequest(123, "test", fireball.CurrentSession);
fireball.Authorize<CustomAutorizeRequest, CustomAutorizeResponse>(request,
    (response) =>
    {
        // success authorization
        Debug.Log($"SomeIntField: {response.SomeIntField}");
        Debug.Log($"SomeStringField: {response.SomeStringField}");
    },
    (error) =>
    {
        // handle error
        Debug.LogError($"Error: {error.Reason}");
    });

Full Sample

Here is a complete code for the simplest way to initialize and authorize Fireball:

public IFireball fireball;
public FireballSettings CustomSettings;

...

public void Start()
{
    if (fireball == null)
    {
        fireball = Fireball.Game.Client.Fireball.Instance;
    }

    fireball.Init(

#if UNITY_EDITOR
        CustomSettings,
#endif

        (session) =>
        {
            // success initialization
            fireball.Authorize(new AuthRequest(session),
                (response) =>
                {
                    // success authorization
                    Debug.Log($"Balance: {response.Currency} {response.Balance}");
                },
                (error) =>
                {
                    // handle error
                    Debug.LogError($"Error: {error.Reason}");
                });
        },
        (error) =>
        {
            // handle error
            Debug.LogError($"Error: {error}");
        });
}

Demo Auth

For successful authorization process simulation, you can use Demo authorization. It will create a successful auth response no matter what data you enter. It can be used for players to try the game locally in demo mode without connection to the fireball server. NOTE: all other fireball features (like messaging, jackpots etc.) will not work, so all game server calculations must be passed locally on the game client

fireball.DemoAuthorize("EUR", 50000,
    (response) =>
    {
        // success demo authorization
        Debug.Log($"Balance: {response.Currency} {response.Balance}");
    });

Also, you can use the custom authorize request class (it will create and return a new instance of your class):

_fireball.DemoAuthorize<CustomAutorizeResponse>("EUR", 50000,
    (response) =>
    {
        // success demo authorization
        Debug.Log($"Balance: {response.Currency} {response.Balance}");
        Debug.Log($"SomeIntField: {response.SomeIntField}");
        Debug.Log($"SomeStringField: {response.SomeStringField}");
    });

Next Steps

  • Send Messages
  • Jackpots
  • Sample Project
Copyright © 2020-. All rights reserved.v1.0.8