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