diff options
Diffstat (limited to 'share/perl/lib/OpenSim/GridServer.pm')
-rw-r--r-- | share/perl/lib/OpenSim/GridServer.pm | 208 |
1 files changed, 208 insertions, 0 deletions
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 | |||