CloudLogin Documentation

Welcome

CloudLogin is a cloud service to quickly give your C# game/app authentication. No need to buy a domain, host a server or write/consume any APIs.

CloudLogin is free for hobby and starting projects. Its simple and easy to implement. Empower your app to be able to create user accounts, login user accounts, manage an in game store (with game currency), manage said currency and more.

Click Here For The How To Video pt 1

Click Here For The How To Video pt 2


Contents

From The Web

1) Creating Your App

2) Adding Store Items

3) Upgrading Subscription

From Unity

1) Importing Package

2) Connecting To Your CloudLogin Game Application

3) Signing Up

4) Signing In

5) Store Items

6) Credits

7) User Key Value Pairs (Custom Attributes)

8) Leaderboard

9) Model Anatomy


Creating Your App On The Web Dashboard

0) For Free starter accounts, you can create an account automatically by importing code then selecting Tools/CloudLogin/ Generate CloudLogin Account in the Unity Editor

1) From cloudlogin.dev, create your developer account And sign in

2) From your homepage, click the + Add Game button to create your first game

3) The key to connecting your app will be to note the GameID and the Token, these will be used to connect to your Unity game to allow your users to sign up, sign in, purchase store items, and more

4) To start, your game will be able to have 100 concurrent users (signed in in the last week). You will recieve a warning email if you are over your concurrent users limit. If this is the case, you will have to subscribe to a larger plan to continue use


Adding Store Items

using CloudLogin.dev, you can create store items, set them to a cost, award users credits, and let them buy the store items you set up. These are in-game store items and not real life transactions.

1) Navigate to your home page then click on your first games title in the left column of the Games Table.

2) Scroll to the bottom of the page to see the Store Items table.

3) Click the + Store Item button to create your new store item. Title and description can be accessed and displayed in the game.


Upgrading Your Subscription

CloudLogin is currently free! Enjoy for a limited time! If this changes an email will be sent out MONTHS before implementation

Importing Package

Download from GitHub and put in your Assets folder of your game


Connecting To Your CloudLogin Game Application

Before you can sign in, sign up, or take any other actions, you must connect your Unity game to your CloudLogin Game.

Place the CloudLoginInitializer in the first scene

This asset can also be built with a blank GameObject, by adding scripts: [CloudLogin, CloudLoginStoreItem, CloudLoginUser, CloudLoginUtilities]

Please place the following code in the Start() function on a MonoBehavior in your first scene.

Each CloudLogin request will contact the server and will provide you with a callback parameter

In addition to being able to access all CloudLogin functions, connecting your game also downloads your in game store


void Start () {
    var gameID = 'Your Game ID Here';
    var gameToken 'your Game Token Here';
    CloudLogin.SetUpGame(gameID, gameToken, GameSetUpCallback);
}



void GameSetUpCallback(string message, bool hasError) {
    if (hasError)
    {
        Debug.Error("Error connecting game: "+message);
    }
    else
    {
        Debug.Log("Game Connected Successfully")
        foreach (CloudLoginStoreItem storeItem in CloudLogin.GetStoreItems())
        {
            Debug.Log(storeItem.GetName() + ": " + storeItem.GetCost());
        }
    }
  }

Signing Up

Enable users to sign up in your Unity game with the following code. They will be saved on your CloudLogin Game.

Add a method on a MonoBehavior on your sign up scene. When you have collected your username and password

Username is mandatory, but you can also feed in the email parameter if you do not with to display a seperate display name


#Feed in your users email, username and password here
void SignUp (email, password, password_confirmation, username) {
  CloudLogin.SignUp(userEmail, "password", "password", username, SignedUp);
}

void SignedUp(string message, bool hasError) {
  if (hasError)
  {
      Debug.Error("Error signign up: "+message);
  }
  else
  {
      Debug.Log("Signed Up: " + CloudLoginUser.CurrentUser.GetName());
  }
}

Signing In

Signing In Follows the same protocal as signing up, just with different parateters. As always, there is a callback function to let you know your sign in has been successful or not.

Email and password (not username), will be used to sign in


#Feed in your users email and password here
void SignIn (email, password, SignedIn) {
  CloudLogin.SignIn(userEmail, "password", "password", username, SignedIn);
}

void SignedIn(string message, bool hasError) {
  if (hasError)
  {
      Debug.Error("Error signign up: "+message);
  }
  else
  {
      Debug.Log("Logged In: " + CloudLoginUser.CurrentUser.GetName());
      Debug.Log("Current Credits: " + CloudLoginUser.CurrentUser.GetCredits());
  }
}

Store Items

Store Items Library are downloaded upon SignIn() and SignUp(), The Items will be refreshed every time the user signs in or signs up again.

To access store items and attributes by calling


