/[drupal]/contributions/modules/secondlife/secondlife.module
ViewVC logotype

Contents of /contributions/modules/secondlife/secondlife.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Sun Dec 14 20:19:01 2008 UTC (11 months, 1 week ago) by kbahey
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.3: +16 -22 lines
File MIME type: text/x-php
#346813 by ssm2017 and kbahey, porting to Drupal 6.x.
1 <?php
2 define('SECONDLIFE_SETTINGS_TIMER', 'secondlife_timer');
3 define('SECONDLIFE_SETTINGS_DEBUG', 'secondlife_debug');
4
5 /**
6 * Implementation of hook_help().
7 */
8 function secondlife_help($section) {
9 switch ($section) {
10 case 'admin/help#sl':
11 $output = '<p>'. t('SecondLife integration library') .'</p>';
12 return $output;
13 break;
14 }
15 }
16
17 /**
18 * Implementation of hook_menu().
19 */
20 function secondlife_menu() {
21 $items['admin/settings/secondlife'] = array(
22 'title' => t('Second Life'),
23 'description' => t('Settings for the Second Life Framework module.'),
24 'page callback' => 'drupal_get_form',
25 'page arguments' => array('secondlife_settings'),
26 'access arguments' => array('administer site configuration'),
27 'type' => MENU_NORMAL_ITEM,
28 );
29
30 $items['secondlife'] = array(
31 'page callback' => 'secondlife_request',
32 'access callback' => TRUE,
33 'type' => MENU_LOCAL_TASK
34 );
35 return $items;
36 }
37
38 function secondlife_settings() {
39 $options = array(
40 0 => t('User page'),
41 1 => t('Referrals page'),
42 );
43
44 $form[SECONDLIFE_SETTINGS_DEBUG] = array(
45 '#type' => 'textfield',
46 '#title' => t('Debugging enabled?'),
47 '#default_value' => variable_get(SECONDLIFE_SETTINGS_DEBUG, ''),
48 '#description' => t('Enable debugging output of server/client interactions. Enter the full path name of the file to write the debugging output to, such as /tmp/secondlife.debug. It must be writable to the user who runs your web server. Leave blank for no debugging'),
49 );
50
51 $form[SECONDLIFE_SETTINGS_TIMER] = array(
52 '#type' => 'radios',
53 '#title' => t('Enable timing of requests?'),
54 '#default_value' => variable_get(SECONDLIFE_SETTINGS_TIMER, 0),
55 '#options' => array( 0 => t('Disabled'), 1 => t('Enabled') ),
56 '#description' => t('Select whether you want to record timing information for how much it takes to process requests from the clients. A "timer=" is send with the response to the client, and if also writting to the debugging output (if enabled).'),
57 );
58
59 return system_settings_form($form);
60 }
61
62 function secondlife_request() {
63 if (secondlife_timer()) {
64 $start = _secondlife_getmillisecs();
65 }
66
67 $sl = secondlife_get_session();
68
69 $dispatcher = $sl->app . '_dispatch';
70 if ($sl->app && $sl->cmd && function_exists($dispatcher)) {
71 $args = secondlife_parse_args($sl->arg);
72 module_invoke($sl->app, 'dispatch', $sl->cmd, $sl, $args);
73 }
74 else {
75 $sl->response['status'] = FALSE;
76 $sl->response['message'] = "function $func does not exist";
77 }
78
79 if (secondlife_timer()) {
80 $end = _secondlife_getmillisecs();
81 $timer = $end - $start;
82 $sl->response['timer'] = round($timer * 1000, 3);
83 }
84
85 secondlife_send_response($sl);
86 }
87
88 function secondlife_get_session() {
89 foreach($_SERVER as $key => $value) {
90 secondlife_debug("SERVER: $key: $value");
91 }
92
93 foreach($_POST as $key => $value) {
94 secondlife_debug("POST: $key: $value");
95 }
96
97 $sl = new stdClass();
98
99 $sl->objectkey = $_SERVER['HTTP_X_SECONDLIFE_OBJECT_KEY'];
100 $sl->objectname = $_SERVER['HTTP_X_SECONDLIFE_OBJECT_NAME'];
101 $sl->ownerkey = $_SERVER['HTTP_X_SECONDLIFE_OWNER_KEY'];
102 $sl->ownername = $_SERVER['HTTP_X_SECONDLIFE_OWNER_NAME'];
103 $sl->region = $_SERVER['HTTP_X_SECONDLIFE_REGION'];
104 $sl->position = $_SERVER['HTTP_X_SECONDLIFE_LOCAL_POSITION'];
105 $sl->app = $_POST['app'];
106 $sl->cmd = $_POST['cmd'];
107 $sl->arg = $_POST['arg'];
108
109 preg_match_all('/(.*) \((\d+), (\d+)\)/', $sl->region, $temp);
110 $sl->region_name = $temp[1][0];
111 $sl->region_x = $temp[2][0];
112 $sl->region_y = $temp[3][0];
113
114 preg_match_all('/\((.*), (.*), (.*)\)/', $sl->position, $temp);
115 $sl->position_x = $temp[1][0];
116 $sl->position_y = $temp[2][0];
117 $sl->position_z = $temp[3][0];
118
119 secondlife_debug("SL: " . print_r($sl, TRUE) . "\n", FILE_APPEND);
120
121 return $sl;
122 }
123
124 function secondlife_parse_args($arg) {
125 $args = array();
126 foreach(explode(':', $arg) as $pair) {
127 list($key, $value) = explode('=', $pair);
128 $args[$key] = $value;
129 secondlife_debug("ARGS: $key=$value");
130 }
131
132 return $args;
133 }
134
135 function secondlife_send_response(&$sl) {
136 $sl->response['app'] = $sl->app;
137 $sl->response['cmd'] = $sl->cmd;
138
139 foreach($sl->response as $key => $value) {
140 secondlife_debug("RESPONSE: $key = $value");
141 }
142
143 foreach($sl->response as $key => $value) {
144 print "$key=$value:";
145 }
146 print "\n";
147 }
148
149 function secondlife_debug($string) {
150 $debug = variable_get('secondlife_debug', '');
151 if ($debug) {
152 file_put_contents($debug, "$string\n", FILE_APPEND);
153 }
154 }
155
156 function secondlife_timer() {
157 $timer = variable_get('secondlife_timer', '');
158 if ($timer) {
159 return TRUE;
160 }
161 return FALSE;
162 }
163
164 function _secondlife_getmillisecs()
165 {
166 list($usec, $sec) = explode (' ', microtime());
167 return (double) $sec + $usec;
168 }

  ViewVC Help
Powered by ViewVC 1.1.2