corrade-http-templates – Blame information for rev 2

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  
14 // The configuration file for this script containing the settings.
15 include_once("config.php");
16  
17 ###########################################################################
18 ## INTERNALS ##
19 ###########################################################################
20  
21 ###########################################################################
22 ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ##
23 ###########################################################################
24 function wasKeyValueGet($key, $data) {
25 return array_reduce(
26 explode(
27 "&",
28 $data
29 ),
30 function($o, $p) {
31 $x = explode("=", $p);
32 return array_shift($x) != $o ? $o : array_shift($x);
33 },
34 $key
35 );
36 }
37  
38 ####
39 # I. Get the terrain height.
40 $params = array(
41 'command' => 'getterrainheight',
42 'group' => $GROUP,
43 'entity' => 'region',
44 'password' => $PASSWORD
45 );
46  
47 # We now escape each key and value: this is very important, because the
48 # data we send to Corrade may contain the '&' or '=' characters (we don't
49 # in this example though but this will not hurt anyone).
50 array_walk($params,
51 function(&$value, $key) {
52 $value = urlencode($key)."=".urlencode($value);
53 }
54 );
55 $postvars = implode('&', $params);
56  
57 # Set the options, send the request and then display the outcome
58 if (!($curl = curl_init())) {
59 echo "Could not initialise CURL".PHP_EOL;
60 }
61  
62 curl_setopt($curl, CURLOPT_URL, $URL);
63 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
64 curl_setopt($curl, CURLOPT_POST, true);
65 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
66 $return = curl_exec($curl);
67 curl_close($curl);
68  
69 $success = urldecode(
70 wasKeyValueGet(
71 "success",
72 $return
73 )
74 );
75  
76 // Unable to get the region heights?
77 if($success == 'False') return -1;
78  
79 ####
80 # II. Get the array of terrain heights and output the maximum value.
81 echo max(
82 str_getcsv(
83 urldecode(
84 wasKeyValueGet(
85 "data",
86 $return
87 )
88 )
89 )
90 );
91  
92 return 0;
93  
94 ?>