Programming Quick Start
In this quick start guide, you will learn:
- How to make a basic configuration of
PgosSDK
in programming. - How to use some basic PGOS services in programming. (Fake Account and PlayerAuth)
We will introduce you in detail according to the following process:
- Retrieve the development configurations of your title from the portal.
- Programming in your game project.
- Create PGOS service and init PGOS config.
- Make a fake account log in with the Fake Account service.
- Login to PGOS to make PGOS authentication with the PlayerAuth service.
1. Retrieve the Development Configurations
Before doing this, please make sure you have a developer account and a title in PGOS Web Portal.
After that, you can log in to the protal to retrieve the necessary configurations for your title:
1.1 Enter PGOS Portal Console
1.2 Retrieve the Title ID and Title Region ID
1.3 Retrieve the Secret Key
Click the Setting link, switch to Secret Keys tab, and retrieve the Secret Key for the game client and game server.
2. Programming in Game Project
The following is the general process of programming with PGOS, and it is also the sequence of calling PGOS APIs:
For game client:
graph LR A(CreatePGOS) -->B[InitConfig] B --> C[LoginPGOS] C -.-> D[Call PGOS APIs in Game Client] D -.-> E(LogoutPGOS) E -.-> F(DestroyPGOS)For game server:
graph LR A(CreatePGOS) -->B[InitConfig] B -.-> C[Call PGOS APIs in Game Server] C -.-> D(DestroyPGOS)
2.1 Programming with C# API
The following uses the game client code as an example to demonstrate a quick start on how to use PGOS C# API programming:
2.1.1 Create and Init PGOS
Add the following codes to the appropriate location of your game project:
using Pgos;
void StartupPGOS()
{
// Init PGOS client or server SDK. // You must create PGOS service before using PGOS service.
PgosClientSDK.Get().CreatePGOS();
/* PgosServerSDK.Get().CreatePGOS(); */
var pgosClient = PgosClientSDK.Get().GetClientSDKAPI();
Dictionary<string, string> cfg = new Dictionary<string, string>();
cfg.Add("secret_key", "Your Client Secret Key");
cfg.Add("title_id", "Your Title ID");
pgosClient.InitConfig(cfg);
}
Call CreatePGOS()
function in the main thread before using any PGOS service.
Call DestroyPGOS()
function in the main thread during process shutdown if possible.
For more detail about PGOS config, you can refer to Configure the PgosSDK.
2.1.2 Make a Fake Account Log in
Add the following codes to the appropriate location of your game project, only works in game client:
using Pgos;
void LoginFakeAccount()
{
// Get business module from PGOS client SDK
var fas = PgosClientSDK.Get().GetFakeAccountAPI();
// Login for Fake Account System (Need only for PGOS client SDK) provide by PGOS
string myAccount = "SomeAccountString"; // It can be made to support getting from the input.
fas.Login(myAccount, (PgosResult ret, Pgos.Client.FasLoginInfo data) => {
Debug.Log("FAS AutoLogin ret: " + ret.err_code + ", msg: " + ret.msg);
if (ret.err_code == 0 && data != null)
{
accountOpenID = data.open_id;
accountToken = data.token;
}
});
}
2.1.3 Make PGOS Authentication
Add the following codes to the appropriate location of your game project, only works in game client:
using Pgos;
// After successful account login
void LoginPGOS()
{
// Login to PGOS
var playerAuthAPI = PgosClientSDK.Get().GetPlayerAuthAPI();
Pgos.Client.LoginPGOSParams loginParams = new Pgos.Client.LoginPGOSParams();
loginParams.account_provider = (Int32)AccountProvider.FAS;
loginParams.account_open_id = this.accountOpenID;
loginParams.account_token = this.accountToken;
loginParams.title_region_id = "region_id_to_login";
playerAuthAPI.LoginPGOS(loginParams, (PgosResult ret, Pgos.Client.AuthenticationInfo data) =>
{
if (ret.err_code == 0)
{
Debug.Log("LoginPGOS success: player id=" + data.player_id);
} else
{
Debug.Log("LoginPGOS failed: ret=" + ret.err_code + ", msg=" + ret.msg);
}
});
}
For more detail about PGOS PlayerAuth, you can refer to PlayerAuth.
Now that the programming work is complete, build and run your game:
- If everything is working fine, you can see the successful log.
- If something is wrong, check the msg to see what happened.
For more detail about Calling PGOS API, you can refer to Call PgosSDK API.
For more detail about PGOS config, you can refer to Configure the PgosSDK.
For more detail about PGOS FAS, you can refer to Using FAS.
For more detail about PGOS PlayerAuth, you can refer to PlayerAuth.