corrade-http-templates – Diff between revs 80 and 82
?pathlinks?
Rev 80 | Rev 82 | |||
---|---|---|---|---|
1 | <?php |
1 | <?php |
|
2 | |
2 | |
|
3 | ########################################################################### |
3 | ########################################################################### |
|
4 | ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ## |
4 | ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ## |
|
5 | ########################################################################### |
5 | ########################################################################### |
|
6 | ## This is a script that listens for Corrade's "terse" notification and ## |
6 | ## This is a script that listens for Corrade's "terse" notification and ## |
|
7 | ## then uses Corrade's "getavatardata" command in order to determine the ## |
7 | ## then uses Corrade's "getavatardata" command in order to determine the ## |
|
8 | ## shape gender and to store that data as a CSV of UUIDs by gender. ## |
8 | ## shape gender and to store that data as a CSV of UUIDs by gender. ## |
|
9 | ########################################################################### |
9 | ########################################################################### |
|
10 | |
10 | |
|
11 | # Check if this is the terse notification, otherwise bail. |
11 | # Check if this is the terse notification, otherwise bail. |
|
12 | if(!isset($_POST['type']) || $_POST['type'] != 'avatars') return; |
12 | if(!isset($_POST['type']) || $_POST['type'] != 'avatars') return; |
|
13 | # Check if this is an avatar terse notification, otherwise bail. |
13 | # Check if this is an avatar terse notification, otherwise bail. |
|
14 | if(!isset($_POST['entity']) || $_POST['entity'] != 'Avatar') return; |
14 | if(!isset($_POST['entity']) || $_POST['entity'] != 'Avatar') return; |
|
15 | |
15 | |
|
16 | ########################################################################### |
16 | ########################################################################### |
|
17 | ## CONFIGURATION ## |
17 | ## CONFIGURATION ## |
|
18 | ########################################################################### |
18 | ########################################################################### |
|
19 | |
19 | |
|
20 | # Set this to the name of the group. |
20 | # Set this to the name of the group. |
|
21 | $GROUP = 'My Group'; |
21 | $GROUP = 'My Group'; |
|
22 | # Set this to the group password. |
22 | # Set this to the group password. |
|
23 | $PASSWORD = 'mypassword'; |
23 | $PASSWORD = 'mypassword'; |
|
24 | # Set this to Corrade's HTTP Server URL. |
24 | # Set this to Corrade's HTTP Server URL. |
|
25 | $URL = 'http://corrade.local.site:8080'; |
25 | $URL = 'http://corrade.local.site:8080'; |
|
26 | # Visitors file. |
26 | # Visitors file. |
|
27 | $VISITOR_FILE = 'visitors.log'; |
27 | $VISITOR_FILE = 'visitors.log'; |
|
28 | |
28 | |
|
29 | ########################################################################### |
29 | ########################################################################### |
|
30 | ## INTERNALS ## |
30 | ## INTERNALS ## |
|
31 | ########################################################################### |
31 | ########################################################################### |
|
32 | |
32 | |
|
33 | require_once('vendor/was/utilities/src/formats/kvp/kvp.php'); |
33 | require_once('vendor/was/utilities/src/formats/kvp/kvp.php'); |
|
34 | require_once('vendor/was/utilities/src/IO/IO.php'); |
34 | require_once('vendor/was/utilities/src/IO/IO.php'); |
|
35 | require_once('vendor/was/utilities/src/formats/csv/csv.php'); |
35 | require_once('vendor/was/utilities/src/formats/csv/csv.php'); |
|
36 | |
36 | |
|
37 | $visitors = array(); |
37 | $visitors = array(); |
|
38 | if(file_exists($VISITOR_FILE)) { |
38 | if(file_exists($VISITOR_FILE)) { |
|
39 | $visitors = explode( |
39 | $visitors = explode( |
|
40 | PHP_EOL, |
40 | PHP_EOL, |
|
41 | atomized_get_contents( |
41 | atomized_get_contents( |
|
42 | $VISITOR_FILE |
42 | $VISITOR_FILE |
|
43 | ) |
43 | ) |
|
44 | ); |
44 | ); |
|
45 | array_walk( |
45 | array_walk( |
|
46 | $visitors, |
46 | $visitors, |
|
47 | function($e, $k) { |
47 | function($e, $k) { |
|
48 | if(wasCSVToArray($e)[0] == $_POST['id']) die; |
48 | if(wasCSVToArray($e)[0] == $_POST['id']) die; |
|
49 | } |
49 | } |
|
50 | ); |
50 | ); |
|
51 | } |
51 | } |
|
52 | |
52 | |
|
53 | # This constructs the command as an array of key-value pairs. |
53 | # This constructs the command as an array of key-value pairs. |
|
54 | $params = array( |
54 | $params = array( |
|
55 | 'command' => 'getavatardata', |
55 | 'command' => 'getavatardata', |
|
56 | 'group' => $GROUP, |
56 | 'group' => $GROUP, |
|
57 | 'password' => $PASSWORD, |
57 | 'password' => $PASSWORD, |
|
58 | 'agent' => $_POST['id'], |
58 | 'agent' => $_POST['id'], |
|
59 | 'data' => 'VisualParameters' |
59 | 'data' => 'VisualParameters' |
|
60 | ); |
60 | ); |
|
61 | |
61 | |
|
62 | # We now escape each key and value: this is very important, because the |
62 | # We now escape each key and value: this is very important, because the |
|
63 | # data we send to Corrade may contain the '&' or '=' characters (we don't |
63 | # data we send to Corrade may contain the '&' or '=' characters (we don't |
|
64 | # in this example though but this will not hurt anyone). |
64 | # in this example though but this will not hurt anyone). |
|
65 | array_walk($params, |
65 | array_walk($params, |
|
66 | function(&$value, $key) { |
66 | function(&$value, $key) { |
|
67 | $value = rawurlencode($key)."=".rawurlencode($value); |
67 | $value = urlencode($key)."=".urlencode($value); |
|
68 | } |
68 | } |
|
69 | ); |
69 | ); |
|
70 | $postvars = implode('&', $params); |
70 | $postvars = implode('&', $params); |
|
71 | |
71 | |
|
72 | # Set the options, send the request and then display the outcome |
72 | # Set the options, send the request and then display the outcome |
|
73 | if (!($curl = curl_init())) { |
73 | if (!($curl = curl_init())) { |
|
74 | print 0; |
74 | print 0; |
|
75 | return; |
75 | return; |
|
76 | } |
76 | } |
|
77 | |
77 | |
|
78 | curl_setopt($curl, CURLOPT_URL, $URL); |
78 | curl_setopt($curl, CURLOPT_URL, $URL); |
|
79 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
79 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
80 | curl_setopt($curl, CURLOPT_POST, true); |
80 | curl_setopt($curl, CURLOPT_POST, true); |
|
81 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); |
81 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); |
|
82 | $return = curl_exec($curl); |
82 | $return = curl_exec($curl); |
|
83 | curl_close($curl); |
83 | curl_close($curl); |
|
84 | |
84 | |
|
85 | $success = urldecode( |
85 | $success = urldecode( |
|
86 | wasKeyValueGet( |
86 | wasKeyValueGet( |
|
87 | "success", |
87 | "success", |
|
88 | $return |
88 | $return |
|
89 | ) |
89 | ) |
|
90 | ); |
90 | ); |
|
91 | |
91 | |
|
92 | if($success == 'False') { |
92 | if($success == 'False') { |
|
93 | # DEBUG: This will be triggered if getting the avatar data fails. |
93 | # DEBUG: This will be triggered if getting the avatar data fails. |
|
94 | #print $uuid." ".urldecode( |
94 | #print $uuid." ".urldecode( |
|
95 | # wasKeyValueGet( |
95 | # wasKeyValueGet( |
|
96 | # 'error', |
96 | # 'error', |
|
97 | # $return |
97 | # $return |
|
98 | # ) |
98 | # ) |
|
99 | #)."\n"; |
99 | #)."\n"; |
|
100 | die; |
100 | die; |
|
101 | } |
101 | } |
|
102 | |
102 | |
|
103 | $visual = wasCSVToArray( |
103 | $visual = wasCSVToArray( |
|
104 | urldecode( |
104 | urldecode( |
|
105 | wasKeyValueGet( |
105 | wasKeyValueGet( |
|
106 | "data", |
106 | "data", |
|
107 | $return |
107 | $return |
|
108 | ) |
108 | ) |
|
109 | ) |
109 | ) |
|
110 | ); |
110 | ); |
|
111 | |
111 | |
|
112 | $new = array(); |
112 | $new = array(); |
|
113 | array_push($new, $_POST['id']); |
113 | array_push($new, $_POST['id']); |
|
114 | switch($visual[32]) { |
114 | switch($visual[32]) { |
|
115 | case 0: |
115 | case 0: |
|
116 | # DEBUG |
116 | # DEBUG |
|
117 | #print $uuid.' is female '."\n"; |
117 | #print $uuid.' is female '."\n"; |
|
118 | array_push($new, 'female'); |
118 | array_push($new, 'female'); |
|
119 | break; |
119 | break; |
|
120 | default: |
120 | default: |
|
121 | # DEBUG |
121 | # DEBUG |
|
122 | #print $uuid.' is male '."\n"; |
122 | #print $uuid.' is male '."\n"; |
|
123 | array_push($new, 'male'); |
123 | array_push($new, 'male'); |
|
124 | break; |
124 | break; |
|
125 | } |
125 | } |
|
126 | |
126 | |
|
127 | array_push($visitors, wasArrayToCSV($new)); |
127 | array_push($visitors, wasArrayToCSV($new)); |
|
128 | |
128 | |
|
129 | atomized_put_contents( |
129 | atomized_put_contents( |
|
130 | $VISITOR_FILE, |
130 | $VISITOR_FILE, |
|
131 | implode( |
131 | implode( |
|
132 | PHP_EOL, |
132 | PHP_EOL, |
|
133 | $visitors |
133 | $visitors |
|
134 | ) |
134 | ) |
|
135 | ); |
135 | ); |
|
136 | |
136 | |