Create a Player

Create players through the Server API

In this How-To we'll look at how to create a player account by using our Unreal Server SDK without involving the Game client.

This is useful when you want all traffic towards LootLocker to run from a secure server and not trust the game client under any circumstances.

In this How To, we will show you how to do this for a Steam user, but LootLocker supports the same flow for a variety of platforms.

Prerequisites

Server Start Up

Once your game server has started up, it needs to connect to LootLocker so that it can make subsequent requests and make full use of LootLocker's functionality.

To get started with this, follow our documentation on how to start and maintain a server session

Client Start Up

Once the client and the server have both started up you establish the client <-> server connection as you usually would. Make sure that the client can replicate information to the server through methods such as replicatable actors, remote procedure calls, or whichever method you prefer.

When the connection is open, it is time to perform platform authentication. For Steam, how to get the Steam Session Ticket and Steam ID is described in our Steam How-To. Though for this use case you should not make the call to LootLocker to create a Steam Session as we will do that from the Server.

Then, in our Game client, when the player has logged in to Steam, we send a request to our Server with the Steam ID of our logged in Steam user.

Note that you can also use a replicatable actor and store the Steam ID there to not need to call a function from the client.

Create LootLocker Player from the Server

Now, back in our server, when we receive the Steam ID from the Game client, we send a request to LootLocker with the Steam ID to create a Steam Account for this user.

void OnClientPlayerAuthenticated(const FString& SteamID) 
{
    ULootLockerServerForCpp::CreatePlayer(ELootLockerServerCreatePlayerPlatforms::Steam, SteamID, FLootLockerServerCreatePlayerResponseDelegate::CreateLambda([SteamID](const FLootLockerServerCreatePlayerResponse& Response)
	{
		if (!Response.Success)
		{
			UE_LOG(LogWorkingProject, Error, TEXT("Failed to create player for SteamID %s. Error: %s"), *SteamID, *Response.ErrorData.Message);
			// Handle error appropriately
			return;
		}
		
		UE_LOG(LogWorkingProject, Display, TEXT("Successfully created player for SteamID %s with LootLocker Player Ulid %s"), *SteamID, *Response.Player_ulid);
		
	}));
}

Conclusion

In this How-to we’ve created a Steam LootLocker Player without involving the Game API. A LootLocker user is needed for any continuous player interactions with LootLocker. Now that you have a LootLocker user, you can make requests on behalf of this user by utilizing our Server Impersonation feature, keeping the Game API out of your game client making your game more secure and customizable.

Last updated