aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server
diff options
context:
space:
mode:
authorDiva Canto2011-05-19 16:54:46 -0700
committerDiva Canto2011-05-19 16:54:46 -0700
commitd21e9c755f004d8fe03b11bc57b810dbd401435a (patch)
tree1efd9e48308192d21ca73d8ff12d6a48c186077c /OpenSim/Server
parentAccidentally committed too early (diff)
downloadopensim-SC-d21e9c755f004d8fe03b11bc57b810dbd401435a.zip
opensim-SC-d21e9c755f004d8fe03b11bc57b810dbd401435a.tar.gz
opensim-SC-d21e9c755f004d8fe03b11bc57b810dbd401435a.tar.bz2
opensim-SC-d21e9c755f004d8fe03b11bc57b810dbd401435a.tar.xz
HG Friends working to some extent: friendships offered and accepted correctly handled. Friends list showing correct foreign names. TODO: GrantRights.
Diffstat (limited to 'OpenSim/Server')
-rw-r--r--OpenSim/Server/Handlers/Friends/FriendServerConnector.cs6
-rw-r--r--OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs2
-rw-r--r--OpenSim/Server/Handlers/Hypergrid/HGFriendServerConnector.cs71
-rw-r--r--OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs242
4 files changed, 317 insertions, 4 deletions
diff --git a/OpenSim/Server/Handlers/Friends/FriendServerConnector.cs b/OpenSim/Server/Handlers/Friends/FriendServerConnector.cs
index 074f869..5784bdf 100644
--- a/OpenSim/Server/Handlers/Friends/FriendServerConnector.cs
+++ b/OpenSim/Server/Handlers/Friends/FriendServerConnector.cs
@@ -46,14 +46,14 @@ namespace OpenSim.Server.Handlers.Friends
46 if (serverConfig == null) 46 if (serverConfig == null)
47 throw new Exception(String.Format("No section {0} in config file", m_ConfigName)); 47 throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
48 48
49 string gridService = serverConfig.GetString("LocalServiceModule", 49 string theService = serverConfig.GetString("LocalServiceModule",
50 String.Empty); 50 String.Empty);
51 51
52 if (gridService == String.Empty) 52 if (theService == String.Empty)
53 throw new Exception("No LocalServiceModule in config file"); 53 throw new Exception("No LocalServiceModule in config file");
54 54
55 Object[] args = new Object[] { config }; 55 Object[] args = new Object[] { config };
56 m_FriendsService = ServerUtils.LoadPlugin<IFriendsService>(gridService, args); 56 m_FriendsService = ServerUtils.LoadPlugin<IFriendsService>(theService, args);
57 57
58 server.AddStreamHandler(new FriendsServerPostHandler(m_FriendsService)); 58 server.AddStreamHandler(new FriendsServerPostHandler(m_FriendsService));
59 } 59 }
diff --git a/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs b/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs
index b168bb3..64002e1 100644
--- a/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs
@@ -138,7 +138,7 @@ namespace OpenSim.Server.Handlers.Friends
138 { 138 {
139 FriendInfo friend = new FriendInfo(request); 139 FriendInfo friend = new FriendInfo(request);
140 140
141 bool success = m_FriendsService.StoreFriend(friend.PrincipalID, friend.Friend, friend.MyFlags); 141 bool success = m_FriendsService.StoreFriend(friend.PrincipalID.ToString(), friend.Friend, friend.MyFlags);
142 142
143 if (success) 143 if (success)
144 return SuccessResult(); 144 return SuccessResult();
diff --git a/OpenSim/Server/Handlers/Hypergrid/HGFriendServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/HGFriendServerConnector.cs
new file mode 100644
index 0000000..82a7220
--- /dev/null
+++ b/OpenSim/Server/Handlers/Hypergrid/HGFriendServerConnector.cs
@@ -0,0 +1,71 @@
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 Nini.Config;
30using OpenSim.Server.Base;
31using OpenSim.Services.Interfaces;
32using OpenSim.Framework.Servers.HttpServer;
33using OpenSim.Server.Handlers.Base;
34
35namespace OpenSim.Server.Handlers.Hypergrid
36{
37 public class HGFriendsServerConnector : ServiceConnector
38 {
39 private IFriendsService m_FriendsService;
40 private IUserAgentService m_UserAgentService;
41 private string m_ConfigName = "HGFriendsService";
42
43 public HGFriendsServerConnector(IConfigSource config, IHttpServer server, string configName) :
44 base(config, server, configName)
45 {
46 if (configName != string.Empty)
47 m_ConfigName = configName;
48
49 IConfig serverConfig = config.Configs[m_ConfigName];
50 if (serverConfig == null)
51 throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
52
53 string theService = serverConfig.GetString("LocalServiceModule",
54 String.Empty);
55
56 if (theService == String.Empty)
57 throw new Exception("No LocalServiceModule in config file");
58
59 Object[] args = new Object[] { config };
60 m_FriendsService = ServerUtils.LoadPlugin<IFriendsService>(theService, args);
61
62 theService = serverConfig.GetString("UserAgentService", string.Empty);
63 if (theService == String.Empty)
64 throw new Exception("No UserAgentService in " + m_ConfigName);
65
66 m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(theService, args);
67
68 server.AddStreamHandler(new HGFriendsServerPostHandler(m_FriendsService, m_UserAgentService));
69 }
70 }
71}
diff --git a/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs b/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs
new file mode 100644
index 0000000..13d1502
--- /dev/null
+++ b/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs
@@ -0,0 +1,242 @@
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 Nini.Config;
29using log4net;
30using System;
31using System.Reflection;
32using System.IO;
33using System.Net;
34using System.Text;
35using System.Text.RegularExpressions;
36using System.Xml;
37using System.Xml.Serialization;
38using System.Collections.Generic;
39using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces;
41using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
42using OpenSim.Framework;
43using OpenSim.Framework.Servers.HttpServer;
44using OpenMetaverse;
45
46namespace OpenSim.Server.Handlers.Hypergrid
47{
48 public class HGFriendsServerPostHandler : BaseStreamHandler
49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51
52 private IFriendsService m_FriendsService;
53 private IUserAgentService m_UserAgentService;
54
55 public HGFriendsServerPostHandler(IFriendsService service, IUserAgentService uservice) :
56 base("POST", "/hgfriends")
57 {
58 m_FriendsService = service;
59 m_UserAgentService = uservice;
60 m_log.DebugFormat("[HGFRIENDS HANDLER]: HGFriendsServerPostHandler is On");
61 }
62
63 public override byte[] Handle(string path, Stream requestData,
64 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
65 {
66 StreamReader sr = new StreamReader(requestData);
67 string body = sr.ReadToEnd();
68 sr.Close();
69 body = body.Trim();
70
71 //m_log.DebugFormat("[XXX]: query String: {0}", body);
72
73 try
74 {
75 Dictionary<string, object> request =
76 ServerUtils.ParseQueryString(body);
77
78 if (!request.ContainsKey("METHOD"))
79 return FailureResult();
80
81 string method = request["METHOD"].ToString();
82
83 switch (method)
84 {
85 case "getfriends":
86 return GetFriends(request);
87
88 case "newfriendship":
89 return NewFriendship(request);
90
91 }
92 m_log.DebugFormat("[HGFRIENDS HANDLER]: unknown method {0} request {1}", method.Length, method);
93 }
94 catch (Exception e)
95 {
96 m_log.DebugFormat("[HGFRIENDS HANDLER]: Exception {0}", e);
97 }
98
99 return FailureResult();
100
101 }
102
103 #region Method-specific handlers
104
105 byte[] GetFriends(Dictionary<string, object> request)
106 {
107 UUID principalID = UUID.Zero;
108 if (request.ContainsKey("PRINCIPALID"))
109 UUID.TryParse(request["PRINCIPALID"].ToString(), out principalID);
110 else
111 m_log.WarnFormat("[HGFRIENDS HANDLER]: no principalID in request to get friends");
112
113 FriendInfo[] finfos = m_FriendsService.GetFriends(principalID);
114 //m_log.DebugFormat("[FRIENDS HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
115
116 Dictionary<string, object> result = new Dictionary<string, object>();
117 if ((finfos == null) || ((finfos != null) && (finfos.Length == 0)))
118 result["result"] = "null";
119 else
120 {
121 int i = 0;
122 foreach (FriendInfo finfo in finfos)
123 {
124 Dictionary<string, object> rinfoDict = finfo.ToKeyValuePairs();
125 result["friend" + i] = rinfoDict;
126 i++;
127 }
128 }
129
130 string xmlString = ServerUtils.BuildXmlResponse(result);
131 //m_log.DebugFormat("[FRIENDS HANDLER]: resp string: {0}", xmlString);
132 UTF8Encoding encoding = new UTF8Encoding();
133 return encoding.GetBytes(xmlString);
134
135 }
136
137 byte[] NewFriendship(Dictionary<string, object> request)
138 {
139 if (!request.ContainsKey("KEY") || !request.ContainsKey("SESSIONID"))
140 {
141 m_log.WarnFormat("[HGFRIENDS HANDLER]: ignoring request without Key or SessionID");
142 return FailureResult();
143 }
144
145 string serviceKey = request["KEY"].ToString();
146 string sessionStr = request["SESSIONID"].ToString();
147 UUID sessionID;
148 UUID.TryParse(sessionStr, out sessionID);
149
150 if (!m_UserAgentService.VerifyAgent(sessionID, serviceKey))
151 {
152 m_log.WarnFormat("[HGFRIENDS HANDLER]: Key {0} for session {1} did not match existing key. Ignoring request", serviceKey, sessionID);
153 return FailureResult();
154 }
155
156 m_log.DebugFormat("[XXX] Verification ok");
157 // OK, can proceed
158 FriendInfo friend = new FriendInfo(request);
159
160 // the user needs to confirm when he gets home
161 bool success = m_FriendsService.StoreFriend(friend.PrincipalID.ToString(), friend.Friend, 0);
162 //if (success)
163 // m_FriendsService.StoreFriend(friend.Friend, friend.PrincipalID.ToString(), 1);
164
165 if (success)
166 return SuccessResult();
167 else
168 return FailureResult();
169 }
170
171 #endregion
172
173 #region Misc
174
175 private byte[] SuccessResult()
176 {
177 XmlDocument doc = new XmlDocument();
178
179 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
180 "", "");
181
182 doc.AppendChild(xmlnode);
183
184 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
185 "");
186
187 doc.AppendChild(rootElement);
188
189 XmlElement result = doc.CreateElement("", "Result", "");
190 result.AppendChild(doc.CreateTextNode("Success"));
191
192 rootElement.AppendChild(result);
193
194 return DocToBytes(doc);
195 }
196
197 private byte[] FailureResult()
198 {
199 return FailureResult(String.Empty);
200 }
201
202 private byte[] FailureResult(string msg)
203 {
204 XmlDocument doc = new XmlDocument();
205
206 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
207 "", "");
208
209 doc.AppendChild(xmlnode);
210
211 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
212 "");
213
214 doc.AppendChild(rootElement);
215
216 XmlElement result = doc.CreateElement("", "Result", "");
217 result.AppendChild(doc.CreateTextNode("Failure"));
218
219 rootElement.AppendChild(result);
220
221 XmlElement message = doc.CreateElement("", "Message", "");
222 message.AppendChild(doc.CreateTextNode(msg));
223
224 rootElement.AppendChild(message);
225
226 return DocToBytes(doc);
227 }
228
229 private byte[] DocToBytes(XmlDocument doc)
230 {
231 MemoryStream ms = new MemoryStream();
232 XmlTextWriter xw = new XmlTextWriter(ms, null);
233 xw.Formatting = Formatting.Indented;
234 doc.WriteTo(xw);
235 xw.Flush();
236
237 return ms.ToArray();
238 }
239
240 #endregion
241 }
242}