A self hosted Open Source PHP Leaderboard for Construct2. Post, fetch and display high scores.
HTML PHP CSS JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
addon
app/inc
c2Example
data
lib
test
.gitignore
.htaccess
LICENSE
README.md
config.ini
index.php

README.md

LeaderboardC2

LeaderboardC2 is a self hosted Open Source PHP Leaderboard for Construct2. Post, fetch and display high scores.

Requirements

  • 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.

Install

Backend installation

  1. Insure that you have the required components.
  2. Download LeaderboardC2 or cloning this Github repo.
  3. Upload LeaderboardC2 through FTP/SFTP or whatever upload method you prefer to the public-facing directory of your site.
  4. Ensure that the permissions for the data folder and yourbase.sqlite file are set to 0777.

Apache

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 5.4's Built-In Web Server

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.

Plugin installation

Manual

  1. Close Construct 2.
  2. Checkout the 'master' branch from this repository.
  3. Copy the contensts of the folder addon/files/leaderboard/ into CONSTRUCT2_INSTALLATION_FOLDER\exporters\html5\plugins\leaderboard.

Automatic

Drag and drop the leaderboard.c2addon in to the Construct2 window to install it.

Installing third-party addons

Plugin configuration

The plugin can be configured by selecting the object Leaderboard from the Object types list inside Construct2.

Plugin Properties

  • 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)

plugin

Plugin Actions

  • 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)

actions

Plugin Conditions

  • 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)

events

Examples

Live demo

http://htejera.ukelelestudio.com/leaderboardc2/demo/

Construct2 project

This project comes with a .capx as a reference to know how to use it, you can download it from here.

Some projects that use LeaderboardC2

Got a successful game you'd like added to this section? Let me know in the forum!

https://www.scirra.com/forum/plugin-a-self-hosted-open-source-php-leaderboard-for-con_t125116

Do you need a SQLite manager?

Need help?

If you need to get in touch with me, you can reach me at henrytejera |AT| gmail |DOT| com

Contribution Guidelines

Please submit issues to ohtejera/leaderboardC2 and pull requests to *-dev branches.

gauchoiwantyou2

Powered by

Fat-Free framework. A powerful yet easy-to-use PHP micro-framework .

License

The MIT License (MIT)

Copyright (c) 2015 Henry Tejera

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.