diff options
author | Diva Canto | 2011-05-19 16:54:46 -0700 |
---|---|---|
committer | Diva Canto | 2011-05-19 16:54:46 -0700 |
commit | d21e9c755f004d8fe03b11bc57b810dbd401435a (patch) | |
tree | 1efd9e48308192d21ca73d8ff12d6a48c186077c /OpenSim/Services | |
parent | Accidentally committed too early (diff) | |
download | opensim-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 '')
7 files changed, 299 insertions, 11 deletions
diff --git a/OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs b/OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs index 861c475..52b80e1 100644 --- a/OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs +++ b/OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs | |||
@@ -38,7 +38,7 @@ using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; | |||
38 | using OpenSim.Server.Base; | 38 | using OpenSim.Server.Base; |
39 | using OpenMetaverse; | 39 | using OpenMetaverse; |
40 | 40 | ||
41 | namespace OpenSim.Services.Connectors | 41 | namespace OpenSim.Services.Connectors.Friends |
42 | { | 42 | { |
43 | public class FriendsServicesConnector : IFriendsService | 43 | public class FriendsServicesConnector : IFriendsService |
44 | { | 44 | { |
@@ -144,10 +144,17 @@ namespace OpenSim.Services.Connectors | |||
144 | 144 | ||
145 | } | 145 | } |
146 | 146 | ||
147 | public bool StoreFriend(UUID PrincipalID, string Friend, int flags) | 147 | public bool StoreFriend(string PrincipalID, string Friend, int flags) |
148 | { | 148 | { |
149 | FriendInfo finfo = new FriendInfo(); | 149 | FriendInfo finfo = new FriendInfo(); |
150 | finfo.PrincipalID = PrincipalID; | 150 | try |
151 | { | ||
152 | finfo.PrincipalID = new UUID(PrincipalID); | ||
153 | } | ||
154 | catch | ||
155 | { | ||
156 | return false; | ||
157 | } | ||
151 | finfo.Friend = Friend; | 158 | finfo.Friend = Friend; |
152 | finfo.MyFlags = flags; | 159 | finfo.MyFlags = flags; |
153 | 160 | ||
diff --git a/OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs new file mode 100644 index 0000000..76f5f19 --- /dev/null +++ b/OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs | |||
@@ -0,0 +1,175 @@ | |||
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.Services.Interfaces; | ||
36 | using OpenSim.Services.Connectors.Friends; | ||
37 | using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; | ||
38 | using OpenSim.Server.Base; | ||
39 | using OpenMetaverse; | ||
40 | |||
41 | namespace OpenSim.Services.Connectors.Hypergrid | ||
42 | { | ||
43 | public class HGFriendsServicesConnector | ||
44 | { | ||
45 | private static readonly ILog m_log = | ||
46 | LogManager.GetLogger( | ||
47 | MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | private string m_ServerURI = String.Empty; | ||
50 | private string m_ServiceKey = String.Empty; | ||
51 | private UUID m_SessionID; | ||
52 | |||
53 | public HGFriendsServicesConnector() | ||
54 | { | ||
55 | } | ||
56 | |||
57 | public HGFriendsServicesConnector(string serverURI, UUID sessionID, string serviceKey) | ||
58 | { | ||
59 | m_ServerURI = serverURI.TrimEnd('/'); | ||
60 | m_ServiceKey = serviceKey; | ||
61 | m_SessionID = sessionID; | ||
62 | } | ||
63 | |||
64 | #region IFriendsService | ||
65 | |||
66 | public FriendInfo[] GetFriends(UUID PrincipalID) | ||
67 | { | ||
68 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
69 | |||
70 | sendData["PRINCIPALID"] = PrincipalID.ToString(); | ||
71 | sendData["METHOD"] = "getfriends"; | ||
72 | sendData["KEY"] = m_ServiceKey; | ||
73 | sendData["SESSIONID"] = m_SessionID.ToString(); | ||
74 | |||
75 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
76 | |||
77 | try | ||
78 | { | ||
79 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
80 | m_ServerURI + "/hgfriends", | ||
81 | reqString); | ||
82 | if (reply != string.Empty) | ||
83 | { | ||
84 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
85 | |||
86 | if (replyData != null) | ||
87 | { | ||
88 | if (replyData.ContainsKey("result") && (replyData["result"].ToString().ToLower() == "null")) | ||
89 | { | ||
90 | return new FriendInfo[0]; | ||
91 | } | ||
92 | |||
93 | List<FriendInfo> finfos = new List<FriendInfo>(); | ||
94 | Dictionary<string, object>.ValueCollection finfosList = replyData.Values; | ||
95 | //m_log.DebugFormat("[FRIENDS CONNECTOR]: get neighbours returned {0} elements", rinfosList.Count); | ||
96 | foreach (object f in finfosList) | ||
97 | { | ||
98 | if (f is Dictionary<string, object>) | ||
99 | { | ||
100 | FriendInfo finfo = new FriendInfo((Dictionary<string, object>)f); | ||
101 | finfos.Add(finfo); | ||
102 | } | ||
103 | else | ||
104 | m_log.DebugFormat("[HGFRIENDS CONNECTOR]: GetFriends {0} received invalid response type {1}", | ||
105 | PrincipalID, f.GetType()); | ||
106 | } | ||
107 | |||
108 | // Success | ||
109 | return finfos.ToArray(); | ||
110 | } | ||
111 | |||
112 | else | ||
113 | m_log.DebugFormat("[HGFRIENDS CONNECTOR]: GetFriends {0} received null response", | ||
114 | PrincipalID); | ||
115 | |||
116 | } | ||
117 | } | ||
118 | catch (Exception e) | ||
119 | { | ||
120 | m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server: {0}", e.Message); | ||
121 | } | ||
122 | |||
123 | return new FriendInfo[0]; | ||
124 | |||
125 | } | ||
126 | |||
127 | public bool NewFriendship(UUID PrincipalID, string Friend) | ||
128 | { | ||
129 | FriendInfo finfo = new FriendInfo(); | ||
130 | finfo.PrincipalID = PrincipalID; | ||
131 | finfo.Friend = Friend; | ||
132 | |||
133 | Dictionary<string, object> sendData = finfo.ToKeyValuePairs(); | ||
134 | |||
135 | sendData["METHOD"] = "newfriendship"; | ||
136 | sendData["KEY"] = m_ServiceKey; | ||
137 | sendData["SESSIONID"] = m_SessionID.ToString(); | ||
138 | |||
139 | string reply = string.Empty; | ||
140 | try | ||
141 | { | ||
142 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
143 | m_ServerURI + "/hgfriends", | ||
144 | ServerUtils.BuildQueryString(sendData)); | ||
145 | } | ||
146 | catch (Exception e) | ||
147 | { | ||
148 | m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server: {0}", e.Message); | ||
149 | return false; | ||
150 | } | ||
151 | |||
152 | if (reply != string.Empty) | ||
153 | { | ||
154 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
155 | |||
156 | if ((replyData != null) && replyData.ContainsKey("Result") && (replyData["Result"] != null)) | ||
157 | { | ||
158 | bool success = false; | ||
159 | Boolean.TryParse(replyData["Result"].ToString(), out success); | ||
160 | return success; | ||
161 | } | ||
162 | else | ||
163 | m_log.DebugFormat("[HGFRIENDS CONNECTOR]: StoreFriend {0} {1} received null response", | ||
164 | PrincipalID, Friend); | ||
165 | } | ||
166 | else | ||
167 | m_log.DebugFormat("[HGFRIENDS CONNECTOR]: StoreFriend received null reply"); | ||
168 | |||
169 | return false; | ||
170 | |||
171 | } | ||
172 | |||
173 | #endregion | ||
174 | } | ||
175 | } \ No newline at end of file | ||
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianFriendsServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianFriendsServiceConnector.cs index 6f2d735..f61ab29 100644 --- a/OpenSim/Services/Connectors/SimianGrid/SimianFriendsServiceConnector.cs +++ b/OpenSim/Services/Connectors/SimianGrid/SimianFriendsServiceConnector.cs | |||
@@ -127,7 +127,7 @@ namespace OpenSim.Services.Connectors.SimianGrid | |||
127 | return array; | 127 | return array; |
128 | } | 128 | } |
129 | 129 | ||
130 | public bool StoreFriend(UUID principalID, string friend, int flags) | 130 | public bool StoreFriend(string principalID, string friend, int flags) |
131 | { | 131 | { |
132 | if (String.IsNullOrEmpty(m_serverUrl)) | 132 | if (String.IsNullOrEmpty(m_serverUrl)) |
133 | return true; | 133 | return true; |
diff --git a/OpenSim/Services/Friends/FriendsService.cs b/OpenSim/Services/Friends/FriendsService.cs index 3c64ecc..039dc0b 100644 --- a/OpenSim/Services/Friends/FriendsService.cs +++ b/OpenSim/Services/Friends/FriendsService.cs | |||
@@ -43,17 +43,16 @@ namespace OpenSim.Services.Friends | |||
43 | { | 43 | { |
44 | } | 44 | } |
45 | 45 | ||
46 | public FriendInfo[] GetFriends(UUID PrincipalID) | 46 | public virtual FriendInfo[] GetFriends(UUID PrincipalID) |
47 | { | 47 | { |
48 | FriendsData[] data = m_Database.GetFriends(PrincipalID); | 48 | FriendsData[] data = m_Database.GetFriends(PrincipalID); |
49 | |||
50 | List<FriendInfo> info = new List<FriendInfo>(); | 49 | List<FriendInfo> info = new List<FriendInfo>(); |
51 | 50 | ||
52 | foreach (FriendsData d in data) | 51 | foreach (FriendsData d in data) |
53 | { | 52 | { |
54 | FriendInfo i = new FriendInfo(); | 53 | FriendInfo i = new FriendInfo(); |
55 | 54 | ||
56 | i.PrincipalID = d.PrincipalID; | 55 | i.PrincipalID = new UUID(d.PrincipalID); |
57 | i.Friend = d.Friend; | 56 | i.Friend = d.Friend; |
58 | i.MyFlags = Convert.ToInt32(d.Data["Flags"]); | 57 | i.MyFlags = Convert.ToInt32(d.Data["Flags"]); |
59 | i.TheirFlags = Convert.ToInt32(d.Data["TheirFlags"]); | 58 | i.TheirFlags = Convert.ToInt32(d.Data["TheirFlags"]); |
@@ -64,7 +63,7 @@ namespace OpenSim.Services.Friends | |||
64 | return info.ToArray(); | 63 | return info.ToArray(); |
65 | } | 64 | } |
66 | 65 | ||
67 | public bool StoreFriend(UUID PrincipalID, string Friend, int flags) | 66 | public virtual bool StoreFriend(string PrincipalID, string Friend, int flags) |
68 | { | 67 | { |
69 | FriendsData d = new FriendsData(); | 68 | FriendsData d = new FriendsData(); |
70 | 69 | ||
@@ -76,7 +75,7 @@ namespace OpenSim.Services.Friends | |||
76 | return m_Database.Store(d); | 75 | return m_Database.Store(d); |
77 | } | 76 | } |
78 | 77 | ||
79 | public bool Delete(UUID PrincipalID, string Friend) | 78 | public virtual bool Delete(UUID PrincipalID, string Friend) |
80 | { | 79 | { |
81 | return m_Database.Delete(PrincipalID, Friend); | 80 | return m_Database.Delete(PrincipalID, Friend); |
82 | } | 81 | } |
diff --git a/OpenSim/Services/HypergridService/HGFriendsService.cs b/OpenSim/Services/HypergridService/HGFriendsService.cs new file mode 100644 index 0000000..fa4ec5d --- /dev/null +++ b/OpenSim/Services/HypergridService/HGFriendsService.cs | |||
@@ -0,0 +1,95 @@ | |||
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 OpenMetaverse; | ||
29 | using OpenSim.Framework; | ||
30 | using System; | ||
31 | using System.Collections.Generic; | ||
32 | using OpenSim.Services.Interfaces; | ||
33 | using OpenSim.Services.Friends; | ||
34 | using OpenSim.Data; | ||
35 | using Nini.Config; | ||
36 | using log4net; | ||
37 | using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; | ||
38 | |||
39 | namespace OpenSim.Services.HypergridService | ||
40 | { | ||
41 | public class HGFriendsService : FriendsService, IFriendsService | ||
42 | { | ||
43 | public HGFriendsService(IConfigSource config) : base(config) | ||
44 | { | ||
45 | } | ||
46 | |||
47 | /// <summary> | ||
48 | /// Overrides base. | ||
49 | /// Storing new friendships from the outside is a tricky, sensitive operation, and it | ||
50 | /// needs to be done under certain restrictions. | ||
51 | /// First of all, if the friendship already exists, this is a no-op. In other words, | ||
52 | /// we cannot change just the flags, it needs to be a new friendship. | ||
53 | /// Second, we store it as flags=0 always, independent of what the caller sends. The | ||
54 | /// owner of the friendship needs to confirm when it gets back home. | ||
55 | /// </summary> | ||
56 | /// <param name="PrincipalID"></param> | ||
57 | /// <param name="Friend"></param> | ||
58 | /// <param name="flags"></param> | ||
59 | /// <returns></returns> | ||
60 | public override bool StoreFriend(string PrincipalID, string Friend, int flags) | ||
61 | { | ||
62 | UUID userID; | ||
63 | if (UUID.TryParse(PrincipalID, out userID)) | ||
64 | { | ||
65 | FriendsData[] friendsData = m_Database.GetFriends(userID); | ||
66 | List<FriendsData> fList = new List<FriendsData>(friendsData); | ||
67 | if (fList.Find(delegate(FriendsData fdata) | ||
68 | { | ||
69 | return fdata.Friend == Friend; | ||
70 | }) != null) | ||
71 | return false; | ||
72 | } | ||
73 | |||
74 | FriendsData d = new FriendsData(); | ||
75 | d.PrincipalID = PrincipalID; | ||
76 | d.Friend = Friend; | ||
77 | d.Data = new Dictionary<string, string>(); | ||
78 | d.Data["Flags"] = "0"; | ||
79 | |||
80 | return m_Database.Store(d); | ||
81 | } | ||
82 | |||
83 | /// <summary> | ||
84 | /// Overrides base. Cannot delete friendships while away from home. | ||
85 | /// </summary> | ||
86 | /// <param name="PrincipalID"></param> | ||
87 | /// <param name="Friend"></param> | ||
88 | /// <returns></returns> | ||
89 | public override bool Delete(UUID PrincipalID, string Friend) | ||
90 | { | ||
91 | return false; | ||
92 | } | ||
93 | |||
94 | } | ||
95 | } | ||
diff --git a/OpenSim/Services/Interfaces/IFriendsService.cs b/OpenSim/Services/Interfaces/IFriendsService.cs index 0ddd5e5..05e85f2 100644 --- a/OpenSim/Services/Interfaces/IFriendsService.cs +++ b/OpenSim/Services/Interfaces/IFriendsService.cs | |||
@@ -74,7 +74,7 @@ namespace OpenSim.Services.Interfaces | |||
74 | public interface IFriendsService | 74 | public interface IFriendsService |
75 | { | 75 | { |
76 | FriendInfo[] GetFriends(UUID PrincipalID); | 76 | FriendInfo[] GetFriends(UUID PrincipalID); |
77 | bool StoreFriend(UUID PrincipalID, string Friend, int flags); | 77 | bool StoreFriend(string PrincipalID, string Friend, int flags); |
78 | bool Delete(UUID PrincipalID, string Friend); | 78 | bool Delete(UUID PrincipalID, string Friend); |
79 | } | 79 | } |
80 | } | 80 | } |
diff --git a/OpenSim/Services/LLLoginService/LLLoginResponse.cs b/OpenSim/Services/LLLoginService/LLLoginResponse.cs index ddc8855..4fac951 100644 --- a/OpenSim/Services/LLLoginService/LLLoginResponse.cs +++ b/OpenSim/Services/LLLoginService/LLLoginResponse.cs | |||
@@ -621,7 +621,19 @@ namespace OpenSim.Services.LLLoginService | |||
621 | if (finfo.TheirFlags == -1) | 621 | if (finfo.TheirFlags == -1) |
622 | continue; | 622 | continue; |
623 | LLLoginResponse.BuddyList.BuddyInfo buddyitem = new LLLoginResponse.BuddyList.BuddyInfo(finfo.Friend); | 623 | LLLoginResponse.BuddyList.BuddyInfo buddyitem = new LLLoginResponse.BuddyList.BuddyInfo(finfo.Friend); |
624 | buddyitem.BuddyID = finfo.Friend; | 624 | // finfo.Friend may not be a simple uuid |
625 | UUID friendID = UUID.Zero; | ||
626 | if (UUID.TryParse(finfo.Friend, out friendID)) | ||
627 | buddyitem.BuddyID = finfo.Friend; | ||
628 | else | ||
629 | { | ||
630 | string tmp; | ||
631 | if (Util.ParseUniversalUserIdentifier(finfo.Friend, out friendID, out tmp, out tmp, out tmp)) | ||
632 | buddyitem.BuddyID = friendID.ToString(); | ||
633 | else | ||
634 | // junk entry | ||
635 | continue; | ||
636 | } | ||
625 | buddyitem.BuddyRightsHave = (int)finfo.TheirFlags; | 637 | buddyitem.BuddyRightsHave = (int)finfo.TheirFlags; |
626 | buddyitem.BuddyRightsGiven = (int)finfo.MyFlags; | 638 | buddyitem.BuddyRightsGiven = (int)finfo.MyFlags; |
627 | buddylistreturn.AddNewBuddy(buddyitem); | 639 | buddylistreturn.AddNewBuddy(buddyitem); |