Skip to content

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

License

Notifications You must be signed in to change notification settings

htejera/leaderboardC2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

<