OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
FriendsSimConnector.cs
Go to the documentation of this file.
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.Generic;
30 using System.Reflection;
31 
32 using OpenSim.Services.Interfaces;
34 using OpenSim.Server.Base;
35 using OpenSim.Framework;
36 
37 using OpenMetaverse;
38 using log4net;
39 
40 namespace OpenSim.Services.Connectors.Friends
41 {
42  public class FriendsSimConnector
43  {
44  private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45 
46  protected virtual string ServicePath()
47  {
48  return "friends";
49  }
50 
51  public bool FriendshipOffered(GridRegion region, UUID userID, UUID friendID, string message)
52  {
53  return FriendshipOffered(region, userID, friendID, message, String.Empty);
54  }
55 
56  public virtual bool FriendshipOffered(GridRegion region, UUID userID, UUID friendID, string message, string userName)
57  {
58  Dictionary<string, object> sendData = new Dictionary<string, object>();
59  //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
60  //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
61  sendData["METHOD"] = "friendship_offered";
62 
63  sendData["FromID"] = userID.ToString();
64  sendData["ToID"] = friendID.ToString();
65  sendData["Message"] = message;
66  if (userName != String.Empty)
67  sendData["FromName"] = userName;
68 
69  return Call(region, sendData);
70  }
71 
72  public bool FriendshipApproved(GridRegion region, UUID userID, string userName, UUID friendID)
73  {
74  Dictionary<string, object> sendData = new Dictionary<string, object>();
75  //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
76  //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
77  sendData["METHOD"] = "friendship_approved";
78 
79  sendData["FromID"] = userID.ToString();
80  sendData["FromName"] = userName;
81  sendData["ToID"] = friendID.ToString();
82 
83  return Call(region, sendData);
84  }
85 
86  public bool FriendshipDenied(GridRegion region, UUID userID, string userName, UUID friendID)
87  {
88  if (region == null)
89  return false;
90 
91  Dictionary<string, object> sendData = new Dictionary<string, object>();
92  //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
93  //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
94  sendData["METHOD"] = "friendship_denied";
95 
96  sendData["FromID"] = userID.ToString();
97  sendData["FromName"] = userName;
98  sendData["ToID"] = friendID.ToString();
99 
100  return Call(region, sendData);
101  }
102 
103  public bool FriendshipTerminated(GridRegion region, UUID userID, UUID friendID)
104  {
105  Dictionary<string, object> sendData = new Dictionary<string, object>();
106  //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
107  //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
108  sendData["METHOD"] = "friendship_terminated";
109 
110  sendData["FromID"] = userID.ToString();
111  sendData["ToID"] = friendID.ToString();
112 
113  return Call(region, sendData);
114  }
115 
116  public bool GrantRights(GridRegion region, UUID userID, UUID friendID, int userFlags, int rights)
117  {
118  Dictionary<string, object> sendData = new Dictionary<string, object>();
119  //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
120  //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
121  sendData["METHOD"] = "grant_rights";
122 
123  sendData["FromID"] = userID.ToString();
124  sendData["ToID"] = friendID.ToString();
125  sendData["UserFlags"] = userFlags.ToString();
126  sendData["Rights"] = rights.ToString();
127 
128  return Call(region, sendData);
129  }
130 
131  public bool StatusNotify(GridRegion region, UUID userID, string friendID, bool online)
132  {
133  Dictionary<string, object> sendData = new Dictionary<string, object>();
134  //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
135  //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
136  sendData["METHOD"] = "status";
137 
138  sendData["FromID"] = userID.ToString();
139  sendData["ToID"] = friendID;
140  sendData["Online"] = online.ToString();
141 
142  return Call(region, sendData);
143  }
144 
145  private bool Call(GridRegion region, Dictionary<string, object> sendData)
146  {
147  Util.FireAndForget(x => {
148  string reqString = ServerUtils.BuildQueryString(sendData);
149  //m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: queryString = {0}", reqString);
150  if (region == null)
151  return;
152 
153  string path = ServicePath();
154  if (!region.ServerURI.EndsWith("/"))
155  path = "/" + path;
156  string uri = region.ServerURI + path;
157  // m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: calling {0}", uri);
158 
159  try
160  {
161  string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString);
162  if (reply != string.Empty)
163  {
164  Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
165 
166  if (replyData.ContainsKey("RESULT"))
167  {
168 // if (replyData["RESULT"].ToString().ToLower() == "true")
169 // return;
170 // else
171  return;
172  }
173  else
174  m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: reply data does not contain result field");
175 
176  }
177  else
178  m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: received empty reply");
179  }
180  catch (Exception e)
181  {
182  m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: Exception when contacting remote sim at {0}: {1}", uri, e.Message);
183  }
184 
185  return;
186  });
187 
188  return true;
189  }
190  }
191 }
bool GrantRights(GridRegion region, UUID userID, UUID friendID, int userFlags, int rights)
bool FriendshipOffered(GridRegion region, UUID userID, UUID friendID, string message)
bool FriendshipTerminated(GridRegion region, UUID userID, UUID friendID)
bool FriendshipApproved(GridRegion region, UUID userID, string userName, UUID friendID)
bool StatusNotify(GridRegion region, UUID userID, string friendID, bool online)
virtual bool FriendshipOffered(GridRegion region, UUID userID, UUID friendID, string message, string userName)
string ServerURI
A well-formed URI for the host region server (namely "http://" + ExternalHostName) ...
bool FriendshipDenied(GridRegion region, UUID userID, string userName, UUID friendID)
OpenSim.Services.Interfaces.GridRegion GridRegion