aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDiva Canto2010-02-25 17:42:51 -0800
committerDiva Canto2010-02-25 17:42:51 -0800
commitc745df007d1730e59fbdb4ebf8440654d1675ade (patch)
treeca3e63d93add73a870901956301bc243b8428a69
parentMerge branch 'presence-refactor' of melanie@opensimulator.org:/var/git/opensi... (diff)
downloadopensim-SC_OLD-c745df007d1730e59fbdb4ebf8440654d1675ade.zip
opensim-SC_OLD-c745df007d1730e59fbdb4ebf8440654d1675ade.tar.gz
opensim-SC_OLD-c745df007d1730e59fbdb4ebf8440654d1675ade.tar.bz2
opensim-SC_OLD-c745df007d1730e59fbdb4ebf8440654d1675ade.tar.xz
Added server-side Friends in connector. Untested.
-rw-r--r--OpenSim/Server/Handlers/Friends/FriendServerConnector.cs61
-rw-r--r--OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs238
-rw-r--r--OpenSim/Services/Interfaces/IFriendsService.cs28
-rw-r--r--bin/OpenSim.Server.HG.ini.example1
-rw-r--r--bin/OpenSim.Server.ini.example1
-rw-r--r--bin/config-include/Grid.ini3
-rw-r--r--bin/config-include/GridHypergrid.ini3
7 files changed, 335 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/Friends/FriendServerConnector.cs b/OpenSim/Server/Handlers/Friends/FriendServerConnector.cs
new file mode 100644
index 0000000..074f869
--- /dev/null
+++ b/OpenSim/Server/Handlers/Friends/FriendServerConnector.cs
@@ -0,0 +1,61 @@
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.Friends
36{
37 public class FriendsServiceConnector : ServiceConnector
38 {
39 private IFriendsService m_FriendsService;
40 private string m_ConfigName = "FriendsService";
41
42 public FriendsServiceConnector(IConfigSource config, IHttpServer server, string configName) :
43 base(config, server, configName)
44 {
45 IConfig serverConfig = config.Configs[m_ConfigName];
46 if (serverConfig == null)
47 throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
48
49 string gridService = serverConfig.GetString("LocalServiceModule",
50 String.Empty);
51
52 if (gridService == String.Empty)
53 throw new Exception("No LocalServiceModule in config file");
54
55 Object[] args = new Object[] { config };
56 m_FriendsService = ServerUtils.LoadPlugin<IFriendsService>(gridService, args);
57
58 server.AddStreamHandler(new FriendsServerPostHandler(m_FriendsService));
59 }
60 }
61}
diff --git a/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs b/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs
new file mode 100644
index 0000000..fa655d2
--- /dev/null
+++ b/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs
@@ -0,0 +1,238 @@
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.Friends
47{
48 public class FriendsServerPostHandler : BaseStreamHandler
49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51
52 private IFriendsService m_FriendsService;
53
54 public FriendsServerPostHandler(IFriendsService service) :
55 base("POST", "/friends")
56 {
57 m_FriendsService = service;
58 }
59
60 public override byte[] Handle(string path, Stream requestData,
61 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
62 {
63 StreamReader sr = new StreamReader(requestData);
64 string body = sr.ReadToEnd();
65 sr.Close();
66 body = body.Trim();
67
68 //m_log.DebugFormat("[XXX]: query String: {0}", body);
69
70 try
71 {
72 Dictionary<string, object> request =
73 ServerUtils.ParseQueryString(body);
74
75 if (!request.ContainsKey("METHOD"))
76 return FailureResult();
77
78 string method = request["METHOD"].ToString();
79
80 switch (method)
81 {
82 case "getfriends":
83 return GetFriends(request);
84
85 case "storefriend":
86 return StoreFriend(request);
87
88 case "deletefriend":
89 return DeleteFriend(request);
90
91 }
92 m_log.DebugFormat("[FRIENDS HANDLER]: unknown method {0} request {1}", method.Length, method);
93 }
94 catch (Exception e)
95 {
96 m_log.DebugFormat("[FRIENDS 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("[FRIENDS 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[] StoreFriend(Dictionary<string, object> request)
138 {
139 FriendInfo friend = new FriendInfo(request);
140
141 bool success = m_FriendsService.StoreFriend(friend.PrincipalID, friend.Friend, friend.TheirFlags);
142
143 if (success)
144 return SuccessResult();
145 else
146 return FailureResult();
147 }
148
149 byte[] DeleteFriend(Dictionary<string, object> request)
150 {
151 UUID principalID = UUID.Zero;
152 if (request.ContainsKey("PRINCIPALID"))
153 UUID.TryParse(request["PRINCIPALID"].ToString(), out principalID);
154 else
155 m_log.WarnFormat("[FRIENDS HANDLER]: no principalID in request to delete friend");
156 string friend = string.Empty;
157 if (request.ContainsKey("FRIEND"))
158 friend = request["FRIEND"].ToString();
159
160 bool success = m_FriendsService.Delete(principalID, friend);
161 if (success)
162 return SuccessResult();
163 else
164 return FailureResult();
165 }
166
167 #endregion
168
169 #region Misc
170
171 private byte[] SuccessResult()
172 {
173 XmlDocument doc = new XmlDocument();
174
175 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
176 "", "");
177
178 doc.AppendChild(xmlnode);
179
180 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
181 "");
182
183 doc.AppendChild(rootElement);
184
185 XmlElement result = doc.CreateElement("", "Result", "");
186 result.AppendChild(doc.CreateTextNode("Success"));
187
188 rootElement.AppendChild(result);
189
190 return DocToBytes(doc);
191 }
192
193 private byte[] FailureResult()
194 {
195 return FailureResult(String.Empty);
196 }
197
198 private byte[] FailureResult(string msg)
199 {
200 XmlDocument doc = new XmlDocument();
201
202 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
203 "", "");
204
205 doc.AppendChild(xmlnode);
206
207 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
208 "");
209
210 doc.AppendChild(rootElement);
211
212 XmlElement result = doc.CreateElement("", "Result", "");
213 result.AppendChild(doc.CreateTextNode("Failure"));
214
215 rootElement.AppendChild(result);
216
217 XmlElement message = doc.CreateElement("", "Message", "");
218 message.AppendChild(doc.CreateTextNode(msg));
219
220 rootElement.AppendChild(message);
221
222 return DocToBytes(doc);
223 }
224
225 private byte[] DocToBytes(XmlDocument doc)
226 {
227 MemoryStream ms = new MemoryStream();
228 XmlTextWriter xw = new XmlTextWriter(ms, null);
229 xw.Formatting = Formatting.Indented;
230 doc.WriteTo(xw);
231 xw.Flush();
232
233 return ms.ToArray();
234 }
235
236 #endregion
237 }
238}
diff --git a/OpenSim/Services/Interfaces/IFriendsService.cs b/OpenSim/Services/Interfaces/IFriendsService.cs
index 811203c..fc20224 100644
--- a/OpenSim/Services/Interfaces/IFriendsService.cs
+++ b/OpenSim/Services/Interfaces/IFriendsService.cs
@@ -25,6 +25,7 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using System;
28using OpenMetaverse; 29using OpenMetaverse;
29using OpenSim.Framework; 30using OpenSim.Framework;
30using System.Collections.Generic; 31using System.Collections.Generic;
@@ -37,6 +38,33 @@ namespace OpenSim.Services.Interfaces
37 public string Friend; 38 public string Friend;
38 public int MyFlags; 39 public int MyFlags;
39 public int TheirFlags; 40 public int TheirFlags;
41
42 public FriendInfo(Dictionary<string, object> kvp)
43 {
44 PrincipalID = UUID.Zero;
45 if (kvp.ContainsKey("PrincipalID") && kvp["PrincipalID"] != null)
46 UUID.TryParse(kvp["PrincipalID"].ToString(), out PrincipalID);
47 Friend = string.Empty;
48 if (kvp.ContainsKey("Friend") && kvp["Friend"] != null)
49 Friend = kvp["Friend"].ToString();
50 MyFlags = 0;
51 if (kvp.ContainsKey("MyFlags") && kvp["MyFlags"] != null)
52 Int32.TryParse(kvp["MyFlags"].ToString(), out MyFlags);
53 TheirFlags = 0;
54 if (kvp.ContainsKey("TheirFlags") && kvp["TheirFlags"] != null)
55 Int32.TryParse(kvp["TheirFlags"].ToString(), out TheirFlags);
56 }
57
58 public Dictionary<string, object> ToKeyValuePairs()
59 {
60 Dictionary<string, object> result = new Dictionary<string, object>();
61 result["PricipalID"] = PrincipalID.ToString();
62 result["Friend"] = Friend;
63 result["MyFlags"] = MyFlags.ToString();
64 result["TheirFlags"] = TheirFlags.ToString();
65
66 return result;
67 }
40 } 68 }
41 69
42 public interface IFriendsService 70 public interface IFriendsService
diff --git a/bin/OpenSim.Server.HG.ini.example b/bin/OpenSim.Server.HG.ini.example
index fea0ea2..732d123 100644
--- a/bin/OpenSim.Server.HG.ini.example
+++ b/bin/OpenSim.Server.HG.ini.example
@@ -119,6 +119,7 @@ ServiceConnectors = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector,8003
119 SimulationService ="OpenSim.Services.Connectors.dll:SimulationServiceConnector" 119 SimulationService ="OpenSim.Services.Connectors.dll:SimulationServiceConnector"
120 LibraryService = "OpenSim.Services.InventoryService.dll:LibraryService" 120 LibraryService = "OpenSim.Services.InventoryService.dll:LibraryService"
121 UserAgentService = "OpenSim.Services.HypergridService.dll:UserAgentService" 121 UserAgentService = "OpenSim.Services.HypergridService.dll:UserAgentService"
122 FriendsService = "OpenSim.Services.FriendsService.dll:FriendsService"
122 123
123 WelcomeMessage = "Welcome, Avatar!" 124 WelcomeMessage = "Welcome, Avatar!"
124 ; Defaults for the users, if none is specified in the useraccounts table entry (ServiceURLs) 125 ; Defaults for the users, if none is specified in the useraccounts table entry (ServiceURLs)
diff --git a/bin/OpenSim.Server.ini.example b/bin/OpenSim.Server.ini.example
index 54101b0..e6508b1 100644
--- a/bin/OpenSim.Server.ini.example
+++ b/bin/OpenSim.Server.ini.example
@@ -120,5 +120,6 @@ ServiceConnectors = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector,8003
120 GridService = "OpenSim.Services.GridService.dll:GridService" 120 GridService = "OpenSim.Services.GridService.dll:GridService"
121 SimulationService ="OpenSim.Services.Connectors.dll:SimulationServiceConnector" 121 SimulationService ="OpenSim.Services.Connectors.dll:SimulationServiceConnector"
122 LibraryService = "OpenSim.Services.InventoryService.dll:LibraryService" 122 LibraryService = "OpenSim.Services.InventoryService.dll:LibraryService"
123 FriendsService = "OpenSim.Services.FriendsService.dll:FriendsService"
123 124
124 WelcomeMessage = "Welcome, Avatar!" 125 WelcomeMessage = "Welcome, Avatar!"
diff --git a/bin/config-include/Grid.ini b/bin/config-include/Grid.ini
index 56c76c6..a656e7b 100644
--- a/bin/config-include/Grid.ini
+++ b/bin/config-include/Grid.ini
@@ -34,3 +34,6 @@
34 LocalServiceModule = "OpenSim.Services.InventoryService.dll:LibraryService" 34 LocalServiceModule = "OpenSim.Services.InventoryService.dll:LibraryService"
35 LibraryName = "OpenSim Library" 35 LibraryName = "OpenSim Library"
36 DefaultLibrary = "./inventory/Libraries.xml" 36 DefaultLibrary = "./inventory/Libraries.xml"
37
38[Friends]
39 Connector = "OpenSim.Services.Connectors.dll:FriendsServiceConnector"
diff --git a/bin/config-include/GridHypergrid.ini b/bin/config-include/GridHypergrid.ini
index 7391278..36cefdc 100644
--- a/bin/config-include/GridHypergrid.ini
+++ b/bin/config-include/GridHypergrid.ini
@@ -40,3 +40,6 @@
40 StorageProvider = "OpenSim.Data.Null.dll:NullRegionData" 40 StorageProvider = "OpenSim.Data.Null.dll:NullRegionData"
41 41
42 AllowHypergridMapSearch = true 42 AllowHypergridMapSearch = true
43
44[Friends]
45 Connector = "OpenSim.Services.Connectors.dll:FriendsServiceConnector"