diff options
Diffstat (limited to 'share/perl/lib/OpenSim/UserServer.pm')
-rw-r--r-- | share/perl/lib/OpenSim/UserServer.pm | 239 |
1 files changed, 0 insertions, 239 deletions
diff --git a/share/perl/lib/OpenSim/UserServer.pm b/share/perl/lib/OpenSim/UserServer.pm deleted file mode 100644 index 77117e1..0000000 --- a/share/perl/lib/OpenSim/UserServer.pm +++ /dev/null | |||
@@ -1,239 +0,0 @@ | |||
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; | ||