last update: 30/08/2019parent: eZombie 1.1 (en)

Server Scores

This part it is optional and no needed to run eZombie in your regions.

 

In this chapter we will try to give you all infos needed to build a web server where collect scores made by players and put them in a html page visible by web. This want to be a basic guide to drive you in managing the scores data, not an exaustive guide about how to install a "ready to run" server. Please consider that the Endivatomic staff for no reason and under no circumstances can follow you step by step in the installation process or implement a custom server created specifically for your needs.

 

If you filled the parameter "score_url = secret_code|http://www.mydomain.com/xxx/yyy" in the config.cfg notecard, everytime a player will end his game session, a "PUT" call will be made to the URL you wrote (in this example: http://www.mydomain.com/xxx/yyy) with the following json data:

 

{

  "gameID":"abcdefg",
  "method":"scoreupdate",
  "regionID":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "regionName":"My Zombie region",
  "scores": [
    [

      "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", (player UID)

      "Player Name", (player name)

      "1:15:03",  (played time)

      718,  (number of zombie killed)

      22347  (score)
    ],[

      "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",

      "Player Name",

      "1:15:03",

      718,

      22347
    ],[

      ..............

    ]

  ]
}

 

the following example is a PHP code to get that data and store them in a file. You can easily change it to store the data into a dbase as you need.

 

<?php

// insert here the secret code you wrote in config.cfg

// notecard at param:

//   score_url = secret_code|http://www.mydomain.com/xxx/yyy

$secret_code = "abcdef";


// read PUT contents

$json = file_get_contents("php://input");
if ($json == null || $json == "") {

  // if no data had been send, nothing todo 

  exit(0);

}

 

$par = json_decode($json, true);
if ($par == null) {

  // data has not valid json, nothing todo 

  exit(0);

}


if (!isset($par['gameID']) || !isset($par['regionID'])) {

  // missing mandatory parameters, exit

  exit(0);

}   


if ($par['gameID'] != $secret_code) {

  // the secret code set in config.cfg it is not valid, exit!

  exit(0); 

}

 

// store json to file in folder scores/

file_put_contents( "scores/". $par['regionID'] .".json", $json );
exit(0);

php example 1

 

in same folder where you saved php example 1, create a subfolder named scores, and set full read/write permission to it.

 

NOTE!!! this is just an example, do not use it "as is" in your server, this is valid only for tests. In this example the files are stored in "scores/" subfolder, this will be normally readable from web, and peoples can read it directly. You will have to store this files elsewhere or protect them by read using something like .htaccess on Apache httpd server.

 

If you want to show scores into your web page, you have to add something like the following PHP code to your page:

 

<?php
// Region ID we want to read scores
$regID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";

 

// Load the Score file of the region and decode it

$cont = file_get_contents( "scores/". $regID .".json");
$score = json_decode( $cont, true );

 

// Extract scores and reorder list by points
$score = $score['scores'];
usort($score, "custom_sort");

 

// Define the custom sort function
function custom_sort($a,$b) { return $a[4]<$b[4]; }

 

// Output score table
?>
<table>          
  <tr>

    <th>Player name</th>

    <th>Score</th>

    <th>Kills</th>

    <th>Time (h:m:s)</th>

  </tr>

<?php
  foreach($score as $sc) {      
    $buf  = "<td>". $sc[1] ."</td>";    // Player name
    $buf .= "<td>". $sc[4] ."</td>";    // Top Score
    $buf .= "<td>". $sc[3] ."</td>";    // Killed zombies
    $buf .= "<td>". $sc[2] ."</td>";    // Played time
    echo "<tr>". $buf ."</tr>";      
  }  
?>
</table>

php example 2

 

REMEMBER:

  • this examples are done just for test purposes, do not use them in production environment. They are kept as simple as possible to help you understanding how does eZombie dll works. It is up to you adapt them to your needs.
  • this examples are simple and do not take care about security of your data. It is up to you secure them depending of your web server configuration.
  • this examples are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, like suggested on Licence pages.
  • this are all the infos we can give you about how configure your webserver, to really make it works it is up to you and your programmers. 
  • We aren't Joomla, WordPress, etc., experts then we can not support you in other way, please do not ask.