diff options
Diffstat (limited to 'OpenSim/Server')
3 files changed, 133 insertions, 57 deletions
diff --git a/OpenSim/Server/Handlers/Hypergrid/HGFriendServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/HGFriendServerConnector.cs index 82a7220..6c79c60 100644 --- a/OpenSim/Server/Handlers/Hypergrid/HGFriendServerConnector.cs +++ b/OpenSim/Server/Handlers/Hypergrid/HGFriendServerConnector.cs | |||
@@ -36,36 +36,42 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
36 | { | 36 | { |
37 | public class HGFriendsServerConnector : ServiceConnector | 37 | public class HGFriendsServerConnector : ServiceConnector |
38 | { | 38 | { |
39 | private IFriendsService m_FriendsService; | ||
40 | private IUserAgentService m_UserAgentService; | 39 | private IUserAgentService m_UserAgentService; |
40 | private IHGFriendsService m_TheService; | ||
41 | private string m_ConfigName = "HGFriendsService"; | 41 | private string m_ConfigName = "HGFriendsService"; |
42 | 42 | ||
43 | // Called from Robust | ||
43 | public HGFriendsServerConnector(IConfigSource config, IHttpServer server, string configName) : | 44 | public HGFriendsServerConnector(IConfigSource config, IHttpServer server, string configName) : |
44 | base(config, server, configName) | 45 | this(config, server, configName, null) |
45 | { | 46 | { |
46 | if (configName != string.Empty) | 47 | |
48 | } | ||
49 | |||
50 | // Called from standalone configurations | ||
51 | public HGFriendsServerConnector(IConfigSource config, IHttpServer server, string configName, IFriendsSimConnector localConn) | ||
52 | : base(config, server, configName) | ||
53 | { | ||
54 | if (configName != string.Empty) | ||
47 | m_ConfigName = configName; | 55 | m_ConfigName = configName; |
48 | 56 | ||
57 | Object[] args = new Object[] { config, m_ConfigName, localConn }; | ||
58 | |||
49 | IConfig serverConfig = config.Configs[m_ConfigName]; | 59 | IConfig serverConfig = config.Configs[m_ConfigName]; |
50 | if (serverConfig == null) | 60 | if (serverConfig == null) |
51 | throw new Exception(String.Format("No section {0} in config file", m_ConfigName)); | 61 | throw new Exception(String.Format("No section {0} in config file", m_ConfigName)); |
52 | 62 | ||
53 | string theService = serverConfig.GetString("LocalServiceModule", | 63 | string theService = serverConfig.GetString("LocalServiceModule", |
54 | String.Empty); | 64 | String.Empty); |
55 | |||
56 | if (theService == String.Empty) | 65 | if (theService == String.Empty) |
57 | throw new Exception("No LocalServiceModule in config file"); | 66 | throw new Exception("No LocalServiceModule in config file"); |
58 | 67 | m_TheService = ServerUtils.LoadPlugin<IHGFriendsService>(theService, args); | |
59 | Object[] args = new Object[] { config }; | ||
60 | m_FriendsService = ServerUtils.LoadPlugin<IFriendsService>(theService, args); | ||
61 | 68 | ||
62 | theService = serverConfig.GetString("UserAgentService", string.Empty); | 69 | theService = serverConfig.GetString("UserAgentService", string.Empty); |
63 | if (theService == String.Empty) | 70 | if (theService == String.Empty) |
64 | throw new Exception("No UserAgentService in " + m_ConfigName); | 71 | throw new Exception("No UserAgentService in " + m_ConfigName); |
72 | m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(theService, new Object[] { config, localConn }); | ||
65 | 73 | ||
66 | m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(theService, args); | 74 | server.AddStreamHandler(new HGFriendsServerPostHandler(m_TheService, m_UserAgentService, localConn)); |
67 | |||
68 | server.AddStreamHandler(new HGFriendsServerPostHandler(m_FriendsService, m_UserAgentService)); | ||
69 | } | 75 | } |
70 | } | 76 | } |
71 | } | 77 | } |
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 | } |
diff --git a/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs index 7348368..9a0e27e 100644 --- a/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs +++ b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs | |||
@@ -52,6 +52,11 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
52 | // MethodBase.GetCurrentMethod().DeclaringType); | 52 | // MethodBase.GetCurrentMethod().DeclaringType); |
53 | 53 | ||
54 | private IUserAgentService m_HomeUsersService; | 54 | private IUserAgentService m_HomeUsersService; |
55 | public IUserAgentService HomeUsersService | ||
56 | { | ||
57 | get { return m_HomeUsersService; } | ||
58 | } | ||
59 | |||
55 | private string[] m_AuthorizedCallers; | 60 | private string[] m_AuthorizedCallers; |
56 | 61 | ||
57 | private bool m_VerifyCallers = false; | 62 | private bool m_VerifyCallers = false; |