Skip to content

Instantly share code, notes, and snippets.

View TobiasBerg's full-sized avatar
🎮

Tobias Berg TobiasBerg

🎮
View GitHub Profile
@TobiasBerg
TobiasBerg / WriterPlayerStorage.sh
Created January 22, 2021 12:29
Bash Write Player Storage Example
curl -X POST 'https://api.lootlocker.io/game/v1/player/storage' \
-H 'Content-Type: application/json' \
-H 'x-session-token: your session token' \
-d '[{
"order": 1,
"key": "characterColor",
"value": "0,193,82"
}]'
public class LootLocker : MonoBehaviour
{
// Configuration
private string LootLockerAPIKey = ""; // Found in settings @ my.lootlocker.io
private string PlayerIdentifier = ""; // In this case, your 64-bit steam ID - Looks like this: 76561298123001763 (Use https://steamid.io/lookup to find it)
private string baseUrl = "https://api.lootlocker.io/game/v1/";
// State
private bool loginDone = false;
private bool loginStarted = false;
IEnumerator Login()
{
if (loginStarted)
{
loginDone = true;
loginFailed = true;
Debug.Log("Multiple calls to login detected. Rejected attempt.");
}
else
{
IEnumerator GetPlayerStorage()
{
Debug.Log("Getting player storage");
using (UnityWebRequest webRequest = UnityWebRequest.Get(LootLocker.baseUrl + "v1/player/storage"))
{
// Set the header to authenticate the request
webRequest.SetRequestHeader("x-session-token", this.sessionToken);
// Send request and wait for the response
IEnumerator UpdatePlayerStorage()
{
Debug.Log("Updating player color with player storage");
using (UnityWebRequest webRequest = UnityWebRequest.Post(LootLocker.baseUrl + "v1/player/storage", ""))
{
// Set the header to authenticate the request, using our session token
webRequest.SetRequestHeader("x-session-token", this.sessionToken);
// Set header to let the server know we are sending JSON