1. Config, Callback Settings

To initialize PC SDK, start with filling in the values for the StovePCConfig and StovePCCallback structures, and calling the StovePC_Init function.

Refer to the code below to fill in each field values within the StovePCConfig structure.

StovePCConfig config{"live",
                    "YOUR_APP_KEY",
                    "YOUR_SECRET_KEY",
                    "YOUR_GAME_ID",
                    StovePCLogLevel::STOVE_PC_LOG_LEVEL_DEBUG,
                    ""};

Refer to the StovePCDefine.h file for details regarding the StovePCConfig structure.

Communication between the game and the PC SDK uses callback functions connected to the StovePCCallback structure. In the game code, you need to define the function pointer to connect to the callback pointer of the StovePCCallback structure below in advance. The pointer of the specified function should be connected.

struct StovePCCallback
{

    /// Callback for StovePCSDK errors
    void(*OnError)(const StovePCError error);

    /// Callback for completing PC SDK initialization
    void(*OnInitComplete)();

    /// Callback for completing GetToken process
    void(*OnToken)(const StovePCToken token);

    /// Callback for completing GetUser process
    void(*OnUser)(const StovePCUser user);

    /// Callback for completing GetOwnership process
    void(*OnOwnership)(int size, StovePCOwnership* ownership);
};

NULL initialization is required before using the StovePCCallback structure’s instance.

/* Create StovePCCallback structure instance*/
StovePCCallback callback;
/* Initialize all function pointers to NULL*/
memset(&callback, 0, sizeof(StovePCCallback));
/* Connect configured function pointers*/
callback.OnError = OnMyErrorCallback;
callback.OnInitComplete = OnMyInitCompleteCallback;
callback.OnToken = OnMyTokenCallback;
callback.OnUser = OnMyUserInfoCallback;
callback.OnOwnership = OnMyOwnershipCallback;

The OnErrorOnInitComplete and OnOwnership callback functions must work together. You can integrate the rest of the callback functions only when necessary. For example, suppose you only use the Ownership function. In that case, you can implement it as shown below.

/*When only the ownership feature is being used,
only the OnOwnership callback is essential
On top of the essential callbacks, OnError and OnInitcomplte.*/
callback.OnError = OnMyErrorCallback;
callback.OnInitComplete = OnMyInitCompleteCallback;
callback.OnOwnership = OnMyOwnershipCallback;

2. SDK Initialization

When you complete StovePCConfig and StovePCCallback structure initialization and callback function connection, call the StovePC_Init function to initialize PC SDK.

StovePCResult result = StovePC_Init(config, callback);
if (result == StovePCResult::STOVE_PC_NO_ERROR)
{
    /*StovePCSDK init success.
    Call StovePC_RunCallback at regular intervals using timers, etc.*/

}

After the StovePC_Init function checks only the config and callback validity, it immediately returns the type value of the StovePCResult enum.

In case of success, it returns a value of STOVE_PC_NO_ERROR. In case of failure, it returns the corresponding error code, and you need to quit the game. Check the StovePCResult enum in the StovePCDefine.h file for a complete list of error codes.

If the returned value is STOVE_PC_NO_ERROR, therefore, a 'success', regularly call the StovePC_RunCallback function.

StovePC_RunCallback function must be regularly called to normally call the connected callback.

The callback response speed slows down if the call cycle is long, so it is better to maintain an appropriate call cycle. The example code in this guide sets the call period to 0.5 seconds.

<aside> 💡 Please be sure to write your code to call the StovePC_RunCallback function and other callback functions that work with the PCSDK from the main thread.

</aside>