mirror of
https://github.com/opensim/opensim.git
synced 2026-08-05 08:55:56 +08:00
Merge branch 'master' into careminster
Conflicts: OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
This commit is contained in:
@@ -36,36 +36,42 @@ namespace OpenSim.Server.Handlers.Hypergrid
|
||||
{
|
||||
public class HGFriendsServerConnector : ServiceConnector
|
||||
{
|
||||
private IFriendsService m_FriendsService;
|
||||
private IUserAgentService m_UserAgentService;
|
||||
private IHGFriendsService m_TheService;
|
||||
private string m_ConfigName = "HGFriendsService";
|
||||
|
||||
// Called from Robust
|
||||
public HGFriendsServerConnector(IConfigSource config, IHttpServer server, string configName) :
|
||||
base(config, server, configName)
|
||||
this(config, server, configName, null)
|
||||
{
|
||||
if (configName != string.Empty)
|
||||
|
||||
}
|
||||
|
||||
// Called from standalone configurations
|
||||
public HGFriendsServerConnector(IConfigSource config, IHttpServer server, string configName, IFriendsSimConnector localConn)
|
||||
: base(config, server, configName)
|
||||
{
|
||||
if (configName != string.Empty)
|
||||
m_ConfigName = configName;
|
||||
|
||||
Object[] args = new Object[] { config, m_ConfigName, localConn };
|
||||
|
||||
IConfig serverConfig = config.Configs[m_ConfigName];
|
||||
if (serverConfig == null)
|
||||
throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
|
||||
|
||||
string theService = serverConfig.GetString("LocalServiceModule",
|
||||
String.Empty);
|
||||
|
||||
if (theService == String.Empty)
|
||||
throw new Exception("No LocalServiceModule in config file");
|
||||
|
||||
Object[] args = new Object[] { config };
|
||||
m_FriendsService = ServerUtils.LoadPlugin<IFriendsService>(theService, args);
|
||||
m_TheService = ServerUtils.LoadPlugin<IHGFriendsService>(theService, args);
|
||||
|
||||
theService = serverConfig.GetString("UserAgentService", string.Empty);
|
||||
if (theService == String.Empty)
|
||||
throw new Exception("No UserAgentService in " + m_ConfigName);
|
||||
m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(theService, new Object[] { config, localConn });
|
||||
|
||||
m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(theService, args);
|
||||
|
||||
server.AddStreamHandler(new HGFriendsServerPostHandler(m_FriendsService, m_UserAgentService));
|
||||
server.AddStreamHandler(new HGFriendsServerPostHandler(m_TheService, m_UserAgentService, localConn));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ using System.Collections.Generic;
|
||||
using OpenSim.Server.Base;
|
||||
using OpenSim.Services.Interfaces;
|
||||
using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
|
||||
using GridRegion = OpenSim.Services.Interfaces.GridRegion;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Servers.HttpServer;
|
||||
using OpenMetaverse;
|
||||
@@ -49,15 +50,22 @@ namespace OpenSim.Server.Handlers.Hypergrid
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private IFriendsService m_FriendsService;
|
||||
private IUserAgentService m_UserAgentService;
|
||||
private IFriendsSimConnector m_FriendsLocalSimConnector;
|
||||
private IHGFriendsService m_TheService;
|
||||
|
||||
public HGFriendsServerPostHandler(IFriendsService service, IUserAgentService uservice) :
|
||||
public HGFriendsServerPostHandler(IHGFriendsService service, IUserAgentService uas, IFriendsSimConnector friendsConn) :
|
||||
base("POST", "/hgfriends")
|
||||
{
|
||||
m_FriendsService = service;
|
||||
m_UserAgentService = uservice;
|
||||
m_log.DebugFormat("[HGFRIENDS HANDLER]: HGFriendsServerPostHandler is On");
|
||||
m_TheService = service;
|
||||
m_UserAgentService = uas;
|
||||
m_FriendsLocalSimConnector = friendsConn;
|
||||
|
||||
m_log.DebugFormat("[HGFRIENDS HANDLER]: HGFriendsServerPostHandler is On ({0})",
|
||||
(m_FriendsLocalSimConnector == null ? "robust" : "standalone"));
|
||||
|
||||
if (m_TheService == null)
|
||||
m_log.ErrorFormat("[HGFRIENDS HANDLER]: TheService is null!");
|
||||
}
|
||||
|
||||
public override byte[] Handle(string path, Stream requestData,
|
||||
@@ -90,6 +98,26 @@ namespace OpenSim.Server.Handlers.Hypergrid
|
||||
|
||||
case "deletefriendship":
|
||||
return DeleteFriendship(request);
|
||||
|
||||
/* Same as inter-sim */
|
||||
case "friendship_offered":
|
||||
return FriendshipOffered(request);
|
||||
|
||||
case "validate_friendship_offered":
|
||||
return ValidateFriendshipOffered(request);
|
||||
/*
|
||||
case "friendship_approved":
|
||||
return FriendshipApproved(request);
|
||||
|
||||
case "friendship_denied":
|
||||
return FriendshipDenied(request);
|
||||
|
||||
case "friendship_terminated":
|
||||
return FriendshipTerminated(request);
|
||||
|
||||
case "grant_rights":
|
||||
return GrantRights(request);
|
||||
*/
|
||||
}
|
||||
m_log.DebugFormat("[HGFRIENDS HANDLER]: unknown method {0} request {1}", method.Length, method);
|
||||
}
|
||||
@@ -126,39 +154,20 @@ namespace OpenSim.Server.Handlers.Hypergrid
|
||||
return FailureResult();
|
||||
}
|
||||
|
||||
FriendInfo[] friendsInfo = m_FriendsService.GetFriends(principalID);
|
||||
foreach (FriendInfo finfo in friendsInfo)
|
||||
{
|
||||
if (finfo.Friend.StartsWith(friendID.ToString()))
|
||||
return SuccessResult(finfo.TheirFlags.ToString());
|
||||
}
|
||||
int perms = m_TheService.GetFriendPerms(principalID, friendID);
|
||||
if (perms < 0)
|
||||
return FailureResult("Friend not found");
|
||||
|
||||
return FailureResult("Friend not found");
|
||||
return SuccessResult(perms.ToString());
|
||||
}
|
||||
|
||||
byte[] NewFriendship(Dictionary<string, object> request)
|
||||
{
|
||||
if (!VerifyServiceKey(request))
|
||||
return FailureResult();
|
||||
bool verified = VerifyServiceKey(request);
|
||||
|
||||
// OK, can proceed
|
||||
FriendInfo friend = new FriendInfo(request);
|
||||
UUID friendID;
|
||||
string tmp = string.Empty;
|
||||
if (!Util.ParseUniversalUserIdentifier(friend.Friend, out friendID, out tmp, out tmp, out tmp, out tmp))
|
||||
return FailureResult();
|
||||
|
||||
|
||||
m_log.DebugFormat("[HGFRIENDS HANDLER]: New friendship {0} {1}", friend.PrincipalID, friend.Friend);
|
||||
|
||||
// If the friendship already exists, return fail
|
||||
FriendInfo[] finfos = m_FriendsService.GetFriends(friend.PrincipalID);
|
||||
foreach (FriendInfo finfo in finfos)
|
||||
if (finfo.Friend.StartsWith(friendID.ToString()))
|
||||
return FailureResult();
|
||||
|
||||
// the user needs to confirm when he gets home
|
||||
bool success = m_FriendsService.StoreFriend(friend.PrincipalID.ToString(), friend.Friend, 0);
|
||||
bool success = m_TheService.NewFriendship(friend, verified);
|
||||
|
||||
if (success)
|
||||
return SuccessResult();
|
||||
@@ -174,25 +183,53 @@ namespace OpenSim.Server.Handlers.Hypergrid
|
||||
secret = request["SECRET"].ToString();
|
||||
|
||||
if (secret == string.Empty)
|
||||
return FailureResult();
|
||||
return BoolResult(false);
|
||||
|
||||
FriendInfo[] finfos = m_FriendsService.GetFriends(friend.PrincipalID);
|
||||
foreach (FriendInfo finfo in finfos)
|
||||
{
|
||||
// We check the secret here
|
||||
if (finfo.Friend.StartsWith(friend.Friend) && finfo.Friend.EndsWith(secret))
|
||||
{
|
||||
m_log.DebugFormat("[HGFRIENDS HANDLER]: Delete friendship {0} {1}", friend.PrincipalID, friend.Friend);
|
||||
m_FriendsService.Delete(friend.PrincipalID, finfo.Friend);
|
||||
m_FriendsService.Delete(finfo.Friend, friend.PrincipalID.ToString());
|
||||
bool success = m_TheService.DeleteFriendship(friend, secret);
|
||||
|
||||
return SuccessResult();
|
||||
}
|
||||
}
|
||||
|
||||
return FailureResult();
|
||||
return BoolResult(success);
|
||||
}
|
||||
|
||||
byte[] FriendshipOffered(Dictionary<string, object> request)
|
||||
{
|
||||
UUID fromID = UUID.Zero;
|
||||
UUID toID = UUID.Zero;
|
||||
string message = string.Empty;
|
||||
string name = string.Empty;
|
||||
|
||||
m_log.DebugFormat("[HGFRIENDS HANDLER]: Friendship offered");
|
||||
if (!request.ContainsKey("FromID") || !request.ContainsKey("ToID"))
|
||||
return BoolResult(false);
|
||||
|
||||
if (!UUID.TryParse(request["ToID"].ToString(), out toID))
|
||||
return BoolResult(false);
|
||||
|
||||
message = request["Message"].ToString();
|
||||
|
||||
if (!UUID.TryParse(request["FromID"].ToString(), out fromID))
|
||||
return BoolResult(false);
|
||||
|
||||
if (request.ContainsKey("FromName"))
|
||||
name = request["FromName"].ToString();
|
||||
|
||||
bool success = m_TheService.FriendshipOffered(fromID, name, toID, message);
|
||||
|
||||
return BoolResult(success);
|
||||
}
|
||||
|
||||
byte[] ValidateFriendshipOffered(Dictionary<string, object> request)
|
||||
{
|
||||
FriendInfo friend = new FriendInfo(request);
|
||||
UUID friendID = UUID.Zero;
|
||||
if (!UUID.TryParse(friend.Friend, out friendID))
|
||||
return BoolResult(false);
|
||||
|
||||
bool success = m_TheService.ValidateFriendshipOffered(friend.PrincipalID, friendID);
|
||||
|
||||
return BoolResult(success);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Misc
|
||||
@@ -205,10 +242,15 @@ namespace OpenSim.Server.Handlers.Hypergrid
|
||||
return false;
|
||||
}
|
||||
|
||||
if (request["KEY"] == null || request["SESSIONID"] == null)
|
||||
return false;
|
||||
|
||||
string serviceKey = request["KEY"].ToString();
|
||||
string sessionStr = request["SESSIONID"].ToString();
|
||||
|
||||
UUID sessionID;
|
||||
UUID.TryParse(sessionStr, out sessionID);
|
||||
if (!UUID.TryParse(sessionStr, out sessionID) || serviceKey == string.Empty)
|
||||
return false;
|
||||
|
||||
if (!m_UserAgentService.VerifyAgent(sessionID, serviceKey))
|
||||
{
|
||||
@@ -256,7 +298,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
|
||||
|
||||
doc.AppendChild(rootElement);
|
||||
|
||||
XmlElement result = doc.CreateElement("", "Result", "");
|
||||
XmlElement result = doc.CreateElement("", "RESULT", "");
|
||||
result.AppendChild(doc.CreateTextNode("Success"));
|
||||
|
||||
rootElement.AppendChild(result);
|
||||
@@ -289,7 +331,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
|
||||
|
||||
doc.AppendChild(rootElement);
|
||||
|
||||
XmlElement result = doc.CreateElement("", "Result", "");
|
||||
XmlElement result = doc.CreateElement("", "RESULT", "");
|
||||
result.AppendChild(doc.CreateTextNode("Failure"));
|
||||
|
||||
rootElement.AppendChild(result);
|
||||
@@ -302,6 +344,28 @@ namespace OpenSim.Server.Handlers.Hypergrid
|
||||
return DocToBytes(doc);
|
||||
}
|
||||
|
||||
private byte[] BoolResult(bool value)
|
||||
{
|
||||
XmlDocument doc = new XmlDocument();
|
||||
|
||||
XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
|
||||
"", "");
|
||||
|
||||
doc.AppendChild(xmlnode);
|
||||
|
||||
XmlElement rootElement = doc.CreateElement("", "ServerResponse",
|
||||
"");
|
||||
|
||||
doc.AppendChild(rootElement);
|
||||
|
||||
XmlElement result = doc.CreateElement("", "RESULT", "");
|
||||
result.AppendChild(doc.CreateTextNode(value.ToString()));
|
||||
|
||||
rootElement.AppendChild(result);
|
||||
|
||||
return DocToBytes(doc);
|
||||
}
|
||||
|
||||
private byte[] DocToBytes(XmlDocument doc)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
@@ -313,6 +377,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
|
||||
return ms.ToArray();
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,11 @@ namespace OpenSim.Server.Handlers.Hypergrid
|
||||
// MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private IUserAgentService m_HomeUsersService;
|
||||
public IUserAgentService HomeUsersService
|
||||
{
|
||||
get { return m_HomeUsersService; }
|
||||
}
|
||||
|
||||
private string[] m_AuthorizedCallers;
|
||||
|
||||
private bool m_VerifyCallers = false;
|
||||
@@ -96,6 +101,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
|
||||
|
||||
server.AddXmlRPCHandler("locate_user", LocateUser, false);
|
||||
server.AddXmlRPCHandler("get_uui", GetUUI, false);
|
||||
server.AddXmlRPCHandler("get_uuid", GetUUID, false);
|
||||
|
||||
server.AddHTTPHandler("/homeagent/", new HomeAgentHandler(m_HomeUsersService, loginServerIP, proxy).Handler);
|
||||
}
|
||||
@@ -410,8 +416,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Locates the user.
|
||||
/// This is a sensitive operation, only authorized IP addresses can perform it.
|
||||
/// Returns the UUI of a user given a UUID.
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="remoteClient"></param>
|
||||
@@ -445,5 +450,33 @@ namespace OpenSim.Server.Handlers.Hypergrid
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the UUID of a user given First name, Last name.
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="remoteClient"></param>
|
||||
/// <returns></returns>
|
||||
public XmlRpcResponse GetUUID(XmlRpcRequest request, IPEndPoint remoteClient)
|
||||
{
|
||||
Hashtable hash = new Hashtable();
|
||||
|
||||
Hashtable requestData = (Hashtable)request.Params[0];
|
||||
//string host = (string)requestData["host"];
|
||||
//string portstr = (string)requestData["port"];
|
||||
if (requestData.ContainsKey("first") && requestData.ContainsKey("last"))
|
||||
{
|
||||
UUID userID = UUID.Zero;
|
||||
string first = (string)requestData["first"];
|
||||
|
||||
string last = (string)requestData["last"];
|
||||
UUID uuid = m_HomeUsersService.GetUUID(first, last);
|
||||
hash["UUID"] = uuid.ToString();
|
||||
}
|
||||
|
||||
XmlRpcResponse response = new XmlRpcResponse();
|
||||
response.Value = hash;
|
||||
return response;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user