예제 #1
0
function homeagent_handler($path_tail, $data)
{
    $userid = $path_tail[0];
    $osd = decode_recursive_json($data);
    $gatekeeper_host = $osd['gatekeeper_host'];
    $gatekeeper_port = $osd['gatekeeper_port'];
    $dest_x = $osd['destination_x'];
    $dest_y = $osd['destination_y'];
    if ($dest_x == null) {
        $dest_x = 0;
    }
    if ($dest_y == null) {
        $dest_y = 0;
    }
    $dest_uuid = $osd['destination_uuid'];
    #$dest_name = $osd['destination_name'];
    $scene = get_scene($dest_uuid);
    if ($dest_uuid == null || $dest_name == null) {
        header("HTTP/1.1 400 Bad Request");
        echo "missing destination_name and/or destination_uuid";
        exit;
    }
    $caps_path = $osd['caps_path'];
    $username = $osd['first_name'] . ' ' . $osd['last_name'];
    $circuit_code = $osd['circuit_code'];
    $session_id = $osd['session_id'];
    $secure_session_id = $osd['secure_session_id'];
    $start_pos = $osd['start_pos'];
    $appearance = $osd['wearables'];
    $attachments = $osd['attachments'];
    $result = create_opensim_presence($scene, $userid, $circuit_code, $username, $appearance, $attachments, $session_id, $secure_session_id, $start_pos, $caps_path);
    echo "{'success': {$result}, 'reason': 'no reason set lol'}";
    exit;
}
 function simulator_details($scene_id)
 {
     $scene = $this->get_scene($scene_id);
     if ($scene == null) {
         return null;
     }
     $url = $scene['Address'] . "monitorstats/{$scene_id}";
     $url2 = $scene['Address'] . "jsonSimStats";
     $result = $this->ci->curl->simple_get($url);
     if ($result == null) {
         log_message('debug', "Unable to retrieve simulator stats from {$url}");
         return null;
     }
     $result2 = $this->ci->curl->simple_get($url2);
     $json_result = array();
     if ($result2 == null) {
         log_message('debug', "Unable to retrieve instance information from {$result2}");
         $json_result['Version'] = "??";
         $json_result['Uptime'] = "??";
     } else {
         $json_result = decode_recursive_json($result2);
     }
     $xml = new SimpleXMLElement($result);
     $result = array('simulation_fps' => $xml->SimFPSMonitor, 'physics_fps' => $xml->PhysicsFPSMonitor, 'version' => $json_result['Version'], 'uptime' => $json_result['Uptime'], 'dilation' => $xml->TimeDilationMonitor, 'prim_count' => $xml->ObjectCountMonitor, 'agents' => $xml->AgentCountMonitor, 'child_agents' => $xml->ChildAgentCountMonitor);
     return $result;
 }
