aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs
diff options
context:
space:
mode:
authorDiva Canto2011-05-19 16:54:46 -0700
committerDiva Canto2011-05-19 16:54:46 -0700
commitd21e9c755f004d8fe03b11bc57b810dbd401435a (patch)
tree1efd9e48308192d21ca73d8ff12d6a48c186077c /OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs
parentAccidentally committed too early (diff)
downloadopensim-SC_OLD-d21e9c755f004d8fe03b11bc57b810dbd401435a.zip
opensim-SC_OLD-d21e9c755f004d8fe03b11bc57b810dbd401435a.tar.gz
opensim-SC_OLD-d21e9c755f004d8fe03b11bc57b810dbd401435a.tar.bz2
opensim-SC_OLD-d21e9c755f004d8fe03b11bc57b810dbd401435a.tar.xz
HG Friends working to some extent: friendships offered and accepted correctly handled. Friends list showing correct foreign names. TODO: GrantRights.
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs438
1 files changed, 438 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs
new file mode 100644
index 0000000..645ecdc
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs
@@ -0,0 +1,438 @@
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
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Reflection;
32using log4net;
33using Nini.Config;
34using Nwc.XmlRpc;
35using Mono.Addins;
36using OpenMetaverse;
37using OpenSim.Framework;
38using OpenSim.Region.Framework.Interfaces;
39using OpenSim.Region.Framework.Scenes;
40using OpenSim.Services.Interfaces;
41using OpenSim.Services.Connectors.Hypergrid;
42using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
43using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo;
44using GridRegion = OpenSim.Services.Interfaces.GridRegion;
45
46namespace OpenSim.Region.CoreModules.Avatar.Friends
47{
48 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
49 public class HGFriendsModule : FriendsModule, ISharedRegionModule, IFriendsModule
50 {
51 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52
53 #region ISharedRegionModule
54 public override string Name
55 {
56 get { return "HGFriendsModule"; }
57 }
58
59 #endregion
60
61 //public void SendFriendsOnlineIfNeeded(IClientAPI client)
62 //{
63 // UUID agentID = client.AgentId;
64
65 // // Check if the online friends list is needed
66 // lock (m_NeedsListOfFriends)
67 // {
68 // if (!m_NeedsListOfFriends.Remove(agentID))
69 // return;
70 // }
71
72 // // Send the friends online
73 // List<UUID> online = GetOnlineFriends(agentID);
74 // if (online.Count > 0)
75 // {
76 // m_log.DebugFormat("[FRIENDS MODULE]: User {0} in region {1} has {2} friends online", client.AgentId, client.Scene.RegionInfo.RegionName, online.Count);
77 // client.SendAgentOnline(online.ToArray());
78 // }
79
80 // // Send outstanding friendship offers
81 // List<string> outstanding = new List<string>();
82 // FriendInfo[] friends = GetFriends(agentID);
83 // foreach (FriendInfo fi in friends)
84 // {
85 // if (fi.TheirFlags == -1)
86 // outstanding.Add(fi.Friend);
87 // }
88
89 // GridInstantMessage im = new GridInstantMessage(client.Scene, UUID.Zero, String.Empty, agentID, (byte)InstantMessageDialog.FriendshipOffered,
90 // "Will you be my friend?", true, Vector3.Zero);
91
92 // foreach (string fid in outstanding)
93 // {
94 // UUID fromAgentID;
95 // if (!UUID.TryParse(fid, out fromAgentID))
96 // continue;
97
98 // UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(client.Scene.RegionInfo.ScopeID, fromAgentID);
99
100 // PresenceInfo presence = null;
101 // PresenceInfo[] presences = PresenceService.GetAgents(new string[] { fid });
102 // if (presences != null && presences.Length > 0)
103 // presence = presences[0];
104 // if (presence != null)
105 // im.offline = 0;
106
107 // im.fromAgentID = fromAgentID.Guid;
108 // im.fromAgentName = account.FirstName + " " + account.LastName;
109 // im.offline = (byte)((presence == null) ? 1 : 0);
110 // im.imSessionID = im.fromAgentID;
111
112 // // Finally
113 // LocalFriendshipOffered(agentID, im);
114 // }
115 //}
116
117 //List<UUID> GetOnlineFriends(UUID userID)
118 //{
119 // List<string> friendList = new List<string>();
120 // List<UUID> online = new List<UUID>();
121
122 // FriendInfo[] friends = GetFriends(userID);
123 // foreach (FriendInfo fi in friends)
124 // {
125 // if (((fi.TheirFlags & 1) != 0) && (fi.TheirFlags != -1))
126 // friendList.Add(fi.Friend);
127 // }
128
129 // if (friendList.Count > 0)
130 // {
131 // PresenceInfo[] presence = PresenceService.GetAgents(friendList.ToArray());
132 // foreach (PresenceInfo pi in presence)
133 // {
134 // UUID presenceID;
135 // if (UUID.TryParse(pi.UserID, out presenceID))
136 // online.Add(presenceID);
137 // }
138 // }
139
140 // return online;
141 //}
142
143 //private void StatusNotify(FriendInfo friend, UUID userID, bool online)
144 //{
145 // UUID friendID;
146 // if (UUID.TryParse(friend.Friend, out friendID))
147 // {
148 // // Try local
149 // if (LocalStatusNotification(userID, friendID, online))
150 // return;
151
152 // // The friend is not here [as root]. Let's forward.
153 // PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() });
154 // if (friendSessions != null && friendSessions.Length > 0)
155 // {
156 // PresenceInfo friendSession = null;
157 // foreach (PresenceInfo pinfo in friendSessions)
158 // if (pinfo.RegionID != UUID.Zero) // let's guard against sessions-gone-bad
159 // {
160 // friendSession = pinfo;
161 // break;
162 // }
163
164 // if (friendSession != null)
165 // {
166 // GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID);
167 // //m_log.DebugFormat("[FRIENDS]: Remote Notify to region {0}", region.RegionName);
168 // m_FriendsSimConnector.StatusNotify(region, userID, friendID, online);
169 // }
170 // }
171
172 // // Friend is not online. Ignore.
173 // }
174 // else
175 // {
176 // m_log.WarnFormat("[FRIENDS]: Error parsing friend ID {0}", friend.Friend);
177 // }
178 //}
179
180 protected override bool FetchFriendslist(UUID agentID)
181 {
182 if (base.FetchFriendslist(agentID))
183 {
184 // We need to preload the user management cache with the names
185 // of foreign friends, just like we do with SOPs' creators
186 foreach (FriendInfo finfo in m_Friends[agentID].Friends)
187 {
188 if (finfo.TheirFlags != -1)
189 {
190 UUID id;
191 if (!UUID.TryParse(finfo.Friend, out id))
192 {
193 string url = string.Empty, first = string.Empty, last = string.Empty;
194 if (Util.ParseUniversalUserIdentifier(finfo.Friend, out id, out url, out first, out last))
195 {
196 IUserManagement uMan = m_Scenes[0].RequestModuleInterface<IUserManagement>();
197 uMan.AddUser(id, url + ";" + first + " " + last);
198 }
199 }
200 }
201 }
202 return true;
203 }
204 return false;
205 }
206
207 protected override bool GetAgentInfo(UUID scopeID, string fid, out UUID agentID, out string first, out string last)
208 {
209 first = "Unknown"; last = "User";
210 if (base.GetAgentInfo(scopeID, fid, out agentID, out first, out last))
211 return true;
212
213 // fid is not a UUID...
214 string url = string.Empty;
215 if (Util.ParseUniversalUserIdentifier(fid, out agentID, out url, out first, out last))
216 {
217 IUserManagement userMan = m_Scenes[0].RequestModuleInterface<IUserManagement>();
218 userMan.AddUser(agentID, url + ";" + first + " " + last);
219
220 try // our best
221 {
222 string[] parts = userMan.GetUserName(agentID).Split();
223 first = parts[0];
224 last = parts[1];
225 }
226 catch { }
227 return true;
228 }
229 return false;
230 }
231
232 protected override string GetFriendshipRequesterName(UUID agentID)
233 {
234 // For the time being we assume that HG friendship requests can only happen
235 // when avies are on the same region.
236 IClientAPI client = LocateClientObject(agentID);
237 if (client != null)
238 return client.FirstName + " " + client.LastName;
239 else
240 return base.GetFriendshipRequesterName(agentID);
241 }
242
243 protected override string FriendshipMessage(string friendID)
244 {
245 UUID id;
246 if (UUID.TryParse(friendID, out id))
247 return base.FriendshipMessage(friendID);
248
249 return "Please confirm this friendship you made while you were away.";
250 }
251
252 protected override void StoreBackwards(UUID friendID, UUID agentID)
253 {
254 UserAccount account1 = UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, agentID);
255 UserAccount account2 = UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, friendID);
256 // Are they both local users?
257 if (account1 != null && account2 != null)
258 {
259 // local grid users
260 m_log.DebugFormat("[HGFRIENDS MODULE]: Users are both local");
261 base.StoreBackwards(friendID, agentID);
262 return;
263 }
264
265 // no provision for this temporary friendship state
266 //FriendsService.StoreFriend(friendID.ToString(), agentID.ToString(), 0);
267 }
268
269 protected override void StoreFriendships(UUID agentID, UUID friendID)
270 {
271 UserAccount agentAccount = UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, agentID);
272 UserAccount friendAccount = UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, friendID);
273 // Are they both local users?
274 if (agentAccount != null && friendAccount != null)
275 {
276 // local grid users
277 m_log.DebugFormat("[HGFRIENDS MODULE]: Users are both local");
278 base.StoreFriendships(agentID, friendID);
279 return;
280 }
281
282
283 // ok, at least one of them is foreigner, let's get their data
284 IClientAPI agentClient = LocateClientObject(agentID);
285 IClientAPI friendClient = LocateClientObject(friendID);
286 AgentCircuitData agentClientCircuit = null;
287 AgentCircuitData friendClientCircuit = null;
288 string agentUUI = string.Empty;
289 string friendUUI = string.Empty;
290 string agentFriendService = string.Empty;
291 string friendFriendService = string.Empty;
292
293 if (agentClient != null)
294 {
295 agentClientCircuit = ((Scene)(agentClient.Scene)).AuthenticateHandler.GetAgentCircuitData(agentClient.CircuitCode);
296 agentUUI = Util.ProduceUserUniversalIdentifier(agentClientCircuit);
297 agentFriendService = agentClientCircuit.ServiceURLs["FriendsServerURI"].ToString();
298 }
299 if (friendClient != null)
300 {
301 friendClientCircuit = ((Scene)(friendClient.Scene)).AuthenticateHandler.GetAgentCircuitData(friendClient.CircuitCode);
302 friendUUI = Util.ProduceUserUniversalIdentifier(friendClientCircuit);
303 friendFriendService = friendClientCircuit.ServiceURLs["FriendsServerURI"].ToString();
304 }
305
306 m_log.DebugFormat("[XXX] HG Friendship! thisUUI={0}; friendUUI={1}; foreignThisFriendService={2}; foreignFriendFriendService={3}",
307 agentUUI, friendUUI, agentFriendService, friendFriendService);
308
309 if (agentAccount != null) // agent is local, 'friend' is foreigner
310 {
311 // This may happen when the agent returned home, in which case the friend is not there
312 // We need to llok for its information in the friends list itself
313 if (friendUUI == string.Empty)
314 {
315 FriendInfo[] finfos = GetFriends(agentID);
316 foreach (FriendInfo finfo in finfos)
317 {
318 if (finfo.TheirFlags == -1)
319 {
320 if (finfo.Friend.StartsWith(friendID.ToString()))
321 friendUUI = finfo.Friend;
322 }
323 }
324 }
325
326 // store in the local friends service a reference to the foreign friend
327 FriendsService.StoreFriend(agentID.ToString(), friendUUI, 1);
328 // and also the converse
329 FriendsService.StoreFriend(friendUUI, agentID.ToString(), 1);
330
331 if (friendClientCircuit != null)
332 {
333 // store in the foreign friends service a reference to the local agent
334 HGFriendsServicesConnector friendsConn = new HGFriendsServicesConnector(friendFriendService, friendClientCircuit.SessionID, friendClientCircuit.ServiceSessionID);
335 friendsConn.NewFriendship(friendID, agentUUI);
336 }
337 }
338 else if (friendAccount != null) // 'friend' is local, agent is foreigner
339 {
340 // store in the local friends service a reference to the foreign agent
341 FriendsService.StoreFriend(friendID.ToString(), agentUUI, 1);
342 // and also the converse
343 FriendsService.StoreFriend(agentUUI, friendID.ToString(), 1);
344
345 if (agentClientCircuit != null)
346 {
347 // store in the foreign friends service a reference to the local agent
348 HGFriendsServicesConnector friendsConn = new HGFriendsServicesConnector(agentFriendService, agentClientCircuit.SessionID, agentClientCircuit.ServiceSessionID);
349 friendsConn.NewFriendship(agentID, friendUUI);
350 }
351 }
352 else // They're both foreigners!
353 {
354 HGFriendsServicesConnector friendsConn;
355 if (agentClientCircuit != null)
356 {
357 friendsConn = new HGFriendsServicesConnector(agentFriendService, agentClientCircuit.SessionID, agentClientCircuit.ServiceSessionID);
358 friendsConn.NewFriendship(agentID, friendUUI);
359 }
360 if (friendClientCircuit != null)
361 {
362 friendsConn = new HGFriendsServicesConnector(friendFriendService, friendClientCircuit.SessionID, friendClientCircuit.ServiceSessionID);
363 friendsConn.NewFriendship(friendID, agentUUI);
364 }
365 }
366 // my brain hurts now
367 }
368
369 protected override void DeleteFriendship(UUID agentID, UUID exfriendID)
370 {
371 base.DeleteFriendship(agentID, exfriendID);
372 // Maybe some of the base deletes will fail.
373 // Let's delete the local friendship with foreign friend
374 FriendInfo[] friends = GetFriends(agentID);
375 foreach (FriendInfo finfo in friends)
376 {
377 if (finfo.Friend != exfriendID.ToString() && finfo.Friend.EndsWith(exfriendID.ToString()))
378 {
379 FriendsService.Delete(agentID, exfriendID.ToString());
380 // TODO: delete the friendship on the other side
381 // Should use the homeurl given in finfo.Friend
382 }
383 }
384 }
385
386 //private void OnGrantUserRights(IClientAPI remoteClient, UUID requester, UUID target, int rights)
387 //{
388 // FriendInfo[] friends = GetFriends(remoteClient.AgentId);
389 // if (friends.Length == 0)
390 // return;
391
392 // m_log.DebugFormat("[FRIENDS MODULE]: User {0} changing rights to {1} for friend {2}", requester, rights, target);
393 // // Let's find the friend in this user's friend list
394 // FriendInfo friend = null;
395 // foreach (FriendInfo fi in friends)
396 // {
397 // if (fi.Friend == target.ToString())
398 // friend = fi;
399 // }
400
401 // if (friend != null) // Found it
402 // {
403 // // Store it on the DB
404 // FriendsService.StoreFriend(requester, target.ToString(), rights);
405
406 // // Store it in the local cache
407 // int myFlags = friend.MyFlags;
408 // friend.MyFlags = rights;
409
410 // // Always send this back to the original client
411 // remoteClient.SendChangeUserRights(requester, target, rights);
412
413 // //
414 // // Notify the friend
415 // //
416
417 // // Try local
418 // if (LocalGrantRights(requester, target, myFlags, rights))
419 // return;
420
421 // PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { target.ToString() });
422 // if (friendSessions != null && friendSessions.Length > 0)
423 // {
424 // PresenceInfo friendSession = friendSessions[0];
425 // if (friendSession != null)
426 // {
427 // GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID);
428 // // TODO: You might want to send the delta to save the lookup
429 // // on the other end!!
430 // m_FriendsSimConnector.GrantRights(region, requester, target, myFlags, rights);
431 // }
432 // }
433 // }
434 //}
435
436
437 }
438}