corrade-http-templates – Blame information for rev 12

Subversion Repositories:
Rev:
Rev Author Line No. Line
2 eva 1 <?php
2  
3 ###########################################################################
4 ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ##
5 ###########################################################################
6 ## This is a script that uses Corrade's "getterrainheight" command in ##
7 ## order to retrieve the maximal terrain height of a region. ##
8 ###########################################################################
9  
10 ###########################################################################
11 ## CONFIGURATION ##
12 ###########################################################################
13  
12 eva 14 # The configuration file for this script containing the settings.
15 require_once('config.php');
16 require_once('functions.php');
17  
2 eva 18 ###########################################################################
19 ## INTERNALS ##
20 ###########################################################################
21  
22 ####
23 # I. Get the terrain height.
24 $params = array(
25 'command' => 'getterrainheight',
26 'group' => $GROUP,
27 'entity' => 'region',
28 'password' => $PASSWORD
29 );
30  
31 # We now escape each key and value: this is very important, because the
32 # data we send to Corrade may contain the '&' or '=' characters (we don't
33 # in this example though but this will not hurt anyone).
34 array_walk($params,
35 function(&$value, $key) {
36 $value = urlencode($key)."=".urlencode($value);
37 }
38 );
39 $postvars = implode('&', $params);
40  
41 # Set the options, send the request and then display the outcome
42 if (!($curl = curl_init())) {
43 echo "Could not initialise CURL".PHP_EOL;
44 }
45  
46 curl_setopt($curl, CURLOPT_URL, $URL);
47 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
48 curl_setopt($curl, CURLOPT_POST, true);
49 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
50 $return = curl_exec($curl);
51 curl_close($curl);
52  
53 $success = urldecode(
54 wasKeyValueGet(
55 "success",
56 $return
57 )
58 );
59  
60 // Unable to get the region heights?
61 if($success == 'False') return -1;
62  
63 ####
64 # II. Get the array of terrain heights and output the maximum value.
65 echo max(
66 str_getcsv(
67 urldecode(
68 wasKeyValueGet(
69 "data",
70 $return
71 )
72 )
73 )
74 );
75  
76 return 0;
77  
78 ?>