diff options
author | UbitUmarov | 2012-07-17 00:54:23 +0100 |
---|---|---|
committer | UbitUmarov | 2012-07-17 00:54:23 +0100 |
commit | d5f4fb7b50fb7c594b018f8241399e22f88fc951 (patch) | |
tree | 8f3dab3d170596f02b1d1d836a0bc08a3e6b8ebd /OpenSim/Services/Connectors/GridUser/GridUserServicesConnector.cs | |
parent | UbitOde: remove useless water collider from active code. (diff) | |
parent | Merge branch 'avination' into careminster (diff) | |
download | opensim-SC-d5f4fb7b50fb7c594b018f8241399e22f88fc951.zip opensim-SC-d5f4fb7b50fb7c594b018f8241399e22f88fc951.tar.gz opensim-SC-d5f4fb7b50fb7c594b018f8241399e22f88fc951.tar.bz2 opensim-SC-d5f4fb7b50fb7c594b018f8241399e22f88fc951.tar.xz |
Merge branch 'avination' into ubitwork
Diffstat (limited to 'OpenSim/Services/Connectors/GridUser/GridUserServicesConnector.cs')
-rw-r--r-- | OpenSim/Services/Connectors/GridUser/GridUserServicesConnector.cs | 290 |
1 files changed, 290 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/GridUser/GridUserServicesConnector.cs b/OpenSim/Services/Connectors/GridUser/GridUserServicesConnector.cs new file mode 100644 index 0000000..20d7eaf --- /dev/null +++ b/OpenSim/Services/Connectors/GridUser/GridUserServicesConnector.cs | |||
@@ -0,0 +1,290 @@ | |||
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.Services.Interfaces; | ||
37 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
38 | using OpenSim.Server.Base; | ||
39 | using OpenMetaverse; | ||
40 | |||
41 | namespace OpenSim.Services.Connectors | ||
42 | { | ||
43 | public class GridUserServicesConnector : IGridUserService | ||
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 GridUserServicesConnector() | ||
52 | { | ||
53 | } | ||
54 | |||
55 | public GridUserServicesConnector(string serverURI) | ||
56 | { | ||
57 | m_ServerURI = serverURI.TrimEnd('/'); | ||
58 | } | ||
59 | |||
60 | public GridUserServicesConnector(IConfigSource source) | ||
61 | { | ||
62 | Initialise(source); | ||
63 | } | ||
64 | |||
65 | public virtual void Initialise(IConfigSource source) | ||
66 | { | ||
67 | IConfig gridConfig = source.Configs["GridUserService"]; | ||
68 | if (gridConfig == null) | ||
69 | { | ||
70 | m_log.Error("[GRID USER CONNECTOR]: GridUserService missing from OpenSim.ini"); | ||
71 | throw new Exception("GridUser connector init error"); | ||
72 | } | ||
73 | |||
74 | string serviceURI = gridConfig.GetString("GridUserServerURI", | ||
75 | String.Empty); | ||
76 | |||
77 | if (serviceURI == String.Empty) | ||
78 | { | ||
79 | m_log.Error("[GRID USER CONNECTOR]: No Server URI named in section GridUserService"); | ||
80 | throw new Exception("GridUser connector init error"); | ||
81 | } | ||
82 | m_ServerURI = serviceURI; | ||
83 | } | ||
84 | |||
85 | |||
86 | #region IGridUserService | ||
87 | |||
88 | |||
89 | public GridUserInfo LoggedIn(string userID) | ||
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"] = "loggedin"; | ||
96 | |||
97 | sendData["UserID"] = userID; | ||
98 | |||
99 | return Get(sendData); | ||
100 | |||
101 | } | ||
102 | |||
103 | public bool LoggedOut(string userID, UUID sessionID, UUID region, Vector3 position, Vector3 lookat) | ||
104 | { | ||
105 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
106 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
107 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
108 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
109 | sendData["METHOD"] = "loggedout"; | ||
110 | |||
111 | return Set(sendData, userID, region, position, lookat); | ||
112 | } | ||
113 | |||
114 | public bool SetHome(string userID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
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"] = "sethome"; | ||
121 | |||
122 | return Set(sendData, userID, regionID, position, lookAt); | ||
123 | } | ||
124 | |||
125 | public bool SetLastPosition(string userID, UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
126 | { | ||
127 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
128 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
129 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
130 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
131 | sendData["METHOD"] = "setposition"; | ||
132 | |||
133 | return Set(sendData, userID, regionID, position, lookAt); | ||
134 | } | ||
135 | |||
136 | public GridUserInfo GetGridUserInfo(string userID) | ||
137 | { | ||
138 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
139 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
140 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
141 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
142 | sendData["METHOD"] = "getgriduserinfo"; | ||
143 | |||
144 | sendData["UserID"] = userID; | ||
145 | |||
146 | return Get(sendData); | ||
147 | } | ||
148 | |||
149 | #endregion | ||
150 | |||
151 | protected bool Set(Dictionary<string, object> sendData, string userID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
152 | { | ||
153 | sendData["UserID"] = userID; | ||
154 | sendData["RegionID"] = regionID.ToString(); | ||
155 | sendData["Position"] = position.ToString(); | ||
156 | sendData["LookAt"] = lookAt.ToString(); | ||
157 | |||
158 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
159 | string uri = m_ServerURI + "/griduser"; | ||
160 | // m_log.DebugFormat("[GRID USER CONNECTOR]: queryString = {0}", reqString); | ||
161 | try | ||
162 | { | ||
163 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
164 | uri, | ||
165 | reqString); | ||
166 | if (reply != string.Empty) | ||
167 | { | ||
168 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
169 | |||
170 | if (replyData.ContainsKey("result")) | ||
171 | { | ||
172 | if (replyData["result"].ToString().ToLower() == "success") | ||
173 | return true; | ||
174 | else | ||
175 | return false; | ||
176 | } | ||
177 | else | ||
178 | m_log.DebugFormat("[GRID USER CONNECTOR]: SetPosition reply data does not contain result field"); | ||
179 | |||
180 | } | ||
181 | else | ||
182 | m_log.DebugFormat("[GRID USER CONNECTOR]: SetPosition received empty reply"); | ||
183 | } | ||
184 | catch (Exception e) | ||
185 | { | ||
186 | m_log.DebugFormat("[GRID USER CONNECTOR]: Exception when contacting grid user server at {0}: {1}", uri, e.Message); | ||
187 | } | ||
188 | |||
189 | return false; | ||
190 | } | ||
191 | |||
192 | protected GridUserInfo Get(Dictionary<string, object> sendData) | ||
193 | { | ||
194 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
195 | string uri = m_ServerURI + "/griduser"; | ||
196 | // m_log.DebugFormat("[GRID USER CONNECTOR]: queryString = {0}", reqString); | ||
197 | try | ||
198 | { | ||
199 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
200 | uri, | ||
201 | reqString); | ||
202 | if (reply != string.Empty) | ||
203 | { | ||
204 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
205 | GridUserInfo guinfo = null; | ||
206 | |||
207 | if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) | ||
208 | { | ||
209 | if (replyData["result"] is Dictionary<string, object>) | ||
210 | guinfo = new GridUserInfo((Dictionary<string, object>)replyData["result"]); | ||
211 | } | ||
212 | |||
213 | return guinfo; | ||
214 | |||
215 | } | ||
216 | else | ||
217 | m_log.DebugFormat("[GRID USER CONNECTOR]: Loggedin received empty reply"); | ||
218 | } | ||
219 | catch (Exception e) | ||
220 | { | ||
221 | m_log.DebugFormat("[GRID USER CONNECTOR]: Exception when contacting grid user server at {0}: {1}", uri, e.Message); | ||
222 | } | ||
223 | |||
224 | return null; | ||
225 | |||
226 | } | ||
227 | |||
228 | public GridUserInfo[] GetGridUserInfo(string[] userIDs) | ||
229 | { | ||
230 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
231 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
232 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
233 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
234 | sendData["METHOD"] = "getgriduserinfos"; | ||
235 | |||
236 | sendData["AgentIDs"] = new List<string>(userIDs); | ||
237 | |||
238 | string reply = string.Empty; | ||
239 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
240 | string uri = m_ServerURI + "/griduser"; | ||
241 | //m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
242 | try | ||
243 | { | ||
244 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
245 | uri, | ||
246 | reqString); | ||
247 | if (reply == null || (reply != null && reply == string.Empty)) | ||
248 | { | ||
249 | m_log.DebugFormat("[GRID USER CONNECTOR]: GetGridUserInfo received null or empty reply"); | ||
250 | return null; | ||
251 | } | ||
252 | } | ||
253 | catch (Exception e) | ||
254 | { | ||
255 | m_log.DebugFormat("[GRID USER CONNECTOR]: Exception when contacting grid user server at {0}: {1}", uri, e.Message); | ||
256 | } | ||
257 | |||
258 | List<GridUserInfo> rinfos = new List<GridUserInfo>(); | ||
259 | |||
260 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
261 | |||
262 | if (replyData != null) | ||
263 | { | ||
264 | if (replyData.ContainsKey("result") && | ||
265 | (replyData["result"].ToString() == "null" || replyData["result"].ToString() == "Failure")) | ||
266 | { | ||
267 | return new GridUserInfo[0]; | ||
268 | } | ||
269 | |||
270 | Dictionary<string, object>.ValueCollection pinfosList = replyData.Values; | ||
271 | //m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count); | ||
272 | foreach (object griduser in pinfosList) | ||
273 | { | ||
274 | if (griduser is Dictionary<string, object>) | ||
275 | { | ||
276 | GridUserInfo pinfo = new GridUserInfo((Dictionary<string, object>)griduser); | ||
277 | rinfos.Add(pinfo); | ||
278 | } | ||
279 | else | ||
280 | m_log.DebugFormat("[GRID USER CONNECTOR]: GetGridUserInfo received invalid response type {0}", | ||
281 | griduser.GetType()); | ||
282 | } | ||
283 | } | ||
284 | else | ||
285 | m_log.DebugFormat("[GRID USER CONNECTOR]: GetGridUserInfo received null response"); | ||
286 | |||
287 | return rinfos.ToArray(); | ||
288 | } | ||
289 | } | ||
290 | } | ||