KTplay Community Login

 


Certain KTplay features, such as posting content to community or LiveOps’ require player authenticated by a trusted user account system, and this section will describe authentication options can be used.

KTplay Account Login by Community Login Window

Game Account Login with Game's own User System

Update Account Profile

Control if player can edit their User profile information

Community Logout

Monitor Community Login Status Change

Get Current Login Status

Get Current Login Player Profile

Get Player Profile

KTplay Account Login by Community Login Window

Game can select to use KTplay Account System to authenticate player identify. Apart from player can login from the Profile Page of KTPlay Community Window, the game can use the method described here to initiate player login by showing a KTplay login user interface.

The KTAccountManager's showLoginView method will show the Community Login Window, and he login result will be returned by a callback method.

KTAccountManager.showLoginView(closeable,
  new KTLoginListener(){
                @Override
                public void onLoginResult(boolean isSuccess, KTUser user,
                        KTError error) {
                    if(isSuccess){
                        Toast.makeText(context, "login success", Toast.LENGTH_SHORT).show();
                    }else{
                        Toast.makeText(context, "login failed", Toast.LENGTH_SHORT).show();
                    }
                }
    });

[KTAccountManager showLoginView:NO success:^(KTUser * account) {
    //login success
} failure:^(NSError *error) {
   //login fail
}

static void showLoginViewCallback(bool isSuccess ,KTUserC * user,KTErrorC *error)
{
    if (isSuccess) {
        //login success
    } else {
       //login fail
    }
}

KTAccountManagerC::showLoginView(false, showLoginViewCallback);

KTAccountManager.ShowLoginView (true, (KTUser user, KTError error) => {
        if(error==null){
            //success
        }else{
            //fail
        }
});

Game Account Login with Game's own User System

If the game selects to use its own or 3rd party user system, then it can use the method described in this section to inform KTplay user system to trust its authentication, and also associated with a player identify from game to KTplay Community.
The method KTAccountManager loginWithGameUser will be used to inform KTplay account system that player is authenticated by the game’s or 3rd parties user system, with a unique player ID,. The login result will be get back from the callback.

Important Note:

  • The feature is only provided for game with their own user account system, and please contact support@ktplay.com to enable the feature access if needed.
  • The player identifies send from Game to KTplay must be unique in the game, otherwise, community content or operations will be confused. E.g.

    • if the game is partitioned by game server (region), and game’s originally player identify is only unique within the server partition, then there will be chance of duplicated identifies if a community serve for more than one server (region). In this case, suggest to construct a unique ID by composing region ID and originally player ID, etc.
  • Strongly suggest to login to KTplay Community (via LoginWithGameUser) right after the KTplay SDK is initialized. Since some KTplay features require player login, e.g. reward notification or player’s activities, if those features invoked without community login status, a KTplay Community login dialog will be displayed even it is using Game account login, and that will cause confusion to player
  • Once the game login using this method, suggest to change the player’s community Account profile to make it consistent to the game’s player information.

  • Once the game use loginWithGameUser method to login to Community, Community will hide its logon UI entry, so player will not able logout Community from User Interface. So when player logout from game user system, make sure it logout Community by calling the Community’s Logout method

//pass logged-in game user id to KTplay backend
KTAccountManager.loginWithGameUser("100010", new KTAccountManager.KTGameUserLoginListener() {

                    @Override
                    public void onLoginResult(boolean isSuccess, String gameUserId,
                            KTUser user, KTError error) {
                        if(isSuccess){
                            Toast.makeText(context, "Login Success", Toast.LENGTH_SHORT).show();

                        }else{
                            Toast.makeText(context, "Login Failed", Toast.LENGTH_SHORT).show();
                        }

                    }
                });

//pass logged-in game user id to KTplay backend
   [KTAccountManager loginWithGameUser:@"100010" success:^(KTUser *user) {
    //success 
   } failure:^(NSError *error) {
     // fail
   }];

static void loginWithGameUserCallback(bool isSuccess ,const char * gameUserid, KTUserC * user,KTErrorC *error)
{
    if (isSuccess) {
        // success, with user profile
    } else {
        // fail
    }
}

KTAccountManagerC::loginWithGameUser("100010", loginWithGameUserCallback);

KTAccountManager.LoginWithGameUser ("100010", (KTUser user, KTError error) => {
        if(error==null){
            //success
        }else{
            //fail
        }
});

Update Account Profile

When use Game Account Login with Game's own User System ,you need to sync up key profile information of player, as to make a consistent user experience. Information include:

  • Nickname: not unique, if null, will keep the existing value, i.e. no change.
  • Avatar: local image path, if null, will keep the existing value, i.e. no change.
  • Gender:
    • 0 - No change,
    • 1 - Male,
    • 2 - Female,
    • 3 - Confidential

KTAccountManager.updateProfile(nickname, avatarFilePath, gender, new KTAccountManager.OnUpdateProfileListener() {
                    @Override
                    public void onUpdateProfileResult(boolean isSuccess,
                                                    KTUser user, KTError error) {
                        if(isSuccess){
                            //success
                        }else{
                            //failed                        }
                    }
                });

 [KTAccountManager updateProfile:nickname avatarPath: avatarFilePath gender:gender complete:^(BOOL isSuccess, KTUser *user, NSError *error) {
                if (isSuccess) {
                   //success
                }else{
                   //failed
                }
            }];

//Callback
void Game::ktUpdateProfileCallback(bool isSuccess, KTUserC * user, KTErrorC *error)
{
    if(isSuccess)
    {
        //success
    }
    else
    {
        //failed
    }
}

//Update profile.
KTAccountManagerC::updateProfile(nickName, avatarFilePath, gender, ktUpdateProfileCallback);

KTAccountManager.UpdateProfile (nickName, avatarFilePath, gender, (bool isSuccess, KTUser user, KTError error) => {
                if(isSuccess){
                    //success
                }else{
                    //failed
                }
                });

Control if player can edit their User profile information

By default, KTplay Community allow player to edit their profile information such as nickname, avatar. However, if game has own user account system and want KTplay Community to use the same user profile information, then it can use KTAccountManage.setUserProfileLocks to keep Community’s user profile synchronized, in doing that, it is strongly recommended to also disable the ability (UI) of player to edit the user profile information, so that any change from one side will not overwrite others and that will cause confusion to player.

The following are user profile properties that can be controlled (or locked) for editing:

  • KT_USERPROFILE_PROPERTY_NICKNAME //player nickname in Community
  • KT_USERPROFILE_PROPERTY_AVATAR //player avatar in Community
  • KT_USERPROFILE_PROPERTY_GENDER //player gender in community

if more than one properties need to be locked for editing, then it can use | as separator for the usage。

e.g. KT_USERPROFILE_PROPERTY_NICKNAME | KT_USERPROFILE_PROPERTY_AVATAR

//Lock editability for nickname and avatar.
KTAccountManager.setUserProfileLocks(KT_USERPROFILE_PROPERTY_NICKNAME|KT_USERPROFILE_PROPERTY_AVATAR);

//Lock editability for nickname and avatar.
[KTAccountManager setUserProfileLocks:KT_USERPROFILE_PROPERTY_NICKNAME|KT_USERPROFILE_PROPERTY_AVATAR];

//Lock editability for nickname and avatar.
KTAccountManagerC::setUserProfileLocks(KT_USERPROFILE_PROPERTY_NICKNAMEC | KT_USERPROFILE_PROPERTY_AVATARC);

//Lock editability for nickname and avatar.
KTAccountManager.setUserProfileLocks(KTAccountManager.KT_USERPROFILE_PROPERTY_NICKNAME|KTAccountManager.KT_USERPROFILE_PROPERTY_AVATAR);

Community Logout

When game login using its own user system (or use 3 rd party user system), it is required to call the KTAccountManager's logout method to logout Community once the Player is logout from Game user system.

KTAccountManager.logout();

[KTAccountManager logout];

KTAccountManagerC::logout();

KTAccountManager.Logout();

Monitor Community Login Status Change

The callback inform game if KTplay community logon status change, so that game can make further action if needed. e.g. visual change to reflect status change

//create callback
OnLoginStatusChangedListener onloginstatuschangedListener=
new OnLoginStatusChangedListener(){

  public void onLoginStatusChanged(boolean isLoggedIn, KTUser user){

   Toast.makeText(context,user.toString(),Toast.LENGTH_SHORT).show();
   }

 }

  //setup callback 
KTAccountManager.setLoginStatusChangedListener(onloginstatuschangedListener);

KTLoginStatusChangedBlock block = ^(BOOL isLoggedIn, KTUser * account){
        if (isLoggedIn){
                           //login
                      }else{
                            //logout
                       }
}

//Create callback
void loginStatusChangedCallback(bool isLoggedIn, KTUserC * user)
{
    if(isLoggedIn) {
        //login
    } else {
         //logout
    }
}


KTAccountManagerC::setLoginStatusChangedCallback(loginStatusChangedCallback);

KTAccountManager.SetLoginStatusChangeDelegate ((bool isLoggedIn, KTUser user) => {
    if(isLoggedIn) {
        //login
    } else {
         //logout
    }
});

Get Current Login Status

The method gets the Community login status, so that game can make further action if needed, e.g. popup to ask player to login

  boolean isLoggedIn = KTAccountManager.isLoggedIn();
     if(isLoggedIn){
         //login 
     }else{
        //
  }

BOOL isLoggedIn  = [KTAccountManager isLoggedIn];
if(isLoggedIn){
    //logged-in
}else{
    //not logged-in
}

    bool isLoggedIn = KTAccountManagerC::isLoggedIn();
    if(isLoggedIn) {
        //logged-in
    } else {
        //not logged-in
    }

    bool isLoggedIn = KTAccountManager.IsLoggedIn();
    if(isLoggedIn){
     //logged-in
    }else{
     //not logged-in
    }

Get Current Login Player Profile

Call KTAccountManager's currentAccount method to get user profile of current logged-in community user.
.
User Profile contain information about user id, avatar, nickname, gender, etc. that are provided by player before.

KTUser curLoggedInUser = KTAccountManager.currentAccount();

KTUser *user = [KTAccountManager currentAccount];
//if user equal to nil ,is not yet logged-in

KTUserC *userC = KTAccountManagerC::currentAccount();

KTUser user = (KTUser)KTAccountManager.CurrentAccount();

Get Player Profile

Call KTAccountManager's userProfile method to get Community user profile of user id requested.

User Profile contain information about user id, avatar, nickname, gender, etc. that are provided by player before.

//Create callback
KTAccountManager.OnGetUserInfoListener onGetUserInfoListener=
new KTAccountManager.OnGetUserInfoListener(){

    @Override
    public void onGetUserInfoResult(boolean isSuccess ,String userId,
    KTUser user, KTError error) {
        if(isSuccess){
            Toast.makeText(context, context.getString(R.string.success),
            Toast.LENGTH_SHORT).show();
        }else{
            Toast.makeText(context, error.description,
            Toast.LENGTH_SHORT).show();
        }
    }
    }
//get user profile
KTAccountManager.userProfile("userId", onGetUserInfoListener);

[KTAccountManager userProfile:@"123456" success:^(KTUser *user) {
        //success 
        } failure:^(NSError *error) {
            //fail
    }];

static void userProfileCallback(bool isSuccess ,const char *userId ,KTUserC * user,KTErrorC *error)
{
    if (isSuccess) {
        //success
    } else {
       //fail
    }
}

KTAccountManagerC::userProfile("1234" ,userProfileCallback);

KTAccountManager.GetUserProfile ("1234", (KTUser user, KTError error) => {
    if(error==null){
        //success
    }else{
        //fail
    }
});
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.