Integration

You can handle GameSwift login in 2 ways: with launcher or without launcher. You can download GameSwift launcher here. As long as your game targets Windows or MacOS, we strongly recommend to use data passed from our launcher. By doing so, you won't need to implement any login screen for your game as launcher already handles user credentials ina secure way.If you are building for mobile, you will need to create a login screen and implement connection with GameSwift backend the other way.

No matter which approach you choose (C++ or Blueprints), be sure that AuthorizeAndReadUserInfoFromLauncher or LoginAndAuthorize is called at the application startup.This method wil succeed provided that:

  1. User has internet connection.

  2. User did not attempt to login simultaneously from multiple devices (applicable only for applications with Multiple Logins Blocker enabled).

  3. User launched the game via launcher instead of your game executable file (provided that you used with launcher flow).

Otherwise, you should retry calling this method or close the application as it may not be launched the intended way.

Authorizing the user and getting his info can be done by calling UGameSwiftAuthenticationManager::AuthorizeAndReadUserInfoFromLauncher.

void ASampleCharacter::ReadUserInfoFromLauncher()
{
	FGetUserInfoDelegate SuccessDelegate;
	SuccessDelegate.BindUFunction(this, "OnSuccess");
	FBaseSdkFailDelegate FailDelegate;
	FailDelegate.BindUFunction(this, "OnError");
	
	UGameSwiftAuthenticationManager::AuthorizeAndReadUserInfoFromLauncher(SuccessDelegate, FailDelegate);
}

void ASampleCharacter::OnSuccess(const FOAuthUserInfoResponse& Response)
{
	// success - you can read user nickname and other data from Response
}

void ASampleCharacter::OnError(const FBaseSdkFailResponse& Response)
{
	// fail - close the application or retry authorization
}

AuthorizeAndReadUserInfoFromLauncher node is responsible for authorizing the user, who accessed the game through GameSwift Launcher.

With this approach you need to create a custom login widget, which will enable user to input the login data and authorize.

Authorizing the user and getting his info can be done by calling UGameSwiftAuthenticationManager::LoginAndAuthorize.

void ASampleCharacter::LoginAndAuthorize()
{
	Fstring EmailOrNickname = "bob.smith@example.com";
	Fstring Password = "Password123";
	FGetUserInfoDelegate SuccessDelegate;
	SuccessDelegate.BindUFunction(this, "OnSuccess");
	FBaseSdkFailDelegate FailDelegate;
	FailDelegate.BindUFunction(this, "OnError");
	
	UGameSwiftAuthenticationManager::LoginAndAuthorize(EmailOrNickname, Password, 
	SuccessDelegate, FailDelegate);
}

void ASampleCharacter::OnSuccess(const FOAuthUserInfoResponse& Response)
{
	// success - you can read user nickname and other data from Response
}

void ASampleCharacter::OnError(const FBaseSdkFailResponse& Response)
{
	// fail - close the application or retry authorization
}

GetUserCredentials node in the sample below is your implementation of retrieving login data from your custom login widget. Then, you can pass retrieved data to LoginAndAuthorize node.

Multiple Logins Blocker is an optional, powerful feature of GameSwift Unreal SDK that ensures a user's account can only be logged in on one device at a time. This component's setup is done in Project Settings under Plugins > GameSwiftSdk.

If enabled, this component works in background of your game, sending periodic heartbeats to GameSwift server at time intervals specified by you. When server receives these heartbeats, it recognizes that the user is already logged in and will block any additional login attempts from this user for a configurable duration. If you want to configure the lock duration, feel free to contact us.

Last updated