123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
-
- using System;
- using System.Collections.Generic;
- using System.Reflection;
- using OpenSim.Services.Interfaces;
- using GridRegion = OpenSim.Services.Interfaces.GridRegion;
- using OpenSim.Server.Base;
- using OpenSim.Framework;
- using OpenMetaverse;
- using log4net;
- namespace OpenSim.Services.Connectors.Friends
- {
- public class FriendsSimConnector
- {
- private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
- protected virtual string ServicePath()
- {
- return "friends";
- }
- public bool FriendshipOffered(GridRegion region, UUID userID, UUID friendID, string message)
- {
- return FriendshipOffered(region, userID, friendID, message, String.Empty);
- }
- public virtual bool FriendshipOffered(GridRegion region, UUID userID, UUID friendID, string message, string userName)
- {
- Dictionary<string, object> sendData = new Dictionary<string, object>();
-
-
- sendData["METHOD"] = "friendship_offered";
- sendData["FromID"] = userID.ToString();
- sendData["ToID"] = friendID.ToString();
- sendData["Message"] = message;
- if (userName != String.Empty)
- sendData["FromName"] = userName;
- return Call(region, sendData);
- }
- public bool FriendshipApproved(GridRegion region, UUID userID, string userName, UUID friendID)
- {
- Dictionary<string, object> sendData = new Dictionary<string, object>();
-
-
- sendData["METHOD"] = "friendship_approved";
- sendData["FromID"] = userID.ToString();
- sendData["FromName"] = userName;
- sendData["ToID"] = friendID.ToString();
- return Call(region, sendData);
- }
- public bool FriendshipDenied(GridRegion region, UUID userID, string userName, UUID friendID)
- {
- if (region == null)
- return false;
- Dictionary<string, object> sendData = new Dictionary<string, object>();
-
-
- sendData["METHOD"] = "friendship_denied";
- sendData["FromID"] = userID.ToString();
- sendData["FromName"] = userName;
- sendData["ToID"] = friendID.ToString();
- return Call(region, sendData);
- }
- public bool FriendshipTerminated(GridRegion region, UUID userID, UUID friendID)
- {
- Dictionary<string, object> sendData = new Dictionary<string, object>();
-
-
- sendData["METHOD"] = "friendship_terminated";
- sendData["FromID"] = userID.ToString();
- sendData["ToID"] = friendID.ToString();
- return Call(region, sendData);
- }
- public bool GrantRights(GridRegion region, UUID userID, UUID friendID, int userFlags, int rights)
- {
- Dictionary<string, object> sendData = new Dictionary<string, object>();
-
-
- sendData["METHOD"] = "grant_rights";
- sendData["FromID"] = userID.ToString();
- sendData["ToID"] = friendID.ToString();
- sendData["UserFlags"] = userFlags.ToString();
- sendData["Rights"] = rights.ToString();
- return Call(region, sendData);
- }
- public bool StatusNotify(GridRegion region, UUID userID, string friendID, bool online)
- {
- Dictionary<string, object> sendData = new Dictionary<string, object>();
-
-
- sendData["METHOD"] = "status";
- sendData["FromID"] = userID.ToString();
- sendData["ToID"] = friendID;
- sendData["Online"] = online.ToString();
- return Call(region, sendData);
- }
- private bool Call(GridRegion region, Dictionary<string, object> sendData)
- {
- string reqString = ServerUtils.BuildQueryString(sendData);
-
- if (region == null)
- return false;
- string path = ServicePath();
- if (!region.ServerURI.EndsWith("/"))
- path = "/" + path;
- string uri = region.ServerURI + path;
- try
- {
- string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString);
- if (reply != string.Empty)
- {
- Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
- if (replyData.ContainsKey("RESULT"))
- {
- if (replyData["RESULT"].ToString().ToLower() == "true")
- return true;
- else
- return false;
- }
- else
- m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: reply data does not contain result field");
- }
- else
- m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: received empty reply");
- }
- catch (Exception e)
- {
- m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: Exception when contacting remote sim at {0}: {1}", uri, e.Message);
- }
- return false;
- }
- }
- }
|