aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs')
-rw-r--r--OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs167
1 files changed, 167 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs b/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs
new file mode 100644
index 0000000..a29ac28
--- /dev/null
+++ b/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs
@@ -0,0 +1,167 @@
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
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31
32using OpenSim.Services.Interfaces;
33using GridRegion = OpenSim.Services.Interfaces.GridRegion;
34using OpenSim.Server.Base;
35using OpenSim.Framework.Servers.HttpServer;
36
37using OpenMetaverse;
38using log4net;
39
40namespace OpenSim.Services.Connectors.Friends
41{
42 public class FriendsSimConnector
43 {
44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45
46 public bool FriendshipOffered(GridRegion region, UUID userID, UUID friendID, string message)
47 {
48 Dictionary<string, object> sendData = new Dictionary<string, object>();
49 //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
50 //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
51 sendData["METHOD"] = "friendship_offered";
52
53 sendData["FromID"] = userID.ToString();
54 sendData["ToID"] = friendID.ToString();
55 sendData["Message"] = message;
56
57 return Call(region, sendData);
58
59 }
60
61 public bool FriendshipApproved(GridRegion region, UUID userID, string userName, UUID friendID)
62 {
63 Dictionary<string, object> sendData = new Dictionary<string, object>();
64 //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
65 //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
66 sendData["METHOD"] = "friendship_approved";
67
68 sendData["FromID"] = userID.ToString();
69 sendData["FromName"] = userName;
70 sendData["ToID"] = friendID.ToString();
71
72 return Call(region, sendData);
73 }
74
75 public bool FriendshipDenied(GridRegion region, UUID userID, string userName, UUID friendID)
76 {
77 Dictionary<string, object> sendData = new Dictionary<string, object>();
78 //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
79 //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
80 sendData["METHOD"] = "friendship_denied";
81
82 sendData["FromID"] = userID.ToString();
83 sendData["FromName"] = userName;
84 sendData["ToID"] = friendID.ToString();
85
86 return Call(region, sendData);
87 }
88
89 public bool FriendshipTerminated(GridRegion region, UUID userID, UUID friendID)
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_terminated";
95
96 sendData["FromID"] = userID.ToString();
97 sendData["ToID"] = friendID.ToString();
98
99 return Call(region, sendData);
100 }
101
102 public bool GrantRights(GridRegion region, UUID userID, UUID friendID, int userFlags, int rights)
103 {
104 Dictionary<string, object> sendData = new Dictionary<string, object>();
105 //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
106 //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
107 sendData["METHOD"] = "grant_rights";
108
109 sendData["FromID"] = userID.ToString();
110 sendData["ToID"] = friendID.ToString();
111 sendData["UserFlags"] = userFlags.ToString();
112 sendData["Rights"] = rights.ToString();
113
114 return Call(region, sendData);
115 }
116
117 public bool StatusNotify(GridRegion region, UUID userID, UUID friendID, bool online)
118 {
119 Dictionary<string, object> sendData = new Dictionary<string, object>();
120 //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
121 //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
122 sendData["METHOD"] = "status";
123
124 sendData["FromID"] = userID.ToString();
125 sendData["ToID"] = friendID.ToString();
126 sendData["Online"] = online.ToString();
127
128 return Call(region, sendData);
129 }
130
131 private bool Call(GridRegion region, Dictionary<string, object> sendData)
132 {
133 string reqString = ServerUtils.BuildQueryString(sendData);
134 // m_log.DebugFormat("[FRIENDS CONNECTOR]: queryString = {0}", reqString);
135 try
136 {
137 string url = "http://" + region.ExternalHostName + ":" + region.HttpPort;
138 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
139 url + "/friends",
140 reqString);
141 if (reply != string.Empty)
142 {
143 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
144
145 if (replyData.ContainsKey("RESULT"))
146 {
147 if (replyData["RESULT"].ToString().ToLower() == "true")
148 return true;
149 else
150 return false;
151 }
152 else
153 m_log.DebugFormat("[FRIENDS CONNECTOR]: reply data does not contain result field");
154
155 }
156 else
157 m_log.DebugFormat("[FRIENDS CONNECTOR]: received empty reply");
158 }
159 catch (Exception e)
160 {
161 m_log.DebugFormat("[FRIENDS CONNECTOR]: Exception when contacting remote sim: {0}", e.Message);
162 }
163
164 return false;
165 }
166 }
167}