diff options
Diffstat (limited to 'OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs')
-rw-r--r-- | OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs | 204 |
1 files changed, 162 insertions, 42 deletions
diff --git a/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs b/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs index 661507e..8ef03e7 100644 --- a/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs | |||
@@ -39,6 +39,7 @@ using System.Collections.Generic; | |||
39 | using OpenSim.Server.Base; | 39 | using OpenSim.Server.Base; |
40 | using OpenSim.Services.Interfaces; | 40 | using OpenSim.Services.Interfaces; |
41 | using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; | 41 | using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; |
42 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
42 | using OpenSim.Framework; | 43 | using OpenSim.Framework; |
43 | using OpenSim.Framework.Servers.HttpServer; | 44 | using OpenSim.Framework.Servers.HttpServer; |
44 | using OpenMetaverse; | 45 | using OpenMetaverse; |
@@ -49,15 +50,22 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
49 | { | 50 | { |
50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 51 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
51 | 52 | ||
52 | private IFriendsService m_FriendsService; | ||
53 | private IUserAgentService m_UserAgentService; | 53 | private IUserAgentService m_UserAgentService; |
54 | private IFriendsSimConnector m_FriendsLocalSimConnector; | ||
55 | private IHGFriendsService m_TheService; | ||
54 | 56 | ||
55 | public HGFriendsServerPostHandler(IFriendsService service, IUserAgentService uservice) : | 57 | public HGFriendsServerPostHandler(IHGFriendsService service, IUserAgentService uas, IFriendsSimConnector friendsConn) : |
56 | base("POST", "/hgfriends") | 58 | base("POST", "/hgfriends") |
57 | { | 59 | { |
58 | m_FriendsService = service; | 60 | m_TheService = service; |
59 | m_UserAgentService = uservice; | 61 | m_UserAgentService = uas; |
60 | m_log.DebugFormat("[HGFRIENDS HANDLER]: HGFriendsServerPostHandler is On"); | 62 | m_FriendsLocalSimConnector = friendsConn; |
63 | |||
64 | m_log.DebugFormat("[HGFRIENDS HANDLER]: HGFriendsServerPostHandler is On ({0})", | ||
65 | (m_FriendsLocalSimConnector == null ? "robust" : "standalone")); | ||
66 | |||
67 | if (m_TheService == null) | ||
68 | m_log.ErrorFormat("[HGFRIENDS HANDLER]: TheService is null!"); | ||
61 | } | 69 | } |
62 | 70 | ||
63 | public override byte[] Handle(string path, Stream requestData, | 71 | public override byte[] Handle(string path, Stream requestData, |
@@ -90,6 +98,29 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
90 | 98 | ||
91 | case "deletefriendship": | 99 | case "deletefriendship": |
92 | return DeleteFriendship(request); | 100 | return DeleteFriendship(request); |
101 | |||
102 | /* Same as inter-sim */ | ||
103 | case "friendship_offered": | ||
104 | return FriendshipOffered(request); | ||
105 | |||
106 | case "validate_friendship_offered": | ||
107 | return ValidateFriendshipOffered(request); | ||
108 | |||
109 | case "statusnotification": | ||
110 | return StatusNotification(request); | ||
111 | /* | ||
112 | case "friendship_approved": | ||
113 | return FriendshipApproved(request); | ||
114 | |||
115 | case "friendship_denied": | ||
116 | return FriendshipDenied(request); | ||
117 | |||
118 | case "friendship_terminated": | ||
119 | return FriendshipTerminated(request); | ||
120 | |||
121 | case "grant_rights": | ||
122 | return GrantRights(request); | ||
123 | */ | ||
93 | } | 124 | } |
94 | m_log.DebugFormat("[HGFRIENDS HANDLER]: unknown method {0} request {1}", method.Length, method); | 125 | m_log.DebugFormat("[HGFRIENDS HANDLER]: unknown method {0} request {1}", method.Length, method); |
95 | } | 126 | } |
@@ -126,39 +157,20 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
126 | return FailureResult(); | 157 | return FailureResult(); |
127 | } | 158 | } |
128 | 159 | ||
129 | FriendInfo[] friendsInfo = m_FriendsService.GetFriends(principalID); | 160 | int perms = m_TheService.GetFriendPerms(principalID, friendID); |
130 | foreach (FriendInfo finfo in friendsInfo) | 161 | if (perms < 0) |
131 | { | 162 | return FailureResult("Friend not found"); |
132 | if (finfo.Friend.StartsWith(friendID.ToString())) | ||
133 | return SuccessResult(finfo.TheirFlags.ToString()); | ||
134 | } | ||
135 | 163 | ||
136 | return FailureResult("Friend not found"); | 164 | return SuccessResult(perms.ToString()); |
137 | } | 165 | } |
138 | 166 | ||
139 | byte[] NewFriendship(Dictionary<string, object> request) | 167 | byte[] NewFriendship(Dictionary<string, object> request) |
140 | { | 168 | { |
141 | if (!VerifyServiceKey(request)) | 169 | bool verified = VerifyServiceKey(request); |
142 | return FailureResult(); | ||
143 | 170 | ||
144 | // OK, can proceed | ||
145 | FriendInfo friend = new FriendInfo(request); | 171 | FriendInfo friend = new FriendInfo(request); |
146 | UUID friendID; | ||
147 | string tmp = string.Empty; | ||
148 | if (!Util.ParseUniversalUserIdentifier(friend.Friend, out friendID, out tmp, out tmp, out tmp, out tmp)) | ||
149 | return FailureResult(); | ||
150 | |||
151 | |||
152 | m_log.DebugFormat("[HGFRIENDS HANDLER]: New friendship {0} {1}", friend.PrincipalID, friend.Friend); | ||
153 | 172 | ||
154 | // If the friendship already exists, return fail | 173 | bool success = m_TheService.NewFriendship(friend, verified); |
155 | FriendInfo[] finfos = m_FriendsService.GetFriends(friend.PrincipalID); | ||
156 | foreach (FriendInfo finfo in finfos) | ||
157 | if (finfo.Friend.StartsWith(friendID.ToString())) | ||
158 | return FailureResult(); | ||
159 | |||
160 | // the user needs to confirm when he gets home | ||
161 | bool success = m_FriendsService.StoreFriend(friend.PrincipalID.ToString(), friend.Friend, 0); | ||
162 | 174 | ||
163 | if (success) | 175 | if (success) |
164 | return SuccessResult(); | 176 | return SuccessResult(); |
@@ -174,25 +186,105 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
174 | secret = request["SECRET"].ToString(); | 186 | secret = request["SECRET"].ToString(); |
175 | 187 | ||
176 | if (secret == string.Empty) | 188 | if (secret == string.Empty) |
189 | return BoolResult(false); | ||
190 | |||
191 | bool success = m_TheService.DeleteFriendship(friend, secret); | ||
192 | |||
193 | return BoolResult(success); | ||
194 | } | ||
195 | |||
196 | byte[] FriendshipOffered(Dictionary<string, object> request) | ||
197 | { | ||
198 | UUID fromID = UUID.Zero; | ||
199 | UUID toID = UUID.Zero; | ||
200 | string message = string.Empty; | ||
201 | string name = string.Empty; | ||
202 | |||
203 | if (!request.ContainsKey("FromID") || !request.ContainsKey("ToID")) | ||
204 | return BoolResult(false); | ||
205 | |||
206 | if (!UUID.TryParse(request["ToID"].ToString(), out toID)) | ||
207 | return BoolResult(false); | ||
208 | |||
209 | message = request["Message"].ToString(); | ||
210 | |||
211 | if (!UUID.TryParse(request["FromID"].ToString(), out fromID)) | ||
212 | return BoolResult(false); | ||
213 | |||
214 | if (request.ContainsKey("FromName")) | ||
215 | name = request["FromName"].ToString(); | ||
216 | |||
217 | bool success = m_TheService.FriendshipOffered(fromID, name, toID, message); | ||
218 | |||
219 | return BoolResult(success); | ||
220 | } | ||
221 | |||
222 | byte[] ValidateFriendshipOffered(Dictionary<string, object> request) | ||
223 | { | ||
224 | FriendInfo friend = new FriendInfo(request); | ||
225 | UUID friendID = UUID.Zero; | ||
226 | if (!UUID.TryParse(friend.Friend, out friendID)) | ||
227 | return BoolResult(false); | ||
228 | |||
229 | bool success = m_TheService.ValidateFriendshipOffered(friend.PrincipalID, friendID); | ||
230 | |||
231 | return BoolResult(success); | ||
232 | } | ||
233 | |||
234 | byte[] StatusNotification(Dictionary<string, object> request) | ||
235 | { | ||
236 | UUID principalID = UUID.Zero; | ||
237 | if (request.ContainsKey("userID")) | ||
238 | UUID.TryParse(request["userID"].ToString(), out principalID); | ||
239 | else | ||
240 | { | ||
241 | m_log.WarnFormat("[HGFRIENDS HANDLER]: no userID in request to notify"); | ||
242 | return FailureResult(); | ||
243 | } | ||
244 | |||
245 | bool online = true; | ||
246 | if (request.ContainsKey("online")) | ||
247 | Boolean.TryParse(request["online"].ToString(), out online); | ||
248 | else | ||
249 | { | ||
250 | m_log.WarnFormat("[HGFRIENDS HANDLER]: no online in request to notify"); | ||
177 | return FailureResult(); | 251 | return FailureResult(); |
252 | } | ||
178 | 253 | ||
179 | FriendInfo[] finfos = m_FriendsService.GetFriends(friend.PrincipalID); | 254 | List<string> friends = new List<string>(); |
180 | foreach (FriendInfo finfo in finfos) | 255 | int i = 0; |
256 | foreach (KeyValuePair<string, object> kvp in request) | ||
181 | { | 257 | { |
182 | // We check the secret here | 258 | if (kvp.Key.Equals("friend_" + i.ToString())) |
183 | if (finfo.Friend.StartsWith(friend.Friend) && finfo.Friend.EndsWith(secret)) | ||
184 | { | 259 | { |
185 | m_log.DebugFormat("[HGFRIENDS HANDLER]: Delete friendship {0} {1}", friend.PrincipalID, friend.Friend); | 260 | friends.Add(kvp.Value.ToString()); |
186 | m_FriendsService.Delete(friend.PrincipalID, finfo.Friend); | 261 | i++; |
187 | m_FriendsService.Delete(finfo.Friend, friend.PrincipalID.ToString()); | 262 | } |
263 | } | ||
264 | |||
265 | List<UUID> onlineFriends = m_TheService.StatusNotification(friends, principalID, online); | ||
188 | 266 | ||
189 | return SuccessResult(); | 267 | Dictionary<string, object> result = new Dictionary<string, object>(); |
268 | if ((onlineFriends == null) || ((onlineFriends != null) && (onlineFriends.Count == 0))) | ||
269 | result["RESULT"] = "NULL"; | ||
270 | else | ||
271 | { | ||
272 | i = 0; | ||
273 | foreach (UUID f in onlineFriends) | ||
274 | { | ||
275 | result["friend_" + i] = f.ToString(); | ||
276 | i++; | ||
190 | } | 277 | } |
191 | } | 278 | } |
192 | 279 | ||
193 | return FailureResult(); | 280 | string xmlString = ServerUtils.BuildXmlResponse(result); |
281 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
282 | UTF8Encoding encoding = new UTF8Encoding(); | ||
283 | return encoding.GetBytes(xmlString); | ||
284 | |||
194 | } | 285 | } |
195 | 286 | ||
287 | |||
196 | #endregion | 288 | #endregion |
197 | 289 | ||
198 | #region Misc | 290 | #region Misc |
@@ -205,10 +297,15 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
205 | return false; | 297 | return false; |
206 | } | 298 | } |
207 | 299 | ||
300 | if (request["KEY"] == null || request["SESSIONID"] == null) | ||
301 | return false; | ||
302 | |||
208 | string serviceKey = request["KEY"].ToString(); | 303 | string serviceKey = request["KEY"].ToString(); |
209 | string sessionStr = request["SESSIONID"].ToString(); | 304 | string sessionStr = request["SESSIONID"].ToString(); |
305 | |||
210 | UUID sessionID; | 306 | UUID sessionID; |
211 | UUID.TryParse(sessionStr, out sessionID); | 307 | if (!UUID.TryParse(sessionStr, out sessionID) || serviceKey == string.Empty) |
308 | return false; | ||
212 | 309 | ||
213 | if (!m_UserAgentService.VerifyAgent(sessionID, serviceKey)) | 310 | if (!m_UserAgentService.VerifyAgent(sessionID, serviceKey)) |
214 | { | 311 | { |
@@ -256,7 +353,7 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
256 | 353 | ||
257 | doc.AppendChild(rootElement); | 354 | doc.AppendChild(rootElement); |
258 | 355 | ||
259 | XmlElement result = doc.CreateElement("", "Result", ""); | 356 | XmlElement result = doc.CreateElement("", "RESULT", ""); |
260 | result.AppendChild(doc.CreateTextNode("Success")); | 357 | result.AppendChild(doc.CreateTextNode("Success")); |
261 | 358 | ||
262 | rootElement.AppendChild(result); | 359 | rootElement.AppendChild(result); |
@@ -289,7 +386,7 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
289 | 386 | ||
290 | doc.AppendChild(rootElement); | 387 | doc.AppendChild(rootElement); |
291 | 388 | ||
292 | XmlElement result = doc.CreateElement("", "Result", ""); | 389 | XmlElement result = doc.CreateElement("", "RESULT", ""); |
293 | result.AppendChild(doc.CreateTextNode("Failure")); | 390 | result.AppendChild(doc.CreateTextNode("Failure")); |
294 | 391 | ||
295 | rootElement.AppendChild(result); | 392 | rootElement.AppendChild(result); |
@@ -302,6 +399,28 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
302 | return DocToBytes(doc); | 399 | return DocToBytes(doc); |
303 | } | 400 | } |
304 | 401 | ||
402 | private byte[] BoolResult(bool value) | ||
403 | { | ||
404 | XmlDocument doc = new XmlDocument(); | ||
405 | |||
406 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
407 | "", ""); | ||
408 | |||
409 | doc.AppendChild(xmlnode); | ||
410 | |||
411 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
412 | ""); | ||
413 | |||
414 | doc.AppendChild(rootElement); | ||
415 | |||
416 | XmlElement result = doc.CreateElement("", "RESULT", ""); | ||
417 | result.AppendChild(doc.CreateTextNode(value.ToString())); | ||
418 | |||
419 | rootElement.AppendChild(result); | ||
420 | |||
421 | return DocToBytes(doc); | ||
422 | } | ||
423 | |||
305 | private byte[] DocToBytes(XmlDocument doc) | 424 | private byte[] DocToBytes(XmlDocument doc) |
306 | { | 425 | { |
307 | MemoryStream ms = new MemoryStream(); | 426 | MemoryStream ms = new MemoryStream(); |
@@ -313,6 +432,7 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
313 | return ms.ToArray(); | 432 | return ms.ToArray(); |
314 | } | 433 | } |
315 | 434 | ||
435 | |||
316 | #endregion | 436 | #endregion |
317 | } | 437 | } |
318 | } | 438 | } |