diff options
Diffstat (limited to '')
15 files changed, 2855 insertions, 321 deletions
diff --git a/OpenSim/Services/Connectors/User/UserServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/RemoteAuthenticationServiceConnector.cs index 683990f..a053bc2 100644 --- a/OpenSim/Services/Connectors/User/UserServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/RemoteAuthenticationServiceConnector.cs | |||
@@ -25,90 +25,90 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using log4net; | ||
29 | using System; | 28 | using System; |
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using Nini.Config; | 29 | using Nini.Config; |
34 | using OpenSim.Framework; | 30 | using log4net; |
35 | using OpenSim.Framework.Communications; | 31 | using System.Reflection; |
36 | using OpenSim.Framework.Servers.HttpServer; | 32 | using OpenSim.Region.Framework.Interfaces; |
33 | using OpenSim.Region.Framework.Scenes; | ||
37 | using OpenSim.Services.Interfaces; | 34 | using OpenSim.Services.Interfaces; |
38 | using OpenMetaverse; | 35 | using OpenSim.Services.Connectors; |
39 | 36 | ||
40 | namespace OpenSim.Services.Connectors | 37 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authentication |
41 | { | 38 | { |
42 | public class UserServicesConnector : IUserAccountService | 39 | public class RemoteAuthenticationServicesConnector : AuthenticationServicesConnector, |
40 | ISharedRegionModule, IAuthenticationService | ||
43 | { | 41 | { |
44 | private static readonly ILog m_log = | 42 | private static readonly ILog m_log = |
45 | LogManager.GetLogger( | 43 | LogManager.GetLogger( |
46 | MethodBase.GetCurrentMethod().DeclaringType); | 44 | MethodBase.GetCurrentMethod().DeclaringType); |
47 | 45 | ||
48 | // private string m_ServerURI = String.Empty; | 46 | private bool m_Enabled = false; |
49 | |||
50 | public UserServicesConnector() | ||
51 | { | ||
52 | } | ||
53 | 47 | ||
54 | public UserServicesConnector(string serverURI) | 48 | public Type ReplaceableInterface |
55 | { | 49 | { |
56 | // m_ServerURI = serverURI.TrimEnd('/'); | 50 | get { return null; } |
57 | } | 51 | } |
58 | 52 | ||
59 | public UserServicesConnector(IConfigSource source) | 53 | public string Name |
60 | { | 54 | { |
61 | Initialise(source); | 55 | get { return "RemoteAuthenticationServicesConnector"; } |
62 | } | 56 | } |
63 | 57 | ||
64 | public virtual void Initialise(IConfigSource source) | 58 | public override void Initialise(IConfigSource source) |
65 | { | 59 | { |
66 | IConfig assetConfig = source.Configs["UserService"]; | 60 | IConfig moduleConfig = source.Configs["Modules"]; |
67 | if (assetConfig == null) | 61 | if (moduleConfig != null) |
68 | { | 62 | { |
69 | m_log.Error("[USER CONNECTOR]: UserService missing from OpanSim.ini"); | 63 | string name = moduleConfig.GetString("AuthenticationServices", ""); |
70 | throw new Exception("User connector init error"); | 64 | if (name == Name) |
71 | } | 65 | { |
66 | IConfig userConfig = source.Configs["AuthenticationService"]; | ||
67 | if (userConfig == null) | ||
68 | { | ||
69 | m_log.Error("[AUTH CONNECTOR]: AuthenticationService missing from OpenSim.ini"); | ||
70 | return; | ||
71 | } | ||
72 | 72 | ||
73 | string serviceURI = assetConfig.GetString("UserServerURI", | 73 | m_Enabled = true; |
74 | String.Empty); | ||
75 | 74 | ||
76 | if (serviceURI == String.Empty) | 75 | base.Initialise(source); |
77 | { | 76 | |
78 | m_log.Error("[USER CONNECTOR]: No Server URI named in section UserService"); | 77 | m_log.Info("[AUTH CONNECTOR]: Remote Authentication enabled"); |
79 | throw new Exception("User connector init error"); | 78 | } |
80 | } | 79 | } |
81 | //m_ServerURI = serviceURI; | ||
82 | } | 80 | } |
83 | 81 | ||
84 | public UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName) | 82 | public void PostInitialise() |
85 | { | 83 | { |
86 | return null; | 84 | if (!m_Enabled) |
85 | return; | ||
87 | } | 86 | } |
88 | 87 | ||
89 | public UserAccount GetUserAccount(UUID scopeID, UUID userID) | 88 | public void Close() |
90 | { | 89 | { |
91 | return null; | 90 | if (!m_Enabled) |
91 | return; | ||
92 | } | 92 | } |
93 | 93 | ||
94 | public bool SetHomePosition(UserAccount data, UUID regionID, UUID regionSecret) | 94 | public void AddRegion(Scene scene) |
95 | { | 95 | { |
96 | return false; | 96 | if (!m_Enabled) |
97 | } | 97 | return; |
98 | 98 | ||
99 | public bool SetUserAccount(UserAccount data, UUID principalID, string token) | 99 | scene.RegisterModuleInterface<IAuthenticationService>(this); |
100 | { | ||
101 | return false; | ||
102 | } | 100 | } |
103 | 101 | ||
104 | public bool CreateUserAccount(UserAccount data, UUID principalID, string token) | 102 | public void RemoveRegion(Scene scene) |
105 | { | 103 | { |
106 | return false; | 104 | if (!m_Enabled) |
105 | return; | ||
107 | } | 106 | } |
108 | 107 | ||
109 | public List<UserAccount> GetUserAccount(UUID scopeID, string query) | 108 | public void RegionLoaded(Scene scene) |
110 | { | 109 | { |
111 | return null; | 110 | if (!m_Enabled) |
111 | return; | ||
112 | } | 112 | } |
113 | } | 113 | } |
114 | } | 114 | } |
diff --git a/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs b/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs index 8e311d7..a5c157d 100644 --- a/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs +++ b/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs | |||
@@ -68,7 +68,7 @@ namespace OpenSim.Services.Connectors | |||
68 | IConfig assetConfig = source.Configs["AssetService"]; | 68 | IConfig assetConfig = source.Configs["AssetService"]; |
69 | if (assetConfig == null) | 69 | if (assetConfig == null) |
70 | { | 70 | { |
71 | m_log.Error("[ASSET CONNECTOR]: AssetService missing from OpanSim.ini"); | 71 | m_log.Error("[ASSET CONNECTOR]: AssetService missing from OpenSim.ini"); |
72 | throw new Exception("Asset connector init error"); | 72 | throw new Exception("Asset connector init error"); |
73 | } | 73 | } |
74 | 74 | ||
@@ -243,7 +243,7 @@ namespace OpenSim.Services.Connectors | |||
243 | if (metadata == null) | 243 | if (metadata == null) |
244 | return false; | 244 | return false; |
245 | 245 | ||
246 | asset = new AssetBase(metadata.FullID, metadata.Name, metadata.Type); | 246 | asset = new AssetBase(metadata.FullID, metadata.Name, metadata.Type, UUID.Zero.ToString()); |
247 | asset.Metadata = metadata; | 247 | asset.Metadata = metadata; |
248 | } | 248 | } |
249 | asset.Data = data; | 249 | asset.Data = data; |
diff --git a/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs b/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs index 19bb3e2..6f77a2d 100644 --- a/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs +++ b/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs | |||
@@ -67,7 +67,7 @@ namespace OpenSim.Services.Connectors | |||
67 | IConfig assetConfig = source.Configs["AuthenticationService"]; | 67 | IConfig assetConfig = source.Configs["AuthenticationService"]; |
68 | if (assetConfig == null) | 68 | if (assetConfig == null) |
69 | { | 69 | { |
70 | m_log.Error("[USER CONNECTOR]: AuthenticationService missing from OpanSim.ini"); | 70 | m_log.Error("[AUTH CONNECTOR]: AuthenticationService missing from OpenSim.ini"); |
71 | throw new Exception("Authentication connector init error"); | 71 | throw new Exception("Authentication connector init error"); |
72 | } | 72 | } |
73 | 73 | ||
@@ -76,7 +76,7 @@ namespace OpenSim.Services.Connectors | |||
76 | 76 | ||
77 | if (serviceURI == String.Empty) | 77 | if (serviceURI == String.Empty) |
78 | { | 78 | { |
79 | m_log.Error("[USER CONNECTOR]: No Server URI named in section AuthenticationService"); | 79 | m_log.Error("[AUTH CONNECTOR]: No Server URI named in section AuthenticationService"); |
80 | throw new Exception("Authentication connector init error"); | 80 | throw new Exception("Authentication connector init error"); |
81 | } | 81 | } |
82 | m_ServerURI = serviceURI; | 82 | m_ServerURI = serviceURI; |
@@ -146,5 +146,11 @@ namespace OpenSim.Services.Connectors | |||
146 | 146 | ||
147 | return true; | 147 | return true; |
148 | } | 148 | } |
149 | |||
150 | public bool SetPassword(UUID principalID, string passwd) | ||
151 | { | ||
152 | // nope, we don't do this | ||
153 | return false; | ||
154 | } | ||
149 | } | 155 | } |
150 | } | 156 | } |
diff --git a/OpenSim/Services/Connectors/Avatar/AvatarServiceConnector.cs b/OpenSim/Services/Connectors/Avatar/AvatarServiceConnector.cs new file mode 100644 index 0000000..96c05a9 --- /dev/null +++ b/OpenSim/Services/Connectors/Avatar/AvatarServiceConnector.cs | |||
@@ -0,0 +1,317 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using log4net; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
39 | using IAvatarService = OpenSim.Services.Interfaces.IAvatarService; | ||
40 | using OpenSim.Server.Base; | ||
41 | using OpenMetaverse; | ||
42 | |||
43 | namespace OpenSim.Services.Connectors | ||
44 | { | ||
45 | public class AvatarServicesConnector : IAvatarService | ||
46 | { | ||
47 | private static readonly ILog m_log = | ||
48 | LogManager.GetLogger( | ||
49 | MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | |||
51 | private string m_ServerURI = String.Empty; | ||
52 | |||
53 | public AvatarServicesConnector() | ||
54 | { | ||
55 | } | ||
56 | |||
57 | public AvatarServicesConnector(string serverURI) | ||
58 | { | ||
59 | m_ServerURI = serverURI.TrimEnd('/'); | ||
60 | } | ||
61 | |||
62 | public AvatarServicesConnector(IConfigSource source) | ||
63 | { | ||
64 | Initialise(source); | ||
65 | } | ||
66 | |||
67 | public virtual void Initialise(IConfigSource source) | ||
68 | { | ||
69 | IConfig gridConfig = source.Configs["AvatarService"]; | ||
70 | if (gridConfig == null) | ||
71 | { | ||
72 | m_log.Error("[AVATAR CONNECTOR]: AvatarService missing from OpenSim.ini"); | ||
73 | throw new Exception("Avatar connector init error"); | ||
74 | } | ||
75 | |||
76 | string serviceURI = gridConfig.GetString("AvatarServerURI", | ||
77 | String.Empty); | ||
78 | |||
79 | if (serviceURI == String.Empty) | ||
80 | { | ||
81 | m_log.Error("[AVATAR CONNECTOR]: No Server URI named in section AvatarService"); | ||
82 | throw new Exception("Avatar connector init error"); | ||
83 | } | ||
84 | m_ServerURI = serviceURI; | ||
85 | } | ||
86 | |||
87 | |||
88 | #region IAvatarService | ||
89 | |||
90 | public AvatarData GetAvatar(UUID userID) | ||
91 | { | ||
92 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
93 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
94 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
95 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
96 | sendData["METHOD"] = "getavatar"; | ||
97 | |||
98 | sendData["UserID"] = userID; | ||
99 | |||
100 | string reply = string.Empty; | ||
101 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
102 | // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString); | ||
103 | try | ||
104 | { | ||
105 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
106 | m_ServerURI + "/avatar", | ||
107 | reqString); | ||
108 | if (reply == null || (reply != null && reply == string.Empty)) | ||
109 | { | ||
110 | m_log.DebugFormat("[AVATAR CONNECTOR]: GetAgent received null or empty reply"); | ||
111 | return null; | ||
112 | } | ||
113 | } | ||
114 | catch (Exception e) | ||
115 | { | ||
116 | m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
117 | } | ||
118 | |||
119 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
120 | AvatarData avatar = null; | ||
121 | |||
122 | if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) | ||
123 | { | ||
124 | if (replyData["result"] is Dictionary<string, object>) | ||
125 | { | ||
126 | avatar = new AvatarData((Dictionary<string, object>)replyData["result"]); | ||
127 | } | ||
128 | } | ||
129 | |||
130 | return avatar; | ||
131 | |||
132 | } | ||
133 | |||
134 | public bool SetAvatar(UUID userID, AvatarData avatar) | ||
135 | { | ||
136 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
137 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
138 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
139 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
140 | sendData["METHOD"] = "setavatar"; | ||
141 | |||
142 | sendData["UserID"] = userID.ToString(); | ||
143 | |||
144 | Dictionary<string, object> structData = avatar.ToKeyValuePairs(); | ||
145 | |||
146 | foreach (KeyValuePair<string, object> kvp in structData) | ||
147 | sendData[kvp.Key] = kvp.Value.ToString(); | ||
148 | |||
149 | |||
150 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
151 | //m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString); | ||
152 | try | ||
153 | { | ||
154 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
155 | m_ServerURI + "/avatar", | ||
156 | reqString); | ||
157 | if (reply != string.Empty) | ||
158 | { | ||
159 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
160 | |||
161 | if (replyData.ContainsKey("result")) | ||
162 | { | ||
163 | if (replyData["result"].ToString().ToLower() == "success") | ||
164 | return true; | ||
165 | else | ||
166 | return false; | ||
167 | } | ||
168 | else | ||
169 | m_log.DebugFormat("[AVATAR CONNECTOR]: SetAvatar reply data does not contain result field"); | ||
170 | |||
171 | } | ||
172 | else | ||
173 | m_log.DebugFormat("[AVATAR CONNECTOR]: SetAvatar received empty reply"); | ||
174 | } | ||
175 | catch (Exception e) | ||
176 | { | ||
177 | m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting avatar server: {0}", e.Message); | ||
178 | } | ||
179 | |||
180 | return false; | ||
181 | } | ||
182 | |||
183 | public bool ResetAvatar(UUID userID) | ||
184 | { | ||
185 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
186 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
187 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
188 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
189 | sendData["METHOD"] = "resetavatar"; | ||
190 | |||
191 | sendData["UserID"] = userID.ToString(); | ||
192 | |||
193 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
194 | // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString); | ||
195 | try | ||
196 | { | ||
197 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
198 | m_ServerURI + "/avatar", | ||
199 | reqString); | ||
200 | if (reply != string.Empty) | ||
201 | { | ||
202 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
203 | |||
204 | if (replyData.ContainsKey("result")) | ||
205 | { | ||
206 | if (replyData["result"].ToString().ToLower() == "success") | ||
207 | return true; | ||
208 | else | ||
209 | return false; | ||
210 | } | ||
211 | else | ||
212 | m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems reply data does not contain result field"); | ||
213 | |||
214 | } | ||
215 | else | ||
216 | m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems received empty reply"); | ||
217 | } | ||
218 | catch (Exception e) | ||
219 | { | ||
220 | m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting avatar server: {0}", e.Message); | ||
221 | } | ||
222 | |||
223 | return false; | ||
224 | } | ||
225 | |||
226 | public bool SetItems(UUID userID, string[] names, string[] values) | ||
227 | { | ||
228 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
229 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
230 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
231 | sendData["METHOD"] = "setitems"; | ||
232 | |||
233 | sendData["UserID"] = userID.ToString(); | ||
234 | sendData["Names"] = new List<string>(names); | ||
235 | sendData["Values"] = new List<string>(values); | ||
236 | |||
237 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
238 | // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString); | ||
239 | try | ||
240 | { | ||
241 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
242 | m_ServerURI + "/avatar", | ||
243 | reqString); | ||
244 | if (reply != string.Empty) | ||
245 | { | ||
246 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
247 | |||
248 | if (replyData.ContainsKey("result")) | ||
249 | { | ||
250 | if (replyData["result"].ToString().ToLower() == "success") | ||
251 | return true; | ||
252 | else | ||
253 | return false; | ||
254 | } | ||
255 | else | ||
256 | m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems reply data does not contain result field"); | ||
257 | |||
258 | } | ||
259 | else | ||
260 | m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems received empty reply"); | ||
261 | } | ||
262 | catch (Exception e) | ||
263 | { | ||
264 | m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting avatar server: {0}", e.Message); | ||
265 | } | ||
266 | |||
267 | return false; | ||
268 | } | ||
269 | |||
270 | public bool RemoveItems(UUID userID, string[] names) | ||
271 | { | ||
272 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
273 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
274 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
275 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
276 | sendData["METHOD"] = "removeitems"; | ||
277 | |||
278 | sendData["UserID"] = userID.ToString(); | ||
279 | sendData["Names"] = new List<string>(names); | ||
280 | |||
281 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
282 | // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString); | ||
283 | try | ||
284 | { | ||
285 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
286 | m_ServerURI + "/avatar", | ||
287 | reqString); | ||
288 | if (reply != string.Empty) | ||
289 | { | ||
290 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
291 | |||
292 | if (replyData.ContainsKey("result")) | ||
293 | { | ||
294 | if (replyData["result"].ToString().ToLower() == "success") | ||
295 | return true; | ||
296 | else | ||
297 | return false; | ||
298 | } | ||
299 | else | ||
300 | m_log.DebugFormat("[AVATAR CONNECTOR]: RemoveItems reply data does not contain result field"); | ||
301 | |||
302 | } | ||
303 | else | ||
304 | m_log.DebugFormat("[AVATAR CONNECTOR]: RemoveItems received empty reply"); | ||
305 | } | ||
306 | catch (Exception e) | ||
307 | { | ||
308 | m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting avatar server: {0}", e.Message); | ||
309 | } | ||
310 | |||
311 | return false; | ||
312 | } | ||
313 | |||
314 | #endregion | ||
315 | |||
316 | } | ||
317 | } | ||
diff --git a/OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs b/OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs new file mode 100644 index 0000000..baefebd --- /dev/null +++ b/OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs | |||
@@ -0,0 +1,241 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using log4net; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; | ||
39 | using OpenSim.Server.Base; | ||
40 | using OpenMetaverse; | ||
41 | |||
42 | namespace OpenSim.Services.Connectors | ||
43 | { | ||
44 | public class FriendsServicesConnector : IFriendsService | ||
45 | { | ||
46 | private static readonly ILog m_log = | ||
47 | LogManager.GetLogger( | ||
48 | MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | private string m_ServerURI = String.Empty; | ||
51 | |||
52 | public FriendsServicesConnector() | ||
53 | { | ||
54 | } | ||
55 | |||
56 | public FriendsServicesConnector(string serverURI) | ||
57 | { | ||
58 | m_ServerURI = serverURI.TrimEnd('/'); | ||
59 | } | ||
60 | |||
61 | public FriendsServicesConnector(IConfigSource source) | ||
62 | { | ||
63 | Initialise(source); | ||
64 | } | ||
65 | |||
66 | public virtual void Initialise(IConfigSource source) | ||
67 | { | ||
68 | IConfig gridConfig = source.Configs["FriendsService"]; | ||
69 | if (gridConfig == null) | ||
70 | { | ||
71 | m_log.Error("[FRIENDS CONNECTOR]: FriendsService missing from OpenSim.ini"); | ||
72 | throw new Exception("Friends connector init error"); | ||
73 | } | ||
74 | |||
75 | string serviceURI = gridConfig.GetString("FriendsServerURI", | ||
76 | String.Empty); | ||
77 | |||
78 | if (serviceURI == String.Empty) | ||
79 | { | ||
80 | m_log.Error("[FRIENDS CONNECTOR]: No Server URI named in section FriendsService"); | ||
81 | throw new Exception("Friends connector init error"); | ||
82 | } | ||
83 | m_ServerURI = serviceURI; | ||
84 | } | ||
85 | |||
86 | |||
87 | #region IFriendsService | ||
88 | |||
89 | public FriendInfo[] GetFriends(UUID PrincipalID) | ||
90 | { | ||
91 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
92 | |||
93 | sendData["PRINCIPALID"] = PrincipalID.ToString(); | ||
94 | sendData["METHOD"] = "getfriends"; | ||
95 | |||
96 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
97 | |||
98 | try | ||
99 | { | ||
100 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
101 | m_ServerURI + "/friends", | ||
102 | reqString); | ||
103 | if (reply != string.Empty) | ||
104 | { | ||
105 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
106 | |||
107 | if (replyData != null) | ||
108 | { | ||
109 | if (replyData.ContainsKey("result") && (replyData["result"].ToString().ToLower() == "null")) | ||
110 | { | ||
111 | return new FriendInfo[0]; | ||
112 | } | ||
113 | |||
114 | List<FriendInfo> finfos = new List<FriendInfo>(); | ||
115 | Dictionary<string, object>.ValueCollection finfosList = replyData.Values; | ||
116 | //m_log.DebugFormat("[FRIENDS CONNECTOR]: get neighbours returned {0} elements", rinfosList.Count); | ||
117 | foreach (object f in finfosList) | ||
118 | { | ||
119 | if (f is Dictionary<string, object>) | ||
120 | { | ||
121 | FriendInfo finfo = new FriendInfo((Dictionary<string, object>)f); | ||
122 | finfos.Add(finfo); | ||
123 | } | ||
124 | else | ||
125 | m_log.DebugFormat("[FRIENDS CONNECTOR]: GetFriends {0} received invalid response type {1}", | ||
126 | PrincipalID, f.GetType()); | ||
127 | } | ||
128 | |||
129 | // Success | ||
130 | return finfos.ToArray(); | ||
131 | } | ||
132 | |||
133 | else | ||
134 | m_log.DebugFormat("[FRIENDS CONNECTOR]: GetFriends {0} received null response", | ||
135 | PrincipalID); | ||
136 | |||
137 | } | ||
138 | } | ||
139 | catch (Exception e) | ||
140 | { | ||
141 | m_log.DebugFormat("[FRIENDS CONNECTOR]: Exception when contacting friends server: {0}", e.Message); | ||
142 | } | ||
143 | |||
144 | return new FriendInfo[0]; | ||
145 | |||
146 | } | ||
147 | |||
148 | public bool StoreFriend(UUID PrincipalID, string Friend, int flags) | ||
149 | { | ||
150 | FriendInfo finfo = new FriendInfo(); | ||
151 | finfo.PrincipalID = PrincipalID; | ||
152 | finfo.Friend = Friend; | ||
153 | finfo.MyFlags = flags; | ||
154 | |||
155 | Dictionary<string, object> sendData = finfo.ToKeyValuePairs(); | ||
156 | |||
157 | sendData["METHOD"] = "storefriend"; | ||
158 | |||
159 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
160 | |||
161 | string reply = string.Empty; | ||
162 | try | ||
163 | { | ||
164 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
165 | m_ServerURI + "/friends", | ||
166 | ServerUtils.BuildQueryString(sendData)); | ||
167 | } | ||
168 | catch (Exception e) | ||
169 | { | ||
170 | m_log.DebugFormat("[FRIENDS CONNECTOR]: Exception when contacting friends server: {0}", e.Message); | ||
171 | return false; | ||
172 | } | ||
173 | |||
174 | if (reply != string.Empty) | ||
175 | { | ||
176 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
177 | |||
178 | if ((replyData != null) && replyData.ContainsKey("Result") && (replyData["Result"] != null)) | ||
179 | { | ||
180 | bool success = false; | ||
181 | Boolean.TryParse(replyData["Result"].ToString(), out success); | ||
182 | return success; | ||
183 | } | ||
184 | else | ||
185 | m_log.DebugFormat("[FRIENDS CONNECTOR]: StoreFriend {0} {1} received null response", | ||
186 | PrincipalID, Friend); | ||
187 | } | ||
188 | else | ||
189 | m_log.DebugFormat("[FRIENDS CONNECTOR]: StoreFriend received null reply"); | ||
190 | |||
191 | return false; | ||
192 | |||
193 | } | ||
194 | |||
195 | public bool Delete(UUID PrincipalID, string Friend) | ||
196 | { | ||
197 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
198 | sendData["PRINCIPALID"] = PrincipalID.ToString(); | ||
199 | sendData["FRIENDS"] = Friend; | ||
200 | sendData["METHOD"] = "deletefriend"; | ||
201 | |||
202 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
203 | |||
204 | string reply = string.Empty; | ||
205 | try | ||
206 | { | ||
207 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
208 | m_ServerURI + "/friends", | ||
209 | ServerUtils.BuildQueryString(sendData)); | ||
210 | } | ||
211 | catch (Exception e) | ||
212 | { | ||
213 | m_log.DebugFormat("[FRIENDS CONNECTOR]: Exception when contacting friends server: {0}", e.Message); | ||
214 | return false; | ||
215 | } | ||
216 | |||
217 | if (reply != string.Empty) | ||
218 | { | ||
219 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
220 | |||
221 | if ((replyData != null) && replyData.ContainsKey("Result") && (replyData["Result"] != null)) | ||
222 | { | ||
223 | bool success = false; | ||
224 | Boolean.TryParse(replyData["Result"].ToString(), out success); | ||
225 | return success; | ||
226 | } | ||
227 | else | ||
228 | m_log.DebugFormat("[FRIENDS CONNECTOR]: DeleteFriend {0} {1} received null response", | ||
229 | PrincipalID, Friend); | ||
230 | } | ||
231 | else | ||
232 | m_log.DebugFormat("[FRIENDS CONNECTOR]: DeleteFriend received null reply"); | ||
233 | |||
234 | return false; | ||
235 | |||
236 | } | ||
237 | |||
238 | #endregion | ||
239 | |||
240 | } | ||
241 | } | ||
diff --git a/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs b/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs new file mode 100644 index 0000000..a29ac28 --- /dev/null +++ b/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs | |||
@@ -0,0 +1,167 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | |||
32 | using OpenSim.Services.Interfaces; | ||
33 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
34 | using OpenSim.Server.Base; | ||
35 | using OpenSim.Framework.Servers.HttpServer; | ||
36 | |||
37 | using OpenMetaverse; | ||
38 | using log4net; | ||
39 | |||
40 | namespace OpenSim.Services.Connectors.Friends | ||
41 | { | ||
42 | public class FriendsSimConnector | ||
43 | { | ||
44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
45 | |||
46 | public bool FriendshipOffered(GridRegion region, UUID userID, UUID friendID, string message) | ||
47 | { | ||
48 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
49 | //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
50 | //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
51 | sendData["METHOD"] = "friendship_offered"; | ||
52 | |||
53 | sendData["FromID"] = userID.ToString(); | ||
54 | sendData["ToID"] = friendID.ToString(); | ||
55 | sendData["Message"] = message; | ||
56 | |||
57 | return Call(region, sendData); | ||
58 | |||
59 | } | ||
60 | |||
61 | public bool FriendshipApproved(GridRegion region, UUID userID, string userName, UUID friendID) | ||
62 | { | ||
63 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
64 | //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
65 | //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
66 | sendData["METHOD"] = "friendship_approved"; | ||
67 | |||
68 | sendData["FromID"] = userID.ToString(); | ||
69 | sendData["FromName"] = userName; | ||
70 | sendData["ToID"] = friendID.ToString(); | ||
71 | |||
72 | return Call(region, sendData); | ||
73 | } | ||
74 | |||
75 | public bool FriendshipDenied(GridRegion region, UUID userID, string userName, UUID friendID) | ||
76 | { | ||
77 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
78 | //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
79 | //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
80 | sendData["METHOD"] = "friendship_denied"; | ||
81 | |||
82 | sendData["FromID"] = userID.ToString(); | ||
83 | sendData["FromName"] = userName; | ||
84 | sendData["ToID"] = friendID.ToString(); | ||
85 | |||
86 | return Call(region, sendData); | ||
87 | } | ||
88 | |||
89 | public bool FriendshipTerminated(GridRegion region, UUID userID, UUID friendID) | ||
90 | { | ||
91 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
92 | //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
93 | //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
94 | sendData["METHOD"] = "friendship_terminated"; | ||
95 | |||
96 | sendData["FromID"] = userID.ToString(); | ||
97 | sendData["ToID"] = friendID.ToString(); | ||
98 | |||
99 | return Call(region, sendData); | ||
100 | } | ||
101 | |||
102 | public bool GrantRights(GridRegion region, UUID userID, UUID friendID, int userFlags, int rights) | ||
103 | { | ||
104 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
105 | //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
106 | //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
107 | sendData["METHOD"] = "grant_rights"; | ||
108 | |||
109 | sendData["FromID"] = userID.ToString(); | ||
110 | sendData["ToID"] = friendID.ToString(); | ||
111 | sendData["UserFlags"] = userFlags.ToString(); | ||
112 | sendData["Rights"] = rights.ToString(); | ||
113 | |||
114 | return Call(region, sendData); | ||
115 | } | ||
116 | |||
117 | public bool StatusNotify(GridRegion region, UUID userID, UUID friendID, bool online) | ||
118 | { | ||
119 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
120 | //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
121 | //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
122 | sendData["METHOD"] = "status"; | ||
123 | |||
124 | sendData["FromID"] = userID.ToString(); | ||
125 | sendData["ToID"] = friendID.ToString(); | ||
126 | sendData["Online"] = online.ToString(); | ||
127 | |||
128 | return Call(region, sendData); | ||
129 | } | ||
130 | |||
131 | private bool Call(GridRegion region, Dictionary<string, object> sendData) | ||
132 | { | ||
133 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
134 | // m_log.DebugFormat("[FRIENDS CONNECTOR]: queryString = {0}", reqString); | ||
135 | try | ||
136 | { | ||
137 | string url = "http://" + region.ExternalHostName + ":" + region.HttpPort; | ||
138 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
139 | url + "/friends", | ||
140 | reqString); | ||
141 | if (reply != string.Empty) | ||
142 | { | ||
143 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
144 | |||
145 | if (replyData.ContainsKey("RESULT")) | ||
146 | { | ||
147 | if (replyData["RESULT"].ToString().ToLower() == "true") | ||
148 | return true; | ||
149 | else | ||
150 | return false; | ||
151 | } | ||
152 | else | ||
153 | m_log.DebugFormat("[FRIENDS CONNECTOR]: reply data does not contain result field"); | ||
154 | |||
155 | } | ||
156 | else | ||
157 | m_log.DebugFormat("[FRIENDS CONNECTOR]: received empty reply"); | ||
158 | } | ||
159 | catch (Exception e) | ||
160 | { | ||
161 | m_log.DebugFormat("[FRIENDS CONNECTOR]: Exception when contacting remote sim: {0}", e.Message); | ||
162 | } | ||
163 | |||
164 | return false; | ||
165 | } | ||
166 | } | ||
167 | } | ||
diff --git a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs index 04c7c53..a453d99 100644 --- a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs +++ b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs | |||
@@ -460,6 +460,153 @@ namespace OpenSim.Services.Connectors | |||
460 | return rinfos; | 460 | return rinfos; |
461 | } | 461 | } |
462 | 462 | ||
463 | public List<GridRegion> GetDefaultRegions(UUID scopeID) | ||
464 | { | ||
465 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
466 | |||
467 | sendData["SCOPEID"] = scopeID.ToString(); | ||
468 | |||
469 | sendData["METHOD"] = "get_default_regions"; | ||
470 | |||
471 | List<GridRegion> rinfos = new List<GridRegion>(); | ||
472 | string reply = string.Empty; | ||
473 | try | ||
474 | { | ||
475 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
476 | m_ServerURI + "/grid", | ||
477 | ServerUtils.BuildQueryString(sendData)); | ||
478 | |||
479 | //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); | ||
480 | } | ||
481 | catch (Exception e) | ||
482 | { | ||
483 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message); | ||
484 | return rinfos; | ||
485 | } | ||
486 | |||
487 | if (reply != string.Empty) | ||
488 | { | ||
489 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
490 | |||
491 | if (replyData != null) | ||
492 | { | ||
493 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; | ||
494 | foreach (object r in rinfosList) | ||
495 | { | ||
496 | if (r is Dictionary<string, object>) | ||
497 | { | ||
498 | GridRegion rinfo = new GridRegion((Dictionary<string, object>)r); | ||
499 | rinfos.Add(rinfo); | ||
500 | } | ||
501 | } | ||
502 | } | ||
503 | else | ||
504 | m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultRegions {0} received null response", | ||
505 | scopeID); | ||
506 | } | ||
507 | else | ||
508 | m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultRegions received null reply"); | ||
509 | |||
510 | return rinfos; | ||
511 | } | ||
512 | |||
513 | public List<GridRegion> GetFallbackRegions(UUID scopeID, int x, int y) | ||
514 | { | ||
515 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
516 | |||
517 | sendData["SCOPEID"] = scopeID.ToString(); | ||
518 | sendData["X"] = x.ToString(); | ||
519 | sendData["Y"] = y.ToString(); | ||
520 | |||
521 | sendData["METHOD"] = "get_fallback_regions"; | ||
522 | |||
523 | List<GridRegion> rinfos = new List<GridRegion>(); | ||
524 | string reply = string.Empty; | ||
525 | try | ||
526 | { | ||
527 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
528 | m_ServerURI + "/grid", | ||
529 | ServerUtils.BuildQueryString(sendData)); | ||
530 | |||
531 | //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); | ||
532 | } | ||
533 | catch (Exception e) | ||
534 | { | ||
535 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message); | ||
536 | return rinfos; | ||
537 | } | ||
538 | |||
539 | if (reply != string.Empty) | ||
540 | { | ||
541 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
542 | |||
543 | if (replyData != null) | ||
544 | { | ||
545 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; | ||
546 | foreach (object r in rinfosList) | ||
547 | { | ||
548 | if (r is Dictionary<string, object>) | ||
549 | { | ||
550 | GridRegion rinfo = new GridRegion((Dictionary<string, object>)r); | ||
551 | rinfos.Add(rinfo); | ||
552 | } | ||
553 | } | ||
554 | } | ||
555 | else | ||
556 | m_log.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions {0}, {1}-{2} received null response", | ||
557 | scopeID, x, y); | ||
558 | } | ||
559 | else | ||
560 | m_log.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions received null reply"); | ||
561 | |||
562 | return rinfos; | ||
563 | } | ||
564 | |||
565 | public virtual int GetRegionFlags(UUID scopeID, UUID regionID) | ||
566 | { | ||
567 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
568 | |||
569 | sendData["SCOPEID"] = scopeID.ToString(); | ||
570 | sendData["REGIONID"] = regionID.ToString(); | ||
571 | |||
572 | sendData["METHOD"] = "get_region_flags"; | ||
573 | |||
574 | string reply = string.Empty; | ||
575 | try | ||
576 | { | ||
577 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
578 | m_ServerURI + "/grid", | ||
579 | ServerUtils.BuildQueryString(sendData)); | ||
580 | } | ||
581 | catch (Exception e) | ||
582 | { | ||
583 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message); | ||
584 | return -1; | ||
585 | } | ||
586 | |||
587 | int flags = -1; | ||
588 | |||
589 | if (reply != string.Empty) | ||
590 | { | ||
591 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
592 | |||
593 | if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) | ||
594 | { | ||
595 | Int32.TryParse((string)replyData["result"], out flags); | ||
596 | //else | ||
597 | // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags {0}, {1} received wrong type {2}", | ||
598 | // scopeID, regionID, replyData["result"].GetType()); | ||
599 | } | ||
600 | else | ||
601 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags {0}, {1} received null response", | ||
602 | scopeID, regionID); | ||
603 | } | ||
604 | else | ||
605 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags received null reply"); | ||
606 | |||
607 | return flags; | ||
608 | } | ||
609 | |||
463 | #endregion | 610 | #endregion |
464 | 611 | ||
465 | } | 612 | } |
diff --git a/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs b/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs deleted file mode 100644 index 7098b07..0000000 --- a/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs +++ /dev/null | |||
@@ -1,254 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | using System.Drawing; | ||
33 | using System.Net; | ||
34 | using System.Reflection; | ||
35 | using OpenSim.Services.Interfaces; | ||
36 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
37 | |||
38 | using OpenSim.Framework; | ||
39 | |||
40 | using OpenMetaverse; | ||
41 | using OpenMetaverse.Imaging; | ||
42 | using log4net; | ||
43 | using Nwc.XmlRpc; | ||
44 | |||
45 | namespace OpenSim.Services.Connectors.Grid | ||
46 | { | ||
47 | public class HypergridServiceConnector | ||
48 | { | ||
49 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | |||
51 | private IAssetService m_AssetService; | ||
52 | |||
53 | public HypergridServiceConnector(IAssetService assService) | ||
54 | { | ||
55 | m_AssetService = assService; | ||
56 | } | ||
57 | |||
58 | public UUID LinkRegion(GridRegion info, out ulong realHandle) | ||
59 | { | ||
60 | UUID uuid = UUID.Zero; | ||
61 | realHandle = 0; | ||
62 | |||
63 | Hashtable hash = new Hashtable(); | ||
64 | hash["region_name"] = info.RegionName; | ||
65 | |||
66 | IList paramList = new ArrayList(); | ||
67 | paramList.Add(hash); | ||
68 | |||
69 | XmlRpcRequest request = new XmlRpcRequest("link_region", paramList); | ||
70 | string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/"; | ||
71 | m_log.Debug("[HGrid]: Linking to " + uri); | ||
72 | XmlRpcResponse response = null; | ||
73 | try | ||
74 | { | ||
75 | response = request.Send(uri, 10000); | ||
76 | } | ||
77 | catch (Exception e) | ||
78 | { | ||
79 | m_log.Debug("[HGrid]: Exception " + e.Message); | ||
80 | return uuid; | ||
81 | } | ||
82 | |||
83 | if (response.IsFault) | ||
84 | { | ||
85 | m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString); | ||
86 | } | ||
87 | else | ||
88 | { | ||
89 | hash = (Hashtable)response.Value; | ||
90 | //foreach (Object o in hash) | ||
91 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); | ||
92 | try | ||
93 | { | ||
94 | UUID.TryParse((string)hash["uuid"], out uuid); | ||
95 | //m_log.Debug(">> HERE, uuid: " + uuid); | ||
96 | info.RegionID = uuid; | ||
97 | if ((string)hash["handle"] != null) | ||
98 | { | ||
99 | realHandle = Convert.ToUInt64((string)hash["handle"]); | ||
100 | //m_log.Debug(">> HERE, realHandle: " + realHandle); | ||
101 | } | ||
102 | //if (hash["region_image"] != null) | ||
103 | //{ | ||
104 | // UUID img = UUID.Zero; | ||
105 | // UUID.TryParse((string)hash["region_image"], out img); | ||
106 | // info.RegionSettings.TerrainImageID = img; | ||
107 | //} | ||
108 | if (hash["region_name"] != null) | ||
109 | { | ||
110 | info.RegionName = (string)hash["region_name"]; | ||
111 | //m_log.Debug(">> " + info.RegionName); | ||
112 | } | ||
113 | if (hash["internal_port"] != null) | ||
114 | { | ||
115 | int port = Convert.ToInt32((string)hash["internal_port"]); | ||
116 | info.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), port); | ||
117 | //m_log.Debug(">> " + info.InternalEndPoint.ToString()); | ||
118 | } | ||
119 | |||
120 | } | ||
121 | catch (Exception e) | ||
122 | { | ||
123 | m_log.Error("[HGrid]: Got exception while parsing hyperlink response " + e.StackTrace); | ||
124 | } | ||
125 | } | ||
126 | return uuid; | ||
127 | } | ||
128 | |||
129 | public void GetMapImage(GridRegion info) | ||
130 | { | ||
131 | try | ||
132 | { | ||
133 | string regionimage = "regionImage" + info.RegionID.ToString(); | ||
134 | regionimage = regionimage.Replace("-", ""); | ||
135 | |||
136 | WebClient c = new WebClient(); | ||
137 | string uri = "http://" + info.ExternalHostName + ":" + info.HttpPort + "/index.php?method=" + regionimage; | ||
138 | //m_log.Debug("JPEG: " + uri); | ||
139 | c.DownloadFile(uri, info.RegionID.ToString() + ".jpg"); | ||
140 | Bitmap m = new Bitmap(info.RegionID.ToString() + ".jpg"); | ||
141 | //m_log.Debug("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width); | ||
142 | byte[] imageData = OpenJPEG.EncodeFromImage(m, true); | ||
143 | AssetBase ass = new AssetBase(UUID.Random(), "region " + info.RegionID.ToString(), (sbyte)AssetType.Texture); | ||
144 | |||
145 | // !!! for now | ||
146 | //info.RegionSettings.TerrainImageID = ass.FullID; | ||
147 | |||
148 | ass.Temporary = true; | ||
149 | ass.Local = true; | ||
150 | ass.Data = imageData; | ||
151 | |||
152 | m_AssetService.Store(ass); | ||
153 | |||
154 | // finally | ||
155 | info.TerrainImage = ass.FullID; | ||
156 | |||
157 | } | ||
158 | catch // LEGIT: Catching problems caused by OpenJPEG p/invoke | ||
159 | { | ||
160 | m_log.Warn("[HGrid]: Failed getting/storing map image, because it is probably already in the cache"); | ||
161 | } | ||
162 | } | ||
163 | |||
164 | public bool InformRegionOfUser(GridRegion regInfo, AgentCircuitData agentData, GridRegion home, string userServer, string assetServer, string inventoryServer) | ||
165 | { | ||
166 | string capsPath = agentData.CapsPath; | ||
167 | Hashtable loginParams = new Hashtable(); | ||
168 | loginParams["session_id"] = agentData.SessionID.ToString(); | ||
169 | |||
170 | loginParams["firstname"] = agentData.firstname; | ||
171 | loginParams["lastname"] = agentData.lastname; | ||
172 | |||
173 | loginParams["agent_id"] = agentData.AgentID.ToString(); | ||
174 | loginParams["circuit_code"] = agentData.circuitcode.ToString(); | ||
175 | loginParams["startpos_x"] = agentData.startpos.X.ToString(); | ||
176 | loginParams["startpos_y"] = agentData.startpos.Y.ToString(); | ||
177 | loginParams["startpos_z"] = agentData.startpos.Z.ToString(); | ||
178 | loginParams["caps_path"] = capsPath; | ||
179 | |||
180 | if (home != null) | ||
181 | { | ||
182 | loginParams["region_uuid"] = home.RegionID.ToString(); | ||
183 | loginParams["regionhandle"] = home.RegionHandle.ToString(); | ||
184 | loginParams["home_address"] = home.ExternalHostName; | ||
185 | loginParams["home_port"] = home.HttpPort.ToString(); | ||
186 | loginParams["internal_port"] = home.InternalEndPoint.Port.ToString(); | ||
187 | |||
188 | m_log.Debug(" --------- Home -------"); | ||
189 | m_log.Debug(" >> " + loginParams["home_address"] + " <<"); | ||
190 | m_log.Debug(" >> " + loginParams["region_uuid"] + " <<"); | ||
191 | m_log.Debug(" >> " + loginParams["regionhandle"] + " <<"); | ||
192 | m_log.Debug(" >> " + loginParams["home_port"] + " <<"); | ||
193 | m_log.Debug(" --------- ------------ -------"); | ||
194 | } | ||
195 | else | ||
196 | m_log.WarnFormat("[HGrid]: Home region not found for {0} {1}", agentData.firstname, agentData.lastname); | ||
197 | |||
198 | loginParams["userserver_id"] = userServer; | ||
199 | loginParams["assetserver_id"] = assetServer; | ||
200 | loginParams["inventoryserver_id"] = inventoryServer; | ||
201 | |||
202 | |||
203 | ArrayList SendParams = new ArrayList(); | ||
204 | SendParams.Add(loginParams); | ||
205 | |||
206 | // Send | ||
207 | string uri = "http://" + regInfo.ExternalHostName + ":" + regInfo.HttpPort + "/"; | ||
208 | //m_log.Debug("XXX uri: " + uri); | ||
209 | XmlRpcRequest request = new XmlRpcRequest("expect_hg_user", SendParams); | ||
210 | XmlRpcResponse reply; | ||
211 | try | ||
212 | { | ||
213 | reply = request.Send(uri, 6000); | ||
214 | } | ||
215 | catch (Exception e) | ||
216 | { | ||
217 | m_log.Warn("[HGrid]: Failed to notify region about user. Reason: " + e.Message); | ||
218 | return false; | ||
219 | } | ||
220 | |||
221 | if (!reply.IsFault) | ||
222 | { | ||
223 | bool responseSuccess = true; | ||
224 | if (reply.Value != null) | ||
225 | { | ||
226 | Hashtable resp = (Hashtable)reply.Value; | ||
227 | if (resp.ContainsKey("success")) | ||
228 | { | ||
229 | if ((string)resp["success"] == "FALSE") | ||
230 | { | ||
231 | responseSuccess = false; | ||
232 | } | ||
233 | } | ||
234 | } | ||
235 | if (responseSuccess) | ||
236 | { | ||
237 | m_log.Info("[HGrid]: Successfully informed remote region about user " + agentData.AgentID); | ||
238 | return true; | ||
239 | } | ||
240 | else | ||
241 | { | ||
242 | m_log.ErrorFormat("[HGrid]: Region responded that it is not available to receive clients"); | ||
243 | return false; | ||
244 | } | ||
245 | } | ||
246 | else | ||
247 | { | ||
248 | m_log.ErrorFormat("[HGrid]: XmlRpc request to region failed with message {0}, code {1} ", reply.FaultString, reply.FaultCode); | ||
249 | return false; | ||
250 | } | ||
251 | } | ||
252 | |||
253 | } | ||
254 | } | ||
diff --git a/OpenSim/Grid/Manager/OpenGridServices.Manager/ConnectToGridServer.cs b/OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs index 25f25a7..ce88236 100644 --- a/OpenSim/Grid/Manager/OpenGridServices.Manager/ConnectToGridServer.cs +++ b/OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs | |||
@@ -27,13 +27,12 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | 29 | ||
30 | namespace OpenGridServices.Manager | 30 | namespace OpenSim.Services.Connectors |
31 | { | 31 | { |
32 | public partial class Connect to grid server : Gtk.Dialog | 32 | public class GridUserServiceConnector |
33 | { | 33 | { |
34 | public Connect to grid server() | 34 | public GridUserServiceConnector() |
35 | { | 35 | { |
36 | this.Build(); | ||
37 | } | 36 | } |
38 | } | 37 | } |
39 | } | 38 | } |
diff --git a/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs new file mode 100644 index 0000000..9f73b38 --- /dev/null +++ b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs | |||
@@ -0,0 +1,245 @@ | |||
1 | using System; | ||
2 | using System.Collections; | ||
3 | using System.Collections.Generic; | ||
4 | using System.Drawing; | ||
5 | using System.Net; | ||
6 | using System.Reflection; | ||
7 | |||
8 | using OpenSim.Framework; | ||
9 | using OpenSim.Services.Interfaces; | ||
10 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
11 | |||
12 | using OpenMetaverse; | ||
13 | using OpenMetaverse.Imaging; | ||
14 | using Nwc.XmlRpc; | ||
15 | using log4net; | ||
16 | |||
17 | using OpenSim.Services.Connectors.Simulation; | ||
18 | |||
19 | namespace OpenSim.Services.Connectors.Hypergrid | ||
20 | { | ||
21 | public class GatekeeperServiceConnector : SimulationServiceConnector | ||
22 | { | ||
23 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
24 | |||
25 | private static UUID m_HGMapImage = new UUID("00000000-0000-1111-9999-000000000013"); | ||
26 | |||
27 | private IAssetService m_AssetService; | ||
28 | |||
29 | public GatekeeperServiceConnector() : base() | ||
30 | { | ||
31 | } | ||
32 | |||
33 | public GatekeeperServiceConnector(IAssetService assService) | ||
34 | { | ||
35 | m_AssetService = assService; | ||
36 | } | ||
37 | |||
38 | protected override string AgentPath() | ||
39 | { | ||
40 | return "/foreignagent/"; | ||
41 | } | ||
42 | |||
43 | protected override string ObjectPath() | ||
44 | { | ||
45 | return "/foreignobject/"; | ||
46 | } | ||
47 | |||
48 | public bool LinkRegion(GridRegion info, out UUID regionID, out ulong realHandle, out string externalName, out string imageURL, out string reason) | ||
49 | { | ||
50 | regionID = UUID.Zero; | ||
51 | imageURL = string.Empty; | ||
52 | realHandle = 0; | ||
53 | externalName = string.Empty; | ||
54 | reason = string.Empty; | ||
55 | |||
56 | Hashtable hash = new Hashtable(); | ||
57 | hash["region_name"] = info.RegionName; | ||
58 | |||
59 | IList paramList = new ArrayList(); | ||
60 | paramList.Add(hash); | ||
61 | |||
62 | XmlRpcRequest request = new XmlRpcRequest("link_region", paramList); | ||
63 | string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/"; | ||
64 | //m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: Linking to " + uri); | ||
65 | XmlRpcResponse response = null; | ||
66 | try | ||
67 | { | ||
68 | response = request.Send(uri, 10000); | ||
69 | } | ||
70 | catch (Exception e) | ||
71 | { | ||
72 | m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: Exception " + e.Message); | ||
73 | reason = "Error contacting remote server"; | ||
74 | return false; | ||
75 | } | ||
76 | |||
77 | if (response.IsFault) | ||
78 | { | ||
79 | reason = response.FaultString; | ||
80 | m_log.ErrorFormat("[GATEKEEPER SERVICE CONNECTOR]: remote call returned an error: {0}", response.FaultString); | ||
81 | return false; | ||
82 | } | ||
83 | |||
84 | hash = (Hashtable)response.Value; | ||
85 | //foreach (Object o in hash) | ||
86 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); | ||
87 | try | ||
88 | { | ||
89 | bool success = false; | ||
90 | Boolean.TryParse((string)hash["result"], out success); | ||
91 | if (success) | ||
92 | { | ||
93 | UUID.TryParse((string)hash["uuid"], out regionID); | ||
94 | //m_log.Debug(">> HERE, uuid: " + uuid); | ||
95 | if ((string)hash["handle"] != null) | ||
96 | { | ||
97 | realHandle = Convert.ToUInt64((string)hash["handle"]); | ||
98 | //m_log.Debug(">> HERE, realHandle: " + realHandle); | ||
99 | } | ||
100 | if (hash["region_image"] != null) | ||
101 | imageURL = (string)hash["region_image"]; | ||
102 | if (hash["external_name"] != null) | ||
103 | externalName = (string)hash["external_name"]; | ||
104 | } | ||
105 | |||
106 | } | ||
107 | catch (Exception e) | ||
108 | { | ||
109 | reason = "Error parsing return arguments"; | ||
110 | m_log.Error("[GATEKEEPER SERVICE CONNECTOR]: Got exception while parsing hyperlink response " + e.StackTrace); | ||
111 | return false; | ||
112 | } | ||
113 | |||
114 | return true; | ||
115 | } | ||
116 | |||
117 | UUID m_MissingTexture = new UUID("5748decc-f629-461c-9a36-a35a221fe21f"); | ||
118 | |||
119 | public UUID GetMapImage(UUID regionID, string imageURL) | ||
120 | { | ||
121 | if (m_AssetService == null) | ||
122 | return m_MissingTexture; | ||
123 | |||
124 | try | ||
125 | { | ||
126 | |||
127 | WebClient c = new WebClient(); | ||
128 | //m_log.Debug("JPEG: " + imageURL); | ||
129 | string filename = regionID.ToString(); | ||
130 | c.DownloadFile(imageURL, filename + ".jpg"); | ||
131 | Bitmap m = new Bitmap(filename + ".jpg"); | ||
132 | //m_log.Debug("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width); | ||
133 | byte[] imageData = OpenJPEG.EncodeFromImage(m, true); | ||
134 | AssetBase ass = new AssetBase(UUID.Random(), "region " + filename, (sbyte)AssetType.Texture, regionID.ToString()); | ||
135 | |||
136 | // !!! for now | ||
137 | //info.RegionSettings.TerrainImageID = ass.FullID; | ||
138 | |||
139 | ass.Temporary = true; | ||
140 | ass.Local = true; | ||
141 | ass.Data = imageData; | ||
142 | |||
143 | m_AssetService.Store(ass); | ||
144 | |||
145 | // finally | ||
146 | return ass.FullID; | ||
147 | |||
148 | } | ||
149 | catch // LEGIT: Catching problems caused by OpenJPEG p/invoke | ||
150 | { | ||
151 | m_log.Warn("[GATEKEEPER SERVICE CONNECTOR]: Failed getting/storing map image, because it is probably already in the cache"); | ||
152 | } | ||
153 | return UUID.Zero; | ||
154 | } | ||
155 | |||
156 | public GridRegion GetHyperlinkRegion(GridRegion gatekeeper, UUID regionID) | ||
157 | { | ||
158 | Hashtable hash = new Hashtable(); | ||
159 | hash["region_uuid"] = regionID.ToString(); | ||
160 | |||
161 | IList paramList = new ArrayList(); | ||
162 | paramList.Add(hash); | ||
163 | |||
164 | XmlRpcRequest request = new XmlRpcRequest("get_region", paramList); | ||
165 | string uri = "http://" + gatekeeper.ExternalEndPoint.Address + ":" + gatekeeper.HttpPort + "/"; | ||
166 | m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: contacting " + uri); | ||
167 | XmlRpcResponse response = null; | ||
168 | try | ||
169 | { | ||
170 | response = request.Send(uri, 10000); | ||
171 | } | ||
172 | catch (Exception e) | ||
173 | { | ||
174 | m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: Exception " + e.Message); | ||
175 | return null; | ||
176 | } | ||
177 | |||
178 | if (response.IsFault) | ||
179 | { | ||
180 | m_log.ErrorFormat("[GATEKEEPER SERVICE CONNECTOR]: remote call returned an error: {0}", response.FaultString); | ||
181 | return null; | ||
182 | } | ||
183 | |||
184 | hash = (Hashtable)response.Value; | ||
185 | //foreach (Object o in hash) | ||
186 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); | ||
187 | try | ||
188 | { | ||
189 | bool success = false; | ||
190 | Boolean.TryParse((string)hash["result"], out success); | ||
191 | if (success) | ||
192 | { | ||
193 | GridRegion region = new GridRegion(); | ||
194 | |||
195 | UUID.TryParse((string)hash["uuid"], out region.RegionID); | ||
196 | //m_log.Debug(">> HERE, uuid: " + region.RegionID); | ||
197 | int n = 0; | ||
198 | if (hash["x"] != null) | ||
199 | { | ||
200 | Int32.TryParse((string)hash["x"], out n); | ||
201 | region.RegionLocX = n; | ||
202 | //m_log.Debug(">> HERE, x: " + region.RegionLocX); | ||
203 | } | ||
204 | if (hash["y"] != null) | ||
205 | { | ||
206 | Int32.TryParse((string)hash["y"], out n); | ||
207 | region.RegionLocY = n; | ||
208 | //m_log.Debug(">> HERE, y: " + region.RegionLocY); | ||
209 | } | ||
210 | if (hash["region_name"] != null) | ||
211 | { | ||
212 | region.RegionName = (string)hash["region_name"]; | ||
213 | //m_log.Debug(">> HERE, name: " + region.RegionName); | ||
214 | } | ||
215 | if (hash["hostname"] != null) | ||
216 | region.ExternalHostName = (string)hash["hostname"]; | ||
217 | if (hash["http_port"] != null) | ||
218 | { | ||
219 | uint p = 0; | ||
220 | UInt32.TryParse((string)hash["http_port"], out p); | ||
221 | region.HttpPort = p; | ||
222 | } | ||
223 | if (hash["internal_port"] != null) | ||
224 | { | ||
225 | int p = 0; | ||
226 | Int32.TryParse((string)hash["internal_port"], out p); | ||
227 | region.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), p); | ||
228 | } | ||
229 | |||
230 | // Successful return | ||
231 | return region; | ||
232 | } | ||
233 | |||
234 | } | ||
235 | catch (Exception e) | ||
236 | { | ||
237 | m_log.Error("[GATEKEEPER SERVICE CONNECTOR]: Got exception while parsing hyperlink response " + e.StackTrace); | ||
238 | return null; | ||
239 | } | ||
240 | |||
241 | return null; | ||
242 | } | ||
243 | |||
244 | } | ||
245 | } | ||
diff --git a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs new file mode 100644 index 0000000..83d3449 --- /dev/null +++ b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs | |||
@@ -0,0 +1,370 @@ | |||
1 | using System; | ||
2 | using System.Collections; | ||
3 | using System.Collections.Generic; | ||
4 | using System.IO; | ||
5 | using System.Net; | ||
6 | using System.Reflection; | ||
7 | using System.Text; | ||
8 | |||
9 | using OpenSim.Framework; | ||
10 | using OpenSim.Services.Interfaces; | ||
11 | using OpenSim.Services.Connectors.Simulation; | ||
12 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
13 | |||
14 | using OpenMetaverse; | ||
15 | using OpenMetaverse.StructuredData; | ||
16 | using log4net; | ||
17 | using Nwc.XmlRpc; | ||
18 | using Nini.Config; | ||
19 | |||
20 | namespace OpenSim.Services.Connectors.Hypergrid | ||
21 | { | ||
22 | public class UserAgentServiceConnector : IUserAgentService | ||
23 | { | ||
24 | private static readonly ILog m_log = | ||
25 | LogManager.GetLogger( | ||
26 | MethodBase.GetCurrentMethod().DeclaringType); | ||
27 | |||
28 | string m_ServerURL; | ||
29 | public UserAgentServiceConnector(string url) | ||
30 | { | ||
31 | m_ServerURL = url; | ||
32 | } | ||
33 | |||
34 | public UserAgentServiceConnector(IConfigSource config) | ||
35 | { | ||
36 | } | ||
37 | |||
38 | public bool LoginAgentToGrid(AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination, out string reason) | ||
39 | { | ||
40 | reason = String.Empty; | ||
41 | |||
42 | if (destination == null) | ||
43 | { | ||
44 | reason = "Destination is null"; | ||
45 | m_log.Debug("[USER AGENT CONNECTOR]: Given destination is null"); | ||
46 | return false; | ||
47 | } | ||
48 | |||
49 | string uri = m_ServerURL + "/homeagent/" + aCircuit.AgentID + "/"; | ||
50 | |||
51 | Console.WriteLine(" >>> LoginAgentToGrid <<< " + uri); | ||
52 | |||
53 | HttpWebRequest AgentCreateRequest = (HttpWebRequest)WebRequest.Create(uri); | ||
54 | AgentCreateRequest.Method = "POST"; | ||
55 | AgentCreateRequest.ContentType = "application/json"; | ||
56 | AgentCreateRequest.Timeout = 10000; | ||
57 | //AgentCreateRequest.KeepAlive = false; | ||
58 | //AgentCreateRequest.Headers.Add("Authorization", authKey); | ||
59 | |||
60 | // Fill it in | ||
61 | OSDMap args = PackCreateAgentArguments(aCircuit, gatekeeper, destination); | ||
62 | |||
63 | string strBuffer = ""; | ||
64 | byte[] buffer = new byte[1]; | ||
65 | try | ||
66 | { | ||
67 | strBuffer = OSDParser.SerializeJsonString(args); | ||
68 | Encoding str = Util.UTF8; | ||
69 | buffer = str.GetBytes(strBuffer); | ||
70 | |||
71 | } | ||
72 | catch (Exception e) | ||
73 | { | ||
74 | m_log.WarnFormat("[USER AGENT CONNECTOR]: Exception thrown on serialization of ChildCreate: {0}", e.Message); | ||
75 | // ignore. buffer will be empty, caller should check. | ||
76 | } | ||
77 | |||
78 | Stream os = null; | ||
79 | try | ||
80 | { // send the Post | ||
81 | AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send | ||
82 | os = AgentCreateRequest.GetRequestStream(); | ||
83 | os.Write(buffer, 0, strBuffer.Length); //Send it | ||
84 | m_log.InfoFormat("[USER AGENT CONNECTOR]: Posted CreateAgent request to remote sim {0}, region {1}, x={2} y={3}", | ||
85 | uri, destination.RegionName, destination.RegionLocX, destination.RegionLocY); | ||
86 | } | ||
87 | //catch (WebException ex) | ||
88 | catch | ||
89 | { | ||
90 | //m_log.InfoFormat("[USER AGENT CONNECTOR]: Bad send on ChildAgentUpdate {0}", ex.Message); | ||
91 | reason = "cannot contact remote region"; | ||
92 | return false; | ||
93 | } | ||
94 | finally | ||
95 | { | ||
96 | if (os != null) | ||
97 | os.Close(); | ||
98 | } | ||
99 | |||
100 | // Let's wait for the response | ||
101 | //m_log.Info("[USER AGENT CONNECTOR]: Waiting for a reply after DoCreateChildAgentCall"); | ||
102 | |||
103 | WebResponse webResponse = null; | ||
104 | StreamReader sr = null; | ||
105 | try | ||
106 | { | ||
107 | webResponse = AgentCreateRequest.GetResponse(); | ||
108 | if (webResponse == null) | ||
109 | { | ||
110 | m_log.Info("[USER AGENT CONNECTOR]: Null reply on DoCreateChildAgentCall post"); | ||
111 | } | ||
112 | else | ||
113 | { | ||
114 | |||
115 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
116 | string response = sr.ReadToEnd().Trim(); | ||
117 | m_log.InfoFormat("[USER AGENT CONNECTOR]: DoCreateChildAgentCall reply was {0} ", response); | ||
118 | |||
119 | if (!String.IsNullOrEmpty(response)) | ||
120 | { | ||
121 | try | ||
122 | { | ||
123 | // we assume we got an OSDMap back | ||
124 | OSDMap r = Util.GetOSDMap(response); | ||
125 | bool success = r["success"].AsBoolean(); | ||
126 | reason = r["reason"].AsString(); | ||
127 | return success; | ||
128 | } | ||
129 | catch (NullReferenceException e) | ||
130 | { | ||
131 | m_log.InfoFormat("[USER AGENT CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", e.Message); | ||
132 | |||
133 | // check for old style response | ||
134 | if (response.ToLower().StartsWith("true")) | ||
135 | return true; | ||
136 | |||
137 | return false; | ||
138 | } | ||
139 | } | ||
140 | } | ||
141 | } | ||
142 | catch (WebException ex) | ||
143 | { | ||
144 | m_log.InfoFormat("[USER AGENT CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", ex.Message); | ||
145 | reason = "Destination did not reply"; | ||
146 | return false; | ||
147 | } | ||
148 | finally | ||
149 | { | ||
150 | if (sr != null) | ||
151 | sr.Close(); | ||
152 | } | ||
153 | |||
154 | return true; | ||
155 | |||
156 | } | ||
157 | |||
158 | protected OSDMap PackCreateAgentArguments(AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination) | ||
159 | { | ||
160 | OSDMap args = null; | ||
161 | try | ||
162 | { | ||
163 | args = aCircuit.PackAgentCircuitData(); | ||
164 | } | ||
165 | catch (Exception e) | ||
166 | { | ||
167 | m_log.Debug("[USER AGENT CONNECTOR]: PackAgentCircuitData failed with exception: " + e.Message); | ||
168 | } | ||
169 | // Add the input arguments | ||
170 | args["gatekeeper_host"] = OSD.FromString(gatekeeper.ExternalHostName); | ||
171 | args["gatekeeper_port"] = OSD.FromString(gatekeeper.HttpPort.ToString()); | ||
172 | args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString()); | ||
173 | args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString()); | ||
174 | args["destination_name"] = OSD.FromString(destination.RegionName); | ||
175 | args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString()); | ||
176 | |||
177 | return args; | ||
178 | } | ||
179 | |||
180 | public GridRegion GetHomeRegion(UUID userID, out Vector3 position, out Vector3 lookAt) | ||
181 | { | ||
182 | position = Vector3.UnitY; lookAt = Vector3.UnitY; | ||
183 | |||
184 | Hashtable hash = new Hashtable(); | ||
185 | hash["userID"] = userID.ToString(); | ||
186 | |||
187 | IList paramList = new ArrayList(); | ||
188 | paramList.Add(hash); | ||
189 | |||
190 | XmlRpcRequest request = new XmlRpcRequest("get_home_region", paramList); | ||
191 | XmlRpcResponse response = null; | ||
192 | try | ||
193 | { | ||
194 | response = request.Send(m_ServerURL, 10000); | ||
195 | } | ||
196 | catch (Exception e) | ||
197 | { | ||
198 | return null; | ||
199 | } | ||
200 | |||
201 | if (response.IsFault) | ||
202 | { | ||
203 | return null; | ||
204 | } | ||
205 | |||
206 | hash = (Hashtable)response.Value; | ||
207 | //foreach (Object o in hash) | ||
208 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); | ||
209 | try | ||
210 | { | ||
211 | bool success = false; | ||
212 | Boolean.TryParse((string)hash["result"], out success); | ||
213 | if (success) | ||
214 | { | ||
215 | GridRegion region = new GridRegion(); | ||
216 | |||
217 | UUID.TryParse((string)hash["uuid"], out region.RegionID); | ||
218 | //m_log.Debug(">> HERE, uuid: " + region.RegionID); | ||
219 | int n = 0; | ||
220 | if (hash["x"] != null) | ||
221 | { | ||
222 | Int32.TryParse((string)hash["x"], out n); | ||
223 | region.RegionLocX = n; | ||
224 | //m_log.Debug(">> HERE, x: " + region.RegionLocX); | ||
225 | } | ||
226 | if (hash["y"] != null) | ||
227 | { | ||
228 | Int32.TryParse((string)hash["y"], out n); | ||
229 | region.RegionLocY = n; | ||
230 | //m_log.Debug(">> HERE, y: " + region.RegionLocY); | ||
231 | } | ||
232 | if (hash["region_name"] != null) | ||
233 | { | ||
234 | region.RegionName = (string)hash["region_name"]; | ||
235 | //m_log.Debug(">> HERE, name: " + region.RegionName); | ||
236 | } | ||
237 | if (hash["hostname"] != null) | ||
238 | region.ExternalHostName = (string)hash["hostname"]; | ||
239 | if (hash["http_port"] != null) | ||
240 | { | ||
241 | uint p = 0; | ||
242 | UInt32.TryParse((string)hash["http_port"], out p); | ||
243 | region.HttpPort = p; | ||
244 | } | ||
245 | if (hash["internal_port"] != null) | ||
246 | { | ||
247 | int p = 0; | ||
248 | Int32.TryParse((string)hash["internal_port"], out p); | ||
249 | region.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), p); | ||
250 | } | ||
251 | if (hash["position"] != null) | ||
252 | Vector3.TryParse((string)hash["position"], out position); | ||
253 | if (hash["lookAt"] != null) | ||
254 | Vector3.TryParse((string)hash["lookAt"], out lookAt); | ||
255 | |||
256 | // Successful return | ||
257 | return region; | ||
258 | } | ||
259 | |||
260 | } | ||
261 | catch (Exception e) | ||
262 | { | ||
263 | return null; | ||
264 | } | ||
265 | |||
266 | return null; | ||
267 | |||
268 | } | ||
269 | |||
270 | public bool AgentIsComingHome(UUID sessionID, string thisGridExternalName) | ||
271 | { | ||
272 | Hashtable hash = new Hashtable(); | ||
273 | hash["sessionID"] = sessionID.ToString(); | ||
274 | hash["externalName"] = thisGridExternalName; | ||
275 | |||
276 | IList paramList = new ArrayList(); | ||
277 | paramList.Add(hash); | ||
278 | |||
279 | XmlRpcRequest request = new XmlRpcRequest("agent_is_coming_home", paramList); | ||
280 | string reason = string.Empty; | ||
281 | return GetBoolResponse(request, out reason); | ||
282 | } | ||
283 | |||
284 | public bool VerifyAgent(UUID sessionID, string token) | ||
285 | { | ||
286 | Hashtable hash = new Hashtable(); | ||
287 | hash["sessionID"] = sessionID.ToString(); | ||
288 | hash["token"] = token; | ||
289 | |||
290 | IList paramList = new ArrayList(); | ||
291 | paramList.Add(hash); | ||
292 | |||
293 | XmlRpcRequest request = new XmlRpcRequest("verify_agent", paramList); | ||
294 | string reason = string.Empty; | ||
295 | return GetBoolResponse(request, out reason); | ||
296 | } | ||
297 | |||
298 | public bool VerifyClient(UUID sessionID, string token) | ||
299 | { | ||
300 | Hashtable hash = new Hashtable(); | ||
301 | hash["sessionID"] = sessionID.ToString(); | ||
302 | hash["token"] = token; | ||
303 | |||
304 | IList paramList = new ArrayList(); | ||
305 | paramList.Add(hash); | ||
306 | |||
307 | XmlRpcRequest request = new XmlRpcRequest("verify_client", paramList); | ||
308 | string reason = string.Empty; | ||
309 | return GetBoolResponse(request, out reason); | ||
310 | } | ||
311 | |||
312 | public void LogoutAgent(UUID userID, UUID sessionID) | ||
313 | { | ||
314 | Hashtable hash = new Hashtable(); | ||
315 | hash["sessionID"] = sessionID.ToString(); | ||
316 | hash["userID"] = userID.ToString(); | ||
317 | |||
318 | IList paramList = new ArrayList(); | ||
319 | paramList.Add(hash); | ||
320 | |||
321 | XmlRpcRequest request = new XmlRpcRequest("logout_agent", paramList); | ||
322 | string reason = string.Empty; | ||
323 | GetBoolResponse(request, out reason); | ||
324 | } | ||
325 | |||
326 | |||
327 | private bool GetBoolResponse(XmlRpcRequest request, out string reason) | ||
328 | { | ||
329 | //m_log.Debug("[HGrid]: Linking to " + uri); | ||
330 | XmlRpcResponse response = null; | ||
331 | try | ||
332 | { | ||
333 | response = request.Send(m_ServerURL, 10000); | ||
334 | } | ||
335 | catch (Exception e) | ||
336 | { | ||
337 | m_log.Debug("[HGrid]: Exception " + e.Message); | ||
338 | reason = "Exception: " + e.Message; | ||
339 | return false; | ||
340 | } | ||
341 | |||
342 | if (response.IsFault) | ||
343 | { | ||
344 | m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString); | ||
345 | reason = "XMLRPC Fault"; | ||
346 | return false; | ||
347 | } | ||
348 | |||
349 | Hashtable hash = (Hashtable)response.Value; | ||
350 | //foreach (Object o in hash) | ||
351 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); | ||
352 | try | ||
353 | { | ||
354 | bool success = false; | ||
355 | reason = string.Empty; | ||
356 | Boolean.TryParse((string)hash["result"], out success); | ||
357 | |||
358 | return success; | ||
359 | } | ||
360 | catch (Exception e) | ||
361 | { | ||
362 | m_log.Error("[HGrid]: Got exception while parsing GetEndPoint response " + e.StackTrace); | ||
363 | reason = "Exception: " + e.Message; | ||
364 | return false; | ||
365 | } | ||
366 | |||
367 | } | ||
368 | |||
369 | } | ||
370 | } | ||
diff --git a/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs b/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs index b9ccd7e..9821dd4 100644 --- a/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs +++ b/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs | |||
@@ -68,7 +68,7 @@ namespace OpenSim.Services.Connectors | |||
68 | IConfig assetConfig = source.Configs["InventoryService"]; | 68 | IConfig assetConfig = source.Configs["InventoryService"]; |
69 | if (assetConfig == null) | 69 | if (assetConfig == null) |
70 | { | 70 | { |
71 | m_log.Error("[INVENTORY CONNECTOR]: InventoryService missing from OpanSim.ini"); | 71 | m_log.Error("[INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini"); |
72 | throw new Exception("Inventory connector init error"); | 72 | throw new Exception("Inventory connector init error"); |
73 | } | 73 | } |
74 | 74 | ||
@@ -92,6 +92,8 @@ namespace OpenSim.Services.Connectors | |||
92 | 92 | ||
93 | if (ret == null) | 93 | if (ret == null) |
94 | return false; | 94 | return false; |
95 | if (ret.Count == 0) | ||
96 | return false; | ||
95 | 97 | ||
96 | return bool.Parse(ret["RESULT"].ToString()); | 98 | return bool.Parse(ret["RESULT"].ToString()); |
97 | } | 99 | } |
@@ -105,6 +107,8 @@ namespace OpenSim.Services.Connectors | |||
105 | 107 | ||
106 | if (ret == null) | 108 | if (ret == null) |
107 | return null; | 109 | return null; |
110 | if (ret.Count == 0) | ||
111 | return null; | ||
108 | 112 | ||
109 | List<InventoryFolderBase> folders = new List<InventoryFolderBase>(); | 113 | List<InventoryFolderBase> folders = new List<InventoryFolderBase>(); |
110 | 114 | ||
@@ -122,8 +126,7 @@ namespace OpenSim.Services.Connectors | |||
122 | }); | 126 | }); |
123 | 127 | ||
124 | if (ret == null) | 128 | if (ret == null) |
125 | return null; | 129 | return null; |
126 | |||
127 | if (ret.Count == 0) | 130 | if (ret.Count == 0) |
128 | return null; | 131 | return null; |
129 | 132 | ||
@@ -140,7 +143,6 @@ namespace OpenSim.Services.Connectors | |||
140 | 143 | ||
141 | if (ret == null) | 144 | if (ret == null) |
142 | return null; | 145 | return null; |
143 | |||
144 | if (ret.Count == 0) | 146 | if (ret.Count == 0) |
145 | return null; | 147 | return null; |
146 | 148 | ||
@@ -157,7 +159,6 @@ namespace OpenSim.Services.Connectors | |||
157 | 159 | ||
158 | if (ret == null) | 160 | if (ret == null) |
159 | return null; | 161 | return null; |
160 | |||
161 | if (ret.Count == 0) | 162 | if (ret.Count == 0) |
162 | return null; | 163 | return null; |
163 | 164 | ||
@@ -182,7 +183,7 @@ namespace OpenSim.Services.Connectors | |||
182 | 183 | ||
183 | public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID) | 184 | public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID) |
184 | { | 185 | { |
185 | Dictionary<string,object> ret = MakeRequest("GETFOLDERCONTENT", | 186 | Dictionary<string,object> ret = MakeRequest("GETFOLDERITEMS", |
186 | new Dictionary<string,object> { | 187 | new Dictionary<string,object> { |
187 | { "PRINCIPAL", principalID.ToString() }, | 188 | { "PRINCIPAL", principalID.ToString() }, |
188 | { "FOLDER", folderID.ToString() } | 189 | { "FOLDER", folderID.ToString() } |
@@ -190,7 +191,6 @@ namespace OpenSim.Services.Connectors | |||
190 | 191 | ||
191 | if (ret == null) | 192 | if (ret == null) |
192 | return null; | 193 | return null; |
193 | |||
194 | if (ret.Count == 0) | 194 | if (ret.Count == 0) |
195 | return null; | 195 | return null; |
196 | 196 | ||
@@ -244,7 +244,8 @@ namespace OpenSim.Services.Connectors | |||
244 | Dictionary<string,object> ret = MakeRequest("MOVEFOLDER", | 244 | Dictionary<string,object> ret = MakeRequest("MOVEFOLDER", |
245 | new Dictionary<string,object> { | 245 | new Dictionary<string,object> { |
246 | { "ParentID", folder.ParentID.ToString() }, | 246 | { "ParentID", folder.ParentID.ToString() }, |
247 | { "ID", folder.ID.ToString() } | 247 | { "ID", folder.ID.ToString() }, |
248 | { "PRINCIPAL", folder.Owner.ToString() } | ||
248 | }); | 249 | }); |
249 | 250 | ||
250 | if (ret == null) | 251 | if (ret == null) |
@@ -362,7 +363,7 @@ namespace OpenSim.Services.Connectors | |||
362 | 363 | ||
363 | Dictionary<string,object> ret = MakeRequest("MOVEITEMS", | 364 | Dictionary<string,object> ret = MakeRequest("MOVEITEMS", |
364 | new Dictionary<string,object> { | 365 | new Dictionary<string,object> { |
365 | { "PrincipalID", principalID.ToString() }, | 366 | { "PRINCIPAL", principalID.ToString() }, |
366 | { "IDLIST", idlist }, | 367 | { "IDLIST", idlist }, |
367 | { "DESTLIST", destlist } | 368 | { "DESTLIST", destlist } |
368 | }); | 369 | }); |
@@ -401,7 +402,6 @@ namespace OpenSim.Services.Connectors | |||
401 | 402 | ||
402 | if (ret == null) | 403 | if (ret == null) |
403 | return null; | 404 | return null; |
404 | |||
405 | if (ret.Count == 0) | 405 | if (ret.Count == 0) |
406 | return null; | 406 | return null; |
407 | 407 | ||
@@ -417,7 +417,6 @@ namespace OpenSim.Services.Connectors | |||
417 | 417 | ||
418 | if (ret == null) | 418 | if (ret == null) |
419 | return null; | 419 | return null; |
420 | |||
421 | if (ret.Count == 0) | 420 | if (ret.Count == 0) |
422 | return null; | 421 | return null; |
423 | 422 | ||
@@ -531,5 +530,6 @@ namespace OpenSim.Services.Connectors | |||
531 | 530 | ||
532 | return item; | 531 | return item; |
533 | } | 532 | } |
533 | |||
534 | } | 534 | } |
535 | } | 535 | } |
diff --git a/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs b/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs new file mode 100644 index 0000000..4dadd9e --- /dev/null +++ b/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs | |||
@@ -0,0 +1,423 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using log4net; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
39 | using OpenSim.Server.Base; | ||
40 | using OpenMetaverse; | ||
41 | |||
42 | namespace OpenSim.Services.Connectors | ||
43 | { | ||
44 | public class PresenceServicesConnector : IPresenceService | ||
45 | { | ||
46 | private static readonly ILog m_log = | ||
47 | LogManager.GetLogger( | ||
48 | MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | private string m_ServerURI = String.Empty; | ||
51 | |||
52 | public PresenceServicesConnector() | ||
53 | { | ||
54 | } | ||
55 | |||
56 | public PresenceServicesConnector(string serverURI) | ||
57 | { | ||
58 | m_ServerURI = serverURI.TrimEnd('/'); | ||
59 | } | ||
60 | |||
61 | public PresenceServicesConnector(IConfigSource source) | ||
62 | { | ||
63 | Initialise(source); | ||
64 | } | ||
65 | |||
66 | public virtual void Initialise(IConfigSource source) | ||
67 | { | ||
68 | IConfig gridConfig = source.Configs["PresenceService"]; | ||
69 | if (gridConfig == null) | ||
70 | { | ||
71 | m_log.Error("[PRESENCE CONNECTOR]: PresenceService missing from OpenSim.ini"); | ||
72 | throw new Exception("Presence connector init error"); | ||
73 | } | ||
74 | |||
75 | string serviceURI = gridConfig.GetString("PresenceServerURI", | ||
76 | String.Empty); | ||
77 | |||
78 | if (serviceURI == String.Empty) | ||
79 | { | ||
80 | m_log.Error("[PRESENCE CONNECTOR]: No Server URI named in section PresenceService"); | ||
81 | throw new Exception("Presence connector init error"); | ||
82 | } | ||
83 | m_ServerURI = serviceURI; | ||
84 | } | ||
85 | |||
86 | |||
87 | #region IPresenceService | ||
88 | |||
89 | public bool LoginAgent(string userID, UUID sessionID, UUID secureSessionID) | ||
90 | { | ||
91 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
92 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
93 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
94 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
95 | sendData["METHOD"] = "login"; | ||
96 | |||
97 | sendData["UserID"] = userID; | ||
98 | sendData["SessionID"] = sessionID.ToString(); | ||
99 | sendData["SecureSessionID"] = secureSessionID.ToString(); | ||
100 | |||
101 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
102 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
103 | try | ||
104 | { | ||
105 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
106 | m_ServerURI + "/presence", | ||
107 | reqString); | ||
108 | if (reply != string.Empty) | ||
109 | { | ||
110 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
111 | |||
112 | if (replyData.ContainsKey("result")) | ||
113 | { | ||
114 | if (replyData["result"].ToString().ToLower() == "success") | ||
115 | return true; | ||
116 | else | ||
117 | return false; | ||
118 | } | ||
119 | else | ||
120 | m_log.DebugFormat("[PRESENCE CONNECTOR]: LoginAgent reply data does not contain result field"); | ||
121 | |||
122 | } | ||
123 | else | ||
124 | m_log.DebugFormat("[PRESENCE CONNECTOR]: LoginAgent received empty reply"); | ||
125 | } | ||
126 | catch (Exception e) | ||
127 | { | ||
128 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
129 | } | ||
130 | |||
131 | return false; | ||
132 | |||
133 | } | ||
134 | |||
135 | public bool LogoutAgent(UUID sessionID, Vector3 position, Vector3 lookat) | ||
136 | { | ||
137 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
138 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
139 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
140 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
141 | sendData["METHOD"] = "logout"; | ||
142 | |||
143 | sendData["SessionID"] = sessionID.ToString(); | ||
144 | sendData["Position"] = position.ToString(); | ||
145 | sendData["LookAt"] = lookat.ToString(); | ||
146 | |||
147 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
148 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
149 | try | ||
150 | { | ||
151 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
152 | m_ServerURI + "/presence", | ||
153 | reqString); | ||
154 | if (reply != string.Empty) | ||
155 | { | ||
156 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
157 | |||
158 | if (replyData.ContainsKey("result")) | ||
159 | { | ||
160 | if (replyData["result"].ToString().ToLower() == "success") | ||
161 | return true; | ||
162 | else | ||
163 | return false; | ||
164 | } | ||
165 | else | ||
166 | m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutAgent reply data does not contain result field"); | ||
167 | |||
168 | } | ||
169 | else | ||
170 | m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutAgent received empty reply"); | ||
171 | } | ||
172 | catch (Exception e) | ||
173 | { | ||
174 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
175 | } | ||
176 | |||
177 | return false; | ||
178 | } | ||
179 | |||
180 | public bool LogoutRegionAgents(UUID regionID) | ||
181 | { | ||
182 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
183 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
184 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
185 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
186 | sendData["METHOD"] = "logoutregion"; | ||
187 | |||
188 | sendData["RegionID"] = regionID.ToString(); | ||
189 | |||
190 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
191 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
192 | try | ||
193 | { | ||
194 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
195 | m_ServerURI + "/presence", | ||
196 | reqString); | ||
197 | if (reply != string.Empty) | ||
198 | { | ||
199 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
200 | |||
201 | if (replyData.ContainsKey("result")) | ||
202 | { | ||
203 | if (replyData["result"].ToString().ToLower() == "success") | ||
204 | return true; | ||
205 | else | ||
206 | return false; | ||
207 | } | ||
208 | else | ||
209 | m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutRegionAgents reply data does not contain result field"); | ||
210 | |||
211 | } | ||
212 | else | ||
213 | m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutRegionAgents received empty reply"); | ||
214 | } | ||
215 | catch (Exception e) | ||
216 | { | ||
217 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
218 | } | ||
219 | |||
220 | return false; | ||
221 | } | ||
222 | |||
223 | public bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
224 | { | ||
225 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
226 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
227 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
228 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
229 | sendData["METHOD"] = "report"; | ||
230 | |||
231 | sendData["SessionID"] = sessionID.ToString(); | ||
232 | sendData["RegionID"] = regionID.ToString(); | ||
233 | sendData["position"] = position.ToString(); | ||
234 | sendData["lookAt"] = lookAt.ToString(); | ||
235 | |||
236 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
237 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
238 | try | ||
239 | { | ||
240 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
241 | m_ServerURI + "/presence", | ||
242 | reqString); | ||
243 | if (reply != string.Empty) | ||
244 | { | ||
245 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
246 | |||
247 | if (replyData.ContainsKey("result")) | ||
248 | { | ||
249 | if (replyData["result"].ToString().ToLower() == "success") | ||
250 | return true; | ||
251 | else | ||
252 | return false; | ||
253 | } | ||
254 | else | ||
255 | m_log.DebugFormat("[PRESENCE CONNECTOR]: ReportAgent reply data does not contain result field"); | ||
256 | |||
257 | } | ||
258 | else | ||
259 | m_log.DebugFormat("[PRESENCE CONNECTOR]: ReportAgent received empty reply"); | ||
260 | } | ||
261 | catch (Exception e) | ||
262 | { | ||
263 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
264 | } | ||
265 | |||
266 | return false; | ||
267 | } | ||
268 | |||
269 | public PresenceInfo GetAgent(UUID sessionID) | ||
270 | { | ||
271 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
272 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
273 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
274 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
275 | sendData["METHOD"] = "getagent"; | ||
276 | |||
277 | sendData["SessionID"] = sessionID.ToString(); | ||
278 | |||
279 | string reply = string.Empty; | ||
280 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
281 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
282 | try | ||
283 | { | ||
284 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
285 | m_ServerURI + "/presence", | ||
286 | reqString); | ||
287 | if (reply == null || (reply != null && reply == string.Empty)) | ||
288 | { | ||
289 | m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgent received null or empty reply"); | ||
290 | return null; | ||
291 | } | ||
292 | } | ||
293 | catch (Exception e) | ||
294 | { | ||
295 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
296 | } | ||
297 | |||
298 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
299 | PresenceInfo pinfo = null; | ||
300 | |||
301 | if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) | ||
302 | { | ||
303 | if (replyData["result"] is Dictionary<string, object>) | ||
304 | { | ||
305 | pinfo = new PresenceInfo((Dictionary<string, object>)replyData["result"]); | ||
306 | } | ||
307 | } | ||
308 | |||
309 | return pinfo; | ||
310 | } | ||
311 | |||
312 | public PresenceInfo[] GetAgents(string[] userIDs) | ||
313 | { | ||
314 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
315 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
316 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
317 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
318 | sendData["METHOD"] = "getagents"; | ||
319 | |||
320 | sendData["uuids"] = new List<string>(userIDs); | ||
321 | |||
322 | string reply = string.Empty; | ||
323 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
324 | //m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
325 | try | ||
326 | { | ||
327 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
328 | m_ServerURI + "/presence", | ||
329 | reqString); | ||
330 | if (reply == null || (reply != null && reply == string.Empty)) | ||
331 | { | ||
332 | m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgent received null or empty reply"); | ||
333 | return null; | ||
334 | } | ||
335 | } | ||
336 | catch (Exception e) | ||
337 | { | ||
338 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
339 | } | ||
340 | |||
341 | List<PresenceInfo> rinfos = new List<PresenceInfo>(); | ||
342 | |||
343 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
344 | |||
345 | if (replyData != null) | ||
346 | { | ||
347 | if (replyData.ContainsKey("result") && | ||
348 | (replyData["result"].ToString() == "null" || replyData["result"].ToString() == "Failure")) | ||
349 | { | ||
350 | return new PresenceInfo[0]; | ||
351 | } | ||
352 | |||
353 | Dictionary<string, object>.ValueCollection pinfosList = replyData.Values; | ||
354 | //m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count); | ||
355 | foreach (object presence in pinfosList) | ||
356 | { | ||
357 | if (presence is Dictionary<string, object>) | ||
358 | { | ||
359 | PresenceInfo pinfo = new PresenceInfo((Dictionary<string, object>)presence); | ||
360 | rinfos.Add(pinfo); | ||
361 | } | ||
362 | else | ||
363 | m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received invalid response type {0}", | ||
364 | presence.GetType()); | ||
365 | } | ||
366 | } | ||
367 | else | ||
368 | m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received null response"); | ||
369 | |||
370 | return rinfos.ToArray(); | ||
371 | } | ||
372 | |||
373 | |||
374 | public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
375 | { | ||
376 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
377 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
378 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
379 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
380 | sendData["METHOD"] = "sethome"; | ||
381 | |||
382 | sendData["UserID"] = userID; | ||
383 | sendData["RegionID"] = regionID.ToString(); | ||
384 | sendData["position"] = position.ToString(); | ||
385 | sendData["lookAt"] = lookAt.ToString(); | ||
386 | |||
387 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
388 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
389 | try | ||
390 | { | ||
391 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
392 | m_ServerURI + "/presence", | ||
393 | reqString); | ||
394 | if (reply != string.Empty) | ||
395 | { | ||
396 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
397 | |||
398 | if (replyData.ContainsKey("result")) | ||
399 | { | ||
400 | if (replyData["result"].ToString().ToLower() == "success") | ||
401 | return true; | ||
402 | else | ||
403 | return false; | ||
404 | } | ||
405 | else | ||
406 | m_log.DebugFormat("[PRESENCE CONNECTOR]: SetHomeLocation reply data does not contain result field"); | ||
407 | |||
408 | } | ||
409 | else | ||
410 | m_log.DebugFormat("[PRESENCE CONNECTOR]: SetHomeLocation received empty reply"); | ||
411 | } | ||
412 | catch (Exception e) | ||
413 | { | ||
414 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
415 | } | ||
416 | |||
417 | return false; | ||
418 | } | ||
419 | |||
420 | #endregion | ||
421 | |||
422 | } | ||
423 | } | ||
diff --git a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs new file mode 100644 index 0000000..d3be1a8 --- /dev/null +++ b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs | |||
@@ -0,0 +1,596 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Net; | ||
32 | using System.Reflection; | ||
33 | using System.Text; | ||
34 | |||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
38 | |||
39 | using OpenMetaverse; | ||
40 | using OpenMetaverse.StructuredData; | ||
41 | using log4net; | ||
42 | using Nini.Config; | ||
43 | |||
44 | namespace OpenSim.Services.Connectors.Simulation | ||
45 | { | ||
46 | public class SimulationServiceConnector : ISimulationService | ||
47 | { | ||
48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | //private GridRegion m_Region; | ||
51 | |||
52 | public SimulationServiceConnector() | ||
53 | { | ||
54 | } | ||
55 | |||
56 | public SimulationServiceConnector(IConfigSource config) | ||
57 | { | ||
58 | //m_Region = region; | ||
59 | } | ||
60 | |||
61 | public IScene GetScene(ulong regionHandle) | ||
62 | { | ||
63 | return null; | ||
64 | } | ||
65 | |||
66 | #region Agents | ||
67 | |||
68 | protected virtual string AgentPath() | ||
69 | { | ||
70 | return "/agent/"; | ||
71 | } | ||
72 | |||
73 | public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string reason) | ||
74 | { | ||
75 | reason = String.Empty; | ||
76 | |||
77 | if (destination == null) | ||
78 | { | ||
79 | reason = "Destination is null"; | ||
80 | m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Given destination is null"); | ||
81 | return false; | ||
82 | } | ||
83 | |||
84 | // Eventually, we want to use a caps url instead of the agentID | ||
85 | string uri = string.Empty; | ||
86 | try | ||
87 | { | ||
88 | uri = "http://" + destination.ExternalEndPoint.Address + ":" + destination.HttpPort + AgentPath() + aCircuit.AgentID + "/"; | ||
89 | } | ||
90 | catch (Exception e) | ||
91 | { | ||
92 | m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Unable to resolve external endpoint on agent create. Reason: " + e.Message); | ||
93 | reason = e.Message; | ||
94 | return false; | ||
95 | } | ||
96 | |||
97 | //Console.WriteLine(" >>> DoCreateChildAgentCall <<< " + uri); | ||
98 | |||
99 | HttpWebRequest AgentCreateRequest = (HttpWebRequest)WebRequest.Create(uri); | ||
100 | AgentCreateRequest.Method = "POST"; | ||
101 | AgentCreateRequest.ContentType = "application/json"; | ||
102 | AgentCreateRequest.Timeout = 10000; | ||
103 | //AgentCreateRequest.KeepAlive = false; | ||
104 | //AgentCreateRequest.Headers.Add("Authorization", authKey); | ||
105 | |||
106 | // Fill it in | ||
107 | OSDMap args = PackCreateAgentArguments(aCircuit, destination, flags); | ||
108 | if (args == null) | ||
109 | return false; | ||
110 | |||
111 | string strBuffer = ""; | ||
112 | byte[] buffer = new byte[1]; | ||
113 | try | ||
114 | { | ||
115 | strBuffer = OSDParser.SerializeJsonString(args); | ||
116 | Encoding str = Util.UTF8; | ||
117 | buffer = str.GetBytes(strBuffer); | ||
118 | |||
119 | } | ||
120 | catch (Exception e) | ||
121 | { | ||
122 | m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Exception thrown on serialization of ChildCreate: {0}", e.Message); | ||
123 | // ignore. buffer will be empty, caller should check. | ||
124 | } | ||
125 | |||
126 | Stream os = null; | ||
127 | try | ||
128 | { // send the Post | ||
129 | AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send | ||
130 | os = AgentCreateRequest.GetRequestStream(); | ||
131 | os.Write(buffer, 0, strBuffer.Length); //Send it | ||
132 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: Posted CreateAgent request to remote sim {0}, region {1}, x={2} y={3}", | ||
133 | uri, destination.RegionName, destination.RegionLocX, destination.RegionLocY); | ||
134 | } | ||
135 | //catch (WebException ex) | ||
136 | catch | ||
137 | { | ||
138 | //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: Bad send on ChildAgentUpdate {0}", ex.Message); | ||
139 | reason = "cannot contact remote region"; | ||
140 | return false; | ||
141 | } | ||
142 | finally | ||
143 | { | ||
144 | if (os != null) | ||
145 | os.Close(); | ||
146 | } | ||
147 | |||
148 | // Let's wait for the response | ||
149 | //m_log.Info("[REMOTE SIMULATION CONNECTOR]: Waiting for a reply after DoCreateChildAgentCall"); | ||
150 | |||
151 | WebResponse webResponse = null; | ||
152 | StreamReader sr = null; | ||
153 | try | ||
154 | { | ||
155 | webResponse = AgentCreateRequest.GetResponse(); | ||
156 | if (webResponse == null) | ||
157 | { | ||
158 | m_log.Info("[REMOTE SIMULATION CONNECTOR]: Null reply on DoCreateChildAgentCall post"); | ||
159 | } | ||
160 | else | ||
161 | { | ||
162 | |||
163 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
164 | string response = sr.ReadToEnd().Trim(); | ||
165 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: DoCreateChildAgentCall reply was {0} ", response); | ||
166 | |||
167 | if (!String.IsNullOrEmpty(response)) | ||
168 | { | ||
169 | try | ||
170 | { | ||
171 | // we assume we got an OSDMap back | ||
172 | OSDMap r = Util.GetOSDMap(response); | ||
173 | bool success = r["success"].AsBoolean(); | ||
174 | reason = r["reason"].AsString(); | ||
175 | return success; | ||
176 | } | ||
177 | catch (NullReferenceException e) | ||
178 | { | ||
179 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", e.Message); | ||
180 | |||
181 | // check for old style response | ||
182 | if (response.ToLower().StartsWith("true")) | ||
183 | return true; | ||
184 | |||
185 | return false; | ||
186 | } | ||
187 | } | ||
188 | } | ||
189 | } | ||
190 | catch (WebException ex) | ||
191 | { | ||
192 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", ex.Message); | ||
193 | reason = "Destination did not reply"; | ||
194 | return false; | ||
195 | } | ||
196 | finally | ||
197 | { | ||
198 | if (sr != null) | ||
199 | sr.Close(); | ||
200 | } | ||
201 | |||
202 | return true; | ||
203 | } | ||
204 | |||
205 | protected virtual OSDMap PackCreateAgentArguments(AgentCircuitData aCircuit, GridRegion destination, uint flags) | ||
206 | { | ||
207 | OSDMap args = null; | ||
208 | try | ||
209 | { | ||
210 | args = aCircuit.PackAgentCircuitData(); | ||
211 | } | ||
212 | catch (Exception e) | ||
213 | { | ||
214 | m_log.Debug("[REMOTE SIMULATION CONNECTOR]: PackAgentCircuitData failed with exception: " + e.Message); | ||
215 | return null; | ||
216 | } | ||
217 | // Add the input arguments | ||
218 | args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString()); | ||
219 | args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString()); | ||
220 | args["destination_name"] = OSD.FromString(destination.RegionName); | ||
221 | args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString()); | ||
222 | args["teleport_flags"] = OSD.FromString(flags.ToString()); | ||
223 | |||
224 | return args; | ||
225 | } | ||
226 | |||
227 | public bool UpdateAgent(GridRegion destination, AgentData data) | ||
228 | { | ||
229 | return UpdateAgent(destination, (IAgentData)data); | ||
230 | } | ||
231 | |||
232 | public bool UpdateAgent(GridRegion destination, AgentPosition data) | ||
233 | { | ||
234 | return UpdateAgent(destination, (IAgentData)data); | ||
235 | } | ||
236 | |||
237 | private bool UpdateAgent(GridRegion destination, IAgentData cAgentData) | ||
238 | { | ||
239 | // Eventually, we want to use a caps url instead of the agentID | ||
240 | string uri = string.Empty; | ||
241 | try | ||
242 | { | ||
243 | uri = "http://" + destination.ExternalEndPoint.Address + ":" + destination.HttpPort + AgentPath() + cAgentData.AgentID + "/"; | ||
244 | } | ||
245 | catch (Exception e) | ||
246 | { | ||
247 | m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Unable to resolve external endpoint on agent update. Reason: " + e.Message); | ||
248 | return false; | ||
249 | } | ||
250 | //Console.WriteLine(" >>> DoAgentUpdateCall <<< " + uri); | ||
251 | |||
252 | HttpWebRequest ChildUpdateRequest = (HttpWebRequest)WebRequest.Create(uri); | ||
253 | ChildUpdateRequest.Method = "PUT"; | ||
254 | ChildUpdateRequest.ContentType = "application/json"; | ||
255 | ChildUpdateRequest.Timeout = 10000; | ||
256 | //ChildUpdateRequest.KeepAlive = false; | ||
257 | |||
258 | // Fill it in | ||
259 | OSDMap args = null; | ||
260 | try | ||
261 | { | ||
262 | args = cAgentData.Pack(); | ||
263 | } | ||
264 | catch (Exception e) | ||
265 | { | ||
266 | m_log.Debug("[REMOTE SIMULATION CONNECTOR]: PackUpdateMessage failed with exception: " + e.Message); | ||
267 | } | ||
268 | // Add the input arguments | ||
269 | args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString()); | ||
270 | args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString()); | ||
271 | args["destination_name"] = OSD.FromString(destination.RegionName); | ||
272 | args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString()); | ||
273 | |||
274 | string strBuffer = ""; | ||
275 | byte[] buffer = new byte[1]; | ||
276 | try | ||
277 | { | ||
278 | strBuffer = OSDParser.SerializeJsonString(args); | ||
279 | Encoding str = Util.UTF8; | ||
280 | buffer = str.GetBytes(strBuffer); | ||
281 | |||
282 | } | ||
283 | catch (Exception e) | ||
284 | { | ||
285 | m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Exception thrown on serialization of ChildUpdate: {0}", e.Message); | ||
286 | // ignore. buffer will be empty, caller should check. | ||
287 | } | ||
288 | |||
289 | Stream os = null; | ||
290 | try | ||
291 | { // send the Post | ||
292 | ChildUpdateRequest.ContentLength = buffer.Length; //Count bytes to send | ||
293 | os = ChildUpdateRequest.GetRequestStream(); | ||
294 | os.Write(buffer, 0, strBuffer.Length); //Send it | ||
295 | //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: Posted AgentUpdate request to remote sim {0}", uri); | ||
296 | } | ||
297 | catch (WebException ex) | ||
298 | //catch | ||
299 | { | ||
300 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: Bad send on AgentUpdate {0}", ex.Message); | ||
301 | |||
302 | return false; | ||
303 | } | ||
304 | finally | ||
305 | { | ||
306 | if (os != null) | ||
307 | os.Close(); | ||
308 | } | ||
309 | |||
310 | // Let's wait for the response | ||
311 | //m_log.Info("[REMOTE SIMULATION CONNECTOR]: Waiting for a reply after ChildAgentUpdate"); | ||
312 | |||
313 | WebResponse webResponse = null; | ||
314 | StreamReader sr = null; | ||
315 | try | ||
316 | { | ||
317 | webResponse = ChildUpdateRequest.GetResponse(); | ||
318 | if (webResponse == null) | ||
319 | { | ||
320 | m_log.Info("[REMOTE SIMULATION CONNECTOR]: Null reply on ChilAgentUpdate post"); | ||
321 | } | ||
322 | |||
323 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
324 | //reply = sr.ReadToEnd().Trim(); | ||
325 | sr.ReadToEnd().Trim(); | ||
326 | sr.Close(); | ||
327 | //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was {0} ", reply); | ||
328 | |||
329 | } | ||
330 | catch (WebException ex) | ||
331 | { | ||
332 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of ChilAgentUpdate {0}", ex.Message); | ||
333 | // ignore, really | ||
334 | } | ||
335 | finally | ||
336 | { | ||
337 | if (sr != null) | ||
338 | sr.Close(); | ||
339 | } | ||
340 | |||
341 | return true; | ||
342 | } | ||
343 | |||
344 | public bool RetrieveAgent(GridRegion destination, UUID id, out IAgentData agent) | ||
345 | { | ||
346 | agent = null; | ||
347 | // Eventually, we want to use a caps url instead of the agentID | ||
348 | string uri = "http://" + destination.ExternalEndPoint.Address + ":" + destination.HttpPort + AgentPath() + id + "/" + destination.RegionID.ToString() + "/"; | ||
349 | //Console.WriteLine(" >>> DoRetrieveRootAgentCall <<< " + uri); | ||
350 | |||
351 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); | ||
352 | request.Method = "GET"; | ||
353 | request.Timeout = 10000; | ||
354 | //request.Headers.Add("authorization", ""); // coming soon | ||
355 | |||
356 | HttpWebResponse webResponse = null; | ||
357 | string reply = string.Empty; | ||
358 | StreamReader sr = null; | ||
359 | try | ||
360 | { | ||
361 | webResponse = (HttpWebResponse)request.GetResponse(); | ||
362 | if (webResponse == null) | ||
363 | { | ||
364 | m_log.Info("[REMOTE SIMULATION CONNECTOR]: Null reply on agent get "); | ||
365 | } | ||
366 | |||
367 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
368 | reply = sr.ReadToEnd().Trim(); | ||
369 | |||
370 | //Console.WriteLine("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was " + reply); | ||
371 | |||
372 | } | ||
373 | catch (WebException ex) | ||
374 | { | ||
375 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of agent get {0}", ex.Message); | ||
376 | // ignore, really | ||
377 | return false; | ||
378 | } | ||
379 | finally | ||
380 | { | ||
381 | if (sr != null) | ||
382 | sr.Close(); | ||
383 | } | ||
384 | |||
385 | if (webResponse.StatusCode == HttpStatusCode.OK) | ||
386 | { | ||
387 | // we know it's jason | ||
388 | OSDMap args = Util.GetOSDMap(reply); | ||
389 | if (args == null) | ||
390 | { | ||
391 | //Console.WriteLine("[REMOTE SIMULATION CONNECTOR]: Error getting OSDMap from reply"); | ||
392 | return false; | ||
393 | } | ||
394 | |||
395 | agent = new CompleteAgentData(); | ||
396 | agent.Unpack(args); | ||
397 | return true; | ||
398 | } | ||
399 | |||
400 | //Console.WriteLine("[REMOTE SIMULATION CONNECTOR]: DoRetrieveRootAgentCall returned status " + webResponse.StatusCode); | ||
401 | return false; | ||
402 | } | ||
403 | |||
404 | public bool ReleaseAgent(UUID origin, UUID id, string uri) | ||
405 | { | ||
406 | WebRequest request = WebRequest.Create(uri); | ||
407 | request.Method = "DELETE"; | ||
408 | request.Timeout = 10000; | ||
409 | |||
410 | StreamReader sr = null; | ||
411 | try | ||
412 | { | ||
413 | WebResponse webResponse = request.GetResponse(); | ||
414 | if (webResponse == null) | ||
415 | { | ||
416 | m_log.Info("[REMOTE SIMULATION CONNECTOR]: Null reply on ReleaseAgent"); | ||
417 | } | ||
418 | |||
419 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
420 | //reply = sr.ReadToEnd().Trim(); | ||
421 | sr.ReadToEnd().Trim(); | ||
422 | sr.Close(); | ||
423 | //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was {0} ", reply); | ||
424 | |||
425 | } | ||
426 | catch (WebException ex) | ||
427 | { | ||
428 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of ReleaseAgent {0}", ex.Message); | ||
429 | return false; | ||
430 | } | ||
431 | finally | ||
432 | { | ||
433 | if (sr != null) | ||
434 | sr.Close(); | ||
435 | } | ||
436 | |||
437 | return true; | ||
438 | } | ||
439 | |||
440 | public bool CloseAgent(GridRegion destination, UUID id) | ||
441 | { | ||
442 | string uri = string.Empty; | ||
443 | try | ||
444 | { | ||
445 | uri = "http://" + destination.ExternalEndPoint.Address + ":" + destination.HttpPort + AgentPath() + id + "/" + destination.RegionID.ToString() + "/"; | ||
446 | } | ||
447 | catch (Exception e) | ||
448 | { | ||
449 | m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Unable to resolve external endpoint on agent close. Reason: " + e.Message); | ||
450 | return false; | ||
451 | } | ||
452 | |||
453 | //Console.WriteLine(" >>> DoCloseAgentCall <<< " + uri); | ||
454 | |||
455 | WebRequest request = WebRequest.Create(uri); | ||
456 | request.Method = "DELETE"; | ||
457 | request.Timeout = 10000; | ||
458 | |||
459 | StreamReader sr = null; | ||
460 | try | ||
461 | { | ||
462 | WebResponse webResponse = request.GetResponse(); | ||
463 | if (webResponse == null) | ||
464 | { | ||
465 | m_log.Info("[REMOTE SIMULATION CONNECTOR]: Null reply on agent delete "); | ||
466 | } | ||
467 | |||
468 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
469 | //reply = sr.ReadToEnd().Trim(); | ||
470 | sr.ReadToEnd().Trim(); | ||
471 | sr.Close(); | ||
472 | //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was {0} ", reply); | ||
473 | |||
474 | } | ||
475 | catch (WebException ex) | ||
476 | { | ||
477 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of agent delete {0}", ex.Message); | ||
478 | return false; | ||
479 | } | ||
480 | finally | ||
481 | { | ||
482 | if (sr != null) | ||
483 | sr.Close(); | ||
484 | } | ||
485 | |||
486 | return true; | ||
487 | } | ||
488 | |||
489 | #endregion Agents | ||
490 | |||
491 | #region Objects | ||
492 | |||
493 | protected virtual string ObjectPath() | ||
494 | { | ||
495 | return "/object/"; | ||
496 | } | ||
497 | |||
498 | public bool CreateObject(GridRegion destination, ISceneObject sog, bool isLocalCall) | ||
499 | { | ||
500 | string uri | ||
501 | = "http://" + destination.ExternalEndPoint.Address + ":" + destination.HttpPort + ObjectPath() + sog.UUID + "/"; | ||
502 | //m_log.Debug(" >>> DoCreateObjectCall <<< " + uri); | ||
503 | |||
504 | WebRequest ObjectCreateRequest = WebRequest.Create(uri); | ||
505 | ObjectCreateRequest.Method = "POST"; | ||
506 | ObjectCreateRequest.ContentType = "application/json"; | ||
507 | ObjectCreateRequest.Timeout = 10000; | ||
508 | |||
509 | OSDMap args = new OSDMap(2); | ||
510 | args["sog"] = OSD.FromString(sog.ToXml2()); | ||
511 | args["extra"] = OSD.FromString(sog.ExtraToXmlString()); | ||
512 | string state = sog.GetStateSnapshot(); | ||
513 | if (state.Length > 0) | ||
514 | args["state"] = OSD.FromString(state); | ||
515 | // Add the input general arguments | ||
516 | args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString()); | ||
517 | args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString()); | ||
518 | args["destination_name"] = OSD.FromString(destination.RegionName); | ||
519 | args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString()); | ||
520 | |||
521 | string strBuffer = ""; | ||
522 | byte[] buffer = new byte[1]; | ||
523 | try | ||
524 | { | ||
525 | strBuffer = OSDParser.SerializeJsonString(args); | ||
526 | Encoding str = Util.UTF8; | ||
527 | buffer = str.GetBytes(strBuffer); | ||
528 | |||
529 | } | ||
530 | catch (Exception e) | ||
531 | { | ||
532 | m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Exception thrown on serialization of CreateObject: {0}", e.Message); | ||
533 | // ignore. buffer will be empty, caller should check. | ||
534 | } | ||
535 | |||
536 | Stream os = null; | ||
537 | try | ||
538 | { // send the Post | ||
539 | ObjectCreateRequest.ContentLength = buffer.Length; //Count bytes to send | ||
540 | os = ObjectCreateRequest.GetRequestStream(); | ||
541 | os.Write(buffer, 0, strBuffer.Length); //Send it | ||
542 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: Posted CreateObject request to remote sim {0}", uri); | ||
543 | } | ||
544 | catch (WebException ex) | ||
545 | { | ||
546 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: Bad send on CreateObject {0}", ex.Message); | ||
547 | return false; | ||
548 | } | ||
549 | finally | ||
550 | { | ||
551 | if (os != null) | ||
552 | os.Close(); | ||
553 | } | ||
554 | |||
555 | // Let's wait for the response | ||
556 | //m_log.Info("[REMOTE SIMULATION CONNECTOR]: Waiting for a reply after DoCreateChildAgentCall"); | ||
557 | |||
558 | StreamReader sr = null; | ||
559 | try | ||
560 | { | ||
561 | WebResponse webResponse = ObjectCreateRequest.GetResponse(); | ||
562 | if (webResponse == null) | ||
563 | { | ||
564 | m_log.Info("[REMOTE SIMULATION CONNECTOR]: Null reply on CreateObject post"); | ||
565 | return false; | ||
566 | } | ||
567 | |||
568 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
569 | //reply = sr.ReadToEnd().Trim(); | ||
570 | sr.ReadToEnd().Trim(); | ||
571 | //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: DoCreateChildAgentCall reply was {0} ", reply); | ||
572 | |||
573 | } | ||
574 | catch (WebException ex) | ||
575 | { | ||
576 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of CreateObject {0}", ex.Message); | ||
577 | return false; | ||
578 | } | ||
579 | finally | ||
580 | { | ||
581 | if (sr != null) | ||
582 | sr.Close(); | ||
583 | } | ||
584 | |||
585 | return true; | ||
586 | } | ||
587 | |||
588 | public bool CreateObject(GridRegion destination, UUID userID, UUID itemID) | ||
589 | { | ||
590 | // TODO, not that urgent | ||
591 | return false; | ||
592 | } | ||
593 | |||
594 | #endregion Objects | ||
595 | } | ||
596 | } | ||
diff --git a/OpenSim/Services/Connectors/UserAccounts/UserAccountServiceConnector.cs b/OpenSim/Services/Connectors/UserAccounts/UserAccountServiceConnector.cs new file mode 100644 index 0000000..8e7c92b --- /dev/null +++ b/OpenSim/Services/Connectors/UserAccounts/UserAccountServiceConnector.cs | |||
@@ -0,0 +1,277 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using log4net; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Server.Base; | ||
38 | using OpenSim.Services.Interfaces; | ||
39 | using OpenMetaverse; | ||
40 | |||
41 | namespace OpenSim.Services.Connectors | ||
42 | { | ||
43 | public class UserAccountServicesConnector : IUserAccountService | ||
44 | { | ||
45 | private static readonly ILog m_log = | ||
46 | LogManager.GetLogger( | ||
47 | MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | private string m_ServerURI = String.Empty; | ||
50 | |||
51 | public UserAccountServicesConnector() | ||
52 | { | ||
53 | } | ||
54 | |||
55 | public UserAccountServicesConnector(string serverURI) | ||
56 | { | ||
57 | m_ServerURI = serverURI.TrimEnd('/'); | ||
58 | } | ||
59 | |||
60 | public UserAccountServicesConnector(IConfigSource source) | ||
61 | { | ||
62 | Initialise(source); | ||
63 | } | ||
64 | |||
65 | public virtual void Initialise(IConfigSource source) | ||
66 | { | ||
67 | IConfig assetConfig = source.Configs["UserAccountService"]; | ||
68 | if (assetConfig == null) | ||
69 | { | ||
70 | m_log.Error("[ACCOUNT CONNECTOR]: UserAccountService missing from OpenSim.ini"); | ||
71 | throw new Exception("User account connector init error"); | ||
72 | } | ||
73 | |||
74 | string serviceURI = assetConfig.GetString("UserAccountServerURI", | ||
75 | String.Empty); | ||
76 | |||
77 | if (serviceURI == String.Empty) | ||
78 | { | ||
79 | m_log.Error("[ACCOUNT CONNECTOR]: No Server URI named in section UserAccountService"); | ||
80 | throw new Exception("User account connector init error"); | ||
81 | } | ||
82 | m_ServerURI = serviceURI; | ||
83 | } | ||
84 | |||
85 | public virtual UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName) | ||
86 | { | ||
87 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
88 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
89 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
90 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
91 | sendData["METHOD"] = "getaccount"; | ||
92 | |||
93 | sendData["ScopeID"] = scopeID; | ||
94 | sendData["FirstName"] = firstName.ToString(); | ||
95 | sendData["LastName"] = lastName.ToString(); | ||
96 | |||
97 | return SendAndGetReply(sendData); | ||
98 | } | ||
99 | |||
100 | public virtual UserAccount GetUserAccount(UUID scopeID, string email) | ||
101 | { | ||
102 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
103 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
104 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
105 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
106 | sendData["METHOD"] = "getaccount"; | ||
107 | |||
108 | sendData["ScopeID"] = scopeID; | ||
109 | sendData["Email"] = email; | ||
110 | |||
111 | return SendAndGetReply(sendData); | ||
112 | } | ||
113 | |||
114 | public virtual UserAccount GetUserAccount(UUID scopeID, UUID userID) | ||
115 | { | ||
116 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
117 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
118 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
119 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
120 | sendData["METHOD"] = "getaccount"; | ||
121 | |||
122 | sendData["ScopeID"] = scopeID; | ||
123 | sendData["UserID"] = userID.ToString(); | ||
124 | |||
125 | return SendAndGetReply(sendData); | ||
126 | } | ||
127 | |||
128 | public List<UserAccount> GetUserAccounts(UUID scopeID, string query) | ||
129 | { | ||
130 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
131 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
132 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
133 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
134 | sendData["METHOD"] = "getaccounts"; | ||
135 | |||
136 | sendData["ScopeID"] = scopeID.ToString(); | ||
137 | sendData["query"] = query; | ||
138 | |||
139 | string reply = string.Empty; | ||
140 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
141 | // m_log.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString); | ||
142 | try | ||
143 | { | ||
144 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
145 | m_ServerURI + "/accounts", | ||
146 | reqString); | ||
147 | if (reply == null || (reply != null && reply == string.Empty)) | ||
148 | { | ||
149 | m_log.DebugFormat("[ACCOUNT CONNECTOR]: GetUserAccounts received null or empty reply"); | ||
150 | return null; | ||
151 | } | ||
152 | } | ||
153 | catch (Exception e) | ||
154 | { | ||
155 | m_log.DebugFormat("[ACCOUNT CONNECTOR]: Exception when contacting accounts server: {0}", e.Message); | ||
156 | } | ||
157 | |||
158 | List<UserAccount> accounts = new List<UserAccount>(); | ||
159 | |||
160 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
161 | |||
162 | if (replyData != null) | ||
163 | { | ||
164 | if (replyData.ContainsKey("result") && replyData.ContainsKey("result").ToString() == "null") | ||
165 | { | ||
166 | return accounts; | ||
167 | } | ||
168 | |||
169 | Dictionary<string, object>.ValueCollection accountList = replyData.Values; | ||
170 | //m_log.DebugFormat("[ACCOUNTS CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count); | ||
171 | foreach (object acc in accountList) | ||
172 | { | ||
173 | if (acc is Dictionary<string, object>) | ||
174 | { | ||
175 | UserAccount pinfo = new UserAccount((Dictionary<string, object>)acc); | ||
176 | accounts.Add(pinfo); | ||
177 | } | ||
178 | else | ||
179 | m_log.DebugFormat("[ACCOUNT CONNECTOR]: GetUserAccounts received invalid response type {0}", | ||
180 | acc.GetType()); | ||
181 | } | ||
182 | } | ||
183 | else | ||
184 | m_log.DebugFormat("[ACCOUNTS CONNECTOR]: GetUserAccounts received null response"); | ||
185 | |||
186 | return accounts; | ||
187 | } | ||
188 | |||
189 | public bool StoreUserAccount(UserAccount data) | ||
190 | { | ||
191 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
192 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
193 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
194 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
195 | sendData["METHOD"] = "setaccount"; | ||
196 | |||
197 | Dictionary<string, object> structData = data.ToKeyValuePairs(); | ||
198 | |||
199 | foreach (KeyValuePair<string,object> kvp in structData) | ||
200 | sendData[kvp.Key] = kvp.Value.ToString(); | ||
201 | |||
202 | return SendAndGetBoolReply(sendData); | ||
203 | } | ||
204 | |||
205 | private UserAccount SendAndGetReply(Dictionary<string, object> sendData) | ||
206 | { | ||
207 | string reply = string.Empty; | ||
208 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
209 | // m_log.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString); | ||
210 | try | ||
211 | { | ||
212 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
213 | m_ServerURI + "/accounts", | ||
214 | reqString); | ||
215 | if (reply == null || (reply != null && reply == string.Empty)) | ||
216 | { | ||
217 | m_log.DebugFormat("[ACCOUNT CONNECTOR]: GetUserAccount received null or empty reply"); | ||
218 | return null; | ||
219 | } | ||
220 | } | ||
221 | catch (Exception e) | ||
222 | { | ||
223 | m_log.DebugFormat("[ACCOUNT CONNECTOR]: Exception when contacting user account server: {0}", e.Message); | ||
224 | } | ||
225 | |||
226 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
227 | UserAccount account = null; | ||
228 | |||
229 | if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) | ||
230 | { | ||
231 | if (replyData["result"] is Dictionary<string, object>) | ||
232 | { | ||
233 | account = new UserAccount((Dictionary<string, object>)replyData["result"]); | ||
234 | } | ||
235 | } | ||
236 | |||
237 | return account; | ||
238 | |||
239 | } | ||
240 | |||
241 | private bool SendAndGetBoolReply(Dictionary<string, object> sendData) | ||
242 | { | ||
243 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
244 | // m_log.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString); | ||
245 | try | ||
246 | { | ||
247 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
248 | m_ServerURI + "/accounts", | ||
249 | reqString); | ||
250 | if (reply != string.Empty) | ||
251 | { | ||
252 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
253 | |||
254 | if (replyData.ContainsKey("result")) | ||
255 | { | ||
256 | if (replyData["result"].ToString().ToLower() == "success") | ||
257 | return true; | ||
258 | else | ||
259 | return false; | ||
260 | } | ||
261 | else | ||
262 | m_log.DebugFormat("[ACCOUNTS CONNECTOR]: Set or Create UserAccount reply data does not contain result field"); | ||
263 | |||
264 | } | ||
265 | else | ||
266 | m_log.DebugFormat("[ACCOUNTS CONNECTOR]: Set or Create UserAccount received empty reply"); | ||
267 | } | ||
268 | catch (Exception e) | ||
269 | { | ||
270 | m_log.DebugFormat("[ACCOUNTS CONNECTOR]: Exception when contacting user account server: {0}", e.Message); | ||
271 | } | ||
272 | |||
273 | return false; | ||
274 | } | ||
275 | |||
276 | } | ||
277 | } | ||