diff options
Merge branch 'master' of ssh://opensimulator.org/var/git/opensim
Diffstat (limited to 'OpenSim/Region/CoreModules')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/UserProfiles/OpenProfileClient.cs | 193 | ||||
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs | 68 |
2 files changed, 38 insertions, 223 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/UserProfiles/OpenProfileClient.cs b/OpenSim/Region/CoreModules/Avatar/UserProfiles/OpenProfileClient.cs deleted file mode 100644 index 23de3f5..0000000 --- a/OpenSim/Region/CoreModules/Avatar/UserProfiles/OpenProfileClient.cs +++ /dev/null | |||
@@ -1,193 +0,0 @@ | |||
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 System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Linq; | ||
32 | using System.Net; | ||
33 | using System.Net.Sockets; | ||
34 | using System.Reflection; | ||
35 | using System.Text; | ||
36 | using System.Xml; | ||
37 | using log4net; | ||
38 | using Nwc.XmlRpc; | ||
39 | using OpenMetaverse; | ||
40 | using OpenSim.Framework; | ||
41 | |||
42 | namespace OpenSim.Region.CoreModules.Avatar.UserProfiles | ||
43 | { | ||
44 | /// <summary> | ||
45 | /// A client for accessing a profile server using the OpenProfile protocol. | ||
46 | /// </summary> | ||
47 | /// <remarks> | ||
48 | /// This class was adapted from the full OpenProfile class. Since it's only a client, and not a server, | ||
49 | /// it's much simpler. | ||
50 | /// </remarks> | ||
51 | public class OpenProfileClient | ||
52 | { | ||
53 | static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
54 | |||
55 | private string m_serverURI; | ||
56 | |||
57 | /// <summary> | ||
58 | /// Creates a client for accessing a foreign grid's profile server using the OpenProfile protocol. | ||
59 | /// </summary> | ||
60 | /// <param name="serverURI">The grid's profile server URL</param> | ||
61 | public OpenProfileClient(string serverURI) | ||
62 | { | ||
63 | m_serverURI = serverURI; | ||
64 | } | ||
65 | |||
66 | |||
67 | /// <summary> | ||
68 | /// Gets an avatar's profile using the OpenProfile protocol. | ||
69 | /// </summary> | ||
70 | /// <param name="props">On success, this will contain the avatar's profile</param> | ||
71 | /// <returns>Success/failure</returns> | ||
72 | /// <remarks> | ||
73 | /// There are two profile modules currently in use in OpenSim: the older one is OpenProfile, and the newer | ||
74 | /// one is UserProfileModule (this file). This method attempts to read an avatar's profile from a foreign | ||
75 | /// grid using the OpenProfile protocol. | ||
76 | /// </remarks> | ||
77 | public bool RequestAvatarPropertiesUsingOpenProfile(ref UserProfileProperties props) | ||
78 | { | ||
79 | Hashtable ReqHash = new Hashtable(); | ||
80 | ReqHash["avatar_id"] = props.UserId.ToString(); | ||
81 | |||
82 | Hashtable profileData = GenericXMLRPCRequest(ReqHash, "avatar_properties_request", m_serverURI); | ||
83 | |||
84 | ArrayList dataArray = (ArrayList)profileData["data"]; | ||
85 | |||
86 | if (dataArray == null || dataArray[0] == null) | ||
87 | return false; | ||
88 | profileData = (Hashtable)dataArray[0]; | ||
89 | |||
90 | props.WebUrl = string.Empty; | ||
91 | props.AboutText = String.Empty; | ||
92 | props.FirstLifeText = String.Empty; | ||
93 | props.ImageId = UUID.Zero; | ||
94 | props.FirstLifeImageId = UUID.Zero; | ||
95 | props.PartnerId = UUID.Zero; | ||
96 | |||
97 | if (profileData["ProfileUrl"] != null) | ||
98 | props.WebUrl = profileData["ProfileUrl"].ToString(); | ||
99 | if (profileData["AboutText"] != null) | ||
100 | props.AboutText = profileData["AboutText"].ToString(); | ||
101 | if (profileData["FirstLifeAboutText"] != null) | ||
102 | props.FirstLifeText = profileData["FirstLifeAboutText"].ToString(); | ||
103 | if (profileData["Image"] != null) | ||
104 | props.ImageId = new UUID(profileData["Image"].ToString()); | ||
105 | if (profileData["FirstLifeImage"] != null) | ||
106 | props.FirstLifeImageId = new UUID(profileData["FirstLifeImage"].ToString()); | ||
107 | if (profileData["Partner"] != null) | ||
108 | props.PartnerId = new UUID(profileData["Partner"].ToString()); | ||
109 | |||
110 | props.WantToMask = 0; | ||
111 | props.WantToText = String.Empty; | ||
112 | props.SkillsMask = 0; | ||
113 | props.SkillsText = String.Empty; | ||
114 | props.Language = String.Empty; | ||
115 | |||
116 | if (profileData["wantmask"] != null) | ||
117 | props.WantToMask = Convert.ToInt32(profileData["wantmask"].ToString()); | ||
118 | if (profileData["wanttext"] != null) | ||
119 | props.WantToText = profileData["wanttext"].ToString(); | ||
120 | |||
121 | if (profileData["skillsmask"] != null) | ||
122 | props.SkillsMask = Convert.ToInt32(profileData["skillsmask"].ToString()); | ||
123 | if (profileData["skillstext"] != null) | ||
124 | props.SkillsText = profileData["skillstext"].ToString(); | ||
125 | |||
126 | if (profileData["languages"] != null) | ||
127 | props.Language = profileData["languages"].ToString(); | ||
128 | |||
129 | return true; | ||
130 | } | ||
131 | |||
132 | private Hashtable GenericXMLRPCRequest(Hashtable ReqParams, string method, string server) | ||
133 | { | ||
134 | ArrayList SendParams = new ArrayList(); | ||
135 | SendParams.Add(ReqParams); | ||
136 | |||
137 | XmlRpcResponse Resp; | ||
138 | try | ||
139 | { | ||
140 | XmlRpcRequest Req = new XmlRpcRequest(method, SendParams); | ||
141 | Resp = Req.Send(server, 30000); | ||
142 | } | ||
143 | catch (WebException ex) | ||
144 | { | ||
145 | m_log.ErrorFormat("[PROFILE]: Unable to connect to Profile " + | ||
146 | "Server {0}. Exception {1}", server, ex); | ||
147 | |||
148 | Hashtable ErrorHash = new Hashtable(); | ||
149 | ErrorHash["success"] = false; | ||
150 | ErrorHash["errorMessage"] = "Unable to fetch profile data at this time. "; | ||
151 | ErrorHash["errorURI"] = ""; | ||
152 | |||
153 | return ErrorHash; | ||
154 | } | ||
155 | catch (SocketException ex) | ||
156 | { | ||
157 | m_log.ErrorFormat( | ||
158 | "[PROFILE]: Unable to connect to Profile Server {0}. Method {1}, params {2}. " + | ||
159 | "Exception {3}", server, method, ReqParams, ex); | ||
160 | |||
161 | Hashtable ErrorHash = new Hashtable(); | ||
162 | ErrorHash["success"] = false; | ||
163 | ErrorHash["errorMessage"] = "Unable to fetch profile data at this time. "; | ||
164 | ErrorHash["errorURI"] = ""; | ||
165 | |||
166 | return ErrorHash; | ||
167 | } | ||
168 | catch (XmlException ex) | ||
169 | { | ||
170 | m_log.ErrorFormat( | ||
171 | "[PROFILE]: Unable to connect to Profile Server {0}. Method {1}, params {2}. " + | ||
172 | "Exception {3}", server, method, ReqParams.ToString(), ex); | ||
173 | Hashtable ErrorHash = new Hashtable(); | ||
174 | ErrorHash["success"] = false; | ||
175 | ErrorHash["errorMessage"] = "Unable to fetch profile data at this time. "; | ||
176 | ErrorHash["errorURI"] = ""; | ||
177 | |||
178 | return ErrorHash; | ||
179 | } | ||
180 | if (Resp.IsFault) | ||
181 | { | ||
182 | Hashtable ErrorHash = new Hashtable(); | ||
183 | ErrorHash["success"] = false; | ||
184 | ErrorHash["errorMessage"] = "Unable to fetch profile data at this time. "; | ||
185 | ErrorHash["errorURI"] = ""; | ||
186 | return ErrorHash; | ||
187 | } | ||
188 | Hashtable RespData = (Hashtable)Resp.Value; | ||
189 | |||
190 | return RespData; | ||
191 | } | ||
192 | } | ||
193 | } | ||
diff --git a/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs b/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs index d05b1f6..1ee2a7b 100644 --- a/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs | |||
@@ -47,6 +47,7 @@ using OpenSim.Services.Interfaces; | |||
47 | using Mono.Addins; | 47 | using Mono.Addins; |
48 | using OpenSim.Services.Connectors.Hypergrid; | 48 | using OpenSim.Services.Connectors.Hypergrid; |
49 | using OpenSim.Framework.Servers.HttpServer; | 49 | using OpenSim.Framework.Servers.HttpServer; |
50 | using OpenSim.Services.UserProfilesService; | ||
50 | 51 | ||
51 | namespace OpenSim.Region.CoreModules.Avatar.UserProfiles | 52 | namespace OpenSim.Region.CoreModules.Avatar.UserProfiles |
52 | { | 53 | { |
@@ -64,6 +65,8 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles | |||
64 | Dictionary<UUID, UUID> m_classifiedCache = new Dictionary<UUID, UUID>(); | 65 | Dictionary<UUID, UUID> m_classifiedCache = new Dictionary<UUID, UUID>(); |
65 | Dictionary<UUID, int> m_classifiedInterest = new Dictionary<UUID, int>(); | 66 | Dictionary<UUID, int> m_classifiedInterest = new Dictionary<UUID, int>(); |
66 | 67 | ||
68 | private JsonRpcRequestManager rpc = new JsonRpcRequestManager(); | ||
69 | |||
67 | public Scene Scene | 70 | public Scene Scene |
68 | { | 71 | { |
69 | get; private set; | 72 | get; private set; |
@@ -113,7 +116,6 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles | |||
113 | set; | 116 | set; |
114 | } | 117 | } |
115 | 118 | ||
116 | JsonRpcRequestManager rpc = new JsonRpcRequestManager(); | ||
117 | 119 | ||
118 | #region IRegionModuleBase implementation | 120 | #region IRegionModuleBase implementation |
119 | /// <summary> | 121 | /// <summary> |
@@ -919,7 +921,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles | |||
919 | 921 | ||
920 | public void RequestAvatarProperties(IClientAPI remoteClient, UUID avatarID) | 922 | public void RequestAvatarProperties(IClientAPI remoteClient, UUID avatarID) |
921 | { | 923 | { |
922 | if ( String.IsNullOrEmpty(avatarID.ToString()) || String.IsNullOrEmpty(remoteClient.AgentId.ToString())) | 924 | if (String.IsNullOrEmpty(avatarID.ToString()) || String.IsNullOrEmpty(remoteClient.AgentId.ToString())) |
923 | { | 925 | { |
924 | // Looking for a reason that some viewers are sending null Id's | 926 | // Looking for a reason that some viewers are sending null Id's |
925 | m_log.DebugFormat("[PROFILES]: This should not happen remoteClient.AgentId {0} - avatarID {1}", remoteClient.AgentId, avatarID); | 927 | m_log.DebugFormat("[PROFILES]: This should not happen remoteClient.AgentId {0} - avatarID {1}", remoteClient.AgentId, avatarID); |
@@ -997,29 +999,10 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles | |||
997 | 999 | ||
998 | props.UserId = avatarID; | 1000 | props.UserId = avatarID; |
999 | 1001 | ||
1000 | try | 1002 | if (!GetProfileData(ref props, foreign, out result)) |
1001 | { | ||
1002 | GetProfileData(ref props, out result); | ||
1003 | } | ||
1004 | catch (Exception e) | ||
1005 | { | 1003 | { |
1006 | if (foreign) | 1004 | m_log.DebugFormat("Error getting profile for {0}: {1}", avatarID, result); |
1007 | { | 1005 | return; |
1008 | // Check if the foreign grid is using OpenProfile. | ||
1009 | // If any error occurs then discard it, and report the original error. | ||
1010 | try | ||
1011 | { | ||
1012 | OpenProfileClient client = new OpenProfileClient(serverURI); | ||
1013 | if (!client.RequestAvatarPropertiesUsingOpenProfile(ref props)) | ||
1014 | throw e; | ||
1015 | } | ||
1016 | catch (Exception) | ||
1017 | { | ||
1018 | throw e; | ||
1019 | } | ||
1020 | } | ||
1021 | else | ||
1022 | throw; | ||
1023 | } | 1006 | } |
1024 | 1007 | ||
1025 | remoteClient.SendAvatarProperties(props.UserId, props.AboutText, born, charterMember , props.FirstLifeText, flags, | 1008 | remoteClient.SendAvatarProperties(props.UserId, props.AboutText, born, charterMember , props.FirstLifeText, flags, |
@@ -1073,10 +1056,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles | |||
1073 | /// <returns> | 1056 | /// <returns> |
1074 | /// The profile data. | 1057 | /// The profile data. |
1075 | /// </returns> | 1058 | /// </returns> |
1076 | /// <param name='userID'> | 1059 | bool GetProfileData(ref UserProfileProperties properties, bool foreign, out string message) |
1077 | /// User I. | ||
1078 | /// </param> | ||
1079 | bool GetProfileData(ref UserProfileProperties properties, out string message) | ||
1080 | { | 1060 | { |
1081 | // Can't handle NPC yet... | 1061 | // Can't handle NPC yet... |
1082 | ScenePresence p = FindPresence(properties.UserId); | 1062 | ScenePresence p = FindPresence(properties.UserId); |
@@ -1095,14 +1075,42 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles | |||
1095 | 1075 | ||
1096 | // This is checking a friend on the home grid | 1076 | // This is checking a friend on the home grid |
1097 | // Not HG friend | 1077 | // Not HG friend |
1098 | if ( String.IsNullOrEmpty(serverURI)) | 1078 | if (String.IsNullOrEmpty(serverURI)) |
1099 | { | 1079 | { |
1100 | message = "No Presence - foreign friend"; | 1080 | message = "No Presence - foreign friend"; |
1101 | return false; | 1081 | return false; |
1102 | } | 1082 | } |
1103 | 1083 | ||
1104 | object Prop = (object)properties; | 1084 | object Prop = (object)properties; |
1105 | rpc.JsonRpcRequest(ref Prop, "avatar_properties_request", serverURI, UUID.Random().ToString()); | 1085 | if (!rpc.JsonRpcRequest(ref Prop, "avatar_properties_request", serverURI, UUID.Random().ToString())) |
1086 | { | ||
1087 | // If it's a foreign user then try again using OpenProfile, in case that's what the grid is using | ||
1088 | bool secondChanceSuccess = false; | ||
1089 | if (foreign) | ||
1090 | { | ||
1091 | try | ||
1092 | { | ||
1093 | OpenProfileClient client = new OpenProfileClient(serverURI); | ||
1094 | if (client.RequestAvatarPropertiesUsingOpenProfile(ref properties)) | ||
1095 | secondChanceSuccess = true; | ||
1096 | } | ||
1097 | catch (Exception e) | ||
1098 | { | ||
1099 | m_log.Debug(string.Format("Request using the OpenProfile API to {0} failed", serverURI), e); | ||
1100 | // Allow the return 'message' to say "JsonRpcRequest" and not "OpenProfile", because | ||
1101 | // the most likely reason that OpenProfile failed is that the remote server | ||
1102 | // doesn't support OpenProfile, and that's not very interesting. | ||
1103 | } | ||
1104 | } | ||
1105 | |||
1106 | if (!secondChanceSuccess) | ||
1107 | { | ||
1108 | message = string.Format("JsonRpcRequest to {0} failed", serverURI); | ||
1109 | return false; | ||
1110 | } | ||
1111 | // else, continue below | ||
1112 | } | ||
1113 | |||
1106 | properties = (UserProfileProperties)Prop; | 1114 | properties = (UserProfileProperties)Prop; |
1107 | 1115 | ||
1108 | message = "Success"; | 1116 | message = "Success"; |