Pre-purchase questi...
 
Notifications
Clear all

Pre-purchase question

14 Posts
2 Users
0 Likes
751 Views
(@punchey)
Posts: 36
Trusted Member
Topic starter
 

I have a couple of questions to know if Combu will meet my needs:

  1. I need to be able to automatically register a user with zero friction.  That is, I want to be able to take an automatically generated user ID (generated from information I have already obtained about that user) and create an account completely transparently with zero interaction from the user.  So no need to setup a name, password, or anything. This ID should serve as the user's ID that can be queried for leaderboards, friends, etc.
  2. I need to be able to query leaderboards either for global top scores, scores surrounding a specific user (like 5 above and 5 below or something similar), and scores of a list of user IDs.  The IDs specified for these queries should be the ID mentioned in #1 above.
  3. I need to be able to either control the ID of leaderboards, or else be able to query a leaderboard based on a custom field that effectively serves as its ID. (I'm using a hash string that's generated from a level's content to identify that level, and want that to serve as the identifier of the leaderboard, along with a description).
  4. I need to be able to create a new leaderboard whenever a user submits a score for a leaderboard ID that doesn't already exist. So if the leaderboard ID/hash value doesn't already exist, a new leaderboard is created.  This is to support user-created levels, and the ability of members of the public to compete on those user-generated levels.

Thanks!

 
Posted : 11/03/2020 4:43 am
(@punchey)
Posts: 36
Trusted Member
Topic starter
 

I see that user IDs are type long, which doesn't work for my custom ID.  However, if there is a way to store my custom ID as custom data in the user/profile record, as long as there's a way to search for and find a user based on that custom data, I could have the functionality I need. Is that what SearchCustomData() can accomplish?

 
Posted : 11/03/2020 8:56 pm
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

The account's Id is currently an auto-increment long as you noticed, but you could use your autogenerated custom ID to get an automatic username:

  • instead of default Authenticate method to login, use AuthenticatePlatform passing "MyCustomPlatform" as platform key and your custom ID, now if a user with your custom ID doesn't exist in such platform then it creates a new account with username={platform key}_{platform_id}
  • now you know that usernames are "MyCustomPlatform_YOURCUSTOMID"

This way you can use this information with the overload of Leaderboard.LoadScoresByUser that accepts the username as parameter (and any other classes methods that accepts a username).

About the possibility to load a certain number of ranks before/after a specified user, that's not something built-in, though you could probably get it with the existing methods by chaining Leaderboard.LoadScoresByUser (passes to the callback the score's page) and LoadScores (calculating the page and rank before/after what's returned previously).

About Leaderboard Ids, like any other Id in other core classes, are all auto-increment long but you can assign a custom unique Code and use freely instead of Id, so it should fit your needs.

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 12/03/2020 8:54 pm
(@punchey)
Posts: 36
Trusted Member
Topic starter
 

@skaredcreations thank you for your answers.  Just a few clarifications:

  1. So you're saying I can perform all necessary functions on a given user account just based on knowing their username ({platform key}_{custom id})? That is, all critical APIs permit locating a user by username? 
  2. The above suggests to me that username must be unique. Is there a way to support a non-unique display name as well? I'm guessing some custom data field perhaps?
  3. So to get scores surrounding the player's position on the board (so that I can show their score flanked by those scores immediately above and below theirs), would I be able to get the current user's score, note the rank, which let's say is 100, and then I can call LoadScores() with a range of 90-110?
  4. For leaderboard IDs, if I use a custom unique code, where do I assign that when creating it, and how to I select and retrieve a leaderboard based on that custom code on the client?
  5. To be clear, I need the ability to create a new leaderboard (with custom ID code as described earlier) from the client side. That is, when a user/client creates a new custom level and then plays it and gets a score on it, I need to be able to automatically create a new leaderboard for that user-generated custom level.  And it needs to happen transparent to the user, and obviously needs to be able to happen without any intervention on my part. Does this functionality exist?

 

 
Posted : 12/03/2020 10:19 pm
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

Most of APIs accepts username as parameter, of course the username is unique like any other authentication system. For display name you can use a key in the hashtable customData of the account.

About the score ranks before/after a user's rank as said LoadScoresByUser returns the page where the user's rank is placed (accordingly to the "limit" parameter, that is the number of results per page), so you should be able to get them by loading the scores of that page (and eventually previous page if needed) with LoadScores passing the same value of "limit" to have the same pagination.

About the leaderboard creation, it's not built-in because it's usually something that you configure on admin website, but since Combu supports custom add-ons you can create an add-on with a webservice endpoint to create the leaderboard (PHP programming is required, check the link for the tutorial blog posts to see how to create a custom add-on).

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 15/03/2020 5:15 pm
(@punchey)
Posts: 36
Trusted Member
Topic starter
 

@skaredcreations Thanks very much. I assume there are some APIs in the server scripts to create a new Leaderboard? Any tips or guidance you could offer in where to start looking for which APIs I need to focus on would be extremely helpful.

 

 
Posted : 16/03/2020 12:01 am
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

Tomorrow I will create a simple custom-addon with a webservice endpoint for you and will post it here so everyone else can benefit.

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 16/03/2020 10:39 pm
(@punchey)
Posts: 36
Trusted Member
Topic starter
 

@skaredcreations Oh, that would be amazing!  Thank you!

 

 
Posted : 16/03/2020 11:51 pm
(@punchey)
Posts: 36
Trusted Member
Topic starter
 

@skaredcreations I hope you're doing okay and are safe!  Also still very much looking forward to that endpoint example when you get a chance.  Thanks!

 

 
Posted : 19/03/2020 10:49 pm
(@skaredcreations)
Posts: 805
Prominent Member Admin
 
Posted by: @punchey

@skaredcreations I hope you're doing okay and are safe!  Also still very much looking forward to that endpoint example when you get a chance.  Thanks!

 

Yes, sorry unfortunately as you may imagine it's not a good time here in Italy, and all the pain and sufferings and deaths in our cities and around us make these days very hard for willing to work harder than helping our weaker people as much as we can.

I promise to you that will write the code here during the weekend, sorry for being late but you'll understand...

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 20/03/2020 11:29 am
(@punchey)
Posts: 36
Trusted Member
Topic starter
 

@skaredcreations oh, I did not know you were in Italy.  I'm so very sorry to hear about all of that. I fear we are about to experience the same here in the US very soon.  I am bracing myself for it.

 

 
Posted : 20/03/2020 7:47 pm
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

@punchey I really pray that it'll not hurt you guys, neither in US nor in any other country, it's terribly depressing and poignant... 🙁 

Anyway I'll write the custom addon for you tomorrow for sure and post it here for everyone benefit

 

Stay tuned 😎 

 

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 20/03/2020 7:52 pm
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

And here is the step-by-step guide:

  1. Create a folder for your addon inside /addons (for this example I'll use "myaddon")
  2. In the new folder create the file addon's settings file called "addon.php" (this is automatically loaded and adds your addon to the addons list)
  3. Also create your web service endpoint with the actions you'll need (for the purpose of your topic it'll only contain an action to create a leaderboard)
  4. Finally create your client class to be used in Unity (it'll handle the calls to your web service endpoints)

 

1. Create addon's folder (Server)

Go into /addons on your Combu server root and create the folder which will contain all files for your addon (for example "myaddon").

 

2. Create the addon settings (Server)

Inside your addon folder (for example /addons/myaddon) create the file addon.php that is the standard settings file for your addon, which contains the addon's name, version and any other setting that you want publicly available to your server side addon's scripts. This is the content for this file:

<?php

// Give a name to this add-on
$addon->Name = "My Add-on";
$addon->Version = "1.0";

3. Create the endpoint (Server)

Inside your addon folder create also the file client.php that will be your web service endpoint and contains the functions to handle the actions. This is the content for this file:

<?php

include_once '../../lib/api.php';

use Combu\Utils;
use Combu\ErrorMessage;
use Combu\LeaderBoard;

if (isset($WS_REQUEST["action"])) {
switch ($WS_REQUEST["action"]) {

case "create_leaderboard":
wsCreateLeaderboard();
break;

}
}
$Database->CloseConnection();
exit();

/**
* Create a leaderboard
* @global \Combu\AppId $AppId
* @global array[string] $WS_REQUEST
* @global Combu\Account $LoggedAccount
*/
function wsCreateLeaderboard() {
global $AppId, $WS_REQUEST, $LoggedAccount;
$success = FALSE;
$message = "";
if (!$LoggedAccount->IsLogged()) {
$message = ErrorMessage::Get(ERROR_USER_NOT_AUTHENTICATED);
} else {

// Create a new leaderboard object
$leaderboard
= new LeaderBoard();
$leaderboard->IdApp = $AppId->Id;

// Set the score type to register only the highest per account
// (check /vendor/skaredcreations/combu/combu/LeaderBoard.php for the other SCORE_UNIQUE_* score types)
$leaderboard->UniqueRecords = LeaderBoard::SCORE_UNIQUE_REPLACE_HIGHER;

// Set the leaderboard's title and unique code sent from client
$leaderboard->Title = $WS_REQUEST["Title"];
$leaderboard->Code = $WS_REQUEST["Code"];

if ($leaderboard->Code && is_numeric(substr($leaderboard->Code, 0, 1))) {
$message = "Code cannot start with a number";
} else if ($leaderboard->Code && $leaderboard->ExistsCode()) {
$message = "This Code is already used for another Leaderboard";
} else {
// Save the leaderboard
if ($leaderboard->Save()) {
$success = TRUE;
$message = $leaderboard->ToJson();
} else {
$message = ErrorMessage::Get(ERROR_UNEXPECTED_GENERIC);
}
}
}
Utils::EchoJson(Utils::JsonEncodeSuccessMessage($success, $message));
}

4. Create the client script (Unity)

Create the Unity C# script to handle the call to your web service endpoints:

using System;
using System.Collections;
using Combu;

public static class MyAddon
{
static string URL
{
get
{
return CombuManager.instance.GetUrl("addons/myaddon/client.php");
}
}

public static void CreateLeaderboard(string title, string code, Action<Leaderboard, string> onCreate)
{
if (!CombuManager.isInitialized)
{
throw new Exception("CombuManager is not initialized yet");
}
CombuForm form = new CombuForm();
form.AddField("action", "create_leaderboard");
form.AddField("Title", title);
form.AddField("Code", code);
CombuManager.instance.CallWebservice(URL, form, (string text, string error) =>
{
Leaderboard leaderboard = null;
if (string.IsNullOrEmpty(error) && !string.IsNullOrEmpty(text))
{
Hashtable response = text.hashtableFromJson();
if (response != null && response.ContainsKey("success"))
{
bool success;
if (bool.TryParse(response["success"] + "", out success) && success)
{
leaderboard = new Leaderboard(response["message"] + "");
}
else if (!string.IsNullOrEmpty(response["message"] + ""))
{
error = response["message"].ToString();
}
}
}
if (onCreate != null)
{
onCreate(leaderboard, error);
}
});
}
}

Use it in your code

Now you can finally create the leaderboard from your Unity client by using the following code sample:

string title = CombuManager.localUser.userName + "'s Leaderboard";
string code = "User" + CombuManager.localUser.id;
MyAddon.CreateLeaderboard(title, code, (Leaderboard leaderboard, string error) =>
{
Debug.Log("Leaderboard Id: " + (leaderboard != null ? leaderboard.id : "0") + " -- " + error);
});

 

You'll find the sample files attached to this post. By the way, you can find the complete list of all server core classes at here (also checkout the files in /admin in case you want to see how the entities are created/updated/deleted in the administration website).

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 22/03/2020 6:39 pm
(@punchey)
Posts: 36
Trusted Member
Topic starter
 

@skaredcreations thank you so much for this! I'll dive into it right away.  Also, please check your DM.

 

 
Posted : 22/03/2020 9:51 pm
Share: