diff options
author | Diva Canto | 2012-03-20 17:14:19 -0700 |
---|---|---|
committer | Diva Canto | 2012-03-20 17:14:19 -0700 |
commit | d08ad6459a03a6a5a6a551fd2b275f1c7da94d8e (patch) | |
tree | 62075048f4773a00593c658285b269459e9fcdfb /OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs | |
parent | Added GetUUID(first, last) on UserAgentsService so that we can finally make d... (diff) | |
download | opensim-SC_OLD-d08ad6459a03a6a5a6a551fd2b275f1c7da94d8e.zip opensim-SC_OLD-d08ad6459a03a6a5a6a551fd2b275f1c7da94d8e.tar.gz opensim-SC_OLD-d08ad6459a03a6a5a6a551fd2b275f1c7da94d8e.tar.bz2 opensim-SC_OLD-d08ad6459a03a6a5a6a551fd2b275f1c7da94d8e.tar.xz |
HG Friends: allow the establishment of HG friendships without requiring co-presence in the same sim. Using avatar picker, users can now search for names such as "first.last@grid.com:9000", find them, and request friendship. Friendship requests are stored if target user is offline. TESTED ON STANDALONE ONLY.
Diffstat (limited to 'OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs')
-rw-r--r-- | OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs | 159 |
1 files changed, 112 insertions, 47 deletions
diff --git a/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs b/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs index 661507e..ca566f2 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,26 @@ 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 "friendship_approved": | ||
110 | return FriendshipApproved(request); | ||
111 | |||
112 | case "friendship_denied": | ||
113 | return FriendshipDenied(request); | ||
114 | |||
115 | case "friendship_terminated": | ||
116 | return FriendshipTerminated(request); | ||
117 | |||
118 | case "grant_rights": | ||
119 | return GrantRights(request); | ||
120 | */ | ||
93 | } | 121 | } |
94 | m_log.DebugFormat("[HGFRIENDS HANDLER]: unknown method {0} request {1}", method.Length, method); | 122 | m_log.DebugFormat("[HGFRIENDS HANDLER]: unknown method {0} request {1}", method.Length, method); |
95 | } | 123 | } |
@@ -126,39 +154,20 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
126 | return FailureResult(); | 154 | return FailureResult(); |
127 | } | 155 | } |
128 | 156 | ||
129 | FriendInfo[] friendsInfo = m_FriendsService.GetFriends(principalID); | 157 | int perms = m_TheService.GetFriendPerms(principalID, friendID); |
130 | foreach (FriendInfo finfo in friendsInfo) | 158 | if (perms < 0) |
131 | { | 159 | return FailureResult("Friend not found"); |
132 | if (finfo.Friend.StartsWith(friendID.ToString())) | ||
133 | return SuccessResult(finfo.TheirFlags.ToString()); | ||
134 | } | ||
135 | 160 | ||
136 | return FailureResult("Friend not found"); | 161 | return SuccessResult(perms.ToString()); |
137 | } | 162 | } |
138 | 163 | ||
139 | byte[] NewFriendship(Dictionary<string, object> request) | 164 | byte[] NewFriendship(Dictionary<string, object> request) |
140 | { | 165 | { |
141 | if (!VerifyServiceKey(request)) | 166 | bool verified = VerifyServiceKey(request); |
142 | return FailureResult(); | ||
143 | 167 | ||
144 | // OK, can proceed | ||
145 | FriendInfo friend = new FriendInfo(request); | 168 | 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 | 169 | ||
151 | 170 | bool success = m_TheService.NewFriendship(friend, verified); | |
152 | m_log.DebugFormat("[HGFRIENDS HANDLER]: New friendship {0} {1}", friend.PrincipalID, friend.Friend); | ||
153 | |||
154 | // If the friendship already exists, return fail | ||
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 | 171 | ||
163 | if (success) | 172 | if (success) |
164 | return SuccessResult(); | 173 | return SuccessResult(); |
@@ -174,25 +183,53 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
174 | secret = request["SECRET"].ToString(); | 183 | secret = request["SECRET"].ToString(); |
175 | 184 | ||
176 | if (secret == string.Empty) | 185 | if (secret == string.Empty) |
177 | return FailureResult(); | 186 | return BoolResult(false); |
178 | 187 | ||
179 | FriendInfo[] finfos = m_FriendsService.GetFriends(friend.PrincipalID); | 188 | bool success = m_TheService.DeleteFriendship(friend, secret); |
180 | foreach (FriendInfo finfo in finfos) | ||
181 | { | ||
182 | // We check the secret here | ||
183 | if (finfo.Friend.StartsWith(friend.Friend) && finfo.Friend.EndsWith(secret)) | ||
184 | { | ||
185 | m_log.DebugFormat("[HGFRIENDS HANDLER]: Delete friendship {0} {1}", friend.PrincipalID, friend.Friend); | ||
186 | m_FriendsService.Delete(friend.PrincipalID, finfo.Friend); | ||
187 | m_FriendsService.Delete(finfo.Friend, friend.PrincipalID.ToString()); | ||
188 | 189 | ||
189 | return SuccessResult(); | 190 | return BoolResult(success); |
190 | } | 191 | } |
191 | } | ||
192 | 192 | ||
193 | return FailureResult(); | 193 | byte[] FriendshipOffered(Dictionary<string, object> request) |
194 | { | ||
195 | UUID fromID = UUID.Zero; | ||
196 | UUID toID = UUID.Zero; | ||
197 | string message = string.Empty; | ||
198 | string name = string.Empty; | ||
199 | |||
200 | m_log.DebugFormat("[HGFRIENDS HANDLER]: Friendship offered"); | ||
201 | if (!request.ContainsKey("FromID") || !request.ContainsKey("ToID")) | ||
202 | return BoolResult(false); | ||
203 | |||
204 | if (!UUID.TryParse(request["ToID"].ToString(), out toID)) | ||
205 | return BoolResult(false); | ||
206 | |||
207 | message = request["Message"].ToString(); | ||
208 | |||
209 | if (!UUID.TryParse(request["FromID"].ToString(), out fromID)) | ||
210 | return BoolResult(false); | ||
211 | |||
212 | if (request.ContainsKey("FromName")) | ||
213 | name = request["FromName"].ToString(); | ||
214 | |||
215 | bool success = m_TheService.FriendshipOffered(fromID, name, toID, message); | ||
216 | |||
217 | return BoolResult(success); | ||
194 | } | 218 | } |
195 | 219 | ||
220 | byte[] ValidateFriendshipOffered(Dictionary<string, object> request) | ||
221 | { | ||
222 | FriendInfo friend = new FriendInfo(request); | ||
223 | UUID friendID = UUID.Zero; | ||
224 | if (!UUID.TryParse(friend.Friend, out friendID)) | ||
225 | return BoolResult(false); | ||
226 | |||
227 | bool success = m_TheService.ValidateFriendshipOffered(friend.PrincipalID, friendID); | ||
228 | |||
229 | return BoolResult(success); | ||
230 | } | ||
231 | |||
232 | |||
196 | #endregion | 233 | #endregion |
197 | 234 | ||
198 | #region Misc | 235 | #region Misc |
@@ -205,10 +242,15 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
205 | return false; | 242 | return false; |
206 | } | 243 | } |
207 | 244 | ||
245 | if (request["KEY"] == null || request["SESSIONID"] == null) | ||
246 | return false; | ||
247 | |||
208 | string serviceKey = request["KEY"].ToString(); | 248 | string serviceKey = request["KEY"].ToString(); |
209 | string sessionStr = request["SESSIONID"].ToString(); | 249 | string sessionStr = request["SESSIONID"].ToString(); |
250 | |||
210 | UUID sessionID; | 251 | UUID sessionID; |
211 | UUID.TryParse(sessionStr, out sessionID); | 252 | if (!UUID.TryParse(sessionStr, out sessionID) || serviceKey == string.Empty) |
253 | return false; | ||
212 | 254 | ||
213 | if (!m_UserAgentService.VerifyAgent(sessionID, serviceKey)) | 255 | if (!m_UserAgentService.VerifyAgent(sessionID, serviceKey)) |
214 | { | 256 | { |
@@ -256,7 +298,7 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
256 | 298 | ||
257 | doc.AppendChild(rootElement); | 299 | doc.AppendChild(rootElement); |
258 | 300 | ||
259 | XmlElement result = doc.CreateElement("", "Result", ""); | 301 | XmlElement result = doc.CreateElement("", "RESULT", ""); |
260 | result.AppendChild(doc.CreateTextNode("Success")); | 302 | result.AppendChild(doc.CreateTextNode("Success")); |
261 | 303 | ||
262 | rootElement.AppendChild(result); | 304 | rootElement.AppendChild(result); |
@@ -289,7 +331,7 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
289 | 331 | ||
290 | doc.AppendChild(rootElement); | 332 | doc.AppendChild(rootElement); |
291 | 333 | ||
292 | XmlElement result = doc.CreateElement("", "Result", ""); | 334 | XmlElement result = doc.CreateElement("", "RESULT", ""); |
293 | result.AppendChild(doc.CreateTextNode("Failure")); | 335 | result.AppendChild(doc.CreateTextNode("Failure")); |
294 | 336 | ||
295 | rootElement.AppendChild(result); | 337 | rootElement.AppendChild(result); |
@@ -302,6 +344,28 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
302 | return DocToBytes(doc); | 344 | return DocToBytes(doc); |
303 | } | 345 | } |
304 | 346 | ||
347 | private byte[] BoolResult(bool value) | ||
348 | { | ||
349 | XmlDocument doc = new XmlDocument(); | ||
350 | |||
351 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
352 | "", ""); | ||
353 | |||
354 | doc.AppendChild(xmlnode); | ||
355 | |||
356 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
357 | ""); | ||
358 | |||
359 | doc.AppendChild(rootElement); | ||
360 | |||
361 | XmlElement result = doc.CreateElement("", "RESULT", ""); | ||
362 | result.AppendChild(doc.CreateTextNode(value.ToString())); | ||
363 | |||
364 | rootElement.AppendChild(result); | ||
365 | |||
366 | return DocToBytes(doc); | ||
367 | } | ||
368 | |||
305 | private byte[] DocToBytes(XmlDocument doc) | 369 | private byte[] DocToBytes(XmlDocument doc) |
306 | { | 370 | { |
307 | MemoryStream ms = new MemoryStream(); | 371 | MemoryStream ms = new MemoryStream(); |
@@ -313,6 +377,7 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
313 | return ms.ToArray(); | 377 | return ms.ToArray(); |
314 | } | 378 | } |
315 | 379 | ||
380 | |||
316 | #endregion | 381 | #endregion |
317 | } | 382 | } |
318 | } | 383 | } |