-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
87 lines (78 loc) · 2.62 KB
/
register.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* register.php
*
* Script called by the simulator to register on the search engine. Actual data
* fetch is processed by parser.php.
*
* Requires OpenSimulator Search module
* [OpenSimSearch](https://github.com/kcozens/OpenSimSearch)
* Events are fetched from 2do HYPEvents or any other HYPEvents implementation
* [2do HYPEvents](https://2do.directory)
*
* @package magicoli/opensim-helpers
* @author Gudule Lapointe <gudule@speculoos.world>
* @link https://github.com/magicoli/opensim-helpers
* @license AGPLv3
*
* Includes portions of code from
* [OpenSimSearch](https://github.com/kcozens/OpenSimSearch)
*/
require_once 'includes/config.php';
require_once 'includes/search.php';
$host = $_GET['host'];
$port = $_GET['port'];
$service = $_GET['service'];
if ( $host == '' || $port == '' ) {
header( 'HTTP/1.0 400 Bad Request' );
echo "400 Bad Request: missing region host and/or port\n";
exit;
}
switch ( $service ) {
case 'online':
// Check if there is already a database row for this host
$query = $SearchDB->prepare( 'SELECT register FROM hostsregister WHERE host = :host AND port = :port' );
$query->execute(
array(
':host' => $host,
':port' => $port,
)
);
// Get the request time as a timestamp for later
$timestamp = $_SERVER['REQUEST_TIME'];
// If a database row was returned check the nextcheck date
if ( $query->rowCount() > 0 ) {
$query = $SearchDB->prepare(
'UPDATE hostsregister
SET register = :timestamp, nextcheck = 0, checked = 0, failcounter = 0
WHERE host = :host AND port = :port'
);
} else {
// The SELECT did not return a result. Insert a new record.
$query = $SearchDB->prepare( "INSERT INTO hostsregister VALUES (:host, :port, :timestamp, 0, 0, 0, '')" );
// $query->execute( array($host, $port, $timestamp) );
}
$query->execute(
array(
':host' => $host,
':port' => $port,
':timestamp' => $timestamp,
)
);
// Trigger parser for new host
dontwait(); // make sure simulator doesn't pause start process
sleep( 2 ); // leave simulator start process some time before querying it
$parser = "{$_SERVER['REQUEST_SCHEME']}://{$_SERVER['HTTP_HOST']}" . dirname( $_SERVER['REQUEST_URI'] ) . '/parser.php';
$result = file_get_contents( $parser );
break;
case 'offline':
ossearch_hostUnregister( $host, $port );
break;
}
if ( is_array( SEARCH_REGISTRARS ) & ! empty( $hostname ) & ! empty( $port ) & ! empty( $service ) ) {
$querystring = getenv( 'QUERY_STRING' );
foreach ( SEARCH_REGISTRARS as $registrar ) {
$result = file_get_contents( "$registrar?$querystring" );
}
}
die;