aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Data/MySQL/Resources/001_GridUserStore.sql17
-rw-r--r--OpenSim/Data/SQLite/Resources/001_GridUserStore.sql16
-rw-r--r--OpenSim/Data/SQLite/SQLiteGridUserData.cs61
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/ActivityDetector.cs116
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/RemoteGridUserServiceConnector.cs153
-rw-r--r--OpenSim/Server/Handlers/GridUser/GridUserServerConnector.cs61
-rw-r--r--OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs278
7 files changed, 702 insertions, 0 deletions
diff --git a/OpenSim/Data/MySQL/Resources/001_GridUserStore.sql b/OpenSim/Data/MySQL/Resources/001_GridUserStore.sql
new file mode 100644
index 0000000..ce4ab96
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/001_GridUserStore.sql
@@ -0,0 +1,17 @@
1BEGIN;
2
3CREATE TABLE `GridUser` (
4 `UserID` VARCHAR(255) NOT NULL,
5 `HomeRegionID` CHAR(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000',
6 `HomePosition` CHAR(64) NOT NULL DEFAULT '<0,0,0>',
7 `HomeLookAt` CHAR(64) NOT NULL DEFAULT '<0,0,0>',
8 `LastRegionID` CHAR(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000',
9 `LastPosition` CHAR(64) NOT NULL DEFAULT '<0,0,0>',
10 `LastLookAt` CHAR(64) NOT NULL DEFAULT '<0,0,0>',
11 `Online` CHAR(5) NOT NULL DEFAULT 'false',
12 `Login` CHAR(16) NOT NULL DEFAULT '0',
13 `Logout` CHAR(16) NOT NULL DEFAULT '0',
14 PRIMARY KEY (`UserID`)
15) ENGINE=InnoDB;
16
17COMMIT;
diff --git a/OpenSim/Data/SQLite/Resources/001_GridUserStore.sql b/OpenSim/Data/SQLite/Resources/001_GridUserStore.sql
new file mode 100644
index 0000000..1a24613
--- /dev/null
+++ b/OpenSim/Data/SQLite/Resources/001_GridUserStore.sql
@@ -0,0 +1,16 @@
1BEGIN TRANSACTION;
2
3CREATE TABLE GridUser (
4 UserID VARCHAR(255) primary key,
5 HomeRegionID CHAR(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000',
6 HomePosition CHAR(64) NOT NULL DEFAULT '<0,0,0>',
7 HomeLookAt CHAR(64) NOT NULL DEFAULT '<0,0,0>',
8 LastRegionID CHAR(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000',
9 LastPosition CHAR(64) NOT NULL DEFAULT '<0,0,0>',
10 LastLookAt CHAR(64) NOT NULL DEFAULT '<0,0,0>',
11 Online CHAR(5) NOT NULL DEFAULT 'false',
12 Login CHAR(16) NOT NULL DEFAULT '0',
13 Logout CHAR(16) NOT NULL DEFAULT '0'
14) ;
15
16COMMIT;
diff --git a/OpenSim/Data/SQLite/SQLiteGridUserData.cs b/OpenSim/Data/SQLite/SQLiteGridUserData.cs
new file mode 100644
index 0000000..1bb5ed8
--- /dev/null
+++ b/OpenSim/Data/SQLite/SQLiteGridUserData.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 System.Collections.Generic;
30using System.Data;
31using System.Reflection;
32using System.Threading;
33using log4net;
34using OpenMetaverse;
35using OpenSim.Framework;
36
37namespace OpenSim.Data.SQLite
38{
39 /// <summary>
40 /// A SQL Interface for user grid data
41 /// </summary>
42 public class SQLiteGridUserData : SQLiteGenericTableHandler<GridUserData>, IGridUserData
43 {
44// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45
46 public SQLiteGridUserData(string connectionString, string realm)
47 : base(connectionString, realm, "GridUserStore") {}
48
49 public new GridUserData Get(string userID)
50 {
51 GridUserData[] ret = Get("UserID", userID);
52
53 if (ret.Length == 0)
54 return null;
55
56 return ret[0];
57 }
58
59
60 }
61} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/ActivityDetector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/ActivityDetector.cs
new file mode 100644
index 0000000..6c01927
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/ActivityDetector.cs
@@ -0,0 +1,116 @@
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.Framework;
32using OpenSim.Region.Framework.Scenes;
33using OpenSim.Services.Interfaces;
34
35using OpenMetaverse;
36using log4net;
37
38namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.GridUser
39{
40 public class ActivityDetector
41 {
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43
44 private IGridUserService m_GridUserService;
45 private Scene m_aScene;
46
47 public ActivityDetector(IGridUserService guservice)
48 {
49 m_GridUserService = guservice;
50 m_log.DebugFormat("[ACTIVITY DETECTOR]: starting ");
51 }
52
53 public void AddRegion(Scene scene)
54 {
55 // For now the only events we listen to are these
56 // But we could trigger the position update more often
57 scene.EventManager.OnMakeRootAgent += OnMakeRootAgent;
58 scene.EventManager.OnNewClient += OnNewClient;
59 scene.EventManager.OnAvatarEnteringNewParcel += OnEnteringNewParcel;
60
61 if (m_aScene == null)
62 m_aScene = scene;
63 }
64
65 public void RemoveRegion(Scene scene)
66 {
67 scene.EventManager.OnMakeRootAgent -= OnMakeRootAgent;
68 scene.EventManager.OnNewClient -= OnNewClient;
69 }
70
71 public void OnMakeRootAgent(ScenePresence sp)
72 {
73 m_log.DebugFormat("[ACTIVITY DETECTOR]: Detected root presence {0} in {1}", sp.UUID, sp.Scene.RegionInfo.RegionName);
74
75 m_GridUserService.SetLastPosition(sp.UUID.ToString(), sp.Scene.RegionInfo.RegionID, sp.AbsolutePosition, sp.Lookat);
76 }
77
78 public void OnNewClient(IClientAPI client)
79 {
80 client.OnConnectionClosed += OnConnectionClose;
81 }
82
83 public void OnConnectionClose(IClientAPI client)
84 {
85 if (client.IsLoggingOut)
86 {
87 object sp = null;
88 Vector3 position = new Vector3(128, 128, 0);
89 Vector3 lookat = new Vector3(0, 1, 0);
90
91 if (client.Scene.TryGetScenePresence(client.AgentId, out sp))
92 {
93 if (sp is ScenePresence)
94 {
95 if (((ScenePresence)sp).IsChildAgent)
96 return;
97
98 position = ((ScenePresence)sp).AbsolutePosition;
99 lookat = ((ScenePresence)sp).Lookat;
100 }
101 }
102 m_log.DebugFormat("[ACTIVITY DETECTOR]: Detected client logout {0} in {1}", client.AgentId, client.Scene.RegionInfo.RegionName);
103 m_GridUserService.LoggedOut(client.AgentId.ToString(), client.Scene.RegionInfo.RegionID, position, lookat);
104 }
105
106 }
107
108 void OnEnteringNewParcel(ScenePresence sp, int localLandID, UUID regionID)
109 {
110 // TODO: grab the parcel ID from ILandModule
111 // and send that along
112 m_GridUserService.SetLastPosition(sp.UUID.ToString(), sp.Scene.RegionInfo.RegionID, sp.AbsolutePosition, sp.Lookat);
113 }
114
115 }
116}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/RemoteGridUserServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/RemoteGridUserServiceConnector.cs
new file mode 100644
index 0000000..e3e2e61
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/RemoteGridUserServiceConnector.cs
@@ -0,0 +1,153 @@
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 OpenSim.Services.Connectors;
36
37using OpenMetaverse;
38using log4net;
39using Nini.Config;
40
41namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.GridUser
42{
43 public class RemoteGridUserServicesConnector : ISharedRegionModule, IGridUserService
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 ActivityDetector m_ActivityDetector;
52 private IGridUserService m_RemoteConnector;
53
54 public Type ReplaceableInterface
55 {
56 get { return null; }
57 }
58
59 public string Name
60 {
61 get { return "RemoteGridUserServicesConnector"; }
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("GridUserServices", "");
70 if (name == Name)
71 {
72 m_RemoteConnector = new GridUserServicesConnector(source);
73
74 m_Enabled = true;
75
76 m_ActivityDetector = new ActivityDetector(this);
77
78 m_log.Info("[REMOTE GRID USER CONNECTOR]: Remote grid user 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<IGridUserService>(this);
98 m_ActivityDetector.AddRegion(scene);
99
100 m_log.InfoFormat("[REMOTE GRID USER CONNECTOR]: Enabled remote grid user 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_ActivityDetector.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 IGridUserService
122
123 public GridUserInfo LoggedIn(string userID)
124 {
125 m_log.Warn("[REMOTE GRID USER CONNECTOR]: LoggedIn not implemented at the simulators");
126 return null;
127 }
128
129 public bool LoggedOut(string userID, UUID region, Vector3 position, Vector3 lookat)
130 {
131 return m_RemoteConnector.LoggedOut(userID, region, position, lookat);
132 }
133
134
135 public bool SetHome(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
136 {
137 return m_RemoteConnector.SetHome(userID, regionID, position, lookAt);
138 }
139
140 public bool SetLastPosition(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
141 {
142 return m_RemoteConnector.SetLastPosition(userID, regionID, position, lookAt);
143 }
144
145 public GridUserInfo GetGridUserInfo(string userID)
146 {
147 return m_RemoteConnector.GetGridUserInfo(userID);
148 }
149
150 #endregion
151
152 }
153}
diff --git a/OpenSim/Server/Handlers/GridUser/GridUserServerConnector.cs b/OpenSim/Server/Handlers/GridUser/GridUserServerConnector.cs
new file mode 100644
index 0000000..66f35e3
--- /dev/null
+++ b/OpenSim/Server/Handlers/GridUser/GridUserServerConnector.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.GridUser
36{
37 public class GridUserServiceConnector : ServiceConnector
38 {
39 private IGridUserService m_GridUserService;
40 private string m_ConfigName = "GridUserService";
41
42 public GridUserServiceConnector(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 service = serverConfig.GetString("LocalServiceModule",
50 String.Empty);
51
52 if (service == String.Empty)
53 throw new Exception("No LocalServiceModule in config file");
54
55 Object[] args = new Object[] { config };
56 m_GridUserService = ServerUtils.LoadPlugin<IGridUserService>(service, args);
57
58 server.AddStreamHandler(new GridUserServerPostHandler(m_GridUserService));
59 }
60 }
61}
diff --git a/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs b/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs
new file mode 100644
index 0000000..f8fa429
--- /dev/null
+++ b/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs
@@ -0,0 +1,278 @@
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 OpenSim.Framework;
42using OpenSim.Framework.Servers.HttpServer;
43using OpenMetaverse;
44
45namespace OpenSim.Server.Handlers.GridUser
46{
47 public class GridUserServerPostHandler : BaseStreamHandler
48 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50
51 private IGridUserService m_GridUserService;
52
53 public GridUserServerPostHandler(IGridUserService service) :
54 base("POST", "/griduser")
55 {
56 m_GridUserService = service;
57 }
58
59 public override byte[] Handle(string path, Stream requestData,
60 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
61 {
62 StreamReader sr = new StreamReader(requestData);
63 string body = sr.ReadToEnd();
64 sr.Close();
65 body = body.Trim();
66
67 //m_log.DebugFormat("[XXX]: query String: {0}", body);
68 string method = string.Empty;
69 try
70 {
71 Dictionary<string, object> request =
72 ServerUtils.ParseQueryString(body);
73
74 if (!request.ContainsKey("METHOD"))
75 return FailureResult();
76
77 method = request["METHOD"].ToString();
78
79 switch (method)
80 {
81 case "loggedin":
82 return LoggedIn(request);
83 case "loggedout":
84 return LoggedOut(request);
85 case "sethome":
86 return SetHome(request);
87 case "setposition":
88 return SetPosition(request);
89 case "getgriduserinfo":
90 return GetGridUserInfo(request);
91 }
92 m_log.DebugFormat("[GRID USER HANDLER]: unknown method request: {0}", method);
93 }
94 catch (Exception e)
95 {
96 m_log.DebugFormat("[GRID USER HANDLER]: Exception in method {0}: {1}", method, e);
97 }
98
99 return FailureResult();
100
101 }
102
103 byte[] LoggedIn(Dictionary<string, object> request)
104 {
105 string user = String.Empty;
106
107 if (!request.ContainsKey("UserID"))
108 return FailureResult();
109
110 user = request["UserID"].ToString();
111
112 GridUserInfo guinfo = m_GridUserService.LoggedIn(user);
113
114 Dictionary<string, object> result = new Dictionary<string, object>();
115 result["result"] = guinfo.ToKeyValuePairs();
116
117 string xmlString = ServerUtils.BuildXmlResponse(result);
118 //m_log.DebugFormat("[GRID USER HANDLER]: resp string: {0}", xmlString);
119 UTF8Encoding encoding = new UTF8Encoding();
120 return encoding.GetBytes(xmlString);
121
122 }
123
124 byte[] LoggedOut(Dictionary<string, object> request)
125 {
126 string userID = string.Empty;
127 UUID regionID = UUID.Zero;
128 Vector3 position = Vector3.Zero;
129 Vector3 lookat = Vector3.Zero;
130
131 if (!UnpackArgs(request, out userID, out regionID, out position, out lookat))
132 return FailureResult();
133
134 if (m_GridUserService.LoggedOut(userID, regionID, position, lookat))
135 return SuccessResult();
136
137 return FailureResult();
138 }
139
140 byte[] SetHome(Dictionary<string, object> request)
141 {
142 string user = string.Empty;
143 UUID region = UUID.Zero;
144 Vector3 position = new Vector3(128, 128, 70);
145 Vector3 look = Vector3.Zero;
146
147 if (!UnpackArgs(request, out user, out region, out position, out look))
148 return FailureResult();
149
150 if (m_GridUserService.SetHome(user, region, position, look))
151 return SuccessResult();
152
153 return FailureResult();
154 }
155
156 byte[] SetPosition(Dictionary<string, object> request)
157 {
158 string user = string.Empty;
159 UUID region = UUID.Zero;
160 Vector3 position = new Vector3(128, 128, 70);
161 Vector3 look = Vector3.Zero;
162
163 if (!request.ContainsKey("UserID") || !request.ContainsKey("RegionID"))
164 return FailureResult();
165
166 if (!UnpackArgs(request, out user, out region, out position, out look))
167 return FailureResult();
168
169 if (m_GridUserService.SetLastPosition(user, region, position, look))
170 return SuccessResult();
171
172 return FailureResult();
173 }
174
175 byte[] GetGridUserInfo(Dictionary<string, object> request)
176 {
177 string user = String.Empty;
178
179 if (!request.ContainsKey("UserID"))
180 return FailureResult();
181
182 user = request["UserID"].ToString();
183
184 GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(user);
185
186 Dictionary<string, object> result = new Dictionary<string, object>();
187 result["result"] = guinfo.ToKeyValuePairs();
188
189 string xmlString = ServerUtils.BuildXmlResponse(result);
190 //m_log.DebugFormat("[GRID USER HANDLER]: resp string: {0}", xmlString);
191 UTF8Encoding encoding = new UTF8Encoding();
192 return encoding.GetBytes(xmlString);
193
194 }
195
196 private bool UnpackArgs(Dictionary<string, object> request, out string user, out UUID region, out Vector3 position, out Vector3 lookAt)
197 {
198 user = string.Empty;
199 region = UUID.Zero;
200 position = new Vector3(128, 128, 70);
201 lookAt = Vector3.Zero;
202
203 if (!request.ContainsKey("UserID") || !request.ContainsKey("RegionID"))
204 return false;
205
206 user = request["UserID"].ToString();
207
208 if (!UUID.TryParse(request["RegionID"].ToString(), out region))
209 return false;
210
211 if (request.ContainsKey("Position"))
212 Vector3.TryParse(request["Position"].ToString(), out position);
213
214 if (request.ContainsKey("LookAt"))
215 Vector3.TryParse(request["LookAt"].ToString(), out lookAt);
216
217 return true;
218 }
219
220
221 private byte[] SuccessResult()
222 {
223 XmlDocument doc = new XmlDocument();
224
225 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
226 "", "");
227
228 doc.AppendChild(xmlnode);
229
230 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
231 "");
232
233 doc.AppendChild(rootElement);
234
235 XmlElement result = doc.CreateElement("", "result", "");
236 result.AppendChild(doc.CreateTextNode("Success"));
237
238 rootElement.AppendChild(result);
239
240 return DocToBytes(doc);
241 }
242
243 private byte[] FailureResult()
244 {
245 XmlDocument doc = new XmlDocument();
246
247 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
248 "", "");
249
250 doc.AppendChild(xmlnode);
251
252 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
253 "");
254
255 doc.AppendChild(rootElement);
256
257 XmlElement result = doc.CreateElement("", "result", "");
258 result.AppendChild(doc.CreateTextNode("Failure"));
259
260 rootElement.AppendChild(result);
261
262 return DocToBytes(doc);
263 }
264
265 private byte[] DocToBytes(XmlDocument doc)
266 {
267 MemoryStream ms = new MemoryStream();
268 XmlTextWriter xw = new XmlTextWriter(ms, null);
269 xw.Formatting = Formatting.Indented;
270 doc.WriteTo(xw);
271 xw.Flush();
272
273 return ms.ToArray();
274 }
275
276
277 }
278}