corrade-http-templates – Blame information for rev 7

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: ##
7 ## * getregiondata ##
8 ## * getavatarpositions ##
9 ## * download ##
10 ## commands in order to display the positions of avatars on the region. ##
11 ###########################################################################
12  
13 ###########################################################################
14 ## CONFIGURATION ##
15 ###########################################################################
16  
7 zed 17 require_once('config.php');
18 require_once('functions.php');
2 eva 19  
20 ###########################################################################
21 ## INTERNALS ##
22 ###########################################################################
23  
24 ####
25 # I. Get the UUID of the map image for the current region
26 $params = array(
27 'command' => 'getgridregiondata',
28 'group' => $GROUP,
29 'password' => $PASSWORD,
30 'data' => 'MapImageID'
31 );
32 array_walk($params,
33 function(&$value, $key) {
34 $value = rawurlencode($key)."=".rawurlencode($value);
35 }
36 );
37 $postvars = implode('&', $params);
38 if (!($curl = curl_init())) {
39 print 0;
40 return;
41 }
42  
43 curl_setopt($curl, CURLOPT_URL, $URL);
44 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
45 curl_setopt($curl, CURLOPT_POST, true);
46 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
7 zed 47 curl_setopt($curl, CURLOPT_ENCODING, true);
2 eva 48 $return = curl_exec($curl);
49 curl_close($curl);
50  
51 $success = urldecode(
52 wasKeyValueGet(
53 "success",
54 $return
55 )
56 );
57  
58 if($success == 'False') {
59 echo 'Unable to get the region map image.';
60 die;
61 }
62  
63 $mapUUID = wasCSVToArray(
64 urldecode(
65 wasKeyValueGet(
66 "data",
67 $return
68 )
69 )
70 )[1];
71  
72 ####
73 # II. Download the map image as a PNG file.
74 $params = array(
75 'command' => 'download',
76 'group' => $GROUP,
77 'password' => $PASSWORD,
78 'item' => $mapUUID,
79 'type' => 'Texture',
80 'format' => 'Png'
81 );
82 array_walk($params,
83 function(&$value, $key) {
84 $value = rawurlencode($key)."=".rawurlencode($value);
85 }
86 );
87 $postvars = implode('&', $params);
88 if (!($curl = curl_init())) {
89 print 0;
90 return;
91 }
92 curl_setopt($curl, CURLOPT_URL, $URL);
93 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
94 curl_setopt($curl, CURLOPT_POST, true);
95 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
7 zed 96 curl_setopt($curl, CURLOPT_ENCODING, true);
2 eva 97 $return = curl_exec($curl);
98 curl_close($curl);
99  
100 if($success == 'False') {
101 echo 'Unable to download the region map texture.';
102 die;
103 }
104  
105  
106 ####
107 # III. Convert the image data to a PNG of size 512x512
108 $im = imagescale(
109 imagecreatefromstring(
110 base64_decode(
111 urldecode(
112 wasKeyValueGet(
113 "data",
114 $return
115 )
116 )
117 )
118 ),
119 512,
120 512
121 );
122  
123 ####
124 # IV. Get the avatar positions on the map.
125 $params = array(
126 'command' => 'getavatarpositions',
127 'group' => $GROUP,
128 'password' => $PASSWORD,
129 'entity' => 'region'
130 );
131 array_walk($params,
132 function(&$value, $key) {
133 $value = rawurlencode($key)."=".rawurlencode($value);
134 }
135 );
136 $postvars = implode('&', $params);
137 if (!($curl = curl_init())) {
138 print 0;
139 return;
140 }
141 curl_setopt($curl, CURLOPT_URL, $URL);
142 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
143 curl_setopt($curl, CURLOPT_POST, true);
144 curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
7 zed 145 curl_setopt($curl, CURLOPT_ENCODING, true);
2 eva 146 $return = curl_exec($curl);
147 curl_close($curl);
148  
149 $success = urldecode(
150 wasKeyValueGet(
151 "success",
152 $return
153 )
154 );
155  
156 if($success == 'False') {
157 echo 'Unable to get the avatars positions.';
158 die;
159 }
160  
161  
162 ####
163 # V. Display the coordinates on the map.
164 array_walk(
165 array_chunk(
166 wasCSVToArray(
167 urldecode(
168 wasKeyValueGet(
169 "data",
170 $return
171 )
172 )
173 ),
174 3
175 ),
176 function(&$value, $key) use(&$im) {
177 if(count($value) != 3) return;
178 $components = wasLSLVectorToArray($value[2]);
179 if(count($components) != 3) return;
180 $x = mapValueToRange($components[0], 0, 255, 0, 512);
181 $y = 512 - mapValueToRange($components[1], 0, 255, 0, 512);
182 imagefilledellipse(
183 $im,
184 $x,
185 $y,
186 8,
187 8,
188 imagecolorallocate(
189 $im,
190 0,
191 0,
192  
193 )
194 );
195 imagefilledellipse(
196 $im,
197 $x,
198 $y,
199 6,
200 6,
201 imagecolorallocate(
202 $im,
203 0,
204 255,
205  
206 )
207 );
208 }
209 );
210  
211 ####
212 # VI. Output the Base64 encoded image for AJAX.
213 ob_start();
214 imagepng($im);
215 $png = ob_get_contents();
216 imagedestroy($im);
217 ob_end_clean();
218  
219 echo base64_encode($png);
220  
221 ?>
222