aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Hypergrid
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Server/Handlers/Hypergrid/HGFriendServerConnector.cs26
-rw-r--r--OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs204
-rw-r--r--OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs38
3 files changed, 214 insertions, 54 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..8ef03e7 100644
--- a/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs
@@ -39,6 +39,7 @@ using System.Collections.Generic;
39using OpenSim.Server.Base; 39using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces; 40using OpenSim.Services.Interfaces;
41using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; 41using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
42using GridRegion = OpenSim.Services.Interfaces.GridRegion;
42using OpenSim.Framework; 43using OpenSim.Framework;
43using OpenSim.Framework.Servers.HttpServer; 44using OpenSim.Framework.Servers.HttpServer;
44using OpenMetaverse; 45using 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,29 @@ 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 "statusnotification":
110 return StatusNotification(request);
111 /*
112 case "friendship_approved":
113 return FriendshipApproved(request);
114
115 case "friendship_denied":
116 return FriendshipDenied(request);
117
118 case "friendship_terminated":
119 return FriendshipTerminated(request);
120
121 case "grant_rights":
122 return GrantRights(request);
123 */
93 } 124 }
94 m_log.DebugFormat("[HGFRIENDS HANDLER]: unknown method {0} request {1}", method.Length, method); 125 m_log.DebugFormat("[HGFRIENDS HANDLER]: unknown method {0} request {1}", method.Length, method);
95 } 126 }
@@ -126,39 +157,20 @@ namespace OpenSim.Server.Handlers.Hypergrid
126 return FailureResult(); 157 return FailureResult();
127 } 158 }
128 159
129 FriendInfo[] friendsInfo = m_FriendsService.GetFriends(principalID); 160 int perms = m_TheService.GetFriendPerms(principalID, friendID);
130 foreach (FriendInfo finfo in friendsInfo) 161 if (perms < 0)
131 { 162 return FailureResult("Friend not found");
132 if (finfo.Friend.StartsWith(friendID.ToString()))
133 return SuccessResult(finfo.TheirFlags.ToString());
134 }
135 163
136 return FailureResult("Friend not found"); 164 return SuccessResult(perms.ToString());
137 } 165 }
138 166
139 byte[] NewFriendship(Dictionary<string, object> request) 167 byte[] NewFriendship(Dictionary<string, object> request)
140 { 168 {
141 if (!VerifyServiceKey(request)) 169 bool verified = VerifyServiceKey(request);
142 return FailureResult();
143 170
144 // OK, can proceed
145 FriendInfo friend = new FriendInfo(request); 171 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
151
152 m_log.DebugFormat("[HGFRIENDS HANDLER]: New friendship {0} {1}", friend.PrincipalID, friend.Friend);
153 172
154 // If the friendship already exists, return fail 173 bool success = m_TheService.NewFriendship(friend, verified);
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 174
163 if (success) 175 if (success)
164 return SuccessResult(); 176 return SuccessResult();
@@ -174,25 +186,105 @@ namespace OpenSim.Server.Handlers.Hypergrid
174 secret = request["SECRET"].ToString(); 186 secret = request["SECRET"].ToString();
175 187
176 if (secret == string.Empty) 188 if (secret == string.Empty)
189 return BoolResult(false);
190
191 bool success = m_TheService.DeleteFriendship(friend, secret);
192
193 return BoolResult(success);
194 }
195
196 byte[] FriendshipOffered(Dictionary<string, object> request)
197 {
198 UUID fromID = UUID.Zero;
199 UUID toID = UUID.Zero;
200 string message = string.Empty;
201 string name = string.Empty;
202
203 if (!request.ContainsKey("FromID") || !request.ContainsKey("ToID"))
204 return BoolResult(false);
205
206 if (!UUID.TryParse(request["ToID"].ToString(), out toID))
207 return BoolResult(false);
208
209 message = request["Message"].ToString();
210
211 if (!UUID.TryParse(request["FromID"].ToString(), out fromID))
212 return BoolResult(false);
213
214 if (request.ContainsKey("FromName"))
215 name = request["FromName"].ToString();
216
217 bool success = m_TheService.FriendshipOffered(fromID, name, toID, message);
218
219 return BoolResult(success);
220 }
221
222 byte[] ValidateFriendshipOffered(Dictionary<string, object> request)
223 {
224 FriendInfo friend = new FriendInfo(request);
225 UUID friendID = UUID.Zero;
226 if (!UUID.TryParse(friend.Friend, out friendID))
227 return BoolResult(false);
228
229 bool success = m_TheService.ValidateFriendshipOffered(friend.PrincipalID, friendID);
230
231 return BoolResult(success);
232 }
233
234 byte[] StatusNotification(Dictionary<string, object> request)
235 {
236 UUID principalID = UUID.Zero;
237 if (request.ContainsKey("userID"))
238 UUID.TryParse(request["userID"].ToString(), out principalID);
239 else
240 {
241 m_log.WarnFormat("[HGFRIENDS HANDLER]: no userID in request to notify");
242 return FailureResult();
243 }
244
245 bool online = true;
246 if (request.ContainsKey("online"))
247 Boolean.TryParse(request["online"].ToString(), out online);
248 else
249 {
250 m_log.WarnFormat("[HGFRIENDS HANDLER]: no online in request to notify");
177 return FailureResult(); 251 return FailureResult();
252 }
178 253
179 FriendInfo[] finfos = m_FriendsService.GetFriends(friend.PrincipalID); 254 List<string> friends = new List<string>();
180 foreach (FriendInfo finfo in finfos) 255 int i = 0;
256 foreach (KeyValuePair<string, object> kvp in request)
181 { 257 {
182 // We check the secret here 258 if (kvp.Key.Equals("friend_" + i.ToString()))
183 if (finfo.Friend.StartsWith(friend.Friend) && finfo.Friend.EndsWith(secret))
184 { 259 {
185 m_log.DebugFormat("[HGFRIENDS HANDLER]: Delete friendship {0} {1}", friend.PrincipalID, friend.Friend); 260 friends.Add(kvp.Value.ToString());
186 m_FriendsService.Delete(friend.PrincipalID, finfo.Friend); 261 i++;
187 m_FriendsService.Delete(finfo.Friend, friend.PrincipalID.ToString()); 262 }
263 }
264
265 List<UUID> onlineFriends = m_TheService.StatusNotification(friends, principalID, online);
188 266
189 return SuccessResult(); 267 Dictionary<string, object> result = new Dictionary<string, object>();
268 if ((onlineFriends == null) || ((onlineFriends != null) && (onlineFriends.Count == 0)))
269 result["RESULT"] = "NULL";
270 else
271 {
272 i = 0;
273 foreach (UUID f in onlineFriends)
274 {
275 result["friend_" + i] = f.ToString();
276 i++;
190 } 277 }
191 } 278 }
192 279
193 return FailureResult(); 280 string xmlString = ServerUtils.BuildXmlResponse(result);
281 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
282 UTF8Encoding encoding = new UTF8Encoding();
283 return encoding.GetBytes(xmlString);
284
194 } 285 }
195 286
287
196 #endregion 288 #endregion
197 289
198 #region Misc 290 #region Misc
@@ -205,10 +297,15 @@ namespace OpenSim.Server.Handlers.Hypergrid
205 return false; 297 return false;
206 } 298 }
207 299
300 if (request["KEY"] == null || request["SESSIONID"] == null)
301 return false;
302
208 string serviceKey = request["KEY"].ToString(); 303 string serviceKey = request["KEY"].ToString();
209 string sessionStr = request["SESSIONID"].ToString(); 304 string sessionStr = request["SESSIONID"].ToString();
305
210 UUID sessionID; 306 UUID sessionID;
211 UUID.TryParse(sessionStr, out sessionID); 307 if (!UUID.TryParse(sessionStr, out sessionID) || serviceKey == string.Empty)
308 return false;
212 309
213 if (!m_UserAgentService.VerifyAgent(sessionID, serviceKey)) 310 if (!m_UserAgentService.VerifyAgent(sessionID, serviceKey))
214 { 311 {
@@ -256,7 +353,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
256 353
257 doc.AppendChild(rootElement); 354 doc.AppendChild(rootElement);
258 355
259 XmlElement result = doc.CreateElement("", "Result", ""); 356 XmlElement result = doc.CreateElement("", "RESULT", "");
260 result.AppendChild(doc.CreateTextNode("Success")); 357 result.AppendChild(doc.CreateTextNode("Success"));
261 358
262 rootElement.AppendChild(result); 359 rootElement.AppendChild(result);
@@ -289,7 +386,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
289 386
290 doc.AppendChild(rootElement); 387 doc.AppendChild(rootElement);
291 388
292 XmlElement result = doc.CreateElement("", "Result", ""); 389 XmlElement result = doc.CreateElement("", "RESULT", "");
293 result.AppendChild(doc.CreateTextNode("Failure")); 390 result.AppendChild(doc.CreateTextNode("Failure"));
294 391
295 rootElement.AppendChild(result); 392 rootElement.AppendChild(result);
@@ -302,6 +399,28 @@ namespace OpenSim.Server.Handlers.Hypergrid
302 return DocToBytes(doc); 399 return DocToBytes(doc);
303 } 400 }
304 401
402 private byte[] BoolResult(bool value)
403 {
404 XmlDocument doc = new XmlDocument();
405
406 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
407 "", "");
408
409 doc.AppendChild(xmlnode);
410
411 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
412 "");
413
414 doc.AppendChild(rootElement);
415
416 XmlElement result = doc.CreateElement("", "RESULT", "");
417 result.AppendChild(doc.CreateTextNode(value.ToString()));
418
419 rootElement.AppendChild(result);
420
421 return DocToBytes(doc);
422 }
423
305 private byte[] DocToBytes(XmlDocument doc) 424 private byte[] DocToBytes(XmlDocument doc)
306 { 425 {
307 MemoryStream ms = new MemoryStream(); 426 MemoryStream ms = new MemoryStream();
@@ -313,6 +432,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
313 return ms.ToArray(); 432 return ms.ToArray();
314 } 433 }
315 434
435
316 #endregion 436 #endregion
317 } 437 }
318} 438}
diff --git a/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs
index 1bd3706..db62aaa 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;
@@ -96,6 +101,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
96 101
97 server.AddXmlRPCHandler("locate_user", LocateUser, false); 102 server.AddXmlRPCHandler("locate_user", LocateUser, false);
98 server.AddXmlRPCHandler("get_uui", GetUUI, false); 103 server.AddXmlRPCHandler("get_uui", GetUUI, false);
104 server.AddXmlRPCHandler("get_uuid", GetUUID, false);
99 105
100 server.AddHTTPHandler("/homeagent/", new HomeAgentHandler(m_HomeUsersService, loginServerIP, proxy).Handler); 106 server.AddHTTPHandler("/homeagent/", new HomeAgentHandler(m_HomeUsersService, loginServerIP, proxy).Handler);
101 } 107 }
@@ -216,6 +222,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
216 222
217 } 223 }
218 224
225 [Obsolete]
219 public XmlRpcResponse StatusNotification(XmlRpcRequest request, IPEndPoint remoteClient) 226 public XmlRpcResponse StatusNotification(XmlRpcRequest request, IPEndPoint remoteClient)
220 { 227 {
221 Hashtable hash = new Hashtable(); 228 Hashtable hash = new Hashtable();
@@ -410,8 +417,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
410 } 417 }
411 418
412 /// <summary> 419 /// <summary>
413 /// Locates the user. 420 /// Returns the UUI of a user given a UUID.
414 /// This is a sensitive operation, only authorized IP addresses can perform it.
415 /// </summary> 421 /// </summary>
416 /// <param name="request"></param> 422 /// <param name="request"></param>
417 /// <param name="remoteClient"></param> 423 /// <param name="remoteClient"></param>
@@ -445,5 +451,33 @@ namespace OpenSim.Server.Handlers.Hypergrid
445 451
446 } 452 }
447 453
454 /// <summary>
455 /// Gets the UUID of a user given First name, Last name.
456 /// </summary>
457 /// <param name="request"></param>
458 /// <param name="remoteClient"></param>
459 /// <returns></returns>
460 public XmlRpcResponse GetUUID(XmlRpcRequest request, IPEndPoint remoteClient)
461 {
462 Hashtable hash = new Hashtable();
463
464 Hashtable requestData = (Hashtable)request.Params[0];
465 //string host = (string)requestData["host"];
466 //string portstr = (string)requestData["port"];
467 if (requestData.ContainsKey("first") && requestData.ContainsKey("last"))
468 {
469 UUID userID = UUID.Zero;
470 string first = (string)requestData["first"];
471
472 string last = (string)requestData["last"];
473 UUID uuid = m_HomeUsersService.GetUUID(first, last);
474 hash["UUID"] = uuid.ToString();
475 }
476
477 XmlRpcResponse response = new XmlRpcResponse();
478 response.Value = hash;
479 return response;
480
481 }
448 } 482 }
449} 483}