diff options
author | Diva Canto | 2010-02-26 08:46:30 -0800 |
---|---|---|
committer | Diva Canto | 2010-02-26 08:46:30 -0800 |
commit | cc05bdf6aba5d74202cb5863a5d0f5950540e7bd (patch) | |
tree | dd6275ae206f9216bc027efcad48f0f88435f1d5 /OpenSim/Services/Connectors/Friends | |
parent | Added server-side Friends in connector. Untested. (diff) | |
download | opensim-SC-cc05bdf6aba5d74202cb5863a5d0f5950540e7bd.zip opensim-SC-cc05bdf6aba5d74202cb5863a5d0f5950540e7bd.tar.gz opensim-SC-cc05bdf6aba5d74202cb5863a5d0f5950540e7bd.tar.bz2 opensim-SC-cc05bdf6aba5d74202cb5863a5d0f5950540e7bd.tar.xz |
* Friends out connector completed. Grid login retrieves friends correctly.
* Added friends configs to grid .inis
Diffstat (limited to 'OpenSim/Services/Connectors/Friends')
-rw-r--r-- | OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs | 241 |
1 files changed, 241 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs b/OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs new file mode 100644 index 0000000..b617138 --- /dev/null +++ b/OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs | |||
@@ -0,0 +1,241 @@ | |||
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 log4net; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; | ||
39 | using OpenSim.Server.Base; | ||
40 | using OpenMetaverse; | ||
41 | |||
42 | namespace OpenSim.Services.Connectors | ||
43 | { | ||
44 | public class FriendsServicesConnector : IFriendsService | ||
45 | { | ||
46 | private static readonly ILog m_log = | ||
47 | LogManager.GetLogger( | ||
48 | MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | private string m_ServerURI = String.Empty; | ||
51 | |||
52 | public FriendsServicesConnector() | ||
53 | { | ||
54 | } | ||
55 | |||
56 | public FriendsServicesConnector(string serverURI) | ||
57 | { | ||
58 | m_ServerURI = serverURI.TrimEnd('/'); | ||
59 | } | ||
60 | |||
61 | public FriendsServicesConnector(IConfigSource source) | ||
62 | { | ||
63 | Initialise(source); | ||
64 | } | ||
65 | |||
66 | public virtual void Initialise(IConfigSource source) | ||
67 | { | ||
68 | IConfig gridConfig = source.Configs["FriendsService"]; | ||
69 | if (gridConfig == null) | ||
70 | { | ||
71 | m_log.Error("[FRIENDS CONNECTOR]: FriendsService missing from OpenSim.ini"); | ||
72 | throw new Exception("Friends connector init error"); | ||
73 | } | ||
74 | |||
75 | string serviceURI = gridConfig.GetString("FriendsServerURI", | ||
76 | String.Empty); | ||
77 | |||
78 | if (serviceURI == String.Empty) | ||
79 | { | ||
80 | m_log.Error("[FRIENDS CONNECTOR]: No Server URI named in section FriendsService"); | ||
81 | throw new Exception("Friends connector init error"); | ||
82 | } | ||
83 | m_ServerURI = serviceURI; | ||
84 | } | ||
85 | |||
86 | |||
87 | #region IFriendsService | ||
88 | |||
89 | public FriendInfo[] GetFriends(UUID PrincipalID) | ||
90 | { | ||
91 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
92 | |||
93 | sendData["PRINCIPALID"] = PrincipalID.ToString(); | ||
94 | sendData["METHOD"] = "getfriends"; | ||
95 | |||
96 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
97 | |||
98 | try | ||
99 | { | ||
100 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
101 | m_ServerURI + "/friends", | ||
102 | reqString); | ||
103 | if (reply != string.Empty) | ||
104 | { | ||
105 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
106 | |||
107 | if (replyData != null) | ||
108 | { | ||
109 | if (replyData.ContainsKey("result") && (replyData["result"].ToString().ToLower() == "null")) | ||
110 | { | ||
111 | return new FriendInfo[0]; | ||
112 | } | ||
113 | |||
114 | List<FriendInfo> finfos = new List<FriendInfo>(); | ||
115 | Dictionary<string, object>.ValueCollection finfosList = replyData.Values; | ||
116 | //m_log.DebugFormat("[FRIENDS CONNECTOR]: get neighbours returned {0} elements", rinfosList.Count); | ||
117 | foreach (object f in finfosList) | ||
118 | { | ||
119 | if (f is Dictionary<string, object>) | ||
120 | { | ||
121 | FriendInfo finfo = new FriendInfo((Dictionary<string, object>)f); | ||
122 | finfos.Add(finfo); | ||
123 | } | ||
124 | else | ||
125 | m_log.DebugFormat("[FRIENDS CONNECTOR]: GetFriends {0} received invalid response type {1}", | ||
126 | PrincipalID, f.GetType()); | ||
127 | } | ||
128 | |||
129 | // Success | ||
130 | return finfos.ToArray(); | ||
131 | } | ||
132 | |||
133 | else | ||
134 | m_log.DebugFormat("[FRIENDS CONNECTOR]: GetFriends {0} received null response", | ||
135 | PrincipalID); | ||
136 | |||
137 | } | ||
138 | } | ||
139 | catch (Exception e) | ||
140 | { | ||
141 | m_log.DebugFormat("[FRIENDS CONNECTOR]: Exception when contacting friends server: {0}", e.Message); | ||
142 | } | ||
143 | |||
144 | return new FriendInfo[0]; | ||
145 | |||
146 | } | ||
147 | |||
148 | public bool StoreFriend(UUID PrincipalID, string Friend, int flags) | ||
149 | { | ||
150 | FriendInfo finfo = new FriendInfo(); | ||
151 | finfo.PrincipalID = PrincipalID; | ||
152 | finfo.Friend = Friend; | ||
153 | finfo.TheirFlags = flags; | ||
154 | |||
155 | Dictionary<string, object> sendData = finfo.ToKeyValuePairs(); | ||
156 | |||
157 | sendData["METHOD"] = "storefriend"; | ||
158 | |||
159 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
160 | |||
161 | string reply = string.Empty; | ||
162 | try | ||
163 | { | ||
164 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
165 | m_ServerURI + "/friends", | ||
166 | ServerUtils.BuildQueryString(sendData)); | ||
167 | } | ||
168 | catch (Exception e) | ||
169 | { | ||
170 | m_log.DebugFormat("[FRIENDS CONNECTOR]: Exception when contacting friends server: {0}", e.Message); | ||
171 | return false; | ||
172 | } | ||
173 | |||
174 | if (reply != string.Empty) | ||
175 | { | ||
176 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
177 | |||
178 | if ((replyData != null) && replyData.ContainsKey("Result") && (replyData["Result"] != null)) | ||
179 | { | ||
180 | bool success = false; | ||
181 | Boolean.TryParse(replyData["Result"].ToString(), out success); | ||
182 | return success; | ||
183 | } | ||
184 | else | ||
185 | m_log.DebugFormat("[FRIENDS CONNECTOR]: StoreFriend {0} {1} received null response", | ||
186 | PrincipalID, Friend); | ||
187 | } | ||
188 | else | ||
189 | m_log.DebugFormat("[FRIENDS CONNECTOR]: StoreFriend received null reply"); | ||
190 | |||
191 | return false; | ||
192 | |||
193 | } | ||
194 | |||
195 | public bool Delete(UUID PrincipalID, string Friend) | ||
196 | { | ||
197 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
198 | sendData["PRINCIPALID"] = PrincipalID.ToString(); | ||
199 | sendData["FRIENDS"] = Friend; | ||
200 | sendData["METHOD"] = "deletefriend"; | ||
201 | |||
202 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
203 | |||
204 | string reply = string.Empty; | ||
205 | try | ||
206 | { | ||
207 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
208 | m_ServerURI + "/friends", | ||
209 | ServerUtils.BuildQueryString(sendData)); | ||
210 | } | ||
211 | catch (Exception e) | ||
212 | { | ||
213 | m_log.DebugFormat("[FRIENDS CONNECTOR]: Exception when contacting friends server: {0}", e.Message); | ||
214 | return false; | ||
215 | } | ||
216 | |||
217 | if (reply != string.Empty) | ||
218 | { | ||
219 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
220 | |||
221 | if ((replyData != null) && replyData.ContainsKey("Result") && (replyData["Result"] != null)) | ||
222 | { | ||
223 | bool success = false; | ||
224 | Boolean.TryParse(replyData["Result"].ToString(), out success); | ||
225 | return success; | ||
226 | } | ||
227 | else | ||
228 | m_log.DebugFormat("[FRIENDS CONNECTOR]: DeleteFriend {0} {1} received null response", | ||
229 | PrincipalID, Friend); | ||
230 | } | ||
231 | else | ||
232 | m_log.DebugFormat("[FRIENDS CONNECTOR]: DeleteFriend received null reply"); | ||
233 | |||
234 | return false; | ||
235 | |||
236 | } | ||
237 | |||
238 | #endregion | ||
239 | |||
240 | } | ||
241 | } | ||