aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/HGPresenceBroker.cs256
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/LocalPresenceServiceConnector.cs1
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/RemotePresenceServiceConnector.cs158
-rw-r--r--OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs152
-rw-r--r--OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs377
-rw-r--r--OpenSim/Services/Interfaces/IPresenceService.cs39
6 files changed, 973 insertions, 10 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/HGPresenceBroker.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/HGPresenceBroker.cs
new file mode 100644
index 0000000..0d913bc
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/HGPresenceBroker.cs
@@ -0,0 +1,256 @@
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 */
27using System;
28using System.Collections.Generic;
29using System.Reflection;
30
31using OpenSim.Region.Framework.Interfaces;
32using OpenSim.Region.Framework.Scenes;
33using OpenSim.Server.Base;
34using OpenSim.Services.Interfaces;
35using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo;
36
37using OpenMetaverse;
38using log4net;
39using Nini.Config;
40
41namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence
42{
43 public class HGPresenceBroker : ISharedRegionModule, IPresenceService
44 {
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46
47 #region ISharedRegionModule
48
49 private bool m_Enabled = false;
50
51 private PresenceDetector m_PresenceDetector;
52 private IPresenceService m_GridService;
53 private IPresenceService m_HGService;
54
55 public Type ReplaceableInterface
56 {
57 get { return null; }
58 }
59
60 public string Name
61 {
62 get { return "HGPresenceBroker"; }
63 }
64
65 public void Initialise(IConfigSource source)
66 {
67 IConfig moduleConfig = source.Configs["Modules"];
68 if (moduleConfig != null)
69 {
70 string name = moduleConfig.GetString("PresenceServices", "");
71 if (name == Name)
72 {
73 //m_RemoteConnector = new InventoryServicesConnector(source);
74
75 m_Enabled = true;
76
77 m_PresenceDetector = new PresenceDetector(this);
78
79
80 IConfig pConfig = source.Configs["PresenceService"];
81 if (pConfig == null)
82 {
83 m_log.Error("[HG PRESENCE CONNECTOR]: PresenceService missing from OpenSim.ini");
84 return;
85 }
86
87 string localDll = pConfig.GetString("LocalGridPresenceService",
88 String.Empty);
89 string HGDll = pConfig.GetString("HypergridPresenceService",
90 String.Empty);
91
92 if (localDll == String.Empty)
93 {
94 m_log.Error("[HG PRESENCE CONNECTOR]: No LocalGridPresenceService named in section PresenceService");
95 //return;
96 throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's");
97 }
98
99 if (HGDll == String.Empty)
100 {
101 m_log.Error("[HG PRESENCE CONNECTOR]: No HypergridPresenceService named in section PresenceService");
102 //return;
103 throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's");
104 }
105
106 Object[] args = new Object[] { source };
107 m_GridService = ServerUtils.LoadPlugin<IPresenceService>(localDll, args);
108
109 m_HGService = ServerUtils.LoadPlugin<IPresenceService>(HGDll, args);
110 // no. This will be:
111 // m_HGService = new HGPresenceServiceConnector();
112
113 if (m_GridService == null)
114 {
115 m_log.Error("[HG PRESENCE CONNECTOR]: Can't load local presence service");
116 return;
117 }
118 if (m_HGService == null)
119 {
120 m_log.Error("[HG PRESENCE CONNECTOR]: Can't load hypergrid presence service");
121 return;
122 }
123
124 m_log.Info("[HG PRESENCE CONNECTOR]: Hypergrid presence enabled");
125 }
126 }
127
128 }
129
130 public void PostInitialise()
131 {
132 }
133
134 public void Close()
135 {
136 }
137
138 public void AddRegion(Scene scene)
139 {
140 if (!m_Enabled)
141 return;
142
143 scene.RegisterModuleInterface<IPresenceService>(this);
144 m_PresenceDetector.AddRegion(scene);
145
146 m_log.InfoFormat("[HG PRESENCE CONNECTOR]: Enabled hypergrid presence for region {0}", scene.RegionInfo.RegionName);
147
148 }
149
150 public void RemoveRegion(Scene scene)
151 {
152 if (!m_Enabled)
153 return;
154
155 m_PresenceDetector.RemoveRegion(scene);
156 }
157
158 public void RegionLoaded(Scene scene)
159 {
160 if (!m_Enabled)
161 return;
162
163 }
164
165 #endregion
166
167 #region IPresenceService
168
169 public bool LoginAgent(UUID principalID, UUID sessionID, UUID secureSessionID)
170 {
171 m_log.Warn("[HG PRESENCE CONNECTOR]: LoginAgent connector not implemented at the simulators");
172 return false;
173 }
174
175 public bool LogoutAgent(UUID sessionID)
176 {
177 return m_GridService.LogoutAgent(sessionID);
178 }
179
180
181 public bool LogoutRegionAgents(UUID regionID)
182 {
183 return m_GridService.LogoutRegionAgents(regionID);
184 }
185
186 public bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt)
187 {
188 return m_GridService.ReportAgent(sessionID, regionID, position, lookAt);
189 }
190
191 public PresenceInfo GetAgent(UUID sessionID)
192 {
193 return m_GridService.GetAgent(sessionID);
194 }
195
196 public PresenceInfo[] GetAgents(string[] principalIDs)
197 {
198 Dictionary<string, List<string>> triage = new Dictionary<string, List<string>>();
199 List<PresenceInfo> presences = new List<PresenceInfo>();
200
201 foreach (string s in principalIDs)
202 {
203 string url = string.Empty;
204 string uuid = UUID.Zero.ToString();
205 StringToUrlAndUUID(s, out url, out uuid);
206 if (triage.ContainsKey(url))
207 triage[url].Add(uuid);
208 else
209 {
210 List<string> list = new List<string>();
211 list.Add(uuid);
212 triage.Add(url, list);
213 }
214 }
215
216 foreach (KeyValuePair<string, List<string>> kvp in triage)
217 {
218 if (kvp.Key == "local")
219 {
220 PresenceInfo[] pinfos = m_GridService.GetAgents(kvp.Value.ToArray());
221 presences.AddRange(pinfos);
222 }
223 else
224 {
225 PresenceInfo[] pinfos = m_HGService.GetAgents(/*kvp.Key,*/ kvp.Value.ToArray());
226 presences.AddRange(pinfos);
227 }
228 }
229
230 return presences.ToArray();
231 }
232
233 #endregion
234
235 private void StringToUrlAndUUID(string id, out string url, out string uuid)
236 {
237 url = String.Empty;
238 uuid = String.Empty;
239
240 Uri uri;
241
242 if (Uri.TryCreate(id, UriKind.Absolute, out uri) &&
243 uri.Scheme == Uri.UriSchemeHttp)
244 {
245 url = "http://" + uri.Authority;
246 uuid = uri.LocalPath.Trim(new char[] { '/' });
247 }
248 else
249 {
250 url = "local";
251 uuid = id;
252 }
253 }
254
255 }
256}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/LocalPresenceServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/LocalPresenceServiceConnector.cs
index 24362c7..510e9cb 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/LocalPresenceServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/LocalPresenceServiceConnector.cs
@@ -47,7 +47,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence
47 #region ISharedRegionModule 47 #region ISharedRegionModule
48 48
49 private bool m_Enabled = false; 49 private bool m_Enabled = false;
50 private bool m_Initialized = false;
51 50
52 private PresenceDetector m_PresenceDetector; 51 private PresenceDetector m_PresenceDetector;
53 private IPresenceService m_PresenceService; 52 private IPresenceService m_PresenceService;
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/RemotePresenceServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/RemotePresenceServiceConnector.cs
new file mode 100644
index 0000000..eacf467
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/RemotePresenceServiceConnector.cs
@@ -0,0 +1,158 @@
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 */
27using System;
28using System.Collections.Generic;
29using System.Reflection;
30
31using OpenSim.Region.Framework.Interfaces;
32using OpenSim.Region.Framework.Scenes;
33using OpenSim.Server.Base;
34using OpenSim.Services.Interfaces;
35using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo;
36
37using OpenMetaverse;
38using log4net;
39using Nini.Config;
40
41namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence
42{
43 public class RemotePresenceServiceConnector : ISharedRegionModule, IPresenceService
44 {
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46
47 #region ISharedRegionModule
48
49 private bool m_Enabled = false;
50
51 private PresenceDetector m_PresenceDetector;
52 private IPresenceService m_RemoteConnector;
53
54 public Type ReplaceableInterface
55 {
56 get { return null; }
57 }
58
59 public string Name
60 {
61 get { return "RemotePresenceServiceConnector"; }
62 }
63
64 public void Initialise(IConfigSource source)
65 {
66 IConfig moduleConfig = source.Configs["Modules"];
67 if (moduleConfig != null)
68 {
69 string name = moduleConfig.GetString("PresenceServices", "");
70 if (name == Name)
71 {
72 //m_RemoteConnector = new PresenceServicesConnector(source);
73
74 m_Enabled = true;
75
76 m_PresenceDetector = new PresenceDetector(this);
77
78 m_log.Info("[INVENTORY CONNECTOR]: Remote presence enabled");
79 }
80 }
81
82 }
83
84 public void PostInitialise()
85 {
86 }
87
88 public void Close()
89 {
90 }
91
92 public void AddRegion(Scene scene)
93 {
94 if (!m_Enabled)
95 return;
96
97 scene.RegisterModuleInterface<IPresenceService>(this);
98 m_PresenceDetector.AddRegion(scene);
99
100 m_log.InfoFormat("[REMOTE PRESENCE CONNECTOR]: Enabled remote presence for region {0}", scene.RegionInfo.RegionName);
101
102 }
103
104 public void RemoveRegion(Scene scene)
105 {
106 if (!m_Enabled)
107 return;
108
109 m_PresenceDetector.RemoveRegion(scene);
110 }
111
112 public void RegionLoaded(Scene scene)
113 {
114 if (!m_Enabled)
115 return;
116
117 }
118
119 #endregion
120
121 #region IPresenceService
122
123 public bool LoginAgent(UUID principalID, UUID sessionID, UUID secureSessionID)
124 {
125 m_log.Warn("[REMOTE PRESENCE CONNECTOR]: LoginAgent connector not implemented at the simulators");
126 return false;
127 }
128
129 public bool LogoutAgent(UUID sessionID)
130 {
131 return m_RemoteConnector.LogoutAgent(sessionID);
132 }
133
134
135 public bool LogoutRegionAgents(UUID regionID)
136 {
137 return m_RemoteConnector.LogoutRegionAgents(regionID);
138 }
139
140 public bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt)
141 {
142 return m_RemoteConnector.ReportAgent(sessionID, regionID, position, lookAt);
143 }
144
145 public PresenceInfo GetAgent(UUID sessionID)
146 {
147 return m_RemoteConnector.GetAgent(sessionID);
148 }
149
150 public PresenceInfo[] GetAgents(string[] principalIDs)
151 {
152 return m_RemoteConnector.GetAgents(principalIDs);
153 }
154
155 #endregion
156
157 }
158}
diff --git a/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs
index d914d32..b02c2ed 100644
--- a/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs
@@ -78,8 +78,18 @@ namespace OpenSim.Server.Handlers.Presence
78 78
79 switch (method) 79 switch (method)
80 { 80 {
81 case "login":
82 return LoginAgent(request);
83 case "logout":
84 return LogoutAgent(request);
85 case "logoutregion":
86 return LogoutRegionAgents(request);
81 case "report": 87 case "report":
82 return Report(request); 88 return Report(request);
89 case "getagent":
90 return GetAgent(request);
91 case "getagents":
92 return GetAgents(request);
83 } 93 }
84 m_log.DebugFormat("[PRESENCE HANDLER]: unknown method request: {0}", method); 94 m_log.DebugFormat("[PRESENCE HANDLER]: unknown method request: {0}", method);
85 } 95 }
@@ -92,28 +102,154 @@ namespace OpenSim.Server.Handlers.Presence
92 102
93 } 103 }
94 104
105 byte[] LoginAgent(Dictionary<string, object> request)
106 {
107 UUID principal = UUID.Zero;
108 UUID session = UUID.Zero;
109 UUID ssession = UUID.Zero;
110
111 if (!request.ContainsKey("PrincipalID") || !request.ContainsKey("SessionID"))
112 return FailureResult();
113
114 if (!UUID.TryParse(request["PrincipalID"].ToString(), out principal))
115 return FailureResult();
116
117 if (!UUID.TryParse(request["SessionID"].ToString(), out session))
118 return FailureResult();
119
120 if (request.ContainsKey("SecureSessionID"))
121 // If it's malformed, we go on with a Zero on it
122 UUID.TryParse(request["SecureSessionID"].ToString(), out ssession);
123
124 if (m_PresenceService.LoginAgent(principal, session, ssession))
125 return SuccessResult();
126
127 return FailureResult();
128 }
129
130 byte[] LogoutAgent(Dictionary<string, object> request)
131 {
132 UUID session = UUID.Zero;
133
134 if (!request.ContainsKey("SessionID"))
135 return FailureResult();
136
137 if (!UUID.TryParse(request["SessionID"].ToString(), out session))
138 return FailureResult();
139
140 if (m_PresenceService.LogoutAgent(session))
141 return SuccessResult();
142
143 return FailureResult();
144 }
145
146 byte[] LogoutRegionAgents(Dictionary<string, object> request)
147 {
148 UUID region = UUID.Zero;
149
150 if (!request.ContainsKey("RegionID"))
151 return FailureResult();
152
153 if (!UUID.TryParse(request["RegionID"].ToString(), out region))
154 return FailureResult();
155
156 if (m_PresenceService.LogoutRegionAgents(region))
157 return SuccessResult();
158
159 return FailureResult();
160 }
161
95 byte[] Report(Dictionary<string, object> request) 162 byte[] Report(Dictionary<string, object> request)
96 { 163 {
97 PresenceInfo info = new PresenceInfo(); 164 UUID session = UUID.Zero;
165 UUID region = UUID.Zero;
166 Vector3 position = new Vector3(128, 128, 70);
167 Vector3 look = Vector3.Zero;
98 168
99 if (!request.ContainsKey("PrincipalID") || !request.ContainsKey("RegionID")) 169 if (!request.ContainsKey("SessionID") || !request.ContainsKey("RegionID"))
100 return FailureResult(); 170 return FailureResult();
101 171
102 if (!UUID.TryParse(request["PrincipalID"].ToString(), 172 if (!UUID.TryParse(request["SessionID"].ToString(), out session))
103 out info.PrincipalID))
104 return FailureResult(); 173 return FailureResult();
105 174
106 if (!UUID.TryParse(request["RegionID"].ToString(), 175 if (!UUID.TryParse(request["RegionID"].ToString(), out region))
107 out info.RegionID))
108 return FailureResult(); 176 return FailureResult();
109 177
178 if (request.ContainsKey("position"))
179 Vector3.TryParse(request["position"].ToString(), out position);
110 180
111// if (m_PresenceService.ReportAgent(info)) 181 if (request.ContainsKey("lookAt"))
112// return SuccessResult(); 182 Vector3.TryParse(request["lookAt"].ToString(), out look);
183
184 if (m_PresenceService.ReportAgent(session, region, position, look))
185 return SuccessResult();
113 186
114 return FailureResult(); 187 return FailureResult();
115 } 188 }
116 189
190 byte[] GetAgent(Dictionary<string, object> request)
191 {
192 UUID session = UUID.Zero;
193
194 if (!request.ContainsKey("SessionID"))
195 return FailureResult();
196
197 if (!UUID.TryParse(request["SessionID"].ToString(), out session))
198 return FailureResult();
199
200 PresenceInfo pinfo = m_PresenceService.GetAgent(session);
201
202 Dictionary<string, object> result = new Dictionary<string, object>();
203 if (pinfo == null)
204 result["result"] = "null";
205 else
206 result["result"] = pinfo.ToKeyValuePairs();
207
208 string xmlString = ServerUtils.BuildXmlResponse(result);
209 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
210 UTF8Encoding encoding = new UTF8Encoding();
211 return encoding.GetBytes(xmlString);
212 }
213
214 byte[] GetAgents(Dictionary<string, object> request)
215 {
216
217 string[] userIDs;
218
219 if (!request.ContainsKey("uuids"))
220 return FailureResult();
221
222 if (!(request["uuids"] is List<string>))
223 {
224 m_log.DebugFormat("[PRESENCE HANDLER]: GetAgents input argument was of unexpected type {0}", request["uuids"].GetType().ToString());
225 return FailureResult();
226 }
227
228 userIDs = ((List<string>)request["uuids"]).ToArray();
229
230 PresenceInfo[] pinfos = m_PresenceService.GetAgents(userIDs);
231
232 Dictionary<string, object> result = new Dictionary<string, object>();
233 if ((pinfos == null) || ((pinfos != null) && (pinfos.Length == 0)))
234 result["result"] = "null";
235 else
236 {
237 int i = 0;
238 foreach (PresenceInfo pinfo in pinfos)
239 {
240 Dictionary<string, object> rinfoDict = pinfo.ToKeyValuePairs();
241 result["presence" + i] = rinfoDict;
242 i++;
243 }
244 }
245
246 string xmlString = ServerUtils.BuildXmlResponse(result);
247 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
248 UTF8Encoding encoding = new UTF8Encoding();
249 return encoding.GetBytes(xmlString);
250 }
251
252
117 private byte[] SuccessResult() 253 private byte[] SuccessResult()
118 { 254 {
119 XmlDocument doc = new XmlDocument(); 255 XmlDocument doc = new XmlDocument();
diff --git a/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs b/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs
new file mode 100644
index 0000000..906d6bd
--- /dev/null
+++ b/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs
@@ -0,0 +1,377 @@
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 log4net;
29using System;
30using System.Collections.Generic;
31using System.IO;
32using System.Reflection;
33using Nini.Config;
34using OpenSim.Framework;
35using OpenSim.Framework.Communications;
36using OpenSim.Framework.Servers.HttpServer;
37using OpenSim.Services.Interfaces;
38using GridRegion = OpenSim.Services.Interfaces.GridRegion;
39using OpenSim.Server.Base;
40using OpenMetaverse;
41
42namespace OpenSim.Services.Connectors
43{
44 public class PresenceServicesConnector : IPresenceService
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 PresenceServicesConnector()
53 {
54 }
55
56 public PresenceServicesConnector(string serverURI)
57 {
58 m_ServerURI = serverURI.TrimEnd('/');
59 }
60
61 public PresenceServicesConnector(IConfigSource source)
62 {
63 Initialise(source);
64 }
65
66 public virtual void Initialise(IConfigSource source)
67 {
68 IConfig gridConfig = source.Configs["PresenceService"];
69 if (gridConfig == null)
70 {
71 m_log.Error("[PRESENCE CONNECTOR]: PresenceService missing from OpenSim.ini");
72 throw new Exception("Presence connector init error");
73 }
74
75 string serviceURI = gridConfig.GetString("PresenceServerURI",
76 String.Empty);
77
78 if (serviceURI == String.Empty)
79 {
80 m_log.Error("[PRESENCE CONNECTOR]: No Server URI named in section PresenceService");
81 throw new Exception("Presence connector init error");
82 }
83 m_ServerURI = serviceURI;
84 }
85
86
87 #region IPresenceService
88
89 public bool LoginAgent(UUID principalID, UUID sessionID, UUID secureSessionID)
90 {
91 Dictionary<string, object> sendData = new Dictionary<string, object>();
92 //sendData["SCOPEID"] = scopeID.ToString();
93 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
94 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
95 sendData["METHOD"] = "login";
96
97 sendData["PrincipalID"] = principalID.ToString();
98 sendData["SessionID"] = sessionID.ToString();
99 sendData["SecureSessionID"] = secureSessionID.ToString();
100
101 string reqString = ServerUtils.BuildQueryString(sendData);
102 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
103 try
104 {
105 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
106 m_ServerURI + "/presence",
107 reqString);
108 if (reply != string.Empty)
109 {
110 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
111
112 if (replyData.ContainsKey("Result"))
113 {
114 if (replyData["Result"].ToString().ToLower() == "success")
115 return true;
116 else
117 return false;
118 }
119 else
120 m_log.DebugFormat("[PRESENCE CONNECTOR]: LoginAgent reply data does not contain result field");
121
122 }
123 else
124 m_log.DebugFormat("[PRESENCE CONNECTOR]: LoginAgent received empty reply");
125 }
126 catch (Exception e)
127 {
128 m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message);
129 }
130
131 return false;
132
133 }
134
135 public bool LogoutAgent(UUID sessionID)
136 {
137 Dictionary<string, object> sendData = new Dictionary<string, object>();
138 //sendData["SCOPEID"] = scopeID.ToString();
139 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
140 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
141 sendData["METHOD"] = "logout";
142
143 sendData["SessionID"] = sessionID.ToString();
144
145 string reqString = ServerUtils.BuildQueryString(sendData);
146 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
147 try
148 {
149 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
150 m_ServerURI + "/presence",
151 reqString);
152 if (reply != string.Empty)
153 {
154 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
155
156 if (replyData.ContainsKey("Result"))
157 {
158 if (replyData["Result"].ToString().ToLower() == "success")
159 return true;
160 else
161 return false;
162 }
163 else
164 m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutAgent reply data does not contain result field");
165
166 }
167 else
168 m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutAgent received empty reply");
169 }
170 catch (Exception e)
171 {
172 m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message);
173 }
174
175 return false;
176 }
177
178 public bool LogoutRegionAgents(UUID regionID)
179 {
180 Dictionary<string, object> sendData = new Dictionary<string, object>();
181 //sendData["SCOPEID"] = scopeID.ToString();
182 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
183 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
184 sendData["METHOD"] = "logoutregion";
185
186 sendData["RegionID"] = regionID.ToString();
187
188 string reqString = ServerUtils.BuildQueryString(sendData);
189 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
190 try
191 {
192 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
193 m_ServerURI + "/presence",
194 reqString);
195 if (reply != string.Empty)
196 {
197 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
198
199 if (replyData.ContainsKey("Result"))
200 {
201 if (replyData["Result"].ToString().ToLower() == "success")
202 return true;
203 else
204 return false;
205 }
206 else
207 m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutRegionAgents reply data does not contain result field");
208
209 }
210 else
211 m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutRegionAgents received empty reply");
212 }
213 catch (Exception e)
214 {
215 m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message);
216 }
217
218 return false;
219 }
220
221 public bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt)
222 {
223 Dictionary<string, object> sendData = new Dictionary<string, object>();
224 //sendData["SCOPEID"] = scopeID.ToString();
225 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
226 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
227 sendData["METHOD"] = "report";
228
229 sendData["SessionID"] = sessionID.ToString();
230 sendData["RegionID"] = regionID.ToString();
231 sendData["position"] = position.ToString();
232 sendData["lookAt"] = lookAt.ToString();
233
234 string reqString = ServerUtils.BuildQueryString(sendData);
235 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
236 try
237 {
238 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
239 m_ServerURI + "/presence",
240 reqString);
241 if (reply != string.Empty)
242 {
243 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
244
245 if (replyData.ContainsKey("Result"))
246 {
247 if (replyData["Result"].ToString().ToLower() == "success")
248 return true;
249 else
250 return false;
251 }
252 else
253 m_log.DebugFormat("[PRESENCE CONNECTOR]: ReportAgent reply data does not contain result field");
254
255 }
256 else
257 m_log.DebugFormat("[PRESENCE CONNECTOR]: ReportAgent received empty reply");
258 }
259 catch (Exception e)
260 {
261 m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message);
262 }
263
264 return false;
265 }
266
267 public PresenceInfo GetAgent(UUID sessionID)
268 {
269 Dictionary<string, object> sendData = new Dictionary<string, object>();
270 //sendData["SCOPEID"] = scopeID.ToString();
271 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
272 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
273 sendData["METHOD"] = "getagent";
274
275 sendData["SessionID"] = sessionID.ToString();
276
277 string reply = string.Empty;
278 string reqString = ServerUtils.BuildQueryString(sendData);
279 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
280 try
281 {
282 reply = SynchronousRestFormsRequester.MakeRequest("POST",
283 m_ServerURI + "/presence",
284 reqString);
285 if (reply == null || (reply != null && reply == string.Empty))
286 {
287 m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgent received null or empty reply");
288 return null;
289 }
290 }
291 catch (Exception e)
292 {
293 m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message);
294 }
295
296 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
297 PresenceInfo pinfo = null;
298
299 if ((replyData != null) && (replyData["result"] != null))
300 {
301 if (replyData["result"].ToString() == "null")
302 return null;
303
304 if (replyData["result"] is Dictionary<string, object>)
305 {
306 pinfo = new PresenceInfo((Dictionary<string, object>)replyData["result"]);
307 }
308 }
309
310 return pinfo;
311 }
312
313 public PresenceInfo[] GetAgents(string[] userIDs)
314 {
315 Dictionary<string, object> sendData = new Dictionary<string, object>();
316 //sendData["SCOPEID"] = scopeID.ToString();
317 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
318 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
319 sendData["METHOD"] = "getagents";
320
321 sendData["uuids"] = new List<string>(userIDs);
322
323 string reply = string.Empty;
324 string reqString = ServerUtils.BuildQueryString(sendData);
325 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
326 try
327 {
328 reply = SynchronousRestFormsRequester.MakeRequest("POST",
329 m_ServerURI + "/presence",
330 reqString);
331 if (reply == null || (reply != null && reply == string.Empty))
332 {
333 m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgent received null or empty reply");
334 return null;
335 }
336 }
337 catch (Exception e)
338 {
339 m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message);
340 }
341
342 List<PresenceInfo> rinfos = new List<PresenceInfo>();
343
344 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
345
346 if (replyData != null)
347 {
348 if (replyData.ContainsKey("result") && replyData.ContainsKey("result").ToString() == "null")
349 {
350 return new PresenceInfo[0];
351 }
352
353 Dictionary<string, object>.ValueCollection pinfosList = replyData.Values;
354 //m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count);
355 foreach (object presence in pinfosList)
356 {
357 if (presence is Dictionary<string, object>)
358 {
359 PresenceInfo pinfo = new PresenceInfo((Dictionary<string, object>)presence);
360 rinfos.Add(pinfo);
361 }
362 else
363 m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received invalid response type {0}",
364 presence.GetType());
365 }
366 }
367 else
368 m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received null response");
369
370 return rinfos.ToArray();
371 }
372
373
374 #endregion
375
376 }
377}
diff --git a/OpenSim/Services/Interfaces/IPresenceService.cs b/OpenSim/Services/Interfaces/IPresenceService.cs
index 1cda13c..56d8f15 100644
--- a/OpenSim/Services/Interfaces/IPresenceService.cs
+++ b/OpenSim/Services/Interfaces/IPresenceService.cs
@@ -41,6 +41,43 @@ namespace OpenSim.Services.Interfaces
41 public DateTime Logout; 41 public DateTime Logout;
42 public Vector3 Position; 42 public Vector3 Position;
43 public Vector3 LookAt; 43 public Vector3 LookAt;
44
45 public PresenceInfo()
46 {
47 }
48
49 public PresenceInfo(Dictionary<string, object> kvp)
50 {
51 if (kvp.ContainsKey("PrincipalID"))
52 UUID.TryParse(kvp["PrincipalID"].ToString(), out PrincipalID);
53 if (kvp.ContainsKey("RegionID"))
54 UUID.TryParse(kvp["RegionID"].ToString(), out RegionID);
55 if (kvp.ContainsKey("login"))
56 DateTime.TryParse(kvp["login"].ToString(), out Login);
57 if (kvp.ContainsKey("logout"))
58 DateTime.TryParse(kvp["logout"].ToString(), out Logout);
59 if (kvp.ContainsKey("lookAt"))
60 Vector3.TryParse(kvp["lookAt"].ToString(), out LookAt);
61 if (kvp.ContainsKey("online"))
62 Boolean.TryParse(kvp["online"].ToString(), out Online);
63 if (kvp.ContainsKey("position"))
64 Vector3.TryParse(kvp["position"].ToString(), out Position);
65
66 }
67
68 public Dictionary<string, object> ToKeyValuePairs()
69 {
70 Dictionary<string, object> result = new Dictionary<string, object>();
71 result["PrincipalID"] = PrincipalID.ToString();
72 result["RegionID"] = RegionID.ToString();
73 result["online"] = Online.ToString();
74 result["login"] = Login.ToString();
75 result["logout"] = Logout.ToString();
76 result["position"] = Position.ToString();
77 result["lookAt"] = LookAt.ToString();
78
79 return result;
80 }
44 } 81 }
45 82
46 public interface IPresenceService 83 public interface IPresenceService
@@ -52,6 +89,6 @@ namespace OpenSim.Services.Interfaces
52 bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt); 89 bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt);
53 90
54 PresenceInfo GetAgent(UUID sessionID); 91 PresenceInfo GetAgent(UUID sessionID);
55 PresenceInfo[] GetAgents(string[] principalIDs); 92 PresenceInfo[] GetAgents(string[] userIDs);
56 } 93 }
57} 94}