#LeaderboardC2
LeaderboardC2 is a self hosted Open Source PHP Leaderboard for Construct2. Post, fetch and display high scores.
- PHP 5.4+ with at least one library extension that deals with SQLite is required (either PDO, SQLite3, or SQLiteDatabase). PHP version 5.3.0 and greater usually comes with the SQLite3 extension installed and enabled by default so no custom action is necessary.
To determine your PHP version, create a new file with this PHP code: <?php echo PHP_VERSION; // version.php
. This will print your version number to the screen.
- Insure that you have the required components.
- Download LeaderboardC2 or cloning this Github repo.
- Upload LeaderboardC2 through FTP/SFTP or whatever upload method you prefer to the public-facing directory of your site.
- Ensure that the permissions for the
data
folder andyourbase.sqlite
file are set to0777
.
If you're using Apache, make sure you activate the URL rewriting module (mod_rewrite) in your apache.conf (or httpd.conf) file. You should also create a .htaccess file containing the following:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L,QSA]
The script tells Apache that whenever an HTTP request arrives and if no physical file (!-f) or path (!-d) or symbolic link (!-l) can be found, it should transfer control to index.php, which contains our main/front controller, and which in turn, invokes the framework.
The .htaccess file containing the Apache directives stated above should always be in the same folder as index.php.
You also need to set up Apache so it knows the physical location of index.php in your hard drive. A typical configuration is:
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
Options -Indexes +FollowSymLinks +Includes
AllowOverride All
Order allow,deny
Allow from All
</Directory>
PHP's latest stable version has its own built-in Web server. Start it up using the following configuration:
php -S localhost:80 -t /var/www/
The above command will start routing all requests to the Web root /var/www. If an incoming HTTP request for a file or folder is received, PHP will look for it inside the Web root and send it over to the browser if found. Otherwise, PHP will load the default index.php.
- Close Construct 2.
- Checkout the 'master' branch from this repository.
- Copy the contensts of the folder addon/files/leaderboard/ into CONSTRUCT2_INSTALLATION_FOLDER\exporters\html5\plugins\leaderboard.
Drag and drop the leaderboard.c2addon in to the Construct2 window to install it.
The plugin can be configured by selecting the object Leaderboard from the Object types list inside Construct2.
- Leaderboard service URL (The Leaderboard service URL. This value most not end with a slash, e.g: http//myserver/leaderboard)
- Game ID (The game id. Should be equal to the SQLite file name without the .sqlite extension)
- Magic number (The magic number. Should be equal to the 'magic_number' property in the config.ini file)
- Magic key (The magic key. Should be equal to the 'magic_key' property in the config.ini file)
- Log requests (Sends request URLs into console. For debugging purposes)
- Set timeout (Set the maximum time before a request is considered to have failed)
- Set request header (Set a HTTP header on the next request that is made)
- Request Top Scores (Top Scores request returns an array of scores to your function where you can display the data in your Leaderboard)
- Get the player's last rank (Get the player's last rank)
- Get the player's best rank (Get the player's best rank)
- Submit score (Submit player's score)
- On Top Scores completed (Triggered when a Top Scores request completes successfully)
- On Get Best Rank completed (Triggered when a Get Best Rank request completes successfully)
- On Get Last Rank completed (Triggered when a Get Last Rank request completes successfully)
- On Add Score completed (Triggered when a Add Score request completes successfully)
<