diff options
author | Adam Frisby | 2008-03-25 16:29:54 +0000 |
---|---|---|
committer | Adam Frisby | 2008-03-25 16:29:54 +0000 |
commit | 8c05b81d6860d8e0da4098cc6f59f630d7c53037 (patch) | |
tree | 3325e09660ee8ad5a12cc19c8da6c4bd8bff5c21 /share/perl/lib/OpenSim | |
parent | * On Ray casting. Now returning the face normal of the collision face. (diff) | |
download | opensim-SC_OLD-8c05b81d6860d8e0da4098cc6f59f630d7c53037.zip opensim-SC_OLD-8c05b81d6860d8e0da4098cc6f59f630d7c53037.tar.gz opensim-SC_OLD-8c05b81d6860d8e0da4098cc6f59f630d7c53037.tar.bz2 opensim-SC_OLD-8c05b81d6860d8e0da4098cc6f59f630d7c53037.tar.xz |
* Committing Lulurun's Cgi/Perl implementation of the UGAI servers.
* I love you long time.
Diffstat (limited to '')
-rw-r--r-- | share/perl/lib/OpenSim/AssetServer.pm | 87 | ||||
-rw-r--r-- | share/perl/lib/OpenSim/AssetServer/AssetManager.pm | 34 | ||||
-rw-r--r-- | share/perl/lib/OpenSim/AssetServer/Config.pm | 24 | ||||
-rw-r--r-- | share/perl/lib/OpenSim/Config.pm | 41 | ||||
-rw-r--r-- | share/perl/lib/OpenSim/GridServer.pm | 208 | ||||
-rw-r--r-- | share/perl/lib/OpenSim/GridServer/Config.pm | 50 | ||||
-rw-r--r-- | share/perl/lib/OpenSim/GridServer/GridManager.pm | 57 | ||||
-rw-r--r-- | share/perl/lib/OpenSim/InventoryServer.pm | 249 | ||||
-rw-r--r-- | share/perl/lib/OpenSim/InventoryServer/Config.pm | 51 | ||||
-rw-r--r-- | share/perl/lib/OpenSim/InventoryServer/InventoryManager.pm | 86 | ||||
-rw-r--r-- | share/perl/lib/OpenSim/UserServer.pm | 239 | ||||
-rw-r--r-- | share/perl/lib/OpenSim/UserServer/Config.pm | 125 | ||||
-rw-r--r-- | share/perl/lib/OpenSim/UserServer/UserManager.pm | 49 | ||||
-rw-r--r-- | share/perl/lib/OpenSim/Utility.pm | 155 |
14 files changed, 1455 insertions, 0 deletions
diff --git a/share/perl/lib/OpenSim/AssetServer.pm b/share/perl/lib/OpenSim/AssetServer.pm new file mode 100644 index 0000000..6418166 --- /dev/null +++ b/share/perl/lib/OpenSim/AssetServer.pm | |||
@@ -0,0 +1,87 @@ | |||
1 | package OpenSim::AssetServer; | ||
2 | |||
3 | use strict; | ||
4 | use MIME::Base64; | ||
5 | use XML::Simple; | ||
6 | use OpenSim::Utility; | ||
7 | use OpenSim::AssetServer::AssetManager; | ||
8 | |||
9 | # !! | ||
10 | # TODO: delete asset | ||
11 | # | ||
12 | |||
13 | sub getAsset { | ||
14 | my ($asset_id, $param) = @_; | ||
15 | # get asset | ||
16 | my $asset_id_string = &OpenSim::Utility::UUID2HEX($asset_id); | ||
17 | my $asset = &OpenSim::AssetServer::AssetManager::getAssetByUUID($asset_id_string); | ||
18 | $asset->{assetUUID} = $asset_id; | ||
19 | # make response | ||
20 | return &_asset_to_xml($asset); | ||
21 | } | ||
22 | |||
23 | sub saveAsset { | ||
24 | my $xml = shift; | ||
25 | my $asset = &_xml_to_asset($xml); | ||
26 | &OpenSim::AssetServer::AssetManager::saveAsset($asset); | ||
27 | return ""; # TODO: temporary solution of "success!" | ||
28 | } | ||
29 | |||
30 | # ################## | ||
31 | # private functions | ||
32 | sub _asset_to_xml { | ||
33 | my $asset = shift; | ||
34 | my $asset_data = &MIME::Base64::encode_base64($asset->{data}); | ||
35 | return << "ASSET_XML"; | ||
36 | <AssetBase> | ||
37 | <Data> | ||
38 | $asset_data | ||
39 | </Data> | ||
40 | <FullID> | ||
41 | <UUID>$asset->{assetUUID}</UUID> | ||
42 | </FullID> | ||
43 | <Type>$asset->{assetType}</Type> | ||
44 | <InvType>$asset->{invType}</InvType> | ||
45 | <Name>$asset->{name}</Name> | ||
46 | <Description>$asset->{description}</Description> | ||
47 | <Local>$asset->{local}</Local> | ||
48 | <Temporary>$asset->{temporary}</Temporary> | ||
49 | </AssetBase> | ||
50 | ASSET_XML | ||
51 | } | ||
52 | |||
53 | sub _xml_to_asset { | ||
54 | my $xml = shift; | ||
55 | my $xs = new XML::Simple(); | ||
56 | my $obj = $xs->XMLin($xml); | ||
57 | print STDERR $obj->{FullID}->{UUID} . "\n"; | ||
58 | my %asset = ( | ||
59 | "id" => &OpenSim::Utility::UUID2BIN($obj->{FullID}->{UUID}), | ||
60 | "name" => $obj->{Name}, | ||
61 | "description" => $obj->{Description}, | ||
62 | "assetType" => $obj->{Type}, | ||
63 | "invType" => $obj->{InvType}, | ||
64 | "local" => $obj->{Local}, | ||
65 | "temporary" => $obj->{Temporary}, | ||
66 | "data" => &MIME::Base64::decode_base64($obj->{Data}), | ||
67 | ); | ||
68 | return \%asset; | ||
69 | } | ||
70 | |||
71 | 1; | ||
72 | |||
73 | __END__ | ||
74 | |||
75 | { | ||
76 | Data => "PFNjZW5lT2JqZWN0R3JvdXA+PFJvb3RQYXJ0PjxTY2VuZU9iamVjdFBhcnQgeG1sbnM6eHNpPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYS1pbnN0YW5jZSIgeG1sbnM6eHNkPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYSI+PExhc3RPd25lcklEPjxVVUlEPmI5Y2I1OGU4LWYzYzktNGFmNS1iZTQ3LTAyOTc2MmJhYTY4ZjwvVVVJRD48L0xhc3RPd25lcklEPjxPd25lcklEPjxVVUlEPmI5Y2I1OGU4LWYzYzktNGFmNS1iZTQ3LTAyOTc2MmJhYTY4ZjwvVVVJRD48L093bmVySUQ+PEdyb3VwSUQ+PFVVSUQ+MDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDAwPC9VVUlEPjwvR3JvdXBJRD48T3duZXJzaGlwQ29zdD4wPC9Pd25lcnNoaXBDb3N0PjxPYmplY3RTYWxlVHlwZT4wPC9PYmplY3RTYWxlVHlwZT48U2FsZVByaWNlPjA8L1NhbGVQcmljZT48Q2F0ZWdvcnk+MDwvQ2F0ZWdvcnk+PENyZWF0aW9uRGF0ZT4xMTk4NjQ5MjA5PC9DcmVhdGlvbkRhdGU+PFBhcmVudElEPjA8L1BhcmVudElEPjxPd25lck1hc2s+NTI2MDUzNjkyPC9Pd25lck1hc2s+PE5leHRPd25lck1hc2s+MjU3NDg3MTMyPC9OZXh0T3duZXJNYXNrPjxHcm91cE1hc2s+MDwvR3JvdXBNYXNrPjxFdmVyeW9uZU1hc2s+MDwvRXZlcnlvbmVNYXNrPjxCYXNlTWFzaz4yMTQ3NDgzNjQ3PC9CYXNlTWFzaz48Q3JlYXRvcklEPjxVVUlEPmI5Y2I1OGU4LWYzYzktNGFmNS1iZTQ3LTAyOTc2MmJhYTY4ZjwvVVVJRD48L0NyZWF0b3JJRD48VVVJRD48VVVJRD5hMGY3NmQzYi02MTlkLTRjNjktODVmOS0zNzhjMDExZDg2NzI8L1VVSUQ+PC9VVUlEPjxMb2NhbElEPjcwMjAwMTwvTG9jYWxJRD48TmFtZT5QcmltaXRpdmU8L05hbWU+PE9iamVjdEZsYWdzPjY1NjY2PC9PYmplY3RGbGFncz48TWF0ZXJpYWw+MDwvTWF0ZXJpYWw+PFJlZ2lvbkhhbmRsZT4xMDk5NTExNjI4MDMyMDAwPC9SZWdpb25IYW5kbGU+PEdyb3VwUG9zaXRpb24+PFg+MTMwLjA5OTQ8L1g+PFk+MTI4LjcxNTQ8L1k+PFo+MjEuMzM1NTI8L1o+PC9Hcm91cFBvc2l0aW9uPjxPZmZzZXRQb3NpdGlvbj48WD4wPC9YPjxZPjA8L1k+PFo+MDwvWj48L09mZnNldFBvc2l0aW9uPjxSb3RhdGlvbk9mZnNldD48WD4wPC9YPjxZPjA8L1k+PFo+MDwvWj48Vz4xPC9XPjwvUm90YXRpb25PZmZzZXQ+PFZlbG9jaXR5PjxYPjA8L1g+PFk+MDwvWT48Wj4wPC9aPjwvVmVsb2NpdHk+PFJvdGF0aW9uYWxWZWxvY2l0eT48WD4wPC9YPjxZPjA8L1k+PFo+MDwvWj48L1JvdGF0aW9uYWxWZWxvY2l0eT48QW5ndWxhclZlbG9jaXR5PjxYPjA8L1g+PFk+MDwvWT48Wj4wPC9aPjwvQW5ndWxhclZlbG9jaXR5PjxBY2NlbGVyYXRpb24+PFg+MDwvWD48WT4wPC9ZPjxaPjA8L1o+PC9BY2NlbGVyYXRpb24+PERlc2NyaXB0aW9uIC8+PENvbG9yIC8+PFRleHQgLz48U2l0TmFtZSAvPjxUb3VjaE5hbWUgLz48TGlua051bT4wPC9MaW5rTnVtPjxDbGlja0FjdGlvbj4wPC9DbGlja0FjdGlvbj48U2hhcGU+PFN0YXRlPjA8L1N0YXRlPjxQQ29kZT45PC9QQ29kZT48UGF0aEJlZ2luPjA8L1BhdGhCZWdpbj48UGF0aEVuZD4wPC9QYXRoRW5kPjxQYXRoU2NhbGVYPjIwMDwvUGF0aFNjYWxlWD48UGF0aFNjYWxlWT4yMDA8L1BhdGhTY2FsZVk+PFBhdGhTaGVhclg+MDwvUGF0aFNoZWFyWD48UGF0aFNoZWFyWT4wPC9QYXRoU2hlYXJZPjxQYXRoU2tldz4wPC9QYXRoU2tldz48UHJvZmlsZUJlZ2luPjA8L1Byb2ZpbGVCZWdpbj48UHJvZmlsZUVuZD4wPC9Qcm9maWxlRW5kPjxTY2FsZT48WD4wLjU8L1g+PFk+MC41PC9ZPjxaPjAuNTwvWj48L1NjYWxlPjxQYXRoQ3VydmU+MTY8L1BhdGhDdXJ2ZT48UHJvZmlsZUN1cnZlPjA8L1Byb2ZpbGVDdXJ2ZT48UHJvZmlsZUhvbGxvdz4wPC9Qcm9maWxlSG9sbG93PjxQYXRoUmFkaXVzT2Zmc2V0PjA8L1BhdGhSYWRpdXNPZmZzZXQ+PFBhdGhSZXZvbHV0aW9ucz4wPC9QYXRoUmV2b2x1dGlvbnM+PFBhdGhUYXBlclg+MDwvUGF0aFRhcGVyWD48UGF0aFRhcGVyWT4wPC9QYXRoVGFwZXJZPjxQYXRoVHdpc3Q+MDwvUGF0aFR3aXN0PjxQYXRoVHdpc3RCZWdpbj4wPC9QYXRoVHdpc3RCZWdpbj48VGV4dHVyZUVudHJ5PkFBQUFBQUFBQUFDWm1RQUFBQUFBQlFBQUFBQUFBQUFBZ0Q4QUFBQ0FQd0FBQUFBQUFBQUFBQUFBQUFBPTwvVGV4dHVyZUVudHJ5PjxFeHRyYVBhcmFtcz5BQT09PC9FeHRyYVBhcmFtcz48UHJvZmlsZVNoYXBlPkNpcmNsZTwvUHJvZmlsZVNoYXBlPjwvU2hhcGU+PFNjYWxlPjxYPjAuNTwvWD48WT4wLjU8L1k+PFo+MC41PC9aPjwvU2NhbGU+PFVwZGF0ZUZsYWc+MDwvVXBkYXRlRmxhZz48L1NjZW5lT2JqZWN0UGFydD48L1Jvb3RQYXJ0PjxPdGhlclBhcnRzIC8+PC9TY2VuZU9iamVjdEdyb3VwPgA=", | ||
77 | Description => {}, | ||
78 | FullID => { UUID => "feb7e249-e462-499f-a881-553b9829539a" }, | ||
79 | InvType => 6, | ||
80 | Local => "false", | ||
81 | Name => "Primitive", | ||
82 | Temporary => "false", | ||
83 | Type => 6, | ||
84 | "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema", | ||
85 | "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", | ||
86 | } | ||
87 | |||
diff --git a/share/perl/lib/OpenSim/AssetServer/AssetManager.pm b/share/perl/lib/OpenSim/AssetServer/AssetManager.pm new file mode 100644 index 0000000..f36ab1a --- /dev/null +++ b/share/perl/lib/OpenSim/AssetServer/AssetManager.pm | |||
@@ -0,0 +1,34 @@ | |||
1 | package OpenSim::AssetServer::AssetManager; | ||
2 | |||
3 | use strict; | ||
4 | use Carp; | ||
5 | use OpenSim::Utility; | ||
6 | use OpenSim::AssetServer::Config; | ||
7 | |||
8 | |||
9 | sub getAssetByUUID { | ||
10 | my $uuid = shift; | ||
11 | my $result = &OpenSim::Utility::getSimpleResult($OpenSim::AssetServer::Config::SYS_SQL{select_asset_by_uuid}, $uuid); | ||
12 | my $count = @$result; | ||
13 | if ($count > 0) { | ||
14 | return $result->[0]; | ||
15 | } | ||
16 | Carp::croak("can not find asset($uuid)"); | ||
17 | } | ||
18 | |||
19 | sub saveAsset { | ||
20 | my $asset = shift; | ||
21 | my $result = &OpenSim::Utility::getSimpleResult( | ||
22 | $OpenSim::AssetServer::Config::SYS_SQL{insert_asset}, | ||
23 | $asset->{id}, | ||
24 | $asset->{name}, | ||
25 | $asset->{description}, | ||
26 | $asset->{assetType}, | ||
27 | $asset->{invType}, | ||
28 | $asset->{"local"}, | ||
29 | $asset->{temporary}, | ||
30 | $asset->{data} | ||
31 | ); | ||
32 | } | ||
33 | |||
34 | 1; | ||
diff --git a/share/perl/lib/OpenSim/AssetServer/Config.pm b/share/perl/lib/OpenSim/AssetServer/Config.pm new file mode 100644 index 0000000..5598921 --- /dev/null +++ b/share/perl/lib/OpenSim/AssetServer/Config.pm | |||
@@ -0,0 +1,24 @@ | |||
1 | package OpenSim::AssetServer::Config; | ||
2 | |||
3 | use strict; | ||
4 | |||
5 | our %SYS_SQL = ( | ||
6 | select_asset_by_uuid => | ||
7 | "SELECT * FROM assets WHERE id=X?", | ||
8 | insert_asset => | ||
9 | "INSERT INTO assets VALUES (?,?,?,?,?,?,?,?)" | ||
10 | ); | ||
11 | |||
12 | |||
13 | our @ASSETS_COLUMNS = ( | ||
14 | "id", | ||
15 | "name", | ||
16 | "description", | ||
17 | "assetType", | ||
18 | "invType", | ||
19 | "local", | ||
20 | "temporary", | ||
21 | "data", | ||
22 | ); | ||
23 | |||
24 | 1; | ||
diff --git a/share/perl/lib/OpenSim/Config.pm b/share/perl/lib/OpenSim/Config.pm new file mode 100644 index 0000000..246ef26 --- /dev/null +++ b/share/perl/lib/OpenSim/Config.pm | |||
@@ -0,0 +1,41 @@ | |||
1 | package OpenSim::Config; | ||
2 | |||
3 | # REGION keys | ||
4 | our $SIM_RECV_KEY = ""; | ||
5 | our $SIM_SEND_KEY = ""; | ||
6 | # ASSET server url | ||
7 | #our $ASSET_SERVER_URL = "http://127.0.0.1:8003/"; | ||
8 | our $ASSET_SERVER_URL = "http://opensim.wolfdrawer.net:80/asset.cgi"; | ||
9 | our $ASSET_RECV_KEY = ""; | ||
10 | our $ASSET_SEND_KEY = ""; | ||
11 | # USER server url | ||
12 | #our $USER_SERVER_URL = "http://127.0.0.1:8001/"; | ||
13 | our $USER_SERVER_URL = "http://opensim.wolfdrawer.net:80/user.cgi"; | ||
14 | our $USER_RECV_KEY = ""; | ||
15 | our $USER_SEND_KEY = ""; | ||
16 | # GRID server url | ||
17 | #our $GRID_SERVER_URL = "http://127.0.0.1:8001/"; | ||
18 | our $GRID_SERVER_URL = "http://opensim.wolfdrawer.net:80/grid.cgi"; | ||
19 | our $GRID_RECV_KEY = ""; | ||
20 | our $GRID_SEND_KEY = ""; | ||
21 | # INVENTORY server url | ||
22 | #our $INVENTORY_SERVER_URL = "http://127.0.0.1:8004"; | ||
23 | our $INVENTORY_SERVER_URL = "http://opensim.wolfdrawer.net:80/inventory.cgi"; | ||
24 | # DB | ||
25 | our $DSN = "dbi:mysql:database=opensim;host=192.168.0.20"; | ||
26 | our $DBUSER = "lulu"; | ||
27 | our $DBPASS = "1234"; | ||
28 | |||
29 | # DEBUG LOG | ||
30 | our $DEBUG_LOGDIR = "/home/lulu/temp/opensim"; | ||
31 | |||
32 | # MSG | ||
33 | our %SYS_MSG = ( | ||
34 | FATAL => "You must have been eaten by a wolf.", | ||
35 | FAIL => "Late! There is a wolf behind you", | ||
36 | LOGIN_WELCOME => "Do you fear the wolf ?", | ||
37 | ); | ||
38 | |||
39 | |||
40 | 1; | ||
41 | |||
diff --git a/share/perl/lib/OpenSim/GridServer.pm b/share/perl/lib/OpenSim/GridServer.pm new file mode 100644 index 0000000..7b21cd8 --- /dev/null +++ b/share/perl/lib/OpenSim/GridServer.pm | |||
@@ -0,0 +1,208 @@ | |||
1 | package OpenSim::GridServer; | ||
2 | |||
3 | use strict; | ||
4 | use OpenSim::Utility; | ||
5 | use OpenSim::GridServer::Config; | ||
6 | use OpenSim::GridServer::GridManager; | ||
7 | |||
8 | sub getHandlerList { | ||
9 | my %list = ( | ||
10 | "simulator_login" => \&_simulator_login, | ||
11 | "simulator_data_request" => \&_simulator_data_request, | ||
12 | "map_block" => \&_map_block, | ||
13 | "map_block2" => \&_map_block2, # this is better for the Region Monitor | ||
14 | ); | ||
15 | return \%list; | ||
16 | } | ||
17 | |||
18 | # ################# | ||
19 | # XMLRPC Handlers | ||
20 | sub _simulator_login { | ||
21 | my $params = shift; | ||
22 | |||
23 | my $region_data = undef; | ||
24 | my %response = (); | ||
25 | if ($params->{"UUID"}) { | ||
26 | $region_data = &OpenSim::GridServer::GridManager::getRegionByUUID($params->{"UUID"}); | ||
27 | } elsif ($params->{"region_handle"}) { | ||
28 | $region_data = &OpenSim::GridServer::GridManager::getRegionByHandle($params->{"region_handle"}); | ||
29 | } else { | ||
30 | $response{"error"} = "No UUID or region_handle passed to grid server - unable to connect you"; | ||
31 | return \%response; | ||
32 | } | ||
33 | |||
34 | if (!$region_data) { | ||
35 | my %new_region_data = ( | ||
36 | uuid => undef, | ||
37 | regionHandle => OpenSim::Utility::UIntsToLong($params->{region_locx}*256, $params->{region_locx}*256), | ||
38 | regionName => $params->{sim_name}, | ||
39 | regionRecvKey => $OpenSim::Config::SIM_RECV_KEY, | ||
40 | regionSendKey => $OpenSim::Config::SIM_SEND_KEY, | ||
41 | regionSecret => $OpenSim::Config::SIM_RECV_KEY, | ||
42 | regionDataURI => "", | ||
43 | serverIP => $params->{sim_ip}, | ||
44 | serverPort => $params->{sim_port}, | ||
45 | serverURI => "http://" + $params->{sim_ip} + ":" + $params->{sim_port} + "/", | ||
46 | LocX => $params->{region_locx}, | ||
47 | LocY => $params->{region_locy}, | ||
48 | LocZ => 0, | ||
49 | regionAssetURI => $OpenSim::Config::ASSET_SERVER_URL, | ||
50 | regionAssetRecvKey => $OpenSim::Config::ASSET_RECV_KEY, | ||
51 | regionAssetSendKey => $OpenSim::Config::ASSET_SEND_KEY, | ||
52 | regionUserURI => $OpenSim::Config::USER_SERVER_URL, | ||
53 | regionUserRecvKey => $OpenSim::Config::USER_RECV_KEY, | ||
54 | regionUserSendKey => $OpenSim::Config::USER_SEND_KEY, | ||
55 | regionMapTextureID => $params->{"map-image-id"}, | ||
56 | serverHttpPort => $params->{http_port}, | ||
57 | serverRemotingPort => $params->{remoting_port}, | ||
58 | ); | ||
59 | eval { | ||
60 | &OpenSim::GridServer::GridManager::addRegion(\%new_region_data); | ||
61 | }; | ||
62 | if ($@) { | ||
63 | $response{"error"} = "unable to add region"; | ||
64 | return \%response; | ||
65 | } | ||
66 | $region_data = \%new_region_data; | ||
67 | } | ||
68 | |||
69 | my @region_neighbours_data = (); | ||
70 | my $region_list = &OpenSim::GridServer::GridManager::getRegionList($region_data->{locX}-1, $region_data->{locY}-1, $region_data->{locX}+1, $region_data->{locY}+1); | ||
71 | foreach my $region (@$region_list) { | ||
72 | next if ($region->{regionHandle} eq $region_data->{regionHandle}); | ||
73 | my %neighbour_block = ( | ||
74 | "sim_ip" => $region->{serverIP}, | ||
75 | "sim_port" => $region->{serverPort}, | ||
76 | "region_locx" => $region->{locX}, | ||
77 | "region_locy" => $region->{locY}, | ||
78 | "UUID" => $region->{uuid}, | ||
79 | "regionHandle" => $region->{regionHandle}, | ||
80 | ); | ||
81 | push @region_neighbours_data, \%neighbour_block; | ||
82 | } | ||
83 | |||
84 | %response = ( | ||
85 | UUID => $region_data->{uuid}, | ||
86 | region_locx => $region_data->{locX}, | ||
87 | region_locy => $region_data->{locY}, | ||
88 | regionname => $region_data->{regionName}, | ||
89 | estate_id => "1", # TODO ??? | ||
90 | neighbours => \@region_neighbours_data, | ||
91 | sim_ip => $region_data->{serverIP}, | ||
92 | sim_port => $region_data->{serverPort}, | ||
93 | asset_url => $region_data->{regionAssetURI}, | ||
94 | asset_recvkey => $region_data->{regionAssetRecvKey}, | ||
95 | asset_sendkey => $region_data->{regionAssetSendKey}, | ||
96 | user_url => $region_data->{regionUserURI}, | ||
97 | user_recvkey => $region_data->{regionUserRecvKey}, | ||
98 | user_sendkey => $region_data->{regionUserSendKey}, | ||
99 | authkey => $region_data->{regionSecret}, | ||
100 | data_uri => $region_data->{regionDataURI}, | ||
101 | "allow_forceful_banlines" => "TRUE", | ||
102 | ); | ||
103 | |||
104 | return \%response; | ||
105 | } | ||
106 | |||
107 | sub _simulator_data_request { | ||
108 | my $params = shift; | ||
109 | |||
110 | my $region_data = undef; | ||
111 | my %response = (); | ||
112 | if ($params->{"region_UUID"}) { | ||
113 | $region_data = &OpenSim::GridServer::GridManager::getRegionByUUID($params->{"region_UUID"}); | ||
114 | } elsif ($params->{"region_handle"}) { | ||
115 | $region_data = &OpenSim::GridServer::GridManager::getRegionByHandle($params->{"region_handle"}); | ||
116 | } | ||
117 | if (!$region_data) { | ||
118 | $response{"error"} = "Sim does not exist"; | ||
119 | return \%response; | ||
120 | } | ||
121 | |||
122 | $response{"sim_ip"} = $region_data->{serverIP}; | ||
123 | $response{"sim_port"} = $region_data->{serverPort}; | ||
124 | $response{"http_port"} = $region_data->{serverHttpPort}; | ||
125 | $response{"remoting_port"} = $region_data->{serverRemotingPort}; | ||
126 | $response{"region_locx"} = $region_data->{locX}; | ||
127 | $response{"region_locy"} = $region_data->{locY}; | ||
128 | $response{"region_UUID"} = $region_data->{uuid}; | ||
129 | $response{"region_name"} = $region_data->{regionName}; | ||
130 | $response{"regionHandle"} = $region_data->{regionHandle}; | ||
131 | |||
132 | return \%response; | ||
133 | } | ||
134 | |||
135 | sub _map_block { | ||
136 | my $params = shift; | ||
137 | |||
138 | my $xmin = $params->{xmin} || 980; | ||
139 | my $ymin = $params->{ymin} || 980; | ||
140 | my $xmax = $params->{xmax} || 1020; | ||
141 | my $ymax = $params->{ymax} || 1020; | ||
142 | |||
143 | my @sim_block_list = (); | ||
144 | my $region_list = &OpenSim::GridServer::GridManager::getRegionList($xmin, $ymin, $xmax, $ymax); | ||
145 | foreach my $region (@$region_list) { | ||
146 | my %sim_block = ( | ||
147 | "x" => $region->{locX}, | ||
148 | "y" => $region->{locY}, | ||
149 | "name" => $region->{regionName}, | ||
150 | "access" => 0, # TODO ? meaning unknown | ||
151 | "region-flags" => 0, # TODO ? unknown | ||
152 | "water-height" => 20, # TODO ? get from a XML | ||
153 | "agents" => 1, # TODO | ||
154 | "map-image-id" => $region->{regionMapTexture}, | ||
155 | "regionhandle" => $region->{regionHandle}, | ||
156 | "sim_ip" => $region->{serverIP}, | ||
157 | "sim_port" => $region->{serverPort}, | ||
158 | "sim_uri" => $region->{serverURI}, | ||
159 | "uuid" => $region->{uuid}, | ||
160 | "remoting_port" => $region->{serverRemotingPort}, | ||
161 | ); | ||
162 | push @sim_block_list, \%sim_block; | ||
163 | } | ||
164 | |||
165 | my %response = ( | ||
166 | "sim-profiles" => \@sim_block_list, | ||
167 | ); | ||
168 | return \%response; | ||
169 | } | ||
170 | |||
171 | sub _map_block2 { | ||
172 | my $params = shift; | ||
173 | |||
174 | my $xmin = $params->{xmin} || 980; | ||
175 | my $ymin = $params->{ymin} || 980; | ||
176 | my $xmax = $params->{xmax} || 1020; | ||
177 | my $ymax = $params->{ymax} || 1020; | ||
178 | |||
179 | my @sim_block_list = (); | ||
180 | my $region_list = &OpenSim::GridServer::GridManager::getRegionList2($xmin, $ymin, $xmax, $ymax); | ||
181 | foreach my $region (@$region_list) { | ||
182 | my %sim_block = ( | ||
183 | "x" => $region->{locX}, | ||
184 | "y" => $region->{locY}, | ||
185 | "name" => $region->{regionName}, | ||
186 | "access" => 0, # TODO ? meaning unknown | ||
187 | "region-flags" => 0, # TODO ? unknown | ||
188 | "water-height" => 20, # TODO ? get from a XML | ||
189 | "agents" => 1, # TODO | ||
190 | "map-image-id" => $region->{regionMapTexture}, | ||
191 | "regionhandle" => $region->{regionHandle}, | ||
192 | "sim_ip" => $region->{serverIP}, | ||
193 | "sim_port" => $region->{serverPort}, | ||
194 | "sim_uri" => $region->{serverURI}, | ||
195 | "uuid" => $region->{uuid}, | ||
196 | "remoting_port" => $region->{serverRemotingPort}, | ||
197 | ); | ||
198 | push @sim_block_list, \%sim_block; | ||
199 | } | ||
200 | |||
201 | my %response = ( | ||
202 | "sim-profiles" => \@sim_block_list, | ||
203 | ); | ||
204 | return \%response; | ||
205 | } | ||
206 | |||
207 | 1; | ||
208 | |||
diff --git a/share/perl/lib/OpenSim/GridServer/Config.pm b/share/perl/lib/OpenSim/GridServer/Config.pm new file mode 100644 index 0000000..dc72e5a --- /dev/null +++ b/share/perl/lib/OpenSim/GridServer/Config.pm | |||
@@ -0,0 +1,50 @@ | |||
1 | package OpenSim::GridServer::Config; | ||
2 | |||
3 | use strict; | ||
4 | |||
5 | our %SYS_SQL = ( | ||
6 | select_region_by_uuid => | ||
7 | "SELECT * FROM regions WHERE uuid=?", | ||
8 | select_region_by_handle => | ||
9 | "SELECT * FROM regions WHERE regionHandle=?", | ||
10 | select_region_list => | ||
11 | "SELECT * FROM regions WHERE locX>=? AND locX<? AND locY>=? AND locY<?", | ||
12 | select_region_list2 => | ||
13 | "SELECT * FROM regions WHERE locX>=? AND locX<? AND locY>=? AND locY<?", | ||
14 | insert_region => | ||
15 | "INSERT INTO regions VALUES (?????????)", | ||
16 | delete_all_regions => | ||
17 | "delete from regions", | ||
18 | ); | ||
19 | |||
20 | |||
21 | our @REGIONS_COLUMNS = ( | ||
22 | "uuid", | ||
23 | "regionHandle", | ||
24 | "regionName", | ||
25 | "regionRecvKey", | ||
26 | "regionSendKey", | ||
27 | "regionSecret", | ||
28 | "regionDataURI", | ||
29 | "serverIP", | ||
30 | "serverPort", | ||
31 | "serverURI", | ||
32 | "locX", | ||
33 | "locY", | ||
34 | "locZ", | ||
35 | "eastOverrideHandle", | ||
36 | "westOverrideHandle", | ||
37 | "southOverrideHandle", | ||
38 | "northOverrideHandle", | ||
39 | "regionAssetURI", | ||
40 | "regionAssetRecvKey", | ||
41 | "regionAssetSendKey", | ||
42 | "regionUserURI", | ||
43 | "regionUserRecvKey", | ||
44 | "regionUserSendKey", | ||
45 | "regionMapTexture", | ||
46 | "serverHttpPort", | ||
47 | "serverRemotingPort", | ||
48 | ); | ||
49 | |||
50 | 1; | ||
diff --git a/share/perl/lib/OpenSim/GridServer/GridManager.pm b/share/perl/lib/OpenSim/GridServer/GridManager.pm new file mode 100644 index 0000000..2170d74 --- /dev/null +++ b/share/perl/lib/OpenSim/GridServer/GridManager.pm | |||
@@ -0,0 +1,57 @@ | |||
1 | package OpenSim::GridServer::GridManager; | ||
2 | |||
3 | use strict; | ||
4 | use Carp; | ||
5 | use OpenSim::Utility; | ||
6 | use OpenSim::GridServer::Config; | ||
7 | |||
8 | sub getRegionByUUID { | ||
9 | my $uuid = shift; | ||
10 | my $result = &OpenSim::Utility::getSimpleResult($OpenSim::GridServer::Config::SYS_SQL{select_region_by_uuid}, $uuid); | ||
11 | my $count = @$result; | ||
12 | if ($count > 0) { | ||
13 | return $result->[0]; | ||
14 | } | ||
15 | Carp::croak("can not find region"); | ||
16 | } | ||
17 | |||
18 | sub getRegionByHandle { | ||
19 | my $handle = shift; | ||
20 | my $result = &OpenSim::Utility::getSimpleResult($OpenSim::GridServer::Config::SYS_SQL{select_region_by_handle}, $handle); | ||
21 | my $count = @$result; | ||
22 | if ($count > 0) { | ||
23 | return $result->[0]; | ||
24 | } | ||
25 | Carp::croak("can not find region # $handle"); | ||
26 | } | ||
27 | |||
28 | sub getRegionList { | ||
29 | my ($xmin, $ymin, $xmax, $ymax) = @_; | ||
30 | my $result = &OpenSim::Utility::getSimpleResult($OpenSim::GridServer::Config::SYS_SQL{select_region_list}, $xmin, $xmax, $ymin, $ymax); | ||
31 | my $count = @$result; | ||
32 | if ($count > 0) { | ||
33 | return $result; | ||
34 | } | ||
35 | Carp::croak("can not find region"); | ||
36 | } | ||
37 | |||
38 | sub getRegionList2 { | ||
39 | my ($xmin, $ymin, $xmax, $ymax) = @_; | ||
40 | my $result = &OpenSim::Utility::getSimpleResult($OpenSim::GridServer::Config::SYS_SQL{select_region_list2}, $xmin, $xmax, $ymin, $ymax); | ||
41 | my $count = @$result; | ||
42 | if ($count > 0) { | ||
43 | return $result; | ||
44 | } | ||
45 | Carp::croak("can not find region"); | ||
46 | } | ||
47 | |||
48 | sub deleteRegions { | ||
49 | my $result = &OpenSim::Utility::getSimpleResult($OpenSim::GridServer::Config::SYS_SQL{delete_all_regions}); | ||
50 | my $count = @$result; | ||
51 | if ($count > 0) { | ||
52 | return $result; | ||
53 | } | ||
54 | Carp::croak("failed to delete regions"); | ||
55 | } | ||
56 | |||
57 | 1; | ||
diff --git a/share/perl/lib/OpenSim/InventoryServer.pm b/share/perl/lib/OpenSim/InventoryServer.pm new file mode 100644 index 0000000..184e19a --- /dev/null +++ b/share/perl/lib/OpenSim/InventoryServer.pm | |||
@@ -0,0 +1,249 @@ | |||
1 | package OpenSim::InventoryServer; | ||
2 | |||
3 | use strict; | ||
4 | use XML::Serializer; | ||
5 | use OpenSim::Utility; | ||
6 | use OpenSim::Config; | ||
7 | use OpenSim::InventoryServer::Config; | ||
8 | use OpenSim::InventoryServer::InventoryManager; | ||
9 | |||
10 | my $METHOD_LIST = undef; | ||
11 | |||
12 | sub getHandlerList { | ||
13 | if (!$METHOD_LIST) { | ||
14 | my %list = ( | ||
15 | "GetInventory" => \&_get_inventory, | ||
16 | "CreateInventory" => \&_create_inventory, | ||
17 | "NewFolder" => \&_new_folder, | ||
18 | "MoveFolder" => \&_move_folder, | ||
19 | "NewItem" => \&_new_item, | ||
20 | "DeleteItem" => \&_delete_item, | ||
21 | "RootFolders" => \&_root_folders, | ||
22 | ); | ||
23 | $METHOD_LIST = \%list; | ||
24 | } | ||
25 | return $METHOD_LIST; | ||
26 | } | ||
27 | |||
28 | # ################# | ||
29 | # Handlers | ||
30 | sub _get_inventory { | ||
31 | my $post_data = shift; | ||
32 | my $uuid = &_get_uuid($post_data); | ||
33 | my $inventry_folders = &OpenSim::InventoryServer::InventoryManager::getUserInventoryFolders($uuid); | ||
34 | my @response_folders = (); | ||
35 | foreach (@$inventry_folders) { | ||
36 | my $folder = &_convert_to_response_folder($_); | ||
37 | push @response_folders, $folder; | ||
38 | } | ||
39 | my $inventry_items = &OpenSim::InventoryServer::InventoryManager::getUserInventoryItems($uuid); | ||
40 | my @response_items = (); | ||
41 | foreach (@$inventry_items) { | ||
42 | my $item = &_convert_to_response_item($_); | ||
43 | push @response_items, $item; | ||
44 | } | ||
45 | my $response_obj = { | ||
46 | Folders => { InventoryFolderBase => \@response_folders }, | ||
47 | AllItems => { InventoryItemBase => \@response_items }, | ||
48 | UserID => { UUID => $uuid }, | ||
49 | }; | ||
50 | my $serializer = new XML::Serializer( $response_obj, "InventoryCollection"); | ||
51 | return $serializer->to_formatted(XML::Serializer::WITH_HEADER); # TODO: | ||
52 | } | ||
53 | |||
54 | sub _create_inventory { | ||
55 | my $post_data = shift; | ||
56 | my $uuid = &_get_uuid($post_data); | ||
57 | my $InventoryFolders = &_create_default_inventory($uuid); | ||
58 | foreach (@$InventoryFolders) { | ||
59 | &OpenSim::InventoryServer::InventoryManager::saveInventoryFolder($_); | ||
60 | } | ||
61 | my $serializer = new XML::Serializer("true", "boolean"); | ||
62 | return $serializer->to_formatted(XML::Serializer::WITH_HEADER); # TODO: | ||
63 | } | ||
64 | |||
65 | sub _new_folder { | ||
66 | my $post_data = shift; | ||
67 | my $request_obj = &OpenSim::Utility::XML2Obj($post_data); | ||
68 | my $folder = &_convert_to_db_folder($request_obj); | ||
69 | &OpenSim::InventoryServer::InventoryManager::saveInventoryFolder($folder); | ||
70 | my $serializer = new XML::Serializer("true", "boolean"); | ||
71 | return $serializer->to_formatted(XML::Serializer::WITH_HEADER); # TODO: | ||
72 | } | ||
73 | |||
74 | sub _move_folder { | ||
75 | my $post_data = shift; | ||
76 | my $request_info = &OpenSim::Utility::XML2Obj($post_data); | ||
77 | &OpenSim::InventoryServer::InventoryManager::moveInventoryFolder($request_info); | ||
78 | my $serializer = new XML::Serializer("true", "boolean"); | ||
79 | return $serializer->to_formatted(XML::Serializer::WITH_HEADER); # TODO: | ||
80 | } | ||
81 | |||
82 | sub _new_item { | ||
83 | my $post_data = shift; | ||
84 | my $request_obj = &OpenSim::Utility::XML2Obj($post_data); | ||
85 | my $item = &_convert_to_db_item($request_obj); | ||
86 | &OpenSim::InventoryServer::InventoryManager::saveInventoryItem($item); | ||
87 | my $serializer = new XML::Serializer("true", "boolean"); | ||
88 | return $serializer->to_formatted(XML::Serializer::WITH_HEADER); # TODO: | ||
89 | } | ||
90 | |||
91 | sub _delete_item { | ||
92 | my $post_data = shift; | ||
93 | my $request_obj = &OpenSim::Utility::XML2Obj($post_data); | ||
94 | my $item_id = $request_obj->{inventoryID}->{UUID}; | ||
95 | &OpenSim::InventoryServer::InventoryManager::deleteInventoryItem($item_id); | ||
96 | my $serializer = new XML::Serializer("true", "boolean"); | ||
97 | return $serializer->to_formatted(XML::Serializer::WITH_HEADER); # TODO: | ||
98 | } | ||
99 | |||
100 | sub _root_folders { | ||
101 | my $post_data = shift; | ||
102 | my $uuid = &_get_uuid($post_data); | ||
103 | my $response = undef; | ||
104 | my $inventory_root_folder = &OpenSim::InventoryServer::InventoryManager::getRootFolder($uuid); | ||
105 | if ($inventory_root_folder) { | ||
106 | my $root_folder_id = $inventory_root_folder->{folderID}; | ||
107 | my $root_folder = &_convert_to_response_folder($inventory_root_folder); | ||
108 | my $root_folders = &OpenSim::InventoryServer::InventoryManager::getChildrenFolders($root_folder_id); | ||
109 | my @folders = ($root_folder); | ||
110 | foreach(@$root_folders) { | ||
111 | my $folder = &_convert_to_response_folder($_); | ||
112 | push @folders, $folder; | ||
113 | } | ||
114 | $response = { InventoryFolderBase => \@folders }; | ||
115 | } else { | ||
116 | $response = ""; # TODO: need better failed message | ||
117 | } | ||
118 | my $serializer = new XML::Serializer($response, "ArrayOfInventoryFolderBase"); | ||
119 | return $serializer->to_formatted(XML::Serializer::WITH_HEADER); # TODO: | ||
120 | } | ||
121 | |||
122 | # ################# | ||
123 | # subfunctions | ||
124 | sub _convert_to_db_item { | ||
125 | my $item = shift; | ||
126 | my $ret = { | ||
127 | inventoryID => $item->{inventoryID}->{UUID}, | ||
128 | assetID => $item->{assetID}->{UUID}, | ||
129 | assetType => $item->{assetType}, | ||
130 | invType => $item->{invType}, | ||
131 | parentFolderID => $item->{parentFolderID}->{UUID}, | ||
132 | avatarID => $item->{avatarID}->{UUID}, | ||
133 | creatorID => $item->{creatorsID}->{UUID}, # TODO: human error ??? | ||
134 | inventoryName => $item->{inventoryName}, | ||
135 | inventoryDescription => $item->{inventoryDescription} || "", | ||
136 | inventoryNextPermissions => $item->{inventoryNextPermissions}, | ||
137 | inventoryCurrentPermissions => $item->{inventoryCurrentPermissions}, | ||
138 | inventoryBasePermissions => $item->{inventoryBasePermissions}, | ||
139 | inventoryEveryOnePermissions => $item->{inventoryEveryOnePermissions}, | ||
140 | }; | ||
141 | return $ret; | ||
142 | } | ||
143 | |||
144 | sub _convert_to_response_item { | ||
145 | my $item = shift; | ||
146 | my $ret = { | ||
147 | inventoryID => { UUID => $item->{inventoryID} }, | ||
148 | assetID => { UUID => $item->{assetID} }, | ||
149 | assetType => $item->{assetType}, | ||
150 | invType => $item->{invType}, | ||
151 | parentFolderID => { UUID => $item->{parentFolderID} }, | ||
152 | avatarID => { UUID => $item->{avatarID} }, | ||
153 | creatorsID => { UUID => $item->{creatorID} }, # TODO: human error ??? | ||
154 | inventoryName => $item->{inventoryName}, | ||
155 | inventoryDescription => $item->{inventoryDescription} || "", | ||
156 | inventoryNextPermissions => $item->{inventoryNextPermissions}, | ||
157 | inventoryCurrentPermissions => $item->{inventoryCurrentPermissions}, | ||
158 | inventoryBasePermissions => $item->{inventoryBasePermissions}, | ||
159 | inventoryEveryOnePermissions => $item->{inventoryEveryOnePermissions}, | ||
160 | }; | ||
161 | return $ret; | ||
162 | } | ||
163 | |||
164 | sub _convert_to_db_folder { | ||
165 | my $folder = shift; | ||
166 | my $ret = { | ||
167 | folderName => $folder->{name}, | ||
168 | agentID => $folder->{agentID}->{UUID}, | ||
169 | parentFolderID => $folder->{parentID}->{UUID}, | ||
170 | folderID => $folder->{folderID}->{UUID}, | ||
171 | type => $folder->{type}, | ||
172 | version => $folder->{version}, | ||
173 | }; | ||
174 | return $ret; | ||
175 | } | ||
176 | |||
177 | sub _convert_to_response_folder { | ||
178 | my $folder = shift; | ||
179 | my $ret = { | ||
180 | name => $folder->{folderName}, | ||
181 | agentID => { UUID => $folder->{agentID} }, | ||
182 | parentID => { UUID => $folder->{parentFolderID} }, | ||
183 | folderID => { UUID => $folder->{folderID} }, | ||
184 | type => $folder->{type}, | ||
185 | version => $folder->{version}, | ||
186 | }; | ||
187 | return $ret; | ||
188 | } | ||
189 | |||
190 | sub _create_default_inventory { | ||
191 | my $uuid = shift; | ||
192 | |||
193 | my @InventoryFolders = (); | ||
194 | my $root_folder_id = &OpenSim::Utility::GenerateUUID(); | ||
195 | |||
196 | push @InventoryFolders, { | ||
197 | "folderID" => $root_folder_id, | ||
198 | "agentID" => $uuid, | ||
199 | "parentFolderID" => &OpenSim::Utility::ZeroUUID(), | ||
200 | "folderName" => "My Inventory", | ||
201 | "type" => 8, | ||
202 | "version" => 1, | ||
203 | }; | ||
204 | |||
205 | push @InventoryFolders, { | ||
206 | "folderID" => &OpenSim::Utility::GenerateUUID(), | ||
207 | "agentID" => $uuid, | ||
208 | "parentFolderID" => $root_folder_id, | ||
209 | "folderName" => "Textures", | ||
210 | "type" => 0, | ||
211 | "version" => 1, | ||
212 | }; | ||
213 | |||
214 | push @InventoryFolders, { | ||
215 | "folderID" => &OpenSim::Utility::GenerateUUID(), | ||
216 | "agentID" => $uuid, | ||
217 | "parentFolderID" => $root_folder_id, | ||
218 | "folderName" => "Objects", | ||
219 | "type" => 6, | ||
220 | "version" => 1, | ||
221 | }; | ||
222 | |||
223 | push @InventoryFolders, { | ||
224 | "folderID" => &OpenSim::Utility::GenerateUUID(), | ||
225 | "agentID" => $uuid, | ||
226 | "parentFolderID" => $root_folder_id, | ||
227 | "folderName" => "Clothes", | ||
228 | "type" => 5, | ||
229 | "version" => 1, | ||
230 | }; | ||
231 | |||
232 | return \@InventoryFolders; | ||
233 | } | ||
234 | |||
235 | |||
236 | # ################# | ||
237 | # Utilities | ||
238 | sub _get_uuid { | ||
239 | my $data = shift; | ||
240 | if ($data =~ /<guid\s*>([^<]+)<\/guid>/) { | ||
241 | return $1; | ||
242 | } else { | ||
243 | Carp::croak("can not find uuid: $data"); | ||
244 | } | ||
245 | } | ||
246 | |||
247 | |||
248 | 1; | ||
249 | |||
diff --git a/share/perl/lib/OpenSim/InventoryServer/Config.pm b/share/perl/lib/OpenSim/InventoryServer/Config.pm new file mode 100644 index 0000000..64dbdd1 --- /dev/null +++ b/share/perl/lib/OpenSim/InventoryServer/Config.pm | |||
@@ -0,0 +1,51 @@ | |||
1 | package OpenSim::InventoryServer::Config; | ||
2 | |||
3 | use strict; | ||
4 | |||
5 | our %SYS_SQL = ( | ||
6 | save_inventory_folder => | ||
7 | "REPLACE INTO inventoryfolders VALUES (?,?,?,?,?,?)", | ||
8 | save_inventory_item => | ||
9 | "REPLACE INTO inventoryitems VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)", | ||
10 | get_root_folder => | ||
11 | "SELECT * FROM inventoryfolders WHERE parentFolderID=? AND agentId=?", | ||
12 | get_children_folders => | ||
13 | "SELECT * FROM inventoryfolders WHERE parentFolderID=?", | ||
14 | get_user_inventory_folders => | ||
15 | "SELECT * FROM inventoryfolders WHERE agentID=?", | ||
16 | get_user_inventory_items => | ||
17 | "SELECT * FROM inventoryitems WHERE avatarID=?", | ||
18 | delete_inventory_item => | ||
19 | "DELETE FROM inventoryitems WHERE inventoryID=?", | ||
20 | move_inventory_folder => | ||
21 | "UPDATE inventoryfolders SET parentFolderID=? WHERE folderID=?", | ||
22 | ); | ||
23 | |||
24 | |||
25 | our @INVENTORYFOLDERS_COLUMNS = ( | ||
26 | "folderID", | ||
27 | "agentID", | ||
28 | "parentFolderID", | ||
29 | "folderName", | ||
30 | "type", | ||
31 | "version", | ||
32 | ); | ||
33 | |||
34 | our @INVENTORYITEMS_COLUMNS = ( | ||
35 | "inventoryID", | ||
36 | "assetID", | ||
37 | "type", | ||
38 | "parentFolderID", | ||
39 | "avatarID", | ||
40 | "inventoryName", | ||
41 | "inventoryDescription", | ||
42 | "inventoryNextPermissions", | ||
43 | "inventoryCurrentPermissions", | ||
44 | "assetType", | ||
45 | "invType", | ||
46 | "creatorID", | ||
47 | "inventoryBasePermissions", | ||
48 | "inventoryEveryOnePermissions", | ||
49 | ); | ||
50 | |||
51 | 1; | ||
diff --git a/share/perl/lib/OpenSim/InventoryServer/InventoryManager.pm b/share/perl/lib/OpenSim/InventoryServer/InventoryManager.pm new file mode 100644 index 0000000..97111b7 --- /dev/null +++ b/share/perl/lib/OpenSim/InventoryServer/InventoryManager.pm | |||
@@ -0,0 +1,86 @@ | |||
1 | package OpenSim::InventoryServer::InventoryManager; | ||
2 | |||
3 | use strict; | ||
4 | use Carp; | ||
5 | use OpenSim::Utility; | ||
6 | use OpenSim::InventoryServer::Config; | ||
7 | |||
8 | sub saveInventoryFolder { | ||
9 | my $folder = shift; | ||
10 | my $result = &OpenSim::Utility::getSimpleResult($OpenSim::InventoryServer::Config::SYS_SQL{save_inventory_folder}, | ||
11 | $folder->{"folderID"}, | ||
12 | $folder->{"agentID"}, | ||
13 | $folder->{"parentFolderID"}, | ||
14 | $folder->{"folderName"}, | ||
15 | $folder->{"type"}, | ||
16 | $folder->{"version"}); | ||
17 | } | ||
18 | |||
19 | sub saveInventoryItem { | ||
20 | my $item = shift; | ||
21 | my $result = &OpenSim::Utility::getSimpleResult($OpenSim::InventoryServer::Config::SYS_SQL{save_inventory_item}, | ||
22 | $item->{"inventoryID"}, | ||
23 | $item->{"assetID"}, | ||
24 | $item->{"type"}, | ||
25 | $item->{"parentFolderID"}, | ||
26 | $item->{"avatarID"}, | ||
27 | $item->{"inventoryName"}, | ||
28 | $item->{"inventoryDescription"}, | ||
29 | $item->{"inventoryNextPermissions"}, | ||
30 | $item->{"inventoryCurrentPermissions"}, | ||
31 | $item->{"assetType"}, | ||
32 | $item->{"invType"}, | ||
33 | $item->{"creatorID"}, | ||
34 | $item->{"inventoryBasePermissions"}, | ||
35 | $item->{"inventoryEveryOnePermissions"}); | ||
36 | } | ||
37 | |||
38 | sub getRootFolder { | ||
39 | my $agent_id = shift; | ||
40 | my $result = &OpenSim::Utility::getSimpleResult($OpenSim::InventoryServer::Config::SYS_SQL{get_root_folder}, | ||
41 | &OpenSim::Utility::ZeroUUID(), | ||
42 | $agent_id); | ||
43 | my $count = @$result; | ||
44 | if ($count > 0) { | ||
45 | return $result->[0]; | ||
46 | } else { | ||
47 | return undef; | ||
48 | } | ||
49 | } | ||
50 | |||
51 | sub getChildrenFolders { | ||
52 | my $parent_id = shift; | ||
53 | my $result = &OpenSim::Utility::getSimpleResult($OpenSim::InventoryServer::Config::SYS_SQL{get_children_folders}, $parent_id); | ||
54 | return $result; | ||
55 | } | ||
56 | |||
57 | sub getUserInventoryFolders { | ||
58 | my $agent_id = shift; | ||
59 | my $result = &OpenSim::Utility::getSimpleResult($OpenSim::InventoryServer::Config::SYS_SQL{get_user_inventory_folders}, | ||
60 | $agent_id); | ||
61 | return $result; | ||
62 | } | ||
63 | |||
64 | sub getUserInventoryItems { | ||
65 | my $agent_id = shift; | ||
66 | my $result = &OpenSim::Utility::getSimpleResult($OpenSim::InventoryServer::Config::SYS_SQL{get_user_inventory_items}, | ||
67 | $agent_id); | ||
68 | return $result; | ||
69 | } | ||
70 | |||
71 | sub deleteInventoryItem { | ||
72 | my $item_id = shift; | ||
73 | &OpenSim::Utility::getSimpleResult($OpenSim::InventoryServer::Config::SYS_SQL{delete_inventory_item}, | ||
74 | $item_id); | ||
75 | } | ||
76 | |||
77 | sub moveInventoryFolder { | ||
78 | my $info = shift; | ||
79 | &OpenSim::Utility::getSimpleResult($OpenSim::InventoryServer::Config::SYS_SQL{move_inventory_folder}, | ||
80 | $info->{parentID}->{UUID}, # TODO: not good | ||
81 | $info->{folderID}->{UUID}, # TODO: not good UUID should be extracted in the higher level | ||
82 | ); | ||
83 | } | ||
84 | |||
85 | 1; | ||
86 | |||
diff --git a/share/perl/lib/OpenSim/UserServer.pm b/share/perl/lib/OpenSim/UserServer.pm new file mode 100644 index 0000000..77117e1 --- /dev/null +++ b/share/perl/lib/OpenSim/UserServer.pm | |||
@@ -0,0 +1,239 @@ | |||
1 | package OpenSim::UserServer; | ||
2 | |||
3 | use strict; | ||
4 | use OpenSim::Config; | ||
5 | use OpenSim::UserServer::Config; | ||
6 | use OpenSim::UserServer::UserManager; | ||
7 | |||
8 | sub getHandlerList { | ||
9 | my %list = ( | ||
10 | "login_to_simulator" => \&_login_to_simulator, | ||
11 | "get_user_by_name" => \&_get_user_by_name, | ||
12 | "get_user_by_uuid" => \&_get_user_by_uuid, | ||
13 | "get_avatar_picker_avatar" => \&_get_avatar_picker_avatar, | ||
14 | ); | ||
15 | return \%list; | ||
16 | } | ||
17 | |||
18 | # ################# | ||
19 | # Handlers | ||
20 | sub _login_to_simulator { | ||
21 | my $params = shift; | ||
22 | # check params | ||
23 | if (!$params->{first} || !$params->{last} || !$params->{passwd}) { | ||
24 | return &_make_false_response("not enough params", $OpenSim::Config::SYS_MSG{FATAL}); | ||
25 | } | ||
26 | # select user (check passwd) | ||
27 | my $user = &OpenSim::UserServer::UserManager::getUserByName($params->{first}, $params->{last}); | ||
28 | if ($user->{passwordHash} ne $params->{passwd}) { | ||
29 | &_make_false_response("password not match", $OpenSim::Config::SYS_MSG{FAIL}); | ||
30 | } | ||
31 | |||
32 | # contact with Grid server | ||
33 | my %grid_request_params = ( | ||
34 | region_handle => $user->{homeRegion}, | ||
35 | authkey => undef | ||
36 | ); | ||
37 | my $grid_response = &OpenSim::Utility::XMLRPCCall($OpenSim::Config::GRID_SERVER_URL, "simulator_data_request", \%grid_request_params); | ||
38 | my $region_server_url = "http://" . $grid_response->{sim_ip} . ":" . $grid_response->{http_port}; | ||
39 | |||
40 | # contact with Region server | ||
41 | my $session_id = &OpenSim::Utility::GenerateUUID; | ||
42 | my $secure_session_id = &OpenSim::Utility::GenerateUUID; | ||
43 | my $circuit_code = int(rand() * 1000000000); # just a random integer | ||
44 | my $caps_id = &OpenSim::Utility::GenerateUUID; | ||
45 | my %region_request_params = ( | ||
46 | session_id => $session_id, | ||
47 | secure_session_id => $secure_session_id, | ||
48 | firstname => $user->{username}, | ||
49 | lastname => $user->{lastname}, | ||
50 | agent_id => $user->{UUID}, | ||
51 | circuit_code => $circuit_code, | ||
52 | startpos_x => $user->{homeLocationX}, | ||
53 | startpos_y => $user->{homeLocationY}, | ||
54 | startpos_z => $user->{homeLocationZ}, | ||
55 | regionhandle => $user->{homeRegion}, | ||
56 | caps_path => $caps_id, | ||
57 | ); | ||
58 | my $region_response = &OpenSim::Utility::XMLRPCCall($region_server_url, "expect_user", \%region_request_params); | ||
59 | |||
60 | # contact with Inventory server | ||
61 | my $inventory_data = &_create_inventory_data($user->{UUID}); | ||
62 | |||
63 | # return to client | ||
64 | my %response = ( | ||
65 | # login info | ||
66 | login => "true", | ||
67 | session_id => $session_id, | ||
68 | secure_session_id => $secure_session_id, | ||
69 | # agent | ||
70 | first_name => $user->{username}, | ||
71 | last_name => $user->{lastname}, | ||
72 | agent_id => $user->{UUID}, | ||
73 | agent_access => "M", # TODO: do not know its meaning, hard coding in opensim | ||
74 | # grid | ||
75 | start_location => $params->{start}, | ||
76 | sim_ip => $grid_response->{sim_ip}, | ||
77 | sim_port => $grid_response->{sim_port}, | ||
78 | #sim_port => 9001, | ||
79 | region_x => $grid_response->{region_locx} * 256, | ||
80 | region_y => $grid_response->{region_locy} * 256, | ||
81 | # other | ||
82 | inventory_host => undef, # inv13-mysql | ||
83 | circuit_code => $circuit_code, | ||
84 | message => $OpenSim::Config::SYS_MSG{LOGIN_WELCOME}, | ||
85 | seconds_since_epoch => time, | ||
86 | seed_capability => $region_server_url . "/CAPS/" . $caps_id . "0000/", # https://sim2734.agni.lindenlab.com:12043/cap/61d6d8a0-2098-7eb4-2989-76265d80e9b6 | ||
87 | look_at => &_make_r_string($user->{homeLookAtX}, $user->{homeLookAtY}, $user->{homeLookAtZ}), | ||
88 | home => &_make_home_string( | ||
89 | [$grid_response->{region_locx} * 256, $grid_response->{region_locy} * 256], | ||
90 | [$user->{homeLocationX}, $user->{homeLocationY}, $user->{homeLocationX}], | ||
91 | [$user->{homeLookAtX}, $user->{homeLookAtY}, $user->{homeLookAtZ}]), | ||
92 | "inventory-skeleton" => $inventory_data->{InventoryArray}, | ||
93 | "inventory-root" => [ { folder_id => $inventory_data->{RootFolderID} } ], | ||
94 | "event_notifications" => \@OpenSim::UserServer::Config::event_notifications, | ||
95 | "event_categories" => \@OpenSim::UserServer::Config::event_categories, | ||
96 | "global-textures" => \@OpenSim::UserServer::Config::global_textures, | ||
97 | "inventory-lib-owner" => \@OpenSim::UserServer::Config::inventory_lib_owner, | ||
98 | "inventory-skel-lib" => \@OpenSim::UserServer::Config::inventory_skel_lib, # hard coding in OpenSim | ||
99 | "inventory-lib-root" => \@OpenSim::UserServer::Config::inventory_lib_root, | ||
100 | "classified_categories" => \@OpenSim::UserServer::Config::classified_categories, | ||
101 | "login-flags" => \@OpenSim::UserServer::Config::login_flags, | ||
102 | "initial-outfit" => \@OpenSim::UserServer::Config::initial_outfit, | ||
103 | "gestures" => \@OpenSim::UserServer::Config::gestures, | ||
104 | "ui-config" => \@OpenSim::UserServer::Config::ui_config, | ||
105 | ); | ||
106 | return \%response; | ||
107 | } | ||
108 | |||
109 | sub _get_user_by_name { | ||
110 | my $param = shift; | ||
111 | |||
112 | if ($param->{avatar_name}) { | ||
113 | my ($first, $last) = split(/\s+/, $param->{avatar_name}); | ||
114 | my $user = &OpenSim::UserServer::UserManager::getUserByName($first, $last); | ||
115 | if (!$user) { | ||
116 | return &_unknown_user_response; | ||
117 | } | ||
118 | return &_convert_to_response($user); | ||
119 | } else { | ||
120 | return &_unknown_user_response; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | sub _get_user_by_uuid { | ||
125 | my $param = shift; | ||
126 | |||
127 | if ($param->{avatar_uuid}) { | ||
128 | my $user = &OpenSim::UserServer::UserManager::getUserByUUID($param->{avatar_uuid}); | ||
129 | if (!$user) { | ||
130 | return &_unknown_user_response; | ||
131 | } | ||
132 | return &_convert_to_response($user); | ||
133 | } else { | ||
134 | return &_unknown_user_response; | ||
135 | } | ||
136 | } | ||
137 | |||
138 | sub _get_avatar_picker_avatar { | ||
139 | } | ||
140 | |||
141 | # ################# | ||
142 | # sub functions | ||
143 | sub _create_inventory_data { | ||
144 | my $user_id = shift; | ||
145 | # TODO : too bad!! -> URI encoding | ||
146 | my $postdata =<< "POSTDATA"; | ||
147 | POSTDATA=<?xml version="1.0" encoding="utf-8"?><guid>$user_id</guid> | ||
148 | POSTDATA | ||
149 | my $res = &OpenSim::Utility::HttpPostRequest($OpenSim::Config::INVENTORY_SERVER_URL . "/RootFolders/", $postdata); | ||
150 | my $res_obj = &OpenSim::Utility::XML2Obj($res); | ||
151 | if (!$res_obj->{InventoryFolderBase}) { | ||
152 | &OpenSim::Utility::HttpPostRequest($OpenSim::Config::INVENTORY_SERVER_URL . "/CreateInventory/", $postdata); | ||
153 | # Sleep(10000); # TODO: need not to do this | ||
154 | $res = &OpenSim::Utility::HttpPostRequest($OpenSim::Config::INVENTORY_SERVER_URL . "/RootFolders/", $postdata); | ||
155 | $res_obj = &OpenSim::Utility::XML2Obj($res); | ||
156 | } | ||
157 | my $folders = $res_obj->{InventoryFolderBase}; | ||
158 | my $folders_count = @$folders; | ||
159 | if ($folders_count > 0) { | ||
160 | my @AgentInventoryFolders = (); | ||
161 | my $root_uuid = &OpenSim::Utility::ZeroUUID(); | ||
162 | foreach my $folder (@$folders) { | ||
163 | if ($folder->{parentID}->{UUID} eq &OpenSim::Utility::ZeroUUID()) { | ||
164 | $root_uuid = $folder->{folderID}->{UUID}; | ||
165 | } | ||
166 | my %folder_hash = ( | ||
167 | name => $folder->{name}, | ||
168 | parent_id => $folder->{parentID}->{UUID}, | ||
169 | version => $folder->{version}, | ||
170 | type_default => $folder->{type}, | ||
171 | folder_id => $folder->{folderID}->{UUID}, | ||
172 | ); | ||
173 | push @AgentInventoryFolders, \%folder_hash; | ||
174 | } | ||
175 | return { InventoryArray => \@AgentInventoryFolders, RootFolderID => $root_uuid }; | ||
176 | } else { | ||
177 | # TODO: impossible ??? | ||
178 | } | ||
179 | return undef; | ||
180 | } | ||
181 | |||
182 | sub _convert_to_response { | ||
183 | my $user = shift; | ||
184 | my %response = ( | ||
185 | firstname => $user->{username}, | ||
186 | lastname => $user->{lastname}, | ||
187 | uuid => $user->{UUID}, | ||
188 | server_inventory => $user->{userInventoryURI}, | ||
189 | server_asset => $user->{userAssetURI}, | ||
190 | profile_about => $user->{profileAboutText}, | ||
191 | profile_firstlife_about => $user->{profileFirstText}, | ||
192 | profile_firstlife_image => $user->{profileFirstImage}, | ||
193 | profile_can_do => $user->{profileCanDoMask} || "0", | ||
194 | profile_want_do => $user->{profileWantDoMask} || "0", | ||
195 | profile_image => $user->{profileImage}, | ||
196 | profile_created => $user->{created}, | ||
197 | profile_lastlogin => $user->{lastLogin} || "0", | ||
198 | home_coordinates_x => $user->{homeLocationX}, | ||
199 | home_coordinates_y => $user->{homeLocationY}, | ||
200 | home_coordinates_z => $user->{homeLocationZ}, | ||
201 | home_region => $user->{homeRegion} || 0, | ||
202 | home_look_x => $user->{homeLookAtX}, | ||
203 | home_look_y => $user->{homeLookAtY}, | ||
204 | home_look_z => $user->{homeLookAtZ}, | ||
205 | ); | ||
206 | return \%response; | ||
207 | } | ||
208 | |||
209 | # ################# | ||
210 | # Utility Functions | ||
211 | sub _make_false_response { | ||
212 | my ($reason, $message) = @_; | ||
213 | return { reason => $reason, login => "false", message => $message }; | ||
214 | } | ||
215 | |||
216 | sub _unknown_user_response { | ||
217 | return { | ||
218 | error_type => "unknown_user", | ||
219 | error_desc => "The user requested is not in the database", | ||
220 | }; | ||
221 | } | ||
222 | |||
223 | sub _make_home_string { | ||
224 | my ($region_handle, $position, $look_at) = @_; | ||
225 | my $region_handle_string = "'region_handle':" . &_make_r_string(@$region_handle); | ||
226 | my $position_string = "'position':" . &_make_r_string(@$position); | ||
227 | my $look_at_string = "'look_at':" . &_make_r_string(@$look_at); | ||
228 | return "{" . $region_handle_string . ", " . $position_string . ", " . $look_at_string . "}"; | ||
229 | } | ||
230 | |||
231 | sub _make_r_string { | ||
232 | my @params = @_; | ||
233 | foreach (@params) { | ||
234 | $_ = "r" . $_; | ||
235 | } | ||
236 | return "[" . join(",", @params) . "]"; | ||
237 | } | ||
238 | |||
239 | 1; | ||
diff --git a/share/perl/lib/OpenSim/UserServer/Config.pm b/share/perl/lib/OpenSim/UserServer/Config.pm new file mode 100644 index 0000000..da628ed --- /dev/null +++ b/share/perl/lib/OpenSim/UserServer/Config.pm | |||
@@ -0,0 +1,125 @@ | |||
1 | package OpenSim::UserServer::Config; | ||
2 | |||
3 | use strict; | ||
4 | |||
5 | our %SYS_SQL = ( | ||
6 | select_user_by_name => | ||
7 | "select * from users where username=? and lastname=?", | ||
8 | select_user_by_uuid => | ||
9 | "select * from users where uuid=?", | ||
10 | create_user => | ||
11 | "insert into users values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", | ||
12 | ); | ||
13 | |||
14 | our @USERS_COLUMNS = ( | ||
15 | "UUID", | ||
16 | "username", | ||
17 | "lastname", | ||
18 | "passwordHash", | ||
19 | "passwordSalt", | ||
20 | "homeRegion", | ||
21 | "homeLocationX", | ||
22 | "homeLocationY", | ||
23 | "homeLocationZ", | ||
24 | "homeLookAtX", | ||
25 | "homeLookAtY", | ||
26 | "homeLookAtZ", | ||
27 | "created", | ||
28 | "lastLogin", | ||
29 | "userInventoryURI", | ||
30 | "userAssetURI", | ||
31 | "profileCanDoMask", | ||
32 | "profileWantDoMask", | ||
33 | "profileAboutText", | ||
34 | "profileFirstText", | ||
35 | "profileImage", | ||
36 | "profileFirstImage", | ||
37 | ); | ||
38 | |||
39 | # copied from opensim | ||
40 | our @classified_categories = ( | ||
41 | { category_id => 1, category_name => "Shopping" }, | ||
42 | { category_id => 2, category_name => "Land Rental" }, | ||
43 | { category_id => 3, category_name => "Property Rental" }, | ||
44 | { category_id => 4, category_name => "Special Attraction" }, | ||
45 | { category_id => 5, category_name => "New Products" }, | ||
46 | { category_id => 6, category_name => "Employment" }, | ||
47 | { category_id => 7, category_name => "Wanted" }, | ||
48 | { category_id => 8, category_name => "Service" }, | ||
49 | { category_id => 9, category_name => "Personal" }, | ||
50 | ); | ||
51 | |||
52 | our @event_categories = (); | ||
53 | our @event_notifications = (); | ||
54 | our @gestures =(); | ||
55 | our @global_textures = ( | ||
56 | { | ||
57 | cloud_texture_id => "dc4b9f0b-d008-45c6-96a4-01dd947ac621", | ||
58 | moon_texture_id => "ec4b9f0b-d008-45c6-96a4-01dd947ac621", | ||
59 | sun_texture_id => "cce0f112-878f-4586-a2e2-a8f104bba271", | ||
60 | }, | ||
61 | ); | ||
62 | our @initial_outfit = ( | ||
63 | { folder_name => "Nightclub Female", gender => "female" } | ||
64 | ); | ||
65 | our @inventory_lib_owner = ({ agent_id => "11111111-1111-0000-0000-000100bba000" }); | ||
66 | our @inventory_lib_root = ({ folder_id => "00000112-000f-0000-0000-000100bba000" }); | ||
67 | our @inventory_root = ({ folder_id => "2eb27bc2-22ee-48db-b2e9-5c79a6582919" }); | ||
68 | our @inventory_skel_lib = ( | ||
69 | { | ||
70 | folder_id => "00000112-000f-0000-0000-000100bba000", | ||
71 | name => "OpenSim Library", | ||
72 | parent_id => "00000000-0000-0000-0000-000000000000", | ||
73 | type_default => -1, | ||
74 | version => 1, | ||
75 | }, | ||
76 | { | ||
77 | folder_id => "00000112-000f-0000-0000-000100bba001", | ||
78 | name => "Texture Library", | ||
79 | parent_id => "00000112-000f-0000-0000-000100bba000", | ||
80 | type_default => -1, | ||
81 | version => 1, | ||
82 | }, | ||
83 | ); | ||
84 | our @inventory_skeleton = ( | ||
85 | { | ||
86 | folder_id => "2eb27bc2-22ee-48db-b2e9-5c79a6582919", | ||
87 | name => "My Inventory", | ||
88 | parent_id => "00000000-0000-0000-0000-000000000000", | ||
89 | type_default => 8, | ||
90 | version => 1, | ||
91 | }, | ||
92 | { | ||
93 | folder_id => "6cc20d86-9945-4997-a102-959348d56821", | ||
94 | name => "Textures", | ||
95 | parent_id => "2eb27bc2-22ee-48db-b2e9-5c79a6582919", | ||
96 | type_default => 0, | ||
97 | version => 1, | ||
98 | }, | ||
99 | { | ||
100 | folder_id => "840b747f-bb7d-465e-ab5a-58badc953484", | ||
101 | name => "Clothes", | ||
102 | parent_id => "2eb27bc2-22ee-48db-b2e9-5c79a6582919", | ||
103 | type_default => 5, | ||
104 | version => 1, | ||
105 | }, | ||
106 | { | ||
107 | folder_id => "37039005-7bbe-42a2-aa12-6bda453f37fd", | ||
108 | name => "Objects", | ||
109 | parent_id => "2eb27bc2-22ee-48db-b2e9-5c79a6582919", | ||
110 | type_default => 6, | ||
111 | version => 1, | ||
112 | }, | ||
113 | ); | ||
114 | our @login_flags = ( | ||
115 | { | ||
116 | daylight_savings => "N", | ||
117 | ever_logged_in => "Y", | ||
118 | gendered => "Y", | ||
119 | stipend_since_login => "N", | ||
120 | }, | ||
121 | ); | ||
122 | our @ui_config = ({ allow_first_life => "Y" }); | ||
123 | |||
124 | 1; | ||
125 | |||
diff --git a/share/perl/lib/OpenSim/UserServer/UserManager.pm b/share/perl/lib/OpenSim/UserServer/UserManager.pm new file mode 100644 index 0000000..ce35329 --- /dev/null +++ b/share/perl/lib/OpenSim/UserServer/UserManager.pm | |||
@@ -0,0 +1,49 @@ | |||
1 | package OpenSim::UserServer::UserManager; | ||
2 | |||
3 | use strict; | ||
4 | use Carp; | ||
5 | use OpenSim::Utility; | ||
6 | use OpenSim::UserServer::Config; | ||
7 | |||
8 | sub getUserByName { | ||
9 | my ($first, $last) = @_; | ||
10 | my $res = &OpenSim::Utility::getSimpleResult($OpenSim::UserServer::Config::SYS_SQL{select_user_by_name}, $first, $last); | ||
11 | my $count = @$res; | ||
12 | my %user = (); | ||
13 | if ($count == 1) { | ||
14 | my $user_row = $res->[0]; | ||
15 | foreach (@OpenSim::UserServer::Config::USERS_COLUMNS) { | ||
16 | $user{$_} = $user_row->{$_} || ""; | ||
17 | } | ||
18 | } else { | ||
19 | Carp::croak("user not found"); | ||
20 | } | ||
21 | return \%user; | ||
22 | } | ||
23 | |||
24 | sub getUserByUUID { | ||
25 | my ($uuid) = @_; | ||
26 | my $res = &OpenSim::Utility::getSimpleResult($OpenSim::UserServer::Config::SYS_SQL{select_user_by_uuid}, $uuid); | ||
27 | my $count = @$res; | ||
28 | my %user = (); | ||
29 | if ($count == 1) { | ||
30 | my $user_row = $res->[0]; | ||
31 | foreach (@OpenSim::UserServer::Config::USERS_COLUMNS) { | ||
32 | $user{$_} = $user_row->{$_} || ""; | ||
33 | } | ||
34 | } else { | ||
35 | Carp::croak("user not found"); | ||
36 | } | ||
37 | return \%user; | ||
38 | } | ||
39 | |||
40 | sub createUser { | ||
41 | my $user = shift; | ||
42 | my @params = (); | ||
43 | foreach (@OpenSim::UserServer::Config::USERS_COLUMNS) { | ||
44 | push @params, $user->{$_}; | ||
45 | } | ||
46 | my $res = &OpenSim::Utility::getSimpleResult($OpenSim::UserServer::Config::SYS_SQL{create_user}, @params); | ||
47 | } | ||
48 | |||
49 | 1; | ||
diff --git a/share/perl/lib/OpenSim/Utility.pm b/share/perl/lib/OpenSim/Utility.pm new file mode 100644 index 0000000..7fc91e7 --- /dev/null +++ b/share/perl/lib/OpenSim/Utility.pm | |||
@@ -0,0 +1,155 @@ | |||
1 | package OpenSim::Utility; | ||
2 | |||
3 | use strict; | ||
4 | use XML::RPC; | ||
5 | use XML::Simple; | ||
6 | use Data::UUID; | ||
7 | use DBHandler; | ||
8 | use OpenSim::Config; | ||
9 | use Socket; | ||
10 | |||
11 | sub XMLRPCCall { | ||
12 | my ($url, $methodname, $param) = @_; | ||
13 | my $xmlrpc = new XML::RPC($url); | ||
14 | my $result = $xmlrpc->call($methodname, $param); | ||
15 | return $result; | ||
16 | } | ||
17 | |||
18 | sub XMLRPCCall_array { | ||
19 | my ($url, $methodname, $param) = @_; | ||
20 | my $xmlrpc = new XML::RPC($url); | ||
21 | my $result = $xmlrpc->call($methodname, @$param); | ||
22 | return $result; | ||
23 | } | ||
24 | |||
25 | sub UIntsToLong { | ||
26 | my ($int1, $int2) = @_; | ||
27 | return $int1 * 4294967296 + $int2; | ||
28 | } | ||
29 | |||
30 | sub getSimpleResult { | ||
31 | my ($sql, @args) = @_; | ||
32 | my $dbh = &DBHandler::getConnection($OpenSim::Config::DSN, $OpenSim::Config::DBUSER, $OpenSim::Config::DBPASS); | ||
33 | my $st = new Statement($dbh, $sql); | ||
34 | return $st->exec(@args); | ||
35 | } | ||
36 | |||
37 | sub GenerateUUID { | ||
38 | my $ug = new Data::UUID(); | ||
39 | my $uuid = $ug->create(); | ||
40 | return $ug->to_string($uuid); | ||
41 | } | ||
42 | |||
43 | sub ZeroUUID { | ||
44 | return "00000000-0000-0000-0000-000000000000"; | ||
45 | } | ||
46 | |||
47 | sub HEX2UUID { | ||
48 | my $hex = shift; | ||
49 | Carp::croak("$hex is not a uuid") if (length($hex) != 32); | ||
50 | my @sub_uuids = ($hex =~ /(\w{8})(\w{4})(\w{4})(\w{4})(\w{12})/); | ||
51 | return join("-", @sub_uuids); | ||
52 | } | ||
53 | |||
54 | sub BIN2UUID { | ||
55 | # TODO: | ||
56 | } | ||
57 | |||
58 | sub UUID2HEX { | ||
59 | my $uuid = shift; | ||
60 | $uuid =~ s/-//g; | ||
61 | return $uuid; | ||
62 | } | ||
63 | |||
64 | sub UUID2BIN { | ||
65 | my $uuid = shift; | ||
66 | return pack("H*", &UUID2HEX($uuid)); | ||
67 | } | ||
68 | |||
69 | sub HttpPostRequest { | ||
70 | my ($url, $postdata) = @_; | ||
71 | $url =~ /http:\/\/([^:\/]+)(:([0-9]+))?(\/.*)?/; | ||
72 | my ($host, $port, $path) = ($1, $3, $4); | ||
73 | $port ||= 80; | ||
74 | $path ||= "/"; | ||
75 | my $CRLF= "\015\012"; | ||
76 | my $addr = (gethostbyname($host))[4]; | ||
77 | my $name = pack('S n a4 x8', 2, $port, $addr); | ||
78 | my $data_len = length($postdata); | ||
79 | socket(SOCK, PF_INET, SOCK_STREAM, 0); | ||
80 | connect(SOCK, $name) ; | ||
81 | select(SOCK); $| = 1; select(STDOUT); | ||
82 | print SOCK "POST $path HTTP/1.0$CRLF"; | ||
83 | print SOCK "Host: $host:$port$CRLF"; | ||
84 | print SOCK "Content-Length: $data_len$CRLF"; | ||
85 | print SOCK "$CRLF"; | ||
86 | print SOCK $postdata; | ||
87 | |||
88 | my $ret = ""; | ||
89 | unless (<SOCK>) { | ||
90 | close(SOCK); | ||
91 | Carp::croak("can not connect to $url"); | ||
92 | } | ||
93 | my $header = ""; | ||
94 | while (<SOCK>) { | ||
95 | $header .= $_; | ||
96 | last if ($_ eq $CRLF); | ||
97 | } | ||
98 | if ($header != /200/) { | ||
99 | return $ret; | ||
100 | } | ||
101 | while (<SOCK>) { | ||
102 | $ret .= $_; | ||
103 | } | ||
104 | return $ret; | ||
105 | } | ||
106 | # TODO : merge with POST | ||
107 | sub HttpGetRequest { | ||
108 | my ($url) = @_; | ||
109 | $url =~ /http:\/\/([^:\/]+)(:([0-9]+))?(\/.*)?/; | ||
110 | my ($host, $port, $path) = ($1, $3, $4); | ||
111 | $port ||= 80; | ||
112 | $path ||= "/"; | ||
113 | my $CRLF= "\015\012"; | ||
114 | my $addr = (gethostbyname($host))[4]; | ||
115 | my $name = pack('S n a4 x8', 2, $port, $addr); | ||
116 | socket(SOCK, PF_INET, SOCK_STREAM, 0); | ||
117 | connect(SOCK, $name) ; | ||
118 | select(SOCK); $| = 1; select(STDOUT); | ||
119 | print SOCK "GET $path HTTP/1.0$CRLF"; | ||
120 | print SOCK "Host: $host:$port$CRLF"; | ||
121 | print SOCK "$CRLF"; | ||
122 | |||
123 | unless (<SOCK>) { | ||
124 | close(SOCK); | ||
125 | Carp::croak("can not connect to $url"); | ||
126 | } | ||
127 | while (<SOCK>) { | ||
128 | last if ($_ eq $CRLF); | ||
129 | } | ||
130 | my $ret = ""; | ||
131 | while (<SOCK>) { | ||
132 | $ret .= $_; | ||
133 | } | ||
134 | return $ret; | ||
135 | } | ||
136 | |||
137 | sub XML2Obj { | ||
138 | my $xml = shift; | ||
139 | my $xs = new XML::Simple( keyattr=>[] ); | ||
140 | return $xs->XMLin($xml); | ||
141 | } | ||
142 | |||
143 | sub Log { | ||
144 | my $server_name = shift; | ||
145 | my @param = @_; | ||
146 | open(FILE, ">>" . $OpenSim::Config::DEBUG_LOGDIR . "/" . $server_name . ".log"); | ||
147 | foreach(@param) { | ||
148 | print FILE $_ . "\n"; | ||
149 | } | ||
150 | print FILE "<<<<<<<<<<<=====================\n\n"; | ||
151 | close(FILE); | ||
152 | } | ||
153 | |||
154 | 1; | ||
155 | |||