diff options
Diffstat (limited to 'OpenSim/Services/Connectors/GridUser')
-rw-r--r-- | OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs | 196 |
1 files changed, 194 insertions, 2 deletions
diff --git a/OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs b/OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs index 0e85067..b4500a5 100644 --- a/OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs +++ b/OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs | |||
@@ -25,14 +25,206 @@ | |||
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; | ||
28 | using System; | 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; | ||
29 | 41 | ||
30 | namespace OpenSim.Services.Connectors | 42 | namespace OpenSim.Services.Connectors |
31 | { | 43 | { |
32 | public class GridUserServiceConnector | 44 | public class GridUserServicesConnector : IGridUserService |
33 | { | 45 | { |
34 | public GridUserServiceConnector() | 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 GridUserServicesConnector() | ||
53 | { | ||
54 | } | ||
55 | |||
56 | public GridUserServicesConnector(string serverURI) | ||
57 | { | ||
58 | m_ServerURI = serverURI.TrimEnd('/'); | ||
59 | } | ||
60 | |||
61 | public GridUserServicesConnector(IConfigSource source) | ||
62 | { | ||
63 | Initialise(source); | ||
64 | } | ||
65 | |||
66 | public virtual void Initialise(IConfigSource source) | ||
67 | { | ||
68 | IConfig gridConfig = source.Configs["GridUserService"]; | ||
69 | if (gridConfig == null) | ||
70 | { | ||
71 | m_log.Error("[GRID USER CONNECTOR]: GridUserService missing from OpenSim.ini"); | ||
72 | throw new Exception("GridUser connector init error"); | ||
73 | } | ||
74 | |||
75 | string serviceURI = gridConfig.GetString("GridUserServerURI", | ||
76 | String.Empty); | ||
77 | |||
78 | if (serviceURI == String.Empty) | ||
79 | { | ||
80 | m_log.Error("[GRID USER CONNECTOR]: No Server URI named in section GridUserService"); | ||
81 | throw new Exception("GridUser connector init error"); | ||
82 | } | ||
83 | m_ServerURI = serviceURI; | ||
84 | } | ||
85 | |||
86 | |||
87 | #region IPresenceService | ||
88 | |||
89 | |||
90 | public GridUserInfo LoggedIn(string 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"] = "loggedin"; | ||
97 | |||
98 | sendData["UserID"] = userID; | ||
99 | |||
100 | return Get(sendData); | ||
101 | |||
102 | } | ||
103 | |||
104 | public bool LoggedOut(string userID, UUID region, Vector3 position, Vector3 lookat) | ||
105 | { | ||
106 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
107 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
108 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
109 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
110 | sendData["METHOD"] = "loggedout"; | ||
111 | |||
112 | return Set(sendData, userID, region, position, lookat); | ||
113 | } | ||
114 | |||
115 | public bool SetHome(string userID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
116 | { | ||
117 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
118 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
119 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
120 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
121 | sendData["METHOD"] = "sethome"; | ||
122 | |||
123 | return Set(sendData, userID, regionID, position, lookAt); | ||
124 | } | ||
125 | |||
126 | public bool SetLastPosition(string userID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
127 | { | ||
128 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
129 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
130 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
131 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
132 | sendData["METHOD"] = "setposition"; | ||
133 | |||
134 | return Set(sendData, userID, regionID, position, lookAt); | ||
135 | } | ||
136 | |||
137 | public GridUserInfo GetGridUserInfo(string userID) | ||
138 | { | ||
139 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
140 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
141 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
142 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
143 | sendData["METHOD"] = "getgriduserinfo"; | ||
144 | |||
145 | sendData["UserID"] = userID; | ||
146 | |||
147 | return Get(sendData); | ||
148 | } | ||
149 | |||
150 | #endregion | ||
151 | |||
152 | protected bool Set(Dictionary<string, object> sendData, string userID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
153 | { | ||
154 | sendData["UserID"] = userID; | ||
155 | sendData["RegionID"] = regionID.ToString(); | ||
156 | sendData["Position"] = position.ToString(); | ||
157 | sendData["LookAt"] = lookAt.ToString(); | ||
158 | |||
159 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
160 | // m_log.DebugFormat("[GRID USER CONNECTOR]: queryString = {0}", reqString); | ||
161 | try | ||
162 | { | ||
163 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
164 | m_ServerURI + "/griduser", | ||
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: {0}", e.Message); | ||
187 | } | ||
188 | |||
189 | return false; | ||
190 | } | ||
191 | |||
192 | protected GridUserInfo Get(Dictionary<string, object> sendData) | ||
35 | { | 193 | { |
194 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
195 | // m_log.DebugFormat("[GRID USER CONNECTOR]: queryString = {0}", reqString); | ||
196 | try | ||
197 | { | ||
198 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
199 | m_ServerURI + "/griduser", | ||
200 | reqString); | ||
201 | if (reply != string.Empty) | ||
202 | { | ||
203 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
204 | GridUserInfo guinfo = null; | ||
205 | |||
206 | if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) | ||
207 | { | ||
208 | if (replyData["result"] is Dictionary<string, object>) | ||
209 | { | ||
210 | guinfo = new GridUserInfo((Dictionary<string, object>)replyData["result"]); | ||
211 | } | ||
212 | } | ||
213 | |||
214 | return guinfo; | ||
215 | |||
216 | } | ||
217 | else | ||
218 | m_log.DebugFormat("[GRID USER CONNECTOR]: Loggedin received empty reply"); | ||
219 | } | ||
220 | catch (Exception e) | ||
221 | { | ||
222 | m_log.DebugFormat("[GRID USER CONNECTOR]: Exception when contacting grid user server: {0}", e.Message); | ||
223 | } | ||
224 | |||
225 | return null; | ||
226 | |||
36 | } | 227 | } |
228 | |||
37 | } | 229 | } |
38 | } | 230 | } |