foreach (CloudLoginStoreItem storeItem in CloudLogin.GetStoreItems())
{
    Debug.Log(storeItem.GetName());  //FireBow
    Debug.Log(storeItem.GetCategory()); //BowAndArrows
    Debug.Log(storeItem.GetId()); //12
    Debug.Log(storeItem.GetDescription());  //A bow and arrow item that shoots fire arrows
    Debug.Log(storeItem.GetCost()); // 500 (credits)
}

To access purchased store items by your current logged in user call the following. Because these are downloaded on login, there is no callback for this! It is already available!

This will throw an error if you are not signed in already


List < CloudLoginStoreItem > items = CloudLoginUser.CurrentUser.GetPurchasedStoreItems();

To Purchase a store item simply call the code before

Because this function talks to the server, it will require a callback.

This function will refresh the CloudLoginUser.CurrentUser.purchasedStoreItems List with the new item


void PurchaseItem(store_item){
  Debug.Log(CloudLoginUser.CurrentUser.purchasedStoreItems.Count); // Prints 0
  CloudLoginUser.PurchaseStoreItem(CloudLogin.GetStoreItems().First, PurchasedItemCallback)
}

void PurchasedItemCallback(string message, bool hasError) {
  if (hasError)
  {
      Debug.Error("Error purchasing item: "+message);
  }
  else
  {
      Debug.Log("Purchased Item");
      Debug.Log(CloudLoginUser.CurrentUser.purchasedStoreItems.Count); // Prints 1
  }
}

Credits

Credits are a numeric attribute of each game user. It is a simple integer value.

You can add them manually and they are detracted automatically upon store item purchases

Below is a script to demonstrate the full lifecycle of credits on a signed in user.