function decode_recursive_json($json)
{
    if (is_string($json)) {
        $response = json_decode($json, TRUE);
    } else {
        if (is_array($json)) {
            $response = $json;
        } else {
            return $json;
        }
    }
    if ($response == null || !is_array($response)) {
        return $json;
    }
    foreach ($response as $key => $value) {
        $response[$key] = decode_recursive_json($value);
    }
    return $response;
}
function webservice_post($url, $params, $jsonRequest = FALSE)
{
    // Parse the RequestMethod out of the request for debugging purposes
    if (isset($params['RequestMethod'])) {
        $requestMethod = $params['RequestMethod'];
    } else {
        $requestMethod = '';
    }
    if (empty($url)) {
        log_message('error', "Canceling {$requestMethod} POST to an empty URL");
        return array('Message' => 'Web service URL is not configured');
    }
    $options = array();
    if ($jsonRequest) {
        $params = json_encode($params);
        $options[CURLOPT_HTTPHEADER] = array('Content-Type: application/json');
    }
    // POST our query and fetch the response
    $curl = new Curl();
    $response = $curl->simple_post($url, $params, $options);
    // JSON decode the response
    $response = decode_recursive_json($response);
    if (!isset($response)) {
        $response = array('Message' => 'Invalid or missing response');
    }
    return $response;
}
function homeagent_handler($path_tail, $data)
{
    log_message('info', "[hypergrid] homeagent_handler called");
    $data = decodedata($data);
    $userid = $path_tail[0];
    log_message('info', "homeagent_handler called for {$userid} with {$data}");
    $osd = decode_recursive_json($data);
    if ($osd == null) {
        log_message('error', sprintf('[hypergrid] failed to decode foreignagent json string %s', $data));
        sendresponse(false, 'failed to decode foreignagent string');
    }
    $gatekeeper_uri = $osd['gatekeeper_serveruri'];
    if (!isset($osd['destination_x'])) {
        $osd['destination_x'] = 128;
    }
    if (!isset($osd['destination_y'])) {
        $osd['destination_y'] = 128;
    }
    if (!isset($osd['client_ip'])) {
        $session = get_session($userid);
        if (!isset($session['ExtraData']['ClientIP'])) {
            log_message('warn', "[hypergrid] no client ip found in session, this is going to fail");
            sendresponse(false, 'no client ip found in the session');
        }
        $osd['client_ip'] = $session['ExtraData']['ClientIP'];
    }
    if (!isset($osd['service_session_id'])) {
        log_message('debug', 'missing service_session_id, generating a new one');
        $osd['service_session_id'] = $gatekeeper_uri . ';' . UUID::Random();
    }
    /* $dest_uuid = $osd['destination_uuid']; */
    /* $caps_path = $osd['caps_path']; */
    /* $username = $osd['first_name'] . ' ' . $osd['last_name']; */
    /* $circuit_code = $osd['circuit_code']; */
    /* $session_id = $osd['session_id']; */
    /* $secure_session_id = $osd['secure_session_id']; */
    /* $start_pos = $osd['start_pos']; */
    /* $appearance = $osd['packed_appearance']; */
    /* $server_uri = $osd['destination_serveruri']; */
    $data = json_encode($osd);
    log_message('info', "[hypergrid] login to region with {$data}");
    $result = array();
    if (hg_login($gatekeeper_uri, $userid, $data, $yourip)) {
        $result['success'] = true;
        $result['reason'] = "success";
        $result['your_ip'] = $yourip;
        //echo '{"success": true, "reason": "success"}';
    } else {
        $result['success'] = false;
        $result['reason'] = "hypergrid login failed";
        $result['your_ip'] = $yourip;
        // echo '{"success": false, "reason": "hypergrid login failed"}';
    }
    $jresult = json_encode($result);
    log_message('info', "[hypergrid] homeagent returns {$jresult}");
    echo $jresult;
    exit;
}
function _facebook_graph_get($url_suffix, $token = null, $ci)
{
    $ci->load->library('Curl');
    $url = "https://graph.facebook.com/{$url_suffix}";
    if ($token != null) {
        $url = $url . "?access_token={$token}";
    }
    return decode_recursive_json($ci->curl->simple_get($url));
}
예제 #7
0
 function simulator_details($scene_id)
 {
     $scene = $this->get_scene($scene_id);
     if ($scene == null) {
         return null;
     }
     $url = $scene['Address'] . 'jsonSimStats/';
     $result = $this->ci->curl->simple_get($url);
     if ($result == null) {
         log_message('debug', "Unable to retrieve simulator stats from {$url}");
         return null;
     }
     $details = decode_recursive_json($result);
     $result = array('simulation_fps' => $details['SimFPS'], 'physics_fps' => $details['PhyFPS'], 'version' => $details['Version'], 'uptime' => $details['Uptime'], 'dilation' => $details['Dilatn'], 'prim_count' => $details['Prims'], 'agents' => $details['RootAg'], 'child_agents' => $details['ChldAg']);
     return $result;
 }