corrade-http-templates – Blame information for rev 82

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