void Start(){
    Debug.Log(CloudLoginUser.CurrentUser.credits;  // Prints 0
    Debug.Log(CloudLogin.GetStoreItems().First.cost) // Prints 25 (or whatever you set your first item to on the web dashboard)
    CloudLoginUser.CurrentUser.AddCredits(50, AddCreditsCallback);
}

void AddCreditsCallback(string message, bool hasError)
{
    if (hasError)
    {
        Debug.Error("Error adding credits: " + message);
    }
    else
    {
      Debug.Log(CloudLoginUser.CurrentUser.credits;  // Prints 50
      CloudLoginUser.PurchaseStoreItem(CloudLogin.GetStoreItems().First, PurchasedItemCallback)

    }

}

void PurchasedItemCallback(string message, bool hasError) {
  if (hasError)
  {
      Debug.Error("Error purchasing item: "+message);
  }
  else
  {
      Debug.Log("Purchased Item");
      Debug.Log("Current Credits: " + CloudLoginUser.CurrentUser.GetCredits());
  }
}


Key Value Pairs

Key Value pairs are a simple way to save any kind of data for a particular user.

Some examples might be {"world_2_unlocked":"true"}, {"player_color","red"}, {"favorite_food","Onion"}

These are downloaded to your system upon login, and synced when one is updated. You can access with CloudLoginUser.CurrentUser.attributes

All values and keys must be strings


void Start(){
    Debug.Log(CloudLoginUser.CurrentUser.attributes.Count);  // Prints 0
    Debug.Log(CloudLoginUser.CurrentUser.GetAttributeValue("CURRENT_LEVEL") == null); // Prints true
    CloudLoginUser.CurrentUser.SetAttribute("CURRENT_LEVEL", "5", SetAttributeCallback);
}

void SetAttributeCallback(string message, bool hasError) {
  if (hasError)
  {
      Debug.Error("Error setting attribute: "+message);
  }
  else
  {
      Debug.Log(CloudLoginUser.CurrentUser.GetAttributeValue("CURRENT_LEVEL")); // Prints "5"
  }
}

Leaderboard

Leaderboards can be easily created within CloudLogin

From the Unity game client, a Leaderboard Entry can be added with a leaderboard_name, score, and extra_attributes (metadata) for the current signed in user

Leaderboards can be downloaded for a specific leaderboard_name, which would gather all the high scores in order for all users in the game or

Leaderboards can be downloaded for a specific user, so that you can download the current users leaderboard data for all leaderboard_names

The below example shows submitting 2 leaderboard entries, then retrieving them for the game, and for the current user


void Start(){
  var extraAttributes = new Dictionary < string, string > ();
  extraAttributes.Add("deaths", "15");
  extraAttributes.Add("Jewels", "12");
  CloudLoginUser.CurrentUser.AddLeaderboardEntry("BombBomb",10, extraAttributes, LeaderboardEntryAdded);
}

void LeaderboardEntryAdded(string message, bool hasError)
{
    if (hasError)
    {
        print("Error adding leaderboard entry: " + message);
    }
    else
    {

        print("Set Leaderboard Entry 2");
        var extraAttributes = new Dictionary < string, string > ();
        extraAttributes.Add("deaths", "25");
        extraAttributes.Add("Jewels", "15");

        CloudLoginUser.CurrentUser.AddLeaderboardEntry("BombBomb", 7, extraAttributes, LeaderboardEntryAdded2);

    }
}

void LeaderboardEntryAdded2(string message, bool hasError)
{
    if (hasError)
    {
        print("Error adding leaderboard entry 2: " + message);
    }
    else
    {
        print("Set Leaderboard Entry 2");
        CloudLoginUser.CurrentUser.GetLeaderboard(5, true, LeaderboardEntriesRetrieved);
    }
}

void LeaderboardEntriesRetrieved(string message, bool hasError)
{
    if (hasError)
    {
        print("Error loading leaderboard entries: " + message);
    }
    else
    {

        print("Got leaderboard entries for specific user!");
        foreach( CloudLoginLeaderboardEntry entry in CloudLogin.Instance.leaderboardEntries)
        {
            print(entry.GetUsername() + ": " + entry.GetScore().ToString() + ": " + entry.GetLeaderboardName() );
            foreach (KeyValuePair < string,string > kvPair in entry.GetExtraAttributes())
            {
                print(kvPair.Key + ": " + kvPair.Value);
            }

        }
        CloudLogin.Instance.GetLeaderboard(5, true, "BombBomb", LeaderboardEntriesRetrievedAll);

    }
}

void LeaderboardEntriesRetrievedAll(string message, bool hasError)
{
    if (hasError)
    {
        print("Error loading leaderboard entries: " + message);
    }
    else
    {
        print("Got leaderboard entries for whole game!");
        foreach (CloudLoginLeaderboardEntry entry in CloudLogin.Instance.leaderboardEntries)
        {
            print(entry.GetUsername() + ": " + entry.GetScore().ToString() + ": " + entry.GetLeaderboardName());
            foreach (KeyValuePair < string, string > kvPair in entry.GetExtraAttributes())
            {
                print(kvPair.Key + ": " + kvPair.Value);
            }

        }

    }
}

Model Anatomy

Check each model below for a list of methods and attributes.




your current signed in user can be retrieved with: CloudLoginUser user = CloudLogin.CurrentUser; public bool IsSignedIn(); public int GetNumberOfLogins(); public DateTime GetLastLogin(); public string GetUsername(); public int GetScore(); public int GetCredits(); public void AddCredits(int credits, Action < string, bool > callback = null); public void SetCredits(int credits, Action < string, bool > callback = null); public void AddScore(int credits, Action < string, bool > callback = null); public void SetScore(int score, Action < string, bool > callback = null); public Dictionary < string,string > GetAttributes(); public Dictionary < string,string > .KeyCollection GetAttributesKeys(); public string GetAttributeValue(string key); public void SetAttribute(string key, string value, Action < string, bool > callback = null); public void RemoveAttribute(string key, Action < string, bool > callback = null); public List < CloudLoginStoreItem > GetPurchasedStoreItems(); public void PurchaseStoreItem(CloudLoginStoreItem storeItem, Action < string, bool > callback = null); public void PurchaseStoreItem(int storeItemId, Action < string, bool > callback = null); public void RemoveStoreItem(int storeItemID, bool reimburseUser, Action < string, bool > callback = null); public void RemoveStoreItem(CloudLoginStoreItem storeItem, bool reimburseUser, Action < string, bool > callback = null); public void AddLeaderboardEntry(string leaderboardName, int score, Dictionary extraAttributes = null, Action < string, bool > callback = null); public void AddLeaderboardEntry(string leaderboardName, int score, Action < string, bool > callback = null); public void GetLeaderboard(int limit, bool onePerUser, Action < string, bool > callback = null); //Get all leaderboard entries for current signed in user


public static void SetUpGame(string gameId, string token, Action < string, bool > callback = null); public static string GetGameId(); public static string GetGameName(); public static string GetGameDescription(); public static List < CloudLoginStoreItem > GetStoreItems() //Gets all store items (your library) public static void SignIn(string email, string password, Action < string, bool > callback = null); public static void SignUp(string email, string password, string password_confirmation, string username, Action < string, bool > callback = null); public void GetLeaderboard(int limit /* how many records? */, bool onePerUser /* only get max result for each user? or all results */, string LeaderboardName, Action < string, bool > callback = null); //Retrieves leaderboard for one specific Leaderboard Name


public string GetName(); public string GetCategory(); public string GetDescription(); public int GetCost(); public int GetId();


public string GetUsername(); public int GetScore(); public string GetLeaderboardName(); public Dictionary GetExtraAttributes();